]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Improve 多次接收开播信息不会切片
authorqydysky <qydysky@foxmail.com>
Thu, 4 Jul 2024 14:29:13 +0000 (14:29 +0000)
committerqydysky <qydysky@foxmail.com>
Thu, 4 Jul 2024 14:29:13 +0000 (14:29 +0000)
Reply/F.go
Reply/Reply.go
bili_danmu.go

index b3fb07c65056ed2bc9899183e12164b460b6dcd9..b91b5de28615a75338aa61e35bc2574e908d4cdf 100644 (file)
@@ -319,38 +319,37 @@ func StreamOStart(common *c.Common, roomid int) {
 }
 
 // 停止实例
-//
-// -2 其他房间
-// -1 所有房间
-// 针对某房间
-func StreamOStop(roomid int) {
-       switch roomid {
-       case -2: // 其他房间
-               c.StreamO.Range(func(_roomid, v interface{}) bool {
-                       if c.C.Roomid == _roomid {
-                               return true
-                       }
-                       if !pctx.Done(v.(*M4SStream).Status) {
-                               v.(*M4SStream).Stop()
-                       }
-                       c.StreamO.Delete(_roomid)
-                       return true
-               })
-       case -1: // 所有房间
-               c.StreamO.Range(func(k, v interface{}) bool {
-                       if !pctx.Done(v.(*M4SStream).Status) {
-                               v.(*M4SStream).Stop()
-                       }
-                       c.StreamO.Delete(k)
+func StreamOStopAll() {
+       c.StreamO.Range(func(k, v interface{}) bool {
+               if !pctx.Done(v.(*M4SStream).Status) {
+                       v.(*M4SStream).Stop()
+               }
+               c.StreamO.Delete(k)
+               return true
+       })
+}
+
+// 停止实例
+func StreamOStopOther(roomid int) {
+       c.StreamO.Range(func(_roomid, v interface{}) bool {
+               if roomid == _roomid {
                        return true
-               })
-       default: // 针对某房间
-               if v, ok := c.StreamO.Load(roomid); ok {
-                       if !pctx.Done(v.(*M4SStream).Status) {
-                               v.(*M4SStream).Stop()
-                       }
-                       c.StreamO.Delete(roomid)
                }
+               if !pctx.Done(v.(*M4SStream).Status) {
+                       v.(*M4SStream).Stop()
+               }
+               c.StreamO.Delete(_roomid)
+               return true
+       })
+}
+
+// 停止实例
+func StreamOStop(roomid int) {
+       if v, ok := c.StreamO.Load(roomid); ok {
+               if !pctx.Done(v.(*M4SStream).Status) {
+                       v.(*M4SStream).Stop()
+               }
+               c.StreamO.Delete(roomid)
        }
 }
 
index 434d54e7ab1a27cf3478db72810929984d879c1f..7ece581ade3766289abee2c5fddaecf2cbc791e5 100644 (file)
@@ -855,12 +855,10 @@ func (t replyF) live(s string) {
                //开始录制
                go func() {
                        if v, ok := t.common.K_v.LoadV(`仅保存当前直播间流`).(bool); ok && v {
-                               StreamOStop(-2) //停止其他房间录制
+                               StreamOStopOther(t.common.Roomid) //停止其他房间录制
                        }
                        if _, e := recStartEnd.RecStartCheck.Run(context.Background(), t.common); e == nil {
-                               if StreamOStatus(t.common.Roomid) {
-                                       StreamOCut(t.common.Roomid)
-                               } else {
+                               if !StreamOStatus(t.common.Roomid) {
                                        StreamOStart(t.common.Copy(), t.common.Roomid)
                                }
                        } else {
index 11dddfb7abdad82b36bf1800bfe8b051fa0e73eb..dd1a7e5ceb5332616a13fbf9a030bd1487c0c214 100644 (file)
@@ -341,7 +341,7 @@ func Start() {
                                                        exitSign = true
                                                        ws_c.Close()
                                                        danmulog.L(`I: `, "停止,等待服务器断开连接")
-                                                       reply.StreamOStop(-1) //停止录制
+                                                       reply.StreamOStopAll() //停止录制
                                                        return true
                                                },
                                                `exit_room`: func(_ any) bool { //退出当前房间
@@ -356,7 +356,7 @@ func Start() {
                                                        exitloop = true
                                                        ws_c.Close()
                                                        if v, ok := c.C.K_v.LoadV(`仅保存当前直播间流`).(bool); ok && v {
-                                                               reply.StreamOStop(-2) //停止其他房间录制
+                                                               reply.StreamOStopOther(c.C.Roomid) //停止其他房间录制
                                                        }
                                                        return true
                                                },
@@ -414,7 +414,7 @@ func Start() {
 
                { //附加功能 直播流停止 ws信息保存
                        reply.SaveToJson.Close()
-                       reply.StreamOStop(-1)
+                       reply.StreamOStopAll()
                }
        }
 }