Skip to content

Commit

Permalink
Support wave box and AudioSampleEntry of QuickTime style
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfish-shogi committed Nov 15, 2020
1 parent 55702ef commit 04634da
Show file tree
Hide file tree
Showing 16 changed files with 481 additions and 145 deletions.
Binary file added _examples/sample_qt.mp4
Binary file not shown.
35 changes: 19 additions & 16 deletions box.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,71 @@ package mp4
import (
"errors"
"io"
"math"

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

const LengthUnlimited = math.MaxUint32

type ICustomFieldObject interface {
// GetFieldSize returns size of dynamic field
GetFieldSize(string) uint
GetFieldSize(name string, bss BoxStructureStatus) uint

// GetFieldLength returns length of dynamic field
GetFieldLength(string) uint
GetFieldLength(name string, bss BoxStructureStatus) uint

// IsOptFieldEnabled check whether if the optional field is enabled
IsOptFieldEnabled(string) bool
IsOptFieldEnabled(name string, bss BoxStructureStatus) bool

// StringifyField returns field value as string
StringifyField(string, string, int) (string, bool)
StringifyField(name string, indent string, depth int, bss BoxStructureStatus) (string, bool)

IsPString(name string, bytes []byte, remainingSize uint64) bool
IsPString(name string, bytes []byte, remainingSize uint64, bss BoxStructureStatus) bool

BeforeUnmarshal(r io.ReadSeeker, size uint64) (n uint64, override bool, err error)
BeforeUnmarshal(r io.ReadSeeker, size uint64, bss BoxStructureStatus) (n uint64, override bool, err error)

OnReadField(name string, r bitio.ReadSeeker, leftBits uint64) (rbits uint64, override bool, err error)
OnReadField(name string, r bitio.ReadSeeker, leftBits uint64, bss BoxStructureStatus) (rbits uint64, override bool, err error)

OnWriteField(name string, w bitio.Writer) (wbits uint64, override bool, err error)
OnWriteField(name string, w bitio.Writer, bss BoxStructureStatus) (wbits uint64, override bool, err error)
}

type BaseCustomFieldObject struct {
}

// GetFieldSize returns size of dynamic field
func (box *BaseCustomFieldObject) GetFieldSize(string) uint {
func (box *BaseCustomFieldObject) GetFieldSize(string, BoxStructureStatus) uint {
panic(errors.New("GetFieldSize not implemented"))
}

// GetFieldLength returns length of dynamic field
func (box *BaseCustomFieldObject) GetFieldLength(string) uint {
func (box *BaseCustomFieldObject) GetFieldLength(string, BoxStructureStatus) uint {
panic(errors.New("GetFieldLength not implemented"))
}

// IsOptFieldEnabled check whether if the optional field is enabled
func (box *BaseCustomFieldObject) IsOptFieldEnabled(string) bool {
func (box *BaseCustomFieldObject) IsOptFieldEnabled(string, BoxStructureStatus) bool {
return false
}

// StringifyField returns field value as string
func (box *BaseCustomFieldObject) StringifyField(string, string, int) (string, bool) {
func (box *BaseCustomFieldObject) StringifyField(string, string, int, BoxStructureStatus) (string, bool) {
return "", false
}

func (*BaseCustomFieldObject) IsPString(name string, bytes []byte, remainingSize uint64) bool {
func (*BaseCustomFieldObject) IsPString(name string, bytes []byte, remainingSize uint64, bss BoxStructureStatus) bool {
return true
}

func (*BaseCustomFieldObject) BeforeUnmarshal(io.ReadSeeker, uint64) (uint64, bool, error) {
func (*BaseCustomFieldObject) BeforeUnmarshal(io.ReadSeeker, uint64, BoxStructureStatus) (uint64, bool, error) {
return 0, false, nil
}

func (*BaseCustomFieldObject) OnReadField(string, bitio.ReadSeeker, uint64) (uint64, bool, error) {
func (*BaseCustomFieldObject) OnReadField(string, bitio.ReadSeeker, uint64, BoxStructureStatus) (uint64, bool, error) {
return 0, false, nil
}

func (*BaseCustomFieldObject) OnWriteField(string, bitio.Writer) (uint64, bool, error) {
func (*BaseCustomFieldObject) OnWriteField(string, bitio.Writer, BoxStructureStatus) (uint64, bool, error) {
return 0, false, nil
}

Expand Down
11 changes: 11 additions & 0 deletions box_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import (
"math"
)

type BoxStructureStatus struct {
// IsQuickTimeCompatible represents whether ftyp.compatible_brands contains "qt ".
IsQuickTimeCompatible bool

// UnderWave represents whether current box is under the wave box.
UnderWave bool
}

// BoxInfo has common infomations of box
type BoxInfo struct {
// Offset specifies an offset of the box in a file.
Expand All @@ -23,6 +31,9 @@ type BoxInfo struct {

// ExtendToEOF is set true when Box.size is zero. It means that end of box equals to end of file.
ExtendToEOF bool

// BoxStructureStatus would be set by ReadBoxStructure, not ReadBoxInfo.
BoxStructureStatus
}

const (
Expand Down
Loading

0 comments on commit 04634da

Please sign in to comment.