]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
hls均衡
authorqydysky <qydysky@foxmail.com>
Tue, 8 Jun 2021 08:52:22 +0000 (16:52 +0800)
committerqydysky <qydysky@foxmail.com>
Tue, 8 Jun 2021 08:52:22 +0000 (16:52 +0800)
README.md
Reply/F.go
demo/config/config_K_v.json

index d1d53b9aeb2b2d43b54e59992967ca139ace28cd..3965296b8ccf937c48e1cfe9c4be55dfd90a093d 100644 (file)
--- a/README.md
+++ b/README.md
@@ -94,6 +94,7 @@ golang go version go1.15 linux/amd64
 - [x] 弹幕自动重连(30s)
 - [x] 直播流开播自动下载
 - [x] 直播流断流再保存
+- [x] 直播hls流均衡负载
 - [x] 命令行支持房间切换、弹幕发送、启停录制
 - [x] GTK信息窗支持房间切换、弹幕格式化发送、时长统计
 - [x] GTK弹幕窗支持自定义人/事件消息停留
@@ -126,7 +127,7 @@ ass编码GB18030支持中文
 在`demo/config/config_K_v.json`中可找到配置项,0:随机可用端口 >0:固定可用端口 <0:禁用服务。
 
 ```
-    "直播保存位置Web服务":0,
+    "直播Web服务口":0,
 ```
 
 开启之后,启动会显示服务地址,在局域网内打开网址可以取得所有直播流的串流地址
index 311116f4e4a3c4e8791ebd9b4cecf90fca3d5975..206cc51bb093ee29ece74f38e6135716c53bf21c 100644 (file)
@@ -253,7 +253,7 @@ type Savestream struct {
        flv_front []byte//flv头及首tag
        flv_stream *msgq.Msgq//发送给客户的flv流关键帧间隔片
 
-       m4s_hls int
+       hls_banlance_host bool//使用均衡hls服务器
 
        wait *s.Signal
        cancel *s.Signal
@@ -304,6 +304,9 @@ func init(){
                        savestream.base_path = path+"/"
                }
        }
+       if v, ok := c.K_v.LoadV(`直播hls流均衡`).(bool);ok {
+               savestream.hls_banlance_host = v
+       }
 }
 
 //已go func形式调用,将会获取直播流
@@ -1147,6 +1150,23 @@ func Savestreamf(){
                                        continue
                                }
 
+                               //random host load balance
+                               if savestream.hls_banlance_host {
+                                       Host_list := []string{}
+                                       for _,v := range c.Live { 
+                                               url_struct,e := url.Parse(v)
+                                               if e != nil {continue}
+                                               Host_list = append(Host_list, url_struct.Hostname())
+                                       }
+                                       random := int(time.Now().Unix())
+                                       for i:=0;i<len(links);i+=1 {
+                                               url_struct,e := url.Parse(links[i].Url)
+                                               if e != nil {continue}
+                                               url_struct.Host = Host_list[(random+i) % len(Host_list)]
+                                               links[i].Url = url_struct.String()
+                                       }
+                               }
+
                                //qn in expect , set expires
                                if c.Live_want_qn >= c.Live_qn {
                                        expires = int64(exp)
index daced4cf680494d88ed03bfa46c35ab32725ae9d..05642cd7a9f5bb52554790a0035ebed251deefb5 100644 (file)
@@ -48,7 +48,8 @@
     "直播流类型-help": "flv or hls",
     "直播流类型": "hls",
     "直播流保存位置": "./live",
-    "直播流缓冲": 20,
+    "直播hls流均衡-help":"true:使用所有hls服务器",
+    "直播hls流均衡": true,
     "ass-help": "只有保存直播流时才考虑生成ass,ass编码默认GB18030(可选utf-8)",
     "生成Ass弹幕": true,
     "Ass编码": "GB18030",