1 /*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <string>
17 #include "gtest/gtest.h"
18 #include "AudioDecoderDemoCommon.h"
19
20 using namespace std;
21 using namespace testing::ext;
22 using namespace OHOS;
23 using namespace OHOS::MediaAVCodec;
24
25 namespace {
26 class NativeParamCheckTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp() override;
31 void TearDown() override;
32 };
33
SetUpTestCase()34 void NativeParamCheckTest::SetUpTestCase() {}
TearDownTestCase()35 void NativeParamCheckTest::TearDownTestCase() {}
SetUp()36 void NativeParamCheckTest::SetUp() {}
TearDown()37 void NativeParamCheckTest::TearDown() {}
38 } // namespace
39
40 /**
41 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_001
42 * @tc.name : OH_AudioDecoder_CreateByMime - mime check
43 * @tc.desc : param check test
44 */
45 HWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_001, TestSize.Level2)
46 {
47 AudioDecoderDemo *decoderDemo = new AudioDecoderDemo();
48 OH_AVCodec *handle = decoderDemo->NativeCreateByMime("aaa");
49 ASSERT_EQ(nullptr, handle);
50
51 handle = decoderDemo->NativeCreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
52 ASSERT_NE(nullptr, handle);
53
54 decoderDemo->NativeDestroy(handle);
55 handle = nullptr;
56 handle = decoderDemo->NativeCreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
57 ASSERT_NE(nullptr, handle);
58 decoderDemo->NativeDestroy(handle);
59 delete decoderDemo;
60 }
61
62 /**
63 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_002
64 * @tc.name : OH_AudioDecoder_CreateByName - name check
65 * @tc.desc : param check test
66 */
67 HWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_002, TestSize.Level2)
68 {
69 AudioDecoderDemo *decoderDemo = new AudioDecoderDemo();
70 OH_AVCodec *handle = decoderDemo->NativeCreateByName("aaa");
71 ASSERT_EQ(nullptr, handle);
72
73 handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC");
74 ASSERT_EQ(nullptr, handle);
75
76 handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.AAC");
77 ASSERT_NE(nullptr, handle);
78
79 decoderDemo->NativeDestroy(handle);
80 handle = nullptr;
81 handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
82 ASSERT_NE(nullptr, handle);
83
84 decoderDemo->NativeDestroy(handle);
85 handle = nullptr;
86 handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Flac");
87 ASSERT_NE(nullptr, handle);
88
89 decoderDemo->NativeDestroy(handle);
90 handle = nullptr;
91 handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Vorbis");
92 ASSERT_NE(nullptr, handle);
93 decoderDemo->NativeDestroy(handle);
94 delete decoderDemo;
95 }
96
97 /**
98 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_003
99 * @tc.name : OH_AudioDecoder_Configure - format(MD_KEY_BITRATE) check
100 * @tc.desc : param check test
101 */
102 HWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_003, TestSize.Level2)
103 {
104 AudioDecoderDemo *decoderDemo = new AudioDecoderDemo();
105 OH_AVCodec *handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
106 ASSERT_NE(nullptr, handle);
107
108 OH_AVFormat *format = OH_AVFormat_Create();
109 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
110 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
111 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
112
113 OH_AVErrCode ret = decoderDemo->NativeConfigure(handle, format);
114 ASSERT_EQ(AV_ERR_OK, ret);
115
116 decoderDemo->NativeReset(handle);
117 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, -1);
118 ret = decoderDemo->NativeConfigure(handle, format);
119 ASSERT_EQ(AV_ERR_OK, ret);
120
121 decoderDemo->NativeReset(handle);
122 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, 1);
123 ret = decoderDemo->NativeConfigure(handle, format);
124 ASSERT_EQ(AV_ERR_OK, ret);
125
126 decoderDemo->NativeReset(handle);
127 OH_AVFormat_SetStringValue(format, OH_MD_KEY_BITRATE, "aaa");
128 ret = decoderDemo->NativeConfigure(handle, format);
129 ASSERT_EQ(AV_ERR_OK, ret);
130
131 decoderDemo->NativeReset(handle);
132 OH_AVFormat_SetFloatValue(format, OH_MD_KEY_BITRATE, 0.1);
133 ret = decoderDemo->NativeConfigure(handle, format);
134 ASSERT_EQ(AV_ERR_OK, ret);
135
136 decoderDemo->NativeReset(handle);
137 OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_BITRATE, 0.1);
138 ret = decoderDemo->NativeConfigure(handle, format);
139 ASSERT_EQ(AV_ERR_OK, ret);
140
141 uint8_t a[100];
142 decoderDemo->NativeReset(handle);
143 OH_AVFormat_SetBuffer(format, OH_MD_KEY_BITRATE, a, 100);
144 ret = decoderDemo->NativeConfigure(handle, format);
145 ASSERT_EQ(AV_ERR_OK, ret);
146
147 OH_AVFormat_Destroy(format);
148 decoderDemo->NativeDestroy(handle);
149 delete decoderDemo;
150 }
151
152 /**
153 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_004
154 * @tc.name : OH_AudioDecoder_Configure - format(OH_MD_KEY_AUD_CHANNEL_COUNT) check
155 * @tc.desc : param check test
156 */
157 HWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_004, TestSize.Level2)
158 {
159 AudioDecoderDemo *decoderDemo = new AudioDecoderDemo();
160 OH_AVCodec *handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
161 ASSERT_NE(nullptr, handle);
162
163 OH_AVFormat *format = OH_AVFormat_Create();
164 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
165 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
166 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
167
168 OH_AVErrCode ret = decoderDemo->NativeConfigure(handle, format);
169 ASSERT_EQ(AV_ERR_OK, ret);
170
171 decoderDemo->NativeReset(handle);
172 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, -1);
173 ret = decoderDemo->NativeConfigure(handle, format);
174 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
175
176 decoderDemo->NativeReset(handle);
177 OH_AVFormat_SetStringValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, "aaa");
178 ret = decoderDemo->NativeConfigure(handle, format);
179 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
180
181 decoderDemo->NativeReset(handle);
182 OH_AVFormat_SetLongValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0);
183 ret = decoderDemo->NativeConfigure(handle, format);
184 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
185
186 decoderDemo->NativeReset(handle);
187 OH_AVFormat_SetFloatValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0.1);
188 ret = decoderDemo->NativeConfigure(handle, format);
189 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
190
191 decoderDemo->NativeReset(handle);
192 OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0.1);
193 ret = decoderDemo->NativeConfigure(handle, format);
194 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
195
196 uint8_t a[100];
197 decoderDemo->NativeReset(handle);
198 OH_AVFormat_SetBuffer(format, OH_MD_KEY_AUD_CHANNEL_COUNT, a, 100);
199 ret = decoderDemo->NativeConfigure(handle, format);
200 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
201
202 OH_AVFormat_Destroy(format);
203 decoderDemo->NativeDestroy(handle);
204 delete decoderDemo;
205 }
206
207 /**
208 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_005
209 * @tc.name : OH_AudioDecoder_Configure - format(OH_MD_KEY_AUD_SAMPLE_RATE) check
210 * @tc.desc : param check test
211 */
212 HWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_005, TestSize.Level2)
213 {
214 AudioDecoderDemo *decoderDemo = new AudioDecoderDemo();
215 OH_AVCodec *handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
216 ASSERT_NE(nullptr, handle);
217
218 OH_AVFormat *format = OH_AVFormat_Create();
219 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
220 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
221 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
222
223 OH_AVErrCode ret = decoderDemo->NativeConfigure(handle, format);
224 ASSERT_EQ(AV_ERR_OK, ret);
225
226 decoderDemo->NativeReset(handle);
227 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, -1);
228 ret = decoderDemo->NativeConfigure(handle, format);
229 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
230
231 decoderDemo->NativeReset(handle);
232 OH_AVFormat_SetStringValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, "aaa");
233 ret = decoderDemo->NativeConfigure(handle, format);
234 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
235
236 decoderDemo->NativeReset(handle);
237 OH_AVFormat_SetLongValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0);
238 ret = decoderDemo->NativeConfigure(handle, format);
239 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
240
241 decoderDemo->NativeReset(handle);
242 OH_AVFormat_SetFloatValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0.1);
243 ret = decoderDemo->NativeConfigure(handle, format);
244 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
245
246 decoderDemo->NativeReset(handle);
247 OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0.1);
248 ret = decoderDemo->NativeConfigure(handle, format);
249 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
250
251 uint8_t a[100];
252 decoderDemo->NativeReset(handle);
253 OH_AVFormat_SetBuffer(format, OH_MD_KEY_AUD_SAMPLE_RATE, a, 100);
254 ret = decoderDemo->NativeConfigure(handle, format);
255 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
256
257 OH_AVFormat_Destroy(format);
258 decoderDemo->NativeDestroy(handle);
259 delete decoderDemo;
260 }
261
262 /**
263 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_006
264 * @tc.name : OH_AudioDecoder_SetParameter - format(MD_KEY_BITRATE) check
265 * @tc.desc : param check test
266 */
267 HWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_006, TestSize.Level2)
268 {
269 AudioDecoderDemo *decoderDemo = new AudioDecoderDemo();
270 OH_AVCodec *handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
271 ASSERT_NE(nullptr, handle);
272
273 OH_AVFormat *format = OH_AVFormat_Create();
274 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
275 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
276 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
277
278 OH_AVErrCode ret = decoderDemo->NativeConfigure(handle, format);
279 ASSERT_EQ(AV_ERR_OK, ret);
280
281 ret = decoderDemo->NativePrepare(handle);
282 ASSERT_EQ(AV_ERR_OK, ret);
283 ret = decoderDemo->NativeStart(handle);
284 ASSERT_EQ(AV_ERR_OK, ret);
285
286 ret = decoderDemo->NativeSetParameter(handle, format);
287 ASSERT_EQ(AV_ERR_OK, ret);
288
289 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, -1);
290 ret = decoderDemo->NativeSetParameter(handle, format);
291 ASSERT_EQ(AV_ERR_OK, ret);
292
293 OH_AVFormat_SetStringValue(format, OH_MD_KEY_BITRATE, "aaa");
294 ret = decoderDemo->NativeSetParameter(handle, format);
295 ASSERT_EQ(AV_ERR_OK, ret);
296
297 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, 0);
298 ret = decoderDemo->NativeSetParameter(handle, format);
299 ASSERT_EQ(AV_ERR_OK, ret);
300
301 OH_AVFormat_SetFloatValue(format, OH_MD_KEY_BITRATE, 0.1);
302 ret = decoderDemo->NativeSetParameter(handle, format);
303 ASSERT_EQ(AV_ERR_OK, ret);
304
305 OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_BITRATE, 0.1);
306 ret = decoderDemo->NativeSetParameter(handle, format);
307 ASSERT_EQ(AV_ERR_OK, ret);
308
309 uint8_t a[100];
310 OH_AVFormat_SetBuffer(format, OH_MD_KEY_AUD_SAMPLE_RATE, a, 100);
311 ret = decoderDemo->NativeSetParameter(handle, format);
312 ASSERT_EQ(AV_ERR_OK, ret);
313
314 OH_AVFormat_Destroy(format);
315 decoderDemo->NativeDestroy(handle);
316 delete decoderDemo;
317 }
318
319 /**
320 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_007
321 * @tc.name : OH_AudioDecoder_SetParameter - format(OH_MD_KEY_AUD_CHANNEL_COUNT) check
322 * @tc.desc : param check test
323 */
324 HWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_007, TestSize.Level2)
325 {
326 AudioDecoderDemo *decoderDemo = new AudioDecoderDemo();
327 OH_AVCodec *handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
328 ASSERT_NE(nullptr, handle);
329
330 OH_AVFormat *format = OH_AVFormat_Create();
331 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
332 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
333 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
334
335 OH_AVErrCode ret = decoderDemo->NativeConfigure(handle, format);
336 ASSERT_EQ(AV_ERR_OK, ret);
337
338 ret = decoderDemo->NativePrepare(handle);
339 ASSERT_EQ(AV_ERR_OK, ret);
340 ret = decoderDemo->NativeStart(handle);
341 ASSERT_EQ(AV_ERR_OK, ret);
342
343 ret = decoderDemo->NativeSetParameter(handle, format);
344 ASSERT_EQ(AV_ERR_OK, ret);
345
346 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, -1);
347 ret = decoderDemo->NativeSetParameter(handle, format);
348 ASSERT_EQ(AV_ERR_OK, ret);
349
350 OH_AVFormat_SetStringValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, "aaa");
351 ret = decoderDemo->NativeSetParameter(handle, format);
352 ASSERT_EQ(AV_ERR_OK, ret);
353
354 OH_AVFormat_SetLongValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0);
355 ret = decoderDemo->NativeSetParameter(handle, format);
356 ASSERT_EQ(AV_ERR_OK, ret);
357
358 OH_AVFormat_SetFloatValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0.1);
359 ret = decoderDemo->NativeSetParameter(handle, format);
360 ASSERT_EQ(AV_ERR_OK, ret);
361
362 OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0.1);
363 ret = decoderDemo->NativeSetParameter(handle, format);
364 ASSERT_EQ(AV_ERR_OK, ret);
365
366 uint8_t a[100];
367 OH_AVFormat_SetBuffer(format, OH_MD_KEY_AUD_CHANNEL_COUNT, a, 100);
368 ret = decoderDemo->NativeSetParameter(handle, format);
369 ASSERT_EQ(AV_ERR_OK, ret);
370
371 OH_AVFormat_Destroy(format);
372 decoderDemo->NativeDestroy(handle);
373 delete decoderDemo;
374 }
375
376 /**
377 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_008
378 * @tc.name : OH_AudioDecoder_SetParameter - format(OH_MD_KEY_AUD_SAMPLE_RATE) check
379 * @tc.desc : param check test
380 */
381 HWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_008, TestSize.Level2)
382 {
383 AudioDecoderDemo *decoderDemo = new AudioDecoderDemo();
384 OH_AVCodec *handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
385 ASSERT_NE(nullptr, handle);
386
387 OH_AVFormat *format = OH_AVFormat_Create();
388 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
389 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
390 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
391
392 OH_AVErrCode ret = decoderDemo->NativeConfigure(handle, format);
393 ASSERT_EQ(AV_ERR_OK, ret);
394
395 ret = decoderDemo->NativePrepare(handle);
396 ASSERT_EQ(AV_ERR_OK, ret);
397 ret = decoderDemo->NativeStart(handle);
398 ASSERT_EQ(AV_ERR_OK, ret);
399
400 ret = decoderDemo->NativeSetParameter(handle, format);
401 ASSERT_EQ(AV_ERR_OK, ret);
402
403 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, -1);
404 ret = decoderDemo->NativeSetParameter(handle, format);
405 ASSERT_EQ(AV_ERR_OK, ret);
406
407 OH_AVFormat_SetStringValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, "aaa");
408 ret = decoderDemo->NativeSetParameter(handle, format);
409 ASSERT_EQ(AV_ERR_OK, ret);
410
411 OH_AVFormat_SetLongValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0);
412 ret = decoderDemo->NativeSetParameter(handle, format);
413 ASSERT_EQ(AV_ERR_OK, ret);
414
415 OH_AVFormat_SetFloatValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0.1);
416 ret = decoderDemo->NativeSetParameter(handle, format);
417 ASSERT_EQ(AV_ERR_OK, ret);
418
419 OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0.1);
420 ret = decoderDemo->NativeSetParameter(handle, format);
421 ASSERT_EQ(AV_ERR_OK, ret);
422
423 uint8_t a[100];
424 OH_AVFormat_SetBuffer(format, OH_MD_KEY_AUD_SAMPLE_RATE, a, 100);
425 ret = decoderDemo->NativeSetParameter(handle, format);
426 ASSERT_EQ(AV_ERR_OK, ret);
427
428 OH_AVFormat_Destroy(format);
429 decoderDemo->NativeDestroy(handle);
430 delete decoderDemo;
431 }
432
433 /**
434 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_009
435 * @tc.name : OH_AudioDecoder_PushInputData - index check
436 * @tc.desc : param check test
437 */
438 HWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_009, TestSize.Level2)
439 {
440 AudioDecoderDemo *decoderDemo = new AudioDecoderDemo();
441 OH_AVCodec *handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
442 ASSERT_NE(nullptr, handle);
443
444 OH_AVFormat *format = OH_AVFormat_Create();
445 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
446 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
447 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
448
449 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable,
450 &OnOutputBufferAvailable};
451 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb);
452 ASSERT_EQ(AV_ERR_OK, ret);
453
454 ret = decoderDemo->NativeConfigure(handle, format);
455 ASSERT_EQ(AV_ERR_OK, ret);
456
457 ret = decoderDemo->NativePrepare(handle);
458 ASSERT_EQ(AV_ERR_OK, ret);
459 ret = decoderDemo->NativeStart(handle);
460 ASSERT_EQ(AV_ERR_OK, ret);
461
462 OH_AVCodecBufferAttr info;
463 info.size = 100;
464 info.offset = 0;
465 info.pts = 0;
466 info.flags = AVCODEC_BUFFER_FLAGS_NONE;
467
468 uint32_t index = decoderDemo->NativeGetInputIndex();
469 ret = decoderDemo->NativePushInputData(handle, index, info);
470 ASSERT_EQ(AV_ERR_OK, ret);
471
472 ret = decoderDemo->NativePushInputData(handle, -1, info);
473 ASSERT_EQ(AV_ERR_NO_MEMORY, ret);
474
475 OH_AVFormat_Destroy(format);
476 decoderDemo->NativeDestroy(handle);
477 delete decoderDemo;
478 }
479
480 /**
481 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_010
482 * @tc.name : OH_AudioDecoder_PushInputData - info.size check
483 * @tc.desc : param check test
484 */
485 HWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_010, TestSize.Level2)
486 {
487 AudioDecoderDemo *decoderDemo = new AudioDecoderDemo();
488 OH_AVCodec *handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
489 ASSERT_NE(nullptr, handle);
490
491 OH_AVFormat *format = OH_AVFormat_Create();
492 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
493 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
494 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
495
496 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable,
497 &OnOutputBufferAvailable};
498 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb);
499 ASSERT_EQ(AV_ERR_OK, ret);
500
501 ret = decoderDemo->NativeConfigure(handle, format);
502 ASSERT_EQ(AV_ERR_OK, ret);
503
504 ret = decoderDemo->NativePrepare(handle);
505 ASSERT_EQ(AV_ERR_OK, ret);
506 ret = decoderDemo->NativeStart(handle);
507 ASSERT_EQ(AV_ERR_OK, ret);
508
509 OH_AVCodecBufferAttr info;
510 info.size = 100;
511 info.offset = 0;
512 info.pts = 0;
513 info.flags = AVCODEC_BUFFER_FLAGS_NONE;
514
515 uint32_t index = decoderDemo->NativeGetInputIndex();
516 ret = decoderDemo->NativePushInputData(handle, index, info);
517 ASSERT_EQ(AV_ERR_OK, ret);
518
519 index = decoderDemo->NativeGetInputIndex();
520 info.size = -1;
521 ret = decoderDemo->NativePushInputData(handle, index, info);
522 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
523
524 OH_AVFormat_Destroy(format);
525 decoderDemo->NativeDestroy(handle);
526 delete decoderDemo;
527 }
528
529 /**
530 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_011
531 * @tc.name : OH_AudioDecoder_PushInputData - info.offset check
532 * @tc.desc : param check test
533 */
534 HWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_011, TestSize.Level2)
535 {
536 AudioDecoderDemo *decoderDemo = new AudioDecoderDemo();
537 OH_AVCodec *handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
538 ASSERT_NE(nullptr, handle);
539
540 OH_AVFormat *format = OH_AVFormat_Create();
541 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
542 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
543 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
544
545 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable,
546 &OnOutputBufferAvailable};
547 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb);
548 ASSERT_EQ(AV_ERR_OK, ret);
549
550 ret = decoderDemo->NativeConfigure(handle, format);
551 ASSERT_EQ(AV_ERR_OK, ret);
552
553 ret = decoderDemo->NativePrepare(handle);
554 ASSERT_EQ(AV_ERR_OK, ret);
555 ret = decoderDemo->NativeStart(handle);
556 ASSERT_EQ(AV_ERR_OK, ret);
557
558 OH_AVCodecBufferAttr info;
559 info.size = 100;
560 info.offset = 0;
561 info.pts = 0;
562 info.flags = AVCODEC_BUFFER_FLAGS_NONE;
563
564 uint32_t index = decoderDemo->NativeGetInputIndex();
565 ret = decoderDemo->NativePushInputData(handle, index, info);
566 ASSERT_EQ(AV_ERR_OK, ret);
567
568 index = decoderDemo->NativeGetInputIndex();
569 info.offset = -1;
570 ret = decoderDemo->NativePushInputData(handle, index, info);
571 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
572
573 OH_AVFormat_Destroy(format);
574 decoderDemo->NativeDestroy(handle);
575 delete decoderDemo;
576 }
577
578 /**
579 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_012
580 * @tc.name : OH_AudioDecoder_PushInputData - info.pts check
581 * @tc.desc : param check test
582 */
583 HWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_012, TestSize.Level2)
584 {
585 AudioDecoderDemo *decoderDemo = new AudioDecoderDemo();
586 OH_AVCodec *handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
587 ASSERT_NE(nullptr, handle);
588
589 OH_AVFormat *format = OH_AVFormat_Create();
590 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
591 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
592 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
593
594 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable,
595 &OnOutputBufferAvailable};
596 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb);
597 ASSERT_EQ(AV_ERR_OK, ret);
598
599 ret = decoderDemo->NativeConfigure(handle, format);
600 ASSERT_EQ(AV_ERR_OK, ret);
601
602 ret = decoderDemo->NativePrepare(handle);
603 ASSERT_EQ(AV_ERR_OK, ret);
604 ret = decoderDemo->NativeStart(handle);
605 ASSERT_EQ(AV_ERR_OK, ret);
606
607 OH_AVCodecBufferAttr info;
608 info.size = 100;
609 info.offset = 0;
610 info.pts = 0;
611 info.flags = AVCODEC_BUFFER_FLAGS_NONE;
612
613 uint32_t index = decoderDemo->NativeGetInputIndex();
614 ret = decoderDemo->NativePushInputData(handle, index, info);
615 ASSERT_EQ(AV_ERR_OK, ret);
616
617 index = decoderDemo->NativeGetInputIndex();
618 info.pts = -1;
619 ret = decoderDemo->NativePushInputData(handle, index, info);
620 ASSERT_EQ(AV_ERR_OK, ret);
621
622 OH_AVFormat_Destroy(format);
623 decoderDemo->NativeDestroy(handle);
624 delete decoderDemo;
625 }
626
627 /**
628 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_013
629 * @tc.name : OH_AudioDecoder_FreeOutputData - index check
630 * @tc.desc : param check test
631 */
632 HWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_PARAM_CHECK_013, TestSize.Level2)
633 {
634 AudioDecoderDemo *decoderDemo = new AudioDecoderDemo();
635 OH_AVCodec *handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
636 ASSERT_NE(nullptr, handle);
637
638 OH_AVFormat *format = OH_AVFormat_Create();
639 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
640 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
641 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
642
643 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable,
644 &OnOutputBufferAvailable};
645 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb);
646 ASSERT_EQ(AV_ERR_OK, ret);
647
648 ret = decoderDemo->NativeConfigure(handle, format);
649 ASSERT_EQ(AV_ERR_OK, ret);
650
651 ret = decoderDemo->NativePrepare(handle);
652 ASSERT_EQ(AV_ERR_OK, ret);
653 ret = decoderDemo->NativeStart(handle);
654 ASSERT_EQ(AV_ERR_OK, ret);
655
656 ret = decoderDemo->NativeFreeOutputData(handle, -1);
657 ASSERT_EQ(AV_ERR_NO_MEMORY, ret);
658
659 OH_AVFormat_Destroy(format);
660 decoderDemo->NativeDestroy(handle);
661 delete decoderDemo;
662 }