Commit 6382fcb3 by ziyue

确保on_publish事件回调时线程安全

parent 4e8c56e2
...@@ -244,10 +244,16 @@ void RtpProcess::emitOnPublish() { ...@@ -244,10 +244,16 @@ void RtpProcess::emitOnPublish() {
if (!strong_self) { if (!strong_self) {
return; return;
} }
auto poller = strong_self->_sock ? strong_self->_sock->getPoller() : EventPollerPool::Instance().getPoller();
poller->async([weak_self, err, option]() {
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
if (err.empty()) { if (err.empty()) {
strong_self->_muxer = std::make_shared<MultiMediaSourceMuxer>(strong_self->_media_info._vhost, strong_self->_muxer = std::make_shared<MultiMediaSourceMuxer>(strong_self->_media_info._vhost,
strong_self->_media_info._app, strong_self->_media_info._app,
strong_self->_media_info._streamid, 0.0f, strong_self->_media_info._streamid,0.0f,
option); option);
strong_self->_muxer->setMediaListener(strong_self); strong_self->_muxer->setMediaListener(strong_self);
strong_self->doCachedFunc(); strong_self->doCachedFunc();
...@@ -255,6 +261,7 @@ void RtpProcess::emitOnPublish() { ...@@ -255,6 +261,7 @@ void RtpProcess::emitOnPublish() {
} else { } else {
WarnP(strong_self) << "禁止RTP推流:" << err; WarnP(strong_self) << "禁止RTP推流:" << err;
} }
});
}; };
//触发推流鉴权事件 //触发推流鉴权事件
......
...@@ -161,10 +161,16 @@ void SrtTransportImp::emitOnPublish() { ...@@ -161,10 +161,16 @@ void SrtTransportImp::emitOnPublish() {
if (!strong_self) { if (!strong_self) {
return; return;
} }
strong_self->getPoller()->async([weak_self, err, option](){
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
if (err.empty()) { if (err.empty()) {
strong_self->_muxer = std::make_shared<MultiMediaSourceMuxer>( strong_self->_muxer = std::make_shared<MultiMediaSourceMuxer>(strong_self->_media_info._vhost,
strong_self->_media_info._vhost, strong_self->_media_info._app, strong_self->_media_info._streamid, strong_self->_media_info._app,
0.0f, option); strong_self->_media_info._streamid,0.0f,
option);
strong_self->_muxer->setMediaListener(strong_self); strong_self->_muxer->setMediaListener(strong_self);
strong_self->doCachedFunc(); strong_self->doCachedFunc();
InfoP(strong_self) << "允许 srt 推流"; InfoP(strong_self) << "允许 srt 推流";
...@@ -172,6 +178,7 @@ void SrtTransportImp::emitOnPublish() { ...@@ -172,6 +178,7 @@ void SrtTransportImp::emitOnPublish() {
WarnP(strong_self) << "禁止 srt 推流:" << err; WarnP(strong_self) << "禁止 srt 推流:" << err;
strong_self->onShutdown(SockException(Err_refused, err)); strong_self->onShutdown(SockException(Err_refused, err));
} }
});
}; };
// 触发推流鉴权事件 // 触发推流鉴权事件
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论