Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support QuickTime style AudioSampleEntry and wave box #52

Merged
merged 1 commit into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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