diff --git a/interfaces/inner_api/native/media_description.h b/interfaces/inner_api/native/media_description.h index 3ebc0b377b79071ed0b5be1ee2a964d8e8798c0b..41ae54f79c08ba2af9e12f34d2fa2e5c027804ff 100644 --- a/interfaces/inner_api/native/media_description.h +++ b/interfaces/inner_api/native/media_description.h @@ -201,7 +201,7 @@ public: /** * Key for the number of bits used to encode each sample, value type is uint32_t */ - static constexpr std::string_view MD_BITS_PER_CODED_SAMPLE_KEY = "bits_per_coded_sample"; + static constexpr std::string_view MD_KEY_BITS_PER_CODED_SAMPLE = "bits_per_coded_sample"; /** * Key for aac type, value type is uint32_t diff --git a/services/engine/codec/audio/decoder/audio_ffmpeg_decoder_plugin.cpp b/services/engine/codec/audio/decoder/audio_ffmpeg_decoder_plugin.cpp index 99999bf17d8ad2061006ceef115b63c05d269041..80314fbfccdb2db618c520ee9dcb8776117a6a7b 100644 --- a/services/engine/codec/audio/decoder/audio_ffmpeg_decoder_plugin.cpp +++ b/services/engine/codec/audio/decoder/audio_ffmpeg_decoder_plugin.cpp @@ -43,7 +43,9 @@ AudioFfmpegDecoderPlugin::AudioFfmpegDecoderPlugin() AudioFfmpegDecoderPlugin::~AudioFfmpegDecoderPlugin() { CloseCtxLocked(); - avCodecContext_.reset(); + if (avCodecContext_ != nullptr) { + avCodecContext_.reset(); + } } int32_t AudioFfmpegDecoderPlugin::ProcessSendData(const std::shared_ptr &inputBuffer) @@ -211,7 +213,9 @@ int32_t AudioFfmpegDecoderPlugin::Release() { std::unique_lock lock(avMutext_); auto ret = CloseCtxLocked(); - avCodecContext_.reset(); + if (avCodecContext_ != nullptr) { + avCodecContext_.reset(); + } return ret; } @@ -243,6 +247,8 @@ int32_t AudioFfmpegDecoderPlugin::AllocateContext(const std::string &name) context = avcodec_alloc_context3(avCodec_.get()); avCodecContext_ = std::shared_ptr(context, [](AVCodecContext *ptr) { + ptr->extradata = nullptr; + ptr->extradata_size = 0; avcodec_free_context(&ptr); avcodec_close(ptr); }); @@ -252,13 +258,14 @@ int32_t AudioFfmpegDecoderPlugin::AllocateContext(const std::string &name) int32_t AudioFfmpegDecoderPlugin::InitContext(const Format &format) { - format.GetIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, avCodecContext_->channels); - format.GetIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, avCodecContext_->sample_rate); - format.GetLongValue(MediaDescriptionKey::MD_KEY_BITRATE, avCodecContext_->bit_rate); - format.GetLongValue(MediaDescriptionKey::MD_KEY_MAX_INPUT_SIZE, maxInputSize_); + format_ = format; + format_.GetIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, avCodecContext_->channels); + format_.GetIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, avCodecContext_->sample_rate); + format_.GetLongValue(MediaDescriptionKey::MD_KEY_BITRATE, avCodecContext_->bit_rate); + format_.GetLongValue(MediaDescriptionKey::MD_KEY_MAX_INPUT_SIZE, maxInputSize_); size_t extraSize; - if (format.GetBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, &avCodecContext_->extradata, extraSize)) { + if (format_.GetBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, &avCodecContext_->extradata, extraSize)) { avCodecContext_->extradata_size = extraSize; hasExtra_ = true; } @@ -268,7 +275,6 @@ int32_t AudioFfmpegDecoderPlugin::InitContext(const Format &format) avCodecContext_->workaround_bugs = static_cast(avCodecContext_->workaround_bugs) | static_cast(FF_BUG_AUTODETECT); avCodecContext_->err_recognition = 1; - format_ = format; return AVCodecServiceErrCode::AVCS_ERR_OK; } diff --git a/services/engine/codec/audio/decoder/audio_ffmpeg_flac_decoder_plugin.cpp b/services/engine/codec/audio/decoder/audio_ffmpeg_flac_decoder_plugin.cpp index 0af486d74f2c2366f805528427438c39242faa27..5461c723e883bf73c487ada05967430b1bf727b7 100644 --- a/services/engine/codec/audio/decoder/audio_ffmpeg_flac_decoder_plugin.cpp +++ b/services/engine/codec/audio/decoder/audio_ffmpeg_flac_decoder_plugin.cpp @@ -68,7 +68,7 @@ int32_t AudioFFMpegFlacDecoderPlugin::init(const Format &format) format.GetIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, channels); format.GetIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, sample_rate); format.GetLongValue(MediaDescriptionKey::MD_KEY_BITRATE, bit_rate); - format.GetIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, bits_per_coded_sample); + format.GetIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, bits_per_coded_sample); if (!isTrueSampleRate(sample_rate)) { return AVCodecServiceErrCode::AVCS_ERR_MISMATCH_SAMPLE_RATE; } else if (channels < minChannels || channels > maxChannels) { diff --git a/services/engine/codec/audio/encoder/audio_ffmpeg_flac_encoder_plugin.cpp b/services/engine/codec/audio/encoder/audio_ffmpeg_flac_encoder_plugin.cpp index ce21962675671c7188da508021e77537f18acc9c..a9480a44010d248122e2db732dbdf5066a0245a6 100644 --- a/services/engine/codec/audio/encoder/audio_ffmpeg_flac_encoder_plugin.cpp +++ b/services/engine/codec/audio/encoder/audio_ffmpeg_flac_encoder_plugin.cpp @@ -71,7 +71,7 @@ int32_t AudioFFMpegFlacEncoderPlugin::init(const Format &format) int32_t bits_per_coded_sample; format.GetIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, channels); format.GetIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, sample_rate); - format.GetIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, bits_per_coded_sample); + format.GetIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, bits_per_coded_sample); if (!isTrueSampleRate(sample_rate)) { AVCODEC_LOGE("init failed, because sample rate=%{public}d not in table.", sample_rate); return AVCodecServiceErrCode::AVCS_ERR_MISMATCH_SAMPLE_RATE; diff --git a/test/nativedemo/audio_demo/avcodec_audio_aac_encoder_demo.cpp b/test/nativedemo/audio_demo/avcodec_audio_aac_encoder_demo.cpp index 790671da6e470fd643e047785d4c79ee40841c31..c8544a50040993866642c27c8d6b6941df6d57ba 100644 --- a/test/nativedemo/audio_demo/avcodec_audio_aac_encoder_demo.cpp +++ b/test/nativedemo/audio_demo/avcodec_audio_aac_encoder_demo.cpp @@ -98,7 +98,7 @@ void AEncAacDemo::RunCase() OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), CHANNEL_COUNT); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), SAMPLE_RATE); OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), BITS_RATE); - OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY.data(), BITS_PER_CODED_RATE); + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE.data(), BITS_PER_CODED_RATE); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_FORMAT.data(), SAMPLE_FORMAT); OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT.data(), CHANNEL_LAYOUT); diff --git a/test/nativedemo/audio_demo/avcodec_audio_decoder_demo.cpp b/test/nativedemo/audio_demo/avcodec_audio_decoder_demo.cpp index b4a05bd80945d1aad1005e6f21f1ef27e9de47ec..cc95556ec852803851ed3b5c7a68bb507aebbda4 100644 --- a/test/nativedemo/audio_demo/avcodec_audio_decoder_demo.cpp +++ b/test/nativedemo/audio_demo/avcodec_audio_decoder_demo.cpp @@ -32,12 +32,18 @@ using namespace std; namespace { constexpr uint32_t CHANNEL_COUNT = 2; constexpr uint32_t SAMPLE_RATE = 44100; -constexpr uint32_t BITS_RATE = 169000; -constexpr uint32_t BITS_PER_CODED_RATE = 16; -constexpr uint32_t FRAME_DURATION_US = 33000; -constexpr uint32_t FRAME_BYTES = 18432; -constexpr string_view inputFilePath = "/data/test1.flac"; -constexpr string_view outputFilePath = "/data/test1.pcm"; +constexpr uint32_t BITS_PER_SAMPLE = 16; +constexpr uint32_t BITS_PER_CODED_RATE = 4; +constexpr uint32_t DEFAULT_AAC_TYPE = 1; +constexpr int64_t BITS_RETE[TYPE_MAX] = {197000, 543000, 128000, 160000}; +constexpr string_view inputAacFilePath = "/data/aac_2c_44100hz_197k.dat";; +constexpr string_view outputAacPcmFilePath = "/data/aac_2c_44100hz_197k.pcm"; +constexpr string_view inputFlacFilePath = "/data/flac_2c_44100hz_543k.dat";; +constexpr string_view outputFlacPcmFilePath = "/data/flac_2c_44100hz_543k.pcm"; +constexpr string_view inputMp3FilePath = "/data/mp3_2c_44100hz_128k.dat";; +constexpr string_view outputMp3PcmFilePath = "/data/mp3_2c_44100hz_128k.pcm"; +constexpr string_view inputVorbisFilePath = "/data/vorbis_2c_44100hz_160k.dat";; +constexpr string_view outputVorbisPcmFilePath = "/data/vorbis_2c_44100hz_160k.pcm"; } // namespace static void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData) @@ -60,7 +66,6 @@ static void OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemor { (void)codec; ADecSignal *signal_ = static_cast(userData); - cout << "OnInputBufferAvailable received, index:" << index << endl; unique_lock lock(signal_->inMutex_); signal_->inQueue_.push(index); signal_->inBufferQueue_.push(data); @@ -72,12 +77,10 @@ static void OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemo { (void)codec; ADecSignal *signal_ = static_cast(userData); - cout << "OnOutputBufferAvailable received, index:" << index << endl; unique_lock lock(signal_->outMutex_); signal_->outQueue_.push(index); signal_->outBufferQueue_.push(data); if (attr) { - cout << "OnOutputBufferAvailable received, index:" << index << ", attr->size:" << attr->size << endl; signal_->attrQueue_.push(*attr); } else { cout << "OnOutputBufferAvailable error, attr is nullptr!" << endl; @@ -85,17 +88,62 @@ static void OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemo signal_->outCond_.notify_all(); } -void ADecDemo::RunCase() +bool ADecDemo::InitFile(AudioFormatType audioType) { + if (audioType == TYPE_AAC) { + inputFile_.open(inputAacFilePath, std::ios::binary); + pcmOutputFile_.open(outputAacPcmFilePath.data(), std::ios::out | std::ios::binary); + } else if (audioType == TYPE_FLAC) { + inputFile_.open(inputFlacFilePath, std::ios::binary); + pcmOutputFile_.open(outputFlacPcmFilePath.data(), std::ios::out | std::ios::binary); + } else if (audioType == TYPE_MP3) { + inputFile_.open(inputMp3FilePath, std::ios::binary); + pcmOutputFile_.open(outputMp3PcmFilePath.data(), std::ios::out | std::ios::binary); + } else if (audioType == TYPE_VORBIS) { + inputFile_.open(inputVorbisFilePath, std::ios::binary); + pcmOutputFile_.open(outputVorbisPcmFilePath.data(), std::ios::out | std::ios::binary); + } else { + std::cout << "audio format type not support\n"; + return false; + } + DEMO_CHECK_AND_RETURN_RET_LOG(inputFile_.is_open(), false, "Fatal: open input file failed"); + DEMO_CHECK_AND_RETURN_RET_LOG(pcmOutputFile_.is_open(), false, "Fatal: open output file failed"); + return true; +} + +void ADecDemo::RunCase(AudioFormatType audioType) +{ + DEMO_CHECK_AND_RETURN_LOG(InitFile(audioType), "Fatal: InitFile file failed"); + audioType_ = audioType; DEMO_CHECK_AND_RETURN_LOG(CreateDec() == AVCS_ERR_OK, "Fatal: CreateDec fail"); OH_AVFormat *format = OH_AVFormat_Create(); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), CHANNEL_COUNT); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), SAMPLE_RATE); - OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY.data(), BITS_PER_CODED_RATE); - OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), BITS_RATE); + if (audioType == TYPE_FLAC) { + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE.data(), BITS_PER_SAMPLE); + } else { + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE.data(), BITS_PER_CODED_RATE); + } + if (audioType == TYPE_AAC) { + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_AAC_IS_ADTS.data(), DEFAULT_AAC_TYPE); + } + OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), BITS_RETE[audioType]); + if (audioType == TYPE_VORBIS) { + // extradata for vorbis + int64_t extradataSize; + DEMO_CHECK_AND_RETURN_LOG(inputFile_.is_open(), "Fatal: file is not open"); + inputFile_.read(reinterpret_cast(&extradataSize), sizeof(int64_t)); + DEMO_CHECK_AND_RETURN_LOG(inputFile_.gcount() == sizeof(int64_t), "Fatal: read extradataSize bytes error"); + if (extradataSize < 0) { + return; + } + char buffer[extradataSize]; + inputFile_.read(buffer, extradataSize); + DEMO_CHECK_AND_RETURN_LOG(inputFile_.gcount() == extradataSize, "Fatal: read extradata bytes error"); + OH_AVFormat_SetBuffer(format, MediaDescriptionKey::MD_KEY_CODEC_CONFIG.data(), (uint8_t*)buffer, extradataSize); + } DEMO_CHECK_AND_RETURN_LOG(Configure(format) == AVCS_ERR_OK, "Fatal: Configure fail"); - DEMO_CHECK_AND_RETURN_LOG(Start() == AVCS_ERR_OK, "Fatal: Start fail"); while (isRunning_.load()) { @@ -109,21 +157,6 @@ void ADecDemo::RunCase() ADecDemo::ADecDemo() { - int32_t ret = 0; - ret = avformat_open_input(&fmpt_ctx, inputFilePath.data(), NULL, NULL); - if (ret < 0) { - std::cout << "open file failed" << ret << "\n"; - exit(1); - } - if (avformat_find_stream_info(fmpt_ctx, NULL) < 0) { - std::cout << "get file stream failed" - << "\n"; - exit(1); - } - frame = av_frame_alloc(); - av_init_packet(&pkt); - pkt.data = NULL; - pkt.size = 0; } ADecDemo::~ADecDemo() @@ -132,11 +165,27 @@ ADecDemo::~ADecDemo() delete signal_; signal_ = nullptr; } + if (inputFile_.is_open()) { + inputFile_.close(); + } + if (pcmOutputFile_.is_open()) { + pcmOutputFile_.close(); + } } int32_t ADecDemo::CreateDec() { - audioDec_ = OH_AudioDecoder_CreateByName((AVCodecCodecName::AUDIO_DECODER_MP3_NAME_KEY).data()); + if (audioType_ == TYPE_AAC) { + audioDec_ = OH_AudioDecoder_CreateByName((AVCodecCodecName::AUDIO_DECODER_AAC_NAME_KEY).data()); + } else if (audioType_ == TYPE_FLAC) { + audioDec_ = OH_AudioDecoder_CreateByName((AVCodecCodecName::AUDIO_DECODER_FLAC_NAME_KEY).data()); + } else if (audioType_ == TYPE_MP3) { + audioDec_ = OH_AudioDecoder_CreateByName((AVCodecCodecName::AUDIO_DECODER_MP3_NAME_KEY).data()); + } else if (audioType_ == TYPE_VORBIS) { + audioDec_ = OH_AudioDecoder_CreateByName((AVCodecCodecName::AUDIO_DECODER_VORBIS_NAME_KEY).data()); + } else { + return AVCS_ERR_INVALID_VAL; + } DEMO_CHECK_AND_RETURN_RET_LOG(audioDec_ != nullptr, AVCS_ERR_UNKNOWN, "Fatal: CreateByName fail"); signal_ = new ADecSignal(); @@ -202,13 +251,49 @@ int32_t ADecDemo::Release() return OH_AudioDecoder_Destroy(audioDec_); } +void ADecDemo::HandleInputEOS(const uint32_t index) +{ + OH_AVCodecBufferAttr info; + info.size = 0; + info.offset = 0; + info.pts = 0; + info.flags = AVCODEC_BUFFER_FLAGS_EOS; + OH_AudioDecoder_PushInputData(audioDec_, index, info); + signal_->inBufferQueue_.pop(); + signal_->inQueue_.pop(); +} + +int32_t ADecDemo::HandleNormalInput(const uint32_t &index, const int64_t pts, const size_t size) +{ + OH_AVCodecBufferAttr info; + info.size = size; + info.offset = 0; + info.pts = pts; + + int32_t ret = AVCS_ERR_OK; + if (isFirstFrame_) { + info.flags = AVCODEC_BUFFER_FLAGS_CODEC_DATA; + ret = OH_AudioDecoder_PushInputData(audioDec_, index, info); + isFirstFrame_ = false; + } else { + info.flags = AVCODEC_BUFFER_FLAGS_NONE; + ret = OH_AudioDecoder_PushInputData(audioDec_, index, info); + } + signal_->inQueue_.pop(); + signal_->inBufferQueue_.pop(); + frameCount_++; + return ret; +} + void ADecDemo::InputFunc() { + int64_t size; + int64_t pts; + while (true) { if (!isRunning_.load()) { break; } - unique_lock lock(signal_->inMutex_); signal_->inCond_.wait(lock, [this]() { return (signal_->inQueue_.size() > 0 || !isRunning_.load()); }); @@ -218,60 +303,31 @@ void ADecDemo::InputFunc() uint32_t index = signal_->inQueue_.front(); auto buffer = signal_->inBufferQueue_.front(); - int32_t ret = av_read_frame(fmpt_ctx, &pkt); - if (ret < 0) { - OH_AVCodecBufferAttr info; - info.size = 0; - info.offset = 0; - info.pts = 0; - info.flags = AVCODEC_BUFFER_FLAGS_EOS; - av_packet_unref(&pkt); - OH_AudioDecoder_PushInputData(audioDec_, index, info); - signal_->inBufferQueue_.pop(); - signal_->inQueue_.pop(); + DEMO_CHECK_AND_BREAK_LOG(buffer != nullptr, "Fatal: GetInputBuffer fail"); + inputFile_.read(reinterpret_cast(&size), sizeof(size)); + if (inputFile_.eof() || inputFile_.gcount() == 0) { + HandleInputEOS(index); std::cout << "end buffer\n"; break; } - std::cout << "start read frame: size:" << pkt.size << ",pts:" << pkt.pts << "\n"; - DEMO_CHECK_AND_BREAK_LOG(buffer != nullptr, "Fatal: GetInputBuffer fail"); - OH_AVCodecBufferAttr info; - info.size = pkt.size; - info.offset = 0; - info.pts = pkt.pts; - memcpy_s(OH_AVMemory_GetAddr(buffer), pkt.size, pkt.data, pkt.size); - - ret = AVCS_ERR_OK; - if (isFirstFrame_) { - info.flags = AVCODEC_BUFFER_FLAGS_CODEC_DATA; - ret = OH_AudioDecoder_PushInputData(audioDec_, index, info); - isFirstFrame_ = false; - } else { - info.flags = AVCODEC_BUFFER_FLAGS_NONE; - ret = OH_AudioDecoder_PushInputData(audioDec_, index, info); - } - - timeStamp_ += FRAME_DURATION_US; - signal_->inQueue_.pop(); - signal_->inBufferQueue_.pop(); - - frameCount_++; + DEMO_CHECK_AND_BREAK_LOG(inputFile_.gcount() == sizeof(size), "Fatal: read size fail"); + inputFile_.read(reinterpret_cast(&pts), sizeof(pts)); + DEMO_CHECK_AND_BREAK_LOG(inputFile_.gcount() == sizeof(pts), "Fatal: read pts fail"); + inputFile_.read((char*)OH_AVMemory_GetAddr(buffer), size); + DEMO_CHECK_AND_BREAK_LOG(inputFile_.gcount() == size, "Fatal: read buffer fail"); + int32_t ret = HandleNormalInput(index, pts, size); if (ret != AVCS_ERR_OK) { cout << "Fatal error, exit" << endl; break; } } + inputFile_.close(); } void ADecDemo::OutputFunc() { - std::ofstream pcmFile; - bool no_write = false; - pcmFile.open(outputFilePath.data(), std::ios::out | std::ios::binary); - if (!pcmFile.is_open()) { - std::cout << "open " << outputFilePath << " failed!" << std::endl; - } - + DEMO_CHECK_AND_RETURN_LOG(pcmOutputFile_.is_open(), "Fatal: output file failedis not open"); while (true) { if (!isRunning_.load()) { cout << "stop, exit" << endl; @@ -289,12 +345,8 @@ void ADecDemo::OutputFunc() uint32_t index = signal_->outQueue_.front(); OH_AVCodecBufferAttr attr = signal_->attrQueue_.front(); OH_AVMemory *data = signal_->outBufferQueue_.front(); - if (data != nullptr && !no_write) { - if (attr.size != FRAME_BYTES) { - no_write = true; - } - cout << "OutputFunc write file,buffer index" << index << ", data size = :" << attr.size << endl; - pcmFile.write(reinterpret_cast(OH_AVMemory_GetAddr(data)), attr.size); + if (data != nullptr) { + pcmOutputFile_.write(reinterpret_cast(OH_AVMemory_GetAddr(data)), attr.size); } if (attr.flags == AVCODEC_BUFFER_FLAGS_EOS) { @@ -309,5 +361,5 @@ void ADecDemo::OutputFunc() break; } } - pcmFile.close(); + pcmOutputFile_.close(); } \ No newline at end of file diff --git a/test/nativedemo/audio_demo/avcodec_audio_decoder_demo.h b/test/nativedemo/audio_demo/avcodec_audio_decoder_demo.h index 443a17c3ba9f17da2708bc1989e0ea682132690a..49c699ac46f88590f4be4c2dc131fa475019f42d 100644 --- a/test/nativedemo/audio_demo/avcodec_audio_decoder_demo.h +++ b/test/nativedemo/audio_demo/avcodec_audio_decoder_demo.h @@ -25,18 +25,17 @@ #include "native_avcodec_audiodecoder.h" #include "nocopyable.h" -#ifdef __cplusplus -extern "C" { -#endif -#include "libavcodec/avcodec.h" -#include "libavformat/avformat.h" -#ifdef __cplusplus -} -#endif - namespace OHOS { namespace Media { namespace AudioDemo { +enum AudioFormatType : int32_t { + TYPE_AAC = 0, + TYPE_FLAC = 1, + TYPE_MP3 = 2, + TYPE_VORBIS = 3, + TYPE_MAX = 4, +}; + class ADecSignal { public: std::mutex inMutex_; @@ -54,7 +53,7 @@ class ADecDemo : public NoCopyable { public: ADecDemo(); virtual ~ADecDemo(); - void RunCase(); + void RunCase(AudioFormatType audioType); private: int32_t CreateDec(); @@ -66,6 +65,9 @@ private: int32_t Release(); void InputFunc(); void OutputFunc(); + void HandleInputEOS(const uint32_t index); + int32_t HandleNormalInput(const uint32_t &index, const int64_t pts, const size_t size); + bool InitFile(AudioFormatType audioType); std::atomic isRunning_ = false; std::unique_ptr testFile_; @@ -75,12 +77,10 @@ private: ADecSignal *signal_; struct OH_AVCodecAsyncCallback cb_; bool isFirstFrame_ = true; - int64_t timeStamp_ = 0; uint32_t frameCount_ = 0; - - AVFormatContext *fmpt_ctx; - AVFrame *frame; - AVPacket pkt; + std::ifstream inputFile_; + std::ofstream pcmOutputFile_; + AudioFormatType audioType_; }; } // namespace AudioDemo } // namespace Media diff --git a/test/nativedemo/audio_demo/avcodec_audio_encoder_inner_demo.cpp b/test/nativedemo/audio_demo/avcodec_audio_encoder_inner_demo.cpp index be2e258b44c67921fa1baf8d3f0468ef7c4b4bf5..0cda18b4e0ce3ad055e372a00d3ac9cd402df942 100644 --- a/test/nativedemo/audio_demo/avcodec_audio_encoder_inner_demo.cpp +++ b/test/nativedemo/audio_demo/avcodec_audio_encoder_inner_demo.cpp @@ -54,7 +54,7 @@ void AEnInnerDemo::RunCase() format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT); format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE); format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, BITS_RATE); - format.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, BITS_PER_CODED_RATE); + format.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, BITS_PER_CODED_RATE); format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_FORMAT, DEFAULT_SAMPLE_FORMATE_VALE); format.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, DEFAULT_CHANNEL_LAYOUT_COUNT); DEMO_CHECK_AND_RETURN_LOG(Configure(format) == AVCS_ERR_OK, "Fatal: Configure fail"); diff --git a/test/nativedemo/audio_demo/avcodec_audio_flac_encoder_demo.cpp b/test/nativedemo/audio_demo/avcodec_audio_flac_encoder_demo.cpp index 268efef0176854b8238152d65beed3179080dc25..1b49fe56d8197d61ee45949dc3eb80da77f7b389 100644 --- a/test/nativedemo/audio_demo/avcodec_audio_flac_encoder_demo.cpp +++ b/test/nativedemo/audio_demo/avcodec_audio_flac_encoder_demo.cpp @@ -98,7 +98,7 @@ void AEncFlacDemo::RunCase() OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), CHANNEL_COUNT); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), SAMPLE_RATE); OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), BITS_RATE); - OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY.data(), BITS_PER_CODED_SAMPLE); + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE.data(), BITS_PER_CODED_SAMPLE); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_FORMAT.data(), SAMPLE_FORMAT); OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT.data(), CHANNEL_LAYOUT); diff --git a/test/nativedemo/av_codec_demo.cpp b/test/nativedemo/av_codec_demo.cpp index 21e8c7a08d038a0311d13ea5b15cadf2fba9efd9..8e5aa25d6d6d3ad24dccb7318cc1087b2f24bfff 100644 --- a/test/nativedemo/av_codec_demo.cpp +++ b/test/nativedemo/av_codec_demo.cpp @@ -40,31 +40,24 @@ static int RunAudioDecoder() cout << "2: MP3" << endl; cout << "3: VORBIS" << endl; string mode; + AudioFormatType audioFormatType = TYPE_AAC; (void)getline(cin, mode); if (mode == "" || mode == "0") { - auto audioDec = std::make_unique(); - if (audioDec) { - audioDec->RunCase(); - } + audioFormatType = TYPE_AAC; } else if (mode == "1") { - auto audioDec = std::make_unique(); - if (audioDec) { - audioDec->RunCase(); - } + audioFormatType = TYPE_FLAC; } else if (mode == "2") { - auto audioDec = std::make_unique(); - if (audioDec) { - audioDec->RunCase(); - } + audioFormatType = TYPE_MP3; } else if (mode == "3") { - auto audioDec = std::make_unique(); - if (audioDec) { - audioDec->RunCase(); - } + audioFormatType = TYPE_VORBIS; } else { cout << "no that selection" << endl; return 0; } + auto audioDec = std::make_unique(); + if (audioDec) { + audioDec->RunCase(audioFormatType); + } cout << "demo audio decoder end" << endl; return 0; } diff --git a/test/nativedemo/resources/aac_2c_44100hz_197k.dat b/test/nativedemo/resources/aac_2c_44100hz_197k.dat new file mode 100644 index 0000000000000000000000000000000000000000..947d1825c428f08104704bd51ef6ecd9e4596b0b Binary files /dev/null and b/test/nativedemo/resources/aac_2c_44100hz_197k.dat differ diff --git a/test/nativedemo/resources/flac_2c_44100hz_543k.dat b/test/nativedemo/resources/flac_2c_44100hz_543k.dat new file mode 100644 index 0000000000000000000000000000000000000000..f47c3e6c2d1f0f8cb6623345805d737aecacecbf Binary files /dev/null and b/test/nativedemo/resources/flac_2c_44100hz_543k.dat differ diff --git a/test/nativedemo/resources/mp3_2c_44100hz_128k.dat b/test/nativedemo/resources/mp3_2c_44100hz_128k.dat new file mode 100644 index 0000000000000000000000000000000000000000..682c06ab277019de38beb089544f27b6f824ac2c Binary files /dev/null and b/test/nativedemo/resources/mp3_2c_44100hz_128k.dat differ diff --git a/test/nativedemo/resources/vorbis_2c_44100hz_160k.dat b/test/nativedemo/resources/vorbis_2c_44100hz_160k.dat new file mode 100644 index 0000000000000000000000000000000000000000..283ad9e2b9e13fa47fe354c3de2787f26c8a4f32 Binary files /dev/null and b/test/nativedemo/resources/vorbis_2c_44100hz_160k.dat differ diff --git a/test/unittest/audio_test/audio_decoder_capi_unit_test.cpp b/test/unittest/audio_test/audio_decoder_capi_unit_test.cpp index debc57458aae009ba41d1a2a310b77e6a3499ea1..7266d0aa9d889e526f80a7834a118309d8f1b637 100644 --- a/test/unittest/audio_test/audio_decoder_capi_unit_test.cpp +++ b/test/unittest/audio_test/audio_decoder_capi_unit_test.cpp @@ -321,7 +321,7 @@ HWTEST_F(AudioCodeCapiDecoderUnitTest, audioDecoder_SetParameter_01, TestSize.Le ProceFunc(); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), MAX_CHANNEL_COUNT); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE); - OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY.data(), + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE.data(), DEFAULT_BITS_PER_CODED_RATE); OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), DEFAULT_BITRATE); @@ -361,7 +361,7 @@ HWTEST_F(AudioCodeCapiDecoderUnitTest, audioDecoder_SetParameter_02, TestSize.Le ProceFunc(); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), MAX_CHANNEL_COUNT); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE); - OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY.data(), + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE.data(), DEFAULT_BITS_PER_CODED_RATE); OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), DEFAULT_BITRATE); @@ -373,7 +373,7 @@ HWTEST_F(AudioCodeCapiDecoderUnitTest, audioDecoder_Configure_01, TestSize.Level ProceFunc(); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), MAX_CHANNEL_COUNT); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE); - OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY.data(), + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE.data(), DEFAULT_BITS_PER_CODED_RATE); OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), DEFAULT_BITRATE); @@ -385,7 +385,7 @@ HWTEST_F(AudioCodeCapiDecoderUnitTest, audioDecoder_normalcase_01, TestSize.Leve ProceFunc(); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), MAX_CHANNEL_COUNT); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE); - OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY.data(), + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE.data(), DEFAULT_BITS_PER_CODED_RATE); OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), DEFAULT_BITRATE); @@ -424,7 +424,7 @@ HWTEST_F(AudioCodeCapiDecoderUnitTest, audioDecoder_normalcase_02, TestSize.Leve ProceFunc(); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), MAX_CHANNEL_COUNT); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE); - OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY.data(), + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE.data(), DEFAULT_BITS_PER_CODED_RATE); OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), DEFAULT_BITRATE); @@ -463,7 +463,7 @@ HWTEST_F(AudioCodeCapiDecoderUnitTest, audioDecoder_normalcase_03, TestSize.Leve ProceFunc(); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), MAX_CHANNEL_COUNT); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE); - OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY.data(), + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE.data(), DEFAULT_BITS_PER_CODED_RATE); OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), DEFAULT_BITRATE); @@ -505,7 +505,7 @@ HWTEST_F(AudioCodeCapiDecoderUnitTest, audioDecoder_normalcase_04, TestSize.Leve ProceFunc(); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), MAX_CHANNEL_COUNT); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE); - OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY.data(), + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE.data(), DEFAULT_BITS_PER_CODED_RATE); OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), DEFAULT_BITRATE); @@ -545,7 +545,7 @@ HWTEST_F(AudioCodeCapiDecoderUnitTest, audioDecoder_normalcase_05, TestSize.Leve ProceFunc(); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), MAX_CHANNEL_COUNT); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE); - OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY.data(), + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE.data(), DEFAULT_BITS_PER_CODED_RATE); OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), DEFAULT_BITRATE); @@ -584,7 +584,7 @@ HWTEST_F(AudioCodeCapiDecoderUnitTest, audioDecoder_abnormalcase_01, TestSize.Le { OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_CHANNEL_COUNT.data(), MAX_CHANNEL_COUNT); OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_SAMPLE_RATE.data(), DEFAULT_SAMPLE_RATE); - OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY.data(), + OH_AVFormat_SetIntValue(format, MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE.data(), DEFAULT_BITS_PER_CODED_RATE); OH_AVFormat_SetLongValue(format, MediaDescriptionKey::MD_KEY_BITRATE.data(), DEFAULT_BITRATE); diff --git a/test/unittest/audio_test/audio_decoder_codecbase_unit_test.cpp b/test/unittest/audio_test/audio_decoder_codecbase_unit_test.cpp index c1771c10251ffb717a9e4f9fa42fee0158be7a9d..83d01b4b03266f6ce73eab0ba63623abc299696a 100644 --- a/test/unittest/audio_test/audio_decoder_codecbase_unit_test.cpp +++ b/test/unittest/audio_test/audio_decoder_codecbase_unit_test.cpp @@ -197,7 +197,7 @@ int32_t AudioCodeDecoderUnitTest::ProceFlacFunc(void) format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); if (adec_->Configure(format_) != AVCodecServiceErrCode::AVCS_ERR_OK) { return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN; @@ -513,7 +513,7 @@ HWTEST_F(AudioCodeDecoderUnitTest, audioDecoder_Flac_Configure_02, TestSize.Leve format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); } @@ -524,7 +524,7 @@ HWTEST_F(AudioCodeDecoderUnitTest, audioDecoder_Flac_Configure_03, TestSize.Leve format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); format_.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); } @@ -536,7 +536,7 @@ HWTEST_F(AudioCodeDecoderUnitTest, audioDecoder_Flac_Configure_04, TestSize.Leve format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); } @@ -547,7 +547,7 @@ HWTEST_F(AudioCodeDecoderUnitTest, audioDecoder_Flac_Configure_05, TestSize.Leve format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, INVALID_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, INVALID_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); } @@ -605,7 +605,7 @@ HWTEST_F(AudioCodeDecoderUnitTest, audioDecoder_Flac_Stop_02, TestSize.Level1) format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Stop()); } @@ -640,7 +640,7 @@ HWTEST_F(AudioCodeDecoderUnitTest, audioDecoder_Flac_Reset_02, TestSize.Level1) format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Reset()); } @@ -666,7 +666,7 @@ HWTEST_F(AudioCodeDecoderUnitTest, audioDecoder_Flac_Release_02, TestSize.Level1 format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Release()); } diff --git a/test/unittest/audio_test/audio_decoder_inner_unit_test.cpp b/test/unittest/audio_test/audio_decoder_inner_unit_test.cpp index 54f8abf8bd8e05a2a003ee8b60248b21504aabdd..04a1f851d1c72a06eac767d660042a6091297e0b 100644 --- a/test/unittest/audio_test/audio_decoder_inner_unit_test.cpp +++ b/test/unittest/audio_test/audio_decoder_inner_unit_test.cpp @@ -204,7 +204,7 @@ int32_t AudioCodeDecoderInnerUnitTest::ProceFlacFunc(void) format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); if (adec_->Configure(format_) != AVCodecServiceErrCode::AVCS_ERR_OK) { return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN; @@ -512,7 +512,7 @@ HWTEST_F(AudioCodeDecoderInnerUnitTest, audioDecoder_Flac_Configure_02, TestSize format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); } @@ -523,7 +523,7 @@ HWTEST_F(AudioCodeDecoderInnerUnitTest, audioDecoder_Flac_Configure_03, TestSize format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); format_.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); } @@ -535,7 +535,7 @@ HWTEST_F(AudioCodeDecoderInnerUnitTest, audioDecoder_Flac_Configure_04, TestSize format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); } @@ -546,7 +546,7 @@ HWTEST_F(AudioCodeDecoderInnerUnitTest, audioDecoder_Flac_Configure_05, TestSize format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, INVALID_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, INVALID_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); } @@ -604,7 +604,7 @@ HWTEST_F(AudioCodeDecoderInnerUnitTest, audioDecoder_Flac_Stop_02, TestSize.Leve format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); EXPECT_NE(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Stop()); } @@ -639,7 +639,7 @@ HWTEST_F(AudioCodeDecoderInnerUnitTest, audioDecoder_Flac_Reset_02, TestSize.Lev format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Reset()); } @@ -665,7 +665,7 @@ HWTEST_F(AudioCodeDecoderInnerUnitTest, audioDecoder_Flac_Release_02, TestSize.L format_.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, MAX_CHANNEL_COUNT); format_.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, DEFAULT_SAMPLE_RATE); format_.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, DEFAULT_BITRATE); - format_.PutIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, DEFAULT_BITS_PER_CODED_RATE); + format_.PutIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, DEFAULT_BITS_PER_CODED_RATE); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Configure(format_)); EXPECT_EQ(AVCodecServiceErrCode::AVCS_ERR_OK, adec_->Release()); }