-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathmfra.go
106 lines (93 loc) · 2.35 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package mp4
import (
"io"
"github.com/Eyevinn/mp4ff/bits"
)
// 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
}
// DecodeMfraSR - box-specific decode
func DecodeMfraSR(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 := &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 box := child.(type) {
case *TfraBox:
if m.Tfra == nil {
m.Tfra = box
}
m.Tfras = append(m.Tfras, box)
case *MfroBox:
m.Mfro = box
}
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 - write mfra container to w
func (m *MfraBox) Encode(w io.Writer) error {
return EncodeContainer(m, w)
}
// EncodeSW- write mfra container via sw
func (m *MfraBox) EncodeSW(sw bits.SliceWriter) error {
return EncodeContainerSW(m, sw)
}
// GetChildren - list of child boxes
func (m *MfraBox) GetChildren() []Box {
return m.Children
}
// Info - write box-specific information
func (m *MfraBox) Info(w io.Writer, specificBoxLevels, indent, indentStep string) error {
return ContainerInfo(m, w, specificBoxLevels, indent, indentStep)
}
// FindEntry - find tfra entry for given moof start offset and trackID. Return nil if not found.
func (m *MfraBox) FindEntry(moofStart uint64, trackID uint32) *TfraEntry {
for _, tfra := range m.Tfras {
if tfra.TrackID == trackID {
return tfra.FindEntry(moofStart)
}
}
return nil
}