• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #include "gtest/gtest.h"
17 #include "media_errors.h"
18 #include "avcodec_list_unit_test.h"
19 
20 using namespace std;
21 using namespace OHOS;
22 using namespace OHOS::Media;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Media {
SetUpTestCase(void)27 void AVCodecListUnitTest::SetUpTestCase(void) {}
28 
TearDownTestCase(void)29 void AVCodecListUnitTest::TearDownTestCase(void) {}
30 
SetUp(void)31 void AVCodecListUnitTest::SetUp(void)
32 {
33     avCodecList_ = AVCodecMockFactory::CreateAVCodecList();
34     ASSERT_NE(nullptr, avCodecList_);
35     enum_ = AVCodecMockFactory::CreateEnum();
36     ASSERT_NE(nullptr, enum_);
37     codecMimeKey_ = enum_->GetMediaDescriptionKey(MediaDescriptionKeyMock::MOCK_MD_KEY_CODEC_MIME);
38     bitrateKey_ = enum_->GetMediaDescriptionKey(MediaDescriptionKeyMock::MOCK_MD_KEY_BITRATE);
39     widthKey_ = enum_->GetMediaDescriptionKey(MediaDescriptionKeyMock::MOCK_MD_KEY_WIDTH);
40     heightKey_ = enum_->GetMediaDescriptionKey(MediaDescriptionKeyMock::MOCK_MD_KEY_HEIGHT);
41     pixelFormatKey_ = enum_->GetMediaDescriptionKey(MediaDescriptionKeyMock::MOCK_MD_KEY_PIXEL_FORMAT);
42     frameRateKey_ = enum_->GetMediaDescriptionKey(MediaDescriptionKeyMock::MOCK_MD_KEY_FRAME_RATE);
43     channelCountKey_ = enum_->GetMediaDescriptionKey(MediaDescriptionKeyMock::MOCK_MD_KEY_CHANNEL_COUNT);
44     sampleRateKey_ = enum_->GetMediaDescriptionKey(MediaDescriptionKeyMock::MOCK_MD_KEY_SAMPLE_RATE);
45 }
46 
TearDown(void)47 void AVCodecListUnitTest::TearDown(void)
48 {
49 }
50 
51 /**
52  * @tc.name: AVCdecList_FindVideoDecoder_0100
53  * @tc.desc: AVCdecList FindVideoDecoder
54  * @tc.type: FUNC
55  * @tc.require:
56  */
57 HWTEST_F(AVCodecListUnitTest, AVCdecList_FindVideoDecoder_0100, TestSize.Level0)
58 {
59     std::string codecName;
60     std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
61     ASSERT_NE(nullptr, format);
62     (void)format->PutStringValue(codecMimeKey_, enum_->GetCodecMimeType(CodecMimeTypeMock::VIDEO_AVC));
63     (void)format->PutIntValue(bitrateKey_, MAX_VIDEO_BITRATE);
64     (void)format->PutIntValue(widthKey_, DEFAULT_WIDTH);
65     (void)format->PutIntValue(heightKey_, DEFAULT_HEIGHT);
66     (void)format->PutIntValue(pixelFormatKey_, enum_->GetVideoPixelFormat(VideoPixelFormatMock::MOCK_NV12));
67     (void)format->PutIntValue(frameRateKey_, MAX_FRAME_RATE);
68     codecName = avCodecList_->FindVideoDecoder(format);
69     EXPECT_NE("", codecName);
70 }
71 
72 /**
73  * @tc.name: AVCdecList_FindVideoEncoder_0100
74  * @tc.desc: AVCdecList FindVideoEncoder
75  * @tc.type: FUNC
76  * @tc.require:
77  */
78 HWTEST_F(AVCodecListUnitTest, AVCdecList_FindVideoEncoder_0100, TestSize.Level0)
79 {
80     std::string codecName;
81     std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
82     (void)format->PutStringValue(codecMimeKey_, enum_->GetCodecMimeType(CodecMimeTypeMock::VIDEO_MPEG4));
83     (void)format->PutIntValue(bitrateKey_, MAX_VIDEO_BITRATE);
84     (void)format->PutIntValue(widthKey_, DEFAULT_WIDTH);
85     (void)format->PutIntValue(heightKey_, DEFAULT_HEIGHT);
86     (void)format->PutIntValue(pixelFormatKey_, enum_->GetVideoPixelFormat(VideoPixelFormatMock::MOCK_NV21));
87     (void)format->PutIntValue(frameRateKey_, MAX_FRAME_RATE);
88     codecName = avCodecList_->FindVideoEncoder(format);
89     EXPECT_NE("", codecName);
90 }
91 
92 /**
93  * @tc.name: AVCdecList_FindAudioDecoder_0100
94  * @tc.desc: AVCdecList FindAudioDecoder
95  * @tc.type: FUNC
96  * @tc.require:
97  */
98 HWTEST_F(AVCodecListUnitTest, AVCdecList_FindAudioDecoder_0100, TestSize.Level0)
99 {
100     std::string codecName;
101     std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
102     (void)format->PutStringValue(codecMimeKey_, enum_->GetCodecMimeType(CodecMimeTypeMock::AUDIO_MPEG));
103     (void)format->PutIntValue(bitrateKey_, MAX_AUDIO_BITRATE);
104     (void)format->PutIntValue(channelCountKey_, MAX_CHANNEL_COUNT);
105     (void)format->PutIntValue(sampleRateKey_, DEFAULT_SAMPLE_RATE);
106     codecName = avCodecList_->FindAudioDecoder(format);
107     EXPECT_EQ("avdec_mp3", codecName);
108 }
109 
110 /**
111  * @tc.name: AVCdecList_FindAudioEncoder_0100
112  * @tc.desc: AVCdecList FindAudioEncoder
113  * @tc.type: FUNC
114  * @tc.require:
115  */
116 HWTEST_F(AVCodecListUnitTest, AVCdecList_FindAudioEncoder_0100, TestSize.Level0)
117 {
118     std::string codecName;
119     std::shared_ptr<FormatMock> format = AVCodecMockFactory::CreateFormat();
120     (void)format->PutStringValue(codecMimeKey_, enum_->GetCodecMimeType(CodecMimeTypeMock::AUDIO_AAC));
121     (void)format->PutIntValue(bitrateKey_, MAX_AUDIO_BITRATE);
122     (void)format->PutIntValue(channelCountKey_, MAX_CHANNEL_COUNT);
123     (void)format->PutIntValue(sampleRateKey_, DEFAULT_SAMPLE_RATE);
124     codecName = avCodecList_->FindAudioEncoder(format);
125     EXPECT_EQ("avenc_aac", codecName);
126 }
127 
CheckVideoCapsArray(const std::vector<std::shared_ptr<VideoCapsMock>> & videoCapsArray) const128 void AVCodecListUnitTest::CheckVideoCapsArray(const std::vector<std::shared_ptr<VideoCapsMock>> &videoCapsArray) const
129 {
130     for (auto iter = videoCapsArray.begin(); iter != videoCapsArray.end(); iter++) {
131         std::shared_ptr<VideoCapsMock> pVideoCaps = *iter;
132         if (pVideoCaps == nullptr) {
133             cout << "pVideoCaps is nullptr" << endl;
134             break;
135         }
136         CheckVideoCaps(pVideoCaps);
137     }
138 }
139 
CheckVideoCaps(const std::shared_ptr<VideoCapsMock> & videoCaps) const140 void AVCodecListUnitTest::CheckVideoCaps(const std::shared_ptr<VideoCapsMock> &videoCaps) const
141 {
142     std::shared_ptr<AVCodecInfoMock> videoCodecCaps;
143     videoCodecCaps = videoCaps->GetCodecInfo();
144     std::string codecName = videoCodecCaps->GetName();
145     cout << "codecName is : " << codecName << endl;
146     if (codecName.compare("avdec_h264") == 0) {
147         CheckAVDecH264(videoCaps);
148     } else if (codecName.compare("avdec_h263") == 0) {
149         CheckAVDecH263(videoCaps);
150     } else if (codecName.compare("avdec_mpeg2video") == 0) {
151         CheckAVDecMpeg2Video(videoCaps);
152     } else if (codecName.compare("avdec_mpeg4") == 0) {
153         CheckAVDecMpeg4(videoCaps);
154     } else if (codecName.compare("avenc_mpeg4") == 0) {
155         CheckAVEncMpeg4(videoCaps);
156     }
157 }
158 
CheckAVDecH264(const std::shared_ptr<VideoCapsMock> & videoCaps) const159 void AVCodecListUnitTest::CheckAVDecH264(const std::shared_ptr<VideoCapsMock> &videoCaps) const
160 {
161     std::shared_ptr<AVCodecInfoMock> videoCodecCaps = videoCaps->GetCodecInfo();
162     EXPECT_EQ(AVCODEC_TYPE_MOCK_VIDEO_DECODER, videoCodecCaps->GetType());
163     EXPECT_EQ(enum_->GetCodecMimeType(CodecMimeTypeMock::VIDEO_AVC), videoCodecCaps->GetMimeType());
164     EXPECT_EQ(0, videoCodecCaps->IsHardwareAccelerated());
165     EXPECT_EQ(1, videoCodecCaps->IsSoftwareOnly());
166     EXPECT_EQ(0, videoCodecCaps->IsVendor());
167     EXPECT_EQ(1, videoCaps->GetSupportedBitrate().minVal);
168     EXPECT_EQ(MAX_VIDEO_BITRATE, videoCaps->GetSupportedBitrate().maxVal);
169     EXPECT_EQ(0, videoCaps->GetSupportedWidthAlignment());
170     EXPECT_EQ(MIN_WIDTH, videoCaps->GetSupportedWidth().minVal);
171     EXPECT_EQ(MAX_WIDTH, videoCaps->GetSupportedWidth().maxVal);
172     EXPECT_EQ(MIN_HEIGHT, videoCaps->GetSupportedHeight().minVal);
173     EXPECT_EQ(MAX_HEIGHT, videoCaps->GetSupportedHeight().maxVal);
174     EXPECT_EQ(1, videoCaps->GetSupportedFrameRate().minVal);
175     EXPECT_EQ(MAX_FRAME_RATE, videoCaps->GetSupportedFrameRate().maxVal);
176     EXPECT_EQ(0, videoCaps->GetSupportedEncodeQuality().minVal);
177     EXPECT_EQ(0, videoCaps->GetSupportedEncodeQuality().maxVal);
178     EXPECT_EQ(0, videoCaps->GetSupportedQuality().minVal);
179     EXPECT_EQ(0, videoCaps->GetSupportedQuality().maxVal);
180     EXPECT_EQ(0, videoCaps->GetSupportedComplexity().minVal);
181     EXPECT_EQ(0, videoCaps->GetSupportedComplexity().maxVal);
182     EXPECT_EQ(2, videoCaps->GetSupportedFormats().size()); // 2: supported formats count
183     EXPECT_EQ(3, videoCaps->GetSupportedProfiles().size()); // 3: supported profile count
184     EXPECT_EQ(0, videoCaps->GetSupportedBitrateMode().size());
185     EXPECT_EQ(0, videoCaps->GetSupportedLevels().size());
186     EXPECT_EQ(false, videoCaps->IsSupportDynamicIframe());
187     EXPECT_EQ(true, videoCaps->IsSizeSupported(videoCaps->GetSupportedWidth().minVal,
188         videoCaps->GetSupportedHeight().maxVal));
189 }
190 
CheckAVDecH263(const std::shared_ptr<VideoCapsMock> & videoCaps) const191 void AVCodecListUnitTest::CheckAVDecH263(const std::shared_ptr<VideoCapsMock> &videoCaps) const
192 {
193     std::shared_ptr<AVCodecInfoMock> videoCodecCaps = videoCaps->GetCodecInfo();
194     EXPECT_EQ(AVCODEC_TYPE_MOCK_VIDEO_DECODER, videoCodecCaps->GetType());
195     EXPECT_EQ(enum_->GetCodecMimeType(CodecMimeTypeMock::VIDEO_H263), videoCodecCaps->GetMimeType());
196     EXPECT_EQ(0, videoCodecCaps->IsHardwareAccelerated());
197     EXPECT_EQ(1, videoCodecCaps->IsSoftwareOnly());
198     EXPECT_EQ(0, videoCodecCaps->IsVendor());
199     EXPECT_EQ(1, videoCaps->GetSupportedBitrate().minVal);
200     EXPECT_EQ(MAX_VIDEO_BITRATE, videoCaps->GetSupportedBitrate().maxVal);
201     EXPECT_EQ(0, videoCaps->GetSupportedWidthAlignment());
202     EXPECT_EQ(0, videoCaps->GetSupportedHeightAlignment());
203     EXPECT_EQ(MIN_WIDTH, videoCaps->GetSupportedWidth().minVal);
204     EXPECT_EQ(MAX_WIDTH, videoCaps->GetSupportedWidth().maxVal);
205     EXPECT_EQ(MIN_HEIGHT, videoCaps->GetSupportedHeight().minVal);
206     EXPECT_EQ(MAX_HEIGHT, videoCaps->GetSupportedHeight().maxVal);
207     EXPECT_EQ(1, videoCaps->GetSupportedFrameRate().minVal);
208     EXPECT_EQ(MAX_FRAME_RATE, videoCaps->GetSupportedFrameRate().maxVal);
209     EXPECT_EQ(0, videoCaps->GetSupportedEncodeQuality().minVal);
210     EXPECT_EQ(0, videoCaps->GetSupportedEncodeQuality().maxVal);
211     EXPECT_EQ(0, videoCaps->GetSupportedQuality().minVal);
212     EXPECT_EQ(0, videoCaps->GetSupportedQuality().maxVal);
213     EXPECT_EQ(0, videoCaps->GetSupportedComplexity().minVal);
214     EXPECT_EQ(0, videoCaps->GetSupportedComplexity().maxVal);
215     EXPECT_EQ(2, videoCaps->GetSupportedFormats().size()); // 2: supported formats count
216     EXPECT_EQ(1, videoCaps->GetSupportedProfiles().size());
217     EXPECT_EQ(0, videoCaps->GetSupportedBitrateMode().size());
218     EXPECT_EQ(0, videoCaps->GetSupportedLevels().size());
219     EXPECT_EQ(false, videoCaps->IsSupportDynamicIframe());
220     EXPECT_EQ(false, videoCaps->IsSizeSupported(videoCaps->GetSupportedWidth().minVal - 1,
221         videoCaps->GetSupportedHeight().maxVal));
222 }
223 
CheckAVDecMpeg2Video(const std::shared_ptr<VideoCapsMock> & videoCaps) const224 void AVCodecListUnitTest::CheckAVDecMpeg2Video(const std::shared_ptr<VideoCapsMock> &videoCaps) const
225 {
226     std::shared_ptr<AVCodecInfoMock> videoCodecCaps = videoCaps->GetCodecInfo();
227     EXPECT_EQ(AVCODEC_TYPE_MOCK_VIDEO_DECODER, videoCodecCaps->GetType());
228     EXPECT_EQ(enum_->GetCodecMimeType(CodecMimeTypeMock::VIDEO_MPEG2), videoCodecCaps->GetMimeType());
229     EXPECT_EQ(0, videoCodecCaps->IsHardwareAccelerated());
230     EXPECT_EQ(1, videoCodecCaps->IsSoftwareOnly());
231     EXPECT_EQ(0, videoCodecCaps->IsVendor());
232     EXPECT_EQ(1, videoCaps->GetSupportedBitrate().minVal);
233     EXPECT_EQ(MAX_VIDEO_BITRATE, videoCaps->GetSupportedBitrate().maxVal);
234     EXPECT_EQ(0, videoCaps->GetSupportedWidthAlignment());
235     EXPECT_EQ(0, videoCaps->GetSupportedHeightAlignment());
236     EXPECT_EQ(MIN_WIDTH, videoCaps->GetSupportedWidth().minVal);
237     EXPECT_EQ(MAX_WIDTH, videoCaps->GetSupportedWidth().maxVal);
238     EXPECT_EQ(MIN_HEIGHT, videoCaps->GetSupportedHeight().minVal);
239     EXPECT_EQ(MAX_HEIGHT, videoCaps->GetSupportedHeight().maxVal);
240     EXPECT_EQ(1, videoCaps->GetSupportedFrameRate().minVal);
241     EXPECT_EQ(MAX_FRAME_RATE, videoCaps->GetSupportedFrameRate().maxVal);
242     EXPECT_EQ(0, videoCaps->GetSupportedEncodeQuality().minVal);
243     EXPECT_EQ(0, videoCaps->GetSupportedEncodeQuality().maxVal);
244     EXPECT_EQ(0, videoCaps->GetSupportedQuality().minVal);
245     EXPECT_EQ(0, videoCaps->GetSupportedQuality().maxVal);
246     EXPECT_EQ(0, videoCaps->GetSupportedComplexity().minVal);
247     EXPECT_EQ(0, videoCaps->GetSupportedComplexity().maxVal);
248     EXPECT_EQ(2, videoCaps->GetSupportedFormats().size()); // 2: supported formats count
249     EXPECT_EQ(2, videoCaps->GetSupportedProfiles().size()); // 2: supported profile count
250     EXPECT_EQ(0, videoCaps->GetSupportedBitrateMode().size());
251     EXPECT_EQ(0, videoCaps->GetSupportedLevels().size());
252     EXPECT_EQ(false, videoCaps->IsSupportDynamicIframe());
253     EXPECT_EQ(0, videoCaps->IsSizeAndRateSupported(videoCaps->GetSupportedWidth().minVal,
254         videoCaps->GetSupportedHeight().maxVal, videoCaps->GetSupportedFrameRate().maxVal));
255     EXPECT_EQ(false, videoCaps->IsSizeAndRateSupported(videoCaps->GetSupportedWidth().minVal-1,
256         videoCaps->GetSupportedHeight().maxVal + 1, videoCaps->GetSupportedFrameRate().maxVal));
257 }
258 
CheckAVDecMpeg4(const std::shared_ptr<VideoCapsMock> & videoCaps) const259 void AVCodecListUnitTest::CheckAVDecMpeg4(const std::shared_ptr<VideoCapsMock> &videoCaps) const
260 {
261     std::shared_ptr<AVCodecInfoMock> videoCodecCaps = videoCaps->GetCodecInfo();
262     EXPECT_EQ(AVCODEC_TYPE_MOCK_VIDEO_DECODER, videoCodecCaps->GetType());
263     EXPECT_EQ(enum_->GetCodecMimeType(CodecMimeTypeMock::VIDEO_MPEG4), videoCodecCaps->GetMimeType());
264     EXPECT_EQ(0, videoCodecCaps->IsHardwareAccelerated());
265     EXPECT_EQ(1, videoCodecCaps->IsSoftwareOnly());
266     EXPECT_EQ(0, videoCodecCaps->IsVendor());
267     EXPECT_EQ(1, videoCaps->GetSupportedBitrate().minVal);
268     EXPECT_EQ(MAX_VIDEO_BITRATE, videoCaps->GetSupportedBitrate().maxVal);
269     EXPECT_EQ(0, videoCaps->GetSupportedWidthAlignment());
270     EXPECT_EQ(0, videoCaps->GetSupportedHeightAlignment());
271     EXPECT_EQ(MIN_WIDTH, videoCaps->GetSupportedWidth().minVal);
272     EXPECT_EQ(MAX_WIDTH, videoCaps->GetSupportedWidth().maxVal);
273     EXPECT_EQ(MIN_HEIGHT, videoCaps->GetSupportedHeight().minVal);
274     EXPECT_EQ(MAX_HEIGHT, videoCaps->GetSupportedHeight().maxVal);
275     EXPECT_EQ(1, videoCaps->GetSupportedFrameRate().minVal);
276     EXPECT_EQ(MAX_FRAME_RATE, videoCaps->GetSupportedFrameRate().maxVal);
277     EXPECT_EQ(0, videoCaps->GetSupportedEncodeQuality().minVal);
278     EXPECT_EQ(0, videoCaps->GetSupportedEncodeQuality().maxVal);
279     EXPECT_EQ(0, videoCaps->GetSupportedQuality().minVal);
280     EXPECT_EQ(0, videoCaps->GetSupportedQuality().maxVal);
281     EXPECT_EQ(0, videoCaps->GetSupportedComplexity().minVal);
282     EXPECT_EQ(0, videoCaps->GetSupportedComplexity().maxVal);
283     EXPECT_EQ(2, videoCaps->GetSupportedFormats().size()); // 2: supported formats count
284     EXPECT_EQ(2, videoCaps->GetSupportedProfiles().size()); // 2: supported profile count
285     EXPECT_EQ(0, videoCaps->GetSupportedBitrateMode().size());
286     EXPECT_EQ(0, videoCaps->GetSupportedLevels().size());
287     EXPECT_EQ(false, videoCaps->IsSupportDynamicIframe());
288     EXPECT_EQ(false, videoCaps->IsSizeAndRateSupported(videoCaps->GetSupportedWidth().minVal,
289         videoCaps->GetSupportedHeight().maxVal, videoCaps->GetSupportedFrameRate().maxVal + 1));
290 }
291 
CheckAVEncMpeg4(const std::shared_ptr<VideoCapsMock> & videoCaps) const292 void AVCodecListUnitTest::CheckAVEncMpeg4(const std::shared_ptr<VideoCapsMock> &videoCaps) const
293 {
294     std::shared_ptr<AVCodecInfoMock> videoCodecCaps = videoCaps->GetCodecInfo();
295     EXPECT_EQ(AVCODEC_TYPE_MOCK_VIDEO_ENCODER, videoCodecCaps->GetType());
296     EXPECT_EQ(enum_->GetCodecMimeType(CodecMimeTypeMock::VIDEO_MPEG4), videoCodecCaps->GetMimeType());
297     EXPECT_EQ(0, videoCodecCaps->IsHardwareAccelerated());
298     EXPECT_EQ(1, videoCodecCaps->IsSoftwareOnly());
299     EXPECT_EQ(0, videoCodecCaps->IsVendor());
300     EXPECT_EQ(1, videoCaps->GetSupportedBitrate().minVal);
301     EXPECT_EQ(MAX_VIDEO_BITRATE, videoCaps->GetSupportedBitrate().maxVal);
302     EXPECT_EQ(0, videoCaps->GetSupportedWidthAlignment());
303     EXPECT_EQ(0, videoCaps->GetSupportedHeightAlignment());
304     EXPECT_EQ(MIN_WIDTH, videoCaps->GetSupportedWidth().minVal);
305     EXPECT_EQ(DEFAULT_WIDTH, videoCaps->GetSupportedWidth().maxVal);
306     EXPECT_EQ(MIN_HEIGHT, videoCaps->GetSupportedHeight().minVal);
307     EXPECT_EQ(DEFAULT_HEIGHT, videoCaps->GetSupportedHeight().maxVal);
308     EXPECT_EQ(1, videoCaps->GetSupportedFrameRate().minVal);
309     EXPECT_EQ(MAX_FRAME_RATE, videoCaps->GetSupportedFrameRate().maxVal);
310     EXPECT_EQ(0, videoCaps->GetSupportedEncodeQuality().minVal);
311     EXPECT_EQ(0, videoCaps->GetSupportedEncodeQuality().maxVal);
312     EXPECT_EQ(0, videoCaps->GetSupportedQuality().minVal);
313     EXPECT_EQ(0, videoCaps->GetSupportedQuality().maxVal);
314     EXPECT_EQ(0, videoCaps->GetSupportedComplexity().minVal);
315     EXPECT_EQ(0, videoCaps->GetSupportedComplexity().maxVal);
316     EXPECT_EQ(2, videoCaps->GetSupportedFormats().size()); // 2: supported formats count
317     EXPECT_EQ(2, videoCaps->GetSupportedProfiles().size()); // 2: supported profile count
318     EXPECT_EQ(2, videoCaps->GetSupportedBitrateMode().size()); // 2: supported bitretemode count
319     EXPECT_EQ(0, videoCaps->GetSupportedLevels().size());
320     EXPECT_EQ(false, videoCaps->IsSupportDynamicIframe());
321 }
322 
CheckAudioCapsArray(const std::vector<std::shared_ptr<AudioCapsMock>> & audioCapsArray) const323 void AVCodecListUnitTest::CheckAudioCapsArray(const std::vector<std::shared_ptr<AudioCapsMock>> &audioCapsArray) const
324 {
325     for (auto iter = audioCapsArray.begin(); iter != audioCapsArray.end(); iter++) {
326         std::shared_ptr<AudioCapsMock> pAudioCaps = *iter;
327         if (pAudioCaps == nullptr) {
328             cout << "pAudioCaps is nullptr" << endl;
329             break;
330         }
331         CheckAudioCaps(pAudioCaps);
332     }
333 }
334 
CheckAudioCaps(const std::shared_ptr<AudioCapsMock> & audioCaps) const335 void AVCodecListUnitTest::CheckAudioCaps(const std::shared_ptr<AudioCapsMock> &audioCaps) const
336 {
337     std::shared_ptr<AVCodecInfoMock> audioCodecCaps;
338     audioCodecCaps = audioCaps->GetCodecInfo();
339     std::string codecName = audioCodecCaps->GetName();
340     if (codecName.compare("avdec_mp3") == 0) {
341         CheckAVDecMP3(audioCaps);
342     } else if (codecName.compare("avdec_aac") == 0) {
343         CheckAVDecAAC(audioCaps);
344     } else if (codecName.compare("avdec_vorbis") == 0) {
345         CheckAVDecVorbis(audioCaps);
346     } else if (codecName.compare("avdec_flac") == 0) {
347         CheckAVDecFlac(audioCaps);
348     } else if (codecName.compare("avdec_opus") == 0) {
349         CheckAVDecOpus(audioCaps);
350     } else if (codecName.compare("avenc_aac") == 0) {
351         CheckAVEncAAC(audioCaps);
352     } else if (codecName.compare("avenc_opus") == 0) {
353         CheckAVEncOpus(audioCaps);
354     }
355 }
356 
CheckAVDecMP3(const std::shared_ptr<AudioCapsMock> & audioCaps) const357 void AVCodecListUnitTest::CheckAVDecMP3(const std::shared_ptr<AudioCapsMock> &audioCaps) const
358 {
359     std::shared_ptr<AVCodecInfoMock> audioCodecCaps = audioCaps->GetCodecInfo();
360     EXPECT_EQ(AVCODEC_TYPE_MOCK_AUDIO_DECODER, audioCodecCaps->GetType());
361     EXPECT_EQ(enum_->GetCodecMimeType(CodecMimeTypeMock::AUDIO_MPEG), audioCodecCaps->GetMimeType());
362     EXPECT_EQ(0, audioCodecCaps->IsHardwareAccelerated());
363     EXPECT_EQ(1, audioCodecCaps->IsSoftwareOnly());
364     EXPECT_EQ(0, audioCodecCaps->IsVendor());
365     EXPECT_EQ(1, audioCaps->GetSupportedBitrate().minVal);
366     EXPECT_EQ(MAX_AUDIO_BITRATE, audioCaps->GetSupportedBitrate().maxVal);
367     EXPECT_EQ(1, audioCaps->GetSupportedChannel().minVal);
368     EXPECT_EQ(MAX_CHANNEL_COUNT, audioCaps->GetSupportedChannel().maxVal);
369     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().minVal);
370     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().maxVal);
371     EXPECT_EQ(1, audioCaps->GetSupportedFormats().size());
372     EXPECT_EQ(12, audioCaps->GetSupportedSampleRates().size()); // 12: supported samplerate count
373     EXPECT_EQ(0, audioCaps->GetSupportedProfiles().size());
374     EXPECT_EQ(0, audioCaps->GetSupportedLevels().size());
375 }
376 
CheckAVDecAAC(const std::shared_ptr<AudioCapsMock> & audioCaps) const377 void AVCodecListUnitTest::CheckAVDecAAC(const std::shared_ptr<AudioCapsMock> &audioCaps) const
378 {
379     std::shared_ptr<AVCodecInfoMock> audioCodecCaps = audioCaps->GetCodecInfo();
380     EXPECT_EQ(AVCODEC_TYPE_MOCK_AUDIO_DECODER, audioCodecCaps->GetType());
381     EXPECT_EQ(enum_->GetCodecMimeType(CodecMimeTypeMock::AUDIO_AAC), audioCodecCaps->GetMimeType());
382     EXPECT_EQ(0, audioCodecCaps->IsHardwareAccelerated());
383     EXPECT_EQ(1, audioCodecCaps->IsSoftwareOnly());
384     EXPECT_EQ(0, audioCodecCaps->IsVendor());
385     EXPECT_EQ(1, audioCaps->GetSupportedBitrate().minVal);
386     EXPECT_EQ(MAX_AUDIO_BITRATE, audioCaps->GetSupportedBitrate().maxVal);
387     EXPECT_EQ(1, audioCaps->GetSupportedChannel().minVal);
388     EXPECT_EQ(MAX_CHANNEL_COUNT, audioCaps->GetSupportedChannel().maxVal);
389     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().minVal);
390     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().maxVal);
391     EXPECT_EQ(1, audioCaps->GetSupportedFormats().size());
392     EXPECT_EQ(12, audioCaps->GetSupportedSampleRates().size()); // 12: supported samplerate count
393     EXPECT_EQ(1, audioCaps->GetSupportedProfiles().size());
394     EXPECT_EQ(0, audioCaps->GetSupportedLevels().size());
395 }
396 
CheckAVDecVorbis(const std::shared_ptr<AudioCapsMock> & audioCaps) const397 void AVCodecListUnitTest::CheckAVDecVorbis(const std::shared_ptr<AudioCapsMock> &audioCaps) const
398 {
399     std::shared_ptr<AVCodecInfoMock> audioCodecCaps = audioCaps->GetCodecInfo();
400     EXPECT_EQ(AVCODEC_TYPE_MOCK_AUDIO_DECODER, audioCodecCaps->GetType());
401     EXPECT_EQ(enum_->GetCodecMimeType(CodecMimeTypeMock::AUDIO_VORBIS), audioCodecCaps->GetMimeType());
402     EXPECT_EQ(0, audioCodecCaps->IsHardwareAccelerated());
403     EXPECT_EQ(1, audioCodecCaps->IsSoftwareOnly());
404     EXPECT_EQ(0, audioCodecCaps->IsVendor());
405     EXPECT_EQ(1, audioCaps->GetSupportedBitrate().minVal);
406     EXPECT_EQ(MAX_AUDIO_BITRATE, audioCaps->GetSupportedBitrate().maxVal);
407     EXPECT_EQ(1, audioCaps->GetSupportedChannel().minVal);
408     EXPECT_EQ(MAX_CHANNEL_COUNT_VORBIS, audioCaps->GetSupportedChannel().maxVal);
409     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().minVal);
410     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().maxVal);
411     EXPECT_EQ(1, audioCaps->GetSupportedFormats().size());
412     EXPECT_EQ(14, audioCaps->GetSupportedSampleRates().size()); // 14: supported samplerate count
413     EXPECT_EQ(0, audioCaps->GetSupportedProfiles().size());
414     EXPECT_EQ(0, audioCaps->GetSupportedLevels().size());
415 }
416 
CheckAVDecFlac(const std::shared_ptr<AudioCapsMock> & audioCaps) const417 void AVCodecListUnitTest::CheckAVDecFlac(const std::shared_ptr<AudioCapsMock> &audioCaps) const
418 {
419     std::shared_ptr<AVCodecInfoMock> audioCodecCaps = audioCaps->GetCodecInfo();
420     EXPECT_EQ(AVCODEC_TYPE_MOCK_AUDIO_DECODER, audioCodecCaps->GetType());
421     EXPECT_EQ(enum_->GetCodecMimeType(CodecMimeTypeMock::AUDIO_FLAC), audioCodecCaps->GetMimeType());
422     EXPECT_EQ(0, audioCodecCaps->IsHardwareAccelerated());
423     EXPECT_EQ(1, audioCodecCaps->IsSoftwareOnly());
424     EXPECT_EQ(0, audioCodecCaps->IsVendor());
425     EXPECT_EQ(1, audioCaps->GetSupportedBitrate().minVal);
426     EXPECT_EQ(MAX_AUDIO_BITRATE, audioCaps->GetSupportedBitrate().maxVal);
427     EXPECT_EQ(1, audioCaps->GetSupportedChannel().minVal);
428     EXPECT_EQ(MAX_CHANNEL_COUNT, audioCaps->GetSupportedChannel().maxVal);
429     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().minVal);
430     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().maxVal);
431     EXPECT_EQ(1, audioCaps->GetSupportedFormats().size());
432     EXPECT_EQ(12, audioCaps->GetSupportedSampleRates().size()); // 12: supported samplerate count
433     EXPECT_EQ(0, audioCaps->GetSupportedProfiles().size());
434     EXPECT_EQ(0, audioCaps->GetSupportedLevels().size());
435 }
436 
CheckAVDecOpus(const std::shared_ptr<AudioCapsMock> & audioCaps) const437 void AVCodecListUnitTest::CheckAVDecOpus(const std::shared_ptr<AudioCapsMock> &audioCaps) const
438 {
439     std::shared_ptr<AVCodecInfoMock> audioCodecCaps = audioCaps->GetCodecInfo();
440     EXPECT_EQ(AVCODEC_TYPE_MOCK_AUDIO_DECODER, audioCodecCaps->GetType());
441     EXPECT_EQ(enum_->GetCodecMimeType(CodecMimeTypeMock::AUDIO_OPUS), audioCodecCaps->GetMimeType());
442     EXPECT_EQ(0, audioCodecCaps->IsHardwareAccelerated());
443     EXPECT_EQ(1, audioCodecCaps->IsSoftwareOnly());
444     EXPECT_EQ(0, audioCodecCaps->IsVendor());
445     EXPECT_EQ(1, audioCaps->GetSupportedBitrate().minVal);
446     EXPECT_EQ(MAX_AUDIO_BITRATE, audioCaps->GetSupportedBitrate().maxVal);
447     EXPECT_EQ(1, audioCaps->GetSupportedChannel().minVal);
448     EXPECT_EQ(MAX_CHANNEL_COUNT, audioCaps->GetSupportedChannel().maxVal);
449     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().minVal);
450     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().maxVal);
451     EXPECT_EQ(1, audioCaps->GetSupportedFormats().size());
452     EXPECT_EQ(1, audioCaps->GetSupportedSampleRates().size());
453     EXPECT_EQ(0, audioCaps->GetSupportedProfiles().size());
454     EXPECT_EQ(0, audioCaps->GetSupportedLevels().size());
455 }
456 
CheckAVEncAAC(const std::shared_ptr<AudioCapsMock> & audioCaps) const457 void AVCodecListUnitTest::CheckAVEncAAC(const std::shared_ptr<AudioCapsMock> &audioCaps) const
458 {
459     std::shared_ptr<AVCodecInfoMock> audioCodecCaps = audioCaps->GetCodecInfo();
460     EXPECT_EQ(AVCODEC_TYPE_MOCK_AUDIO_ENCODER, audioCodecCaps->GetType());
461     EXPECT_EQ(enum_->GetCodecMimeType(CodecMimeTypeMock::AUDIO_AAC), audioCodecCaps->GetMimeType());
462     EXPECT_EQ(0, audioCodecCaps->IsHardwareAccelerated());
463     EXPECT_EQ(1, audioCodecCaps->IsSoftwareOnly());
464     EXPECT_EQ(0, audioCodecCaps->IsVendor());
465     EXPECT_EQ(8000, audioCaps->GetSupportedBitrate().minVal);  // 8000: supported min bitrate
466     EXPECT_EQ(MAX_AUDIO_BITRATE, audioCaps->GetSupportedBitrate().maxVal);
467     EXPECT_EQ(1, audioCaps->GetSupportedChannel().minVal);
468     EXPECT_EQ(MAX_CHANNEL_COUNT, audioCaps->GetSupportedChannel().maxVal);
469     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().minVal);
470     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().maxVal);
471     EXPECT_EQ(1, audioCaps->GetSupportedFormats().size());
472     EXPECT_EQ(11, audioCaps->GetSupportedSampleRates().size()); // 11: supported samplerate count
473     EXPECT_EQ(0, audioCaps->GetSupportedProfiles().size());
474     EXPECT_EQ(0, audioCaps->GetSupportedLevels().size());
475 }
476 
CheckAVEncOpus(const std::shared_ptr<AudioCapsMock> & audioCaps) const477 void AVCodecListUnitTest::CheckAVEncOpus(const std::shared_ptr<AudioCapsMock> &audioCaps) const
478 {
479     std::shared_ptr<AVCodecInfoMock> audioCodecCaps = audioCaps->GetCodecInfo();
480     EXPECT_EQ(AVCODEC_TYPE_MOCK_AUDIO_ENCODER, audioCodecCaps->GetType());
481     EXPECT_EQ(enum_->GetCodecMimeType(CodecMimeTypeMock::AUDIO_OPUS), audioCodecCaps->GetMimeType());
482     EXPECT_EQ(0, audioCodecCaps->IsHardwareAccelerated());
483     EXPECT_EQ(1, audioCodecCaps->IsSoftwareOnly());
484     EXPECT_EQ(0, audioCodecCaps->IsVendor());
485     EXPECT_EQ(1, audioCaps->GetSupportedBitrate().minVal);
486     EXPECT_EQ(MAX_AUDIO_BITRATE, audioCaps->GetSupportedBitrate().maxVal);
487     EXPECT_EQ(1, audioCaps->GetSupportedChannel().minVal);
488     EXPECT_EQ(MAX_CHANNEL_COUNT, audioCaps->GetSupportedChannel().maxVal);
489     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().minVal);
490     EXPECT_EQ(0, audioCaps->GetSupportedComplexity().maxVal);
491     EXPECT_EQ(1, audioCaps->GetSupportedFormats().size());
492     EXPECT_EQ(1, audioCaps->GetSupportedSampleRates().size());
493     EXPECT_EQ(0, audioCaps->GetSupportedProfiles().size());
494     EXPECT_EQ(0, audioCaps->GetSupportedLevels().size());
495 }
496 
497 /**
498  * @tc.name: AVCdecList_GetVideoDecoderCaps_0100
499  * @tc.desc: AVCdecList GetVideoDecoderCaps
500  * @tc.type: FUNC
501  * @tc.require:
502  */
503 HWTEST_F(AVCodecListUnitTest, AVCdecList_GetVideoDecoderCaps_0100, TestSize.Level0)
504 {
505     std::vector<std::shared_ptr<VideoCapsMock>> videoDecoderArray;
506     videoDecoderArray = avCodecList_->GetVideoDecoderCaps();
507     CheckVideoCapsArray(videoDecoderArray);
508 }
509 
510 /**
511  * @tc.name: AVCdecList_GetVideoEncoderCaps_0100
512  * @tc.desc: AVCdecList GetVideoEncoderCaps
513  * @tc.type: FUNC
514  * @tc.require:
515  */
516 HWTEST_F(AVCodecListUnitTest, AVCdecList_GetVideoEncoderCaps_0100, TestSize.Level0)
517 {
518     std::vector<std::shared_ptr<VideoCapsMock>> videoEncoderArray;
519     videoEncoderArray = avCodecList_->GetVideoEncoderCaps();
520     CheckVideoCapsArray(videoEncoderArray);
521 }
522 
523 /**
524  * @tc.name: AVCdecList_GetAudioDecoderCaps_0100
525  * @tc.desc: AVCdecList GetAudioDecoderCaps
526  * @tc.type: FUNC
527  * @tc.require:
528  */
529 HWTEST_F(AVCodecListUnitTest, AVCdecList_GetAudioDecoderCaps_0100, TestSize.Level0)
530 {
531     std::vector<std::shared_ptr<AudioCapsMock>> audioDecoderArray;
532     audioDecoderArray = avCodecList_->GetAudioDecoderCaps();
533     CheckAudioCapsArray(audioDecoderArray);
534 }
535 
536 /**
537  * @tc.name: AVCdecList_GetAudioEncoderCaps_0100
538  * @tc.desc: AVCdecList GetAudioEncoderCaps
539  * @tc.type: FUNC
540  * @tc.require:
541  */
542 HWTEST_F(AVCodecListUnitTest, AVCdecList_GetAudioEncoderCaps_0100, TestSize.Level0)
543 {
544     std::vector<std::shared_ptr<AudioCapsMock>> audioEncoderArray;
545     audioEncoderArray = avCodecList_->GetAudioEncoderCaps();
546     CheckAudioCapsArray(audioEncoderArray);
547 }
548 
549 /**
550  * @tc.name: AVCdecList_GetSupportedFrameRatesFor_0100
551  * @tc.desc: AVCdecList GetSupportedFrameRatesFor
552  * @tc.type: FUNC
553  * @tc.require:
554  */
555 HWTEST_F(AVCodecListUnitTest, AVCdecList_GetSupportedFrameRatesFor_0100, TestSize.Level0)
556 {
557     RangeMock ret;
558     std::vector<std::shared_ptr<VideoCapsMock>> videoDecoderArray = avCodecList_->GetVideoDecoderCaps();
559     for (auto iter = videoDecoderArray.begin(); iter != videoDecoderArray.end(); iter++) {
560         std::shared_ptr<VideoCapsMock> pVideoCaps = *iter;
561         ret = (*iter)->GetSupportedFrameRatesFor(DEFAULT_WIDTH, DEFAULT_HEIGHT);
562         EXPECT_GE(ret.minVal, 0);
563         EXPECT_LE(ret.maxVal, MAX_FRAME_RATE);
564     }
565     std::vector<std::shared_ptr<VideoCapsMock>> videoEncoderArray = avCodecList_->GetVideoEncoderCaps();
566     for (auto iter = videoEncoderArray.begin(); iter != videoEncoderArray.end(); iter++) {
567         ret = (*iter)->GetSupportedFrameRatesFor(DEFAULT_WIDTH, DEFAULT_HEIGHT);
568         EXPECT_GE(ret.minVal, 0);
569         EXPECT_LE(ret.maxVal, MAX_FRAME_RATE);
570     }
571 }
572 
573 /**
574  * @tc.name: AVCdecList_GetSupportedFrameRatesFor_0200
575  * @tc.desc: AVCdecList GetSupportedFrameRatesFor not supported size
576  * @tc.type: FUNC
577  * @tc.require:
578  */
579 HWTEST_F(AVCodecListUnitTest, AVCdecList_GetSupportedFrameRatesFor_0200, TestSize.Level0)
580 {
581     RangeMock ret;
582     std::vector<std::shared_ptr<VideoCapsMock>> videoDecoderArray = avCodecList_->GetVideoDecoderCaps();
583     for (auto iter = videoDecoderArray.begin(); iter != videoDecoderArray.end(); iter++) {
584         std::shared_ptr<VideoCapsMock> pVideoCaps = *iter;
585         ret = (*iter)->GetSupportedFrameRatesFor(MAX_WIDTH + 1, MAX_HEIGHT + 1);
586         EXPECT_GE(ret.minVal, 0);
587         EXPECT_LE(ret.maxVal, MAX_FRAME_RATE);
588     }
589     std::vector<std::shared_ptr<VideoCapsMock>> videoEncoderArray = avCodecList_->GetVideoEncoderCaps();
590     for (auto iter = videoEncoderArray.begin(); iter != videoEncoderArray.end(); iter++) {
591         ret = (*iter)->GetSupportedFrameRatesFor(MIN_WIDTH - 1, MIN_HEIGHT - 1);
592         EXPECT_GE(ret.minVal, 0);
593         EXPECT_LE(ret.maxVal, MAX_FRAME_RATE);
594     }
595 }
596 
597 /**
598  * @tc.name: AVCdecList_GetPreferredFrameRate_0100
599  * @tc.desc: AVCdecList GetPreferredFrameRate
600  * @tc.type: FUNC
601  * @tc.require:
602  */
603 HWTEST_F(AVCodecListUnitTest, AVCdecList_GetPreferredFrameRate_0100, TestSize.Level0)
604 {
605     RangeMock ret;
606     std::vector<std::shared_ptr<VideoCapsMock>> videoEncoderArray = avCodecList_->GetVideoEncoderCaps();
607     for (auto iter = videoEncoderArray.begin(); iter != videoEncoderArray.end(); iter++) {
608         ret = (*iter)->GetPreferredFrameRate(DEFAULT_WIDTH, DEFAULT_HEIGHT);
609         EXPECT_GE(ret.minVal, 0);
610     }
611     std::vector<std::shared_ptr<VideoCapsMock>> videoDecoderArray = avCodecList_->GetVideoDecoderCaps();
612     for (auto iter = videoDecoderArray.begin(); iter != videoDecoderArray.end(); iter++) {
613         ret = (*iter)->GetPreferredFrameRate(DEFAULT_WIDTH, DEFAULT_HEIGHT);
614         EXPECT_GE(ret.minVal, 0);
615     }
616 }
617 
618 /**
619  * @tc.name: AVCdecList_GetPreferredFrameRate_0200
620  * @tc.desc: AVCdecList GetPreferredFrameRate for not supported size
621  * @tc.type: FUNC
622  * @tc.require:
623  */
624 HWTEST_F(AVCodecListUnitTest, AVCdecList_GetPreferredFrameRate_0200, TestSize.Level0)
625 {
626     RangeMock ret;
627     std::vector<std::shared_ptr<VideoCapsMock>> videoEncoderArray = avCodecList_->GetVideoEncoderCaps();
628     for (auto iter = videoEncoderArray.begin(); iter != videoEncoderArray.end(); iter++) {
629         ret = (*iter)->GetPreferredFrameRate(MAX_WIDTH + 1, MAX_HEIGHT + 1);
630         EXPECT_GE(ret.minVal, 0);
631     }
632     std::vector<std::shared_ptr<VideoCapsMock>> videoDecoderArray = avCodecList_->GetVideoDecoderCaps();
633     for (auto iter = videoDecoderArray.begin(); iter != videoDecoderArray.end(); iter++) {
634         ret = (*iter)->GetPreferredFrameRate(MIN_WIDTH - 1, MIN_HEIGHT - 1);
635         EXPECT_GE(ret.minVal, 0);
636     }
637 }
638 } // namespace Media
639 } // namespace OHOS
640