-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdia.go
51 lines (46 loc) · 970 Bytes
/
mdia.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
package bmff
import "fmt"
type Media struct {
*box
Header *MediaHeader
Handler *Handler
Information *MediaInformation
Unknown []*box
}
func (b *Media) parse() error {
for subBox := range readBoxes(b.raw) {
var fb *fullbox
switch subBox.boxtype {
case "mdhd", "hdlr":
fb = &fullbox{box: subBox}
if err := fb.decode(); err != nil {
return err
}
}
switch subBox.boxtype {
case "mdhd":
mdhd := &MediaHeader{fullbox: fb}
if err := mdhd.parse(); err != nil {
return err
}
b.Header = mdhd
case "hdlr":
hdlr := &Handler{fullbox: fb}
if err := hdlr.parse(); err != nil {
return err
}
b.Handler = hdlr
case "minf":
minf := &MediaInformation{box: subBox}
if err := minf.parse(); err != nil {
return err
}
b.Information = minf
default:
b.Unknown = append(b.Unknown, subBox)
fmt.Printf("unknown '%s' child: %s\n", b.boxtype, subBox.Type())
}
}
b.raw = nil
return nil
}