From e4dd2bb257d49dfb102a3f344e1bab5e19ccacb2 Mon Sep 17 00:00:00 2001 From: byndyx Date: Tue, 7 Jan 2025 10:48:35 +0800 Subject: [PATCH] json Signed-off-by: byndyx --- av_transport/common/include/pipeline_event.h | 4 +- av_transport/framework/BUILD.gn | 6 + .../framework/filter/include/filter.h | 2 + av_transport/framework/test/demo/BUILD.gn | 84 ++++++ .../framework/test/demo/head_filter.cpp | 243 +++++++++++++++++ .../framework/test/demo/head_filter.h | 77 ++++++ .../framework/test/demo/mid_filter.cpp | 247 ++++++++++++++++++ av_transport/framework/test/demo/mid_filter.h | 77 ++++++ .../framework/test/demo/pipe_demo.cpp | 209 +++++++++++++++ av_transport/framework/test/demo/pipe_demo.h | 69 +++++ .../framework/test/demo/tail_filter.cpp | 236 +++++++++++++++++ .../framework/test/demo/tail_filter.h | 77 ++++++ bundle.json | 2 + 13 files changed, 1332 insertions(+), 1 deletion(-) create mode 100644 av_transport/framework/test/demo/BUILD.gn create mode 100644 av_transport/framework/test/demo/head_filter.cpp create mode 100644 av_transport/framework/test/demo/head_filter.h create mode 100644 av_transport/framework/test/demo/mid_filter.cpp create mode 100644 av_transport/framework/test/demo/mid_filter.h create mode 100644 av_transport/framework/test/demo/pipe_demo.cpp create mode 100644 av_transport/framework/test/demo/pipe_demo.h create mode 100644 av_transport/framework/test/demo/tail_filter.cpp create mode 100644 av_transport/framework/test/demo/tail_filter.h diff --git a/av_transport/common/include/pipeline_event.h b/av_transport/common/include/pipeline_event.h index ad19d54e..611373da 100644 --- a/av_transport/common/include/pipeline_event.h +++ b/av_transport/common/include/pipeline_event.h @@ -23,6 +23,7 @@ namespace OHOS { namespace DistributedHardware { +namespace Pipeline { enum struct EventType : uint32_t { EVENT_READY = 0, EVENT_AUDIO_PROGRESS, // unit is HST_TIME_BASE @@ -63,6 +64,7 @@ struct Event { }; const char* GetEventName(EventType type); +} // namespace Pipeline } // namespace DistributedHardware } // namespace OHOS -#endif //OHOS_AV_PIPELINE_EVENT_H +#endif // OHOS_AV_PIPELINE_EVENT_H diff --git a/av_transport/framework/BUILD.gn b/av_transport/framework/BUILD.gn index e9945405..e9285316 100644 --- a/av_transport/framework/BUILD.gn +++ b/av_transport/framework/BUILD.gn @@ -58,12 +58,18 @@ ohos_shared_library("distributed_av_pipeline_fwk") { ] external_deps = [ + "av_codec:av_codec_client", + "av_codec:native_media_acodec", "bounds_checking_function:libsec_shared", + "cJSON:cjson", "c_utils:utils", + "dsoftbus:softbus_client", "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", + "media_foundation:media_foundation", + "media_foundation:native_media_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/av_transport/framework/filter/include/filter.h b/av_transport/framework/filter/include/filter.h index 54369a36..13be15fd 100644 --- a/av_transport/framework/filter/include/filter.h +++ b/av_transport/framework/filter/include/filter.h @@ -59,6 +59,8 @@ enum class StreamType { STREAMTYPE_PACKED, STREAMTYPE_ENCODED_AUDIO, STREAMTYPE_ENCODED_VIDEO, + STREAMTYPE_DECODED_AUDIO, + STREAMTYPE_DECODED_VIDEO, STREAMTYPE_RAW_AUDIO, STREAMTYPE_RAW_VIDEO, STREAMTYPE_SUBTITLE, diff --git a/av_transport/framework/test/demo/BUILD.gn b/av_transport/framework/test/demo/BUILD.gn new file mode 100644 index 00000000..add42a8f --- /dev/null +++ b/av_transport/framework/test/demo/BUILD.gn @@ -0,0 +1,84 @@ +# Copyright (c) 2024 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("../../../distributed_av_transport.gni") + +config("av_pipeline_demo_external_config") { + include_dirs = [ + "${common_path}/include", + "${dh_fwk_sdk_path}/include", + "${interface_path}", + ] +} + +ohos_executable("av_trans_pipelie_demo") { + sanitize = { + cfi = true + cfi_cross_dso = true + cfi_no_nvcall = true + cfi_vcall_icall_only = true + debug = false + boundary_sanitize = true + integer_overflow = true + ubsan = true + } + branch_protector_ret = "pac_ret" + public_configs = [ ":av_pipeline_demo_external_config" ] + + include_dirs = [ + "./include", + "${distributed_av_transport_path}/framework", + "${distributed_av_transport_path}/framework/filter/include", + ] + + sources = [ + "${distributed_av_transport_path}/framework/test/demo/head_filter.cpp", + "${distributed_av_transport_path}/framework/test/demo/mid_filter.cpp", + "${distributed_av_transport_path}/framework/test/demo/pipe_demo.cpp", + "${distributed_av_transport_path}/framework/test/demo/tail_filter.cpp", + ] + + deps = [ + "${dh_fwk_sdk_path}:libdhfwk_sdk", + "${distributed_av_transport_path}/framework:distributed_av_pipeline_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"av_trans_pipe_demo\"", + "LOG_DOMAIN=0xD004101", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + + if (histreamer_compile_part) { + external_deps += [ "media_foundation:media_foundation" ] + } + + cflags = [ + "-fexceptions", + "-fno-rtti", + "-fPIC", + "-O2", + "-Wall", + ] + cflags_cc = cflags + + install_enable = false + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" +} diff --git a/av_transport/framework/test/demo/head_filter.cpp b/av_transport/framework/test/demo/head_filter.cpp new file mode 100644 index 00000000..3cb0a226 --- /dev/null +++ b/av_transport/framework/test/demo/head_filter.cpp @@ -0,0 +1,243 @@ +/* + * Copyright (c) 2024 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 "head_filter.h" + +#include + +#include "av_trans_log.h" +#include "filter_factory.h" + +#undef DH_LOG_TAG +#define DH_LOG_TAG "HeadFilter" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +static AutoRegisterFilter g_registerAudioEncoderFilter("builtin.recorder.test1", + FilterType::FILTERTYPE_MUXER, + [](const std::string& name, const FilterType type) { + return std::make_shared(name, FilterType::FILTERTYPE_MUXER); + }); + +class HeadFilterLinkCallback : public FilterLinkCallback { +public: + explicit HeadFilterLinkCallback(std::shared_ptr filter) + : headFilter_(std::move(filter)) {} + ~HeadFilterLinkCallback() = default; + + void OnLinkedResult(const sptr &queue, std::shared_ptr &meta) override + { + if (auto filter = headFilter_.lock()) { + filter->OnLinkedResult(queue, meta); + } else { + AVTRANS_LOGI("invalid headFilter"); + } + } + + void OnUnlinkedResult(std::shared_ptr &meta) override + { + if (auto filter = headFilter_.lock()) { + filter->OnUnlinkedResult(meta); + } else { + AVTRANS_LOGI("invalid headFilter"); + } + } + + void OnUpdatedResult(std::shared_ptr &meta) override + { + if (auto filter = headFilter_.lock()) { + filter->OnUpdatedResult(meta); + } else { + AVTRANS_LOGI("invalid headFilter"); + } + } + +private: + std::weak_ptr headFilter_ {}; +}; + +HeadFilter::HeadFilter(std::string name, FilterType type, bool isAsyncMode) + : Filter(name, type) +{ +} + +HeadFilter::~HeadFilter() +{ + nextFiltersMap_.clear(); +} + +void HeadFilter::Init(const std::shared_ptr& receiver, const std::shared_ptr& callback) +{ + AVTRANS_LOGI("HeadFilter::Init"); + receiver_ = receiver; + callback_ = callback; + AVTRANS_LOGI("HeadFilter::Init Done"); +} + +Status HeadFilter::DoInitAfterLink() +{ + AVTRANS_LOGI("HeadFilter::DoInitAfterLink"); + return Status::OK; +} + +Status HeadFilter::DoPrepare() +{ + // 1. 本Filter的准备 + AVTRANS_LOGI("HeadFilter::DoPrepare"); + + // 2. 回调申请下一级filter + if (callback_ == nullptr) { + AVTRANS_LOGE("filter callback is null"); + return Status::ERROR_NULL_POINTER; + } + callback_->OnCallback(shared_from_this(), FilterCallBackCommand::NEXT_FILTER_NEEDED, + StreamType::STREAMTYPE_ENCODED_AUDIO); + AVTRANS_LOGI("HeadFilter::DoPrepare done"); + return Status::OK; +} + +Status HeadFilter::DoStart() +{ + AVTRANS_LOGI("HeadFilter::DoStart"); + return Status::OK; +} + +Status HeadFilter::DoPause() +{ + AVTRANS_LOGI("HeadFilter::DoPause"); + return Status::OK; +} + +Status HeadFilter::DoPauseDragging() +{ + AVTRANS_LOGI("HeadFilter::DoPauseDragging"); + return Status::OK; +} + +Status HeadFilter::DoResume() +{ + AVTRANS_LOGI("HeadFilter::DoResume"); + return Status::OK; +} + +Status HeadFilter::DoResumeDragging() +{ + AVTRANS_LOGI("HeadFilter::DoResumeDragging"); + return Status::OK; +} + +Status HeadFilter::DoStop() +{ + AVTRANS_LOGI("HeadFilter::DoStop"); + return Status::OK; +} + +Status HeadFilter::DoFlush() +{ + AVTRANS_LOGI("HeadFilter::DoFlush"); + return Status::OK; +} + +Status HeadFilter::DoRelease() +{ + AVTRANS_LOGI("HeadFilter::DoRelease"); + return Status::OK; +} + +Status HeadFilter::DoProcessInputBuffer(int recvArg, bool dropFrame) +{ + AVTRANS_LOGI("HeadFilter::DoProcessInputBuffer"); + return Status::OK; +} + +Status HeadFilter::DoProcessOutputBuffer(int recvArg, bool dropFrame, bool byIdx, uint32_t idx, int64_t renderTimee) +{ + AVTRANS_LOGI("HeadFilter::DoProcessOutputBuffer"); + return Status::OK; +} + +void HeadFilter::SetParameter(const std::shared_ptr& meta) +{ + meta_ = meta; +} + +void HeadFilter::GetParameter(std::shared_ptr& meta) +{ + meta = meta_; +} + +Status HeadFilter::LinkNext(const std::shared_ptr& nextFilter, StreamType outType) +{ + AVTRANS_LOGI("cur: HeadFilter, link next filter.."); + // 1. 插入下级filter维护map + nextFilter_ = nextFilter; + nextFiltersMap_[outType].push_back(nextFilter_); + // 2. 下级节点的Link初始化 + auto filterLinkCallback = std::make_shared(shared_from_this()); + auto ret = nextFilter->OnLinked(outType, configureParam_, filterLinkCallback); + if (ret != Status::OK) { + AVTRANS_LOGE("Onlinked failed, status: %{public}d.", ret); + return ret; + } + return Status::OK; +} + +Status HeadFilter::UpdateNext(const std::shared_ptr&, StreamType) +{ + return Status::OK; +} + +Status HeadFilter::UnLinkNext(const std::shared_ptr&, StreamType) +{ + AVTRANS_LOGI("cur: HeadFilter, unlink next filter.."); + return Status::OK; +} + +Status HeadFilter::OnLinked(StreamType inType, const std::shared_ptr &meta, + const std::shared_ptr &callback) +{ + AVTRANS_LOGI("cur: HeadFilter, OnLinked"); + return Status::OK; +}; + +Status HeadFilter::OnUpdated(StreamType, const std::shared_ptr&, + const std::shared_ptr&) +{ + return Status::OK; +} + +Status HeadFilter::OnUnLinked(StreamType, const std::shared_ptr&) +{ + AVTRANS_LOGI("cur: HeadFilter, OnUnLinked."); + return Status::OK; +} + +void HeadFilter::OnLinkedResult(const sptr& queue, std::shared_ptr& meta) +{ + // link bufferQueue + AVTRANS_LOGI("cur: HeadFilter, OnLinkedResult"); +} + +void HeadFilter::OnUnlinkedResult(std::shared_ptr& meta) +{ +} + +void HeadFilter::OnUpdatedResult(std::shared_ptr& meta) +{ +} +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS diff --git a/av_transport/framework/test/demo/head_filter.h b/av_transport/framework/test/demo/head_filter.h new file mode 100644 index 00000000..cf68cdb6 --- /dev/null +++ b/av_transport/framework/test/demo/head_filter.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 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 OHOS_AV_PIPELINE_HEAD_FILTER_DEMO_H +#define OHOS_AV_PIPELINE_HEAD_FILTER_DEMO_H + +#include +#include +#include + +#include "pipeline_status.h" +#include "filter.h" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +// 分两步:第一先保证fiter连接正常,第二,filter保证数据流转正常 +class HeadFilter : public Filter, public std::enable_shared_from_this { +public: + HeadFilter(std::string name, FilterType type, bool asyncMode = false); + virtual ~HeadFilter(); + void Init(const std::shared_ptr& receiver, const std::shared_ptr& callback) override; + Status DoInitAfterLink() override; + Status DoPrepare() override; + Status DoStart() override; + Status DoPause() override; + Status DoPauseDragging() override; + Status DoResume() override; + Status DoResumeDragging() override; + Status DoStop() override; + Status DoFlush() override; + Status DoRelease() override; + + Status DoProcessInputBuffer(int recvArg, bool dropFrame) override; + Status DoProcessOutputBuffer(int recvArg, bool dropFrame, bool byIdx, uint32_t idx, int64_t renderTime) override; + void SetParameter(const std::shared_ptr& meta) override; + void GetParameter(std::shared_ptr& meta) override; + + Status LinkNext(const std::shared_ptr& nextFilter, StreamType outType) override; + Status UpdateNext(const std::shared_ptr& nextFilter, StreamType outType) override; + Status UnLinkNext(const std::shared_ptr& nextFilter, StreamType outType) override; + + Status OnLinked(StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback) override; + Status OnUpdated(StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback) override; + Status OnUnLinked(StreamType inType, const std::shared_ptr& callback) override; + + // PipeLinked 后处理 + void OnLinkedResult(const sptr& queue, std::shared_ptr& meta); + void OnUnlinkedResult(std::shared_ptr& meta); + void OnUpdatedResult(std::shared_ptr& meta); + +private: + std::shared_ptr configureParam_ {nullptr}; + std::shared_ptr nextFilter_ {nullptr}; + + std::shared_ptr eventReceiver_ {nullptr}; + std::shared_ptr filterCallback_ {nullptr}; + std::shared_ptr onLinkedResultCallback_ {nullptr}; +}; +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_AV_PIPELINE_HEAD_FILTER_DEMO_H diff --git a/av_transport/framework/test/demo/mid_filter.cpp b/av_transport/framework/test/demo/mid_filter.cpp new file mode 100644 index 00000000..edec23d7 --- /dev/null +++ b/av_transport/framework/test/demo/mid_filter.cpp @@ -0,0 +1,247 @@ +/* + * Copyright (c) 2024 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 "mid_filter.h" + +#include + +#include "av_trans_log.h" +#include "filter_factory.h" + +#undef DH_LOG_TAG +#define DH_LOG_TAG "MidFilter" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +static AutoRegisterFilter g_registerAudioEncoderFilter("builtin.recorder.midfilter", + FilterType::FILTERTYPE_VIDEODEC, + [](const std::string& name, const FilterType type) { + return std::make_shared(name, FilterType::FILTERTYPE_VIDEODEC); + }); + +class MidFilterLinkCallback : public FilterLinkCallback { +public: + explicit MidFilterLinkCallback(std::shared_ptr filter) + : headFilter_(std::move(filter)) {} + ~MidFilterLinkCallback() = default; + + void OnLinkedResult(const sptr &queue, std::shared_ptr &meta) override + { + if (auto filter = headFilter_.lock()) { + filter->OnLinkedResult(queue, meta); + } else { + AVTRANS_LOGI("invalid headFilter"); + } + } + + void OnUnlinkedResult(std::shared_ptr &meta) override + { + if (auto filter = headFilter_.lock()) { + filter->OnUnlinkedResult(meta); + } else { + AVTRANS_LOGI("invalid headFilter"); + } + } + + void OnUpdatedResult(std::shared_ptr &meta) override + { + if (auto filter = headFilter_.lock()) { + filter->OnUpdatedResult(meta); + } else { + AVTRANS_LOGI("invalid headFilter"); + } + } + +private: + std::weak_ptr headFilter_ {}; +}; + +MidFilter::MidFilter(std::string name, FilterType type, bool isAsyncMode) + : Filter(name, type) +{ +} + +MidFilter::~MidFilter() +{ + nextFiltersMap_.clear(); +} + +void MidFilter::Init(const std::shared_ptr& receiver, const std::shared_ptr& callback) +{ + receiver_ = receiver; + callback_ = callback; +} + +Status MidFilter::DoInitAfterLink() +{ + AVTRANS_LOGI("MidFilter::DoInitAfterLink"); + return Status::OK; +} + +Status MidFilter::DoPrepare() +{ + // 1. 本Filter的准备 + AVTRANS_LOGI("MidFilter::DoPrepare"); + + // 2. 回调申请下一级filter + if (callback_ == nullptr) { + AVTRANS_LOGE("filter callback is null"); + return Status::ERROR_NULL_POINTER; + } + callback_->OnCallback(shared_from_this(), FilterCallBackCommand::NEXT_FILTER_NEEDED, + StreamType::STREAMTYPE_RAW_AUDIO); + AVTRANS_LOGI("MidFilter::DoPrepare done"); + return Status::OK; +} + +Status MidFilter::DoStart() +{ + AVTRANS_LOGI("MidFilter::DoStart"); + return Status::OK; +} + +Status MidFilter::DoPause() +{ + AVTRANS_LOGI("MidFilter::DoPause"); + return Status::OK; +} + +Status MidFilter::DoPauseDragging() +{ + AVTRANS_LOGI("MidFilter::DoPauseDragging"); + return Status::OK; +} + +Status MidFilter::DoResume() +{ + AVTRANS_LOGI("MidFilter::DoResume"); + return Status::OK; +} + +Status MidFilter::DoResumeDragging() +{ + AVTRANS_LOGI("MidFilter::DoResumeDragging"); + return Status::OK; +} + +Status MidFilter::DoStop() +{ + AVTRANS_LOGI("MidFilter::DoStop"); + return Status::OK; +} + +Status MidFilter::DoFlush() +{ + AVTRANS_LOGI("MidFilter::DoFlush"); + return Status::OK; +} + +Status MidFilter::DoRelease() +{ + AVTRANS_LOGI("MidFilter::DoRelease"); + return Status::OK; +} + +Status MidFilter::DoProcessInputBuffer(int recvArg, bool dropFrame) +{ + AVTRANS_LOGI("MidFilter::DoProcessInputBuffer"); + return Status::OK; +} + +Status MidFilter::DoProcessOutputBuffer(int recvArg, bool dropFrame, bool byIdx, uint32_t idx, int64_t renderTimee) +{ + AVTRANS_LOGI("MidFilter::DoProcessOutputBuffer"); + return Status::OK; +} + +void MidFilter::SetParameter(const std::shared_ptr& meta) +{ + meta_ = meta; +} + +void MidFilter::GetParameter(std::shared_ptr& meta) +{ + meta = meta_; +} + +Status MidFilter::LinkNext(const std::shared_ptr& nextFilter, StreamType outType) +{ + AVTRANS_LOGI("cur: MidFilter, link next filter.."); + // 1. 插入下级filter维护map + nextFilter_ = nextFilter; + nextFiltersMap_[outType].push_back(nextFilter_); + // 2. 下级节点的Link初始化 + auto filterLinkCallback = std::make_shared(shared_from_this()); + auto ret = nextFilter->OnLinked(outType, configureParam_, filterLinkCallback); + if (ret != Status::OK) { + AVTRANS_LOGE("Onlinked failed, status: %{public}d.", ret); + return ret; + } + return Status::OK; +} + +Status MidFilter::UpdateNext(const std::shared_ptr&, StreamType) +{ + return Status::OK; +} + +Status MidFilter::UnLinkNext(const std::shared_ptr&, StreamType) +{ + AVTRANS_LOGI("cur: MidFilter, unlink next filter.."); + return Status::OK; +} + +Status MidFilter::OnLinked(StreamType inType, const std::shared_ptr &meta, + const std::shared_ptr &callback) +{ + AVTRANS_LOGI("cur: MidFilter, OnLinked"); + onLinkedResultCallback_ = callback; + return Status::OK; +}; + +Status MidFilter::OnUpdated(StreamType, const std::shared_ptr&, + const std::shared_ptr&) +{ + return Status::OK; +} + +Status MidFilter::OnUnLinked(StreamType, const std::shared_ptr&) +{ + AVTRANS_LOGI("cur: MidFilter, OnUnLinked."); + return Status::OK; +} + +void MidFilter::OnLinkedResult(const sptr& queue, std::shared_ptr& meta) +{ + // link bufferQueue + AVTRANS_LOGI("cur: MidFilter, OnLinkedResult."); + sptr producer = nullptr; + std::shared_ptr midMeta = std::make_shared(); + if (onLinkedResultCallback_ != nullptr) { + onLinkedResultCallback_->OnLinkedResult(producer, midMeta); + } +} + +void MidFilter::OnUnlinkedResult(std::shared_ptr& meta) +{ +} + +void MidFilter::OnUpdatedResult(std::shared_ptr& meta) +{ +} +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS diff --git a/av_transport/framework/test/demo/mid_filter.h b/av_transport/framework/test/demo/mid_filter.h new file mode 100644 index 00000000..51fa583b --- /dev/null +++ b/av_transport/framework/test/demo/mid_filter.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 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 OHOS_AV_PIPELINE_MID_FILTER_DEMO_H +#define OHOS_AV_PIPELINE_MID_FILTER_DEMO_H + +#include +#include +#include + +#include "pipeline_status.h" +#include "filter.h" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +// 分两步:第一先保证fiter连接正常,第二,filter保证数据流转正常 +class MidFilter : public Filter, public std::enable_shared_from_this { +public: + MidFilter(std::string name, FilterType type, bool asyncMode = false); + virtual ~MidFilter(); + void Init(const std::shared_ptr& receiver, const std::shared_ptr& callback) override; + Status DoInitAfterLink() override; + Status DoPrepare() override; + Status DoStart() override; + Status DoPause() override; + Status DoPauseDragging() override; + Status DoResume() override; + Status DoResumeDragging() override; + Status DoStop() override; + Status DoFlush() override; + Status DoRelease() override; + + Status DoProcessInputBuffer(int recvArg, bool dropFrame) override; + Status DoProcessOutputBuffer(int recvArg, bool dropFrame, bool byIdx, uint32_t idx, int64_t renderTime) override; + void SetParameter(const std::shared_ptr& meta) override; + void GetParameter(std::shared_ptr& meta) override; + + Status LinkNext(const std::shared_ptr& nextFilter, StreamType outType) override; + Status UpdateNext(const std::shared_ptr& nextFilter, StreamType outType) override; + Status UnLinkNext(const std::shared_ptr& nextFilter, StreamType outType) override; + + Status OnLinked(StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback) override; + Status OnUpdated(StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback) override; + Status OnUnLinked(StreamType inType, const std::shared_ptr& callback) override; + + // PipeLinked 后处理 + void OnLinkedResult(const sptr& queue, std::shared_ptr& meta); + void OnUnlinkedResult(std::shared_ptr& meta); + void OnUpdatedResult(std::shared_ptr& meta); + +private: + std::shared_ptr configureParam_ {nullptr}; + std::shared_ptr nextFilter_ {nullptr}; + + std::shared_ptr eventReceiver_ {nullptr}; + std::shared_ptr filterCallback_ {nullptr}; + std::shared_ptr onLinkedResultCallback_ {nullptr}; +}; +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_AV_PIPELINE_MID_FILTER_DEMO_H diff --git a/av_transport/framework/test/demo/pipe_demo.cpp b/av_transport/framework/test/demo/pipe_demo.cpp new file mode 100644 index 00000000..513ad285 --- /dev/null +++ b/av_transport/framework/test/demo/pipe_demo.cpp @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2024 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 "pipe_demo.h" + +#include +#include + +#include "av_trans_log.h" +#include "filter_factory.h" + +#undef DH_LOG_TAG +#define DH_LOG_TAG "PipeDemo" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +class PlayerEventReceiver : public EventReceiver { +public: + explicit PlayerEventReceiver(PipeDemo* pipeDemo, std::string playerId) + { + AVTRANS_LOGI("PlayerEventReceiver ctor called."); + pipeDemo_ = pipeDemo; + } + + void OnEvent(const Event &event) + { + AVTRANS_LOGD("PlayerEventReceiver OnEvent."); + } + +private: + PipeDemo* pipeDemo_; +}; + +class PlayerFilterCallback : public FilterCallback { +public: + explicit PlayerFilterCallback(PipeDemo* pipeDemo) + { + AVTRANS_LOGI("PlayerFilterCallback ctor called."); + pipeDemo_ = pipeDemo; + } + + Status OnCallback(const std::shared_ptr& filter, FilterCallBackCommand cmd, StreamType outType) override + { + AVTRANS_LOGI("PlayerFilterCallback OnCallback."); + if (pipeDemo_ == nullptr) { + return Status::ERROR_NULL_POINTER; + } + return pipeDemo_->OnCallback(filter, cmd, outType); + } + +private: + PipeDemo* pipeDemo_; +}; + + +PipeDemo::PipeDemo() {} + +PipeDemo::~PipeDemo() {} + +int32_t PipeDemo::InitPipe() +{ + // 初始化pipeline + demoId_ = std::string("PipeDemo") + std::to_string(Pipeline::GetNextPipelineId()); + pipeline_ = std::make_shared(); + playerEventReceiver_ = std::make_shared(this, demoId_); + playerFilterCallback_ = std::make_shared(this); + + AVTRANS_LOGI("pipeline Init in"); + pipeline_->Init(playerEventReceiver_, playerFilterCallback_, demoId_); + AVTRANS_LOGI("pipeline Init out"); + // 添加头Filter + headFilter_ = FilterFactory::Instance().CreateFilter("builtin.recorder.test1", + FilterType::FILTERTYPE_MUXER); + if (headFilter_ == nullptr) { + return -1; + } + + headFilter_->Init(playerEventReceiver_, playerFilterCallback_); + pipeline_->AddHeadFilters({headFilter_}); + return 0; +} + +int32_t PipeDemo::Prepare() +{ + if (pipeline_ != nullptr) { + pipeline_->Prepare(); + } + return 0; +} + +int32_t PipeDemo::Start() +{ + if (pipeline_ != nullptr) { + pipeline_->Start(); + } + return 0; +} + +int32_t PipeDemo::Pause() +{ + if (pipeline_ != nullptr) { + pipeline_->Pause(); + } + return 0; +} + +int32_t PipeDemo::Stop() +{ + if (pipeline_ != nullptr) { + pipeline_->Stop(); + } + return 0; +} + +int32_t PipeDemo::Release() +{ + if (pipeline_ != nullptr) { + pipeline_->Release(); + } + return 0; +} + +Status PipeDemo::OnCallback(std::shared_ptr filter, const FilterCallBackCommand cmd, + StreamType outType) +{ + AVTRANS_LOGI("PipeDemo::OnCallback filter, outType: %{public}d", outType); + if (cmd == FilterCallBackCommand::NEXT_FILTER_NEEDED) { + switch (outType) { + case StreamType::STREAMTYPE_RAW_AUDIO: + return LinkAudioSinkFilter(filter, outType); + case StreamType::STREAMTYPE_ENCODED_AUDIO: + return LinkAudioDecoderFilter(filter, outType); + default: + break; + } + } + return Status::OK; +} + +Status PipeDemo::LinkAudioDecoderFilter(const std::shared_ptr& preFilter, StreamType type) +{ + AVTRANS_LOGI("PipeDemo::LinkAudioDecoderFilter"); + TRUE_RETURN_V(midFilter_ != nullptr, Status::OK); + midFilter_ = FilterFactory::Instance().CreateFilter("builtin.recorder.midfilter", + FilterType::FILTERTYPE_VIDEODEC); + TRUE_RETURN_V(midFilter_ == nullptr, Status::ERROR_NULL_POINTER); + midFilter_->Init(playerEventReceiver_, playerFilterCallback_); + + return pipeline_->LinkFilters(preFilter, {midFilter_}, type); +} + +Status PipeDemo::LinkAudioSinkFilter(const std::shared_ptr& preFilter, StreamType type) +{ + AVTRANS_LOGI("PipeDemo::LinkAudioSinkFilter"); + TRUE_RETURN_V(tailFilter_ != nullptr, Status::OK); + tailFilter_ = FilterFactory::Instance().CreateFilter("builtin.recorder.tailfilter", + FilterType::FILTERTYPE_DEMUXER); + TRUE_RETURN_V(tailFilter_ == nullptr, Status::ERROR_NULL_POINTER); + tailFilter_->Init(playerEventReceiver_, playerFilterCallback_); + + return pipeline_->LinkFilters(preFilter, {tailFilter_}, type); +} +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS + + +int main(int argc, char *argv[]) +{ + auto pipeDemo = std::make_shared(); + std::cout << "Initing..." << std::endl; + pipeDemo->InitPipe(); + std::cout << "Init piep success" << std::endl; + + std::cout << "Preparing..." << std::endl; + pipeDemo->Prepare(); + std::cout << "Prepare success" << std::endl; + + std::cout << "Starting..." << std::endl; + pipeDemo->Start(); + std::cout << "Start success" << std::endl; + + std::cout << "Pausing..." << std::endl; + pipeDemo->Pause(); + std::cout << "Pause success" << std::endl; + + std::cout << "Stoping..." << std::endl; + pipeDemo->Stop(); + std::cout << "Stop success" << std::endl; + + std::cout << "Releasing..." << std::endl; + pipeDemo->Release(); + std::cout << "Release success" << std::endl; + + return 0; +} diff --git a/av_transport/framework/test/demo/pipe_demo.h b/av_transport/framework/test/demo/pipe_demo.h new file mode 100644 index 00000000..b424d674 --- /dev/null +++ b/av_transport/framework/test/demo/pipe_demo.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 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 OHOS_AV_PIPELINE_DEMO_H +#define OHOS_AV_PIPELINE_DEMO_H + +#include +#include +#include + +#include "osal/task/mutex.h" + +#include "filter.h" +#include "head_filter.h" +#include "mid_filter.h" +#include "pipeline_status.h" +#include "pipeline/include/pipeline.h" +#include "tail_filter.h" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +class PipeDemo { +public: + PipeDemo(); + ~PipeDemo(); + + int32_t InitPipe(); + + int32_t Prepare(); + + int32_t Start(); + + int32_t Pause(); + + int32_t Stop(); + + int32_t Release(); + + Status OnCallback(std::shared_ptr filter, const FilterCallBackCommand cmd, + StreamType outType); + Status LinkAudioDecoderFilter(const std::shared_ptr& preFilter, StreamType type); + Status LinkAudioSinkFilter(const std::shared_ptr& preFilter, StreamType type); + +private: + std::string demoId_ {-1}; + std::shared_ptr playerEventReceiver_ {nullptr}; + std::shared_ptr playerFilterCallback_ {nullptr}; + std::shared_ptr pipeline_ {nullptr}; + std::shared_ptr headFilter_ {nullptr}; + std::shared_ptr midFilter_ {nullptr}; + std::shared_ptr tailFilter_ {nullptr}; +}; +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_AV_PIPELINE_DEMO_H diff --git a/av_transport/framework/test/demo/tail_filter.cpp b/av_transport/framework/test/demo/tail_filter.cpp new file mode 100644 index 00000000..dc1c425d --- /dev/null +++ b/av_transport/framework/test/demo/tail_filter.cpp @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2024 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 "tail_filter.h" + +#include + +#include "av_trans_log.h" +#include "filter_factory.h" + +#undef DH_LOG_TAG +#define DH_LOG_TAG "TailFilter" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +static AutoRegisterFilter g_registerAudioEncoderFilter("builtin.recorder.tailfilter", + FilterType::FILTERTYPE_DEMUXER, + [](const std::string& name, const FilterType type) { + return std::make_shared(name, FilterType::FILTERTYPE_DEMUXER); + }); + +class TailFilterLinkCallback : public FilterLinkCallback { +public: + explicit TailFilterLinkCallback(std::shared_ptr filter) + : headFilter_(std::move(filter)) {} + ~TailFilterLinkCallback() = default; + + void OnLinkedResult(const sptr &queue, std::shared_ptr &meta) override + { + if (auto filter = headFilter_.lock()) { + filter->OnLinkedResult(queue, meta); + } else { + AVTRANS_LOGI("invalid headFilter"); + } + } + + void OnUnlinkedResult(std::shared_ptr &meta) override + { + if (auto filter = headFilter_.lock()) { + filter->OnUnlinkedResult(meta); + } else { + AVTRANS_LOGI("invalid headFilter"); + } + } + + void OnUpdatedResult(std::shared_ptr &meta) override + { + if (auto filter = headFilter_.lock()) { + filter->OnUpdatedResult(meta); + } else { + AVTRANS_LOGI("invalid headFilter"); + } + } + +private: + std::weak_ptr headFilter_ {}; +}; + +TailFilter::TailFilter(std::string name, FilterType type, bool isAsyncMode) + : Filter(name, type) +{ +} + +TailFilter::~TailFilter() +{ + nextFiltersMap_.clear(); +} + +void TailFilter::Init(const std::shared_ptr& receiver, const std::shared_ptr& callback) +{ + receiver_ = receiver; + callback_ = callback; +} + +Status TailFilter::DoInitAfterLink() +{ + AVTRANS_LOGI("TailFilter::DoInitAfterLink"); + return Status::OK; +} + +Status TailFilter::DoPrepare() +{ + AVTRANS_LOGI("cur: TailFilter, notify linkedResult."); + sptr producer = nullptr; + std::shared_ptr meta = std::make_shared(); + if (onLinkedResultCallback_ != nullptr) { + onLinkedResultCallback_->OnLinkedResult(producer, meta); + } + return Status::OK; +} + +Status TailFilter::DoStart() +{ + AVTRANS_LOGI("TailFilter::DoStart"); + return Status::OK; +} + +Status TailFilter::DoPause() +{ + AVTRANS_LOGI("TailFilter::DoPause"); + return Status::OK; +} + +Status TailFilter::DoPauseDragging() +{ + AVTRANS_LOGI("TailFilter::DoPauseDragging"); + return Status::OK; +} + +Status TailFilter::DoResume() +{ + AVTRANS_LOGI("TailFilter::DoResume"); + return Status::OK; +} + +Status TailFilter::DoResumeDragging() +{ + AVTRANS_LOGI("TailFilter::DoResumeDragging"); + return Status::OK; +} + +Status TailFilter::DoStop() +{ + AVTRANS_LOGI("TailFilter::DoStop"); + return Status::OK; +} + +Status TailFilter::DoFlush() +{ + AVTRANS_LOGI("TailFilter::DoFlush"); + return Status::OK; +} + +Status TailFilter::DoRelease() +{ + AVTRANS_LOGI("TailFilter::DoRelease"); + return Status::OK; +} + +Status TailFilter::DoProcessInputBuffer(int recvArg, bool dropFrame) +{ + AVTRANS_LOGI("TailFilter::DoProcessInputBuffer"); + return Status::OK; +} + +Status TailFilter::DoProcessOutputBuffer(int recvArg, bool dropFrame, bool byIdx, uint32_t idx, int64_t renderTimee) +{ + AVTRANS_LOGI("TailFilter::DoProcessOutputBuffer"); + return Status::OK; +} + +void TailFilter::SetParameter(const std::shared_ptr& meta) +{ + meta_ = meta; +} + +void TailFilter::GetParameter(std::shared_ptr& meta) +{ + meta = meta_; +} + +Status TailFilter::LinkNext(const std::shared_ptr& nextFilter, StreamType outType) +{ + AVTRANS_LOGI("cur: TailFilter, link next filter.."); + // 1. 插入下级filter维护map + nextFilter_ = nextFilter; + nextFiltersMap_[outType].push_back(nextFilter_); + // 2. 下级节点的Link初始化 + auto filterLinkCallback = std::make_shared(shared_from_this()); + auto ret = nextFilter->OnLinked(outType, configureParam_, filterLinkCallback); + if (ret != Status::OK) { + AVTRANS_LOGE("Onlinked failed, status: %{public}d.", ret); + return ret; + } + return Status::OK; +} + +Status TailFilter::UpdateNext(const std::shared_ptr&, StreamType) +{ + return Status::OK; +} + +Status TailFilter::UnLinkNext(const std::shared_ptr&, StreamType) +{ + AVTRANS_LOGI("cur: TailFilter, unlink next filter.."); + return Status::OK; +} + +Status TailFilter::OnLinked(StreamType inType, const std::shared_ptr &meta, + const std::shared_ptr &callback) +{ + AVTRANS_LOGI("cur: TailFilter, OnLinked"); + onLinkedResultCallback_ = callback; + return Status::OK; +}; + +Status TailFilter::OnUpdated(StreamType, const std::shared_ptr&, + const std::shared_ptr&) +{ + return Status::OK; +} + +Status TailFilter::OnUnLinked(StreamType, const std::shared_ptr&) +{ + AVTRANS_LOGI("cur: TailFilter, OnUnLinked."); + return Status::OK; +} + +void TailFilter::OnLinkedResult(const sptr& queue, std::shared_ptr& meta) +{ + // link bufferQueue +} + +void TailFilter::OnUnlinkedResult(std::shared_ptr& meta) +{ +} + +void TailFilter::OnUpdatedResult(std::shared_ptr& meta) +{ +} +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS diff --git a/av_transport/framework/test/demo/tail_filter.h b/av_transport/framework/test/demo/tail_filter.h new file mode 100644 index 00000000..4978f289 --- /dev/null +++ b/av_transport/framework/test/demo/tail_filter.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024 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 OHOS_AV_PIPELINE_TAIL_FILTER_DEMO_H +#define OHOS_AV_PIPELINE_TAIL_FILTER_DEMO_H + +#include +#include +#include + +#include "pipeline_status.h" +#include "filter.h" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +// 分两步:第一先保证fiter连接正常,第二,filter保证数据流转正常 +class TailFilter : public Filter, public std::enable_shared_from_this { +public: + TailFilter(std::string name, FilterType type, bool asyncMode = false); + virtual ~TailFilter(); + void Init(const std::shared_ptr& receiver, const std::shared_ptr& callback) override; + Status DoInitAfterLink() override; + Status DoPrepare() override; + Status DoStart() override; + Status DoPause() override; + Status DoPauseDragging() override; + Status DoResume() override; + Status DoResumeDragging() override; + Status DoStop() override; + Status DoFlush() override; + Status DoRelease() override; + + Status DoProcessInputBuffer(int recvArg, bool dropFrame) override; + Status DoProcessOutputBuffer(int recvArg, bool dropFrame, bool byIdx, uint32_t idx, int64_t renderTime) override; + void SetParameter(const std::shared_ptr& meta) override; + void GetParameter(std::shared_ptr& meta) override; + + Status LinkNext(const std::shared_ptr& nextFilter, StreamType outType) override; + Status UpdateNext(const std::shared_ptr& nextFilter, StreamType outType) override; + Status UnLinkNext(const std::shared_ptr& nextFilter, StreamType outType) override; + + Status OnLinked(StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback) override; + Status OnUpdated(StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback) override; + Status OnUnLinked(StreamType inType, const std::shared_ptr& callback) override; + + // PipeLinked 后处理 + void OnLinkedResult(const sptr& queue, std::shared_ptr& meta); + void OnUnlinkedResult(std::shared_ptr& meta); + void OnUpdatedResult(std::shared_ptr& meta); + +private: + std::shared_ptr configureParam_ {nullptr}; + std::shared_ptr nextFilter_ {nullptr}; + + std::shared_ptr eventReceiver_ {nullptr}; + std::shared_ptr filterCallback_ {nullptr}; + std::shared_ptr onLinkedResultCallback_ {nullptr}; +}; +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_AV_PIPELINE_TAIL_FILTER_DEMO_H diff --git a/bundle.json b/bundle.json index 86e25ff5..313deb80 100644 --- a/bundle.json +++ b/bundle.json @@ -33,6 +33,7 @@ "ability_base", "ability_runtime", "access_token", + "av_codec", "bundle_framework", "napi", "dsoftbus", @@ -67,6 +68,7 @@ "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_sender:distributed_av_sender", "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_handler/histreamer_ability_querier:histreamer_ability_querier", "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/framework:distributed_av_pipeline_fwk", + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/framework/test/demo:av_trans_pipelie_demo", "//foundation/distributedhardware/distributed_hardware_fwk/interfaces/inner_kits:libdhfwk_sdk", "//foundation/distributedhardware/distributed_hardware_fwk/interfaces/kits/napi:hardwaremanager", "//foundation/distributedhardware/distributed_hardware_fwk/sa_profile:dhardware.cfg", -- Gitee