From fd9df3f5cf63cb82f94f9afe7b18f46065abcccd Mon Sep 17 00:00:00 2001 From: xzl <771730766@qq.com> Date: Fri, 12 May 2017 13:59:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E7=BA=BF=E7=A8=8B=E7=AB=9E?= =?UTF-8?q?=E4=BA=89=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/RtmpPusher.cpp | 10 +++++++--- src/Rtmp/RtmpPusher.h | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Rtmp/RtmpPusher.cpp b/src/Rtmp/RtmpPusher.cpp index f13ed160..82076fe8 100644 --- a/src/Rtmp/RtmpPusher.cpp +++ b/src/Rtmp/RtmpPusher.cpp @@ -41,9 +41,12 @@ void RtmpPusher::teardown() { m_strApp.clear(); m_strStream.clear(); m_strTcUrl.clear(); - m_mapOnResultCB.clear(); + { + lock_guard lck(m_mtxOnResultCB); + m_mapOnResultCB.clear(); + } { - lock_guard lck(m_mtxDeque); + lock_guard lck(m_mtxOnStatusCB); m_dqOnStatusCB.clear(); } m_pPlayTimer.reset(); @@ -198,6 +201,7 @@ inline void RtmpPusher::send_metaData(){ } void RtmpPusher::onCmd_result(AMFDecoder &dec){ auto iReqId = dec.load(); + lock_guard lck(m_mtxOnResultCB); auto it = m_mapOnResultCB.find(iReqId); if(it != m_mapOnResultCB.end()){ it->second(dec); @@ -218,7 +222,7 @@ void RtmpPusher::onCmd_onStatus(AMFDecoder &dec) { throw std::runtime_error("onStatus: 未找到结果对象"); } - lock_guard lck(m_mtxDeque); + lock_guard lck(m_mtxOnStatusCB); if(m_dqOnStatusCB.size()){ m_dqOnStatusCB.front()(val); m_dqOnStatusCB.pop_front(); diff --git a/src/Rtmp/RtmpPusher.h b/src/Rtmp/RtmpPusher.h index 1ef501ad..cb5dcf66 100644 --- a/src/Rtmp/RtmpPusher.h +++ b/src/Rtmp/RtmpPusher.h @@ -53,11 +53,12 @@ private: template inline void addOnResultCB(const FUN &fun) { + lock_guard lck(m_mtxOnResultCB); m_mapOnResultCB.emplace(m_iReqID, fun); } template inline void addOnStatusCB(const FUN &fun) { - lock_guard lck(m_mtxDeque); + lock_guard lck(m_mtxOnStatusCB); m_dqOnStatusCB.emplace_back(fun); } @@ -75,8 +76,9 @@ private: string m_strTcUrl; unordered_map > m_mapOnResultCB; + recursive_mutex m_mtxOnResultCB; deque > m_dqOnStatusCB; - recursive_mutex m_mtxDeque; + recursive_mutex m_mtxOnStatusCB; typedef void (RtmpPusher::*rtmpCMDHandle)(AMFDecoder &dec); static unordered_map g_mapCmd;