From 5464313b41c86f854f9bdbd1a3a88db750bc1984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Sat, 29 Jul 2023 13:04:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwebrtc=E6=8E=A8=E6=B5=81?= =?UTF-8?q?=E4=BA=92=E6=96=A5=E9=94=81=E9=87=8D=E5=85=A5=E6=AD=BB=E9=94=81?= =?UTF-8?q?bug=20(#2713)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit simulcast推流时,在onRecvRtp函数中可能触发对totalReaderCount的调用,从而导致死锁。 --- webrtc/WebRtcPusher.cpp | 4 ++-- webrtc/WebRtcPusher.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/webrtc/WebRtcPusher.cpp b/webrtc/WebRtcPusher.cpp index 11fb1b30..0a62c0f3 100644 --- a/webrtc/WebRtcPusher.cpp +++ b/webrtc/WebRtcPusher.cpp @@ -61,7 +61,7 @@ bool WebRtcPusher::close(MediaSource &sender) { int WebRtcPusher::totalReaderCount(MediaSource &sender) { auto total_count = _push_src ? _push_src->totalReaderCount() : 0; if (_simulcast) { - std::lock_guard lock(_mtx); + std::lock_guard lock(_mtx); for (auto &src : _push_src_sim) { total_count += src.second->totalReaderCount(); } @@ -99,7 +99,7 @@ void WebRtcPusher::onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Pt } } else { //视频 - std::lock_guard lock(_mtx); + std::lock_guard lock(_mtx); auto &src = _push_src_sim[rid]; if (!src) { const auto& stream = _push_src->getMediaTuple().stream; diff --git a/webrtc/WebRtcPusher.h b/webrtc/WebRtcPusher.h index 4c332a35..8d309395 100644 --- a/webrtc/WebRtcPusher.h +++ b/webrtc/WebRtcPusher.h @@ -67,7 +67,7 @@ private: //推流所有权 std::shared_ptr _push_src_ownership; //推流的rtsp源,支持simulcast - std::mutex _mtx; + std::recursive_mutex _mtx; std::unordered_map _push_src_sim; std::unordered_map > _push_src_sim_ownership; };