MediaPusher: 整理代码风格

This commit is contained in:
ziyue 2021-11-09 15:32:48 +08:00
parent b42072405e
commit b96a2291eb
2 changed files with 19 additions and 27 deletions

View File

@ -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);
}

View File

@ -22,18 +22,17 @@ using namespace toolkit;
namespace mediakit {
class PusherBase : public mINI {
public:
typedef std::shared_ptr<PusherBase> Ptr;
typedef std::function<void(const SockException &ex)> Event;
using Ptr = std::shared_ptr<PusherBase>;
using Event = std::function<void(const SockException &ex)>;
static Ptr createPusher(const EventPoller::Ptr &poller,
const MediaSource::Ptr &src,
const string &strUrl);
PusherBase();
virtual ~PusherBase(){}
virtual ~PusherBase() = default;
/**
*
@ -48,13 +47,11 @@ public:
/**
*
* @param onPublished
*/
virtual void setOnPublished(const Event &cb) = 0;
/**
*
* @param onShutdown
*/
virtual void setOnShutdown(const Event &cb) = 0;
};
@ -62,12 +59,11 @@ public:
template<typename Parent, typename Delegate>
class PusherImp : public Parent {
public:
typedef std::shared_ptr<PusherImp> Ptr;
using Ptr = std::shared_ptr<PusherImp>;
template<typename ...ArgsType>
PusherImp(ArgsType &&...args) : Parent(std::forward<ArgsType>(args)...) {}
virtual ~PusherImp(){}
~PusherImp() override = default;
/**
*
@ -90,24 +86,22 @@ public:
/**
*
* @param onPublished
*/
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 {
if (_delegate) {
_delegate->setOnShutdown(cb);
}
_shutdownCB = cb;
_on_shutdown = cb;
}
std::shared_ptr<SockInfo> getSockInfo() const {
@ -115,12 +109,10 @@ public:
}
protected:
PusherBase::Event _shutdownCB;
PusherBase::Event _publishCB;
PusherBase::Event _on_shutdown;
PusherBase::Event _on_publish;
std::shared_ptr<Delegate> _delegate;
};
} /* namespace mediakit */
#endif /* SRC_PUSHER_PUSHERBASE_H_ */