From 59fa296365c2c821b65fc37ed98a5e7b45fa043d Mon Sep 17 00:00:00 2001 From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Wed, 2 Nov 2022 09:00:35 +0800 Subject: [PATCH] =?utf8?q?=E9=98=B2=E6=AD=A2=E8=B4=9F=E6=95=B0=E5=A4=A7?= =?utf8?q?=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- CV/Var.go | 10 ++++------ F/B_I.go | 11 +++++++++++ F/B_I_test.go | 2 +- Reply/fmp4Decode.go | 34 +++++++++++++++++----------------- bili_danmu.go | 7 +++++++ 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/CV/Var.go b/CV/Var.go index 407440d..35264f3 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -5,6 +5,7 @@ import ( "errors" "flag" "io" + "testing" "time" file "github.com/qydysky/part/file" @@ -49,7 +50,7 @@ type Common struct { ReqPool *idpool.Idpool //请求池 } -func (t *Common) init() Common { +func (t *Common) Init() Common { t.Qn = map[int]string{ // no change 20000: "4K", 10000: "原画", @@ -74,6 +75,7 @@ func (t *Common) init() Common { ckv = flag.String("ckv", "", "自定义配置KV文件,将会覆盖config_K_v配置") roomIdP = flag.Int("r", 0, "roomid") ) + testing.Init() flag.Parse() t.Roomid = *roomIdP @@ -89,10 +91,6 @@ func (t *Common) init() Common { } } - if t.K_v.Len() == 0 { - panic("未能加载配置") - } - if *ckv != "" { if bb, err := file.New(*ckv, 0, true).ReadAll(100, 1<<16); err != nil { if errors.Is(err, io.EOF) { @@ -178,7 +176,7 @@ func (t *Common) init() Common { return *t } -var C = new(Common).init() +var C = new(Common).Init() // 消息队列 type Danmu_Main_mq_item struct { diff --git a/F/B_I.go b/F/B_I.go index 8c93fa2..4fe5de1 100644 --- a/F/B_I.go +++ b/F/B_I.go @@ -74,6 +74,17 @@ func Btoi64(b []byte, offset int) int64 { return btoi64(b[offset : offset+8]) } +func Btoi(b []byte, offset int, size int) int64 { + if size > 8 { + panic("最大8位") + } + var buf = b[offset : offset+size] + for len(buf) < 8 { + buf = append([]byte{0x00}, buf...) + } + return btoi64(buf) +} + func Btoi32(b []byte, offset int) int32 { for len(b) < 4 { b = append([]byte{0x00}, b...) diff --git a/F/B_I_test.go b/F/B_I_test.go index bd1bc9c..05d36e6 100644 --- a/F/B_I_test.go +++ b/F/B_I_test.go @@ -3,7 +3,7 @@ package F import "testing" func TestBtoi32(t *testing.T) { - t.Log(Btoi64([]byte{0xd6, 0xfd, 0x62, 0x50}, 0)) + t.Log(Btoi64([]byte{0xff, 0x0f, 0xff, 0xff}, 0)) } func TestItob32(t *testing.T) { diff --git a/Reply/fmp4Decode.go b/Reply/fmp4Decode.go index 919488a..b1a2880 100644 --- a/Reply/fmp4Decode.go +++ b/Reply/fmp4Decode.go @@ -27,7 +27,7 @@ func (t *Fmp4Decoder) Init_fmp4(buf []byte) error { } moovI = cu + moovI - 4 cu = moovI - moovE := moovI + int(F.Btoi32(buf, moovI)) + moovE := moovI + int(F.Btoi(buf, moovI, 4)) if moovE > len(buf) { return errors.New("moov包破损") } @@ -40,7 +40,7 @@ func (t *Fmp4Decoder) Init_fmp4(buf []byte) error { } trakI = cu + trakI - 4 cu = trakI - trakE := trakI + int(F.Btoi32(buf, trakI)) + trakE := trakI + int(F.Btoi(buf, trakI, 4)) if trakE > moovE { return errors.New("trak包破损") } @@ -52,7 +52,7 @@ func (t *Fmp4Decoder) Init_fmp4(buf []byte) error { } tkhdI = cu + tkhdI - 4 cu = tkhdI - tkhdE := tkhdI + int(F.Btoi32(buf, tkhdI)) + tkhdE := tkhdI + int(F.Btoi(buf, tkhdI, 4)) if tkhdE > trakE { return errors.New("tkhd包破损") } @@ -64,7 +64,7 @@ func (t *Fmp4Decoder) Init_fmp4(buf []byte) error { } mdiaI = cu + mdiaI - 4 cu = mdiaI - mdiaE := mdiaI + int(F.Btoi32(buf, mdiaI)) + mdiaE := mdiaI + int(F.Btoi(buf, mdiaI, 4)) if mdiaE > trakE { return errors.New("mdia包破损") } @@ -76,7 +76,7 @@ func (t *Fmp4Decoder) Init_fmp4(buf []byte) error { } mdhdI = cu + mdhdI - 4 cu = mdhdI - mdhdE := mdhdI + int(F.Btoi32(buf, mdhdI)) + mdhdE := mdhdI + int(F.Btoi(buf, mdhdI, 4)) if mdhdE > mdiaE { return errors.New("mdhd包破损") } @@ -88,18 +88,18 @@ func (t *Fmp4Decoder) Init_fmp4(buf []byte) error { } hdlrI = cu + hdlrI - 4 cu = hdlrI - hdlrE := hdlrI + int(F.Btoi32(buf, hdlrI)) + hdlrE := hdlrI + int(F.Btoi(buf, hdlrI, 4)) if hdlrE > mdiaE { return errors.New("hdlr包破损") } - tackId := int(F.Btoi32(buf, tkhdI+20)) + tackId := int(F.Btoi(buf, tkhdI+20, 4)) if t.traks == nil { t.traks = make(map[int]trak) } t.traks[tackId] = trak{ trackID: tackId, - timescale: int(F.Btoi32(buf, mdhdI+20)), + timescale: int(F.Btoi(buf, mdhdI+20, 4)), handlerType: buf[hdlrI+16], } } @@ -129,7 +129,7 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av } moofI = cu + moofI - 4 cu = moofI - moofE := moofI + int(F.Btoi32(buf, moofI)) + moofE := moofI + int(F.Btoi(buf, moofI, 4)) if moofE > len(buf) { break } @@ -151,7 +151,7 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av } trafI = cu + trafI - 4 cu = trafI - trafE := trafI + int(F.Btoi32(buf, trafI)) + trafE := trafI + int(F.Btoi(buf, trafI, 4)) if trafE > moofE { break } @@ -164,7 +164,7 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av } tfhdI = cu + tfhdI - 4 cu = tfhdI - tfhdE := tfhdI + int(F.Btoi32(buf, tfhdI)) + tfhdE := tfhdI + int(F.Btoi(buf, tfhdI, 4)) if tfhdE > trafE { err = errors.New("tfhd包破损") break @@ -178,7 +178,7 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av } tfdtI = cu + tfdtI - 4 cu = tfdtI - tfdtE := tfdtI + int(F.Btoi32(buf, tfdtI)) + tfdtE := tfdtI + int(F.Btoi(buf, tfdtI, 4)) if tfdtE > trafE { err = errors.New("tfdt包破损") break @@ -192,7 +192,7 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av } trunI = cu + trunI - 4 cu = trunI - trunE := trunI + int(F.Btoi32(buf, trunI)) + trunE := trunI + int(F.Btoi(buf, trunI, 4)) if trunE > trafE { err = errors.New("trun包破损") break @@ -207,17 +207,17 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av case 0: timeSize = 4 timeStampIndex = tfdtI + 16 - timeStamp = int(F.Btoi32(buf, tfdtI+16)) + timeStamp = int(F.Btoi(buf, tfdtI+16, 4)) case 1: timeSize = 8 timeStampIndex = tfdtI + 12 timeStamp = int(F.Btoi64(buf, tfdtI+12)) } - track, ok := t.traks[int(F.Btoi32(buf, tfhdI+12))] + track, ok := t.traks[int(F.Btoi(buf, tfhdI+12, 4))] if !ok { err = errors.New("找不到trak") - // log.Default().Println(`cant find trak`, int(F.Btoi32(buf, tfhdI+12))) + // log.Default().Println(`cant find trak`, int(F.Btoi(buf, tfhdI+12))) continue } @@ -275,7 +275,7 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av } mdatI = cu + mdatI - 4 cu = mdatI - mdatE := mdatI + int(F.Btoi32(buf, mdatI)) + mdatE := mdatI + int(F.Btoi(buf, mdatI, 4)) if mdatE > len(buf) { err = errors.New("mdat包破损") break diff --git a/bili_danmu.go b/bili_danmu.go index f0b594e..66868ac 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -66,6 +66,13 @@ func Start() { } } + //检查配置 + { + if c.C.K_v.Len() == 0 { + panic("未能加载配置") + } + } + { var ( change_room_chan = make(chan struct{}) -- 2.39.2