-
Notifications
You must be signed in to change notification settings - Fork 31
/
box_types_iso14496_14.go
126 lines (110 loc) · 3.47 KB
/
box_types_iso14496_14.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package mp4
import "fmt"
/*************************** esds ****************************/
// https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html
func BoxTypeEsds() BoxType { return StrToBoxType("esds") }
func init() {
AddBoxDef(&Esds{}, 0)
}
const (
ESDescrTag = 0x03
DecoderConfigDescrTag = 0x04
DecSpecificInfoTag = 0x05
SLConfigDescrTag = 0x06
)
// Esds is ES descripter box
type Esds struct {
FullBox `mp4:"0,extend"`
Descriptors []Descriptor `mp4:"1,array"`
}
// GetType returns the BoxType
func (*Esds) GetType() BoxType {
return BoxTypeEsds()
}
type Descriptor struct {
BaseCustomFieldObject
Tag int8 `mp4:"0,size=8"` // must be 0x03
Size uint32 `mp4:"1,varint"`
ESDescriptor *ESDescriptor `mp4:"2,extend,opt=dynamic"`
DecoderConfigDescriptor *DecoderConfigDescriptor `mp4:"3,extend,opt=dynamic"`
Data []byte `mp4:"4,size=8,opt=dynamic,len=dynamic"`
}
// GetFieldLength returns length of dynamic field
func (ds *Descriptor) GetFieldLength(name string, ctx Context) uint {
switch name {
case "Data":
return uint(ds.Size)
}
panic(fmt.Errorf("invalid name of dynamic-length field: boxType=esds fieldName=%s", name))
}
func (ds *Descriptor) IsOptFieldEnabled(name string, ctx Context) bool {
switch ds.Tag {
case ESDescrTag:
return name == "ESDescriptor"
case DecoderConfigDescrTag:
return name == "DecoderConfigDescriptor"
default:
return name == "Data"
}
}
// StringifyField returns field value as string
func (ds *Descriptor) StringifyField(name string, indent string, depth int, ctx Context) (string, bool) {
switch name {
case "Tag":
switch ds.Tag {
case ESDescrTag:
return "ESDescr", true
case DecoderConfigDescrTag:
return "DecoderConfigDescr", true
case DecSpecificInfoTag:
return "DecSpecificInfo", true
case SLConfigDescrTag:
return "SLConfigDescr", true
default:
return "", false
}
default:
return "", false
}
}
type ESDescriptor struct {
BaseCustomFieldObject
ESID uint16 `mp4:"0,size=16"`
StreamDependenceFlag bool `mp4:"1,size=1"`
UrlFlag bool `mp4:"2,size=1"`
OcrStreamFlag bool `mp4:"3,size=1"`
StreamPriority int8 `mp4:"4,size=5"`
DependsOnESID uint16 `mp4:"5,size=16,opt=dynamic"`
URLLength uint8 `mp4:"6,size=8,opt=dynamic"`
URLString []byte `mp4:"7,size=8,len=dynamic,opt=dynamic,string"`
OCRESID uint16 `mp4:"8,size=16,opt=dynamic"`
}
func (esds *ESDescriptor) GetFieldLength(name string, ctx Context) uint {
switch name {
case "URLString":
return uint(esds.URLLength)
}
panic(fmt.Errorf("invalid name of dynamic-length field: boxType=ESDescriptor fieldName=%s", name))
}
func (esds *ESDescriptor) IsOptFieldEnabled(name string, ctx Context) bool {
switch name {
case "DependsOnESID":
return esds.StreamDependenceFlag
case "URLLength", "URLString":
return esds.UrlFlag
case "OCRESID":
return esds.OcrStreamFlag
default:
return false
}
}
type DecoderConfigDescriptor struct {
BaseCustomFieldObject
ObjectTypeIndication byte `mp4:"0,size=8"`
StreamType int8 `mp4:"1,size=6"`
UpStream bool `mp4:"2,size=1"`
Reserved bool `mp4:"3,size=1"`
BufferSizeDB uint32 `mp4:"4,size=24"`
MaxBitrate uint32 `mp4:"5,size=32"`
AvgBitrate uint32 `mp4:"6,size=32"`
}