From a595aee21631f47e462288509067a582d7efb5d5 Mon Sep 17 00:00:00 2001 From: notch Date: Mon, 28 Dec 2020 10:48:44 +0800 Subject: [PATCH] add hlsfragment config --- config/config.go | 22 ++++++++++++---------- config/global.go | 5 ++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/config/config.go b/config/config.go index a640775..f132588 100755 --- a/config/config.go +++ b/config/config.go @@ -10,15 +10,16 @@ import ( // config 服务配置 type config struct { - ListenAddr string `json:"listen"` // 服务侦听地址和端口 - Auth bool `json:"auth"` // 启用安全验证 - CacheGop bool `json:"cache_gop"` // 缓存图像组,以便提高播放端打开速度,但内存需求大 - HlsPath string `json:"hlspath,omitempty"` // Hls临时缓存目录 - Profile bool `json:"profile"` // 是否启动Profile - TLS *TLSConfig `json:"tls,omitempty"` // https安全端口交互 - Routetable *ProviderConfig `json:"routetable,omitempty"` // 路由表 - Users *ProviderConfig `json:"users,omitempty"` // 用户 - Log LogConfig `json:"log"` // 日志配置 + ListenAddr string `json:"listen"` // 服务侦听地址和端口 + Auth bool `json:"auth"` // 启用安全验证 + CacheGop bool `json:"cache_gop"` // 缓存图像组,以便提高播放端打开速度,但内存需求大 + HlsPath string `json:"hlspath"` // Hls 临时缓存目录 + HlsFragment int `json:"hlsfragment"` // Hls 分段时长,单位秒 + Profile bool `json:"profile"` // 是否启动Profile + TLS *TLSConfig `json:"tls,omitempty"` // https安全端口交互 + Routetable *ProviderConfig `json:"routetable,omitempty"` // 路由表 + Users *ProviderConfig `json:"users,omitempty"` // 用户 + Log LogConfig `json:"log"` // 日志配置 } func (c *config) initFlags() { @@ -28,7 +29,8 @@ func (c *config) initFlags() { "Determines if requires permission verification to access stream media") flag.BoolVar(&c.CacheGop, "cachegop", false, "Determines if Gop should be cached to memory") - flag.StringVar(&c.HlsPath, "hlspath", "", "Set HLS live dir") + flag.StringVar(&c.HlsPath, "hlspath", "", "Set HLS live cache path") + flag.IntVar(&c.HlsFragment, "hlsfragment", 5, "Set HLS segment duration") flag.BoolVar(&c.Profile, "pprof", false, "Determines if profile enabled") diff --git a/config/global.go b/config/global.go index 9deab25..fc2a601 100755 --- a/config/global.go +++ b/config/global.go @@ -177,7 +177,10 @@ func HlsEnable() bool { // HlsFragment TS片段时长(s) func HlsFragment() int { - return 6 + if globalC == nil || globalC.HlsFragment < 5 { + return 5 + } + return globalC.HlsFragment } // HlsPath hls 存储目录