Commit ea4f9a0c by xiongziliang

mp4close放在后台线程执行

parent 3453575c
Subproject commit e79d24b51051ed9b3bd9c66b9d8ace3c76a0411a
Subproject commit b6bca50b1213de39b460b6a87f91d4bec5d95f7e
......@@ -227,8 +227,8 @@ const char kAppName[] = RECORD_FIELD"appName";
#define RECORD_SAMPLE_MS 100
const char kSampleMS[] = RECORD_FIELD"sampleMS";
//MP4文件录制大小,不能太大,否则MP4Close函数执行事件太长
#define RECORD_FILE_SECOND (10*60)
//MP4文件录制大小,默认一个小时
#define RECORD_FILE_SECOND (60*60)
const char kFileSecond[] = RECORD_FIELD"fileSecond";
//录制文件路径
......
......@@ -73,7 +73,7 @@ extern const char kBroadcastMediaChanged[];
//录制mp4文件成功后广播
extern const char kBroadcastRecordMP4[];
#define BroadcastRecordMP4Args const Mp4Info &info,Mp4Maker &sender
#define BroadcastRecordMP4Args const Mp4Info &info
//收到http api请求广播
extern const char kBroadcastHttpRequest[];
......@@ -216,7 +216,7 @@ namespace Record {
extern const char kAppName[];
//每次流化MP4文件的时长,单位毫秒
extern const char kSampleMS[];
//MP4文件录制大小,不能太大,否则MP4Close函数执行事件太长
//MP4文件录制大小,默认一个小时
extern const char kFileSecond[];
//录制文件路径
extern const char kFilePath[];
......
......@@ -36,6 +36,7 @@
#include "Util/NoticeCenter.h"
#include "Extension/H264.h"
#include "Extension/AAC.h"
#include "Thread/WorkThreadPool.h"
using namespace toolkit;
......@@ -212,25 +213,33 @@ void Mp4Maker::createFile() {
}
}
void Mp4Maker::asyncClose() {
auto hMp4 = _hMp4;
auto strFileTmp = _strFileTmp;
auto strFile = _strFile;
auto info = _info;
WorkThreadPool::Instance().getExecutor()->async([hMp4,strFileTmp,strFile,info]() {
//获取文件录制时间,放在MP4Close之前是为了忽略MP4Close执行时间
const_cast<Mp4Info&>(info).ui64TimeLen = ::time(NULL) - info.ui64StartedTime;
//MP4Close非常耗时,所以要放在后台线程执行
MP4Close(hMp4,MP4_CLOSE_DO_NOT_COMPUTE_BITRATE);
//临时文件名改成正式文件名,防止mp4未完成时被访问
rename(strFileTmp.data(),strFile.data());
//获取文件大小
struct stat fileData;
stat(strFile.data(), &fileData);
const_cast<Mp4Info&>(info).ui64FileSize = fileData.st_size;
/////record 业务逻辑//////
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordMP4,info);
});
}
void Mp4Maker::closeFile() {
if (_hMp4 != MP4_INVALID_FILE_HANDLE) {
{
TimeTicker();
MP4Close(_hMp4,MP4_CLOSE_DO_NOT_COMPUTE_BITRATE);
}
rename(_strFileTmp.data(),_strFile.data());
asyncClose();
_hMp4 = MP4_INVALID_FILE_HANDLE;
_hVideo = MP4_INVALID_TRACK_ID;
_hAudio = MP4_INVALID_TRACK_ID;
/////record 业务逻辑//////
_info.ui64TimeLen = ::time(NULL) - _info.ui64StartedTime;
//获取文件大小
struct stat fileData;
stat(_strFile.data(), &fileData);
_info.ui64FileSize = fileData.st_size;
//----record 业务逻辑----//
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastRecordMP4,_info,*this);
}
}
......
......@@ -79,6 +79,7 @@ private:
private:
void createFile();
void closeFile();
void asyncClose();
//时间戳:参考频率1000
void inputH264(void *pData, uint32_t ui32Length, uint32_t ui32TimeStamp);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论