-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstsd.go
49 lines (39 loc) · 894 Bytes
/
stsd.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
package bmff
import (
"encoding/binary"
"errors"
)
type SampleDescription struct {
*fullbox
entryCount uint32
Entries []*SampleEntry
}
func (b *SampleDescription) parse() error {
b.entryCount = binary.BigEndian.Uint32(b.raw[0:4])
b.Entries = make([]*SampleEntry, 0, b.entryCount)
b.raw = b.raw[4:]
for subBox := range readBoxes(b.raw) {
entry := &SampleEntry{box: subBox}
if err := entry.parse(); err != nil {
return err
}
b.Entries = append(b.Entries, entry)
}
if uint32(len(b.Entries)) > b.entryCount {
return errors.New("SampleEntries > entryCount")
}
b.raw = nil
return nil
}
type SampleEntry struct {
*box
data_reference_index uint16
sample []byte
}
func (b *SampleEntry) parse() error {
// first six bytes are reserved
b.data_reference_index = binary.BigEndian.Uint16(b.raw[6:8])
b.sample = b.raw[8:]
b.raw = nil
return nil
}