mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 03:10:04 +08:00
MediaPusher: 整理代码风格
This commit is contained in:
parent
b42072405e
commit
b96a2291eb
@ -44,8 +44,8 @@ void MediaPusher::publish(const string &url) {
|
|||||||
_delegate = PusherBase::createPusher(_poller, _src.lock(), url);
|
_delegate = PusherBase::createPusher(_poller, _src.lock(), url);
|
||||||
assert(_delegate);
|
assert(_delegate);
|
||||||
setOnCreateSocket_l(_delegate, _on_create_socket);
|
setOnCreateSocket_l(_delegate, _on_create_socket);
|
||||||
_delegate->setOnShutdown(_shutdownCB);
|
_delegate->setOnShutdown(_on_shutdown);
|
||||||
_delegate->setOnPublished(_publishCB);
|
_delegate->setOnPublished(_on_publish);
|
||||||
_delegate->mINI::operator=(*this);
|
_delegate->mINI::operator=(*this);
|
||||||
_delegate->publish(url);
|
_delegate->publish(url);
|
||||||
}
|
}
|
||||||
|
@ -22,18 +22,17 @@ using namespace toolkit;
|
|||||||
|
|
||||||
namespace mediakit {
|
namespace mediakit {
|
||||||
|
|
||||||
|
class PusherBase : public mINI {
|
||||||
class PusherBase : public mINI{
|
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<PusherBase> Ptr;
|
using Ptr = std::shared_ptr<PusherBase>;
|
||||||
typedef std::function<void(const SockException &ex)> Event;
|
using Event = std::function<void(const SockException &ex)>;
|
||||||
|
|
||||||
static Ptr createPusher(const EventPoller::Ptr &poller,
|
static Ptr createPusher(const EventPoller::Ptr &poller,
|
||||||
const MediaSource::Ptr &src,
|
const MediaSource::Ptr &src,
|
||||||
const string &strUrl);
|
const string &strUrl);
|
||||||
|
|
||||||
PusherBase();
|
PusherBase();
|
||||||
virtual ~PusherBase(){}
|
virtual ~PusherBase() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始推流
|
* 开始推流
|
||||||
@ -48,32 +47,29 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 摄像推流结果回调
|
* 摄像推流结果回调
|
||||||
* @param onPublished
|
|
||||||
*/
|
*/
|
||||||
virtual void setOnPublished(const Event &cb) = 0;
|
virtual void setOnPublished(const Event &cb) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置断开回调
|
* 设置断开回调
|
||||||
* @param onShutdown
|
|
||||||
*/
|
*/
|
||||||
virtual void setOnShutdown(const Event &cb) = 0;
|
virtual void setOnShutdown(const Event &cb) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Parent,typename Delegate>
|
template<typename Parent, typename Delegate>
|
||||||
class PusherImp : public Parent {
|
class PusherImp : public Parent {
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<PusherImp> Ptr;
|
using Ptr = std::shared_ptr<PusherImp>;
|
||||||
|
|
||||||
template<typename ...ArgsType>
|
template<typename ...ArgsType>
|
||||||
PusherImp(ArgsType &&...args):Parent(std::forward<ArgsType>(args)...){}
|
PusherImp(ArgsType &&...args) : Parent(std::forward<ArgsType>(args)...) {}
|
||||||
|
~PusherImp() override = default;
|
||||||
virtual ~PusherImp(){}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始推流
|
* 开始推流
|
||||||
* @param strUrl 推流url,支持rtsp/rtmp
|
* @param strUrl 推流url,支持rtsp/rtmp
|
||||||
*/
|
*/
|
||||||
void publish(const string &strUrl) override{
|
void publish(const string &strUrl) override {
|
||||||
if (_delegate) {
|
if (_delegate) {
|
||||||
_delegate->publish(strUrl);
|
_delegate->publish(strUrl);
|
||||||
}
|
}
|
||||||
@ -82,7 +78,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* 中断推流
|
* 中断推流
|
||||||
*/
|
*/
|
||||||
void teardown() override{
|
void teardown() override {
|
||||||
if (_delegate) {
|
if (_delegate) {
|
||||||
_delegate->teardown();
|
_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) {
|
if (_delegate) {
|
||||||
_delegate->setOnPublished(cb);
|
_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) {
|
if (_delegate) {
|
||||||
_delegate->setOnShutdown(cb);
|
_delegate->setOnShutdown(cb);
|
||||||
}
|
}
|
||||||
_shutdownCB = cb;
|
_on_shutdown = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<SockInfo> getSockInfo() const{
|
std::shared_ptr<SockInfo> getSockInfo() const {
|
||||||
return dynamic_pointer_cast<SockInfo>(_delegate);
|
return dynamic_pointer_cast<SockInfo>(_delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PusherBase::Event _shutdownCB;
|
PusherBase::Event _on_shutdown;
|
||||||
PusherBase::Event _publishCB;
|
PusherBase::Event _on_publish;
|
||||||
std::shared_ptr<Delegate> _delegate;
|
std::shared_ptr<Delegate> _delegate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} /* namespace mediakit */
|
} /* namespace mediakit */
|
||||||
|
|
||||||
#endif /* SRC_PUSHER_PUSHERBASE_H_ */
|
#endif /* SRC_PUSHER_PUSHERBASE_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user