1 /* 2 * Copyright (c) 2024 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 #ifndef DUMP_BUFFER_DEFINE_H 16 #define DUMP_BUFFER_DEFINE_H 17 18 #include "avbuffer_queue.h" 19 #include "parcel.h" 20 #include "message_parcel.h" 21 22 struct DumpBuffer : public OHOS::Parcelable { 23 DumpBuffer(); 24 explicit DumpBuffer(const std::shared_ptr<OHOS::Media::AVBuffer> &buffer); 25 virtual ~DumpBuffer(); 26 std::shared_ptr<OHOS::Media::AVBuffer> buffer_; 27 MarshallingDumpBuffer28 bool Marshalling(OHOS::Parcel &parcel) const 29 { 30 OHOS::MessageParcel *parcelIn = static_cast<OHOS::MessageParcel*>(&parcel); 31 if (buffer_ == nullptr) { 32 return false; 33 } 34 bool ret = buffer_->WriteToMessageParcel(*parcelIn); 35 return ret; 36 } 37 UnmarshallingDumpBuffer38 static DumpBuffer *Unmarshalling(OHOS::Parcel &data) 39 { 40 std::shared_ptr<OHOS::Media::AVBuffer> buffer = OHOS::Media::AVBuffer::CreateAVBuffer(); 41 if (buffer == nullptr) { 42 return nullptr; 43 } 44 struct DumpBuffer *dumpBuffer = new (std::nothrow) DumpBuffer(buffer); 45 if (dumpBuffer == nullptr) { 46 return nullptr; 47 } 48 49 OHOS::MessageParcel *parcelIn = static_cast<OHOS::MessageParcel*>(&data); 50 dumpBuffer->buffer_->ReadFromMessageParcel(*parcelIn); 51 return dumpBuffer; 52 } 53 }; 54 55 #endif // DUMP_BUFFER_DEFINE_H