From fcd0db909b9e79e0da112adfe872ffa2815d2955 Mon Sep 17 00:00:00 2001 From: byndyx Date: Tue, 10 Dec 2024 15:10:18 +0800 Subject: [PATCH] encoder filter Signed-off-by: byndyx --- .../av_transport_encoder_filter.cpp | 221 ++++++++++++++++++ .../av_transport_encoder_filter.h | 74 ++++++ 2 files changed, 295 insertions(+) create mode 100644 av_transport/av_trans_engine/filters/av_transport_encoder/av_transport_encoder_filter.cpp create mode 100644 av_transport/av_trans_engine/filters/av_transport_encoder/av_transport_encoder_filter.h diff --git a/av_transport/av_trans_engine/filters/av_transport_encoder/av_transport_encoder_filter.cpp b/av_transport/av_trans_engine/filters/av_transport_encoder/av_transport_encoder_filter.cpp new file mode 100644 index 00000000..63357130 --- /dev/null +++ b/av_transport/av_trans_engine/filters/av_transport_encoder/av_transport_encoder_filter.cpp @@ -0,0 +1,221 @@ +/* + * 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 "av_transport_encoder_filter.h" + +#include "av_trans_log.h" +#include "filter_factory.h" + +#undef DH_LOG_TAG +#define DH_LOG_TAG "AudioEncoderFilter" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +static AutoRegisterFilterg_registerAudioEncoderFilter("builtin.recorder.audioencoderfilter", + FilterType::FILTERTYPE_AENC, + [](const std::string& name, const FilterType type) { + return std::make_shared(name, FilterType::FILTERTYPE_AENC); + }); + +class AudioEncoderFilterCallback : public FilterLinkCallback { +public: + explicit AudioEncoderFilterCallback(std::shared_ptr filter) + : inputFilter_(std::move(filter)) {} + ~AudioEncoderFilterCallback() = default; + + void OnLinkedResult(const std::sptr& queue, + const std::shared_ptr& meta) override + { + if (auto filter = inputFilter_.lock()) { + filter->OnLinkedResult(queue, meta); + } else { + AVTRANS_LOGI(Invalid inputfilter); + } + } + void OnUnLinkedResult(const std::shared_ptr& meta) override + { + if (auto filter = inputFilter_.lock()) { + filter->OnUnLinkedResult(queue, meta); + } else { + AVTRANS_LOGI(Invalid inputfilter); + } + } + void OnUpdatedResult(const std::shared_ptr& meta) override + { + if (auto filter = inputFilter_.lock()) { + filter->OnUpdatedResult(queue, meta); + } else { + AVTRANS_LOGI(Invalid inputfilter); + } + } +private: + std::weak_ptr inputFilter_ {}; +}; + +AudioEncoderFilter(const std::string& name, FilterType type, bool asyncMode = false) +{ +} + +~AudioEncoderFilter() +{ + std::lock_guard lock(nextFiltersMutex_); + nextFiltersMap_.clear(); +} + +void Init(const std::shared_ptr& receiver, const std::shared_ptr& callback) +{ + receiver_ = receiver; + callback_ = callback; +} + +Status DoInitAfterLink() +{ + return Status::OK; +} + +Status DoPrepare() +{ + TRUE_RETURN_V_MSG_E(callback_ == nullptr, Status::ERROR_NULL_POINTER, "callback is nullptr"); + callback_->OnCallback(shared_from_this(), FilterCallBackCommand::NEXT_FILTER_NEEDED, + StreamType::STREAMTYPE_RAW_AUDIO); + return Status::OK; +} + +Status DoStart() +{ + return Status::OK; +} + +Status DoPause() +{ + return Status::OK; +} + +Status DoPauseDragging() +{ + return Status::OK; +} + +Status DoResume() +{ + return Status::OK; +} + +Status DoResumeDragging() +{ + return Status::OK; +} + +Status DoStop() +{ + return Status::OK; +} + +Status DoFlush() +{ + return Status::OK; +} + +Status DoRelease() +{ + return Status::OK; +} + + +Status DoProcessInputBuffer(int recvArg, bool dropFrame) +{ + return Status::OK; +} + +Status DoProcessOutputBuffer(int recvArg, bool dropFrame, bool byIdx, uint32_t idx, int64_t renderTime) +{ + return Status::OK; +} + +void SetParameter(const std::shared_ptr& meta) +{ + +} + +void GetParameter(std::shared_ptr& meta) +{ + +} + +Status LinkNext(const std::shared_ptr& nextFilter, StreamType outType) +{ + TRUE_RETURN_V_MSG_E(nextFilter == nullptr, Status::ERROR_NULL_POINTER, "input nextFilter is nullptr"); + nextFilter_ = nextFilter; + { + std::lock_guard lock(nextFiltersMutex_); + nextFiltersMap_[outType].push_back(nextFilter); + } + auto filterLinkCallback = std::make_shared(shared_from_this()); + auto ret = nextFilter->OnLinked(outType, configureParam_, filterLinkCallback); + TRUE_RETURN_V_MSG_E(ret != Status::OK, ret, "Onlinked failed: %{public}d", ret); + return Status::OK; +} + +Status UpdateNext(const std::shared_ptr& nextFilter, StreamType outType) +{ + return Status::OK; +} + +Status UnLinkNext(const std::shared_ptr& nextFilter, StreamType outType) +{ + return Status::OK; +} + + +Status OnLinked(StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback) +{ + TRUE_RETURN_V_MSG_E(callback == nullptr, Status::ERROR_NULL_POINTER, "input callback is nullptr"); + onLinkedResultCallback_ = callback; + return Status::OK; +} + +Status OnUpdated(StreamType inType, const std::shared_ptr& meta, + const std::shared_ptr& callback) +{ + return Status::OK; +} + +Status OnUnLinked(StreamType inType, const std::shared_ptr& callback) +{ + return Status::OK; +} + +void OnLinkedResult(const sptr& queue, std::shared_ptr& meta) +{ + // 从入参保存outputfilter的queue的producer和meta + // 获取encoderProducer和encoderMeta + TRUE_RETURN(onLinkedResultCallback_ == nullptr, "onLinkedResultCallback_ is nullptr"); + onLinkedResultCallback_->OnLinkedResult(encoderProducer, encoderMeta); +} + +void OnUnLinkedResult(std::shared_ptr& meta) +{ + return Status::OK; +} + +void OnUpdatedResult(std::shared_ptr& meta) +{ + return Status::OK; +} +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/av_transport/av_trans_engine/filters/av_transport_encoder/av_transport_encoder_filter.h b/av_transport/av_trans_engine/filters/av_transport_encoder/av_transport_encoder_filter.h new file mode 100644 index 00000000..0c240b4e --- /dev/null +++ b/av_transport/av_trans_engine/filters/av_transport_encoder/av_transport_encoder_filter.h @@ -0,0 +1,74 @@ +/* + * 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 MEDIA_PIPELINE_ENCODER_FILTER_H +#define MEDIA_PIPELINE_ENCODER_FILTER_H + +#include +#include +#include +#include + +#include "pipeline_status.h" +#include "filter.h" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +class AudioEncoderFilter : public Filter, public std::enable_shared_from_this { +public: + AudioEncoderFilter(const std::string& name, FilterType type, bool asyncMode = false); + ~AudioEncoderFilter() override; + 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; + + 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 filterLinkCallback_ {nullptr}; + std::mutex nextFiltersMutex_; +}; +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file -- Gitee