]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Fix m4s偶尔断流后无法继续录制 #87
authorqydysky <qydysky@foxmail.com>
Wed, 6 Sep 2023 14:17:15 +0000 (22:17 +0800)
committerqydysky <qydysky@foxmail.com>
Wed, 6 Sep 2023 14:17:15 +0000 (22:17 +0800)
Reply/stream.go
demo/config/config_K_v.json

index 2e9f9acf6550a9e181f6c5df6477233fba01bbc9..2cf078bc196f0c7ade807c4a2054932f0e8f9a48 100644 (file)
@@ -883,16 +883,21 @@ func (t *M4SStream) saveStreamM4s() (e error) {
 
        //
        var (
-               buf         = slice.New[byte]()
-               fmp4Decoder = &Fmp4Decoder{}
-               keyframe    = slice.New[byte]()
-               frameCount  = 0
-               to          = 3
+               buf          = slice.New[byte]()
+               fmp4Decoder  = &Fmp4Decoder{}
+               keyframe     = slice.New[byte]()
+               frameCount   = 0
+               to           = 3
+               fmp4UpdateTo = 7.0
+               fmp4Updated  time.Time
        )
 
        if v, ok := t.common.K_v.LoadV(`fmp4切片下载超时s`).(float64); ok && to < int(v) {
                to = int(v)
        }
+       if v, ok := t.common.K_v.LoadV(`fmp4列表更新超时s`).(float64); ok && fmp4UpdateTo < v {
+               fmp4UpdateTo = v
+       }
 
        // 下载循环
        for download_seq := []*m4s_link_item{}; ; {
@@ -1127,19 +1132,25 @@ func (t *M4SStream) saveStreamM4s() (e error) {
                // }
 
                if len(m4s_links) == 0 {
+                       if time.Since(fmp4Updated).Seconds() > fmp4UpdateTo {
+                               t.log.L(`E: `, `fmp4列表更新超时`)
+                               break
+                       }
                        time.Sleep(time.Second)
                        continue
-               } else {
-                       // 设置最后的切片
-                       if t.last_m4s == nil {
-                               t.last_m4s = &m4s_link_item{}
-                       }
-                       for i := len(m4s_links) - 1; i >= 0; i-- {
-                               // fmt.Println("set last m4s", m4s_links[i].Base)
-                               if !m4s_links[i].isInit() && len(m4s_links[i].Base) > 0 {
-                                       m4s_links[i].copyTo(t.last_m4s)
-                                       break
-                               }
+               }
+
+               fmp4Updated = time.Now()
+
+               // 设置最后的切片
+               if t.last_m4s == nil {
+                       t.last_m4s = &m4s_link_item{}
+               }
+               for i := len(m4s_links) - 1; i >= 0; i-- {
+                       // fmt.Println("set last m4s", m4s_links[i].Base)
+                       if !m4s_links[i].isInit() && len(m4s_links[i].Base) > 0 {
+                               m4s_links[i].copyTo(t.last_m4s)
+                               break
                        }
                }
 
@@ -1357,6 +1368,8 @@ func (t *M4SStream) Start() bool {
 
 func (t *M4SStream) Stop() {
        if !t.Status.Islive() {
+               t.log.L(`I: `, `正在等待下载完成...`)
+               t.exitSign.Wait()
                return
        }
        t.exitSign = signal.Init()
index 4798a72b3d8510bccb325321df2a16b5d62f39d8..6cee3cd2f633bfa411b2d2109e47f27042b1011c 100644 (file)
@@ -73,6 +73,7 @@
     "flv断流超时s": 5,
     "flv断流续接": true,
     "fmp4切片下载超时s": 3,
+    "fmp4列表更新超时s": 7,
     "分段时长min-help": "=0为不启动功能,>0为指定分钟数时分段",
     "分段时长min": 0,
     "直播流保存位置": "./live",