Commit e8c9666a by ziyue

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

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