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 <atomic>
16 #include <iostream>
17 #include <fstream>
18 #include <queue>
19 #include <string>
20 #include <thread>
21 #include "gtest/gtest.h"
22 #include "avcodec_audio_avbuffer_encoder_demo.h"
23 
24 using namespace std;
25 using namespace testing::ext;
26 using namespace OHOS;
27 using namespace OHOS::MediaAVCodec;
28 using namespace OHOS::MediaAVCodec::AudioAacEncDemo;
29 
30 namespace {
31 class ParamCheckTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37 };
38 
SetUpTestCase()39 void ParamCheckTest::SetUpTestCase() {}
TearDownTestCase()40 void ParamCheckTest::TearDownTestCase() {}
SetUp()41 void ParamCheckTest::SetUp() {}
TearDown()42 void ParamCheckTest::TearDown() {}
43 
44 } // namespace
45 
46 /**
47  * @tc.number    : PARAM_CHECK_001
48  * @tc.name      : CreateByMime - mime param check
49  * @tc.desc      : param check test
50  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_001, TestSize.Level2)51 HWTEST_F(ParamCheckTest, PARAM_CHECK_001, TestSize.Level2)
52 {
53     OH_AVCodec *codec = nullptr;
54     OH_AVErrCode result0;
55     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
56     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
57     ASSERT_NE(codec, nullptr);
58     result0 = audioBufferAacEncDemo->Destroy(codec);
59     ASSERT_EQ(result0, AV_ERR_OK);
60 
61     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
62     ASSERT_NE(codec, nullptr);
63     result0 = audioBufferAacEncDemo->Destroy(codec);
64     ASSERT_EQ(result0, AV_ERR_OK);
65 
66     codec = audioBufferAacEncDemo->CreateByMime("aaa");
67     ASSERT_EQ(codec, nullptr);
68     result0 = audioBufferAacEncDemo->Destroy(codec);
69     ASSERT_NE(result0, AV_ERR_OK);
70 
71     delete audioBufferAacEncDemo;
72 }
73 
74 /**
75  * @tc.number    : PARAM_CHECK_002
76  * @tc.name      : CreateByName - mime param check
77  * @tc.desc      : param check test
78  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_002, TestSize.Level2)79 HWTEST_F(ParamCheckTest, PARAM_CHECK_002, TestSize.Level2)
80 {
81     OH_AVCodec *codec = nullptr;
82     OH_AVErrCode result0;
83     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
84     codec = audioBufferAacEncDemo->CreateByName("OH.Media.Codec.Encoder.Audio.AAC");
85     ASSERT_NE(codec, nullptr);
86     result0 = audioBufferAacEncDemo->Destroy(codec);
87     ASSERT_EQ(result0, AV_ERR_OK);
88 
89     codec = audioBufferAacEncDemo->CreateByName("OH.Media.Codec.Encoder.Audio.G711mu");
90     ASSERT_NE(codec, nullptr);
91     result0 = audioBufferAacEncDemo->Destroy(codec);
92     ASSERT_EQ(result0, AV_ERR_OK);
93 
94     codec = audioBufferAacEncDemo->CreateByName("aaa");
95     ASSERT_EQ(codec, nullptr);
96     result0 = audioBufferAacEncDemo->Destroy(codec);
97     ASSERT_NE(result0, AV_ERR_OK);
98 
99     delete audioBufferAacEncDemo;
100 }
101 
102 /**
103  * @tc.number    : PARAM_CHECK_003
104  * @tc.name      : Configure - channel(OH_AVCODEC_MIMETYPE_AUDIO_G711MU) param check
105  * @tc.desc      : param check test
106  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_003, TestSize.Level2)107 HWTEST_F(ParamCheckTest, PARAM_CHECK_003, TestSize.Level2)
108 {
109     OH_AVCodec *codec = nullptr;
110     OH_AVFormat *format = OH_AVFormat_Create();
111     int32_t channel = 1; //channel1
112     int32_t sampleRate = 8000;  // 8000hz
113     int64_t bitRate = 64000; //64K
114     int32_t sampleFormat = SAMPLE_S16LE;
115     int32_t sampleBit = 16;
116     int32_t complexity = 10;
117     OH_AVErrCode result0;
118     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
119     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
120     result0 = audioBufferAacEncDemo->SetCallback(codec);
121     channel = 1;
122     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
123                                                complexity);
124     ASSERT_EQ(result0, AV_ERR_OK);
125     result0 = audioBufferAacEncDemo->Destroy(codec);
126 
127     format = OH_AVFormat_Create();
128     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
129     result0 = audioBufferAacEncDemo->SetCallback(codec);
130     channel = 2;
131     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
132                                                complexity);
133     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
134     result0 = audioBufferAacEncDemo->Destroy(codec);
135 
136     format = OH_AVFormat_Create();
137     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
138     result0 = audioBufferAacEncDemo->SetCallback(codec);
139     channel = 0;
140     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
141                                                complexity);
142     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
143     result0 = audioBufferAacEncDemo->Destroy(codec);
144 
145     format = OH_AVFormat_Create();
146     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
147     result0 = audioBufferAacEncDemo->SetCallback(codec);
148     channel = 3;
149     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
150                                                complexity);
151     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
152     result0 = audioBufferAacEncDemo->Destroy(codec);
153 
154     delete audioBufferAacEncDemo;
155 }
156 
157 /**
158  * @tc.number    : PARAM_CHECK_004
159  * @tc.name      : Configure - sampleRate(OH_AVCODEC_MIMETYPE_AUDIO_G711MU) param check
160  * @tc.desc      : param check test
161  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_004, TestSize.Level2)162 HWTEST_F(ParamCheckTest, PARAM_CHECK_004, TestSize.Level2)
163 {
164     OH_AVCodec *codec = nullptr;
165     OH_AVFormat *format = OH_AVFormat_Create();
166     int32_t channel = 1; //channel1
167     int32_t sampleRate = 8000;  // 8000hz
168     int64_t bitRate = 64000; //64K
169     int32_t sampleFormat = SAMPLE_S16LE;
170     int32_t sampleBit = 16;
171     int32_t complexity = 10;
172     OH_AVErrCode result0;
173     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
174     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
175     result0 = audioBufferAacEncDemo->SetCallback(codec);
176     sampleRate = 8000;
177     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
178                                                complexity);
179     ASSERT_EQ(result0, AV_ERR_OK);
180     result0 = audioBufferAacEncDemo->Destroy(codec);
181 
182     format = OH_AVFormat_Create();
183     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
184     result0 = audioBufferAacEncDemo->SetCallback(codec);
185     sampleRate = 12000;
186     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
187                                                complexity);
188     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
189     result0 = audioBufferAacEncDemo->Destroy(codec);
190 
191     format = OH_AVFormat_Create();
192     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
193     result0 = audioBufferAacEncDemo->SetCallback(codec);
194     sampleRate = 16000;
195     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
196                                                complexity);
197     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
198     result0 = audioBufferAacEncDemo->Destroy(codec);
199 
200     format = OH_AVFormat_Create();
201     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
202     result0 = audioBufferAacEncDemo->SetCallback(codec);
203     sampleRate = 24000;
204     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
205                                                complexity);
206     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
207     result0 = audioBufferAacEncDemo->Destroy(codec);
208 
209     format = OH_AVFormat_Create();
210     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
211     result0 = audioBufferAacEncDemo->SetCallback(codec);
212     sampleRate = 48000;
213     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
214                                                complexity);
215     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
216     result0 = audioBufferAacEncDemo->Destroy(codec);
217 
218     format = OH_AVFormat_Create();
219     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
220     result0 = audioBufferAacEncDemo->SetCallback(codec);
221     sampleRate = 7999;
222     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
223                                                complexity);
224     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
225     result0 = audioBufferAacEncDemo->Destroy(codec);
226 
227     format = OH_AVFormat_Create();
228     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
229     result0 = audioBufferAacEncDemo->SetCallback(codec);
230     sampleRate = 48001;
231     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
232                                                complexity);
233     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
234     result0 = audioBufferAacEncDemo->Destroy(codec);
235 
236     delete audioBufferAacEncDemo;
237 }
238 
239 /**
240  * @tc.number    : PARAM_CHECK_005
241  * @tc.name      : Configure - bitRate(OH_AVCODEC_MIMETYPE_AUDIO_G711MU) param check
242  * @tc.desc      : param check test
243  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_005, TestSize.Level2)244 HWTEST_F(ParamCheckTest, PARAM_CHECK_005, TestSize.Level2)
245 {
246     OH_AVCodec *codec = nullptr;
247     OH_AVFormat *format = OH_AVFormat_Create();
248     int32_t channel = 1; //channel1
249     int32_t sampleRate = 8000;  // 8000hz
250     int64_t bitRate = 64000; //64K
251     int32_t sampleFormat = SAMPLE_S16LE;
252     int32_t sampleBit = 16;
253     int32_t complexity = 10;
254     OH_AVErrCode result0;
255     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
256     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
257     result0 = audioBufferAacEncDemo->SetCallback(codec);
258     bitRate = 8000;
259     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
260                                                complexity);
261     ASSERT_EQ(result0, AV_ERR_OK);
262     result0 = audioBufferAacEncDemo->Destroy(codec);
263 
264     format = OH_AVFormat_Create();
265     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
266     result0 = audioBufferAacEncDemo->SetCallback(codec);
267     bitRate = 48000;
268     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
269                                                complexity);
270     ASSERT_EQ(result0, AV_ERR_OK);
271     result0 = audioBufferAacEncDemo->Destroy(codec);
272 
273     delete audioBufferAacEncDemo;
274 }
275 
276 /**
277  * @tc.number    : PARAM_CHECK_006
278  * @tc.name      : Configure - sampleFormat(OH_AVCODEC_MIMETYPE_AUDIO_G711MU) param check
279  * @tc.desc      : param check test
280  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_006, TestSize.Level2)281 HWTEST_F(ParamCheckTest, PARAM_CHECK_006, TestSize.Level2)
282 {
283     OH_AVCodec *codec = nullptr;
284     OH_AVFormat *format = OH_AVFormat_Create();
285     int32_t channel = 1; //channel1
286     int32_t sampleRate = 8000;  // 8000hz
287     int64_t bitRate = 64000; //64K
288     int32_t sampleFormat = SAMPLE_S16LE;
289     int32_t sampleBit = 16;
290     int32_t complexity = 10;
291     OH_AVErrCode result0;
292     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
293     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
294     result0 = audioBufferAacEncDemo->SetCallback(codec);
295     sampleFormat = SAMPLE_S16LE;
296     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
297                                                complexity);
298     ASSERT_EQ(result0, AV_ERR_OK);
299     result0 = audioBufferAacEncDemo->Destroy(codec);
300 
301     delete audioBufferAacEncDemo;
302 }
303 
304 /**
305  * @tc.number    : PARAM_CHECK_007
306  * @tc.name      : Configure - complexity(OH_AVCODEC_MIMETYPE_AUDIO_G711MU) param check
307  * @tc.desc      : param check test
308  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_007, TestSize.Level2)309 HWTEST_F(ParamCheckTest, PARAM_CHECK_007, TestSize.Level2)
310 {
311     OH_AVCodec *codec = nullptr;
312     OH_AVFormat *format = OH_AVFormat_Create();
313     int32_t channel = 1; //channel1
314     int32_t sampleRate = 8000;  // 8000hz
315     int64_t bitRate = 64000; //64K
316     int32_t sampleFormat = SAMPLE_S16LE;
317     int32_t sampleBit = 16;
318     int32_t complexity = 10;
319     OH_AVErrCode result0;
320     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
321     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
322     result0 = audioBufferAacEncDemo->SetCallback(codec);
323     complexity = 1;
324     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
325                                                complexity);
326     ASSERT_EQ(result0, AV_ERR_OK);
327     result0 = audioBufferAacEncDemo->Destroy(codec);
328 
329     format = OH_AVFormat_Create();
330     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
331     result0 = audioBufferAacEncDemo->SetCallback(codec);
332     complexity = 10;
333     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
334                                                complexity);
335     ASSERT_EQ(result0, AV_ERR_OK);
336     result0 = audioBufferAacEncDemo->Destroy(codec);
337 
338     format = OH_AVFormat_Create();
339     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
340     result0 = audioBufferAacEncDemo->SetCallback(codec);
341     complexity = 0;
342     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
343                                                complexity);
344     ASSERT_EQ(result0, AV_ERR_OK);
345     result0 = audioBufferAacEncDemo->Destroy(codec);
346 
347     format = OH_AVFormat_Create();
348     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
349     result0 = audioBufferAacEncDemo->SetCallback(codec);
350     complexity = 11;
351     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
352                                                complexity);
353     ASSERT_EQ(result0, AV_ERR_OK);
354     result0 = audioBufferAacEncDemo->Destroy(codec);
355 
356     delete audioBufferAacEncDemo;
357 }
358 
359 /**
360  * @tc.number    : PARAM_CHECK_008
361  * @tc.name      : Configure - channel(OH_AVCODEC_MIMETYPE_AUDIO_G711MU) param check
362  * @tc.desc      : param check test
363  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_008, TestSize.Level2)364 HWTEST_F(ParamCheckTest, PARAM_CHECK_008, TestSize.Level2)
365 {
366     OH_AVCodec *codec = nullptr;
367     OH_AVFormat *format = OH_AVFormat_Create();
368     int32_t channel = 1;
369     int32_t sampleRate = 8000;
370     int64_t bitRate = 64000; //64K
371     int32_t sampleFormat = SAMPLE_S16LE;
372     int32_t sampleBit = 16;
373     int32_t complexity = 10;
374     OH_AVErrCode result0;
375     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
376     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
377     result0 = audioBufferAacEncDemo->SetCallback(codec);
378     channel = 1;
379     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
380                                                complexity);
381     ASSERT_EQ(result0, AV_ERR_OK);
382     result0 = audioBufferAacEncDemo->Destroy(codec);
383 
384     format = OH_AVFormat_Create();
385     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
386     result0 = audioBufferAacEncDemo->SetCallback(codec);
387     channel = 0;
388     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
389                                                complexity);
390     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
391     result0 = audioBufferAacEncDemo->Destroy(codec);
392 
393     format = OH_AVFormat_Create();
394     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
395     result0 = audioBufferAacEncDemo->SetCallback(codec);
396     channel = 2;
397     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
398                                                complexity);
399     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
400     result0 = audioBufferAacEncDemo->Destroy(codec);
401 
402     delete audioBufferAacEncDemo;
403 }
404 
405 /**
406  * @tc.number    : PARAM_CHECK_009
407  * @tc.name      : Configure - sampleRate(OH_AVCODEC_MIMETYPE_AUDIO_G711MU) param check
408  * @tc.desc      : param check test
409  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_009, TestSize.Level2)410 HWTEST_F(ParamCheckTest, PARAM_CHECK_009, TestSize.Level2)
411 {
412     OH_AVCodec *codec = nullptr;
413     OH_AVFormat *format = OH_AVFormat_Create();
414     int32_t channel = 1;
415     int32_t sampleRate = 8000;
416     int64_t bitRate = 64000; //64K
417     int32_t sampleFormat = SAMPLE_S16LE;
418     int32_t sampleBit = 16;
419     int32_t complexity = 10;
420     OH_AVErrCode result0;
421     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
422     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
423     result0 = audioBufferAacEncDemo->SetCallback(codec);
424     sampleRate = 8000;
425     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
426                                                complexity);
427     ASSERT_EQ(result0, AV_ERR_OK);
428     result0 = audioBufferAacEncDemo->Destroy(codec);
429 
430     format = OH_AVFormat_Create();
431     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
432     result0 = audioBufferAacEncDemo->SetCallback(codec);
433     sampleRate = 7999;
434     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
435                                                complexity);
436     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
437     result0 = audioBufferAacEncDemo->Destroy(codec);
438 
439     format = OH_AVFormat_Create();
440     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
441     result0 = audioBufferAacEncDemo->SetCallback(codec);
442     sampleRate = 8001;
443     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
444                                                complexity);
445     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
446     result0 = audioBufferAacEncDemo->Destroy(codec);
447 
448     delete audioBufferAacEncDemo;
449 }
450 
451 /**
452  * @tc.number    : PARAM_CHECK_010
453  * @tc.name      : Configure - bitRate(OH_AVCODEC_MIMETYPE_AUDIO_G711MU) param check
454  * @tc.desc      : param check test
455  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_010, TestSize.Level2)456 HWTEST_F(ParamCheckTest, PARAM_CHECK_010, TestSize.Level2)
457 {
458     OH_AVCodec *codec = nullptr;
459     OH_AVFormat *format = OH_AVFormat_Create();
460     int32_t channel = 1;
461     int32_t sampleRate = 8000;
462     int64_t bitRate = 64000; //64K
463     int32_t sampleFormat = SAMPLE_S16LE;
464     int32_t sampleBit = 16;
465     int32_t complexity = 10;
466     OH_AVErrCode result0;
467     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
468     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
469     result0 = audioBufferAacEncDemo->SetCallback(codec);
470     bitRate = 6000;
471     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
472                                                complexity);
473     ASSERT_EQ(result0, AV_ERR_OK);
474     result0 = audioBufferAacEncDemo->Destroy(codec);
475 
476     format = OH_AVFormat_Create();
477     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
478     result0 = audioBufferAacEncDemo->SetCallback(codec);
479     bitRate = 510000;
480     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
481                                                complexity);
482     ASSERT_EQ(result0, AV_ERR_OK);
483     result0 = audioBufferAacEncDemo->Destroy(codec);
484 
485     format = OH_AVFormat_Create();
486     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
487     result0 = audioBufferAacEncDemo->SetCallback(codec);
488     bitRate = 5999;
489     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
490                                                complexity);
491     ASSERT_EQ(result0, AV_ERR_OK);
492     result0 = audioBufferAacEncDemo->Destroy(codec);
493 
494     format = OH_AVFormat_Create();
495     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
496     result0 = audioBufferAacEncDemo->SetCallback(codec);
497     bitRate = 510001;
498     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
499                                                complexity);
500     ASSERT_EQ(result0, AV_ERR_OK);
501     result0 = audioBufferAacEncDemo->Destroy(codec);
502 
503     delete audioBufferAacEncDemo;
504 }
505 
506 /**
507  * @tc.number    : PARAM_CHECK_011
508  * @tc.name      : Configure - sampleFormat(OH_AVCODEC_MIMETYPE_AUDIO_G711MU) param check
509  * @tc.desc      : param check test
510  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_011, TestSize.Level2)511 HWTEST_F(ParamCheckTest, PARAM_CHECK_011, TestSize.Level2)
512 {
513     OH_AVCodec *codec = nullptr;
514     OH_AVFormat *format = OH_AVFormat_Create();
515     int32_t channel = 1;
516     int32_t sampleRate = 8000;
517     int64_t bitRate = 64000; //64K
518     int32_t sampleFormat = SAMPLE_S16LE;
519     int32_t sampleBit = 16;
520     int32_t complexity = 10;
521     OH_AVErrCode result0;
522     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
523     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
524     result0 = audioBufferAacEncDemo->SetCallback(codec);
525     sampleFormat = SAMPLE_S16LE;
526     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
527                                                complexity);
528     ASSERT_EQ(result0, AV_ERR_OK);
529     result0 = audioBufferAacEncDemo->Destroy(codec);
530 
531     delete audioBufferAacEncDemo;
532 }
533 
534 /**
535  * @tc.number    : PARAM_CHECK_012
536  * @tc.name      : Configure - complexity(OH_AVCODEC_MIMETYPE_AUDIO_G711MU) param check
537  * @tc.desc      : param check test
538  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_012, TestSize.Level2)539 HWTEST_F(ParamCheckTest, PARAM_CHECK_012, TestSize.Level2)
540 {
541     OH_AVCodec *codec = nullptr;
542     OH_AVFormat *format = OH_AVFormat_Create();
543     int32_t channel = 1;
544     int32_t sampleRate = 8000;
545     int64_t bitRate = 64000; //64K
546     int32_t sampleFormat = SAMPLE_S16LE;
547     int32_t sampleBit = 16;
548     int32_t complexity = 10;
549     OH_AVErrCode result0;
550     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
551     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
552     result0 = audioBufferAacEncDemo->SetCallback(codec);
553     complexity = 1;
554     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
555                                                complexity);
556     ASSERT_EQ(result0, AV_ERR_OK);
557     result0 = audioBufferAacEncDemo->Destroy(codec);
558 
559     format = OH_AVFormat_Create();
560     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
561     result0 = audioBufferAacEncDemo->SetCallback(codec);
562     complexity = 10;
563     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
564                                                complexity);
565     ASSERT_EQ(result0, AV_ERR_OK);
566     result0 = audioBufferAacEncDemo->Destroy(codec);
567 
568     format = OH_AVFormat_Create();
569     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
570     result0 = audioBufferAacEncDemo->SetCallback(codec);
571     complexity = 0;
572     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
573                                                complexity);
574     ASSERT_EQ(result0, AV_ERR_OK);
575     result0 = audioBufferAacEncDemo->Destroy(codec);
576 
577     format = OH_AVFormat_Create();
578     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
579     result0 = audioBufferAacEncDemo->SetCallback(codec);
580     complexity = 11;
581     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
582                                                complexity);
583     ASSERT_EQ(result0, AV_ERR_OK);
584     result0 = audioBufferAacEncDemo->Destroy(codec);
585 
586     delete audioBufferAacEncDemo;
587 }
588 
589 /**
590  * @tc.number    : PARAM_CHECK_013
591  * @tc.name      : PushInputData - index param check
592  * @tc.desc      : param check test
593  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_013, TestSize.Level2)594 HWTEST_F(ParamCheckTest, PARAM_CHECK_013, TestSize.Level2)
595 {
596     OH_AVCodec *codec = nullptr;
597     OH_AVFormat *format = OH_AVFormat_Create();
598     int32_t channel = 1; //channel1
599     int32_t sampleRate = 8000;  // 8000hz
600     int64_t bitRate = 64000; //64K
601     int32_t sampleFormat = SAMPLE_S16LE;
602     int32_t sampleBit = 16;
603     int32_t complexity = 10;
604     uint32_t index;
605     OH_AVErrCode result0;
606     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
607     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
608     ASSERT_NE(codec, nullptr);
609     result0 = audioBufferAacEncDemo->SetCallback(codec);
610     ASSERT_EQ(result0, AV_ERR_OK);
611     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
612                                                complexity);
613     ASSERT_EQ(result0, AV_ERR_OK);
614     result0 = audioBufferAacEncDemo->Start(codec);
615     ASSERT_EQ(result0, AV_ERR_OK);
616     index = audioBufferAacEncDemo->GetInputIndex();
617     index = -1;
618     result0 = audioBufferAacEncDemo->PushInputData(codec, index);
619     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
620     result0 = audioBufferAacEncDemo->Destroy(codec);
621 
622     format = OH_AVFormat_Create();
623     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
624     ASSERT_NE(codec, nullptr);
625     result0 = audioBufferAacEncDemo->SetCallback(codec);
626     ASSERT_EQ(result0, AV_ERR_OK);
627     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
628                                                complexity);
629     ASSERT_EQ(result0, AV_ERR_OK);
630     result0 = audioBufferAacEncDemo->Start(codec);
631     ASSERT_EQ(result0, AV_ERR_OK);
632     index = audioBufferAacEncDemo->GetInputIndex();
633     index = 8;
634     result0 = audioBufferAacEncDemo->PushInputData(codec, index);
635     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
636     result0 = audioBufferAacEncDemo->Destroy(codec);
637 
638     delete audioBufferAacEncDemo;
639 }
640 
641 /**
642  * @tc.number    : PARAM_CHECK_014
643  * @tc.name      : PushInputDataEOS - index param check
644  * @tc.desc      : param check test
645  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_014, TestSize.Level2)646 HWTEST_F(ParamCheckTest, PARAM_CHECK_014, TestSize.Level2)
647 {
648     OH_AVCodec *codec = nullptr;
649     OH_AVFormat *format = OH_AVFormat_Create();
650     int32_t channel = 1; //channel1
651     int32_t sampleRate = 8000;  // 8000hz
652     int64_t bitRate = 64000; //64K
653     int32_t sampleFormat = SAMPLE_S16LE;
654     int32_t sampleBit = 16;
655     int32_t complexity = 10;
656     uint32_t index;
657     OH_AVErrCode result0;
658     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
659     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
660     ASSERT_NE(codec, nullptr);
661     result0 = audioBufferAacEncDemo->SetCallback(codec);
662     ASSERT_EQ(result0, AV_ERR_OK);
663     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
664                                                complexity);
665     ASSERT_EQ(result0, AV_ERR_OK);
666     result0 = audioBufferAacEncDemo->Start(codec);
667     ASSERT_EQ(result0, AV_ERR_OK);
668     index = audioBufferAacEncDemo->GetInputIndex();
669     index = -1;
670     result0 = audioBufferAacEncDemo->PushInputDataEOS(codec, index);
671     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
672     result0 = audioBufferAacEncDemo->Destroy(codec);
673 
674     format = OH_AVFormat_Create();
675     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
676     ASSERT_NE(codec, nullptr);
677     result0 = audioBufferAacEncDemo->SetCallback(codec);
678     ASSERT_EQ(result0, AV_ERR_OK);
679     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
680                                                complexity);
681     ASSERT_EQ(result0, AV_ERR_OK);
682     result0 = audioBufferAacEncDemo->Start(codec);
683     ASSERT_EQ(result0, AV_ERR_OK);
684     index = audioBufferAacEncDemo->GetInputIndex();
685     index = 8;
686     result0 = audioBufferAacEncDemo->PushInputDataEOS(codec, index);
687     ASSERT_NE(result0, AV_ERR_OK);
688     result0 = audioBufferAacEncDemo->Destroy(codec);
689 
690     delete audioBufferAacEncDemo;
691 }
692 
693 /**
694  * @tc.number    : PARAM_CHECK_015
695  * @tc.name      : FreeOutputData - index param check
696  * @tc.desc      : param check test
697  */
HWTEST_F(ParamCheckTest, PARAM_CHECK_015, TestSize.Level2)698 HWTEST_F(ParamCheckTest, PARAM_CHECK_015, TestSize.Level2)
699 {
700     OH_AVCodec *codec = nullptr;
701     OH_AVFormat *format = OH_AVFormat_Create();
702     int32_t channel = 1; //channel1
703     int32_t sampleRate = 8000;  // 8000hz
704     int64_t bitRate = 64000; //64K
705     int32_t sampleFormat = SAMPLE_S16LE;
706     int32_t sampleBit = 16;
707     int32_t complexity = 10;
708     OH_AVErrCode result0;
709     AudioBufferAacEncDemo *audioBufferAacEncDemo = new AudioBufferAacEncDemo();
710     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
711     ASSERT_NE(codec, nullptr);
712     result0 = audioBufferAacEncDemo->SetCallback(codec);
713     ASSERT_EQ(result0, AV_ERR_OK);
714     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
715                                                complexity);
716     ASSERT_EQ(result0, AV_ERR_OK);
717     result0 = audioBufferAacEncDemo->Start(codec);
718     ASSERT_EQ(result0, AV_ERR_OK);
719     uint32_t index = audioBufferAacEncDemo->GetInputIndex();
720     index = -1;
721     result0 = audioBufferAacEncDemo->PushInputDataEOS(codec, index);
722     ASSERT_NE(result0, AV_ERR_OK);
723     index = audioBufferAacEncDemo->GetOutputIndex();
724     index = -1;
725     result0 = audioBufferAacEncDemo->FreeOutputData(codec, index);
726     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
727     result0 = audioBufferAacEncDemo->Destroy(codec);
728 
729     format = OH_AVFormat_Create();
730     codec = audioBufferAacEncDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
731     ASSERT_NE(codec, nullptr);
732     result0 = audioBufferAacEncDemo->SetCallback(codec);
733     ASSERT_EQ(result0, AV_ERR_OK);
734     result0 = audioBufferAacEncDemo->Configure(codec, format, channel, sampleRate, bitRate, sampleFormat, sampleBit,
735                                                complexity);
736     ASSERT_EQ(result0, AV_ERR_OK);
737     result0 = audioBufferAacEncDemo->Start(codec);
738     ASSERT_EQ(result0, AV_ERR_OK);
739     index = audioBufferAacEncDemo->GetInputIndex();
740     index = -1;
741     result0 = audioBufferAacEncDemo->PushInputDataEOS(codec, index);
742     ASSERT_NE(result0, AV_ERR_OK);
743     index = audioBufferAacEncDemo->GetOutputIndex();
744     index = 8;
745     result0 = audioBufferAacEncDemo->FreeOutputData(codec, index);
746     ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
747     result0 = audioBufferAacEncDemo->Destroy(codec);
748 
749     delete audioBufferAacEncDemo;
750 }
751