mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
修复hls快速重连时,延迟删除文件夹相关bug (#3039)
This commit is contained in:
parent
c12a6f0aed
commit
3137b95406
@ -1 +1 @@
|
|||||||
Subproject commit e7cd1f3d1ec81014f92ab844915db60bb7e34bd5
|
Subproject commit 7a403274c385f59a7eefd5474a05a05139220ee6
|
@ -45,6 +45,13 @@ void HlsMakerImp::clearCache() {
|
|||||||
clearCache(true, false);
|
clearCache(true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void clearHls(const std::list<std::string> &files) {
|
||||||
|
for (auto &file : files) {
|
||||||
|
File::delete_file(file);
|
||||||
|
}
|
||||||
|
File::deleteEmptyDir(File::parentDir(files.back()));
|
||||||
|
}
|
||||||
|
|
||||||
void HlsMakerImp::clearCache(bool immediately, bool eof) {
|
void HlsMakerImp::clearCache(bool immediately, bool eof) {
|
||||||
// 录制完了
|
// 录制完了
|
||||||
flushLastSegment(eof);
|
flushLastSegment(eof);
|
||||||
@ -52,23 +59,33 @@ void HlsMakerImp::clearCache(bool immediately, bool eof) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clear();
|
{
|
||||||
_file = nullptr;
|
std::list<std::string> lst;
|
||||||
_segment_file_paths.clear();
|
lst.emplace_back(_path_hls);
|
||||||
|
if (!_path_init.empty()) {
|
||||||
|
lst.emplace_back(_path_init);
|
||||||
|
}
|
||||||
|
for (auto &pr : _segment_file_paths) {
|
||||||
|
lst.emplace_back(std::move(pr.second));
|
||||||
|
}
|
||||||
|
|
||||||
// hls直播才删除文件
|
// hls直播才删除文件
|
||||||
GET_CONFIG(uint32_t, delay, Hls::kDeleteDelaySec);
|
GET_CONFIG(uint32_t, delay, Hls::kDeleteDelaySec);
|
||||||
if (!delay || immediately) {
|
if (!delay || immediately) {
|
||||||
File::delete_file(_path_prefix.data());
|
clearHls(lst);
|
||||||
} else {
|
} else {
|
||||||
auto path_prefix = _path_prefix;
|
_poller->doDelayTask(delay * 1000, [lst]() {
|
||||||
_poller->doDelayTask(delay * 1000, [path_prefix]() {
|
clearHls(lst);
|
||||||
File::delete_file(path_prefix.data());
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear();
|
||||||
|
_file = nullptr;
|
||||||
|
_segment_file_paths.clear();
|
||||||
|
}
|
||||||
|
|
||||||
string HlsMakerImp::onOpenSegment(uint64_t index) {
|
string HlsMakerImp::onOpenSegment(uint64_t index) {
|
||||||
string segment_name, segment_path;
|
string segment_name, segment_path;
|
||||||
{
|
{
|
||||||
@ -103,16 +120,17 @@ void HlsMakerImp::onDelSegment(uint64_t index) {
|
|||||||
if (it == _segment_file_paths.end()) {
|
if (it == _segment_file_paths.end()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File::delete_file(it->second.data());
|
File::delete_file(it->second.data(), true);
|
||||||
_segment_file_paths.erase(it);
|
_segment_file_paths.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HlsMakerImp::onWriteInitSegment(const char *data, size_t len) {
|
void HlsMakerImp::onWriteInitSegment(const char *data, size_t len) {
|
||||||
string init_seg_path = _path_prefix + "/init.mp4";
|
string init_seg_path = _path_prefix + "/init.mp4";
|
||||||
_file = makeFile(init_seg_path, true);
|
_file = makeFile(init_seg_path);
|
||||||
|
|
||||||
if (_file) {
|
if (_file) {
|
||||||
fwrite(data, len, 1, _file.get());
|
fwrite(data, len, 1, _file.get());
|
||||||
|
_path_init = std::move(init_seg_path);
|
||||||
_file = nullptr;
|
_file = nullptr;
|
||||||
} else {
|
} else {
|
||||||
WarnL << "Create file failed," << init_seg_path << " " << get_uv_errmsg();
|
WarnL << "Create file failed," << init_seg_path << " " << get_uv_errmsg();
|
||||||
|
@ -60,6 +60,7 @@ private:
|
|||||||
int _buf_size;
|
int _buf_size;
|
||||||
std::string _params;
|
std::string _params;
|
||||||
std::string _path_hls;
|
std::string _path_hls;
|
||||||
|
std::string _path_init;
|
||||||
std::string _path_prefix;
|
std::string _path_prefix;
|
||||||
RecordInfo _info;
|
RecordInfo _info;
|
||||||
std::shared_ptr<FILE> _file;
|
std::shared_ptr<FILE> _file;
|
||||||
|
Loading…
Reference in New Issue
Block a user