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 "avqueue_item.h"
17 #include "avsession_log.h"
18 
19 namespace OHOS::AVSession {
Marshalling(Parcel & parcel) const20 bool AVQueueItem::Marshalling(Parcel& parcel) const
21 {
22     return parcel.WriteInt32(itemId_) &&
23         parcel.WriteParcelable(description_.get());
24 }
25 
Unmarshalling(Parcel & data)26 AVQueueItem *AVQueueItem::Unmarshalling(Parcel& data)
27 {
28     auto *result = new (std::nothrow) AVQueueItem();
29     CHECK_AND_RETURN_RET_LOG(result != nullptr, nullptr, "new AVMetaData failed");
30     if (!data.ReadInt32(result->itemId_)) {
31         SLOGE("read AVQueueItem failed");
32         delete result;
33         return nullptr;
34     }
35     result->description_ = std::shared_ptr<AVMediaDescription>(data.ReadParcelable<AVMediaDescription>());
36     if (result->description_ == nullptr) {
37         SLOGE("read AVQueueItem - description failed");
38         delete result;
39         return nullptr;
40     }
41     return result;
42 }
43 
SetItemId(int32_t itemId)44 void AVQueueItem::SetItemId(int32_t itemId)
45 {
46     itemId_ = itemId;
47 }
48 
GetItemId() const49 int32_t AVQueueItem::GetItemId() const
50 {
51     return itemId_;
52 }
53 
SetDescription(const std::shared_ptr<AVMediaDescription> & description)54 void AVQueueItem::SetDescription(const std::shared_ptr<AVMediaDescription>& description)
55 {
56     description_ = description;
57 }
58 
GetDescription() const59 std::shared_ptr<AVMediaDescription> AVQueueItem::GetDescription() const
60 {
61     return description_;
62 }
63 
IsValid() const64 bool AVQueueItem::IsValid() const
65 {
66     if (description_ == nullptr) {
67         SLOGE("checkIsValid queueItem without description");
68         return false;
69     }
70     return (*description_).IsValid();
71 }
72 
Reset()73 void AVQueueItem::Reset()
74 {
75     itemId_ = 0;
76     description_ = nullptr;
77 }
78 } // namespace OHOS::AVSession
79