• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "audio_codec_decoder_adapter_impl.h"
17 #include "audio_cenc_info_adapter_impl.h"
18 #include "native_drm_common.h"
19 #include "native_avcodec_base.h"
20 
21 #include "nweb_log.h"
22 #include "gtest/gtest.h"
23 #include <gmock/gmock.h>
24 
25 using namespace testing;
26 using namespace testing::ext;
27 using testing::ext::TestSize;
28 
29 namespace OHOS {
30 namespace NWeb {
31 const char *OH_AVCODEC_MIMETYPE_AUDIO_MPEG = "audio/mpeg";
32 const char *OH_AVCODEC_NAME_AUDIO_MPEG = "OH.Media.Codec.Decoder.Audio.Mpeg";
33 
34 class AudioDecoderCallbackImplTest : public testing::Test {};
35 
36 class AudioDecoderCallbackAdapterMock : public AudioDecoderCallbackAdapter {
37 public:
38     AudioDecoderCallbackAdapterMock() = default;
39 
40     ~AudioDecoderCallbackAdapterMock() override = default;
41 
OnError(int32_t errorCode)42     void OnError(int32_t errorCode) override {}
43 
OnOutputFormatChanged()44     void OnOutputFormatChanged() override {}
45 
OnInputBufferAvailable(uint32_t index)46     void OnInputBufferAvailable(uint32_t index) override {}
47 
OnOutputBufferAvailable(uint32_t index,uint8_t * bufferData,int32_t size,int64_t pts,int32_t offset,uint32_t flags)48     void OnOutputBufferAvailable(
49         uint32_t index, uint8_t *bufferData, int32_t size, int64_t pts, int32_t offset, uint32_t flags) override {}
50 };
51 
52 class AudioDecoderFormatAdapterMock : public AudioDecoderFormatAdapter {
53 public:
54     AudioDecoderFormatAdapterMock() = default;
55 
56     ~AudioDecoderFormatAdapterMock() override = default;
57 
GetSampleRate()58     int32_t GetSampleRate() override
59     {
60         return sampleRate_;
61     }
62 
GetChannelCount()63     int32_t GetChannelCount() override
64     {
65         return channelCount_;
66     }
67 
GetBitRate()68     int64_t GetBitRate() override
69     {
70         return bitRate_;
71     }
72 
GetMaxInputSize()73     int32_t GetMaxInputSize() override
74     {
75         return maxInputSize_;
76     }
77 
GetAACIsAdts()78     bool GetAACIsAdts() override
79     {
80         return aacIsAdts_;
81     }
82 
GetAudioSampleFormat()83     int32_t GetAudioSampleFormat() override
84     {
85         return audioSampleFormat_;
86     }
87 
GetIdentificationHeader()88     int32_t GetIdentificationHeader() override
89     {
90         return idHeader_;
91     }
92 
GetSetupHeader()93     int32_t GetSetupHeader() override
94     {
95         return setupHeader_;
96     }
97 
GetCodecConfig()98     uint8_t* GetCodecConfig() override
99     {
100         return codecConfig_;
101     }
102 
GetCodecConfigSize()103     uint32_t GetCodecConfigSize() override
104     {
105         return codecConfigSize_;
106     }
107 
SetSampleRate(int32_t sampleRate)108     void SetSampleRate(int32_t sampleRate) override
109     {
110         sampleRate_ = sampleRate;
111     }
112 
SetChannelCount(int32_t channelCount)113     void SetChannelCount(int32_t channelCount) override
114     {
115         channelCount_ = channelCount;
116     }
117 
SetBitRate(int64_t bitRate)118     void SetBitRate(int64_t bitRate) override
119     {
120         bitRate_ = bitRate;
121     }
122 
SetMaxInputSize(int32_t maxInputSize)123     void SetMaxInputSize(int32_t maxInputSize) override
124     {
125         maxInputSize_ = maxInputSize;
126     }
127 
SetAudioSampleFormat(int32_t audioSampleFormat)128     void SetAudioSampleFormat(int32_t audioSampleFormat) override
129     {
130         audioSampleFormat_ = audioSampleFormat;
131     }
132 
SetAACIsAdts(bool isAdts)133     void SetAACIsAdts(bool isAdts) override
134     {
135         aacIsAdts_ = isAdts;
136     }
137 
SetIdentificationHeader(int32_t idHeader)138     void SetIdentificationHeader(int32_t idHeader) override
139     {
140         idHeader_ = idHeader;
141     }
142 
SetSetupHeader(int32_t setupHeader)143     void SetSetupHeader(int32_t setupHeader) override
144     {
145         setupHeader_ = setupHeader;
146     }
147 
SetCodecConfig(uint8_t * codecConfig)148     void SetCodecConfig(uint8_t* codecConfig) override
149     {
150         codecConfig_ = codecConfig;
151     }
152 
SetCodecConfigSize(uint32_t size)153     void SetCodecConfigSize(uint32_t size) override
154     {
155         codecConfigSize_ = size;
156     }
157 private:
158     int32_t sampleRate_ = 0;
159     int32_t channelCount_ = 0;
160     int64_t bitRate_ = 0;
161     int32_t maxInputSize_ = 0;
162     bool aacIsAdts_ = false;
163     int32_t audioSampleFormat_ = 0;
164     int32_t idHeader_ = 0;
165     int32_t setupHeader_ = 0;
166     uint8_t* codecConfig_ = nullptr;
167     uint32_t codecConfigSize_ = 0;
168 };
169 
170 /**
171  * @tc.name: AudioDecoderCallbackImpl_NormalTest_001.
172  * @tc.desc: test of AudioDecoderCallbackManager::OnError() OnOutputFormatChanged() OnInputBufferAvailable()
173              OnOutputBufferAvailable()
174  * @tc.type: FUNC.
175  * @tc.require:
176  */
177 HWTEST_F(AudioDecoderCallbackImplTest, AudioDecoderCallbackImpl_NormalTest_001, TestSize.Level1)
178 {
179     std::shared_ptr<AudioCodecDecoderAdapterImpl> decoder = std::make_shared<AudioCodecDecoderAdapterImpl>();
180     EXPECT_NE(decoder, nullptr);
181     EXPECT_EQ(decoder->CreateAudioDecoderByName(std::string(OH_AVCODEC_NAME_AUDIO_MPEG)),
182         AudioDecoderAdapterCode::DECODER_OK);
183     AudioDecoderCallbackManager::OnError(nullptr, 0, nullptr);
184     AudioDecoderCallbackManager::OnError(decoder->GetAVCodec(), 0, nullptr);
185     AudioDecoderCallbackManager::OnOutputFormatChanged(nullptr, 0, nullptr);
186     AudioDecoderCallbackManager::OnOutputFormatChanged(decoder->GetAVCodec(), 0, nullptr);
187 
188     constexpr int32_t MEMSIZE = 1024 * 1024;
189     OH_AVBuffer* buffer = OH_AVBuffer_Create(MEMSIZE);
190     AudioDecoderCallbackManager::OnInputBufferAvailable(nullptr, 0, nullptr, nullptr);
191     AudioDecoderCallbackManager::OnInputBufferAvailable(decoder->GetAVCodec(), 0, nullptr, nullptr);
192     AudioDecoderCallbackManager::OnInputBufferAvailable(decoder->GetAVCodec(), 0, buffer, nullptr);
193     AudioDecoderCallbackManager::OnInputBufferAvailable(
194         decoder->GetAVCodec(), 0, buffer, nullptr);
195 
196     AudioDecoderCallbackManager::OnOutputBufferAvailable(nullptr, 0, nullptr, nullptr);
197     AudioDecoderCallbackManager::OnOutputBufferAvailable(decoder->GetAVCodec(), 0, nullptr, nullptr);
198     AudioDecoderCallbackManager::OnOutputBufferAvailable(decoder->GetAVCodec(), 0, buffer, nullptr);
199     AudioDecoderCallbackManager::OnOutputBufferAvailable(
200         decoder->GetAVCodec(), 0, buffer, nullptr);
201 
202     EXPECT_EQ(decoder->SetCallbackDec(nullptr), AudioDecoderAdapterCode::DECODER_ERROR);
203 
204     std::shared_ptr<AudioDecoderCallbackAdapter> callback = std::make_shared<AudioDecoderCallbackAdapterMock>();
205     EXPECT_EQ(decoder->SetCallbackDec(callback), AudioDecoderAdapterCode::DECODER_OK);
206     AudioDecoderCallbackManager::OnError(decoder->GetAVCodec(), 0, nullptr);
207     AudioDecoderCallbackManager::OnOutputFormatChanged(decoder->GetAVCodec(), 0, nullptr);
208     AudioDecoderCallbackManager::OnInputBufferAvailable(
209         decoder->GetAVCodec(), 0, buffer, nullptr);
210     AudioDecoderCallbackManager::OnOutputBufferAvailable(
211         decoder->GetAVCodec(), 0, buffer, nullptr);
212     OH_AVBuffer_Destroy(buffer);
213     buffer = nullptr;
214 
215     std::shared_ptr<AudioDecoderCallbackAdapterImpl> errCallbackImpl =
216         std::make_shared<AudioDecoderCallbackAdapterImpl>(nullptr);
217     errCallbackImpl->OnError(0);
218     errCallbackImpl->OnOutputFormatChanged();
219     errCallbackImpl->OnInputBufferAvailable(0);
220     errCallbackImpl->OnOutputBufferAvailable(0, nullptr, 0, 0, 0, 0);
221     std::shared_ptr<AudioDecoderCallbackAdapterImpl> callbackImpl =
222         std::make_shared<AudioDecoderCallbackAdapterImpl>(callback);
223     callbackImpl->OnError(0);
224     callbackImpl->OnOutputFormatChanged();
225     callbackImpl->OnInputBufferAvailable(0);
226     callbackImpl->OnOutputBufferAvailable(0, nullptr, 0, 0, 0, 0);
227 }
228 
229 class AudioCodecDecoderAdapterImplTest : public testing::Test {
230 public:
231     static void SetUpTestCase(void);
232     static void TearDownTestCase(void);
233     void SetUp();
234     void TearDown();
235     void SetCencInfoAboutKeyIdIvAlgo(std::shared_ptr<AudioCencInfoAdapter> cencInfo);
236     void SetCencInfoAboutClearHeaderAndPayLoadLens(std::shared_ptr<AudioCencInfoAdapter> cencInfo);
237 
238 protected:
239     std::shared_ptr<AudioDecoderFormatAdapterMock> format_ = nullptr;
240     std::shared_ptr<AudioCodecDecoderAdapterImpl> AudioCodecDecoderAdapterImpl_ = nullptr;
241 };
242 
SetUpTestCase(void)243 void AudioCodecDecoderAdapterImplTest::SetUpTestCase(void) {}
244 
TearDownTestCase(void)245 void AudioCodecDecoderAdapterImplTest::TearDownTestCase(void) {}
246 
SetUp()247 void AudioCodecDecoderAdapterImplTest::SetUp()
248 {
249     EXPECT_EQ(AudioCodecDecoderAdapterImpl_, nullptr);
250     AudioCodecDecoderAdapterImpl_ = std::make_shared<AudioCodecDecoderAdapterImpl>();
251     EXPECT_NE(AudioCodecDecoderAdapterImpl_, nullptr);
252     format_ = std::make_unique<AudioDecoderFormatAdapterMock>();
253     EXPECT_NE(format_, nullptr);
254 }
255 
TearDown(void)256 void AudioCodecDecoderAdapterImplTest::TearDown(void)
257 {
258     format_ = nullptr;
259     AudioCodecDecoderAdapterImpl_ = nullptr;
260 }
261 
SetCencInfoAboutKeyIdIvAlgo(std::shared_ptr<AudioCencInfoAdapter> cencInfo)262 void AudioCodecDecoderAdapterImplTest::SetCencInfoAboutKeyIdIvAlgo(
263     std::shared_ptr<AudioCencInfoAdapter> cencInfo)
264 {
265     uint8_t keyId[] = {
266         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
267         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
268     uint8_t iv[] = {
269         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
270         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
271     cencInfo->SetAlgo(0);
272     cencInfo->SetKeyId(keyId);
273     cencInfo->SetKeyIdLen(DRM_KEY_ID_SIZE);
274     cencInfo->SetIv(iv);
275     cencInfo->SetIvLen(DRM_KEY_ID_SIZE);
276 }
277 
SetCencInfoAboutClearHeaderAndPayLoadLens(std::shared_ptr<AudioCencInfoAdapter> cencInfo)278 void AudioCodecDecoderAdapterImplTest::SetCencInfoAboutClearHeaderAndPayLoadLens(
279     std::shared_ptr<AudioCencInfoAdapter> cencInfo)
280 {
281     const std::vector<uint32_t> clearHeaderLens = {1, 2, 3};
282     const std::vector<uint32_t> payLoadLens = {4, 5, 6};
283     const uint32_t ERR_BLOCK_COUNT = 10000;
284     cencInfo->SetClearHeaderLens(clearHeaderLens);
285     cencInfo->SetPayLoadLens(payLoadLens);
286     cencInfo->SetEncryptedBlockCount(ERR_BLOCK_COUNT);
287     cencInfo->SetSkippedBlockCount(0);
288     cencInfo->SetFirstEncryptedOffset(0);
289 }
290 
291 /**
292  * @tc.name: AudioCodecDecoderAdapterImpl_CreateAudioDecoderByName_001.
293  * @tc.desc: test of AudioCodecDecoderAdapterImpl::CreateAudioDecoderByName() CreateAudioDecoderByMime()
294  * @tc.type: FUNC.
295  * @tc.require:
296  */
297 HWTEST_F(AudioCodecDecoderAdapterImplTest, AudioCodecDecoderAdapterImpl_CreateAudioDecoderByName_001, TestSize.Level1)
298 {
299     EXPECT_NE(AudioCodecDecoderAdapterImpl_, nullptr);
300 
301     // create decoder by invalid name or mimetype.
302     std::string name = "testname";
303     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->CreateAudioDecoderByName(name), AudioDecoderAdapterCode::DECODER_ERROR);
304 
305     std::string mimetype = "testmimeType";
306     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->CreateAudioDecoderByMime(mimetype),
307         AudioDecoderAdapterCode::DECODER_ERROR);
308 
309     // create decoder by normal name.
310     name = std::string(OH_AVCODEC_NAME_AUDIO_MPEG);
311     AudioDecoderAdapterCode ret = AudioCodecDecoderAdapterImpl_->CreateAudioDecoderByName(name);
312     EXPECT_EQ(ret, AudioDecoderAdapterCode::DECODER_OK);
313 
314     // repeat create
315     ret = AudioCodecDecoderAdapterImpl_->CreateAudioDecoderByName(name);
316     EXPECT_EQ(ret, AudioDecoderAdapterCode::DECODER_OK);
317 
318     // release decoder.
319     ret = AudioCodecDecoderAdapterImpl_->ReleaseDecoder();
320     EXPECT_EQ(ret, AudioDecoderAdapterCode::DECODER_OK);
321 
322     // create decoder by normal mimetype.
323     mimetype = std::string(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
324     ret = AudioCodecDecoderAdapterImpl_->CreateAudioDecoderByMime(mimetype);
325     EXPECT_EQ(ret, AudioDecoderAdapterCode::DECODER_OK);
326 
327     // repeat create
328     ret = AudioCodecDecoderAdapterImpl_->CreateAudioDecoderByMime(mimetype);
329     EXPECT_EQ(ret, AudioDecoderAdapterCode::DECODER_OK);
330 
331     // release decoder.
332     ret = AudioCodecDecoderAdapterImpl_->ReleaseDecoder();
333     EXPECT_EQ(ret, AudioDecoderAdapterCode::DECODER_OK);
334 
335     // repeat release decoder.
336     ret = AudioCodecDecoderAdapterImpl_->ReleaseDecoder();
337     EXPECT_EQ(ret, AudioDecoderAdapterCode::DECODER_OK);
338 }
339 
340 /**
341  * @tc.name: AudioCodecDecoderAdapterImpl_InvalidValueTest_002.
342  * @tc.desc: test of InvalidValueScene in AudioCodecDecoderAdapterImpl
343  * @tc.type: FUNC.
344  * @tc.require:
345  */
346 HWTEST_F(AudioCodecDecoderAdapterImplTest, AudioCodecDecoderAdapterImpl_InvalidValueTest_002, TestSize.Level1)
347 {
348     // not create decoder
349     format_->SetSampleRate(0);
350     format_->SetChannelCount(0);
351     format_->SetBitRate(0);
352     format_->SetMaxInputSize(0);
353     format_->SetAudioSampleFormat(0);
354     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->ConfigureDecoder(format_), AudioDecoderAdapterCode::DECODER_ERROR);
355     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->ConfigureDecoder(nullptr), AudioDecoderAdapterCode::DECODER_ERROR);
356     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->SetParameterDecoder(format_), AudioDecoderAdapterCode::DECODER_ERROR);
357     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->SetParameterDecoder(nullptr), AudioDecoderAdapterCode::DECODER_ERROR);
358 
359     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->SetCallbackDec(nullptr), AudioDecoderAdapterCode::DECODER_ERROR);
360     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->GetAudioDecoderCallBack(), nullptr);
361 
362     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->QueueInputBufferDec(0, 0, nullptr, 0, nullptr, false,
363         BufferFlag::CODEC_BUFFER_FLAG_NONE), AudioDecoderAdapterCode::DECODER_ERROR);
364     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->GetOutputFormatDec(format_), AudioDecoderAdapterCode::DECODER_ERROR);
365     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->ReleaseOutputBufferDec(0), AudioDecoderAdapterCode::DECODER_ERROR);
366     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->PrepareDecoder(), AudioDecoderAdapterCode::DECODER_ERROR);
367     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->StartDecoder(), AudioDecoderAdapterCode::DECODER_ERROR);
368     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->StopDecoder(), AudioDecoderAdapterCode::DECODER_ERROR);
369     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->FlushDecoder(), AudioDecoderAdapterCode::DECODER_ERROR);
370     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->ResetDecoder(), AudioDecoderAdapterCode::DECODER_ERROR);
371     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->SetDecryptionConfig(nullptr, false),
372         AudioDecoderAdapterCode::DECODER_ERROR);
373 }
374 
375 /**
376  * @tc.name: AudioCodecDecoderAdapterImpl_QueueInputBufferDec_003.
377  * @tc.desc: test of InvalidValueScene in AudioCodecDecoderAdapterImpl
378  * @tc.type: FUNC.
379  * @tc.require:
380  */
381 HWTEST_F(AudioCodecDecoderAdapterImplTest, AudioCodecDecoderAdapterImpl_QueueInputBufferDec_003, TestSize.Level1)
382 {
383     std::string mimetype = std::string(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
384     AudioDecoderAdapterCode ret = AudioCodecDecoderAdapterImpl_->CreateAudioDecoderByMime(mimetype);
385     EXPECT_EQ(ret, AudioDecoderAdapterCode::DECODER_OK);
386     EXPECT_NE(AudioCodecDecoderAdapterImpl_->GetAVCodec(), nullptr);
387 
388     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->QueueInputBufferDec(0, 0, nullptr, 0, nullptr, true,
389         BufferFlag::CODEC_BUFFER_FLAG_NONE), AudioDecoderAdapterCode::DECODER_ERROR);
390 
391     // test QueueInputBufferDec with decrypt data
392     std::shared_ptr<AudioCencInfoAdapterImpl> cencInfo = std::make_shared<AudioCencInfoAdapterImpl>();
393     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->QueueInputBufferDec(0, 0, nullptr, 0, cencInfo, true,
394         BufferFlag::CODEC_BUFFER_FLAG_NONE), AudioDecoderAdapterCode::DECODER_ERROR);
395     const uint32_t ERR_ALGO = 10000;
396     cencInfo->SetAlgo(ERR_ALGO);
397     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->QueueInputBufferDec(0, 0, nullptr, 0, cencInfo, true,
398         BufferFlag::CODEC_BUFFER_FLAG_NONE), AudioDecoderAdapterCode::DECODER_ERROR);
399     SetCencInfoAboutKeyIdIvAlgo(cencInfo);
400     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->QueueInputBufferDec(0, 0, nullptr, 0, cencInfo, true,
401         BufferFlag::CODEC_BUFFER_FLAG_NONE), AudioDecoderAdapterCode::DECODER_ERROR);
402     SetCencInfoAboutClearHeaderAndPayLoadLens(cencInfo);
403     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->QueueInputBufferDec(0, 0, nullptr, 0, cencInfo, true,
404         BufferFlag::CODEC_BUFFER_FLAG_NONE), AudioDecoderAdapterCode::DECODER_ERROR);
405     cencInfo->SetEncryptedBlockCount(0);
406     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->QueueInputBufferDec(0, 0, nullptr, 0, cencInfo, true,
407         BufferFlag::CODEC_BUFFER_FLAG_NONE), AudioDecoderAdapterCode::DECODER_ERROR);
408     const uint32_t ERR_MODE = 10000;
409     cencInfo->SetMode(ERR_MODE);
410     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->QueueInputBufferDec(0, 0, nullptr, 0, cencInfo, true,
411         BufferFlag::CODEC_BUFFER_FLAG_NONE), AudioDecoderAdapterCode::DECODER_ERROR);
412     cencInfo->SetMode(0);
413     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->QueueInputBufferDec(0, 0, nullptr, 0, cencInfo, true,
414         BufferFlag::CODEC_BUFFER_FLAG_NONE), AudioDecoderAdapterCode::DECODER_ERROR);
415     // test QueueInputBufferDec with input buffer and output buffer
416     constexpr int32_t MEMSIZE = 1024 * 1024;
417     OH_AVBuffer* buffer = OH_AVBuffer_Create(MEMSIZE);
418     AudioCodecDecoderAdapterImpl_->SetInputBuffer(0, buffer);
419     AudioCodecDecoderAdapterImpl_->SetOutputBuffer(0, buffer);
420     AudioCodecDecoderAdapterImpl_->SetInputBuffer(0, nullptr);
421     AudioCodecDecoderAdapterImpl_->SetOutputBuffer(0, nullptr);
422 
423     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->QueueInputBufferDec(1, 0, nullptr, 0, cencInfo, true,
424         BufferFlag::CODEC_BUFFER_FLAG_NONE), AudioDecoderAdapterCode::DECODER_ERROR);
425     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->QueueInputBufferDec(0, 0, nullptr, 0, cencInfo, true,
426         BufferFlag::CODEC_BUFFER_FLAG_NONE), AudioDecoderAdapterCode::DECODER_ERROR);
427     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->QueueInputBufferDec(0, 0, nullptr, 0, cencInfo, true,
428         BufferFlag::CODEC_BUFFER_FLAG_EOS), AudioDecoderAdapterCode::DECODER_ERROR);
429     AudioCodecDecoderAdapterImpl_->ReleaseOutputBufferDec(0);
430     OH_AVBuffer_Destroy(buffer);
431     buffer = nullptr;
432 }
433 
434 /**
435  * @tc.name: AudioCodecDecoderAdapterImpl_NormalValueTest_004.
436  * @tc.desc: test of NormalScene in AudioCodecDecoderAdapterImpl
437  * @tc.type: FUNC.
438  * @tc.require:
439  */
440 HWTEST_F(AudioCodecDecoderAdapterImplTest, AudioCodecDecoderAdapterImpl_NormalValueTest_004, TestSize.Level1)
441 {
442     // create decoder by normal mimetype.
443     std::string mimetype = std::string(OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
444     AudioDecoderAdapterCode ret = AudioCodecDecoderAdapterImpl_->CreateAudioDecoderByMime(mimetype);
445     EXPECT_EQ(ret, AudioDecoderAdapterCode::DECODER_OK);
446 
447     // config decoder.
448     constexpr uint32_t DEFAULT_SAMPLERATE = 44100;
449     constexpr uint32_t DEFAULT_BITRATE = 32000;
450     constexpr uint32_t DEFAULT_CHANNEL_COUNT = 2;
451     constexpr uint32_t DEFAULT_MAX_INPUT_SIZE = 1152;
452     format_->SetSampleRate(DEFAULT_SAMPLERATE);
453     format_->SetChannelCount(DEFAULT_CHANNEL_COUNT);
454     format_->SetBitRate(DEFAULT_BITRATE);
455     format_->SetMaxInputSize(DEFAULT_MAX_INPUT_SIZE);
456     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->ConfigureDecoder(nullptr), AudioDecoderAdapterCode::DECODER_ERROR);
457     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->ConfigureDecoder(format_), AudioDecoderAdapterCode::DECODER_OK);
458     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->GetOutputFormatDec(nullptr), AudioDecoderAdapterCode::DECODER_ERROR);
459     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->GetOutputFormatDec(format_), AudioDecoderAdapterCode::DECODER_OK);
460 
461     // set callback for decoding.
462     std::shared_ptr<AudioDecoderCallbackAdapter> callback = std::make_shared<AudioDecoderCallbackAdapterMock>();
463     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->SetCallbackDec(callback), AudioDecoderAdapterCode::DECODER_OK);
464 
465     // prepare decoder.
466     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->PrepareDecoder(), AudioDecoderAdapterCode::DECODER_OK);
467     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->StartDecoder(), AudioDecoderAdapterCode::DECODER_OK);
468     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->SetParameterDecoder(nullptr), AudioDecoderAdapterCode::DECODER_ERROR);
469     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->SetParameterDecoder(format_), AudioDecoderAdapterCode::DECODER_OK);
470     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->FlushDecoder(), AudioDecoderAdapterCode::DECODER_OK);
471     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->StopDecoder(), AudioDecoderAdapterCode::DECODER_OK);
472     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->ResetDecoder(), AudioDecoderAdapterCode::DECODER_OK);
473     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->SetCallbackDec(callback), AudioDecoderAdapterCode::DECODER_OK);
474 
475     EXPECT_EQ(AudioCodecDecoderAdapterImpl_->GetBufferFlag(
476         OHOS::MediaAVCodec::AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_EOS), BufferFlag::CODEC_BUFFER_FLAG_EOS);
477     (void)AudioCodecDecoderAdapterImpl_->GetDecoderMutex();
478 }
479 
480 /**
481  * @tc.name: AudioCodecDecoderAdapterImpl_NormalValueTest_005.
482  * @tc.desc: test of NormalScene in AudioCodecDecoderAdapterImpl
483  * @tc.type: FUNC.
484  * @tc.require:
485  */
486 HWTEST_F(AudioCodecDecoderAdapterImplTest, AudioCodecDecoderAdapterImpl_NormalValueTest_005, TestSize.Level1)
487 {
488     constexpr int32_t DEFAULT_SAMPLERATE = 44100;
489     constexpr int64_t DEFAULT_BITRATE = 32000;
490     constexpr int32_t DEFAULT_CHANNEL_COUNT = 2;
491     constexpr int32_t DEFAULT_MAX_INPUT_SIZE = 1152;
492     constexpr bool DEFAUL_AAC_IS_ADTS = false;
493     constexpr int32_t DEFAULT_AUDIO_SAMPLE_FORMAT = 100;
494     constexpr int32_t DEFAUL_ID_HEARDER = 100;
495     constexpr int32_t DEFAULT_SETUP_HEADER = 100;
496     uint8_t codecConfig[10] = {0};
497     constexpr uint32_t DEFAULT_CODEC_Config_SIZE = 10;
498     std::shared_ptr<AudioDecoderFormatAdapterImpl> format = std::make_shared<AudioDecoderFormatAdapterImpl>();
499     format->SetSampleRate(DEFAULT_SAMPLERATE);
500     format->SetChannelCount(DEFAULT_CHANNEL_COUNT);
501     format->SetBitRate(DEFAULT_BITRATE);
502     format->SetMaxInputSize(DEFAULT_MAX_INPUT_SIZE);
503     format->SetAACIsAdts(DEFAUL_AAC_IS_ADTS);
504     format->SetAudioSampleFormat(DEFAULT_AUDIO_SAMPLE_FORMAT);
505     format->SetIdentificationHeader(DEFAUL_ID_HEARDER);
506     format->SetSetupHeader(DEFAULT_SETUP_HEADER);
507     format->SetCodecConfig(codecConfig);
508     format->SetCodecConfigSize(DEFAULT_CODEC_Config_SIZE);
509     format->PrintFormatData(format);
510     EXPECT_EQ(format->GetSampleRate(), DEFAULT_SAMPLERATE);
511     EXPECT_EQ(format->GetChannelCount(), DEFAULT_CHANNEL_COUNT);
512     EXPECT_EQ(format->GetBitRate(), DEFAULT_BITRATE);
513     EXPECT_EQ(format->GetMaxInputSize(), DEFAULT_MAX_INPUT_SIZE);
514     EXPECT_EQ(format->GetAACIsAdts(), DEFAUL_AAC_IS_ADTS);
515     EXPECT_EQ(format->GetAudioSampleFormat(), DEFAULT_AUDIO_SAMPLE_FORMAT);
516     EXPECT_EQ(format->GetIdentificationHeader(), DEFAUL_ID_HEARDER);
517     EXPECT_EQ(format->GetSetupHeader(), DEFAULT_SETUP_HEADER);
518     EXPECT_EQ(format->GetCodecConfig(), codecConfig);
519     EXPECT_EQ(format->GetCodecConfigSize(), DEFAULT_CODEC_Config_SIZE);
520 }
521 }
522 } // namespace OHOS::NWeb
523