diff --git a/av_transport/av_trans_control_center/inner_kits/BUILD.gn b/av_transport/av_trans_control_center/inner_kits/BUILD.gn index 191394dc6f9858ce0af7cb9db83b4387de872928..23ea976ffe2026e494fb2471b082c43df1d3f832 100644 --- a/av_transport/av_trans_control_center/inner_kits/BUILD.gn +++ b/av_transport/av_trans_control_center/inner_kits/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("avtranscenter_sdk") { "samgr:samgr_proxy", ] - part_name = "distributed_hardware_fwk" subsystem_name = "distributedhardware" + + part_name = "distributed_hardware_fwk" } diff --git a/av_transport/av_trans_engine/av_receiver/BUILD.gn b/av_transport/av_trans_engine/av_receiver/BUILD.gn index 3b2e6c69b3193ab736044d859a692a00fd446751..94f10d451692a930f7ba732ef07e055dd71497e5 100644 --- a/av_transport/av_trans_engine/av_receiver/BUILD.gn +++ b/av_transport/av_trans_engine/av_receiver/BUILD.gn @@ -15,35 +15,31 @@ import("//build/ohos.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") +config("sender_external_config") { + include_dirs = [ + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/common/include", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_sender/include", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_receiver/include", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/interface", + ] +} + ohos_shared_library("distributed_av_receiver") { include_dirs = [ "${drivers_disaplay_path}/interfaces/include", "${media_standard_path}/interfaces/inner_api/native", "//third_party/json/include", - "${common_path}/include", "${engine_path}", "${engine_path}/av_sender/include", "${engine_path}/av_receiver/include", "${interface_path}", "${dh_fwk_utils_path}/include", + "${dh_fwk_utils_path}/include", "${control_center_path}/inner_kits/include", "${control_center_path}/inner_kits/include/ipc", - - "${histreamer_path}/include", - "${histreamer_path}/include/foundation", - "${histreamer_path}/include/pipeline", - "${histreamer_path}/include/pipeline/core", - "${histreamer_path}/include/pipeline/factory", - "${histreamer_path}/include/pipeline/filters", - "${histreamer_path}/include/pipeline/filters/codec/audio_decoder", - "${histreamer_path}/include/pipeline/filters/codec/video_decoder", - "${histreamer_path}/include/pipeline/filters/source/av_transport_input", - "${histreamer_path}/include/pipeline/filters/sink/av_transport_output", - "${histreamer_path}/include/plugin", - "${histreamer_path}/include/plugin/common", - "${histreamer_path}/include/scene/standard", - "${histreamer_path}/pipeline/filters/codec", + "${filters_path}/av_transport_input", + "${filters_path}/av_transport_output", ] sources = [ @@ -59,8 +55,8 @@ ohos_shared_library("distributed_av_receiver") { deps = [ "${control_center_path}/inner_kits:avtranscenter_sdk", - "${histreamer_path}/pipeline:histreamer_pipeline", - "${histreamer_path}/pipeline:histreamer_pipeline_base", + "${filters_path}:avtrans_input_filter", + "${filters_path}:avtrans_output_filter", ] defines = [ @@ -80,6 +76,10 @@ ohos_shared_library("distributed_av_receiver") { "dsoftbus:softbus_client", "graphic_standard:libgraphic_utils", "graphic_standard:surface", + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", @@ -101,6 +101,6 @@ ohos_shared_library("distributed_av_receiver") { ] cflags_cc = cflags - part_name = "histreamer" - subsystem_name = "multimedia" + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" } diff --git a/av_transport/av_trans_engine/av_receiver/include/av_receiver_engine.h b/av_transport/av_trans_engine/av_receiver/include/av_receiver_engine.h index 3d9aae643111b3b142616fc25bb4c9e0c3000dbe..e22705cce7c11629a411909be72580370c7e5cf2 100644 --- a/av_transport/av_trans_engine/av_receiver/include/av_receiver_engine.h +++ b/av_transport/av_trans_engine/av_receiver/include/av_receiver_engine.h @@ -27,6 +27,8 @@ #include "softbus_channel_adapter.h" #include "av_trans_control_center_kit.h" #include "av_trans_control_center_callback.h" +#include "av_transport_input_filter.h" +#include "av_transport_output_filter.h" // follwing head files depends on histreamer #include "error_code.h" @@ -36,9 +38,6 @@ #include "pipeline_core.h" #include "audio_decoder_filter.h" #include "video_decoder_filter.h" -#include "av_transport_input_filter.h" -#include "av_transport_output_filter.h" -#include "async_mode.h" namespace OHOS { namespace DistributedHardware { @@ -106,8 +105,8 @@ private: std::shared_ptr receiverCallback_ = nullptr; std::shared_ptr pipeline_ = nullptr; - std::shared_ptr avInput_; - std::shared_ptr avOutput_; + std::shared_ptr avInput_; + std::shared_ptr avOutput_; std::shared_ptr audioDecoder_; std::shared_ptr videoDecoder_; }; diff --git a/av_transport/av_trans_engine/av_receiver/src/av_receiver_engine.cpp b/av_transport/av_trans_engine/av_receiver/src/av_receiver_engine.cpp index 151f035eee79e9ed20900a8e2c9f17ffbc31de60..4d4808a15393e380f91e891703c89d50516e4cf9 100644 --- a/av_transport/av_trans_engine/av_receiver/src/av_receiver_engine.cpp +++ b/av_transport/av_trans_engine/av_receiver/src/av_receiver_engine.cpp @@ -68,12 +68,10 @@ int32_t AVReceiverEngine::InitPipeline() avOutput_ = FilterFactory::Instance().CreateFilterWithType(AVOUTPUT_NAME, "avoutput"); TRUE_RETURN_V_MSG_E(avOutput_ == nullptr, ERR_DH_AVT_NULL_POINTER, "create av output filter failed"); - std::shared_ptr vCodecMode = std::make_shared("videoDec"); - videoDecoder_ = std::make_shared(VDECODER_NAME, vCodecMode); + videoDecoder_ = FilterFactory::Instance().CreateFilterWithType(VDECODER_NAME, "videoDec"); TRUE_RETURN_V_MSG_E(videoDecoder_ == nullptr, ERR_DH_AVT_NULL_POINTER, "create av video decoder filter failed"); - - std::shared_ptr aCodecMode = std::make_shared("audioDec"); - audioDecoder_ = std::make_shared(ADECODER_NAME, aCodecMode); + + audioDecoder_ = FilterFactory::Instance().CreateFilterWithType(ADECODER_NAME, "audioDec"); TRUE_RETURN_V_MSG_E(audioDecoder_ == nullptr, ERR_DH_AVT_NULL_POINTER, "create av audio decoder filter failed"); ErrorCode ret; diff --git a/av_transport/av_trans_engine/av_sender/BUILD.gn b/av_transport/av_trans_engine/av_sender/BUILD.gn index 568c98d57c0bc9d0c4650a2ba81df1fd176cf4c7..d5ddc5ca5e7e33428daca4a286315190a9a61aa2 100644 --- a/av_transport/av_trans_engine/av_sender/BUILD.gn +++ b/av_transport/av_trans_engine/av_sender/BUILD.gn @@ -15,7 +15,18 @@ import("//build/ohos.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") +config("sender_external_config") { + include_dirs = [ + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/common/include", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_sender/include", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_receiver/include", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/interface", + ] +} + ohos_shared_library("distributed_av_sender") { + public_configs = [ ":sender_external_config" ] + include_dirs = [ "${drivers_disaplay_path}/interfaces/include", "${media_standard_path}/interfaces/inner_api/native", @@ -29,20 +40,8 @@ ohos_shared_library("distributed_av_sender") { "${dh_fwk_utils_path}/include", "${control_center_path}/inner_kits/include", "${control_center_path}/inner_kits/include/ipc", - - "${histreamer_path}/include", - "${histreamer_path}/include/foundation", - "${histreamer_path}/include/pipeline", - "${histreamer_path}/include/pipeline/core", - "${histreamer_path}/include/pipeline/factory", - "${histreamer_path}/include/pipeline/filters", - "${histreamer_path}/include/pipeline/filters/codec/audio_encoder", - "${histreamer_path}/include/pipeline/filters/codec/video_encoder", - "${histreamer_path}/include/pipeline/filters/source/av_transport_input", - "${histreamer_path}/include/pipeline/filters/sink/av_transport_output", - "${histreamer_path}/include/plugin", - "${histreamer_path}/include/plugin/common", - "${histreamer_path}/include/scene/standard", + "${filters_path}/av_transport_input", + "${filters_path}/av_transport_output", ] sources = [ @@ -58,8 +57,8 @@ ohos_shared_library("distributed_av_sender") { deps = [ "${control_center_path}/inner_kits:avtranscenter_sdk", - "${histreamer_path}/pipeline:histreamer_pipeline", - "${histreamer_path}/pipeline:histreamer_pipeline_base", + "${filters_path}:avtrans_input_filter", + "${filters_path}:avtrans_output_filter", ] defines = [ @@ -79,6 +78,10 @@ ohos_shared_library("distributed_av_sender") { "dsoftbus:softbus_client", "graphic_standard:libgraphic_utils", "graphic_standard:surface", + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", @@ -100,6 +103,6 @@ ohos_shared_library("distributed_av_sender") { ] cflags_cc = cflags - part_name = "histreamer" - subsystem_name = "multimedia" + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" } diff --git a/av_transport/av_trans_engine/av_sender/include/av_sender_engine.h b/av_transport/av_trans_engine/av_sender/include/av_sender_engine.h index b4a1d2f1799e25cfb14af3679abced2e886ad637..c9ac7d44dedc0f03fa38e2811dcbc5e34d4fe02e 100644 --- a/av_transport/av_trans_engine/av_sender/include/av_sender_engine.h +++ b/av_transport/av_trans_engine/av_sender/include/av_sender_engine.h @@ -27,6 +27,8 @@ #include "softbus_channel_adapter.h" #include "av_trans_control_center_kit.h" #include "av_trans_control_center_callback.h" +#include "av_transport_input_filter.h" +#include "av_transport_output_filter.h" // follwing head files depends on histreamer #include "error_code.h" @@ -35,8 +37,6 @@ #include "pipeline_core.h" #include "audio_encoder_filter.h" #include "video_encoder_filter.h" -#include "av_transport_input_filter.h" -#include "av_transport_output_filter.h" namespace OHOS { namespace DistributedHardware { @@ -106,8 +106,8 @@ private: std::shared_ptr senderCallback_ = nullptr; std::shared_ptr pipeline_ = nullptr; - std::shared_ptr avInput_ = nullptr; - std::shared_ptr avOutput_ = nullptr; + std::shared_ptr avInput_ = nullptr; + std::shared_ptr avOutput_ = nullptr; std::shared_ptr audioEncoder_ = nullptr; std::shared_ptr videoEncoder_ = nullptr; }; diff --git a/av_transport/av_trans_engine/filters/BUILD.gn b/av_transport/av_trans_engine/filters/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..20de80277fb79229091a61add76ce262e14f67af --- /dev/null +++ b/av_transport/av_trans_engine/filters/BUILD.gn @@ -0,0 +1,110 @@ +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import( + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") + +ohos_source_set("avtrans_input_filter") { + include_dirs = [ + "${plugin_path}/core", + "${plugin_path}/interface", + "${common_path}/include", + ] + + sources = [ + "${plugin_path}/core/avtrans_input.cpp", + "av_transport_input/av_transport_input_filter.cpp", + ] + + external_deps = [ + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", + "hiviewdfx_hilog_native:libhilog", + ] + + public_deps = [ + "${plugin_path}/plugins/av_trans_input/daudio_input:plugin_AVTransDaudioInput", + "${plugin_path}/plugins/av_trans_input/dscreen_input:plugin_AVTransDscreenInput", + "${plugin_path}/plugins/av_trans_input/dsoftbus_input:plugin_AVTransDsoftbusInput", + "${plugin_path}/plugins/av_trans_input/dsoftbus_input_audio:plugin_AVTransDsoftbusInputAudio", + ] + + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-frtti", + "-fexceptions", + "-Wno-unused-but-set-variable", + "-Wno-format", + ] + cflags_cc = cflags + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"av_transport_input_filter\"", + "LOG_DOMAIN=0xD004100", + ] +} + +ohos_source_set("avtrans_output_filter") { + include_dirs = [ + "${plugin_path}/core", + "${plugin_path}/interface", + "${common_path}/include", + ] + + sources = [ + "${plugin_path}/core/avtrans_output.cpp", + "av_transport_output/av_transport_output_filter.cpp", + ] + + external_deps = [ + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", + "hiviewdfx_hilog_native:libhilog", + ] + + public_deps = [ + "${plugin_path}/plugins/av_trans_output/daudio_output:plugin_AVTransDaudioOutput", + "${plugin_path}/plugins/av_trans_output/dscreen_output:plugin_AVTransDscreenOutput", + "${plugin_path}/plugins/av_trans_output/dsoftbus_output:plugin_AVTransDsoftbusOutput", + "${plugin_path}/plugins/av_trans_output/dsoftbus_output_audio:plugin_AVTransDsoftbusOutputAudio", + ] + + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-frtti", + "-fexceptions", + "-Wno-unused-but-set-variable", + "-Wno-format", + ] + cflags_cc = cflags + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"av_transport_output_filter\"", + "LOG_DOMAIN=0xD004100", + ] +} diff --git a/av_transport/av_trans_engine/filters/av_transport_input/av_transport_input_filter.cpp b/av_transport/av_trans_engine/filters/av_transport_input/av_transport_input_filter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b337e414286cfe56c74b233a045c97662fee2e14 --- /dev/null +++ b/av_transport/av_trans_engine/filters/av_transport_input/av_transport_input_filter.cpp @@ -0,0 +1,572 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define HST_LOG_TAG "AVInputFilter" +#include "av_transport_input_filter.h" +#include "av_trans_log.h" +#include "av_trans_constants.h" +#include "pipeline/filters/common/plugin_utils.h" +#include "pipeline/factory/filter_factory.h" +#include "plugin/common/plugin_attr_desc.h" + +namespace OHOS { +namespace DistributedHardware { + +static AutoRegisterFilter g_registerFilterHelper("builtin.avtransport.avinput"); + +AVInputFilter::AVInputFilter(const std::string& name) : FilterBase(name), plugin_(nullptr), pluginInfo_(nullptr) +{ + AVTRANS_LOGI("ctor called"); +} + +AVInputFilter::~AVInputFilter() +{ + AVTRANS_LOGI("dtor called"); + OSAL::ScopedLock lock(inputFilterMutex_); + if (plugin_ != nullptr) { + plugin_->Deinit(); + } +} + +std::vector AVInputFilter::GetWorkModes() +{ + return {WorkMode::PUSH}; +} + +ErrorCode AVInputFilter::SetParameter(int32_t key, const Any& value) +{ + Tag tag; + if (!TranslateIntoParameter(key, tag)) { + AVTRANS_LOGE("This key is invalid!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + { + OSAL::ScopedLock lock(inputFilterMutex_); + paramsMap_[tag] = value; + } + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::GetParameter(int32_t key, Any& value) +{ + Tag tag; + if (!TranslateIntoParameter(key, tag)) { + AVTRANS_LOGE("This key is invalid!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + { + OSAL::ScopedLock lock(inputFilterMutex_); + value = paramsMap_[tag]; + } + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::Prepare() +{ + AVTRANS_LOGI("Prepare entered."); + if (state_ != FilterState::INITIALIZED) { + AVTRANS_LOGE("The current state is invalid"); + return ErrorCode::ERROR_INVALID_STATE; + } + state_ = FilterState::PREPARING; + ErrorCode err = FindPlugin(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Find plugin fail"); + state_ = FilterState::INITIALIZED; + return err; + } + err = DoConfigure(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Configure downStream fail"); + state_ = FilterState::INITIALIZED; + return err; + } + err = PreparePlugin(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Prepare plugin fail"); + state_ = FilterState::INITIALIZED; + return err; + } + state_ = FilterState::READY; + AVTRANS_LOGI("Prepare end."); + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::Start() +{ + AVTRANS_LOGI("Start"); + OSAL::ScopedLock lock(inputFilterMutex_); + if (state_ != FilterState::READY && state_ != FilterState::PAUSED) { + AVTRANS_LOGE("The current state is invalid"); + return ErrorCode::ERROR_INVALID_STATE; + } + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_NULL_POINTER; + } + if (TranslatePluginStatus(plugin_->Start()) != ErrorCode::SUCCESS) { + AVTRANS_LOGE("The plugin start fail!"); + return ErrorCode::ERROR_INVALID_OPERATION; + } + state_ = FilterState::RUNNING; + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::Stop() +{ + AVTRANS_LOGI("Stop"); + OSAL::ScopedLock lock(inputFilterMutex_); + if (state_ != FilterState::RUNNING) { + AVTRANS_LOGE("The current state is invalid"); + return ErrorCode::ERROR_INVALID_STATE; + } + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_NULL_POINTER; + } + if (TranslatePluginStatus(plugin_->Stop()) != ErrorCode::SUCCESS) { + AVTRANS_LOGE("The plugin stop fail!"); + return ErrorCode::ERROR_INVALID_OPERATION; + } + state_ = FilterState::READY; + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::Pause() +{ + AVTRANS_LOGI("Pause"); + OSAL::ScopedLock lock(inputFilterMutex_); + if (state_ != FilterState::RUNNING) { + AVTRANS_LOGE("The current state is invalid"); + return ErrorCode::ERROR_INVALID_STATE; + } + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_NULL_POINTER; + } + if (TranslatePluginStatus(plugin_->Stop()) != ErrorCode::SUCCESS) { + AVTRANS_LOGE("The plugin stop fail!"); + return ErrorCode::ERROR_INVALID_OPERATION; + } + state_ = FilterState::PAUSED; + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::Resume() +{ + AVTRANS_LOGI("Resume"); + return ErrorCode::SUCCESS; +} + +void AVInputFilter::InitPorts() +{ + AVTRANS_LOGI("InitPorts"); + auto outPort = std::make_shared(this); + { + OSAL::ScopedLock lock(inputFilterMutex_); + outPorts_.push_back(outPort); + } +} + +ErrorCode AVInputFilter::FindPlugin() +{ + OSAL::ScopedLock lock(inputFilterMutex_); + std::string mime; + if (paramsMap_.find(Tag::MIME) == paramsMap_.end() || + !paramsMap_[Tag::MIME].SameTypeWith(typeid(std::string))) { + AVTRANS_LOGE("Must set mime correctly first"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + mime = Plugin::AnyCast(paramsMap_[Tag::MIME]); + auto nameList = PluginManager::Instance().ListPlugins(PluginType::GENERIC_PLUGIN); + for (const std::string& name : nameList) { + auto info = PluginManager::Instance().GetPluginInfo(PluginType::GENERIC_PLUGIN, name); + if (info->outCaps.empty() || mime != info->outCaps[0].mime) { + continue; + } + if (DoNegotiate(info->outCaps) && CreatePlugin(info) == ErrorCode::SUCCESS) { + AVTRANS_LOGI("CreatePlugin %s success", name_.c_str()); + return ErrorCode::SUCCESS; + } + } + AVTRANS_LOGI("Cannot find any plugin"); + return ErrorCode::ERROR_UNSUPPORTED_FORMAT; +} + +bool AVInputFilter::DoNegotiate(const CapabilitySet& outCaps) +{ + AVTRANS_LOGI("DoNegotiate start"); + if (outCaps.empty()) { + AVTRANS_LOGE("Input plugin must have out caps"); + return false; + } + for (const auto& outCap : outCaps) { + auto thisOutCap = std::make_shared(outCap); + AVTRANS_LOGI("thisOutCap %s", thisOutCap->mime.c_str()); + Meta upstreamParams; + Meta downstreamParams; + if (outPorts_.size() == 0 || outPorts_[0] == nullptr) { + AVTRANS_LOGE("outPorts is empty or invalid!"); + return false; + } + if (outPorts_[0]->Negotiate(thisOutCap, capNegWithDownstream_, upstreamParams, downstreamParams)) { + AVTRANS_LOGI("Negotiate success"); + return true; + } + } + AVTRANS_LOGI("DoNegotiate end"); + return false; +} + +ErrorCode AVInputFilter::CreatePlugin(const std::shared_ptr& selectedInfo) +{ + AVTRANS_LOGI("CreatePlugin"); + if (selectedInfo == nullptr || selectedInfo->name.empty()) { + AVTRANS_LOGE("selectedInfo is nullptr or pluginName is invalid!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + if ((plugin_ != nullptr) && (pluginInfo_ != nullptr)) { + if (selectedInfo->name == pluginInfo_->name && TranslatePluginStatus(plugin_->Reset()) == ErrorCode::SUCCESS) { + AVTRANS_LOGI("Reuse last plugin: %s", selectedInfo->name.c_str()); + return ErrorCode::SUCCESS; + } + if (TranslatePluginStatus(plugin_->Deinit()) != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Deinit last plugin: %s error", pluginInfo_->name.c_str()); + } + } + plugin_ = PluginManager::Instance().CreateGenericPlugin(selectedInfo->name); + if (plugin_ == nullptr) { + AVTRANS_LOGE("PluginManager CreatePlugin %s fail", selectedInfo->name.c_str()); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + pluginInfo_ = selectedInfo; + AVTRANS_LOGI("Create new plugin: %s success", pluginInfo_->name.c_str()); + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::DoConfigure() +{ + Plugin::Meta emptyMeta; + Plugin::Meta targetMeta; + if (MergeMeta(emptyMeta, targetMeta) != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Merge Meta fail!"); + return ErrorCode::ERROR_INVALID_OPERATION; + } + if (ConfigMeta(targetMeta) != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Config Meta fail!"); + return ErrorCode::ERROR_INVALID_OPERATION; + } + if (ConfigDownStream(targetMeta) != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Config DownStream fail!"); + return ErrorCode::ERROR_INVALID_OPERATION; + } + auto err = InitPlugin(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Init plugin fail"); + state_ = FilterState::INITIALIZED; + return ErrorCode::ERROR_INVALID_OPERATION; + } + err = ConfigPlugin(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Configure plugin fail"); + state_ = FilterState::INITIALIZED; + return ErrorCode::ERROR_INVALID_OPERATION; + } + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::MergeMeta(const Plugin::Meta& meta, Plugin::Meta& targetMeta) +{ + OSAL::ScopedLock lock(inputFilterMutex_); + if (!MergeMetaWithCapability(meta, capNegWithDownstream_, targetMeta)) { + AVTRANS_LOGE("cannot find available capability of plugin %s", pluginInfo_->name.c_str()); + return ErrorCode::ERROR_INVALID_OPERATION; + } + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::ConfigMeta(Plugin::Meta& meta) +{ + AVTRANS_LOGI("ConfigMeta start!"); + OSAL::ScopedLock lock(inputFilterMutex_); + if (paramsMap_.find(Tag::MEDIA_TYPE) == paramsMap_.end() || + !paramsMap_[Tag::MEDIA_TYPE].SameTypeWith(typeid(Plugin::MediaType))) { + AVTRANS_LOGE("MEDIA_TYPE in ParamsMap is not exist!"); + return ErrorCode::ERROR_NOT_EXISTED; + } + auto mediaType = Plugin::AnyCast(paramsMap_[Tag::MEDIA_TYPE]); + if (mediaType == MediaType::VIDEO) { + ConfigVideoMeta(meta); + } else { + ConfigAudioMeta(meta); + } + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::ConfigVideoMeta(Plugin::Meta& meta) +{ + AVTRANS_LOGI("ConfigVideoMeta start!"); + if (paramsMap_.find(Tag::VIDEO_WIDTH) != paramsMap_.end() && + paramsMap_[Tag::VIDEO_WIDTH].SameTypeWith(typeid(int))) { + uint32_t width = static_cast(Plugin::AnyCast(paramsMap_[Tag::VIDEO_WIDTH])); + AVTRANS_LOGI("ConfigVideoMeta: VIDEO_WIDTH is %d", width); + meta.Set(width); + } + if (paramsMap_.find(Tag::VIDEO_HEIGHT) != paramsMap_.end() && + paramsMap_[Tag::VIDEO_HEIGHT].SameTypeWith(typeid(int))) { + uint32_t height = static_cast(Plugin::AnyCast(paramsMap_[Tag::VIDEO_HEIGHT])); + AVTRANS_LOGI("ConfigVideoMeta: VIDEO_HEIGHT is %d", height); + meta.Set(height); + } + if (paramsMap_.find(Tag::MEDIA_BITRATE) != paramsMap_.end() && + paramsMap_[Tag::MEDIA_BITRATE].SameTypeWith(typeid(int))) { + int64_t mediaBitRate = Plugin::AnyCast(paramsMap_[Tag::MEDIA_BITRATE]); + AVTRANS_LOGI("ConfigVideoMeta: MEDIA_BITRATE is %ld", mediaBitRate); + meta.Set(mediaBitRate); + } + if (paramsMap_.find(Tag::VIDEO_FRAME_RATE) != paramsMap_.end() && + paramsMap_[Tag::VIDEO_FRAME_RATE].SameTypeWith(typeid(int))) { + uint32_t videoFrameRate = static_cast(Plugin::AnyCast(paramsMap_[Tag::VIDEO_FRAME_RATE])); + AVTRANS_LOGI("ConfigVideoMeta: VIDEO_FRAME_RATE is %d", videoFrameRate); + meta.Set(videoFrameRate); + } + if (paramsMap_.find(Tag::VIDEO_BIT_STREAM_FORMAT) != paramsMap_.end() && + paramsMap_[Tag::VIDEO_BIT_STREAM_FORMAT].SameTypeWith(typeid(VideoBitStreamFormat))) { + auto videoBitStreamFormat = Plugin::AnyCast(paramsMap_[Tag::VIDEO_BIT_STREAM_FORMAT]); + AVTRANS_LOGI("ConfigVideoMeta: VIDEO_BIT_STREAM_FORMAT is %d", videoBitStreamFormat); + meta.Set(std::vector{videoBitStreamFormat}); + } + if (paramsMap_.find(Tag::VIDEO_PIXEL_FORMAT) != paramsMap_.end() && + paramsMap_[Tag::VIDEO_PIXEL_FORMAT].SameTypeWith(typeid(VideoPixelFormat))) { + auto videoPixelFormat = Plugin::AnyCast(paramsMap_[Tag::VIDEO_PIXEL_FORMAT]); + AVTRANS_LOGI("ConfigVideoMeta: VIDEO_PIXEL_FORMAT is %d", videoPixelFormat); + meta.Set(videoPixelFormat); + } + return ErrorCode::SUCCESS; +} + +OHOS::Media::Plugin::AudioChannelLayout AVInputFilter::TransAudioChannelLayout(int layoutPtr) +{ + const static std::pair mapArray[] = { + {1, OHOS::Media::Plugin::AudioChannelLayout::MONO}, + {2, OHOS::Media::Plugin::AudioChannelLayout::STEREO}, + }; + for (const auto& item : mapArray) { + if (item.first == layoutPtr) { + return item.second; + } + } + return OHOS::Media::Plugin::AudioChannelLayout::UNKNOWN; +} + +OHOS::Media::Plugin::AudioSampleFormat AVInputFilter::TransAudioSampleFormat(int sampleFormat) +{ + const static std::pair mapArray[] = { + {0, OHOS::Media::Plugin::AudioSampleFormat::U8}, + {1, OHOS::Media::Plugin::AudioSampleFormat::S16}, + {2, OHOS::Media::Plugin::AudioSampleFormat::S24}, + {3, OHOS::Media::Plugin::AudioSampleFormat::S32}, + {4, OHOS::Media::Plugin::AudioSampleFormat::F32P}, + {-1, OHOS::Media::Plugin::AudioSampleFormat::NONE}, + }; + for (const auto& item : mapArray) { + if (item.first == sampleFormat) { + return item.second; + } + } + return OHOS::Media::Plugin::AudioSampleFormat::NONE; +} + +ErrorCode AVInputFilter::ConfigAudioMeta(Plugin::Meta& meta) +{ + AVTRANS_LOGI("ConfigAudioMeta start"); + if (paramsMap_.find(Tag::AUDIO_CHANNELS) != paramsMap_.end() && + paramsMap_[Tag::AUDIO_CHANNELS].SameTypeWith(typeid(int))) { + uint32_t audioChannel = static_cast(Plugin::AnyCast(paramsMap_[Tag::AUDIO_CHANNELS])); + AVTRANS_LOGI("ConfigAudioMeta: AUDIO_CHANNELS is %d", audioChannel); + meta.Set(audioChannel); + } + if (paramsMap_.find(Tag::AUDIO_SAMPLE_RATE) != paramsMap_.end() && + paramsMap_[Tag::AUDIO_SAMPLE_RATE].SameTypeWith(typeid(int))) { + uint32_t sampleRate = static_cast(Plugin::AnyCast(paramsMap_[Tag::AUDIO_SAMPLE_RATE])); + AVTRANS_LOGI("ConfigAudioMeta: AUDIO_SAMPLE_RATE is %d", sampleRate); + meta.Set(sampleRate); + } + if (paramsMap_.find(Tag::MEDIA_BITRATE) != paramsMap_.end() && + paramsMap_[Tag::MEDIA_BITRATE].SameTypeWith(typeid(int))) { + int64_t mediaBitRate = Plugin::AnyCast(paramsMap_[Tag::MEDIA_BITRATE]); + AVTRANS_LOGI("ConfigAudioMeta: MEDIA_BITRATE is %ld", mediaBitRate); + meta.Set(mediaBitRate); + } + if (paramsMap_.find(Tag::AUDIO_SAMPLE_FORMAT) != paramsMap_.end() && + paramsMap_[Tag::AUDIO_SAMPLE_FORMAT].SameTypeWith(typeid(int))) { + auto audioSampleFmtPtr = Plugin::AnyCast(paramsMap_[Tag::AUDIO_SAMPLE_FORMAT]); + AVTRANS_LOGI("ConfigAudioMeta: AUDIO_SAMPLE_FORMAT is %d", audioSampleFmtPtr); + meta.Set(TransAudioSampleFormat(audioSampleFmtPtr)); + } + if (paramsMap_.find(Tag::AUDIO_CHANNEL_LAYOUT) != paramsMap_.end() && + paramsMap_[Tag::AUDIO_CHANNEL_LAYOUT].SameTypeWith(typeid(int))) { + auto layoutPtr = Plugin::AnyCast(paramsMap_[Tag::AUDIO_CHANNEL_LAYOUT]); + AVTRANS_LOGI("ConfigAudioMeta: AUDIO_CHANNEL_LAYOUT is %d", layoutPtr); + meta.Set(TransAudioChannelLayout(layoutPtr)); + } + if (paramsMap_.find(Tag::AUDIO_SAMPLE_PER_FRAME) != paramsMap_.end() && + paramsMap_[Tag::AUDIO_SAMPLE_PER_FRAME].SameTypeWith(typeid(int))) { + uint32_t samplePerFrame = static_cast(Plugin::AnyCast(paramsMap_[Tag::AUDIO_SAMPLE_PER_FRAME])); + AVTRANS_LOGI("ConfigAudioMeta: AUDIO_SAMPLE_PER_FRAME is %d", samplePerFrame); + meta.Set(samplePerFrame); + } + if (paramsMap_.find(Tag::AUDIO_AAC_LEVEL) != paramsMap_.end() && + paramsMap_[Tag::AUDIO_AAC_LEVEL].SameTypeWith(typeid(int))) { + uint32_t aacLevel = static_cast(Plugin::AnyCast(paramsMap_[Tag::AUDIO_AAC_LEVEL])); + AVTRANS_LOGI("ConfigAudioMeta: AUDIO_AAC_LEVEL is %d", aacLevel); + meta.Set(aacLevel); + } + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::ConfigDownStream(const Plugin::Meta& meta) +{ + Meta upstreamParams; + Meta downstreamParams; + OSAL::ScopedLock lock(inputFilterMutex_); + if (outPorts_.size() == 0 || outPorts_[0] == nullptr) { + AVTRANS_LOGE("outPorts is empty or invalid!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + if (!outPorts_[0]->Configure(std::make_shared(meta), upstreamParams, downstreamParams)) { + AVTRANS_LOGE("Configure downstream fail"); + return ErrorCode::ERROR_INVALID_OPERATION; + } + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::InitPlugin() +{ + AVTRANS_LOGI("InitPlugin"); + OSAL::ScopedLock lock(inputFilterMutex_); + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + return TranslatePluginStatus(plugin_->Init()); +} + +ErrorCode AVInputFilter::ConfigPlugin() +{ + AVTRANS_LOGI("Configure"); + ErrorCode err = SetPluginParams(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Set Plugin fail!"); + return err; + } + err = SetEventCallBack(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Plugin SetEventCallBack fail!"); + return err; + } + err = SetDataCallBack(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Plugin SetDataCallBack fail!"); + return err; + } + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::SetPluginParams() +{ + OSAL::ScopedLock lock(inputFilterMutex_); + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_NULL_POINTER; + } + if (paramsMap_.find(Tag::MEDIA_DESCRIPTION) != paramsMap_.end()) { + plugin_->SetParameter(Tag::MEDIA_DESCRIPTION, paramsMap_[Tag::MEDIA_DESCRIPTION]); + } + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::PreparePlugin() +{ + OSAL::ScopedLock lock(inputFilterMutex_); + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_NULL_POINTER; + } + return TranslatePluginStatus(plugin_->Prepare()); +} + +ErrorCode AVInputFilter::PushData(const std::string& inPort, const AVBufferPtr& buffer, int64_t offset) +{ + OSAL::ScopedLock lock(inputFilterMutex_); + if (name_.compare(inPort) != 0) { + AVTRANS_LOGE("FilterName is not targetName!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + if (buffer == nullptr || plugin_ == nullptr) { + AVTRANS_LOGE("buffer or plugin is nullptr!"); + return ErrorCode::ERROR_NULL_POINTER; + } + AVTRANS_LOGI("PushData to plugin"); + if (TranslatePluginStatus(plugin_->PushData(inPort, buffer, offset)) != ErrorCode::SUCCESS) { + AVTRANS_LOGE("PushData to plugin fail!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + AVTRANS_LOGI("PushData from plugin"); + if (outPorts_.size() == 0 || outPorts_[0] == nullptr) { + AVTRANS_LOGE("outPorts is empty or invalid!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + AVTRANS_LOGI("PushData to next filter plugin!"); + outPorts_[0]->PushData(buffer, 0); + return ErrorCode::SUCCESS; +} + +ErrorCode AVInputFilter::SetEventCallBack() +{ + OSAL::ScopedLock lock(inputFilterMutex_); + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_NULL_POINTER ; + } + return TranslatePluginStatus(plugin_->SetCallback(this)); +} + +ErrorCode AVInputFilter::SetDataCallBack() +{ + OSAL::ScopedLock lock(inputFilterMutex_); + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_NULL_POINTER; + } + return TranslatePluginStatus(plugin_->SetDataCallback(std::bind(&AVInputFilter::OnDataCallback, this, + std::placeholders::_1))); +} + +void AVInputFilter::OnDataCallback(std::shared_ptr buffer) +{ + OSAL::ScopedLock lock(inputFilterMutex_); + if (buffer == nullptr) { + AVTRANS_LOGE("buffer is nullptr!"); + return; + } + if (outPorts_.size() == 0 || outPorts_[0] == nullptr) { + AVTRANS_LOGE("outPorts is invalid!"); + return; + } + outPorts_[0]->PushData(buffer, 0); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/av_transport/av_trans_engine/filters/av_transport_input/av_transport_input_filter.h b/av_transport/av_trans_engine/filters/av_transport_input/av_transport_input_filter.h new file mode 100644 index 0000000000000000000000000000000000000000..8debcd5fca2e88b0dc0848899249e6ede73dc920 --- /dev/null +++ b/av_transport/av_trans_engine/filters/av_transport_input/av_transport_input_filter.h @@ -0,0 +1,82 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MEDIA_PIPELINE_INPUT_FILTER_H +#define MEDIA_PIPELINE_INPUT_FILTER_H + +#include +#include + +#include "foundation/osal/utils/util.h" +#include "foundation/utils/constants.h" +#include "pipeline/core/error_code.h" +#include "pipeline/core/filter_base.h" +#include "plugin/common/plugin_video_tags.h" +#include "plugin/core/plugin_manager.h" +#include "pipeline/core/type_define.h" +#include "../../plugin/interface/avtrans_input_plugin.h" +#include "../../plugin/core/avtrans_input.h" + +namespace OHOS { +namespace DistributedHardware { + +using namespace OHOS::Media; +using namespace OHOS::Media::Pipeline; + +class AVInputFilter : public FilterBase { +public: + explicit AVInputFilter(const std::string& name); + ~AVInputFilter() override; + + std::vector GetWorkModes() override; + ErrorCode SetParameter(int32_t key, const Plugin::Any& value) override; + ErrorCode GetParameter(int32_t key, Plugin::Any& value) override; + ErrorCode Prepare() override; + ErrorCode Start() override; + ErrorCode Stop() override; + ErrorCode Pause() override; + ErrorCode Resume() override; + ErrorCode PushData(const std::string& inPort, const AVBufferPtr& buffer, int64_t offset) override; + +private: + void InitPorts() override; + ErrorCode FindPlugin(); + bool DoNegotiate(const CapabilitySet& outCaps); + ErrorCode CreatePlugin(const std::shared_ptr& selectedInfo); + ErrorCode DoConfigure(); + ErrorCode MergeMeta(const Plugin::Meta& meta, Plugin::Meta& targetMeta); + ErrorCode ConfigMeta(Plugin::Meta& meta); + ErrorCode ConfigVideoMeta(Plugin::Meta& meta); + ErrorCode ConfigAudioMeta(Plugin::Meta& meta); + ErrorCode ConfigDownStream(const Plugin::Meta& meta); + ErrorCode InitPlugin(); + ErrorCode ConfigPlugin(); + ErrorCode PreparePlugin(); + ErrorCode SetEventCallBack(); + ErrorCode SetDataCallBack(); + ErrorCode SetPluginParams(); + void OnDataCallback(std::shared_ptr buffer); + OHOS::Media::Plugin::AudioChannelLayout TransAudioChannelLayout(int layoutPtr); + OHOS::Media::Plugin::AudioSampleFormat TransAudioSampleFormat(int sampleFormat); + + std::shared_ptr plugin_ {nullptr}; + std::shared_ptr pluginInfo_ {nullptr}; + Capability capNegWithDownstream_ {}; + std::unordered_map paramsMap_; + OSAL::Mutex inputFilterMutex_ {}; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/av_transport/av_trans_engine/filters/av_transport_output/av_transport_output_filter.cpp b/av_transport/av_trans_engine/filters/av_transport_output/av_transport_output_filter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b7a2005e3d373a200b5e1efab06d2b83c4cfd4ab --- /dev/null +++ b/av_transport/av_trans_engine/filters/av_transport_output/av_transport_output_filter.cpp @@ -0,0 +1,368 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define HST_LOG_TAG "AVOutputFilter" +#include "av_transport_output_filter.h" +#include "av_trans_log.h" +#include "av_trans_constants.h" +#include "pipeline/filters/common/plugin_utils.h" +#include "pipeline/factory/filter_factory.h" +#include "plugin/common/plugin_attr_desc.h" + +namespace OHOS { +namespace DistributedHardware { + +static AutoRegisterFilter g_registerFilterHelper("builtin.avtransport.avoutput"); + +AVOutputFilter::AVOutputFilter(const std::string& name) : FilterBase(name), plugin_(nullptr), pluginInfo_(nullptr) +{ + AVTRANS_LOGI("ctor called"); +} + +AVOutputFilter::~AVOutputFilter() +{ + AVTRANS_LOGI("dtor called"); + OSAL::ScopedLock lock(outputFilterMutex_); + if (plugin_ != nullptr) { + plugin_->Deinit(); + } +} + +std::vector AVOutputFilter::GetWorkModes() +{ + return {WorkMode::PUSH}; +} + +ErrorCode AVOutputFilter::SetParameter(int32_t key, const Any& value) +{ + AVTRANS_LOGI("SetParameter key %d", key); + Tag tag; + if (!TranslateIntoParameter(key, tag)) { + AVTRANS_LOGE("This key is invalid!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + { + OSAL::ScopedLock lock(outputFilterMutex_); + paramsMap_[tag] = value; + } + return ErrorCode::SUCCESS; +} + +ErrorCode AVOutputFilter::GetParameter(int32_t key, Any& value) +{ + Tag tag; + if (!TranslateIntoParameter(key, tag)) { + AVTRANS_LOGE("This key is invalid!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + { + OSAL::ScopedLock lock(outputFilterMutex_); + value = paramsMap_[tag]; + } + return ErrorCode::SUCCESS; +} + +ErrorCode AVOutputFilter::Prepare() +{ + AVTRANS_LOGI("Prepare entered."); + if (state_ != FilterState::INITIALIZED) { + AVTRANS_LOGE("The current state is invalid"); + return ErrorCode::ERROR_INVALID_STATE; + } + state_ = FilterState::PREPARING; + ErrorCode err = FindPlugin(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Find plugin fail"); + state_ = FilterState::INITIALIZED; + return err; + } + err = InitPlugin(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Init plugin fail"); + state_ = FilterState::INITIALIZED; + return err; + } + err = ConfigPlugin(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Configure downStream fail"); + state_ = FilterState::INITIALIZED; + return err; + } + err = PreparePlugin(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Prepare plugin fail"); + state_ = FilterState::INITIALIZED; + return err; + } + state_ = FilterState::READY; + AVTRANS_LOGI("Prepare end."); + return err; +} + +ErrorCode AVOutputFilter::Start() +{ + AVTRANS_LOGI("Start"); + OSAL::ScopedLock lock(outputFilterMutex_); + if (state_ != FilterState::READY && state_ != FilterState::PAUSED) { + AVTRANS_LOGE("The current state is invalid"); + return ErrorCode::ERROR_INVALID_STATE; + } + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_NULL_POINTER; + } + if (TranslatePluginStatus(plugin_->Start()) != ErrorCode::SUCCESS) { + AVTRANS_LOGE("The plugin start fail!"); + return ErrorCode::ERROR_INVALID_OPERATION; + } + state_ = FilterState::RUNNING; + return ErrorCode::SUCCESS; +} + +ErrorCode AVOutputFilter::Stop() +{ + AVTRANS_LOGI("Stop"); + OSAL::ScopedLock lock(outputFilterMutex_); + if (state_ != FilterState::RUNNING) { + AVTRANS_LOGE("The current state is invalid"); + return ErrorCode::ERROR_INVALID_STATE; + } + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_NULL_POINTER; + } + if (TranslatePluginStatus(plugin_->Stop()) != ErrorCode::SUCCESS) { + AVTRANS_LOGE("The plugin stop fail!"); + return ErrorCode::ERROR_INVALID_OPERATION; + } + state_ = FilterState::READY; + return ErrorCode::SUCCESS; +} + +ErrorCode AVOutputFilter::Pause() +{ + AVTRANS_LOGI("Pause"); + OSAL::ScopedLock lock(outputFilterMutex_); + if (state_ != FilterState::RUNNING) { + AVTRANS_LOGE("The current state is invalid"); + return ErrorCode::ERROR_INVALID_STATE; + } + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_NULL_POINTER; + } + if (TranslatePluginStatus(plugin_->Stop()) != ErrorCode::SUCCESS) { + AVTRANS_LOGE("The plugin stop fail!"); + return ErrorCode::ERROR_INVALID_OPERATION; + } + state_ = FilterState::PAUSED; + return ErrorCode::SUCCESS; +} + +ErrorCode AVOutputFilter::Resume() +{ + AVTRANS_LOGI("Resume"); + return ErrorCode::SUCCESS; +} + +void AVOutputFilter::InitPorts() +{ + AVTRANS_LOGI("InitPorts"); + auto inPort = std::make_shared(this); + { + OSAL::ScopedLock lock(outputFilterMutex_); + inPorts_.push_back(inPort); + } +} + +ErrorCode AVOutputFilter::FindPlugin() +{ + OSAL::ScopedLock lock(outputFilterMutex_); + std::string mime; + if (paramsMap_.find(Tag::MIME) == paramsMap_.end() || + !paramsMap_[Tag::MIME].SameTypeWith(typeid(std::string))) { + AVTRANS_LOGE("Must set mime correctly first"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + mime = Plugin::AnyCast(paramsMap_[Tag::MIME]); + auto nameList = PluginManager::Instance().ListPlugins(PluginType::GENERIC_PLUGIN); + for (const std::string& name : nameList) { + auto info = PluginManager::Instance().GetPluginInfo(PluginType::GENERIC_PLUGIN, name); + if (info->inCaps.empty() || mime != info->inCaps[0].mime) { + continue; + } + if (CreatePlugin(info) == ErrorCode::SUCCESS) { + AVTRANS_LOGI("CreatePlugin %s success", name_.c_str()); + return ErrorCode::SUCCESS; + } + } + AVTRANS_LOGI("Cannot find any plugin"); + return ErrorCode::ERROR_UNSUPPORTED_FORMAT; +} + +bool AVOutputFilter::Negotiate(const std::string& inPort, const std::shared_ptr& upstreamCap, + Plugin::Capability& negotiatedCap, const Plugin::Meta& upstreamParams, Plugin::Meta& downstreamParams) +{ + AVTRANS_LOGI("Negotiate"); + if (pluginInfo_ == nullptr) { + AVTRANS_LOGE("pluginInfo_ is nullptr"); + return false; + } + negotiatedCap = pluginInfo_->inCaps[0]; + return true; +} + +ErrorCode AVOutputFilter::CreatePlugin(const std::shared_ptr& selectedInfo) +{ + AVTRANS_LOGI("CreatePlugin"); + if (selectedInfo == nullptr || selectedInfo->name.empty()) { + AVTRANS_LOGE("selectedInfo is nullptr or pluginName is invalid!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + if ((plugin_ != nullptr) && (pluginInfo_ != nullptr)) { + if (selectedInfo->name == pluginInfo_->name && TranslatePluginStatus(plugin_->Reset()) == ErrorCode::SUCCESS) { + AVTRANS_LOGI("Reuse last plugin: %s", selectedInfo->name.c_str()); + return ErrorCode::SUCCESS; + } + if (TranslatePluginStatus(plugin_->Deinit()) != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Deinit last plugin: %s error", pluginInfo_->name.c_str()); + } + } + plugin_ = PluginManager::Instance().CreateGenericPlugin(selectedInfo->name); + if (plugin_ == nullptr) { + AVTRANS_LOGE("PluginManager CreatePlugin %s fail", selectedInfo->name.c_str()); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + pluginInfo_ = selectedInfo; + AVTRANS_LOGI("Create new plugin: %s success", pluginInfo_->name.c_str()); + return ErrorCode::SUCCESS; +} + +bool AVOutputFilter::Configure(const std::string& inPort, const std::shared_ptr& upstreamMeta, + Plugin::Meta& upstreamParams, Plugin::Meta& downstreamParams) +{ + AVTRANS_LOGI("DoConfigure"); + return true; +} + +ErrorCode AVOutputFilter::InitPlugin() +{ + AVTRANS_LOGI("InitPlugin"); + OSAL::ScopedLock lock(outputFilterMutex_); + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + return TranslatePluginStatus(plugin_->Init()); +} + +ErrorCode AVOutputFilter::ConfigPlugin() +{ + AVTRANS_LOGI("Configure"); + ErrorCode err = SetPluginParams(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Set Plugin fail!"); + return err; + } + err = SetEventCallBack(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Plugin SetEventCallBack fail!"); + return err; + } + err = SetDataCallBack(); + if (err != ErrorCode::SUCCESS) { + AVTRANS_LOGE("Plugin SetDataCallBack fail!"); + return err; + } + return ErrorCode::SUCCESS; +} + +ErrorCode AVOutputFilter::PreparePlugin() +{ + OSAL::ScopedLock lock(outputFilterMutex_); + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_INVALID_PARAMETER_TYPE; + } + return TranslatePluginStatus(plugin_->Prepare()); +} + +ErrorCode AVOutputFilter::PushData(const std::string& inPort, const AVBufferPtr& buffer, int64_t offset) +{ + OSAL::ScopedLock lock(outputFilterMutex_); + if (buffer == nullptr || plugin_ == nullptr) { + AVTRANS_LOGE("buffer or plugin is nullptr!"); + return ErrorCode::ERROR_INVALID_PARAMETER_TYPE; + } + plugin_->PushData(inPort, buffer, offset); + AVTRANS_LOGE("push buffer to plugin."); + return ErrorCode::SUCCESS; +} + +ErrorCode AVOutputFilter::SetPluginParams() +{ + OSAL::ScopedLock lock(outputFilterMutex_); + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_NULL_POINTER; + } + if (paramsMap_.find(Tag::MEDIA_DESCRIPTION) != paramsMap_.end()) { + plugin_->SetParameter(Tag::MEDIA_DESCRIPTION, paramsMap_[Tag::MEDIA_DESCRIPTION]); + } + if (paramsMap_.find(Tag::AUDIO_CHANNELS) != paramsMap_.end()) { + plugin_->SetParameter(Tag::AUDIO_CHANNELS, paramsMap_[Tag::AUDIO_CHANNELS]); + } + if (paramsMap_.find(Tag::AUDIO_SAMPLE_RATE) != paramsMap_.end()) { + plugin_->SetParameter(Tag::AUDIO_SAMPLE_RATE, paramsMap_[Tag::AUDIO_SAMPLE_RATE]); + } + if (paramsMap_.find(Tag::AUDIO_CHANNEL_LAYOUT) != paramsMap_.end()) { + plugin_->SetParameter(Tag::AUDIO_CHANNEL_LAYOUT, paramsMap_[Tag::AUDIO_CHANNEL_LAYOUT]); + } + return ErrorCode::SUCCESS; +} + +ErrorCode AVOutputFilter::SetEventCallBack() +{ + OSAL::ScopedLock lock(outputFilterMutex_); + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + plugin_->SetCallback(this); + return ErrorCode::SUCCESS; +} + +ErrorCode AVOutputFilter::SetDataCallBack() +{ + OSAL::ScopedLock lock(outputFilterMutex_); + if (plugin_ == nullptr) { + AVTRANS_LOGE("plugin is nullptr!"); + return ErrorCode::ERROR_INVALID_PARAMETER_VALUE; + } + plugin_->SetDataCallback(std::bind(&AVOutputFilter::OnDataCallback, this, std::placeholders::_1)); + return ErrorCode::SUCCESS; +} + +void AVOutputFilter::OnDataCallback(std::shared_ptr buffer) +{ + OSAL::ScopedLock lock(outputFilterMutex_); + if (buffer == nullptr) { + AVTRANS_LOGE("buffer is nullptr!"); + return; + } + OnEvent(Event{name_, EventType::EVENT_BUFFER_PROGRESS, buffer}); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/av_transport/av_trans_engine/filters/av_transport_output/av_transport_output_filter.h b/av_transport/av_trans_engine/filters/av_transport_output/av_transport_output_filter.h new file mode 100644 index 0000000000000000000000000000000000000000..5390ae7902ce8a34d28d8183b7fe4059e046479a --- /dev/null +++ b/av_transport/av_trans_engine/filters/av_transport_output/av_transport_output_filter.h @@ -0,0 +1,77 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MEDIA_PIPELINE_OUTPUT_FILTER_H +#define MEDIA_PIPELINE_OUTPUT_FILTER_H + +#include +#include + +#include "foundation/osal/utils/util.h" +#include "foundation/utils/constants.h" +#include "pipeline/core/error_code.h" +#include "pipeline/core/filter_base.h" +#include "plugin/common/plugin_video_tags.h" +#include "plugin/core/plugin_manager.h" +#include "pipeline/core/type_define.h" +#include "../../plugin/interface/avtrans_output_plugin.h" +#include "../../plugin/core/avtrans_output.h" + +namespace OHOS { +namespace DistributedHardware { + +using namespace OHOS::Media; +using namespace OHOS::Media::Pipeline; + +class AVOutputFilter : public FilterBase { +public: + explicit AVOutputFilter(const std::string& name); + ~AVOutputFilter() override; + + std::vector GetWorkModes() override; + ErrorCode SetParameter(int32_t key, const Plugin::Any& value) override; + ErrorCode GetParameter(int32_t key, Plugin::Any& value) override; + ErrorCode Prepare() override; + ErrorCode Start() override; + ErrorCode Stop() override; + ErrorCode Pause() override; + ErrorCode Resume() override; + ErrorCode PushData(const std::string& inPort, const AVBufferPtr& buffer, int64_t offset) override; + bool Negotiate(const std::string& inPort, const std::shared_ptr& upstreamCap, + Plugin::Capability& negotiatedCap, const Plugin::Meta& upstreamParams, + Plugin::Meta& downstreamParams) override; + bool Configure(const std::string& inPort, const std::shared_ptr& upstreamMeta, + Plugin::Meta& upstreamParams, Plugin::Meta& downstreamParams) override; + +private: + void InitPorts() override; + ErrorCode FindPlugin(); + ErrorCode CreatePlugin(const std::shared_ptr& selectedInfo); + ErrorCode InitPlugin(); + ErrorCode ConfigPlugin(); + ErrorCode PreparePlugin(); + ErrorCode SetEventCallBack(); + ErrorCode SetDataCallBack(); + ErrorCode SetPluginParams(); + void OnDataCallback(std::shared_ptr buffer); + + std::shared_ptr plugin_ {nullptr}; + std::shared_ptr pluginInfo_ {nullptr}; + std::unordered_map paramsMap_; + OSAL::Mutex outputFilterMutex_ {}; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/av_transport/av_trans_engine/plugin/core/avtrans_input.cpp b/av_transport/av_trans_engine/plugin/core/avtrans_input.cpp new file mode 100644 index 0000000000000000000000000000000000000000..258ca24df90ca7fa54e243fed23e5cead90f5101 --- /dev/null +++ b/av_transport/av_trans_engine/plugin/core/avtrans_input.cpp @@ -0,0 +1,36 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "avtrans_input.h" + +#include "../interface/avtrans_input_plugin.h" + +namespace OHOS { +namespace DistributedHardware { + +AvTransInput::AvTransInput(uint32_t pkgVer, uint32_t apiVer, std::shared_ptr plugin) + : Base(pkgVer, apiVer, plugin), AvTransInputPlugin_(std::move(plugin)) {} + +Status AvTransInput::PushData(const std::string& inPort, std::shared_ptr buffer, int32_t offset) +{ + return AvTransInputPlugin_->PushData(inPort, buffer, offset); +} + +Status AvTransInput::SetDataCallback(std::function)> callback) +{ + return AvTransInputPlugin_->SetDataCallback(callback); +} +} +} \ No newline at end of file diff --git a/av_transport/av_trans_engine/plugin/core/avtrans_input.h b/av_transport/av_trans_engine/plugin/core/avtrans_input.h new file mode 100644 index 0000000000000000000000000000000000000000..26190d5e52b1854dfac7c2e2daa2d855b1ee60fc --- /dev/null +++ b/av_transport/av_trans_engine/plugin/core/avtrans_input.h @@ -0,0 +1,50 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HISTREAMER_PLUGIN_CORE_AVTRANS_INPUT_H +#define HISTREAMER_PLUGIN_CORE_AVTRANS_INPUT_H + +#include +#include +#include + +#include "plugin/core/base.h" +#include "plugin/common/plugin_types.h" + +namespace OHOS { +namespace DistributedHardware { +struct AvTransInputPlugin; + +using namespace OHOS::Media; +using namespace OHOS::Media::Plugin; + +class AvTransInput : public Base { +public: + AvTransInput(const AvTransInput &) = delete; + AvTransInput operator=(const AvTransInput &) = delete; + ~AvTransInput() override = default; + + Status PushData(const std::string& inPort, std::shared_ptr buffer, int32_t offset); + + Status SetDataCallback(std::function)> callback); + + AvTransInput(uint32_t pkgVer, uint32_t apiVer, std::shared_ptr plugin); + +private: + std::shared_ptr AvTransInputPlugin_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // HISTREAMER_PLUGIN_CORE_AVTRANS_INPUT_H \ No newline at end of file diff --git a/av_transport/av_trans_engine/plugin/core/avtrans_output.cpp b/av_transport/av_trans_engine/plugin/core/avtrans_output.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d5de623cac8432667b43f7e04c5f8ef63afc4d78 --- /dev/null +++ b/av_transport/av_trans_engine/plugin/core/avtrans_output.cpp @@ -0,0 +1,36 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "avtrans_output.h" + +#include "../interface/avtrans_output_plugin.h" + +namespace OHOS { +namespace DistributedHardware { + +AvTransOutput::AvTransOutput(uint32_t pkgVer, uint32_t apiVer, std::shared_ptr plugin) + : Base(pkgVer, apiVer, plugin), AvTransOutputPlugin_(std::move(plugin)) {} + +Status AvTransOutput::PushData(const std::string& inPort, std::shared_ptr buffer, int32_t offset) +{ + return AvTransOutputPlugin_->PushData(inPort, buffer, offset); +} + +Status AvTransOutput::SetDataCallback(std::function)> callback) +{ + return AvTransOutputPlugin_->SetDataCallback(callback); +} +} +} \ No newline at end of file diff --git a/av_transport/av_trans_engine/plugin/core/avtrans_output.h b/av_transport/av_trans_engine/plugin/core/avtrans_output.h new file mode 100644 index 0000000000000000000000000000000000000000..7c3f168926b2cc42372362effd970d8195f0d3f8 --- /dev/null +++ b/av_transport/av_trans_engine/plugin/core/avtrans_output.h @@ -0,0 +1,50 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HISTREAMER_PLUGIN_CORE_AVTRANS_OUTPUT_H +#define HISTREAMER_PLUGIN_CORE_AVTRANS_OUTPUT_H + +#include +#include +#include + +#include "plugin/core/base.h" +#include "plugin/common/plugin_types.h" + +namespace OHOS { +namespace DistributedHardware { +struct AvTransOutputPlugin; + +using namespace OHOS::Media; +using namespace OHOS::Media::Plugin; + +class AvTransOutput : public Base { +public: + AvTransOutput(const AvTransOutput &) = delete; + AvTransOutput operator=(const AvTransOutput &) = delete; + ~AvTransOutput() override = default; + + Status PushData(const std::string& inPort, std::shared_ptr buffer, int32_t offset); + + Status SetDataCallback(std::function)> callback); + + AvTransOutput(uint32_t pkgVer, uint32_t apiVer, std::shared_ptr plugin); + +private: + std::shared_ptr AvTransOutputPlugin_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // HISTREAMER_PLUGIN_CORE_AVTRANS_OUTPUT_H \ No newline at end of file diff --git a/av_transport/av_trans_engine/plugin/interface/avtrans_input_plugin.h b/av_transport/av_trans_engine/plugin/interface/avtrans_input_plugin.h new file mode 100644 index 0000000000000000000000000000000000000000..2d259ee247d221dd7127aee2037ec0acb25d9c91 --- /dev/null +++ b/av_transport/av_trans_engine/plugin/interface/avtrans_input_plugin.h @@ -0,0 +1,55 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HISTREAMER_PLUGIN_INTF_AVTRANS_INPUT_PLUGIN_H +#define HISTREAMER_PLUGIN_INTF_AVTRANS_INPUT_PLUGIN_H + +#include +#include + +#include "plugin/common/media_source.h" +#include "plugin/common/plugin_source_tags.h" +#include "plugin/common/plugin_buffer.h" +#include "plugin/common/plugin_caps.h" +#include "plugin/interface/plugin_base.h" +#include "plugin/interface/plugin_definition.h" + +namespace OHOS { +namespace DistributedHardware { + +using namespace OHOS::Media; +using namespace OHOS::Media::Plugin; + +struct AvTransInputPlugin : public PluginBase { +explicit AvTransInputPlugin(std::string name): PluginBase(std::move(name)) {} + +virtual OHOS::Media::Plugin::Status PushData(const std::string& inPort, std::shared_ptr buffer, + int32_t offset) = 0; + +virtual OHOS::Media::Plugin::Status SetDataCallback(std::function)> callback) = 0; +}; + +/// Avtrans input plugin api major number. +#define AVTRANS_INPUT_API_VERSION_MAJOR (1) + +/// Avtrans input plugin api minor number +#define AVTRANS_INPUT_API_VERSION_MINOR (0) + +/// Avtrans input plugin version +#define AVTRANS_INPUT_API_VERSION MAKE_VERSION(AVTRANS_INPUT_API_VERSION_MAJOR, AVTRANS_INPUT_API_VERSION_MINOR) + +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/av_transport/av_trans_engine/plugin/interface/avtrans_output_plugin.h b/av_transport/av_trans_engine/plugin/interface/avtrans_output_plugin.h new file mode 100644 index 0000000000000000000000000000000000000000..ae8301bb8af535e6e2b81fcf16b5c8c6ba9c10db --- /dev/null +++ b/av_transport/av_trans_engine/plugin/interface/avtrans_output_plugin.h @@ -0,0 +1,55 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HISTREAMER_PLUGIN_INTF_AVTRANS_OUTPUT_PLUGIN_H +#define HISTREAMER_PLUGIN_INTF_AVTRANS_OUTPUT_PLUGIN_H + +#include +#include + +#include "plugin/common/media_source.h" +#include "plugin/common/plugin_source_tags.h" +#include "plugin/common/plugin_buffer.h" +#include "plugin/common/plugin_caps.h" +#include "plugin/interface/plugin_base.h" +#include "plugin/interface/plugin_definition.h" + +namespace OHOS { +namespace DistributedHardware { + +using namespace OHOS::Media; +using namespace OHOS::Media::Plugin; + +struct AvTransOutputPlugin : public PluginBase { +explicit AvTransOutputPlugin(std::string name): PluginBase(std::move(name)) {} + +virtual OHOS::Media::Plugin::Status PushData(const std::string& inPort, std::shared_ptr buffer, + int32_t offset) = 0; + +virtual OHOS::Media::Plugin::Status SetDataCallback(std::function)> callback) = 0; +}; + +/// Avtrans output plugin api major number. +#define AVTRANS_OUTPUT_API_VERSION_MAJOR (1) + +/// Avtrans output plugin api minor number +#define AVTRANS_OUTPUT_API_VERSION_MINOR (0) + +/// Avtrans output plugin version +#define AVTRANS_OUTPUT_API_VERSION MAKE_VERSION(AVTRANS_OUTPUT_API_VERSION_MAJOR, AVTRANS_OUTPUT_API_VERSION_MINOR) + +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/av_transport/av_trans_engine/plugin/plugins/BUILD.gn b/av_transport/av_trans_engine/plugin/plugins/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..aae9560b016d5153921d8e7bed5b15688ccc8339 --- /dev/null +++ b/av_transport/av_trans_engine/plugin/plugins/BUILD.gn @@ -0,0 +1,25 @@ +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +config("avtrans_cflags") { + cflags = [ + "-O2", + "-fPIC", + "-Wall", + "-frtti", + "-fexceptions", + "-Wno-unused-but-set-variable", + "-Wno-format", + ] + cflags_cc = cflags +} diff --git a/av_transport/av_trans_engine/plugins/av_trans_input/daudio_input/BUILD.gn b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/daudio_input/BUILD.gn similarity index 51% rename from av_transport/av_trans_engine/plugins/av_trans_input/daudio_input/BUILD.gn rename to av_transport/av_trans_engine/plugin/plugins/av_trans_input/daudio_input/BUILD.gn index 7da1939cab202f51c51c8356dd76338e8b264f9a..e0ca0949ccac39ff70dd2b2a9aebdfda732b31f6 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_input/daudio_input/BUILD.gn +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/daudio_input/BUILD.gn @@ -15,43 +15,29 @@ import("//build/ohos.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") -ohos_shared_library("histreamer_plugin_AVTransDaudioInput") { +ohos_source_set("plugin_AVTransDaudioInput") { include_dirs = [ "${common_path}/include", - "${histreamer_path}/foundation/osal/thread", - "${histreamer_path}/include/pipeline/core", - "${histreamer_path}/include/plugin/common", - "${histreamer_path}/include/plugin/interface", - "${histreamer_path}/foundation/utils", - "${histreamer_path}/plugin/core", "${plugin_path}/interface", "//third_party/json/include", ] - sources = [ - "${common_path}/src/av_sync_utils.cpp", - "${common_path}/src/av_trans_buffer.cpp", - "${common_path}/src/av_trans_log.cpp", - "${common_path}/src/av_trans_meta.cpp", - "${common_path}/src/av_trans_utils.cpp", - "daudio_input_plugin.cpp", - ] + sources = [ "daudio_input_plugin.cpp" ] - deps = [ - "${histreamer_path}/foundation:histreamer_foundation", - "${histreamer_path}/plugin:histreamer_plugin_core", - "${histreamer_path}/plugin:histreamer_plugin_intf", + external_deps = [ + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", ] + public_configs = [ "${plugin_path}/plugins:avtrans_cflags" ] + defines = [ "HI_LOG_ENABLE", "DH_LOG_TAG=\"daudio_input_plugin\"", "LOG_DOMAIN=0xD004100", ] - - relative_install_dir = "media/histreamer_plugins" - - subsystem_name = "multimedia" - - part_name = "histreamer" + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" } diff --git a/av_transport/av_trans_engine/plugins/av_trans_input/daudio_input/daudio_input_plugin.cpp b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/daudio_input/daudio_input_plugin.cpp similarity index 86% rename from av_transport/av_trans_engine/plugins/av_trans_input/daudio_input/daudio_input_plugin.cpp rename to av_transport/av_trans_engine/plugin/plugins/av_trans_input/daudio_input/daudio_input_plugin.cpp index fda9811e5e809891c80d5dc8dea6b766c83810f3..9b1eacc1357b5f38c031aef909630d12fd180713 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_input/daudio_input/daudio_input_plugin.cpp +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/daudio_input/daudio_input_plugin.cpp @@ -17,23 +17,26 @@ #include "foundation/utils/constants.h" #include "plugin/common/plugin_caps_builder.h" +#include "plugin/factory/plugin_factory.h" +#include "plugin/interface/generic_plugin.h" namespace OHOS { namespace DistributedHardware { -std::shared_ptr DaudioInputPluginCreator(const std::string& name) +GenericPluginDef CreateDaudioInputPluginDef() { - return std::make_shared(name); -} - -Status DaudioInputRegister(const std::shared_ptr& reg) -{ - AvTransInputPluginDef definition; + AVTRANS_LOGI("DaudioInputPlugin registered."); + GenericPluginDef definition; definition.name = "AVTransDaudioInputPlugin"; + definition.pkgName = "AVTransDaudioInputPlugin"; definition.description = "Audio transport from daudio service"; definition.rank = PLUGIN_RANK; - definition.creator = DaudioInputPluginCreator; - definition.pluginType = PluginType::AVTRANS_INPUT; + definition.creator = [] (const std::string& name) -> std::shared_ptr { + return std::make_shared(name); + }; + + definition.pkgVersion = AVTRANS_INPUT_API_VERSION; + definition.license = LicenseType::APACHE_V2; CapabilityBuilder capBuilder; capBuilder.SetMime(OHOS::Media::MEDIA_MIME_AUDIO_RAW); @@ -41,11 +44,10 @@ Status DaudioInputRegister(const std::shared_ptr& reg) 22050, 24000, 32000, 44100, 48000, 64000, 96000}; capBuilder.SetAudioSampleRateList(values); definition.outCaps.push_back(capBuilder.Build()); - - return reg->AddPlugin(definition); + return definition; } -PLUGIN_DEFINITION(AVTransDaudioInput, LicenseType::APACHE_V2, DaudioInputRegister, [] {}); +static AutoRegisterPlugin g_registerPluginHelper(CreateDaudioInputPluginDef()); DaudioInputPlugin::DaudioInputPlugin(std::string name) : AvTransInputPlugin(std::move(name)) diff --git a/av_transport/av_trans_engine/plugins/av_trans_input/daudio_input/daudio_input_plugin.h b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/daudio_input/daudio_input_plugin.h similarity index 97% rename from av_transport/av_trans_engine/plugins/av_trans_input/daudio_input/daudio_input_plugin.h rename to av_transport/av_trans_engine/plugin/plugins/av_trans_input/daudio_input/daudio_input_plugin.h index 0e0174a9d398eb1e7092c185c38435a6e4324150..1bac99f385a9bcb74455e6c4130d411db7d382db 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_input/daudio_input/daudio_input_plugin.h +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/daudio_input/daudio_input_plugin.h @@ -45,7 +45,7 @@ using namespace OHOS::Media::Plugin; using json = nlohmann::json; using AVDataCallback = std::function)>; -class DaudioInputPlugin : public Media::Plugin::AvTransInputPlugin { +class DaudioInputPlugin : public AvTransInputPlugin { public: explicit DaudioInputPlugin(std::string name); ~DaudioInputPlugin(); diff --git a/av_transport/av_trans_engine/plugins/av_trans_input/dscreen_input/BUILD.gn b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dscreen_input/BUILD.gn similarity index 49% rename from av_transport/av_trans_engine/plugins/av_trans_input/dscreen_input/BUILD.gn rename to av_transport/av_trans_engine/plugin/plugins/av_trans_input/dscreen_input/BUILD.gn index 143fb45d8158f1130f99710920ccb7419b550b45..7f1a7387db7e964d4f34756fb9d07e14866d4cfb 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_input/dscreen_input/BUILD.gn +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dscreen_input/BUILD.gn @@ -15,50 +15,29 @@ import("//build/ohos.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") -ohos_shared_library("histreamer_plugin_AVTransDscreenInput") { +ohos_source_set("plugin_AVTransDscreenInput") { include_dirs = [ "${common_path}/include", "${plugin_path}/interface", - "${histreamer_path}/include/pipeline/core", - "${histreamer_path}/include/plugin/interface", - "${histreamer_path}/include/plugin/common", - "${histreamer_path}/plugin/core", - "${histreamer_path}/include/foundation/osal/thread", - "${histreamer_path}/foundation/utils", "//third_party/json/include", ] - sources = [ - "${common_path}/src/av_sync_utils.cpp", - "${common_path}/src/av_trans_buffer.cpp", - "${common_path}/src/av_trans_log.cpp", - "${common_path}/src/av_trans_meta.cpp", - "${common_path}/src/av_trans_utils.cpp", - "dscreen_input_plugin.cpp", - ] + sources = [ "dscreen_input_plugin.cpp" ] - deps = [ - "${histreamer_path}/foundation:histreamer_foundation", - "${histreamer_path}/plugin:histreamer_plugin_core", - "${histreamer_path}/plugin:histreamer_plugin_intf", + external_deps = [ + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", ] + public_configs = [ "${plugin_path}/plugins:avtrans_cflags" ] + defines = [ "HI_LOG_ENABLE", "DH_LOG_TAG=\"dscreen_input_plugin\"", "LOG_DOMAIN=0xD004100", ] - - external_deps = [ - "c_utils:utils", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "samgr:samgr_proxy", - ] - - relative_install_dir = "media/histreamer_plugins" - - subsystem_name = "multimedia" - - part_name = "histreamer" + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" } diff --git a/av_transport/av_trans_engine/plugins/av_trans_input/dscreen_input/dscreen_input_plugin.cpp b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dscreen_input/dscreen_input_plugin.cpp similarity index 84% rename from av_transport/av_trans_engine/plugins/av_trans_input/dscreen_input/dscreen_input_plugin.cpp rename to av_transport/av_trans_engine/plugin/plugins/av_trans_input/dscreen_input/dscreen_input_plugin.cpp index aeb9d2388ac69c857fea3c4032bca1842514ec92..e1bad397bcf0e82b6f8c08d8336412055d8b9611 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_input/dscreen_input/dscreen_input_plugin.cpp +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dscreen_input/dscreen_input_plugin.cpp @@ -17,33 +17,36 @@ #include "av_trans_utils.h" #include "foundation/utils/constants.h" #include "nlohmann/json.hpp" +#include "plugin/factory/plugin_factory.h" +#include "plugin/interface/generic_plugin.h" namespace OHOS { namespace DistributedHardware { using json = nlohmann::json; -std::shared_ptr DscreenInputPluginCreator(const std::string &name) +GenericPluginDef CreateDscreenInputPluginDef() { - return std::make_shared(name); -} - -Status DscreenInputRegister(const std::shared_ptr ®) -{ - AvTransInputPluginDef definition; + AVTRANS_LOGI("DscreenInputPlugin registered."); + GenericPluginDef definition; definition.name = "AVTransDscreenInputPlugin"; - definition.description = "Video transport from dsrceen service"; + definition.pkgName = "AVTransDscreenInputPlugin"; + definition.description = "Video transport from dscreen service"; definition.rank = PLUGIN_RANK; - definition.pluginType = PluginType::AVTRANS_INPUT; - definition.creator = DscreenInputPluginCreator; + definition.creator = [] (const std::string& name) -> std::shared_ptr { + return std::make_shared(name); + }; + + definition.pkgVersion = AVTRANS_INPUT_API_VERSION; + definition.license = LicenseType::APACHE_V2; Capability outCap(Media::MEDIA_MIME_VIDEO_RAW); outCap.AppendDiscreteKeys( Capability::Key::VIDEO_PIXEL_FORMAT, {VideoPixelFormat::RGBA}); definition.outCaps.push_back(outCap); - return reg->AddPlugin(definition); + return definition; } -PLUGIN_DEFINITION(AVTransDscreenInput, LicenseType::APACHE_V2, DscreenInputRegister, [] {}); +static AutoRegisterPlugin g_registerPluginHelper(CreateDscreenInputPluginDef()); DscreenInputPlugin::DscreenInputPlugin(std::string name) : AvTransInputPlugin(std::move(name)) diff --git a/av_transport/av_trans_engine/plugins/av_trans_input/dscreen_input/dscreen_input_plugin.h b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dscreen_input/dscreen_input_plugin.h similarity index 100% rename from av_transport/av_trans_engine/plugins/av_trans_input/dscreen_input/dscreen_input_plugin.h rename to av_transport/av_trans_engine/plugin/plugins/av_trans_input/dscreen_input/dscreen_input_plugin.h diff --git a/av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input/BUILD.gn b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/BUILD.gn similarity index 49% rename from av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input/BUILD.gn rename to av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/BUILD.gn index 05d871009598cce87c06a0b6f9007cd02b9916ed..617713adaeff3006bea10aa051e8f1d54b9db04d 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input/BUILD.gn +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/BUILD.gn @@ -15,45 +15,32 @@ import("//build/ohos.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") -ohos_shared_library("histreamer_plugin_AVTransDsoftbusInput") { +ohos_source_set("plugin_AVTransDsoftbusInput") { include_dirs = [ "${common_path}/include", "${plugin_path}/interface", - "${histreamer_path}/include/pipeline/core", - "${histreamer_path}/include/plugin/interface", - "${histreamer_path}/include/plugin/common", - "${histreamer_path}/plugin/core", - "${histreamer_path}/include/foundation/osal/thread", - "${histreamer_path}/foundation/utils", + "${dsoftbus_path}/interfaces/kits/transport", + "${dsoftbus_path}/interfaces/kits/bus_center", + "${dsoftbus_path}/interfaces/kits/common", "//third_party/json/include", ] - sources = [ - "${common_path}/src/av_trans_buffer.cpp", - "${common_path}/src/av_trans_log.cpp", - "${common_path}/src/av_trans_meta.cpp", - "${common_path}/src/av_trans_utils.cpp", - "${common_path}/src/softbus_channel_adapter.cpp", - "dsoftbus_input_plugin.cpp", - ] + sources = [ "dsoftbus_input_plugin.cpp" ] - deps = [ - "${histreamer_path}/foundation:histreamer_foundation", - "${histreamer_path}/plugin:histreamer_plugin_core", - "${histreamer_path}/plugin:histreamer_plugin_intf", + external_deps = [ + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", ] + public_configs = [ "${plugin_path}/plugins:avtrans_cflags" ] + defines = [ "HI_LOG_ENABLE", "DH_LOG_TAG=\"dsoftbus_input_plugin\"", "LOG_DOMAIN=0xD004100", ] - - external_deps = [ "dsoftbus:softbus_client" ] - - relative_install_dir = "media/histreamer_plugins" - - subsystem_name = "multimedia" - - part_name = "histreamer" + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" } diff --git a/av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.cpp b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.cpp similarity index 91% rename from av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.cpp rename to av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.cpp index 5e76d5cb4a2def7b49d21831270ad7be6a0f1203..3f705f99a62518052b54e0d511605860bfc38481 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.cpp +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.cpp @@ -18,38 +18,44 @@ #include "foundation/utils/constants.h" #include "plugin/common/share_memory.h" #include "plugin/common/plugin_caps_builder.h" +#include "plugin/factory/plugin_factory.h" +#include "plugin/interface/generic_plugin.h" namespace OHOS { namespace DistributedHardware { -std::shared_ptr DsoftbusInputPluginCreator(const std::string &name) -{ - return std::make_shared(name); -} -Status DsoftbusInputRegister(const std::shared_ptr ®) +std::vector CreateDsoftbusInputPluginDef() { int32_t capNum = 2; + std::vector definitionList; for (int i = 0; i < capNum; i++) { - AvTransInputPluginDef definition; + AVTRANS_LOGI("DsoftbusInputPlugin_H264 registered."); + GenericPluginDef definition; definition.name = "AVTransDsoftbusInputPlugin_H264"; + definition.pkgName = "AVTransDsoftbusInputPlugin"; definition.description = "Video transport from dsoftbus"; definition.rank = PLUGIN_RANK; - definition.pluginType = PluginType::AVTRANS_INPUT; - definition.creator = DsoftbusInputPluginCreator; + definition.creator = [] (const std::string& name) -> std::shared_ptr { + return std::make_shared(name); + }; + + definition.pkgVersion = AVTRANS_INPUT_API_VERSION; + definition.license = LicenseType::APACHE_V2; CapabilityBuilder capBuilder; capBuilder.SetMime(Media::MEDIA_MIME_VIDEO_H264); if (i == 1) { + AVTRANS_LOGI("DsoftbusInputPlugin_H265 registered."); definition.name = "AVTransDsoftbusInputPlugin_H265"; capBuilder.SetMime(Media::MEDIA_MIME_VIDEO_H265); } definition.outCaps.push_back(capBuilder.Build()); - reg->AddPlugin(definition); + definitionList.push_back(definition); } - return Status::OK; + return definitionList; } -PLUGIN_DEFINITION(AVTransDsoftbusInput, LicenseType::APACHE_V2, DsoftbusInputRegister, [] {}); +static AutoRegisterPlugin g_registerPluginHelper(CreateDsoftbusInputPluginDef()); DsoftbusInputPlugin::DsoftbusInputPlugin(std::string name) : AvTransInputPlugin(std::move(name)) diff --git a/av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.h b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.h similarity index 100% rename from av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.h rename to av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.h diff --git a/av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input_audio/BUILD.gn b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input_audio/BUILD.gn similarity index 49% rename from av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input_audio/BUILD.gn rename to av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input_audio/BUILD.gn index e7ccc5f758c398d1ac00df08730374cc325ecbbd..9701c3668bda187b95008c9cfa0b9bb0fbf9ce7a 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input_audio/BUILD.gn +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input_audio/BUILD.gn @@ -15,45 +15,32 @@ import("//build/ohos.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") -ohos_shared_library("histreamer_plugin_AVTransDsoftbusInputAudio") { +ohos_source_set("plugin_AVTransDsoftbusInputAudio") { include_dirs = [ "${common_path}/include", "${plugin_path}/interface", - "${histreamer_path}/include/pipeline/core", - "${histreamer_path}/include/plugin/interface", - "${histreamer_path}/include/plugin/common", - "${histreamer_path}/plugin/core", - "${histreamer_path}/include/foundation/osal/thread", - "${histreamer_path}/foundation/utils", + "${dsoftbus_path}/interfaces/kits/transport", + "${dsoftbus_path}/interfaces/kits/bus_center", + "${dsoftbus_path}/interfaces/kits/common", "//third_party/json/include", ] - sources = [ - "${common_path}/src/av_trans_buffer.cpp", - "${common_path}/src/av_trans_log.cpp", - "${common_path}/src/av_trans_meta.cpp", - "${common_path}/src/av_trans_utils.cpp", - "${common_path}/src/softbus_channel_adapter.cpp", - "dsoftbus_input_audio_plugin.cpp", - ] + sources = [ "dsoftbus_input_audio_plugin.cpp" ] - deps = [ - "${histreamer_path}/foundation:histreamer_foundation", - "${histreamer_path}/plugin:histreamer_plugin_core", - "${histreamer_path}/plugin:histreamer_plugin_intf", + external_deps = [ + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", ] + public_configs = [ "${plugin_path}/plugins:avtrans_cflags" ] + defines = [ "HI_LOG_ENABLE", "DH_LOG_TAG=\"dsoftbus_input_audio_plugin\"", "LOG_DOMAIN=0xD004100", ] - - external_deps = [ "dsoftbus:softbus_client" ] - - relative_install_dir = "media/histreamer_plugins" - - subsystem_name = "multimedia" - - part_name = "histreamer" + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" } diff --git a/av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input_audio/dsoftbus_input_audio_plugin.cpp b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input_audio/dsoftbus_input_audio_plugin.cpp similarity index 92% rename from av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input_audio/dsoftbus_input_audio_plugin.cpp rename to av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input_audio/dsoftbus_input_audio_plugin.cpp index 6663bef980aa7880f1ab225767066d0caaea7bfa..c435fe7f182dcc1545a82023abce98c74a684c52 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input_audio/dsoftbus_input_audio_plugin.cpp +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input_audio/dsoftbus_input_audio_plugin.cpp @@ -18,22 +18,26 @@ #include "foundation/utils/constants.h" #include "plugin/common/share_memory.h" #include "plugin/common/plugin_caps_builder.h" +#include "plugin/factory/plugin_factory.h" +#include "plugin/interface/generic_plugin.h" namespace OHOS { namespace DistributedHardware { -std::shared_ptr DsoftbusInputAudioPluginCreator(const std::string &name) -{ - return std::make_shared(name); -} -Status DsoftbusInputAudioRegister(const std::shared_ptr ®) +GenericPluginDef CreateDsoftbusInputAudioPluginDef() { - AvTransInputPluginDef definition; + AVTRANS_LOGI("DsoftbusInputAudioPlugin registered."); + GenericPluginDef definition; definition.name = "AVTransDsoftbusInputAudioPlugin"; + definition.pkgName = "AVTransDsoftbusInputAudioPlugin"; definition.description = "Audio transport from dsoftbus"; definition.rank = PLUGIN_RANK; - definition.pluginType = PluginType::AVTRANS_INPUT; - definition.creator = DsoftbusInputAudioPluginCreator; + definition.creator = [] (const std::string& name) -> std::shared_ptr { + return std::make_shared(name); + }; + + definition.pkgVersion = AVTRANS_INPUT_API_VERSION; + definition.license = LicenseType::APACHE_V2; CapabilityBuilder capBuilder; capBuilder.SetMime(OHOS::Media::MEDIA_MIME_AUDIO_AAC); @@ -41,11 +45,10 @@ Status DsoftbusInputAudioRegister(const std::shared_ptr ®) 22050, 24000, 32000, 44100, 48000, 64000, 96000}; capBuilder.SetAudioSampleRateList(values); definition.outCaps.push_back(capBuilder.Build()); - - return reg->AddPlugin(definition); + return definition; } -PLUGIN_DEFINITION(AVTransDsoftbusInputAudio, LicenseType::APACHE_V2, DsoftbusInputAudioRegister, [] {}); +static AutoRegisterPlugin g_registerPluginHelper(CreateDsoftbusInputAudioPluginDef()); DsoftbusInputAudioPlugin::DsoftbusInputAudioPlugin(std::string name) : AvTransInputPlugin(std::move(name)) diff --git a/av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input_audio/dsoftbus_input_audio_plugin.h b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input_audio/dsoftbus_input_audio_plugin.h similarity index 100% rename from av_transport/av_trans_engine/plugins/av_trans_input/dsoftbus_input_audio/dsoftbus_input_audio_plugin.h rename to av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input_audio/dsoftbus_input_audio_plugin.h diff --git a/av_transport/av_trans_engine/plugins/av_trans_output/daudio_output/BUILD.gn b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/daudio_output/BUILD.gn similarity index 49% rename from av_transport/av_trans_engine/plugins/av_trans_output/daudio_output/BUILD.gn rename to av_transport/av_trans_engine/plugin/plugins/av_trans_output/daudio_output/BUILD.gn index aeabb7bc295bd9fa61be526d35469049cb63a0a2..fd729219468362ab7fad33b152f2ed0878348812 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_output/daudio_output/BUILD.gn +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/daudio_output/BUILD.gn @@ -15,46 +15,30 @@ import("//build/ohos.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") -ohos_shared_library("histreamer_plugin_AVTransDaudioOutput") { +ohos_source_set("plugin_AVTransDaudioOutput") { include_dirs = [ "${common_path}/include", - "${histreamer_path}/foundation/osal/thread", - "${histreamer_path}/include/pipeline/core", - "${histreamer_path}/include/plugin/common", - "${histreamer_path}/include/plugin/interface", - "${histreamer_path}/foundation/utils", - "${histreamer_path}/plugin/core", "${plugin_path}/interface", "//third_party/json/include", "//third_party/ffmpeg", ] - sources = [ - "${common_path}/src/av_sync_utils.cpp", - "${common_path}/src/av_trans_buffer.cpp", - "${common_path}/src/av_trans_log.cpp", - "${common_path}/src/av_trans_meta.cpp", - "${common_path}/src/av_trans_utils.cpp", - "${histreamer_path}/plugin/plugins/ffmpeg_adapter/utils/ffmpeg_utils.cpp", - "daudio_output_plugin.cpp", - ] + sources = [ "daudio_output_plugin.cpp" ] - deps = [ - "${histreamer_path}/foundation:histreamer_foundation", - "${histreamer_path}/plugin:histreamer_plugin_core", - "${histreamer_path}/plugin:histreamer_plugin_intf", - "//third_party/ffmpeg:libohosffmpeg", + external_deps = [ + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", ] + public_configs = [ "${plugin_path}/plugins:avtrans_cflags" ] + defines = [ "HI_LOG_ENABLE", "DH_LOG_TAG=\"daudio_output_plugin\"", "LOG_DOMAIN=0xD004100", ] - - relative_install_dir = "media/histreamer_plugins" - - subsystem_name = "multimedia" - - part_name = "histreamer" + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" } diff --git a/av_transport/av_trans_engine/plugins/av_trans_output/daudio_output/daudio_output_plugin.cpp b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/daudio_output/daudio_output_plugin.cpp similarity index 94% rename from av_transport/av_trans_engine/plugins/av_trans_output/daudio_output/daudio_output_plugin.cpp rename to av_transport/av_trans_engine/plugin/plugins/av_trans_output/daudio_output/daudio_output_plugin.cpp index 5768f4627b4f4c9e1a655ecb84705a1fcefdfd21..0fe50b457cd3e2f356e1aca07bd3d304532e8d10 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_output/daudio_output/daudio_output_plugin.cpp +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/daudio_output/daudio_output_plugin.cpp @@ -17,23 +17,26 @@ #include "foundation/utils/constants.h" #include "plugin/common/plugin_caps_builder.h" +#include "plugin/factory/plugin_factory.h" +#include "plugin/interface/generic_plugin.h" namespace OHOS { namespace DistributedHardware { -std::shared_ptr DaudioOutputPluginCreator(const std::string& name) +GenericPluginDef CreateDaudioOutputPluginDef() { - return std::make_shared(name); -} - -Status DaudioOutputRegister(const std::shared_ptr ®) -{ - AvTransOutputPluginDef definition; + AVTRANS_LOGI("DaudioOutputPlugin registered."); + GenericPluginDef definition; definition.name = "AVTransDaudioOutputPlugin"; + definition.pkgName = "AVTransDaudioOutputPlugin"; definition.description = "Send audio playback and frame rate control."; definition.rank = PLUGIN_RANK; - definition.creator = DaudioOutputPluginCreator; - definition.pluginType = PluginType::AVTRANS_OUTPUT; + definition.creator = [] (const std::string& name) -> std::shared_ptr { + return std::make_shared(name); + }; + + definition.pkgVersion = AVTRANS_OUTPUT_API_VERSION; + definition.license = LicenseType::APACHE_V2; CapabilityBuilder capBuilder; capBuilder.SetMime(OHOS::Media::MEDIA_MIME_AUDIO_RAW); @@ -43,11 +46,10 @@ Status DaudioOutputRegister(const std::shared_ptr ®) DiscreteCapability valuesSampleFormat = {AudioSampleFormat::F32P}; capBuilder.SetAudioSampleFormatList(valuesSampleFormat); definition.inCaps.push_back(capBuilder.Build()); - - return reg->AddPlugin(definition); + return definition; } -PLUGIN_DEFINITION(AVTransDaudioOutput, LicenseType::APACHE_V2, DaudioOutputRegister, [] {}); +static AutoRegisterPlugin g_registerPluginHelper(CreateDaudioOutputPluginDef()); DaudioOutputPlugin::DaudioOutputPlugin(std::string name) : AvTransOutputPlugin(std::move(name)) diff --git a/av_transport/av_trans_engine/plugins/av_trans_output/daudio_output/daudio_output_plugin.h b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/daudio_output/daudio_output_plugin.h similarity index 98% rename from av_transport/av_trans_engine/plugins/av_trans_output/daudio_output/daudio_output_plugin.h rename to av_transport/av_trans_engine/plugin/plugins/av_trans_output/daudio_output/daudio_output_plugin.h index f2d5960e0f3d1376689297db0efe78d8d6f024ca..b634faa443d5614bb1d65b99bc0e8d09b1fe0239 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_output/daudio_output/daudio_output_plugin.h +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/daudio_output/daudio_output_plugin.h @@ -23,9 +23,9 @@ #include #include "av_sync_utils.h" +#include "av_trans_errno.h" #include "av_trans_buffer.h" #include "av_trans_constants.h" -#include "av_trans_errno.h" #include "av_trans_log.h" #include "av_trans_meta.h" #include "av_trans_types.h" @@ -37,7 +37,7 @@ #include "nlohmann/json.hpp" #include "plugin_manager.h" #include "plugin_types.h" -#include "plugin/plugins/ffmpeg_adapter/utils/ffmpeg_utils.h" +#include "plugin/convert/ffmpeg_convert.h" namespace OHOS { namespace DistributedHardware { diff --git a/av_transport/av_trans_engine/plugins/av_trans_output/dscreen_output/BUILD.gn b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dscreen_output/BUILD.gn similarity index 51% rename from av_transport/av_trans_engine/plugins/av_trans_output/dscreen_output/BUILD.gn rename to av_transport/av_trans_engine/plugin/plugins/av_trans_output/dscreen_output/BUILD.gn index a18192afea6e2363a56efe27fc1745d2972ac0c2..b780e423ba2b24534045d986105eed405de3d49b 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_output/dscreen_output/BUILD.gn +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dscreen_output/BUILD.gn @@ -15,43 +15,29 @@ import("//build/ohos.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") -ohos_shared_library("histreamer_plugin_AVTransDscreenOutput") { +ohos_source_set("plugin_AVTransDscreenOutput") { include_dirs = [ "${common_path}/include", "${plugin_path}/interface", - "${histreamer_path}/include/pipeline/core", - "${histreamer_path}/include/plugin/interface", - "${histreamer_path}/include/plugin/common", - "${histreamer_path}/plugin/core", - "${histreamer_path}/include/foundation/osal/thread", - "${histreamer_path}/foundation/utils", "//third_party/json/include", ] - sources = [ - "${common_path}/src/av_sync_utils.cpp", - "${common_path}/src/av_trans_buffer.cpp", - "${common_path}/src/av_trans_log.cpp", - "${common_path}/src/av_trans_meta.cpp", - "${common_path}/src/av_trans_utils.cpp", - "dscreen_output_plugin.cpp", - ] + sources = [ "dscreen_output_plugin.cpp" ] - deps = [ - "${histreamer_path}/foundation:histreamer_foundation", - "${histreamer_path}/plugin:histreamer_plugin_core", - "${histreamer_path}/plugin:histreamer_plugin_intf", + external_deps = [ + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", ] + public_configs = [ "${plugin_path}/plugins:avtrans_cflags" ] + defines = [ "HI_LOG_ENABLE", "DH_LOG_TAG=\"dscreen_output_plugin\"", "LOG_DOMAIN=0xD004100", ] - - relative_install_dir = "media/histreamer_plugins" - - subsystem_name = "multimedia" - - part_name = "histreamer" + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" } diff --git a/av_transport/av_trans_engine/plugins/av_trans_output/dscreen_output/dscreen_output_plugin.cpp b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dscreen_output/dscreen_output_plugin.cpp similarity index 91% rename from av_transport/av_trans_engine/plugins/av_trans_output/dscreen_output/dscreen_output_plugin.cpp rename to av_transport/av_trans_engine/plugin/plugins/av_trans_output/dscreen_output/dscreen_output_plugin.cpp index 2da45da4d80fbe37dc995aa1d9e2a230ef079653..f7987ffa7a5089edf1a01457a070f8a41960944b 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_output/dscreen_output/dscreen_output_plugin.cpp +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dscreen_output/dscreen_output_plugin.cpp @@ -16,31 +16,35 @@ #include "dscreen_output_plugin.h" #include "foundation/utils/constants.h" +#include "plugin/factory/plugin_factory.h" +#include "plugin/interface/generic_plugin.h" namespace OHOS { namespace DistributedHardware { -std::shared_ptr DscreenOutputPluginCreator(const std::string &name) -{ - return std::make_shared(name); -} -Status DscreenOutputRegister(const std::shared_ptr ®) +GenericPluginDef CreateDscreenOutputPluginDef() { - AvTransOutputPluginDef definition; - definition.name = "AVTranseDscreenOutputPlugin"; + AVTRANS_LOGI("DscreenOutputPlugin registered."); + GenericPluginDef definition; + definition.name = "AVTransDscreenOutputPlugin"; + definition.pkgName = "AVTransDscreenOutputPlugin"; definition.description = "Send video display and frame rate control."; definition.rank = PLUGIN_RANK; - definition.pluginType = PluginType::AVTRANS_OUTPUT; - definition.creator = DscreenOutputPluginCreator; + definition.creator = [] (const std::string& name) -> std::shared_ptr { + return std::make_shared(name); + }; + + definition.pkgVersion = AVTRANS_OUTPUT_API_VERSION; + definition.license = LicenseType::APACHE_V2; Capability inCap(Media::MEDIA_MIME_VIDEO_RAW); inCap.AppendDiscreteKeys( Capability::Key::VIDEO_PIXEL_FORMAT, {VideoPixelFormat::RGBA}); definition.inCaps.push_back(inCap); - return reg->AddPlugin(definition); + return definition; } -PLUGIN_DEFINITION(AVTransDscreenOutput, LicenseType::APACHE_V2, DscreenOutputRegister, [] {}); +static AutoRegisterPlugin g_registerPluginHelper(CreateDscreenOutputPluginDef()); DscreenOutputPlugin::DscreenOutputPlugin(std::string name) : AvTransOutputPlugin(std::move(name)) diff --git a/av_transport/av_trans_engine/plugins/av_trans_output/dscreen_output/dscreen_output_plugin.h b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dscreen_output/dscreen_output_plugin.h similarity index 97% rename from av_transport/av_trans_engine/plugins/av_trans_output/dscreen_output/dscreen_output_plugin.h rename to av_transport/av_trans_engine/plugin/plugins/av_trans_output/dscreen_output/dscreen_output_plugin.h index 53b951fd5ea9799f0df612b4d944ba1caa235680..49580749ae9653815d58af2d5b8d1da3f88766ca 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_output/dscreen_output/dscreen_output_plugin.h +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dscreen_output/dscreen_output_plugin.h @@ -45,7 +45,7 @@ using namespace OHOS::Media::Plugin; using json = nlohmann::json; using AVDataCallback = std::function)>; -class DscreenOutputPlugin : public Media::Plugin::AvTransOutputPlugin { +class DscreenOutputPlugin : public AvTransOutputPlugin { public: explicit DscreenOutputPlugin(std::string name); ~DscreenOutputPlugin(); diff --git a/av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output/BUILD.gn b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/BUILD.gn similarity index 49% rename from av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output/BUILD.gn rename to av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/BUILD.gn index 920516541dcb3b63945e6a4d845c3ba6b98dafe2..12d62f3de3c09f92f8cc20b4835a9ea3913f4f1b 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output/BUILD.gn +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/BUILD.gn @@ -15,45 +15,32 @@ import("//build/ohos.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") -ohos_shared_library("histreamer_plugin_AVTransDsoftbusOutput") { +ohos_source_set("plugin_AVTransDsoftbusOutput") { include_dirs = [ "${common_path}/include", "${plugin_path}/interface", - "${histreamer_path}/include/pipeline/core", - "${histreamer_path}/include/plugin/interface", - "${histreamer_path}/include/plugin/common", - "${histreamer_path}/plugin/core", - "${histreamer_path}/include/foundation/osal/thread", - "${histreamer_path}/foundation/utils", + "${dsoftbus_path}/interfaces/kits/transport", + "${dsoftbus_path}/interfaces/kits/bus_center", + "${dsoftbus_path}/interfaces/kits/common", "//third_party/json/include", ] - sources = [ - "${common_path}/src/av_trans_buffer.cpp", - "${common_path}/src/av_trans_log.cpp", - "${common_path}/src/av_trans_meta.cpp", - "${common_path}/src/av_trans_utils.cpp", - "${common_path}/src/softbus_channel_adapter.cpp", - "dsoftbus_output_plugin.cpp", - ] + sources = [ "dsoftbus_output_plugin.cpp" ] - deps = [ - "${histreamer_path}/foundation:histreamer_foundation", - "${histreamer_path}/plugin:histreamer_plugin_core", - "${histreamer_path}/plugin:histreamer_plugin_intf", + external_deps = [ + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", ] + public_configs = [ "${plugin_path}/plugins:avtrans_cflags" ] + defines = [ "HI_LOG_ENABLE", "DH_LOG_TAG=\"dsoftbus_output_plugin\"", "LOG_DOMAIN=0xD004100", ] - - external_deps = [ "dsoftbus:softbus_client" ] - - relative_install_dir = "media/histreamer_plugins" - - subsystem_name = "multimedia" - - part_name = "histreamer" + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" } diff --git a/av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.cpp b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.cpp similarity index 91% rename from av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.cpp rename to av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.cpp index 8c9c2491b1fd910647d699951c075f6d2b326811..ce733828dbdadd9f27064ada255b8bb8589aab8b 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.cpp +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.cpp @@ -16,39 +16,44 @@ #include "foundation/utils/constants.h" #include "plugin/common/plugin_caps_builder.h" +#include "plugin/factory/plugin_factory.h" +#include "plugin/interface/generic_plugin.h" namespace OHOS { namespace DistributedHardware { -std::shared_ptr DsoftbusOutputPluginCreator(const std::string &name) -{ - return std::make_shared(name); -} - -Status DsoftbusOutputRegister(const std::shared_ptr ®) +std::vector CreateDsoftbusOutputPluginDef() { int32_t capNum = 2; + std::vector definitionList; for (int i = 0; i < capNum; i++) { - AvTransOutputPluginDef definition; + AVTRANS_LOGI("DsoftbusOutputPlugin_H264 registered."); + GenericPluginDef definition; definition.name = "AVTransDsoftbusOutputPlugin_H264"; + definition.pkgName = "AVTransDsoftbusOutputPlugin"; definition.description = "Video transport to dsoftbus"; definition.rank = PLUGIN_RANK; - definition.pluginType = PluginType::AVTRANS_OUTPUT; - definition.creator = DsoftbusOutputPluginCreator; + definition.creator = [] (const std::string& name) -> std::shared_ptr { + return std::make_shared(name); + }; + + definition.pkgVersion = AVTRANS_OUTPUT_API_VERSION; + definition.license = LicenseType::APACHE_V2; CapabilityBuilder capBuilder; capBuilder.SetMime(Media::MEDIA_MIME_VIDEO_H264); if (i == 1) { + AVTRANS_LOGI("DsoftbusOutputPlugin_H265 registered."); definition.name = "AVTransDsoftbusOutputPlugin_H265"; capBuilder.SetMime(Media::MEDIA_MIME_VIDEO_H265); } definition.inCaps.push_back(capBuilder.Build()); - reg->AddPlugin(definition); + definitionList.push_back(definition); } - return Status::OK; + return definitionList; } -PLUGIN_DEFINITION(AVTransDsoftbusOutput, LicenseType::APACHE_V2, DsoftbusOutputRegister, [] {}); +static AutoRegisterPlugin g_registerPluginHelper(CreateDsoftbusOutputPluginDef()); DsoftbusOutputPlugin::DsoftbusOutputPlugin(std::string name) : AvTransOutputPlugin(std::move(name)) diff --git a/av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.h b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.h similarity index 100% rename from av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.h rename to av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.h diff --git a/av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output_audio/BUILD.gn b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output_audio/BUILD.gn similarity index 49% rename from av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output_audio/BUILD.gn rename to av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output_audio/BUILD.gn index 330ae6df62a389ecc800c57f1ae86289af54d676..c0538ee79505c62f94458bc17371e220e5428713 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output_audio/BUILD.gn +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output_audio/BUILD.gn @@ -15,45 +15,32 @@ import("//build/ohos.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") -ohos_shared_library("histreamer_plugin_AVTransDsoftbusOutputAudio") { +ohos_source_set("plugin_AVTransDsoftbusOutputAudio") { include_dirs = [ "${common_path}/include", "${plugin_path}/interface", - "${histreamer_path}/include/pipeline/core", - "${histreamer_path}/include/plugin/interface", - "${histreamer_path}/include/plugin/common", - "${histreamer_path}/plugin/core", - "${histreamer_path}/include/foundation/osal/thread", - "${histreamer_path}/foundation/utils", + "${dsoftbus_path}/interfaces/kits/transport", + "${dsoftbus_path}/interfaces/kits/bus_center", + "${dsoftbus_path}/interfaces/kits/common", "//third_party/json/include", ] - sources = [ - "${common_path}/src/av_trans_buffer.cpp", - "${common_path}/src/av_trans_log.cpp", - "${common_path}/src/av_trans_meta.cpp", - "${common_path}/src/av_trans_utils.cpp", - "${common_path}/src/softbus_channel_adapter.cpp", - "dsoftbus_output_audio_plugin.cpp", - ] + sources = [ "dsoftbus_output_audio_plugin.cpp" ] - deps = [ - "${histreamer_path}/foundation:histreamer_foundation", - "${histreamer_path}/plugin:histreamer_plugin_core", - "${histreamer_path}/plugin:histreamer_plugin_intf", + external_deps = [ + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", ] + public_configs = [ "${plugin_path}/plugins:avtrans_cflags" ] + defines = [ "HI_LOG_ENABLE", "DH_LOG_TAG=\"dsoftbus_output_audio_plugin\"", "LOG_DOMAIN=0xD004100", ] - - external_deps = [ "dsoftbus:softbus_client" ] - - relative_install_dir = "media/histreamer_plugins" - - subsystem_name = "multimedia" - - part_name = "histreamer" + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" } diff --git a/av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output_audio/dsoftbus_output_audio_plugin.cpp b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output_audio/dsoftbus_output_audio_plugin.cpp similarity index 94% rename from av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output_audio/dsoftbus_output_audio_plugin.cpp rename to av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output_audio/dsoftbus_output_audio_plugin.cpp index 0edaaf778663ea694e8a8e494b8d8649d9ef42e5..132e55f9f656db61a4702004821298cfe073cce6 100644 --- a/av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output_audio/dsoftbus_output_audio_plugin.cpp +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output_audio/dsoftbus_output_audio_plugin.cpp @@ -16,23 +16,26 @@ #include "foundation/utils/constants.h" #include "plugin/common/plugin_caps_builder.h" +#include "plugin/factory/plugin_factory.h" +#include "plugin/interface/generic_plugin.h" namespace OHOS { namespace DistributedHardware { -std::shared_ptr DsoftbusOutputAudioPluginCreator(const std::string &name) +GenericPluginDef CreateDsoftbusOutputAudioPluginDef() { - return std::make_shared(name); -} - -Status DsoftbusOutputAudioRegister(const std::shared_ptr ®) -{ - AvTransOutputPluginDef definition; + AVTRANS_LOGI("DsoftbusOutputAudioPlugin registered."); + GenericPluginDef definition; definition.name = "AVTransDsoftbusOutputAudioPlugin"; + definition.pkgName = "AVTransDsoftbusOutputAudioPlugin"; definition.description = "Audio transport to dsoftbus"; definition.rank = PLUGIN_RANK; - definition.pluginType = PluginType::AVTRANS_OUTPUT; - definition.creator = DsoftbusOutputAudioPluginCreator; + definition.creator = [] (const std::string& name) -> std::shared_ptr { + return std::make_shared(name); + }; + + definition.pkgVersion = AVTRANS_OUTPUT_API_VERSION; + definition.license = LicenseType::APACHE_V2; CapabilityBuilder capBuilder; capBuilder.SetMime(OHOS::Media::MEDIA_MIME_AUDIO_AAC); @@ -42,11 +45,10 @@ Status DsoftbusOutputAudioRegister(const std::shared_ptr ®) DiscreteCapability valuesSampleFormat = {AudioSampleFormat::S16}; capBuilder.SetAudioSampleFormatList(valuesSampleFormat); definition.inCaps.push_back(capBuilder.Build()); - - return reg->AddPlugin(definition); + return definition; } -PLUGIN_DEFINITION(AVTransDsoftbusOutputAudio, LicenseType::APACHE_V2, DsoftbusOutputAudioRegister, [] {}); +static AutoRegisterPlugin g_registerPluginHelper(CreateDsoftbusOutputAudioPluginDef()); DsoftbusOutputAudioPlugin::DsoftbusOutputAudioPlugin(std::string name) : AvTransOutputPlugin(std::move(name)) diff --git a/av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output_audio/dsoftbus_output_audio_plugin.h b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output_audio/dsoftbus_output_audio_plugin.h similarity index 100% rename from av_transport/av_trans_engine/plugins/av_trans_output/dsoftbus_output_audio/dsoftbus_output_audio_plugin.h rename to av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output_audio/dsoftbus_output_audio_plugin.h diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/BUILD.gn b/av_transport/av_trans_handler/histreamer_ability_querier/BUILD.gn index 7b51c8042fd2fafc404e06a827e60562f59dd1eb..0cd00f94ca24b72745ebd3b1d5336e3e11c2cc31 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/BUILD.gn +++ b/av_transport/av_trans_handler/histreamer_ability_querier/BUILD.gn @@ -15,18 +15,21 @@ import("//build/ohos.gni") import( "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") +config("handler_external_config") { + include_dirs = [ + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/common/include", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_sender/include", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_receiver/include", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/interface", + ] +} + ohos_shared_library("histreamer_ability_querier") { + public_configs = [ ":handler_external_config" ] + include_dirs = [ "include", "//third_party/json/include", - "${histreamer_path}", - "${histreamer_path}/include", - "${histreamer_path}/include/plugin", - "${histreamer_path}/include/plugin/common", - "${histreamer_path}/include/pipeline/core", - "${histreamer_path}/plugin/core", - "${histreamer_path}/pipeline/filters/common", - "${histreamer_path}/scene/standard", "${media_standard_path}/interfaces/inner_api/native", "${common_path}/include", ] @@ -36,19 +39,19 @@ ohos_shared_library("histreamer_ability_querier") { "src/histreamer_ability_querier.cpp", ] - deps = [ - "${histreamer_path}/pipeline:histreamer_base", - "${histreamer_path}/plugin:histreamer_plugin_base", - "${histreamer_path}/plugin:histreamer_plugin_core", - ] - defines = [ "HI_LOG_ENABLE", "DH_LOG_TAG=\"distributed_av_transport\"", "LOG_DOMAIN=0xD004100", ] - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + external_deps = [ + "histreamer:histreamer_base", + "histreamer:histreamer_codec_filters", + "histreamer:histreamer_ffmpeg_convert", + "histreamer:histreamer_plugin_base", + "hiviewdfx_hilog_native:libhilog", + ] cflags = [ "-O2", @@ -67,8 +70,8 @@ ohos_shared_library("histreamer_ability_querier") { "//build/config/compiler:no_exceptions", ] - subsystem_name = "multimedia" - part_name = "histreamer" + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" } ohos_rust_shared_ffi("histreamer_ability_querier_core") { diff --git a/av_transport/av_trans_handler/histreamer_ability_querier/src/histreamer_ability_querier.cpp b/av_transport/av_trans_handler/histreamer_ability_querier/src/histreamer_ability_querier.cpp index 0788dfcf882d4cb4de05fe29e92548ce3b93c2dd..ff1b529f076f292643357d0abe3d11bd0e14b25e 100644 --- a/av_transport/av_trans_handler/histreamer_ability_querier/src/histreamer_ability_querier.cpp +++ b/av_transport/av_trans_handler/histreamer_ability_querier/src/histreamer_ability_querier.cpp @@ -21,7 +21,7 @@ #include #include "plugin_caps.h" #include "plugin_manager.h" -#include "plugin_utils.h" +#include "pipeline/filters/common/plugin_utils.h" #include "av_trans_log.h" diff --git a/av_transport/common/include/av_sync_utils.h b/av_transport/common/include/av_sync_utils.h index d838f29f1ebcaed9a9d128cf8e6b3d9ad75eba7e..424ceeb5e662ce741d000f99f528de2183499400 100644 --- a/av_transport/common/include/av_sync_utils.h +++ b/av_transport/common/include/av_sync_utils.h @@ -18,7 +18,6 @@ #include #include -#include "nocopyable.h" namespace OHOS { namespace DistributedHardware { diff --git a/av_transport/distributed_av_transport.gni b/av_transport/distributed_av_transport.gni index 5601b7c500e75fda3848fb9557916e139d90b569..801ec54454a38bfc4526e046177fee443e5ec331 100644 --- a/av_transport/distributed_av_transport.gni +++ b/av_transport/distributed_av_transport.gni @@ -18,6 +18,8 @@ distributed_av_transport_path = "${distributedhardwarefwk_path}/av_transport" histreamer_path = "//foundation/multimedia/histreamer/engine" +dsoftbus_path = "//foundation/communication/dsoftbus" + media_standard_path = "//foundation/multimedia/player_framework" drivers_disaplay_path = "//drivers/peripheral/display" @@ -32,10 +34,12 @@ handler_path = "${distributed_av_transport_path}/av_trans_handler" control_center_path = "${distributed_av_transport_path}/av_trans_control_center" +filters_path = "${distributed_av_transport_path}/av_trans_engine/filters" + dh_fwk_utils_path = "${distributedhardwarefwk_path}/common/utils" dh_fwk_services_path = "${distributedhardwarefwk_path}/services" -plugin_path = "${engine_path}/plugins" +plugin_path = "${engine_path}/plugin" build_flags = [ "-Werror" ] diff --git a/bundle.json b/bundle.json index c3f190c0bee936bc592a54c2b52663c25ef3b20d..f7444a9b6a463435ff1a7b8c28f5bfe4cf24d7e6 100644 --- a/bundle.json +++ b/bundle.json @@ -47,7 +47,9 @@ "init", "kv_store", "resource_schedule_service", - "multimedia_histreamer" + "multimedia_histreamer", + "graphic_standard", + "histreamer" ], "third_party": [ "json", @@ -62,6 +64,9 @@ "//foundation/distributedhardware/distributed_hardware_fwk/sa_profile:dhfwk_sa_profile", "//foundation/distributedhardware/distributed_hardware_fwk/sa_profile:dhardware.cfg", "//foundation/distributedhardware/distributed_hardware_fwk/interfaces/inner_kits:libdhfwk_sdk", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_control_center/inner_kits:avtranscenter_sdk", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_sender:distributed_av_sender", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_receiver:distributed_av_receiver", "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_handler/histreamer_ability_querier:histreamer_ability_querier" ], "inner_kits": [ @@ -75,6 +80,14 @@ "header_base": "//foundation/distributedhardware/distributed_hardware_fwk/interfaces/inner_kits/include" } }, + { + "type": "so", + "name": "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_sender:distributed_av_sender", + "header": { + "header_files": [], + "header_base": "//foundation/distributedhardware/distributed_hardware_fwk/av_transport" + } + }, { "type": "so", "name": "//foundation/distributedhardware/distributed_hardware_fwk/utils:distributedhardwareutils", diff --git a/distributedhardwarefwk.gni b/distributedhardwarefwk.gni index 3dcc22341303aec4a28f523a4facaec4a6b6d68a..22668242f6519ea010203a24927845a3de5e6d3b 100644 --- a/distributedhardwarefwk.gni +++ b/distributedhardwarefwk.gni @@ -27,8 +27,6 @@ av_trans_path = "${distributedhardwarefwk_path}/av_transport" av_trans_ctl_center_svc_path = "${av_trans_path}/av_trans_control_center/services" -histreamer_path = "//foundation/multimedia/histreamer/engine" - build_flags = [ "-Werror" ] declare_args() {