新增hls快速注册相关配置,提高hls打开速度 (#3024)

新增配置项:hls.fastRegister,默认关闭。
开启后首个切片文件只保存一个gop,可提高hls注册速度,加快播放器打开速度。
但是第一个切片播放完毕,第二个切片需要更长时间生成,可能导致播放器等待加载。
This commit is contained in:
zjx94 2023-11-30 17:47:22 +08:00 committed by GitHub
parent e81ff307c7
commit 1cbfcd96e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 3 deletions

View File

@ -140,6 +140,8 @@ deleteDelaySec=10
#0为不保留不起作用
#1为保留则不删除hls文件如果开启此功能注意磁盘大小或者定期手动清理hls文件
segKeep=0
#如果设置为1则第一个切片长度强制设置为1个GOP。当GOP小于segDur可以提高首屏速度
fastRegister=0
[hook]
#是否启用hook事件启用后推拉流都将进行鉴权

View File

@ -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

View File

@ -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代理相关配置///////////

View File

@ -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);
//新增切片