]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
内存泄漏
authorqydysky <qydysky@foxmail.com>
Wed, 13 Jan 2021 13:15:38 +0000 (21:15 +0800)
committerqydysky <qydysky@foxmail.com>
Wed, 13 Jan 2021 13:15:38 +0000 (21:15 +0800)
.gitignore
F/api.go
Reply/Msg.go
Reply/gtk.go
demo/config/config_K_v.json
demo/go.mod
demo/go.sum

index f32679797482ae0b176fb27706f593bd66f3b804..56ea13e5f99c753453f2d2d3fcbf77cbb950b54c 100644 (file)
@@ -15,3 +15,4 @@ demo/main
 demo/face/*
 demo/demo.run
 demo/ui/*.glade~
+demo/tts.mp3
index 64dc4c3263b9a87808029c1bb3084e2e0a9961ec..6b8ce37122cc7fc21336546f3bf874cb55ae22b2 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -102,45 +102,74 @@ func (i *api) Get_info() (o *api) {
                        apilog.L(`E: `,err)
                        return
                }
-               res := string(req.Respon)
-               if code := p.Json().GetValFrom(res, "code");code == nil || code.(float64) != 0 {
-                       apilog.L(`E: `,"code", code, p.Json().GetValFrom(res, "message"))
+               var tmp struct{
+                       Code int `json:"code"`
+                       Message string `json:"message"`
+                       Data struct{
+                               Room_info struct{
+                                       Uid int `json:"uid"`
+                                       Room_id int `json:"room_id"`
+                                       Title string `json:"title"`
+                                       Lock_status int `json:"lock_status"`
+                                       Parent_area_id int `json:"parent_area_id"`
+                               } `json:"room_info"`
+                               Anchor_info struct{
+                                       Base_info struct{
+                                               Uname string `json:"uname"`
+                                       } `json:"base_info"`
+                               } `json:"anchor_info"`
+                       } `json:"data"`
+               }
+               if e := json.Unmarshal(req.Respon, &tmp);e != nil{
+                       apilog.L(`E: `,e)
+                       return
+               }
+
+               //错误响应
+               if tmp.Code != 0 {
+                       apilog.L(`E: `,`code`,tmp.Message)
                        return
                }
+
+               //主播
+               if tmp.Data.Anchor_info.Base_info.Uname != `` && c.Uname == ``{
+                       c.Uname = tmp.Data.Anchor_info.Base_info.Uname
+               }
+
                //主播id
-               if Uname,ok := p.Json().GetValFrom(res, "data.anchor_info.base_info.uname").(string);ok && c.Uname == `` {
-                       c.Uname = Uname
+               if tmp.Data.Room_info.Uid != 0{
+                       o.Uid = tmp.Data.Room_info.Uid
+               } else {
+                       apilog.L(`E: `,"data.room_info.parent_area_id = 0")
+                       return
                }
+
                //分区
-               if parent_area_id := p.Json().GetValFrom(res, "data.room_info.parent_area_id");parent_area_id == nil {
-                       apilog.L(`E: `,"data.room_info.parent_area_id", parent_area_id)
-                       return
+               if tmp.Data.Room_info.Parent_area_id != 0{
+                       o.Parent_area_id = tmp.Data.Room_info.Parent_area_id
                } else {
-                       o.Parent_area_id = int(parent_area_id.(float64))
-               }
-               if Uid := p.Json().GetValFrom(res, "data.room_info.uid");Uid == nil {
-                       apilog.L(`E: `,"data.room_info.uid", Uid)
+                       apilog.L(`E: `,"data.room_info.parent_area_id = 0")
                        return
-               } else {
-                       o.Uid = int(Uid.(float64))
                }
 
-               if room_id := p.Json().GetValFrom(res, "data.room_info.room_id");room_id == nil {
-                       apilog.L(`E: `,"data.room_info.room_id", room_id)
-                       return
+               //房间id
+               if tmp.Data.Room_info.Room_id != 0{
+                       o.Roomid = tmp.Data.Room_info.Room_id
                } else {
-                       o.Roomid = int(room_id.(float64))
-               }
-               if title := p.Json().GetValFrom(res, "data.room_info.title");title == nil {
-                       apilog.L(`E: `,"data.room_info.title", title)
+                       apilog.L(`E: `,"data.room_info.room_id = 0")
                        return
-               } else {
-                       c.Title = title.(string)
                }
-               if is_locked := p.Json().GetValFrom(res, "data.room_info.lock_status");is_locked == nil {
-                       apilog.L(`E: `,"data.room_info.is_locked", is_locked)
+               
+               //房间标题
+               if tmp.Data.Room_info.Title != ``{
+                       c.Title = tmp.Data.Room_info.Title
+               } else {
+                       apilog.L(`E: `,"data.room_info.title = ''")
                        return
-               } else if is_locked.(float64) == 1 {
+               }
+
+               //直播间是否被封禁
+               if tmp.Data.Room_info.Lock_status == 1{
                        apilog.L(`W: `,"直播间封禁中")
                        o.Locked = true
                        return
index c07e2fe03fcff93788608359a789b4c9884c07ec..045bd4d46c353806cf1191a39103a9c7577bc1ea 100644 (file)
@@ -1,7 +1,7 @@
 package reply
 
 import (
-       p "github.com/qydysky/part"
+       "encoding/json"
        c "github.com/qydysky/bili_danmu/CV"
        s "github.com/qydysky/part/buf"
 )
@@ -96,18 +96,19 @@ func init(){
 //Msg类型数据处理方法挑选
 //识别cmd字段类型,查找上述map中设置的方法,并将json转为字符串型传入
 func Msg(b []byte) {
-       s := string(b)
-       if cmd := p.Json().GetValFromS(s, "cmd");cmd == nil {
-               msglog.L(`E: `,"cmd", s)
+
+       msglog := msglog.Base_add(`select func`)
+       var tmp struct{
+               Cmd string `json:"cmd"`
+       }
+       if e := json.Unmarshal(b, &tmp);e != nil {
+               msglog.L(`E: `,e)
                return
+       }
+       if F, ok := Msg_map[tmp.Cmd]; ok {
+               if F != nil {F(replyF{}, string(b))}
        } else {
-               var f replyF
-
-               if F, ok := Msg_map[cmd.(string)]; ok {
-                       if F != nil {F(f, s)}
-               } else {
-                       f.defaultMsg(s)
-               }
+               (replyF{}).defaultMsg(string(b))
        }
 
        return 
index fece5a926b2cdafea0e02e5b9abe40e94595eccc..df9a1a9e81d78884eb71c6fd99291dfee282dc2d 100644 (file)
@@ -19,13 +19,6 @@ import (
        c "github.com/qydysky/bili_danmu/CV"
        s "github.com/qydysky/part/buf"
 )
-const (
-       max_danmu = 50
-       max_keep = 5
-       max_img = 500
-)
-
-var appId = "com.github.qydysky.bili_danmu.reply"+p.Sys().GetTime()//时间戳允许多开
 
 type gtk_list struct {
        text *gtk.TextView
@@ -38,11 +31,7 @@ type gtk_item_source struct {
        time time.Time
 }
 
-var pro_style *gtk.CssProvider
-var gtkGetList = list.New()
-
-var imgbuf = make(map[string](*gdk.Pixbuf))
-var keep_list = list.New()
+var gtkGetList = make(map[string]struct{})
 
 var keep_key = map[string]int{
        "face/0default":0,
@@ -58,10 +47,8 @@ var keep_key = map[string]int{
 }
 var (
        Gtk_on bool
-       Gtk_Tra bool
        Gtk_img_path string = "face"
-       Gtk_danmuChan chan string = make(chan string, 1000)
-       Gtk_danmuChan_uid chan string = make(chan string, 1000)
+       Gtk_danmu_pool = make(map[string]string)
 )
 
 func init(){
@@ -70,8 +57,7 @@ func init(){
        //使用带tag的消息队列在功能间传递消息
        Danmu_mq.Pull_tag(map[string]func(interface{})(bool){
                `danmu`:func(data interface{})(bool){//弹幕
-                       Gtk_danmuChan_uid <- data.(Danmu_mq_t).uid
-                       Gtk_danmuChan <- data.(Danmu_mq_t).msg
+                       Gtk_danmu_pool[data.(Danmu_mq_t).uid] = data.(Danmu_mq_t).msg
                        return false
                },
        })
@@ -102,8 +88,13 @@ func Gtk_danmu() {
        var grid0 *gtk.Grid;
        var grid1 *gtk.Grid;
        var in_smooth_roll bool
+       var imgbuf = make(map[string](*gdk.Pixbuf))
+       var keep_list = list.New()
+
+       application, err := gtk.ApplicationNew(
+       "com.github.qydysky.bili_danmu.reply"+p.Sys().GetTime(),//时间戳允许多开
+       glib.APPLICATION_FLAGS_NONE)
 
-       application, err := gtk.ApplicationNew(appId, glib.APPLICATION_FLAGS_NONE)
        if err != nil {log.Println(err);return}
 
        application.Connect("startup", func() {
@@ -287,8 +278,7 @@ func Gtk_danmu() {
                imgbuf["face/0default"],_ = gdk.PixbufNewFromFileAtSize("face/0default", 40, 40);
 
                {
-                       var e error
-                       if pro_style,e = gtk.CssProviderNew();e == nil{
+                       if pro_style,e := gtk.CssProviderNew();e == nil{
                                if e = pro_style.LoadFromPath(`ui/1.css`);e == nil{
                                        if scr := win.GetScreen();scr != nil {
                                                gtk.AddProviderForScreen(scr,pro_style,gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
@@ -330,7 +320,7 @@ func Gtk_danmu() {
                                } else {
                                        pixbuf,e = gdk.PixbufNewFromFileAtSize(img_src, 40, 40);
                                        if e == nil {
-                                               if len(imgbuf) > max_img {
+                                               if v,ok := K_v[`gtk_内存头像数量`].(int);ok && len(imgbuf) > v {
                                                        for k,_ := range imgbuf {delete(imgbuf,k);break}
                                                }
                                                imgbuf[img_src],e = gdk.PixbufCopy(pixbuf)
@@ -360,7 +350,7 @@ func Gtk_danmu() {
                                        back index:0
                                */
                                var InsertIndex int = keep_list.Len()
