• 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 };
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 constexpr int32_t MAX_SURPPORT_ACODEC = 16;
97 constexpr int32_t MAX_SURPPORT_VCODEC = 16;
98 
99 constexpr OH_AVRange DEFAULT_BITRATE_RANGE = {8000, 448000};
100 constexpr OH_AVRange DEFAULT_QUALITY_RANGE = {0, 0};
101 constexpr OH_AVRange DEFAULT_COMPLEXITY_RANGE = {0, 0};
102 constexpr OH_AVRange DEFAULT_CHANNELCOUNT_RANGE = {1, 8};
103 constexpr OH_AVRange DEFAULT_HEIGHT_RANGE_OF_WIDTH = {96, 4096};
104 constexpr OH_AVRange DEFAULT_WIDTH_RANGE_OF_HEIGHT = {96, 2304};
105 constexpr OH_AVRange DEFAULT_HEIGHT_RANGE = {96, 2304};
106 constexpr OH_AVRange DEFAULT_WIDTH_RANGE = {96, 4096};
107 constexpr OH_AVRange DEFAULT_HEIGHT_RANGE_ENC = {144, 2772};
108 constexpr OH_AVRange DEFAULT_WIDTH_RANGE_ENC = {176, 3840};
109 constexpr OH_AVRange DEFAULT_FRAMERATE_RANGE = {0, 120};
110 constexpr OH_AVRange DEFAULT_BITRATE_RANGE_ENC = {280000, 100000000};
111 
112 const std::vector<int32_t> DEFAULT_AUDIO_ACC_SAMPLES = {8000,  11025, 12000, 16000, 22050, 24000,
113                                                         32000, 44100, 48000, 64000, 88200, 96000};
114 const std::vector<int32_t> DEFAULT_VIDEO_AVC_PIXFORMATS = {
115     static_cast<int32_t>(VideoPixelFormat::YUVI420), static_cast<int32_t>(VideoPixelFormat::NV12),
116     static_cast<int32_t>(VideoPixelFormat::NV21), static_cast<int32_t>(VideoPixelFormat::RGBA)};
117 const std::vector<int32_t> DEFAULT_VIDEO_AVC_PROFILES = {AVC_PROFILE_BASELINE, AVC_PROFILE_HIGH, AVC_PROFILE_MAIN};
118 const std::vector<int32_t> DEFAULT_VIDEO_AVC_LEVELS = {
119     AVC_LEVEL_1, AVC_LEVEL_1b, AVC_LEVEL_11, AVC_LEVEL_12, AVC_LEVEL_13, AVC_LEVEL_2,  AVC_LEVEL_21, AVC_LEVEL_22,
120     AVC_LEVEL_3, AVC_LEVEL_31, AVC_LEVEL_32, AVC_LEVEL_4,  AVC_LEVEL_41, AVC_LEVEL_42, AVC_LEVEL_5,  AVC_LEVEL_51};
121 
122 constexpr int32_t DEFAULT_WIDTH_ALIGNMENT = 2;
123 constexpr int32_t DEFAULT_HEIGHT_ALIGNMENT = 2;
124 constexpr int32_t DEFAULT_ALIGNMENT_ENC = 4;
125 constexpr int32_t DEFAULT_BITRATEMODE_ENC = 2;
126 
127 constexpr int32_t DEFAULT_FRAMERATE = 1;
128 constexpr int32_t DEFAULT_WIDTH = 1920;
129 constexpr int32_t DEFAULT_HEIGHT = 1080;
130 constexpr int32_t DEFAULT_VIDEO_AVC_PROFILE = AVC_PROFILE_HIGH;
131 constexpr int32_t DEFAULT_LEVEL = AVC_LEVEL_1;
132 constexpr int32_t ERROR_FRAMERATE = 121;
133 constexpr int32_t ERROR_WIDTH = 95;
134 constexpr int32_t ERROR_HEIGHT = 95;
135 constexpr int32_t ERROR_VIDEO_AVC_PROFILE = -1;
136 constexpr int32_t ERROR_LEVEL = -1;
137 
138 constexpr uint32_t MAX_VIDEO_BITRATE = 300000000;
139 constexpr uint32_t MAX_AUDIO_BITRATE = 320000;
140 constexpr uint32_t MIN_AUDIO_BITRATE = 32000;
141 constexpr uint32_t MAX_AUDIO_BITRATE_AAC = 448000;
142 constexpr uint32_t DEFAULT_SAMPLE_RATE = 8000;
143 constexpr uint32_t DEFAULT_SAMPLE_RATE_SIZE = 12;
144 constexpr uint32_t MAX_CHANNEL_COUNT = 8;
145 constexpr uint32_t MAX_CHANNEL_COUNT_MP3 = 2;
146 constexpr int AUDIO_MIN_BIT_RATE_VIVID_DECODER = 16000;
147 constexpr int AUDIO_MAX_BIT_RATE_VIVID_DECODER = 3075000;
148 constexpr int AUDIO_MAX_CHANNEL_COUNT_VIVID = 16;
149 constexpr int AUDIO_SAMPLE_RATE_COUNT_VIVID = 5;
150 
151 constexpr int32_t STACK_BUF_OVERWRITE_MAX_BUF_SIZE = 100;
152 constexpr int32_t STACK_BUF_OVERWRITE_TIMES = 1000;
153 
154 const std::vector<std::string> videoDecoderList = {std::string(CodecMimeType::VIDEO_AVC)};
155 
156 const std::vector<std::string> videoEncoderList = {std::string(CodecMimeType::VIDEO_AVC)};
157 
158 const std::vector<std::string> audioDecoderList = {
159     std::string(CodecMimeType::AUDIO_MPEG), std::string(CodecMimeType::AUDIO_AAC),
160     std::string(CodecMimeType::AUDIO_VORBIS), std::string(CodecMimeType::AUDIO_FLAC)};
161 
162 const std::vector<std::string> audioEncoderList = {std::string(CodecMimeType::AUDIO_AAC)};
163 } // namespace CodecListTestParam
164 } // namespace MediaAVCodec
165 } // namespace OHOS
166 #endif // CODECLIST_MOCK_H