• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SAMPLE_RATE_8K = 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_FLAC_192K_FILE_PATH = "/data/test/media/FLAC_192k_2c_xxkb.dat";
70 constexpr string_view OUTPUT_FLAC_192K_PCM_FILE_PATH = "/data/test/media/FLAC_192k_2c_xxkb.pcm";
71 constexpr string_view INPUT_MP3_FILE_PATH = "/data/test/media/mp3_2c_44100hz_60k.dat";
72 constexpr string_view OUTPUT_MP3_PCM_FILE_PATH = "/data/test/media/mp3_2c_44100hz_60k.pcm";
73 constexpr string_view INPUT_VORBIS_FILE_PATH = "/data/test/media/vorbis_2c_44100hz_320k.dat";
74 constexpr string_view OUTPUT_VORBIS_PCM_FILE_PATH = "/data/test/media/vorbis_2c_44100hz_320k.pcm";
75 constexpr string_view INPUT_AMRNB_FILE_PATH = "/data/test/media/voice_amrnb_12200.dat";
76 constexpr string_view OUTPUT_AMRNB_PCM_FILE_PATH = "/data/test/media/voice_amrnb_12200.pcm";
77 constexpr string_view INPUT_AMRWB_FILE_PATH = "/data/test/media/voice_amrwb_23850.dat";
78 constexpr string_view OUTPUT_AMRWB_PCM_FILE_PATH = "/data/test/media/voice_amrwb_23850.pcm";
79 constexpr string_view INPUT_G711MU_FILE_PATH = "/data/test/media/g711mu_8kHz.dat";
80 constexpr string_view OUTPUT_G711MU_PCM_FILE_PATH = "/data/test/media/g711mu_8kHz_decode.pcm";
81 constexpr string_view INPUT_OPUS_FILE_PATH = "/data/test/media/voice_opus.dat";
82 constexpr string_view OUTPUT_OPUS_PCM_FILE_PATH = "/data/test/media/opus_decode.pcm";
83 constexpr string_view INPUT_APE_FILE_PATH = "/data/test/media/voice_ape.dat";
84 constexpr string_view OUTPUT_APE_PCM_FILE_PATH = "/data/test/media/ape_decode.pcm";
85 constexpr string_view INPUT_COOK_FILE_PATH = "/data/test/media/voice_cook.dat";
86 constexpr string_view OUTPUT_COOK_PCM_FILE_PATH = "/data/test/media/cook_decode.pcm";
87 constexpr string_view INPUT_AC3_FILE_PATH = "/data/test/media/voice_ac3.dat";
88 constexpr string_view OUTPUT_AC3_PCM_FILE_PATH = "/data/test/media/ac3_decode.pcm";
89 constexpr string_view INPUT_AAC_LC_ADTS_FILE_PATH = "/data/test/media/aac_2c_44100hz_199k_lc.dat";
90 constexpr string_view OUTPUT_AAC_LC_ADTS_FILE_PATH = "/data/test/media/aac_2c_44100hz_199k_lc.pcm";
91 constexpr string_view INPUT_AAC_HE_ADTS_FILE_PATH = "/data/test/media/aac_2c_44100hz_199k_he.dat";
92 constexpr string_view OUTPUT_AAC_HE_ADTS_FILE_PATH = "/data/test/media/aac_2c_44100hz_199k_he.pcm";
93 constexpr string_view INPUT_AAC_HEV2_ADTS_FILE_PATH = "/data/test/media/aac_2c_44100hz_199k_hev2.dat";
94 constexpr string_view OUTPUT_AAC_HEV2_ADTS_FILE_PATH = "/data/test/media/aac_2c_44100hz_199k_hev2.pcm";
95 const string OPUS_SO_FILE_PATH = std::string(AV_CODEC_PATH) + "/libav_codec_ext_base.z.so";
96 } // namespace
97 
98 namespace OHOS {
99 namespace MediaAVCodec {
100 enum class AudioBufferFormatType : int32_t {
101     TYPE_AAC = 0,
102     TYPE_FLAC = 1,
103     TYPE_MP3 = 2,
104     TYPE_VORBIS = 3,
105     TYPE_AMRNB = 4,
106     TYPE_AMRWB = 5,
107     TYPE_G711MU = 6,
108     TYPE_OPUS = 7,
109     TYPE_APE = 8,
110     TYPE_COOK = 9,
111     TYPE_AC3 = 10,
112     TYPE_MAX = 20,
113 };
114 
115 class AudioCodecBufferSignal {
116 public:
117     std::mutex inMutex_;
118     std::mutex outMutex_;
119     std::mutex startMutex_;
120     std::condition_variable inCond_;
121     std::condition_variable outCond_;
122     std::condition_variable startCond_;
123     std::queue<uint32_t> inQueue_;
124     std::queue<uint32_t> outQueue_;
125     std::queue<OH_AVBuffer *> inBufferQueue_;
126     std::queue<OH_AVBuffer *> outBufferQueue_;
127 };
128 
129 static uint32_t g_outputFormatChangedTimes = 0;
130 static int32_t g_outputSampleRate = 0;
131 static int32_t g_outputChannels = 0;
132 
OnError(OH_AVCodec * codec,int32_t errorCode,void * userData)133 static void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData)
134 {
135     (void)codec;
136     (void)errorCode;
137     (void)userData;
138     cout << "Error received, errorCode:" << errorCode << endl;
139 }
140 
OnOutputFormatChanged(OH_AVCodec * codec,OH_AVFormat * format,void * userData)141 static void OnOutputFormatChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData)
142 {
143     (void)codec;
144     (void)userData;
145     g_outputFormatChangedTimes++;
146     OH_AVFormat_GetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, &g_outputChannels);
147     OH_AVFormat_GetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, &g_outputSampleRate);
148     cout << "OnOutputFormatChanged received, rate:" << g_outputSampleRate << ",channel:" << g_outputChannels << endl;
149 }
150 
OnInputBufferAvailable(OH_AVCodec * codec,uint32_t index,OH_AVBuffer * data,void * userData)151 static void OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData)
152 {
153     (void)codec;
154     AudioCodecBufferSignal *signal = static_cast<AudioCodecBufferSignal *>(userData);
155     unique_lock<mutex> lock(signal->inMutex_);
156     signal->inQueue_.push(index);
157     signal->inBufferQueue_.push(data);
158     signal->inCond_.notify_all();
159 }
160 
OnOutputBufferAvailable(OH_AVCodec * codec,uint32_t index,OH_AVBuffer * data,void * userData)161 static void OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData)
162 {
163     (void)codec;
164     AudioCodecBufferSignal *signal = static_cast<AudioCodecBufferSignal *>(userData);
165     unique_lock<mutex> lock(signal->outMutex_);
166     signal->outQueue_.push(index);
167     signal->outBufferQueue_.push(data);
168     signal->outCond_.notify_all();
169 }
170 
171 class AudioDecoderBufferCapiUnitTest : public testing::Test {
172 public:
173     static void SetUpTestCase(void);
174     static void TearDownTestCase(void);
175     void SetUp();
176     void TearDown();
177     bool ReadBuffer(OH_AVBuffer *buffer, uint32_t index);
178     int32_t InitFile(AudioBufferFormatType audioType);
179     int32_t InitFile(string_view input, string_view output);
180     void InputFunc();
181     void OutputFunc();
182     int32_t CreateCodecFunc(AudioBufferFormatType audioType);
183     int32_t CheckSoFunc();
184     void HandleInputEOS(const uint32_t index);
185     int32_t Configure(AudioBufferFormatType audioType);
186     void SetTestingFormat(AudioBufferFormatType audioType);
187     int32_t Start();
188     int32_t Stop();
189     void Release();
190 
191 protected:
192     std::atomic<bool> isRunning_ = false;
193     std::unique_ptr<std::thread> inputLoop_;
194     std::unique_ptr<std::thread> outputLoop_;
195     struct OH_AVCodecCallback cb_;
196     AudioCodecBufferSignal *signal_ = nullptr;
197     OH_AVCodec *audioDec_ = nullptr;
198     OH_AVFormat *format_ = nullptr;
199     bool isTestingFormat_ = false;
200     bool isFirstFrame_ = true;
201     uint32_t frameCount_ = 0;
202     std::ifstream inputFile_;
203     std::unique_ptr<std::ifstream> soFile_;
204     std::ofstream pcmOutputFile_;
205 };
206 
SetUpTestCase(void)207 void AudioDecoderBufferCapiUnitTest::SetUpTestCase(void)
208 {
209     cout << "[SetUpTestCase]: " << endl;
210 }
211 
TearDownTestCase(void)212 void AudioDecoderBufferCapiUnitTest::TearDownTestCase(void)
213 {
214     cout << "[TearDownTestCase]: " << endl;
215 }
216 
SetUp(void)217 void AudioDecoderBufferCapiUnitTest::SetUp(void)
218 {
219     g_outputFormatChangedTimes = 0;
220     g_outputSampleRate = 0;
221     g_outputChannels = 0;
222     cout << "[SetUp]: SetUp!!!" << endl;
223 }
224 
TearDown(void)225 void AudioDecoderBufferCapiUnitTest::TearDown(void)
226 {
227     if (isTestingFormat_) {
228         EXPECT_EQ(g_outputFormatChangedTimes, 1);
229     } else {
230         EXPECT_EQ(g_outputFormatChangedTimes, 0);
231     }
232     cout << "[TearDown]: over!!!" << endl;
233 
234     if (signal_) {
235         delete signal_;
236         signal_ = nullptr;
237     }
238     if (inputFile_.is_open()) {
239         inputFile_.close();
240     }
241     if (pcmOutputFile_.is_open()) {
242         pcmOutputFile_.close();
243     }
244 
245     if (format_ != nullptr) {
246         OH_AVFormat_Destroy(format_);
247         format_ = nullptr;
248     }
249 }
250 
Release()251 void AudioDecoderBufferCapiUnitTest::Release()
252 {
253     Stop();
254     OH_AudioCodec_Destroy(audioDec_);
255 }
256 
HandleInputEOS(const uint32_t index)257 void AudioDecoderBufferCapiUnitTest::HandleInputEOS(const uint32_t index)
258 {
259     std::cout << "end buffer\n";
260     OH_AudioCodec_PushInputBuffer(audioDec_, index);
261     signal_->inBufferQueue_.pop();
262     signal_->inQueue_.pop();
263 }
264 
ReadBuffer(OH_AVBuffer * buffer,uint32_t index)265 bool AudioDecoderBufferCapiUnitTest::ReadBuffer(OH_AVBuffer *buffer, uint32_t index)
266 {
267     int64_t size;
268     int64_t pts;
269     inputFile_.read(reinterpret_cast<char *>(&size), sizeof(size));
270     if (inputFile_.eof() || inputFile_.gcount() == 0 || size == 0) {
271         buffer->buffer_->memory_->SetSize(1);
272         buffer->buffer_->flag_ = AVCODEC_BUFFER_FLAGS_EOS;
273         HandleInputEOS(index);
274         cout << "Set EOS" << endl;
275         return false;
276     }
277 
278     if (inputFile_.gcount() != sizeof(size)) {
279         cout << "Fatal: read size fail" << endl;
280         return false;
281     }
282 
283     inputFile_.read(reinterpret_cast<char *>(&buffer->buffer_->pts_), sizeof(buffer->buffer_->pts_));
284     if (inputFile_.gcount() != sizeof(pts)) {
285         cout << "Fatal: read size fail" << endl;
286         return false;
287     }
288 
289     inputFile_.read((char *)OH_AVBuffer_GetAddr(buffer), size);
290     buffer->buffer_->memory_->SetSize(size);
291     if (inputFile_.gcount() != size) {
292         cout << "Fatal: read buffer fail" << endl;
293         return false;
294     }
295 
296     return true;
297 }
298 
InputFunc()299 void AudioDecoderBufferCapiUnitTest::InputFunc()
300 {
301     while (isRunning_.load()) {
302         unique_lock<mutex> lock(signal_->inMutex_);
303         signal_->inCond_.wait(lock, [this]() { return (signal_->inQueue_.size() > 0 || !isRunning_.load()); });
304 
305         if (!isRunning_.load()) {
306             break;
307         }
308 
309         uint32_t index = signal_->inQueue_.front();
310         auto buffer = signal_->inBufferQueue_.front();
311         if (buffer == nullptr) {
312             cout << "Fatal: GetInputBuffer fail" << endl;
313             break;
314         }
315         if (ReadBuffer(buffer, index) == false) {
316             break;
317         }
318 
319         int32_t ret;
320         if (isFirstFrame_) {
321             buffer->buffer_->flag_ = AVCODEC_BUFFER_FLAGS_CODEC_DATA;
322             ret = OH_AudioCodec_PushInputBuffer(audioDec_, index);
323             isFirstFrame_ = false;
324         } else {
325             buffer->buffer_->flag_ = AVCODEC_BUFFER_FLAGS_NONE;
326             ret = OH_AudioCodec_PushInputBuffer(audioDec_, index);
327         }
328         signal_->inQueue_.pop();
329         signal_->inBufferQueue_.pop();
330         frameCount_++;
331         if (ret != AVCS_ERR_OK) {
332             cout << "Fatal error, exit" << endl;
333             break;
334         }
335     }
336     cout << "stop, exit" << endl;
337     inputFile_.close();
338 }
339 
OutputFunc()340 void AudioDecoderBufferCapiUnitTest::OutputFunc()
341 {
342     if (!pcmOutputFile_.is_open()) {
343         std::cout << "open " << OUTPUT_MP3_PCM_FILE_PATH << " failed!" << std::endl;
344     }
345     while (isRunning_.load()) {
346         unique_lock<mutex> lock(signal_->outMutex_);
347         signal_->outCond_.wait(lock, [this]() { return (signal_->outQueue_.size() > 0 || !isRunning_.load()); });
348 
349         if (!isRunning_.load()) {
350             cout << "wait to stop, exit" << endl;
351             break;
352         }
353 
354         uint32_t index = signal_->outQueue_.front();
355         OH_AVBuffer *data = signal_->outBufferQueue_.front();
356 
357         if (data == nullptr) {
358             cout << "OutputFunc OH_AVBuffer is nullptr" << endl;
359             continue;
360         }
361         pcmOutputFile_.write(reinterpret_cast<char *>(OH_AVBuffer_GetAddr(data)), data->buffer_->memory_->GetSize());
362 
363         if (data != nullptr &&
364             (data->buffer_->flag_ == AVCODEC_BUFFER_FLAGS_EOS || data->buffer_->memory_->GetSize() == 0)) {
365             cout << "decode eos" << endl;
366             isRunning_.store(false);
367             signal_->startCond_.notify_all();
368         }
369         signal_->outBufferQueue_.pop();
370         signal_->outQueue_.pop();
371         if (OH_AudioCodec_FreeOutputBuffer(audioDec_, index) != AV_ERR_OK) {
372             cout << "Fatal: FreeOutputData fail" << endl;
373             break;
374         }
375 
376         if (data->buffer_->flag_ == AVCODEC_BUFFER_FLAGS_EOS) {
377             cout << "decode eos" << endl;
378             isRunning_.store(false);
379             signal_->startCond_.notify_all();
380         }
381     }
382     cout << "stop, exit" << endl;
383     pcmOutputFile_.close();
384 }
385 
Start()386 int32_t AudioDecoderBufferCapiUnitTest::Start()
387 {
388     isRunning_.store(true);
389     inputLoop_ = make_unique<thread>(&AudioDecoderBufferCapiUnitTest::InputFunc, this);
390     if (inputLoop_ == nullptr) {
391         cout << "Fatal: No memory" << endl;
392         return OH_AVErrCode::AV_ERR_UNKNOWN;
393     }
394 
395     outputLoop_ = make_unique<thread>(&AudioDecoderBufferCapiUnitTest::OutputFunc, this);
396     if (outputLoop_ == nullptr) {
397         cout << "Fatal: No memory" << endl;
398         return OH_AVErrCode::AV_ERR_UNKNOWN;
399     }
400 
401     return OH_AudioCodec_Start(audioDec_);
402 }
403 
Stop()404 int32_t AudioDecoderBufferCapiUnitTest::Stop()
405 {
406     isRunning_.store(false);
407     if (inputLoop_ != nullptr && inputLoop_->joinable()) {
408         {
409             unique_lock<mutex> lock(signal_->inMutex_);
410             signal_->inCond_.notify_all();
411         }
412         inputLoop_->join();
413         inputLoop_ = nullptr;
414         while (!signal_->inQueue_.empty()) {
415             signal_->inQueue_.pop();
416         }
417         while (!signal_->inBufferQueue_.empty()) {
418             signal_->inBufferQueue_.pop();
419         }
420     }
421 
422     if (outputLoop_ != nullptr && outputLoop_->joinable()) {
423         {
424             unique_lock<mutex> lock(signal_->outMutex_);
425             signal_->outCond_.notify_all();
426         }
427         outputLoop_->join();
428         outputLoop_ = nullptr;
429         while (!signal_->outQueue_.empty()) {
430             signal_->outQueue_.pop();
431         }
432         while (!signal_->outBufferQueue_.empty()) {
433             signal_->outBufferQueue_.pop();
434         }
435     }
436     std::cout << "start stop!\n";
437     return OH_AudioCodec_Stop(audioDec_);
438 }
439 
InitFile(AudioBufferFormatType audioType)440 int32_t AudioDecoderBufferCapiUnitTest::InitFile(AudioBufferFormatType audioType)
441 {
442     if (audioType == AudioBufferFormatType::TYPE_AAC) {
443         inputFile_.open(INPUT_AAC_FILE_PATH, std::ios::binary);
444         pcmOutputFile_.open(OUTPUT_AAC_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
445     } else if (audioType == AudioBufferFormatType::TYPE_FLAC) {
446         inputFile_.open(INPUT_FLAC_FILE_PATH, std::ios::binary);
447         pcmOutputFile_.open(OUTPUT_FLAC_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
448     } else if (audioType == AudioBufferFormatType::TYPE_MP3) {
449         inputFile_.open(INPUT_MP3_FILE_PATH, std::ios::binary);
450         pcmOutputFile_.open(OUTPUT_MP3_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
451     } else if (audioType == AudioBufferFormatType::TYPE_VORBIS) {
452         inputFile_.open(INPUT_VORBIS_FILE_PATH, std::ios::binary);
453         pcmOutputFile_.open(OUTPUT_VORBIS_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
454     } else if (audioType == AudioBufferFormatType::TYPE_AMRNB) {
455         inputFile_.open(INPUT_AMRNB_FILE_PATH, std::ios::binary);
456         pcmOutputFile_.open(OUTPUT_AMRNB_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
457     } else if (audioType == AudioBufferFormatType::TYPE_AMRWB) {
458         inputFile_.open(INPUT_AMRWB_FILE_PATH, std::ios::binary);
459         pcmOutputFile_.open(OUTPUT_AMRWB_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
460     } else if (audioType == AudioBufferFormatType::TYPE_G711MU) {
461         inputFile_.open(INPUT_G711MU_FILE_PATH, std::ios::binary);
462         pcmOutputFile_.open(OUTPUT_G711MU_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
463     } else if (audioType == AudioBufferFormatType::TYPE_OPUS) {
464         inputFile_.open(INPUT_OPUS_FILE_PATH, std::ios::binary);
465         pcmOutputFile_.open(OUTPUT_OPUS_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
466     } else if (audioType == AudioBufferFormatType::TYPE_APE) {
467         inputFile_.open(INPUT_APE_FILE_PATH, std::ios::binary);
468         pcmOutputFile_.open(OUTPUT_APE_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
469     } else if (audioType == AudioBufferFormatType::TYPE_COOK) {
470         inputFile_.open(INPUT_COOK_FILE_PATH, std::ios::binary);
471         pcmOutputFile_.open(OUTPUT_COOK_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
472     } else if (audioType == AudioBufferFormatType::TYPE_AC3) {
473         inputFile_.open(INPUT_AC3_FILE_PATH, std::ios::binary);
474         pcmOutputFile_.open(OUTPUT_AC3_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
475     } else {
476         cout << "Fatal: audio format type not support" << endl;
477         return OH_AVErrCode::AV_ERR_UNKNOWN;
478     }
479 
480     if (!inputFile_.is_open()) {
481         cout << "Fatal: open input file failed" << endl;
482         return OH_AVErrCode::AV_ERR_UNKNOWN;
483     }
484     if (!pcmOutputFile_.is_open()) {
485         cout << "Fatal: open output file failed" << endl;
486         return OH_AVErrCode::AV_ERR_UNKNOWN;
487     }
488     return OH_AVErrCode::AV_ERR_OK;
489 }
490 
InitFile(string_view inputFilename,string_view outputFilename)491 int32_t AudioDecoderBufferCapiUnitTest::InitFile(string_view inputFilename, string_view outputFilename)
492 {
493     inputFile_.open(inputFilename, std::ios::binary);
494     if (!inputFile_.is_open()) {
495         cout << "Fatal: open input file failed:" << inputFilename << endl;
496         return OH_AVErrCode::AV_ERR_UNKNOWN;
497     }
498     pcmOutputFile_.open(outputFilename, std::ios::out | std::ios::binary);
499     if (!pcmOutputFile_.is_open()) {
500         cout << "Fatal: open output file failed" << outputFilename << endl;
501         inputFile_.close();
502         return OH_AVErrCode::AV_ERR_UNKNOWN;
503     }
504     return OH_AVErrCode::AV_ERR_OK;
505 }
506 
CreateCodecFunc(AudioBufferFormatType audioType)507 int32_t AudioDecoderBufferCapiUnitTest::CreateCodecFunc(AudioBufferFormatType audioType)
508 {
509     if (audioType == AudioBufferFormatType::TYPE_MP3) {
510         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_MP3_NAME).data());
511     } else if (audioType == AudioBufferFormatType::TYPE_FLAC) {
512         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_FLAC_NAME).data());
513     } else if (audioType == AudioBufferFormatType::TYPE_AAC) {
514         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AAC_NAME).data());
515     } else if (audioType == AudioBufferFormatType::TYPE_VORBIS) {
516         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_VORBIS_NAME).data());
517     } else if (audioType == AudioBufferFormatType::TYPE_AMRWB) {
518         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AMRWB_NAME).data());
519     } else if (audioType == AudioBufferFormatType::TYPE_AMRNB) {
520         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AMRNB_NAME).data());
521     } else if (audioType == AudioBufferFormatType::TYPE_G711MU) {
522         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_G711MU_NAME).data());
523     } else if (audioType == AudioBufferFormatType::TYPE_OPUS) {
524         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_OPUS_NAME).data());
525     } else if (audioType == AudioBufferFormatType::TYPE_APE) {
526         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_APE_NAME).data());
527     } else if (audioType == AudioBufferFormatType::TYPE_COOK) {
528         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_COOK_NAME).data());
529     } else if (audioType == AudioBufferFormatType::TYPE_AC3) {
530         audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AC3_NAME).data());
531     } else {
532         cout << "audio name not support" << endl;
533         return OH_AVErrCode::AV_ERR_UNKNOWN;
534     }
535 
536     if (audioDec_ == nullptr) {
537         cout << "Fatal: CreateByName fail" << endl;
538         return OH_AVErrCode::AV_ERR_UNKNOWN;
539     }
540 
541     signal_ = new AudioCodecBufferSignal();
542     if (signal_ == nullptr) {
543         cout << "Fatal: create signal fail" << endl;
544         return OH_AVErrCode::AV_ERR_UNKNOWN;
545     }
546     cb_ = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, &OnOutputBufferAvailable};
547     int32_t ret = OH_AudioCodec_RegisterCallback(audioDec_, cb_, signal_);
548     if (ret != OH_AVErrCode::AV_ERR_OK) {
549         cout << "Fatal: SetCallback fail" << endl;
550         return OH_AVErrCode::AV_ERR_UNKNOWN;
551     }
552 
553     return OH_AVErrCode::AV_ERR_OK;
554 }
555 
SetTestingFormat(AudioBufferFormatType audioType)556 void AudioDecoderBufferCapiUnitTest::SetTestingFormat(AudioBufferFormatType audioType)
557 {
558     if (!isTestingFormat_) {
559         OH_AVFormat_SetIntValue(format_, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, DEFAULT_SAMPLE_FORMAT);
560         return;
561     }
562     int32_t notMatchRate = 48000; // 48000 is valid for most codec but not match default
563     if (audioType == AudioBufferFormatType::TYPE_OPUS) {
564         OH_AVFormat_SetIntValue(format_, OH_MD_KEY_AUD_CHANNEL_COUNT, 1);
565     } else {
566         OH_AVFormat_SetIntValue(format_, OH_MD_KEY_AUD_SAMPLE_RATE, notMatchRate);
567     }
568 }
569 
Configure(AudioBufferFormatType audioType)570 int32_t AudioDecoderBufferCapiUnitTest::Configure(AudioBufferFormatType audioType)
571 {
572     format_ = OH_AVFormat_Create();
573     if (format_ == nullptr) {
574         cout << "Fatal: create format failed" << endl;
575         return OH_AVErrCode::AV_ERR_UNKNOWN;
576     }
577     int32_t channelCount = DEFAULT_CHANNEL_COUNT;
578     int32_t sampleRate = DEFAULT_SAMPLE_RATE;
579     if (audioType == AudioBufferFormatType::TYPE_AAC) {
580         OH_AVFormat_SetIntValue(format_, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
581     } else if (audioType == AudioBufferFormatType::TYPE_AMRNB || audioType == AudioBufferFormatType::TYPE_G711MU ||
582         audioType == AudioBufferFormatType::TYPE_APE) {
583         channelCount = 1;
584         sampleRate = SAMPLE_RATE_8K;
585     } else if (audioType == AudioBufferFormatType::TYPE_AMRWB) {
586         channelCount = 1;
587         sampleRate = AMRWB_SAMPLE_RATE;
588     } else if (audioType == AudioBufferFormatType::TYPE_OPUS) {
589         channelCount = DEFAULT_CHANNEL_COUNT;
590         sampleRate = SAMPLE_RATE_8K;
591     }
592     OH_AVFormat_SetIntValue(format_, OH_MD_KEY_AUD_CHANNEL_COUNT, channelCount);
593     OH_AVFormat_SetIntValue(format_, OH_MD_KEY_AUD_SAMPLE_RATE, sampleRate);
594     OH_AVFormat_SetLongValue(format_, OH_MD_KEY_BITRATE, BITS_RATE[(uint32_t)audioType]);
595     if (audioType == AudioBufferFormatType::TYPE_VORBIS || audioType == AudioBufferFormatType::TYPE_COOK) {
596         int64_t extradataSize;
597         if (!inputFile_.is_open()) {
598             cout << "Fatal: file is not open" << endl;
599             return OH_AVErrCode::AV_ERR_UNKNOWN;
600         }
601         inputFile_.read(reinterpret_cast<char *>(&extradataSize), sizeof(int64_t));
602         if (inputFile_.gcount() != sizeof(int64_t) || extradataSize < 0) {
603             cout << "Fatal: read extradataSize bytes error" << endl;
604             return OH_AVErrCode::AV_ERR_UNKNOWN;
605         }
606         char buffer[extradataSize];
607         inputFile_.read(buffer, extradataSize);
608         if (inputFile_.gcount() != extradataSize) {
609             cout << "Fatal: read extradata bytes error" << endl;
610             return OH_AVErrCode::AV_ERR_UNKNOWN;
611         }
612         OH_AVFormat_SetBuffer(format_, OH_MD_KEY_CODEC_CONFIG, (uint8_t *)buffer, extradataSize);
613     }
614     SetTestingFormat(audioType);
615     return OH_AudioCodec_Configure(audioDec_, format_);
616 }
617 
CheckSoFunc()618 int32_t AudioDecoderBufferCapiUnitTest::CheckSoFunc()
619 {
620     soFile_ = std::make_unique<std::ifstream>(OPUS_SO_FILE_PATH, std::ios::binary);
621     if (!soFile_->is_open()) {
622         cout << "Fatal: Open so file failed" << endl;
623         return false;
624     }
625     soFile_->close();
626     return true;
627 }
628 
629 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_CreateByMime_01, TestSize.Level1)
630 {
631     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_MPEG.data(), false);
632     EXPECT_NE(nullptr, audioDec_);
633     Release();
634 }
635 
636 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_CreateByName_01, TestSize.Level1)
637 {
638     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_MP3_NAME).data());
639     EXPECT_NE(nullptr, audioDec_);
640     Release();
641 }
642 
643 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Configure_01, TestSize.Level1)
644 {
645     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
646     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
647     Release();
648 }
649 
650 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Configure_02, TestSize.Level1)
651 {
652     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
653     format_ = OH_AVFormat_Create();
654     EXPECT_NE(nullptr, format_);
655 
656     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
657     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
658     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
659         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_MP3]);
660     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
661 
662     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
663     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
664     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal min channel count
665 
666     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
667     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MAX_CHANNEL_COUNT);
668     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal max channel count
669 
670     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
671     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
672     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
673 
674     Release();
675 }
676 
677 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Configure_03, TestSize.Level1)
678 {
679     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
680     format_ = OH_AVFormat_Create();
681     EXPECT_NE(nullptr, format_);
682 
683     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
684     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
685     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
686         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_MP3]);
687     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
688 
689     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
690     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
691     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample rate
692 
693     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
694     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
695     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
696 
697     Release();
698 }
699 
700 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Configure_04, TestSize.Level1)
701 {
702     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
703     format_ = OH_AVFormat_Create();
704     EXPECT_NE(nullptr, format_);
705 
706     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
707     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
708     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
709         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_MP3]);
710     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
711     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT.data(), CHANNEL_LAYOUT);
712     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel layout
713 
714     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
715     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT.data(), ABNORMAL_CHANNEL_LAYOUT);
716     ASSERT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal channel layout
717     Release();
718 }
719 
720 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_SetParameter_01, TestSize.Level1)
721 {
722     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
723     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
724     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
725     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
726     {
727         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c0402() 728         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
729     }
730     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
731     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
732     Release();
733 }
734 
735 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_SetParameter_02, TestSize.Level1)
736 {
737     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
738     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
739     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
740     Release();
741 }
742 
743 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Start_01, TestSize.Level1)
744 {
745     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
746     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
747     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
748     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
749     {
750         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c0502() 751         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
752     }
753     Release();
754 }
755 
756 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Start_02, TestSize.Level1)
757 {
758     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
759     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
760     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
761     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
762     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
763     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
764     {
765         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c0602() 766         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
767     }
768     Release();
769 }
770 
771 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Stop_01, TestSize.Level1)
772 {
773     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
774     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
775     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
776     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
777     sleep(1);
778 
779     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
780     Release();
781 }
782 
783 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Flush_01, TestSize.Level1)
784 {
785     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
786     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
787     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
788     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
789     {
790         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c0702() 791         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
792     }
793     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
794     Release();
795 }
796 
797 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Reset_01, TestSize.Level1)
798 {
799     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
800     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
801     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
802     Release();
803 }
804 
805 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Reset_02, TestSize.Level1)
806 {
807     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
808     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
809     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
810     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
811     {
812         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c0802() 813         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
814     }
815     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
816     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
817     Release();
818 }
819 
820 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Reset_03, TestSize.Level1)
821 {
822     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
823     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
824     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
825     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
826     {
827         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c0902() 828         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
829     }
830     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
831     Release();
832 }
833 
834 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Destroy_01, TestSize.Level1)
835 {
836     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
837     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
838     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
839     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
840     {
841         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c0a02() 842         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
843     }
844     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
845     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
846 }
847 
848 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Destroy_02, TestSize.Level1)
849 {
850     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
851     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
852     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
853 
854     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
855 }
856 
857 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_GetOutputFormat_01, TestSize.Level1)
858 {
859     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
860     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
861     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
862 
863     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
864     Release();
865 }
866 
867 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_State_01, TestSize.Level1)
868 {
869     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
870     bool isValid = false;
871     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
872     Release();
873 }
874 
875 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_IsValid_01, TestSize.Level1)
876 {
877     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
878     bool isValid = false;
879     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
880     Release();
881 }
882 
883 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_Prepare_01, TestSize.Level1)
884 {
885     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
886     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
887     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
888     Release();
889 }
890 
891 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_PushInputData_01, TestSize.Level1)
892 {
893     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
894     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
895     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
896     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
897 
898     // case0 传参异常
899     const uint32_t index = 1024;
900     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
901     Release();
902 }
903 
904 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3_ReleaseOutputBuffer_01, TestSize.Level1)
905 {
906     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_MP3));
907     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
908     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
909     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
910 
911     // case0 传参异常
912     const uint32_t index = 1024;
913     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
914     Release();
915 }
916 
917 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_CreateByMime_01, TestSize.Level1)
918 {
919     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_FLAC.data(), false);
920     EXPECT_NE(nullptr, audioDec_);
921     Release();
922 }
923 
924 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_CreateByName_01, TestSize.Level1)
925 {
926     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_FLAC_NAME).data());
927     EXPECT_NE(nullptr, audioDec_);
928     Release();
929 }
930 
931 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_01, TestSize.Level1)
932 {
933     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
934     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
935     Release();
936 }
937 
938 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_02, TestSize.Level1)
939 {
940     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
941     format_ = OH_AVFormat_Create();
942     EXPECT_NE(nullptr, format_);
943     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
944     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
945     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
946                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
947     ASSERT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
948     Release();
949 }
950 
951 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_03, TestSize.Level1)
952 {
953     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
954     format_ = OH_AVFormat_Create();
955     EXPECT_NE(nullptr, format_);
956     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MAX_CHANNEL_COUNT);
957     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
958     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
959                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
960     ASSERT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
961     Release();
962 }
963 
964 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_04, TestSize.Level1)
965 {
966     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
967     format_ = OH_AVFormat_Create();
968     EXPECT_NE(nullptr, format_);
969     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
970     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
971     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
972                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
973     ASSERT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
974     Release();
975 }
976 
977 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_05, TestSize.Level1)
978 {
979     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
980     format_ = OH_AVFormat_Create();
981     EXPECT_NE(nullptr, format_);
982     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
983     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), FLAC_192K_SAMPLE_RATE);
984     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
985                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
986     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
987     Release();
988 }
989 
990 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_06, TestSize.Level1)
991 {
992     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
993     format_ = OH_AVFormat_Create();
994     EXPECT_NE(nullptr, format_);
995     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
996     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
997     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
998                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
999     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1000     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
1001     Release();
1002 }
1003 
1004 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_07, TestSize.Level1)
1005 {
1006     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1007     format_ = OH_AVFormat_Create();
1008     EXPECT_NE(nullptr, format_);
1009     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1010     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1011     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1012                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
1013     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), FLAC_S24_SAMPLE_FORMAT);
1014     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
1015     Release();
1016 }
1017 
1018 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Configure_08, TestSize.Level1)
1019 {
1020     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1021     format_ = OH_AVFormat_Create();
1022     EXPECT_NE(nullptr, format_);
1023     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1024     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1025     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1026                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
1027     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1028     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT.data(), CHANNEL_LAYOUT);
1029     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel layout
1030 
1031     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1032     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT.data(), ABNORMAL_CHANNEL_LAYOUT);
1033     ASSERT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal channel layout
1034     Release();
1035 }
1036 
1037 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_SetParameter_01, TestSize.Level1)
1038 {
1039     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1040     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1041     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1042     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1043     {
1044         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c0b02() 1045         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1046     }
1047     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1048     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
1049     Release();
1050 }
1051 
1052 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_SetParameter_02, TestSize.Level1)
1053 {
1054     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1055     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1056     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
1057     Release();
1058 }
1059 
1060 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Start_01, TestSize.Level1)
1061 {
1062     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1063     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1064     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1065     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1066     {
1067         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c0c02() 1068         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1069     }
1070     Release();
1071 }
1072 
1073 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Start_02, TestSize.Level1)
1074 {
1075     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1076     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1077     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1078     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1079     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1080     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
1081     {
1082         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c0d02() 1083         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1084     }
1085     Release();
1086 }
1087 
1088 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Stop_01, TestSize.Level1)
1089 {
1090     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1091     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1092     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1093     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1094     sleep(1);
1095 
1096     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1097     Release();
1098 }
1099 
1100 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Flush_01, TestSize.Level1)
1101 {
1102     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1103     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1104     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1105     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1106     {
1107         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c0e02() 1108         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1109     }
1110     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1111     Release();
1112 }
1113 
1114 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Reset_01, TestSize.Level1)
1115 {
1116     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1117     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1118     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1119     Release();
1120 }
1121 
1122 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Reset_02, TestSize.Level1)
1123 {
1124     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1125     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1126     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1127     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1128     {
1129         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c0f02() 1130         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1131     }
1132     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1133     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1134     Release();
1135 }
1136 
1137 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Reset_03, TestSize.Level1)
1138 {
1139     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1140     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1141     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1142     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1143     {
1144         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1002() 1145         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1146     }
1147     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1148     Release();
1149 }
1150 
1151 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Destroy_01, TestSize.Level1)
1152 {
1153     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1154     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1155     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1156     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1157     {
1158         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1102() 1159         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1160     }
1161     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1162     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
1163 }
1164 
1165 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Destroy_02, TestSize.Level1)
1166 {
1167     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1168     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1169     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1170 
1171     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
1172 }
1173 
1174 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_GetOutputFormat_01, TestSize.Level1)
1175 {
1176     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1177     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1178     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1179 
1180     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
1181     Release();
1182 }
1183 
1184 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_IsValid_01, TestSize.Level1)
1185 {
1186     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1187     bool isValid = false;
1188     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
1189     Release();
1190 }
1191 
1192 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_Prepare_01, TestSize.Level1)
1193 {
1194     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1195     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1196     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
1197     Release();
1198 }
1199 
1200 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_PushInputData_01, TestSize.Level1)
1201 {
1202     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1203     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1204     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1205     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1206 
1207     // case0 传参异常
1208     const uint32_t index = 1024;
1209     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
1210     Release();
1211 }
1212 
1213 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_ReleaseOutputBuffer_01, TestSize.Level1)
1214 {
1215     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_FLAC));
1216     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1217     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
1218     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1219 
1220     // case0 传参异常
1221     const uint32_t index = 1024;
1222     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
1223     Release();
1224 }
1225 
1226 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Flac_192k_01, TestSize.Level1)
1227 {
1228     inputFile_.open(INPUT_FLAC_192K_FILE_PATH, std::ios::binary);
1229     ASSERT_EQ(true, inputFile_.is_open());
1230     pcmOutputFile_.open(OUTPUT_FLAC_192K_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
1231     ASSERT_EQ(true, pcmOutputFile_.is_open());
1232     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
1233     format_ = OH_AVFormat_Create();
1234     EXPECT_NE(nullptr, format_);
1235     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1236     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), FLAC_192K_SAMPLE_RATE);
1237     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1238     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1239                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
1240     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
1241     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1242     {
1243         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1202() 1244         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1245     }
1246     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1247     Release();
1248 }
1249 
1250 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_CreateByMime_01, TestSize.Level1)
1251 {
1252     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_AAC.data(), false);
1253     EXPECT_NE(nullptr, audioDec_);
1254     Release();
1255 }
1256 
1257 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_CreateByName_01, TestSize.Level1)
1258 {
1259     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AAC_NAME).data());
1260     EXPECT_NE(nullptr, audioDec_);
1261     Release();
1262 }
1263 
1264 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Configure_01, TestSize.Level1)
1265 {
1266     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1267     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1268     Release();
1269 }
1270 
1271 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Configure_02, TestSize.Level1)
1272 {
1273     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1274     format_ = OH_AVFormat_Create();
1275     EXPECT_NE(nullptr, format_);
1276 
1277     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1278     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1279     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1280     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1281         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_AAC]);
1282     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AAC_IS_ADTS.data(), ABNORMAL_AAC_TYPE);
1283     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal aac type
1284 
1285     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1286     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AAC_IS_ADTS.data(), DEFAULT_AAC_TYPE);
1287     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal aac type
1288 
1289     Release();
1290 }
1291 
1292 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Configure_03, TestSize.Level1)
1293 {
1294     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1295     format_ = OH_AVFormat_Create();
1296     EXPECT_NE(nullptr, format_);
1297 
1298     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1299     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AAC_IS_ADTS.data(), DEFAULT_AAC_TYPE);
1300     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1301     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1302         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_AAC]);
1303     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
1304 
1305     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1306     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
1307     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal min channel count
1308 
1309     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1310     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MAX_CHANNEL_COUNT);
1311     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal max channel count
1312 
1313     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1314     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1315     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
1316 
1317     Release();
1318 }
1319 
1320 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Configure_04, TestSize.Level1)
1321 {
1322     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1323     format_ = OH_AVFormat_Create();
1324     EXPECT_NE(nullptr, format_);
1325 
1326     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1327     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AAC_IS_ADTS.data(), DEFAULT_AAC_TYPE);
1328     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1329     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1330         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_AAC]);
1331     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
1332 
1333     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1334     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
1335     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample rate
1336 
1337     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1338     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1339     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
1340 
1341     Release();
1342 }
1343 
1344 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Configure_05, TestSize.Level1)
1345 {
1346     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1347     format_ = OH_AVFormat_Create();
1348     EXPECT_NE(nullptr, format_);
1349 
1350     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AAC_IS_ADTS.data(), DEFAULT_AAC_TYPE);
1351     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1352     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1353     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1354         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_AAC]);
1355     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), ABNORMAL_SAMPLE_FORMAT);
1356     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // default change to s16le
1357 
1358     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1359     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1360     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample format
1361 
1362     Release();
1363 }
1364 
1365 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_SetParameter_01, TestSize.Level1)
1366 {
1367     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1368     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1369     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1370     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1371     {
1372         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1302() 1373         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1374     }
1375     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1376     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
1377     Release();
1378 }
1379 
1380 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_SetParameter_02, TestSize.Level1)
1381 {
1382     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1383     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1384     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
1385     Release();
1386 }
1387 
1388 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Start_01, 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_);
__anon87d6d78c1402() 1396         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1397     }
1398     Release();
1399 }
1400 
1401 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Start_02, TestSize.Level1)
1402 {
1403     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1404     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1405     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1406     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1407     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1408     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
1409     {
1410         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1502() 1411         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1412     }
1413     Release();
1414 }
1415 
1416 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Stop_01, 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     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1422     sleep(1);
1423 
1424     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1425     Release();
1426 }
1427 
1428 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Flush_01, TestSize.Level1)
1429 {
1430     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1431     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1432     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1433     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1434     {
1435         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1602() 1436         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1437     }
1438     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1439     Release();
1440 }
1441 
1442 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Reset_01, TestSize.Level1)
1443 {
1444     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1445     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1446     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1447     Release();
1448 }
1449 
1450 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Reset_02, TestSize.Level1)
1451 {
1452     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1453     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1454     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1455     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1456     {
1457         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1702() 1458         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1459     }
1460     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1461     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1462     Release();
1463 }
1464 
1465 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Reset_03, TestSize.Level1)
1466 {
1467     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1468     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1469     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1470     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1471     {
1472         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1802() 1473         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1474     }
1475     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1476     Release();
1477 }
1478 
1479 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Destroy_01, TestSize.Level1)
1480 {
1481     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1482     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1483     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1484     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1485     {
1486         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1902() 1487         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1488     }
1489     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1490     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
1491 }
1492 
1493 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Destroy_02, TestSize.Level1)
1494 {
1495     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1496     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1497     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1498 
1499     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
1500 }
1501 
1502 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_GetOutputFormat_01, TestSize.Level1)
1503 {
1504     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1505     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1506     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1507 
1508     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
1509     Release();
1510 }
1511 
1512 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_IsValid_01, TestSize.Level1)
1513 {
1514     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1515     bool isValid = false;
1516     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
1517     Release();
1518 }
1519 
1520 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_Prepare_01, TestSize.Level1)
1521 {
1522     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1523     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1524     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
1525     Release();
1526 }
1527 
1528 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_PushInputData_01, TestSize.Level1)
1529 {
1530     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1531     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1532     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1533     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1534 
1535     // case0 传参异常
1536     const uint32_t index = 1024;
1537     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
1538     Release();
1539 }
1540 
1541 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_ReleaseOutputBuffer_01, TestSize.Level1)
1542 {
1543     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AAC));
1544     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
1545     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
1546     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1547 
1548     // case0 传参异常
1549     const uint32_t index = 1024;
1550     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
1551     Release();
1552 }
1553 
1554 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_CreateByMime_01, TestSize.Level1)
1555 {
1556     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_VORBIS.data(), false);
1557     EXPECT_NE(nullptr, audioDec_);
1558     Release();
1559 }
1560 
1561 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_CreateByName_01, TestSize.Level1)
1562 {
1563     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_VORBIS_NAME).data());
1564     EXPECT_NE(nullptr, audioDec_);
1565     Release();
1566 }
1567 
1568 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Configure_01, TestSize.Level1)
1569 {
1570     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1571     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1572     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1573     Release();
1574 }
1575 
1576 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Configure_02, TestSize.Level1)
1577 {
1578     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1579     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1580     format_ = OH_AVFormat_Create();
1581     EXPECT_NE(nullptr, format_);
1582 
1583     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1584     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1585     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1586         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_VORBIS]);
1587     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
1588 
1589     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1590     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
1591     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal min channel count
1592 
1593     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1594     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MAX_CHANNEL_COUNT);
1595     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal max channel count
1596 
1597     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1598     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1599     int64_t extradataSize;
1600     EXPECT_EQ(true, inputFile_.is_open());
1601     inputFile_.read(reinterpret_cast<char *>(&extradataSize), sizeof(int64_t));
1602     EXPECT_EQ(false, inputFile_.gcount() != sizeof(int64_t) || extradataSize < 0);
1603     char buffer[extradataSize];
1604     inputFile_.read(buffer, extradataSize);
1605     EXPECT_EQ(false, inputFile_.gcount() != extradataSize);
1606     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_CODEC_CONFIG.data(), (uint8_t *)buffer,
1607                             extradataSize);
1608     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
1609 
1610     Release();
1611 }
1612 
1613 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Configure_03, TestSize.Level1)
1614 {
1615     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1616     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1617     format_ = OH_AVFormat_Create();
1618     EXPECT_NE(nullptr, format_);
1619 
1620     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1621     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1622     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1623         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_VORBIS]);
1624     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
1625 
1626     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1627     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
1628     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample rate
1629 
1630     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1631     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1632     int64_t extradataSize;
1633     EXPECT_EQ(true, inputFile_.is_open());
1634     inputFile_.read(reinterpret_cast<char *>(&extradataSize), sizeof(int64_t));
1635     EXPECT_EQ(false, inputFile_.gcount() != sizeof(int64_t) || extradataSize < 0);
1636     char buffer[extradataSize];
1637     inputFile_.read(buffer, extradataSize);
1638     EXPECT_EQ(false, inputFile_.gcount() != extradataSize);
1639     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_CODEC_CONFIG.data(), (uint8_t *)buffer,
1640                             extradataSize);
1641     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
1642 
1643     Release();
1644 }
1645 
1646 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Configure_04, TestSize.Level1)
1647 {
1648     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1649     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1650     format_ = OH_AVFormat_Create();
1651     EXPECT_NE(nullptr, format_);
1652 
1653     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1654     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1655     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
1656         BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_VORBIS]);
1657     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), ABNORMAL_SAMPLE_FORMAT);
1658     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample format
1659 
1660     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1661     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1662     int64_t extradataSize;
1663     EXPECT_EQ(true, inputFile_.is_open());
1664     inputFile_.read(reinterpret_cast<char *>(&extradataSize), sizeof(int64_t));
1665     EXPECT_EQ(false, inputFile_.gcount() != sizeof(int64_t) || extradataSize < 0);
1666     char buffer[extradataSize];
1667     inputFile_.read(buffer, extradataSize);
1668     EXPECT_EQ(false, inputFile_.gcount() != extradataSize);
1669     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_CODEC_CONFIG.data(), (uint8_t *)buffer,
1670                             extradataSize);
1671     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample format
1672 
1673     Release();
1674 }
1675 
1676 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_SetParameter_01, TestSize.Level1)
1677 {
1678     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1679     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1680     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1681     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1682     {
1683         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1a02() 1684         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1685     }
1686     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1687     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
1688     Release();
1689 }
1690 
1691 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_SetParameter_02, TestSize.Level1)
1692 {
1693     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1694     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1695     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1696     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
1697     Release();
1698 }
1699 
1700 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Start_01, TestSize.Level1)
1701 {
1702     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1703     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1704     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1705     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1706     {
1707         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1b02() 1708         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1709     }
1710     Release();
1711 }
1712 
1713 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Start_02, TestSize.Level1)
1714 {
1715     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1716     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1717     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1718     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1719     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1720     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
1721     {
1722         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1c02() 1723         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1724     }
1725     Release();
1726 }
1727 
1728 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Stop_01, TestSize.Level1)
1729 {
1730     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1731     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1732     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1733     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1734     sleep(1);
1735 
1736     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1737     Release();
1738 }
1739 
1740 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Flush_01, TestSize.Level1)
1741 {
1742     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1743     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1744     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1745     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1746     {
1747         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1d02() 1748         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1749     }
1750     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1751     Release();
1752 }
1753 
1754 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Reset_01, TestSize.Level1)
1755 {
1756     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1757     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1758     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1759     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1760     Release();
1761 }
1762 
1763 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Reset_02, TestSize.Level1)
1764 {
1765     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1766     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1767     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1768     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1769     {
1770         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1e02() 1771         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1772     }
1773     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1774     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1775     Release();
1776 }
1777 
1778 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Reset_03, 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         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c1f02() 1786         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1787     }
1788     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1789     Release();
1790 }
1791 
1792 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Destroy_01, TestSize.Level1)
1793 {
1794     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1795     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1796     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1797     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1798     {
1799         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2002() 1800         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1801     }
1802     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
1803     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
1804 }
1805 
1806 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Destroy_02, TestSize.Level1)
1807 {
1808     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1809     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1810     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1811 
1812     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
1813 }
1814 
1815 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_GetOutputFormat_01, TestSize.Level1)
1816 {
1817     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1818     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1819     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1820 
1821     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
1822     Release();
1823 }
1824 
1825 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_IsValid_01, TestSize.Level1)
1826 {
1827     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1828     bool isValid = false;
1829     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
1830     Release();
1831 }
1832 
1833 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_Prepare_01, TestSize.Level1)
1834 {
1835     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1836     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1837     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1838     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
1839     Release();
1840 }
1841 
1842 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_PushInputData_01, TestSize.Level1)
1843 {
1844     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1845     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1846     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1847     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1848 
1849     // case0 传参异常
1850     const uint32_t index = 1024;
1851     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
1852     Release();
1853 }
1854 
1855 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Vorbis_ReleaseOutputBuffer_01, TestSize.Level1)
1856 {
1857     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_VORBIS));
1858     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1859     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
1860     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1861 
1862     // case0 传参异常
1863     const uint32_t index = 1024;
1864     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
1865     Release();
1866 }
1867 
1868 HWTEST_F(AudioDecoderBufferCapiUnitTest, vorbisMissingHeader, TestSize.Level1)
1869 {
1870     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1871     format_ = OH_AVFormat_Create();
1872     EXPECT_NE(nullptr, format_);
1873     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1874     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1875     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_MAX_INPUT_SIZE.data(), ABNORMAL_MAX_INPUT_SIZE);
1876     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
1877     Release();
1878 }
1879 
1880 HWTEST_F(AudioDecoderBufferCapiUnitTest, vorbisMissingIdHeader, TestSize.Level1)
1881 {
1882     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1883     format_ = OH_AVFormat_Create();
1884     EXPECT_NE(nullptr, format_);
1885     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1886     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1887     uint8_t buffer[1];
1888     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_IDENTIFICATION_HEADER.data(), buffer, 1);
1889     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
1890     Release();
1891 }
1892 
1893 HWTEST_F(AudioDecoderBufferCapiUnitTest, vorbisInvalidHeader, TestSize.Level1)
1894 {
1895     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
1896     format_ = OH_AVFormat_Create();
1897     EXPECT_NE(nullptr, format_);
1898     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
1899     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
1900     uint8_t buffer[1];
1901     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_IDENTIFICATION_HEADER.data(), buffer, 1);
1902     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_SETUP_HEADER.data(), buffer, 1);
1903     EXPECT_EQ(OH_AVErrCode::AV_ERR_UNKNOWN, OH_AudioCodec_Configure(audioDec_, format_));
1904     Release();
1905 }
1906 
1907 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_CreateByMime_01, TestSize.Level1)
1908 {
1909     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_AMRWB.data(), false);
1910     EXPECT_NE(nullptr, audioDec_);
1911     Release();
1912 }
1913 
1914 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_CreateByName_01, TestSize.Level1)
1915 {
1916     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AMRWB_NAME).data());
1917     EXPECT_NE(nullptr, audioDec_);
1918     Release();
1919 }
1920 
1921 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Configure_01, TestSize.Level1)
1922 {
1923     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1924     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
1925     Release();
1926 }
1927 
1928 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Configure_02, TestSize.Level1)
1929 {
1930     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1931     format_ = OH_AVFormat_Create();
1932     EXPECT_NE(nullptr, format_);
1933 
1934     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1935     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
1936     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
1937 
1938     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1939     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
1940     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal min channel count
1941 
1942     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1943     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
1944     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
1945 
1946     Release();
1947 }
1948 
1949 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Configure_03, TestSize.Level1)
1950 {
1951     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1952     format_ = OH_AVFormat_Create();
1953     EXPECT_NE(nullptr, format_);
1954 
1955     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1956     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
1957     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
1958 
1959     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1960     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
1961     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample rate
1962 
1963     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1964     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
1965     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
1966 
1967     Release();
1968 }
1969 
1970 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Configure_04, TestSize.Level1)
1971 {
1972     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1973     format_ = OH_AVFormat_Create();
1974     EXPECT_NE(nullptr, format_);
1975 
1976     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
1977     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
1978     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), ABNORMAL_SAMPLE_FORMAT);
1979     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample format
1980 
1981     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
1982     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
1983     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample format
1984 
1985     Release();
1986 }
1987 
1988 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_SetParameter_01, TestSize.Level1)
1989 {
1990     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
1991     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
1992     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
1993     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
1994     {
1995         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2102() 1996         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
1997     }
1998     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
1999     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2000     Release();
2001 }
2002 
2003 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_SetParameter_02, TestSize.Level1)
2004 {
2005     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2006     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2007     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2008     Release();
2009 }
2010 
2011 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Start_01, 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_);
__anon87d6d78c2202() 2019         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2020     }
2021     Release();
2022 }
2023 
2024 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Start_02, TestSize.Level1)
2025 {
2026     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2027     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2028     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2029     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2030     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2031     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
2032     {
2033         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2302() 2034         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2035     }
2036     Release();
2037 }
2038 
2039 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Stop_01, 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     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2045     sleep(1);
2046 
2047     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2048     Release();
2049 }
2050 
2051 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Flush_01, TestSize.Level1)
2052 {
2053     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2054     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2055     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2056     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2057     {
2058         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2402() 2059         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2060     }
2061     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
2062     Release();
2063 }
2064 
2065 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Reset_01, TestSize.Level1)
2066 {
2067     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2068     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2069     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2070     Release();
2071 }
2072 
2073 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Reset_02, TestSize.Level1)
2074 {
2075     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2076     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2077     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2078     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2079     {
2080         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2502() 2081         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2082     }
2083     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2084     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2085     Release();
2086 }
2087 
2088 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Reset_03, TestSize.Level1)
2089 {
2090     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2091     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2092     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2093     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2094     {
2095         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2602() 2096         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2097     }
2098     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2099     Release();
2100 }
2101 
2102 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Destroy_01, TestSize.Level1)
2103 {
2104     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2105     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2106     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2107     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2108     {
2109         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2702() 2110         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2111     }
2112     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2113     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2114 }
2115 
2116 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Destroy_02, TestSize.Level1)
2117 {
2118     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2119     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2120     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2121 
2122     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2123 }
2124 
2125 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_GetOutputFormat_01, TestSize.Level1)
2126 {
2127     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2128     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2129     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2130 
2131     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
2132     Release();
2133 }
2134 
2135 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_IsValid_01, TestSize.Level1)
2136 {
2137     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2138     bool isValid = false;
2139     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
2140     Release();
2141 }
2142 
2143 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_Prepare_01, TestSize.Level1)
2144 {
2145     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2146     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2147     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
2148     Release();
2149 }
2150 
2151 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_PushInputData_01, TestSize.Level1)
2152 {
2153     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2154     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2155     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2156     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2157 
2158     // case0 传参异常
2159     const uint32_t index = 1024;
2160     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
2161     Release();
2162 }
2163 
2164 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrwb_ReleaseOutputBuffer_01, TestSize.Level1)
2165 {
2166     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRWB));
2167     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRWB));
2168     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRWB));
2169     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2170 
2171     // case0 传参异常
2172     const uint32_t index = 1024;
2173     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
2174     Release();
2175 }
2176 
2177 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_CreateByMime_01, TestSize.Level1)
2178 {
2179     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_AMRNB.data(), false);
2180     EXPECT_NE(nullptr, audioDec_);
2181     Release();
2182 }
2183 
2184 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_CreateByName_01, TestSize.Level1)
2185 {
2186     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AMRNB_NAME).data());
2187     EXPECT_NE(nullptr, audioDec_);
2188     Release();
2189 }
2190 
2191 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Configure_01, TestSize.Level1)
2192 {
2193     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2194     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2195     Release();
2196 }
2197 
2198 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Configure_02, TestSize.Level1)
2199 {
2200     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2201     format_ = OH_AVFormat_Create();
2202     EXPECT_NE(nullptr, format_);
2203 
2204     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
2205     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), SAMPLE_RATE_8K);
2206     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
2207 
2208     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2209     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
2210     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal min channel count
2211 
2212     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2213     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2214     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
2215 
2216     Release();
2217 }
2218 
2219 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Configure_03, TestSize.Level1)
2220 {
2221     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2222     format_ = OH_AVFormat_Create();
2223     EXPECT_NE(nullptr, format_);
2224 
2225     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
2226     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2227     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
2228 
2229     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2230     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
2231     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample rate
2232 
2233     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2234     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), SAMPLE_RATE_8K);
2235     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
2236 
2237     Release();
2238 }
2239 
2240 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_SetParameter_01, TestSize.Level1)
2241 {
2242     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2243     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2244     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2245     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2246     {
2247         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2802() 2248         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2249     }
2250     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
2251     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2252     Release();
2253 }
2254 
2255 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_SetParameter_02, TestSize.Level1)
2256 {
2257     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2258     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2259     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2260     Release();
2261 }
2262 
2263 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Start_01, 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_);
__anon87d6d78c2902() 2271         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2272     }
2273     Release();
2274 }
2275 
2276 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Start_02, TestSize.Level1)
2277 {
2278     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2279     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2280     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2281     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2282     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2283     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
2284     {
2285         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2a02() 2286         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2287     }
2288     Release();
2289 }
2290 
2291 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Stop_01, 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     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2297     sleep(1);
2298 
2299     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2300     Release();
2301 }
2302 
2303 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Flush_01, TestSize.Level1)
2304 {
2305     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2306     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2307     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2308     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2309     {
2310         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2b02() 2311         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2312     }
2313     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
2314     Release();
2315 }
2316 
2317 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Reset_01, TestSize.Level1)
2318 {
2319     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2320     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2321     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2322     Release();
2323 }
2324 
2325 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Reset_02, TestSize.Level1)
2326 {
2327     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2328     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2329     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2330     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2331     {
2332         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2c02() 2333         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2334     }
2335     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2336     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2337     Release();
2338 }
2339 
2340 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Reset_03, TestSize.Level1)
2341 {
2342     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2343     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2344     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2345     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2346     {
2347         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2d02() 2348         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2349     }
2350     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2351     Release();
2352 }
2353 
2354 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Destroy_01, TestSize.Level1)
2355 {
2356     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2357     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2358     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2359     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2360     {
2361         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2e02() 2362         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2363     }
2364     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2365     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2366 }
2367 
2368 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Destroy_02, TestSize.Level1)
2369 {
2370     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2371     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2372     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2373 
2374     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2375 }
2376 
2377 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_GetOutputFormat_01, TestSize.Level1)
2378 {
2379     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2380     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2381     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2382 
2383     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
2384     Release();
2385 }
2386 
2387 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_IsValid_01, TestSize.Level1)
2388 {
2389     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2390     bool isValid = false;
2391     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
2392     Release();
2393 }
2394 
2395 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_Prepare_01, TestSize.Level1)
2396 {
2397     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2398     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2399     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
2400     Release();
2401 }
2402 
2403 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_PushInputData_01, TestSize.Level1)
2404 {
2405     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2406     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2407     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2408     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2409 
2410     // case0 传参异常
2411     const uint32_t index = 1024;
2412     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
2413     Release();
2414 }
2415 
2416 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Amrnb_ReleaseOutputBuffer_01, TestSize.Level1)
2417 {
2418     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AMRNB));
2419     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AMRNB));
2420     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AMRNB));
2421     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2422 
2423     // case0 传参异常
2424     const uint32_t index = 1024;
2425     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
2426     Release();
2427 }
2428 
2429 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_CreateByMime_01, TestSize.Level1)
2430 {
2431     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_G711MU.data(), false);
2432     EXPECT_NE(nullptr, audioDec_);
2433     Release();
2434 }
2435 
2436 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_CreateByName_01, TestSize.Level1)
2437 {
2438     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_G711MU_NAME).data());
2439     EXPECT_NE(nullptr, audioDec_);
2440     Release();
2441 }
2442 
2443 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Configure_01, TestSize.Level1)
2444 {
2445     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2446     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2447     Release();
2448 }
2449 
2450 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_SetParameter_01, TestSize.Level1)
2451 {
2452     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2453     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2454     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2455     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2456     {
2457         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c2f02() 2458         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2459     }
2460     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
2461     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2462     Release();
2463 }
2464 
2465 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_SetParameter_02, TestSize.Level1)
2466 {
2467     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2468     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2469     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2470     Release();
2471 }
2472 
2473 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Start_01, 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_);
__anon87d6d78c3002() 2481         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2482     }
2483     Release();
2484 }
2485 
2486 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Start_02, TestSize.Level1)
2487 {
2488     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2489     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2490     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2491     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2492     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2493     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
2494     {
2495         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3102() 2496         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2497     }
2498     Release();
2499 }
2500 
2501 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Stop_01, 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     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2507     sleep(1);
2508 
2509     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2510     Release();
2511 }
2512 
2513 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Flush_01, TestSize.Level1)
2514 {
2515     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2516     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2517     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2518     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2519     {
2520         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3202() 2521         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2522     }
2523     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
2524     Release();
2525 }
2526 
2527 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Reset_01, TestSize.Level1)
2528 {
2529     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2530     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2531     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2532     Release();
2533 }
2534 
2535 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Reset_02, TestSize.Level1)
2536 {
2537     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2538     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2539     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2540     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2541     {
2542         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3302() 2543         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2544     }
2545     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2546     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2547     Release();
2548 }
2549 
2550 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Reset_03, TestSize.Level1)
2551 {
2552     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2553     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2554     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2555     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2556     {
2557         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3402() 2558         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2559     }
2560     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2561     Release();
2562 }
2563 
2564 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Destroy_01, TestSize.Level1)
2565 {
2566     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2567     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2568     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2569     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2570     {
2571         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3502() 2572         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2573     }
2574     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2575     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2576 }
2577 
2578 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Destroy_02, TestSize.Level1)
2579 {
2580     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2581     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2582     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2583 
2584     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2585 }
2586 
2587 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_GetOutputFormat_01, TestSize.Level1)
2588 {
2589     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2590     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2591     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2592 
2593     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
2594     Release();
2595 }
2596 
2597 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_IsValid_01, TestSize.Level1)
2598 {
2599     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2600     bool isValid = false;
2601     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
2602     Release();
2603 }
2604 
2605 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_Prepare_01, TestSize.Level1)
2606 {
2607     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2608     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2609     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
2610     Release();
2611 }
2612 
2613 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_PushInputData_01, TestSize.Level1)
2614 {
2615     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2616     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2617     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2618     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2619 
2620     // case0 传参异常
2621     const uint32_t index = 1024;
2622     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
2623     Release();
2624 }
2625 
2626 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_G711mu_ReleaseOutputBuffer_01, TestSize.Level1)
2627 {
2628     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_G711MU));
2629     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU));
2630     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_G711MU));
2631     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2632 
2633     // case0 传参异常
2634     const uint32_t index = 1024;
2635     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
2636     Release();
2637 }
2638 
2639 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_g711muCheckChannelCount, TestSize.Level1)
2640 {
2641     CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU);
2642     format_ = OH_AVFormat_Create();
2643     EXPECT_NE(nullptr, format_);
2644     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), SAMPLE_RATE_8K);
2645     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
2646 
2647     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2648     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MAX_CHANNEL_COUNT);
2649     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // illegal channel count
2650 
2651     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2652     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2653     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
2654 
2655     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2656 }
2657 
2658 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_g711muCheckSampleRate, TestSize.Level1)
2659 {
2660     CreateCodecFunc(AudioBufferFormatType::TYPE_G711MU);
2661     format_ = OH_AVFormat_Create();
2662     EXPECT_NE(nullptr, format_);
2663     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2664     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
2665 
2666     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2667     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
2668     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // illegal sample rate
2669 
2670     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2671     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), SAMPLE_RATE_8K);
2672     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
2673 
2674     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
2675 }
2676 
2677 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_CreateByMime_01, TestSize.Level1)
2678 {
2679     if (!CheckSoFunc()) {
2680         return;
2681     }
2682     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_OPUS.data(), false);
2683     EXPECT_NE(nullptr, audioDec_);
2684     Release();
2685 }
2686 
2687 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_CreateByName_01, TestSize.Level1)
2688 {
2689     if (!CheckSoFunc()) {
2690         return;
2691     }
2692     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_OPUS_NAME).data());
2693     EXPECT_NE(nullptr, audioDec_);
2694     Release();
2695 }
2696 
2697 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Configure_01, TestSize.Level1)
2698 {
2699     if (!CheckSoFunc()) {
2700         return;
2701     }
2702     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2703     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2704     Release();
2705 }
2706 
2707 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_SetParameter_01, TestSize.Level1)
2708 {
2709     if (!CheckSoFunc()) {
2710         return;
2711     }
2712     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2713     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2714     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2715     Release();
2716 }
2717 
2718 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Stop_01, TestSize.Level1)
2719 {
2720     if (!CheckSoFunc()) {
2721         return;
2722     }
2723     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_OPUS));
2724     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2725     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2726     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2727     sleep(1);
2728 
2729     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2730     Release();
2731 }
2732 
2733 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Flush_01, TestSize.Level1)
2734 {
2735     if (!CheckSoFunc()) {
2736         return;
2737     }
2738     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_OPUS));
2739     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2740     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2741     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2742     {
2743         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3602() 2744         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2745     }
2746     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
2747     Release();
2748 }
2749 
2750 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Reset_01, TestSize.Level1)
2751 {
2752     if (!CheckSoFunc()) {
2753         return;
2754     }
2755     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2756     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2757     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2758     Release();
2759 }
2760 
2761 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_GetOutputFormat_01, TestSize.Level1)
2762 {
2763     if (!CheckSoFunc()) {
2764         return;
2765     }
2766     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_OPUS));
2767     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2768     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2769 
2770     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
2771     Release();
2772 }
2773 
2774 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_IsValid_01, TestSize.Level1)
2775 {
2776     if (!CheckSoFunc()) {
2777         return;
2778     }
2779     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2780     bool isValid = false;
2781     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
2782     Release();
2783 }
2784 
2785 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Opus_Prepare_01, TestSize.Level1)
2786 {
2787     if (!CheckSoFunc()) {
2788         return;
2789     }
2790     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_OPUS));
2791     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_OPUS));
2792     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
2793     Release();
2794 }
2795 
2796 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_CreateByMime_01, TestSize.Level1)
2797 {
2798     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_APE.data(), false);
2799     EXPECT_NE(nullptr, audioDec_);
2800     Release();
2801 }
2802 
2803 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_CreateByName_01, TestSize.Level1)
2804 {
2805     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_APE_NAME).data());
2806     EXPECT_NE(nullptr, audioDec_);
2807     Release();
2808 }
2809 
2810 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_APE_Configure_01, TestSize.Level1)
2811 {
2812     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2813     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2814     Release();
2815 }
2816 
2817 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_APE_Configure_02, TestSize.Level1)
2818 {
2819     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2820     format_ = OH_AVFormat_Create();
2821     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2822     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), -1); // use -1 as error input
2823     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
2824     Release();
2825 }
2826 
2827 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_APE_Configure_03, TestSize.Level1)
2828 {
2829     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2830     format_ = OH_AVFormat_Create();
2831     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), -1); // use -1 as error input
2832     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
2833     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
2834     Release();
2835 }
2836 
2837 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_APE_Configure_04, TestSize.Level1)
2838 {
2839     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2840     format_ = OH_AVFormat_Create();
2841     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2842     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
2843     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
2844                                 AudioSampleFormat::SAMPLE_U8P);
2845     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
2846     Release();
2847 }
2848 
2849 
2850 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_APE_Configure_05, TestSize.Level1)
2851 {
2852     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2853     format_ = OH_AVFormat_Create();
2854     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2855     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), 16000);
2856     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
2857                                 AudioSampleFormat::SAMPLE_S32LE);
2858     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
2859     Release();
2860 }
2861 
2862 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_APE_Configure_06, TestSize.Level1)
2863 {
2864     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2865     format_ = OH_AVFormat_Create();
2866     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ONE_CHANNEL_COUNT);
2867     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), 0);
2868     OH_AudioCodec_Configure(audioDec_, format_);
2869     Release();
2870 }
2871 
2872 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_SetParameter_01, TestSize.Level1)
2873 {
2874     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2875     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2876     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2877     Release();
2878 }
2879 
2880 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_SetParameter_02, TestSize.Level1)
2881 {
2882     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2883     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), 1);
2884     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), 0);
2885     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
2886                                 AudioSampleFormat::SAMPLE_S16LE);
2887     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2888     Release();
2889 }
2890 
2891 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_SetParameter_03, TestSize.Level1)
2892 {
2893     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2894     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), 1);
2895     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
2896     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
2897                                 AudioSampleFormat::SAMPLE_U8);
2898     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2899     Release();
2900 }
2901 
2902 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_SetParameter_04, TestSize.Level1)
2903 {
2904     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2905     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), 1);
2906     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), AMRWB_SAMPLE_RATE);
2907     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
2908                                 AudioSampleFormat::SAMPLE_S32LE);
2909     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
2910     Release();
2911 }
2912 
2913 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_Stop_01, TestSize.Level1)
2914 {
2915     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_APE));
2916     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2917     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2918     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2919     sleep(1);
2920 
2921     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
2922     Release();
2923 }
2924 
2925 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_Flush_01, TestSize.Level1)
2926 {
2927     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_APE));
2928     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2929     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2930     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2931     {
2932         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3702() 2933         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
2934     }
2935     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
2936     Release();
2937 }
2938 
2939 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_Reset_01, TestSize.Level1)
2940 {
2941     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2942     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2943     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
2944     Release();
2945 }
2946 
2947 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_GetOutputFormat_01, TestSize.Level1)
2948 {
2949     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_APE));
2950     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2951     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2952 
2953     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
2954     Release();
2955 }
2956 
2957 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_IsValid_01, TestSize.Level1)
2958 {
2959     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2960     bool isValid = false;
2961     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
2962     Release();
2963 }
2964 
2965 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Ape_Prepare_01, TestSize.Level1)
2966 {
2967     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_APE));
2968     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_APE));
2969     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
2970     Release();
2971 }
2972 
2973 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Aac_SetDecryptionConfig_01, TestSize.Level1)
2974 {
2975 #ifdef SUPPORT_DRM
2976     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
2977     std::shared_ptr<MediaKeySystemCapiMock> mediaKeySystemMock = std::make_shared<MediaKeySystemCapiMock>();
2978     mediaKeySystemMock->CreateMediaKeySystem();
2979     mediaKeySystemMock->CreateMediaKeySession();
2980 
2981     bool isSecure = false;
2982     int32_t ret = OH_AudioCodec_SetDecryptionConfig(audioDec_, mediaKeySystemMock->GetMediaKeySession(), isSecure);
2983     if (ret != OH_AVErrCode::AV_ERR_OK && mediaKeySystemMock->GetMediaKeySession() == nullptr) {
2984         Release();
2985         return;
2986     }
2987     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, ret);
2988     Release();
2989 #endif
2990 }
2991 
2992 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AacLcFormatChanged, TestSize.Level1)
2993 {
2994     isTestingFormat_ = true;
2995     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(INPUT_AAC_LC_ADTS_FILE_PATH, OUTPUT_AAC_LC_ADTS_FILE_PATH));
2996     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
2997     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
2998     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
2999     {
3000         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3802() 3001         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3002     }
3003     EXPECT_EQ(g_outputSampleRate, DEFAULT_SAMPLE_RATE);
3004     EXPECT_EQ(g_outputChannels, DEFAULT_CHANNEL_COUNT);
3005     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3006     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3007     Release();
3008 }
3009 
3010 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AacHeFormatChanged, TestSize.Level1)
3011 {
3012     isTestingFormat_ = true;
3013     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(INPUT_AAC_HE_ADTS_FILE_PATH, OUTPUT_AAC_HE_ADTS_FILE_PATH));
3014     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
3015     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
3016     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3017     {
3018         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3902() 3019         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3020     }
3021     EXPECT_EQ(g_outputSampleRate, DEFAULT_SAMPLE_RATE);
3022     EXPECT_EQ(g_outputChannels, DEFAULT_CHANNEL_COUNT);
3023     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3024     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3025     Release();
3026 }
3027 
3028 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AacHev2FormatChanged, TestSize.Level1)
3029 {
3030     isTestingFormat_ = true;
3031     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(INPUT_AAC_HEV2_ADTS_FILE_PATH, OUTPUT_AAC_HEV2_ADTS_FILE_PATH));
3032     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AAC));
3033     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AAC));
3034     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3035     {
3036         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3a02() 3037         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3038     }
3039     EXPECT_EQ(g_outputSampleRate, DEFAULT_SAMPLE_RATE);
3040     EXPECT_EQ(g_outputChannels, DEFAULT_CHANNEL_COUNT);
3041     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3042     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3043     Release();
3044 }
3045 
3046 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_FlacFormatChanged, TestSize.Level1)
3047 {
3048     isTestingFormat_ = true;
3049     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(INPUT_FLAC_FILE_PATH, OUTPUT_FLAC_PCM_FILE_PATH));
3050     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
3051     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_FLAC));
3052     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3053     {
3054         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3b02() 3055         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3056     }
3057     EXPECT_EQ(g_outputSampleRate, DEFAULT_SAMPLE_RATE);
3058     EXPECT_EQ(g_outputChannels, DEFAULT_CHANNEL_COUNT);
3059     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3060     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3061     Release();
3062 }
3063 
3064 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_FlacSampleFormatChanged, TestSize.Level1)
3065 {
3066     isTestingFormat_ = true;
3067     inputFile_.open(INPUT_FLAC_192K_FILE_PATH, std::ios::binary);
3068     ASSERT_EQ(true, inputFile_.is_open());
3069     pcmOutputFile_.open(OUTPUT_FLAC_192K_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
3070     ASSERT_EQ(true, pcmOutputFile_.is_open());
3071     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
3072     format_ = OH_AVFormat_Create();
3073     EXPECT_NE(nullptr, format_);
3074     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
3075     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), FLAC_192K_SAMPLE_RATE);
3076     // set abnormal trigger on changed callback
3077     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), ABNORMAL_SAMPLE_FORMAT);
3078     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
3079                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
3080     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
3081     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3082     {
3083         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3c02() 3084         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3085     }
3086     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3087     Release();
3088 }
3089 
3090 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_FlacSampleFormatChanged_02, TestSize.Level1)
3091 {
3092     isTestingFormat_ = true;
3093     inputFile_.open(INPUT_FLAC_192K_FILE_PATH, std::ios::binary);
3094     ASSERT_EQ(true, inputFile_.is_open());
3095     pcmOutputFile_.open(OUTPUT_FLAC_192K_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
3096     ASSERT_EQ(true, pcmOutputFile_.is_open());
3097     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
3098     format_ = OH_AVFormat_Create();
3099     EXPECT_NE(nullptr, format_);
3100     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
3101     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), FLAC_192K_SAMPLE_RATE);
3102     // set invalid sample format trigger on changed callback
3103     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(),
3104                             AudioSampleFormat::SAMPLE_S16P);
3105     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
3106                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
3107     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
3108     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3109     {
3110         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3d02() 3111         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3112     }
3113     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3114     Release();
3115 }
3116 
3117 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_FlacSampleFormatChanged_03, TestSize.Level1)
3118 {
3119     isTestingFormat_ = true;
3120     inputFile_.open(INPUT_FLAC_192K_FILE_PATH, std::ios::binary);
3121     ASSERT_EQ(true, inputFile_.is_open());
3122     pcmOutputFile_.open(OUTPUT_FLAC_192K_PCM_FILE_PATH.data(), std::ios::out | std::ios::binary);
3123     ASSERT_EQ(true, pcmOutputFile_.is_open());
3124     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_FLAC));
3125     format_ = OH_AVFormat_Create();
3126     EXPECT_NE(nullptr, format_);
3127     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
3128     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), FLAC_192K_SAMPLE_RATE);
3129     // not set sample format trigger on changed callback
3130     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(),
3131                              BITS_RATE[(uint32_t)AudioBufferFormatType::TYPE_FLAC]);
3132     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_));
3133     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3134     {
3135         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3e02() 3136         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3137     }
3138     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3139     Release();
3140 }
3141 
3142 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Mp3FormatChanged, TestSize.Level1)
3143 {
3144     isTestingFormat_ = true;
3145     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(INPUT_MP3_FILE_PATH, OUTPUT_MP3_PCM_FILE_PATH));
3146     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_MP3));
3147     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_MP3));
3148     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3149     {
3150         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c3f02() 3151         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3152     }
3153     EXPECT_EQ(g_outputSampleRate, DEFAULT_SAMPLE_RATE);
3154     EXPECT_EQ(g_outputChannels, DEFAULT_CHANNEL_COUNT);
3155     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3156     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3157     Release();
3158 }
3159 
3160 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_VorbisFormatChanged, TestSize.Level1)
3161 {
3162     isTestingFormat_ = true;
3163     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(INPUT_VORBIS_FILE_PATH, OUTPUT_VORBIS_PCM_FILE_PATH));
3164     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_VORBIS));
3165     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_VORBIS));
3166     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3167     {
3168         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4002() 3169         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3170     }
3171     EXPECT_EQ(g_outputSampleRate, DEFAULT_SAMPLE_RATE);
3172     EXPECT_EQ(g_outputChannels, DEFAULT_CHANNEL_COUNT);
3173     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3174     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3175     Release();
3176 }
3177 
3178 #ifdef SUPPORT_CODEC_COOK
3179 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_CreateByMime_01, TestSize.Level1)
3180 {
3181     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_COOK.data(), false);
3182     EXPECT_NE(nullptr, audioDec_);
3183     Release();
3184 }
3185 
3186 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_CreateByName_01, TestSize.Level1)
3187 {
3188     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_COOK_NAME).data());
3189     EXPECT_NE(nullptr, audioDec_);
3190     Release();
3191 }
3192 
3193 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_Configure_01, TestSize.Level1)
3194 {
3195     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3196     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3197     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3198     Release();
3199 }
3200 
3201 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_Configure_02, TestSize.Level1)
3202 {
3203     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3204     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3205     format_ = OH_AVFormat_Create();
3206     EXPECT_NE(nullptr, format_);
3207 
3208     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
3209     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
3210     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(), 44100);
3211     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
3212 
3213     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3214     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
3215     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal min channel count
3216 
3217     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3218     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MAX_CHANNEL_COUNT);
3219     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal max channel count
3220 
3221     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3222     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
3223     int64_t extradataSize;
3224     EXPECT_EQ(true, inputFile_.is_open());
3225     inputFile_.read(reinterpret_cast<char *>(&extradataSize), sizeof(int64_t));
3226     EXPECT_EQ(false, inputFile_.gcount() != sizeof(int64_t) || extradataSize < 0);
3227     char buffer[extradataSize];
3228     inputFile_.read(buffer, extradataSize);
3229     EXPECT_EQ(false, inputFile_.gcount() != extradataSize);
3230     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_CODEC_CONFIG.data(), (uint8_t *)buffer,
3231                             extradataSize);
3232     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
3233 
3234     Release();
3235 }
3236 
3237 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_Configure_03, TestSize.Level1)
3238 {
3239     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3240     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3241     format_ = OH_AVFormat_Create();
3242     EXPECT_NE(nullptr, format_);
3243 
3244     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
3245     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
3246     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(), 44100);
3247     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
3248 
3249     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3250     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
3251     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample rate
3252 
3253     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3254     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
3255     int64_t extradataSize;
3256     EXPECT_EQ(true, inputFile_.is_open());
3257     inputFile_.read(reinterpret_cast<char *>(&extradataSize), sizeof(int64_t));
3258     EXPECT_EQ(false, inputFile_.gcount() != sizeof(int64_t) || extradataSize < 0);
3259     char buffer[extradataSize];
3260     inputFile_.read(buffer, extradataSize);
3261     EXPECT_EQ(false, inputFile_.gcount() != extradataSize);
3262     OH_AVFormat_SetBuffer(format_, MediaDescriptionKey::MD_KEY_CODEC_CONFIG.data(), (uint8_t *)buffer,
3263                             extradataSize);
3264     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
3265 
3266     Release();
3267 }
3268 
3269 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_SetParameter_01, TestSize.Level1)
3270 {
3271     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3272     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3273     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3274     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3275     {
3276         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4102() 3277         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3278     }
3279     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
3280     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
3281     Release();
3282 }
3283 
3284 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_SetParameter_02, TestSize.Level1)
3285 {
3286     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3287     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3288     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3289     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
3290     Release();
3291 }
3292 
3293 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_Start_01, TestSize.Level1)
3294 {
3295     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3296     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3297     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3298     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3299     {
3300         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4202() 3301         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3302     }
3303     Release();
3304 }
3305 
3306 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_Start_02, TestSize.Level1)
3307 {
3308     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3309     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3310     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3311     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3312     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3313     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
3314     {
3315         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4302() 3316         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3317     }
3318     Release();
3319 }
3320 
3321 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_Stop_01, TestSize.Level1)
3322 {
3323     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3324     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3325     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3326     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3327     sleep(1);
3328 
3329     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3330     Release();
3331 }
3332 
3333 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_Flush_01, TestSize.Level1)
3334 {
3335     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3336     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3337     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3338     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3339     {
3340         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4402() 3341         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3342     }
3343     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
3344     Release();
3345 }
3346 
3347 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_Reset_01, TestSize.Level1)
3348 {
3349     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3350     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3351     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3352     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3353     Release();
3354 }
3355 
3356 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_Reset_02, TestSize.Level1)
3357 {
3358     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3359     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3360     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3361     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3362     {
3363         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4502() 3364         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3365     }
3366     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3367     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3368     Release();
3369 }
3370 
3371 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_Reset_03, TestSize.Level1)
3372 {
3373     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3374     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3375     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3376     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3377     {
3378         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4602() 3379         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3380     }
3381     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3382     Release();
3383 }
3384 
3385 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_Destroy_01, TestSize.Level1)
3386 {
3387     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3388     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3389     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3390     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3391     {
3392         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4702() 3393         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3394     }
3395     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3396     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
3397 }
3398 
3399 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_Destroy_02, TestSize.Level1)
3400 {
3401     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3402     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3403     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3404 
3405     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
3406 }
3407 
3408 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_GetOutputFormat_01, TestSize.Level1)
3409 {
3410     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3411     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3412     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3413 
3414     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
3415     Release();
3416 }
3417 
3418 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_IsValid_01, TestSize.Level1)
3419 {
3420     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3421     bool isValid = false;
3422     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
3423     Release();
3424 }
3425 
3426 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_Prepare_01, TestSize.Level1)
3427 {
3428     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3429     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3430     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3431     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
3432     Release();
3433 }
3434 
3435 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_PushInputData_01, TestSize.Level1)
3436 {
3437     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3438     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3439     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3440     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3441 
3442     // case0 传参异常
3443     const uint32_t index = 1024;
3444     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
3445     Release();
3446 }
3447 
3448 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_Cook_ReleaseOutputBuffer_01, TestSize.Level1)
3449 {
3450     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_COOK));
3451     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_COOK));
3452     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_COOK));
3453     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3454 
3455     // case0 传参异常
3456     const uint32_t index = 1024;
3457     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
3458     Release();
3459 }
3460 #endif
3461 
3462 #ifdef SUPPORT_CODEC_AC3
3463 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_CreateByMime_01, TestSize.Level1)
3464 {
3465     audioDec_ = OH_AudioCodec_CreateByMime(AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_AC3.data(), false);
3466     EXPECT_NE(nullptr, audioDec_);
3467     Release();
3468 }
3469 
3470 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_CreateByName_01, TestSize.Level1)
3471 {
3472     audioDec_ = OH_AudioCodec_CreateByName((AVCodecCodecName::AUDIO_DECODER_AC3_NAME).data());
3473     EXPECT_NE(nullptr, audioDec_);
3474     Release();
3475 }
3476 
3477 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_Configure_01, TestSize.Level1)
3478 {
3479     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3480     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3481     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3482     Release();
3483 }
3484 
3485 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_Configure_02, TestSize.Level1)
3486 {
3487     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3488     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3489     format_ = OH_AVFormat_Create();
3490     EXPECT_NE(nullptr, format_);
3491 
3492     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
3493     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
3494     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(), 44100);
3495     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing channel count
3496 
3497     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3498     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MIN_CHANNEL_COUNT);
3499     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal min channel count
3500 
3501     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3502     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), ABNORMAL_MAX_CHANNEL_COUNT);
3503     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal max channel count
3504 
3505     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3506     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
3507     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal channel count
3508 
3509     Release();
3510 }
3511 
3512 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_Configure_03, TestSize.Level1)
3513 {
3514     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3515     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3516     format_ = OH_AVFormat_Create();
3517     EXPECT_NE(nullptr, format_);
3518 
3519     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_AUDIO_SAMPLE_FORMAT.data(), DEFAULT_SAMPLE_FORMAT);
3520     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), DEFAULT_CHANNEL_COUNT);
3521     OH_AVFormat_SetLongValue(format_, MediaDescriptionKey::MD_KEY_BITRATE.data(), 44100);
3522     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // missing sample rate
3523 
3524     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3525     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), ABNORMAL_SAMPLE_RATE);
3526     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // abnormal sample rate
3527 
3528     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3529     OH_AVFormat_SetIntValue(format_, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE);
3530     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioDec_, format_)); // normal sample rate
3531 
3532     Release();
3533 }
3534 
3535 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_SetParameter_01, TestSize.Level1)
3536 {
3537     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3538     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3539     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3540     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3541     {
3542         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4802() 3543         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3544     }
3545     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
3546     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
3547     Release();
3548 }
3549 
3550 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_SetParameter_02, TestSize.Level1)
3551 {
3552     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3553     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3554     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3555     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_SetParameter(audioDec_, format_));
3556     Release();
3557 }
3558 
3559 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_Start_01, TestSize.Level1)
3560 {
3561     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3562     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3563     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3564     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3565     {
3566         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4902() 3567         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3568     }
3569     Release();
3570 }
3571 
3572 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_Start_02, TestSize.Level1)
3573 {
3574     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3575     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3576     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3577     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3578     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3579     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioDec_));
3580     {
3581         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4a02() 3582         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3583     }
3584     Release();
3585 }
3586 
3587 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_Stop_01, TestSize.Level1)
3588 {
3589     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3590     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3591     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3592     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3593     sleep(1);
3594 
3595     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3596     Release();
3597 }
3598 
3599 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_Flush_01, TestSize.Level1)
3600 {
3601     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3602     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3603     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3604     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3605     {
3606         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4b02() 3607         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3608     }
3609     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioDec_));
3610     Release();
3611 }
3612 
3613 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_Reset_01, TestSize.Level1)
3614 {
3615     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3616     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3617     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3618     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3619     Release();
3620 }
3621 
3622 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_Reset_02, TestSize.Level1)
3623 {
3624     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3625     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3626     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3627     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3628     {
3629         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4c02() 3630         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3631     }
3632     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3633     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3634     Release();
3635 }
3636 
3637 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_Reset_03, TestSize.Level1)
3638 {
3639     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3640     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3641     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3642     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3643     {
3644         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4d02() 3645         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3646     }
3647     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Reset(audioDec_));
3648     Release();
3649 }
3650 
3651 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_Destroy_01, TestSize.Level1)
3652 {
3653     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3654     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3655     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3656     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3657     {
3658         unique_lock<mutex> lock(signal_->startMutex_);
__anon87d6d78c4e02() 3659         signal_->startCond_.wait(lock, [this]() { return (!(isRunning_.load())); });
3660     }
3661     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Stop());
3662     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
3663 }
3664 
3665 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_Destroy_02, TestSize.Level1)
3666 {
3667     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3668     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3669     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3670 
3671     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioDec_));
3672 }
3673 
3674 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_GetOutputFormat_01, TestSize.Level1)
3675 {
3676     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3677     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3678     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3679 
3680     EXPECT_NE(nullptr, OH_AudioCodec_GetOutputDescription(audioDec_));
3681     Release();
3682 }
3683 
3684 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_IsValid_01, TestSize.Level1)
3685 {
3686     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3687     bool isValid = false;
3688     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_IsValid(audioDec_, &isValid));
3689     Release();
3690 }
3691 
3692 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_Prepare_01, TestSize.Level1)
3693 {
3694     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3695     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3696     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3697     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Prepare(audioDec_));
3698     Release();
3699 }
3700 
3701 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_PushInputData_01, TestSize.Level1)
3702 {
3703     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3704     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3705     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3706     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3707 
3708     // case0 传参异常
3709     const uint32_t index = 1024;
3710     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_PushInputBuffer(audioDec_, index));
3711     Release();
3712 }
3713 
3714 HWTEST_F(AudioDecoderBufferCapiUnitTest, audioDecoder_AC3_ReleaseOutputBuffer_01, TestSize.Level1)
3715 {
3716     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, InitFile(AudioBufferFormatType::TYPE_AC3));
3717     ASSERT_EQ(OH_AVErrCode::AV_ERR_OK, CreateCodecFunc(AudioBufferFormatType::TYPE_AC3));
3718     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Configure(AudioBufferFormatType::TYPE_AC3));
3719     EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, Start());
3720 
3721     // case0 传参异常
3722     const uint32_t index = 1024;
3723     EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_FreeOutputBuffer(audioDec_, index));
3724     Release();
3725 }
3726 #endif
3727 
3728 }
3729 }