mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-19 06:42:21 +08:00
支持客户端自定义设置EventPoller对象,提高线程安全性
This commit is contained in:
@@ -32,21 +32,27 @@ using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
MediaPusher::MediaPusher(const MediaSource::Ptr &src) {
|
||||
MediaPusher::MediaPusher(const MediaSource::Ptr &src,
|
||||
const EventPoller::Ptr &poller) {
|
||||
_src = src;
|
||||
_poller = poller;
|
||||
if(!_poller){
|
||||
_poller = EventPollerPool::Instance().getPoller();
|
||||
}
|
||||
}
|
||||
|
||||
MediaPusher::MediaPusher(const string &schema,
|
||||
const string &strVhost,
|
||||
const string &strApp,
|
||||
const string &strStream) {
|
||||
_src = MediaSource::find(schema,strVhost,strApp,strStream);
|
||||
const string &strStream,
|
||||
const EventPoller::Ptr &poller) :
|
||||
MediaPusher(MediaSource::find(schema,strVhost,strApp,strStream),poller){
|
||||
}
|
||||
|
||||
MediaPusher::~MediaPusher() {
|
||||
}
|
||||
void MediaPusher::publish(const string &strUrl) {
|
||||
_parser = PusherBase::createPusher(_src.lock(),strUrl);
|
||||
_parser = PusherBase::createPusher(_poller,_src.lock(),strUrl);
|
||||
_parser->setOnShutdown(_shutdownCB);
|
||||
_parser->setOnPublished(_publishCB);
|
||||
_parser->mINI::operator=(*this);
|
||||
@@ -54,11 +60,7 @@ void MediaPusher::publish(const string &strUrl) {
|
||||
}
|
||||
|
||||
EventPoller::Ptr MediaPusher::getPoller(){
|
||||
auto parser = dynamic_pointer_cast<SocketHelper>(_parser);
|
||||
if(!parser){
|
||||
return nullptr;
|
||||
}
|
||||
return parser->getPoller();
|
||||
return _poller;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -42,15 +42,18 @@ public:
|
||||
MediaPusher(const string &schema,
|
||||
const string &strVhost,
|
||||
const string &strApp,
|
||||
const string &strStream);
|
||||
const string &strStream,
|
||||
const EventPoller::Ptr &poller = nullptr);
|
||||
|
||||
MediaPusher(const MediaSource::Ptr &src);
|
||||
MediaPusher(const MediaSource::Ptr &src,
|
||||
const EventPoller::Ptr &poller = nullptr);
|
||||
|
||||
virtual ~MediaPusher();
|
||||
void publish(const string &strUrl) override;
|
||||
EventPoller::Ptr getPoller();
|
||||
private:
|
||||
std::weak_ptr<MediaSource> _src;
|
||||
EventPoller::Ptr _poller;
|
||||
};
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
@@ -35,7 +35,8 @@ using namespace mediakit::Client;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
PusherBase::Ptr PusherBase::createPusher(const MediaSource::Ptr &src,
|
||||
PusherBase::Ptr PusherBase::createPusher(const EventPoller::Ptr &poller,
|
||||
const MediaSource::Ptr &src,
|
||||
const string & strUrl) {
|
||||
static auto releasePusher = [](PusherBase *ptr){
|
||||
onceToken token(nullptr,[&](){
|
||||
@@ -45,12 +46,12 @@ PusherBase::Ptr PusherBase::createPusher(const MediaSource::Ptr &src,
|
||||
};
|
||||
string prefix = FindField(strUrl.data(), NULL, "://");
|
||||
if (strcasecmp("rtsp",prefix.data()) == 0) {
|
||||
return PusherBase::Ptr(new RtspPusher(dynamic_pointer_cast<RtspMediaSource>(src)),releasePusher);
|
||||
return PusherBase::Ptr(new RtspPusher(poller,dynamic_pointer_cast<RtspMediaSource>(src)),releasePusher);
|
||||
}
|
||||
if (strcasecmp("rtmp",prefix.data()) == 0) {
|
||||
return PusherBase::Ptr(new RtmpPusher(dynamic_pointer_cast<RtmpMediaSource>(src)),releasePusher);
|
||||
return PusherBase::Ptr(new RtmpPusher(poller,dynamic_pointer_cast<RtmpMediaSource>(src)),releasePusher);
|
||||
}
|
||||
return PusherBase::Ptr(new RtspPusher(dynamic_pointer_cast<RtspMediaSource>(src)),releasePusher);
|
||||
return PusherBase::Ptr(new RtspPusher(poller,dynamic_pointer_cast<RtspMediaSource>(src)),releasePusher);
|
||||
}
|
||||
|
||||
PusherBase::PusherBase() {
|
||||
|
||||
@@ -44,7 +44,8 @@ public:
|
||||
typedef std::shared_ptr<PusherBase> Ptr;
|
||||
typedef std::function<void(const SockException &ex)> Event;
|
||||
|
||||
static Ptr createPusher(const MediaSource::Ptr &src,
|
||||
static Ptr createPusher(const EventPoller::Ptr &poller,
|
||||
const MediaSource::Ptr &src,
|
||||
const string &strUrl);
|
||||
|
||||
PusherBase();
|
||||
@@ -78,7 +79,10 @@ template<typename Parent,typename Parser>
|
||||
class PusherImp : public Parent {
|
||||
public:
|
||||
typedef std::shared_ptr<PusherImp> Ptr;
|
||||
PusherImp(){}
|
||||
|
||||
template<typename ...ArgsType>
|
||||
PusherImp(ArgsType &&...args):Parent(std::forward<ArgsType>(args)...){}
|
||||
|
||||
virtual ~PusherImp(){}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user