-
Notifications
You must be signed in to change notification settings - Fork 1
/
mfra.go
81 lines (72 loc) · 1.62 KB
/
mfra.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
package mp4
import (
"io"
)
// MfraBox - Movie Fragment Random Access Box (mfra)
// Container for TfraBox(es) that can be used to find sync samples
type MfraBox struct {
Tfra *TfraBox
Tfras []*TfraBox
Mfro *MfroBox
Children []Box
StartPos uint64
}
// DecodeMfra - box-specific decode
func DecodeMfra(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 := &MfraBox{}
m.StartPos = startPos
for _, box := range children {
err := m.AddChild(box)
if err != nil {
return nil, err
}
}
return m, nil
}
// AddChild - add child box
func (m *MfraBox) AddChild(child Box) error {
switch child.Type() {
case "tfra":
if m.Tfra == nil {
m.Tfra = child.(*TfraBox)
}
m.Tfras = append(m.Tfras, child.(*TfraBox))
case "mfro":
m.Mfro = child.(*MfroBox)
}
m.Children = append(m.Children, child)
return nil
}
// Type - returns box type
func (m *MfraBox) Type() string {
return "mfra"
}
// Size - returns calculated size
func (m *MfraBox) Size() uint64 {
return containerSize(m.Children)
}
// Encode - byte-specific encode
func (m *MfraBox) Encode(w io.Writer) error {
err := EncodeHeader(m, w)
if err != nil {
return err
}
for _, b := range m.Children {
err = b.Encode(w)
if err != nil {
return err
}
}
return nil
}
// GetChildren - list of child boxes
func (m *MfraBox) GetChildren() []Box {
return m.Children
}
func (m *MfraBox) Info(w io.Writer, specificBoxLevels, indent, indentStep string) error {
return ContainerInfo(m, w, specificBoxLevels, indent, indentStep)
}