Commit 2b4d8a12 by xiongziliang

完善FLV复用器

parent 8ebf127e
Subproject commit eefe3ce118c0720a3a9c1e5770411b0b80275593 Subproject commit e589ef61db16b3d7c43661f1e421b451227af07e
...@@ -42,6 +42,16 @@ void FlvMuxer::start(const EventPoller::Ptr &poller,const RtmpMediaSource::Ptr & ...@@ -42,6 +42,16 @@ void FlvMuxer::start(const EventPoller::Ptr &poller,const RtmpMediaSource::Ptr &
if(!media){ if(!media){
throw std::runtime_error("RtmpMediaSource 无效"); throw std::runtime_error("RtmpMediaSource 无效");
} }
if(!poller->isCurrentThread()){
weak_ptr<FlvMuxer> weakSelf = getSharedPtr();
poller->async([weakSelf,poller,media](){
auto strongSelf = weakSelf.lock();
if(strongSelf){
strongSelf->start(poller,media);
}
});
return;
}
onWriteFlvHeader(media); onWriteFlvHeader(media);
......
...@@ -185,9 +185,6 @@ static onceToken s_token([](){ ...@@ -185,9 +185,6 @@ static onceToken s_token([](){
if(schema == RTMP_SCHEMA && app == "live"){ if(schema == RTMP_SCHEMA && app == "live"){
static map<string,FlvRecorder::Ptr> s_mapFlvRecorder; static map<string,FlvRecorder::Ptr> s_mapFlvRecorder;
static mutex s_mtxFlvRecorder; static mutex s_mtxFlvRecorder;
auto poller = EventPollerPool::Instance().getPoller();
auto rtmpMediaSrc = dynamic_pointer_cast<RtmpMediaSource>(sender.shared_from_this());
poller->async([bRegist,schema,vhost,app,stream,poller,rtmpMediaSrc](){
lock_guard<mutex> lck(s_mtxFlvRecorder); lock_guard<mutex> lck(s_mtxFlvRecorder);
if(bRegist){ if(bRegist){
DebugL << "开始录制RTMP:" << schema << " " << vhost << " " << app << " " << stream; DebugL << "开始录制RTMP:" << schema << " " << vhost << " " << app << " " << stream;
...@@ -195,7 +192,7 @@ static onceToken s_token([](){ ...@@ -195,7 +192,7 @@ static onceToken s_token([](){
auto path = http_root + "/" + vhost + "/" + app + "/" + stream + "_" + to_string(time(NULL)) + ".flv"; auto path = http_root + "/" + vhost + "/" + app + "/" + stream + "_" + to_string(time(NULL)) + ".flv";
FlvRecorder::Ptr recorder(new FlvRecorder); FlvRecorder::Ptr recorder(new FlvRecorder);
try{ try{
recorder->startRecord(poller,rtmpMediaSrc,path); recorder->startRecord(EventPollerPool::Instance().getPoller(),dynamic_pointer_cast<RtmpMediaSource>(sender.shared_from_this()),path);
s_mapFlvRecorder[vhost + "/" + app + "/" + stream] = recorder; s_mapFlvRecorder[vhost + "/" + app + "/" + stream] = recorder;
}catch(std::exception &ex){ }catch(std::exception &ex){
WarnL << ex.what(); WarnL << ex.what();
...@@ -203,7 +200,6 @@ static onceToken s_token([](){ ...@@ -203,7 +200,6 @@ static onceToken s_token([](){
}else{ }else{
s_mapFlvRecorder.erase(vhost + "/" + app + "/" + stream); s_mapFlvRecorder.erase(vhost + "/" + app + "/" + stream);
} }
});
} }
}); });
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论