]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Dev (#128)
authorqydysky <qydysky@foxmail.com>
Sat, 7 Dec 2024 20:04:11 +0000 (04:04 +0800)
committerGitHub <noreply@github.com>
Sat, 7 Dec 2024 20:04:11 +0000 (04:04 +0800)
* 签到活动已下线

* Fix  ErrBufTooLarge #127

F/api.go
Reply/F.go
Reply/flvDecode.go
Reply/fmp4Decode.go
Reply/stream.go
bili_danmu.go

index 6546c2bfd82dd9438f6780628ab17b47586d3b4e..9ca695a0908fc2c2a533784f2a46ac54d514f763 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -1216,6 +1216,7 @@ func (t *GetFunc) CheckSwitch_FansMedal() (missKey []string) {
 }
 
 // 签到
+// 签到活动已下线
 func Dosign() {
        apilog := apilog.Base_add(`签到`).L(`T: `, `签到`)
        //验证cookie
index 337d713755166e35aa7d6b8ebbf2d19471e888e6..5fdcc9fa3197e39a5f4695deacc390e9f50e82ed 100644 (file)
@@ -1191,6 +1191,9 @@ func init() {
                                                if strings.HasSuffix(v, "mp4") {
                                                        w.Header().Set("Content-Disposition", fmt.Sprintf("inline; filename=\"%s.%d.mp4\"", qref, time.Now().Unix()))
                                                        fmp4Decoder := NewFmp4Decoder()
+                                                       if v, ok := c.C.K_v.LoadV(`debug模式`).(bool); ok && v {
+                                                               fmp4Decoder.Debug = true
+                                                       }
                                                        if v, ok := c.C.K_v.LoadV(`fmp4音视频时间戳容差s`).(float64); ok && v > 0.1 {
                                                                fmp4Decoder.AVTDiff = v
                                                        }
index 7f99a719229d247cb72c24777184bcf9668718a1..5ed5111f3afe3248990b88ddd0e9f8f0b14f21c6 100644 (file)
@@ -298,12 +298,12 @@ func (t *FlvDecoder) Cut(reader io.Reader, startT, duration time.Duration, w io.
        }
 
        for c := 0; err == nil && !over; c++ {
-               n, e := reader.Read(buf)
-               if n == 0 && errors.Is(e, io.EOF) {
-                       return io.EOF
-               }
-               err = buff.Append(buf[:n])
                if buff.Size() < bufSize {
+                       n, e := reader.Read(buf)
+                       if n == 0 && errors.Is(e, io.EOF) {
+                               return io.EOF
+                       }
+                       err = buff.Append(buf[:n])
                        continue
                }
 
index 859661505dec7a6ae0d1cbc4c79c1a4d1544138c..579d234e5728f0ce086b9277de8d939f33c86708 100644 (file)
@@ -79,6 +79,7 @@ type Fmp4Decoder struct {
        buf   *slice.Buf[byte]
 
        AVTDiff float64 // 音视频时间戳容差
+       Debug   bool
 }
 
 func NewFmp4Decoder() *Fmp4Decoder {
@@ -582,8 +583,6 @@ func (t *Fmp4Decoder) oneF(buf []byte, ifWrite func(t float64) bool, w ...io.Wri
                                        audio timeStamp
                                )
 
-                               // fmt.Println(moofSN, "frame1", keyframeMoof, t.buf.size(), m[0].i, m[10].n, m[10].e)
-
                                {
                                        ts, handlerType := get_track_type(m[3].i, m[4].i)
                                        if handlerType == 'v' {
@@ -658,6 +657,7 @@ func (t *Fmp4Decoder) oneF(buf []byte, ifWrite func(t float64) bool, w ...io.Wri
                                                        if ifWrite(video.getT()) {
                                                                _, err = w[0].Write(t.buf.GetPureBuf())
                                                        }
+                                                       t.buf.Reset()
                                                        return true, ErrNormal
                                                }
                                                t.buf.Reset()
@@ -699,19 +699,19 @@ func (t *Fmp4Decoder) Cut(reader io.Reader, startT, duration time.Duration, w io
                }
                cu := t - firstFT
                over = cu > durationM+startTM
-               if startTM <= cu && !over {
-                       return true
-               }
-               return false
+               return startTM <= cu && !over
        }
 
+       if t.Debug {
+               fmt.Printf("cut startT: %v duration: %v\n", startT, duration)
+       }
        for c := 0; err == nil && !over; c++ {
-               n, e := reader.Read(buf)
-               if n == 0 && errors.Is(e, io.EOF) {
-                       return io.EOF
-               }
-               err = buff.Append(buf[:n])
                if buff.Size() < bufSize {
+                       n, e := reader.Read(buf)
+                       if n == 0 && errors.Is(e, io.EOF) {
+                               return io.EOF
+                       }
+                       err = buff.Append(buf[:n])
                        continue
                }
 
@@ -723,6 +723,9 @@ func (t *Fmp4Decoder) Cut(reader io.Reader, startT, duration time.Duration, w io
                                        bufSize *= 2
                                        continue
                                } else {
+                                       if t.Debug {
+                                               fmt.Printf("write frontBuf: frontBufSize: %d\n", len(frontBuf))
+                                       }
                                        init = true
                                        _, err = w.Write(frontBuf)
                                }
index 87ab11789c02a651c8032d63bf75f1528390d628..5ab5eb74f9bfbae46720e4abb5658baa8b40372b 100644 (file)
@@ -891,13 +891,14 @@ func (t *M4SStream) saveStreamFlv() (e error) {
                                }
 
                                for {
-                                       if n, e := pipe.Read(buf); e != nil {
-                                               pctx.PutVal(cancelC, &errCtx, e)
-                                               break
-                                       } else if e = buff.Append(buf[:n]); e != nil {
-                                               pctx.PutVal(cancelC, &errCtx, e)
-                                               break
-                                       } else if buff.Size() < bufSize {
+                                       if buff.Size() < bufSize {
+                                               if n, e := pipe.Read(buf); e != nil {
+                                                       pctx.PutVal(cancelC, &errCtx, e)
+                                                       break
+                                               } else if e = buff.Append(buf[:n]); e != nil {
+                                                       pctx.PutVal(cancelC, &errCtx, e)
+                                                       break
+                                               }
                                                continue
                                        }
 
@@ -1011,7 +1012,22 @@ func (t *M4SStream) removeSer() {
 
 func (t *M4SStream) saveStreamM4s() (e error) {
 
+       var (
+               // 同时下载数限制
+               downloadLimit    = funcCtrl.NewBlockFuncN(3)
+               buf              = slice.New[byte]()
+               fmp4Decoder      = NewFmp4Decoder()
+               keyframe         = slice.New[byte]()
+               lastM4s          *m4s_link_item
+               to               = 3
+               fmp4ListUpdateTo = 5.0
+               fmp4Count        = 0
+               startT           = time.Now()
+               skipErrFrame     = false
+       )
+
        if v, ok := t.common.K_v.LoadV(`debug模式`).(bool); ok && v {
+               fmp4Decoder.Debug = true
                cancle := make(chan struct{})
                defer close(cancle)
                go func() {
@@ -1027,21 +1043,6 @@ func (t *M4SStream) saveStreamM4s() (e error) {
                        }
                }()
        }
-
-       var (
-               // 同时下载数限制
-               downloadLimit    = funcCtrl.NewBlockFuncN(3)
-               buf              = slice.New[byte]()
-               fmp4Decoder      = NewFmp4Decoder()
-               keyframe         = slice.New[byte]()
-               lastM4s          *m4s_link_item
-               to               = 3
-               fmp4ListUpdateTo = 5.0
-               fmp4Count        = 0
-               startT           = time.Now()
-               skipErrFrame     = false
-       )
-
        if v, ok := t.common.K_v.LoadV(`fmp4音视频时间戳容差s`).(float64); ok && v > 0.1 {
                fmp4Decoder.AVTDiff = v
        }
index f5b1c53b1d634249a2eab555b959ace8ab0c3bd0..1a7791ba0f5ea1f9197a75dd1ffeb8cecf9ee932 100644 (file)
@@ -89,7 +89,7 @@ func Start() {
                //兑换硬币
                F.Get(c.C).Silver_2_coin()
                //每日签到
-               F.Dosign()
+               // F.Dosign()
                // 附加功能 savetojson
                reply.SaveToJson.Init()
                // 附加功能 保持牌子点亮
@@ -177,7 +177,7 @@ func Start() {
                                `new day`: func(_ any) bool { //日期更换
                                        go func() {
                                                //每日签到
-                                               F.Dosign()
+                                               // F.Dosign()
                                                //每日兑换硬币
                                                F.Get(c.C).Silver_2_coin()
                                                //附加功能 每日发送弹幕
@@ -374,7 +374,7 @@ func entryRoom(mainCtx context.Context, danmulog *part.Log_interface, common *c.
                        replyFunc.Danmuji.Danmuji_auto(mainCtx, c.C.K_v.LoadV(`自动弹幕机_内容`).([]any), c.C.K_v.LoadV(`自动弹幕机_发送间隔s`).(float64), reply.Msg_senddanmu)
                }
                { //附加功能 进房间发送弹幕 直播流保存 每日签到
-                       go F.Dosign()
+                       // go F.Dosign()
                        go reply.Entry_danmu(common)
                        if _, e := recStartEnd.RecStartCheck.Run(mainCtx, common); e == nil {
                                go reply.StreamOStart(common, common.Roomid)