]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Fix 异常分配 #203 (#204)
authorqydysky <qydysky@foxmail.com>
Sun, 11 May 2025 19:19:01 +0000 (03:19 +0800)
committerGitHub <noreply@github.com>
Sun, 11 May 2025 19:19:01 +0000 (03:19 +0800)
Reply/fmp4Decode.go
go.mod
go.sum

index b127257166a6bf24ba589d70051668bbcea0aae9..eace75d63e9564dc029e29cbb2f38d2c3eda59ef 100644 (file)
@@ -106,7 +106,8 @@ func NewFmp4Decoder() *Fmp4Decoder {
 func (t *Fmp4Decoder) Init_fmp4(buf []byte) (b []byte, err error) {
        var ftypI, ftypE, moovI, moovE int
 
-       ies, e := decode(buf, "ftyp")
+       ies, recycle, e := decode(buf, "ftyp")
+       defer recycle(ies)
        if e != nil {
                return
        }
@@ -267,7 +268,8 @@ func (t *Fmp4Decoder) Search_stream_fmp4(buf []byte, keyframe *slice.Buf[byte])
                }
        )
 
-       ies, e := decode(buf, "moof")
+       ies, recycle, e := decode(buf, "moof")
+       defer recycle(ies)
        if e != nil {
                return 0, e
        }
@@ -512,7 +514,8 @@ func (t *Fmp4Decoder) oneF(buf []byte, w ...dealFMp4) (cu int, err error) {
                }
        )
 
-       ies, e := decode(buf, "moof")
+       ies, recycle, e := decode(buf, "moof")
+       defer recycle(ies)
        if e != nil {
                return 0, e
        }
@@ -838,11 +841,18 @@ func deals(ies []ie, dealIEs []dealIE) (err error) {
 var (
        ErrMisBox     = pe.New("decode", "ErrMisBox")
        ErrCantResync = pe.New("decode")
+       iesPool       = slice.NewFlexBlocks[ie](5)
 )
 
-func decode(buf []byte, reSyncboxName string) (m []ie, err error) {
+func decode(buf []byte, reSyncboxName string) (m []ie, recycle func([]ie), err error) {
        var cu int
 
+       m, recycle, err = iesPool.Get()
+       if err != nil {
+               return
+       }
+       m = m[:0]
+
        for cu < len(buf)-fmp4BoxLenSize-fmp4BoxNameSize {
                boxName, i, e, E := searchBox(buf, &cu)
                if E != nil {
@@ -862,11 +872,18 @@ func decode(buf []byte, reSyncboxName string) (m []ie, err error) {
                        return
                }
 
-               m = append(m, ie{
-                       n: boxName,
-                       i: i,
-                       e: e,
-               })
+               if cu := len(m); cu < cap(m) {
+                       m = m[:cu+1]
+                       m[cu].n = boxName
+                       m[cu].i = i
+                       m[cu].e = e
+               } else {
+                       m = append(m, ie{
+                               n: boxName,
+                               i: i,
+                               e: e,
+                       })
+               }
        }
 
        return
diff --git a/go.mod b/go.mod
index d7310f98ebc7e2efad808ee781e606b20f6da41f..27c39a1eff7323011b29f5df8b6bd95fe13dcad1 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ go 1.24
 require (
        github.com/gotk3/gotk3 v0.6.4
        github.com/mdp/qrterminal/v3 v3.2.0
-       github.com/qydysky/part v0.28.20250509205808
+       github.com/qydysky/part v0.28.20250511190336
        github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
        github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
        golang.org/x/text v0.24.0 // indirect
diff --git a/go.sum b/go.sum
index 7e0d856ed8a9d3102a4c0eab1cb04e17dbc4c56d..c2291b61ab967df98007cde06e8e9c7bfe981e7c 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -46,8 +46,8 @@ github.com/qydysky/biliApi v0.0.0-20250509210314-8407d638b123 h1:YXqqrwvzFwfs8Lo
 github.com/qydysky/biliApi v0.0.0-20250509210314-8407d638b123/go.mod h1:1FbgCj+aOwIvuRRuX/l5uTLb3JIwWyJSa0uEfwpYV/8=
 github.com/qydysky/brotli v0.0.0-20240828134800-e9913a6e7ed9 h1:k451T+bpsLr+Dq9Ujo+Qtx0iomRA1XXS5ttlEojvfuQ=
 github.com/qydysky/brotli v0.0.0-20240828134800-e9913a6e7ed9/go.mod h1:cI8/gy/wjy2Eb+p2IUj2ZuDnC8R5Vrx3O0VMPvMvphA=
-github.com/qydysky/part v0.28.20250509205808 h1:vyv+TA9uK9IV4n0J5nuACqrARESX2HphoLgslecubyw=
-github.com/qydysky/part v0.28.20250509205808/go.mod h1:wp71PQdKYcg9jn9yDDvqC4shS/kzejyvFqbfUxuHocY=
+github.com/qydysky/part v0.28.20250511190336 h1:99Wfw3jbBQ0iohS2bY5xKNh2mwv5weWoh7harkGEOQ0=
+github.com/qydysky/part v0.28.20250511190336/go.mod h1:wp71PQdKYcg9jn9yDDvqC4shS/kzejyvFqbfUxuHocY=
 github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
 github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
 github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=