• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "media_info_holder.h"
17 #include "avsession_log.h"
18 
19 namespace OHOS::AVSession {
Marshalling(Parcel & parcel) const20 bool MediaInfoHolder::Marshalling(Parcel& parcel) const
21 {
22     CHECK_AND_RETURN_RET_LOG(parcel.WriteInt32(currentIndex_), false, "write currentIndex failed");
23     int32_t playInfosSize = playInfos_.size();
24     CHECK_AND_RETURN_RET_LOG(parcel.WriteInt32(playInfosSize), false, "write playInfoSize failed");
25     for (auto playInfo : playInfos_) {
26         CHECK_AND_RETURN_RET_LOG(playInfo.Marshalling(parcel), false, "write playInfoSize failed");
27     }
28     return true;
29 }
30 
Unmarshalling(Parcel & data)31 MediaInfoHolder *MediaInfoHolder::Unmarshalling(Parcel& data)
32 {
33     auto *result = new (std::nothrow) MediaInfoHolder();
34 
35     int32_t currentIndex;
36     CHECK_AND_RETURN_RET_LOG(data.ReadInt32(currentIndex), nullptr, "write currentIndex failed");
37     result->currentIndex_ = currentIndex;
38     int32_t playInfosSize;
39     CHECK_AND_RETURN_RET_LOG(data.ReadInt32(playInfosSize), nullptr, "write playInfoSize failed");
40     for (int i = 0; i < playInfosSize; i++) {
41         AVQueueItem* queueItem = AVQueueItem::Unmarshalling(data);
42         result->playInfos_.emplace_back(*queueItem);
43     }
44     CHECK_AND_RETURN_RET_LOG(result != nullptr, nullptr, "new MediaInfoHolder failed");
45     return result;
46 }
47 
SetCurrentIndex(const int32_t & currentIndex)48 void MediaInfoHolder::SetCurrentIndex(const int32_t& currentIndex)
49 {
50     currentIndex_ = currentIndex;
51 }
52 
GetCurrentIndex() const53 int32_t MediaInfoHolder::GetCurrentIndex() const
54 {
55     return currentIndex_;
56 }
57 
SetPlayInfos(const std::vector<AVQueueItem> & playInfos)58 void MediaInfoHolder::SetPlayInfos(const std::vector<AVQueueItem>& playInfos)
59 {
60     playInfos_ = playInfos;
61 }
62 
GetPlayInfos() const63 const std::vector<AVQueueItem>& MediaInfoHolder::GetPlayInfos() const
64 {
65     return playInfos_;
66 }
67 
IsValid() const68 bool MediaInfoHolder::IsValid() const
69 {
70     return playInfos_.size() > 0;
71 }
72 
Reset()73 void MediaInfoHolder::Reset()
74 {
75     currentIndex_ = 0;
76     playInfos_.clear();
77 }
78 } // namespace OHOS::AVSession
79