From 100af97d51c1f254e67d28c1ea6ad889f8e86f77 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sun, 20 Sep 2020 10:43:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=AD=BB=E9=94=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98:#486?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtp/RtpSelector.cpp | 45 ++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/Rtp/RtpSelector.cpp b/src/Rtp/RtpSelector.cpp index 8f74e8ce..283dd98f 100644 --- a/src/Rtp/RtpSelector.cpp +++ b/src/Rtp/RtpSelector.cpp @@ -72,31 +72,40 @@ void RtpSelector::createTimer() { } void RtpSelector::delProcess(const string &stream_id,const RtpProcess *ptr) { - lock_guard lck(_mtx_map); - auto it = _map_rtp_process.find(stream_id); - if (it == _map_rtp_process.end()) { - return; + RtpProcess::Ptr process; + { + lock_guard lck(_mtx_map); + auto it = _map_rtp_process.find(stream_id); + if (it == _map_rtp_process.end()) { + return; + } + if (it->second->getProcess().get() != ptr) { + return; + } + process = it->second->getProcess(); + _map_rtp_process.erase(it); } - if (it->second->getProcess().get() != ptr) { - return; - } - auto process = it->second->getProcess(); - _map_rtp_process.erase(it); process->onDetach(); } void RtpSelector::onManager() { - lock_guard lck(_mtx_map); - for (auto it = _map_rtp_process.begin(); it != _map_rtp_process.end();) { - if (it->second->getProcess()->alive()) { - ++it; - continue; + List clear_list; + { + lock_guard lck(_mtx_map); + for (auto it = _map_rtp_process.begin(); it != _map_rtp_process.end();) { + if (it->second->getProcess()->alive()) { + ++it; + continue; + } + WarnL << "RtpProcess timeout:" << it->first; + clear_list.emplace_back(it->second->getProcess()); + it = _map_rtp_process.erase(it); } - WarnL << "RtpProcess timeout:" << it->first; - auto process = it->second->getProcess(); - it = _map_rtp_process.erase(it); - process->onDetach(); } + + clear_list.for_each([](const RtpProcess::Ptr &process) { + process->onDetach(); + }); } RtpSelector::RtpSelector() {