mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
修复一个rtmp播放器跨线程操作的bug
This commit is contained in:
parent
60590c1de7
commit
4b48a24ad9
@ -37,9 +37,13 @@ void RtmpPlayer::teardown() {
|
|||||||
m_strApp.clear();
|
m_strApp.clear();
|
||||||
m_strStream.clear();
|
m_strStream.clear();
|
||||||
m_strTcUrl.clear();
|
m_strTcUrl.clear();
|
||||||
m_mapOnResultCB.clear();
|
|
||||||
|
{
|
||||||
|
lock_guard<recursive_mutex> lck(m_mtxOnResultCB);
|
||||||
|
m_mapOnResultCB.clear();
|
||||||
|
}
|
||||||
{
|
{
|
||||||
lock_guard<recursive_mutex> lck(m_mtxDeque);
|
lock_guard<recursive_mutex> lck(m_mtxOnStatusCB);
|
||||||
m_dqOnStatusCB.clear();
|
m_dqOnStatusCB.clear();
|
||||||
}
|
}
|
||||||
m_pBeatTimer.reset();
|
m_pBeatTimer.reset();
|
||||||
@ -211,6 +215,7 @@ inline void RtmpPlayer::send_pause(bool bPause) {
|
|||||||
|
|
||||||
void RtmpPlayer::onCmd_result(AMFDecoder &dec){
|
void RtmpPlayer::onCmd_result(AMFDecoder &dec){
|
||||||
auto iReqId = dec.load<int>();
|
auto iReqId = dec.load<int>();
|
||||||
|
lock_guard<recursive_mutex> lck(m_mtxOnResultCB);
|
||||||
auto it = m_mapOnResultCB.find(iReqId);
|
auto it = m_mapOnResultCB.find(iReqId);
|
||||||
if(it != m_mapOnResultCB.end()){
|
if(it != m_mapOnResultCB.end()){
|
||||||
it->second(dec);
|
it->second(dec);
|
||||||
@ -231,7 +236,7 @@ void RtmpPlayer::onCmd_onStatus(AMFDecoder &dec) {
|
|||||||
throw std::runtime_error("onStatus: 未找到结果对象");
|
throw std::runtime_error("onStatus: 未找到结果对象");
|
||||||
}
|
}
|
||||||
|
|
||||||
lock_guard<recursive_mutex> lck(m_mtxDeque);
|
lock_guard<recursive_mutex> lck(m_mtxOnStatusCB);
|
||||||
if(m_dqOnStatusCB.size()){
|
if(m_dqOnStatusCB.size()){
|
||||||
m_dqOnStatusCB.front()(val);
|
m_dqOnStatusCB.front()(val);
|
||||||
m_dqOnStatusCB.pop_front();
|
m_dqOnStatusCB.pop_front();
|
||||||
|
@ -94,11 +94,12 @@ private:
|
|||||||
|
|
||||||
template<typename FUN>
|
template<typename FUN>
|
||||||
inline void addOnResultCB(const FUN &fun) {
|
inline void addOnResultCB(const FUN &fun) {
|
||||||
|
lock_guard<recursive_mutex> lck(m_mtxOnResultCB);
|
||||||
m_mapOnResultCB.emplace(m_iReqID, fun);
|
m_mapOnResultCB.emplace(m_iReqID, fun);
|
||||||
}
|
}
|
||||||
template<typename FUN>
|
template<typename FUN>
|
||||||
inline void addOnStatusCB(const FUN &fun) {
|
inline void addOnStatusCB(const FUN &fun) {
|
||||||
lock_guard<recursive_mutex> lck(m_mtxDeque);
|
lock_guard<recursive_mutex> lck(m_mtxOnStatusCB);
|
||||||
m_dqOnStatusCB.emplace_back(fun);
|
m_dqOnStatusCB.emplace_back(fun);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,8 +118,9 @@ private:
|
|||||||
bool m_bPaused = false;
|
bool m_bPaused = false;
|
||||||
|
|
||||||
unordered_map<int, function<void(AMFDecoder &dec)> > m_mapOnResultCB;
|
unordered_map<int, function<void(AMFDecoder &dec)> > m_mapOnResultCB;
|
||||||
|
recursive_mutex m_mtxOnResultCB;
|
||||||
deque<function<void(AMFValue &dec)> > m_dqOnStatusCB;
|
deque<function<void(AMFValue &dec)> > m_dqOnStatusCB;
|
||||||
recursive_mutex m_mtxDeque;
|
recursive_mutex m_mtxOnStatusCB;
|
||||||
|
|
||||||
typedef void (RtmpPlayer::*rtmpCMDHandle)(AMFDecoder &dec);
|
typedef void (RtmpPlayer::*rtmpCMDHandle)(AMFDecoder &dec);
|
||||||
static unordered_map<string, rtmpCMDHandle> g_mapCmd;
|
static unordered_map<string, rtmpCMDHandle> g_mapCmd;
|
||||||
|
@ -31,6 +31,7 @@ RtmpSession::~RtmpSession() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RtmpSession::onError(const SockException& err) {
|
void RtmpSession::onError(const SockException& err) {
|
||||||
|
DebugL << err.what();
|
||||||
if (m_pPublisherSrc) {
|
if (m_pPublisherSrc) {
|
||||||
m_pPublisherSrc.reset();
|
m_pPublisherSrc.reset();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user