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 "AudioEncoderDemoCommon.h"
20 #include "avcodec_errors.h"
21 #include "avcodec_common.h"
22 #include "media_description.h"
23 #include "securec.h"
24 #include "avcodec_audio_common.h"
25 #include "libavcodec/avcodec.h"
26 #include "libavformat/avformat.h"
27 #include "libavutil/imgutils.h"
28 #include "libavutil/samplefmt.h"
29 #include "libavutil/timestamp.h"
30
31 using namespace std;
32 using namespace testing::ext;
33 using namespace OHOS;
34 using namespace OHOS::MediaAVCodec;
35 constexpr uint32_t SAMPLE_RATE_16000 = 16000;
36 constexpr uint32_t SAMPLE_RATE_128000 = 128000;
37 constexpr uint32_t SAMPLE_RATE_112000 = 112000;
38 constexpr uint32_t CHANNEL_COUNT = 2;
39 constexpr uint32_t CHANNEL_COUNT_2 = -2;
40 int32_t testResult[10] = { -1 };
41
42 namespace {
43 class InnerFunctionTest : public testing::Test {
44 public:
45 static void SetUpTestCase();
46 static void TearDownTestCase();
47 void SetUp() override;
48 void TearDown() override;
49 };
50
SetUpTestCase()51 void InnerFunctionTest::SetUpTestCase() {}
TearDownTestCase()52 void InnerFunctionTest::TearDownTestCase() {}
SetUp()53 void InnerFunctionTest::SetUp() {}
TearDown()54 void InnerFunctionTest::TearDown() {}
55
runEncode(string encoderName, string inputFile, string outputFile, int32_t threadId)56 void runEncode(string encoderName, string inputFile, string outputFile, int32_t threadId)
57 {
58 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo();
59 if (encoderName == "OH.Media.Codec.Encoder.Audio.AAC") {
60 Format format;
61 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
62 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_16000);
63 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_128000);
64 format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
65 format.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
66 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
67 format.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1);
68 encoderDemo->InnerRunCase(inputFile, outputFile, encoderName.c_str(), format);
69 } else if (encoderName == "OH.Media.Codec.Encoder.Audio.Flac") {
70 Format format;
71 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
72 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_16000);
73 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_112000);
74 format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_S32LE);
75 format.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_S32LE);
76 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, STEREO);
77 format.PutIntValue(MediaDescriptionKey::MD_KEY_COMPLIANCE_LEVEL, CHANNEL_COUNT_2);
78
79 encoderDemo->InnerRunCase(inputFile, outputFile, encoderName.c_str(), format);
80 }
81 testResult[threadId] = AVCS_ERR_OK;
82 delete encoderDemo;
83 }
84 }
85
86 /**
87 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_001
88 * @tc.name : aac(different sample rate)
89 * @tc.desc : Function test
90 */
HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_001, TestSize.Level2)91 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_001, TestSize.Level2)
92 {
93 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo();
94 ASSERT_NE(nullptr, encoderDemo);
95
96 string encoderName = "OH.Media.Codec.Encoder.Audio.AAC";
97
98 int32_t sample_rate_List[] = {7350, 8000, 16000, 44100, 48000, 96000};
99
100 for (int i = 0; i < 6; i++)
101 {
102 Format format;
103 int sample_rate = sample_rate_List[i];
104 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
105 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, sample_rate);
106 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_128000);
107 format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
108 format.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
109 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
110 format.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1);
111
112 string inputFile = "f32le_" + to_string(sample_rate) + "_1_dayuhaitang.pcm";
113 string outputFile = "FUNCTION_001_" + to_string(sample_rate) + "_1_output.aac";
114
115 cout << "inputFile " << inputFile << endl;
116 encoderDemo->InnerRunCase(inputFile, outputFile, encoderName.c_str(), format);
117 }
118 delete encoderDemo;
119 }
120
121
122 /**
123 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_002
124 * @tc.name : AAC different Channel_count
125 * @tc.desc : Function test
126 */
HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_002, TestSize.Level2)127 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_002, TestSize.Level2)
128 {
129 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo();
130 ASSERT_NE(nullptr, encoderDemo);
131
132 string encoderName = "OH.Media.Codec.Encoder.Audio.AAC";
133
134 int Channel_count_List[] = {1, 2, 8};
135
136 for (int i = 0; i < 3; i++)
137 {
138 Format format;
139 int Channel_count = Channel_count_List[i];
140 switch (Channel_count)
141 {
142 case 1:
143 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
144 break;
145 case 2:
146 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, STEREO);
147 break;
148 case 8:
149 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, CH_7POINT1);
150 break;
151 default:
152 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, UNKNOWN_CHANNEL_LAYOUT);
153 break;
154 }
155
156 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, Channel_count);
157 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_16000);
158 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_128000);
159 format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
160 format.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
161 format.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1);
162
163 string inputFile = "f32le_16000_" + to_string(Channel_count) + "_dayuhaitang.pcm";
164 string outputFile = "FUNCTION_002_16000_" + to_string(Channel_count) + "_output.aac";
165
166 cout << "inputFile " << inputFile << endl;
167 encoderDemo->InnerRunCase(inputFile, outputFile, encoderName.c_str(), format);
168 }
169 delete encoderDemo;
170 }
171
172 /**
173 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_003
174 * @tc.name : AAC different bitrate
175 * @tc.desc : Function test
176 */
HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_003, TestSize.Level2)177 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_003, TestSize.Level2)
178 {
179 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo();
180 ASSERT_NE(nullptr, encoderDemo);
181
182 string encoderName = "OH.Media.Codec.Encoder.Audio.AAC";
183
184 int32_t bitrateList[] = {32000, 96000, 128000, 256000, 300000, 500000};
185
186 for (int i = 0; i < 6; i++)
187 {
188 Format format;
189 int32_t bitrate = bitrateList[i];
190
191 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
192 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_16000);
193 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, bitrate);
194 format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
195 format.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
196 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
197 format.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1);
198
199 string inputFile = "f32le_16000_1_dayuhaitang.pcm";
200 string outputFile = "FUNCTION_003_16000_1_" + to_string((int)(bitrate/1000)) + "k_output.aac";
201
202 cout << "inputFile " << inputFile << endl;
203 encoderDemo->InnerRunCase(inputFile, outputFile, encoderName.c_str(), format);
204 }
205 delete encoderDemo;
206 }
207
208 /**
209 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_004
210 * @tc.name : FLAC(different sample rate)
211 * @tc.desc : Function test
212 */
HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_004, TestSize.Level2)213 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_004, TestSize.Level2)
214 {
215 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo();
216 ASSERT_NE(nullptr, encoderDemo);
217
218 string encoderName = "OH.Media.Codec.Encoder.Audio.Flac";
219
220 int32_t sample_rate_List[] = {8000, 16000, 44100, 48000, 96000};
221
222 for (int i = 0; i < 5; i++)
223 {
224 Format format;
225 int32_t sample_rate = sample_rate_List[i];
226 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
227 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, sample_rate);
228 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 50000);
229 format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_S32LE);
230 format.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_S32LE);
231 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, STEREO);
232 format.PutIntValue(MediaDescriptionKey::MD_KEY_COMPLIANCE_LEVEL, -2);
233
234 string inputFile = "s16_" + to_string(sample_rate) + "_2_dayuhaitang.pcm";
235 string outputFile = "FUNCTION_004_" + to_string(sample_rate) + "_2_output.flac";
236
237 cout << "inputFile " << inputFile << endl;
238 encoderDemo->InnerRunCase(inputFile, outputFile, encoderName.c_str(), format);
239 }
240 delete encoderDemo;
241 }
242
243
244 /**
245 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_005
246 * @tc.name : flac different format
247 * @tc.desc : Function test
248 */
HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_005, TestSize.Level2)249 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_005, TestSize.Level2)
250 {
251 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo();
252 ASSERT_NE(nullptr, encoderDemo);
253
254 string encoderName = "OH.Media.Codec.Encoder.Audio.Flac";
255
256 string formatList[] = { "s16", "s32" };
257 uint32_t sample_format;
258 for (int i = 0; i < 2; i++)
259 {
260 Format format;
261 string sample_Media::FORMAT_TYPE = formatList[i];
262 if (sample_Media::FORMAT_TYPE == "s16") {
263 sample_format = AudioSampleFormat::SAMPLE_S16LE;
264 }
265 if (sample_Media::FORMAT_TYPE == "s32") {
266 sample_format = AudioSampleFormat::SAMPLE_S32LE;
267 }
268 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
269 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000);
270 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 50000);
271 format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, sample_format);
272 format.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, sample_format);
273 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, STEREO);
274 format.PutIntValue(MediaDescriptionKey::MD_KEY_COMPLIANCE_LEVEL, -2);
275
276 string inputFile = sample_Media::FORMAT_TYPE + "_48000_2_dayuhaitang.pcm";
277 string outputFile = "FUNCTION_005_48000_2_1536k_" + sample_Media::FORMAT_TYPE + "_output.flac";
278
279 cout << "inputFile " << inputFile << endl;
280 encoderDemo->InnerRunCase(inputFile, outputFile, encoderName.c_str(), format);
281 }
282 delete encoderDemo;
283 }
284
285 /**
286 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_006
287 * @tc.name : flac different Channel_count
288 * @tc.desc : Function test
289 */
HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_006, TestSize.Level2)290 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_006, TestSize.Level2)
291 {
292 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo();
293 ASSERT_NE(nullptr, encoderDemo);
294
295 string encoderName = "OH.Media.Codec.Encoder.Audio.Flac";
296
297 int Channel_count_List[] = { 1, 2, 8};
298
299 for (int i = 0; i < 3; i++)
300 {
301 Format format;
302 int32_t Channel_count = Channel_count_List[i];
303
304 switch (Channel_count)
305 {
306 case 1:
307 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
308 break;
309 case 2:
310 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, STEREO);
311 break;
312 case 8:
313 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, CH_7POINT1);
314 break;
315 default:
316 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, UNKNOWN_CHANNEL_LAYOUT);
317 break;
318 }
319
320 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, Channel_count);
321 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000);
322 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 50000);
323 format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_S32LE);
324 format.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_S32LE);
325 format.PutIntValue(MediaDescriptionKey::MD_KEY_COMPLIANCE_LEVEL, -2);
326
327 string inputFile = "s16_48000_" + to_string(Channel_count) + "_dayuhaitang.pcm";
328 string outputFile = "FUNCTION_006_48000_" + to_string(Channel_count) + "_output.flac";
329
330 cout << "inputFile " << inputFile << endl;
331 encoderDemo->InnerRunCase(inputFile, outputFile, encoderName.c_str(), format);
332 }
333 delete encoderDemo;
334 }
335
336 /**
337 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_007
338 * @tc.name : aac flush
339 * @tc.desc : Function test
340 */
HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_007, TestSize.Level2)341 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_007, TestSize.Level2)
342 {
343 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo();
344 ASSERT_NE(nullptr, encoderDemo);
345
346 string encoderName = "OH.Media.Codec.Encoder.Audio.AAC";
347
348 string inputFile = "f32le_44100_1_dayuhaitang.pcm";
349 string firstOutputFile = "FUNCTION_007_InnerFlush1.aac";
350 string secondOutputFile = "FUNCTION_007_InnerFlush2.aac";
351
352 Format format;
353 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
354 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
355 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_112000);
356 format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
357 format.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
358 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
359 format.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1);
360
361 cout << "inputFile " << inputFile << endl;
362 encoderDemo->InnerRunCaseFlush(inputFile, firstOutputFile, secondOutputFile, encoderName.c_str(), format);
363
364 delete encoderDemo;
365 }
366
367 /**
368 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_008
369 * @tc.name : aac reset
370 * @tc.desc : Function test
371 */
HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_008, TestSize.Level2)372 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_008, TestSize.Level2)
373 {
374 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo();
375 ASSERT_NE(nullptr, encoderDemo);
376
377 string encoderName = "OH.Media.Codec.Encoder.Audio.AAC";
378
379 string inputFile = "f32le_44100_1_dayuhaitang.pcm";
380 string firstOutputFile = "FUNCTION_008_InnerReset1.aac";
381 string secondOutputFile = "FUNCTION_008_InnerReset2.aac";
382
383 Format format;
384 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
385 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
386 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 112000);
387 format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
388 format.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
389 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
390 format.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1);
391
392 cout << "inputFile " << inputFile << endl;
393 encoderDemo->InnerRunCaseReset(inputFile, firstOutputFile, secondOutputFile, encoderName.c_str(), format);
394
395 delete encoderDemo;
396 }
397
398 /**
399 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_009
400 * @tc.name : flac flush
401 * @tc.desc : Function test
402 */
HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_009, TestSize.Level2)403 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_009, TestSize.Level2)
404 {
405 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo();
406 ASSERT_NE(nullptr, encoderDemo);
407
408 string encoderName = "OH.Media.Codec.Encoder.Audio.Flac";
409
410 string inputFile = "s16_44100_2_dayuhaitang.pcm";
411 string firstOutputFile = "FUNCTION_009_InnerFlush1.flac";
412 string secondOutputFile = "FUNCTION_009_InnerFlush2.flac";
413
414
415 Format format;
416 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
417 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
418 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_112000);
419 format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_S32LE);
420 format.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_S32LE);
421 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, STEREO);
422 format.PutIntValue(MediaDescriptionKey::MD_KEY_COMPLIANCE_LEVEL, -2);
423
424 cout << "inputFile " << inputFile << endl;
425 encoderDemo->InnerRunCaseFlush(inputFile, firstOutputFile, secondOutputFile, encoderName.c_str(), format);
426
427 delete encoderDemo;
428 }
429
430 /**
431 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_010
432 * @tc.name : flac reset
433 * @tc.desc : Function test
434 */
HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_010, TestSize.Level2)435 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_010, TestSize.Level2)
436 {
437 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo();
438 ASSERT_NE(nullptr, encoderDemo);
439
440 string encoderName = "OH.Media.Codec.Encoder.Audio.Flac";
441
442 string inputFile = "s16_44100_2_dayuhaitang.pcm";
443 string firstOutputFile = "FUNCTION_010_InnerReset1.flac";
444 string secondOutputFile = "FUNCTION_010_InnerReset2.flac";
445
446 Format format;
447 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
448 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 44100);
449 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_112000);
450 format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_S32LE);
451 format.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_S32LE);
452 format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, STEREO);
453 format.PutIntValue(MediaDescriptionKey::MD_KEY_COMPLIANCE_LEVEL, -2);
454
455 cout << "inputFile " << inputFile << endl;
456 encoderDemo->InnerRunCaseReset(inputFile, firstOutputFile, secondOutputFile, encoderName.c_str(), format);
457
458 delete encoderDemo;
459 }
460
461 /**
462 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_011
463 * @tc.name : AAC(thread)
464 * @tc.desc : Function test
465 */
HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_011, TestSize.Level2)466 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_011, TestSize.Level2)
467 {
468 vector<thread> threadVec;
469 string decoderName = "OH.Media.Codec.Encoder.Audio.AAC";
470
471 string inputFile = "f32le_16000_1_dayuhaitang.pcm";
472
473 for (int32_t i = 0; i < 16; i++)
474 {
475 string outputFile = "FUNCTION_011_" + to_string(i) + ".aac";
476 threadVec.push_back(thread(runEncode, decoderName, inputFile, outputFile, i));
477 }
478 for (uint32_t i = 0; i < threadVec.size(); i++)
479 {
480 threadVec[i].join();
481 }
482 for (int32_t i = 0; i < 10; i++)
483 {
484 ASSERT_EQ(AVCS_ERR_OK, testResult[i]);
485 }
486 }
487
488 /**
489 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_012
490 * @tc.name : Flac(thread)
491 * @tc.desc : Function test
492 */
HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_012, TestSize.Level2)493 HWTEST_F(InnerFunctionTest, SUB_MULTIMEDIA_AUDIO_ENCODER_FUNCTION_012, TestSize.Level2)
494 {
495 vector<thread> threadVec;
496 string decoderName = "OH.Media.Codec.Encoder.Audio.Flac";
497
498 string inputFile = "s16_16000_2_dayuhaitang.pcm";
499
500 for (int i = 0; i < 16; i++)
501 {
502 string outputFile = "FUNCTION_012_" + to_string(i) + ".flac";
503 threadVec.push_back(thread(runEncode, decoderName, inputFile, outputFile, i));
504 }
505 for (uint32_t i = 0; i < threadVec.size(); i++)
506 {
507 threadVec[i].join();
508 }
509 for (int32_t i = 0; i < 10; i++)
510 {
511 ASSERT_EQ(AVCS_ERR_OK, testResult[i]);
512 }
513 }
514