From b96a2291ebd6e712c08619a4ffcd0ecb2fb22eb6 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Tue, 9 Nov 2021 15:32:48 +0800 Subject: [PATCH] =?UTF-8?q?MediaPusher:=20=E6=95=B4=E7=90=86=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Pusher/MediaPusher.cpp | 4 ++-- src/Pusher/PusherBase.h | 42 +++++++++++++++----------------------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/Pusher/MediaPusher.cpp b/src/Pusher/MediaPusher.cpp index d7055bc7..f6ee013f 100644 --- a/src/Pusher/MediaPusher.cpp +++ b/src/Pusher/MediaPusher.cpp @@ -44,8 +44,8 @@ void MediaPusher::publish(const string &url) { _delegate = PusherBase::createPusher(_poller, _src.lock(), url); assert(_delegate); setOnCreateSocket_l(_delegate, _on_create_socket); - _delegate->setOnShutdown(_shutdownCB); - _delegate->setOnPublished(_publishCB); + _delegate->setOnShutdown(_on_shutdown); + _delegate->setOnPublished(_on_publish); _delegate->mINI::operator=(*this); _delegate->publish(url); } diff --git a/src/Pusher/PusherBase.h b/src/Pusher/PusherBase.h index f1ae0d9f..3538118f 100644 --- a/src/Pusher/PusherBase.h +++ b/src/Pusher/PusherBase.h @@ -22,18 +22,17 @@ using namespace toolkit; namespace mediakit { - -class PusherBase : public mINI{ +class PusherBase : public mINI { public: - typedef std::shared_ptr Ptr; - typedef std::function Event; + using Ptr = std::shared_ptr; + using Event = std::function; static Ptr createPusher(const EventPoller::Ptr &poller, const MediaSource::Ptr &src, const string &strUrl); PusherBase(); - virtual ~PusherBase(){} + virtual ~PusherBase() = default; /** * 开始推流 @@ -48,32 +47,29 @@ public: /** * 摄像推流结果回调 - * @param onPublished */ virtual void setOnPublished(const Event &cb) = 0; /** * 设置断开回调 - * @param onShutdown */ virtual void setOnShutdown(const Event &cb) = 0; }; -template +template class PusherImp : public Parent { public: - typedef std::shared_ptr Ptr; + using Ptr = std::shared_ptr; template - PusherImp(ArgsType &&...args):Parent(std::forward(args)...){} - - virtual ~PusherImp(){} + PusherImp(ArgsType &&...args) : Parent(std::forward(args)...) {} + ~PusherImp() override = default; /** * 开始推流 * @param strUrl 推流url,支持rtsp/rtmp */ - void publish(const string &strUrl) override{ + void publish(const string &strUrl) override { if (_delegate) { _delegate->publish(strUrl); } @@ -82,7 +78,7 @@ public: /** * 中断推流 */ - void teardown() override{ + void teardown() override { if (_delegate) { _delegate->teardown(); } @@ -90,37 +86,33 @@ public: /** * 摄像推流结果回调 - * @param onPublished */ - void setOnPublished(const PusherBase::Event &cb) override{ + void setOnPublished(const PusherBase::Event &cb) override { if (_delegate) { _delegate->setOnPublished(cb); } - _publishCB = cb; + _on_publish = cb; } /** * 设置断开回调 - * @param onShutdown */ - void setOnShutdown(const PusherBase::Event &cb) override{ + void setOnShutdown(const PusherBase::Event &cb) override { if (_delegate) { _delegate->setOnShutdown(cb); } - _shutdownCB = cb; + _on_shutdown = cb; } - std::shared_ptr getSockInfo() const{ + std::shared_ptr getSockInfo() const { return dynamic_pointer_cast(_delegate); } protected: - PusherBase::Event _shutdownCB; - PusherBase::Event _publishCB; + PusherBase::Event _on_shutdown; + PusherBase::Event _on_publish; std::shared_ptr _delegate; }; - } /* namespace mediakit */ - #endif /* SRC_PUSHER_PUSHERBASE_H_ */