]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
切换房间flv流内存泄漏修复
authorqydysky <qydysky@foxmail.com>
Tue, 11 May 2021 00:34:49 +0000 (08:34 +0800)
committerqydysky <qydysky@foxmail.com>
Tue, 11 May 2021 00:34:49 +0000 (08:34 +0800)
Reply/F.go
demo/config/config_K_v.json
demo/go.mod
demo/go.sum
go.mod
go.sum

index dcbd5b3c0d750b96eb0d53c362cf0f2c664325c9..2584f7660797dd9a825020efb574a48420845fbc 100644 (file)
@@ -421,12 +421,6 @@ func Savestreamf(){
 
                savestream.wait = s.Init()
                savestream.cancel = s.Init()
-               
-               rr := reqf.New()
-               go func(){
-                       savestream.cancel.Wait()
-                       rr.Close()
-               }()
 
                CookieM := make(map[string]string)
                c.Cookie.Range(func(k,v interface{})(bool){
@@ -435,6 +429,11 @@ func Savestreamf(){
                })
 
                {//重试
+                       rr := reqf.New()
+                       go func(){
+                               savestream.cancel.Wait()
+                               rr.Close()
+                       }()
                        l.L(`I: `,"尝试连接live")
                        if e := rr.Reqf(reqf.Rval{
                                Url:c.Live[0],
@@ -653,7 +652,8 @@ func Savestreamf(){
                                                                        out.Write(req.keyframe[i])
                                                                }
                                                                // reqs_keyframe[0] = [][]byte{reqs_keyframe[0][len(reqs_keyframe[0])-1]} 
-                                                       } else if len(reqs_keyframe[len(reqs_used_id)-1]) > 5 {
+                                                       } else if len(reqs_keyframe[len(reqs_used_id)-1]) > 3 {
+                                                               l.L(`T: `,"flv强行拼合")
                                                                // fmt.Println(`强行merge`)
                                                                // reqs_remove_id = append(reqs_remove_id, reqs_used_id[0])
                                                                // last_time_stamp = int(F.Btoi32([]byte{reqs_keyframe[0][0][7], reqs_keyframe[0][0][4], reqs_keyframe[0][0][5], reqs_keyframe[0][0][6]},0))
@@ -674,7 +674,7 @@ func Savestreamf(){
                                                                        savestream.flv_stream.Push_tag("stream",req.keyframe[i])
                                                                        out.Write(req.keyframe[i])
                                                                }
-                                                       } else if len(reqs_keyframe[len(reqs_used_id)-1]) > 2 {
+                                                       } else if len(reqs_keyframe[len(reqs_used_id)-1]) > 1 {
                                                                // fmt.Println(`merge 旧连接退出`)
                                                                reqs_used_id[0].close()
                                                                // reqs_used_id = reqs_used_id[1:]
@@ -696,7 +696,8 @@ func Savestreamf(){
                                                                // }
                                                        }
                                                } else {
-                                                       fmt.Println(`merge成功`,len(b))
+                                                       // fmt.Println(`merge成功`,len(b))
+                                                       l.L(`T: `,"flv拼合成功")
 
                                                        last_keyframe_timestamp = success_last_keyframe_timestamp
        
@@ -718,6 +719,7 @@ func Savestreamf(){
                                        },
                                        // 11区        1
                                        `close`:func(data interface{})(bool){
+                                               // defer l.L(`I: `,"处理退出")
                                                reqs_used_id = []id_close{}
                                                // reqs_remove_id = []id_close{}
                                                reqs_keyframe = [][][]byte{}
@@ -728,11 +730,11 @@ func Savestreamf(){
                        }
 
                        //连接保持
-                       for savestream.cancel.Islive() {
+                       for {
                                //获取超时时间
                                link,exp,e := flv_get_link(c.Live[0])
                                if e != nil {
-                                       l.L(`E: `,e)
+                                       l.L(`W: `,e)
                                        break
                                }
 
@@ -744,8 +746,13 @@ func Savestreamf(){
 
                                //新建请求
                                go func(r *reqf.Req,rval reqf.Rval){
+                                       go func(){
+                                               savestream.cancel.Wait()
+                                               req.Close()
+                                       }()
+
                                        if e := r.Reqf(rval);e != nil {
-                                               l.L(`E: `,e)
+                                               l.L(`W: `,e)
                                                return
                                        }
                                }(req,reqf.Rval{
@@ -771,6 +778,7 @@ func Savestreamf(){
 
                                //解析
                                go func(http_error chan error,bc chan[]byte,item *link_stream){
+                                       // defer l.L(`I: `,"解析退出")
                                        var (
                                                buf []byte
                                                skip_buf_size int
@@ -813,6 +821,11 @@ func Savestreamf(){
                                                        }
 
                                                        // total := 0
+                                                       // var tmp_buf []byte
+                                                       // {
+                                                       //      tmp_buf = make([]byte,len(buf))
+                                                       //      copy(tmp_buf, buf)
+                                                       // }
                                                        item.keyframe = list
                                                        // item.keyframe = make([][]byte,len(list))
                                                        // for i:=0;i<len(list);i+=1 {
@@ -826,7 +839,7 @@ func Savestreamf(){
                                                        {
                                                                last_keyframe := list[len(list)-1]
                                                                cut_offset := bytes.LastIndex(buf, last_keyframe)+len(last_keyframe)
-                                                               // fmt.Println(`buf截断 剩余`,len(buf), `下一header`,buf[:11])
+                                                               // fmt.Printf("buf截断 当前%d=>%d 下一header %b\n",len(buf),len(buf)-cut_offset,buf[:11])
                                                                buf = buf[cut_offset:]
                                                        }
 
@@ -847,11 +860,14 @@ func Savestreamf(){
                                        case e :=<- http_error:
                                                l.L(`W: `,`连接`,item.id.Id,e)
                                        }
-                                       if exit_sign {break}
+                                       if exit_sign {
+                                               //退出
+                                               // l.L(`T: `,"chan退出")
+                                               break
+                                       }
                                }
                                
                                l.L(`I: `,"flv过期,开始新连接")
-                               // fmt.Println(`过期`)
        
                                //即将过期,刷新c.Live
                                F.Get(`Liveing`)
@@ -948,7 +964,7 @@ func Savestreamf(){
                                links,file_add,exp,e := hls_get_link(c.Live[0],last_download)
 
                                if e != nil && !reqf.IsTimeout(e) {
-                                       l.L(`E: `,e)
+                                       l.L(`W: `,e)
                                        break
                                }
 
@@ -1106,7 +1122,10 @@ func Savestreamf(){
                //set ro ``
                savestream.path = ``
 
-               if !savestream.cancel.Islive() {break}//cancel
+               if !savestream.cancel.Islive() {
+                       // l.L(`I: `,"退出")
+                       break
+               }//cancel
                /*
                        Savestream需要外部组件
                        ffmpeg http://ffmpeg.org/download.html
@@ -1422,12 +1441,12 @@ func init() {
        
                                lessdanmu.Lock()
                                if ptk := lessdanmu.limit.PTK();ptk == lessdanmu.max_num {
-                                       if lessdanmu.threshold > 0.01 {
-                                               lessdanmu.threshold -= 0.01
+                                       if lessdanmu.threshold > 0.03 {
+                                               lessdanmu.threshold -= 0.03
                                        }
                                } else if ptk == 0 {
-                                       if lessdanmu.threshold < 0.99 {
-                                               lessdanmu.threshold += 0.01
+                                       if lessdanmu.threshold < 0.97 {
+                                               lessdanmu.threshold += 0.03
                                        }
                                }
                                lessdanmu.Unlock()
index fffeb66200599e134d8db7f370e482d2cbc9af61..9f324c7e76c5a664adec2fb84cc29da33fc0abb7 100644 (file)
@@ -55,7 +55,7 @@
     "弹幕合并": true,
     "相似弹幕忽略": true,
     "每10秒显示弹幕数-help": "为0时禁用,相似弹幕忽略需设为true",
-    "每10秒显示弹幕数": 14,
+    "每10秒显示弹幕数": 10,
     "精简弹幕": true,
     "弹幕机": "",
     "反射弹幕机": true,
index 1a50dda7c72472cb6a81289594f445f986035822..aff7a8263ff39e372a224bd44ea52fc46a9e81b8 100644 (file)
@@ -14,7 +14,7 @@ require (
        github.com/miekg/dns v1.1.41 // indirect
        github.com/mitchellh/mapstructure v1.4.1 // indirect
        github.com/qydysky/bili_danmu v0.5.8
-       github.com/qydysky/part v0.5.13 // indirect
+       github.com/qydysky/part v0.5.14 // indirect
        github.com/shirou/gopsutil v3.21.4+incompatible // indirect
        github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
        github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
index dfbaf667fef219a1a900e2f4babeb785005a7fe0..ffcf7598657d0acac1a30bebc42fa25e41e8df73 100644 (file)
@@ -278,6 +278,8 @@ github.com/qydysky/part v0.5.12 h1:HnXJ7NmL5kvpFwPSpz5D5Kmg50mTblRP6tIufVsXP+U=
 github.com/qydysky/part v0.5.12/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg=
 github.com/qydysky/part v0.5.13 h1:Y1SXoT5ZKCBURoP63G3iOx17kJKlXHpUVNE+oJVFp3o=
 github.com/qydysky/part v0.5.13/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg=
+github.com/qydysky/part v0.5.14 h1:jlroaks8tdBhV1CPIgdW9jtwtwMg4L9OSZH2WzsPfQg=
+github.com/qydysky/part v0.5.14/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg=
 github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad h1:Jtzf509lQrkUMGTV0Sc6IDCAiR1VrBcHrIban7hpye4=
 github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad/go.mod h1:w32TkJNVtTJd4LOS09cq+4uYG6itcN2vsqw+slp44Rg=
 github.com/qydysky/part/msgq v0.0.0-20201213120821-f36e49c32bba h1:1ew9dRpc0Rux0WkWeT/4AE15ynYWmL2D7onJEJIFOB8=
diff --git a/go.mod b/go.mod
index 9a313a61485359a84bcbc462e70184c81d1deff3..6a729317a5fae57551a309b73f1fb32a23693560 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -12,7 +12,7 @@ require (
        github.com/mdp/qrterminal/v3 v3.0.0
        github.com/miekg/dns v1.1.41 // indirect
        github.com/mitchellh/mapstructure v1.4.1 // indirect
-       github.com/qydysky/part v0.5.13
+       github.com/qydysky/part v0.5.14
        github.com/shirou/gopsutil v3.21.4+incompatible // indirect
        github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
        github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
diff --git a/go.sum b/go.sum
index 524c3e985e9ba3b4fa1b685abf9a837ab6de9c1b..f41ff901abbee29d13ea8979bb3a1da6ec09ca85 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -52,6 +52,8 @@ github.com/qydysky/part v0.5.12 h1:HnXJ7NmL5kvpFwPSpz5D5Kmg50mTblRP6tIufVsXP+U=
 github.com/qydysky/part v0.5.12/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg=
 github.com/qydysky/part v0.5.13 h1:Y1SXoT5ZKCBURoP63G3iOx17kJKlXHpUVNE+oJVFp3o=
 github.com/qydysky/part v0.5.13/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg=
+github.com/qydysky/part v0.5.14 h1:jlroaks8tdBhV1CPIgdW9jtwtwMg4L9OSZH2WzsPfQg=
+github.com/qydysky/part v0.5.14/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg=
 github.com/qydysky/part/msgq v0.0.0-20201213120821-f36e49c32bba h1:1ew9dRpc0Rux0WkWeT/4AE15ynYWmL2D7onJEJIFOB8=
 github.com/qydysky/part/msgq v0.0.0-20201213120821-f36e49c32bba/go.mod h1:w32TkJNVtTJd4LOS09cq+4uYG6itcN2vsqw+slp44Rg=
 github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=