forked from Eyevinn/mp4ff
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mvex.go
72 lines (61 loc) · 1.45 KB
/
mvex.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
package mp4
import "io"
// MvexBox - MovieExtendsBox (mevx)
//
// Contained in : Movie Box (moov)
//
// Its presence signals a fragmented asset
type MvexBox struct {
Mehd *MehdBox
Trex *TrexBox
Trexs []*TrexBox
Children []Box
}
// NewMvexBox - Generate a new empty mvex box
func NewMvexBox() *MvexBox {
return &MvexBox{}
}
// AddChild - Add a child box
func (m *MvexBox) AddChild(box Box) {
switch box.Type() {
case "mehd":
m.Mehd = box.(*MehdBox)
case "trex":
if m.Trex == nil {
m.Trex = box.(*TrexBox)
}
m.Trexs = append(m.Trexs, box.(*TrexBox))
}
m.Children = append(m.Children, box)
}
// DecodeMvex - box-specific decode
func DecodeMvex(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 := NewMvexBox()
for _, b := range l {
m.AddChild(b)
}
return m, nil
}
// Type - return box type
func (m *MvexBox) Type() string {
return "mvex"
}
// Size - return calculated size
func (m *MvexBox) Size() uint64 {
return containerSize(m.Children)
}
// GetChildren - list of child boxes
func (t *MvexBox) GetChildren() []Box {
return t.Children
}
// Encode - write mvex container to w
func (m *MvexBox) Encode(w io.Writer) error {
return EncodeContainer(m, w)
}
func (m *MvexBox) Info(w io.Writer, specificBoxLevels, indent, indentStep string) error {
return ContainerInfo(m, w, specificBoxLevels, indent, indentStep)
}