• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 "audio_ffmpeg_aac_decoder_plugin.h"
18 #include "audio_ffmpeg_amrnb_decoder_plugin.h"
19 #include "audio_ffmpeg_amrwb_decoder_plugin.h"
20 #include "audio_ffmpeg_vorbis_decoder_plugin.h"
21 #include "audio_g711mu_decoder_plugin.h"
22 #include <set>
23 #include <fstream>
24 #include "media_description.h"
25 #include "avcodec_errors.h"
26 #include "avcodec_trace.h"
27 #include "avcodec_log.h"
28 #include "avcodec_mime_type.h"
29 #include "avcodec_audio_common.h"
30 #include "ffmpeg_converter.h"
31 #include "audio_codec_adapter.h"
32 #include "meta/format.h"
33 #include "avcodec_audio_decoder.h"
34 #include "avcodec_codec_name.h"
35 
36 using namespace std;
37 using namespace testing::ext;
38 
39 namespace {
40 constexpr int32_t MIN_CHANNELS = 1;
41 constexpr int32_t MAX_CHANNELS = 8;
42 constexpr int32_t DEFAULT_AAC_TYPE = 1;
43 constexpr int32_t AMRNB_SUPPORT_CHANNELS = 1;
44 constexpr int32_t AMRWB_SUPPORT_CHANNELS = 1;
45 constexpr int32_t G711MU_SUPPORT_CHANNELS = 1;
46 constexpr int32_t AMRNB_SUPPORT_SAMPLE_RATE = 8000;
47 constexpr int32_t AMRWB_SUPPORT_SAMPLE_RATE = 16000;
48 constexpr int32_t G711MU_SUPPORT_SAMPLE_RATE = 8000;
49 
50 static std::set<int32_t> supportedSampleRate = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000,
51                                                 11025, 8000, 7350};
52 static std::set<OHOS::MediaAVCodec::AudioSampleFormat> supportedSampleFormats = {
53     OHOS::MediaAVCodec::AudioSampleFormat::SAMPLE_S16LE,
54     OHOS::MediaAVCodec::AudioSampleFormat::SAMPLE_F32LE};
55 static std::set<int32_t> supportedSampleRates = {7350, 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000,
56                                                  64000, 88200, 96000};
57 const string CODEC_OGG_NAME = std::string(OHOS::MediaAVCodec::AVCodecCodecName::AUDIO_DECODER_VORBIS_NAME);
58 const string INPUT_SOURCE_PATH = "/data/test/media/";
59 const string INPUT_OGG_FILE_WITH_HEADER[1][5] = {{"OGG_44k_2c_with_header.dat", "44100", "2", "128000", "16"}};
60 constexpr string_view OUTPUT_PCM_FILE_PATH = "/data/test/media/out.pcm";
61 }
62 
63 namespace OHOS {
64 namespace MediaAVCodec {
65 class AudioDecPluginUnitTest : public testing::Test {
66 public:
67     static void SetUpTestCase(void);
68     static void TearDownTestCase(void);
69     void SetUp();
70     void TearDown();
71     int32_t InitOggFile(const string &codecName, string inputTestFile);
72     int32_t SetVorbisHeader();
73 protected:
74     OHOS::MediaAVCodec::Format format_;
75     std::shared_ptr<AudioFFMpegAacDecoderPlugin> aacDecPlugin_ = {nullptr};
76     std::shared_ptr<AudioFFMpegAmrnbDecoderPlugin> amrnbDecPlugin_ = {nullptr};
77     std::shared_ptr<AudioFFMpegAmrwbDecoderPlugin> amrwbDecPlugin_ = {nullptr};
78     std::shared_ptr<AudioFFMpegVorbisDecoderPlugin> vorbisDecPlugin_ = {nullptr};
79     std::shared_ptr<AudioG711muDecoderPlugin> g711muDecPlugin_ = {nullptr};
80     std::ifstream inputFile_;
81     std::ofstream pcmOutputFile_;
82     bool vorbisHasExtradata_ = true;
83 };
84 
SetUpTestCase(void)85 void AudioDecPluginUnitTest::SetUpTestCase(void)
86 {
87     cout << "[SetUpTestCase]: " << endl;
88 }
89 
TearDownTestCase(void)90 void AudioDecPluginUnitTest::TearDownTestCase(void)
91 {
92     cout << "[TearDownTestCase]: " << endl;
93 }
94 
SetUp(void)95 void AudioDecPluginUnitTest::SetUp(void)
96 {
97     cout << "[SetUp]: SetUp!!!" << endl;
98 }
99 
TearDown(void)100 void AudioDecPluginUnitTest::TearDown(void)
101 {
102     if (aacDecPlugin_) {
103         aacDecPlugin_->Release();
104     }
105     if (amrnbDecPlugin_) {
106         amrnbDecPlugin_->Release();
107     }
108     if (amrwbDecPlugin_) {
109         amrwbDecPlugin_->Release();
110     }
111     if (vorbisDecPlugin_) {
112         vorbisDecPlugin_->Release();
113     }
114     if (g711muDecPlugin_) {
115         g711muDecPlugin_->Release();
116     }
117     cout << "[TearDown]: over!!!" << endl;
118 }
119 
InitOggFile(const string & codecName,string inputTestFile)120 int32_t AudioDecPluginUnitTest::InitOggFile(const string &codecName, string inputTestFile)
121 {
122     if (vorbisDecPlugin_ == nullptr) {
123         return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
124     }
125 
126     inputFile_.open(INPUT_SOURCE_PATH + inputTestFile, std::ios::binary);
127     pcmOutputFile_.open(OUTPUT_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
128     if (!inputFile_.is_open()) {
129         cout << "Fatal: open input file failed" << endl;
130         return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
131     }
132     if (!pcmOutputFile_.is_open()) {
133         cout << "Fatal: open output file failed" << endl;
134         return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
135     }
136 
137     if (codecName.compare(CODEC_OGG_NAME) == 0) {
138         if (!vorbisHasExtradata_) {
139             return SetVorbisHeader();
140         }
141         int64_t extradataSize;
142         inputFile_.read(reinterpret_cast<char *>(&extradataSize), sizeof(int64_t));
143         if (extradataSize < 0) {
144             return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
145         }
146         char buffer[extradataSize];
147         inputFile_.read(buffer, extradataSize);
148         if (inputFile_.gcount() != extradataSize) {
149             cout << "read extradata bytes error" << endl;
150         }
151         format_.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, (uint8_t *)buffer, extradataSize);
152     }
153 
154     return AVCodecServiceErrCode::AVCS_ERR_OK;
155 }
156 
SetVorbisHeader()157 int32_t AudioDecPluginUnitTest::SetVorbisHeader()
158 {
159     // set identification header
160     int64_t headerSize;
161     inputFile_.read(reinterpret_cast<char *>(&headerSize), sizeof(int64_t));
162     if (headerSize < 0) {
163         return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
164     }
165     char idBuffer[headerSize];
166     inputFile_.read(idBuffer, headerSize);
167     if (inputFile_.gcount() != headerSize) {
168         cout << "read extradata bytes error" << endl;
169         return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
170     }
171     format_.PutBuffer(MediaDescriptionKey::MD_KEY_IDENTIFICATION_HEADER, (uint8_t *)idBuffer, headerSize);
172 
173     // set setup header
174     inputFile_.read(reinterpret_cast<char *>(&headerSize), sizeof(int64_t));
175     if (headerSize < 0) {
176         return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
177     }
178     char setupBuffer[headerSize];
179     inputFile_.read(setupBuffer, headerSize);
180     if (inputFile_.gcount() != headerSize) {
181         cout << "read extradata bytes error" << endl;
182         return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
183     }
184     format_.PutBuffer(MediaDescriptionKey::MD_KEY_SETUP_HEADER, (uint8_t *)setupBuffer, headerSize);
185     return AVCodecServiceErrCode::AVCS_ERR_OK;
186 }
187 
188 /**
189  * @tc.name: CheckSampleFormat_Aac_001
190  * @tc.desc: init success
191  * @tc.type: FUNC
192  */
193 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Aac_001, TestSize.Level1)
194 {
195     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNELS);
196     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
197     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16LE);
198     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
199     aacDecPlugin_ = std::make_shared<AudioFFMpegAacDecoderPlugin>();
200     auto ret = aacDecPlugin_->Init(format_);
201     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
202 }
203 
204 /**
205  * @tc.name: CheckSampleFormat_Aac_002
206  * @tc.desc: unsupported aac samplerate
207  * @tc.type: FUNC
208  */
209 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Aac_002, TestSize.Level1)
210 {
211     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNELS);
212     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44444); // unsupported aac samplerate
213     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16LE);
214     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
215     aacDecPlugin_ = std::make_shared<AudioFFMpegAacDecoderPlugin>();
216     auto ret = aacDecPlugin_->Init(format_);
217     EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
218 }
219 
220 /**
221  * @tc.name: CheckSampleFormat_Aac_003
222  * @tc.desc: unsupported aac sampleformat
223  * @tc.type: FUNC
224  */
225 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Aac_003, TestSize.Level1)
226 {
227     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNELS);
228     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
229     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16P);
230     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
231     aacDecPlugin_ = std::make_shared<AudioFFMpegAacDecoderPlugin>();
232     auto ret = aacDecPlugin_->Init(format_);
233     EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
234 }
235 
236 /**
237  * @tc.name: CheckSampleFormat_Aac_004
238  * @tc.desc: channels_ == 1 && sampleFormat == SAMPLE_F32LE
239  * @tc.type: FUNC
240  */
241 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Aac_004, TestSize.Level1)
242 {
243     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MIN_CHANNELS);
244     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
245     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_F32LE);
246     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
247     aacDecPlugin_ = std::make_shared<AudioFFMpegAacDecoderPlugin>();
248     auto ret = aacDecPlugin_->Init(format_);
249     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
250 }
251 
252 /**
253  * @tc.name: CheckSampleFormat_Aac_005
254  * @tc.desc: channels_ == 1 && sampleFormat != SAMPLE_F32LE
255  * @tc.type: FUNC
256  */
257 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Aac_005, TestSize.Level1)
258 {
259     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MIN_CHANNELS);
260     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
261     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16LE);
262     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
263     aacDecPlugin_ = std::make_shared<AudioFFMpegAacDecoderPlugin>();
264     auto ret = aacDecPlugin_->Init(format_);
265     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
266 }
267 
268 /**
269  * @tc.name: CheckSampleFormat_Aac_006
270  * @tc.desc: channels_ != 1 && sampleFormat != SAMPLE_F32LE
271  * @tc.type: FUNC
272  */
273 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Aac_006, TestSize.Level1)
274 {
275     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNELS);
276     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
277     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16LE);
278     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
279     aacDecPlugin_ = std::make_shared<AudioFFMpegAacDecoderPlugin>();
280     auto ret = aacDecPlugin_->Init(format_);
281     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
282 }
283 
284 /**
285  * @tc.name: CheckSampleFormat_Aac_007
286  * @tc.desc: channels_ != 1 && sampleFormat == SAMPLE_F32LE
287  * @tc.type: FUNC
288  */
289 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Aac_007, TestSize.Level1)
290 {
291     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNELS);
292     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
293     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_F32LE);
294     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
295     aacDecPlugin_ = std::make_shared<AudioFFMpegAacDecoderPlugin>();
296     auto ret = aacDecPlugin_->Init(format_);
297     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
298 }
299 
300 /**
301  * @tc.name: CheckChannelCount_Aac_001
302  * @tc.desc: channel_count missing
303  * @tc.type: FUNC
304  */
305 HWTEST_F(AudioDecPluginUnitTest, CheckChannelCount_Aac_001, TestSize.Level1)
306 {
307     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
308     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_F32LE);
309     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
310     aacDecPlugin_ = std::make_shared<AudioFFMpegAacDecoderPlugin>();
311     auto ret = aacDecPlugin_->Init(format_);
312     EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
313 }
314 
315 /**
316  * @tc.name: CheckSampleFormat_Amrnb_001
317  * @tc.desc: sampleformat not missing and EQ SAMPLE_F32LE
318  * @tc.type: FUNC
319  */
320 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Amrnb_001, TestSize.Level1)
321 {
322     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, AMRNB_SUPPORT_CHANNELS);
323     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, AMRNB_SUPPORT_SAMPLE_RATE);
324     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_F32LE);
325     amrnbDecPlugin_ = std::make_shared<AudioFFMpegAmrnbDecoderPlugin>();
326     auto ret = amrnbDecPlugin_->Init(format_);
327     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
328 }
329 
330 /**
331  * @tc.name: CheckSampleFormat_Amrnb_002
332  * @tc.desc: sampleformat not missing and EQ SAMPLE_S16LE
333  * @tc.type: FUNC
334  */
335 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Amrnb_002, TestSize.Level1)
336 {
337     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, AMRNB_SUPPORT_CHANNELS);
338     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, AMRNB_SUPPORT_SAMPLE_RATE);
339     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16LE);
340     amrnbDecPlugin_ = std::make_shared<AudioFFMpegAmrnbDecoderPlugin>();
341     auto ret = amrnbDecPlugin_->Init(format_);
342     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
343 }
344 
345 /**
346  * @tc.name: CheckSampleFormat_Amrnb_003
347  * @tc.desc: sampleformat not missing but unsupported
348  * @tc.type: FUNC
349  */
350 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Amrnb_003, TestSize.Level1)
351 {
352     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, AMRNB_SUPPORT_CHANNELS);
353     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, AMRNB_SUPPORT_SAMPLE_RATE);
354     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16P);
355     amrnbDecPlugin_ = std::make_shared<AudioFFMpegAmrnbDecoderPlugin>();
356     auto ret = amrnbDecPlugin_->Init(format_);
357     EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
358 }
359 
360 /**
361  * @tc.name: CheckSampleFormat_Amrwb_001
362  * @tc.desc: sampleformat not missing and EQ SAMPLE_F32LE
363  * @tc.type: FUNC
364  */
365 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Amrwb_001, TestSize.Level1)
366 {
367     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, AMRWB_SUPPORT_CHANNELS);
368     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, AMRWB_SUPPORT_SAMPLE_RATE);
369     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_F32LE);
370     amrwbDecPlugin_ = std::make_shared<AudioFFMpegAmrwbDecoderPlugin>();
371     auto ret = amrwbDecPlugin_->Init(format_);
372     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
373 }
374 
375 /**
376  * @tc.name: CheckSampleFormat_Amrwb_002
377  * @tc.desc: sampleformat not missing and EQ SAMPLE_S16LE
378  * @tc.type: FUNC
379  */
380 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Amrwb_002, TestSize.Level1)
381 {
382     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, AMRNB_SUPPORT_CHANNELS);
383     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, AMRWB_SUPPORT_SAMPLE_RATE);
384     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16LE);
385     amrwbDecPlugin_ = std::make_shared<AudioFFMpegAmrwbDecoderPlugin>();
386     auto ret = amrwbDecPlugin_->Init(format_);
387     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
388 }
389 
390 /**
391  * @tc.name: CheckSampleFormat_Amrwb_003
392  * @tc.desc: sampleformat not missing but unsupported
393  * @tc.type: FUNC
394  */
395 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Amrwb_003, TestSize.Level1)
396 {
397     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, AMRNB_SUPPORT_CHANNELS);
398     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, AMRWB_SUPPORT_SAMPLE_RATE);
399     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16P);
400     amrwbDecPlugin_ = std::make_shared<AudioFFMpegAmrwbDecoderPlugin>();
401     auto ret = amrwbDecPlugin_->Init(format_);
402     EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
403 }
404 
405 /**
406  * @tc.name: CheckSampleFormat_Vorbis_001
407  * @tc.desc: channels_ == 1 && sampleFormat == SAMPLE_F32LE
408  * @tc.type: FUNC
409  */
410 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Vorbis_001, TestSize.Level1)
411 {
412     vorbisHasExtradata_ = false;
413     vorbisDecPlugin_ = std::make_shared<AudioFFMpegVorbisDecoderPlugin>();
414 
415     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, stoi(INPUT_OGG_FILE_WITH_HEADER[0][1]));
416     format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITRATE, stoi(INPUT_OGG_FILE_WITH_HEADER[0][3]));
417     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MIN_CHANNELS);
418     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_F32LE);
419     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, InitOggFile(CODEC_OGG_NAME, INPUT_OGG_FILE_WITH_HEADER[0][0]));
420     auto ret = vorbisDecPlugin_->Init(format_);
421     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
422 }
423 
424 /**
425  * @tc.name: CheckSampleFormat_Vorbis_002
426  * @tc.desc: channels_ == 1 && sampleFormat != SAMPLE_F32LE
427  * @tc.type: FUNC
428  */
429 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Vorbis_002, TestSize.Level1)
430 {
431     vorbisHasExtradata_ = false;
432     vorbisDecPlugin_ = std::make_shared<AudioFFMpegVorbisDecoderPlugin>();
433 
434     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, stoi(INPUT_OGG_FILE_WITH_HEADER[0][1]));
435     format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITRATE, stoi(INPUT_OGG_FILE_WITH_HEADER[0][3]));
436     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MIN_CHANNELS);
437     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16LE);
438     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, InitOggFile(CODEC_OGG_NAME, INPUT_OGG_FILE_WITH_HEADER[0][0]));
439     auto ret = vorbisDecPlugin_->Init(format_);
440     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
441 }
442 
443 /**
444  * @tc.name: CheckSampleFormat_Vorbis_003
445  * @tc.desc: channels_ != 1 && sampleFormat == SAMPLE_F32LE
446  * @tc.type: FUNC
447  */
448 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Vorbis_003, TestSize.Level1)
449 {
450     vorbisHasExtradata_ = false;
451     vorbisDecPlugin_ = std::make_shared<AudioFFMpegVorbisDecoderPlugin>();
452 
453     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, stoi(INPUT_OGG_FILE_WITH_HEADER[0][1]));
454     format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITRATE, stoi(INPUT_OGG_FILE_WITH_HEADER[0][3]));
455     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNELS);
456     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_F32LE);
457     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, InitOggFile(CODEC_OGG_NAME, INPUT_OGG_FILE_WITH_HEADER[0][0]));
458     auto ret = vorbisDecPlugin_->Init(format_);
459     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
460 }
461 
462 /**
463  * @tc.name: CheckSampleFormat_Vorbis_004
464  * @tc.desc: channels_ != 1 && sampleFormat != SAMPLE_F32LE
465  * @tc.type: FUNC
466  */
467 HWTEST_F(AudioDecPluginUnitTest, CheckSampleFormat_Vorbis_004, TestSize.Level1)
468 {
469     vorbisHasExtradata_ = false;
470     vorbisDecPlugin_ = std::make_shared<AudioFFMpegVorbisDecoderPlugin>();
471 
472     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, stoi(INPUT_OGG_FILE_WITH_HEADER[0][1]));
473     format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITRATE, stoi(INPUT_OGG_FILE_WITH_HEADER[0][3]));
474     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNELS);
475     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16LE);
476     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, InitOggFile(CODEC_OGG_NAME, INPUT_OGG_FILE_WITH_HEADER[0][0]));
477     auto ret = vorbisDecPlugin_->Init(format_);
478     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
479 }
480 
481 /**
482  * @tc.name: CheckChannelCount_Vorbis_001
483  * @tc.desc: missing channelCount
484  * @tc.type: FUNC
485  */
486 HWTEST_F(AudioDecPluginUnitTest, CheckChannelCount_Vorbis_001, TestSize.Level1)
487 {
488     vorbisHasExtradata_ = false;
489     vorbisDecPlugin_ = std::make_shared<AudioFFMpegVorbisDecoderPlugin>();
490 
491     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, stoi(INPUT_OGG_FILE_WITH_HEADER[0][1]));
492     format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITRATE, stoi(INPUT_OGG_FILE_WITH_HEADER[0][3]));
493     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_F32LE);
494     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, InitOggFile(CODEC_OGG_NAME, INPUT_OGG_FILE_WITH_HEADER[0][0]));
495     auto ret = vorbisDecPlugin_->Init(format_);
496     EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
497 }
498 
499 /**
500  * @tc.name: CheckSampleRate_Vorbis_001
501  * @tc.desc: missing samplerate
502  * @tc.type: FUNC
503  */
504 HWTEST_F(AudioDecPluginUnitTest, CheckSampleRate_Vorbis_001, TestSize.Level1)
505 {
506     vorbisHasExtradata_ = false;
507     vorbisDecPlugin_ = std::make_shared<AudioFFMpegVorbisDecoderPlugin>();
508 
509     format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITRATE, stoi(INPUT_OGG_FILE_WITH_HEADER[0][3]));
510     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNELS);
511     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_F32LE);
512     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, InitOggFile(CODEC_OGG_NAME, INPUT_OGG_FILE_WITH_HEADER[0][0]));
513     auto ret = vorbisDecPlugin_->Init(format_);
514     EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
515 }
516 
517 /**
518  * @tc.name: CheckSampleRate_Vorbis_002
519  * @tc.desc: LT min samplerate
520  * @tc.type: FUNC
521  */
522 HWTEST_F(AudioDecPluginUnitTest, CheckSampleRate_Vorbis_002, TestSize.Level1)
523 {
524     vorbisHasExtradata_ = false;
525     vorbisDecPlugin_ = std::make_shared<AudioFFMpegVorbisDecoderPlugin>();
526 
527     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 7000); // invalid samplerate
528     format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITRATE, stoi(INPUT_OGG_FILE_WITH_HEADER[0][3]));
529     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNELS);
530     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_F32LE);
531     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, InitOggFile(CODEC_OGG_NAME, INPUT_OGG_FILE_WITH_HEADER[0][0]));
532     auto ret = vorbisDecPlugin_->Init(format_);
533     EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
534 }
535 
536 /**
537  * @tc.name: CheckSampleRate_Vorbis_003
538  * @tc.desc: GT max samplerate
539  * @tc.type: FUNC
540  */
541 HWTEST_F(AudioDecPluginUnitTest, CheckSampleRate_Vorbis_003, TestSize.Level1)
542 {
543     vorbisHasExtradata_ = false;
544     vorbisDecPlugin_ = std::make_shared<AudioFFMpegVorbisDecoderPlugin>();
545 
546     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 200000); // invalid samplerate
547     format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITRATE, stoi(INPUT_OGG_FILE_WITH_HEADER[0][3]));
548     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNELS);
549     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_F32LE);
550     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, InitOggFile(CODEC_OGG_NAME, INPUT_OGG_FILE_WITH_HEADER[0][0]));
551     auto ret = vorbisDecPlugin_->Init(format_);
552     EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
553 }
554 
555 /**
556  * @tc.name: CheckInit_g711mu_001
557  * @tc.desc: CheckInit success
558  * @tc.type: FUNC
559  */
560 HWTEST_F(AudioDecPluginUnitTest, CheckInit_g711mu_001, TestSize.Level1)
561 {
562     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, G711MU_SUPPORT_CHANNELS);
563     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, G711MU_SUPPORT_SAMPLE_RATE);
564     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16LE);
565     g711muDecPlugin_ = std::make_shared<AudioG711muDecoderPlugin>();
566     auto ret = g711muDecPlugin_->Init(format_);
567     EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
568 }
569 
570 /**
571  * @tc.name: CheckInit_g711mu_002
572  * @tc.desc: unsupported channelcount
573  * @tc.type: FUNC
574  */
575 HWTEST_F(AudioDecPluginUnitTest, CheckInit_g711mu_002, TestSize.Level1)
576 {
577     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2); // unsupported channelcount
578     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, G711MU_SUPPORT_SAMPLE_RATE);
579     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16LE);
580     g711muDecPlugin_ = std::make_shared<AudioG711muDecoderPlugin>();
581     auto ret = g711muDecPlugin_->Init(format_);
582     EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
583 }
584 
585 /**
586  * @tc.name: CheckInit_g711mu_003
587  * @tc.desc: unsupported samplerate
588  * @tc.type: FUNC
589  */
590 HWTEST_F(AudioDecPluginUnitTest, CheckInit_g711mu_003, TestSize.Level1)
591 {
592     format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, G711MU_SUPPORT_CHANNELS);
593     format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 192000); // unsupported samplerate
594     format_.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16LE);
595     g711muDecPlugin_ = std::make_shared<AudioG711muDecoderPlugin>();
596     auto ret = g711muDecPlugin_->Init(format_);
597     EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, ret);
598 }
599 } // namespace MediaAVCodec
600 } // namespace OHOS