]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
直播hls流均衡=》直播hls流故障转移
authorqydysky <32743305+qydysky@users.noreply.github.com>
Tue, 1 Nov 2022 01:36:27 +0000 (09:36 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Tue, 1 Nov 2022 01:36:27 +0000 (09:36 +0800)
Reply/stream.go
demo/config/config_K_v.json

index 4ecfc4a5e44739c1b6f5f614b27d4619dbcdbf75..b43af0584f7d8e51ae5bca1395891b9b46ab337c 100644 (file)
@@ -58,7 +58,7 @@ type M4SStream_Config struct {
        want_qn       int    //直播流清晰度
        want_type     string //直播流类型
        save_as_mp4   bool   //直播hls流保存为MP4
-       banlance_host bool   //直播hls流均衡
+       banlance_host bool   //直播hls流故障转移
 }
 
 type m4s_link_item struct {
@@ -112,7 +112,7 @@ func (t *M4SStream) LoadConfig(common c.Common, l *log.Log_interface) {
        if v, ok := common.K_v.LoadV(`直播hls流保存为MP4`).(bool); ok {
                t.config.save_as_mp4 = v
        }
-       if v, ok := common.K_v.LoadV(`直播hls流均衡`).(bool); ok {
+       if v, ok := common.K_v.LoadV(`直播hls流故障转移`).(bool); ok {
                t.config.banlance_host = v
        }
        if v, ok := common.K_v.LoadV(`直播流清晰度`).(float64); ok {
@@ -664,16 +664,25 @@ func (t *M4SStream) saveStreamM4s() (e error) {
 
                                        link.status = 1 // 设置切片状态为正在下载
 
-                                       // 均衡负载
+                                       // 故障转移
                                        if link_url, e := url.Parse(link.Url); e == nil {
                                                if t.stream_hosts.Len() != 1 {
-                                                       t.stream_hosts.Range(func(key, _ interface{}) bool {
-                                                               // 故障转移
-                                                               if link.status == 3 && link_url.Host == key.(string) {
-                                                                       return true
+                                                       t.stream_hosts.Range(func(key, v interface{}) bool {
+                                                               if link.status == 3 {
+                                                                       if link_url.Host == key.(string) {
+                                                                               t.stream_hosts.Store(key, false)
+                                                                               return true
+                                                                       } else if v != nil {
+                                                                               return true
+                                                                       } else {
+                                                                               link_url.Host = key.(string)
+                                                                               return false
+                                                                       }
+                                                               }
+
+                                                               if v != nil {
+                                                                       t.stream_hosts.Store(key, nil)
                                                                }
-                                                               // 随机
-                                                               link_url.Host = key.(string)
                                                                return false
                                                        })
                                                }
@@ -899,14 +908,11 @@ func (t *M4SStream) Start() bool {
                                continue
                        }
 
-                       // è®¾ç½®å\9d\87è¡¡è´\9fè½½
+                       // è®¾ç½®å\85¨é\83¨æ\9c\8då\8a¡
                        for _, v := range t.common.Live {
                                if url_struct, e := url.Parse(v); e == nil {
                                        t.stream_hosts.Store(url_struct.Hostname(), nil)
                                }
-                               if !t.config.banlance_host {
-                                       break
-                               }
                        }
 
                        // 保存流
index f2f073ef7f8e766f9a477aa38beafd4515d93c5f..c2365b723700e3e29118022a66fb1583be44d937 100644 (file)
@@ -58,8 +58,8 @@
     "直播流类型": "flv",
     "直播流类型故障切换": true,
     "直播流保存位置": "./live",
-    "直播hls流均衡-help":"true:使用所有hls服务器",
-    "直播hls流均衡": true,
+    "直播hls流故障转移-help":"true:hls服务器故障时,使用其他",
+    "直播hls流故障转移": true,
     "直播hls流保存为MP4": true,
     "仅保存当前直播间流-help": "启用此项,才会保存Ass",
     "仅保存当前直播间流": true,