-
Notifications
You must be signed in to change notification settings - Fork 84
/
ludt.go
83 lines (71 loc) · 1.83 KB
/
ludt.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
package mp4
import (
"io"
"github.com/Eyevinn/mp4ff/bits"
)
// LudtBox - Track loudness container
//
// Contained in : Udta Box (udta)
type LudtBox struct {
Loudness []*TlouBox
AlbumLoudness []*AlouBox
Children []Box
}
// DecodeLudt - box-specific decode
func DecodeLudt(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
}
b := &LudtBox{}
for _, c := range children {
b.AddChild(c)
}
return b, nil
}
// DecodeLudtSR - box-specific decode
func DecodeLudtSR(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
}
b := &LudtBox{}
for _, c := range children {
b.AddChild(c)
}
return b, nil
}
// AddChild - add child box
func (b *LudtBox) AddChild(child Box) {
switch box := child.(type) {
case *TlouBox:
b.Loudness = append(b.Loudness, box)
case *AlouBox:
b.AlbumLoudness = append(b.AlbumLoudness, box)
}
b.Children = append(b.Children, child)
}
// Size - calculated size of box
func (b *LudtBox) Size() uint64 {
return containerSize(b.Children)
}
// Type - return box type
func (b *LudtBox) Type() string {
return "ludt"
}
// Encode - write ludt container to w
func (b *LudtBox) Encode(w io.Writer) error {
return EncodeContainer(b, w)
}
// Encode - write ludt container to sw
func (b *LudtBox) EncodeSW(sw bits.SliceWriter) error {
return EncodeContainerSW(b, sw)
}
// GetChildren - list of child boxes
func (b *LudtBox) GetChildren() []Box {
return b.Children
}
// Info - write box-specific information
func (b *LudtBox) Info(w io.Writer, specificBoxLevels, indent, indentStep string) error {
return ContainerInfo(b, w, specificBoxLevels, indent, indentStep)
}