From 60d96f4f3b153653e85f62b0d9bde22b6081e2bb Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Tue, 1 Nov 2022 16:52:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96FrameDispatcher=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/Frame.cpp | 23 ++++++++--------------- src/Extension/Frame.h | 7 ++++--- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Extension/Frame.cpp b/src/Extension/Frame.cpp index dda876ca..8ff0bdf9 100644 --- a/src/Extension/Frame.cpp +++ b/src/Extension/Frame.cpp @@ -215,34 +215,27 @@ void FrameMerger::flush() { */ class FrameWriterInterfaceHelper : public FrameWriterInterface { public: - typedef std::shared_ptr Ptr; - typedef std::function onWriteFrame; + using Ptr = std::shared_ptr; + using onWriteFrame = std::function; /** * inputFrame后触发onWriteFrame回调 */ - FrameWriterInterfaceHelper(const onWriteFrame& cb){ - _writeCallback = cb; - } + FrameWriterInterfaceHelper(onWriteFrame cb) { _callback = std::move(cb); } - virtual ~FrameWriterInterfaceHelper(){} + virtual ~FrameWriterInterfaceHelper() = default; /** * 写入帧数据 */ - bool inputFrame(const Frame::Ptr &frame) override { - return _writeCallback(frame); - } + bool inputFrame(const Frame::Ptr &frame) override { return _callback(frame); } private: - onWriteFrame _writeCallback; + onWriteFrame _callback; }; -FrameWriterInterface* FrameDispatcher::addDelegate(const std::function &cb) { - auto delegate = std::make_shared(cb); - std::lock_guard lck(_mtx); - _delegates.emplace(delegate.get(), delegate); - return delegate.get(); +FrameWriterInterface* FrameDispatcher::addDelegate(std::function cb) { + return addDelegate(std::make_shared(std::move(cb))); } }//namespace mediakit diff --git a/src/Extension/Frame.h b/src/Extension/Frame.h index aa096681..182c70eb 100644 --- a/src/Extension/Frame.h +++ b/src/Extension/Frame.h @@ -290,12 +290,13 @@ public: /** * 添加代理 */ - void addDelegate(const FrameWriterInterface::Ptr &delegate) { + FrameWriterInterface* addDelegate(FrameWriterInterface::Ptr delegate) { std::lock_guard lck(_mtx); - _delegates.emplace(delegate.get(), delegate); + return _delegates.emplace(delegate.get(), std::move(delegate)).first->second.get(); } - FrameWriterInterface* addDelegate(const std::function &cb); + FrameWriterInterface* addDelegate(std::function cb); + /** * 删除代理 */