修复MediaSource::close线程安全问题

主动或无人观看关闭流可能会由于线程安全问题导致崩溃
This commit is contained in:
xia-chu
2025-09-09 21:59:43 +08:00
parent c89caf560a
commit 5686027fc2
9 changed files with 23 additions and 49 deletions

View File

@@ -42,19 +42,10 @@ WebRtcPusher::WebRtcPusher(const EventPoller::Ptr &poller,
}
bool WebRtcPusher::close(MediaSource &sender) {
// 此回调在其他线程触发 [AUTO-TRANSLATED:c98e7686]
// This callback is triggered in another thread
string err = StrPrinter << "close media: " << sender.getUrl();
weak_ptr<WebRtcPusher> weak_self = static_pointer_cast<WebRtcPusher>(shared_from_this());
getPoller()->async([weak_self, err]() {
auto strong_self = weak_self.lock();
if (strong_self) {
strong_self->onShutdown(SockException(Err_shutdown, err));
// 主动关闭推流,那么不延时注销 [AUTO-TRANSLATED:ee7cc580]
// Actively close the stream, then do not delay the logout
strong_self->_push_src = nullptr;
}
});
onShutdown(SockException(Err_shutdown, "close media: " + sender.getUrl()));
// 主动关闭推流,那么不延时注销 [AUTO-TRANSLATED:ee7cc580]
// Actively close the stream, then do not delay the logout
_push_src = nullptr;
return true;
}