1 /* 2 * Copyright (C) 2025 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 #ifndef AVBUFFER_H 17 #define AVBUFFER_H 18 19 #include <gmock/gmock.h> 20 #include <gtest/gtest.h> 21 #include <memory> 22 #include <string> 23 #include "buffer/avallocator.h" 24 #include "common/status.h" 25 26 namespace OHOS { 27 namespace Media { 28 class AVMemory; 29 class AVBuffer { 30 public: 31 AVBuffer() = default; 32 virtual ~AVBuffer() = default; 33 MOCK_METHOD(const AVBufferConfig&, GetConfig, (), ()); 34 MOCK_METHOD(uint64_t, GetUniqueId, (), ()); 35 MOCK_METHOD(bool, WriteToMessageParcel, (MessageParcel& parcel), ()); 36 MOCK_METHOD(bool, ReadFromMessageParcel, (MessageParcel& parcel, bool isSurfaceBuffer), ()); CreateAVBuffer(const AVBufferConfig & config)37 static std::shared_ptr<AVBuffer> CreateAVBuffer(const AVBufferConfig &config) 38 { 39 return std::make_shared<AVBuffer>(); 40 } 41 static std::shared_ptr<AVBuffer> CreateAVBuffer(std::shared_ptr<AVAllocator> allocator, int32_t capacity = 0, 42 int32_t align = 0) 43 { 44 return std::make_shared<AVBuffer>(); 45 } 46 static std::shared_ptr<AVBuffer> CreateAVBuffer(uint8_t *ptr, int32_t capacity, int32_t size = 0) 47 { 48 return std::make_shared<AVBuffer>(); 49 } CreateAVBuffer(sptr<SurfaceBuffer> surfaceBuffer)50 static std::shared_ptr<AVBuffer> CreateAVBuffer(sptr<SurfaceBuffer> surfaceBuffer) 51 { 52 return std::make_shared<AVBuffer>(); 53 } 54 protected: 55 using MetaData = std::vector<uint8_t>; 56 int64_t pts_; 57 int64_t dts_; 58 int64_t duration_; 59 uint32_t flag_; 60 std::shared_ptr<Meta> meta_; 61 std::shared_ptr<AVMemory> memory_; 62 AVBufferConfig config_; 63 MOCK_METHOD(Status, Init, (std::shared_ptr<AVAllocator> allocator, int32_t capacity, int32_t align), ()); 64 MOCK_METHOD(Status, Init, (uint8_t* ptr, int32_t capacity, int32_t size), ()); 65 MOCK_METHOD(Status, Init, (sptr<SurfaceBuffer> surfaceBuffer), ()); 66 }; 67 68 class AVMemory { 69 public: 70 AVMemory() = default; 71 virtual ~AVMemory() = default; 72 MOCK_METHOD(MemoryType, GetMemoryType, (), ()); 73 MOCK_METHOD(MemoryFlag, GetMemoryFlag, (), ()); 74 MOCK_METHOD(int32_t, GetCapacity, (), ()); 75 MOCK_METHOD(int32_t, GetSize, (), ()); 76 MOCK_METHOD(Status, SetSize, (int32_t size), ()); 77 MOCK_METHOD(int32_t, GetOffset, (), ()); 78 MOCK_METHOD(Status, SetOffset, (int32_t offset), ()); 79 MOCK_METHOD(int32_t, GetFileDescriptor, (), ()); 80 MOCK_METHOD(uint8_t*, GetAddr, (), ()); 81 MOCK_METHOD(int32_t, Write, (const uint8_t* in, int32_t writeSize, int32_t position), ()); 82 MOCK_METHOD(int32_t, Read, (uint8_t* out, int32_t readSize, int32_t position), ()); 83 MOCK_METHOD(void, Reset, (), ()); 84 MOCK_METHOD(sptr<SurfaceBuffer>, GetSurfaceBuffer, (), ()); 85 86 protected: 87 MOCK_METHOD(Status, Init, (), ()); 88 MOCK_METHOD(Status, Init, (MessageParcel& parcel), ()); 89 MOCK_METHOD(Status, InitSurfaceBuffer, (MessageParcel& parcel), ()); 90 MOCK_METHOD(Status, InitSurfaceBuffer, (sptr<SurfaceBuffer> surfaceBuffer), ()); 91 MOCK_METHOD(bool, WriteToMessageParcel, (MessageParcel& parcel), ()); 92 MOCK_METHOD(bool, ReadFromMessageParcel, (MessageParcel& parcel), ()); 93 MOCK_METHOD(bool, ReadCommonFromMessageParcel, (MessageParcel& parcel), ()); 94 MOCK_METHOD(bool, SkipCommonFromMessageParcel, (MessageParcel& parcel), ()); 95 MOCK_METHOD(bool, WriteCommonToMessageParcel, (MessageParcel& parcel), ()); 96 int32_t capacity_ = 0; 97 int32_t align_; 98 int32_t offset_; 99 int32_t size_; 100 uint8_t *base_; 101 uint64_t uid_; 102 std::shared_ptr<AVAllocator> allocator_; 103 static std::shared_ptr<AVMemory> CreateAVMemory(std::shared_ptr<AVAllocator> allocator, 104 int32_t capacity = 0, int32_t align = 0) 105 { 106 return std::make_shared<AVMemory>(); 107 } CreateAVMemory(uint8_t * ptr,int32_t capacity,int32_t size)108 static std::shared_ptr<AVMemory> CreateAVMemory(uint8_t *ptr, int32_t capacity, int32_t size) 109 { 110 return std::make_shared<AVMemory>(); 111 } 112 static std::shared_ptr<AVMemory> CreateAVMemory(MessageParcel &parcel, bool isSurfaceBuffer = false) 113 { 114 return std::make_shared<AVMemory>(); 115 } CreateAVMemory(sptr<SurfaceBuffer> surfaceBuffer)116 static std::shared_ptr<AVMemory> CreateAVMemory(sptr<SurfaceBuffer> surfaceBuffer) 117 { 118 return std::make_shared<AVMemory>(); 119 } 120 }; 121 } 122 } 123 #endif // MOCK_AVBUFFER_H