]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Improve 优化fmp4重试机制
authorqydysky <32743305+qydysky@users.noreply.github.com>
Mon, 6 Feb 2023 11:31:42 +0000 (19:31 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Mon, 6 Feb 2023 11:31:42 +0000 (19:31 +0800)
CV/Var.go
Reply/stream.go

index 3e215e22b0b2e63345cbf21453ccf56c59e983f1..3aefd16aa33c590e6510d95735324aafe60270af 100644 (file)
--- a/CV/Var.go
+++ b/CV/Var.go
@@ -57,9 +57,10 @@ type Common struct {
 }
 
 type LiveQn struct {
-       Url      string
-       ReUpTime time.Time
-       Expires  int //流到期时间
+       Url          string
+       ReUpTime     time.Time
+       disableCount int
+       Expires      int //流到期时间
 }
 
 func (t *LiveQn) Host() string {
@@ -74,10 +75,31 @@ func (t *LiveQn) Valid() bool {
        return time.Now().After(t.ReUpTime)
 }
 
+// 自动停用机制
+func (t *LiveQn) DisableAuto() {
+       if time.Now().After(t.ReUpTime.Add(time.Minute).Add(time.Second * time.Duration(10*t.disableCount))) {
+               t.disableCount = 0
+       }
+       t.disableCount += 1
+       t.ReUpTime = time.Now().Add(time.Minute).Add(time.Second * time.Duration(10*t.disableCount))
+}
+
 func (t *LiveQn) Disable(reUpTime time.Time) {
        t.ReUpTime = reUpTime
 }
 
+// 自动停用机制
+func (t *Common) DisableLiveAuto(host string) {
+       for i := 0; i < len(t.Live); i++ {
+               if liveUrl, e := url.Parse(t.Live[i].Url); e == nil {
+                       if host == liveUrl.Host {
+                               t.Live[i].DisableAuto()
+                               break
+                       }
+               }
+       }
+}
+
 func (t *Common) DisableLive(host string, reUpTime time.Time) {
        for i := 0; i < len(t.Live); i++ {
                if liveUrl, e := url.Parse(t.Live[i].Url); e == nil {
index 74eafc38b197aa10dca0fbee990d4d8f4849d63c..8701f41c14b89815e965c5b8f7433d9b172906b9 100644 (file)
@@ -299,7 +299,7 @@ func (t *M4SStream) fetchParseM3U8() (m4s_links []*m4s_link_item, m3u8_addon []b
 
                if err := r.Reqf(rval); err != nil {
                        // 1min后重新启用
-                       t.common.Live[k].Disable(time.Now().Add(time.Minute))
+                       t.common.Live[k].DisableAuto()
                        t.log.L("W: ", fmt.Sprintf("服务器 %s 发生故障 %s", m3u8_url.Host, err.Error()))
                        if t.common.ValidLive() == nil {
                                e = errors.New("全部流服务器发生故障")
@@ -416,7 +416,7 @@ func (t *M4SStream) fetchParseM3U8() (m4s_links []*m4s_link_item, m3u8_addon []b
                        noe, _ := t.last_m4s.getNo()
                        if timed > 5 && nos-noe == 0 {
                                // 1min后重新启用
-                               t.common.Live[k].Disable(time.Now().Add(time.Minute))
+                               t.common.Live[k].DisableAuto()
                                t.log.L("W: ", fmt.Sprintf("服务器 %s 发生故障 %d 秒产出了 %d 切片", m3u8_url.Host, int(timed), nos-noe))
                                if t.common.ValidLive() == nil {
                                        e = errors.New("全部切片服务器发生故障")
@@ -791,8 +791,8 @@ func (t *M4SStream) saveStreamM4s() (e error) {
                                if v.status == 3 {
                                        if linkUrl, e := url.Parse(v.Url); e == nil {
                                                oldHost := linkUrl.Host
-                                               // 将此切片服务器设置1min停用
-                                               t.common.DisableLive(oldHost, time.Now().Add(time.Minute))
+                                               // 将此切片服务器设置停用
+                                               t.common.DisableLiveAuto(oldHost)
                                                // 从其他服务器获取此切片
                                                if vl := t.common.ValidLive(); vl == nil {
                                                        return errors.New(`全部流服务器故障`)
@@ -831,11 +831,11 @@ func (t *M4SStream) saveStreamM4s() (e error) {
 
                                        if e := r.Reqf(reqConfig); e != nil && !errors.Is(e, io.EOF) {
                                                // t.log.L(`T: `, `下载错误`, link.Base, e)
-                                               if !reqf.IsTimeout(e) {
-                                                       // 发生非超时错误
-                                                       link.err = e
-                                                       link.tryDownCount = 3 // 设置切片状态为下载失败
-                                               }
+                                               // if !reqf.IsTimeout(e) {
+                                               //      // 发生非超时错误
+                                               //      link.err = e
+                                               //      link.tryDownCount = 3 // 设置切片状态为下载失败
+                                               // }
                                                link.status = 3 // 设置切片状态为下载失败
                                        } else {
                                                // if usedt := r.UsedTime.Seconds(); usedt > 700 {