Skip to content

Commit

Permalink
feat: description boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Sep 3, 2023
1 parent 175b940 commit 566daec
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 63 deletions.
6 changes: 5 additions & 1 deletion mp4/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func init() {
"dac3": DecodeDac3,
"data": DecodeData,
"dec3": DecodeDec3,
"desc": DecodeGenericContainerBox,
"dinf": DecodeDinf,
"dpnd": DecodeTrefType,
"dref": DecodeDref,
Expand Down Expand Up @@ -132,7 +133,10 @@ func init() {
"vttC": DecodeVttC,
"vtte": DecodeVtte,
"wvtt": DecodeWvtt,
"\xa9too": DecodeCToo,
"\xa9cpy": DecodeGenericContainerBox,
"\xa9nam": DecodeGenericContainerBox,
"\xa9too": DecodeGenericContainerBox,
"\xa9ART": DecodeGenericContainerBox,
}
}

Expand Down
6 changes: 5 additions & 1 deletion mp4/boxsr.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func init() {
"dac3": DecodeDac3SR,
"data": DecodeDataSR,
"dec3": DecodeDec3SR,
"desc": DecodeGenericContainerBoxSR,
"dinf": DecodeDinfSR,
"dpnd": DecodeTrefTypeSR,
"dref": DecodeDrefSR,
Expand Down Expand Up @@ -123,7 +124,10 @@ func init() {
"vttC": DecodeVttCSR,
"vtte": DecodeVtteSR,
"wvtt": DecodeWvttSR,
"\xa9too": DecodeCTooSR,
"\xa9cpy": DecodeGenericContainerBoxSR,
"\xa9nam": DecodeGenericContainerBoxSR,
"\xa9too": DecodeGenericContainerBoxSR,
"\xa9ART": DecodeGenericContainerBoxSR,
}
}

Expand Down
69 changes: 69 additions & 0 deletions mp4/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,75 @@ type ContainerBox interface {
Info(w io.Writer, specificBoxLevels, indent, indentStep string) error
}

// GenericContainerBox is a generic container box with no special child pointers
type GenericContainerBox struct {
name string
Children []Box
}

func NewGenericContainerBox(name string) *GenericContainerBox {
return &GenericContainerBox{name: name}
}

func (b *GenericContainerBox) Type() string {
return b.name
}

func (b *GenericContainerBox) Size() uint64 {
return containerSize(b.Children)
}

// Encode - write GenericContainerBox to w
func (b *GenericContainerBox) Encode(w io.Writer) error {
return EncodeContainer(b, w)
}

// Encode - write minf container to sw
func (b *GenericContainerBox) EncodeSW(sw bits.SliceWriter) error {
return EncodeContainerSW(b, sw)
}

// Info - write box-specific information
func (b *GenericContainerBox) Info(w io.Writer, specificBoxLevels, indent, indentStep string) error {
return ContainerInfo(b, w, specificBoxLevels, indent, indentStep)
}

// GetChildren - list of child boxes
func (b *GenericContainerBox) GetChildren() []Box {
return b.Children
}

// DecodeGenericContainerBox - box-specific decode
func DecodeGenericContainerBox(hdr BoxHeader, startPos uint64, r io.Reader) (Box, error) {
children, err := DecodeContainerChildren(hdr, startPos+8, startPos+hdr.Size, r)
if err != nil {
return nil, err
}
m := NewGenericContainerBox(hdr.Name)
for _, c := range children {
m.AddChild(c)
}
return m, nil
}

// DecodeGenericContainerBoxSR - box-specific decode
func DecodeGenericContainerBoxSR(hdr BoxHeader, startPos uint64, sr bits.SliceReader) (Box, error) {
children, err := DecodeContainerChildrenSR(hdr, startPos+8, startPos+hdr.Size, sr)
if err != nil {
return nil, err
}
m := NewGenericContainerBox(hdr.Name)
for _, c := range children {
m.AddChild(c)
}
return m, nil
}

// AddChild - Add a child box
func (b *GenericContainerBox) AddChild(child Box) {
b.Children = append(b.Children, child)
}

func containerSize(children []Box) uint64 {
var contentSize uint64 = 0
for _, child := range children {
Expand Down
61 changes: 0 additions & 61 deletions mp4/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,67 +12,6 @@ type CTooBox struct {
Children []Box
}

// DecodeCToo - box-specific decode
func DecodeCToo(hdr BoxHeader, startPos uint64, r io.Reader) (Box, error) {
children, err := DecodeContainerChildren(hdr, startPos+8, startPos+hdr.Size, r)
if err != nil {
return nil, err
}
b := &CTooBox{}
for _, c := range children {
b.AddChild(c)
}
return b, nil
}

// DecodeCTooSR - box-specific decode
func DecodeCTooSR(hdr BoxHeader, startPos uint64, sr bits.SliceReader) (Box, error) {
children, err := DecodeContainerChildrenSR(hdr, startPos+8, startPos+hdr.Size, sr)
if err != nil {
return nil, err
}
b := &CTooBox{}
for _, c := range children {
b.AddChild(c)
}
return b, nil
}

// AddChild - Add a child box and update SampleCount
func (b *CTooBox) AddChild(child Box) {
b.Children = append(b.Children, child)
}

// Type - box type
func (b *CTooBox) Type() string {
return "\xa9too"
}

// Size - calculated size of box
func (b *CTooBox) Size() uint64 {
return containerSize(b.Children)
}

// GetChildren - list of child boxes
func (b *CTooBox) GetChildren() []Box {
return b.Children
}

// Encode - write minf container to w
func (b *CTooBox) Encode(w io.Writer) error {
return EncodeContainer(b, w)
}

// Encode - write minf container to sw
func (b *CTooBox) EncodeSW(sw bits.SliceWriter) error {
return EncodeContainerSW(b, sw)
}

// Info - box-specific Info
func (b *CTooBox) Info(w io.Writer, specificBoxLevels, indent, indentStep string) error {
return ContainerInfo(b, w, specificBoxLevels, indent, indentStep)
}

// DataBox - data box used by ffmpeg for providing information.
type DataBox struct {
Data []byte
Expand Down

0 comments on commit 566daec

Please sign in to comment.