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