合并pr(添加录制ts完成通知): #479

This commit is contained in:
xiongziliang
2020-09-20 11:40:42 +08:00
parent 0fce108de5
commit f84981dc75
11 changed files with 94 additions and 145 deletions

View File

@@ -25,10 +25,10 @@ MP4Recorder::MP4Recorder(const string& strPath,
const string &strStreamId) {
_strPath = strPath;
/////record 业务逻辑//////
_info.strAppName = strApp;
_info.strStreamId = strStreamId;
_info.strVhost = strVhost;
_info.strFolder = strPath;
_info.app = strApp;
_info.stream = strStreamId;
_info.vhost = strVhost;
_info.folder = strPath;
}
MP4Recorder::~MP4Recorder() {
closeFile();
@@ -42,15 +42,15 @@ void MP4Recorder::createFile() {
auto strFile = _strPath + strDate + "/" + strTime + ".mp4";
/////record 业务逻辑//////
_info.ui64StartedTime = ::time(NULL);
_info.strFileName = strTime + ".mp4";
_info.strFilePath = strFile;
_info.start_time = ::time(NULL);
_info.file_name = strTime + ".mp4";
_info.file_path = strFile;
GET_CONFIG(string,appName,Record::kAppName);
_info.strUrl = appName + "/"
+ _info.strAppName + "/"
+ _info.strStreamId + "/"
+ strDate + "/"
+ strTime + ".mp4";
_info.url = appName + "/"
+ _info.app + "/"
+ _info.stream + "/"
+ strDate + "/"
+ strTime + ".mp4";
try {
_muxer = std::make_shared<MP4Muxer>(strFileTmp.data());
@@ -73,7 +73,7 @@ void MP4Recorder::asyncClose() {
auto info = _info;
WorkThreadPool::Instance().getExecutor()->async([muxer,strFileTmp,strFile,info]() {
//获取文件录制时间放在关闭mp4之前是为了忽略关闭mp4执行时间
const_cast<RecordInfo&>(info).ui64TimeLen = ::time(NULL) - info.ui64StartedTime;
const_cast<RecordInfo&>(info).time_len = ::time(NULL) - info.start_time;
//关闭mp4非常耗时所以要放在后台线程执行
muxer->closeMP4();
//临时文件名改成正式文件名防止mp4未完成时被访问
@@ -81,7 +81,7 @@ void MP4Recorder::asyncClose() {
//获取文件大小
struct stat fileData;
stat(strFile.data(), &fileData);
const_cast<RecordInfo&>(info).ui64FileSize = fileData.st_size;
const_cast<RecordInfo&>(info).file_size = fileData.st_size;
/////record 业务逻辑//////
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordMP4,info);
});