1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <queue>
17 #include <mutex>
18 #include <gtest/gtest.h>
19 #include <iostream>
20 #include <unistd.h>
21 #include <atomic>
22 #include <fstream>
23 #include <string>
24 #include <thread>
25 #include "avcodec_codec_name.h"
26 #include "avcodec_common.h"
27 #include "avcodec_errors.h"
28 #include "avcodec_mime_type.h"
29 #include "media_description.h"
30 #include "native_avcodec_base.h"
31 #include "native_avformat.h"
32 #include "avcodec_common.h"
33 #include "avcodec_errors.h"
34 #include "securec.h"
35 #include "avcodec_audio_common.h"
36 #include "native_avbuffer.h"
37 #include "common/native_mfmagic.h"
38 #include "native_avcodec_audiocodec.h"
39 #include "native_audio_channel_layout.h"
40 #include "media_key_system_mock.h"
41 
42 using namespace std;
43 using namespace testing::ext;
44 using namespace OHOS::MediaAVCodec;
45 
46 namespace {
47 constexpr uint32_t DEFAULT_CHANNEL_COUNT = 2;
48 constexpr uint32_t DEFAULT_SAMPLE_RATE = 44100;
49 constexpr uint32_t ABNORMAL_SAMPLE_RATE = 999999;
50 constexpr uint32_t FLAC_192K_SAMPLE_RATE = 192000;
51 constexpr uint32_t DEFAULT_AAC_TYPE = 1;
52 constexpr uint32_t ABNORMAL_AAC_TYPE = 999999;
53 constexpr int32_t DEFAULT_SAMPLE_FORMAT = AudioSampleFormat::SAMPLE_S16LE;
54 constexpr int32_t ABNORMAL_SAMPLE_FORMAT = AudioSampleFormat::INVALID_WIDTH;
55 constexpr int32_t FLAC_S24_SAMPLE_FORMAT = AudioSampleFormat::SAMPLE_S24LE;
56 constexpr int64_t BITS_RATE[7] = {199000, 261000, 60000, 320000};
57 constexpr uint32_t AMRWB_SAMPLE_RATE = 16000;
58 constexpr uint32_t AMRNB_SAMPLE_RATE = 8000;
59 constexpr uint32_t ONE_CHANNEL_COUNT = 1;
60 constexpr uint32_t ABNORMAL_MAX_CHANNEL_COUNT = 999999;
61 constexpr uint32_t ABNORMAL_MIN_CHANNEL_COUNT = 0;
62 constexpr uint32_t ABNORMAL_MAX_INPUT_SIZE = 99999999;
63 constexpr uint64_t CHANNEL_LAYOUT = OH_AudioChannelLayout::CH_LAYOUT_STEREO;
64 constexpr uint64_t ABNORMAL_CHANNEL_LAYOUT = OH_AudioChannelLayout::CH_LAYOUT_5POINT1POINT2;
65 constexpr string_view INPUT_AAC_FILE_PATH = "/data/test/media/aac_2c_44100hz_199k.dat";
66 constexpr string_view OUTPUT_AAC_PCM_FILE_PATH = "/data/test/media/aac_2c_44100hz_199k.pcm";
67 constexpr string_view INPUT_FLAC_FILE_PATH = "/data/test/media/flac_2c_44100hz_261k.dat";
68 constexpr string_view OUTPUT_FLAC_PCM_FILE_PATH = "/data/test/media/flac_2c_44100hz_261k.pcm";
69 constexpr string_view INPUT_MP3_FILE_PATH = "/data/test/media/mp3_2c_44100hz_60k.dat";
70 constexpr string_view OUTPUT_MP3_PCM_FILE_PATH = "/data/test/media/mp3_2c_44100hz_60k.pcm";
71 constexpr string_view INPUT_VORBIS_FILE_PATH = "/data/test/media/vorbis_2c_44100hz_320k.dat";
72 constexpr string_view OUTPUT_VORBIS_PCM_FILE_PATH = "/data/test/media/vorbis_2c_44100hz_320k.pcm";
73 constexpr string_view INPUT_AMRNB_FILE_PATH = "/data/test/media/voice_amrnb_12200.dat";
74 constexpr string_view OUTPUT_AMRNB_PCM_FILE_PATH = "/data/test/media/voice_amrnb_12200.pcm";
75 constexpr string_view INPUT_AMRWB_FILE_PATH = "/data/test/media/voice_amrwb_23850.dat";
76 constexpr string_view OUTPUT_AMRWB_PCM_FILE_PATH = "/data/test/media/voice_amrwb_23850.pcm";
77 constexpr string_view INPUT_G711MU_FILE_PATH = "/data/test/media/g711mu_8kHz.dat";
78 constexpr string_view OUTPUT_G711MU_PCM_FILE_PATH = "/data/test/media/g711mu_8kHz_decode.pcm";
79 constexpr string_view INPUT_OPUS_FILE_PATH = "/data/test/media/voice_opus.dat";
80 constexpr string_view OUTPUT_OPUS_PCM_FILE_PATH = "/data/test/media/opus_decode.pcm";
81 constexpr string_view INPUT_APE_FILE_PATH = "/data/test/media/voice_ape.dat";
82 constexpr string_view OUTPUT_APE_PCM_FILE_PATH = "/data/test/media/ape_decode.pcm";
83 const string OPUS_SO_FILE_PATH = std::string(AV_CODEC_PATH) + "/libav_codec_ext_base.z.so";
84 } // namespace
85 
86 namespace OHOS {
87 namespace MediaAVCodec {
88 enum class AudioBufferFormatType : int32_t {
89     TYPE_AAC = 0,
90     TYPE_FLAC = 1,
91     TYPE_MP3 = 2,
92     TYPE_VORBIS = 3,
93     TYPE_AMRNB = 4,
94     TYPE_AMRWB = 5,
95     TYPE_G711MU = 6,
96     TYPE_OPUS = 7,
97     TYPE_APE = 8,
98     TYPE_MAX = 9,
99 };
100 
101 class AudioCodecBufferSignal {
102 public:
103     std::mutex inMutex_;
104     std::mutex outMutex_;
105     std::mutex startMutex_;
106     std::condition_variable inCond_;
107     std::condition_variable outCond_;
108     std::condition_variable startCond_;
109     std::queue<uint32_t> inQueue_;
110     std::queue<uint32_t> outQueue_;
111     std::queue<OH_AVBuffer *> inBufferQueue_;
112     std::queue<OH_AVBuffer *> outBufferQueue_;
113 };
114 
OnError(OH_AVCodec * codec,int32_t errorCode,void * userData)115 static void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData)
116 {
117     (void)codec;
118     (void)errorCode;
119     (void)userData;
120     cout << "Error received, errorCode:" << errorCode << endl;
121 }
122 
OnOutputFormatChanged(OH_AVCodec * codec,OH_AVFormat * format,void * userData)123 static void OnOutputFormatChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData)
124 {
125     (void)codec;
126     (void)format;
127     (void)userData;
128     cout << "OnOutputFormatChanged received" << endl;
129 }
130 
OnInputBufferAvailable(OH_AVCodec * codec,uint32_t index,OH_AVBuffer * data,void * userData)131 static void OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData)
132 {
133     (void)codec;
134     AudioCodecBufferSignal *signal = static_cast<AudioCodecBufferSignal *>(userData);
135     unique_lock<mutex> lock(signal->inMutex_);
136     signal->inQueue_.push(index);
137     signal->inBufferQueue_.push(data);
138     signal->inCond_.notify_all();
139 }
140 
OnOutputBufferAvailable(OH_AVCodec * codec,uint32_t index,OH_AVBuffer * data,void * userData)141 static void OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData)
142 {
143     (void)codec;
144     AudioCodecBufferSignal *signal = static_cast<AudioCodecBufferSignal *>(userData);
145     unique_lock<mutex> lock(signal->outMutex_);
146     signal->outQueue_.push(index);
147     signal->outBufferQueue_.push(data);
148     signal->outCond_.notify_all();
149 }
150 
151 class AudioDecoderBufferCapiUnitTest : public testing::Test {
152 public:
153     static void SetUpTestCase(void);
154     static void TearDownTestCase(void);
155     void SetUp();
156     void TearDown();
157     bool ReadBuffer(OH_AVBuffer *buffer, uint32_t index);
158     int32_t InitFile(AudioBufferFormatType audioType);
159     void InputFunc();
160     void OutputFunc();
161     int32_t CreateCodecFunc(AudioBufferFormatType audioType);
162     int32_t CheckSoFunc();
163     void HandleInputEOS(const uint32_t index);
164     int32_t Configure(AudioBufferFormatType audioType);
165     int32_t Start();
166     int32_t Stop();
167     void Release();
168 
169 protected:
170     std::atomic<bool> isRunning_ = false;
171     std::unique_ptr<std::thread> inputLoop_;
172     std::unique_ptr<std::thread> outputLoop_;
173     struct OH_AVCodecCallback cb_;
174     AudioCodecBufferSignal *signal_ = nullptr;
175     OH_AVCodec *audioDec_ = nullptr;
176     OH_AVFormat *format_ = nullptr;
177     bool isFirstFrame_ = true;
178     uint32_t frameCount_ = 0;
179     std::ifstream inputFile_;
180     std::unique_ptr<std::ifstream> soFile_;
181     std::ofstream pcmOutputFile_;
182 };
183 
SetUpTestCase(void)184 void AudioDecoderBufferCapiUnitTest::SetUpTestCase(void)
185 {
186     cout << "[SetUpTestCase]: " << endl;
187 }
188 
TearDownTestCase(void)189 void AudioDecoderBufferCapiUnitTest::TearDownTestCase(void)
190 {
191     cout << "[TearDownTestCase]: " << endl;
192 }
193 
SetUp(void)194 void AudioDecoderBufferCapiUnitTest::SetUp(void)
195 {
196     cout << "[SetUp]: SetUp!!!" << endl;
197 }
198 
TearDown(void)199 void AudioDecoderBufferCapiUnitTest::TearDown(void)
200 {
201     cout << "[TearDown]: over!!!" << endl;
202 
203     if (signal_) {
204         delete signal_;
205         signal_ = nullptr;
206     }
207     if (inputFile_.is_open()) {
208         inputFile_.close();
209     }
210     if (pcmOutputFile_.is_open()) {
211         pcmOutputFile_.close();
212     }
213 }
214 
Release()215 void AudioDecoderBufferCapiUnitTest::Release()
216 {
217     Stop();
218     OH_AudioCodec_Destroy(audioDec_);
219 }
220 
HandleInputEOS(const uint32_t index)221 void AudioDecoderBufferCapiUnitTest::HandleInputEOS(const uint32_t index)
222 {
223     std::cout << "end buffer\n";
224     OH_AudioCodec_PushInputBuffer(audioDec_, index);
225     signal_->inBufferQueue_.pop();
226     signal_->inQueue_.pop();
227 }
228 
ReadBuffer(OH_AVBuffer * buffer,uint32_t index)229 bool AudioDecoderBufferCapiUnitTest::ReadBuffer(OH_AVBuffer *buffer, uint32_t index)
230 {
231     int64_t size;
232     int64_t pts;
233     inputFile_.read(reinterpret_cast<char *>(&size), sizeof(size));
234     if (inputFile_.eof() || inputFile_.gcount() == 0 || size == 0) {
235         buffer->buffer_->memory_->SetSize(1);
236         buffer->buffer_->flag_ = AVCODEC_BUFFER_FLAGS_EOS;
237         HandleInputEOS(index);
238         cout << "Set EOS" << endl;
239         return false;
240     }
241 
242     if (inputFile_.gcount() != sizeof(size)) {
243         cout << "Fatal: read size fail" << endl;
244         return false;
245     }
246 
247     inputFile_.read(reinterpret_cast<char *>(&buffer->buffer_->pts_), sizeof(buffer->buffer_->pts_));
248     if (inputFile_.gcount() != sizeof(pts)) {
249         cout << "Fatal: read size fail" << endl;
250         return false;
251     }
252 
253     inputFile_.read((char *)OH_AVBuffer_GetAddr(buffer), size);
254     buffer->buffer_->memory_->SetSize(size);
255     if (inputFile_.gcount() != size) {
256         cout << "Fatal: read buffer fail" << endl;
257         return false;
258     }
259 
260     return true;
261 }
262 
InputFunc()263 void AudioDecoderBufferCapiUnitTest::InputFunc()
264 {
265     while (isRunning_.load()) {
266         unique_lock<mutex> lock(signal_->inMutex_);
267         signal_->inCond_.wait(lock, [this]() { return (signal_->inQueue_.size() > 0 || !isRunning_.load()); });
268 
269         if (!isRunning_.load()) {
270             break;
271         }
272 
273         uint32_t index = signal_->inQueue_.front();
274         auto buffer = signal_->inBufferQueue_.front();
275         if (buffer == nullptr) {
276             cout << "Fatal: GetInputBuffer fail" << endl;
277             break;
278         }
279         if (ReadBuffer(buffer, index) == false) {
280             break;
281         }
282 
283         int32_t ret;
284         if (isFirstFrame_) {
285             buffer->buffer_->flag_ = AVCODEC_BUFFER_FLAGS_CODEC_DATA;
286             ret = OH_AudioCodec_PushInputBuffer(audioDec_, index);
287             isFirstFrame_ = false;
288         } else {
289             buffer->buffer_->flag_ = AVCODEC_BUFFER_FLAGS_NONE;
290             ret = OH_AudioCodec_PushInputBuffer(audioDec_, index);
291         }
292         signal_->inQueue_.pop();
293         signal_->inBufferQueue_.pop();
294         frameCount_++;
295         if (ret != AVCS_ERR_OK) {
296             cout << "Fatal error, exit" << endl;
297             break;
298         }
299     }
300     cout << "stop, exit" << endl;
301     inputFile_.close();
302 }
303 
OutputFunc()304 void AudioDecoderBufferCapiUnitTest::OutputFunc()
305 {
306     if (!pcmOutputFile_.is_open()) {
307         std::cout << "open " << OUTPUT_MP3_PCM_FILE_PATH << " failed!" << std::endl;
308     }
309     while (isRunning_.load()) {
310         unique_lock<mutex> lock(signal_->outMutex_);
311         signal_->outCond_.wait(lock, [this]() { return (signal_->outQueue_.size() > 0 || !isRunning_.load()); });
312 
313         if (!isRunning_.load()) {
314             cout << "wait to stop, exit" << endl;
315             break;
316         }
317 
318         uint32_t index = signal_->outQueue_.front();
319         OH_AVBuffer *data = signal_->outBufferQueue_.front();
320 
321         if (data == nullptr) {
322             cout << "OutputFunc OH_AVBuffer is nullptr" << endl;
323             continue;
324         }
325         pcmOutputFile_.write(reinterpret_cast<char *>(OH_AVBuffer_GetAddr(data)), data->buffer_->memory_->GetSize());
326 
327         if (data != nullptr &&
328             (data->buffer_->flag_ == AVCODEC_BUFFER_FLAGS_EOS || data->buffer_->memory_->GetSize() == 0)) {
329             cout << "decode eos" << endl;
330             isRunning_.store(false);
331             signal_->startCond_.notify_all();
332         }
333         signal_->outBufferQueue_.pop();
334         signal_->outQueue_.pop();
335         if (OH_AudioCodec_FreeOutputBuffer(audioDec_, index) != AV_ERR_OK) {
336             cout << "Fatal: FreeOutputData fail" << endl;
337             break;
338         }
339 
340         if (data->buffer_->flag_ == AVCODEC_BUFFER_FLAGS_EOS) {
341             cout << "decode eos" << endl;
342             isRunning_.store(false);
343             signal_->startCond_.notify_all();
344         }
345     }
346     cout << "stop, exit" << endl;
347     pcmOutputFile_.close();
348 }
349 
Start()350 int32_t AudioDecoderBufferCapiUnitTest::Start()
351 {
352     isRunning_.store(true);
353     inputLoop_ = make_unique<thread>(&AudioDecoderBufferCapiUnitTest::InputFunc, this);
354     if (inputLoop_ == nullptr) {
355         cout << "Fatal: No memory" << endl;
356         return OH_AVErrCode::AV_ERR_UNKNOWN;
357     }
358 
359     outputLoop_ = make_unique<thread>(&AudioDecoderBufferCapiUnitTest::OutputFunc, this);
360     if (outputLoop_ == nullptr) {
361         cout << "Fatal: No memory" << endl;
362         return OH_AVErrCode::AV_ERR_UNKNOWN;
363     }
364 
365     return OH_AudioCodec_Start(audioDec_);
366 }
367 
Stop()368 int32_t AudioDecoderBufferCapiUnitTest::Stop()
369 {
370     isRunning_.store(false);
371     if (inputLoop_ != nullptr && inputLoop_->joinable()) {
372         {
373             unique_lock<mutex> lock(signal_->inMutex_);
374             signal_->inCond_.notify_all();
375         }
376         inputLoop_->join();
377         inputLoop_ = nullptr;
378         while (!signal_->inQueue_.empty()) {
379             signal_->inQueue_.pop();
380         }
381         while (!signal_->inBufferQueue_.empty()) {
382             signal_->inBufferQueue_.pop();
383         }
384     }
385 
386     if (outputLoop_ != nullptr && outputLoop_->joinable()) {
387         {
388             unique_lock<mutex> lock(signal_->outMutex_);
389             signal_->outCond_.notify_all();
390         }
391         outputLoop_->join();
392         outputLoop_ = nullptr;
393         while (!signal_->outQueue_.empty()) {
394             signal_->outQueue_.pop();
395         }
396         while (!signal_->outBufferQueue_.empty()) {
397             signal_->outBufferQueue_.pop();
398         }
399     }
400     std::cout << "start stop!\n";
401     return OH_AudioCodec_Stop(audioDec_);
402 }
403 
InitFile(AudioBufferFormatType audioType)404 int32_t AudioDecoderBufferCapiUnitTest::InitFile(AudioBufferFormatType audioType)
405 {
406     if (audioType == AudioBufferFormatType::TYPE_AAC) {
407         inputFile_.open(INPUT_AAC_FILE_PATH, std::ios::binary);
408         pcmOutputFile_.open(OUTPUT_AAC_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
409     } else if (audioType == AudioBufferFormatType::TYPE_FLAC) {
410         inputFile_.open(INPUT_FLAC_FILE_PATH, std::ios::binary);
411         pcmOutputFile_.open(OUTPUT_FLAC_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
412     } else if (audioType == AudioBufferFormatType::TYPE_MP3) {
413         inputFile_.open(INPUT_MP3_FILE_PATH, std::ios::binary);
414         pcmOutputFile_.open(OUTPUT_MP3_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
415     } else if (audioType == AudioBufferFormatType::TYPE_VORBIS) {
416         inputFile_.open(INPUT_VORBIS_FILE_PATH, std::ios::binary);
417         pcmOutputFile_.open(OUTPUT_VORBIS_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
418     } else if (audioType == AudioBufferFormatType::TYPE_AMRNB) {
419         inputFile_.open(INPUT_AMRNB_FILE_PATH, std::ios::binary);
420         pcmOutputFile_.open(OUTPUT_AMRNB_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
421     } else if (audioType == AudioBufferFormatType::TYPE_AMRWB) {
422         inputFile_.open(INPUT_AMRWB_FILE_PATH, std::ios::binary);
423         pcmOutputFile_.open(OUTPUT_AMRWB_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
424     } else if (audioType == AudioBufferFormatType::TYPE_G711MU) {
425         inputFile_.open(INPUT_G711MU_FILE_PATH, std::ios::binary);
426         pcmOutputFile_.open(OUTPUT_G711MU_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
427     } else if (audioType == AudioBufferFormatType::TYPE_OPUS) {
428         inputFile_.open(INPUT_OPUS_FILE_PATH, std::ios::binary);
429         pcmOutputFile_.open(OUTPUT_OPUS_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
430     } else if (audioType == AudioBufferFormatType::TYPE_APE) {
431         inputFile_.open(INPUT_APE_FILE_PATH, std::ios::binary);
432         pcmOutputFile_.open(OUTPUT_APE_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
433     } else {
434         cout << "Fatal: audio format type not support" << endl;
435         return OH_AVErrCode::AV_ERR_UNKNOWN;
436     }
437 
438     if (!inputFile_.is_open()) {
439         cout << "Fatal: open input file failed" << endl;
440         return OH_AVErrCode::AV_ERR_UNKNOWN;
441     }
442     if (!pcmOutputFile_.is_open()) {
443         cout << "Fatal: open output file failed" << endl;
444         return OH_AVErrCode::AV_ERR_UNKNOWN;
445     }
446     return OH_AVErrCode::AV_ERR_OK;
447 }
448 
CreateCodecFunc(AudioBufferFormatType audioType)449 int32_t AudioDecoderBufferCapiUnitTest::CreateCodecFunc(AudioBufferFormatType audioType)
450 {
451     if (audioType == AudioBufferFormatType::TYPE_MP3) {
452         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_MP3_NAME).data());
453     } else if (audioType == AudioBufferFormatType::TYPE_FLAC) {
454         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_FLAC_NAME).data());
455     } else if (audioType == AudioBufferFormatType::TYPE_AAC) {
456         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AAC_NAME).data());
457     } else if (audioType == AudioBufferFormatType::TYPE_VORBIS) {
458         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_VORBIS_NAME).data());
459     } else if (audioType == AudioBufferFormatType::TYPE_AMRWB) {
460         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AMRWB_NAME).data());
461     } else if (audioType == AudioBufferFormatType::TYPE_AMRNB) {
462         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AMRNB_NAME).data());
463     } else if (audioType == AudioBufferFormatType::TYPE_G711MU) {
464         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_G711MU_NAME).data());
465     } else if (audioType == AudioBufferFormatType::TYPE_OPUS) {
466         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_OPUS_NAME).data());
467     } else if (audioType == AudioBufferFormatType::TYPE_APE) {
468         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_APE_NAME).data());
469     } else {
470         cout << "audio name not support" << endl;
471         return OH_AVErrCode::AV_ERR_UNKNOWN;
472     }
473 
474     if (audioDec_ == nullptr) {
475         cout << "Fatal: CreateByName fail" << endl;
476         return OH_AVErrCode::AV_ERR_UNKNOWN;
477     }
478 
479     signal_ = new AudioCodecBufferSignal();
480     if (signal_ == nullptr) {
481         cout << "Fatal: create signal fail" << endl;
482         return OH_AVErrCode::AV_ERR_UNKNOWN;
483     }
484     cb_ = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, &OnOutputBufferAvailable};
485     int32_t ret = OH_AudioCodec_RegisterCallback(audioDec_, cb_, signal_);
486     if (ret != OH_AVErrCode::AV_ERR_OK) {
487         cout << "Fatal: SetCallback fail" << endl;
488         return OH_AVErrCode::AV_ERR_UNKNOWN;
489     }
490 
491     return OH_AVErrCode::AV_ERR_OK;
492 }
493 
Configure(AudioBufferFormatType audioType)494 int32_t AudioDecoderBufferCapiUnitTest::Configure(AudioBufferFormatType audioType)
495 {
496     format_ = OH_AVFormat_Create();
497     if (format_ == nullptr) {
498         cout << "Fatal: create format failed" << endl;
499         return OH_AVErrCode::AV_ERR_UNKNOWN;
500     }
501     int32_t channelCount = DEFAULT_CHANNEL_COUNT;
502     int32_t sampleRate = DEFAULT_SAMPLE_RATE;
503     if (audioType == AudioBufferFormatType::TYPE_AAC) {
504         OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AAC_IS_ADTS.data(), DEFAULT_AAC_TYPE);
505         OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
506                                 DEFAULT_SAMPLE_FORMAT);
507     } else if (audioType == AudioBufferFormatType::TYPE_AMRNB || audioType == AudioBufferFormatType::TYPE_G711MU ||
508         audioType == AudioBufferFormatType::TYPE_OPUS || audioType == AudioBufferFormatType::TYPE_APE) {
509         channelCount = 1;
510         sampleRate = AMRNB_SAMPLE_RATE;
511     } else if (audioType == AudioBufferFormatType::TYPE_AMRWB) {
512         channelCount = 1;
513         sampleRate = AMRWB_SAMPLE_RATE;
514         OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
515                                 DEFAULT_SAMPLE_FORMAT);
516     }
517     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), channelCount);
518     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), sampleRate);
519     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(), BITS_RATE[(uint32_t)audioType]);
520     if (audioType == AudioBufferFormatType::TYPE_VORBIS) {
521         OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
522                                 DEFAULT_SAMPLE_FORMAT);
523         int64_t extradataSize;
524         if (!inputFile_.is_open()) {
525             cout << "Fatal: file is not open" << endl;
526             return OH_AVErrCode::AV_ERR_UNKNOWN;
527         }
528         inputFile_.read(reinterpret_cast<char *>(&extradataSize), sizeof(int64_t));
529         if (inputFile_.gcount() != sizeof(int64_t) || extradataSize < 0) {
530             cout << "Fatal: read extradataSize bytes error" << endl;
531             return OH_AVErrCode::AV_ERR_UNKNOWN;
532         }
533         char buffer[extradataSize];
534         inputFile_.read(buffer, extradataSize);
535         if (inputFile_.gcount() != extradataSize) {
536             cout << "Fatal: read extradata bytes error" << endl;
537             return OH_AVErrCode::AV_ERR_UNKNOWN;
538         }
539         OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_CODEC_CONFIG.data(), (uint8_t *)buffer,
540                               extradataSize);
541     }
542     return OH_AudioCodec_Configure(audioDec_, format_);
543 }
544 
CheckSoFunc()545 int32_t AudioDecoderBufferCapiUnitTest::CheckSoFunc()
546 {
547     soFile_ = std::make_unique<std::ifstream>(OPUS_SO_FILE_PATH, std::ios::binary);
548     if (!soFile_->is_open()) {
549         cout << "Fatal: Open so file failed" << endl;
550         return false;
551     }
552     soFile_->close();
553     return true;
554 }
555 
556 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_CreateByMime_01, TestSize.Level1)
557 {
558     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_MPEG.data(), false);
559     EXPECT_NE(nullptr, audioDec_);
560     Release();
561 }
562 
563 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_CreateByName_01, TestSize.Level1)
564 {
565     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_MP3_NAME).data());
566     EXPECT_NE(nullptr, audioDec_);
567     Release();
568 }
569 
570 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Configure_01, TestSize.Level1)
571 {
572     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
573     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
574     Release();
575 }
576 
577 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Configure_02, TestSize.Level1)
578 {
579     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
580     format_ = OH_AVFormat_Create();
581     EXPECT_NE(nullptr, format_);
582 
583     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
584     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
585     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
586         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_MP3]);
587     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
588 
589     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
590     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
591     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal min channel count
592 
593     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
594     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MAX_CHANNEL_COUNT);
595     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal max channel count
596 
597     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
598     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
599     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
600 
601     Release();
602 }
603 
604 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Configure_03, TestSize.Level1)
605 {
606     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
607     format_ = OH_AVFormat_Create();
608     EXPECT_NE(nullptr, format_);
609 
610     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
611     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
612     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
613         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_MP3]);
614     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
615 
616     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
617     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
618     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample rate
619 
620     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
621     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
622     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
623 
624     Release();
625 }
626 
627 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Configure_04, TestSize.Level1)
628 {
629     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
630     format_ = OH_AVFormat_Create();
631     EXPECT_NE(nullptr, format_);
632 
633     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
634     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
635     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
636         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_MP3]);
637     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
638     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT.data(), CHANNEL_LAYOUT);
639     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel layout
640 
641     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
642     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT.data(), ABNORMAL_CHANNEL_LAYOUT);
643     ASSERT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal channel layout
644     Release();
645 }
646 
647 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_SetParameter_01, TestSize.Level1)
648 {
649     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
650     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
651     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
652     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
653     {
654         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa840402() 655         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
656     }
657     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
658     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
659     Release();
660 }
661 
662 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_SetParameter_02, TestSize.Level1)
663 {
664     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
665     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
666     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
667     Release();
668 }
669 
670 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Start_01, TestSize.Level1)
671 {
672     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
673     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
674     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
675     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
676     {
677         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa840502() 678         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
679     }
680     Release();
681 }
682 
683 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Start_02, TestSize.Level1)
684 {
685     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
686     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
687     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
688     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
689     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
690     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
691     {
692         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa840602() 693         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
694     }
695     Release();
696 }
697 
698 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Stop_01, TestSize.Level1)
699 {
700     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
701     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
702     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
703     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
704     sleep(1);
705 
706     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
707     Release();
708 }
709 
710 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Flush_01, TestSize.Level1)
711 {
712     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
713     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
714     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
715     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
716     {
717         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa840702() 718         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
719     }
720     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
721     Release();
722 }
723 
724 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Reset_01, TestSize.Level1)
725 {
726     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
727     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
728     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
729     Release();
730 }
731 
732 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Reset_02, TestSize.Level1)
733 {
734     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
735     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
736     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
737     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
738     {
739         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa840802() 740         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
741     }
742     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
743     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
744     Release();
745 }
746 
747 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Reset_03, TestSize.Level1)
748 {
749     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
750     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
751     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
752     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
753     {
754         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa840902() 755         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
756     }
757     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
758     Release();
759 }
760 
761 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Destroy_01, TestSize.Level1)
762 {
763     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
764     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
765     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
766     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
767     {
768         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa840a02() 769         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
770     }
771     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
772     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
773 }
774 
775 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Destroy_02, TestSize.Level1)
776 {
777     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
778     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
779     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
780 
781     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
782 }
783 
784 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_GetOutputFormat_01, TestSize.Level1)
785 {
786     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
787     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
788     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
789 
790     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
791     Release();
792 }
793 
794 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_State_01, TestSize.Level1)
795 {
796     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
797     bool isValid = false;
798     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
799     Release();
800 }
801 
802 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_IsValid_01, TestSize.Level1)
803 {
804     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
805     bool isValid = false;
806     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
807     Release();
808 }
809 
810 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Prepare_01, TestSize.Level1)
811 {
812     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
813     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
814     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
815     Release();
816 }
817 
818 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_PushInputData_01, TestSize.Level1)
819 {
820     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
821     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
822     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
823     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
824 
825     // case0 传参异常
826     const uint32_t index = 1024;
827     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
828     Release();
829 }
830 
831 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_ReleaseOutputBuffer_01, TestSize.Level1)
832 {
833     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
834     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
835     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
836     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
837 
838     // case0 传参异常
839     const uint32_t index = 1024;
840     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
841     Release();
842 }
843 
844 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_CreateByMime_01, TestSize.Level1)
845 {
846     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_FLAC.data(), false);
847     EXPECT_NE(nullptr, audioDec_);
848     Release();
849 }
850 
851 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_CreateByName_01, TestSize.Level1)
852 {
853     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_FLAC_NAME).data());
854     EXPECT_NE(nullptr, audioDec_);
855     Release();
856 }
857 
858 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_01, TestSize.Level1)
859 {
860     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
861     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
862     Release();
863 }
864 
865 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_02, TestSize.Level1)
866 {
867     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
868     format_ = OH_AVFormat_Create();
869     EXPECT_NE(nullptr, format_);
870     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
871     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
872     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
873                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
874     ASSERT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
875     Release();
876 }
877 
878 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_03, TestSize.Level1)
879 {
880     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
881     format_ = OH_AVFormat_Create();
882     EXPECT_NE(nullptr, format_);
883     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MAX_CHANNEL_COUNT);
884     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
885     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
886                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
887     ASSERT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
888     Release();
889 }
890 
891 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_04, TestSize.Level1)
892 {
893     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
894     format_ = OH_AVFormat_Create();
895     EXPECT_NE(nullptr, format_);
896     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
897     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
898     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
899                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
900     ASSERT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
901     Release();
902 }
903 
904 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_05, TestSize.Level1)
905 {
906     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
907     format_ = OH_AVFormat_Create();
908     EXPECT_NE(nullptr, format_);
909     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
910     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), FLAC_192K_SAMPLE_RATE);
911     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
912                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
913     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
914     Release();
915 }
916 
917 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_06, TestSize.Level1)
918 {
919     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
920     format_ = OH_AVFormat_Create();
921     EXPECT_NE(nullptr, format_);
922     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
923     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
924     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
925                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
926     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
927     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
928     Release();
929 }
930 
931 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_07, TestSize.Level1)
932 {
933     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
934     format_ = OH_AVFormat_Create();
935     EXPECT_NE(nullptr, format_);
936     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
937     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
938     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
939                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
940     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), FLAC_S24_SAMPLE_FORMAT);
941     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
942     Release();
943 }
944 
945 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_08, TestSize.Level1)
946 {
947     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
948     format_ = OH_AVFormat_Create();
949     EXPECT_NE(nullptr, format_);
950     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
951     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
952     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
953                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
954     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
955     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT.data(), CHANNEL_LAYOUT);
956     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel layout
957 
958     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
959     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT.data(), ABNORMAL_CHANNEL_LAYOUT);
960     ASSERT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal channel layout
961     Release();
962 }
963 
964 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_SetParameter_01, TestSize.Level1)
965 {
966     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
967     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
968     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
969     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
970     {
971         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa840b02() 972         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
973     }
974     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
975     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
976     Release();
977 }
978 
979 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_SetParameter_02, TestSize.Level1)
980 {
981     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
982     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
983     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
984     Release();
985 }
986 
987 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Start_01, TestSize.Level1)
988 {
989     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
990     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
991     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
992     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
993     {
994         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa840c02() 995         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
996     }
997     Release();
998 }
999 
1000 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Start_02, TestSize.Level1)
1001 {
1002     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1003     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1004     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1005     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1006     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1007     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
1008     {
1009         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa840d02() 1010         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1011     }
1012     Release();
1013 }
1014 
1015 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Stop_01, TestSize.Level1)
1016 {
1017     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1018     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1019     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1020     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1021     sleep(1);
1022 
1023     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1024     Release();
1025 }
1026 
1027 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Flush_01, TestSize.Level1)
1028 {
1029     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1030     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1031     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1032     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1033     {
1034         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa840e02() 1035         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1036     }
1037     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1038     Release();
1039 }
1040 
1041 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Reset_01, TestSize.Level1)
1042 {
1043     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1044     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1045     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1046     Release();
1047 }
1048 
1049 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Reset_02, TestSize.Level1)
1050 {
1051     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1052     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1053     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1054     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1055     {
1056         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa840f02() 1057         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1058     }
1059     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1060     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1061     Release();
1062 }
1063 
1064 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Reset_03, TestSize.Level1)
1065 {
1066     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1067     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1068     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1069     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1070     {
1071         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841002() 1072         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1073     }
1074     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1075     Release();
1076 }
1077 
1078 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Destroy_01, TestSize.Level1)
1079 {
1080     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1081     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1082     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1083     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1084     {
1085         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841102() 1086         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1087     }
1088     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1089     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
1090 }
1091 
1092 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Destroy_02, TestSize.Level1)
1093 {
1094     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1095     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1096     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1097 
1098     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
1099 }
1100 
1101 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_GetOutputFormat_01, TestSize.Level1)
1102 {
1103     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1104     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1105     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1106 
1107     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
1108     Release();
1109 }
1110 
1111 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_IsValid_01, TestSize.Level1)
1112 {
1113     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1114     bool isValid = false;
1115     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
1116     Release();
1117 }
1118 
1119 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Prepare_01, TestSize.Level1)
1120 {
1121     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1122     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1123     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
1124     Release();
1125 }
1126 
1127 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_PushInputData_01, TestSize.Level1)
1128 {
1129     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1130     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1131     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1132     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1133 
1134     // case0 传参异常
1135     const uint32_t index = 1024;
1136     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
1137     Release();
1138 }
1139 
1140 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_ReleaseOutputBuffer_01, TestSize.Level1)
1141 {
1142     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1143     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1144     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1145     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1146 
1147     // case0 传参异常
1148     const uint32_t index = 1024;
1149     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
1150     Release();
1151 }
1152 
1153 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_192k_01, TestSize.Level1)
1154 {
1155     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1156     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1157     format_ = OH_AVFormat_Create();
1158     EXPECT_NE(nullptr, format_);
1159     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1160     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), FLAC_192K_SAMPLE_RATE);
1161     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1162                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
1163     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
1164     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1165     {
1166         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841202() 1167         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1168     }
1169     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1170     Release();
1171 }
1172 
1173 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_CreateByMime_01, TestSize.Level1)
1174 {
1175     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_AAC.data(), false);
1176     EXPECT_NE(nullptr, audioDec_);
1177     Release();
1178 }
1179 
1180 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_CreateByName_01, TestSize.Level1)
1181 {
1182     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AAC_NAME).data());
1183     EXPECT_NE(nullptr, audioDec_);
1184     Release();
1185 }
1186 
1187 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Configure_01, TestSize.Level1)
1188 {
1189     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1190     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1191     Release();
1192 }
1193 
1194 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Configure_02, TestSize.Level1)
1195 {
1196     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1197     format_ = OH_AVFormat_Create();
1198     EXPECT_NE(nullptr, format_);
1199 
1200     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1201     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1202     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1203     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1204         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_AAC]);
1205     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AAC_IS_ADTS.data(), ABNORMAL_AAC_TYPE);
1206     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal aac type
1207 
1208     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1209     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AAC_IS_ADTS.data(), DEFAULT_AAC_TYPE);
1210     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal aac type
1211 
1212     Release();
1213 }
1214 
1215 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Configure_03, TestSize.Level1)
1216 {
1217     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1218     format_ = OH_AVFormat_Create();
1219     EXPECT_NE(nullptr, format_);
1220 
1221     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1222     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AAC_IS_ADTS.data(), DEFAULT_AAC_TYPE);
1223     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1224     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1225         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_AAC]);
1226     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
1227 
1228     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1229     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
1230     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal min channel count
1231 
1232     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1233     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MAX_CHANNEL_COUNT);
1234     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal max channel count
1235 
1236     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1237     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1238     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
1239 
1240     Release();
1241 }
1242 
1243 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Configure_04, TestSize.Level1)
1244 {
1245     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1246     format_ = OH_AVFormat_Create();
1247     EXPECT_NE(nullptr, format_);
1248 
1249     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1250     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AAC_IS_ADTS.data(), DEFAULT_AAC_TYPE);
1251     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1252     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1253         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_AAC]);
1254     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
1255 
1256     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1257     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
1258     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample rate
1259 
1260     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1261     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1262     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
1263 
1264     Release();
1265 }
1266 
1267 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Configure_05, TestSize.Level1)
1268 {
1269     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1270     format_ = OH_AVFormat_Create();
1271     EXPECT_NE(nullptr, format_);
1272 
1273     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AAC_IS_ADTS.data(), DEFAULT_AAC_TYPE);
1274     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1275     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1276     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1277         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_AAC]);
1278     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), ABNORMAL_SAMPLE_FORMAT);
1279     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // default change to s16le
1280 
1281     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1282     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1283     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample format
1284 
1285     Release();
1286 }
1287 
1288 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_SetParameter_01, TestSize.Level1)
1289 {
1290     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1291     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1292     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1293     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1294     {
1295         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841302() 1296         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1297     }
1298     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1299     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
1300     Release();
1301 }
1302 
1303 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_SetParameter_02, TestSize.Level1)
1304 {
1305     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1306     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1307     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
1308     Release();
1309 }
1310 
1311 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Start_01, TestSize.Level1)
1312 {
1313     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1314     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1315     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1316     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1317     {
1318         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841402() 1319         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1320     }
1321     Release();
1322 }
1323 
1324 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Start_02, TestSize.Level1)
1325 {
1326     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1327     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1328     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1329     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1330     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1331     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
1332     {
1333         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841502() 1334         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1335     }
1336     Release();
1337 }
1338 
1339 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Stop_01, TestSize.Level1)
1340 {
1341     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1342     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1343     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1344     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1345     sleep(1);
1346 
1347     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1348     Release();
1349 }
1350 
1351 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Flush_01, TestSize.Level1)
1352 {
1353     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1354     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1355     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1356     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1357     {
1358         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841602() 1359         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1360     }
1361     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1362     Release();
1363 }
1364 
1365 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Reset_01, TestSize.Level1)
1366 {
1367     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1368     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1369     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1370     Release();
1371 }
1372 
1373 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Reset_02, TestSize.Level1)
1374 {
1375     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1376     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1377     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1378     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1379     {
1380         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841702() 1381         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1382     }
1383     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1384     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1385     Release();
1386 }
1387 
1388 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Reset_03, TestSize.Level1)
1389 {
1390     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1391     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1392     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1393     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1394     {
1395         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841802() 1396         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1397     }
1398     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1399     Release();
1400 }
1401 
1402 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Destroy_01, TestSize.Level1)
1403 {
1404     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1405     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1406     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1407     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1408     {
1409         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841902() 1410         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1411     }
1412     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1413     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
1414 }
1415 
1416 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Destroy_02, TestSize.Level1)
1417 {
1418     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1419     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1420     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1421 
1422     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
1423 }
1424 
1425 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_GetOutputFormat_01, TestSize.Level1)
1426 {
1427     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1428     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1429     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1430 
1431     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
1432     Release();
1433 }
1434 
1435 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_IsValid_01, TestSize.Level1)
1436 {
1437     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1438     bool isValid = false;
1439     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
1440     Release();
1441 }
1442 
1443 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Prepare_01, TestSize.Level1)
1444 {
1445     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1446     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1447     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
1448     Release();
1449 }
1450 
1451 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_PushInputData_01, TestSize.Level1)
1452 {
1453     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1454     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1455     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1456     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1457 
1458     // case0 传参异常
1459     const uint32_t index = 1024;
1460     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
1461     Release();
1462 }
1463 
1464 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_ReleaseOutputBuffer_01, TestSize.Level1)
1465 {
1466     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1467     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1468     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1469     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1470 
1471     // case0 传参异常
1472     const uint32_t index = 1024;
1473     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
1474     Release();
1475 }
1476 
1477 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_CreateByMime_01, TestSize.Level1)
1478 {
1479     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_VORBIS.data(), false);
1480     EXPECT_NE(nullptr, audioDec_);
1481     Release();
1482 }
1483 
1484 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_CreateByName_01, TestSize.Level1)
1485 {
1486     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_VORBIS_NAME).data());
1487     EXPECT_NE(nullptr, audioDec_);
1488     Release();
1489 }
1490 
1491 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Configure_01, TestSize.Level1)
1492 {
1493     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1494     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1495     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1496     Release();
1497 }
1498 
1499 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Configure_02, TestSize.Level1)
1500 {
1501     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1502     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1503     format_ = OH_AVFormat_Create();
1504     EXPECT_NE(nullptr, format_);
1505 
1506     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1507     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1508     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1509         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_VORBIS]);
1510     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
1511 
1512     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1513     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
1514     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal min channel count
1515 
1516     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1517     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MAX_CHANNEL_COUNT);
1518     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal max channel count
1519 
1520     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1521     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1522     int64_t extradataSize;
1523     EXPECT_EQ(true, inputFile_.is_open());
1524     inputFile_.read(reinterpret_cast<char *>(&extradataSize), sizeof(int64_t));
1525     EXPECT_EQ(false, inputFile_.gcount() != sizeof(int64_t) || extradataSize < 0);
1526     char buffer[extradataSize];
1527     inputFile_.read(buffer, extradataSize);
1528     EXPECT_EQ(false, inputFile_.gcount() != extradataSize);
1529     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_CODEC_CONFIG.data(), (uint8_t *)buffer,
1530                             extradataSize);
1531     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
1532 
1533     Release();
1534 }
1535 
1536 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Configure_03, TestSize.Level1)
1537 {
1538     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1539     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1540     format_ = OH_AVFormat_Create();
1541     EXPECT_NE(nullptr, format_);
1542 
1543     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1544     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1545     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1546         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_VORBIS]);
1547     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
1548 
1549     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1550     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
1551     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample rate
1552 
1553     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1554     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1555     int64_t extradataSize;
1556     EXPECT_EQ(true, inputFile_.is_open());
1557     inputFile_.read(reinterpret_cast<char *>(&extradataSize), sizeof(int64_t));
1558     EXPECT_EQ(false, inputFile_.gcount() != sizeof(int64_t) || extradataSize < 0);
1559     char buffer[extradataSize];
1560     inputFile_.read(buffer, extradataSize);
1561     EXPECT_EQ(false, inputFile_.gcount() != extradataSize);
1562     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_CODEC_CONFIG.data(), (uint8_t *)buffer,
1563                             extradataSize);
1564     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
1565 
1566     Release();
1567 }
1568 
1569 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Configure_04, TestSize.Level1)
1570 {
1571     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1572     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1573     format_ = OH_AVFormat_Create();
1574     EXPECT_NE(nullptr, format_);
1575 
1576     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1577     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1578     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1579         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_VORBIS]);
1580     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), ABNORMAL_SAMPLE_FORMAT);
1581     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample format
1582 
1583     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1584     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1585     int64_t extradataSize;
1586     EXPECT_EQ(true, inputFile_.is_open());
1587     inputFile_.read(reinterpret_cast<char *>(&extradataSize), sizeof(int64_t));
1588     EXPECT_EQ(false, inputFile_.gcount() != sizeof(int64_t) || extradataSize < 0);
1589     char buffer[extradataSize];
1590     inputFile_.read(buffer, extradataSize);
1591     EXPECT_EQ(false, inputFile_.gcount() != extradataSize);
1592     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_CODEC_CONFIG.data(), (uint8_t *)buffer,
1593                             extradataSize);
1594     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample format
1595 
1596     Release();
1597 }
1598 
1599 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_SetParameter_01, TestSize.Level1)
1600 {
1601     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1602     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1603     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1604     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1605     {
1606         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841a02() 1607         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1608     }
1609     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1610     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
1611     Release();
1612 }
1613 
1614 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_SetParameter_02, TestSize.Level1)
1615 {
1616     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1617     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1618     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1619     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
1620     Release();
1621 }
1622 
1623 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Start_01, TestSize.Level1)
1624 {
1625     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1626     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1627     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1628     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1629     {
1630         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841b02() 1631         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1632     }
1633     Release();
1634 }
1635 
1636 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Start_02, TestSize.Level1)
1637 {
1638     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1639     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1640     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1641     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1642     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1643     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
1644     {
1645         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841c02() 1646         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1647     }
1648     Release();
1649 }
1650 
1651 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Stop_01, TestSize.Level1)
1652 {
1653     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1654     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1655     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1656     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1657     sleep(1);
1658 
1659     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1660     Release();
1661 }
1662 
1663 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Flush_01, TestSize.Level1)
1664 {
1665     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1666     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1667     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1668     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1669     {
1670         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841d02() 1671         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1672     }
1673     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1674     Release();
1675 }
1676 
1677 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Reset_01, TestSize.Level1)
1678 {
1679     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1680     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1681     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1682     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1683     Release();
1684 }
1685 
1686 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Reset_02, TestSize.Level1)
1687 {
1688     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1689     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1690     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1691     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1692     {
1693         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841e02() 1694         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1695     }
1696     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1697     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1698     Release();
1699 }
1700 
1701 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Reset_03, TestSize.Level1)
1702 {
1703     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1704     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1705     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1706     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1707     {
1708         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa841f02() 1709         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1710     }
1711     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1712     Release();
1713 }
1714 
1715 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Destroy_01, TestSize.Level1)
1716 {
1717     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1718     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1719     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1720     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1721     {
1722         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842002() 1723         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1724     }
1725     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1726     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
1727 }
1728 
1729 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Destroy_02, TestSize.Level1)
1730 {
1731     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1732     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1733     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1734 
1735     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
1736 }
1737 
1738 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_GetOutputFormat_01, TestSize.Level1)
1739 {
1740     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1741     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1742     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1743 
1744     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
1745     Release();
1746 }
1747 
1748 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_IsValid_01, TestSize.Level1)
1749 {
1750     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1751     bool isValid = false;
1752     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
1753     Release();
1754 }
1755 
1756 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Prepare_01, TestSize.Level1)
1757 {
1758     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1759     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1760     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1761     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
1762     Release();
1763 }
1764 
1765 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_PushInputData_01, TestSize.Level1)
1766 {
1767     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1768     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1769     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1770     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1771 
1772     // case0 传参异常
1773     const uint32_t index = 1024;
1774     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
1775     Release();
1776 }
1777 
1778 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_ReleaseOutputBuffer_01, TestSize.Level1)
1779 {
1780     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1781     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1782     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1783     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1784 
1785     // case0 传参异常
1786     const uint32_t index = 1024;
1787     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
1788     Release();
1789 }
1790 
1791 HWTEST_F(AudioDecoderBufferCapiUnitTest, vorbisMissingHeader, TestSize.Level1)
1792 {
1793     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1794     format_ = OH_AVFormat_Create();
1795     EXPECT_NE(nullptr, format_);
1796     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1797     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1798     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_MAX_INPUT_SIZE.data(), ABNORMAL_MAX_INPUT_SIZE);
1799     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
1800     Release();
1801 }
1802 
1803 HWTEST_F(AudioDecoderBufferCapiUnitTest, vorbisMissingIdHeader, TestSize.Level1)
1804 {
1805     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1806     format_ = OH_AVFormat_Create();
1807     EXPECT_NE(nullptr, format_);
1808     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1809     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1810     uint8_t buffer[1];
1811     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_IDENTIFICATION_HEADER.data(), buffer, 1);
1812     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
1813     Release();
1814 }
1815 
1816 HWTEST_F(AudioDecoderBufferCapiUnitTest, vorbisInvalidHeader, TestSize.Level1)
1817 {
1818     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1819     format_ = OH_AVFormat_Create();
1820     EXPECT_NE(nullptr, format_);
1821     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1822     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1823     uint8_t buffer[1];
1824     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_IDENTIFICATION_HEADER.data(), buffer, 1);
1825     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_SETUP_HEADER.data(), buffer, 1);
1826     EXPECT_EQ(OH_AVErrCode::AV_ERR_UNKNOWN, OH_AudioCodec_Configure(audioDec_, format_));
1827     Release();
1828 }
1829 
1830 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_CreateByMime_01, TestSize.Level1)
1831 {
1832     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_AMRWB.data(), false);
1833     EXPECT_NE(nullptr, audioDec_);
1834     Release();
1835 }
1836 
1837 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_CreateByName_01, TestSize.Level1)
1838 {
1839     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AMRWB_NAME).data());
1840     EXPECT_NE(nullptr, audioDec_);
1841     Release();
1842 }
1843 
1844 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Configure_01, TestSize.Level1)
1845 {
1846     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1847     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
1848     Release();
1849 }
1850 
1851 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Configure_02, TestSize.Level1)
1852 {
1853     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1854     format_ = OH_AVFormat_Create();
1855     EXPECT_NE(nullptr, format_);
1856 
1857     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1858     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
1859     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
1860 
1861     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1862     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
1863     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal min channel count
1864 
1865     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1866     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
1867     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
1868 
1869     Release();
1870 }
1871 
1872 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Configure_03, TestSize.Level1)
1873 {
1874     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1875     format_ = OH_AVFormat_Create();
1876     EXPECT_NE(nullptr, format_);
1877 
1878     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1879     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
1880     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
1881 
1882     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1883     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
1884     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample rate
1885 
1886     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1887     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
1888     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
1889 
1890     Release();
1891 }
1892 
1893 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Configure_04, TestSize.Level1)
1894 {
1895     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1896     format_ = OH_AVFormat_Create();
1897     EXPECT_NE(nullptr, format_);
1898 
1899     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
1900     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
1901     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), ABNORMAL_SAMPLE_FORMAT);
1902     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample format
1903 
1904     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1905     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1906     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample format
1907 
1908     Release();
1909 }
1910 
1911 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_SetParameter_01, TestSize.Level1)
1912 {
1913     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
1914     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1915     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
1916     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1917     {
1918         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842102() 1919         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1920     }
1921     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1922     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
1923     Release();
1924 }
1925 
1926 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_SetParameter_02, TestSize.Level1)
1927 {
1928     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1929     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
1930     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
1931     Release();
1932 }
1933 
1934 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Start_01, TestSize.Level1)
1935 {
1936     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
1937     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1938     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
1939     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1940     {
1941         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842202() 1942         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1943     }
1944     Release();
1945 }
1946 
1947 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Start_02, TestSize.Level1)
1948 {
1949     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
1950     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1951     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
1952     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1953     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1954     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
1955     {
1956         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842302() 1957         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1958     }
1959     Release();
1960 }
1961 
1962 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Stop_01, TestSize.Level1)
1963 {
1964     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
1965     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1966     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
1967     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1968     sleep(1);
1969 
1970     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1971     Release();
1972 }
1973 
1974 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Flush_01, TestSize.Level1)
1975 {
1976     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
1977     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1978     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
1979     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1980     {
1981         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842402() 1982         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1983     }
1984     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1985     Release();
1986 }
1987 
1988 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Reset_01, TestSize.Level1)
1989 {
1990     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1991     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
1992     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1993     Release();
1994 }
1995 
1996 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Reset_02, TestSize.Level1)
1997 {
1998     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
1999     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2000     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2001     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2002     {
2003         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842502() 2004         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2005     }
2006     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2007     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2008     Release();
2009 }
2010 
2011 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Reset_03, TestSize.Level1)
2012 {
2013     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2014     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2015     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2016     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2017     {
2018         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842602() 2019         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2020     }
2021     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2022     Release();
2023 }
2024 
2025 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Destroy_01, TestSize.Level1)
2026 {
2027     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2028     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2029     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2030     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2031     {
2032         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842702() 2033         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2034     }
2035     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2036     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2037 }
2038 
2039 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Destroy_02, TestSize.Level1)
2040 {
2041     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2042     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2043     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2044 
2045     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2046 }
2047 
2048 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_GetOutputFormat_01, TestSize.Level1)
2049 {
2050     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2051     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2052     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2053 
2054     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
2055     Release();
2056 }
2057 
2058 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_IsValid_01, TestSize.Level1)
2059 {
2060     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2061     bool isValid = false;
2062     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
2063     Release();
2064 }
2065 
2066 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Prepare_01, TestSize.Level1)
2067 {
2068     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2069     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2070     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
2071     Release();
2072 }
2073 
2074 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_PushInputData_01, TestSize.Level1)
2075 {
2076     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2077     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2078     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2079     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2080 
2081     // case0 传参异常
2082     const uint32_t index = 1024;
2083     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
2084     Release();
2085 }
2086 
2087 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_ReleaseOutputBuffer_01, TestSize.Level1)
2088 {
2089     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2090     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2091     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2092     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2093 
2094     // case0 传参异常
2095     const uint32_t index = 1024;
2096     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
2097     Release();
2098 }
2099 
2100 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_CreateByMime_01, TestSize.Level1)
2101 {
2102     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_AMRNB.data(), false);
2103     EXPECT_NE(nullptr, audioDec_);
2104     Release();
2105 }
2106 
2107 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_CreateByName_01, TestSize.Level1)
2108 {
2109     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AMRNB_NAME).data());
2110     EXPECT_NE(nullptr, audioDec_);
2111     Release();
2112 }
2113 
2114 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Configure_01, TestSize.Level1)
2115 {
2116     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2117     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2118     Release();
2119 }
2120 
2121 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Configure_02, TestSize.Level1)
2122 {
2123     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2124     format_ = OH_AVFormat_Create();
2125     EXPECT_NE(nullptr, format_);
2126 
2127     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
2128     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRNB_SAMPLE_RATE);
2129     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
2130 
2131     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2132     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
2133     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal min channel count
2134 
2135     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2136     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2137     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
2138 
2139     Release();
2140 }
2141 
2142 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Configure_03, TestSize.Level1)
2143 {
2144     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2145     format_ = OH_AVFormat_Create();
2146     EXPECT_NE(nullptr, format_);
2147 
2148     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
2149     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2150     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
2151 
2152     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2153     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
2154     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample rate
2155 
2156     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2157     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRNB_SAMPLE_RATE);
2158     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
2159 
2160     Release();
2161 }
2162 
2163 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_SetParameter_01, TestSize.Level1)
2164 {
2165     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2166     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2167     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2168     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2169     {
2170         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842802() 2171         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2172     }
2173     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
2174     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2175     Release();
2176 }
2177 
2178 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_SetParameter_02, TestSize.Level1)
2179 {
2180     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2181     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2182     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2183     Release();
2184 }
2185 
2186 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Start_01, TestSize.Level1)
2187 {
2188     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2189     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2190     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2191     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2192     {
2193         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842902() 2194         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2195     }
2196     Release();
2197 }
2198 
2199 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Start_02, TestSize.Level1)
2200 {
2201     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2202     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2203     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2204     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2205     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2206     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
2207     {
2208         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842a02() 2209         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2210     }
2211     Release();
2212 }
2213 
2214 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Stop_01, TestSize.Level1)
2215 {
2216     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2217     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2218     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2219     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2220     sleep(1);
2221 
2222     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2223     Release();
2224 }
2225 
2226 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Flush_01, TestSize.Level1)
2227 {
2228     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2229     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2230     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2231     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2232     {
2233         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842b02() 2234         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2235     }
2236     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
2237     Release();
2238 }
2239 
2240 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Reset_01, TestSize.Level1)
2241 {
2242     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2243     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2244     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2245     Release();
2246 }
2247 
2248 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Reset_02, TestSize.Level1)
2249 {
2250     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2251     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2252     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2253     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2254     {
2255         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842c02() 2256         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2257     }
2258     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2259     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2260     Release();
2261 }
2262 
2263 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Reset_03, TestSize.Level1)
2264 {
2265     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2266     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2267     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2268     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2269     {
2270         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842d02() 2271         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2272     }
2273     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2274     Release();
2275 }
2276 
2277 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Destroy_01, TestSize.Level1)
2278 {
2279     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2280     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2281     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2282     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2283     {
2284         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842e02() 2285         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2286     }
2287     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2288     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2289 }
2290 
2291 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Destroy_02, TestSize.Level1)
2292 {
2293     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2294     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2295     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2296 
2297     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2298 }
2299 
2300 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_GetOutputFormat_01, TestSize.Level1)
2301 {
2302     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2303     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2304     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2305 
2306     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
2307     Release();
2308 }
2309 
2310 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_IsValid_01, TestSize.Level1)
2311 {
2312     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2313     bool isValid = false;
2314     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
2315     Release();
2316 }
2317 
2318 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Prepare_01, TestSize.Level1)
2319 {
2320     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2321     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2322     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
2323     Release();
2324 }
2325 
2326 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_PushInputData_01, TestSize.Level1)
2327 {
2328     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2329     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2330     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2331     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2332 
2333     // case0 传参异常
2334     const uint32_t index = 1024;
2335     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
2336     Release();
2337 }
2338 
2339 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_ReleaseOutputBuffer_01, TestSize.Level1)
2340 {
2341     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2342     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2343     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2344     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2345 
2346     // case0 传参异常
2347     const uint32_t index = 1024;
2348     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
2349     Release();
2350 }
2351 
2352 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_CreateByMime_01, TestSize.Level1)
2353 {
2354     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_G711MU.data(), false);
2355     EXPECT_NE(nullptr, audioDec_);
2356     Release();
2357 }
2358 
2359 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_CreateByName_01, TestSize.Level1)
2360 {
2361     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_G711MU_NAME).data());
2362     EXPECT_NE(nullptr, audioDec_);
2363     Release();
2364 }
2365 
2366 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Configure_01, TestSize.Level1)
2367 {
2368     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2369     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2370     Release();
2371 }
2372 
2373 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_SetParameter_01, TestSize.Level1)
2374 {
2375     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2376     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2377     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2378     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2379     {
2380         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa842f02() 2381         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2382     }
2383     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
2384     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2385     Release();
2386 }
2387 
2388 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_SetParameter_02, TestSize.Level1)
2389 {
2390     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2391     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2392     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2393     Release();
2394 }
2395 
2396 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Start_01, TestSize.Level1)
2397 {
2398     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2399     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2400     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2401     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2402     {
2403         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa843002() 2404         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2405     }
2406     Release();
2407 }
2408 
2409 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Start_02, TestSize.Level1)
2410 {
2411     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2412     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2413     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2414     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2415     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2416     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
2417     {
2418         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa843102() 2419         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2420     }
2421     Release();
2422 }
2423 
2424 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Stop_01, TestSize.Level1)
2425 {
2426     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2427     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2428     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2429     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2430     sleep(1);
2431 
2432     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2433     Release();
2434 }
2435 
2436 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Flush_01, TestSize.Level1)
2437 {
2438     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2439     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2440     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2441     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2442     {
2443         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa843202() 2444         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2445     }
2446     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
2447     Release();
2448 }
2449 
2450 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Reset_01, TestSize.Level1)
2451 {
2452     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2453     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2454     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2455     Release();
2456 }
2457 
2458 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Reset_02, TestSize.Level1)
2459 {
2460     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2461     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2462     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2463     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2464     {
2465         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa843302() 2466         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2467     }
2468     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2469     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2470     Release();
2471 }
2472 
2473 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Reset_03, TestSize.Level1)
2474 {
2475     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2476     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2477     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2478     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2479     {
2480         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa843402() 2481         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2482     }
2483     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2484     Release();
2485 }
2486 
2487 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Destroy_01, TestSize.Level1)
2488 {
2489     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2490     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2491     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2492     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2493     {
2494         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa843502() 2495         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2496     }
2497     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2498     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2499 }
2500 
2501 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Destroy_02, TestSize.Level1)
2502 {
2503     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2504     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2505     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2506 
2507     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2508 }
2509 
2510 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_GetOutputFormat_01, TestSize.Level1)
2511 {
2512     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2513     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2514     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2515 
2516     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
2517     Release();
2518 }
2519 
2520 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_IsValid_01, TestSize.Level1)
2521 {
2522     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2523     bool isValid = false;
2524     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
2525     Release();
2526 }
2527 
2528 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Prepare_01, TestSize.Level1)
2529 {
2530     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2531     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2532     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
2533     Release();
2534 }
2535 
2536 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_PushInputData_01, TestSize.Level1)
2537 {
2538     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2539     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2540     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2541     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2542 
2543     // case0 传参异常
2544     const uint32_t index = 1024;
2545     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
2546     Release();
2547 }
2548 
2549 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_ReleaseOutputBuffer_01, TestSize.Level1)
2550 {
2551     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2552     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2553     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2554     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2555 
2556     // case0 传参异常
2557     const uint32_t index = 1024;
2558     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
2559     Release();
2560 }
2561 
2562 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_g711muCheckChannelCount, TestSize.Level1)
2563 {
2564     CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU);
2565     format_ = OH_AVFormat_Create();
2566     EXPECT_NE(nullptr, format_);
2567     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRNB_SAMPLE_RATE);
2568     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
2569 
2570     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2571     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MAX_CHANNEL_COUNT);
2572     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // illegal channel count
2573 
2574     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2575     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2576     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
2577 
2578     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2579 }
2580 
2581 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_g711muCheckSampleRate, TestSize.Level1)
2582 {
2583     CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU);
2584     format_ = OH_AVFormat_Create();
2585     EXPECT_NE(nullptr, format_);
2586     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2587     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
2588 
2589     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2590     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
2591     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // illegal sample rate
2592 
2593     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2594     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRNB_SAMPLE_RATE);
2595     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
2596 
2597     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2598 }
2599 
2600 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_CreateByMime_01, TestSize.Level1)
2601 {
2602     if (!CheckSoFunc()) {
2603         return;
2604     }
2605     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_OPUS.data(), false);
2606     EXPECT_NE(nullptr, audioDec_);
2607     Release();
2608 }
2609 
2610 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_CreateByName_01, TestSize.Level1)
2611 {
2612     if (!CheckSoFunc()) {
2613         return;
2614     }
2615     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_OPUS_NAME).data());
2616     EXPECT_NE(nullptr, audioDec_);
2617     Release();
2618 }
2619 
2620 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Configure_01, TestSize.Level1)
2621 {
2622     if (!CheckSoFunc()) {
2623         return;
2624     }
2625     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2626     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2627     Release();
2628 }
2629 
2630 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_SetParameter_01, TestSize.Level1)
2631 {
2632     if (!CheckSoFunc()) {
2633         return;
2634     }
2635     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2636     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2637     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2638     Release();
2639 }
2640 
2641 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Stop_01, TestSize.Level1)
2642 {
2643     if (!CheckSoFunc()) {
2644         return;
2645     }
2646     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_OPUS));
2647     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2648     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2649     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2650     sleep(1);
2651 
2652     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2653     Release();
2654 }
2655 
2656 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Flush_01, TestSize.Level1)
2657 {
2658     if (!CheckSoFunc()) {
2659         return;
2660     }
2661     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_OPUS));
2662     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2663     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2664     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2665     {
2666         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa843602() 2667         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2668     }
2669     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
2670     Release();
2671 }
2672 
2673 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Reset_01, TestSize.Level1)
2674 {
2675     if (!CheckSoFunc()) {
2676         return;
2677     }
2678     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2679     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2680     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2681     Release();
2682 }
2683 
2684 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_GetOutputFormat_01, TestSize.Level1)
2685 {
2686     if (!CheckSoFunc()) {
2687         return;
2688     }
2689     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_OPUS));
2690     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2691     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2692 
2693     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
2694     Release();
2695 }
2696 
2697 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_IsValid_01, TestSize.Level1)
2698 {
2699     if (!CheckSoFunc()) {
2700         return;
2701     }
2702     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2703     bool isValid = false;
2704     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
2705     Release();
2706 }
2707 
2708 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Prepare_01, TestSize.Level1)
2709 {
2710     if (!CheckSoFunc()) {
2711         return;
2712     }
2713     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2714     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2715     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
2716     Release();
2717 }
2718 
2719 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_CreateByMime_01, TestSize.Level1)
2720 {
2721     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_APE.data(), false);
2722     EXPECT_NE(nullptr, audioDec_);
2723     Release();
2724 }
2725 
2726 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_CreateByName_01, TestSize.Level1)
2727 {
2728     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_APE_NAME).data());
2729     EXPECT_NE(nullptr, audioDec_);
2730     Release();
2731 }
2732 
2733 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_APE_Configure_01, TestSize.Level1)
2734 {
2735     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2736     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2737     Release();
2738 }
2739 
2740 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_APE_Configure_02, TestSize.Level1)
2741 {
2742     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2743     format_ = OH_AVFormat_Create();
2744     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2745     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), -1); // use -1 as error input
2746     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
2747     Release();
2748 }
2749 
2750 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_APE_Configure_03, TestSize.Level1)
2751 {
2752     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2753     format_ = OH_AVFormat_Create();
2754     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), -1); // use -1 as error input
2755     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
2756     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
2757     Release();
2758 }
2759 
2760 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_APE_Configure_04, TestSize.Level1)
2761 {
2762     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2763     format_ = OH_AVFormat_Create();
2764     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2765     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
2766     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
2767                                 AudioSampleFormat::SAMPLE_U8P);
2768     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
2769     Release();
2770 }
2771 
2772 
2773 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_APE_Configure_05, TestSize.Level1)
2774 {
2775     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2776     format_ = OH_AVFormat_Create();
2777     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2778     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), 16000);
2779     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
2780                                 AudioSampleFormat::SAMPLE_S32LE);
2781     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
2782     Release();
2783 }
2784 
2785 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_APE_Configure_06, TestSize.Level1)
2786 {
2787     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2788     format_ = OH_AVFormat_Create();
2789     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2790     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), 0);
2791     OH_AudioCodec_Configure(audioDec_, format_);
2792     Release();
2793 }
2794 
2795 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_SetParameter_01, TestSize.Level1)
2796 {
2797     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2798     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2799     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2800     Release();
2801 }
2802 
2803 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_SetParameter_02, TestSize.Level1)
2804 {
2805     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2806     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), 1);
2807     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), 0);
2808     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
2809                                 AudioSampleFormat::SAMPLE_S16LE);
2810     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2811     Release();
2812 }
2813 
2814 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_SetParameter_03, TestSize.Level1)
2815 {
2816     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2817     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), 1);
2818     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
2819     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
2820                                 AudioSampleFormat::SAMPLE_U8);
2821     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2822     Release();
2823 }
2824 
2825 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_SetParameter_04, TestSize.Level1)
2826 {
2827     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2828     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), 1);
2829     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
2830     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
2831                                 AudioSampleFormat::SAMPLE_S32LE);
2832     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2833     Release();
2834 }
2835 
2836 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_Stop_01, TestSize.Level1)
2837 {
2838     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_APE));
2839     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2840     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2841     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2842     sleep(1);
2843 
2844     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2845     Release();
2846 }
2847 
2848 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_Flush_01, TestSize.Level1)
2849 {
2850     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_APE));
2851     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2852     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2853     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2854     {
2855         unique_lock<mutex> lock(signal_->startMutex_);
__anon9d3faa843702() 2856         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2857     }
2858     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
2859     Release();
2860 }
2861 
2862 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_Reset_01, TestSize.Level1)
2863 {
2864     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2865     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2866     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2867     Release();
2868 }
2869 
2870 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_GetOutputFormat_01, TestSize.Level1)
2871 {
2872     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_APE));
2873     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2874     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2875 
2876     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
2877     Release();
2878 }
2879 
2880 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_IsValid_01, TestSize.Level1)
2881 {
2882     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2883     bool isValid = false;
2884     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
2885     Release();
2886 }
2887 
2888 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_Prepare_01, TestSize.Level1)
2889 {
2890     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2891     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2892     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
2893     Release();
2894 }
2895 
2896 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_SetDecryptionConfig_01, TestSize.Level1)
2897 {
2898 #ifdef SUPPORT_DRM
2899     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
2900     std::shared_ptr<MediaKeySystemCapiMock> mediaKeySystemMock = std::make_shared<MediaKeySystemCapiMock>();
2901     mediaKeySystemMock->CreateMediaKeySystem();
2902     mediaKeySystemMock->CreateMediaKeySession();
2903 
2904     bool isSecure = false;
2905     int32_t ret = OH_AudioCodec_SetDecryptionConfig(audioDec_, mediaKeySystemMock->GetMediaKeySession(), isSecure);
2906     if (ret != OH_AVErrCode::AV_ERR_OK && mediaKeySystemMock->GetMediaKeySession() == nullptr) {
2907         Release();
2908         return;
2909     }
2910     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, ret);
2911     Release();
2912 #endif
2913 }
2914 
2915 }
2916 }