-                               if sec > InsertIndex / max_keep {//max_keep不是指最大值,而是当list太大时,sec小的将直接跳过
+                               if sec > InsertIndex / 5 {//5不是指最大值,而是当list太大时,sec小的将直接跳过
                                        var cu_To = time.Now().Add(time.Second * time.Duration(sec))
                                        var hasInsert bool
                                        for el := keep_list.Front(); el != nil; el = el.Next(){
@@ -423,11 +413,13 @@ func Gtk_danmu() {
                                        }
                                        return
                                })
-                               if len(Gtk_danmuChan) == 0 {continue}
-                               glib.TimeoutAdd(uint(1000 / (len(Gtk_danmuChan) + 1)),func()(bool){
-                                       if len(Gtk_danmuChan) == 0 {return false}
-                                       y(<-Gtk_danmuChan,load_face(<-Gtk_danmuChan_uid))
-                                       return true
+                               glib.TimeoutAdd(uint(1000 / (len(Gtk_danmu_pool) + 1)),func()(bool){
+                                       for uid,msg := range Gtk_danmu_pool {
+                                               delete(Gtk_danmu_pool,uid)
+                                               y(msg,load_face(uid))
+                                               return true
+                                       }
+                                       return false
                                })
                        }
                }()
@@ -460,12 +452,11 @@ func Gtk_danmu() {
                                } else {
                                        in_smooth_roll = false
                                        tmp.SetValue(max)
-                                       loc := int(grid0.Container.GetChildren().Length())/2;
-                                       for loc > max_danmu {
+                                       loc := int(grid0.Container.GetChildren().Length())/2
+                                       for v,ok := K_v[`gtk_保留弹幕数量`].(int);ok && loc > v;loc -= 1{
                                                if i,e := grid0.GetChildAt(0,0); e != nil{i.(*gtk.Widget).Destroy()}
                                                if i,e := grid0.GetChildAt(1,0); e != nil{i.(*gtk.Widget).Destroy()}
                                                grid0.RemoveRow(0)
-                                               loc -= 1
                                        }
                                }
                                old_cu = tmp.GetValue()
@@ -552,10 +543,8 @@ func Gtk_danmu() {
                                default:
                                }
                        }
-                       if gtkGetList.Len() == 0 {return}
-                       el := gtkGetList.Front()
-                       if el == nil {return}
-                       if uid,ok := gtkGetList.Remove(el).(string);ok{
+                       for uid,_ := range gtkGetList {
+                               delete(gtkGetList,uid)
                                go func(){
                                        src := F.Get_face_src(uid)
                                        if src == "" {return}
@@ -566,8 +555,8 @@ func Gtk_danmu() {
                                                Timeout:3,
                                        }); e != nil{log.Println(e);}
                                }()
+                               break
                        }
-
                        return
                })
        })
