From 4b48a24ad9176daa8af2e7f50aae6a042b396eb1 Mon Sep 17 00:00:00 2001 From: xzl <771730766@qq.com> Date: Thu, 11 May 2017 11:06:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AArtmp?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E5=99=A8=E8=B7=A8=E7=BA=BF=E7=A8=8B=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/RtmpPlayer.cpp | 11 ++++++++--- src/Rtmp/RtmpPlayer.h | 6 ++++-- src/Rtmp/RtmpSession.cpp | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Rtmp/RtmpPlayer.cpp b/src/Rtmp/RtmpPlayer.cpp index f823f3a7..ac97fdd7 100644 --- a/src/Rtmp/RtmpPlayer.cpp +++ b/src/Rtmp/RtmpPlayer.cpp @@ -37,9 +37,13 @@ void RtmpPlayer::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_pBeatTimer.reset(); @@ -211,6 +215,7 @@ inline void RtmpPlayer::send_pause(bool bPause) { void RtmpPlayer::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); @@ -231,7 +236,7 @@ void RtmpPlayer::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/RtmpPlayer.h b/src/Rtmp/RtmpPlayer.h index c9169e9a..bed5a590 100644 --- a/src/Rtmp/RtmpPlayer.h +++ b/src/Rtmp/RtmpPlayer.h @@ -94,11 +94,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); } @@ -117,8 +118,9 @@ private: bool m_bPaused = false; unordered_map > m_mapOnResultCB; + recursive_mutex m_mtxOnResultCB; deque > m_dqOnStatusCB; - recursive_mutex m_mtxDeque; + recursive_mutex m_mtxOnStatusCB; typedef void (RtmpPlayer::*rtmpCMDHandle)(AMFDecoder &dec); static unordered_map g_mapCmd; diff --git a/src/Rtmp/RtmpSession.cpp b/src/Rtmp/RtmpSession.cpp index eea274c1..b5491f56 100644 --- a/src/Rtmp/RtmpSession.cpp +++ b/src/Rtmp/RtmpSession.cpp @@ -31,6 +31,7 @@ RtmpSession::~RtmpSession() { } void RtmpSession::onError(const SockException& err) { + DebugL << err.what(); if (m_pPublisherSrc) { m_pPublisherSrc.reset(); }