Skip to content

Commit

Permalink
Properly preserve entry count on context.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrejod committed Jan 15, 2024
1 parent aadbe29 commit 848082d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
16 changes: 0 additions & 16 deletions box_types_metadata.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package mp4

import (
"encoding/binary"
"fmt"

"github.com/abema/go-mp4/internal/bitio"
"github.com/abema/go-mp4/internal/util"
)

Expand Down Expand Up @@ -226,20 +224,6 @@ func (k *Keys) GetFieldLength(name string, ctx Context) uint {
panic(fmt.Errorf("invalid name of dynamic-length field: boxType=keys fieldName=%s", name))
}

func (k *Keys) OnReadField(name string, r bitio.ReadSeeker, leftBits uint64, ctx Context) (rbits uint64, override bool, err error) {
switch name {
// Override EntryCount unmarshaller so we can set QuickTimeKeysMetaEntryCount on Context
case "EntryCount":
err = binary.Read(r, binary.BigEndian, &k.EntryCount)
ctx.QuickTimeKeysMetaEntryCount = int(k.EntryCount)
override = true
rbits += uint64(32)
return
default:
return
}
}

/*************************** key ****************************/

// Key is a key value field in the Keys BoxType
Expand Down
17 changes: 17 additions & 0 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ func readBoxStructureFromInternal(r io.ReadSeeker, bi *BoxInfo, path BoxPath, ha
}
}

// parse numbered ilst items after keys box by saving EntryCount field to context
if bi.Type == BoxTypeKeys() {
var keys Keys
if _, err := Unmarshal(r, bi.Size-bi.HeaderSize, &keys, bi.Context); err != nil {
return nil, err
}
bi.QuickTimeKeysMetaEntryCount = int(keys.EntryCount)
if _, err := bi.SeekToPayload(r); err != nil {
return nil, err
}
}

ctx := bi.Context
if bi.Type == BoxTypeWave() {
ctx.UnderWave = true
Expand Down Expand Up @@ -172,6 +184,11 @@ func readBoxStructure(r io.ReadSeeker, totalSize uint64, isRoot bool, path BoxPa
if bi.IsQuickTimeCompatible {
ctx.IsQuickTimeCompatible = true
}

// preserve keys entry count on context for subsequent ilst number item box
if bi.Type == BoxTypeKeys() {
ctx.QuickTimeKeysMetaEntryCount = bi.QuickTimeKeysMetaEntryCount
}
}

if totalSize != 0 && !ctx.IsQuickTimeCompatible {
Expand Down

0 comments on commit 848082d

Please sign in to comment.