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

This commit is contained in:
ziyue 2022-08-11 18:36:17 +08:00
parent 4e8c56e2be
commit 6382fcb3be
2 changed files with 36 additions and 22 deletions

View File

@ -244,17 +244,24 @@ void RtpProcess::emitOnPublish() {
if (!strong_self) {
return;
}
if (err.empty()) {
strong_self->_muxer = std::make_shared<MultiMediaSourceMuxer>(strong_self->_media_info._vhost,
strong_self->_media_info._app,
strong_self->_media_info._streamid, 0.0f,
option);
strong_self->_muxer->setMediaListener(strong_self);
strong_self->doCachedFunc();
InfoP(strong_self) << "允许RTP推流";
} else {
WarnP(strong_self) << "禁止RTP推流:" << err;
}
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()) {
strong_self->_muxer = std::make_shared<MultiMediaSourceMuxer>(strong_self->_media_info._vhost,
strong_self->_media_info._app,
strong_self->_media_info._streamid,0.0f,
option);
strong_self->_muxer->setMediaListener(strong_self);
strong_self->doCachedFunc();
InfoP(strong_self) << "允许RTP推流";
} else {
WarnP(strong_self) << "禁止RTP推流:" << err;
}
});
};
//触发推流鉴权事件

View File

@ -161,17 +161,24 @@ void SrtTransportImp::emitOnPublish() {
if (!strong_self) {
return;
}
if (err.empty()) {
strong_self->_muxer = std::make_shared<MultiMediaSourceMuxer>(
strong_self->_media_info._vhost, strong_self->_media_info._app, strong_self->_media_info._streamid,
0.0f, option);
strong_self->_muxer->setMediaListener(strong_self);
strong_self->doCachedFunc();
InfoP(strong_self) << "允许 srt 推流";
} else {
WarnP(strong_self) << "禁止 srt 推流:" << err;
strong_self->onShutdown(SockException(Err_refused, err));
}
strong_self->getPoller()->async([weak_self, err, option](){
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
if (err.empty()) {
strong_self->_muxer = std::make_shared<MultiMediaSourceMuxer>(strong_self->_media_info._vhost,
strong_self->_media_info._app,
strong_self->_media_info._streamid,0.0f,
option);
strong_self->_muxer->setMediaListener(strong_self);
strong_self->doCachedFunc();
InfoP(strong_self) << "允许 srt 推流";
} else {
WarnP(strong_self) << "禁止 srt 推流:" << err;
strong_self->onShutdown(SockException(Err_refused, err));
}
});
};
// 触发推流鉴权事件