• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef AVFORMAT_MOCK_H
17 #define AVFORMAT_MOCK_H
18 
19 #include <string>
20 #include "nocopyable.h"
21 
22 namespace OHOS {
23 namespace MediaAVCodec {
24 struct AVCodecBufferAttrMock {
25     int64_t pts = 0;
26     int32_t size = 0;
27     int32_t offset = 0;
28     uint32_t flags = 0;
29 };
30 
31 class FormatMock : public NoCopyable {
32 public:
33     virtual ~FormatMock() = default;
34     virtual bool PutIntValue(const std::string_view &key, int32_t value) = 0;
35     virtual bool GetIntValue(const std::string_view &key, int32_t &value) = 0;
36     virtual bool PutLongValue(const std::string_view &key, int64_t value) = 0;
37     virtual bool GetLongValue(const std::string_view &key, int64_t &value) = 0;
38     virtual bool PutFloatValue(const std::string_view &key, float value) = 0;
39     virtual bool GetFloatValue(const std::string_view &key, float &value) = 0;
40     virtual bool PutDoubleValue(const std::string_view &key, double value) = 0;
41     virtual bool GetDoubleValue(const std::string_view &key, double &value) = 0;
42     virtual bool PutStringValue(const std::string_view &key, const std::string_view &value) = 0;
43     virtual bool GetStringValue(const std::string_view &key, std::string &value) = 0;
44     virtual bool GetBuffer(const std::string_view &key, uint8_t **addr, size_t &size) = 0;
45     virtual bool PutBuffer(const std::string_view &key, const uint8_t *addr, size_t size) = 0;
46     virtual void InitTrackFormat() = 0;
47     virtual void InitAudioTrackFormat(const std::string_view &mimeType, int32_t sampleRate, int32_t channelCount) = 0;
48     virtual void InitVideoTrackFormat(const std::string_view &mimeType, int32_t width, int32_t height) = 0;
49     virtual const char *DumpInfo() = 0;
50     virtual void Destroy() = 0;
51 };
52 
53 class __attribute__((visibility("default"))) FormatMockFactory {
54 public:
55     static std::shared_ptr<FormatMock> CreateFormat();
56     static std::shared_ptr<FormatMock> CreateAudioFormat(
57         const std::string_view &mimeType, int32_t sampleRate, int32_t channelCount);
58     static std::shared_ptr<FormatMock> CreateVideoFormat(
59         const std::string_view &mimeType, int32_t width, int32_t height);
60 private:
61     FormatMockFactory() = delete;
62     ~FormatMockFactory() = delete;
63 };
64 }  // namespace MediaAVCodec
65 }  // namespace OHOS
66 #endif // AVFORMAT_MOCK_H