• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         (void)config;
40         return std::make_shared<AVBuffer>();
41     }
42     static std::shared_ptr<AVBuffer> CreateAVBuffer(std::shared_ptr<AVAllocator> allocator, int32_t capacity = 0,
43                                                     int32_t align = 0)
44     {
45         (void)allocator;
46         (void)capacity;
47         (void)align;
48         return std::make_shared<AVBuffer>();
49     }
50     static std::shared_ptr<AVBuffer> CreateAVBuffer(uint8_t *ptr, int32_t capacity, int32_t size = 0)
51     {
52         (void)ptr;
53         (void)capacity;
54         (void)size;
55         return std::make_shared<AVBuffer>();
56     }
CreateAVBuffer(sptr<SurfaceBuffer> surfaceBuffer)57     static std::shared_ptr<AVBuffer> CreateAVBuffer(sptr<SurfaceBuffer> surfaceBuffer)
58     {
59         (void)surfaceBuffer;
60         return std::make_shared<AVBuffer>();
61     }
62 protected:
63     using MetaData = std::vector<uint8_t>;
64     int64_t pts_;
65     int64_t dts_;
66     int64_t duration_;
67     uint32_t flag_;
68     std::shared_ptr<Meta> meta_;
69     std::shared_ptr<AVMemory> memory_;
70     AVBufferConfig config_;
71     MOCK_METHOD(Status, Init, (std::shared_ptr<AVAllocator> allocator, int32_t capacity, int32_t align), ());
72     MOCK_METHOD(Status, Init, (uint8_t* ptr, int32_t capacity, int32_t size), ());
73     MOCK_METHOD(Status, Init, (sptr<SurfaceBuffer> surfaceBuffer), ());
74 };
75 
76 class AVMemory {
77 public:
78     AVMemory() = default;
79     virtual ~AVMemory() = default;
80     MOCK_METHOD(MemoryType, GetMemoryType, (), ());
81     MOCK_METHOD(MemoryFlag, GetMemoryFlag, (), ());
82     MOCK_METHOD(int32_t, GetCapacity, (), ());
83     MOCK_METHOD(int32_t, GetSize, (), ());
84     MOCK_METHOD(Status, SetSize, (int32_t size), ());
85     MOCK_METHOD(int32_t, GetOffset, (), ());
86     MOCK_METHOD(Status, SetOffset, (int32_t offset), ());
87     MOCK_METHOD(int32_t, GetFileDescriptor, (), ());
88     MOCK_METHOD(uint8_t*, GetAddr, (), ());
89     MOCK_METHOD(int32_t, Write, (const uint8_t* in, int32_t writeSize, int32_t position), ());
90     MOCK_METHOD(int32_t, Read, (uint8_t* out, int32_t readSize, int32_t position), ());
91     MOCK_METHOD(void, Reset, (), ());
92     MOCK_METHOD(sptr<SurfaceBuffer>, GetSurfaceBuffer, (), ());
93 
94 protected:
95     MOCK_METHOD(Status, Init, (), ());
96     MOCK_METHOD(Status, Init, (MessageParcel& parcel), ());
97     MOCK_METHOD(Status, InitSurfaceBuffer, (MessageParcel& parcel), ());
98     MOCK_METHOD(Status, InitSurfaceBuffer, (sptr<SurfaceBuffer> surfaceBuffer), ());
99     MOCK_METHOD(bool, WriteToMessageParcel, (MessageParcel& parcel), ());
100     MOCK_METHOD(bool, ReadFromMessageParcel, (MessageParcel& parcel), ());
101     MOCK_METHOD(bool, ReadCommonFromMessageParcel, (MessageParcel& parcel), ());
102     MOCK_METHOD(bool, SkipCommonFromMessageParcel, (MessageParcel& parcel), ());
103     MOCK_METHOD(bool, WriteCommonToMessageParcel, (MessageParcel& parcel), ());
104     int32_t capacity_ = 0;
105     int32_t align_;
106     int32_t offset_;
107     int32_t size_;
108     uint8_t *base_;
109     uint64_t uid_;
110     std::shared_ptr<AVAllocator> allocator_;
111     static std::shared_ptr<AVMemory> CreateAVMemory(std::shared_ptr<AVAllocator> allocator,
112                                                     int32_t capacity = 0, int32_t align = 0)
113     {
114         return std::make_shared<AVMemory>();
115     }
CreateAVMemory(uint8_t * ptr,int32_t capacity,int32_t size)116     static std::shared_ptr<AVMemory> CreateAVMemory(uint8_t *ptr, int32_t capacity, int32_t size)
117     {
118         return std::make_shared<AVMemory>();
119     }
120     static std::shared_ptr<AVMemory> CreateAVMemory(MessageParcel &parcel, bool isSurfaceBuffer = false)
121     {
122         return std::make_shared<AVMemory>();
123     }
CreateAVMemory(sptr<SurfaceBuffer> surfaceBuffer)124     static std::shared_ptr<AVMemory> CreateAVMemory(sptr<SurfaceBuffer> surfaceBuffer)
125     {
126         return std::make_shared<AVMemory>();
127     }
128 };
129 }
130 }
131 #endif // MOCK_AVBUFFER_H