From fad8dd74e77d2848a7c8cc738a5a07262cc72e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Sat, 8 Jul 2023 21:33:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwebrtc=E5=BC=80=E5=90=AFsimul?= =?UTF-8?q?cast=E6=8E=A8=E6=B5=81=E6=97=B6=EF=BC=8C=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E8=A7=82=E7=9C=8B=E4=BA=BA=E6=95=B0=E7=BA=BF=E7=A8=8B=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E7=9B=B8=E5=85=B3bug=20(#2640)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/WebRtcPusher.cpp | 12 ++++++++---- webrtc/WebRtcPusher.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/webrtc/WebRtcPusher.cpp b/webrtc/WebRtcPusher.cpp index e8e46a40..5d6a68d2 100644 --- a/webrtc/WebRtcPusher.cpp +++ b/webrtc/WebRtcPusher.cpp @@ -59,11 +59,14 @@ bool WebRtcPusher::close(MediaSource &sender) { } int WebRtcPusher::totalReaderCount(MediaSource &sender) { - auto total_count = 0; - for (auto &src : _push_src_sim) { - total_count += src.second->totalReaderCount(); + auto total_count = _push_src ? _push_src->totalReaderCount() : 0; + if (_simulcast) { + std::lock_guard lock(_mtx); + for (auto &src : _push_src_sim) { + total_count += src.second->totalReaderCount(); + } } - return total_count + _push_src->totalReaderCount(); + return total_count; } MediaOriginType WebRtcPusher::getOriginType(MediaSource &sender) const { @@ -96,6 +99,7 @@ void WebRtcPusher::onRecvRtp(MediaTrack &track, const string &rid, RtpPacket::Pt } } else { //视频 + 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 32c47055..b35f9e98 100644 --- a/webrtc/WebRtcPusher.h +++ b/webrtc/WebRtcPusher.h @@ -65,6 +65,7 @@ private: //推流所有权 std::shared_ptr _push_src_ownership; //推流的rtsp源,支持simulcast + std::mutex _mtx; std::unordered_map _push_src_sim; std::unordered_map > _push_src_sim_ownership; };