-
Notifications
You must be signed in to change notification settings - Fork 227
/
format.go
266 lines (234 loc) · 6.35 KB
/
format.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package format
//nolint:revive
const (
ALL = "all"
IMAGE = "image"
PROBE = "probe"
LINK_FRAME = "link_frame" // ex: ethernet
INET_PACKET = "inet_packet" // ex: ipv4
IP_PACKET = "ip_packet" // ex: tcp
TCP_STREAM = "tcp_stream" // ex: http
UDP_PAYLOAD = "udp_payload" // ex: dns
AAC_FRAME = "aac_frame"
ADTS = "adts"
ADTS_FRAME = "adts_frame"
AMF0 = "amf0"
APEV2 = "apev2"
AR = "ar"
ASN1_BER = "asn1_ber"
AV1_CCR = "av1_ccr"
AV1_FRAME = "av1_frame"
AV1_OBU = "av1_obu"
AVC_ANNEXB = "avc_annexb"
AVC_AU = "avc_au"
AVC_DCR = "avc_dcr"
AVC_NALU = "avc_nalu"
AVC_PPS = "avc_pps"
AVC_SEI = "avc_sei"
AVC_SPS = "avc_sps"
AVRO_OCF = "avro_ocf"
BENCODE = "bencode"
BSD_LOOPBACK_FRAME = "bsd_loopback_frame"
BSON = "bson"
BZIP2 = "bzip2"
CBOR = "cbor"
DNS = "dns"
DNS_TCP = "dns_tcp"
ELF = "elf"
ETHER8023_FRAME = "ether8023_frame"
EXIF = "exif"
FLAC = "flac"
FLAC_FRAME = "flac_frame"
FLAC_METADATABLOCK = "flac_metadatablock"
FLAC_METADATABLOCKS = "flac_metadatablocks"
FLAC_PICTURE = "flac_picture"
FLAC_STREAMINFO = "flac_streaminfo"
FLV = "flv" // TODO:
GIF = "gif"
GZIP = "gzip"
HEVC_ANNEXB = "hevc_annexb"
HEVC_AU = "hevc_au"
HEVC_DCR = "hevc_dcr"
HEVC_NALU = "hevc_nalu"
HEVC_PPS = "hevc_pps"
HEVC_SPS = "hevc_sps"
HEVC_VPS = "hevc_vps"
ICC_PROFILE = "icc_profile"
ICMP = "icmp"
ICMPV6 = "icmpv6"
ID3V1 = "id3v1"
ID3V11 = "id3v11"
ID3V2 = "id3v2"
IPV4_PACKET = "ipv4_packet"
IPV6_PACKET = "ipv6_packet"
JPEG = "jpeg"
JSON = "json"
MACHO = "macho"
MATROSKA = "matroska"
MP3 = "mp3"
MP3_FRAME = "mp3_frame"
MP4 = "mp4"
MPEG_ASC = "mpeg_asc"
MPEG_ES = "mpeg_es"
MPEG_PES = "mpeg_pes"
MPEG_PES_PACKET = "mpeg_pes_packet"
MPEG_SPU = "mpeg_spu"
MPEG_TS = "mpeg_ts"
MSGPACK = "msgpack"
OGG = "ogg"
OGG_PAGE = "ogg_page"
OPUS_PACKET = "opus_packet"
PCAP = "pcap"
PCAPNG = "pcapng"
PNG = "png"
PROTOBUF = "protobuf"
PROTOBUF_WIDEVINE = "protobuf_widevine"
PSSH_PLAYREADY = "pssh_playready"
RAW = "raw"
RTMP = "rtmp"
SLL_PACKET = "sll_packet"
SLL2_PACKET = "sll2_packet"
TAR = "tar"
TCP_SEGMENT = "tcp_segment"
TIFF = "tiff"
UDP_DATAGRAM = "udp_datagram"
VORBIS_COMMENT = "vorbis_comment"
VORBIS_PACKET = "vorbis_packet"
VP8_FRAME = "vp8_frame"
VP9_CFM = "vp9_cfm"
VP9_FRAME = "vp9_frame"
VPX_CCR = "vpx_ccr"
WAV = "wav"
WEBP = "webp"
XING = "xing"
ZIP = "zip"
)
// below are data types used to communicate between formats <FormatName>In/Out
type FlacStreamInfo struct {
SampleRate uint64
BitsPerSample uint64
TotalSamplesInStream uint64
MD5 []byte
}
type FlacStreaminfoOut struct {
StreamInfo FlacStreamInfo
}
type FlacMetadatablockOut struct {
IsLastBlock bool
HasStreamInfo bool
StreamInfo FlacStreamInfo
}
type FlacMetadatablocksOut struct {
HasStreamInfo bool
StreamInfo FlacStreamInfo
}
type FlacFrameIn struct {
SamplesBuf []byte
BitsPerSample int `doc:"Bits per sample"`
}
type FlacFrameOut struct {
SamplesBuf []byte
Samples uint64
Channels int
BitsPerSample int
}
type OggPageOut struct {
IsLastPage bool
IsFirstPage bool
IsContinuedPacket bool
StreamSerialNumber uint32
SequenceNo uint32
Segments [][]byte
}
type AvcAuIn struct {
LengthSize uint64 `doc:"Length value size"`
}
type AvcDcrOut struct {
LengthSize uint64
}
type HevcAuIn struct {
LengthSize uint64 `doc:"Length value size"`
}
type HevcDcrOut struct {
LengthSize uint64
}
type ProtoBufIn struct {
Message ProtoBufMessage
}
type MpegDecoderConfig struct {
ObjectType int
ASCObjectType int
}
type MpegEsOut struct {
DecoderConfigs []MpegDecoderConfig
}
type MPEGASCOut struct {
ObjectType int
}
type AACFrameIn struct {
ObjectType int `doc:"Audio object type"`
}
type Mp3In struct {
MaxUniqueHeaderConfigs int `doc:"Max number of unique frame header configs allowed"`
MaxSyncSeek int `doc:"Max byte distance to next sync"`
}
type MP3FrameOut struct {
MPEGVersion int
ProtectionAbsent bool
BitRate int
SampleRate int
ChannelsIndex int
ChannelModeIndex int
}
type LinkFrameIn struct {
Type int
IsLittleEndian bool // pcap endian etc
}
type InetPacketIn struct {
EtherType int
}
type IPPacketIn struct {
Protocol int
}
type UDPPayloadIn struct {
SourcePort int
DestinationPort int
}
func (u UDPPayloadIn) IsPort(ports ...int) bool {
for _, p := range ports {
if u.DestinationPort == p || u.SourcePort == p {
return true
}
}
return false
}
func (u UDPPayloadIn) MustIsPort(fn func(format string, a ...interface{}), ports ...int) {
if !u.IsPort(ports...) {
fn("incorrect udp port %t src:%d dst:%d", u.DestinationPort, u.SourcePort)
}
}
type TCPStreamIn struct {
IsClient bool
HasStart bool
HasEnd bool
SourcePort int
DestinationPort int
}
func (t TCPStreamIn) IsPort(ports ...int) bool {
for _, p := range ports {
if (t.IsClient && t.DestinationPort == p) ||
(!t.IsClient && t.SourcePort == p) {
return true
}
}
return false
}
func (t TCPStreamIn) MustIsPort(fn func(format string, a ...interface{}), ports ...int) {
if !t.IsPort(ports...) {
fn("incorrect tcp port client %t src:%d dst:%d", t.IsClient, t.DestinationPort, t.SourcePort)
}
}
type Mp4In struct {
DecodeSamples bool `doc:"Decode supported media samples"`
AllowTruncated bool `doc:"Allow box to be truncated"`
}