1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License") = 0;
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 CODECLIST_MOCK_H
17 #define CODECLIST_MOCK_H
18 
19 #include <iostream>
20 #include <string>
21 #include <vector>
22 #include "avcodec_codec_name.h"
23 #include "avcodec_common.h"
24 #include "avcodec_info.h"
25 #include "avcodec_list.h"
26 #include "avformat_mock.h"
27 #include "media_description.h"
28 #include "native_avcapability.h"
29 #include "native_avcodec_base.h"
30 #include "native_averrors.h"
31 #include "nocopyable.h"
32 
33 namespace OHOS {
34 namespace MediaAVCodec {
35 class CodecListMock : public NoCopyable {
36 public:
37     virtual ~CodecListMock() = default;
38     virtual bool IsHardware() = 0;
39     virtual std::string GetName() = 0;
40     virtual int32_t GetMaxSupportedInstances() = 0; // return is not errcode
41     virtual Range GetEncoderBitrateRange() = 0;
42     virtual bool IsEncoderBitrateModeSupported(OH_BitrateMode bitrateMode) = 0;
43     virtual Range GetEncoderQualityRange() = 0;
44     virtual Range GetEncoderComplexityRange() = 0;
45     virtual std::vector<int32_t> GetAudioSupportedSampleRates() = 0;
46     virtual Range GetAudioChannelsRange() = 0;
47     virtual int32_t GetVideoWidthAlignment() = 0;
48     virtual int32_t GetVideoHeightAlignment() = 0;
49     virtual Range GetVideoWidthRangeForHeight(int32_t height) = 0;
50     virtual Range GetVideoHeightRangeForWidth(int32_t width) = 0;
51     virtual Range GetVideoWidthRange() = 0;
52     virtual Range GetVideoHeightRange() = 0;
53     virtual bool IsVideoSizeSupported(int32_t width, int32_t height) = 0;
54     virtual Range GetVideoFrameRateRange() = 0;
55     virtual Range GetVideoFrameRateRangeForSize(int32_t width, int32_t height) = 0;
56     virtual bool AreVideoSizeAndFrameRateSupported(int32_t width, int32_t height, int32_t frameRate) = 0;
57     virtual std::vector<int32_t> GetVideoSupportedPixelFormats() = 0;
58     virtual std::vector<int32_t> GetSupportedProfiles() = 0;
59     virtual std::vector<int32_t> GetSupportedLevelsForProfile(int32_t profile) = 0;
60     virtual bool AreProfileAndLevelSupported(int32_t profile, int32_t level) = 0;
61 };
62 
63 class __attribute__((visibility("default"))) CodecListMockFactory {
64 public:
65     static std::shared_ptr<CodecListMock> GetCapability(const std::string &mime, bool isEncoder);
66     static std::shared_ptr<CodecListMock> GetCapabilityByCategory(const std::string &mime, bool isEncoder,
67                                                                   AVCodecCategory category);
68 
69 private:
70     CodecListMockFactory() = delete;
71     ~CodecListMockFactory() = delete;
72 };
73 
74 namespace CodecListTestParam {
75 const std::map<std::string, std::string> CAPABILITY_DECODER_NAME = {
76     {std::string(CodecMimeType::AUDIO_MPEG), std::string(AVCodecCodecName::AUDIO_DECODER_MP3_NAME)},
77     {std::string(CodecMimeType::AUDIO_AAC), std::string(AVCodecCodecName::AUDIO_DECODER_AAC_NAME)},
78     {std::string(CodecMimeType::AUDIO_VORBIS), std::string(AVCodecCodecName::AUDIO_DECODER_VORBIS_NAME)},
79     {std::string(CodecMimeType::AUDIO_FLAC), std::string(AVCodecCodecName::AUDIO_DECODER_FLAC_NAME)},
80     {std::string(CodecMimeType::VIDEO_AVC), std::string(AVCodecCodecName::VIDEO_DECODER_AVC_NAME)}};
81 
82 const std::map<std::string, std::string> CAPABILITY_ENCODER_NAME = {
83     {std::string(CodecMimeType::AUDIO_FLAC), std::string(AVCodecCodecName::AUDIO_ENCODER_FLAC_NAME)},
84     {std::string(CodecMimeType::AUDIO_AAC), std::string(AVCodecCodecName::AUDIO_ENCODER_AAC_NAME)}};
85 
86 const std::map<std::string, std::string> CAPABILITY_DECODER_HARD_NAME = {
87     {std::string(CodecMimeType::VIDEO_AVC), "OMX.hisi.video.decoder.avc"},
88     {std::string(CodecMimeType::VIDEO_HEVC), "OMX.hisi.video.decoder.hevc"}};
89 
90 const std::map<std::string, std::string> CAPABILITY_ENCODER_HARD_NAME = {
91     {std::string(CodecMimeType::VIDEO_AVC), "OMX.hisi.video.encoder.avc"},
92     {std::string(CodecMimeType::VIDEO_HEVC), "OMX.hisi.video.encoder.hevc"}};
93 
94 const std::string DEFAULT_AUDIO_MIME = std::string(CodecMimeType::AUDIO_AAC);
95 const std::string DEFAULT_VIDEO_MIME = std::string(CodecMimeType::VIDEO_AVC);
96 const std::string DEFAULT_UNSUPPORTED_MIME = std::string(CodecMimeType::IMAGE_PNG);
97 constexpr int32_t MAX_SURPPORT_ACODEC = 16;
98 constexpr int32_t MAX_SURPPORT_VCODEC = 64;
99 
100 constexpr OH_AVRange DEFAULT_BITRATE_RANGE = {8000, 448000};
101 constexpr OH_AVRange DEFAULT_QUALITY_RANGE = {0, 0};
102 constexpr OH_AVRange DEFAULT_COMPLEXITY_RANGE = {0, 0};
103 constexpr OH_AVRange DEFAULT_CHANNELCOUNT_RANGE = {1, 8};
104 constexpr OH_AVRange DEFAULT_HEIGHT_RANGE_OF_WIDTH = {2, 4096};
105 constexpr OH_AVRange DEFAULT_WIDTH_RANGE_OF_HEIGHT = {2, 2304};
106 constexpr OH_AVRange DEFAULT_HEIGHT_RANGE = {2, 4096};
107 constexpr OH_AVRange DEFAULT_WIDTH_RANGE = {2, 4096};
108 constexpr OH_AVRange DEFAULT_HEIGHT_RANGE_ENC = {144, 4096};
109 constexpr OH_AVRange DEFAULT_WIDTH_RANGE_ENC = {144, 4096};
110 constexpr OH_AVRange DEFAULT_FRAMERATE_RANGE = {0, 120};
111 constexpr OH_AVRange DEFAULT_BITRATE_RANGE_ENC = {10000, 100000000};
112 constexpr OH_AVRange DEFAULT_VIDEO_QUALITY_RANGE = {0, 100};
113 
114 const std::vector<int32_t> DEFAULT_AUDIO_ACC_SAMPLES = {8000,  11025, 12000, 16000, 22050, 24000,
115                                                         32000, 44100, 48000, 64000, 88200, 96000};
116 const std::vector<int32_t> DEFAULT_VIDEO_AVC_PIXFORMATS = {
117     static_cast<int32_t>(VideoPixelFormat::YUVI420), static_cast<int32_t>(VideoPixelFormat::NV12),
118     static_cast<int32_t>(VideoPixelFormat::NV21), static_cast<int32_t>(VideoPixelFormat::RGBA)};
119 const std::vector<int32_t> DEFAULT_VIDEO_AVC_PROFILES = {AVC_PROFILE_BASELINE, AVC_PROFILE_HIGH, AVC_PROFILE_MAIN};
120 const std::vector<int32_t> DEFAULT_VIDEO_AVC_LEVELS = {
121     AVC_LEVEL_1, AVC_LEVEL_1b, AVC_LEVEL_11, AVC_LEVEL_12, AVC_LEVEL_13, AVC_LEVEL_2,  AVC_LEVEL_21, AVC_LEVEL_22,
122     AVC_LEVEL_3, AVC_LEVEL_31, AVC_LEVEL_32, AVC_LEVEL_4,  AVC_LEVEL_41, AVC_LEVEL_42, AVC_LEVEL_5,  AVC_LEVEL_51};
123 
124 constexpr int32_t DEFAULT_WIDTH_ALIGNMENT = 2;
125 constexpr int32_t DEFAULT_HEIGHT_ALIGNMENT = 2;
126 constexpr int32_t DEFAULT_ALIGNMENT_ENC = 4;
127 constexpr int32_t DEFAULT_BITRATEMODE_ENC = 3;
128 
129 constexpr int32_t DEFAULT_FRAMERATE = 1;
130 constexpr int32_t DEFAULT_WIDTH = 1920;
131 constexpr int32_t DEFAULT_HEIGHT = 1080;
132 constexpr int32_t DEFAULT_VIDEO_AVC_PROFILE = AVC_PROFILE_HIGH;
133 constexpr int32_t DEFAULT_LEVEL = AVC_LEVEL_1;
134 constexpr int32_t ERROR_FRAMERATE = 121;
135 constexpr int32_t ERROR_WIDTH = 95;
136 constexpr int32_t ERROR_HEIGHT = 95;
137 constexpr int32_t ERROR_VIDEO_AVC_PROFILE = -1;
138 constexpr int32_t ERROR_LEVEL = -1;
139 
140 constexpr uint32_t MAX_VIDEO_BITRATE = 300000000;
141 constexpr uint32_t MAX_AUDIO_BITRATE = 320000;
142 constexpr uint32_t MIN_AUDIO_BITRATE = 32000;
143 constexpr uint32_t MAX_AUDIO_BITRATE_AAC = 448000;
144 constexpr uint32_t DEFAULT_SAMPLE_RATE = 8000;
145 constexpr uint32_t DEFAULT_SAMPLE_RATE_SIZE = 12;
146 constexpr uint32_t MAX_CHANNEL_COUNT = 8;
147 constexpr uint32_t MAX_CHANNEL_COUNT_MP3 = 2;
148 constexpr int AUDIO_MIN_BIT_RATE_VIVID_DECODER = 16000;
149 constexpr int AUDIO_MAX_BIT_RATE_VIVID_DECODER = 3075000;
150 constexpr int AUDIO_MAX_CHANNEL_COUNT_VIVID = 16;
151 constexpr int AUDIO_SAMPLE_RATE_COUNT_VIVID = 5;
152 
153 constexpr int32_t STACK_BUF_OVERWRITE_MAX_BUF_SIZE = 100;
154 constexpr int32_t STACK_BUF_OVERWRITE_TIMES = 1000;
155 
156 const std::vector<std::string> videoDecoderList = {std::string(CodecMimeType::VIDEO_AVC)};
157 
158 const std::vector<std::string> videoEncoderList = {std::string(CodecMimeType::VIDEO_AVC)};
159 
160 const std::vector<std::string> audioDecoderList = {
161     std::string(CodecMimeType::AUDIO_MPEG), std::string(CodecMimeType::AUDIO_AAC),
162     std::string(CodecMimeType::AUDIO_VORBIS), std::string(CodecMimeType::AUDIO_FLAC)};
163 
164 const std::vector<std::string> audioEncoderList = {std::string(CodecMimeType::AUDIO_AAC)};
165 
166 const std::map<std::string, std::string> CAPABILITY_DECODER_HARD_NAME_VVC = {
167     {std::string(CodecMimeType::VIDEO_VVC), "OMX.hisi.video.decoder.vvc"}};
168 const std::string DEFAULT_VIDEO_VVC_MIME = std::string(CodecMimeType::VIDEO_VVC);
169 
170 constexpr int32_t MAX_SURPPORT_VCODEC_VVC = 4;
171 constexpr int32_t DEFAULT_WIDTH_VVC = 3840;
172 constexpr int32_t DEFAULT_HEIGHT_VVC = 2160;
173 constexpr int32_t DEFAULT_VIDEO_VVC_PROFILE = VVC_PROFILE_MULTI_MAIN_10_444;
174 constexpr int32_t DEFAULT_VIDEO_VVC_LEVEL = VVC_LEVEL_1;
175 constexpr int32_t ERROR_VIDEO_VVC_PROFILE = -1;
176 
177 constexpr OH_AVRange DEFAULT_HEIGHT_RANGE_VVC = {128, 3840};
178 constexpr OH_AVRange DEFAULT_WIDTH_RANGE_VVC = {128, 3840};
179 constexpr OH_AVRange DEFAULT_HEIGHT_RANGE_OF_WIDTH_VVC = {128, 2176};
180 constexpr OH_AVRange DEFAULT_WIDTH_RANGE_OF_HEIGHT_VVC = {128, 3840};
181 constexpr OH_AVRange DEFAULT_FRAMERATE_RANGE_VVC = {1, 240};
182 
183 const std::vector<int32_t> DEFAULT_VIDEO_VVC_PIXFORMATS = {
184     static_cast<int32_t>(VideoPixelFormat::NV12), static_cast<int32_t>(VideoPixelFormat::NV12),
185     static_cast<int32_t>(VideoPixelFormat::NV21), static_cast<int32_t>(VideoPixelFormat::NV21)};
186 const std::vector<int32_t> DEFAULT_VIDEO_VVC_PROFILES = {
187     VVC_PROFILE_MAIN_10, VVC_PROFILE_MULTI_MAIN_10,
188     VVC_PROFILE_MAIN_10_444, VVC_PROFILE_MULTI_MAIN_10_444,
189     VVC_PROFILE_MAIN_10_STILL, VVC_PROFILE_MAIN_10_444_STILL};
190 const std::vector<int32_t> DEFAULT_VIDEO_VVC_LEVELS = {
191     VVC_LEVEL_1, VVC_LEVEL_2, VVC_LEVEL_21, VVC_LEVEL_3, VVC_LEVEL_31,
192     VVC_LEVEL_4, VVC_LEVEL_41, VVC_LEVEL_5, VVC_LEVEL_51};
193 } // namespace CodecListTestParam
194 } // namespace MediaAVCodec
195 } // namespace OHOS
196 #endif // CODECLIST_MOCK_H