-
Notifications
You must be signed in to change notification settings - Fork 84
/
mdia.go
95 lines (82 loc) · 2.01 KB
/
mdia.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package mp4
import (
"io"
"github.com/Eyevinn/mp4ff/bits"
)
// MdiaBox - Media Box (mdia)
//
// Contained in : Track Box (trak)
// Contains all information about the media data.
type MdiaBox struct {
Mdhd *MdhdBox
Hdlr *HdlrBox
Elng *ElngBox
Minf *MinfBox
Children []Box
}
// NewMdiaBox - Generate a new empty mdia box
func NewMdiaBox() *MdiaBox {
return &MdiaBox{}
}
// AddChild - Add a child box
func (m *MdiaBox) AddChild(box Box) {
switch box.Type() {
case "mdhd":
m.Mdhd = box.(*MdhdBox)
case "hdlr":
m.Hdlr = box.(*HdlrBox)
case "elng":
m.Elng = box.(*ElngBox)
case "minf":
m.Minf = box.(*MinfBox)
}
m.Children = append(m.Children, box)
}
// DecodeMdia - box-specific decode
func DecodeMdia(hdr BoxHeader, startPos uint64, r io.Reader) (Box, error) {
l, err := DecodeContainerChildren(hdr, startPos+8, startPos+hdr.Size, r)
if err != nil {
return nil, err
}
m := NewMdiaBox()
for _, b := range l {
m.AddChild(b)
}
return m, nil
}
// DecodeMdiaSR - box-specific decode
func DecodeMdiaSR(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 := NewMdiaBox()
for _, c := range children {
m.AddChild(c)
}
return m, nil
}
// Type - return box type
func (m *MdiaBox) Type() string {
return "mdia"
}
// Size - return calculated size
func (m *MdiaBox) Size() uint64 {
return containerSize(m.Children)
}
// GetChildren - list of child boxes
func (m *MdiaBox) GetChildren() []Box {
return m.Children
}
// EncodeSW - write mdia container to w
func (m *MdiaBox) Encode(w io.Writer) error {
return EncodeContainer(m, w)
}
// Encode - write mdia container via sw
func (m *MdiaBox) EncodeSW(sw bits.SliceWriter) error {
return EncodeContainerSW(m, sw)
}
// Info - write box-specific information
func (m *MdiaBox) Info(w io.Writer, specificBoxLevels, indent, indentStep string) error {
return ContainerInfo(m, w, specificBoxLevels, indent, indentStep)
}