-
Notifications
You must be signed in to change notification settings - Fork 84
/
dinf.go
81 lines (68 loc) · 1.74 KB
/
dinf.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"
"github.com/Eyevinn/mp4ff/bits"
)
// DinfBox - Data Information Box (dinf - mandatory)
//
// Contained in : Media Information Box (minf) or Meta Box (meta)
type DinfBox struct {
Dref *DrefBox
Children []Box
}
// AddChild - Add a child box
func (d *DinfBox) AddChild(box Box) {
switch box.Type() {
case "dref":
d.Dref = box.(*DrefBox)
}
d.Children = append(d.Children, box)
}
// DecodeDinf - box-specific decode
func DecodeDinf(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
}
d := &DinfBox{}
for _, b := range l {
d.AddChild(b)
}
return d, nil
}
// DecodeDinfSR - box-specific decode
func DecodeDinfSR(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
}
d := &DinfBox{}
for _, c := range children {
d.AddChild(c)
}
return d, nil
}
// Type - box-specific type
func (d *DinfBox) Type() string {
return "dinf"
}
// Size - box-specific size
func (d *DinfBox) Size() uint64 {
return containerSize(d.Children)
}
// GetChildren - list of child boxes
func (d *DinfBox) GetChildren() []Box {
return d.Children
}
// Encode - write dinf container to w
func (d *DinfBox) Encode(w io.Writer) error {
return EncodeContainer(d, w)
}
// EncodeSW - write container using slice writer
func (d *DinfBox) EncodeSW(sw bits.SliceWriter) error {
return EncodeContainerSW(d, sw)
}
// Info - write box info to w
func (d *DinfBox) Info(w io.Writer, specificBoxLevels, indent, indentStep string) error {
return ContainerInfo(d, w, specificBoxLevels, indent, indentStep)
}