Commit e8c9666a by ziyue

支持hls直播文件延时删除: #913

parent ce2122d3
......@@ -92,8 +92,10 @@ segDur=2
segNum=3
#HLS切片从m3u8文件中移除后,继续保留在磁盘上的个数
segRetain=5
# 是否广播 ts 切片完成通知
#是否广播 ts 切片完成通知
broadcastRecordTs=0
#直播hls文件删除延时,单位秒,issue: #913
deleteDelaySec=0
[hook]
#在推流时,如果url参数匹对admin_params,那么可以不经过hook鉴权直接推流成功,播放时亦然
......
......@@ -260,6 +260,8 @@ const string kFileBufSize = HLS_FIELD"fileBufSize";
const string kFilePath = HLS_FIELD"filePath";
// 是否广播 ts 切片完成通知
const string kBroadcastRecordTs = HLS_FIELD"broadcastRecordTs";
//hls直播文件删除延时,单位秒
const string kDeleteDelaySec = HLS_FIELD"deleteDelaySec";
onceToken token([](){
mINI::Instance()[kSegmentDuration] = 2;
......@@ -268,6 +270,7 @@ onceToken token([](){
mINI::Instance()[kFileBufSize] = 64 * 1024;
mINI::Instance()[kFilePath] = "./www";
mINI::Instance()[kBroadcastRecordTs] = false;
mINI::Instance()[kDeleteDelaySec] = 0;
},nullptr);
} //namespace Hls
......
......@@ -293,6 +293,8 @@ extern const string kFileBufSize;
extern const string kFilePath;
// 是否广播 ts 切片完成通知
extern const string kBroadcastRecordTs;
//hls直播文件删除延时,单位秒
extern const string kDeleteDelaySec;
} //namespace Hls
////////////Rtp代理相关配置///////////
......
......@@ -23,6 +23,7 @@ HlsMakerImp::HlsMakerImp(const string &m3u8_file,
uint32_t bufSize,
float seg_duration,
uint32_t seg_number) : HlsMaker(seg_duration, seg_number) {
_poller = EventPollerPool::Instance().getPoller();
_path_prefix = m3u8_file.substr(0, m3u8_file.rfind('/'));
_path_hls = m3u8_file;
_params = params;
......@@ -35,18 +36,30 @@ HlsMakerImp::HlsMakerImp(const string &m3u8_file,
}
HlsMakerImp::~HlsMakerImp() {
clearCache();
clearCache(false);
}
void HlsMakerImp::clearCache() {
void HlsMakerImp::clearCache(bool immediately) {
//录制完了
flushLastSegment(true);
if (isLive()) {
//hls直播才删除文件
clear();
_file = nullptr;
_segment_file_paths.clear();
if (!isLive()) {
return;
}
clear();
_file = nullptr;
_segment_file_paths.clear();
//hls直播才删除文件
GET_CONFIG(uint32_t, delay, Hls::kDeleteDelaySec);
if (!delay || immediately) {
File::delete_file(_path_prefix.data());
} else {
auto path_prefix = _path_prefix;
_poller->doDelayTask(delay * 1000, [path_prefix]() {
File::delete_file(path_prefix.data());
return 0;
});
}
}
......
......@@ -47,8 +47,9 @@ public:
/**
* 清空缓存
* @param immediately 时候立即删除
*/
void clearCache();
void clearCache(bool immediately = true);
protected:
string onOpenSegment(uint64_t index) override ;
......@@ -69,6 +70,7 @@ private:
std::shared_ptr<FILE> _file;
std::shared_ptr<char> _file_buf;
HlsMediaSource::Ptr _media_src;
EventPoller::Ptr _poller;
map<uint64_t/*index*/,string/*file_path*/> _segment_file_paths;
};
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论