forked from godeep/mp4
-
Notifications
You must be signed in to change notification settings - Fork 6
/
minf.go
96 lines (89 loc) · 1.48 KB
/
minf.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 "io"
// Media Information Box (minf - mandatory)
//
// Contained in : Media Box (mdia)
//
// Status: partially decoded (hmhd - hint tracks - and nmhd - null media - are ignored)
type MinfBox struct {
Vmhd *VmhdBox
Smhd *SmhdBox
Stbl *StblBox
Dinf *DinfBox
Hdlr *HdlrBox
}
func DecodeMinf(r io.Reader) (Box, error) {
l, err := DecodeContainer(r)
if err != nil {
return nil, err
}
m := &MinfBox{}
for _, b := range l {
switch b.Type() {
case "vmhd":
m.Vmhd = b.(*VmhdBox)
case "smhd":
m.Smhd = b.(*SmhdBox)
case "stbl":
m.Stbl = b.(*StblBox)
case "dinf":
m.Dinf = b.(*DinfBox)
case "hdlr":
m.Hdlr = b.(*HdlrBox)
}
}
return m, nil
}
func (b *MinfBox) Type() string {
return "minf"
}
func (b *MinfBox) Size() int {
sz := 0
if b.Vmhd != nil {
sz += b.Vmhd.Size()
}
if b.Smhd != nil {
sz += b.Smhd.Size()
}
sz += b.Stbl.Size()
if b.Dinf != nil {
sz += b.Dinf.Size()
}
if b.Hdlr != nil {
sz += b.Hdlr.Size()
}
return sz + BoxHeaderSize
}
func (b *MinfBox) Dump() {
b.Stbl.Dump()
}
func (b *MinfBox) Encode(w io.Writer) error {
err := EncodeHeader(b, w)
if err != nil {
return err
}
if b.Vmhd != nil {
err = b.Vmhd.Encode(w)
if err != nil {
return err
}
}
if b.Smhd != nil {
err = b.Smhd.Encode(w)
if err != nil {
return err
}
}
err = b.Dinf.Encode(w)
if err != nil {
return err
}
err = b.Stbl.Encode(w)
if err != nil {
return err
}
if b.Hdlr != nil {
return b.Hdlr.Encode(w)
}
return nil
}