forked from tinyzimmer/go-gst
/
gst_video_format.go
473 lines (425 loc) · 26.3 KB
/
gst_video_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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
package video
/*
#include <gst/video/video.h>
const gchar * formatInfoName (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_NAME(info); }
guint formatInfoBits (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_BITS(info); }
guint formatInfoDepth (GstVideoFormatInfo * info, guint c) { return GST_VIDEO_FORMAT_INFO_DEPTH(info, c); }
GstVideoFormatFlags formatInfoFlags (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_FLAGS(info); }
GstVideoFormat formatInfoFormat (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_FORMAT(info); }
gboolean formatInfoHasAlpha (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_HAS_ALPHA(info); }
gboolean formatInfoHasPalette (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_HAS_PALETTE(info); }
guint formatInfoHSub (GstVideoFormatInfo * info, guint c) { return GST_VIDEO_FORMAT_INFO_H_SUB(info, c); }
gboolean formatInfoIsComplex (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_IS_COMPLEX(info); }
gboolean formatInfoIsGray (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_IS_GRAY(info); }
gboolean formatInfoIsLE (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_IS_LE(info); }
gboolean formatInfoIsRGB (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_IS_RGB(info); }
gboolean formatInfoIsTiled (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_IS_TILED(info); }
gboolean formatInfoIsYUV (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_IS_YUV(info); }
guint formatInfoNComponent (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_N_COMPONENTS(info); }
guint formatInfoNPlanes (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_N_PLANES(info); }
guint formatInfoPlane (GstVideoFormatInfo * info, guint c) { return GST_VIDEO_FORMAT_INFO_PLANE(info, c); }
guint formatInfoPOffset (GstVideoFormatInfo * info, guint c) { return GST_VIDEO_FORMAT_INFO_POFFSET(info, c); }
guint formatInfoPStride (GstVideoFormatInfo * info, guint c) { return GST_VIDEO_FORMAT_INFO_PSTRIDE(info, c); }
guint formatInfoTileHS (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_TILE_HS(info); }
GstVideoTileMode formatInfoTileMode (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_TILE_MODE(info); }
guint formatInfoTileWS (GstVideoFormatInfo * info) { return GST_VIDEO_FORMAT_INFO_TILE_WS(info); }
guint formatInfoWSub (GstVideoFormatInfo * info, guint c) { return GST_VIDEO_FORMAT_INFO_W_SUB(info, c); }
*/
import "C"
import (
"image/color"
"runtime"
"unsafe"
"github.com/tinyzimmer/go-glib/glib"
"github.com/tinyzimmer/go-gst/gst"
)
func init() {
glib.RegisterGValueMarshalers([]glib.TypeMarshaler{
{
T: glib.Type(C.gst_video_format_get_type()),
F: func(p uintptr) (interface{}, error) {
c := C.g_value_get_enum(uintptrToGVal(p))
return Format(c), nil
},
},
})
}
// Format is an enum value describing the most common video formats.
type Format int
// Type castings
const (
FormatUnknown Format = C.GST_VIDEO_FORMAT_UNKNOWN // (0) – Unknown or unset video format id
FormatEncoded Format = C.GST_VIDEO_FORMAT_ENCODED // (1) – Encoded video format. Only ever use that in caps for special video formats in combination with non-system memory GstCapsFeatures where it does not make sense to specify a real video format.
FormatI420 Format = C.GST_VIDEO_FORMAT_I420 // (2) – planar 4:2:0 YUV
FormatYV12 Format = C.GST_VIDEO_FORMAT_YV12 // (3) – planar 4:2:0 YVU (like I420 but UV planes swapped)
FormatYUY2 Format = C.GST_VIDEO_FORMAT_YUY2 // (4) – packed 4:2:2 YUV (Y0-U0-Y1-V0 Y2-U2-Y3-V2 Y4 ...)
FormatUYVY Format = C.GST_VIDEO_FORMAT_UYVY // (5) – packed 4:2:2 YUV (U0-Y0-V0-Y1 U2-Y2-V2-Y3 U4 ...)
FormatAYUV Format = C.GST_VIDEO_FORMAT_AYUV // (6) – packed 4:4:4 YUV with alpha channel (A0-Y0-U0-V0 ...)
FormatRGBx Format = C.GST_VIDEO_FORMAT_RGBx // (7) – sparse rgb packed into 32 bit, space last
FormatBGRx Format = C.GST_VIDEO_FORMAT_BGRx // (8) – sparse reverse rgb packed into 32 bit, space last
FormatxRGB Format = C.GST_VIDEO_FORMAT_xRGB // (9) – sparse rgb packed into 32 bit, space first
FormatxBGR Format = C.GST_VIDEO_FORMAT_xBGR // (10) – sparse reverse rgb packed into 32 bit, space first
FormatRGBA Format = C.GST_VIDEO_FORMAT_RGBA // (11) – rgb with alpha channel last
FormatBGRA Format = C.GST_VIDEO_FORMAT_BGRA // (12) – reverse rgb with alpha channel last
FormatARGB Format = C.GST_VIDEO_FORMAT_ARGB // (13) – rgb with alpha channel first
FormatABGR Format = C.GST_VIDEO_FORMAT_ABGR // (14) – reverse rgb with alpha channel first
FormatRGB Format = C.GST_VIDEO_FORMAT_RGB // (15) – RGB packed into 24 bits without padding (R-G-B-R-G-B)
FormatBGR Format = C.GST_VIDEO_FORMAT_BGR // (16) – reverse RGB packed into 24 bits without padding (B-G-R-B-G-R)
FormatY41B Format = C.GST_VIDEO_FORMAT_Y41B // (17) – planar 4:1:1 YUV
FormatY42B Format = C.GST_VIDEO_FORMAT_Y42B // (18) – planar 4:2:2 YUV
FormatYVYU Format = C.GST_VIDEO_FORMAT_YVYU // (19) – packed 4:2:2 YUV (Y0-V0-Y1-U0 Y2-V2-Y3-U2 Y4 ...)
FormatY444 Format = C.GST_VIDEO_FORMAT_Y444 // (20) – planar 4:4:4 YUV
Formatv210 Format = C.GST_VIDEO_FORMAT_v210 // (21) – packed 4:2:2 10-bit YUV, complex format
Formatv216 Format = C.GST_VIDEO_FORMAT_v216 // (22) – packed 4:2:2 16-bit YUV, Y0-U0-Y1-V1 order
FormatNV12 Format = C.GST_VIDEO_FORMAT_NV12 // (23) – planar 4:2:0 YUV with interleaved UV plane
FormatNV21 Format = C.GST_VIDEO_FORMAT_NV21 // (24) – planar 4:2:0 YUV with interleaved VU plane
FormatGray8 Format = C.GST_VIDEO_FORMAT_GRAY8 // (25) – 8-bit grayscale
FormatGray16BE Format = C.GST_VIDEO_FORMAT_GRAY16_BE // (26) – 16-bit grayscale, most significant byte first
FormatGray16LE Format = C.GST_VIDEO_FORMAT_GRAY16_LE // (27) – 16-bit grayscale, least significant byte first
Formatv308 Format = C.GST_VIDEO_FORMAT_v308 // (28) – packed 4:4:4 YUV (Y-U-V ...)
FormatRGB16 Format = C.GST_VIDEO_FORMAT_RGB16 // (29) – rgb 5-6-5 bits per component
FormatBGR16 Format = C.GST_VIDEO_FORMAT_BGR16 // (30) – reverse rgb 5-6-5 bits per component
FormatRGB15 Format = C.GST_VIDEO_FORMAT_RGB15 // (31) – rgb 5-5-5 bits per component
FormatBGR15 Format = C.GST_VIDEO_FORMAT_BGR15 // (32) – reverse rgb 5-5-5 bits per component
FormatUYVP Format = C.GST_VIDEO_FORMAT_UYVP // (33) – packed 10-bit 4:2:2 YUV (U0-Y0-V0-Y1 U2-Y2-V2-Y3 U4 ...)
FormatA420 Format = C.GST_VIDEO_FORMAT_A420 // (34) – planar 4:4:2:0 AYUV
FormatRGB8P Format = C.GST_VIDEO_FORMAT_RGB8P // (35) – 8-bit paletted RGB
FormatYUV9 Format = C.GST_VIDEO_FORMAT_YUV9 // (36) – planar 4:1:0 YUV
FormatYVU9 Format = C.GST_VIDEO_FORMAT_YVU9 // (37) – planar 4:1:0 YUV (like YUV9 but UV planes swapped)
FormatIYU1 Format = C.GST_VIDEO_FORMAT_IYU1 // (38) – packed 4:1:1 YUV (Cb-Y0-Y1-Cr-Y2-Y3 ...)
FormatARGB64 Format = C.GST_VIDEO_FORMAT_ARGB64 // (39) – rgb with alpha channel first, 16 bits per channel
FormatAYUV64 Format = C.GST_VIDEO_FORMAT_AYUV64 // (40) – packed 4:4:4 YUV with alpha channel, 16 bits per channel (A0-Y0-U0-V0 ...)
Formatr210 Format = C.GST_VIDEO_FORMAT_r210 // (41) – packed 4:4:4 RGB, 10 bits per channel
FormatI42010BE Format = C.GST_VIDEO_FORMAT_I420_10BE // (42) – planar 4:2:0 YUV, 10 bits per channel
FormatI42010LE Format = C.GST_VIDEO_FORMAT_I420_10LE // (43) – planar 4:2:0 YUV, 10 bits per channel
FormatI42210BE Format = C.GST_VIDEO_FORMAT_I422_10BE // (44) – planar 4:2:2 YUV, 10 bits per channel
FormatI42210LE Format = C.GST_VIDEO_FORMAT_I422_10LE // (45) – planar 4:2:2 YUV, 10 bits per channel
FormatY44410BE Format = C.GST_VIDEO_FORMAT_Y444_10BE // (46) – planar 4:4:4 YUV, 10 bits per channel (Since: 1.2)
FormatY44410LE Format = C.GST_VIDEO_FORMAT_Y444_10LE // (47) – planar 4:4:4 YUV, 10 bits per channel (Since: 1.2)
FormatGBR Format = C.GST_VIDEO_FORMAT_GBR // (48) – planar 4:4:4 RGB, 8 bits per channel (Since: 1.2)
FormatGBR10BE Format = C.GST_VIDEO_FORMAT_GBR_10BE // (49) – planar 4:4:4 RGB, 10 bits per channel (Since: 1.2)
FormatGBR10LE Format = C.GST_VIDEO_FORMAT_GBR_10LE // (50) – planar 4:4:4 RGB, 10 bits per channel (Since: 1.2)
FormatNV16 Format = C.GST_VIDEO_FORMAT_NV16 // (51) – planar 4:2:2 YUV with interleaved UV plane (Since: 1.2)
FormatNV24 Format = C.GST_VIDEO_FORMAT_NV24 // (52) – planar 4:4:4 YUV with interleaved UV plane (Since: 1.2)
FormatNV1264Z32 Format = C.GST_VIDEO_FORMAT_NV12_64Z32 // (53) – NV12 with 64x32 tiling in zigzag pattern (Since: 1.4)
FormatA42010BE Format = C.GST_VIDEO_FORMAT_A420_10BE // (54) – planar 4:4:2:0 YUV, 10 bits per channel (Since: 1.6)
FormatA42010LE Format = C.GST_VIDEO_FORMAT_A420_10LE // (55) – planar 4:4:2:0 YUV, 10 bits per channel (Since: 1.6)
FormatA42210BE Format = C.GST_VIDEO_FORMAT_A422_10BE // (56) – planar 4:4:2:2 YUV, 10 bits per channel (Since: 1.6)
FormatA42210LE Format = C.GST_VIDEO_FORMAT_A422_10LE // (57) – planar 4:4:2:2 YUV, 10 bits per channel (Since: 1.6)
FormatA44410BE Format = C.GST_VIDEO_FORMAT_A444_10BE // (58) – planar 4:4:4:4 YUV, 10 bits per channel (Since: 1.6)
FormatA44410LE Format = C.GST_VIDEO_FORMAT_A444_10LE // (59) – planar 4:4:4:4 YUV, 10 bits per channel (Since: 1.6)
FormatNV61 Format = C.GST_VIDEO_FORMAT_NV61 // (60) – planar 4:2:2 YUV with interleaved VU plane (Since: 1.6)
FormatP01010BE Format = C.GST_VIDEO_FORMAT_P010_10BE // (61) – planar 4:2:0 YUV with interleaved UV plane, 10 bits per channel (Since: 1.10)
FormatP01010LE Format = C.GST_VIDEO_FORMAT_P010_10LE // (62) – planar 4:2:0 YUV with interleaved UV plane, 10 bits per channel (Since: 1.10)
FormatIYU2 Format = C.GST_VIDEO_FORMAT_IYU2 // (63) – packed 4:4:4 YUV (U-Y-V ...) (Since: 1.10)
FormatVYUY Format = C.GST_VIDEO_FORMAT_VYUY // (64) – packed 4:2:2 YUV (V0-Y0-U0-Y1 V2-Y2-U2-Y3 V4 ...)
FormatGBRA Format = C.GST_VIDEO_FORMAT_GBRA // (65) – planar 4:4:4:4 ARGB, 8 bits per channel (Since: 1.12)
FormatGBRA10BE Format = C.GST_VIDEO_FORMAT_GBRA_10BE // (66) – planar 4:4:4:4 ARGB, 10 bits per channel (Since: 1.12)
FormatGBRA10LE Format = C.GST_VIDEO_FORMAT_GBRA_10LE // (67) – planar 4:4:4:4 ARGB, 10 bits per channel (Since: 1.12)
FormatGBR12BE Format = C.GST_VIDEO_FORMAT_GBR_12BE // (68) – planar 4:4:4 RGB, 12 bits per channel (Since: 1.12)
FormatGBR12LE Format = C.GST_VIDEO_FORMAT_GBR_12LE // (69) – planar 4:4:4 RGB, 12 bits per channel (Since: 1.12)
FormatGBRA12BE Format = C.GST_VIDEO_FORMAT_GBRA_12BE // (70) – planar 4:4:4:4 ARGB, 12 bits per channel (Since: 1.12)
FormatGBRA12LE Format = C.GST_VIDEO_FORMAT_GBRA_12LE // (71) – planar 4:4:4:4 ARGB, 12 bits per channel (Since: 1.12)
FormatI42012BE Format = C.GST_VIDEO_FORMAT_I420_12BE // (72) – planar 4:2:0 YUV, 12 bits per channel (Since: 1.12)
FormatI42012LE Format = C.GST_VIDEO_FORMAT_I420_12LE // (73) – planar 4:2:0 YUV, 12 bits per channel (Since: 1.12)
FormatI42212BE Format = C.GST_VIDEO_FORMAT_I422_12BE // (74) – planar 4:2:2 YUV, 12 bits per channel (Since: 1.12)
FormatI42212LE Format = C.GST_VIDEO_FORMAT_I422_12LE // (75) – planar 4:2:2 YUV, 12 bits per channel (Since: 1.12)
FormatY44412BE Format = C.GST_VIDEO_FORMAT_Y444_12BE // (76) – planar 4:4:4 YUV, 12 bits per channel (Since: 1.12)
FormatY44412LE Format = C.GST_VIDEO_FORMAT_Y444_12LE // (77) – planar 4:4:4 YUV, 12 bits per channel (Since: 1.12)
FormatGray10LE32 Format = C.GST_VIDEO_FORMAT_GRAY10_LE32 // (78) – 10-bit grayscale, packed into 32bit words (2 bits padding) (Since: 1.14)
FormatNV1210LE32 Format = C.GST_VIDEO_FORMAT_NV12_10LE32 // (79) – 10-bit variant of GST_VIDEO_FORMAT_NV12, packed into 32bit words (MSB 2 bits padding) (Since: 1.14)
FormatNV1610LE32 Format = C.GST_VIDEO_FORMAT_NV16_10LE32 // (80) – 10-bit variant of GST_VIDEO_FORMAT_NV16, packed into 32bit words (MSB 2 bits padding) (Since: 1.14)
FormatNV1210LE40 Format = C.GST_VIDEO_FORMAT_NV12_10LE40 // (81) – Fully packed variant of NV12_10LE32 (Since: 1.16)
FormatY210 Format = C.GST_VIDEO_FORMAT_Y210 // (82) – packed 4:2:2 YUV, 10 bits per channel (Since: 1.16)
FormatY410 Format = C.GST_VIDEO_FORMAT_Y410 // (83) – packed 4:4:4 YUV, 10 bits per channel(A-V-Y-U...) (Since: 1.16)
FormatVUYA Format = C.GST_VIDEO_FORMAT_VUYA // (84) – packed 4:4:4 YUV with alpha channel (V0-U0-Y0-A0...) (Since: 1.16)
FormatBGR10A2LE Format = C.GST_VIDEO_FORMAT_BGR10A2_LE // (85) – packed 4:4:4 RGB with alpha channel(B-G-R-A), 10 bits for R/G/B channel and MSB 2 bits for alpha channel (Since: 1.16)
FormatRGB10A2LE Format = C.GST_VIDEO_FORMAT_RGB10A2_LE // (86) – packed 4:4:4 RGB with alpha channel(R-G-B-A), 10 bits for R/G/B channel and MSB 2 bits for alpha channel (Since: 1.18)
FormatY44416BE Format = C.GST_VIDEO_FORMAT_Y444_16BE // (87) – planar 4:4:4 YUV, 16 bits per channel (Since: 1.18)
FormatY44416LE Format = C.GST_VIDEO_FORMAT_Y444_16LE // (88) – planar 4:4:4 YUV, 16 bits per channel (Since: 1.18)
FormatP016BE Format = C.GST_VIDEO_FORMAT_P016_BE // (89) – planar 4:2:0 YUV with interleaved UV plane, 16 bits per channel (Since: 1.18)
FormatP016LE Format = C.GST_VIDEO_FORMAT_P016_LE // (90) – planar 4:2:0 YUV with interleaved UV plane, 16 bits per channel (Since: 1.18)
FormatP012BE Format = C.GST_VIDEO_FORMAT_P012_BE // (91) – planar 4:2:0 YUV with interleaved UV plane, 12 bits per channel (Since: 1.18)
FormatP012LE Format = C.GST_VIDEO_FORMAT_P012_LE // (92) – planar 4:2:0 YUV with interleaved UV plane, 12 bits per channel (Since: 1.18)
FormatY212BE Format = C.GST_VIDEO_FORMAT_Y212_BE // (93) – packed 4:2:2 YUV, 12 bits per channel (Y-U-Y-V) (Since: 1.18)
FormatY212LE Format = C.GST_VIDEO_FORMAT_Y212_LE // (94) – packed 4:2:2 YUV, 12 bits per channel (Y-U-Y-V) (Since: 1.18)
FormatY412BE Format = C.GST_VIDEO_FORMAT_Y412_BE // (95) – packed 4:4:4:4 YUV, 12 bits per channel(U-Y-V-A...) (Since: 1.18)
FormatY412LE Format = C.GST_VIDEO_FORMAT_Y412_LE // (96) – packed 4:4:4:4 YUV, 12 bits per channel(U-Y-V-A...) (Since: 1.18)
FormatNV124L4 Format = C.GST_VIDEO_FORMAT_NV12_4L4 // (97) – NV12 with 4x4 tiles in linear order.
FormatNV1232L32 Format = C.GST_VIDEO_FORMAT_NV12_32L32 // (98) – NV12 with 32x32 tiles in linear order.
)
// AllFormats is a convenience function for retrieving all formats for inspection purposes.
// This is not really intended for use in an application, and moreso for debugging.
func AllFormats() []Format {
return []Format{
FormatI420,
FormatYV12,
FormatYUY2,
FormatUYVY,
FormatAYUV,
FormatRGBx,
FormatBGRx,
FormatxRGB,
FormatxBGR,
FormatRGBA,
FormatBGRA,
FormatARGB,
FormatABGR,
FormatRGB,
FormatBGR,
FormatY41B,
FormatY42B,
FormatYVYU,
FormatY444,
Formatv210,
Formatv216,
FormatNV12,
FormatNV21,
FormatGray8,
FormatGray16BE,
FormatGray16LE,
Formatv308,
FormatRGB16,
FormatBGR16,
FormatRGB15,
FormatBGR15,
FormatUYVP,
FormatA420,
FormatRGB8P,
FormatYUV9,
FormatYVU9,
FormatIYU1,
FormatARGB64,
FormatAYUV64,
Formatr210,
FormatI42010BE,
FormatI42010LE,
FormatI42210BE,
FormatI42210LE,
FormatY44410BE,
FormatY44410LE,
FormatGBR,
FormatGBR10BE,
FormatGBR10LE,
FormatNV16,
FormatNV24,
FormatNV1264Z32,
FormatA42010BE,
FormatA42010LE,
FormatA42210BE,
FormatA42210LE,
FormatA44410BE,
FormatA44410LE,
FormatNV61,
FormatP01010BE,
FormatP01010LE,
FormatIYU2,
FormatVYUY,
FormatGBRA,
FormatGBRA10BE,
FormatGBRA10LE,
FormatGBR12BE,
FormatGBR12LE,
FormatGBRA12BE,
FormatGBRA12LE,
FormatI42012BE,
FormatI42012LE,
FormatI42212BE,
FormatI42212LE,
FormatY44412BE,
FormatY44412LE,
FormatGray10LE32,
FormatNV1210LE32,
FormatNV1610LE32,
FormatNV1210LE40,
FormatY210,
FormatY410,
FormatVUYA,
FormatBGR10A2LE,
FormatRGB10A2LE,
FormatY44416BE,
FormatY44416LE,
FormatP016BE,
FormatP016LE,
FormatP012BE,
FormatP012LE,
FormatY212BE,
FormatY212LE,
FormatY412BE,
FormatY412LE,
FormatNV124L4,
FormatNV1232L32,
}
}
// RawFormats returns a slice of all the raw video formats supported by GStreamer.
func RawFormats() []Format {
var size C.guint
formats := C.gst_video_formats_raw(&size)
out := make([]Format, uint(size))
for i, f := range (*[1 << 30]C.GstVideoFormat)(unsafe.Pointer(formats))[:size:size] {
out[i] = Format(f)
}
return out
}
// MakeRawCaps returns a generic raw video caps for formats defined in formats. If formats is empty or nil, returns a caps for
// all the supported raw video formats, see RawFormats.
func MakeRawCaps(formats []Format) *gst.Caps {
var caps *C.GstCaps
if len(formats) == 0 {
caps = C.gst_video_make_raw_caps(nil, C.guint(0))
} else {
caps = C.gst_video_make_raw_caps(
(*C.GstVideoFormat)(unsafe.Pointer(&formats[0])),
C.guint(len(formats)),
)
}
return gst.FromGstCapsUnsafeFull(unsafe.Pointer(caps))
}
// MakeRawCapsWithFeatures returns a generic raw video caps for formats defined in formats with features. If formats is
// empty or nil, returns a caps for all the supported video formats, see RawFormats.
func MakeRawCapsWithFeatures(formats []Format, features *gst.CapsFeatures) *gst.Caps {
var caps *C.GstCaps
if len(formats) == 0 {
caps = C.gst_video_make_raw_caps_with_features(nil, C.guint(0), fromCoreCapsFeatures(features))
} else {
caps = C.gst_video_make_raw_caps_with_features(
(*C.GstVideoFormat)(unsafe.Pointer(&formats[0])),
C.guint(len(formats)),
fromCoreCapsFeatures(features),
)
}
return gst.FromGstCapsUnsafeFull(unsafe.Pointer(caps))
}
// TypeFormat is the GType for a GstVideoFormat.
var TypeFormat = glib.Type(C.gst_video_format_get_type())
// ToGValue implements a glib.ValueTransformer
func (f Format) ToGValue() (*glib.Value, error) {
val, err := glib.ValueInit(TypeFormat)
if err != nil {
return nil, err
}
val.SetEnum(int(f))
return val, nil
}
// Info returns the FormatInfo for this video format.
func (f Format) Info() *FormatInfo {
finfo := C.gst_video_format_get_info(C.GstVideoFormat(f))
info := &FormatInfo{ptr: finfo}
runtime.SetFinalizer(info, func(_ *FormatInfo) { C.g_free((C.gpointer)(unsafe.Pointer(finfo))) })
return info
}
// Palette returns the color palette for this format, or nil if the format does not have one.
// At time of writing, RGB8P appears to be the only format with it's own palette.
func (f Format) Palette() color.Palette {
var size C.gsize
ptr := C.gst_video_format_get_palette(C.GstVideoFormat(f), &size)
if ptr == nil {
return nil
}
paletteBytes := make([]uint8, int64(size))
for i, t := range (*[1 << 30]uint8)(ptr)[:int(size):int(size)] {
paletteBytes[i] = t
}
return bytesToColorPalette(paletteBytes)
}
func bytesToColorPalette(in []uint8) color.Palette {
palette := make([]color.Color, len(in)/4)
for i := 0; i < len(in); i += 4 {
palette[i/4] = color.RGBA{in[i], in[i+1], in[i+2], in[i+3]}
}
return color.Palette(palette)
}
// String implements a stringer on a Format.
func (f Format) String() string {
return C.GoString(C.gst_video_format_to_string(C.GstVideoFormat(f)))
}
// FOURCC converts this format value into the corresponding FOURCC. Only a few YUV formats have corresponding
// FOURCC values. If format has no corresponding FOURCC value, 0 is returned.
func (f Format) FOURCC() uint32 {
return uint32(C.gst_video_format_to_fourcc(C.GstVideoFormat(f)))
}
// FormatFlags are different video flags that a format info can have.
type FormatFlags int
// Type castings
const (
FormatFlagYUV FormatFlags = C.GST_VIDEO_FORMAT_FLAG_YUV // (1) – The video format is YUV, components are numbered 0=Y, 1=U, 2=V.
FormatFlagRGB FormatFlags = C.GST_VIDEO_FORMAT_FLAG_RGB // (2) – The video format is RGB, components are numbered 0=R, 1=G, 2=B.
FormatFlagGray FormatFlags = C.GST_VIDEO_FORMAT_FLAG_GRAY // (4) – The video is gray, there is one gray component with index 0.
FormatFlagAlpha FormatFlags = C.GST_VIDEO_FORMAT_FLAG_ALPHA // (8) – The video format has an alpha components with the number 3.
FormatFlagLE FormatFlags = C.GST_VIDEO_FORMAT_FLAG_LE // (16) – The video format has data stored in little endianness.
FormatFlagPalette FormatFlags = C.GST_VIDEO_FORMAT_FLAG_PALETTE // (32) – The video format has a palette. The palette is stored in the second plane and indexes are stored in the first plane.
FormatFlagComplex FormatFlags = C.GST_VIDEO_FORMAT_FLAG_COMPLEX // (64) – The video format has a complex layout that can't be described with the usual information in the GstVideoFormatInfo.
FormatFlagUnpack FormatFlags = C.GST_VIDEO_FORMAT_FLAG_UNPACK // (128) – This format can be used in a GstVideoFormatUnpack and GstVideoFormatPack function.
FormatFlagTiled FormatFlags = C.GST_VIDEO_FORMAT_FLAG_TILED // (256) – The format is tiled, there is tiling information in the last plane.
)
// PackFlags are different flags that can be used when packing and unpacking.
type PackFlags int
// Type castings
const (
PackFlagNone PackFlags = C.GST_VIDEO_PACK_FLAG_NONE // (0) – No flag
PackFlagTruncateRange PackFlags = C.GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE // (1) – When the source has a smaller depth than the target format, set the least significant bits of the target to 0. This is likely slightly faster but less accurate. When this flag is not specified, the most significant bits of the source are duplicated in the least significant bits of the destination.
PackFlagInterlaced PackFlags = C.GST_VIDEO_PACK_FLAG_INTERLACED // (2) – The source is interlaced. The unpacked format will be interlaced as well with each line containing information from alternating fields. (Since: 1.2)
)
// FormatInfo contains information for a video format.
type FormatInfo struct {
ptr *C.GstVideoFormatInfo
}
func (f *FormatInfo) instance() *C.GstVideoFormatInfo { return f.ptr }
// Bits returns the number of bits used to pack data items. This can be less than 8 when
// multiple pixels are stored in a byte. for values > 8 multiple bytes should be read
// according to the endianness flag before applying the shift and mask.
func (f *FormatInfo) Bits() uint { return uint(C.formatInfoBits(f.instance())) }
// ComponentDepth returns the depth in bits for the given component.
func (f *FormatInfo) ComponentDepth(component uint) uint {
return uint(C.formatInfoDepth(f.instance(), C.guint(component)))
}
// ComponentHSub returns the subsampling factor of the height for the component.
func (f *FormatInfo) ComponentHSub(component uint) uint {
return uint(C.formatInfoHSub(f.instance(), C.guint(component)))
}
// ComponentWSub returns the subsampling factor of the width for the component.
func (f *FormatInfo) ComponentWSub(n uint) uint {
return uint(C.formatInfoWSub(f.instance(), C.guint(n)))
}
// Flags returns the flags on this info.
func (f *FormatInfo) Flags() FormatFlags { return FormatFlags(C.formatInfoFlags(f.instance())) }
// Format returns the format for this info.
func (f *FormatInfo) Format() Format { return Format(C.formatInfoFormat(f.instance())) }
// HasAlpha returns true if the alpha flag is set.
func (f *FormatInfo) HasAlpha() bool { return gobool(C.formatInfoHasAlpha(f.instance())) }
// HasPalette returns true if this info has a palette.
func (f *FormatInfo) HasPalette() bool { return gobool(C.formatInfoHasPalette(f.instance())) }
// IsComplex returns true if the complex flag is set.
func (f *FormatInfo) IsComplex() bool { return gobool(C.formatInfoIsComplex(f.instance())) }
// IsGray returns true if the gray flag is set.
func (f *FormatInfo) IsGray() bool { return gobool(C.formatInfoIsGray(f.instance())) }
// IsLE returns true if the LE flag is set.
func (f *FormatInfo) IsLE() bool { return gobool(C.formatInfoIsLE(f.instance())) }
// IsRGB returns true if the RGB flag is set.
func (f *FormatInfo) IsRGB() bool { return gobool(C.formatInfoIsRGB(f.instance())) }
// IsTiled returns true if the tiled flag is set.
func (f *FormatInfo) IsTiled() bool { return gobool(C.formatInfoIsTiled(f.instance())) }
// IsYUV returns true if the YUV flag is set.
func (f *FormatInfo) IsYUV() bool { return gobool(C.formatInfoIsYUV(f.instance())) }
// Name returns a human readable name for this info.
func (f *FormatInfo) Name() string { return C.GoString(C.formatInfoName(f.instance())) }
// NumComponents returns the number of components in this info.
func (f *FormatInfo) NumComponents() uint { return uint(C.formatInfoNComponent(f.instance())) }
// NumPlanes returns the number of planes in this info.
func (f *FormatInfo) NumPlanes() uint { return uint(C.formatInfoNPlanes(f.instance())) }
// Plane returns the given plane index.
func (f *FormatInfo) Plane(n uint) uint { return uint(C.formatInfoPlane(f.instance(), C.guint(n))) }
// PlaneOffset returns the offset for the given plane.
func (f *FormatInfo) PlaneOffset(n uint) uint {
return uint(C.formatInfoPOffset(f.instance(), C.guint(n)))
}
// PlaneStride returns the stride for the given plane.
func (f *FormatInfo) PlaneStride(n uint) uint {
return uint(C.formatInfoPStride(f.instance(), C.guint(n)))
}
// TileHS returns the height of a tile, in bytes, represented as a shift.
func (f *FormatInfo) TileHS() uint { return uint(C.formatInfoTileHS(f.instance())) }
// TileMode returns the tiling mode.
func (f *FormatInfo) TileMode() TileMode { return TileMode(C.formatInfoTileMode(f.instance())) }
// TileWS returns the width of a tile, in bytes, represented as a shift.
func (f *FormatInfo) TileWS() uint { return uint(C.formatInfoTileWS(f.instance())) }