From 1e931275f1a2a0bc980af0f7ac6390c878d616af Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 8 Dec 2024 04:04:11 +0800 Subject: [PATCH] Dev (#128) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * 签到活动已下线 * Fix ErrBufTooLarge #127 --- F/api.go | 1 + Reply/F.go | 3 +++ Reply/flvDecode.go | 10 +++++----- Reply/fmp4Decode.go | 25 ++++++++++++++----------- Reply/stream.go | 45 +++++++++++++++++++++++---------------------- bili_danmu.go | 6 +++--- 6 files changed, 49 insertions(+), 41 deletions(-) diff --git a/F/api.go b/F/api.go index 6546c2b..9ca695a 100644 --- 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 diff --git a/Reply/F.go b/Reply/F.go index 337d713..5fdcc9f 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -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 } diff --git a/Reply/flvDecode.go b/Reply/flvDecode.go index 7f99a71..5ed5111 100644 --- a/Reply/flvDecode.go +++ b/Reply/flvDecode.go @@ -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 } diff --git a/Reply/fmp4Decode.go b/Reply/fmp4Decode.go index 8596615..579d234 100644 --- a/Reply/fmp4Decode.go +++ b/Reply/fmp4Decode.go @@ -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) } diff --git a/Reply/stream.go b/Reply/stream.go index 87ab117..5ab5eb7 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -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 } diff --git a/bili_danmu.go b/bili_danmu.go index f5b1c53..1a7791b 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -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) -- 2.39.2