]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Fix panic: close of closed channel stream.go:1336
authorqydysky <32743305+qydysky@users.noreply.github.com>
Tue, 21 Mar 2023 15:29:30 +0000 (23:29 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Tue, 21 Mar 2023 15:29:30 +0000 (23:29 +0800)
Reply/stream.go
go.mod
go.sum

index 7eb57a4db27275ddbf82c7270be63e86fcf9e2f0..c75b549729944176a24c2de5e114533b2b1dc78e 100644 (file)
@@ -628,11 +628,40 @@ func (t *M4SStream) saveStreamFlv() (e error) {
                        return
                }
 
-               // 如果被主动关闭,则退出saveStreamFlv,否则继续尝试其他live
-               s := signal.Init()
+               CookieM := make(map[string]string)
+               t.common.Cookie.Range(func(k, v interface{}) bool {
+                       CookieM[k.(string)] = v.(string)
+                       return true
+               })
 
                //开始获取
                r := t.reqPool.Get()
+               //检查
+               if e := r.Reqf(reqf.Rval{
+                       Url:              surl.String(),
+                       NoResponse:       true,
+                       JustResponseCode: true,
+                       Proxy:            t.common.Proxy,
+                       Timeout:          5000,
+                       Header: map[string]string{
+                               `Host`:            surl.Host,
+                               `User-Agent`:      `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0`,
+                               `Accept`:          `*/*`,
+                               `Accept-Language`: `zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2`,
+                               `Origin`:          `https://live.bilibili.com`,
+                               `Connection`:      `keep-alive`,
+                               `Pragma`:          `no-cache`,
+                               `Cache-Control`:   `no-cache`,
+                               `Referer`:         "https://live.bilibili.com/",
+                               `Cookie`:          reqf.Map_2_Cookies_String(CookieM),
+                       },
+               }); e != nil && reqf.IsTimeout(e) {
+                       t.reqPool.Put(r)
+                       continue
+               }
+
+               // 如果被主动关闭,则退出saveStreamFlv,否则继续尝试其他live
+               s := signal.Init()
                {
                        go func() {
                                tsc, tscf := t.Status.WaitC()
@@ -701,7 +730,7 @@ func (t *M4SStream) saveStreamFlv() (e error) {
                                        buff.Append(buf[:n])
                                        if e != nil {
                                                out.Close()
-                                               t.Stream_msg.Push_tag(`close`, nil)
+                                               t.Stream_msg.PushLock_tag(`close`, nil)
                                                break
                                        }
                                        leastReadUnix.Store(time.Now().Unix())
@@ -731,13 +760,13 @@ func (t *M4SStream) saveStreamFlv() (e error) {
                                                        copy(t.first_buf, front_buf)
                                                        // fmt.Println("write front_buf")
                                                        out.Write(t.first_buf)
-                                                       t.Stream_msg.Push_tag(`data`, t.first_buf)
+                                                       t.Stream_msg.PushLock_tag(`data`, t.first_buf)
                                                }
                                                if len(t.first_buf) != 0 && keyframe.Size() != 0 {
                                                        t.bootBufPush(keyframe.GetPureBuf())
                                                        keyframe.Reset()
                                                        out.Write(t.boot_buf)
-                                                       t.Stream_msg.Push_tag(`data`, t.boot_buf)
+                                                       t.Stream_msg.PushLock_tag(`data`, t.boot_buf)
                                                }
                                                if last_available_offset > 1 {
                                                        // fmt.Println("write Sync")
@@ -751,12 +780,6 @@ func (t *M4SStream) saveStreamFlv() (e error) {
                                buff.Reset()
                        }()
 
-                       CookieM := make(map[string]string)
-                       t.common.Cookie.Range(func(k, v interface{}) bool {
-                               CookieM[k.(string)] = v.(string)
-                               return true
-                       })
-
                        t.log.L(`I: `, `flv下载开始`)
 
                        r.Reqf(reqf.Rval{
@@ -1002,7 +1025,7 @@ func (t *M4SStream) saveStreamM4s() (e error) {
                        if !keyframe.IsEmpty() {
                                t.bootBufPush(keyframe.GetPureBuf())
                                keyframe.Reset()
-                               t.Stream_msg.Push_tag(`data`, t.boot_buf)
+                               t.Stream_msg.PushLock_tag(`data`, t.boot_buf)
                                if out != nil {
                                        out.Write(t.boot_buf, true)
                                        out.Sync()
@@ -1084,7 +1107,7 @@ func (t *M4SStream) saveStreamM4s() (e error) {
        }
 
        // 发送空字节会导致流服务终止
-       t.Stream_msg.Push_tag(`data`, []byte{})
+       t.Stream_msg.PushLock_tag(`data`, []byte{})
 
        if !t.config.save_as_mp4 {
                // 结束
diff --git a/go.mod b/go.mod
index 820998a7dd71ddb4bd592da7455911073c444bcf..d6f5d3112a920f42501fd2c53a8298024a039013 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ require (
        github.com/gofrs/uuid v4.3.0+incompatible
        github.com/gotk3/gotk3 v0.6.1
        github.com/mdp/qrterminal/v3 v3.0.0
-       github.com/qydysky/part v0.24.3
+       github.com/qydysky/part v0.24.4
        github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
        github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
        golang.org/x/text v0.8.0
diff --git a/go.sum b/go.sum
index ffd6f8c78b7a59b8e926276799914575fb041248..ab5857c4964b9283945fcdf5e68852be3fad284a 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -89,6 +89,8 @@ github.com/qydysky/part v0.24.1 h1:St+338RkG5AGlBpcSq29gK5o4tukFOOX8F5x/TMtQG0=
 github.com/qydysky/part v0.24.1/go.mod h1:AQJH+BYeN30eKXjkDqGEtw0vx3wVGplBeOMLSyleEDo=
 github.com/qydysky/part v0.24.3 h1:bRnN+iYydDyYQHjHX+uVQzdSbglmVwwDUz2QSexO/DY=
 github.com/qydysky/part v0.24.3/go.mod h1:AQJH+BYeN30eKXjkDqGEtw0vx3wVGplBeOMLSyleEDo=
+github.com/qydysky/part v0.24.4 h1:JCA1CyggvUNu/B0xKEjnODaUp6rgEi1hjtJwqOTvnaw=
+github.com/qydysky/part v0.24.4/go.mod h1:AQJH+BYeN30eKXjkDqGEtw0vx3wVGplBeOMLSyleEDo=
 github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
 github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=