mirror of
https://gitee.com/openharmony/multimedia_av_codec
synced 2024-12-03 12:53:04 +00:00
commit
5fa02dea22
@ -1,22 +1,20 @@
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/multimedia/av_codec/config.gni")
|
||||
|
||||
AV_CODEC_ROOT_DIR = "//foundation/multimedia/av_codec"
|
||||
|
||||
ohos_static_library("av_codec_codec_base"){
|
||||
include_dirs=[
|
||||
"//foundation/graphic/graphic_2d/frameworks/surface/include",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/base/include",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/common/include",
|
||||
"$AV_CODEC_ROOT_DIR/interfaces/inner_api/native",
|
||||
"$AV_CODEC_ROOT_DIR/interfaces/kits/c",
|
||||
"$AV_CODEC_ROOT_DIR/services/dfx/include",
|
||||
"$av_codec_root_dir/services/engine/base/include",
|
||||
"$av_codec_root_dir/services/engine/common/include",
|
||||
"$av_codec_root_dir/interfaces/inner_api/native",
|
||||
"$av_codec_root_dir/interfaces/kits/c",
|
||||
"$av_codec_root_dir/services/dfx/include",
|
||||
"//base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include",
|
||||
"//third_party/ffmpeg",
|
||||
]
|
||||
|
||||
sources=[
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/base/codecbase.cpp"
|
||||
"$av_codec_root_dir/services/engine/base/codecbase.cpp"
|
||||
]
|
||||
|
||||
deps=[
|
||||
|
@ -1,35 +1,33 @@
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/multimedia/av_codec/config.gni")
|
||||
|
||||
AV_CODEC_ROOT_DIR = "//foundation/multimedia/av_codec"
|
||||
|
||||
ohos_static_library("av_codec_audio_ffmpeg_codec"){
|
||||
include_dirs=[
|
||||
"//foundation/graphic/graphic_2d/frameworks/surface/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/base/include",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/common/include",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/factory",
|
||||
"$AV_CODEC_ROOT_DIR/services/utils/include",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/codec/include/audio",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/codec/include/audio/decoder",
|
||||
"$AV_CODEC_ROOT_DIR/interfaces/inner_api/native",
|
||||
"$AV_CODEC_ROOT_DIR/interfaces/kits/c",
|
||||
"$AV_CODEC_ROOT_DIR/services/dfx/include",
|
||||
"$av_codec_root_dir/services/engine/base/include",
|
||||
"$av_codec_root_dir/services/engine/common/include",
|
||||
"$av_codec_root_dir/services/engine/factory",
|
||||
"$av_codec_root_dir/services/utils/include",
|
||||
"$av_codec_root_dir/services/engine/codec/include/audio",
|
||||
"$av_codec_root_dir/services/engine/codec/include/audio/decoder",
|
||||
"$av_codec_root_dir/interfaces/inner_api/native",
|
||||
"$av_codec_root_dir/interfaces/kits/c",
|
||||
"$av_codec_root_dir/services/dfx/include",
|
||||
"//base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include",
|
||||
"//third_party/ffmpeg",
|
||||
]
|
||||
|
||||
sources=[
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/codec/audio/audio_buffer_info.cpp",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/codec/audio/audio_buffers_manager.cpp",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/codec/audio/audio_codec_worker.cpp",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/codec/audio/audio_ffmpeg_adapter.cpp",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/codec/audio/decoder/audio_ffmpeg_decoder_plugin.cpp",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/codec/audio/decoder/audio_ffmpeg_aac_decoder_plugin.cpp",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/codec/audio/decoder/audio_ffmpeg_flac_decoder_plugin.cpp",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/codec/audio/decoder/audio_ffmpeg_mp3_decoder_plugin.cpp",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/codec/audio/decoder/audio_ffmpeg_vorbis_decoder_plugin.cpp",
|
||||
"$av_codec_root_dir/services/engine/codec/audio/audio_buffer_info.cpp",
|
||||
"$av_codec_root_dir/services/engine/codec/audio/audio_buffers_manager.cpp",
|
||||
"$av_codec_root_dir/services/engine/codec/audio/audio_codec_worker.cpp",
|
||||
"$av_codec_root_dir/services/engine/codec/audio/audio_ffmpeg_adapter.cpp",
|
||||
"$av_codec_root_dir/services/engine/codec/audio/decoder/audio_ffmpeg_decoder_plugin.cpp",
|
||||
"$av_codec_root_dir/services/engine/codec/audio/decoder/audio_ffmpeg_aac_decoder_plugin.cpp",
|
||||
"$av_codec_root_dir/services/engine/codec/audio/decoder/audio_ffmpeg_flac_decoder_plugin.cpp",
|
||||
"$av_codec_root_dir/services/engine/codec/audio/decoder/audio_ffmpeg_mp3_decoder_plugin.cpp",
|
||||
"$av_codec_root_dir/services/engine/codec/audio/decoder/audio_ffmpeg_vorbis_decoder_plugin.cpp",
|
||||
]
|
||||
|
||||
deps=[
|
||||
|
@ -94,12 +94,12 @@ int32_t AudioFFMpegAdapter::Start()
|
||||
{
|
||||
AVCODEC_LOGD("Start enter");
|
||||
if (!callback_) {
|
||||
AVCODEC_LOGE("ffmpeg adapter start error, callback not initlized .");
|
||||
AVCODEC_LOGE("adapter start error, callback not initlized .");
|
||||
return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
if (!audioCodec) {
|
||||
AVCODEC_LOGE("ffmpeg adapter start error, audio codec not initlized .");
|
||||
AVCODEC_LOGE("adapter start error, audio codec not initlized .");
|
||||
return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
|
@ -40,9 +40,6 @@ AudioFfmpegDecoderPlugin::~AudioFfmpegDecoderPlugin()
|
||||
|
||||
int32_t AudioFfmpegDecoderPlugin::ProcessSendData(const std::shared_ptr<AudioBufferInfo> &inputBuffer)
|
||||
{
|
||||
AVCodecTrace trace(std::string(__FUNCTION__));
|
||||
AVCODEC_LOGD("ffmpeg Plugin ProcessSendData enter");
|
||||
AVCODEC_LOGD("Plugin ProcessSendData enter");
|
||||
int32_t ret = AVCodecServiceErrCode::AVCS_ERR_OK;
|
||||
{
|
||||
std::unique_lock lock(avMutext_);
|
||||
@ -64,9 +61,6 @@ std::string AVStrError(int errnum)
|
||||
|
||||
int32_t AudioFfmpegDecoderPlugin::SendBuffer(const std::shared_ptr<AudioBufferInfo> &inputBuffer)
|
||||
{
|
||||
AVCodecTrace trace(std::string(__FUNCTION__));
|
||||
AVCODEC_LOGD("ffmpeg Plugin SendBuffer enter");
|
||||
AVCODEC_LOGD("Plugin SendBuffer enter");
|
||||
if (!inputBuffer) {
|
||||
AVCODEC_LOGE("inputBuffer is nullptr");
|
||||
return AVCodecServiceErrCode::AVCS_ERR_INVALID_VAL;
|
||||
@ -101,7 +95,6 @@ int32_t AudioFfmpegDecoderPlugin::SendBuffer(const std::shared_ptr<AudioBufferIn
|
||||
|
||||
int32_t AudioFfmpegDecoderPlugin::ProcessRecieveData(std::shared_ptr<AudioBufferInfo> &outBuffer)
|
||||
{
|
||||
AVCodecTrace trace(std::string(__FUNCTION__));
|
||||
if (!outBuffer) {
|
||||
AVCODEC_LOGE("outBuffer is nullptr");
|
||||
return AVCodecServiceErrCode::AVCS_ERR_INVALID_VAL;
|
||||
@ -120,8 +113,6 @@ int32_t AudioFfmpegDecoderPlugin::ProcessRecieveData(std::shared_ptr<AudioBuffer
|
||||
|
||||
int32_t AudioFfmpegDecoderPlugin::ReceiveBuffer(std::shared_ptr<AudioBufferInfo> &outBuffer)
|
||||
{
|
||||
AVCodecTrace trace(std::string(__FUNCTION__));
|
||||
AVCODEC_LOGD("Plugin receiveBuffer enter");
|
||||
auto ret = avcodec_receive_frame(avCodecContext_.get(), cachedFrame_.get());
|
||||
int32_t status;
|
||||
if (ret >= 0) {
|
||||
@ -165,8 +156,6 @@ int32_t AudioFfmpegDecoderPlugin::ReceiveBuffer(std::shared_ptr<AudioBufferInfo>
|
||||
|
||||
int32_t AudioFfmpegDecoderPlugin::ReceiveFrameSucc(std::shared_ptr<AudioBufferInfo> &outBuffer)
|
||||
{
|
||||
AVCodecTrace trace(std::string(__FUNCTION__));
|
||||
AVCODEC_LOGD("Plugin ReceiveFrameSucc enter");
|
||||
int32_t channels = cachedFrame_->channels;
|
||||
int32_t samples = cachedFrame_->nb_samples;
|
||||
auto sampleFormat = static_cast<AVSampleFormat>(cachedFrame_->format);
|
||||
@ -209,19 +198,15 @@ int32_t AudioFfmpegDecoderPlugin::Release()
|
||||
|
||||
int32_t AudioFfmpegDecoderPlugin::Flush()
|
||||
{
|
||||
AVCodecTrace trace(std::string(__FUNCTION__));
|
||||
std::unique_lock lock(avMutext_);
|
||||
if (avCodecContext_ != nullptr) {
|
||||
avcodec_flush_buffers(avCodecContext_.get());
|
||||
}
|
||||
AVCODEC_LOGD("Flush exit.");
|
||||
return AVCodecServiceErrCode::AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AudioFfmpegDecoderPlugin::AllocateContext(const std::string &name)
|
||||
{
|
||||
AVCodecTrace trace(std::string(__FUNCTION__));
|
||||
AVCODEC_LOGD("Plugin AllocateContext enter");
|
||||
{
|
||||
std::unique_lock lock(avMutext_);
|
||||
avCodec_ = std::shared_ptr<AVCodec>(const_cast<AVCodec *>(avcodec_find_decoder_by_name(name.c_str())),
|
||||
@ -229,6 +214,7 @@ int32_t AudioFfmpegDecoderPlugin::AllocateContext(const std::string &name)
|
||||
cachedFrame_ = std::shared_ptr<AVFrame>(av_frame_alloc(), [](AVFrame *fp) { av_frame_free(&fp); });
|
||||
}
|
||||
if (avCodec_ == nullptr) {
|
||||
AVCODEC_LOGD("AllocateContext fail,parameter avcodec is nullptr.");
|
||||
return AVCodecServiceErrCode::AVCS_ERR_UNSUPPORT_PROTOCOL_TYPE;
|
||||
}
|
||||
|
||||
@ -248,7 +234,6 @@ int32_t AudioFfmpegDecoderPlugin::AllocateContext(const std::string &name)
|
||||
|
||||
int32_t AudioFfmpegDecoderPlugin::InitContext(const Format &format)
|
||||
{
|
||||
AVCODEC_LOGD("Plugin InitContext enter");
|
||||
format.GetIntValue(CHANNEL_COUNT_KEY, avCodecContext_->channels);
|
||||
format.GetIntValue(SAMPLE_RATE_KEY, avCodecContext_->sample_rate);
|
||||
format.GetLongValue(BITS_RATE_KEY, avCodecContext_->bit_rate);
|
||||
@ -264,8 +249,6 @@ int32_t AudioFfmpegDecoderPlugin::InitContext(const Format &format)
|
||||
|
||||
int32_t AudioFfmpegDecoderPlugin::OpenContext()
|
||||
{
|
||||
AVCodecTrace trace(std::string(__FUNCTION__));
|
||||
AVCODEC_LOGD("Plugin OpenContext enter");
|
||||
avPacket_ = std::shared_ptr<AVPacket>(av_packet_alloc(), [](AVPacket *ptr) { av_packet_free(&ptr); });
|
||||
{
|
||||
std::unique_lock lock(avMutext_);
|
||||
@ -300,7 +283,6 @@ std::shared_ptr<AVFrame> AudioFfmpegDecoderPlugin::GetCodecCacheFrame() const no
|
||||
|
||||
int32_t AudioFfmpegDecoderPlugin::CloseCtxLocked()
|
||||
{
|
||||
AVCodecTrace trace(std::string(__FUNCTION__));
|
||||
if (avCodecContext_ != nullptr) {
|
||||
auto res = avcodec_close(avCodecContext_.get());
|
||||
if (res != 0) {
|
||||
|
@ -37,12 +37,10 @@ int32_t AudioFFMpegMp3DecoderPlugin::init(const Format &format)
|
||||
return checkresult;
|
||||
}
|
||||
if (ret != AVCodecServiceErrCode::AVCS_ERR_OK) {
|
||||
// std::cout << "init 1 OH error:" << ret << "\n";
|
||||
return ret;
|
||||
}
|
||||
ret = basePlugin->InitContext(format);
|
||||
if (ret != AVCodecServiceErrCode::AVCS_ERR_OK) {
|
||||
// std::cout << "init 2 OH error:" << ret << "\n";
|
||||
return ret;
|
||||
}
|
||||
return basePlugin->OpenContext();
|
||||
@ -77,14 +75,12 @@ uint32_t AudioFFMpegMp3DecoderPlugin::getInputBufferSize() const
|
||||
{
|
||||
|
||||
uint32_t size = int(bit_rate / 150);
|
||||
// printf("in size %d \n", size);
|
||||
return size;
|
||||
}
|
||||
|
||||
uint32_t AudioFFMpegMp3DecoderPlugin::getOutputBufferSize() const
|
||||
{
|
||||
uint32_t size = (int(sample_rate / 31) + 128) * channels * sizeof(short);
|
||||
// printf("out size %d %d\n", size, sample_rate);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -1,29 +1,18 @@
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/multimedia/av_codec/config.gni")
|
||||
|
||||
AV_CODEC_ROOT_DIR = "//foundation/multimedia/av_codec"
|
||||
|
||||
config("av_codec_engine_common_config"){
|
||||
|
||||
}
|
||||
ohos_shared_library("av_codec_engine_common"){
|
||||
install_enable = true
|
||||
|
||||
ohos_static_library("av_codec_engine_common"){
|
||||
include_dirs=[
|
||||
"//base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/common/include",
|
||||
"$AV_CODEC_ROOT_DIR/services/utils/include",
|
||||
"$AV_CODEC_ROOT_DIR/interfaces/inner_api/native",
|
||||
"$AV_CODEC_ROOT_DIR/services/dfx/include",
|
||||
"$av_codec_root_dir/services/engine/common/include",
|
||||
"$av_codec_root_dir/services/utils/include",
|
||||
"$av_codec_root_dir/interfaces/inner_api/native",
|
||||
"$av_codec_root_dir/services/dfx/include",
|
||||
]
|
||||
|
||||
sources=[
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/common/share_memory.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
":av_codec_engine_common_config"
|
||||
"$av_codec_root_dir/services/engine/common/share_memory.cpp",
|
||||
]
|
||||
|
||||
public_deps= [
|
||||
|
Loading…
Reference in New Issue
Block a user