-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrak.go
66 lines (60 loc) · 1.16 KB
/
trak.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
package bmff
import (
"fmt"
)
type TrakBox struct {
*box
Header *TrackHeader
Reference *TrackReference
Media *Media
EditBox *EditBox
UserData *UserData
}
func (b *TrakBox) parse() error {
for subBox := range readBoxes(b.raw) {
var fb *fullbox
switch subBox.boxtype {
case "tkhd":
fb = &fullbox{box: subBox}
if err := fb.decode(); err != nil {
return err
}
}
switch subBox.boxtype {
case "tkhd":
tkhd := &TrackHeader{fullbox: fb}
if err := tkhd.parse(); err != nil {
return err
}
b.Header = tkhd
case "tref":
tref := &TrackReference{box: subBox}
if err := tref.parse(); err != nil {
return err
}
b.Reference = tref
case "mdia":
mdia := &Media{box: subBox}
if err := mdia.parse(); err != nil {
return err
}
b.Media = mdia
case "edts":
edts := &EditBox{box: subBox}
if err := edts.parse(); err != nil {
return err
}
b.EditBox = edts
case "udta":
udta := &UserData{box: subBox}
if err := udta.parse(); err != nil {
return err
}
b.UserData = udta
default:
return fmt.Errorf("unknown 'trak' child: %s", subBox.Type())
}
}
b.raw = nil
return nil
}