完善录制相关功能

This commit is contained in:
xiongziliang 2019-03-22 13:31:39 +08:00
parent cc2d22737f
commit 8ebf127ee6

View File

@ -185,21 +185,25 @@ 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;
lock_guard<mutex> lck(s_mtxFlvRecorder); auto poller = EventPollerPool::Instance().getPoller();
if(bRegist){ auto rtmpMediaSrc = dynamic_pointer_cast<RtmpMediaSource>(sender.shared_from_this());
DebugL << "开始录制RTMP" << schema << " " << vhost << " " << app << " " << stream; poller->async([bRegist,schema,vhost,app,stream,poller,rtmpMediaSrc](){
GET_CONFIG_AND_REGISTER(string,http_root,Http::kRootPath); lock_guard<mutex> lck(s_mtxFlvRecorder);
auto path = http_root + "/" + vhost + "/" + app + "/" + stream + "_" + to_string(time(NULL)) + ".flv"; if(bRegist){
FlvRecorder::Ptr recorder(new FlvRecorder); DebugL << "开始录制RTMP" << schema << " " << vhost << " " << app << " " << stream;
try{ GET_CONFIG_AND_REGISTER(string,http_root,Http::kRootPath);
recorder->startRecord(nullptr,dynamic_pointer_cast<RtmpMediaSource>(sender.shared_from_this()),path); auto path = http_root + "/" + vhost + "/" + app + "/" + stream + "_" + to_string(time(NULL)) + ".flv";
s_mapFlvRecorder[vhost + "/" + app + "/" + stream] = recorder; FlvRecorder::Ptr recorder(new FlvRecorder);
}catch(std::exception &ex){ try{
WarnL << ex.what(); 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);
} }
}else{ });
s_mapFlvRecorder.erase(vhost + "/" + app + "/" + stream);
}
} }
}); });