1 /*
2  * Copyright (C) 2023 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 #include <string>
16 #include <iostream>
17 #include <unistd.h>
18 #include "gtest/gtest.h"
19 #include "AudioDecoderDemoCommon.h"
20 #include "avcodec_errors.h"
21 #include "avcodec_common.h"
22 #include "media_description.h"
23 #include "securec.h"
24 
25 using namespace std;
26 using namespace testing::ext;
27 using namespace OHOS;
28 using namespace OHOS::MediaAVCodec;
29 
30 
31 namespace {
32     class InnerFunctionTest : public testing::Test {
33     public:
34         static void SetUpTestCase();
35         static void TearDownTestCase();
36         void SetUp() override;
37         void TearDown() override;
38     };
39 
SetUpTestCase()40     void InnerFunctionTest::SetUpTestCase() {}
TearDownTestCase()41     void InnerFunctionTest::TearDownTestCase() {}
SetUp()42     void InnerFunctionTest::SetUp() {}
TearDown()43     void InnerFunctionTest::TearDown() {}
44 
45     int32_t testResult[10] = { -1 };
46 
compareFile(string file1,string file2)47     bool compareFile(string file1, string file2)
48     {
49         string ans1, ans2;
50         int i;
51         (void)freopen(file1.c_str(), "r", stdin);
52         char c;
53         while (scanf_s("%c", &c, 1) != EOF) {
54             ans1 += c;
55         }
56         (void)fclose(stdin);
57 
58         (void)freopen(file2.c_str(), "r", stdin);
59         while (scanf_s("%c", &c, 1) != EOF) {
60             ans2 += c;
61         }
62         (void)fclose(stdin);
63         if (ans1.size() != ans2.size()) {
64             return false;
65         }
66         for (i = 0; i < ans1.size(); i++) {
67             if (ans1[i] != ans2[i]) {
68                 return false;
69             }
70         }
71         return true;
72     }
73 
runDecode(string decoderName,string inputFile,string outputFile,int32_t threadId)74     void runDecode(string decoderName, string inputFile, string outputFile, int32_t threadId)
75     {
76         AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
77 
78         if (decoderName == "OH.Media.Codec.Decoder.Audio.AAC") {
79             Format format;
80             uint32_t CHANNEL_COUNT = 1;
81             uint32_t SAMPLE_RATE = 16100;
82             uint32_t BITS_RATE = 128000;
83             uint32_t DEFAULT_AAC_IS_ADTS = 1;
84             format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
85             format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE);
86             format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, BITS_RATE);
87             format.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_IS_ADTS);
88             decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
89         } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Mpeg") {
90             Format format;
91             uint32_t CHANNEL_COUNT = 2;
92             uint32_t SAMPLE_RATE = 44100;
93             uint32_t BITS_RATE = 128000;
94             format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
95             format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE);
96             format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, BITS_RATE);
97             decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
98         } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Flac") {
99             Format format;
100             uint32_t CHANNEL_COUNT = 2;
101             uint32_t SAMPLE_RATE = 8000;
102             uint32_t BITS_RATE = 199000;
103             uint32_t BITS_PER_CODED_SAMPLE = 24;
104             format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
105             format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE);
106             format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, BITS_RATE);
107             format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, BITS_PER_CODED_SAMPLE);
108             decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
109         } else {
110             Format format;
111             uint32_t CHANNEL_COUNT = 2;
112             uint32_t SAMPLE_RATE = 48000;
113             uint32_t BITS_RATE = 45000;
114             format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
115             format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE);
116             format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, BITS_RATE);
117             decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
118         }
119         testResult[threadId] = AVCS_ERR_OK;
120         delete decoderDemo;
121     }
122 }
123 
124 /**
125  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_001
126  * @tc.name      : AAC different sample_rate
127  * @tc.desc      : Function test
128  */
129 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_001, TestSize.Level2)
130 {
131     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
132     ASSERT_NE(nullptr, decoderDemo);
133 
134     string decoderName = "OH.Media.Codec.Decoder.Audio.AAC";
135 
136     int32_t sample_rate_List[] = {7350, 16000, 44100, 48000, 96000};
137 
138     for (int i = 0; i < 5; i++)
139     {
140         Format format;
141         int32_t sample_rate = sample_rate_List[i];
142         cout << "sample_rate is: " << sample_rate << endl;
143         format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
144         format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, sample_rate);
145         format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000);
146         format.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1);
147 
148         string inputFile = "fltp_128k_" + to_string(sample_rate) + "_1_dayuhaitang.aac";
149         string outputFile = "FUNCTION_001_" + to_string(sample_rate) + "_1_aac_output.pcm";
150 
151         decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
152     }
153     delete decoderDemo;
154 }
155 
156 /**
157  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_002
158  * @tc.name      : MP3 different sample_rate
159  * @tc.desc      : Function test
160  */
161 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_002, TestSize.Level2)
162 {
163     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
164     ASSERT_NE(nullptr, decoderDemo);
165 
166     string decoderName = "OH.Media.Codec.Decoder.Audio.Mpeg";
167 
168     int32_t sample_rate_List[] = {8000, 16000, 44100, 48000};
169 
170     for (int i = 0; i < 4; i++)
171     {
172         Format format;
173         int32_t sample_rate = sample_rate_List[i];
174         cout << "sample_rate is: " << sample_rate << endl;
175         format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2);
176         format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, sample_rate);
177         format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 40000);
178 
179         string inputFile = "fltp_40k_" + to_string(sample_rate) + "_2_dayuhaitang.mp3";;
180         string outputFile = "FUNCTION_002_" + to_string(sample_rate) + "_2_mp3_output.pcm";
181 
182         decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
183     }
184     delete decoderDemo;
185 }
186 
187 /**
188  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_003
189  * @tc.name      : vorbis sample_rate
190  * @tc.desc      : Function test
191  */
192 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_003, TestSize.Level2)
193 {
194     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
195     ASSERT_NE(nullptr, decoderDemo);
196 
197     string decoderName = "OH.Media.Codec.Decoder.Audio.Vorbis";
198 
199     int32_t sample_rate_List[] = {8000, 16000, 44100, 48000};
200 
201     for (int i = 0; i < 4; i++)
202     {
203         Format format;
204         int32_t sample_rate = sample_rate_List[i];
205         cout << "sample_rate is: " << sample_rate << endl;
206         format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2);
207         format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, sample_rate);
208         format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 45000);
209 
210         string inputFile = "fltp_45k_" + to_string(sample_rate) + "_2_dayuhaitang.ogg";
211         string outputFile = "FUNCTION_003_" + to_string(sample_rate) + "_2_vorbis_output.pcm";
212 
213         decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
214     }
215     delete decoderDemo;
216 }
217 
218 /**
219  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_004
220  * @tc.name      : flac different sample_rate
221  * @tc.desc      : Function test
222  */
223 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_004, TestSize.Level2)
224 {
225     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
226     ASSERT_NE(nullptr, decoderDemo);
227 
228     string decoderName = "OH.Media.Codec.Decoder.Audio.Flac";
229 
230     int32_t sample_rate_List[] = {8000, 16000, 44100, 48000, 192000};
231 
232     for (int i = 0; i < 5; i++)
233     {
234         Format format;
235         int32_t sample_rate = sample_rate_List[i];
236         cout << "sample_rate is: " << sample_rate << endl;
237         format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2);
238         format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, sample_rate);
239         format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 199000);
240         format.PutIntValue("bits_per_coded_sample", 24);
241 
242         string inputFile = "s16_" + to_string(sample_rate) + "_2_dayuhaitang.flac";;
243         string outputFile = "FUNCTION_004_" + to_string(sample_rate) + "_2_flac_output.pcm";
244 
245         decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
246     }
247     delete decoderDemo;
248 }
249 
250 /**
251  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_005
252  * @tc.name      : AAC different Channel_count
253  * @tc.desc      : Function test
254  */
255 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_005, TestSize.Level2)
256 {
257     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
258     ASSERT_NE(nullptr, decoderDemo);
259 
260     string decoderName = "OH.Media.Codec.Decoder.Audio.AAC";
261 
262     int Channel_count_List[] = {1, 2, 8};
263 
264     for (int i = 0; i < 3; i++)
265     {
266         Format format;
267         int Channel_count = Channel_count_List[i];
268         format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, Channel_count);
269         format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
270         format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000);
271         format.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1);
272 
273         string inputFile = "fltp_128k_44100_" + to_string(Channel_count) + "_dayuhaitang.aac";
274         string outputFile = "FUNCTION_005_44100_" + to_string(Channel_count) + "_aac_output.pcm";
275 
276         decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
277     }
278     delete decoderDemo;
279 }
280 
281 
282 /**
283  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_006
284  * @tc.name      : mp3 different Channel_count
285  * @tc.desc      : Function test
286  */
287 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_006, TestSize.Level2)
288 {
289     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
290     ASSERT_NE(nullptr, decoderDemo);
291 
292     string decoderName = "OH.Media.Codec.Decoder.Audio.Mpeg";
293 
294     int Channel_count_List[] = {1, 2};
295 
296     for (int i = 0; i < 2; i++)
297     {
298         Format format;
299         int Channel_count = Channel_count_List[i];
300         format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, Channel_count);
301         format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
302         format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 320000);
303 
304         string inputFile = "fltp_128k_44100_" + to_string(Channel_count) + "_dayuhaitang.mp3";
305         string outputFile = "FUNCTION_006_44100_" + to_string(Channel_count) + "_mp3_output.pcm";
306 
307         decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
308     }
309     delete decoderDemo;
310 }
311 
312 
313 /**
314  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_007
315  * @tc.name      : flac different Channel_count
316  * @tc.desc      : Function test
317  */
318 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_007, TestSize.Level2)
319 {
320     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
321     ASSERT_NE(nullptr, decoderDemo);
322 
323     string decoderName = "OH.Media.Codec.Decoder.Audio.Flac";
324 
325     int Channel_count_List[] = {1, 2, 8};
326 
327     for (int i = 0; i < 3; i++)
328     {
329         Format format;
330         int Channel_count = Channel_count_List[i];
331         format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, Channel_count);
332         format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000);
333         format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 320000);
334         format.PutIntValue("bits_per_coded_sample", 24);
335 
336         string inputFile = "s16_48000_" + to_string(Channel_count) + "_dayuhaitang.flac";
337         string outputFile = "FUNCTION_007_48000_" + to_string(Channel_count) + "_flac_output.pcm";
338 
339         decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
340     }
341     delete decoderDemo;
342 }
343 
344 /**
345  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_008
346  * @tc.name      : vorbis different Channel_count
347  * @tc.desc      : Function test
348  */
349 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_008, TestSize.Level2)
350 {
351     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
352     ASSERT_NE(nullptr, decoderDemo);
353 
354     string decoderName = "OH.Media.Codec.Decoder.Audio.Vorbis";
355 
356     int Channel_count_List[] = {1, 2};
357 
358     for (int i = 0; i < 2; i++)
359     {
360         Format format;
361         int Channel_count = Channel_count_List[i];
362         format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, Channel_count);
363         format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000);
364         format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000);
365         format.PutIntValue("bits_per_coded_sample", 4);
366 
367         string inputFile = "fltp_128k_48000_" + to_string(Channel_count) + "_dayuhaitang.ogg";
368         string outputFile = "FUNCTION_008_48000_" + to_string(Channel_count) + "_vorbis_output.pcm";
369 
370         decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
371     }
372     delete decoderDemo;
373 }
374 
375 /**
376  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_009
377  * @tc.name      : AAC different bitrate
378  * @tc.desc      : Function test
379  */
380 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_009, TestSize.Level2)
381 {
382     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
383     ASSERT_NE(nullptr, decoderDemo);
384 
385     string decoderName = "OH.Media.Codec.Decoder.Audio.AAC";
386 
387     int32_t bitrateList[] = {32000, 128000};
388     int32_t sample_rate_List[] = {16000, 44100};
389     string fileList[] = {"fltp_32k_16000_2_dayuhaitang.aac", "fltp_128k_44100_2_dayuhaitang.aac"};
390     for (int i = 0; i < 2; i++)
391     {
392         Format format;
393         int32_t bitrate = bitrateList[i];
394         int32_t sample_rate = sample_rate_List[i];
395         format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2);
396         format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, sample_rate);
397         format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, bitrate);
398         format.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1);
399 
400         string inputFile = fileList[i];
401         string outputFile = "FUNCTION_009_16000_2_" + to_string(bitrate) + "_aac_output.pcm";
402 
403         decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
404     }
405     delete decoderDemo;
406 }
407 
408 /**
409  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_010
410  * @tc.name      : mp3 different bitrate
411  * @tc.desc      : Function test
412  */
413 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_010, TestSize.Level2)
414 {
415     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
416     ASSERT_NE(nullptr, decoderDemo);
417 
418     string decoderName = "OH.Media.Codec.Decoder.Audio.Mpeg";
419 
420     int32_t bitrateList[] = {40000, 128000, 320000};
421 
422     for (int i = 0; i < 3; i++)
423     {
424         Format format;
425         int32_t bitrate = bitrateList[i];
426         format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2);
427         format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
428         format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, bitrate);
429 
430         string inputFile = "fltp_" + to_string((int)(bitrate/1000)) + "k_44100_2_dayuhaitang.mp3";
431         string outputFile = "FUNCTION_010_44100_2_" + to_string(bitrate) + "_mp3_output.pcm";
432 
433         decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
434     }
435     delete decoderDemo;
436 }
437 
438 /**
439  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_011
440  * @tc.name      : flac different bitrate
441  * @tc.desc      : Function test
442  */
443 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_011, TestSize.Level2)
444 {
445     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
446     ASSERT_NE(nullptr, decoderDemo);
447 
448     string decoderName = "OH.Media.Codec.Decoder.Audio.Flac";
449 
450     int32_t bitrateList[] = {195000, 780000};
451     int32_t sample_rate_List[] = {8000, 44100};
452     string fileList[] = {"s16_8000_2_dayuhaitang.flac", "s16_44100_2_dayuhaitang.flac"};
453     for (int i = 0; i < 2; i++)
454     {
455         Format format;
456         int32_t bitrate = bitrateList[i];
457         int32_t sample_rate = sample_rate_List[i];
458         format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2);
459         format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, sample_rate);
460         format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, bitrate);
461         format.PutIntValue("bits_per_coded_sample", 24);
462 
463         string inputFile = fileList[i];
464         string outputFile = "FUNCTION_011_"+ to_string(sample_rate) +"_2_" + to_string(bitrate) + "_flac_output.pcm";
465 
466         decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
467     }
468     delete decoderDemo;
469 }
470 
471 /**
472  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_012
473  * @tc.name      : MP3 different sample_format
474  * @tc.desc      : Function test
475  */
476 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_012, TestSize.Level2)
477 {
478     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
479     ASSERT_NE(nullptr, decoderDemo);
480 
481     string decoderName = "OH.Media.Codec.Decoder.Audio.Mpeg";
482 
483     string SampleFormatList[] = {"fltp", "s16p"};
484     for (int j = 0; j < 2; j++) {
485         Format format;
486         int32_t sample_rate = 48000;
487         string SampleFormat = SampleFormatList[j];
488         format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2);
489         format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, sample_rate);
490         format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000);
491 
492         string inputFile = SampleFormat + "_128k_"+to_string(sample_rate) + "_2_dayuhaitang.mp3";
493         string outputFile = "FUNCTION_012_" + SampleFormat + to_string(sample_rate) + "_2_" + "_mp3_output.pcm";
494 
495         decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
496     }
497 
498     delete decoderDemo;
499 }
500 
501 /**
502  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_013
503  * @tc.name      : flac different sample_format
504  * @tc.desc      : Function test
505  */
506 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_013, TestSize.Level2)
507 {
508     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
509     ASSERT_NE(nullptr, decoderDemo);
510 
511     string decoderName = "OH.Media.Codec.Decoder.Audio.Flac";
512 
513     string SampleFormatList[] = {"s32", "s16"};
514 
515     for (int j = 0; j < 2; j++) {
516         Format format;
517         int32_t sample_rate = 48000;
518         string SampleFormat = SampleFormatList[j];
519         format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2);
520         format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, sample_rate);
521         format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000);
522         format.PutIntValue("bits_per_coded_sample", 24);
523 
524         string inputFile = SampleFormat + "_"+to_string(sample_rate) + "_2_dayuhaitang.flac";
525         string outputFile = "FUNCTION_013_" + SampleFormat + to_string(sample_rate) + "_2_" + "_flac_output.pcm";
526 
527         decoderDemo->InnerRunCase(inputFile, outputFile, decoderName.c_str(), format);
528     }
529     delete decoderDemo;
530 }
531 
532 /**
533  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_014
534  * @tc.name      : aac flush
535  * @tc.desc      : Function test
536  */
537 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_014, TestSize.Level2)
538 {
539     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
540     string decoderName = "OH.Media.Codec.Decoder.Audio.AAC";
541 
542     string inputFile = "fltp_128k_16000_1_dayuhaitang.aac";
543 
544     Format format;
545     format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
546     format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 16000);
547     format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000);
548     format.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1);
549 
550     string firstOutputFile = "FUNCTION_014_16000_1_aac_output_1_flush.pcm";
551     string secondOutputFile = "FUNCTION_014_16000_1_aac_output_2_flush.pcm";
552 
553     decoderDemo->InnerRunCaseFlush(inputFile, firstOutputFile, secondOutputFile, decoderName.c_str(), format);
554 
555     bool isSame = compareFile(firstOutputFile, secondOutputFile);
556     ASSERT_EQ(true, isSame);
557 
558     delete decoderDemo;
559 }
560 
561 /**
562  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_015
563  * @tc.name      : MP3 flush
564  * @tc.desc      : Function test
565  */
566 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_015, TestSize.Level2)
567 {
568     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
569     string decoderName = "OH.Media.Codec.Decoder.Audio.Mpeg";
570 
571     string inputFile = "fltp_128k_44100_2_dayuhaitang.mp3";
572     string firstOutputFile = "FUNCTION_015_1_flush.pcm";
573     string secondOutputFile = "FUNCTION_015_2_flush.pcm";
574 
575     Format format;
576     format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2);
577     format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
578     format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000);
579 
580     decoderDemo->InnerRunCaseFlush(inputFile, firstOutputFile, secondOutputFile, decoderName.c_str(), format);
581     bool isSame = compareFile(firstOutputFile, secondOutputFile);
582     ASSERT_EQ(true, isSame);
583     delete decoderDemo;
584 }
585 
586 /**
587  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_016
588  * @tc.name      : Flac flush
589  * @tc.desc      : Function test
590  */
591 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_016, TestSize.Level2)
592 {
593     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
594     string decoderName = "OH.Media.Codec.Decoder.Audio.Flac";
595 
596     string inputFile = "s16_8000_2_dayuhaitang.flac";
597     string firstOutputFile = "FUNCTION_016_1_flush.pcm";
598     string secondOutputFile = "FUNCTION_016_2_flush.pcm";
599 
600     Format format;
601     format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2);
602     format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 8000);
603     format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 40000);
604     format.PutIntValue("bits_per_coded_sample", 24);
605 
606     decoderDemo->InnerRunCaseFlush(inputFile, firstOutputFile, secondOutputFile, decoderName.c_str(), format);
607     bool isSame = compareFile(firstOutputFile, secondOutputFile);
608     ASSERT_EQ(true, isSame);
609     delete decoderDemo;
610 }
611 
612 /**
613  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_017
614  * @tc.name      : Vorbis flush
615  * @tc.desc      : Function test
616  */
617 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_017, TestSize.Level2)
618 {
619     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
620     string decoderName = "OH.Media.Codec.Decoder.Audio.Vorbis";
621 
622     string inputFile = "fltp_45k_8000_2_dayuhaitang.ogg";
623     string firstOutputFile = "FUNCTION_017_1_flush.pcm";
624     string secondOutputFile = "FUNCTION_017_2_flush.pcm";
625 
626     Format format;
627     format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2);
628     format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 8000);
629     format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 45000);
630 
631     decoderDemo->InnerRunCaseFlush(inputFile, firstOutputFile, secondOutputFile, decoderName.c_str(), format);
632     bool isSame = compareFile(firstOutputFile, secondOutputFile);
633     ASSERT_EQ(true, isSame);
634     delete decoderDemo;
635 }
636 
637 /**
638  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_018
639  * @tc.name      : aac reset
640  * @tc.desc      : Function test
641  */
642 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_018, TestSize.Level2)
643 {
644     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
645     string decoderName = "OH.Media.Codec.Decoder.Audio.AAC";
646 
647     Format format;
648     format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
649     format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 16000);
650     format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000);
651     format.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1);
652 
653     string inputFile = "fltp_128k_16000_1_dayuhaitang.aac";
654     string firstOutputFile = "FUNCTION_018_16000_1_aac_output_1_reset.pcm";
655     string secondOutputFile = "FUNCTION_018_16000_1_aac_output_2_reset.pcm";
656 
657     decoderDemo->InnerRunCaseReset(inputFile, firstOutputFile, secondOutputFile, decoderName.c_str(), format);
658     bool isSame = compareFile(firstOutputFile, secondOutputFile);
659     ASSERT_EQ(true, isSame);
660     delete decoderDemo;
661 }
662 
663 /**
664  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_019
665  * @tc.name      : mp3 reset
666  * @tc.desc      : Function test
667  */
668 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_019, TestSize.Level2)
669 {
670     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
671     string decoderName = "OH.Media.Codec.Decoder.Audio.Mpeg";
672 
673     string inputFile = "fltp_128k_44100_2_dayuhaitang.mp3";
674     string firstOutputFile = "FUNCTION_019_1_reset.pcm";
675     string secondOutputFile = "FUNCTION_019_2_reset.pcm";
676 
677     Format format;
678     format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2);
679     format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
680     format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000);
681 
682     decoderDemo->InnerRunCaseReset(inputFile, firstOutputFile, secondOutputFile, decoderName.c_str(), format);
683     bool isSame = compareFile(firstOutputFile, secondOutputFile);
684     ASSERT_EQ(true, isSame);
685 
686     delete decoderDemo;
687 }
688 
689 /**
690  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_020
691  * @tc.name      : Flac reset
692  * @tc.desc      : Function test
693  */
694 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_020, TestSize.Level2)
695 {
696     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
697     string decoderName = "OH.Media.Codec.Decoder.Audio.Flac";
698 
699     string inputFile = "s16_44100_2_dayuhaitang.flac";
700     string firstOutputFile = "FUNCTION_020_1_reset.pcm";
701     string secondOutputFile = "FUNCTION_020_2_reset.pcm";
702 
703     Format format;
704     format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2);
705     format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
706     format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000);
707     format.PutIntValue("bits_per_coded_sample", 24);
708 
709     decoderDemo->InnerRunCaseReset(inputFile, firstOutputFile, secondOutputFile, decoderName.c_str(), format);
710 
711     bool isSame = compareFile(firstOutputFile, secondOutputFile);
712     ASSERT_EQ(true, isSame);
713 
714     delete decoderDemo;
715 }
716 /**
717  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_021
718  * @tc.name      : Vorbis reset
719  * @tc.desc      : Function test
720  */
721 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_021, TestSize.Level2)
722 {
723     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
724     string decoderName = "OH.Media.Codec.Decoder.Audio.Vorbis";
725 
726     string inputFile = "fltp_128k_48000_1_dayuhaitang.ogg";
727     string firstOutputFile = "FUNCTION_021_1.pcm";
728     string secondOutputFile = "FUNCTION_021_2.pcm";
729 
730     Format format;
731     format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
732     format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000);
733     format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000);
734 
735     decoderDemo->InnerRunCaseReset(inputFile, firstOutputFile, secondOutputFile, decoderName.c_str(), format);
736 
737     bool isSame = compareFile(firstOutputFile, secondOutputFile);
738     ASSERT_EQ(true, isSame);
739 
740     delete decoderDemo;
741 }
742 
743 /**
744  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_022
745  * @tc.name      : AAC(thread)
746  * @tc.desc      : Function test
747  */
748 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_022, TestSize.Level2)
749 {
750     vector<thread> threadVec;
751     string decoderName = "OH.Media.Codec.Decoder.Audio.AAC";
752 
753     string inputFile = "fltp_128k_16000_1_dayuhaitang.aac";
754 
755     for (int32_t i = 0; i < 16; i++)
756     {
757         string outputFile = "FUNCTION_022_" + to_string(i) + ".pcm";
758         threadVec.push_back(thread(runDecode, decoderName, inputFile, outputFile, i));
759     }
760     for (uint32_t i = 0; i < threadVec.size(); i++)
761     {
762         threadVec[i].join();
763     }
764     for (int32_t i = 0; i < 10; i++)
765     {
766         ASSERT_EQ(AVCS_ERR_OK, testResult[i]);
767     }
768 }
769 
770 
771 /**
772  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_023
773  * @tc.name      : MP3(thread)
774  * @tc.desc      : Function test
775  */
776 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_023, TestSize.Level2)
777 {
778     vector<thread> threadVec;
779     string decoderName = "OH.Media.Codec.Decoder.Audio.Mpeg";
780 
781     string inputFile = "fltp_128k_44100_2_dayuhaitang.mp3";
782 
783     for (int32_t i = 0; i < 16; i++)
784     {
785         string outputFile = "FUNCTION_023_" + to_string(i) + ".pcm";
786         threadVec.push_back(thread(runDecode, decoderName, inputFile, outputFile, i));
787     }
788     for (uint32_t i = 0; i < threadVec.size(); i++)
789     {
790         threadVec[i].join();
791     }
792     for (int32_t i = 0; i < 10; i++)
793     {
794         ASSERT_EQ(AVCS_ERR_OK, testResult[i]);
795     }
796 }
797 
798 
799 /**
800  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_024
801  * @tc.name      : Flac(thread)
802  * @tc.desc      : Function test
803  */
804 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_024, TestSize.Level2)
805 {
806     vector<thread> threadVec;
807     string decoderName = "OH.Media.Codec.Decoder.Audio.Flac";
808 
809     string inputFile = "s16_44100_2_dayuhaitang.flac";
810 
811     for (int32_t i = 0; i < 16; i++)
812     {
813         string outputFile = "FUNCTION_024_" + to_string(i) + ".pcm";
814         threadVec.push_back(thread(runDecode, decoderName, inputFile, outputFile, i));
815     }
816     for (uint32_t i = 0; i < threadVec.size(); i++)
817     {
818         threadVec[i].join();
819     }
820     for (int32_t i = 0; i < 10; i++)
821     {
822         ASSERT_EQ(AVCS_ERR_OK, testResult[i]);
823     }
824 }
825 
826 
827 /**
828  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_025
829  * @tc.name      : Vorbis(thread)
830  * @tc.desc      : Function test
831  */
832 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_DECODER_FUNCTION_025, TestSize.Level2)
833 {
834     vector<thread> threadVec;
835     string decoderName = "OH.Media.Codec.Decoder.Audio.Vorbis";
836 
837     string inputFile = "fltp_45k_48000_2_dayuhaitang.ogg";
838 
839     for (int32_t i = 0; i < 16; i++)
840     {
841         string outputFile = "FUNCTION_025_" + to_string(i) + ".pcm";
842         threadVec.push_back(thread(runDecode, decoderName, inputFile, outputFile, i));
843     }
844     for (uint32_t i = 0; i < threadVec.size(); i++)
845     {
846         threadVec[i].join();
847     }
848     for (int32_t i = 0; i < 10; i++)
849     {
850         ASSERT_EQ(AVCS_ERR_OK, testResult[i]);
851     }
852 }