]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Improve 重试不影响直播回放
authorqydysky <qydysky@foxmail.com>
Thu, 3 Aug 2023 14:53:14 +0000 (22:53 +0800)
committerqydysky <qydysky@foxmail.com>
Thu, 3 Aug 2023 14:53:14 +0000 (22:53 +0800)
Reply/stream.go

index e3e2d840592e8ab3fec9a4101e4abd1d930b60c0..200be3ec39769e6016ad16110d975a8efa3bc2ae 100644 (file)
@@ -790,7 +790,7 @@ func (t *M4SStream) saveStreamFlv() (e error) {
                                                        t.first_buf = make([]byte, len(front_buf))
                                                        copy(t.first_buf, front_buf)
                                                        // fmt.Println("write front_buf")
-                                                       t.Stream_msg.PushLock_tag(`data`, t.first_buf)
+                                                       // t.Stream_msg.PushLock_tag(`data`, t.first_buf)
                                                        t.msg.Push_tag(`load`, t)
                                                }
                                                if keyframe.Size() != 0 {
@@ -1401,10 +1401,31 @@ func (t *M4SStream) PusherToHttp(w http.ResponseWriter, r *http.Request, startFu
        }
 
        //写入头
-       if _, err := w.Write(t.getFirstBuf()); err != nil {
-               return err
-       } else if flushSupport {
-               flusher.Flush()
+       {
+               retry := 5
+               for retry > 0 {
+                       select {
+                       case <-r.Context().Done():
+                               break
+                       default:
+                       }
+
+                       if len(t.getFirstBuf()) != 0 {
+                               if _, err := w.Write(t.getFirstBuf()); err != nil {
+                                       return err
+                               } else if flushSupport {
+                                       flusher.Flush()
+                               }
+                               break
+                       }
+
+                       time.Sleep(time.Second)
+                       retry -= 1
+               }
+               if retry < 0 {
+                       w.WriteHeader(http.StatusNotFound)
+                       return errors.New("no stream")
+               }
        }
 
        //写入快速启动缓冲