• 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 AVBuffer {
29 public:
30     AVBuffer() = default;
31     virtual ~AVBuffer() = default;
32     MOCK_METHOD(AVBufferConfig&, GetConfig, (), ());
33     MOCK_METHOD(uint64_t, GetUniqueId, (), ());
34     MOCK_METHOD(bool, WriteToMessageParcel, (MessageParcel& parcel), ());
35     MOCK_METHOD(bool, ReadFromMessageParcel, (MessageParcel& parcel, bool isSurfaceBuffer), ());
CreateAVBuffer(const AVBufferConfig & config)36     static std::shared_ptr<AVBuffer> CreateAVBuffer(const AVBufferConfig &config)
37     {
38         auto avBuffer = std::make_shared<AVBuffer>();
39         avBuffer->config_ = config;
40         return 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 }
77 
78 #endif // AVBUFFER_H