-
Notifications
You must be signed in to change notification settings - Fork 0
/
minf.go
97 lines (90 loc) · 2.45 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
97
package bmff
import (
"fmt"
)
type MediaInformation struct {
*box
DataInformation *DataInformation
NullMediaHeader *NullMediaHeader
VideoMediaHeader *VideoMediaHeader
SoundMediaHeader *SoundMediaHeader
HintMediaHeader *HintMediaHeader
SampleTable *SampleTable
Unknown []*box
}
func (b *MediaInformation) parse() error {
for subBox := range readBoxes(b.raw) {
var fb *fullbox
switch subBox.boxtype {
case "nmhd",
"smhd",
"hmhd",
"vmhd":
fb = &fullbox{box: subBox}
if err := fb.decode(); err != nil {
return err
}
}
switch subBox.boxtype {
case "nmhd":
nmhd := &NullMediaHeader{fullbox: fb}
if err := nmhd.parse(); err != nil {
return err
}
if b.NullMediaHeader != nil || b.VideoMediaHeader != nil || b.SoundMediaHeader != nil || b.HintMediaHeader != nil {
return fmt.Errorf("media header already populated for track: %v", b)
}
b.NullMediaHeader = nmhd
case "vmhd":
vmhd := &VideoMediaHeader{fullbox: fb}
if err := vmhd.parse(); err != nil {
return err
}
if b.NullMediaHeader != nil || b.VideoMediaHeader != nil || b.SoundMediaHeader != nil || b.HintMediaHeader != nil {
return fmt.Errorf("media header already populated for track: %v", b)
}
b.VideoMediaHeader = vmhd
case "smhd":
smhd := &SoundMediaHeader{fullbox: fb}
if err := smhd.parse(); err != nil {
return err
}
if b.NullMediaHeader != nil || b.VideoMediaHeader != nil || b.SoundMediaHeader != nil || b.HintMediaHeader != nil {
return fmt.Errorf("media header already populated for track: %v", b)
}
b.SoundMediaHeader = smhd
case "hmhd":
hmhd := &HintMediaHeader{fullbox: fb}
if err := hmhd.parse(); err != nil {
return err
}
if b.NullMediaHeader != nil || b.VideoMediaHeader != nil || b.SoundMediaHeader != nil || b.HintMediaHeader != nil {
return fmt.Errorf("media header already populated for track: %v", b)
}
b.HintMediaHeader = hmhd
case "dinf":
dinf := &DataInformation{box: subBox}
if err := dinf.parse(); err != nil {
return err
}
b.DataInformation = dinf
case "stbl":
stbl := &SampleTable{box: subBox}
if err := stbl.parse(); err != nil {
return err
}
b.SampleTable = stbl
default:
b.Unknown = append(b.Unknown, subBox)
fmt.Printf("unknown '%s' child: %s\n", b.boxtype, subBox.Type())
}
}
b.raw = nil
return nil
}
type NullMediaHeader struct {
*fullbox
}
func (b *NullMediaHeader) parse() error {
return nil
}