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) const20bool AVQueueItem::Marshalling(Parcel& parcel) const 21 { 22 return parcel.WriteInt32(itemId_) && 23 parcel.WriteParcelable(description_.get()); 24 } 25 Unmarshalling(Parcel & data)26AVQueueItem *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 result = nullptr; 34 return nullptr; 35 } 36 result->description_ = std::shared_ptr<AVMediaDescription>(data.ReadParcelable<AVMediaDescription>()); 37 if (result->description_ == nullptr) { 38 SLOGE("read AVQueueItem - description failed"); 39 delete result; 40 result = nullptr; 41 return nullptr; 42 } 43 return result; 44 } 45 SetItemId(int32_t itemId)46void AVQueueItem::SetItemId(int32_t itemId) 47 { 48 itemId_ = itemId; 49 } 50 GetItemId() const51int32_t AVQueueItem::GetItemId() const 52 { 53 return itemId_; 54 } 55 SetDescription(const std::shared_ptr<AVMediaDescription> & description)56void AVQueueItem::SetDescription(const std::shared_ptr<AVMediaDescription>& description) 57 { 58 description_ = description; 59 } 60 GetDescription() const61std::shared_ptr<AVMediaDescription> AVQueueItem::GetDescription() const 62 { 63 return description_; 64 } 65 IsValid() const66bool AVQueueItem::IsValid() const 67 { 68 if (description_ == nullptr) { 69 SLOGE("checkIsValid queueItem without description"); 70 return false; 71 } 72 return (*description_).IsValid(); 73 } 74 Reset()75void AVQueueItem::Reset() 76 { 77 itemId_ = 0; 78 description_ = nullptr; 79 } 80 } // namespace OHOS::AVSession 81