]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
hls流缓冲
authorqydysky <qydysky@foxmail.com>
Tue, 8 Jun 2021 08:54:48 +0000 (16:54 +0800)
committerqydysky <qydysky@foxmail.com>
Tue, 8 Jun 2021 08:54:48 +0000 (16:54 +0800)
Reply/F.go
demo/config/config_K_v.json

index 206cc51bb093ee29ece74f38e6135716c53bf21c..f6c3e62381da72e7ba661bb9acbd307d502e220f 100644 (file)
@@ -253,6 +253,8 @@ type Savestream struct {
        flv_front []byte//flv头及首tag
        flv_stream *msgq.Msgq//发送给客户的flv流关键帧间隔片
 
+       m4s_hls int//hls list 中的m4s数量
+       hlsbuffersize int//hls list缓冲m4s数量
        hls_banlance_host bool//使用均衡hls服务器
 
        wait *s.Signal
@@ -282,7 +284,7 @@ const (
 
 var savestream = Savestream {
        flv_stream:msgq.New(10),//队列最多保留10个关键帧间隔片
-       m4s_hls:5,
+       m4s_hls:8,
 }
 
 func init(){
@@ -304,6 +306,9 @@ func init(){
                        savestream.base_path = path+"/"
                }
        }
+       if v, ok := c.K_v.LoadV(`直播hls流缓冲`).(float64);ok && v > 0 {
+               savestream.hlsbuffersize = int(v)
+       }
        if v, ok := c.K_v.LoadV(`直播hls流均衡`).(bool);ok {
                savestream.hls_banlance_host = v
        }
@@ -911,13 +916,8 @@ func Savestreamf(){
                                hls_gen hls_generate
                                DISCONTINUITY int
                                SEQUENCE int
-                               buffersize int
                        )
 
-                       if v, ok := c.K_v.LoadV(`直播流缓冲`).(float64);ok && v > 0 {
-                               buffersize = int(v)
-                       }
-
                        //hls stream gen 用户m3u8生成
                        go func(){
                                per_second := time.Tick(time.Second)
@@ -960,7 +960,7 @@ func Savestreamf(){
                                },
                                `clock`:func(now interface{})(bool){
                                        //buffer
-                                       if len(hls_gen.m4s_list) - buffersize < 0 {
+                                       if len(hls_gen.m4s_list) - savestream.hlsbuffersize < 0 {
                                                return false
                                        }
 
@@ -998,7 +998,7 @@ func Savestreamf(){
                                                                continue
                                                        }
 
-                                                       if m4s_num >= 8+add {break}
+                                                       if m4s_num >= savestream.m4s_hls+add {break}
 
                                                        m4s_num += 1
                                                        // if m4s_num == 1 {SEQUENCE = strings.ReplaceAll(v.Base, ".m4s", "")}
@@ -1291,7 +1291,7 @@ func Savestreamf(){
                                                        if _,ok := m4s_cache.Load(path + link.Base);!ok{
                                                                m4s_cache.Store(path + link.Base, r.Respon)
                                                                go func(){//移除
-                                                                       time.Sleep(time.Second*time.Duration(savestream.m4s_hls+1))
+                                                                       time.Sleep(time.Second*time.Duration(savestream.hlsbuffersize+savestream.m4s_hls+1))
                                                                        m4s_cache.Delete(path + link.Base)
                                                                }()
                                                        }
index 05642cd7a9f5bb52554790a0035ebed251deefb5..8c37ea6e66e19ec3d3603707a9a48bcd553e2b23 100644 (file)
@@ -48,6 +48,7 @@
     "直播流类型-help": "flv or hls",
     "直播流类型": "hls",
     "直播流保存位置": "./live",
+    "直播hls流缓冲": 20,
     "直播hls流均衡-help":"true:使用所有hls服务器",
     "直播hls流均衡": true,
     "ass-help": "只有保存直播流时才考虑生成ass,ass编码默认GB18030(可选utf-8)",