hls 录像支持直播时移 (#1275)

* hls live record support seek

* 调整代码风格

Co-authored-by: 夏楚 <771730766@qq.com>
This commit is contained in:
xiongguangjie 2021-12-15 16:43:49 +08:00 committed by GitHub
parent 254bc6889e
commit 5bffc98541
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,14 +35,26 @@ void HlsMaker::makeIndexFile(bool eof) {
auto sequence = _seg_number ? (_file_index > _seg_number ? _file_index - _seg_number : 0LL) : 0LL;
string m3u8;
snprintf(file_content, sizeof(file_content),
"#EXTM3U\n"
"#EXT-X-VERSION:3\n"
"#EXT-X-ALLOW-CACHE:NO\n"
"#EXT-X-TARGETDURATION:%u\n"
"#EXT-X-MEDIA-SEQUENCE:%llu\n",
(maxSegmentDuration + 999) / 1000,
sequence);
if (_seg_number == 0) {
// 录像点播支持时移
snprintf(file_content, sizeof(file_content),
"#EXTM3U\n"
"#EXT-X-PLAYLIST-TYPE:EVENT\n"
"#EXT-X-VERSION:4\n"
"#EXT-X-TARGETDURATION:%u\n"
"#EXT-X-MEDIA-SEQUENCE:%llu\n",
(maxSegmentDuration + 999) / 1000,
sequence);
} else {
snprintf(file_content, sizeof(file_content),
"#EXTM3U\n"
"#EXT-X-VERSION:3\n"
"#EXT-X-ALLOW-CACHE:NO\n"
"#EXT-X-TARGETDURATION:%u\n"
"#EXT-X-MEDIA-SEQUENCE:%llu\n",
(maxSegmentDuration + 999) / 1000,
sequence);
}
m3u8.assign(file_content);
@ -100,7 +112,7 @@ void HlsMaker::addNewSegment(uint32_t stamp) {
}
//关闭并保存上一个切片如果_seg_number==0,那么是点播。
flushLastSegment(_seg_number == 0);
flushLastSegment(false);
//新增切片
_last_file_name = onOpenSegment(_file_index++);
//记录本次切片的起始时间戳