/* * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. * * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). * * Use of this source code is governed by MIT license that can be found in the * LICENSE file in the root of the source tree. All contributing project authors * may be found in the AUTHORS file in the root of the source tree. */ #ifndef SRC_PUSHER_PUSHERBASE_H_ #define SRC_PUSHER_PUSHERBASE_H_ #include #include #include #include #include "Network/Socket.h" #include "Util/mini.h" #include "Common/MediaSource.h" using namespace toolkit; namespace mediakit { class PusherBase : public mINI { public: 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() = default; /** * 开始推流 * @param strUrl 视频url,支持rtsp/rtmp */ virtual void publish(const string &strUrl) = 0; /** * 中断推流 */ virtual void teardown() = 0; /** * 摄像推流结果回调 */ virtual void setOnPublished(const Event &cb) = 0; /** * 设置断开回调 */ virtual void setOnShutdown(const Event &cb) = 0; }; template class PusherImp : public Parent { public: using Ptr = std::shared_ptr; template PusherImp(ArgsType &&...args) : Parent(std::forward(args)...) {} ~PusherImp() override = default; /** * 开始推流 * @param strUrl 推流url,支持rtsp/rtmp */ void publish(const string &strUrl) override { if (_delegate) { _delegate->publish(strUrl); } } /** * 中断推流 */ void teardown() override { if (_delegate) { _delegate->teardown(); } } /** * 摄像推流结果回调 */ void setOnPublished(const PusherBase::Event &cb) override { if (_delegate) { _delegate->setOnPublished(cb); } _on_publish = cb; } /** * 设置断开回调 */ void setOnShutdown(const PusherBase::Event &cb) override { if (_delegate) { _delegate->setOnShutdown(cb); } _on_shutdown = cb; } std::shared_ptr getSockInfo() const { return dynamic_pointer_cast(_delegate); } protected: PusherBase::Event _on_shutdown; PusherBase::Event _on_publish; std::shared_ptr _delegate; }; } /* namespace mediakit */ #endif /* SRC_PUSHER_PUSHERBASE_H_ */