diff --git a/ZLToolKit b/ZLToolKit index eefe3ce1..e589ef61 160000 --- a/ZLToolKit +++ b/ZLToolKit @@ -1 +1 @@ -Subproject commit eefe3ce118c0720a3a9c1e5770411b0b80275593 +Subproject commit e589ef61db16b3d7c43661f1e421b451227af07e diff --git a/src/RtmpMuxer/FlvMuxer.cpp b/src/RtmpMuxer/FlvMuxer.cpp index a1512103..b2686874 100644 --- a/src/RtmpMuxer/FlvMuxer.cpp +++ b/src/RtmpMuxer/FlvMuxer.cpp @@ -42,6 +42,16 @@ void FlvMuxer::start(const EventPoller::Ptr &poller,const RtmpMediaSource::Ptr & if(!media){ throw std::runtime_error("RtmpMediaSource 无效"); } + if(!poller->isCurrentThread()){ + weak_ptr weakSelf = getSharedPtr(); + poller->async([weakSelf,poller,media](){ + auto strongSelf = weakSelf.lock(); + if(strongSelf){ + strongSelf->start(poller,media); + } + }); + return; + } onWriteFlvHeader(media); diff --git a/tests/test_server.cpp b/tests/test_server.cpp index eb6f8849..56112c1b 100644 --- a/tests/test_server.cpp +++ b/tests/test_server.cpp @@ -185,25 +185,21 @@ static onceToken s_token([](){ if(schema == RTMP_SCHEMA && app == "live"){ static map s_mapFlvRecorder; static mutex s_mtxFlvRecorder; - auto poller = EventPollerPool::Instance().getPoller(); - auto rtmpMediaSrc = dynamic_pointer_cast(sender.shared_from_this()); - poller->async([bRegist,schema,vhost,app,stream,poller,rtmpMediaSrc](){ - lock_guard lck(s_mtxFlvRecorder); - if(bRegist){ - DebugL << "开始录制RTMP:" << schema << " " << vhost << " " << app << " " << stream; - GET_CONFIG_AND_REGISTER(string,http_root,Http::kRootPath); - auto path = http_root + "/" + vhost + "/" + app + "/" + stream + "_" + to_string(time(NULL)) + ".flv"; - FlvRecorder::Ptr recorder(new FlvRecorder); - try{ - recorder->startRecord(poller,rtmpMediaSrc,path); - s_mapFlvRecorder[vhost + "/" + app + "/" + stream] = recorder; - }catch(std::exception &ex){ - WarnL << ex.what(); - } - }else{ - s_mapFlvRecorder.erase(vhost + "/" + app + "/" + stream); + lock_guard lck(s_mtxFlvRecorder); + if(bRegist){ + DebugL << "开始录制RTMP:" << schema << " " << vhost << " " << app << " " << stream; + GET_CONFIG_AND_REGISTER(string,http_root,Http::kRootPath); + auto path = http_root + "/" + vhost + "/" + app + "/" + stream + "_" + to_string(time(NULL)) + ".flv"; + FlvRecorder::Ptr recorder(new FlvRecorder); + try{ + recorder->startRecord(EventPollerPool::Instance().getPoller(),dynamic_pointer_cast(sender.shared_from_this()),path); + s_mapFlvRecorder[vhost + "/" + app + "/" + stream] = recorder; + }catch(std::exception &ex){ + WarnL << ex.what(); } - }); + }else{ + s_mapFlvRecorder.erase(vhost + "/" + app + "/" + stream); + } } });