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