From 4aeb36d899864a5ad90fd6eda85b041ea0b743b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 12:21:29 +0000 Subject: [PATCH 01/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- interfaces/inner_api/native/audio_sink.h | 1 - interfaces/inner_api/native/subtitle_sink.h | 1 - interfaces/inner_api/native/surface_encoder_filter.h | 1 - interfaces/inner_api/native/video_capture_filter.h | 1 - services/media_engine/filters/audio_capture_filter.cpp | 8 ++++++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/interfaces/inner_api/native/audio_sink.h b/interfaces/inner_api/native/audio_sink.h index 60480de50..d5cde5571 100644 --- a/interfaces/inner_api/native/audio_sink.h +++ b/interfaces/inner_api/native/audio_sink.h @@ -24,7 +24,6 @@ #include "buffer/avbuffer_queue_define.h" #include "plugin/audio_sink_plugin.h" #include "filter/filter.h" -#include "common/log.h" #include "plugin/plugin_time.h" namespace OHOS { diff --git a/interfaces/inner_api/native/subtitle_sink.h b/interfaces/inner_api/native/subtitle_sink.h index f13c44743..7017755d5 100644 --- a/interfaces/inner_api/native/subtitle_sink.h +++ b/interfaces/inner_api/native/subtitle_sink.h @@ -23,7 +23,6 @@ #include "buffer/avbuffer_queue.h" #include "buffer/avbuffer_queue_define.h" #include "filter/filter.h" -#include "common/log.h" namespace OHOS { namespace Media { diff --git a/interfaces/inner_api/native/surface_encoder_filter.h b/interfaces/inner_api/native/surface_encoder_filter.h index b92e3b915..a408b49d5 100644 --- a/interfaces/inner_api/native/surface_encoder_filter.h +++ b/interfaces/inner_api/native/surface_encoder_filter.h @@ -26,7 +26,6 @@ #include "buffer/avbuffer_queue_producer.h" #include "buffer/avbuffer_queue_consumer.h" #include "common/status.h" -#include "common/log.h" namespace OHOS { namespace Media { diff --git a/interfaces/inner_api/native/video_capture_filter.h b/interfaces/inner_api/native/video_capture_filter.h index c79a684fe..80daf6516 100644 --- a/interfaces/inner_api/native/video_capture_filter.h +++ b/interfaces/inner_api/native/video_capture_filter.h @@ -26,7 +26,6 @@ #include "buffer/avbuffer_queue_producer.h" #include "buffer/avbuffer_queue_consumer.h" #include "common/status.h" -#include "common/log.h" #define TIME_NONE ((int64_t) -1) diff --git a/services/media_engine/filters/audio_capture_filter.cpp b/services/media_engine/filters/audio_capture_filter.cpp index d94fa49bb..84dc5167b 100644 --- a/services/media_engine/filters/audio_capture_filter.cpp +++ b/services/media_engine/filters/audio_capture_filter.cpp @@ -19,6 +19,10 @@ #include "source/audio_capture/audio_capture_module.h" #include "avcodec_trace.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Pipeline { @@ -261,7 +265,7 @@ void AudioCaptureFilter::SetParameter(const std::shared_ptr &meta) void AudioCaptureFilter::GetParameter(std::shared_ptr &meta) { MEDIA_LOG_I("GetParameter"); - MediaAVCodec::AVCodecTrace trace("AudioCaptureFilter::SetParameter"); + MediaAVCodec::AVCodecTrace trace("AudioCaptureFilter::GetParameter"); audioCaptureModule_->GetParameter(meta); } @@ -369,7 +373,7 @@ int32_t AudioCaptureFilter::GetMaxAmplitude() { MEDIA_LOG_I("GetMaxAmplitude"); if (audioCaptureModule_ == nullptr) { - MEDIA_LOG_E("audioCaptureModule_ is nullptr, cannot get audio capturer change info "); + MEDIA_LOG_E("audioCaptureModule_ is nullptr, cannot get audio capturer change info"); return (int32_t)Status::ERROR_INVALID_OPERATION; } return audioCaptureModule_->GetMaxAmplitude(); -- Gitee From 4d97cf9e8c39abd83e58fdc7eb98bc37d6179286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:31:17 +0000 Subject: [PATCH 02/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- .../filters/audio_sink_filter.cpp | 33 +++++-------------- .../media_engine/modules/sink/audio_sink.cpp | 4 +++ .../plugins/sink/audio_server_sink_plugin.cpp | 1 + .../http_source/base64/base64_utils.cpp | 4 +++ .../media_sink_test/audio_sink_test.cpp | 4 +++ 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/services/media_engine/filters/audio_sink_filter.cpp b/services/media_engine/filters/audio_sink_filter.cpp index 639efc3d2..7d72d8d30 100644 --- a/services/media_engine/filters/audio_sink_filter.cpp +++ b/services/media_engine/filters/audio_sink_filter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,6 +23,10 @@ #include "media_core.h" #include "parameters.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Pipeline { @@ -116,12 +120,12 @@ Status AudioSinkFilter::DoStart() Status AudioSinkFilter::DoPause() { MEDIA_LOG_I("audio sink filter pause start"); - if (state_ == FilterState::PAUSED) { + if (state_ == FilterState::PAUSED || state_ == FilterState::STOPPED) { return Status::OK; } // only worked when state is working if (state_ != FilterState::READY && state_ != FilterState::RUNNING) { - MEDIA_LOG_W("audio sink cannot pause when not working."); + MEDIA_LOG_W("audio sink cannot pause when not working"); return Status::ERROR_INVALID_OPERATION; } state_ = FilterState::PAUSED; @@ -133,11 +137,8 @@ Status AudioSinkFilter::DoPause() Status AudioSinkFilter::DoResume() { MEDIA_LOG_I("audio sink filter resume"); - if (state_ == FilterState::RUNNING) { - return Status::OK; - } // only worked when state is paused - if (state_ == FilterState::PAUSED || state_ == FilterState::RUNNING) { + if (state_ == FilterState::PAUSED) { forceUpdateTimeAnchorNextTime_ = true; state_ = FilterState::RUNNING; if (frameCnt_ > 0) { @@ -150,11 +151,6 @@ Status AudioSinkFilter::DoResume() Status AudioSinkFilter::DoFlush() { - // only worked when state is working - if (state_ != FilterState::PAUSED && state_ != FilterState::STOPPED) { - MEDIA_LOG_W("audio sink cannot flush when not paused or stopped"); - return Status::ERROR_INVALID_OPERATION; - } MEDIA_LOG_I("audio sink flush start"); if (audioSink_ != nullptr) { audioSink_->Flush(); @@ -165,9 +161,6 @@ Status AudioSinkFilter::DoFlush() Status AudioSinkFilter::DoStop() { - if (state_ == FilterState::STOPPED) { - return Status::OK; - } MEDIA_LOG_I("audio sink stop start"); if (audioSink_ != nullptr) { audioSink_->Stop(); @@ -181,10 +174,9 @@ Status AudioSinkFilter::DoRelease() { return audioSink_->Release(); } - Status AudioSinkFilter::DoProcessInputBuffer(int recvArg, bool dropFrame) { - audioSink_->DrainOutputBuffer(); + audioSink_->DrainOutputBuffer(dropFrame); return Status::OK; } @@ -279,13 +271,6 @@ Status AudioSinkFilter::SetIsTransitent(bool isTransitent) return audioSink_->SetIsTransitent(isTransitent); } -Status AudioSinkFilter::ChangeTrack(std::shared_ptr& meta) -{ - MEDIA_LOG_I("AudioSinkFilter::ChangeTrack in"); - FALSE_RETURN_V(audioSink_ != nullptr, Status::ERROR_INVALID_STATE); - return audioSink_->ChangeTrack(meta, eventReceiver_); -} - Status AudioSinkFilter::OnUpdated(StreamType inType, const std::shared_ptr& meta, const std::shared_ptr& callback) { diff --git a/services/media_engine/modules/sink/audio_sink.cpp b/services/media_engine/modules/sink/audio_sink.cpp index 7998e30cc..2c81c1d52 100644 --- a/services/media_engine/modules/sink/audio_sink.cpp +++ b/services/media_engine/modules/sink/audio_sink.cpp @@ -17,6 +17,10 @@ #include "syspara/parameters.h" #include "plugin/plugin_manager_v2.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { diff --git a/services/media_engine/plugins/sink/audio_server_sink_plugin.cpp b/services/media_engine/plugins/sink/audio_server_sink_plugin.cpp index 7c8599f4c..7080e3aa0 100644 --- a/services/media_engine/plugins/sink/audio_server_sink_plugin.cpp +++ b/services/media_engine/plugins/sink/audio_server_sink_plugin.cpp @@ -35,6 +35,7 @@ namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; using namespace OHOS::Media::Plugins; constexpr int TUPLE_SECOND_ITEM_INDEX = 2; constexpr int32_t DEFAULT_BUFFER_NUM = 8; diff --git a/services/media_engine/plugins/source/http_source/base64/base64_utils.cpp b/services/media_engine/plugins/source/http_source/base64/base64_utils.cpp index b09ae6703..e0f69955f 100644 --- a/services/media_engine/plugins/source/http_source/base64/base64_utils.cpp +++ b/services/media_engine/plugins/source/http_source/base64/base64_utils.cpp @@ -16,6 +16,10 @@ #include "base64_utils.h" #include "common/log.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_STREAM_SOURCE, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Plugins { diff --git a/test/unittest/media_sink_test/audio_sink_test.cpp b/test/unittest/media_sink_test/audio_sink_test.cpp index ebc50e250..9c0394b44 100644 --- a/test/unittest/media_sink_test/audio_sink_test.cpp +++ b/test/unittest/media_sink_test/audio_sink_test.cpp @@ -19,6 +19,10 @@ #include "filter/filter.h" #include "common/log.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + using namespace testing::ext; namespace OHOS { -- Gitee From a2740d947cdcecb4a4615513f05a98ef99dcca92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:31:25 +0000 Subject: [PATCH 03/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- .../filters/audio_data_source_filter.cpp | 8 ++++ .../filters/audio_decoder_filter.cpp | 37 +++++++------------ .../filters/audio_encoder_filter.cpp | 6 +++ .../modules/demuxer/base_stream_demuxer.cpp | 4 ++ .../audio_capture/audio_capture_module.cpp | 4 ++ 5 files changed, 36 insertions(+), 23 deletions(-) diff --git a/services/media_engine/filters/audio_data_source_filter.cpp b/services/media_engine/filters/audio_data_source_filter.cpp index f95f30b77..ad0748992 100644 --- a/services/media_engine/filters/audio_data_source_filter.cpp +++ b/services/media_engine/filters/audio_data_source_filter.cpp @@ -16,6 +16,10 @@ #include "audio_data_source_filter.h" #include "common/log.h" #include "filter/filter_factory.h" + +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} namespace OHOS { namespace Media { @@ -104,6 +108,7 @@ Status AudioDataSourceFilter::DoPrepare() Status AudioDataSourceFilter::DoStart() { MEDIA_LOG_I("AudioDataSourceFilter DoStart"); + nextFilter_->Start(); eos_ = false; if (taskPtr_) { taskPtr_->Start(); @@ -136,6 +141,9 @@ Status AudioDataSourceFilter::DoStop() if (taskPtr_) { taskPtr_->Stop(); } + if (nextFilter_) { + nextFilter_->Stop(); + } return Status::OK; } diff --git a/services/media_engine/filters/audio_decoder_filter.cpp b/services/media_engine/filters/audio_decoder_filter.cpp index d59aca4cb..6d7d7c335 100644 --- a/services/media_engine/filters/audio_decoder_filter.cpp +++ b/services/media_engine/filters/audio_decoder_filter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,9 +16,14 @@ #include "audio_decoder_filter.h" #include "filter/filter_factory.h" +#include "common/log.h" #include "common/media_core.h" #include "avcodec_sysevent.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Pipeline { @@ -113,23 +118,24 @@ void AudioDecoderFilter::Init(const std::shared_ptr &receiver, Status AudioDecoderFilter::DoPrepare() { MEDIA_LOG_I("AudioDecoderFilter::Prepare."); + Status ret = Status::OK; switch (filterType_) { case FilterType::FILTERTYPE_AENC: MEDIA_LOG_I("AudioDecoderFilter::FILTERTYPE_AENC."); - filterCallback_->OnCallback(shared_from_this(), FilterCallBackCommand::NEXT_FILTER_NEEDED, + ret = filterCallback_->OnCallback(shared_from_this(), FilterCallBackCommand::NEXT_FILTER_NEEDED, StreamType::STREAMTYPE_ENCODED_AUDIO); break; case FilterType::FILTERTYPE_ADEC: - filterCallback_->OnCallback(shared_from_this(), FilterCallBackCommand::NEXT_FILTER_NEEDED, + ret = filterCallback_->OnCallback(shared_from_this(), FilterCallBackCommand::NEXT_FILTER_NEEDED, StreamType::STREAMTYPE_RAW_AUDIO); break; default: break; } - return Status::OK; + return ret; } -Status AudioDecoderFilter::PrepareFrame(bool renderFirstFrame) +Status AudioDecoderFilter::DoPrepareFrame(bool renderFirstFrame) { MEDIA_LOG_I("AudioDecoderFilter::PrepareFrame."); (void)renderFirstFrame; @@ -222,21 +228,6 @@ Status AudioDecoderFilter::UnLinkNext(const std::shared_ptr &nextFilter, return Status::OK; } -Status AudioDecoderFilter::ChangePlugin(std::shared_ptr meta) -{ - MEDIA_LOG_I("AudioDecoderFilter::ChangePlugin."); - std::string mime; - meta_ = meta; - bool mimeGetRes = meta_->GetData(Tag::MIME_TYPE, mime); - if (!mimeGetRes && eventReceiver_ != nullptr) { - MEDIA_LOG_I("AudioDecoderFilter cannot get mime"); - eventReceiver_->OnEvent({"audioDecoder", EventType::EVENT_ERROR, MSERR_UNSUPPORT_AUD_DEC_TYPE}); - return Status::ERROR_UNSUPPORTED_FORMAT; - } - meta->SetData(Tag::AUDIO_SAMPLE_FORMAT, Plugins::SAMPLE_S16LE); - return mediaCodec_->ChangePlugin(mime, false, meta); -} - FilterType AudioDecoderFilter::GetFilterType() { return filterType_; @@ -249,7 +240,7 @@ Status AudioDecoderFilter::OnLinked(StreamType inType, const std::shared_ptrGetData(Tag::MIME_TYPE, mime); + bool mimeGetRes = meta_->Get(mime); if (!mimeGetRes && eventReceiver_ != nullptr) { MEDIA_LOG_I("AudioDecoderFilter cannot get mime"); eventReceiver_->OnEvent({"audioDecoder", EventType::EVENT_ERROR, MSERR_UNSUPPORT_AUD_DEC_TYPE}); @@ -330,7 +321,7 @@ void AudioDecoderFilter::OnLinkedResult(const sptr &outpu sptr listener = new CodecBrokerListener(shared_from_this()); inputBufferQueueProducer_->SetBufferFilledListener(listener); FALSE_RETURN(onLinkedResultCallback_ != nullptr); - onLinkedResultCallback_->OnLinkedResult(inputBufferQueueProducer_, meta_); + onLinkedResultCallback_->OnLinkedResult(inputBufferQueueProducer_, meta); } void AudioDecoderFilter::OnUpdatedResult(std::shared_ptr &meta) @@ -367,4 +358,4 @@ void AudioDecoderFilter::SetCallerInfo(uint64_t instanceId, const std::string& a } } // namespace Pipeline } // namespace MEDIA -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/media_engine/filters/audio_encoder_filter.cpp b/services/media_engine/filters/audio_encoder_filter.cpp index 2048373fb..5894e74ce 100644 --- a/services/media_engine/filters/audio_encoder_filter.cpp +++ b/services/media_engine/filters/audio_encoder_filter.cpp @@ -14,10 +14,16 @@ */ #include "audio_encoder_filter.h" + +#include "common/log.h" #include "filter/filter_factory.h" #include "media_codec/media_codec.h" #include "avcodec_sysevent.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Pipeline { diff --git a/services/media_engine/modules/demuxer/base_stream_demuxer.cpp b/services/media_engine/modules/demuxer/base_stream_demuxer.cpp index 14ce096a7..46683eb92 100644 --- a/services/media_engine/modules/demuxer/base_stream_demuxer.cpp +++ b/services/media_engine/modules/demuxer/base_stream_demuxer.cpp @@ -35,6 +35,10 @@ #include "plugin/plugin_info.h" #include "plugin/plugin_time.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { diff --git a/services/media_engine/modules/source/audio_capture/audio_capture_module.cpp b/services/media_engine/modules/source/audio_capture/audio_capture_module.cpp index f8d573067..85bfb2d9e 100644 --- a/services/media_engine/modules/source/audio_capture/audio_capture_module.cpp +++ b/services/media_engine/modules/source/audio_capture/audio_capture_module.cpp @@ -20,6 +20,10 @@ #include "audio_capturer.h" #include "avcodec_sysevent.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace AudioCaptureModule { -- Gitee From 3e7edefcfa9a8fca05c97459c93192e10fdf500a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:31:33 +0000 Subject: [PATCH 04/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- .../media_engine/filters/codec_capability_adapter.cpp | 4 ++++ .../plugins/ffmpeg_adapter/demuxer/block_queue.h | 11 +++++++---- .../ffmpeg_adapter/demuxer/block_queue_pool.cpp | 3 +++ .../http_source/dash/mpd_parser/dash_mpd_parser.cpp | 4 ++++ .../dash/mpd_parser/dash_mpd_prefer_audio_util.cpp | 4 ++++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/services/media_engine/filters/codec_capability_adapter.cpp b/services/media_engine/filters/codec_capability_adapter.cpp index d803d8f0d..e01c02373 100644 --- a/services/media_engine/filters/codec_capability_adapter.cpp +++ b/services/media_engine/filters/codec_capability_adapter.cpp @@ -16,6 +16,10 @@ #include "common/log.h" #include "codec_capability_adapter.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { diff --git a/services/media_engine/plugins/ffmpeg_adapter/demuxer/block_queue.h b/services/media_engine/plugins/ffmpeg_adapter/demuxer/block_queue.h index 5b525ddc5..b77e3b82f 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/demuxer/block_queue.h +++ b/services/media_engine/plugins/ffmpeg_adapter/demuxer/block_queue.h @@ -19,7 +19,6 @@ #include #include #include -#include "common/log.h" namespace OHOS { namespace Media { @@ -81,7 +80,8 @@ public: if (que_.empty() && !isActive_) { MEDIA_LOG_D("block queue " PUBLIC_LOG_S " is inactive for Pop.", name_.c_str()); return {}; - } else if (que_.empty() && isActive_) { + } + (que_.empty() && isActive_) { MEDIA_LOG_D("block queue " PUBLIC_LOG_S " is empty, please waiting for Push.", name_.c_str()); condEmpty_.wait(lock, [this] { return !isActive_ || !que_.empty(); }); } @@ -104,7 +104,8 @@ public: if (que_.empty() && !isActive_) { MEDIA_LOG_D("block queue " PUBLIC_LOG_S " is inactive for Front.", name_.c_str()); return {}; - } else if (que_.empty() && isActive_) { + } + (que_.empty() && isActive_) { MEDIA_LOG_D("block queue " PUBLIC_LOG_S " is empty, please waiting for Push.", name_.c_str()); condEmpty_.wait(lock, [this] { return !isActive_ || !que_.empty(); }); } @@ -126,7 +127,8 @@ public: if (que_.empty() && !isActive_) { MEDIA_LOG_D("block queue " PUBLIC_LOG_S " is inactive for Back.", name_.c_str()); return {}; - } else if (que_.empty() && isActive_) { + } + (que_.empty() && isActive_) { MEDIA_LOG_D("block queue " PUBLIC_LOG_S " is empty, please waiting for Push.", name_.c_str()); condEmpty_.wait(lock, [this] { return !isActive_ || !que_.empty(); }); } @@ -161,6 +163,7 @@ public: } private: + static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_ONLY_PRERELEASE, LOG_DOMAIN_FOUNDATION, "HiStreamer" }; void ClearUnprotected() { if (que_.empty()) { diff --git a/services/media_engine/plugins/ffmpeg_adapter/demuxer/block_queue_pool.cpp b/services/media_engine/plugins/ffmpeg_adapter/demuxer/block_queue_pool.cpp index 5c9be52c6..bdb8a6578 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/demuxer/block_queue_pool.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/demuxer/block_queue_pool.cpp @@ -18,6 +18,9 @@ #include "common/log.h" #include "block_queue_pool.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_DEMUXER, "HiStreamer" }; +} namespace OHOS { namespace Media { diff --git a/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_parser.cpp b/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_parser.cpp index 7c02ffea1..56c1932e4 100644 --- a/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_parser.cpp +++ b/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_parser.cpp @@ -21,6 +21,10 @@ #include "dash_mpd_util.h" #include "utils/time_utils.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_STREAM_SOURCE, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Plugins { diff --git a/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_prefer_audio_util.cpp b/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_prefer_audio_util.cpp index 5843ebceb..bbac9edb6 100644 --- a/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_prefer_audio_util.cpp +++ b/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_prefer_audio_util.cpp @@ -19,6 +19,10 @@ #include "dash_mpd_def.h" #include "common/log.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_STREAM_SOURCE, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Plugins { -- Gitee From 4966ba23a9722b898c79fa267aa7a386b844413e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:31:39 +0000 Subject: [PATCH 05/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- services/media_engine/modules/muxer/data_sink_fd.cpp | 4 ++++ services/media_engine/modules/muxer/data_sink_file.cpp | 4 ++++ .../media_engine/plugins/source/data_stream_source_plugin.cpp | 4 ++++ .../source/http_source/dash/dash_segment_downloader.cpp | 1 - .../source/http_source/dash/mpd_parser/dash_mpd_util.cpp | 4 ++++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/services/media_engine/modules/muxer/data_sink_fd.cpp b/services/media_engine/modules/muxer/data_sink_fd.cpp index 97642a503..8e8613e3a 100644 --- a/services/media_engine/modules/muxer/data_sink_fd.cpp +++ b/services/media_engine/modules/muxer/data_sink_fd.cpp @@ -20,6 +20,10 @@ #include #include "common/log.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_MUXER, "HiStreamer" }; +} + namespace OHOS { namespace Media { DataSinkFd::DataSinkFd(int32_t fd) : fd_(dup(fd)), pos_(0), end_(-1) diff --git a/services/media_engine/modules/muxer/data_sink_file.cpp b/services/media_engine/modules/muxer/data_sink_file.cpp index 95ccabef8..94a4a3d29 100644 --- a/services/media_engine/modules/muxer/data_sink_file.cpp +++ b/services/media_engine/modules/muxer/data_sink_file.cpp @@ -19,6 +19,10 @@ #include #include "common/log.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_MUXER, "HiStreamer" }; +} + namespace OHOS { namespace Media { DataSinkFile::DataSinkFile(FILE *file) : file_(file), pos_(0), end_(-1), isCanRead_(true) diff --git a/services/media_engine/plugins/source/data_stream_source_plugin.cpp b/services/media_engine/plugins/source/data_stream_source_plugin.cpp index 34b187306..c9e4fcf28 100644 --- a/services/media_engine/plugins/source/data_stream_source_plugin.cpp +++ b/services/media_engine/plugins/source/data_stream_source_plugin.cpp @@ -21,6 +21,10 @@ #include "common/media_core.h" #include "osal/utils/util.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Plugin { diff --git a/services/media_engine/plugins/source/http_source/dash/dash_segment_downloader.cpp b/services/media_engine/plugins/source/http_source/dash/dash_segment_downloader.cpp index 49f7c11f0..6036115b8 100644 --- a/services/media_engine/plugins/source/http_source/dash/dash_segment_downloader.cpp +++ b/services/media_engine/plugins/source/http_source/dash/dash_segment_downloader.cpp @@ -18,7 +18,6 @@ #include #include #include "dash_mpd_util.h" -#include "common/log.h" namespace OHOS { namespace Media { diff --git a/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_util.cpp b/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_util.cpp index bd61d01c5..611a31b50 100644 --- a/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_util.cpp +++ b/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_util.cpp @@ -20,6 +20,10 @@ #include "dash_mpd_util.h" #include "utils/time_utils.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_STREAM_SOURCE, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Plugins { -- Gitee From 14066fe055a277d110dc3af5d7c2daa381fcdd03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:31:51 +0000 Subject: [PATCH 06/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- services/media_engine/filters/decoder_surface_filter.cpp | 4 ++++ services/media_engine/filters/demuxer_filter.cpp | 3 +++ .../media_engine/modules/demuxer/demuxer_plugin_manager.cpp | 4 ++++ .../plugins/source/http_source/download/downloader.h | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/services/media_engine/filters/decoder_surface_filter.cpp b/services/media_engine/filters/decoder_surface_filter.cpp index 2b28bd0f6..3568d1439 100644 --- a/services/media_engine/filters/decoder_surface_filter.cpp +++ b/services/media_engine/filters/decoder_surface_filter.cpp @@ -29,6 +29,10 @@ #include "osal/utils/util.h" #include "parameters.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Pipeline { diff --git a/services/media_engine/filters/demuxer_filter.cpp b/services/media_engine/filters/demuxer_filter.cpp index 076ba0760..6fe845f84 100644 --- a/services/media_engine/filters/demuxer_filter.cpp +++ b/services/media_engine/filters/demuxer_filter.cpp @@ -26,6 +26,9 @@ #include "media_types.h" #include "avcodec_sysevent.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} namespace OHOS { namespace Media { diff --git a/services/media_engine/modules/demuxer/demuxer_plugin_manager.cpp b/services/media_engine/modules/demuxer/demuxer_plugin_manager.cpp index c688a5099..c0949e1c8 100644 --- a/services/media_engine/modules/demuxer/demuxer_plugin_manager.cpp +++ b/services/media_engine/modules/demuxer/demuxer_plugin_manager.cpp @@ -38,6 +38,10 @@ #include "base_stream_demuxer.h" #include "media_demuxer.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { diff --git a/services/media_engine/plugins/source/http_source/download/downloader.h b/services/media_engine/plugins/source/http_source/download/downloader.h index 89efa7bd7..3a6864ec5 100644 --- a/services/media_engine/plugins/source/http_source/download/downloader.h +++ b/services/media_engine/plugins/source/http_source/download/downloader.h @@ -27,6 +27,10 @@ #include #include "securec.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_STREAM_SOURCE, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Plugins { -- Gitee From 2b3956574028df70f5fbe72f7bfb6c3cc1e431e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:32:04 +0000 Subject: [PATCH 07/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- .../audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp | 2 ++ .../plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp | 4 ++++ .../plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp | 1 + 3 files changed, 7 insertions(+) diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp index b9209e47c..656946e16 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp @@ -29,6 +29,8 @@ using namespace OHOS::Media; using namespace OHOS::Media::Plugins; using namespace Ffmpeg; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_AUDIO, "FFmpegEncoderPlugin" }; + namespace { constexpr int32_t INPUT_BUFFER_SIZE_DEFAULT = 4 * 1024 * 8; constexpr int32_t OUTPUT_BUFFER_SIZE_DEFAULT = 8192; diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp index a4dace18f..41ae9a1cb 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp @@ -16,6 +16,10 @@ #include "common/log.h" #include "securec.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_AUDIO, "FFmpegEncoderPlugin"}; +} + namespace OHOS { namespace Media { namespace Plugins { diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp index 47b8ec8cf..7f6f3c82d 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp @@ -21,6 +21,7 @@ #include "ffmpeg_converter.h" namespace { constexpr int US_PER_SECOND = 1000000; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "FFmpegEncoderPlugin"}; } namespace OHOS { namespace Media { -- Gitee From 29adf0b0f32d3ea00de7b6741c1c485cc09d8a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:32:29 +0000 Subject: [PATCH 08/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- .../plugins/ffmpeg_adapter/demuxer/ffmpeg_demuxer_plugin.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/media_engine/plugins/ffmpeg_adapter/demuxer/ffmpeg_demuxer_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/demuxer/ffmpeg_demuxer_plugin.cpp index eae65988b..86fd0a285 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/demuxer/ffmpeg_demuxer_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/demuxer/ffmpeg_demuxer_plugin.cpp @@ -35,6 +35,10 @@ #include "ffmpeg_demuxer_plugin.h" #include "meta/format.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_DEMUXER, "HiStreamer" }; +} + #define AV_CODEC_TIME_BASE (static_cast(1)) #define AV_CODEC_NSECOND AV_CODEC_TIME_BASE #define AV_CODEC_USECOND (static_cast(1000) * AV_CODEC_NSECOND) -- Gitee From bc6e5d00e877b5a6174896ea25eded370dc391d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:32:33 +0000 Subject: [PATCH 09/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- .../plugins/ffmpeg_adapter/demuxer/ffmpeg_format_helper.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/media_engine/plugins/ffmpeg_adapter/demuxer/ffmpeg_format_helper.cpp b/services/media_engine/plugins/ffmpeg_adapter/demuxer/ffmpeg_format_helper.cpp index 1bbd15e5d..0818671b7 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/demuxer/ffmpeg_format_helper.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/demuxer/ffmpeg_format_helper.cpp @@ -40,6 +40,10 @@ extern "C" { #define TERMINAL_PROVIDE_CODE (static_cast(4)) #define TERMINAL_PROVIDE_ORIENTED_CODE (static_cast(5)) +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Plugins { -- Gitee From 946eec51642781ec345dacaab85bda8c10af3365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:32:39 +0000 Subject: [PATCH 10/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- services/media_engine/modules/demuxer/frame_detector.cpp | 2 -- .../plugins/ffmpeg_adapter/common/ffmpeg_utils.cpp | 4 ++++ .../media_engine/plugins/source/file_fd_source_plugin.cpp | 4 ++++ services/media_engine/plugins/source/file_source_plugin.cpp | 4 ++++ .../plugins/source/http_source/download/http_curl_client.cpp | 5 ++++- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/services/media_engine/modules/demuxer/frame_detector.cpp b/services/media_engine/modules/demuxer/frame_detector.cpp index 2c297b932..cb7d289f8 100644 --- a/services/media_engine/modules/demuxer/frame_detector.cpp +++ b/services/media_engine/modules/demuxer/frame_detector.cpp @@ -18,8 +18,6 @@ #include #include -#include "common/log.h" - namespace OHOS { namespace Media { using namespace std; diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_utils.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_utils.cpp index 4615ae612..386298597 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_utils.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_utils.cpp @@ -23,6 +23,10 @@ #include "meta/audio_types.h" #include "ffmpeg_utils.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + #define AV_CODEC_TIME_BASE (static_cast(1)) #define AV_CODEC_NSECOND AV_CODEC_TIME_BASE #define AV_CODEC_USECOND (static_cast(1000) * AV_CODEC_NSECOND) diff --git a/services/media_engine/plugins/source/file_fd_source_plugin.cpp b/services/media_engine/plugins/source/file_fd_source_plugin.cpp index 19181185d..0b3c5842a 100644 --- a/services/media_engine/plugins/source/file_fd_source_plugin.cpp +++ b/services/media_engine/plugins/source/file_fd_source_plugin.cpp @@ -31,6 +31,10 @@ #include "file_fd_source_plugin.h" #include "common/media_core.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Plugins { diff --git a/services/media_engine/plugins/source/file_source_plugin.cpp b/services/media_engine/plugins/source/file_source_plugin.cpp index 1b9748fcd..62d717f6b 100644 --- a/services/media_engine/plugins/source/file_source_plugin.cpp +++ b/services/media_engine/plugins/source/file_source_plugin.cpp @@ -19,6 +19,10 @@ #include #include "common/log.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Plugins { diff --git a/services/media_engine/plugins/source/http_source/download/http_curl_client.cpp b/services/media_engine/plugins/source/http_source/download/http_curl_client.cpp index 70fe35461..6e0b197a5 100644 --- a/services/media_engine/plugins/source/http_source/download/http_curl_client.cpp +++ b/services/media_engine/plugins/source/http_source/download/http_curl_client.cpp @@ -18,11 +18,14 @@ #include #include #include -#include "common/log.h" #include "osal/task/autolock.h" #include "securec.h" #include "net_conn_client.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_STREAM_SOURCE, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Plugins { -- Gitee From 174078e1be9a57d7bc3f04f5655a130e0f68b318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:32:46 +0000 Subject: [PATCH 11/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- services/media_engine/modules/media_codec/media_codec.cpp | 1 + services/media_engine/modules/media_codec/media_codec.h | 1 - services/media_engine/plugins/source/http_source/hls/m3u8.cpp | 1 - .../plugins/source/http_source/utils/media_cached_buffer.cpp | 4 ++++ .../plugins/source/http_source/utils/media_cached_buffer.h | 2 -- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/services/media_engine/modules/media_codec/media_codec.cpp b/services/media_engine/modules/media_codec/media_codec.cpp index 927409ab9..fbd51347e 100644 --- a/services/media_engine/modules/media_codec/media_codec.cpp +++ b/services/media_engine/modules/media_codec/media_codec.cpp @@ -21,6 +21,7 @@ #include "osal/utils/dump_buffer.h" namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_MEDIA_CODEC, "HiStreamer" }; const std::string INPUT_BUFFER_QUEUE_NAME = "MediaCodecInputBufferQueue"; constexpr int32_t DEFAULT_BUFFER_NUM = 8; constexpr int32_t TIME_OUT_MS = 500; diff --git a/services/media_engine/modules/media_codec/media_codec.h b/services/media_engine/modules/media_codec/media_codec.h index 08601fbdb..05f3a3982 100644 --- a/services/media_engine/modules/media_codec/media_codec.h +++ b/services/media_engine/modules/media_codec/media_codec.h @@ -25,7 +25,6 @@ #include "buffer/avbuffer_queue_producer.h" #include "buffer/avbuffer_queue_consumer.h" #include "common/status.h" -#include "common/log.h" #include "plugin/plugin_event.h" #include "plugin/codec_plugin.h" #include "osal/task/mutex.h" diff --git a/services/media_engine/plugins/source/http_source/hls/m3u8.cpp b/services/media_engine/plugins/source/http_source/hls/m3u8.cpp index 2d1180988..557fbe1bd 100644 --- a/services/media_engine/plugins/source/http_source/hls/m3u8.cpp +++ b/services/media_engine/plugins/source/http_source/hls/m3u8.cpp @@ -17,7 +17,6 @@ #include #include #include -#include "common/log.h" #include "m3u8.h" namespace OHOS { diff --git a/services/media_engine/plugins/source/http_source/utils/media_cached_buffer.cpp b/services/media_engine/plugins/source/http_source/utils/media_cached_buffer.cpp index 73240d3fc..fcbac34e2 100644 --- a/services/media_engine/plugins/source/http_source/utils/media_cached_buffer.cpp +++ b/services/media_engine/plugins/source/http_source/utils/media_cached_buffer.cpp @@ -24,6 +24,10 @@ #include "avcodec_log.h" #include "avcodec_errors.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_STREAM_SOURCE, "HiStreamer" }; +} + namespace OHOS { namespace Media { diff --git a/services/media_engine/plugins/source/http_source/utils/media_cached_buffer.h b/services/media_engine/plugins/source/http_source/utils/media_cached_buffer.h index 97bd90c13..6a342ce62 100644 --- a/services/media_engine/plugins/source/http_source/utils/media_cached_buffer.h +++ b/services/media_engine/plugins/source/http_source/utils/media_cached_buffer.h @@ -22,8 +22,6 @@ #include #include -#include "common/log.h" - namespace OHOS { namespace Media { constexpr uint32_t CHUNK_SIZE = 16 * 1024; -- Gitee From 3520a6664f8ed9582569f94976c6eda408cf8564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:33:00 +0000 Subject: [PATCH 12/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- services/media_engine/modules/demuxer/media_demuxer.cpp | 1 + services/media_engine/modules/muxer/media_muxer.cpp | 4 ++++ .../plugins/source/http_source/media_downloader.h | 1 + 3 files changed, 6 insertions(+) diff --git a/services/media_engine/modules/demuxer/media_demuxer.cpp b/services/media_engine/modules/demuxer/media_demuxer.cpp index e8b241bbf..b8ee5a645 100755 --- a/services/media_engine/modules/demuxer/media_demuxer.cpp +++ b/services/media_engine/modules/demuxer/media_demuxer.cpp @@ -41,6 +41,7 @@ #include "demuxer_plugin_manager.h" namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_DEMUXER, "HiStreamer" }; const std::string DUMP_PARAM = "a"; const std::string DUMP_DEMUXER_AUDIO_FILE_NAME = "player_demuxer_audio_output.es"; const std::string DUMP_DEMUXER_VIDEO_FILE_NAME = "player_demuxer_video_output.es"; diff --git a/services/media_engine/modules/muxer/media_muxer.cpp b/services/media_engine/modules/muxer/media_muxer.cpp index 53d7b6582..bb3515f9b 100644 --- a/services/media_engine/modules/muxer/media_muxer.cpp +++ b/services/media_engine/modules/muxer/media_muxer.cpp @@ -30,6 +30,10 @@ #include "data_sink_fd.h" #include "data_sink_file.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_MUXER, "HiStreamer" }; +} + namespace { using namespace OHOS::Media; using namespace Plugins; diff --git a/services/media_engine/plugins/source/http_source/media_downloader.h b/services/media_engine/plugins/source/http_source/media_downloader.h index d127a1787..4b7f5b277 100644 --- a/services/media_engine/plugins/source/http_source/media_downloader.h +++ b/services/media_engine/plugins/source/http_source/media_downloader.h @@ -36,6 +36,7 @@ struct ReadDataInfo { class MediaDownloader { public: + static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_STREAM_SOURCE, "HiStreamer" }; virtual ~MediaDownloader() = default; virtual bool Open(const std::string& url, const std::map& httpHeader) = 0; virtual void Close(bool isAsync) = 0; -- Gitee From 293c5415a7f993de8d4473dff2c0747f767f741e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:33:05 +0000 Subject: [PATCH 13/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- services/media_engine/filters/muxer_filter.cpp | 1 + services/media_engine/modules/sink/media_sync_manager.cpp | 4 ++++ services/media_engine/modules/sink/media_synchronous_sink.cpp | 4 ++++ test/unittest/sa_avcodec_test/mock/include/mem_mgr_client.h | 1 - 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/services/media_engine/filters/muxer_filter.cpp b/services/media_engine/filters/muxer_filter.cpp index 363c9e816..8d0d7a13f 100644 --- a/services/media_engine/filters/muxer_filter.cpp +++ b/services/media_engine/filters/muxer_filter.cpp @@ -23,6 +23,7 @@ #include "avcodec_sysevent.h" namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; static const std::unordered_map FORMAT_TABLE = { {OHOS::Media::Plugins::OutputFormat::DEFAULT, OHOS::Media::Plugins::MimeType::MEDIA_MP4}, {OHOS::Media::Plugins::OutputFormat::MPEG_4, OHOS::Media::Plugins::MimeType::MEDIA_MP4}, diff --git a/services/media_engine/modules/sink/media_sync_manager.cpp b/services/media_engine/modules/sink/media_sync_manager.cpp index 6d57d2183..f4394dc01 100644 --- a/services/media_engine/modules/sink/media_sync_manager.cpp +++ b/services/media_engine/modules/sink/media_sync_manager.cpp @@ -22,6 +22,10 @@ #include "common/log.h" #include "osal/utils/steady_clock.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Pipeline { diff --git a/services/media_engine/modules/sink/media_synchronous_sink.cpp b/services/media_engine/modules/sink/media_synchronous_sink.cpp index 9f55c921e..2d666c44d 100644 --- a/services/media_engine/modules/sink/media_synchronous_sink.cpp +++ b/services/media_engine/modules/sink/media_synchronous_sink.cpp @@ -18,6 +18,10 @@ #include "common/log.h" #include "plugin/plugin_time.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Pipeline { diff --git a/test/unittest/sa_avcodec_test/mock/include/mem_mgr_client.h b/test/unittest/sa_avcodec_test/mock/include/mem_mgr_client.h index 448da4a42..bc4749642 100644 --- a/test/unittest/sa_avcodec_test/mock/include/mem_mgr_client.h +++ b/test/unittest/sa_avcodec_test/mock/include/mem_mgr_client.h @@ -20,7 +20,6 @@ #include #include #include "avcodec_errors.h" -#include "hilog/log.h" #include "ipc/av_codec_service_ipc_interface_code.h" #include "iremote_broker.h" #include "iremote_object.h" -- Gitee From 98d0525b9f4e2c721865f581c51c086ad6234cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:33:12 +0000 Subject: [PATCH 14/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- services/media_engine/modules/sink/subtitle_sink.cpp | 4 ++++ services/media_engine/modules/source/source.cpp | 4 ++++ .../plugins/ffmpeg_adapter/common/stream_parser_manager.cpp | 1 + .../source/http_source/dash/mpd_parser/sidx_box_parser.cpp | 4 ++++ .../plugins/source/http_source/hls/playlist_downloader.cpp | 3 +-- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/services/media_engine/modules/sink/subtitle_sink.cpp b/services/media_engine/modules/sink/subtitle_sink.cpp index 578d0f7e7..67d122054 100644 --- a/services/media_engine/modules/sink/subtitle_sink.cpp +++ b/services/media_engine/modules/sink/subtitle_sink.cpp @@ -17,6 +17,10 @@ #include "syspara/parameters.h" #include "meta/format.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace { diff --git a/services/media_engine/modules/source/source.cpp b/services/media_engine/modules/source/source.cpp index 91f11989d..6c0e94bf0 100644 --- a/services/media_engine/modules/source/source.cpp +++ b/services/media_engine/modules/source/source.cpp @@ -24,6 +24,10 @@ #include "plugin/plugin_manager_v2.h" #include "source.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { using namespace Plugins; diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/stream_parser_manager.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/stream_parser_manager.cpp index 97bcd70b8..42b1314b7 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/stream_parser_manager.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/stream_parser_manager.cpp @@ -21,6 +21,7 @@ namespace { const std::string HEVC_LIB_PATH = "libav_codec_hevc_parser.z.so"; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; } namespace OHOS { diff --git a/services/media_engine/plugins/source/http_source/dash/mpd_parser/sidx_box_parser.cpp b/services/media_engine/plugins/source/http_source/dash/mpd_parser/sidx_box_parser.cpp index f1a2a7c69..ce6bc9a09 100644 --- a/services/media_engine/plugins/source/http_source/dash/mpd_parser/sidx_box_parser.cpp +++ b/services/media_engine/plugins/source/http_source/dash/mpd_parser/sidx_box_parser.cpp @@ -18,6 +18,10 @@ #include "sidx_box_parser.h" #include "common/log.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_STREAM_SOURCE, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Plugins { diff --git a/services/media_engine/plugins/source/http_source/hls/playlist_downloader.cpp b/services/media_engine/plugins/source/http_source/hls/playlist_downloader.cpp index c667939fd..bbc6f1ace 100644 --- a/services/media_engine/plugins/source/http_source/hls/playlist_downloader.cpp +++ b/services/media_engine/plugins/source/http_source/hls/playlist_downloader.cpp @@ -99,9 +99,8 @@ void PlayListDownloader::DoOpenNative(const std::string& url) if (ret < 0) { MEDIA_LOG_E("Failed to read, errno " PUBLIC_LOG_D32, static_cast(errno)); return; - } else { - MEDIA_LOG_I("Read success."); } + MEDIA_LOG_I("Read success."); playList_ = m3u8; ParseManifest(playList_); } -- Gitee From d3ae708c58b9bd1f3944dd22f2fcb685b7947a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:33:18 +0000 Subject: [PATCH 15/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- services/media_engine/filters/subtitle_sink_filter.cpp | 4 ++++ services/media_engine/filters/surface_encoder_adapter.cpp | 4 ++++ services/media_engine/filters/surface_encoder_adapter.h | 1 - services/media_engine/filters/surface_encoder_filter.cpp | 8 +++++++- .../sa_avcodec_test/mock/include/system_ability.h | 1 - 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/services/media_engine/filters/subtitle_sink_filter.cpp b/services/media_engine/filters/subtitle_sink_filter.cpp index a8526e007..5c9df073e 100644 --- a/services/media_engine/filters/subtitle_sink_filter.cpp +++ b/services/media_engine/filters/subtitle_sink_filter.cpp @@ -22,6 +22,10 @@ #include "media_core.h" #include "parameters.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Pipeline { diff --git a/services/media_engine/filters/surface_encoder_adapter.cpp b/services/media_engine/filters/surface_encoder_adapter.cpp index 57e95d7d8..cc4792115 100644 --- a/services/media_engine/filters/surface_encoder_adapter.cpp +++ b/services/media_engine/filters/surface_encoder_adapter.cpp @@ -25,6 +25,10 @@ #include "avcodec_trace.h" #include "avcodec_sysevent.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + constexpr uint32_t TIME_OUT_MS = 1000; constexpr uint32_t NS_PER_US = 1000; diff --git a/services/media_engine/filters/surface_encoder_adapter.h b/services/media_engine/filters/surface_encoder_adapter.h index b11b822a7..40ea08361 100644 --- a/services/media_engine/filters/surface_encoder_adapter.h +++ b/services/media_engine/filters/surface_encoder_adapter.h @@ -26,7 +26,6 @@ #include "buffer/avbuffer_queue_producer.h" #include "buffer/avbuffer_queue_consumer.h" #include "common/status.h" -#include "common/log.h" #include "osal/task/task.h" #include "avcodec_common.h" #include "osal/task/condition_variable.h" diff --git a/services/media_engine/filters/surface_encoder_filter.cpp b/services/media_engine/filters/surface_encoder_filter.cpp index 73552979b..6c1ea3035 100644 --- a/services/media_engine/filters/surface_encoder_filter.cpp +++ b/services/media_engine/filters/surface_encoder_filter.cpp @@ -13,12 +13,18 @@ * limitations under the License. */ +#include "surface_encoder_filter.h" + #include #include -#include "surface_encoder_filter.h" + #include "filter/filter_factory.h" #include "surface_encoder_adapter.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Pipeline { diff --git a/test/unittest/sa_avcodec_test/mock/include/system_ability.h b/test/unittest/sa_avcodec_test/mock/include/system_ability.h index 7844d4e65..4ada35844 100644 --- a/test/unittest/sa_avcodec_test/mock/include/system_ability.h +++ b/test/unittest/sa_avcodec_test/mock/include/system_ability.h @@ -19,7 +19,6 @@ #include #include #include -#include "hilog/log.h" #include "iremote_object.h" #include "iservice_registry.h" -- Gitee From e3465133c29c3fac572a9f62f13ac75cdc430d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 5 Jul 2024 13:33:23 +0000 Subject: [PATCH 16/25] 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- services/media_engine/filters/video_capture_filter.cpp | 4 ++++ services/media_engine/filters/video_decoder_adapter.cpp | 4 ++++ services/media_engine/modules/demuxer/type_finder.cpp | 4 ++++ services/media_engine/modules/sink/video_sink.cpp | 4 ++++ .../plugins/source/http_source/xml/xml_parser.cpp | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/services/media_engine/filters/video_capture_filter.cpp b/services/media_engine/filters/video_capture_filter.cpp index adedea11d..2ba940c40 100644 --- a/services/media_engine/filters/video_capture_filter.cpp +++ b/services/media_engine/filters/video_capture_filter.cpp @@ -22,6 +22,10 @@ #include "avcodec_common.h" #include "avcodec_trace.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Pipeline { diff --git a/services/media_engine/filters/video_decoder_adapter.cpp b/services/media_engine/filters/video_decoder_adapter.cpp index 683561de6..645b70475 100644 --- a/services/media_engine/filters/video_decoder_adapter.cpp +++ b/services/media_engine/filters/video_decoder_adapter.cpp @@ -31,6 +31,10 @@ #include "avcodec_sysevent.h" #include "media_core.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { using namespace MediaAVCodec; diff --git a/services/media_engine/modules/demuxer/type_finder.cpp b/services/media_engine/modules/demuxer/type_finder.cpp index c300321e5..f91292190 100644 --- a/services/media_engine/modules/demuxer/type_finder.cpp +++ b/services/media_engine/modules/demuxer/type_finder.cpp @@ -25,6 +25,10 @@ #include "plugin/plugin_info.h" #include "plugin/plugin_manager_v2.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_DEMUXER, "HiStreamer" }; +} + namespace OHOS { namespace Media { using namespace Plugins; diff --git a/services/media_engine/modules/sink/video_sink.cpp b/services/media_engine/modules/sink/video_sink.cpp index 3754f6db6..64b7d9d5a 100644 --- a/services/media_engine/modules/sink/video_sink.cpp +++ b/services/media_engine/modules/sink/video_sink.cpp @@ -22,6 +22,10 @@ #include "osal/task/jobutils.h" #include "syspara/parameters.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Pipeline { diff --git a/services/media_engine/plugins/source/http_source/xml/xml_parser.cpp b/services/media_engine/plugins/source/http_source/xml/xml_parser.cpp index b85648b60..9f841a101 100644 --- a/services/media_engine/plugins/source/http_source/xml/xml_parser.cpp +++ b/services/media_engine/plugins/source/http_source/xml/xml_parser.cpp @@ -16,6 +16,10 @@ #include "xml/xml_parser.h" #include "common/log.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_STREAM_SOURCE, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Plugins { -- Gitee From 9f07eece999f6b9483696622622a4b2e2be03e81 Mon Sep 17 00:00:00 2001 From: hanwenzhao Date: Sat, 6 Jul 2024 18:16:00 +0800 Subject: [PATCH 17/25] patch Signed-off-by: hanwenzhao Change-Id: Idf8959db9a7b25576456c7663818232f0123e7e4 --- .../filters/audio_data_source_filter.cpp | 4 --- .../filters/audio_decoder_filter.cpp | 30 ++++++++++++++----- .../filters/audio_sink_filter.cpp | 27 ++++++++++++++--- .../filters/surface_decoder_adapter.cpp | 4 +++ .../filters/surface_decoder_filter.cpp | 4 +++ .../filters/surface_encoder_adapter.cpp | 1 + .../filters/surface_encoder_filter.cpp | 1 + .../filters/video_capture_filter.cpp | 1 + .../filters/video_resize_filter.cpp | 4 +++ .../modules/demuxer/stream_demuxer.cpp | 4 +++ .../modules/media_codec/media_codec.cpp | 1 + .../media_engine/modules/sink/audio_sink.cpp | 1 + .../modules/sink/subtitle_sink.cpp | 2 ++ .../ffmpeg_adapter/common/ffmpeg_convert.cpp | 2 +- .../common/reference_parser_manager.cpp | 1 + .../ffmpeg_adapter/demuxer/block_queue.h | 6 ++-- .../muxer/ffmpeg_muxer_plugin.cpp | 2 ++ .../http_source/download/http_curl_client.cpp | 1 + 18 files changed, 76 insertions(+), 20 deletions(-) diff --git a/services/media_engine/filters/audio_data_source_filter.cpp b/services/media_engine/filters/audio_data_source_filter.cpp index ad0748992..2b1454f2b 100644 --- a/services/media_engine/filters/audio_data_source_filter.cpp +++ b/services/media_engine/filters/audio_data_source_filter.cpp @@ -108,7 +108,6 @@ Status AudioDataSourceFilter::DoPrepare() Status AudioDataSourceFilter::DoStart() { MEDIA_LOG_I("AudioDataSourceFilter DoStart"); - nextFilter_->Start(); eos_ = false; if (taskPtr_) { taskPtr_->Start(); @@ -141,9 +140,6 @@ Status AudioDataSourceFilter::DoStop() if (taskPtr_) { taskPtr_->Stop(); } - if (nextFilter_) { - nextFilter_->Stop(); - } return Status::OK; } diff --git a/services/media_engine/filters/audio_decoder_filter.cpp b/services/media_engine/filters/audio_decoder_filter.cpp index 6d7d7c335..fa6272304 100644 --- a/services/media_engine/filters/audio_decoder_filter.cpp +++ b/services/media_engine/filters/audio_decoder_filter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -118,24 +118,23 @@ void AudioDecoderFilter::Init(const std::shared_ptr &receiver, Status AudioDecoderFilter::DoPrepare() { MEDIA_LOG_I("AudioDecoderFilter::Prepare."); - Status ret = Status::OK; switch (filterType_) { case FilterType::FILTERTYPE_AENC: MEDIA_LOG_I("AudioDecoderFilter::FILTERTYPE_AENC."); - ret = filterCallback_->OnCallback(shared_from_this(), FilterCallBackCommand::NEXT_FILTER_NEEDED, + filterCallback_->OnCallback(shared_from_this(), FilterCallBackCommand::NEXT_FILTER_NEEDED, StreamType::STREAMTYPE_ENCODED_AUDIO); break; case FilterType::FILTERTYPE_ADEC: - ret = filterCallback_->OnCallback(shared_from_this(), FilterCallBackCommand::NEXT_FILTER_NEEDED, + filterCallback_->OnCallback(shared_from_this(), FilterCallBackCommand::NEXT_FILTER_NEEDED, StreamType::STREAMTYPE_RAW_AUDIO); break; default: break; } - return ret; + return Status::OK; } -Status AudioDecoderFilter::DoPrepareFrame(bool renderFirstFrame) +Status AudioDecoderFilter::PrepareFrame(bool renderFirstFrame) { MEDIA_LOG_I("AudioDecoderFilter::PrepareFrame."); (void)renderFirstFrame; @@ -228,6 +227,21 @@ Status AudioDecoderFilter::UnLinkNext(const std::shared_ptr &nextFilter, return Status::OK; } +Status AudioDecoderFilter::ChangePlugin(std::shared_ptr meta) +{ + MEDIA_LOG_I("AudioDecoderFilter::ChangePlugin."); + std::string mime; + meta_ = meta; + bool mimeGetRes = meta_->GetData(Tag::MIME_TYPE, mime); + if (!mimeGetRes && eventReceiver_ != nullptr) { + MEDIA_LOG_I("AudioDecoderFilter cannot get mime"); + eventReceiver_->OnEvent({"audioDecoder", EventType::EVENT_ERROR, MSERR_UNSUPPORT_AUD_DEC_TYPE}); + return Status::ERROR_UNSUPPORTED_FORMAT; + } + meta->SetData(Tag::AUDIO_SAMPLE_FORMAT, Plugins::SAMPLE_S16LE); + return mediaCodec_->ChangePlugin(mime, false, meta); +} + FilterType AudioDecoderFilter::GetFilterType() { return filterType_; @@ -240,7 +254,7 @@ Status AudioDecoderFilter::OnLinked(StreamType inType, const std::shared_ptrGet(mime); + bool mimeGetRes = meta_->GetData(Tag::MIME_TYPE, mime); if (!mimeGetRes && eventReceiver_ != nullptr) { MEDIA_LOG_I("AudioDecoderFilter cannot get mime"); eventReceiver_->OnEvent({"audioDecoder", EventType::EVENT_ERROR, MSERR_UNSUPPORT_AUD_DEC_TYPE}); @@ -321,7 +335,7 @@ void AudioDecoderFilter::OnLinkedResult(const sptr &outpu sptr listener = new CodecBrokerListener(shared_from_this()); inputBufferQueueProducer_->SetBufferFilledListener(listener); FALSE_RETURN(onLinkedResultCallback_ != nullptr); - onLinkedResultCallback_->OnLinkedResult(inputBufferQueueProducer_, meta); + onLinkedResultCallback_->OnLinkedResult(inputBufferQueueProducer_, meta_); } void AudioDecoderFilter::OnUpdatedResult(std::shared_ptr &meta) diff --git a/services/media_engine/filters/audio_sink_filter.cpp b/services/media_engine/filters/audio_sink_filter.cpp index 7d72d8d30..36be29260 100644 --- a/services/media_engine/filters/audio_sink_filter.cpp +++ b/services/media_engine/filters/audio_sink_filter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2023-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -120,12 +120,12 @@ Status AudioSinkFilter::DoStart() Status AudioSinkFilter::DoPause() { MEDIA_LOG_I("audio sink filter pause start"); - if (state_ == FilterState::PAUSED || state_ == FilterState::STOPPED) { + if (state_ == FilterState::PAUSED) { return Status::OK; } // only worked when state is working if (state_ != FilterState::READY && state_ != FilterState::RUNNING) { - MEDIA_LOG_W("audio sink cannot pause when not working"); + MEDIA_LOG_W("audio sink cannot pause when not working."); return Status::ERROR_INVALID_OPERATION; } state_ = FilterState::PAUSED; @@ -137,6 +137,9 @@ Status AudioSinkFilter::DoPause() Status AudioSinkFilter::DoResume() { MEDIA_LOG_I("audio sink filter resume"); + if (state_ == FilterState::RUNNING) { + return Status::OK; + } // only worked when state is paused if (state_ == FilterState::PAUSED) { forceUpdateTimeAnchorNextTime_ = true; @@ -151,6 +154,11 @@ Status AudioSinkFilter::DoResume() Status AudioSinkFilter::DoFlush() { + // only worked when state is working + if (state_ != FilterState::PAUSED && state_ != FilterState::STOPPED) { + MEDIA_LOG_W("audio sink cannot flush when not paused or stopped"); + return Status::ERROR_INVALID_OPERATION; + } MEDIA_LOG_I("audio sink flush start"); if (audioSink_ != nullptr) { audioSink_->Flush(); @@ -161,6 +169,9 @@ Status AudioSinkFilter::DoFlush() Status AudioSinkFilter::DoStop() { + if (state_ == FilterState::STOPPED) { + return Status::OK; + } MEDIA_LOG_I("audio sink stop start"); if (audioSink_ != nullptr) { audioSink_->Stop(); @@ -174,9 +185,10 @@ Status AudioSinkFilter::DoRelease() { return audioSink_->Release(); } + Status AudioSinkFilter::DoProcessInputBuffer(int recvArg, bool dropFrame) { - audioSink_->DrainOutputBuffer(dropFrame); + audioSink_->DrainOutputBuffer(); return Status::OK; } @@ -271,6 +283,13 @@ Status AudioSinkFilter::SetIsTransitent(bool isTransitent) return audioSink_->SetIsTransitent(isTransitent); } +Status AudioSinkFilter::ChangeTrack(std::shared_ptr& meta) +{ + MEDIA_LOG_I("AudioSinkFilter::ChangeTrack in"); + FALSE_RETURN_V(audioSink_ != nullptr, Status::ERROR_INVALID_STATE); + return audioSink_->ChangeTrack(meta, eventReceiver_); +} + Status AudioSinkFilter::OnUpdated(StreamType inType, const std::shared_ptr& meta, const std::shared_ptr& callback) { diff --git a/services/media_engine/filters/surface_decoder_adapter.cpp b/services/media_engine/filters/surface_decoder_adapter.cpp index 615e94dca..8480af5e4 100644 --- a/services/media_engine/filters/surface_decoder_adapter.cpp +++ b/services/media_engine/filters/surface_decoder_adapter.cpp @@ -21,6 +21,10 @@ #include "meta/format.h" #include "media_description.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_ONLY_PRERELEASE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { diff --git a/services/media_engine/filters/surface_decoder_filter.cpp b/services/media_engine/filters/surface_decoder_filter.cpp index b4d7a70ae..2eb494479 100644 --- a/services/media_engine/filters/surface_decoder_filter.cpp +++ b/services/media_engine/filters/surface_decoder_filter.cpp @@ -19,6 +19,10 @@ #include "surface_decoder_adapter.h" #include "meta/format.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { namespace Pipeline { diff --git a/services/media_engine/filters/surface_encoder_adapter.cpp b/services/media_engine/filters/surface_encoder_adapter.cpp index cc4792115..06987ab23 100644 --- a/services/media_engine/filters/surface_encoder_adapter.cpp +++ b/services/media_engine/filters/surface_encoder_adapter.cpp @@ -24,6 +24,7 @@ #include "native_avcodec_base.h" #include "avcodec_trace.h" #include "avcodec_sysevent.h" +#include "common/log.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; diff --git a/services/media_engine/filters/surface_encoder_filter.cpp b/services/media_engine/filters/surface_encoder_filter.cpp index 6c1ea3035..848941e1a 100644 --- a/services/media_engine/filters/surface_encoder_filter.cpp +++ b/services/media_engine/filters/surface_encoder_filter.cpp @@ -18,6 +18,7 @@ #include #include +#include "common/log.h" #include "filter/filter_factory.h" #include "surface_encoder_adapter.h" diff --git a/services/media_engine/filters/video_capture_filter.cpp b/services/media_engine/filters/video_capture_filter.cpp index 2ba940c40..5f855c129 100644 --- a/services/media_engine/filters/video_capture_filter.cpp +++ b/services/media_engine/filters/video_capture_filter.cpp @@ -21,6 +21,7 @@ #include "avcodec_info.h" #include "avcodec_common.h" #include "avcodec_trace.h" +#include "common/log.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; diff --git a/services/media_engine/filters/video_resize_filter.cpp b/services/media_engine/filters/video_resize_filter.cpp index 9f4250f13..df0e523ae 100644 --- a/services/media_engine/filters/video_resize_filter.cpp +++ b/services/media_engine/filters/video_resize_filter.cpp @@ -22,6 +22,10 @@ #include "detail_enhancer_video_common.h" #endif +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { #ifdef USE_VIDEO_PROCESSING_ENGINE diff --git a/services/media_engine/modules/demuxer/stream_demuxer.cpp b/services/media_engine/modules/demuxer/stream_demuxer.cpp index 40bf24229..52ec93b5d 100644 --- a/services/media_engine/modules/demuxer/stream_demuxer.cpp +++ b/services/media_engine/modules/demuxer/stream_demuxer.cpp @@ -36,6 +36,10 @@ #include "plugin/plugin_time.h" #include "source/source.h" +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +} + namespace OHOS { namespace Media { diff --git a/services/media_engine/modules/media_codec/media_codec.cpp b/services/media_engine/modules/media_codec/media_codec.cpp index fbd51347e..bcb44c5dd 100644 --- a/services/media_engine/modules/media_codec/media_codec.cpp +++ b/services/media_engine/modules/media_codec/media_codec.cpp @@ -19,6 +19,7 @@ #include "avcodec_trace.h" #include "plugin/plugin_manager_v2.h" #include "osal/utils/dump_buffer.h" +#include "common/log.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_MEDIA_CODEC, "HiStreamer" }; diff --git a/services/media_engine/modules/sink/audio_sink.cpp b/services/media_engine/modules/sink/audio_sink.cpp index 2c81c1d52..b70b25814 100644 --- a/services/media_engine/modules/sink/audio_sink.cpp +++ b/services/media_engine/modules/sink/audio_sink.cpp @@ -16,6 +16,7 @@ #include "audio_sink.h" #include "syspara/parameters.h" #include "plugin/plugin_manager_v2.h" +#include "common/log.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; diff --git a/services/media_engine/modules/sink/subtitle_sink.cpp b/services/media_engine/modules/sink/subtitle_sink.cpp index 67d122054..73502ce7b 100644 --- a/services/media_engine/modules/sink/subtitle_sink.cpp +++ b/services/media_engine/modules/sink/subtitle_sink.cpp @@ -14,6 +14,8 @@ */ #include "subtitle_sink.h" + +#include "common/log.h" #include "syspara/parameters.h" #include "meta/format.h" diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp index 41ae9a1cb..5053274e3 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp @@ -17,7 +17,7 @@ #include "securec.h" namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_AUDIO, "FFmpegEncoderPlugin"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "FFmpegEncoderPlugin"}; } namespace OHOS { diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/reference_parser_manager.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/reference_parser_manager.cpp index dc4038590..062fabae5 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/reference_parser_manager.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/reference_parser_manager.cpp @@ -21,6 +21,7 @@ namespace { const std::string REFERENCE_LIB_PATH = "libav_codec_reference_parser.z.so"; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer"}; } namespace OHOS { diff --git a/services/media_engine/plugins/ffmpeg_adapter/demuxer/block_queue.h b/services/media_engine/plugins/ffmpeg_adapter/demuxer/block_queue.h index b77e3b82f..38d33fcd5 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/demuxer/block_queue.h +++ b/services/media_engine/plugins/ffmpeg_adapter/demuxer/block_queue.h @@ -81,7 +81,7 @@ public: MEDIA_LOG_D("block queue " PUBLIC_LOG_S " is inactive for Pop.", name_.c_str()); return {}; } - (que_.empty() && isActive_) { + if (que_.empty() && isActive_) { MEDIA_LOG_D("block queue " PUBLIC_LOG_S " is empty, please waiting for Push.", name_.c_str()); condEmpty_.wait(lock, [this] { return !isActive_ || !que_.empty(); }); } @@ -105,7 +105,7 @@ public: MEDIA_LOG_D("block queue " PUBLIC_LOG_S " is inactive for Front.", name_.c_str()); return {}; } - (que_.empty() && isActive_) { + if (que_.empty() && isActive_) { MEDIA_LOG_D("block queue " PUBLIC_LOG_S " is empty, please waiting for Push.", name_.c_str()); condEmpty_.wait(lock, [this] { return !isActive_ || !que_.empty(); }); } @@ -128,7 +128,7 @@ public: MEDIA_LOG_D("block queue " PUBLIC_LOG_S " is inactive for Back.", name_.c_str()); return {}; } - (que_.empty() && isActive_) { + if (que_.empty() && isActive_) { MEDIA_LOG_D("block queue " PUBLIC_LOG_S " is empty, please waiting for Push.", name_.c_str()); condEmpty_.wait(lock, [this] { return !isActive_ || !que_.empty(); }); } diff --git a/services/media_engine/plugins/ffmpeg_adapter/muxer/ffmpeg_muxer_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/muxer/ffmpeg_muxer_plugin.cpp index b11255113..b80ed94b5 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/muxer/ffmpeg_muxer_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/muxer/ffmpeg_muxer_plugin.cpp @@ -26,6 +26,8 @@ #include "meta/mime_type.h" namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_MUXER, "HiStreamer"}; + using namespace OHOS::Media; using namespace OHOS::Media::Plugins; using namespace Ffmpeg; diff --git a/services/media_engine/plugins/source/http_source/download/http_curl_client.cpp b/services/media_engine/plugins/source/http_source/download/http_curl_client.cpp index 6e0b197a5..50da78ed5 100644 --- a/services/media_engine/plugins/source/http_source/download/http_curl_client.cpp +++ b/services/media_engine/plugins/source/http_source/download/http_curl_client.cpp @@ -21,6 +21,7 @@ #include "osal/task/autolock.h" #include "securec.h" #include "net_conn_client.h" +#include "common/log.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_STREAM_SOURCE, "HiStreamer" }; -- Gitee From 39c18fb1bc6402dcb871da24731b8b11f88ec76c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Mon, 8 Jul 2024 02:26:35 +0000 Subject: [PATCH 18/25] update services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- .../plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp index 5053274e3..41ae9a1cb 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp @@ -17,7 +17,7 @@ #include "securec.h" namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "FFmpegEncoderPlugin"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_AUDIO, "FFmpegEncoderPlugin"}; } namespace OHOS { -- Gitee From 7798d1da675d8958de3b4f811dee3287f9c00573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Mon, 8 Jul 2024 02:27:04 +0000 Subject: [PATCH 19/25] update services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- .../plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp index 7f6f3c82d..f1f64c048 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp @@ -21,7 +21,7 @@ #include "ffmpeg_converter.h" namespace { constexpr int US_PER_SECOND = 1000000; -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "FFmpegEncoderPlugin"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER, "FFmpegEncoderPlugin"}; } namespace OHOS { namespace Media { -- Gitee From 153b11966303875056d6491820d8b5b4f8e9a91f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Mon, 8 Jul 2024 02:27:30 +0000 Subject: [PATCH 20/25] update services/media_engine/filters/audio_sink_filter.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- services/media_engine/filters/audio_sink_filter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/media_engine/filters/audio_sink_filter.cpp b/services/media_engine/filters/audio_sink_filter.cpp index 36be29260..b6891a6be 100644 --- a/services/media_engine/filters/audio_sink_filter.cpp +++ b/services/media_engine/filters/audio_sink_filter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From 1148ad3a29cd3eb63c05bc24f12e754012369bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Mon, 8 Jul 2024 02:32:01 +0000 Subject: [PATCH 21/25] update services/media_engine/plugins/ffmpeg_adapter/common/reference_parser_manager.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- .../plugins/ffmpeg_adapter/common/reference_parser_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/reference_parser_manager.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/reference_parser_manager.cpp index 062fabae5..96a64f40c 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/reference_parser_manager.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/reference_parser_manager.cpp @@ -21,7 +21,7 @@ namespace { const std::string REFERENCE_LIB_PATH = "libav_codec_reference_parser.z.so"; -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER, "HiStreamer"}; } namespace OHOS { -- Gitee From 547dc7ff89d95d634265a38befa717bcc7f9e749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Mon, 8 Jul 2024 02:32:52 +0000 Subject: [PATCH 22/25] update services/media_engine/plugins/ffmpeg_adapter/common/stream_parser_manager.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- .../plugins/ffmpeg_adapter/common/stream_parser_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/stream_parser_manager.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/stream_parser_manager.cpp index 42b1314b7..c2bcc3fde 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/stream_parser_manager.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/stream_parser_manager.cpp @@ -21,7 +21,7 @@ namespace { const std::string HEVC_LIB_PATH = "libav_codec_hevc_parser.z.so"; -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "HiStreamer" }; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_DEMUXER, "HiStreamer" }; } namespace OHOS { -- Gitee From ca049f8c69ae32b154d50538e57cde90a2425279 Mon Sep 17 00:00:00 2001 From: hanwenzhao Date: Mon, 8 Jul 2024 22:19:38 +0800 Subject: [PATCH 23/25] patch Signed-off-by: hanwenzhao Change-Id: I93ba576d8530915bc612752646cb378de39e8edb --- .../modules/media_codec/media_codec.cpp | 276 +++++++++--------- .../audio_decoder/ffmpeg_decoder_plugin.cpp | 3 +- .../aac/ffmpeg_aac_encoder_plugin.cpp | 175 ++++++----- .../audio_encoder/ffmpeg_encoder_plugin.cpp | 3 +- .../ffmpeg_adapter/common/ffmpeg_convert.cpp | 40 +-- 5 files changed, 247 insertions(+), 250 deletions(-) diff --git a/services/media_engine/modules/media_codec/media_codec.cpp b/services/media_engine/modules/media_codec/media_codec.cpp index bcb44c5dd..23cff3779 100644 --- a/services/media_engine/modules/media_codec/media_codec.cpp +++ b/services/media_engine/modules/media_codec/media_codec.cpp @@ -19,10 +19,10 @@ #include "avcodec_trace.h" #include "plugin/plugin_manager_v2.h" #include "osal/utils/dump_buffer.h" -#include "common/log.h" +#include "avcodec_log.h" namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_MEDIA_CODEC, "HiStreamer" }; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_AUDIO, "MediaCodec" }; const std::string INPUT_BUFFER_QUEUE_NAME = "MediaCodecInputBufferQueue"; constexpr int32_t DEFAULT_BUFFER_NUM = 8; constexpr int32_t TIME_OUT_MS = 500; @@ -80,12 +80,12 @@ int32_t MediaCodec::Init(const std::string &mime, bool isEncoder) { AutoLock lock(stateMutex_); MediaAVCodec::AVCodecTrace trace("MediaCodec::Init"); - MEDIA_LOG_I("Init enter, mime: " PUBLIC_LOG_S, mime.c_str()); + AVCODEC_LOGI("Init enter, mime: " PUBLIC_LOG_S, mime.c_str()); if (state_ != CodecState::UNINITIALIZED) { - MEDIA_LOG_E("Init failed, state = %{public}s .", StateToString(state_).data()); + AVCODEC_LOGE("Init failed, state = %{public}s .", StateToString(state_).data()); return (int32_t)Status::ERROR_INVALID_STATE; } - MEDIA_LOG_I("state from %{public}s to INITIALIZING", StateToString(state_).data()); + AVCODEC_LOGI("state from %{public}s to INITIALIZING", StateToString(state_).data()); state_ = CodecState::INITIALIZING; Plugins::PluginType type; if (isEncoder) { @@ -95,12 +95,12 @@ int32_t MediaCodec::Init(const std::string &mime, bool isEncoder) } codecPlugin_ = CreatePlugin(mime, type); if (codecPlugin_ != nullptr) { - MEDIA_LOG_I("codecPlugin_->Init()"); + AVCODEC_LOGI("codecPlugin_->Init()"); auto ret = codecPlugin_->Init(); - FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "pluign init failed"); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "pluign init failed"); state_ = CodecState::INITIALIZED; } else { - MEDIA_LOG_I("createPlugin failed"); + AVCODEC_LOGI("createPlugin failed"); return (int32_t)Status::ERROR_INVALID_PARAMETER; } return (int32_t)Status::OK; @@ -109,20 +109,20 @@ int32_t MediaCodec::Init(const std::string &mime, bool isEncoder) int32_t MediaCodec::Init(const std::string &name) { AutoLock lock(stateMutex_); - MEDIA_LOG_I("Init enter, name: " PUBLIC_LOG_S, name.c_str()); - MEDIA_LOG_I("MediaCodec::Init"); + AVCODEC_LOGI("Init enter, name: " PUBLIC_LOG_S, name.c_str()); + AVCODEC_LOGI("MediaCodec::Init"); MediaAVCodec::AVCodecTrace trace("MediaCodec::Init"); if (state_ != CodecState::UNINITIALIZED) { - MEDIA_LOG_E("Init failed, state = %{public}s .", StateToString(state_).data()); + AVCODEC_LOGE("Init failed, state = %{public}s .", StateToString(state_).data()); return (int32_t)Status::ERROR_INVALID_STATE; } - MEDIA_LOG_I("state from %{public}s to INITIALIZING", StateToString(state_).data()); + AVCODEC_LOGI("state from %{public}s to INITIALIZING", StateToString(state_).data()); state_ = CodecState::INITIALIZING; auto plugin = Plugins::PluginManagerV2::Instance().CreatePluginByName(name); - FALSE_RETURN_V_MSG_E(plugin != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER, "create pluign failed"); + CHECK_AND_RETURN_RET_LOG(plugin != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER, "create pluign failed"); codecPlugin_ = std::reinterpret_pointer_cast(plugin); Status ret = codecPlugin_->Init(); - FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)Status::ERROR_INVALID_PARAMETER, "pluign init failed"); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)Status::ERROR_INVALID_PARAMETER, "pluign init failed"); state_ = CodecState::INITIALIZED; return (int32_t)Status::OK; } @@ -138,14 +138,14 @@ std::shared_ptr MediaCodec::CreatePlugin(const std::string int32_t MediaCodec::Configure(const std::shared_ptr &meta) { - MEDIA_LOG_I("MediaCodec::configure in"); + AVCODEC_LOGI("MediaCodec::configure in"); AutoLock lock(stateMutex_); MediaAVCodec::AVCodecTrace trace("MediaCodec::Configure"); - FALSE_RETURN_V(state_ == CodecState::INITIALIZED, (int32_t)Status::ERROR_INVALID_STATE); + CHECK_AND_RETURN_RET(state_ == CodecState::INITIALIZED, (int32_t)Status::ERROR_INVALID_STATE); auto ret = codecPlugin_->SetParameter(meta); - FALSE_RETURN_V(ret == Status::OK, (int32_t)ret); + CHECK_AND_RETURN_RET(ret == Status::OK, (int32_t)ret); ret = codecPlugin_->SetDataCallback(this); - FALSE_RETURN_V(ret == Status::OK, (int32_t)ret); + CHECK_AND_RETURN_RET(ret == Status::OK, (int32_t)ret); state_ = CodecState::CONFIGURED; return (int32_t)Status::OK; } @@ -154,7 +154,7 @@ int32_t MediaCodec::SetOutputBufferQueue(const sptr &buff { AutoLock lock(stateMutex_); MediaAVCodec::AVCodecTrace trace("MediaCodec::SetOutputBufferQueue"); - FALSE_RETURN_V(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, + CHECK_AND_RETURN_RET(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, (int32_t)Status::ERROR_INVALID_STATE); outputBufferQueueProducer_ = bufferQueueProducer; isBufferMode_ = true; @@ -164,22 +164,22 @@ int32_t MediaCodec::SetOutputBufferQueue(const sptr &buff int32_t MediaCodec::SetCodecCallback(const std::shared_ptr &codecCallback) { AutoLock lock(stateMutex_); - FALSE_RETURN_V(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, + CHECK_AND_RETURN_RET(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, (int32_t)Status::ERROR_INVALID_STATE); - FALSE_RETURN_V_MSG_E(codecCallback != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER, + CHECK_AND_RETURN_RET_LOG(codecCallback != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER, "codecCallback is nullptr"); codecCallback_ = codecCallback; auto ret = codecPlugin_->SetDataCallback(this); - FALSE_RETURN_V(ret == Status::OK, (int32_t)ret); + CHECK_AND_RETURN_RET(ret == Status::OK, (int32_t)ret); return (int32_t)Status::OK; } int32_t MediaCodec::SetCodecCallback(const std::shared_ptr &codecCallback) { AutoLock lock(stateMutex_); - FALSE_RETURN_V(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, + CHECK_AND_RETURN_RET(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, (int32_t)Status::ERROR_INVALID_STATE); - FALSE_RETURN_V_MSG_E(codecCallback != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER, + CHECK_AND_RETURN_RET_LOG(codecCallback != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER, "codecCallback is nullptr"); mediaCodecCallback_ = codecCallback; return (int32_t)Status::OK; @@ -188,7 +188,7 @@ int32_t MediaCodec::SetCodecCallback(const std::shared_ptr surface) { AutoLock lock(stateMutex_); - FALSE_RETURN_V(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, + CHECK_AND_RETURN_RET(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, (int32_t)Status::ERROR_INVALID_STATE); isSurfaceMode_ = true; return (int32_t)Status::OK; @@ -196,36 +196,36 @@ int32_t MediaCodec::SetOutputSurface(sptr surface) int32_t MediaCodec::Prepare() { - MEDIA_LOG_I("Prepare enter"); + AVCODEC_LOGI("Prepare enter"); AutoLock lock(stateMutex_); MediaAVCodec::AVCodecTrace trace("MediaCodec::Prepare"); - FALSE_RETURN_V(state_ != CodecState::PREPARED, (int32_t)Status::OK); - FALSE_RETURN_V(state_ == CodecState::CONFIGURED || state_ == CodecState::FLUSHED, + CHECK_AND_RETURN_RET(state_ != CodecState::PREPARED, (int32_t)Status::OK); + CHECK_AND_RETURN_RET(state_ == CodecState::CONFIGURED || state_ == CodecState::FLUSHED, (int32_t)Status::ERROR_INVALID_STATE); if (isBufferMode_ && isSurfaceMode_) { - MEDIA_LOG_E("state error"); + AVCODEC_LOGE("state error"); return (int32_t)Status::ERROR_UNKNOWN; } outputBufferCapacity_ = 0; auto ret = (int32_t)PrepareInputBufferQueue(); if (ret != (int32_t)Status::OK) { - MEDIA_LOG_E("PrepareInputBufferQueue failed"); + AVCODEC_LOGE("PrepareInputBufferQueue failed"); return (int32_t)ret; } ret = (int32_t)PrepareOutputBufferQueue(); if (ret != (int32_t)Status::OK) { - MEDIA_LOG_E("PrepareOutputBufferQueue failed"); + AVCODEC_LOGE("PrepareOutputBufferQueue failed"); return (int32_t)ret; } state_ = CodecState::PREPARED; - MEDIA_LOG_I("Prepare, ret = %{public}d", (int32_t)ret); + AVCODEC_LOGI("Prepare, ret = %{public}d", (int32_t)ret); return (int32_t)Status::OK; } sptr MediaCodec::GetInputBufferQueue() { AutoLock lock(stateMutex_); - FALSE_RETURN_V(state_ == CodecState::PREPARED, sptr()); + CHECK_AND_RETURN_RET(state_ == CodecState::PREPARED, sptr()); if (isSurfaceMode_) { return nullptr; } @@ -236,7 +236,7 @@ sptr MediaCodec::GetInputBufferQueue() sptr MediaCodec::GetInputSurface() { AutoLock lock(stateMutex_); - FALSE_RETURN_V(state_ == CodecState::PREPARED, nullptr); + CHECK_AND_RETURN_RET(state_ == CodecState::PREPARED, nullptr); if (isBufferMode_) { return nullptr; } @@ -247,14 +247,14 @@ sptr MediaCodec::GetInputSurface() int32_t MediaCodec::Start() { AutoLock lock(stateMutex_); - MEDIA_LOG_I("Start enter"); + AVCODEC_LOGI("Start enter"); MediaAVCodec::AVCodecTrace trace("MediaCodec::Start"); - FALSE_RETURN_V(state_ != CodecState::RUNNING, (int32_t)Status::OK); - FALSE_RETURN_V(state_ == CodecState::PREPARED || state_ == CodecState::FLUSHED, + CHECK_AND_RETURN_RET(state_ != CodecState::RUNNING, (int32_t)Status::OK); + CHECK_AND_RETURN_RET(state_ == CodecState::PREPARED || state_ == CodecState::FLUSHED, (int32_t)Status::ERROR_INVALID_STATE); state_ = CodecState::STARTING; auto ret = codecPlugin_->Start(); - FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin start failed"); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "plugin start failed"); state_ = CodecState::RUNNING; return (int32_t)ret; } @@ -263,18 +263,18 @@ int32_t MediaCodec::Stop() { AutoLock lock(stateMutex_); MediaAVCodec::AVCodecTrace trace("MediaCodec::Stop"); - MEDIA_LOG_I("Stop enter"); - FALSE_RETURN_V(state_ != CodecState::PREPARED, (int32_t)Status::OK); + AVCODEC_LOGI("Stop enter"); + CHECK_AND_RETURN_RET(state_ != CodecState::PREPARED, (int32_t)Status::OK); if (state_ == CodecState::UNINITIALIZED || state_ == CodecState::STOPPING || state_ == CodecState::RELEASING) { - MEDIA_LOG_D("Stop, state_=%{public}s", StateToString(state_).data()); + AVCODEC_LOGD("Stop, state_=%{public}s", StateToString(state_).data()); return (int32_t)Status::OK; } - FALSE_RETURN_V(state_ == CodecState::RUNNING || state_ == CodecState::END_OF_STREAM || + CHECK_AND_RETURN_RET(state_ == CodecState::RUNNING || state_ == CodecState::END_OF_STREAM || state_ == CodecState::FLUSHED, (int32_t)Status::ERROR_INVALID_STATE); state_ = CodecState::STOPPING; auto ret = codecPlugin_->Stop(); - MEDIA_LOG_I("codec Stop, state from %{public}s to Stop", StateToString(state_).data()); - FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin stop failed"); + AVCODEC_LOGI("codec Stop, state from %{public}s to Stop", StateToString(state_).data()); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "plugin stop failed"); ClearInputBuffer(); state_ = CodecState::PREPARED; return (int32_t)ret; @@ -283,20 +283,20 @@ int32_t MediaCodec::Stop() int32_t MediaCodec::Flush() { AutoLock lock(stateMutex_); - MEDIA_LOG_I("Flush enter"); + AVCODEC_LOGI("Flush enter"); if (state_ == CodecState::FLUSHED) { - MEDIA_LOG_W("Flush, state is already flushed, state_=%{public}s .", StateToString(state_).data()); + AVCODEC_LOGW("Flush, state is already flushed, state_=%{public}s .", StateToString(state_).data()); return (int32_t)Status::OK; } if (state_ != CodecState::RUNNING && state_ != CodecState::END_OF_STREAM) { - MEDIA_LOG_E("Flush failed, state =%{public}s", StateToString(state_).data()); + AVCODEC_LOGE("Flush failed, state =%{public}s", StateToString(state_).data()); return (int32_t)Status::ERROR_INVALID_STATE; } - MEDIA_LOG_I("Flush, state from %{public}s to FLUSHING", StateToString(state_).data()); + AVCODEC_LOGI("Flush, state from %{public}s to FLUSHING", StateToString(state_).data()); state_ = CodecState::FLUSHING; inputBufferQueueProducer_->Clear(); auto ret = codecPlugin_->Flush(); - FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin flush failed"); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "plugin flush failed"); ClearInputBuffer(); state_ = CodecState::FLUSHED; return (int32_t)ret; @@ -306,18 +306,18 @@ int32_t MediaCodec::Reset() { AutoLock lock(stateMutex_); MediaAVCodec::AVCodecTrace trace("MediaCodec::Reset"); - MEDIA_LOG_I("Reset enter"); + AVCODEC_LOGI("Reset enter"); if (state_ == CodecState::UNINITIALIZED || state_ == CodecState::RELEASING) { - MEDIA_LOG_W("adapter reset, state is already released, state =%{public}s .", StateToString(state_).data()); + AVCODEC_LOGW("adapter reset, state is already released, state =%{public}s .", StateToString(state_).data()); return (int32_t)Status::OK; } if (state_ == CodecState::INITIALIZING) { - MEDIA_LOG_W("adapter reset, state is initialized, state =%{public}s .", StateToString(state_).data()); + AVCODEC_LOGW("adapter reset, state is initialized, state =%{public}s .", StateToString(state_).data()); state_ = CodecState::INITIALIZED; return (int32_t)Status::OK; } auto ret = codecPlugin_->Reset(); - FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin reset failed"); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "plugin reset failed"); ClearInputBuffer(); state_ = CodecState::INITIALIZED; return (int32_t)ret; @@ -327,21 +327,21 @@ int32_t MediaCodec::Release() { AutoLock lock(stateMutex_); MediaAVCodec::AVCodecTrace trace("MediaCodec::Release"); - MEDIA_LOG_I("Release enter"); + AVCODEC_LOGI("Release enter"); if (state_ == CodecState::UNINITIALIZED || state_ == CodecState::RELEASING) { - MEDIA_LOG_W("codec Release, state isnot completely correct, state =%{public}s .", StateToString(state_).data()); + AVCODEC_LOGW("codec Release, state isnot completely correct, state =%{public}s .", StateToString(state_).data()); return (int32_t)Status::OK; } if (state_ == CodecState::INITIALIZING) { - MEDIA_LOG_W("codec Release, state isnot completely correct, state =%{public}s .", StateToString(state_).data()); + AVCODEC_LOGW("codec Release, state isnot completely correct, state =%{public}s .", StateToString(state_).data()); state_ = CodecState::RELEASING; return (int32_t)Status::OK; } - MEDIA_LOG_I("codec Release, state from %{public}s to RELEASING", StateToString(state_).data()); + AVCODEC_LOGI("codec Release, state from %{public}s to RELEASING", StateToString(state_).data()); state_ = CodecState::RELEASING; auto ret = codecPlugin_->Release(); - FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin release failed"); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "plugin release failed"); codecPlugin_ = nullptr; ClearBufferQueue(); state_ = CodecState::UNINITIALIZED; @@ -351,8 +351,8 @@ int32_t MediaCodec::Release() int32_t MediaCodec::NotifyEos() { AutoLock lock(stateMutex_); - FALSE_RETURN_V(state_ != CodecState::END_OF_STREAM, (int32_t)Status::OK); - FALSE_RETURN_V(state_ == CodecState::RUNNING, (int32_t)Status::ERROR_INVALID_STATE); + CHECK_AND_RETURN_RET(state_ != CodecState::END_OF_STREAM, (int32_t)Status::OK); + CHECK_AND_RETURN_RET(state_ == CodecState::RUNNING, (int32_t)Status::ERROR_INVALID_STATE); state_ = CodecState::END_OF_STREAM; return (int32_t)Status::OK; } @@ -360,18 +360,18 @@ int32_t MediaCodec::NotifyEos() int32_t MediaCodec::SetParameter(const std::shared_ptr ¶meter) { AutoLock lock(stateMutex_); - FALSE_RETURN_V(parameter != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER); - FALSE_RETURN_V(state_ != CodecState::UNINITIALIZED && state_ != CodecState::INITIALIZED && + CHECK_AND_RETURN_RET(parameter != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER); + CHECK_AND_RETURN_RET(state_ != CodecState::UNINITIALIZED && state_ != CodecState::INITIALIZED && state_ != CodecState::PREPARED, (int32_t)Status::ERROR_INVALID_STATE); auto ret = codecPlugin_->SetParameter(parameter); - FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin set parameter failed"); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "plugin set parameter failed"); return (int32_t)ret; } void MediaCodec::SetDumpInfo(bool isDump, uint64_t instanceId) { if (isDump && instanceId == 0) { - MEDIA_LOG_W("Cannot dump with instanceId 0."); + AVCODEC_LOGW("Cannot dump with instanceId 0."); return; } dumpPrefix_ = std::to_string(instanceId); @@ -381,18 +381,18 @@ void MediaCodec::SetDumpInfo(bool isDump, uint64_t instanceId) int32_t MediaCodec::GetOutputFormat(std::shared_ptr ¶meter) { AutoLock lock(stateMutex_); - FALSE_RETURN_V_MSG_E(state_ != CodecState::UNINITIALIZED, (int32_t)Status::ERROR_INVALID_STATE, + CHECK_AND_RETURN_RET_LOG(state_ != CodecState::UNINITIALIZED, (int32_t)Status::ERROR_INVALID_STATE, "status incorrect,get output format failed."); - FALSE_RETURN_V(codecPlugin_ != nullptr, (int32_t)Status::ERROR_INVALID_STATE); - FALSE_RETURN_V(parameter != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER); + CHECK_AND_RETURN_RET(codecPlugin_ != nullptr, (int32_t)Status::ERROR_INVALID_STATE); + CHECK_AND_RETURN_RET(parameter != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER); auto ret = codecPlugin_->GetParameter(parameter); - FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "plugin get parameter failed"); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "plugin get parameter failed"); return (int32_t)ret; } Status MediaCodec::AttachBufffer() { - MEDIA_LOG_I("AttachBufffer enter"); + AVCODEC_LOGI("AttachBufffer enter"); int inputBufferNum = DEFAULT_BUFFER_NUM; MemoryType memoryType; #ifndef MEDIA_OHOS @@ -403,34 +403,34 @@ Status MediaCodec::AttachBufffer() if (inputBufferQueue_ == nullptr) { inputBufferQueue_ = AVBufferQueue::Create(inputBufferNum, memoryType, INPUT_BUFFER_QUEUE_NAME); } - FALSE_RETURN_V_MSG_E(inputBufferQueue_ != nullptr, Status::ERROR_UNKNOWN, + CHECK_AND_RETURN_RET_LOG(inputBufferQueue_ != nullptr, Status::ERROR_UNKNOWN, "inputBufferQueue_ is nullptr"); inputBufferQueueProducer_ = inputBufferQueue_->GetProducer(); std::shared_ptr inputBufferConfig = std::make_shared(); - FALSE_RETURN_V_MSG_E(codecPlugin_ != nullptr, Status::ERROR_UNKNOWN, "codecPlugin_ is nullptr"); + CHECK_AND_RETURN_RET_LOG(codecPlugin_ != nullptr, Status::ERROR_UNKNOWN, "codecPlugin_ is nullptr"); auto ret = codecPlugin_->GetParameter(inputBufferConfig); - FALSE_RETURN_V_MSG_E(ret == Status::OK, ret, "attachBufffer failed, plugin get param error"); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, ret, "attachBufffer failed, plugin get param error"); int32_t capacity = 0; - FALSE_RETURN_V_MSG_E(inputBufferConfig != nullptr, Status::ERROR_UNKNOWN, + CHECK_AND_RETURN_RET_LOG(inputBufferConfig != nullptr, Status::ERROR_UNKNOWN, "inputBufferConfig is nullptr"); - FALSE_RETURN_V(inputBufferConfig->Get(capacity), + CHECK_AND_RETURN_RET(inputBufferConfig->Get(capacity), Status::ERROR_INVALID_PARAMETER); for (int i = 0; i < inputBufferNum; i++) { std::shared_ptr avAllocator; #ifndef MEDIA_OHOS - MEDIA_LOG_D("CreateVirtualAllocator,i=%{public}d capacity=%{public}d", i, capacity); + AVCODEC_LOGD("CreateVirtualAllocator,i=%{public}d capacity=%{public}d", i, capacity); avAllocator = AVAllocatorFactory::CreateVirtualAllocator(); #else - MEDIA_LOG_D("CreateSharedAllocator,i=%{public}d capacity=%{public}d", i, capacity); + AVCODEC_LOGD("CreateSharedAllocator,i=%{public}d capacity=%{public}d", i, capacity); avAllocator = AVAllocatorFactory::CreateSharedAllocator(MemoryFlag::MEMORY_READ_WRITE); #endif std::shared_ptr inputBuffer = AVBuffer::CreateAVBuffer(avAllocator, capacity); - FALSE_RETURN_V_MSG_E(inputBuffer != nullptr, Status::ERROR_UNKNOWN, + CHECK_AND_RETURN_RET_LOG(inputBuffer != nullptr, Status::ERROR_UNKNOWN, "inputBuffer is nullptr"); - FALSE_RETURN_V_MSG_E(inputBufferQueueProducer_ != nullptr, Status::ERROR_UNKNOWN, + CHECK_AND_RETURN_RET_LOG(inputBufferQueueProducer_ != nullptr, Status::ERROR_UNKNOWN, "inputBufferQueueProducer_ is nullptr"); inputBufferQueueProducer_->AttachBuffer(inputBuffer, false); - MEDIA_LOG_I("Attach intput buffer. index: %{public}d, bufferId: %{public}" PRIu64, + AVCODEC_LOGI("Attach intput buffer. index: %{public}d, bufferId: %{public}" PRIu64, i, inputBuffer->GetUniqueId()); inputBufferVector_.push_back(inputBuffer); } @@ -440,23 +440,23 @@ Status MediaCodec::AttachBufffer() Status MediaCodec::AttachDrmBufffer(std::shared_ptr &drmInbuf, std::shared_ptr &drmOutbuf, uint32_t size) { - MEDIA_LOG_D("AttachDrmBufffer"); + AVCODEC_LOGD("AttachDrmBufffer"); std::shared_ptr avAllocator; avAllocator = AVAllocatorFactory::CreateSharedAllocator(MemoryFlag::MEMORY_READ_WRITE); - FALSE_RETURN_V_MSG_E(avAllocator != nullptr, Status::ERROR_UNKNOWN, + CHECK_AND_RETURN_RET_LOG(avAllocator != nullptr, Status::ERROR_UNKNOWN, "avAllocator is nullptr"); drmInbuf = AVBuffer::CreateAVBuffer(avAllocator, size); - FALSE_RETURN_V_MSG_E(drmInbuf != nullptr, Status::ERROR_UNKNOWN, + CHECK_AND_RETURN_RET_LOG(drmInbuf != nullptr, Status::ERROR_UNKNOWN, "drmInbuf is nullptr"); - FALSE_RETURN_V_MSG_E(drmInbuf->memory_ != nullptr, Status::ERROR_UNKNOWN, + CHECK_AND_RETURN_RET_LOG(drmInbuf->memory_ != nullptr, Status::ERROR_UNKNOWN, "drmInbuf->memory_ is nullptr"); drmInbuf->memory_->SetSize(size); drmOutbuf = AVBuffer::CreateAVBuffer(avAllocator, size); - FALSE_RETURN_V_MSG_E(drmOutbuf != nullptr, Status::ERROR_UNKNOWN, + CHECK_AND_RETURN_RET_LOG(drmOutbuf != nullptr, Status::ERROR_UNKNOWN, "drmOutbuf is nullptr"); - FALSE_RETURN_V_MSG_E(drmOutbuf->memory_ != nullptr, Status::ERROR_UNKNOWN, + CHECK_AND_RETURN_RET_LOG(drmOutbuf->memory_ != nullptr, Status::ERROR_UNKNOWN, "drmOutbuf->memory_ is nullptr"); drmOutbuf->memory_->SetSize(size); return Status::OK; @@ -464,50 +464,50 @@ Status MediaCodec::AttachDrmBufffer(std::shared_ptr &drmInbuf, std::sh Status MediaCodec::DrmAudioCencDecrypt(std::shared_ptr &filledInputBuffer) { - MEDIA_LOG_D("DrmAudioCencDecrypt enter"); + AVCODEC_LOGD("DrmAudioCencDecrypt enter"); Status ret = Status::OK; // 1. allocate drm buffer uint32_t bufSize = static_cast(filledInputBuffer->memory_->GetSize()); if (bufSize == 0) { - MEDIA_LOG_D("MediaCodec DrmAudioCencDecrypt input buffer size equal 0"); + AVCODEC_LOGD("MediaCodec DrmAudioCencDecrypt input buffer size equal 0"); return ret; } std::shared_ptr drmInBuf; std::shared_ptr drmOutBuf; ret = AttachDrmBufffer(drmInBuf, drmOutBuf, bufSize); - FALSE_RETURN_V_MSG_E(ret == Status::OK, Status::ERROR_UNKNOWN, "AttachDrmBufffer failed"); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, Status::ERROR_UNKNOWN, "AttachDrmBufffer failed"); // 2. copy data to drm input buffer int32_t drmRes = memcpy_s(drmInBuf->memory_->GetAddr(), bufSize, filledInputBuffer->memory_->GetAddr(), bufSize); - FALSE_RETURN_V_MSG_E(drmRes == 0, Status::ERROR_UNKNOWN, "memcpy_s drmInBuf failed"); + CHECK_AND_RETURN_RET_LOG(drmRes == 0, Status::ERROR_UNKNOWN, "memcpy_s drmInBuf failed"); if (filledInputBuffer->meta_ != nullptr) { *(drmInBuf->meta_) = *(filledInputBuffer->meta_); } // 4. decrypt drmRes = drmDecryptor_->DrmAudioCencDecrypt(drmInBuf, drmOutBuf, bufSize); - FALSE_RETURN_V_MSG_E(drmRes == 0, Status::ERROR_UNKNOWN, "DrmAudioCencDecrypt return error"); + CHECK_AND_RETURN_RET_LOG(drmRes == 0, Status::ERROR_UNKNOWN, "DrmAudioCencDecrypt return error"); // 5. copy decrypted data from drm output buffer back drmRes = memcpy_s(filledInputBuffer->memory_->GetAddr(), bufSize, drmOutBuf->memory_->GetAddr(), bufSize); - FALSE_RETURN_V_MSG_E(drmRes == 0, Status::ERROR_UNKNOWN, "memcpy_s drmOutBuf failed"); + CHECK_AND_RETURN_RET_LOG(drmRes == 0, Status::ERROR_UNKNOWN, "memcpy_s drmOutBuf failed"); return Status::OK; } int32_t MediaCodec::PrepareInputBufferQueue() { - MEDIA_LOG_I("PrepareInputBufferQueue enter"); + AVCODEC_LOGI("PrepareInputBufferQueue enter"); std::vector> inputBuffers; MediaAVCodec::AVCodecTrace trace("MediaCodec::PrepareInputBufferQueue"); - FALSE_RETURN_V_MSG_E(codecPlugin_ != nullptr, (int32_t)Status::ERROR_UNKNOWN, "codecPlugin_ is nullptr"); + CHECK_AND_RETURN_RET_LOG(codecPlugin_ != nullptr, (int32_t)Status::ERROR_UNKNOWN, "codecPlugin_ is nullptr"); auto ret = codecPlugin_->GetInputBuffers(inputBuffers); - FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "pluign getInputBuffers failed"); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "pluign getInputBuffers failed"); if (inputBuffers.empty()) { ret = AttachBufffer(); if (ret != Status::OK) { - MEDIA_LOG_E("GetParameter failed"); + AVCODEC_LOGE("GetParameter failed"); return (int32_t)ret; } } else { @@ -515,7 +515,7 @@ int32_t MediaCodec::PrepareInputBufferQueue() inputBufferQueue_ = AVBufferQueue::Create(inputBuffers.size(), MemoryType::HARDWARE_MEMORY, INPUT_BUFFER_QUEUE_NAME); } - FALSE_RETURN_V_MSG_E(inputBufferQueue_ != nullptr, (int32_t)Status::ERROR_UNKNOWN, + CHECK_AND_RETURN_RET_LOG(inputBufferQueue_ != nullptr, (int32_t)Status::ERROR_UNKNOWN, "inputBufferQueue_ is nullptr"); inputBufferQueueProducer_ = inputBufferQueue_->GetProducer(); for (uint32_t i = 0; i < inputBuffers.size(); i++) { @@ -523,10 +523,10 @@ int32_t MediaCodec::PrepareInputBufferQueue() inputBufferVector_.push_back(inputBuffers[i]); } } - FALSE_RETURN_V_MSG_E(inputBufferQueue_ != nullptr, (int32_t)Status::ERROR_UNKNOWN, "inputBufferQueue_ is nullptr"); + CHECK_AND_RETURN_RET_LOG(inputBufferQueue_ != nullptr, (int32_t)Status::ERROR_UNKNOWN, "inputBufferQueue_ is nullptr"); inputBufferQueueConsumer_ = inputBufferQueue_->GetConsumer(); sptr listener = new InputBufferAvailableListener(this); - FALSE_RETURN_V_MSG_E(inputBufferQueueConsumer_ != nullptr, (int32_t)Status::ERROR_UNKNOWN, + CHECK_AND_RETURN_RET_LOG(inputBufferQueueConsumer_ != nullptr, (int32_t)Status::ERROR_UNKNOWN, "inputBufferQueueConsumer_ is nullptr"); inputBufferQueueConsumer_->SetBufferAvailableListener(listener); return (int32_t)ret; @@ -534,30 +534,30 @@ int32_t MediaCodec::PrepareInputBufferQueue() int32_t MediaCodec::PrepareOutputBufferQueue() { - MEDIA_LOG_I("PrepareOutputBufferQueue enter"); + AVCODEC_LOGI("PrepareOutputBufferQueue enter"); std::vector> outputBuffers; MediaAVCodec::AVCodecTrace trace("MediaCodec::PrepareOutputBufferQueue"); - FALSE_RETURN_V_MSG_E(codecPlugin_ != nullptr, (int32_t)Status::ERROR_INVALID_STATE, "codecPlugin_ is nullptr"); + CHECK_AND_RETURN_RET_LOG(codecPlugin_ != nullptr, (int32_t)Status::ERROR_INVALID_STATE, "codecPlugin_ is nullptr"); auto ret = codecPlugin_->GetOutputBuffers(outputBuffers); - FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "GetOutputBuffers failed"); - FALSE_RETURN_V_MSG_E(outputBufferQueueProducer_ != nullptr, (int32_t)Status::ERROR_INVALID_STATE, + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "GetOutputBuffers failed"); + CHECK_AND_RETURN_RET_LOG(outputBufferQueueProducer_ != nullptr, (int32_t)Status::ERROR_INVALID_STATE, "outputBufferQueueProducer_ is nullptr"); if (outputBuffers.empty()) { int outputBufferNum = 30; std::shared_ptr outputBufferConfig = std::make_shared(); ret = codecPlugin_->GetParameter(outputBufferConfig); - FALSE_RETURN_V_MSG_E(ret == Status::OK, (int32_t)ret, "GetParameter failed"); - FALSE_RETURN_V_MSG_E(outputBufferConfig != nullptr, (int32_t)Status::ERROR_INVALID_STATE, + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "GetParameter failed"); + CHECK_AND_RETURN_RET_LOG(outputBufferConfig != nullptr, (int32_t)Status::ERROR_INVALID_STATE, "outputBufferConfig is nullptr"); - FALSE_RETURN_V(outputBufferConfig->Get(outputBufferCapacity_), + CHECK_AND_RETURN_RET(outputBufferConfig->Get(outputBufferCapacity_), (int32_t)Status::ERROR_INVALID_PARAMETER); for (int i = 0; i < outputBufferNum; i++) { auto avAllocator = AVAllocatorFactory::CreateSharedAllocator(MemoryFlag::MEMORY_READ_WRITE); std::shared_ptr outputBuffer = AVBuffer::CreateAVBuffer(avAllocator, outputBufferCapacity_); - FALSE_RETURN_V_MSG_E(outputBuffer != nullptr, (int32_t)Status::ERROR_INVALID_STATE, + CHECK_AND_RETURN_RET_LOG(outputBuffer != nullptr, (int32_t)Status::ERROR_INVALID_STATE, "outputBuffer is nullptr"); if (outputBufferQueueProducer_->AttachBuffer(outputBuffer, false) == Status::OK) { - MEDIA_LOG_D("Attach output buffer. index: %{public}d, bufferId: %{public}" PRIu64, i, + AVCODEC_LOGD("Attach output buffer. index: %{public}d, bufferId: %{public}" PRIu64, i, outputBuffer->GetUniqueId()); outputBufferVector_.push_back(outputBuffer); } @@ -565,34 +565,34 @@ int32_t MediaCodec::PrepareOutputBufferQueue() } else { for (uint32_t i = 0; i < outputBuffers.size(); i++) { if (outputBufferQueueProducer_->AttachBuffer(outputBuffers[i], false) == Status::OK) { - MEDIA_LOG_D("Attach output buffer. index: %{public}d, bufferId: %{public}" PRIu64, i, + AVCODEC_LOGD("Attach output buffer. index: %{public}d, bufferId: %{public}" PRIu64, i, outputBuffers[i]->GetUniqueId()); outputBufferVector_.push_back(outputBuffers[i]); } } } - FALSE_RETURN_V_MSG_E(outputBufferVector_.size() > 0, (int32_t)Status::ERROR_INVALID_STATE, "Attach no buffer"); + CHECK_AND_RETURN_RET_LOG(outputBufferVector_.size() > 0, (int32_t)Status::ERROR_INVALID_STATE, "Attach no buffer"); return (int32_t)ret; } void MediaCodec::ProcessInputBuffer() { - MEDIA_LOG_D("ProcessInputBuffer enter"); + AVCODEC_LOGD("ProcessInputBuffer enter"); MediaAVCodec::AVCodecTrace trace("MediaCodec::ProcessInputBuffer"); Status ret; uint32_t eosStatus = 0; std::shared_ptr filledInputBuffer; if (state_ != CodecState::RUNNING) { - MEDIA_LOG_E("status changed, current status is not running in ProcessInputBuffer"); + AVCODEC_LOGE("status changed, current status is not running in ProcessInputBuffer"); return; } ret = inputBufferQueueConsumer_->AcquireBuffer(filledInputBuffer); if (ret != Status::OK) { - MEDIA_LOG_E("ProcessInputBuffer AcquireBuffer fail"); + AVCODEC_LOGE("ProcessInputBuffer AcquireBuffer fail"); return; } if (state_ != CodecState::RUNNING) { - MEDIA_LOG_D("ProcessInputBuffer ReleaseBuffer name:MediaCodecInputBufferQueue"); + AVCODEC_LOGD("ProcessInputBuffer ReleaseBuffer name:MediaCodecInputBufferQueue"); inputBufferQueueConsumer_->ReleaseBuffer(filledInputBuffer); return; } @@ -602,7 +602,7 @@ void MediaCodec::ProcessInputBuffer() if (drmDecryptor_ != nullptr) { ret = DrmAudioCencDecrypt(filledInputBuffer); if (ret != Status::OK) { - MEDIA_LOG_E("MediaCodec DrmAudioCencDecrypt failed."); + AVCODEC_LOGE("MediaCodec DrmAudioCencDecrypt failed."); break; } } @@ -616,7 +616,7 @@ void MediaCodec::ProcessInputBuffer() if (ret != Status::OK) { inputBufferQueueConsumer_->ReleaseBuffer(filledInputBuffer); - MEDIA_LOG_E("Plugin queueInputBuffer failed."); + AVCODEC_LOGE("Plugin queueInputBuffer failed."); return; } eosStatus = filledInputBuffer->flag_; @@ -629,11 +629,11 @@ void MediaCodec::ProcessInputBuffer() int32_t MediaCodec::SetAudioDecryptionConfig(const sptr &keySession, const bool svpFlag) { - MEDIA_LOG_I("MediaCodec::SetAudioDecryptionConfig"); + AVCODEC_LOGI("MediaCodec::SetAudioDecryptionConfig"); if (drmDecryptor_ == nullptr) { drmDecryptor_ = std::make_shared(); } - FALSE_RETURN_V_MSG_E(drmDecryptor_ != nullptr, (int32_t)Status::ERROR_NO_MEMORY, "drmDecryptor is nullptr"); + CHECK_AND_RETURN_RET_LOG(drmDecryptor_ != nullptr, (int32_t)Status::ERROR_NO_MEMORY, "drmDecryptor is nullptr"); drmDecryptor_->SetDecryptionConfig(keySession, svpFlag); return (int32_t)Status::OK; } @@ -641,7 +641,7 @@ int32_t MediaCodec::SetAudioDecryptionConfig(const sptr &keySession, const bool svpFlag) { - MEDIA_LOG_I("MediaCodec::SetAudioDecryptionConfig, Not support"); + AVCODEC_LOGI("MediaCodec::SetAudioDecryptionConfig, Not support"); (void)keySession; (void)svpFlag; return (int32_t)Status::OK; @@ -664,19 +664,19 @@ Status MediaCodec::ChangePlugin(const std::string &mime, bool isEncoder, const s codecPlugin_ = CreatePlugin(mime, type); if (codecPlugin_ != nullptr) { ret = codecPlugin_->SetParameter(meta); - MEDIA_LOG_I("codecPlugin SetParameter ret %{public}d", ret); + AVCODEC_LOGI("codecPlugin SetParameter ret %{public}d", ret); ret = codecPlugin_->Init(); - MEDIA_LOG_I("codecPlugin Init ret %{public}d", ret); + AVCODEC_LOGI("codecPlugin Init ret %{public}d", ret); ret = codecPlugin_->SetDataCallback(this); - MEDIA_LOG_I("codecPlugin SetDataCallback ret %{public}d", ret); + AVCODEC_LOGI("codecPlugin SetDataCallback ret %{public}d", ret); PrepareInputBufferQueue(); PrepareOutputBufferQueue(); if (state_ == CodecState::RUNNING) { ret = codecPlugin_->Start(); - MEDIA_LOG_I("codecPlugin Start ret %{public}d", ret); + AVCODEC_LOGI("codecPlugin Start ret %{public}d", ret); } } else { - MEDIA_LOG_I("createPlugin failed"); + AVCODEC_LOGI("createPlugin failed"); return Status::ERROR_INVALID_PARAMETER; } return ret; @@ -684,7 +684,7 @@ Status MediaCodec::ChangePlugin(const std::string &mime, bool isEncoder, const s Status MediaCodec::HandleOutputBuffer(uint32_t eosStatus) { - MEDIA_LOG_D("HandleOutputBuffer enter"); + AVCODEC_LOGD("HandleOutputBuffer enter"); Status ret = Status::OK; std::shared_ptr emptyOutputBuffer; AVBufferConfig avBufferConfig; @@ -701,14 +701,14 @@ Status MediaCodec::HandleOutputBuffer(uint32_t eosStatus) } ret = codecPlugin_->QueueOutputBuffer(emptyOutputBuffer); if (ret == Status::ERROR_NOT_ENOUGH_DATA) { - MEDIA_LOG_D("QueueOutputBuffer ERROR_NOT_ENOUGH_DATA"); + AVCODEC_LOGD("QueueOutputBuffer ERROR_NOT_ENOUGH_DATA"); outputBufferQueueProducer_->PushBuffer(emptyOutputBuffer, false); } else if (ret == Status::ERROR_AGAIN) { - MEDIA_LOG_D("The output data is not completely read, needs to be read again"); + AVCODEC_LOGD("The output data is not completely read, needs to be read again"); } else if (ret == Status::END_OF_STREAM) { - MEDIA_LOG_D("HandleOutputBuffer END_OF_STREAM"); + AVCODEC_LOGD("HandleOutputBuffer END_OF_STREAM"); } else if (ret != Status::OK) { - MEDIA_LOG_E("QueueOutputBuffer error"); + AVCODEC_LOGE("QueueOutputBuffer error"); outputBufferQueueProducer_->PushBuffer(emptyOutputBuffer, false); } return ret; @@ -718,9 +718,9 @@ void MediaCodec::OnInputBufferDone(const std::shared_ptr &inputBuffer) { MediaAVCodec::AVCodecTrace trace("MediaCodec::OnInputBufferDone"); Status ret = inputBufferQueueConsumer_->ReleaseBuffer(inputBuffer); - MEDIA_LOG_D("0x%{public}06" PRIXPTR " OnInputBufferDone, buffer->pts" PUBLIC_LOG_D64, + AVCODEC_LOGD("0x%{public}06" PRIXPTR " OnInputBufferDone, buffer->pts" PUBLIC_LOG_D64, FAKE_POINTER(this), inputBuffer->pts_); - FALSE_RETURN_MSG(ret == Status::OK, "OnInputBufferDone fail"); + CHECK_AND_RETURN_MSG(ret == Status::OK, "OnInputBufferDone fail"); } void MediaCodec::OnOutputBufferDone(const std::shared_ptr &outputBuffer) @@ -733,14 +733,14 @@ void MediaCodec::OnOutputBufferDone(const std::shared_ptr &outputBuffe if (mediaCodecCallback_) { mediaCodecCallback_->OnOutputBufferDone(outputBuffer); } - MEDIA_LOG_D("0x%{public}06" PRIXPTR " OnOutputBufferDone, buffer->pts" PUBLIC_LOG_D64, + AVCODEC_LOGD("0x%{public}06" PRIXPTR " OnOutputBufferDone, buffer->pts" PUBLIC_LOG_D64, FAKE_POINTER(this), outputBuffer->pts_); - FALSE_RETURN_MSG(ret == Status::OK, "OnOutputBufferDone fail"); + CHECK_AND_RETURN_MSG(ret == Status::OK, "OnOutputBufferDone fail"); } void MediaCodec::ClearBufferQueue() { - MEDIA_LOG_I("ClearBufferQueue called."); + AVCODEC_LOGI("ClearBufferQueue called."); if (inputBufferQueueProducer_ != nullptr) { for (auto &buffer : inputBufferVector_) { inputBufferQueueProducer_->DetachBuffer(buffer); @@ -760,7 +760,7 @@ void MediaCodec::ClearBufferQueue() void MediaCodec::ClearInputBuffer() { MediaAVCodec::AVCodecTrace trace("MediaCodec::ClearInputBuffer"); - MEDIA_LOG_D("ClearInputBuffer enter"); + AVCODEC_LOGD("ClearInputBuffer enter"); if (!inputBufferQueueConsumer_) { return; } @@ -769,7 +769,7 @@ void MediaCodec::ClearInputBuffer() while (ret == Status::OK) { ret = inputBufferQueueConsumer_->AcquireBuffer(filledInputBuffer); if (ret != Status::OK) { - MEDIA_LOG_I("clear input Buffer"); + AVCODEC_LOGI("clear input Buffer"); return; } inputBufferQueueConsumer_->ReleaseBuffer(filledInputBuffer); @@ -797,9 +797,9 @@ std::string MediaCodec::StateToString(CodecState state) void MediaCodec::OnDumpInfo(int32_t fd) { - MEDIA_LOG_D("MediaCodec::OnDumpInfo called."); + AVCODEC_LOGD("MediaCodec::OnDumpInfo called."); if (fd < 0) { - MEDIA_LOG_E("MediaCodec::OnDumpInfo fd is invalid."); + AVCODEC_LOGE("MediaCodec::OnDumpInfo fd is invalid."); return; } std::string dumpString; @@ -807,7 +807,7 @@ void MediaCodec::OnDumpInfo(int32_t fd) dumpString += "MediaCodec buffer size is:" + std::to_string(inputBufferQueue_->GetQueueSize()) + "\n"; int ret = write(fd, dumpString.c_str(), dumpString.size()); if (ret < 0) { - MEDIA_LOG_E("MediaCodec::OnDumpInfo write failed."); + AVCODEC_LOGE("MediaCodec::OnDumpInfo write failed."); return; } } diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/ffmpeg_decoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/ffmpeg_decoder_plugin.cpp index d71fca404..a74266fe8 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/ffmpeg_decoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/ffmpeg_decoder_plugin.cpp @@ -20,7 +20,6 @@ #include #include #include "osal/utils/util.h" -#include "common/log.h" #include "avcodec_log.h" #include "avcodec_codec_name.h" #include "meta/mime_type.h" @@ -85,7 +84,7 @@ void SetDefinition(size_t index, CodecPluginDef &definition, Capability &cap) AVCodecCodecName::AUDIO_DECODER_APE_NAME, definition, cap); break; default: - MEDIA_LOG_I("codec is not supported right now"); + AVCODEC_LOGI("codec is not supported right now"); } } diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp index 656946e16..d698e34b3 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp @@ -20,7 +20,6 @@ #include #include #include "avcodec_codec_name.h" -#include "common/log.h" #include "avcodec_log.h" #include "osal/utils/util.h" @@ -125,11 +124,11 @@ bool FFmpegAACEncoderPlugin::CheckSampleRate(const int sampleRate) bool FFmpegAACEncoderPlugin::CheckSampleFormat() { if (supportedSampleFormats.find(audioSampleFormat_) == supportedSampleFormats.end()) { - MEDIA_LOG_E("input sample format not supported,srcFmt_=%{public}d", (int32_t)srcFmt_); + AVCODEC_LOGE("input sample format not supported,srcFmt_=%{public}d", (int32_t)srcFmt_); return false; } AudioSampleFormat2AVSampleFormat(audioSampleFormat_, srcFmt_); - MEDIA_LOG_E("AUDIO_SAMPLE_FORMAT found,srcFmt:%{public}d to " + AVCODEC_LOGE("AUDIO_SAMPLE_FORMAT found,srcFmt:%{public}d to " "ffmpeg-srcFmt_:%{public}d ", (int32_t)audioSampleFormat_, (int32_t)srcFmt_); needResample_ = CheckResample(); @@ -142,7 +141,7 @@ bool FFmpegAACEncoderPlugin::CheckChannelLayout() static_cast(srcLayout_)); // channel layout not available if (av_get_channel_layout_nb_channels(ffmpegChlayout) != channels_) { - MEDIA_LOG_E("channel layout channels mismatch"); + AVCODEC_LOGE("channel layout channels mismatch"); return false; } return true; @@ -151,7 +150,7 @@ bool FFmpegAACEncoderPlugin::CheckChannelLayout() bool FFmpegAACEncoderPlugin::CheckBitRate() const { if (bitRate_ < AAC_MIN_BIT_RATE || bitRate_ > AAC_MAX_BIT_RATE) { - MEDIA_LOG_E("parameter bit_rate illegal"); + AVCODEC_LOGE("parameter bit_rate illegal"); return false; } return true; @@ -160,27 +159,27 @@ bool FFmpegAACEncoderPlugin::CheckBitRate() const bool FFmpegAACEncoderPlugin::CheckFormat() { if (!CheckSampleFormat()) { - MEDIA_LOG_E("sampleFormat not supported"); + AVCODEC_LOGE("sampleFormat not supported"); return false; } if (!CheckBitRate()) { - MEDIA_LOG_E("bitRate not supported"); + AVCODEC_LOGE("bitRate not supported"); return false; } if (!CheckSampleRate(sampleRate_)) { - MEDIA_LOG_E("sample rate not supported"); + AVCODEC_LOGE("sample rate not supported"); return false; } if (channels_ < MIN_CHANNELS || channels_ > MAX_CHANNELS || channels_ == INVALID_CHANNELS) { - MEDIA_LOG_E("channels not supported"); + AVCODEC_LOGE("channels not supported"); return false; } if (!CheckChannelLayout()) { - MEDIA_LOG_E("channelLayout not supported"); + AVCODEC_LOGE("channelLayout not supported"); return false; } @@ -201,7 +200,7 @@ bool FFmpegAACEncoderPlugin::AudioSampleFormat2AVSampleFormat(const AudioSampleF }; // 使用迭代器遍历 unordered_map for (auto itM = formatTable.begin(); itM != formatTable.end(); ++itM) { - MEDIA_LOG_E("formatTable key:%{public}d Value:%{public}d ", (int32_t)itM->first, (int32_t)itM->second); + AVCODEC_LOGE("formatTable key:%{public}d Value:%{public}d ", (int32_t)itM->first, (int32_t)itM->second); } auto it = formatTable.find(audioFmt); @@ -209,7 +208,7 @@ bool FFmpegAACEncoderPlugin::AudioSampleFormat2AVSampleFormat(const AudioSampleF fmt = it->second; return true; } - MEDIA_LOG_E("AudioSampleFormat2AVSampleFormat fail, from fmt:%{public}d to " + AVCODEC_LOGE("AudioSampleFormat2AVSampleFormat fail, from fmt:%{public}d to " "fmt:%{public}d", (int32_t)audioFmt, (int32_t)fmt); return false; @@ -217,36 +216,36 @@ bool FFmpegAACEncoderPlugin::AudioSampleFormat2AVSampleFormat(const AudioSampleF Status FFmpegAACEncoderPlugin::Init() { - MEDIA_LOG_I("Init enter"); + AVCODEC_LOGI("Init enter"); return Status::OK; } Status FFmpegAACEncoderPlugin::Start() { - MEDIA_LOG_I("Start enter"); + AVCODEC_LOGI("Start enter"); Status status = AllocateContext("aac"); if (status != Status::OK) { - MEDIA_LOG_D("Allocat aac context failed, status = %{public}d", status); + AVCODEC_LOGD("Allocat aac context failed, status = %{public}d", status); return status; } if (!CheckFormat()) { - MEDIA_LOG_D("Format check failed."); + AVCODEC_LOGD("Format check failed."); return Status::ERROR_INVALID_PARAMETER; } status = InitContext(); if (status != Status::OK) { - MEDIA_LOG_D("Init context failed, status = %{public}d", status); + AVCODEC_LOGD("Init context failed, status = %{public}d", status); return status; } status = OpenContext(); if (status != Status::OK) { - MEDIA_LOG_D("Open context failed, status = %{public}d", status); + AVCODEC_LOGD("Open context failed, status = %{public}d", status); return status; } status = InitFrame(); if (status != Status::OK) { - MEDIA_LOG_D("Init frame failed, status = %{public}d", status); + AVCODEC_LOGD("Init frame failed, status = %{public}d", status); return status; } return Status::OK; @@ -259,7 +258,7 @@ Status FFmpegAACEncoderPlugin::QueueInputBuffer(const std::shared_ptr return Status::ERROR_INVALID_DATA; } if (memory->GetSize() == 0 && !(inputBuffer->flag_ & BUFFER_FLAG_EOS)) { - MEDIA_LOG_E("size is 0, but flag is not 1"); + AVCODEC_LOGE("size is 0, but flag is not 1"); return Status::ERROR_INVALID_DATA; } Status ret; @@ -272,7 +271,7 @@ Status FFmpegAACEncoderPlugin::QueueInputBuffer(const std::shared_ptr if (ret == Status::OK) { std::lock_guard l(bufferMetaMutex_); if (inputBuffer->meta_ == nullptr) { - MEDIA_LOG_E("encoder input buffer or meta is nullptr"); + AVCODEC_LOGE("encoder input buffer or meta is nullptr"); return Status::ERROR_INVALID_DATA; } bufferMeta_ = inputBuffer->meta_; @@ -286,7 +285,7 @@ Status FFmpegAACEncoderPlugin::QueueInputBuffer(const std::shared_ptr Status FFmpegAACEncoderPlugin::QueueOutputBuffer(std::shared_ptr &outputBuffer) { if (!outputBuffer) { - MEDIA_LOG_E("queue out buffer is nullptr."); + AVCODEC_LOGE("queue out buffer is nullptr."); return Status::ERROR_INVALID_PARAMETER; } std::lock_guard lock(avMutex_); @@ -305,25 +304,25 @@ Status FFmpegAACEncoderPlugin::ReceivePacketSucc(std::shared_ptr &outB std::string header; GetAdtsHeader(header, headerSize, avCodecContext_, avPacket_->size); if (headerSize == 0) { - MEDIA_LOG_E("Get header failed."); + AVCODEC_LOGE("Get header failed."); return Status::ERROR_UNKNOWN; } int32_t writeBytes = memory->Write( reinterpret_cast(const_cast(header.c_str())), headerSize, 0); if (writeBytes < headerSize) { - MEDIA_LOG_E("Write header failed"); + AVCODEC_LOGE("Write header failed"); return Status::ERROR_UNKNOWN; } int32_t outputSize = avPacket_->size + headerSize; if (memory->GetCapacity() < outputSize) { - MEDIA_LOG_E("Output buffer capacity is not enough"); + AVCODEC_LOGE("Output buffer capacity is not enough"); return Status::ERROR_NO_MEMORY; } auto len = memory->Write(avPacket_->data, avPacket_->size, headerSize); if (len < avPacket_->size) { - MEDIA_LOG_E("write packet data failed, len = %{public}d", len); + AVCODEC_LOGE("write packet data failed, len = %{public}d", len); return Status::ERROR_UNKNOWN; } @@ -339,23 +338,23 @@ Status FFmpegAACEncoderPlugin::ReceivePacketSucc(std::shared_ptr &outB Status FFmpegAACEncoderPlugin::ReceiveBuffer(std::shared_ptr &outBuffer) { - MEDIA_LOG_D("ReceiveBuffer enter"); + AVCODEC_LOGD("ReceiveBuffer enter"); (void)memset_s(avPacket_.get(), sizeof(AVPacket), 0, sizeof(AVPacket)); auto ret = avcodec_receive_packet(avCodecContext_.get(), avPacket_.get()); Status status; if (ret >= 0) { - MEDIA_LOG_D("receive one packet"); + AVCODEC_LOGD("receive one packet"); status = ReceivePacketSucc(outBuffer); } else if (ret == AVERROR_EOF) { outBuffer->flag_ = BUFFER_FLAG_EOS; avcodec_flush_buffers(avCodecContext_.get()); status = Status::END_OF_STREAM; - MEDIA_LOG_E("ReceiveBuffer EOF"); + AVCODEC_LOGE("ReceiveBuffer EOF"); } else if (ret == AVERROR(EAGAIN)) { status = Status::ERROR_NOT_ENOUGH_DATA; - MEDIA_LOG_E("ReceiveBuffer EAGAIN"); + AVCODEC_LOGE("ReceiveBuffer EAGAIN"); } else { - MEDIA_LOG_E("audio encoder receive unknow error: %{public}s", OSAL::AVStrError(ret).c_str()); + AVCODEC_LOGE("audio encoder receive unknow error: %{public}s", OSAL::AVStrError(ret).c_str()); status = Status::ERROR_UNKNOWN; } av_packet_unref(avPacket_.get()); @@ -366,7 +365,7 @@ Status FFmpegAACEncoderPlugin::SendOutputBuffer(std::shared_ptr &outpu { Status status = SendFrameToFfmpeg(); if (status == Status::ERROR_NOT_ENOUGH_DATA) { - MEDIA_LOG_D("SendFrameToFfmpeg no one frame data"); + AVCODEC_LOGD("SendFrameToFfmpeg no one frame data"); // last frame mark eos if (outputBuffer->flag_ & BUFFER_FLAG_EOS) { dataCallback_->OnOutputBufferDone(outBuffer_); @@ -379,7 +378,7 @@ Status FFmpegAACEncoderPlugin::SendOutputBuffer(std::shared_ptr &outpu { std::lock_guard l(bufferMetaMutex_); if (outBuffer_ == nullptr) { - MEDIA_LOG_E("SendOutputBuffer ERROR_NULL_POINTER"); + AVCODEC_LOGE("SendOutputBuffer ERROR_NULL_POINTER"); return Status::ERROR_NULL_POINTER; } outBuffer_->meta_ = bufferMeta_; @@ -387,21 +386,21 @@ Status FFmpegAACEncoderPlugin::SendOutputBuffer(std::shared_ptr &outpu int32_t fifoSize = av_audio_fifo_size(fifo_); if (fifoSize >= avCodecContext_->frame_size) { outputBuffer->flag_ = 0; // not eos - MEDIA_LOG_D("fifoSize:%{public}d need another encoder", fifoSize); + AVCODEC_LOGD("fifoSize:%{public}d need another encoder", fifoSize); dataCallback_->OnOutputBufferDone(outBuffer_); return Status::ERROR_AGAIN; } dataCallback_->OnOutputBufferDone(outBuffer_); return Status::OK; } else { - MEDIA_LOG_E("SendOutputBuffer-ReceiveBuffer error"); + AVCODEC_LOGE("SendOutputBuffer-ReceiveBuffer error"); } return status; } Status FFmpegAACEncoderPlugin::Reset() { - MEDIA_LOG_I("Reset enter"); + AVCODEC_LOGI("Reset enter"); std::lock_guard lock(avMutex_); auto ret = CloseCtxLocked(); avCodecContext_.reset(); @@ -411,7 +410,7 @@ Status FFmpegAACEncoderPlugin::Reset() Status FFmpegAACEncoderPlugin::Release() { - MEDIA_LOG_I("Release enter"); + AVCODEC_LOGI("Release enter"); std::lock_guard lock(avMutex_); auto ret = CloseCtxLocked(); avCodecContext_.reset(); @@ -420,7 +419,7 @@ Status FFmpegAACEncoderPlugin::Release() Status FFmpegAACEncoderPlugin::Flush() { - MEDIA_LOG_I("Flush enter"); + AVCODEC_LOGI("Flush enter"); std::lock_guard lock(avMutex_); if (avCodecContext_ != nullptr) { avcodec_flush_buffers(avCodecContext_.get()); @@ -435,7 +434,7 @@ Status FFmpegAACEncoderPlugin::Flush() Status FFmpegAACEncoderPlugin::ReAllocateContext() { if (!codecContextValid_) { - MEDIA_LOG_D("Old avcodec context not valid, no need to reallocate"); + AVCODEC_LOGD("Old avcodec context not valid, no need to reallocate"); return Status::OK; } @@ -453,7 +452,7 @@ Status FFmpegAACEncoderPlugin::ReAllocateContext() auto res = avcodec_open2(tmpContext.get(), avCodec_.get(), nullptr); if (res != 0) { - MEDIA_LOG_E("avcodec reopen error %{public}s", OSAL::AVStrError(res).c_str()); + AVCODEC_LOGE("avcodec reopen error %{public}s", OSAL::AVStrError(res).c_str()); return Status::ERROR_UNKNOWN; } avCodecContext_ = tmpContext; @@ -504,17 +503,17 @@ Status FFmpegAACEncoderPlugin::OpenContext() { { std::unique_lock lock(avMutex_); - MEDIA_LOG_I("avCodecContext_->channels " PUBLIC_LOG_D32, avCodecContext_->channels); - MEDIA_LOG_I("avCodecContext_->sample_rate " PUBLIC_LOG_D32, avCodecContext_->sample_rate); - MEDIA_LOG_I("avCodecContext_->bit_rate " PUBLIC_LOG_D64, avCodecContext_->bit_rate); - MEDIA_LOG_I("avCodecContext_->channel_layout " PUBLIC_LOG_D64, avCodecContext_->channel_layout); - MEDIA_LOG_I("avCodecContext_->sample_fmt " PUBLIC_LOG_D32, + AVCODEC_LOGI("avCodecContext_->channels " PUBLIC_LOG_D32, avCodecContext_->channels); + AVCODEC_LOGI("avCodecContext_->sample_rate " PUBLIC_LOG_D32, avCodecContext_->sample_rate); + AVCODEC_LOGI("avCodecContext_->bit_rate " PUBLIC_LOG_D64, avCodecContext_->bit_rate); + AVCODEC_LOGI("avCodecContext_->channel_layout " PUBLIC_LOG_D64, avCodecContext_->channel_layout); + AVCODEC_LOGI("avCodecContext_->sample_fmt " PUBLIC_LOG_D32, static_cast(*(avCodec_.get()->sample_fmts))); - MEDIA_LOG_I("avCodecContext_ old srcFmt_ " PUBLIC_LOG_D32, static_cast(srcFmt_)); - MEDIA_LOG_I("avCodecContext_->codec_id " PUBLIC_LOG_D32, static_cast(avCodec_.get()->id)); + AVCODEC_LOGI("avCodecContext_ old srcFmt_ " PUBLIC_LOG_D32, static_cast(srcFmt_)); + AVCODEC_LOGI("avCodecContext_->codec_id " PUBLIC_LOG_D32, static_cast(avCodec_.get()->id)); auto res = avcodec_open2(avCodecContext_.get(), avCodec_.get(), nullptr); if (res != 0) { - MEDIA_LOG_E("avcodec open error %{public}s", OSAL::AVStrError(res).c_str()); + AVCODEC_LOGE("avcodec open error %{public}s", OSAL::AVStrError(res).c_str()); return Status::ERROR_UNKNOWN; } av_log_set_level(AV_LOG_DEBUG); @@ -522,7 +521,7 @@ Status FFmpegAACEncoderPlugin::OpenContext() codecContextValid_ = true; } if (avCodecContext_->frame_size <= 0) { - MEDIA_LOG_E("frame size invalid"); + AVCODEC_LOGE("frame size invalid"); } int32_t destSamplesPerFrame = (avCodecContext_->frame_size > (avCodecContext_->sample_rate / FRAMES_PER_SECOND)) ? avCodecContext_->frame_size : (avCodecContext_->sample_rate / FRAMES_PER_SECOND); @@ -538,7 +537,7 @@ Status FFmpegAACEncoderPlugin::OpenContext() }; resample_ = std::make_shared(); if (resample_->Init(resamplePara) != Status::OK) { - MEDIA_LOG_E("Resmaple init failed."); + AVCODEC_LOGE("Resmaple init failed."); return Status::ERROR_UNKNOWN; } } @@ -555,49 +554,49 @@ bool FFmpegAACEncoderPlugin::CheckResample() const return false; } } - MEDIA_LOG_I("CheckResample need resample"); + AVCODEC_LOGI("CheckResample need resample"); return true; } Status FFmpegAACEncoderPlugin::GetMetaData(const std::shared_ptr &meta) { int32_t type; - MEDIA_LOG_I("GetMetaData enter"); + AVCODEC_LOGI("GetMetaData enter"); if (meta->Get(type)) { aacName_ = (type == 1 ? "aac" : "aac_latm"); } if (meta->Get(channels_)) { if (channels_ < MIN_CHANNELS || channels_ > MAX_CHANNELS) { - MEDIA_LOG_E("AUDIO_CHANNEL_COUNT error"); + AVCODEC_LOGE("AUDIO_CHANNEL_COUNT error"); return Status::ERROR_INVALID_PARAMETER; } } else { - MEDIA_LOG_E("no AUDIO_CHANNEL_COUNT"); + AVCODEC_LOGE("no AUDIO_CHANNEL_COUNT"); return Status::ERROR_INVALID_PARAMETER; } if (!meta->Get(sampleRate_)) { - MEDIA_LOG_E("no AUDIO_SAMPLE_RATE"); + AVCODEC_LOGE("no AUDIO_SAMPLE_RATE"); return Status::ERROR_INVALID_PARAMETER; } if (!meta->Get(bitRate_)) { - MEDIA_LOG_E("no MEDIA_BITRATE, set to 32k"); + AVCODEC_LOGE("no MEDIA_BITRATE, set to 32k"); bitRate_ = AAC_DEFAULT_BIT_RATE; } if (meta->Get(audioSampleFormat_)) { - MEDIA_LOG_D("AUDIO_SAMPLE_FORMAT found, srcFmt:%{public}d", audioSampleFormat_); + AVCODEC_LOGD("AUDIO_SAMPLE_FORMAT found, srcFmt:%{public}d", audioSampleFormat_); } else { - MEDIA_LOG_E("no AUDIO_SAMPLE_FORMAT"); + AVCODEC_LOGE("no AUDIO_SAMPLE_FORMAT"); return Status::ERROR_INVALID_PARAMETER; } if (meta->Get(maxInputSize_)) { - MEDIA_LOG_I("maxInputSize: %{public}d", maxInputSize_); + AVCODEC_LOGI("maxInputSize: %{public}d", maxInputSize_); } if (meta->Get(srcLayout_)) { - MEDIA_LOG_I("srcLayout_: " PUBLIC_LOG_U64, srcLayout_); + AVCODEC_LOGI("srcLayout_: " PUBLIC_LOG_U64, srcLayout_); } else { auto iter = channelLayoutMap.find(channels_); if (iter == channelLayoutMap.end()) { - MEDIA_LOG_E("channel layout not found, channels: %{public}d", channels_); + AVCODEC_LOGE("channel layout not found, channels: %{public}d", channels_); return Status::ERROR_UNKNOWN; } else { srcLayout_ = static_cast(iter->second); @@ -608,11 +607,11 @@ Status FFmpegAACEncoderPlugin::GetMetaData(const std::shared_ptr &meta) Status FFmpegAACEncoderPlugin::SetParameter(const std::shared_ptr &meta) { - MEDIA_LOG_I("SetParameter enter"); + AVCODEC_LOGI("SetParameter enter"); std::lock_guard lock(parameterMutex_); Status ret = GetMetaData(meta); if (!CheckFormat()) { - MEDIA_LOG_E("CheckFormat fail"); + AVCODEC_LOGE("CheckFormat fail"); return Status::ERROR_INVALID_PARAMETER; } audioParameter_ = *meta; @@ -626,7 +625,7 @@ Status FFmpegAACEncoderPlugin::GetParameter(std::shared_ptr &meta) maxInputSize_ = INPUT_BUFFER_SIZE_DEFAULT; } maxOutputSize_ = OUTPUT_BUFFER_SIZE_DEFAULT; - MEDIA_LOG_I("GetParameter maxInputSize_: %{public}d", maxInputSize_); + AVCODEC_LOGI("GetParameter maxInputSize_: %{public}d", maxInputSize_); // add codec meta audioParameter_.Set(maxInputSize_); audioParameter_.Set(maxOutputSize_); @@ -636,20 +635,20 @@ Status FFmpegAACEncoderPlugin::GetParameter(std::shared_ptr &meta) Status FFmpegAACEncoderPlugin::InitFrame() { - MEDIA_LOG_I("InitFrame enter"); + AVCODEC_LOGI("InitFrame enter"); cachedFrame_->nb_samples = avCodecContext_->frame_size; cachedFrame_->format = avCodecContext_->sample_fmt; cachedFrame_->channel_layout = avCodecContext_->channel_layout; cachedFrame_->channels = avCodecContext_->channels; int ret = av_frame_get_buffer(cachedFrame_.get(), 0); if (ret < 0) { - MEDIA_LOG_E("Get frame buffer failed: %{public}s", OSAL::AVStrError(ret).c_str()); + AVCODEC_LOGE("Get frame buffer failed: %{public}s", OSAL::AVStrError(ret).c_str()); return Status::ERROR_NO_MEMORY; } if (!(fifo_ = av_audio_fifo_alloc(avCodecContext_->sample_fmt, avCodecContext_->channels, cachedFrame_->nb_samples))) { - MEDIA_LOG_E("Could not allocate FIFO"); + AVCODEC_LOGE("Could not allocate FIFO"); } return Status::OK; } @@ -658,18 +657,18 @@ Status FFmpegAACEncoderPlugin::SendEncoder(const std::shared_ptr &inpu { auto memory = inputBuffer->memory_; if (memory->GetSize() < 0) { - MEDIA_LOG_E("SendEncoder buffer size is less than 0. size : %{public}d", memory->GetSize()); + AVCODEC_LOGE("SendEncoder buffer size is less than 0. size : %{public}d", memory->GetSize()); return Status::ERROR_UNKNOWN; } if (memory->GetSize() > memory->GetCapacity()) { - MEDIA_LOG_E("send input buffer is > allocate size. size : " + AVCODEC_LOGE("send input buffer is > allocate size. size : " "%{public}d, allocate size : %{public}d", memory->GetSize(), memory->GetCapacity()); return Status::ERROR_UNKNOWN; } auto errCode = PcmFillFrame(inputBuffer); if (errCode != Status::OK) { - MEDIA_LOG_E("SendEncoder PcmFillFrame error"); + AVCODEC_LOGE("SendEncoder PcmFillFrame error"); return errCode; } return Status::OK; @@ -678,33 +677,33 @@ Status FFmpegAACEncoderPlugin::SendEncoder(const std::shared_ptr &inpu Status FFmpegAACEncoderPlugin::PushInFifo(const std::shared_ptr &inputBuffer) { if (!inputBuffer) { - MEDIA_LOG_D("inputBuffer is nullptr"); + AVCODEC_LOGD("inputBuffer is nullptr"); return Status::ERROR_INVALID_PARAMETER; } int ret = av_frame_make_writable(cachedFrame_.get()); if (ret != 0) { - MEDIA_LOG_D("Frame make writable failed: %{public}s", OSAL::AVStrError(ret).c_str()); + AVCODEC_LOGD("Frame make writable failed: %{public}s", OSAL::AVStrError(ret).c_str()); return Status::ERROR_UNKNOWN; } bool isEos = inputBuffer->flag_ & BUFFER_FLAG_EOS; if (!isEos) { auto status = SendEncoder(inputBuffer); if (status != Status::OK) { - MEDIA_LOG_E("input push in fifo fail"); + AVCODEC_LOGE("input push in fifo fail"); return status; } } else { - MEDIA_LOG_I("input eos"); + AVCODEC_LOGI("input eos"); } return Status::OK; } Status FFmpegAACEncoderPlugin::SendFrameToFfmpeg() { - MEDIA_LOG_D("SendFrameToFfmpeg enter"); + AVCODEC_LOGD("SendFrameToFfmpeg enter"); int32_t fifoSize = av_audio_fifo_size(fifo_); if (fifoSize < avCodecContext_->frame_size) { - MEDIA_LOG_D("fifoSize:%{public}d not enough", fifoSize); + AVCODEC_LOGD("fifoSize:%{public}d not enough", fifoSize); return Status::ERROR_NOT_ENOUGH_DATA; } cachedFrame_->nb_samples = avCodecContext_->frame_size; @@ -717,7 +716,7 @@ Status FFmpegAACEncoderPlugin::SendFrameToFfmpeg() int readRet = av_audio_fifo_read(fifo_, reinterpret_cast(cachedFrame_->data), avCodecContext_->frame_size); if (readRet < 0) { - MEDIA_LOG_E("fifo read error"); + AVCODEC_LOGE("fifo read error"); return Status::ERROR_UNKNOWN; } cachedFrame_->linesize[0] = readRet * av_get_bytes_per_sample(avCodecContext_->sample_fmt); @@ -725,20 +724,20 @@ Status FFmpegAACEncoderPlugin::SendFrameToFfmpeg() if (ret == 0) { return Status::OK; } else if (ret == AVERROR(EAGAIN)) { - MEDIA_LOG_E("skip this frame because data not enough, msg:%{public}s", OSAL::AVStrError(ret).data()); + AVCODEC_LOGE("skip this frame because data not enough, msg:%{public}s", OSAL::AVStrError(ret).data()); return Status::ERROR_NOT_ENOUGH_DATA; } else if (ret == AVERROR_EOF) { - MEDIA_LOG_D("eos send frame, msg:%{public}s", OSAL::AVStrError(ret).data()); + AVCODEC_LOGD("eos send frame, msg:%{public}s", OSAL::AVStrError(ret).data()); return Status::END_OF_STREAM; } else { - MEDIA_LOG_D("Send frame unknown error: %{public}s", OSAL::AVStrError(ret).c_str()); + AVCODEC_LOGD("Send frame unknown error: %{public}s", OSAL::AVStrError(ret).c_str()); return Status::ERROR_UNKNOWN; } } Status FFmpegAACEncoderPlugin::PcmFillFrame(const std::shared_ptr &inputBuffer) { - MEDIA_LOG_D("PcmFillFrame enter, buffer->pts" PUBLIC_LOG_D64, inputBuffer->pts_); + AVCODEC_LOGD("PcmFillFrame enter, buffer->pts" PUBLIC_LOG_D64, inputBuffer->pts_); auto memory = inputBuffer->memory_; auto bytesPerSample = av_get_bytes_per_sample(avCodecContext_->sample_fmt); const uint8_t *srcBuffer = memory->GetAddr(); @@ -747,13 +746,13 @@ Status FFmpegAACEncoderPlugin::PcmFillFrame(const std::shared_ptr &inp size_t destBufferSize = srcBufferSize; if (needResample_ && resample_ != nullptr) { if (resample_->Convert(srcBuffer, srcBufferSize, destBuffer, destBufferSize) != Status::OK) { - MEDIA_LOG_E("Convert sample format failed"); + AVCODEC_LOGE("Convert sample format failed"); } } cachedFrame_->nb_samples = static_cast(destBufferSize) / (bytesPerSample * avCodecContext_->channels); if (!(inputBuffer->flag_ & BUFFER_FLAG_EOS) && cachedFrame_->nb_samples != avCodecContext_->frame_size) { - MEDIA_LOG_D("Input frame size not match, input samples: %{public}d, " + AVCODEC_LOGD("Input frame size not match, input samples: %{public}d, " "frame_size: %{public}d", cachedFrame_->nb_samples, avCodecContext_->frame_size); } @@ -770,14 +769,14 @@ Status FFmpegAACEncoderPlugin::PcmFillFrame(const std::shared_ptr &inp int32_t cacheSize = av_audio_fifo_size(fifo_); int32_t ret = av_audio_fifo_realloc(fifo_, cacheSize + cachedFrame_->nb_samples); if (ret < 0) { - MEDIA_LOG_E("realloc ret: %{public}d, cacheSize: %{public}d", ret, cacheSize); + AVCODEC_LOGE("realloc ret: %{public}d, cacheSize: %{public}d", ret, cacheSize); } - MEDIA_LOG_D("realloc nb_samples:%{public}d cacheSize:%{public}d channels:%{public}d", + AVCODEC_LOGD("realloc nb_samples:%{public}d cacheSize:%{public}d channels:%{public}d", cachedFrame_->nb_samples, cacheSize, avCodecContext_->channels); int32_t writeSamples = av_audio_fifo_write(fifo_, reinterpret_cast(cachedFrame_->data), cachedFrame_->nb_samples); if (writeSamples < cachedFrame_->nb_samples) { - MEDIA_LOG_E("write smaples: %{public}d, nb_samples: %{public}d", writeSamples, cachedFrame_->nb_samples); + AVCODEC_LOGE("write smaples: %{public}d, nb_samples: %{public}d", writeSamples, cachedFrame_->nb_samples); } return Status::OK; } @@ -797,7 +796,7 @@ Status FFmpegAACEncoderPlugin::Stop() outBuffer_.reset(); outBuffer_ = nullptr; } - MEDIA_LOG_I("Stop"); + AVCODEC_LOGI("Stop"); return ret; } @@ -816,7 +815,7 @@ Status FFmpegAACEncoderPlugin::CloseCtxLocked() if (avCodecContext_ != nullptr) { auto res = avcodec_close(avCodecContext_.get()); if (res != 0) { - MEDIA_LOG_E("avcodec close failed: %{public}s", OSAL::AVStrError(res).c_str()); + AVCODEC_LOGE("avcodec close failed: %{public}s", OSAL::AVStrError(res).c_str()); return Status::ERROR_UNKNOWN; } } diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/ffmpeg_encoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/ffmpeg_encoder_plugin.cpp index 3cb0834ca..8c3f22f97 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/ffmpeg_encoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/ffmpeg_encoder_plugin.cpp @@ -21,7 +21,6 @@ #include #include #include "osal/utils/util.h" -#include "common/log.h" #include "avcodec_log.h" #include "avcodec_codec_name.h" #include "meta/mime_type.h" @@ -59,7 +58,7 @@ void SetDefinition(size_t index, CodecPluginDef &definition, Capability &cap) }); break; default: - MEDIA_LOG_I("codec is not supported right now"); + AVCODEC_LOGI("codec is not supported right now"); } } diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp index 41ae9a1cb..9717c14f4 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ #include "ffmpeg_convert.h" -#include "common/log.h" +#include "avcodec_log.h" #include "securec.h" namespace { @@ -38,18 +38,18 @@ Status Resample::Init(const ResamplePara &resamplePara) resamplePara_.destSamplesPerFrame, resamplePara_.destFmt, 0); auto swrContext = swr_alloc(); if (swrContext == nullptr) { - MEDIA_LOG_E("cannot allocate swr context"); + AVCODEC_LOGE("cannot allocate swr context"); return Status::ERROR_NO_MEMORY; } int32_t error = swr_alloc_set_opts2(&swrContext, &resamplePara_.channelLayout, resamplePara_.destFmt, resamplePara_.sampleRate, &resamplePara_.channelLayout, resamplePara_.srcFfFmt, resamplePara_.sampleRate, 0, nullptr); if (error < 0) { - MEDIA_LOG_E("swr init error"); + AVCODEC_LOGE("swr init error"); return Status::ERROR_UNKNOWN; } if (swr_init(swrContext) != 0) { - MEDIA_LOG_E("swr init error"); + AVCODEC_LOGE("swr init error"); return Status::ERROR_UNKNOWN; } swrCtx_ = std::shared_ptr(swrContext, [](SwrContext *ptr) { @@ -67,18 +67,18 @@ Status Resample::InitSwrContext(const ResamplePara &resamplePara) resamplePara_ = resamplePara; auto swrContext = swr_alloc(); if (swrContext == nullptr) { - MEDIA_LOG_E("cannot allocate swr context"); + AVCODEC_LOGE("cannot allocate swr context"); return Status::ERROR_NO_MEMORY; } int32_t error = swr_alloc_set_opts2(&swrContext, &resamplePara_.channelLayout, resamplePara_.destFmt, resamplePara_.sampleRate, &resamplePara_.channelLayout, resamplePara_.srcFfFmt, resamplePara_.sampleRate, 0, nullptr); if (error < 0) { - MEDIA_LOG_E("swr init error"); + AVCODEC_LOGE("swr init error"); return Status::ERROR_UNKNOWN; } if (swr_init(swrContext) != 0) { - MEDIA_LOG_E("swr init error"); + AVCODEC_LOGE("swr init error"); return Status::ERROR_UNKNOWN; } swrCtx_ = std::shared_ptr(swrContext, [](SwrContext *ptr) { @@ -93,26 +93,26 @@ Status Resample::Convert(const uint8_t *srcBuffer, const size_t srcLength, uint8 { #if defined(_WIN32) || !defined(OHOS_LITE) if (resamplePara_.bitsPerSample == 8) { // 8 - FALSE_RETURN_V_MSG(resamplePara_.destFmt == AV_SAMPLE_FMT_S16, Status::ERROR_UNIMPLEMENTED, + CHECK_AND_RETURN_RET_LOG(resamplePara_.destFmt == AV_SAMPLE_FMT_S16, Status::ERROR_UNIMPLEMENTED, "resample 8bit to other format can not support"); destLength = srcLength * 2; // 2 resampleCache_.reserve(destLength); resampleCache_.assign(destLength, 0); for (size_t i{0}; i < destLength / 2; i++) { // 2 auto resCode = memcpy_s(&resampleCache_[0] + i * 2 + 1, sizeof(uint8_t), srcBuffer + i, 1); // 0 2 1 - FALSE_RETURN_V_MSG_E(resCode == EOK, Status::ERROR_INVALID_OPERATION, "Memcpy failed at 8 bits/sample."); + CHECK_AND_RETURN_RET_LOG(resCode == EOK, Status::ERROR_INVALID_OPERATION, "Memcpy failed at 8 bits/sample."); *(&resampleCache_[0] + i * 2 + 1) += 0x80; // 2 0x80 } destBuffer = resampleCache_.data(); } else if (resamplePara_.bitsPerSample == 24) { // 24 - FALSE_RETURN_V_MSG(resamplePara_.destFmt == AV_SAMPLE_FMT_S16, Status::ERROR_UNIMPLEMENTED, + CHECK_AND_RETURN_RET_LOG(resamplePara_.destFmt == AV_SAMPLE_FMT_S16, Status::ERROR_UNIMPLEMENTED, "resample 24bit to other format can not support"); destLength = srcLength / 3 * 2; // 3 2 resampleCache_.reserve(destLength); resampleCache_.assign(destLength, 0); for (size_t i = 0; i < destLength / 2; i++) { // 2 auto resCode = memcpy_s(&resampleCache_[0] + i * 2, sizeof(uint8_t) * 2, srcBuffer + i * 3 + 1, 2); // 2 3 1 - FALSE_RETURN_V_MSG_E(resCode == EOK, Status::ERROR_INVALID_OPERATION, "Memcpy failed at 24 bits/sample."); + CHECK_AND_RETURN_RET_LOG(resCode == EOK, Status::ERROR_INVALID_OPERATION, "Memcpy failed at 24 bits/sample."); } destBuffer = resampleCache_.data(); } else { @@ -128,7 +128,7 @@ Status Resample::Convert(const uint8_t *srcBuffer, const size_t srcLength, uint8 auto res = swr_convert(swrCtx_.get(), resampleChannelAddr_.data(), resamplePara_.destSamplesPerFrame, tmpInput.data(), samples); if (res < 0) { - MEDIA_LOG_E("resample input failed"); + AVCODEC_LOGE("resample input failed"); destLength = 0; } else { destBuffer = resampleCache_.data(); @@ -150,7 +150,7 @@ static std::string AVStrError(int errnum) Status Resample::ConvertFrame(AVFrame *outputFrame, const AVFrame *inputFrame) { if (outputFrame == nullptr || inputFrame == nullptr) { - MEDIA_LOG_E("Frame null pointer"); + AVCODEC_LOGE("Frame null pointer"); return Status::ERROR_NO_MEMORY; } @@ -160,7 +160,7 @@ Status Resample::ConvertFrame(AVFrame *outputFrame, const AVFrame *inputFrame) auto ret = swr_convert_frame(swrCtx_.get(), outputFrame, inputFrame); if (ret < 0) { - MEDIA_LOG_E("convert frame failed, %{public}s", AVStrError(ret).c_str()); + AVCODEC_LOGE("convert frame failed, %{public}s", AVStrError(ret).c_str()); return Status::ERROR_UNKNOWN; } return Status::OK; @@ -176,7 +176,7 @@ Status Scale::Init(const ScalePara &scalePara, uint8_t **dstData, int32_t *dstLi auto swsContext = sws_getContext(scalePara_.srcWidth, scalePara_.srcHeight, scalePara_.srcFfFmt, scalePara_.dstWidth, scalePara_.dstHeight, scalePara_.dstFfFmt, SWS_FAST_BILINEAR, nullptr, nullptr, nullptr); - FALSE_RETURN_V_MSG_E(swsContext != nullptr, Status::ERROR_UNKNOWN, "sws_getContext fail"); + CHECK_AND_RETURN_RET_LOG(swsContext != nullptr, Status::ERROR_UNKNOWN, "sws_getContext fail"); swsCtx_ = std::shared_ptr(swsContext, [](struct SwsContext *ptr) { if (ptr != nullptr) { sws_freeContext(ptr); @@ -184,14 +184,14 @@ Status Scale::Init(const ScalePara &scalePara, uint8_t **dstData, int32_t *dstLi }); auto ret = av_image_alloc(dstData, dstLineSize, scalePara_.dstWidth, scalePara_.dstHeight, scalePara_.dstFfFmt, scalePara_.align); - FALSE_RETURN_V_MSG_E(ret >= 0, Status::ERROR_UNKNOWN, "could not allocate destination image" PUBLIC_LOG_D32, ret); - MEDIA_LOG_D("av_image_alloc call, ret: " PUBLIC_LOG_U32 "dstPixelFormat_: " PUBLIC_LOG_U32, ret, + CHECK_AND_RETURN_RET_LOG(ret >= 0, Status::ERROR_UNKNOWN, "could not allocate destination image" PUBLIC_LOG_D32, ret); + AVCODEC_LOGD("av_image_alloc call, ret: " PUBLIC_LOG_U32 "dstPixelFormat_: " PUBLIC_LOG_U32, ret, scalePara_.dstFfFmt); // av_image_alloc can make sure that dstLineSize last element is 0 for (int32_t i = 0; dstLineSize[i] > 0; i++) { - MEDIA_LOG_D("dstLineSize[" PUBLIC_LOG_D32 "]: " PUBLIC_LOG_D32, i, dstLineSize[i]); + AVCODEC_LOGD("dstLineSize[" PUBLIC_LOG_D32 "]: " PUBLIC_LOG_D32, i, dstLineSize[i]); if (dstData[i] && !dstLineSize[i]) { - MEDIA_LOG_E("scale frame is broken, i: " PUBLIC_LOG_D32, i); + AVCODEC_LOGE("scale frame is broken, i: " PUBLIC_LOG_D32, i); return Status::ERROR_UNKNOWN; } } @@ -201,7 +201,7 @@ Status Scale::Init(const ScalePara &scalePara, uint8_t **dstData, int32_t *dstLi Status Scale::Convert(uint8_t **srcData, const int32_t *srcLineSize, uint8_t **dstData, int32_t *dstLineSize) { auto res = sws_scale(swsCtx_.get(), srcData, srcLineSize, 0, scalePara_.srcHeight, dstData, dstLineSize); - FALSE_RETURN_V_MSG_E(res >= 0, Status::ERROR_UNKNOWN, "sws_scale fail: " PUBLIC_LOG_D32, res); + CHECK_AND_RETURN_RET_LOG(res >= 0, Status::ERROR_UNKNOWN, "sws_scale fail: " PUBLIC_LOG_D32, res); return Status::OK; } #endif -- Gitee From 051f56076658c77a42bbb7381dd8f1a19ef9d23c Mon Sep 17 00:00:00 2001 From: hanwenzhao Date: Tue, 9 Jul 2024 00:15:48 +0800 Subject: [PATCH 24/25] patch Signed-off-by: hanwenzhao Change-Id: Ic3ddc0ae18d5863680cadece492a1fb67dba6ba3 --- .../native/avdemuxer/avdemuxer_impl.cpp | 2 +- frameworks/native/avmuxer/avmuxer_impl.cpp | 2 +- frameworks/native/avsource/avsource_impl.cpp | 2 +- .../capi/avdemuxer/native_avdemuxer.cpp | 2 +- .../native/capi/avmuxer/native_avmuxer.cpp | 2 +- .../native/capi/avsource/native_avsource.cpp | 2 +- services/dfx/include/avcodec_log.h | 6 +- services/media_engine/modules/BUILD.gn | 5 +- .../modules/media_codec/media_codec.cpp | 92 +++++++++---------- .../aac/ffmpeg_aac_encoder_plugin.cpp | 18 ++-- .../ffmpeg_adapter/common/ffmpeg_convert.cpp | 5 +- .../common/ffmpeg_converter.cpp | 2 +- services/utils/include/block_queue.h | 2 +- 13 files changed, 75 insertions(+), 67 deletions(-) diff --git a/frameworks/native/avdemuxer/avdemuxer_impl.cpp b/frameworks/native/avdemuxer/avdemuxer_impl.cpp index c6e9dddda..ea6755380 100644 --- a/frameworks/native/avdemuxer/avdemuxer_impl.cpp +++ b/frameworks/native/avdemuxer/avdemuxer_impl.cpp @@ -26,7 +26,7 @@ #include "avcodec_errors.h" namespace { - constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER_MUXER, "AVDemuxerImpl"}; + constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER, "AVDemuxerImpl"}; } namespace OHOS { diff --git a/frameworks/native/avmuxer/avmuxer_impl.cpp b/frameworks/native/avmuxer/avmuxer_impl.cpp index 4a9015bae..ad0e10484 100644 --- a/frameworks/native/avmuxer/avmuxer_impl.cpp +++ b/frameworks/native/avmuxer/avmuxer_impl.cpp @@ -22,7 +22,7 @@ #include "avcodec_errors.h" namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER_MUXER, "AVMuxerImpl"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_MUXER, "AVMuxerImpl"}; } namespace OHOS { diff --git a/frameworks/native/avsource/avsource_impl.cpp b/frameworks/native/avsource/avsource_impl.cpp index 230fca300..723205b98 100644 --- a/frameworks/native/avsource/avsource_impl.cpp +++ b/frameworks/native/avsource/avsource_impl.cpp @@ -24,7 +24,7 @@ #include "common/status.h" namespace { - constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER_MUXER, "AVSourceImpl"}; + constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER, "AVSourceImpl"}; } namespace OHOS { diff --git a/frameworks/native/capi/avdemuxer/native_avdemuxer.cpp b/frameworks/native/capi/avdemuxer/native_avdemuxer.cpp index 768d5c020..cfcc51075 100644 --- a/frameworks/native/capi/avdemuxer/native_avdemuxer.cpp +++ b/frameworks/native/capi/avdemuxer/native_avdemuxer.cpp @@ -25,7 +25,7 @@ #include "native_object.h" #include "native_drm_common.h" namespace { - constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER_MUXER, "NativeAVDemuxer"}; + constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER, "NativeAVDemuxer"}; } using namespace OHOS::MediaAVCodec; diff --git a/frameworks/native/capi/avmuxer/native_avmuxer.cpp b/frameworks/native/capi/avmuxer/native_avmuxer.cpp index 7de459db5..528348253 100644 --- a/frameworks/native/capi/avmuxer/native_avmuxer.cpp +++ b/frameworks/native/capi/avmuxer/native_avmuxer.cpp @@ -21,7 +21,7 @@ #include "native_avmagic.h" namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER_MUXER, "NativeAVMuxer"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_MUXER, "NativeAVMuxer"}; } using namespace OHOS::Media; diff --git a/frameworks/native/capi/avsource/native_avsource.cpp b/frameworks/native/capi/avsource/native_avsource.cpp index a95ef1a4e..6acede7b3 100644 --- a/frameworks/native/capi/avsource/native_avsource.cpp +++ b/frameworks/native/capi/avsource/native_avsource.cpp @@ -24,7 +24,7 @@ #include "avbuffer.h" namespace { - constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER_MUXER, "NativeAVSource"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER, "NativeAVSource"}; } using namespace OHOS::MediaAVCodec; diff --git a/services/dfx/include/avcodec_log.h b/services/dfx/include/avcodec_log.h index 63c91c4fe..0455a9f0d 100644 --- a/services/dfx/include/avcodec_log.h +++ b/services/dfx/include/avcodec_log.h @@ -28,8 +28,10 @@ namespace MediaAVCodec { #define LOG_DOMAIN_HCODEC 0xD002B32 #undef LOG_DOMAIN_TEST #define LOG_DOMAIN_TEST 0xD002B36 -#undef LOG_DOMAIN_DEMUXER_MUXER -#define LOG_DOMAIN_DEMUXER_MUXER 0xD002B3A +#undef LOG_DOMAIN_DEMUXER +#define LOG_DOMAIN_DEMUXER 0xD002B3A +#undef LOG_DOMAIN_MUXER +#define LOG_DOMAIN_MUXER 0xD002B3B #ifndef AVCODEC_LOG_USE_NO_DICT_LOG #define AVCODEC_LOG(level, fmt, args...) \ diff --git a/services/media_engine/modules/BUILD.gn b/services/media_engine/modules/BUILD.gn index 369d55b50..85b3b0d02 100644 --- a/services/media_engine/modules/BUILD.gn +++ b/services/media_engine/modules/BUILD.gn @@ -80,7 +80,10 @@ ohos_shared_library("av_codec_media_engine_modules") { "source/source.cpp", ] - deps = [ "$av_codec_root_dir/services/engine/base:av_codec_codec_base" ] + deps = [ + "$av_codec_root_dir/services/dfx:av_codec_service_dfx", + "$av_codec_root_dir/services/engine/base:av_codec_codec_base" + ] public_configs = [ "$audio_framework_root_dir/frameworks/native/audiocapturer:audio_capturer_config" ] diff --git a/services/media_engine/modules/media_codec/media_codec.cpp b/services/media_engine/modules/media_codec/media_codec.cpp index 23cff3779..ef663ba9c 100644 --- a/services/media_engine/modules/media_codec/media_codec.cpp +++ b/services/media_engine/modules/media_codec/media_codec.cpp @@ -80,7 +80,7 @@ int32_t MediaCodec::Init(const std::string &mime, bool isEncoder) { AutoLock lock(stateMutex_); MediaAVCodec::AVCodecTrace trace("MediaCodec::Init"); - AVCODEC_LOGI("Init enter, mime: " PUBLIC_LOG_S, mime.c_str()); + AVCODEC_LOGI("Init enter, mime: %{public}s", mime.c_str()); if (state_ != CodecState::UNINITIALIZED) { AVCODEC_LOGE("Init failed, state = %{public}s .", StateToString(state_).data()); return (int32_t)Status::ERROR_INVALID_STATE; @@ -109,7 +109,7 @@ int32_t MediaCodec::Init(const std::string &mime, bool isEncoder) int32_t MediaCodec::Init(const std::string &name) { AutoLock lock(stateMutex_); - AVCODEC_LOGI("Init enter, name: " PUBLIC_LOG_S, name.c_str()); + AVCODEC_LOGI("Init enter, name: %{public}s", name.c_str()); AVCODEC_LOGI("MediaCodec::Init"); MediaAVCodec::AVCodecTrace trace("MediaCodec::Init"); if (state_ != CodecState::UNINITIALIZED) { @@ -141,11 +141,12 @@ int32_t MediaCodec::Configure(const std::shared_ptr &meta) AVCODEC_LOGI("MediaCodec::configure in"); AutoLock lock(stateMutex_); MediaAVCodec::AVCodecTrace trace("MediaCodec::Configure"); - CHECK_AND_RETURN_RET(state_ == CodecState::INITIALIZED, (int32_t)Status::ERROR_INVALID_STATE); + CHECK_AND_RETURN_RET_LOG(state_ == CodecState::INITIALIZED, (int32_t)Status::ERROR_INVALID_STATE, + "state is not INITIALIZED"); auto ret = codecPlugin_->SetParameter(meta); - CHECK_AND_RETURN_RET(ret == Status::OK, (int32_t)ret); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "SetParameter failed."); ret = codecPlugin_->SetDataCallback(this); - CHECK_AND_RETURN_RET(ret == Status::OK, (int32_t)ret); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "SetDataCallback failed."); state_ = CodecState::CONFIGURED; return (int32_t)Status::OK; } @@ -154,8 +155,8 @@ int32_t MediaCodec::SetOutputBufferQueue(const sptr &buff { AutoLock lock(stateMutex_); MediaAVCodec::AVCodecTrace trace("MediaCodec::SetOutputBufferQueue"); - CHECK_AND_RETURN_RET(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, - (int32_t)Status::ERROR_INVALID_STATE); + CHECK_AND_RETURN_RET_LOG(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, + (int32_t)Status::ERROR_INVALID_STATE, "state is not INITIALIZED or CONFIGURED"); outputBufferQueueProducer_ = bufferQueueProducer; isBufferMode_ = true; return (int32_t)Status::OK; @@ -164,21 +165,21 @@ int32_t MediaCodec::SetOutputBufferQueue(const sptr &buff int32_t MediaCodec::SetCodecCallback(const std::shared_ptr &codecCallback) { AutoLock lock(stateMutex_); - CHECK_AND_RETURN_RET(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, - (int32_t)Status::ERROR_INVALID_STATE); + CHECK_AND_RETURN_RET_LOG(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, + (int32_t)Status::ERROR_INVALID_STATE, "state != INITIALIZED and state != CONFIGURED"); CHECK_AND_RETURN_RET_LOG(codecCallback != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER, - "codecCallback is nullptr"); + "codecCallback is nullptr"); codecCallback_ = codecCallback; auto ret = codecPlugin_->SetDataCallback(this); - CHECK_AND_RETURN_RET(ret == Status::OK, (int32_t)ret); + CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "ret != Status::OK"); return (int32_t)Status::OK; } int32_t MediaCodec::SetCodecCallback(const std::shared_ptr &codecCallback) { AutoLock lock(stateMutex_); - CHECK_AND_RETURN_RET(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, - (int32_t)Status::ERROR_INVALID_STATE); + CHECK_AND_RETURN_RET_LOG(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, + (int32_t)Status::ERROR_INVALID_STATE, "state != INITIALIZED and state != CONFIGURED"); CHECK_AND_RETURN_RET_LOG(codecCallback != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER, "codecCallback is nullptr"); mediaCodecCallback_ = codecCallback; @@ -188,8 +189,8 @@ int32_t MediaCodec::SetCodecCallback(const std::shared_ptr surface) { AutoLock lock(stateMutex_); - CHECK_AND_RETURN_RET(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, - (int32_t)Status::ERROR_INVALID_STATE); + CHECK_AND_RETURN_RET_LOG(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, + (int32_t)Status::ERROR_INVALID_STATE, "state != INITIALIZED and state != CONFIGURED"); isSurfaceMode_ = true; return (int32_t)Status::OK; } @@ -199,9 +200,9 @@ int32_t MediaCodec::Prepare() AVCODEC_LOGI("Prepare enter"); AutoLock lock(stateMutex_); MediaAVCodec::AVCodecTrace trace("MediaCodec::Prepare"); - CHECK_AND_RETURN_RET(state_ != CodecState::PREPARED, (int32_t)Status::OK); - CHECK_AND_RETURN_RET(state_ == CodecState::CONFIGURED || state_ == CodecState::FLUSHED, - (int32_t)Status::ERROR_INVALID_STATE); + CHECK_AND_RETURN_RET_LOG(state_ != CodecState::PREPARED, (int32_t)Status::OK, "state != PREPARED"); + CHECK_AND_RETURN_RET_LOG(state_ == CodecState::CONFIGURED || state_ == CodecState::FLUSHED, + (int32_t)Status::ERROR_INVALID_STATE, "state != CONFIGURED and state != FLUSHED"); if (isBufferMode_ && isSurfaceMode_) { AVCODEC_LOGE("state error"); return (int32_t)Status::ERROR_UNKNOWN; @@ -225,7 +226,7 @@ int32_t MediaCodec::Prepare() sptr MediaCodec::GetInputBufferQueue() { AutoLock lock(stateMutex_); - CHECK_AND_RETURN_RET(state_ == CodecState::PREPARED, sptr()); + CHECK_AND_RETURN_RET_LOG(state_ == CodecState::PREPARED, sptr(), "state != PREPARED"); if (isSurfaceMode_) { return nullptr; } @@ -236,7 +237,7 @@ sptr MediaCodec::GetInputBufferQueue() sptr MediaCodec::GetInputSurface() { AutoLock lock(stateMutex_); - CHECK_AND_RETURN_RET(state_ == CodecState::PREPARED, nullptr); + CHECK_AND_RETURN_RET_LOG(state_ == CodecState::PREPARED, nullptr, "state != PREPARED"); if (isBufferMode_) { return nullptr; } @@ -249,9 +250,9 @@ int32_t MediaCodec::Start() AutoLock lock(stateMutex_); AVCODEC_LOGI("Start enter"); MediaAVCodec::AVCodecTrace trace("MediaCodec::Start"); - CHECK_AND_RETURN_RET(state_ != CodecState::RUNNING, (int32_t)Status::OK); - CHECK_AND_RETURN_RET(state_ == CodecState::PREPARED || state_ == CodecState::FLUSHED, - (int32_t)Status::ERROR_INVALID_STATE); + CHECK_AND_RETURN_RET_LOG(state_ != CodecState::RUNNING, (int32_t)Status::OK, "state != RUNNING"); + CHECK_AND_RETURN_RET_LOG(state_ == CodecState::PREPARED || state_ == CodecState::FLUSHED, + (int32_t)Status::ERROR_INVALID_STATE, "state != PREPARED and state != FLUSHED"); state_ = CodecState::STARTING; auto ret = codecPlugin_->Start(); CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "plugin start failed"); @@ -264,13 +265,13 @@ int32_t MediaCodec::Stop() AutoLock lock(stateMutex_); MediaAVCodec::AVCodecTrace trace("MediaCodec::Stop"); AVCODEC_LOGI("Stop enter"); - CHECK_AND_RETURN_RET(state_ != CodecState::PREPARED, (int32_t)Status::OK); + CHECK_AND_RETURN_RET_LOG(state_ != CodecState::PREPARED, (int32_t)Status::OK, "state != PREPARED"); if (state_ == CodecState::UNINITIALIZED || state_ == CodecState::STOPPING || state_ == CodecState::RELEASING) { AVCODEC_LOGD("Stop, state_=%{public}s", StateToString(state_).data()); return (int32_t)Status::OK; } - CHECK_AND_RETURN_RET(state_ == CodecState::RUNNING || state_ == CodecState::END_OF_STREAM || - state_ == CodecState::FLUSHED, (int32_t)Status::ERROR_INVALID_STATE); + CHECK_AND_RETURN_RET_LOG(state_ == CodecState::RUNNING || state_ == CodecState::END_OF_STREAM || + state_ == CodecState::FLUSHED, (int32_t)Status::ERROR_INVALID_STATE, "state != RUNNING, EOS or FLUSHED"); state_ = CodecState::STOPPING; auto ret = codecPlugin_->Stop(); AVCODEC_LOGI("codec Stop, state from %{public}s to Stop", StateToString(state_).data()); @@ -351,8 +352,8 @@ int32_t MediaCodec::Release() int32_t MediaCodec::NotifyEos() { AutoLock lock(stateMutex_); - CHECK_AND_RETURN_RET(state_ != CodecState::END_OF_STREAM, (int32_t)Status::OK); - CHECK_AND_RETURN_RET(state_ == CodecState::RUNNING, (int32_t)Status::ERROR_INVALID_STATE); + CHECK_AND_RETURN_RET_LOG(state_ != CodecState::END_OF_STREAM, (int32_t)Status::OK, "state not EOS"); + CHECK_AND_RETURN_RET_LOG(state_ == CodecState::RUNNING, (int32_t)Status::ERROR_INVALID_STATE, "state not RUNNING"); state_ = CodecState::END_OF_STREAM; return (int32_t)Status::OK; } @@ -360,9 +361,9 @@ int32_t MediaCodec::NotifyEos() int32_t MediaCodec::SetParameter(const std::shared_ptr ¶meter) { AutoLock lock(stateMutex_); - CHECK_AND_RETURN_RET(parameter != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER); - CHECK_AND_RETURN_RET(state_ != CodecState::UNINITIALIZED && state_ != CodecState::INITIALIZED && - state_ != CodecState::PREPARED, (int32_t)Status::ERROR_INVALID_STATE); + CHECK_AND_RETURN_RET_LOG(parameter != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER, "parameter is nullptr"); + CHECK_AND_RETURN_RET_LOG(state_ != CodecState::UNINITIALIZED && state_ != CodecState::INITIALIZED && + state_ != CodecState::PREPARED, (int32_t)Status::ERROR_INVALID_STATE, "state is invalid"); auto ret = codecPlugin_->SetParameter(parameter); CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "plugin set parameter failed"); return (int32_t)ret; @@ -383,8 +384,8 @@ int32_t MediaCodec::GetOutputFormat(std::shared_ptr ¶meter) AutoLock lock(stateMutex_); CHECK_AND_RETURN_RET_LOG(state_ != CodecState::UNINITIALIZED, (int32_t)Status::ERROR_INVALID_STATE, "status incorrect,get output format failed."); - CHECK_AND_RETURN_RET(codecPlugin_ != nullptr, (int32_t)Status::ERROR_INVALID_STATE); - CHECK_AND_RETURN_RET(parameter != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER); + CHECK_AND_RETURN_RET_LOG(codecPlugin_ != nullptr, (int32_t)Status::ERROR_INVALID_STATE, "codecPlugin_ is nullptr"); + CHECK_AND_RETURN_RET_LOG(parameter != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER, "parameter is nullptr"); auto ret = codecPlugin_->GetParameter(parameter); CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "plugin get parameter failed"); return (int32_t)ret; @@ -412,9 +413,9 @@ Status MediaCodec::AttachBufffer() CHECK_AND_RETURN_RET_LOG(ret == Status::OK, ret, "attachBufffer failed, plugin get param error"); int32_t capacity = 0; CHECK_AND_RETURN_RET_LOG(inputBufferConfig != nullptr, Status::ERROR_UNKNOWN, - "inputBufferConfig is nullptr"); - CHECK_AND_RETURN_RET(inputBufferConfig->Get(capacity), - Status::ERROR_INVALID_PARAMETER); + "inputBufferConfig is nullptr"); + CHECK_AND_RETURN_RET_LOG(inputBufferConfig->Get(capacity), + Status::ERROR_INVALID_PARAMETER, "get AUDIO_MAX_INPUT_SIZE failed"); for (int i = 0; i < inputBufferNum; i++) { std::shared_ptr avAllocator; #ifndef MEDIA_OHOS @@ -425,10 +426,9 @@ Status MediaCodec::AttachBufffer() avAllocator = AVAllocatorFactory::CreateSharedAllocator(MemoryFlag::MEMORY_READ_WRITE); #endif std::shared_ptr inputBuffer = AVBuffer::CreateAVBuffer(avAllocator, capacity); - CHECK_AND_RETURN_RET_LOG(inputBuffer != nullptr, Status::ERROR_UNKNOWN, - "inputBuffer is nullptr"); + CHECK_AND_RETURN_RET_LOG(inputBuffer != nullptr, Status::ERROR_UNKNOWN, "inputBuffer is nullptr"); CHECK_AND_RETURN_RET_LOG(inputBufferQueueProducer_ != nullptr, Status::ERROR_UNKNOWN, - "inputBufferQueueProducer_ is nullptr"); + "inputBufferQueueProducer_ is nullptr"); inputBufferQueueProducer_->AttachBuffer(inputBuffer, false); AVCODEC_LOGI("Attach intput buffer. index: %{public}d, bufferId: %{public}" PRIu64, i, inputBuffer->GetUniqueId()); @@ -548,9 +548,9 @@ int32_t MediaCodec::PrepareOutputBufferQueue() ret = codecPlugin_->GetParameter(outputBufferConfig); CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "GetParameter failed"); CHECK_AND_RETURN_RET_LOG(outputBufferConfig != nullptr, (int32_t)Status::ERROR_INVALID_STATE, - "outputBufferConfig is nullptr"); - CHECK_AND_RETURN_RET(outputBufferConfig->Get(outputBufferCapacity_), - (int32_t)Status::ERROR_INVALID_PARAMETER); + "outputBufferConfig is nullptr"); + CHECK_AND_RETURN_RET_LOG(outputBufferConfig->Get(outputBufferCapacity_), + (int32_t)Status::ERROR_INVALID_PARAMETER, "get AUDIO_MAX_OUTPUT_SIZE failed"); for (int i = 0; i < outputBufferNum; i++) { auto avAllocator = AVAllocatorFactory::CreateSharedAllocator(MemoryFlag::MEMORY_READ_WRITE); std::shared_ptr outputBuffer = AVBuffer::CreateAVBuffer(avAllocator, outputBufferCapacity_); @@ -718,9 +718,9 @@ void MediaCodec::OnInputBufferDone(const std::shared_ptr &inputBuffer) { MediaAVCodec::AVCodecTrace trace("MediaCodec::OnInputBufferDone"); Status ret = inputBufferQueueConsumer_->ReleaseBuffer(inputBuffer); - AVCODEC_LOGD("0x%{public}06" PRIXPTR " OnInputBufferDone, buffer->pts" PUBLIC_LOG_D64, + AVCODEC_LOGD("0x%{public}06" PRIXPTR " OnInputBufferDone, buffer->pts %{public}lld", FAKE_POINTER(this), inputBuffer->pts_); - CHECK_AND_RETURN_MSG(ret == Status::OK, "OnInputBufferDone fail"); + CHECK_AND_RETURN_LOG(ret == Status::OK, "OnInputBufferDone fail"); } void MediaCodec::OnOutputBufferDone(const std::shared_ptr &outputBuffer) @@ -733,9 +733,9 @@ void MediaCodec::OnOutputBufferDone(const std::shared_ptr &outputBuffe if (mediaCodecCallback_) { mediaCodecCallback_->OnOutputBufferDone(outputBuffer); } - AVCODEC_LOGD("0x%{public}06" PRIXPTR " OnOutputBufferDone, buffer->pts" PUBLIC_LOG_D64, + AVCODEC_LOGD("0x%{public}06" PRIXPTR " OnOutputBufferDone, buffer->pts %{public}lld", FAKE_POINTER(this), outputBuffer->pts_); - CHECK_AND_RETURN_MSG(ret == Status::OK, "OnOutputBufferDone fail"); + CHECK_AND_RETURN_LOG(ret == Status::OK, "OnOutputBufferDone fail"); } void MediaCodec::ClearBufferQueue() diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp index d698e34b3..5f9fc91b1 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp @@ -503,14 +503,14 @@ Status FFmpegAACEncoderPlugin::OpenContext() { { std::unique_lock lock(avMutex_); - AVCODEC_LOGI("avCodecContext_->channels " PUBLIC_LOG_D32, avCodecContext_->channels); - AVCODEC_LOGI("avCodecContext_->sample_rate " PUBLIC_LOG_D32, avCodecContext_->sample_rate); - AVCODEC_LOGI("avCodecContext_->bit_rate " PUBLIC_LOG_D64, avCodecContext_->bit_rate); - AVCODEC_LOGI("avCodecContext_->channel_layout " PUBLIC_LOG_D64, avCodecContext_->channel_layout); - AVCODEC_LOGI("avCodecContext_->sample_fmt " PUBLIC_LOG_D32, + AVCODEC_LOGI("avCodecContext_->channels %{public}d", avCodecContext_->channels); + AVCODEC_LOGI("avCodecContext_->sample_rate %{public}d", avCodecContext_->sample_rate); + AVCODEC_LOGI("avCodecContext_->bit_rate %{public}lld", avCodecContext_->bit_rate); + AVCODEC_LOGI("avCodecContext_->channel_layout %{public}lld", avCodecContext_->channel_layout); + AVCODEC_LOGI("avCodecContext_->sample_fmt %{public}d", static_cast(*(avCodec_.get()->sample_fmts))); - AVCODEC_LOGI("avCodecContext_ old srcFmt_ " PUBLIC_LOG_D32, static_cast(srcFmt_)); - AVCODEC_LOGI("avCodecContext_->codec_id " PUBLIC_LOG_D32, static_cast(avCodec_.get()->id)); + AVCODEC_LOGI("avCodecContext_ old srcFmt_ %{public}d", static_cast(srcFmt_)); + AVCODEC_LOGI("avCodecContext_->codec_id %{public}d", static_cast(avCodec_.get()->id)); auto res = avcodec_open2(avCodecContext_.get(), avCodec_.get(), nullptr); if (res != 0) { AVCODEC_LOGE("avcodec open error %{public}s", OSAL::AVStrError(res).c_str()); @@ -592,7 +592,7 @@ Status FFmpegAACEncoderPlugin::GetMetaData(const std::shared_ptr &meta) AVCODEC_LOGI("maxInputSize: %{public}d", maxInputSize_); } if (meta->Get(srcLayout_)) { - AVCODEC_LOGI("srcLayout_: " PUBLIC_LOG_U64, srcLayout_); + AVCODEC_LOGI("srcLayout_: %{public}llu", srcLayout_); } else { auto iter = channelLayoutMap.find(channels_); if (iter == channelLayoutMap.end()) { @@ -737,7 +737,7 @@ Status FFmpegAACEncoderPlugin::SendFrameToFfmpeg() Status FFmpegAACEncoderPlugin::PcmFillFrame(const std::shared_ptr &inputBuffer) { - AVCODEC_LOGD("PcmFillFrame enter, buffer->pts" PUBLIC_LOG_D64, inputBuffer->pts_); + AVCODEC_LOGD("PcmFillFrame enter, buffer->pts %{public}lld", inputBuffer->pts_); auto memory = inputBuffer->memory_; auto bytesPerSample = av_get_bytes_per_sample(avCodecContext_->sample_fmt); const uint8_t *srcBuffer = memory->GetAddr(); diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp index 9717c14f4..8db02b9ad 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp @@ -13,11 +13,14 @@ * limitations under the License. */ #include "ffmpeg_convert.h" + +#include + #include "avcodec_log.h" #include "securec.h" namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_AUDIO, "FFmpegEncoderPlugin"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_AUDIO, "FFmpegConvert"}; } namespace OHOS { diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp index f1f64c048..82fc00bcc 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_converter.cpp @@ -21,7 +21,7 @@ #include "ffmpeg_converter.h" namespace { constexpr int US_PER_SECOND = 1000000; -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER, "FFmpegEncoderPlugin"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER, "FFmpegConverter"}; } namespace OHOS { namespace Media { diff --git a/services/utils/include/block_queue.h b/services/utils/include/block_queue.h index f51bf651f..b69c8d018 100644 --- a/services/utils/include/block_queue.h +++ b/services/utils/include/block_queue.h @@ -161,7 +161,7 @@ private: std::string name_; const size_t capacity_; std::atomic isActive_; - const OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER_MUXER, "BlockQueue"}; + const OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_DEMUXER, "BlockQueue"}; }; } // namespace MediaAVCodec } // namespace OHOS -- Gitee From 731ed2932b382eaf6a2b3a96f0c21dcc44abdbec Mon Sep 17 00:00:00 2001 From: hanwenzhao Date: Tue, 9 Jul 2024 01:00:09 +0800 Subject: [PATCH 25/25] patch Signed-off-by: hanwenzhao Change-Id: Ic6137af9796f469771a2104f2a61f5dda431fe44 --- services/media_engine/modules/BUILD.gn | 2 +- .../modules/media_codec/media_codec.cpp | 24 ++++++++++--------- .../aac/ffmpeg_aac_encoder_plugin.cpp | 23 +++++++----------- .../ffmpeg_adapter/common/ffmpeg_convert.cpp | 21 ++++++++-------- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/services/media_engine/modules/BUILD.gn b/services/media_engine/modules/BUILD.gn index 85b3b0d02..b06cc2aec 100644 --- a/services/media_engine/modules/BUILD.gn +++ b/services/media_engine/modules/BUILD.gn @@ -82,7 +82,7 @@ ohos_shared_library("av_codec_media_engine_modules") { deps = [ "$av_codec_root_dir/services/dfx:av_codec_service_dfx", - "$av_codec_root_dir/services/engine/base:av_codec_codec_base" + "$av_codec_root_dir/services/engine/base:av_codec_codec_base", ] public_configs = [ "$audio_framework_root_dir/frameworks/native/audiocapturer:audio_capturer_config" ] diff --git a/services/media_engine/modules/media_codec/media_codec.cpp b/services/media_engine/modules/media_codec/media_codec.cpp index ef663ba9c..f240dd986 100644 --- a/services/media_engine/modules/media_codec/media_codec.cpp +++ b/services/media_engine/modules/media_codec/media_codec.cpp @@ -168,7 +168,7 @@ int32_t MediaCodec::SetCodecCallback(const std::shared_ptr &codec CHECK_AND_RETURN_RET_LOG(state_ == CodecState::INITIALIZED || state_ == CodecState::CONFIGURED, (int32_t)Status::ERROR_INVALID_STATE, "state != INITIALIZED and state != CONFIGURED"); CHECK_AND_RETURN_RET_LOG(codecCallback != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER, - "codecCallback is nullptr"); + "codecCallback is nullptr"); codecCallback_ = codecCallback; auto ret = codecPlugin_->SetDataCallback(this); CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "ret != Status::OK"); @@ -330,12 +330,14 @@ int32_t MediaCodec::Release() MediaAVCodec::AVCodecTrace trace("MediaCodec::Release"); AVCODEC_LOGI("Release enter"); if (state_ == CodecState::UNINITIALIZED || state_ == CodecState::RELEASING) { - AVCODEC_LOGW("codec Release, state isnot completely correct, state =%{public}s .", StateToString(state_).data()); + AVCODEC_LOGW("codec Release, state isnot completely correct, state =%{public}s .", + StateToString(state_).data()); return (int32_t)Status::OK; } if (state_ == CodecState::INITIALIZING) { - AVCODEC_LOGW("codec Release, state isnot completely correct, state =%{public}s .", StateToString(state_).data()); + AVCODEC_LOGW("codec Release, state isnot completely correct, state =%{public}s .", + StateToString(state_).data()); state_ = CodecState::RELEASING; return (int32_t)Status::OK; } @@ -383,7 +385,7 @@ int32_t MediaCodec::GetOutputFormat(std::shared_ptr ¶meter) { AutoLock lock(stateMutex_); CHECK_AND_RETURN_RET_LOG(state_ != CodecState::UNINITIALIZED, (int32_t)Status::ERROR_INVALID_STATE, - "status incorrect,get output format failed."); + "status incorrect,get output format failed."); CHECK_AND_RETURN_RET_LOG(codecPlugin_ != nullptr, (int32_t)Status::ERROR_INVALID_STATE, "codecPlugin_ is nullptr"); CHECK_AND_RETURN_RET_LOG(parameter != nullptr, (int32_t)Status::ERROR_INVALID_PARAMETER, "parameter is nullptr"); auto ret = codecPlugin_->GetParameter(parameter); @@ -404,8 +406,7 @@ Status MediaCodec::AttachBufffer() if (inputBufferQueue_ == nullptr) { inputBufferQueue_ = AVBufferQueue::Create(inputBufferNum, memoryType, INPUT_BUFFER_QUEUE_NAME); } - CHECK_AND_RETURN_RET_LOG(inputBufferQueue_ != nullptr, Status::ERROR_UNKNOWN, - "inputBufferQueue_ is nullptr"); + CHECK_AND_RETURN_RET_LOG(inputBufferQueue_ != nullptr, Status::ERROR_UNKNOWN, "inputBufferQueue_ is nullptr"); inputBufferQueueProducer_ = inputBufferQueue_->GetProducer(); std::shared_ptr inputBufferConfig = std::make_shared(); CHECK_AND_RETURN_RET_LOG(codecPlugin_ != nullptr, Status::ERROR_UNKNOWN, "codecPlugin_ is nullptr"); @@ -516,18 +517,19 @@ int32_t MediaCodec::PrepareInputBufferQueue() AVBufferQueue::Create(inputBuffers.size(), MemoryType::HARDWARE_MEMORY, INPUT_BUFFER_QUEUE_NAME); } CHECK_AND_RETURN_RET_LOG(inputBufferQueue_ != nullptr, (int32_t)Status::ERROR_UNKNOWN, - "inputBufferQueue_ is nullptr"); + "inputBufferQueue_ is nullptr"); inputBufferQueueProducer_ = inputBufferQueue_->GetProducer(); for (uint32_t i = 0; i < inputBuffers.size(); i++) { inputBufferQueueProducer_->AttachBuffer(inputBuffers[i], false); inputBufferVector_.push_back(inputBuffers[i]); } } - CHECK_AND_RETURN_RET_LOG(inputBufferQueue_ != nullptr, (int32_t)Status::ERROR_UNKNOWN, "inputBufferQueue_ is nullptr"); + CHECK_AND_RETURN_RET_LOG(inputBufferQueue_ != nullptr, (int32_t)Status::ERROR_UNKNOWN, + "inputBufferQueue_ is nullptr"); inputBufferQueueConsumer_ = inputBufferQueue_->GetConsumer(); sptr listener = new InputBufferAvailableListener(this); CHECK_AND_RETURN_RET_LOG(inputBufferQueueConsumer_ != nullptr, (int32_t)Status::ERROR_UNKNOWN, - "inputBufferQueueConsumer_ is nullptr"); + "inputBufferQueueConsumer_ is nullptr"); inputBufferQueueConsumer_->SetBufferAvailableListener(listener); return (int32_t)ret; } @@ -541,7 +543,7 @@ int32_t MediaCodec::PrepareOutputBufferQueue() auto ret = codecPlugin_->GetOutputBuffers(outputBuffers); CHECK_AND_RETURN_RET_LOG(ret == Status::OK, (int32_t)ret, "GetOutputBuffers failed"); CHECK_AND_RETURN_RET_LOG(outputBufferQueueProducer_ != nullptr, (int32_t)Status::ERROR_INVALID_STATE, - "outputBufferQueueProducer_ is nullptr"); + "outputBufferQueueProducer_ is nullptr"); if (outputBuffers.empty()) { int outputBufferNum = 30; std::shared_ptr outputBufferConfig = std::make_shared(); @@ -555,7 +557,7 @@ int32_t MediaCodec::PrepareOutputBufferQueue() auto avAllocator = AVAllocatorFactory::CreateSharedAllocator(MemoryFlag::MEMORY_READ_WRITE); std::shared_ptr outputBuffer = AVBuffer::CreateAVBuffer(avAllocator, outputBufferCapacity_); CHECK_AND_RETURN_RET_LOG(outputBuffer != nullptr, (int32_t)Status::ERROR_INVALID_STATE, - "outputBuffer is nullptr"); + "outputBuffer is nullptr"); if (outputBufferQueueProducer_->AttachBuffer(outputBuffer, false) == Status::OK) { AVCODEC_LOGD("Attach output buffer. index: %{public}d, bufferId: %{public}" PRIu64, i, outputBuffer->GetUniqueId()); diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp index 5f9fc91b1..f73ba5488 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/aac/ffmpeg_aac_encoder_plugin.cpp @@ -128,9 +128,8 @@ bool FFmpegAACEncoderPlugin::CheckSampleFormat() return false; } AudioSampleFormat2AVSampleFormat(audioSampleFormat_, srcFmt_); - AVCODEC_LOGE("AUDIO_SAMPLE_FORMAT found,srcFmt:%{public}d to " - "ffmpeg-srcFmt_:%{public}d ", - (int32_t)audioSampleFormat_, (int32_t)srcFmt_); + AVCODEC_LOGE("AUDIO_SAMPLE_FORMAT found,srcFmt:%{public}d to ffmpeg-srcFmt_:%{public}d", + (int32_t)audioSampleFormat_, (int32_t)srcFmt_); needResample_ = CheckResample(); return true; } @@ -208,9 +207,8 @@ bool FFmpegAACEncoderPlugin::AudioSampleFormat2AVSampleFormat(const AudioSampleF fmt = it->second; return true; } - AVCODEC_LOGE("AudioSampleFormat2AVSampleFormat fail, from fmt:%{public}d to " - "fmt:%{public}d", - (int32_t)audioFmt, (int32_t)fmt); + AVCODEC_LOGE("AudioSampleFormat2AVSampleFormat fail, from fmt:%{public}d to fmt:%{public}d", + (int32_t)audioFmt, (int32_t)fmt); return false; } @@ -507,8 +505,7 @@ Status FFmpegAACEncoderPlugin::OpenContext() AVCODEC_LOGI("avCodecContext_->sample_rate %{public}d", avCodecContext_->sample_rate); AVCODEC_LOGI("avCodecContext_->bit_rate %{public}lld", avCodecContext_->bit_rate); AVCODEC_LOGI("avCodecContext_->channel_layout %{public}lld", avCodecContext_->channel_layout); - AVCODEC_LOGI("avCodecContext_->sample_fmt %{public}d", - static_cast(*(avCodec_.get()->sample_fmts))); + AVCODEC_LOGI("avCodecContext_->sample_fmt %{public}d", static_cast(*(avCodec_.get()->sample_fmts))); AVCODEC_LOGI("avCodecContext_ old srcFmt_ %{public}d", static_cast(srcFmt_)); AVCODEC_LOGI("avCodecContext_->codec_id %{public}d", static_cast(avCodec_.get()->id)); auto res = avcodec_open2(avCodecContext_.get(), avCodec_.get(), nullptr); @@ -661,9 +658,8 @@ Status FFmpegAACEncoderPlugin::SendEncoder(const std::shared_ptr &inpu return Status::ERROR_UNKNOWN; } if (memory->GetSize() > memory->GetCapacity()) { - AVCODEC_LOGE("send input buffer is > allocate size. size : " - "%{public}d, allocate size : %{public}d", - memory->GetSize(), memory->GetCapacity()); + AVCODEC_LOGE("send input buffer is > allocate size. size : %{public}d, allocate size : %{public}d", + memory->GetSize(), memory->GetCapacity()); return Status::ERROR_UNKNOWN; } auto errCode = PcmFillFrame(inputBuffer); @@ -752,9 +748,8 @@ Status FFmpegAACEncoderPlugin::PcmFillFrame(const std::shared_ptr &inp cachedFrame_->nb_samples = static_cast(destBufferSize) / (bytesPerSample * avCodecContext_->channels); if (!(inputBuffer->flag_ & BUFFER_FLAG_EOS) && cachedFrame_->nb_samples != avCodecContext_->frame_size) { - AVCODEC_LOGD("Input frame size not match, input samples: %{public}d, " - "frame_size: %{public}d", - cachedFrame_->nb_samples, avCodecContext_->frame_size); + AVCODEC_LOGD("Input frame size not match, input samples: %{public}d, frame_size: %{public}d", + cachedFrame_->nb_samples, avCodecContext_->frame_size); } int32_t destSamplesPerFrame = (avCodecContext_->frame_size > (avCodecContext_->sample_rate / FRAMES_PER_SECOND)) ? avCodecContext_->frame_size : (avCodecContext_->sample_rate / FRAMES_PER_SECOND); diff --git a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp index 8db02b9ad..01ea23066 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/common/ffmpeg_convert.cpp @@ -97,25 +97,27 @@ Status Resample::Convert(const uint8_t *srcBuffer, const size_t srcLength, uint8 #if defined(_WIN32) || !defined(OHOS_LITE) if (resamplePara_.bitsPerSample == 8) { // 8 CHECK_AND_RETURN_RET_LOG(resamplePara_.destFmt == AV_SAMPLE_FMT_S16, Status::ERROR_UNIMPLEMENTED, - "resample 8bit to other format can not support"); + "resample 8bit to other format can not support"); destLength = srcLength * 2; // 2 resampleCache_.reserve(destLength); resampleCache_.assign(destLength, 0); for (size_t i{0}; i < destLength / 2; i++) { // 2 auto resCode = memcpy_s(&resampleCache_[0] + i * 2 + 1, sizeof(uint8_t), srcBuffer + i, 1); // 0 2 1 - CHECK_AND_RETURN_RET_LOG(resCode == EOK, Status::ERROR_INVALID_OPERATION, "Memcpy failed at 8 bits/sample."); + CHECK_AND_RETURN_RET_LOG(resCode == EOK, Status::ERROR_INVALID_OPERATION, + "Memcpy failed at 8 bits/sample."); *(&resampleCache_[0] + i * 2 + 1) += 0x80; // 2 0x80 } destBuffer = resampleCache_.data(); } else if (resamplePara_.bitsPerSample == 24) { // 24 CHECK_AND_RETURN_RET_LOG(resamplePara_.destFmt == AV_SAMPLE_FMT_S16, Status::ERROR_UNIMPLEMENTED, - "resample 24bit to other format can not support"); + "resample 24bit to other format can not support"); destLength = srcLength / 3 * 2; // 3 2 resampleCache_.reserve(destLength); resampleCache_.assign(destLength, 0); for (size_t i = 0; i < destLength / 2; i++) { // 2 auto resCode = memcpy_s(&resampleCache_[0] + i * 2, sizeof(uint8_t) * 2, srcBuffer + i * 3 + 1, 2); // 2 3 1 - CHECK_AND_RETURN_RET_LOG(resCode == EOK, Status::ERROR_INVALID_OPERATION, "Memcpy failed at 24 bits/sample."); + CHECK_AND_RETURN_RET_LOG(resCode == EOK, Status::ERROR_INVALID_OPERATION, + "Memcpy failed at 24 bits/sample."); } destBuffer = resampleCache_.data(); } else { @@ -187,14 +189,13 @@ Status Scale::Init(const ScalePara &scalePara, uint8_t **dstData, int32_t *dstLi }); auto ret = av_image_alloc(dstData, dstLineSize, scalePara_.dstWidth, scalePara_.dstHeight, scalePara_.dstFfFmt, scalePara_.align); - CHECK_AND_RETURN_RET_LOG(ret >= 0, Status::ERROR_UNKNOWN, "could not allocate destination image" PUBLIC_LOG_D32, ret); - AVCODEC_LOGD("av_image_alloc call, ret: " PUBLIC_LOG_U32 "dstPixelFormat_: " PUBLIC_LOG_U32, ret, - scalePara_.dstFfFmt); + CHECK_AND_RETURN_RET_LOG(ret >= 0, Status::ERROR_UNKNOWN, "could not allocate destination image %{public}d", ret); + AVCODEC_LOGD("av_image_alloc call, ret: %{public}ud dstPixelFormat_: %{public}ud", ret, scalePara_.dstFfFmt); // av_image_alloc can make sure that dstLineSize last element is 0 for (int32_t i = 0; dstLineSize[i] > 0; i++) { - AVCODEC_LOGD("dstLineSize[" PUBLIC_LOG_D32 "]: " PUBLIC_LOG_D32, i, dstLineSize[i]); + AVCODEC_LOGD("dstLineSize[%{public}d]: %{public}d", i, dstLineSize[i]); if (dstData[i] && !dstLineSize[i]) { - AVCODEC_LOGE("scale frame is broken, i: " PUBLIC_LOG_D32, i); + AVCODEC_LOGE("scale frame is broken, i: %{public}d", i); return Status::ERROR_UNKNOWN; } } @@ -204,7 +205,7 @@ Status Scale::Init(const ScalePara &scalePara, uint8_t **dstData, int32_t *dstLi Status Scale::Convert(uint8_t **srcData, const int32_t *srcLineSize, uint8_t **dstData, int32_t *dstLineSize) { auto res = sws_scale(swsCtx_.get(), srcData, srcLineSize, 0, scalePara_.srcHeight, dstData, dstLineSize); - CHECK_AND_RETURN_RET_LOG(res >= 0, Status::ERROR_UNKNOWN, "sws_scale fail: " PUBLIC_LOG_D32, res); + CHECK_AND_RETURN_RET_LOG(res >= 0, Status::ERROR_UNKNOWN, "sws_scale fail: %{public}d", res); return Status::OK; } #endif -- Gitee