@@ -603,11 +592,10 @@ func load_face(uid string) (loc string) {
                loc = Gtk_img_path + `/` + uid
                return
        }
-       if gtkGetList.Len() > 1000 {return}
+       if v,ok := K_v[`gtk_头像获取等待最大数量`].(int);ok && len(gtkGetList) > v {return}
        //加入前先行检查
-       for v := gtkGetList.Front();v != nil;v = v.Next() {
-               if v.Value.(string) == uid {return}
-       }
-       gtkGetList.PushBack(uid)
+       if _,ok := gtkGetList[uid];ok {return}
+
+       gtkGetList[uid] = struct{}{}
        return
 }
\ No newline at end of file
index a3a4ef4879195b0886b43b011a7fdde5f831ef8f..1e7acc5ae06decdc5a0a9828b0b21bf9163487da 100644 (file)
     "TTS_使用程序参数":"-autoexit -nodisp -volume 60",
 
     "弹幕-help":"弹幕相关",
-    "弹幕_礼物金额显示阈值":20
+    "弹幕_礼物金额显示阈值":20,
+
+    "gtk":"GTK相关",
+    "gtk_保留弹幕数量":50,
+    "gtk_内存头像数量":100,
+    "gtk_头像获取等待最大数量":100
 }
\ No newline at end of file
index 9e83cc3bd8b5eb52a210359a4d7c3bde63ef4886..268909bd251bbdc78ae686431eb8c566c764c306 100644 (file)
@@ -7,16 +7,15 @@ require (
        github.com/gofrs/uuid v4.0.0+incompatible // indirect
        github.com/gorilla/websocket v1.4.2 // indirect
        github.com/gotk3/gotk3 v0.5.2 // indirect
-       github.com/klauspost/compress v1.11.4 // indirect
+       github.com/klauspost/compress v1.11.6 // indirect
        github.com/miekg/dns v1.1.35 // indirect
        github.com/mitchellh/mapstructure v1.4.0 // indirect
        github.com/qydysky/bili_danmu v0.5.7
-       github.com/qydysky/part v0.3.5-0.20210110025721-48b2732f9fb8 // indirect
+       github.com/qydysky/part v0.3.5-0.20210113130821-3c354d18111a // indirect
        github.com/shirou/gopsutil v3.20.12+incompatible // indirect
        github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
        golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
        golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
-       golang.org/x/sys v0.0.0-20201231184435-2d18734c6014 // indirect
 )
 
 replace (
index 61a2411a2b14962a3b4ea7df783e8c9d56fc901a..bd903df6961555d43cc0ab8420165873d1e84574 100644 (file)
@@ -9,6 +9,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
 github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
+github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
+github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
 github.com/gofrs/uuid v1.2.0 h1:coDhrjgyJaglxSjxuJdqQSSdUpG3w6p1OwN2od6frBU=
 github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
 github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
@@ -30,6 +32,8 @@ github.com/klauspost/compress v1.11.3 h1:dB4Bn0tN3wdCzQxnS8r06kV74qN/TAfaIS0bVE8
 github.com/klauspost/compress v1.11.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
 github.com/klauspost/compress v1.11.4 h1:kz40R/YWls3iqT9zX9AHN3WoVsrAWVyui5sxuLqiXqU=
 github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
+github.com/klauspost/compress v1.11.6 h1:EgWPCW6O3n1D5n99Zq3xXBt9uCwRGvpwGOusOLNBRSQ=
+github.com/klauspost/compress v1.11.6/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
 github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE=
 github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -107,6 +111,8 @@ github.com/qydysky/part v0.3.5-0.20210106133414-a27e61b5ba4b h1:6udRQFyusCP7uMlf
 github.com/qydysky/part v0.3.5-0.20210106133414-a27e61b5ba4b/go.mod h1:SxxNav0Z7DbsDLoG5uxo0wW5EKU/JBu2CAkZzZeLnX0=
 github.com/qydysky/part v0.3.5-0.20210110025721-48b2732f9fb8 h1:d7aM3Ko9vDv0UC9rVEs+30R8Re9wcqPQp7L35/ZpSCQ=
 github.com/qydysky/part v0.3.5-0.20210110025721-48b2732f9fb8/go.mod h1:SxxNav0Z7DbsDLoG5uxo0wW5EKU/JBu2CAkZzZeLnX0=
+github.com/qydysky/part v0.3.5-0.20210113130821-3c354d18111a h1:r+3GSv1/biomzrDSdJ0Sm7dXjDtdj2lqSUBT5FcqHcU=
+github.com/qydysky/part v0.3.5-0.20210113130821-3c354d18111a/go.mod h1:zE9KPP+RD3EQ4wYL14szrB927AU3amyha/2wKPjPWzo=
 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=
@@ -175,6 +181,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
 golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -192,6 +199,10 @@ golang.org/x/sys v0.0.0-20201218084310-7d0127a74742 h1:+CBz4km/0KPU3RGTwARGh/noP
 golang.org/x/sys v0.0.0-20201218084310-7d0127a74742/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20201231184435-2d18734c6014 h1:joucsQqXmyBVxViHCPFjG3hx8JzIFSaym3l3MM/Jsdg=
 golang.org/x/sys v0.0.0-20201231184435-2d18734c6014/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210110051926-789bb1bd4061 h1:DQmQoKxQWtyybCtX/3dIuDBcAhFszqq8YiNeS6sNu1c=
+golang.org/x/sys v0.0.0-20210110051926-789bb1bd4061/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210113000019-eaf3bda374d2 h1:F9vNgpIiamoF+Q1/c78bikg/NScXEtbZSNEpnRelOzs=
+golang.org/x/sys v0.0.0-20210113000019-eaf3bda374d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=