修复webrtc推流互斥锁重入死锁bug (#2713)

simulcast推流时,在onRecvRtp函数中可能触发对totalReaderCount的调用,从而导致死锁。
This commit is contained in:
夏楚 2023-07-29 13:04:24 +08:00 committed by GitHub
parent eaecf9a56c
commit 5464313b41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -61,7 +61,7 @@ bool WebRtcPusher::close(MediaSource &sender) {
int WebRtcPusher::totalReaderCount(MediaSource &sender) { int WebRtcPusher::totalReaderCount(MediaSource &sender) {
auto total_count = _push_src ? _push_src->totalReaderCount() : 0; auto total_count = _push_src ? _push_src->totalReaderCount() : 0;
if (_simulcast) { if (_simulcast) {
std::lock_guard<std::mutex> lock(_mtx); std::lock_guard<std::recursive_mutex> lock(_mtx);
for (auto &src : _push_src_sim) { for (auto &src : _push_src_sim) {
total_count += src.second->totalReaderCount(); total_count += src.second->totalReaderCount();
} }
@ -99,7 +99,7 @@ void WebRtcPusher::onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Pt
} }
} else { } else {
//视频 //视频
std::lock_guard<std::mutex> lock(_mtx); std::lock_guard<std::recursive_mutex> lock(_mtx);
auto &src = _push_src_sim[rid]; auto &src = _push_src_sim[rid];
if (!src) { if (!src) {
const auto& stream = _push_src->getMediaTuple().stream; const auto& stream = _push_src->getMediaTuple().stream;

View File

@ -67,7 +67,7 @@ private:
//推流所有权 //推流所有权
std::shared_ptr<void> _push_src_ownership; std::shared_ptr<void> _push_src_ownership;
//推流的rtsp源,支持simulcast //推流的rtsp源,支持simulcast
std::mutex _mtx; std::recursive_mutex _mtx;
std::unordered_map<std::string/*rid*/, RtspMediaSource::Ptr> _push_src_sim; std::unordered_map<std::string/*rid*/, RtspMediaSource::Ptr> _push_src_sim;
std::unordered_map<std::string/*rid*/, std::shared_ptr<void> > _push_src_sim_ownership; std::unordered_map<std::string/*rid*/, std::shared_ptr<void> > _push_src_sim_ownership;
}; };