From 5bffc98541b15c8503dd73c8135bd9e0f32055d3 Mon Sep 17 00:00:00 2001 From: xiongguangjie Date: Wed, 15 Dec 2021 16:43:49 +0800 Subject: [PATCH] =?UTF-8?q?hls=20=E5=BD=95=E5=83=8F=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E6=97=B6=E7=A7=BB=20(#1275)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * hls live record support seek * 调整代码风格 Co-authored-by: 夏楚 <771730766@qq.com> --- src/Record/HlsMaker.cpp | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/Record/HlsMaker.cpp b/src/Record/HlsMaker.cpp index db780013..84cd1e4d 100644 --- a/src/Record/HlsMaker.cpp +++ b/src/Record/HlsMaker.cpp @@ -35,15 +35,27 @@ 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); for (auto &tp : _seg_dur_list) { @@ -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++); //记录本次切片的起始时间戳 @@ -135,4 +147,4 @@ void HlsMaker::clear() { _last_file_name.clear(); } -}//namespace mediakit \ No newline at end of file +}//namespace mediakit