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 "AudioEncoderDemoCommon.h"
19 #include "avcodec_info.h"
20 #include "avcodec_errors.h"
21 #include "media_description.h"
22 #include "av_common.h"
23 #include "format.h"
24 #include "avcodec_audio_common.h"
25
26 using namespace std;
27 using namespace testing::ext;
28 using namespace OHOS;
29 using namespace OHOS::MediaAVCodec;
30 constexpr uint32_t SAMPLE_RATE_44100 = 44100;
31 constexpr uint32_t SAMPLE_RATE_112000 = 112000;
32
33 namespace {
34 class InnerParamCheckTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp() override;
39 void TearDown() override;
40 };
41
SetUpTestCase()42 void InnerParamCheckTest::SetUpTestCase() {}
TearDownTestCase()43 void InnerParamCheckTest::TearDownTestCase() {}
SetUp()44 void InnerParamCheckTest::SetUp() {}
TearDown()45 void InnerParamCheckTest::TearDown() {}
46 } // namespace
47
48 /**
49 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_001
50 * @tc.name : InnerCreateByMime
51 * @tc.desc : param check test
52 */
53 HWTEST_F(InnerParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_001, TestSize.Level2)
54 {
55 AudioEncoderDemo *encoderDemo = new AudioEncoderDemo();
56
57 int32_t ret = encoderDemo->InnerCreateByMime("audio/mp4a-latm");
58 ASSERT_EQ(AVCS_ERR_OK, ret);
59 encoderDemo->InnerDestroy();
60
61 ret = encoderDemo->InnerCreateByMime("audio/flac");
62 ASSERT_EQ(AVCS_ERR_OK, ret);
63 encoderDemo->InnerDestroy();
64
65 ret = encoderDemo->InnerCreateByMime("aaa");
66 ASSERT_EQ(AVCS_ERR_INVALID_OPERATION, ret);
67 encoderDemo->InnerDestroy();
68
69 delete encoderDemo;
70 }
71
72 /**
73 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_002
74 * @tc.name : InnerCreateByName
75 * @tc.desc : param check test
76 */
77 HWTEST_F(InnerParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_002, TestSize.Level2)
78 {
79 AudioEncoderDemo *encoderDemo = new AudioEncoderDemo();
80
81 int32_t ret = encoderDemo->InnerCreateByName("OH.Media.Codec.Encoder.Audio.AAC");
82 ASSERT_EQ(AVCS_ERR_OK, ret);
83 encoderDemo->InnerDestroy();
84
85 ret = encoderDemo->InnerCreateByName("OH.Media.Codec.Encoder.Audio.Flac");
86 ASSERT_EQ(AVCS_ERR_OK, ret);
87 encoderDemo->InnerDestroy();
88
89 ret = encoderDemo->InnerCreateByName("aaa");
90 ASSERT_EQ(AVCS_ERR_INVALID_OPERATION, ret);
91 encoderDemo->InnerDestroy();
92
93 delete encoderDemo;
94 }
95
96 /**
97 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_003
98 * @tc.name : InnerConfigure - MD_KEY_BITRATE
99 * @tc.desc : param check test
100 */
101 HWTEST_F(InnerParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_003, TestSize.Level2)
102 {
103 AudioEncoderDemo *encoderDemo = new AudioEncoderDemo();
104
105 int32_t ret = encoderDemo->InnerCreateByName("OH.Media.Codec.Encoder.Audio.AAC");
106 ASSERT_EQ(AVCS_ERR_OK, ret);
107 Format audioParams;
108
109 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
110 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
111 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_112000);
112 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
113 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
114 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
115 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1);
116
117 ret = encoderDemo->InnerConfigure(audioParams);
118 ASSERT_EQ(AVCS_ERR_OK, ret);
119
120 encoderDemo->InnerReset();
121 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_BITRATE, -1);
122 ret = encoderDemo->InnerConfigure(audioParams);
123 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
124
125 encoderDemo->InnerReset();
126 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_BITRATE, "aaaaaa");
127 ret = encoderDemo->InnerConfigure(audioParams);
128 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
129
130 encoderDemo->InnerReset();
131 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, -1);
132 ret = encoderDemo->InnerConfigure(audioParams);
133 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
134
135 encoderDemo->InnerReset();
136 audioParams.PutFloatValue(MediaDescriptionKey::MD_KEY_BITRATE, 0.1);
137 ret = encoderDemo->InnerConfigure(audioParams);
138 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
139
140 encoderDemo->InnerReset();
141 audioParams.PutDoubleValue(MediaDescriptionKey::MD_KEY_BITRATE, 0.1);
142 ret = encoderDemo->InnerConfigure(audioParams);
143 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
144
145 encoderDemo->InnerReset();
146 uint8_t b[100];
147 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_BITRATE, b, 100);
148 ret = encoderDemo->InnerConfigure(audioParams);
149 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
150
151 encoderDemo->InnerDestroy();
152 delete encoderDemo;
153 }
154
155 /**
156 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_004
157 * @tc.name : InnerConfigure - MD_KEY_BITS_PER_CODED_SAMPLE
158 * @tc.desc : param check test
159 */
160 HWTEST_F(InnerParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_004, TestSize.Level2)
161 {
162 AudioEncoderDemo *encoderDemo = new AudioEncoderDemo();
163
164 int32_t ret = encoderDemo->InnerCreateByName("OH.Media.Codec.Encoder.Audio.AAC");
165 ASSERT_EQ(AVCS_ERR_OK, ret);
166
167 Format audioParams;
168
169 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
170 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
171 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_112000);
172 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
173 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
174 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
175
176 ret = encoderDemo->InnerConfigure(audioParams);
177 ASSERT_EQ(AVCS_ERR_OK, ret);
178 encoderDemo->InnerReset();
179 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, -1);
180 ret = encoderDemo->InnerConfigure(audioParams);
181 ASSERT_EQ(AVCS_ERR_OK, ret);
182 encoderDemo->InnerReset();
183 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, "aaaaaa");
184 ret = encoderDemo->InnerConfigure(audioParams);
185 ASSERT_EQ(AVCS_ERR_OK, ret);
186 encoderDemo->InnerReset();
187 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, 0);
188 ret = encoderDemo->InnerConfigure(audioParams);
189 ASSERT_EQ(AVCS_ERR_OK, ret);
190 encoderDemo->InnerReset();
191 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, 0);
192 ret = encoderDemo->InnerConfigure(audioParams);
193 ASSERT_EQ(AVCS_ERR_OK, ret);
194 encoderDemo->InnerReset();
195 audioParams.PutFloatValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, 0.1);
196 ret = encoderDemo->InnerConfigure(audioParams);
197 ASSERT_EQ(AVCS_ERR_OK, ret);
198 encoderDemo->InnerReset();
199 audioParams.PutDoubleValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, 0.1);
200 ret = encoderDemo->InnerConfigure(audioParams);
201 ASSERT_EQ(AVCS_ERR_OK, ret);
202 encoderDemo->InnerReset();
203 uint8_t b[100];
204 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, b, 100);
205 ret = encoderDemo->InnerConfigure(audioParams);
206 ASSERT_EQ(AVCS_ERR_OK, ret);
207 encoderDemo->InnerReset();
208 encoderDemo->InnerDestroy();
209
210 delete encoderDemo;
211 }
212
213 /**
214 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_005
215 * @tc.name : InnerConfigure - MD_KEY_AUDIO_SAMPLE_FORMAT
216 * @tc.desc : param check test
217 */
218 HWTEST_F(InnerParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_005, TestSize.Level2)
219 {
220 AudioEncoderDemo *encoderDemo = new AudioEncoderDemo();
221
222 int32_t ret = encoderDemo->InnerCreateByName("OH.Media.Codec.Encoder.Audio.AAC");
223 ASSERT_EQ(AVCS_ERR_OK, ret);
224
225 Format audioParams;
226
227 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
228 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
229 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_112000);
230 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
231 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
232 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
233
234 ret = encoderDemo->InnerConfigure(audioParams);
235 ASSERT_EQ(AVCS_ERR_OK, ret);
236 encoderDemo->InnerReset();
237 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, -1);
238 ret = encoderDemo->InnerConfigure(audioParams);
239 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
240 encoderDemo->InnerReset();
241 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, "aaaaaa");
242 ret = encoderDemo->InnerConfigure(audioParams);
243 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
244 encoderDemo->InnerReset();
245 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, 0);
246 ret = encoderDemo->InnerConfigure(audioParams);
247 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
248 encoderDemo->InnerReset();
249 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, 0);
250 ret = encoderDemo->InnerConfigure(audioParams);
251 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
252 encoderDemo->InnerReset();
253 audioParams.PutFloatValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, 0.1);
254 ret = encoderDemo->InnerConfigure(audioParams);
255 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
256 encoderDemo->InnerReset();
257 audioParams.PutDoubleValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, 0.1);
258 ret = encoderDemo->InnerConfigure(audioParams);
259 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
260 encoderDemo->InnerReset();
261 uint8_t b[100];
262 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, b, 100);
263 ret = encoderDemo->InnerConfigure(audioParams);
264 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
265 encoderDemo->InnerReset();
266 encoderDemo->InnerDestroy();
267
268 delete encoderDemo;
269 }
270
271 /**
272 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_006
273 * @tc.name : InnerConfigure - MD_KEY_CHANNEL_LAYOUT check
274 * @tc.desc : param check test
275 */
276 HWTEST_F(InnerParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_006, TestSize.Level2)
277 {
278 AudioEncoderDemo *encoderDemo = new AudioEncoderDemo();
279 int32_t ret = encoderDemo->InnerCreateByName("OH.Media.Codec.Encoder.Audio.AAC");
280 ASSERT_EQ(AVCS_ERR_OK, ret);
281
282 Format audioParams;
283
284 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
285 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
286 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_112000);
287 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
288 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
289 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
290
291 ret = encoderDemo->InnerConfigure(audioParams);
292 ASSERT_EQ(AVCS_ERR_OK, ret);
293 encoderDemo->InnerReset();
294 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, -1);
295 ret = encoderDemo->InnerConfigure(audioParams);
296 ASSERT_EQ(AVCS_ERR_OK, ret);
297 encoderDemo->InnerReset();
298 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, "aaaaaa");
299 ret = encoderDemo->InnerConfigure(audioParams);
300 ASSERT_EQ(AVCS_ERR_OK, ret);
301 encoderDemo->InnerReset();
302 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, 0);
303 ret = encoderDemo->InnerConfigure(audioParams);
304 ASSERT_EQ(AVCS_ERR_OK, ret);
305 encoderDemo->InnerReset();
306 audioParams.PutFloatValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, 0.1);
307 ret = encoderDemo->InnerConfigure(audioParams);
308 ASSERT_EQ(AVCS_ERR_OK, ret);
309 encoderDemo->InnerReset();
310 audioParams.PutDoubleValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, 0.1);
311 ret = encoderDemo->InnerConfigure(audioParams);
312 ASSERT_EQ(AVCS_ERR_OK, ret);
313 encoderDemo->InnerReset();
314 uint8_t b[100];
315 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, b, 100);
316 ret = encoderDemo->InnerConfigure(audioParams);
317 ASSERT_EQ(AVCS_ERR_OK, ret);
318 encoderDemo->InnerReset();
319 encoderDemo->InnerDestroy();
320
321 delete encoderDemo;
322 }
323 /**
324 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_007
325 * @tc.name : InnerConfigure - MD_KEY_CHANNEL_COUNT check
326 * @tc.desc : param check test
327 */
328 HWTEST_F(InnerParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_007, TestSize.Level2)
329 {
330 AudioEncoderDemo *encoderDemo = new AudioEncoderDemo();
331 int32_t ret = encoderDemo->InnerCreateByName("OH.Media.Codec.Encoder.Audio.AAC");
332 ASSERT_EQ(AVCS_ERR_OK, ret);
333
334 Format audioParams;
335
336 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
337 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
338 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_112000);
339 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
340 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
341 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
342
343 ret = encoderDemo->InnerConfigure(audioParams);
344 ASSERT_EQ(AVCS_ERR_OK, ret);
345 encoderDemo->InnerReset();
346 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, -1);
347 ret = encoderDemo->InnerConfigure(audioParams);
348 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
349 encoderDemo->InnerReset();
350 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, "aaaaaa");
351 ret = encoderDemo->InnerConfigure(audioParams);
352 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
353 encoderDemo->InnerReset();
354 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, -1);
355 ret = encoderDemo->InnerConfigure(audioParams);
356 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
357 encoderDemo->InnerReset();
358 audioParams.PutFloatValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 0.1);
359 ret = encoderDemo->InnerConfigure(audioParams);
360 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
361 encoderDemo->InnerReset();
362 audioParams.PutDoubleValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 0.1);
363 ret = encoderDemo->InnerConfigure(audioParams);
364 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
365 encoderDemo->InnerReset();
366 uint8_t b[100];
367 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, b, 100);
368 ret = encoderDemo->InnerConfigure(audioParams);
369 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
370 encoderDemo->InnerReset();
371 encoderDemo->InnerDestroy();
372
373 delete encoderDemo;
374 }
375
376 /**
377 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_008
378 * @tc.name : InnerConfigure - MD_KEY_SAMPLE_RATE check
379 * @tc.desc : param check test
380 */
381 HWTEST_F(InnerParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_008, TestSize.Level2)
382 {
383 AudioEncoderDemo *encoderDemo = new AudioEncoderDemo();
384 int32_t ret = encoderDemo->InnerCreateByName("OH.Media.Codec.Encoder.Audio.AAC");
385 ASSERT_EQ(AVCS_ERR_OK, ret);
386
387 Format audioParams;
388
389 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
390 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
391 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_112000);
392 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
393 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
394 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
395
396 ret = encoderDemo->InnerConfigure(audioParams);
397 ASSERT_EQ(AVCS_ERR_OK, ret);
398 encoderDemo->InnerReset();
399 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, -1);
400 ret = encoderDemo->InnerConfigure(audioParams);
401 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
402 encoderDemo->InnerReset();
403 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, "aaaaaa");
404 ret = encoderDemo->InnerConfigure(audioParams);
405 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
406 encoderDemo->InnerReset();
407 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 0);
408 ret = encoderDemo->InnerConfigure(audioParams);
409 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
410 encoderDemo->InnerReset();
411 audioParams.PutFloatValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 0.1);
412 ret = encoderDemo->InnerConfigure(audioParams);
413 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
414 encoderDemo->InnerReset();
415 audioParams.PutDoubleValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 0.1);
416 ret = encoderDemo->InnerConfigure(audioParams);
417 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
418 encoderDemo->InnerReset();
419 uint8_t b[100];
420 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, b, 100);
421 ret = encoderDemo->InnerConfigure(audioParams);
422 ASSERT_EQ(AVCS_ERR_UNSUPPORT_AUD_PARAMS, ret);
423 encoderDemo->InnerReset();
424 encoderDemo->InnerDestroy();
425
426 delete encoderDemo;
427 }
428
429 /**
430 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_009
431 * @tc.name : InnerQueueInputBuffer - info.size check
432 * @tc.desc : param check test
433 */
434 HWTEST_F(InnerParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_009, TestSize.Level2)
435 {
436 AudioEncoderDemo *encoderDemo = new AudioEncoderDemo();
437 int32_t ret = encoderDemo->InnerCreateByName("OH.Media.Codec.Encoder.Audio.AAC");
438 ASSERT_EQ(AVCS_ERR_OK, ret);
439 Format audioParams;
440
441 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
442 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
443 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_112000);
444 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
445 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
446 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
447 std::shared_ptr<AEncSignal> signal_ = encoderDemo->getSignal();
448 std::shared_ptr<InnerAEnDemoCallback> cb_ = make_unique<InnerAEnDemoCallback>(signal_);
449 ret = encoderDemo->InnerSetCallback(cb_);
450 ASSERT_EQ(AVCS_ERR_OK, ret);
451
452 ret = encoderDemo->InnerConfigure(audioParams);
453 ASSERT_EQ(AVCS_ERR_OK, ret);
454
455 encoderDemo->InnerPrepare();
456 encoderDemo->InnerStartWithThread();
457 uint32_t index = encoderDemo->InnerGetInputIndex();
458 AVCodecBufferInfo info;
459 AVCodecBufferFlag flag;
460
461 std::shared_ptr<AVSharedMemory> buffer = signal_->inInnerBufQueue_.front();
462 ASSERT_NE(nullptr, buffer);
463
464 info.presentationTimeUs = 0;
465 info.size = 100;
466 info.offset = 0;
467
468 flag = AVCODEC_BUFFER_FLAG_NONE;
469
470 ret = encoderDemo->InnerQueueInputBuffer(index, info, flag);
471 ASSERT_EQ(AVCS_ERR_OK, ret);
472 index = encoderDemo->InnerGetInputIndex();
473 info.size = -1;
474 ret = encoderDemo->InnerQueueInputBuffer(index, info, flag);
475 ASSERT_EQ(AVCS_ERR_INVALID_VAL, ret);
476
477 encoderDemo->InnerDestroy();
478 delete encoderDemo;
479 }
480
481 /**
482 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_010
483 * @tc.name : InnerQueueInputBuffer - info.offset check
484 * @tc.desc : param check test
485 */
486 HWTEST_F(InnerParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_010, TestSize.Level2)
487 {
488 AudioEncoderDemo *encoderDemo = new AudioEncoderDemo();
489 int32_t ret = encoderDemo->InnerCreateByName("OH.Media.Codec.Encoder.Audio.AAC");
490 ASSERT_EQ(AVCS_ERR_OK, ret);
491 Format audioParams;
492
493 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1);
494 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
495 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, SAMPLE_RATE_112000);
496 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, AudioSampleFormat::SAMPLE_F32LE);
497 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_F32LE);
498 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, MONO);
499 std::shared_ptr<AEncSignal> signal_ = encoderDemo->getSignal();
500 std::shared_ptr<InnerAEnDemoCallback> cb_ = make_unique<InnerAEnDemoCallback>(signal_);
501 ret = encoderDemo->InnerSetCallback(cb_);
502 ASSERT_EQ(AVCS_ERR_OK, ret);
503
504 ret = encoderDemo->InnerConfigure(audioParams);
505 ASSERT_EQ(AVCS_ERR_OK, ret);
506
507 encoderDemo->InnerPrepare();
508 encoderDemo->InnerStartWithThread();
509
510 uint32_t index = encoderDemo->InnerGetInputIndex();
511 AVCodecBufferInfo info;
512 AVCodecBufferFlag flag;
513
514 std::shared_ptr<AVSharedMemory> buffer = signal_->inInnerBufQueue_.front();
515 ASSERT_NE(nullptr, buffer);
516
517 info.presentationTimeUs = 0;
518 info.size = 100;
519 info.offset = 0;
520
521 flag = AVCODEC_BUFFER_FLAG_NONE;
522
523 ret = encoderDemo->InnerQueueInputBuffer(index, info, flag);
524 ASSERT_EQ(AVCS_ERR_OK, ret);
525
526 index = encoderDemo->InnerGetInputIndex();
527 info.offset = -1;
528 ret = encoderDemo->InnerQueueInputBuffer(index, info, flag);
529 ASSERT_EQ(AVCS_ERR_INVALID_VAL, ret);
530
531 encoderDemo->InnerDestroy();
532 delete encoderDemo;
533 }