mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
支持hls直播文件延时删除: #913
This commit is contained in:
parent
ce2122d3b6
commit
e8c9666af0
@ -94,6 +94,8 @@ segNum=3
|
|||||||
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";
|
|||||||
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([](){
|
|||||||
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;
|
|||||||
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,
|
|||||||
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,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空缓存
|
* 清空缓存
|
||||||
|
* @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:
|
|||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user