From 1cbfcd96e277d77e3852425fcac2d86ccb80f119 Mon Sep 17 00:00:00 2001 From: zjx94 <741450045@qq.com> Date: Thu, 30 Nov 2023 17:47:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ehls=E5=BF=AB=E9=80=9F?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E7=9B=B8=E5=85=B3=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E9=AB=98hls=E6=89=93=E5=BC=80=E9=80=9F=E5=BA=A6=20(#3?= =?UTF-8?q?024)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增配置项:hls.fastRegister,默认关闭。 开启后首个切片文件只保存一个gop,可提高hls注册速度,加快播放器打开速度。 但是第一个切片播放完毕,第二个切片需要更长时间生成,可能导致播放器等待加载。 --- conf/config.ini | 2 ++ src/Common/config.cpp | 2 ++ src/Common/config.h | 2 ++ src/Record/HlsMaker.cpp | 6 +++--- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/conf/config.ini b/conf/config.ini index dc343b32..f15ec366 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -140,6 +140,8 @@ deleteDelaySec=10 #0为不保留,不起作用 #1为保留,则不删除hls文件,如果开启此功能,注意磁盘大小,或者定期手动清理hls文件 segKeep=0 +#如果设置为1,则第一个切片长度强制设置为1个GOP。当GOP小于segDur,可以提高首屏速度 +fastRegister=0 [hook] #是否启用hook事件,启用后,推拉流都将进行鉴权 diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 1009f1e6..df9f7c5d 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -305,6 +305,7 @@ const string kSegmentRetain = HLS_FIELD "segRetain"; const string kFileBufSize = HLS_FIELD "fileBufSize"; const string kBroadcastRecordTs = HLS_FIELD "broadcastRecordTs"; const string kDeleteDelaySec = HLS_FIELD "deleteDelaySec"; +const string kFastRegister = HLS_FIELD "fastRegister"; static onceToken token([]() { mINI::Instance()[kSegmentDuration] = 2; @@ -314,6 +315,7 @@ static onceToken token([]() { mINI::Instance()[kFileBufSize] = 64 * 1024; mINI::Instance()[kBroadcastRecordTs] = false; mINI::Instance()[kDeleteDelaySec] = 10; + mINI::Instance()[kFastRegister] = false; }); } // namespace Hls diff --git a/src/Common/config.h b/src/Common/config.h index dcbc5514..68726225 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -350,6 +350,8 @@ extern const std::string kFileBufSize; extern const std::string kBroadcastRecordTs; // hls直播文件删除延时,单位秒 extern const std::string kDeleteDelaySec; +// 如果设置为1,则第一个切片长度强制设置为1个GOP +extern const std::string kFastRegister; } // namespace Hls ////////////Rtp代理相关配置/////////// diff --git a/src/Record/HlsMaker.cpp b/src/Record/HlsMaker.cpp index 31f705b8..082ea63a 100644 --- a/src/Record/HlsMaker.cpp +++ b/src/Record/HlsMaker.cpp @@ -111,11 +111,11 @@ void HlsMaker::delOldSegment() { } void HlsMaker::addNewSegment(uint64_t stamp) { - if (!_last_file_name.empty() && stamp - _last_seg_timestamp < _seg_duration * 1000) { - //存在上个切片,并且未到分片时间 + GET_CONFIG(bool, fastRegister, Hls::kFastRegister); + if (_file_index > fastRegister && stamp - _last_seg_timestamp < _seg_duration * 1000) { + //确保序号为0的切片立即open,如果开启快速注册功能,序号为1的切片也应该遇到关键帧立即生成;否则需要等切片时长够长 return; } - //关闭并保存上一个切片,如果_seg_number==0,那么是点播。 flushLastSegment(false); //新增切片