From d8b844516a14d5a744dcfcee33bfc0df2db5221c Mon Sep 17 00:00:00 2001 From: bilaizi Date: Thu, 17 Feb 2022 16:27:03 +0800 Subject: [PATCH] modify video recorder adjust Signed-off-by: bilaizi --- .../codec/video_encoder/video_encoder_filter.cpp | 5 ++++- .../codec/video_encoder/video_encoder_filter.h | 2 +- .../source/video_capture/video_capture_filter.cpp | 13 +++++++++++++ .../source/video_capture/video_capture_filter.h | 8 ++++---- engine/plugin/common/plugin_tags.h | 2 +- .../source/video_capture/video_capture_plugin.cpp | 6 ++++++ engine/scene/recorder/standard/hirecorder_impl.cpp | 8 ++++---- engine/scene/recorder/standard/recorder_utils.h | 4 ++-- 8 files changed, 35 insertions(+), 13 deletions(-) diff --git a/engine/pipeline/filters/codec/video_encoder/video_encoder_filter.cpp b/engine/pipeline/filters/codec/video_encoder/video_encoder_filter.cpp index c5655eca..3f8800dc 100644 --- a/engine/pipeline/filters/codec/video_encoder/video_encoder_filter.cpp +++ b/engine/pipeline/filters/codec/video_encoder/video_encoder_filter.cpp @@ -300,9 +300,12 @@ ErrorCode VideoEncoderFilter::SetVideoEncoderFormat(const std::shared_ptrGetInt64(Plugin::MetaID::MEDIA_BITRATE, vencFormat_.bitRate)) { MEDIA_LOG_D("Do not have codec bit rate"); } - if (!meta->GetUint64(Plugin::MetaID::VIDEO_FRAME_RATE, vencFormat_.frameRate)) { + if (!meta->GetUint32(Plugin::MetaID::VIDEO_FRAME_RATE, vencFormat_.frameRate)) { MEDIA_LOG_D("Do not have codec frame rate"); } + if (!meta->GetData(Plugin::MetaID::VIDEO_PIXEL_FORMAT, vencFormat_.format)) { + MEDIA_LOG_D("Do not have codec video pixel format"); + } // Optional: codec extra data if (!meta->GetData>(Plugin::MetaID::MEDIA_CODEC_CONFIG, vencFormat_.codecConfig)) { MEDIA_LOG_D("Do not have codec extra data"); diff --git a/engine/pipeline/filters/codec/video_encoder/video_encoder_filter.h b/engine/pipeline/filters/codec/video_encoder/video_encoder_filter.h index ba9a281b..a6f5723b 100644 --- a/engine/pipeline/filters/codec/video_encoder/video_encoder_filter.h +++ b/engine/pipeline/filters/codec/video_encoder/video_encoder_filter.h @@ -71,7 +71,7 @@ private: uint32_t width; uint32_t height; int64_t bitRate; - uint64_t frameRate; + uint32_t frameRate; Plugin::VideoPixelFormat format; std::vector codecConfig; std::shared_ptr codecMeta; diff --git a/engine/pipeline/filters/source/video_capture/video_capture_filter.cpp b/engine/pipeline/filters/source/video_capture/video_capture_filter.cpp index fb8a11ca..dc599d6e 100644 --- a/engine/pipeline/filters/source/video_capture/video_capture_filter.cpp +++ b/engine/pipeline/filters/source/video_capture/video_capture_filter.cpp @@ -78,6 +78,10 @@ ErrorCode VideoCaptureFilter::InitAndConfigPlugin(const std::shared_ptrSetParameter(Tag::VIDEO_PIXEL_FORMAT, pixelFormat_)); + if (err != ErrorCode::SUCCESS) { + return err; + } return ErrorCode::SUCCESS; } @@ -97,6 +101,12 @@ ErrorCode VideoCaptureFilter::SetParameter(int32_t key, const Plugin::Any& value case Tag::VIDEO_CAPTURE_RATE: (void)AssignParameterIfMatch(tag, captureRate_, value); break; + case Tag::MEDIA_BITRATE: + (void)AssignParameterIfMatch(tag, bitRate_, value); + break; + case Tag::VIDEO_FRAME_RATE: + (void)AssignParameterIfMatch(tag, frameRate_, value); + break; default: MEDIA_LOG_W("Unknown key %" PUBLIC_LOG_S, GetTagStrName(tag)); break; @@ -147,6 +157,9 @@ ErrorCode VideoCaptureFilter::DoConfigure() } videoMeta->SetUint32(Plugin::MetaID::VIDEO_WIDTH, videoWidth_); videoMeta->SetUint32(Plugin::MetaID::VIDEO_HEIGHT, videoHeight_); + videoMeta->SetInt64(Plugin::MetaID::MEDIA_BITRATE, bitRate_); + videoMeta->SetUint32(Plugin::MetaID::VIDEO_FRAME_RATE, frameRate_); + videoMeta->SetData(Plugin::MetaID::VIDEO_PIXEL_FORMAT, pixelFormat_); if (!outPorts_[0]->Configure(videoMeta)) { MEDIA_LOG_E("Configure downstream fail"); return ErrorCode::ERROR_UNKNOWN; diff --git a/engine/pipeline/filters/source/video_capture/video_capture_filter.h b/engine/pipeline/filters/source/video_capture/video_capture_filter.h index 6a8ba8cf..08a2f41e 100644 --- a/engine/pipeline/filters/source/video_capture/video_capture_filter.h +++ b/engine/pipeline/filters/source/video_capture/video_capture_filter.h @@ -27,9 +27,9 @@ #include "utils/type_define.h" #include "utils/utils.h" #include "pipeline/core/filter_base.h" +#include "plugin/common/plugin_video_tags.h" #include "plugin/core/plugin_manager.h" #include "plugin/interface/source_plugin.h" -#include "plugin/common/plugin_video_tags.h" namespace OHOS { namespace Media { @@ -56,9 +56,6 @@ private: Plugin::PluginManager& manager); ErrorCode FindPlugin(); bool DoNegotiate(const CapabilitySet& outCaps); - bool CheckSampleRate(const Plugin::Capability& cap); - bool CheckChannels(const Plugin::Capability& cap); - bool CheckSampleFormat(const Plugin::Capability& cap); ErrorCode DoConfigure(); void SendBuffer(const std::shared_ptr& buffer); @@ -71,6 +68,9 @@ private: uint32_t videoWidth_ {0}; uint32_t videoHeight_ {0}; double captureRate_ {0}; + int64_t bitRate_ {0}; + uint32_t frameRate_ {0}; + Plugin::VideoPixelFormat pixelFormat_ {Plugin::VideoPixelFormat::UNKNOWN}; Capability capNegWithDownstream_ {}; std::atomic isEos_ {false}; OSAL::Mutex pushMutex_ {}; diff --git a/engine/plugin/common/plugin_tags.h b/engine/plugin/common/plugin_tags.h index 7c84b19f..916b8bf4 100644 --- a/engine/plugin/common/plugin_tags.h +++ b/engine/plugin/common/plugin_tags.h @@ -130,7 +130,7 @@ enum struct Tag : uint32_t { VIDEO_WIDTH = SECTION_VIDEO_UNIVERSAL_START + 1, ///< uint32_t, video width VIDEO_HEIGHT, ///< uint32_t, video height VIDEO_PIXEL_FORMAT, ///< @see VideoPixelFormat - VIDEO_FRAME_RATE, ///< uint64_t, video frame rate + VIDEO_FRAME_RATE, ///< uint32_t, video frame rate VIDEO_SURFACE, ///< @see class Surface VIDEO_MAX_SURFACE_NUM, ///< uint32_t, max video surface num VIDEO_CAPTURE_RATE, ///< double, video capture rate diff --git a/engine/plugin/plugins/source/video_capture/video_capture_plugin.cpp b/engine/plugin/plugins/source/video_capture/video_capture_plugin.cpp index 864cfe1a..966d106a 100644 --- a/engine/plugin/plugins/source/video_capture/video_capture_plugin.cpp +++ b/engine/plugin/plugins/source/video_capture/video_capture_plugin.cpp @@ -216,6 +216,12 @@ Status VideoCapturePlugin::SetParameter(Tag tag, const ValueType& value) } break; } + case Tag::VIDEO_PIXEL_FORMAT: { + if (value.SameTypeWith(typeid(VideoPixelFormat))) { + pixelFormat_ = Plugin::AnyCast(value); + } + break; + } default: MEDIA_LOG_I("Unknown key"); break; diff --git a/engine/scene/recorder/standard/hirecorder_impl.cpp b/engine/scene/recorder/standard/hirecorder_impl.cpp index 2d97c992..28c1f6a2 100644 --- a/engine/scene/recorder/standard/hirecorder_impl.cpp +++ b/engine/scene/recorder/standard/hirecorder_impl.cpp @@ -588,14 +588,14 @@ ErrorCode HiRecorderImpl::DoConfigureVideo(const RecorderParamInternal& recParam } case RecorderPublicParamType::VID_BITRATE: { int32_t bitRate = Plugin::AnyCast(any).bitRate; - ret = videoEncoder_->SetParameter(static_cast(Plugin::Tag::MEDIA_BITRATE), - static_cast((bitRate >= 0) ? bitRate : 0)); + ret = videoCapture_->SetParameter(static_cast(Plugin::Tag::MEDIA_BITRATE), + static_cast((bitRate >= 0) ? bitRate : 0)); break; } case RecorderPublicParamType::VID_FRAMERATE: { int32_t frameRate = Plugin::AnyCast(any).frameRate; - ret = videoEncoder_->SetParameter(static_cast(Plugin::Tag::VIDEO_FRAME_RATE), - static_cast((frameRate >= 0) ? frameRate : 0)); + ret = videoCapture_->SetParameter(static_cast(Plugin::Tag::VIDEO_FRAME_RATE), + static_cast((frameRate >= 0) ? frameRate : 0)); break; } case RecorderPublicParamType::VID_ENC_FMT: { diff --git a/engine/scene/recorder/standard/recorder_utils.h b/engine/scene/recorder/standard/recorder_utils.h index 150fae47..d0395659 100644 --- a/engine/scene/recorder/standard/recorder_utils.h +++ b/engine/scene/recorder/standard/recorder_utils.h @@ -76,8 +76,8 @@ struct RecorderParamInternal { }; const std::map g_outputFormatToMimeMap = { - {OutputFormatType::FORMAT_DEFAULT, MEDIA_MIME_AUDIO_MPEG}, - {OutputFormatType::FORMAT_MPEG_4, MEDIA_MIME_AUDIO_MPEG}, + {OutputFormatType::FORMAT_DEFAULT, MEDIA_MIME_CONTAINER_MP4}, + {OutputFormatType::FORMAT_MPEG_4, MEDIA_MIME_CONTAINER_MP4}, {OutputFormatType::FORMAT_M4A, MEDIA_MIME_CONTAINER_MP4}, }; -- Gitee