forked from Eyevinn/mp4ff
-
Notifications
You must be signed in to change notification settings - Fork 1
/
trep.go
96 lines (88 loc) · 2.06 KB
/
trep.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
package mp4
import (
"encoding/binary"
"io"
)
// TrepBox - Track Extension Properties Box (trep)
// Contained in mvex
type TrepBox struct {
Version byte
Flags uint32
TrackID uint32
Children []Box
}
// AddChild - Add a child box and update SampleCount
func (s *TrepBox) AddChild(child Box) {
s.Children = append(s.Children, child)
}
// DecodeTrep - box-specific decode
func DecodeTrep(hdr *boxHeader, startPos uint64, r io.Reader) (Box, error) {
var versionAndFlags uint32
err := binary.Read(r, binary.BigEndian, &versionAndFlags)
if err != nil {
return nil, err
}
b := &TrepBox{
Version: byte(versionAndFlags >> 24),
Flags: versionAndFlags & flagsMask,
}
err = binary.Read(r, binary.BigEndian, &b.TrackID)
if err != nil {
return nil, err
}
//Note higher startPos below since not simple container
children, err := DecodeContainerChildren(hdr, startPos+16, startPos+hdr.size, r)
if err != nil {
return nil, err
}
for _, box := range children {
b.AddChild(box)
}
return b, nil
}
// Type - box-specific type
func (s *TrepBox) Type() string {
return "trep"
}
// Size - box-specific type
func (b *TrepBox) Size() uint64 {
return containerSize(b.Children) + 8
}
// Encode - box-specific encode of stsd - not a usual container
func (b *TrepBox) Encode(w io.Writer) error {
err := EncodeHeader(b, w)
if err != nil {
return err
}
versionAndFlags := (uint32(b.Version) << 24) + b.Flags
err = binary.Write(w, binary.BigEndian, versionAndFlags)
if err != nil {
return err
}
err = binary.Write(w, binary.BigEndian, b.TrackID)
if err != nil {
return err
}
for _, c := range b.Children {
err = c.Encode(w)
if err != nil {
return err
}
}
return nil
}
func (b *TrepBox) Info(w io.Writer, specificBoxLevels, indent, indentStep string) error {
bd := newInfoDumper(w, indent, b, int(b.Version), b.Flags)
if bd.err != nil {
return bd.err
}
bd.write(" - trackID: %d", b.TrackID)
var err error
for _, c := range b.Children {
err = c.Info(w, specificBoxLevels, indent+indentStep, indentStep)
if err != nil {
return err
}
}
return err
}