HLS: 修复hls直播ts/m3u8文件更新导致mmap失效,触发bus error的bug

This commit is contained in:
ziyue
2021-12-22 15:42:03 +08:00
parent fe575af0d8
commit 2e9ff3ed3c
6 changed files with 44 additions and 38 deletions

View File

@@ -132,8 +132,10 @@ void HlsMaker::flushLastSegment(bool eof){
_seg_dur_list.push_back(std::make_tuple(seg_dur, std::move(_last_file_name)));
_last_file_name.clear();
delOldSegment();
makeIndexFile(eof);
//先flush ts切片否则可能存在ts文件未写入完毕就被访问的情况
onFlushLastSegment(seg_dur);
//然后写m3u8文件
makeIndexFile(eof);
}
bool HlsMaker::isLive() {

View File

@@ -125,10 +125,11 @@ void HlsMakerImp::onWriteHls(const char *data, size_t len) {
}
void HlsMakerImp::onFlushLastSegment(uint32_t duration_ms) {
//关闭并flush文件到磁盘
_file = nullptr;
GET_CONFIG(bool, broadcastRecordTs, Hls::kBroadcastRecordTs);
if (broadcastRecordTs) {
//关闭ts文件以便获取正确的文件大小
_file = nullptr;
_info.time_len = duration_ms / 1000.0f;
struct stat fileData;
stat(_info.file_path.data(), &fileData);