diff --git a/ZLToolKit b/ZLToolKit index e589ef61..8e90a8db 160000 --- a/ZLToolKit +++ b/ZLToolKit @@ -1 +1 @@ -Subproject commit e589ef61db16b3d7c43661f1e421b451227af07e +Subproject commit 8e90a8dbefe9060fdb86b9dc8036345aa69faf41 diff --git a/src/Rtmp/RtmpPusher.cpp b/src/Rtmp/RtmpPusher.cpp index 6eadcdb1..627ac9b6 100644 --- a/src/Rtmp/RtmpPusher.cpp +++ b/src/Rtmp/RtmpPusher.cpp @@ -35,26 +35,16 @@ namespace mediakit { static int kSockFlags = SOCKET_DEFAULE_FLAGS | FLAG_MORE; -unordered_map RtmpPusher::g_mapCmd; RtmpPusher::RtmpPusher(const char *strVhost,const char *strApp,const char *strStream) { auto src = dynamic_pointer_cast(MediaSource::find(RTMP_SCHEMA,strVhost,strApp,strStream)); if (!src) { auto strErr = StrPrinter << "media source:" << strVhost << "/" << strApp << "/" << strStream << "not found!" << endl; throw std::runtime_error(strErr); } - init(src); + _pMediaSrc=src; } RtmpPusher::RtmpPusher(const RtmpMediaSource::Ptr &src){ - init(src); -} - -void RtmpPusher::init(const RtmpMediaSource::Ptr &src){ - static onceToken token([]() { - g_mapCmd.emplace("_error",&RtmpPusher::onCmd_result); - g_mapCmd.emplace("_result",&RtmpPusher::onCmd_result); - g_mapCmd.emplace("onStatus",&RtmpPusher::onCmd_onStatus); - }, []() {}); - _pMediaSrc=src; + _pMediaSrc=src; } RtmpPusher::~RtmpPusher() { @@ -266,6 +256,14 @@ void RtmpPusher::onRtmpChunk(RtmpPacket &chunkData) { switch (chunkData.typeId) { case MSG_CMD: case MSG_CMD3: { + typedef void (RtmpPusher::*rtmpCMDHandle)(AMFDecoder &dec); + static unordered_map g_mapCmd; + static onceToken token([]() { + g_mapCmd.emplace("_error",&RtmpPusher::onCmd_result); + g_mapCmd.emplace("_result",&RtmpPusher::onCmd_result); + g_mapCmd.emplace("onStatus",&RtmpPusher::onCmd_onStatus); + }, []() {}); + AMFDecoder dec(chunkData.strBuf, 0); std::string type = dec.load(); auto it = g_mapCmd.find(type); diff --git a/src/Rtmp/RtmpPusher.h b/src/Rtmp/RtmpPusher.h index 795f658b..c844f85f 100644 --- a/src/Rtmp/RtmpPusher.h +++ b/src/Rtmp/RtmpPusher.h @@ -64,7 +64,6 @@ protected: send(buffer); } private: - void init(const RtmpMediaSource::Ptr &src); void onShutdown(const SockException &ex) { _pPublishTimer.reset(); if(_onShutdown){ @@ -99,6 +98,7 @@ private: inline void send_publish(); inline void send_metaData(); +private: string _strApp; string _strStream; string _strTcUrl; @@ -107,13 +107,8 @@ private: recursive_mutex _mtxOnResultCB; deque > _dqOnStatusCB; recursive_mutex _mtxOnStatusCB; - - typedef void (RtmpPusher::*rtmpCMDHandle)(AMFDecoder &dec); - static unordered_map g_mapCmd; - //超时功能实现 std::shared_ptr _pPublishTimer; - //源 std::weak_ptr _pMediaSrc; RtmpMediaSource::RingType::RingReader::Ptr _pRtmpReader;