diff --git a/av_transport/common/include/pipeline_event.h b/av_transport/common/include/pipeline_event.h new file mode 100644 index 0000000000000000000000000000000000000000..fa18fcb95b49ebaddaf958b32f520ec8b9ddec49 --- /dev/null +++ b/av_transport/common/include/pipeline_event.h @@ -0,0 +1,49 @@ +/* + * 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_EVENT_H +#define OHOS_AV_PIPELINE_EVENT_H + +#include +#include + +#include "meta/any.h" + +namespace OHOS { +namespace DistributedHardware { +enum struct EventType : uint32_t { + EVENT_READY = 0, + EVENT_AUDIO_PROGRESS, // unit is HST_TIME_BASE + EVENT_VIDEO_PROGRESS, // unit is HST_TIME_BASE + EVENT_COMPLETE, + EVENT_ERROR, + EVENT_PLUGIN_ERROR, + EVENT_PLUGIN_EVENT, + EVENT_BUFFERING, + EVENT_BUFFER_PROGRESS, + EVENT_DECODER_ERROR, + EVENT_RESOLUTION_CHANGE, + EVENT_VIDEO_RENDERING_START, + EVENT_IS_LIVE_STREAM +}; + +struct Event { + std::string srcFilter; + EventType type; + Media::Any param; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif //OHOS_AV_PIPELINE_EVENT_H diff --git a/av_transport/common/include/pipeline_status.h b/av_transport/common/include/pipeline_status.h new file mode 100644 index 0000000000000000000000000000000000000000..7bbe082ff4e66fff5becdf4c51a7d1de48bc8a88 --- /dev/null +++ b/av_transport/common/include/pipeline_status.h @@ -0,0 +1,71 @@ +/* + * 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_STATUS_H +#define OHOS_AV_PIPELINE_STATUS_H + +#include + +namespace OHOS { +namespace DistributedHardware { +enum struct Status : int32_t { + END_OF_STREAM = 1, ///< Read source when end of stream + OK = 0, ///< The execution result is correct. + NO_ERROR = OK, ///< Same as Status::OK + ERROR_UNKNOWN = -1, ///< An unknown error occurred. + ERROR_PLUGIN_ALREADY_EXISTS = -2, ///< The plugin already exists, usually occurs when in plugin registered. + ERROR_INCOMPATIBLE_VERSION = + -3, ///< Incompatible version, may occur during plugin registration or function calling. + ERROR_NO_MEMORY = -4, ///< The system memory is insufficient. + ERROR_WRONG_STATE = -5, ///< The function is called in an invalid state. + ERROR_UNIMPLEMENTED = -6, ///< This method or interface is not implemented. + ERROR_INVALID_PARAMETER = -7, ///< The plugin does not support this parameter. + ERROR_INVALID_DATA = -8, ///< The value is not in the valid range. + ERROR_MISMATCHED_TYPE = -9, ///< Mismatched data type + ERROR_TIMED_OUT = -10, ///< Operation timeout. + ERROR_UNSUPPORTED_FORMAT = -11, ///< The plugin not support this format/name. + ERROR_NOT_ENOUGH_DATA = -12, ///< Not enough data when read from source. + ERROR_NOT_EXISTED = -13, ///< Source is not existed. + ERROR_AGAIN = -14, ///< Operation is not available right now, should try again later. + ERROR_PERMISSION_DENIED = -15, ///< Permission denied. + ERROR_NULL_POINTER = -16, ///< Null pointer. + ERROR_INVALID_OPERATION = -17, ///< Invalid operation. + ERROR_CLIENT = -18, ///< Http client error + ERROR_SERVER = -19, ///< Http server error + ERROR_DELAY_READY = -20, ///< Delay ready event + ERROR_INVALID_STATE = -21, + ERROR_AUDIO_INTERRUPT = -22, + ERROR_INVALID_BUFFER_SIZE = 0xF001, + ERROR_UNEXPECTED_MEMORY_TYPE = 0xF002, + ERROR_CREATE_BUFFER = 0xF003, + ERROR_NULL_POINT_BUFFER = 0xF004, + ERROR_INVALID_BUFFER_ID = 0xF005, + ERROR_INVALID_BUFFER_STATE = 0xF006, + ERROR_NO_FREE_BUFFER = 0xF007, + ERROR_NO_DIRTY_BUFFER = 0xF008, + ERROR_NO_CONSUMER_LISTENER = 0xF009, + ERROR_NULL_BUFFER_QUEUE = 0xF00A, + ERROR_WAIT_TIMEOUT = 0xF00B, + ERROR_OUT_OF_RANGE = 0xF00C, + ERROR_NULL_SURFACE = 0xF00D, + ERROR_SURFACE_INNER = 0xF00E, + ERROR_NULL_SURFACE_BUFFER = 0xF00F, + + ERROR_IPC_WRITE_INTERFACE_TOKEN = 0xF101, + ERROR_IPC_SEND_REQUEST = 0xF102, +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_AV_PIPELINE_STATUS_H diff --git a/av_transport/framework/BUILD.gn b/av_transport/framework/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..316a49ac1d6d29edcf3a804b46cd11400f0b4476 --- /dev/null +++ b/av_transport/framework/BUILD.gn @@ -0,0 +1,88 @@ +# 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( + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/distributed_av_transport.gni") + +config("av_pipeline_fwk_external_config") { + include_dirs = [ + "${common_path}/include", + "${dh_fwk_sdk_path}/include", + "${interface_path}", + ] +} + +ohos_shared_library("distributed_av_pipeline_fwk") { + 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_fwk_external_config" ] + + include_dirs = [ + "${dh_fwk_utils_path}/include", + "${distributed_av_transport_path}/framework", + "${distributed_av_transport_path}/framework/filter/include", + ] + + sources = [ + "${common_path}/src/av_trans_log.cpp", + "${distributed_av_transport_path}/framework/filter/src/filter.cpp", + "${distributed_av_transport_path}/framework/filter/src/filter_factory.cpp", + "${distributed_av_transport_path}/framework/pipeline/src/pipeline.cpp", + ] + + deps = [ "${dh_fwk_sdk_path}:libdhfwk_sdk" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"av_trans_fwk\"", + "LOG_DOMAIN=0xD004101", + ] + + external_deps = [ + "bounds_checking_function:libsec_shared", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (histreamer_compile_part) { + external_deps += [ "media_foundation:media_foundation" ] + } + + cflags = [ + "-fexceptions", + "-fno-rtti", + "-fPIC", + "-O2", + "-Wall", + "-Wno-c++20-extensions", + ] + cflags_cc = cflags + + part_name = "distributed_hardware_fwk" + subsystem_name = "distributedhardware" +} diff --git a/av_transport/framework/filter/include/filter.h b/av_transport/framework/filter/include/filter.h new file mode 100644 index 0000000000000000000000000000000000000000..1b9cc46768488a11cd69e0fd074beda52b2029f2 --- /dev/null +++ b/av_transport/framework/filter/include/filter.h @@ -0,0 +1,159 @@ +/* + * 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_FILTER_BASE_H +#define OHOS_AV_PIPELINE_FILTER_BASE_H +#include +#include +#include +#include + + +#include "pipeline_status.h" +#include "buffer/avbuffer_queue_producer.h" // media_foudation +#include "meta/meta.h" // media_foudation + +#include "pipeline_event.h" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { + +class Filter; + +enum class FilterType { + FILTERTYPE_SOURCE, + FILTERTYPE_DEMUXER, + FILTERTYPE_AENC, + FILTERTYPE_ADEC, + FILTERTYPE_VENC, + FILTERTYPE_VDEC, + FILTERTYPE_MUXER, + FILTERTYPE_ASINK, + FILTERTYPE_FSINK, + AUDIO_CAPTURE, + VIDEO_CAPTURE, + FILTERTYPE_MAX, +}; + +enum class StreamType { + STREAMTYPE_PACKED, + STREAMTYPE_ENCODED_AUDIO, + STREAMTYPE_ENCODED_VIDEO, + STREAMTYPE_RAW_AUDIO, + STREAMTYPE_RAW_VIDEO, + STREAMTYPE_SUBTITLE, + STREAMTYPE_MAX, +}; + +enum class FilterState { + CREATED, // Filter created + INITIALIZED, // Init called + PREPARING, // Prepare called + READY, // Ready Event reported + RUNNING, // Start called + PAUSED, // Pause called +}; + +enum class FilterCallBackCommand { + NEXT_FILTER_NEEDED, + NEXT_FILTER_REMOVED, + NEXT_FILTER_UPDATE, + FILTER_CALLBACK_COMMAND_MAX, +}; + +class EventReceiver { +public: + virtual ~EventReceiver() = default; + virtual void OnEvent(const Event& event) = 0; +}; + +class FilterCallback { +public: + virtual ~FilterCallback() = default; + virtual void OnCallback(const std::shared_ptr& filter, FilterCallBackCommand cmd, StreamType outType) = 0; +}; + +class FilterLinkCallback { +public: + virtual ~FilterLinkCallback() = default; + virtual void OnLinkedResult(const sptr& queue, + std::shared_ptr& meta) = 0; + virtual void OnUnlinkedResult(std::shared_ptr& meta) = 0; + virtual void OnUpdatedResult(std::shared_ptr& meta) = 0; +}; + +class Filter { +public: + explicit Filter(std::string name, FilterType type); + virtual ~Filter() = default; + virtual void Init(const std::shared_ptr& receiver, const std::shared_ptr& callback); + + virtual Status Prepare(); + + virtual Status Start(); + + virtual Status Pause(); + + virtual Status Resume(); + + virtual Status Stop(); + + virtual Status Flush(); + + virtual Status Release(); + + virtual void SetParameter(const std::shared_ptr& meta); + + virtual void GetParameter(std::shared_ptr& meta); + + virtual Status LinkNext(const std::shared_ptr& nextFilter, StreamType outType); + + virtual Status UpdateNext(const std::shared_ptr& nextFilter, StreamType outType); + + virtual Status UnLinkNext(const std::shared_ptr& nextFilter, StreamType outType); + + FilterType GetFilterType(); + + virtual Status OnLinked(StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback); + + virtual Status OnUpdated(StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback); + + virtual Status OnUnLinked(StreamType inType, const std::shared_ptr& callback); + +protected: + std::string name_; + + std::shared_ptr meta_; + + FilterType filterType_; + + std::vector supportedInStreams_; + std::vector supportedOutStreams_; + + std::map>> nextFiltersMap_; + + std::shared_ptr receiver_; + + std::shared_ptr callback_; + + std::map>> linkCallbackMaps_; +}; +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/av_transport/framework/filter/include/filter_factory.h b/av_transport/framework/filter/include/filter_factory.h new file mode 100644 index 0000000000000000000000000000000000000000..952eae2ebfb98e87408440d3cd31be902111b30f --- /dev/null +++ b/av_transport/framework/filter/include/filter_factory.h @@ -0,0 +1,101 @@ +/* + * 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_FILTER_FACTORY_H +#define OHOS_AV_PIPELINE_FILTER_FACTORY_H + +#include +#include +#include +#include + +#include "filter.h" +#include "cpp_ext/type_cast_ext.h" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +using InstanceGenerator = std::function(const std::string&, const FilterType type)>; + +class FilterFactory { +public: + ~FilterFactory() = default; + + FilterFactory(const FilterFactory&) = delete; + + FilterFactory operator=(const FilterFactory&) = delete; + + static FilterFactory& Instance(); + + template + std::shared_ptr CreateFilter(const std::string& filterName, const FilterType type) + { + auto filter = CreateFilterPriv(filterName, type); + auto typedFilter = ReinterpretPointerCast(filter); + return typedFilter; + } + + template + void RegisterFilter(const std::string& name, const FilterType type, const InstanceGenerator& generator = nullptr) + { + RegisterFilterPriv(name, type, generator); + } + +private: + FilterFactory() = default; + + std::shared_ptr CreateFilterPriv(const std::string& filterName, const FilterType type); + + template + void RegisterFilterPriv(const std::string& name, const FilterType type, const InstanceGenerator& generator) + { + if (generator == nullptr) { + auto result = generators.emplace( + type, [](const std::string &aliaName, const FilterType type) { + return std::make_shared(aliaName, type); + }); + if (!result.second) { + result.first->second = generator; + } + } else { + auto result = generators.emplace(type, generator); + if (!result.second) { + result.first->second = generator; + } + } + } + + std::unordered_map generators; +}; + +template +class AutoRegisterFilter { +public: + explicit AutoRegisterFilter(const std::string& name, const FilterType type) + { + FilterFactory::Instance().RegisterFilter(name, type); + } + + AutoRegisterFilter(const std::string& name, const FilterType type, const InstanceGenerator& generator) + { + FilterFactory::Instance().RegisterFilter(name, type, generator); + } + + ~AutoRegisterFilter() = default; +}; +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_AV_PIPELINE_FILTER_FACTORY_H diff --git a/av_transport/framework/filter/src/filter.cpp b/av_transport/framework/filter/src/filter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dbdc8bfefd53125363d72ca2d64c972352e4f73d --- /dev/null +++ b/av_transport/framework/filter/src/filter.cpp @@ -0,0 +1,151 @@ +/* + * 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 "filter.h" + +#include + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +Filter::Filter(std::string name, FilterType type) + : name_(std::move(name)), filterType_(std::move(type)) +{ +} + +void Filter::Init(const std::shared_ptr& receiver, const std::shared_ptr& callback) +{ + receiver_ = receiver; + callback_ = callback; +} + +Status Filter::Prepare() +{ + for (auto iter : nextFiltersMap_) { + for (auto filter : iter.second) { + filter->Prepare(); + } + } + return Status::OK; +} + +Status Filter::Start() +{ + for (auto iter : nextFiltersMap_) { + for (auto filter : iter.second) { + filter->Start(); + } + } + return Status::OK; +} + +Status Filter::Pause() +{ + for (auto iter : nextFiltersMap_) { + for (auto filter : iter.second) { + filter->Pause(); + } + } + return Status::OK; +} + +Status Filter::Resume() +{ + for (auto iter : nextFiltersMap_) { + for (auto filter : iter.second) { + filter->Resume(); + } + } + return Status::OK; +} + +Status Filter::Stop() +{ + for (auto iter : nextFiltersMap_) { + for (auto filter : iter.second) { + filter->Stop(); + } + } + return Status::OK; +} + +Status Filter::Flush() +{ + for (auto iter : nextFiltersMap_) { + for (auto filter : iter.second) { + filter->Flush(); + } + } + return Status::OK; +} + +Status Filter::Release() +{ + for (auto iter : nextFiltersMap_) { + for (auto filter : iter.second) { + filter->Release(); + } + } + nextFiltersMap_.clear(); + return Status::OK; +} + +void Filter::SetParameter(const std::shared_ptr& meta) +{ + meta_ = meta; +} + +void Filter::GetParameter(std::shared_ptr& meta) +{ + meta = meta_; +} + +Status Filter::LinkNext(const std::shared_ptr&, StreamType) +{ + return Status::OK; +} + +Status Filter::UpdateNext(const std::shared_ptr&, StreamType) +{ + return Status::OK; +} + +Status Filter::UnLinkNext(const std::shared_ptr&, StreamType) +{ + return Status::OK; +} + +FilterType Filter::GetFilterType() +{ + return filterType_; +}; + +Status Filter::OnLinked(StreamType, const std::shared_ptr&, const std::shared_ptr&) +{ + return Status::OK; +}; + +Status Filter::OnUpdated(StreamType, const std::shared_ptr&, const std::shared_ptr&) +{ + return Status::OK; +} + +Status Filter::OnUnLinked(StreamType, const std::shared_ptr&) +{ + return Status::OK; +} +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS diff --git a/av_transport/framework/filter/src/filter_factory.cpp b/av_transport/framework/filter/src/filter_factory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..65b495819d52e294dd0f6418fd3a7a80675c2892 --- /dev/null +++ b/av_transport/framework/filter/src/filter_factory.cpp @@ -0,0 +1,37 @@ +/* + * 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 "filter_factory.h" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +FilterFactory& FilterFactory::Instance() +{ + static FilterFactory instance; + return instance; +} + +std::shared_ptr FilterFactory::CreateFilterPriv(const std::string& filterName, const FilterType type) +{ + auto it = generators.find(type); + if (it != generators.end()) { + return it->second(filterName, type); + } + return nullptr; +} +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS diff --git a/av_transport/framework/pipeline/include/pipeline.h b/av_transport/framework/pipeline/include/pipeline.h new file mode 100644 index 0000000000000000000000000000000000000000..16bbf49abf1632935f739edde5b79ed22807ddc4 --- /dev/null +++ b/av_transport/framework/pipeline/include/pipeline.h @@ -0,0 +1,67 @@ +/* + * 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_H +#define OHOS_AV_PIPELINE_H + +#include +#include +#include + +#include "osal/task/mutex.h" + +#include "pipeline_status.h" +#include "filter.h" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +class FilterCallback; + +class Pipeline : public EventReceiver { +public: + ~Pipeline(); + + void Init(const std::shared_ptr& receiver, const std::shared_ptr& callback); + Status Prepare(); + Status Start(); + Status Pause(); + Status Resume(); + Status Stop(); + Status Flush(); + Status Release(); + + Status AddHeadFilters(std::vector> filters); + Status RemoveHeadFilter(const std::shared_ptr& filter); + Status LinkFilters(const std::shared_ptr& preFilter, + const std::vector>& filters, StreamType type); + Status UpdateFilters(const std::shared_ptr& preFilter, + const std::vector>& filters, StreamType type); + Status UnLinkFilters(const std::shared_ptr& preFilter, + const std::vector>& filters, StreamType type); + + void OnEvent(const Event& event) override; + +private: + FilterState state_ {FilterState::CREATED}; + Media::Mutex mutex_ {}; + std::vector> filters_ {}; + std::shared_ptr eventReceiver_ {nullptr}; + std::shared_ptr filterCallback_ {nullptr}; +}; +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_AV_PIPELINE_H diff --git a/av_transport/framework/pipeline/src/pipeline.cpp b/av_transport/framework/pipeline/src/pipeline.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1245b095c9156e50bb6f57a7c35b1b0911eb29df --- /dev/null +++ b/av_transport/framework/pipeline/src/pipeline.cpp @@ -0,0 +1,223 @@ +/* + * 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 "pipeline/include/pipeline.h" + +#include +#include + +#include "osal/task/autolock.h" +#include "osal/task/jobutils.h" + +#include "av_trans_log.h" + +#undef DH_LOG_TAG +#define DH_LOG_TAG "AVSenderEngine" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +Pipeline::~Pipeline() {} +void Pipeline::Init(const std::shared_ptr& receiver, const std::shared_ptr& callback) +{ + state_ = FilterState::INITIALIZED; + eventReceiver_ = receiver; + filterCallback_ = callback; +} + +Status Pipeline::Prepare() +{ + state_ = FilterState::PREPARING; + Media::SubmitJobOnce([&] { + Media::AutoLock lock(mutex_); + for (auto it = filters_.begin(); it != filters_.end(); ++it) { + auto rtv = (*it)->Prepare(); + TRUE_RETURN_V(rtv != Status::OK, rtv); + } + return Status::OK; + }); + return Status::OK; +} + +Status Pipeline::Start() +{ + state_ = FilterState::RUNNING; + Media::SubmitJobOnce([&] { + Media::AutoLock lock(mutex_); + for (auto it = filters_.begin(); it != filters_.end(); ++it) { + auto rtv = (*it)->Start(); + TRUE_RETURN_V(rtv != Status::OK, rtv); + } + return Status::OK; + }); + return Status::OK; +} + +Status Pipeline::Pause() +{ + if (state_ == FilterState::PAUSED) { + return Status::OK; + } + if (state_ != FilterState::READY && state_ != FilterState::RUNNING) { + return Status::ERROR_UNKNOWN; + } + state_ = FilterState::PAUSED; + Media::SubmitJobOnce([&] { + Media::AutoLock lock(mutex_); + for (auto it = filters_.begin(); it != filters_.end(); ++it) { + if ((*it)->Pause() != Status::OK) { + } + } + return Status::OK; + }); + return Status::OK; +} + +Status Pipeline::Resume() +{ + Media::SubmitJobOnce([&] { + Media::AutoLock lock(mutex_); + for (auto it = filters_.begin(); it != filters_.end(); ++it) { + auto rtv = (*it)->Resume(); + TRUE_RETURN_V(rtv != Status::OK, rtv); + } + state_ = FilterState::RUNNING; + return Status::OK; + }); + return Status::OK; +} + +Status Pipeline::Stop() +{ + state_ = FilterState::INITIALIZED; + Media::SubmitJobOnce([&] { + Media::AutoLock lock(mutex_); + for (auto it = filters_.begin(); it != filters_.end(); ++it) { + if (*it == nullptr) { + AVTRANS_LOGE("Pipeline error: %{public}zu", filters_.size()); + continue; + } + auto rtv = (*it)->Stop(); + TRUE_RETURN_V(rtv != Status::OK, rtv); + } + AVTRANS_LOGI("Stop finished, filter number: %{public}zu", filters_.size()); + return Status::OK; + }); + return Status::OK; +} + +Status Pipeline::Flush() +{ + Media::SubmitJobOnce([&] { + Media::AutoLock lock(mutex_); + for (auto it = filters_.begin(); it != filters_.end(); ++it) { + (*it)->Flush(); + } + return Status::OK; + }); + return Status::OK; +} + +Status Pipeline::Release() +{ + state_ = FilterState::CREATED; + Media::SubmitJobOnce([&] { + Media::AutoLock lock(mutex_); + for (auto it = filters_.begin(); it != filters_.end(); ++it) { + (*it)->Release(); + } + filters_.clear(); + return Status::OK; + }); + return Status::OK; +} + +Status Pipeline::AddHeadFilters(std::vector> filtersIn) +{ + std::vector> filtersToAdd; + for (auto& filterIn : filtersIn) { + bool matched = false; + for (const auto& filter : filters_) { + if (filterIn == filter) { + matched = true; + break; + } + } + if (!matched) { + filtersToAdd.push_back(filterIn); + } + } + if (filtersToAdd.empty()) { + AVTRANS_LOGI("Filter already exists"); + return Status::OK; + } + Media::SubmitJobOnce([&] { + Media::AutoLock lock(mutex_); + this->filters_.insert(this->filters_.end(), filtersToAdd.begin(), filtersToAdd.end()); + }); + return Status::OK; +} + +Status Pipeline::RemoveHeadFilter(const std::shared_ptr& filter) +{ + Media::SubmitJobOnce([&] { + Media::AutoLock lock(mutex_); + auto it = std::find_if(filters_.begin(), filters_.end(), + [&filter](const std::shared_ptr& filterPtr) { return filterPtr == filter; }); + if (it != filters_.end()) { + filters_.erase(it); + } + filter->Release(); + return Status::OK; + }); + return Status::OK; +} + +Status Pipeline::LinkFilters(const std::shared_ptr &preFilter, + const std::vector> &nextFilters, + StreamType type) +{ + for (auto nextFilter : nextFilters) { + preFilter->LinkNext(nextFilter, type); + } + return Status::OK; +} + +Status Pipeline::UpdateFilters(const std::shared_ptr &preFilter, + const std::vector> &nextFilters, + StreamType type) +{ + for (auto nextFilter : nextFilters) { + preFilter->UpdateNext(nextFilter, type); + } + return Status::OK; +} + +Status Pipeline::UnLinkFilters(const std::shared_ptr &preFilter, + const std::vector> &nextFilters, + StreamType type) +{ + for (auto nextFilter : nextFilters) { + preFilter->UnLinkNext(nextFilter, type); + } + return Status::OK; +} + +void Pipeline::OnEvent(const Event& event) +{ +} +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS diff --git a/bundle.json b/bundle.json index 7633d1959adbfbf7020452a093b1d531e2888295..b22ad73b0f55167dcd74507213eaedcbc5be122c 100644 --- a/bundle.json +++ b/bundle.json @@ -63,16 +63,17 @@ }, "build": { "sub_component": [ - "//foundation/distributedhardware/distributed_hardware_fwk/utils:distributedhardwareutils", - "//foundation/distributedhardware/distributed_hardware_fwk/services/distributedhardwarefwkservice:distributedhardwarefwksvr", - "//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/interfaces/kits/napi:hardwaremanager", - "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_sender:distributed_av_sender", + "//foundation/distributedhardware/distributed_hardware_fwk/application:DHardware_UI", "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/av_trans_engine/av_receiver:distributed_av_receiver", + "//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/application:DHardware_UI" + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/framework:distributed_av_pipeline_fwk", + "//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", + "//foundation/distributedhardware/distributed_hardware_fwk/sa_profile:dhfwk_sa_profile", + "//foundation/distributedhardware/distributed_hardware_fwk/services/distributedhardwarefwkservice:distributedhardwarefwksvr", + "//foundation/distributedhardware/distributed_hardware_fwk/utils:distributedhardwareutils" ], "inner_kits": [ {