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 &
if(!media){
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);
......
......@@ -185,25 +185,21 @@ static onceToken s_token([](){
if(schema == RTMP_SCHEMA && app == "live"){
static map<string,FlvRecorder::Ptr> s_mapFlvRecorder;
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);
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<mutex> 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<RtmpMediaSource>(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);
}
}
});
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论