• 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") = 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     virtual std::vector<Range> GetAudioSupportedSampleRateRanges() = 0;
62 };
63 
64 class __attribute__((visibility("default"))) CodecListMockFactory {
65 public:
66     static std::shared_ptr<CodecListMock> GetCapability(const std::string &mime, bool isEncoder);
67     static std::shared_ptr<CodecListMock> GetCapabilityByCategory(const std::string &mime, bool isEncoder,
68                                                                   AVCodecCategory category);
69 
70 private:
71     CodecListMockFactory() = delete;
72     ~CodecListMockFactory() = delete;
73 };
74 
75 namespace CodecListTestParam {
76 const std::map<std::string, std::string> CAPABILITY_DECODER_NAME = {
77     {std::string(CodecMimeType::AUDIO_MPEG), std::string(AVCodecCodecName::AUDIO_DECODER_MP3_NAME)},
78     {std::string(CodecMimeType::AUDIO_AAC), std::string(AVCodecCodecName::AUDIO_DECODER_AAC_NAME)},
79     {std::string(CodecMimeType::AUDIO_VORBIS), std::string(AVCodecCodecName::AUDIO_DECODER_VORBIS_NAME)},
80     {std::string(CodecMimeType::AUDIO_FLAC), std::string(AVCodecCodecName::AUDIO_DECODER_FLAC_NAME)},
81     {std::string(CodecMimeType::VIDEO_AVC), std::string(AVCodecCodecName::VIDEO_DECODER_AVC_NAME)}};
82 
83 const std::map<std::string, std::string> CAPABILITY_ENCODER_NAME = {
84     {std::string(CodecMimeType::AUDIO_FLAC), std::string(AVCodecCodecName::AUDIO_ENCODER_FLAC_NAME)},
85     {std::string(CodecMimeType::AUDIO_AAC), std::string(AVCodecCodecName::AUDIO_ENCODER_AAC_NAME)}};
86 
87 const std::map<std::string, std::string> CAPABILITY_DECODER_HARD_NAME = {
88     {std::string(CodecMimeType::VIDEO_AVC), "OMX.hisi.video.decoder.avc"},
89     {std::string(CodecMimeType::VIDEO_HEVC), "OMX.hisi.video.decoder.hevc"}};
90 
91 const std::map<std::string, std::string> CAPABILITY_ENCODER_HARD_NAME = {
92     {std::string(CodecMimeType::VIDEO_AVC), "OMX.hisi.video.encoder.avc"},
93     {std::string(CodecMimeType::VIDEO_HEVC), "OMX.hisi.video.encoder.hevc"}};
94 
95 const std::string DEFAULT_AUDIO_MIME = std::string(CodecMimeType::AUDIO_AAC);
96 const std::string AUDIO_FLAC_MIME = std::string(CodecMimeType::AUDIO_FLAC);
97 const std::string DEFAULT_VIDEO_MIME = std::string(CodecMimeType::VIDEO_AVC);
98 const std::string DEFAULT_UNSUPPORTED_MIME = std::string(CodecMimeType::IMAGE_PNG);
99 constexpr int32_t MAX_SURPPORT_ACODEC = 16;
100 constexpr int32_t MAX_SURPPORT_VCODEC = 64;
101 
102 constexpr OH_AVRange DEFAULT_BITRATE_RANGE = {1, 500000};
103 constexpr OH_AVRange DEFAULT_QUALITY_RANGE = {0, 0};
104 constexpr OH_AVRange DEFAULT_COMPLEXITY_RANGE = {0, 0};
105 constexpr OH_AVRange DEFAULT_CHANNELCOUNT_RANGE = {1, 8};
106 constexpr OH_AVRange DEFAULT_HEIGHT_RANGE_OF_WIDTH = {2, 4096};
107 constexpr OH_AVRange DEFAULT_WIDTH_RANGE_OF_HEIGHT = {2, 2304};
108 constexpr OH_AVRange DEFAULT_HEIGHT_RANGE = {2, 4096};
109 constexpr OH_AVRange DEFAULT_WIDTH_RANGE = {2, 4096};
110 constexpr OH_AVRange DEFAULT_HEIGHT_RANGE_ENC = {144, 4096};
111 constexpr OH_AVRange DEFAULT_WIDTH_RANGE_ENC = {144, 4096};
112 constexpr OH_AVRange DEFAULT_FRAMERATE_RANGE = {0, 120};
113 constexpr OH_AVRange DEFAULT_BITRATE_RANGE_ENC = {10000, 100000000};
114 constexpr OH_AVRange DEFAULT_VIDEO_QUALITY_RANGE = {0, 100};
115 
116 const std::vector<int32_t> DEFAULT_AUDIO_ACC_SAMPLES = {7350, 8000,  11025, 12000, 16000, 22050, 24000,
117                                                         32000, 44100, 48000, 64000, 88200, 96000};
118 const std::vector<int32_t> DEFAULT_VIDEO_AVC_PIXFORMATS = {
119     static_cast<int32_t>(VideoPixelFormat::YUVI420), static_cast<int32_t>(VideoPixelFormat::NV12),
120     static_cast<int32_t>(VideoPixelFormat::NV21), static_cast<int32_t>(VideoPixelFormat::RGBA)};
121 const std::vector<int32_t> DEFAULT_VIDEO_AVC_PROFILES = {AVC_PROFILE_BASELINE, AVC_PROFILE_HIGH, AVC_PROFILE_MAIN};
122 const std::vector<int32_t> DEFAULT_VIDEO_AVC_LEVELS = {
123     AVC_LEVEL_1,  AVC_LEVEL_1b, AVC_LEVEL_11, AVC_LEVEL_12, AVC_LEVEL_13, AVC_LEVEL_2,  AVC_LEVEL_21,
124     AVC_LEVEL_22, AVC_LEVEL_3,  AVC_LEVEL_31, AVC_LEVEL_32, AVC_LEVEL_4,  AVC_LEVEL_41, AVC_LEVEL_42,
125     AVC_LEVEL_5,  AVC_LEVEL_51, AVC_LEVEL_52, AVC_LEVEL_6,  AVC_LEVEL_61, AVC_LEVEL_62};
126 
127 constexpr int32_t DEFAULT_WIDTH_ALIGNMENT = 2;
128 constexpr int32_t DEFAULT_HEIGHT_ALIGNMENT = 2;
129 constexpr int32_t DEFAULT_ALIGNMENT_ENC = 4;
130 constexpr int32_t DEFAULT_BITRATEMODE_ENC = 3;
131 
132 constexpr int32_t DEFAULT_FRAMERATE = 1;
133 constexpr int32_t DEFAULT_WIDTH = 1920;
134 constexpr int32_t DEFAULT_HEIGHT = 1080;
135 constexpr int32_t DEFAULT_VIDEO_AVC_PROFILE = AVC_PROFILE_HIGH;
136 constexpr int32_t DEFAULT_LEVEL = AVC_LEVEL_1;
137 constexpr int32_t ERROR_FRAMERATE = 121;
138 constexpr int32_t ERROR_WIDTH = 95;
139 constexpr int32_t ERROR_HEIGHT = 95;
140 constexpr int32_t ERROR_VIDEO_AVC_PROFILE = -1;
141 constexpr int32_t ERROR_LEVEL = -1;
142 
143 constexpr uint32_t MAX_VIDEO_BITRATE = 300000000;
144 constexpr uint32_t MAX_AUDIO_BITRATE = 320000;
145 constexpr uint32_t MIN_AUDIO_BITRATE = 32000;
146 constexpr uint32_t MAX_AUDIO_BITRATE_AAC = 500000;
147 constexpr uint32_t DEFAULT_SAMPLE_RATE = 8000;
148 constexpr uint32_t DEFAULT_SAMPLE_RATE_SIZE = 13;
149 constexpr uint32_t MAX_CHANNEL_COUNT = 8;
150 constexpr uint32_t MAX_CHANNEL_COUNT_MP3 = 2;
151 constexpr int AUDIO_MIN_BIT_RATE_VIVID_DECODER = 16000;
152 constexpr int AUDIO_MAX_BIT_RATE_VIVID_DECODER = 3075000;
153 constexpr int AUDIO_MAX_CHANNEL_COUNT_VIVID = 16;
154 constexpr int AUDIO_SAMPLE_RATE_COUNT_VIVID = 5;
155 
156 constexpr int32_t STACK_BUF_OVERWRITE_MAX_BUF_SIZE = 100;
157 constexpr int32_t STACK_BUF_OVERWRITE_TIMES = 1000;
158 
159 const std::vector<std::string> videoDecoderList = {std::string(CodecMimeType::VIDEO_AVC)};
160 
161 const std::vector<std::string> videoEncoderList = {std::string(CodecMimeType::VIDEO_AVC)};
162 
163 const std::vector<std::string> audioDecoderList = {
164     std::string(CodecMimeType::AUDIO_MPEG), std::string(CodecMimeType::AUDIO_AAC),
165     std::string(CodecMimeType::AUDIO_VORBIS), std::string(CodecMimeType::AUDIO_FLAC)};
166 
167 const std::vector<std::string> audioEncoderList = {std::string(CodecMimeType::AUDIO_AAC)};
168 
169 const std::map<std::string, std::string> CAPABILITY_DECODER_HARD_NAME_VVC = {
170     {std::string(CodecMimeType::VIDEO_VVC), "OMX.hisi.video.decoder.vvc"}};
171 const std::string DEFAULT_VIDEO_VVC_MIME = std::string(CodecMimeType::VIDEO_VVC);
172 
173 constexpr int32_t MAX_SURPPORT_VCODEC_VVC = 4;
174 constexpr int32_t DEFAULT_WIDTH_VVC = 4096;
175 constexpr int32_t DEFAULT_HEIGHT_VVC = 4096;
176 constexpr int32_t FRAME_RATE_WIDTH_VVC = 3840;
177 constexpr int32_t FRAME_RATE_HEIGHT_VVC = 2160;
178 
179 constexpr int32_t DEFAULT_VIDEO_VVC_PROFILE = VVC_PROFILE_MAIN_10_STILL;
180 constexpr int32_t DEFAULT_VIDEO_VVC_LEVEL = VVC_LEVEL_1;
181 constexpr int32_t ERROR_VIDEO_VVC_PROFILE = -1;
182 
183 constexpr OH_AVRange DEFAULT_HEIGHT_RANGE_VVC = {128, 4096};
184 constexpr OH_AVRange DEFAULT_WIDTH_RANGE_VVC = {128, 4096};
185 constexpr OH_AVRange DEFAULT_HEIGHT_RANGE_OF_WIDTH_VVC = {128, 4096};
186 constexpr OH_AVRange DEFAULT_WIDTH_RANGE_OF_HEIGHT_VVC = {128, 4096};
187 constexpr OH_AVRange DEFAULT_FRAMERATE_RANGE_VVC = {1, 240};
188 
189 const std::vector<int32_t> DEFAULT_VIDEO_VVC_PIXFORMATS = {
190     static_cast<int32_t>(VideoPixelFormat::NV12), static_cast<int32_t>(VideoPixelFormat::NV21)};
191 const std::vector<int32_t> DEFAULT_VIDEO_VVC_PROFILES = {
192     VVC_PROFILE_MAIN_10, VVC_PROFILE_MAIN_10_STILL};
193 const std::vector<int32_t> DEFAULT_VIDEO_VVC_LEVELS = {
194     VVC_LEVEL_1, VVC_LEVEL_2, VVC_LEVEL_21, VVC_LEVEL_3, VVC_LEVEL_31,
195     VVC_LEVEL_4, VVC_LEVEL_41, VVC_LEVEL_5};
196 
197 constexpr OH_AVRange AUDIO_FLAC_SAMPLE_RATE_RANGE = {8000, 384000};
198 } // namespace CodecListTestParam
199 } // namespace MediaAVCodec
200 } // namespace OHOS
201 #endif // CODECLIST_MOCK_H