3 * Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * 2006 Edgard Lima <edgard.lima@gmail.com>
6 * gstv4l2object.c: base class for V4L2 elements
8 * This library is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Library General Public License as published
10 * by the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. This library is distributed in the hope
12 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
13 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
31 #include <sys/ioctl.h>
35 #include <gudev/gudev.h>
38 #include "ext/videodev2.h"
39 #include "gstv4l2object.h"
40 #include "gstv4l2tuner.h"
41 #include "gstv4l2colorbalance.h"
43 #include "gst/gst-i18n-plugin.h"
45 #include <gst/video/video.h>
47 GST_DEBUG_CATEGORY_EXTERN (v4l2_debug);
48 #define GST_CAT_DEFAULT v4l2_debug
50 #define DEFAULT_PROP_DEVICE_NAME NULL
51 #define DEFAULT_PROP_DEVICE_FD -1
52 #define DEFAULT_PROP_FLAGS 0
53 #define DEFAULT_PROP_TV_NORM 0
54 #define DEFAULT_PROP_IO_MODE GST_V4L2_IO_AUTO
56 #define ENCODED_BUFFER_SIZE (2 * 1024 * 1024)
61 V4L2_STD_OBJECT_PROPS,
65 * common format / caps utilities:
69 GST_V4L2_RAW = 1 << 0,
70 GST_V4L2_CODEC = 1 << 1,
71 GST_V4L2_TRANSPORT = 1 << 2,
72 GST_V4L2_NO_PARSE = 1 << 3,
80 GstV4L2FormatFlags flags;
83 static const GstV4L2FormatDesc gst_v4l2_formats[] = {
85 {V4L2_PIX_FMT_RGB332, TRUE, GST_V4L2_RAW},
86 {V4L2_PIX_FMT_ARGB555, TRUE, GST_V4L2_RAW},
87 {V4L2_PIX_FMT_XRGB555, TRUE, GST_V4L2_RAW},
88 {V4L2_PIX_FMT_ARGB555X, TRUE, GST_V4L2_RAW},
89 {V4L2_PIX_FMT_XRGB555X, TRUE, GST_V4L2_RAW},
90 {V4L2_PIX_FMT_RGB565, TRUE, GST_V4L2_RAW},
91 {V4L2_PIX_FMT_RGB565X, TRUE, GST_V4L2_RAW},
92 {V4L2_PIX_FMT_BGR666, TRUE, GST_V4L2_RAW},
93 {V4L2_PIX_FMT_BGR24, TRUE, GST_V4L2_RAW},
94 {V4L2_PIX_FMT_RGB24, TRUE, GST_V4L2_RAW},
95 {V4L2_PIX_FMT_ABGR32, TRUE, GST_V4L2_RAW},
96 {V4L2_PIX_FMT_XBGR32, TRUE, GST_V4L2_RAW},
97 {V4L2_PIX_FMT_ARGB32, TRUE, GST_V4L2_RAW},
98 {V4L2_PIX_FMT_XRGB32, TRUE, GST_V4L2_RAW},
100 /* Deprecated Packed RGB Image Formats (alpha ambiguity) */
101 {V4L2_PIX_FMT_RGB444, TRUE, GST_V4L2_RAW},
102 {V4L2_PIX_FMT_RGB555, TRUE, GST_V4L2_RAW},
103 {V4L2_PIX_FMT_RGB555X, TRUE, GST_V4L2_RAW},
104 {V4L2_PIX_FMT_BGR32, TRUE, GST_V4L2_RAW},
105 {V4L2_PIX_FMT_RGB32, TRUE, GST_V4L2_RAW},
108 {V4L2_PIX_FMT_GREY, TRUE, GST_V4L2_RAW},
109 {V4L2_PIX_FMT_Y4, TRUE, GST_V4L2_RAW},
110 {V4L2_PIX_FMT_Y6, TRUE, GST_V4L2_RAW},
111 {V4L2_PIX_FMT_Y10, TRUE, GST_V4L2_RAW},
112 {V4L2_PIX_FMT_Y12, TRUE, GST_V4L2_RAW},
113 {V4L2_PIX_FMT_Y16, TRUE, GST_V4L2_RAW},
114 {V4L2_PIX_FMT_Y16_BE, TRUE, GST_V4L2_RAW},
115 {V4L2_PIX_FMT_Y10BPACK, TRUE, GST_V4L2_RAW},
117 /* Palette formats */
118 {V4L2_PIX_FMT_PAL8, TRUE, GST_V4L2_RAW},
120 /* Chrominance formats */
121 {V4L2_PIX_FMT_UV8, TRUE, GST_V4L2_RAW},
123 /* Luminance+Chrominance formats */
124 {V4L2_PIX_FMT_YVU410, TRUE, GST_V4L2_RAW},
125 {V4L2_PIX_FMT_YVU420, TRUE, GST_V4L2_RAW},
126 {V4L2_PIX_FMT_YVU420M, TRUE, GST_V4L2_RAW},
127 {V4L2_PIX_FMT_YUYV, TRUE, GST_V4L2_RAW},
128 {V4L2_PIX_FMT_YYUV, TRUE, GST_V4L2_RAW},
129 {V4L2_PIX_FMT_YVYU, TRUE, GST_V4L2_RAW},
130 {V4L2_PIX_FMT_UYVY, TRUE, GST_V4L2_RAW},
131 {V4L2_PIX_FMT_VYUY, TRUE, GST_V4L2_RAW},
132 {V4L2_PIX_FMT_YUV422P, TRUE, GST_V4L2_RAW},
133 {V4L2_PIX_FMT_YUV411P, TRUE, GST_V4L2_RAW},
134 {V4L2_PIX_FMT_Y41P, TRUE, GST_V4L2_RAW},
135 {V4L2_PIX_FMT_YUV444, TRUE, GST_V4L2_RAW},
136 {V4L2_PIX_FMT_YUV555, TRUE, GST_V4L2_RAW},
137 {V4L2_PIX_FMT_YUV565, TRUE, GST_V4L2_RAW},
138 {V4L2_PIX_FMT_YUV32, TRUE, GST_V4L2_RAW},
139 {V4L2_PIX_FMT_YUV410, TRUE, GST_V4L2_RAW},
140 {V4L2_PIX_FMT_YUV420, TRUE, GST_V4L2_RAW},
141 {V4L2_PIX_FMT_YUV420M, TRUE, GST_V4L2_RAW},
142 {V4L2_PIX_FMT_HI240, TRUE, GST_V4L2_RAW},
143 {V4L2_PIX_FMT_HM12, TRUE, GST_V4L2_RAW},
144 {V4L2_PIX_FMT_M420, TRUE, GST_V4L2_RAW},
146 /* two planes -- one Y, one Cr + Cb interleaved */
147 {V4L2_PIX_FMT_NV12, TRUE, GST_V4L2_RAW},
148 {V4L2_PIX_FMT_NV12M, TRUE, GST_V4L2_RAW},
149 {V4L2_PIX_FMT_NV12MT, TRUE, GST_V4L2_RAW},
150 {V4L2_PIX_FMT_NV12MT_16X16, TRUE, GST_V4L2_RAW},
151 {V4L2_PIX_FMT_NV21, TRUE, GST_V4L2_RAW},
152 {V4L2_PIX_FMT_NV21M, TRUE, GST_V4L2_RAW},
153 {V4L2_PIX_FMT_NV16, TRUE, GST_V4L2_RAW},
154 {V4L2_PIX_FMT_NV16M, TRUE, GST_V4L2_RAW},
155 {V4L2_PIX_FMT_NV61, TRUE, GST_V4L2_RAW},
156 {V4L2_PIX_FMT_NV61M, TRUE, GST_V4L2_RAW},
157 {V4L2_PIX_FMT_NV24, TRUE, GST_V4L2_RAW},
158 {V4L2_PIX_FMT_NV42, TRUE, GST_V4L2_RAW},
160 /* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */
161 {V4L2_PIX_FMT_SBGGR8, TRUE, GST_V4L2_CODEC},
162 {V4L2_PIX_FMT_SGBRG8, TRUE, GST_V4L2_CODEC},
163 {V4L2_PIX_FMT_SGRBG8, TRUE, GST_V4L2_CODEC},
164 {V4L2_PIX_FMT_SRGGB8, TRUE, GST_V4L2_CODEC},
166 /* compressed formats */
167 {V4L2_PIX_FMT_MJPEG, FALSE, GST_V4L2_CODEC},
168 {V4L2_PIX_FMT_JPEG, FALSE, GST_V4L2_CODEC},
169 {V4L2_PIX_FMT_PJPG, FALSE, GST_V4L2_CODEC},
170 {V4L2_PIX_FMT_DV, FALSE, GST_V4L2_TRANSPORT},
171 {V4L2_PIX_FMT_MPEG, FALSE, GST_V4L2_TRANSPORT},
172 {V4L2_PIX_FMT_H264, FALSE, GST_V4L2_CODEC},
173 {V4L2_PIX_FMT_H264_NO_SC, FALSE, GST_V4L2_CODEC},
174 {V4L2_PIX_FMT_H264_MVC, FALSE, GST_V4L2_CODEC},
175 {V4L2_PIX_FMT_H263, FALSE, GST_V4L2_CODEC},
176 {V4L2_PIX_FMT_MPEG1, FALSE, GST_V4L2_CODEC},
177 {V4L2_PIX_FMT_MPEG2, FALSE, GST_V4L2_CODEC},
178 {V4L2_PIX_FMT_MPEG4, FALSE, GST_V4L2_CODEC},
179 {V4L2_PIX_FMT_XVID, FALSE, GST_V4L2_CODEC},
180 {V4L2_PIX_FMT_VC1_ANNEX_G, FALSE, GST_V4L2_CODEC},
181 {V4L2_PIX_FMT_VC1_ANNEX_L, FALSE, GST_V4L2_CODEC},
182 {V4L2_PIX_FMT_VP8, FALSE, GST_V4L2_CODEC | GST_V4L2_NO_PARSE},
183 {V4L2_PIX_FMT_VP9, FALSE, GST_V4L2_CODEC | GST_V4L2_NO_PARSE},
185 /* Vendor-specific formats */
186 {V4L2_PIX_FMT_WNVA, TRUE, GST_V4L2_CODEC},
187 {V4L2_PIX_FMT_SN9C10X, TRUE, GST_V4L2_CODEC},
188 {V4L2_PIX_FMT_PWC1, TRUE, GST_V4L2_CODEC},
189 {V4L2_PIX_FMT_PWC2, TRUE, GST_V4L2_CODEC},
192 #define GST_V4L2_FORMAT_COUNT (G_N_ELEMENTS (gst_v4l2_formats))
194 static GSList *gst_v4l2_object_get_format_list (GstV4l2Object * v4l2object);
197 #define GST_TYPE_V4L2_DEVICE_FLAGS (gst_v4l2_device_get_type ())
199 gst_v4l2_device_get_type (void)
201 static GType v4l2_device_type = 0;
203 if (v4l2_device_type == 0) {
204 static const GFlagsValue values[] = {
205 {V4L2_CAP_VIDEO_CAPTURE, "Device supports video capture", "capture"},
206 {V4L2_CAP_VIDEO_OUTPUT, "Device supports video playback", "output"},
207 {V4L2_CAP_VIDEO_OVERLAY, "Device supports video overlay", "overlay"},
209 {V4L2_CAP_VBI_CAPTURE, "Device supports the VBI capture", "vbi-capture"},
210 {V4L2_CAP_VBI_OUTPUT, "Device supports the VBI output", "vbi-output"},
212 {V4L2_CAP_TUNER, "Device has a tuner or modulator", "tuner"},
213 {V4L2_CAP_AUDIO, "Device has audio inputs or outputs", "audio"},
219 g_flags_register_static ("GstV4l2DeviceTypeFlags", values);
222 return v4l2_device_type;
225 #define GST_TYPE_V4L2_TV_NORM (gst_v4l2_tv_norm_get_type ())
227 gst_v4l2_tv_norm_get_type (void)
229 static GType v4l2_tv_norm = 0;
232 static const GEnumValue tv_norms[] = {
235 {V4L2_STD_NTSC, "NTSC", "NTSC"},
236 {V4L2_STD_NTSC_M, "NTSC-M", "NTSC-M"},
237 {V4L2_STD_NTSC_M_JP, "NTSC-M-JP", "NTSC-M-JP"},
238 {V4L2_STD_NTSC_M_KR, "NTSC-M-KR", "NTSC-M-KR"},
239 {V4L2_STD_NTSC_443, "NTSC-443", "NTSC-443"},
241 {V4L2_STD_PAL, "PAL", "PAL"},
242 {V4L2_STD_PAL_BG, "PAL-BG", "PAL-BG"},
243 {V4L2_STD_PAL_B, "PAL-B", "PAL-B"},
244 {V4L2_STD_PAL_B1, "PAL-B1", "PAL-B1"},
245 {V4L2_STD_PAL_G, "PAL-G", "PAL-G"},
246 {V4L2_STD_PAL_H, "PAL-H", "PAL-H"},
247 {V4L2_STD_PAL_I, "PAL-I", "PAL-I"},
248 {V4L2_STD_PAL_DK, "PAL-DK", "PAL-DK"},
249 {V4L2_STD_PAL_D, "PAL-D", "PAL-D"},
250 {V4L2_STD_PAL_D1, "PAL-D1", "PAL-D1"},
251 {V4L2_STD_PAL_K, "PAL-K", "PAL-K"},
252 {V4L2_STD_PAL_M, "PAL-M", "PAL-M"},
253 {V4L2_STD_PAL_N, "PAL-N", "PAL-N"},
254 {V4L2_STD_PAL_Nc, "PAL-Nc", "PAL-Nc"},
255 {V4L2_STD_PAL_60, "PAL-60", "PAL-60"},
257 {V4L2_STD_SECAM, "SECAM", "SECAM"},
258 {V4L2_STD_SECAM_B, "SECAM-B", "SECAM-B"},
259 {V4L2_STD_SECAM_G, "SECAM-G", "SECAM-G"},
260 {V4L2_STD_SECAM_H, "SECAM-H", "SECAM-H"},
261 {V4L2_STD_SECAM_DK, "SECAM-DK", "SECAM-DK"},
262 {V4L2_STD_SECAM_D, "SECAM-D", "SECAM-D"},
263 {V4L2_STD_SECAM_K, "SECAM-K", "SECAM-K"},
264 {V4L2_STD_SECAM_K1, "SECAM-K1", "SECAM-K1"},
265 {V4L2_STD_SECAM_L, "SECAM-L", "SECAM-L"},
266 {V4L2_STD_SECAM_LC, "SECAM-Lc", "SECAM-Lc"},
271 v4l2_tv_norm = g_enum_register_static ("V4L2_TV_norms", tv_norms);
278 gst_v4l2_io_mode_get_type (void)
280 static GType v4l2_io_mode = 0;
283 static const GEnumValue io_modes[] = {
284 {GST_V4L2_IO_AUTO, "GST_V4L2_IO_AUTO", "auto"},
285 {GST_V4L2_IO_RW, "GST_V4L2_IO_RW", "rw"},
286 {GST_V4L2_IO_MMAP, "GST_V4L2_IO_MMAP", "mmap"},
287 {GST_V4L2_IO_USERPTR, "GST_V4L2_IO_USERPTR", "userptr"},
288 {GST_V4L2_IO_DMABUF, "GST_V4L2_IO_DMABUF", "dmabuf"},
289 {GST_V4L2_IO_DMABUF_IMPORT, "GST_V4L2_IO_DMABUF_IMPORT",
294 v4l2_io_mode = g_enum_register_static ("GstV4l2IOMode", io_modes);
300 gst_v4l2_object_install_properties_helper (GObjectClass * gobject_class,
301 const char *default_device)
303 g_object_class_install_property (gobject_class, PROP_DEVICE,
304 g_param_spec_string ("device", "Device", "Device location",
305 default_device, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
306 g_object_class_install_property (gobject_class, PROP_DEVICE_NAME,
307 g_param_spec_string ("device-name", "Device name",
308 "Name of the device", DEFAULT_PROP_DEVICE_NAME,
309 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
310 g_object_class_install_property (gobject_class, PROP_DEVICE_FD,
311 g_param_spec_int ("device-fd", "File descriptor",
312 "File descriptor of the device", -1, G_MAXINT, DEFAULT_PROP_DEVICE_FD,
313 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
314 g_object_class_install_property (gobject_class, PROP_FLAGS,
315 g_param_spec_flags ("flags", "Flags", "Device type flags",
316 GST_TYPE_V4L2_DEVICE_FLAGS, DEFAULT_PROP_FLAGS,
317 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
320 * GstV4l2Src:brightness:
322 * Picture brightness, or more precisely, the black level
324 g_object_class_install_property (gobject_class, PROP_BRIGHTNESS,
325 g_param_spec_int ("brightness", "Brightness",
326 "Picture brightness, or more precisely, the black level", G_MININT,
328 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
330 * GstV4l2Src:contrast:
332 * Picture contrast or luma gain
334 g_object_class_install_property (gobject_class, PROP_CONTRAST,
335 g_param_spec_int ("contrast", "Contrast",
336 "Picture contrast or luma gain", G_MININT,
338 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
340 * GstV4l2Src:saturation:
342 * Picture color saturation or chroma gain
344 g_object_class_install_property (gobject_class, PROP_SATURATION,
345 g_param_spec_int ("saturation", "Saturation",
346 "Picture color saturation or chroma gain", G_MININT,
348 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
352 * Hue or color balance
354 g_object_class_install_property (gobject_class, PROP_HUE,
355 g_param_spec_int ("hue", "Hue",
356 "Hue or color balance", G_MININT,
358 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
365 g_object_class_install_property (gobject_class, PROP_TV_NORM,
366 g_param_spec_enum ("norm", "TV norm",
368 GST_TYPE_V4L2_TV_NORM, DEFAULT_PROP_TV_NORM,
369 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
372 * GstV4l2Src:io-mode:
376 g_object_class_install_property (gobject_class, PROP_IO_MODE,
377 g_param_spec_enum ("io-mode", "IO mode",
379 GST_TYPE_V4L2_IO_MODE, DEFAULT_PROP_IO_MODE,
380 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
383 * GstV4l2Src:extra-controls:
385 * Additional v4l2 controls for the device. The controls are identified
386 * by the control name (lowercase with '_' for any non-alphanumeric
391 g_object_class_install_property (gobject_class, PROP_EXTRA_CONTROLS,
392 g_param_spec_boxed ("extra-controls", "Extra Controls",
393 "Extra v4l2 controls (CIDs) for the device",
394 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
397 * GstV4l2Src:pixel-aspect-ratio:
399 * The pixel aspect ratio of the device. This overwrites the pixel aspect
400 * ratio queried from the device.
404 g_object_class_install_property (gobject_class, PROP_PIXEL_ASPECT_RATIO,
405 g_param_spec_string ("pixel-aspect-ratio", "Pixel Aspect Ratio",
406 "Overwrite the pixel aspect ratio of the device", "1/1",
407 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
410 * GstV4l2Src:force-aspect-ratio:
412 * When enabled, the pixel aspect ratio queried from the device or set
413 * with the pixel-aspect-ratio property will be enforced.
417 g_object_class_install_property (gobject_class, PROP_FORCE_ASPECT_RATIO,
418 g_param_spec_boolean ("force-aspect-ratio", "Force aspect ratio",
419 "When enabled, the pixel aspect ratio will be enforced", TRUE,
420 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
425 gst_v4l2_object_install_m2m_properties_helper (GObjectClass * gobject_class)
427 g_object_class_install_property (gobject_class, PROP_DEVICE,
428 g_param_spec_string ("device", "Device", "Device location",
429 NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
431 g_object_class_install_property (gobject_class, PROP_DEVICE_NAME,
432 g_param_spec_string ("device-name", "Device name",
433 "Name of the device", DEFAULT_PROP_DEVICE_NAME,
434 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
436 g_object_class_install_property (gobject_class, PROP_DEVICE_FD,
437 g_param_spec_int ("device-fd", "File descriptor",
438 "File descriptor of the device", -1, G_MAXINT, DEFAULT_PROP_DEVICE_FD,
439 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
441 g_object_class_install_property (gobject_class, PROP_OUTPUT_IO_MODE,
442 g_param_spec_enum ("output-io-mode", "Output IO mode",
443 "Output side I/O mode (matches sink pad)",
444 GST_TYPE_V4L2_IO_MODE, DEFAULT_PROP_IO_MODE,
445 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
447 g_object_class_install_property (gobject_class, PROP_CAPTURE_IO_MODE,
448 g_param_spec_enum ("capture-io-mode", "Capture IO mode",
449 "Capture I/O mode (matches src pad)",
450 GST_TYPE_V4L2_IO_MODE, DEFAULT_PROP_IO_MODE,
451 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
453 g_object_class_install_property (gobject_class, PROP_EXTRA_CONTROLS,
454 g_param_spec_boxed ("extra-controls", "Extra Controls",
455 "Extra v4l2 controls (CIDs) for the device",
456 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
460 gst_v4l2_object_new (GstElement * element,
461 GstObject * debug_object,
462 enum v4l2_buf_type type,
463 const char *default_device,
464 GstV4l2GetInOutFunction get_in_out_func,
465 GstV4l2SetInOutFunction set_in_out_func,
466 GstV4l2UpdateFpsFunction update_fps_func)
468 GstV4l2Object *v4l2object;
471 * some default values
473 v4l2object = g_new0 (GstV4l2Object, 1);
475 v4l2object->type = type;
476 v4l2object->formats = NULL;
478 v4l2object->element = element;
479 v4l2object->dbg_obj = debug_object;
480 v4l2object->get_in_out_func = get_in_out_func;
481 v4l2object->set_in_out_func = set_in_out_func;
482 v4l2object->update_fps_func = update_fps_func;
484 v4l2object->video_fd = -1;
485 v4l2object->active = FALSE;
486 v4l2object->videodev = g_strdup (default_device);
488 v4l2object->norms = NULL;
489 v4l2object->channels = NULL;
490 v4l2object->colors = NULL;
492 v4l2object->keep_aspect = TRUE;
494 v4l2object->n_v4l2_planes = 0;
496 v4l2object->no_initial_format = FALSE;
498 /* We now disable libv4l2 by default, but have an env to enable it. */
500 if (g_getenv ("GST_V4L2_USE_LIBV4L2")) {
501 v4l2object->fd_open = v4l2_fd_open;
502 v4l2object->close = v4l2_close;
503 v4l2object->dup = v4l2_dup;
504 v4l2object->ioctl = v4l2_ioctl;
505 v4l2object->read = v4l2_read;
506 v4l2object->mmap = v4l2_mmap;
507 v4l2object->munmap = v4l2_munmap;
511 v4l2object->fd_open = NULL;
512 v4l2object->close = close;
513 v4l2object->dup = dup;
514 v4l2object->ioctl = ioctl;
515 v4l2object->read = read;
516 v4l2object->mmap = mmap;
517 v4l2object->munmap = munmap;
523 static gboolean gst_v4l2_object_clear_format_list (GstV4l2Object * v4l2object);
527 gst_v4l2_object_destroy (GstV4l2Object * v4l2object)
529 g_return_if_fail (v4l2object != NULL);
531 g_free (v4l2object->videodev);
533 g_free (v4l2object->channel);
535 if (v4l2object->formats) {
536 gst_v4l2_object_clear_format_list (v4l2object);
539 if (v4l2object->probed_caps) {
540 gst_caps_unref (v4l2object->probed_caps);
543 if (v4l2object->extra_controls) {
544 gst_structure_free (v4l2object->extra_controls);
552 gst_v4l2_object_clear_format_list (GstV4l2Object * v4l2object)
554 g_slist_foreach (v4l2object->formats, (GFunc) g_free, NULL);
555 g_slist_free (v4l2object->formats);
556 v4l2object->formats = NULL;
562 gst_v4l2_object_prop_to_cid (guint prop_id)
567 case PROP_BRIGHTNESS:
568 cid = V4L2_CID_BRIGHTNESS;
571 cid = V4L2_CID_CONTRAST;
573 case PROP_SATURATION:
574 cid = V4L2_CID_SATURATION;
580 GST_WARNING ("unmapped property id: %d", prop_id);
587 gst_v4l2_object_set_property_helper (GstV4l2Object * v4l2object,
588 guint prop_id, const GValue * value, GParamSpec * pspec)
592 g_free (v4l2object->videodev);
593 v4l2object->videodev = g_value_dup_string (value);
595 case PROP_BRIGHTNESS:
597 case PROP_SATURATION:
600 gint cid = gst_v4l2_object_prop_to_cid (prop_id);
603 if (GST_V4L2_IS_OPEN (v4l2object)) {
604 gst_v4l2_set_attribute (v4l2object, cid, g_value_get_int (value));
611 v4l2object->tv_norm = g_value_get_enum (value);
615 if (GST_V4L2_IS_OPEN (v4l2object)) {
616 GstTuner *tuner = GST_TUNER (v4l2object->element);
617 GstTunerChannel *channel = gst_tuner_find_channel_by_name (tuner,
618 (gchar *) g_value_get_string (value));
621 /* like gst_tuner_set_channel (tuner, channel)
622 without g_object_notify */
623 gst_v4l2_tuner_set_channel (v4l2object, channel);
626 g_free (v4l2object->channel);
627 v4l2object->channel = g_value_dup_string (value);
631 if (GST_V4L2_IS_OPEN (v4l2object)) {
632 GstTuner *tuner = GST_TUNER (v4l2object->element);
633 GstTunerChannel *channel = gst_tuner_get_channel (tuner);
636 GST_TUNER_CHANNEL_HAS_FLAG (channel, GST_TUNER_CHANNEL_FREQUENCY)) {
638 gst_tuner_set_frequency (tuner, channel, g_value_get_ulong (value))
639 without g_object_notify */
640 gst_v4l2_tuner_set_frequency (v4l2object, channel,
641 g_value_get_ulong (value));
644 v4l2object->frequency = g_value_get_ulong (value);
650 v4l2object->req_mode = g_value_get_enum (value);
652 case PROP_CAPTURE_IO_MODE:
653 g_return_val_if_fail (!V4L2_TYPE_IS_OUTPUT (v4l2object->type), FALSE);
654 v4l2object->req_mode = g_value_get_enum (value);
656 case PROP_OUTPUT_IO_MODE:
657 g_return_val_if_fail (V4L2_TYPE_IS_OUTPUT (v4l2object->type), FALSE);
658 v4l2object->req_mode = g_value_get_enum (value);
660 case PROP_EXTRA_CONTROLS:{
661 const GstStructure *s = gst_value_get_structure (value);
663 if (v4l2object->extra_controls)
664 gst_structure_free (v4l2object->extra_controls);
666 v4l2object->extra_controls = s ? gst_structure_copy (s) : NULL;
667 if (GST_V4L2_IS_OPEN (v4l2object))
668 gst_v4l2_set_controls (v4l2object, v4l2object->extra_controls);
671 case PROP_PIXEL_ASPECT_RATIO:
672 if (v4l2object->par) {
673 g_value_unset (v4l2object->par);
674 g_free (v4l2object->par);
676 v4l2object->par = g_new0 (GValue, 1);
677 g_value_init (v4l2object->par, GST_TYPE_FRACTION);
678 if (!g_value_transform (value, v4l2object->par)) {
679 g_warning ("Could not transform string to aspect ratio");
680 gst_value_set_fraction (v4l2object->par, 1, 1);
683 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "set PAR to %d/%d",
684 gst_value_get_fraction_numerator (v4l2object->par),
685 gst_value_get_fraction_denominator (v4l2object->par));
687 case PROP_FORCE_ASPECT_RATIO:
688 v4l2object->keep_aspect = g_value_get_boolean (value);
699 gst_v4l2_object_get_property_helper (GstV4l2Object * v4l2object,
700 guint prop_id, GValue * value, GParamSpec * pspec)
704 g_value_set_string (value, v4l2object->videodev);
706 case PROP_DEVICE_NAME:
708 const guchar *new = NULL;
710 if (GST_V4L2_IS_OPEN (v4l2object)) {
711 new = v4l2object->vcap.card;
712 } else if (gst_v4l2_open (v4l2object)) {
713 new = v4l2object->vcap.card;
714 gst_v4l2_close (v4l2object);
716 g_value_set_string (value, (gchar *) new);
721 if (GST_V4L2_IS_OPEN (v4l2object))
722 g_value_set_int (value, v4l2object->video_fd);
724 g_value_set_int (value, DEFAULT_PROP_DEVICE_FD);
731 if (GST_V4L2_IS_OPEN (v4l2object)) {
732 flags |= v4l2object->device_caps &
733 (V4L2_CAP_VIDEO_CAPTURE |
734 V4L2_CAP_VIDEO_OUTPUT |
735 V4L2_CAP_VIDEO_OVERLAY |
736 V4L2_CAP_VBI_CAPTURE |
737 V4L2_CAP_VBI_OUTPUT | V4L2_CAP_TUNER | V4L2_CAP_AUDIO);
739 if (v4l2object->device_caps & V4L2_CAP_VIDEO_CAPTURE_MPLANE)
740 flags |= V4L2_CAP_VIDEO_CAPTURE;
742 if (v4l2object->device_caps & V4L2_CAP_VIDEO_OUTPUT_MPLANE)
743 flags |= V4L2_CAP_VIDEO_OUTPUT;
745 g_value_set_flags (value, flags);
748 case PROP_BRIGHTNESS:
750 case PROP_SATURATION:
753 gint cid = gst_v4l2_object_prop_to_cid (prop_id);
756 if (GST_V4L2_IS_OPEN (v4l2object)) {
758 if (gst_v4l2_get_attribute (v4l2object, cid, &v)) {
759 g_value_set_int (value, v);
767 g_value_set_enum (value, v4l2object->tv_norm);
770 g_value_set_enum (value, v4l2object->req_mode);
772 case PROP_CAPTURE_IO_MODE:
773 g_return_val_if_fail (!V4L2_TYPE_IS_OUTPUT (v4l2object->type), FALSE);
774 g_value_set_enum (value, v4l2object->req_mode);
776 case PROP_OUTPUT_IO_MODE:
777 g_return_val_if_fail (V4L2_TYPE_IS_OUTPUT (v4l2object->type), FALSE);
778 g_value_set_enum (value, v4l2object->req_mode);
780 case PROP_EXTRA_CONTROLS:
781 gst_value_set_structure (value, v4l2object->extra_controls);
783 case PROP_PIXEL_ASPECT_RATIO:
785 g_value_transform (v4l2object->par, value);
787 case PROP_FORCE_ASPECT_RATIO:
788 g_value_set_boolean (value, v4l2object->keep_aspect);
798 gst_v4l2_get_driver_min_buffers (GstV4l2Object * v4l2object)
800 struct v4l2_control control = { 0, };
802 g_return_if_fail (GST_V4L2_IS_OPEN (v4l2object));
804 if (V4L2_TYPE_IS_OUTPUT (v4l2object->type))
805 control.id = V4L2_CID_MIN_BUFFERS_FOR_OUTPUT;
807 control.id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE;
809 if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_G_CTRL, &control) == 0) {
810 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
811 "driver requires a minimum of %d buffers", control.value);
812 v4l2object->min_buffers = control.value;
814 v4l2object->min_buffers = 0;
819 gst_v4l2_set_defaults (GstV4l2Object * v4l2object)
821 GstTunerNorm *norm = NULL;
822 GstTunerChannel *channel = NULL;
825 if (!GST_IS_TUNER (v4l2object->element))
828 tuner = GST_TUNER (v4l2object->element);
830 if (v4l2object->tv_norm)
831 norm = gst_v4l2_tuner_get_norm_by_std_id (v4l2object, v4l2object->tv_norm);
832 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "tv_norm=0x%" G_GINT64_MODIFIER "x, "
833 "norm=%p", (guint64) v4l2object->tv_norm, norm);
835 gst_tuner_set_norm (tuner, norm);
838 GST_TUNER_NORM (gst_tuner_get_norm (GST_TUNER (v4l2object->element)));
840 v4l2object->tv_norm =
841 gst_v4l2_tuner_get_std_id_by_norm (v4l2object, norm);
842 gst_tuner_norm_changed (tuner, norm);
846 if (v4l2object->channel)
847 channel = gst_tuner_find_channel_by_name (tuner, v4l2object->channel);
849 gst_tuner_set_channel (tuner, channel);
852 GST_TUNER_CHANNEL (gst_tuner_get_channel (GST_TUNER
853 (v4l2object->element)));
855 g_free (v4l2object->channel);
856 v4l2object->channel = g_strdup (channel->label);
857 gst_tuner_channel_changed (tuner, channel);
862 && GST_TUNER_CHANNEL_HAS_FLAG (channel, GST_TUNER_CHANNEL_FREQUENCY)) {
863 if (v4l2object->frequency != 0) {
864 gst_tuner_set_frequency (tuner, channel, v4l2object->frequency);
866 v4l2object->frequency = gst_tuner_get_frequency (tuner, channel);
867 if (v4l2object->frequency == 0) {
869 gst_tuner_set_frequency (tuner, channel, 1000);
877 gst_v4l2_object_open (GstV4l2Object * v4l2object)
879 if (gst_v4l2_open (v4l2object))
880 gst_v4l2_set_defaults (v4l2object);
888 gst_v4l2_object_open_shared (GstV4l2Object * v4l2object, GstV4l2Object * other)
892 ret = gst_v4l2_dup (v4l2object, other);
898 gst_v4l2_object_close (GstV4l2Object * v4l2object)
900 if (!gst_v4l2_close (v4l2object))
903 gst_caps_replace (&v4l2object->probed_caps, NULL);
905 /* reset our copy of the device caps */
906 v4l2object->device_caps = 0;
908 if (v4l2object->formats) {
909 gst_v4l2_object_clear_format_list (v4l2object);
912 if (v4l2object->par) {
913 g_value_unset (v4l2object->par);
914 g_free (v4l2object->par);
915 v4l2object->par = NULL;
921 static struct v4l2_fmtdesc *
922 gst_v4l2_object_get_format_from_fourcc (GstV4l2Object * v4l2object,
925 struct v4l2_fmtdesc *fmt;
931 walk = gst_v4l2_object_get_format_list (v4l2object);
933 fmt = (struct v4l2_fmtdesc *) walk->data;
934 if (fmt->pixelformat == fourcc)
936 /* special case for jpeg */
937 if (fmt->pixelformat == V4L2_PIX_FMT_MJPEG ||
938 fmt->pixelformat == V4L2_PIX_FMT_JPEG ||
939 fmt->pixelformat == V4L2_PIX_FMT_PJPG) {
940 if (fourcc == V4L2_PIX_FMT_JPEG || fourcc == V4L2_PIX_FMT_MJPEG ||
941 fourcc == V4L2_PIX_FMT_PJPG) {
945 walk = g_slist_next (walk);
953 /* complete made up ranking, the values themselves are meaningless */
954 /* These ranks MUST be X such that X<<15 fits on a signed int - see
955 the comment at the end of gst_v4l2_object_format_get_rank. */
956 #define YUV_BASE_RANK 1000
957 #define JPEG_BASE_RANK 500
958 #define DV_BASE_RANK 200
959 #define RGB_BASE_RANK 100
960 #define YUV_ODD_BASE_RANK 50
961 #define RGB_ODD_BASE_RANK 25
962 #define BAYER_BASE_RANK 15
963 #define S910_BASE_RANK 10
964 #define GREY_BASE_RANK 5
965 #define PWC_BASE_RANK 1
968 gst_v4l2_object_format_get_rank (const struct v4l2_fmtdesc *fmt)
970 guint32 fourcc = fmt->pixelformat;
971 gboolean emulated = ((fmt->flags & V4L2_FMT_FLAG_EMULATED) != 0);
975 case V4L2_PIX_FMT_MJPEG:
976 case V4L2_PIX_FMT_PJPG:
977 rank = JPEG_BASE_RANK;
979 case V4L2_PIX_FMT_JPEG:
980 rank = JPEG_BASE_RANK + 1;
982 case V4L2_PIX_FMT_MPEG: /* MPEG */
983 rank = JPEG_BASE_RANK + 2;
986 case V4L2_PIX_FMT_RGB332:
987 case V4L2_PIX_FMT_ARGB555:
988 case V4L2_PIX_FMT_XRGB555:
989 case V4L2_PIX_FMT_RGB555:
990 case V4L2_PIX_FMT_ARGB555X:
991 case V4L2_PIX_FMT_XRGB555X:
992 case V4L2_PIX_FMT_RGB555X:
993 case V4L2_PIX_FMT_BGR666:
994 case V4L2_PIX_FMT_RGB565:
995 case V4L2_PIX_FMT_RGB565X:
996 case V4L2_PIX_FMT_RGB444:
997 case V4L2_PIX_FMT_Y4:
998 case V4L2_PIX_FMT_Y6:
999 case V4L2_PIX_FMT_Y10:
1000 case V4L2_PIX_FMT_Y12:
1001 case V4L2_PIX_FMT_Y10BPACK:
1002 case V4L2_PIX_FMT_YUV555:
1003 case V4L2_PIX_FMT_YUV565:
1004 case V4L2_PIX_FMT_YUV32:
1005 case V4L2_PIX_FMT_NV12MT_16X16:
1006 case V4L2_PIX_FMT_NV42:
1007 case V4L2_PIX_FMT_H264_MVC:
1008 rank = RGB_ODD_BASE_RANK;
1011 case V4L2_PIX_FMT_RGB24:
1012 case V4L2_PIX_FMT_BGR24:
1013 rank = RGB_BASE_RANK - 1;
1016 case V4L2_PIX_FMT_RGB32:
1017 case V4L2_PIX_FMT_BGR32:
1018 case V4L2_PIX_FMT_ABGR32:
1019 case V4L2_PIX_FMT_XBGR32:
1020 case V4L2_PIX_FMT_ARGB32:
1021 case V4L2_PIX_FMT_XRGB32:
1022 rank = RGB_BASE_RANK;
1025 case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
1026 rank = GREY_BASE_RANK;
1029 case V4L2_PIX_FMT_NV12: /* 12 Y/CbCr 4:2:0 */
1030 case V4L2_PIX_FMT_NV12M: /* Same as NV12 */
1031 case V4L2_PIX_FMT_NV12MT: /* NV12 64x32 tile */
1032 case V4L2_PIX_FMT_NV21: /* 12 Y/CrCb 4:2:0 */
1033 case V4L2_PIX_FMT_NV21M: /* Same as NV21 */
1034 case V4L2_PIX_FMT_YYUV: /* 16 YUV 4:2:2 */
1035 case V4L2_PIX_FMT_HI240: /* 8 8-bit color */
1036 case V4L2_PIX_FMT_NV16: /* 16 Y/CbCr 4:2:2 */
1037 case V4L2_PIX_FMT_NV16M: /* Same as NV16 */
1038 case V4L2_PIX_FMT_NV61: /* 16 Y/CrCb 4:2:2 */
1039 case V4L2_PIX_FMT_NV61M: /* Same as NV61 */
1040 case V4L2_PIX_FMT_NV24: /* 24 Y/CrCb 4:4:4 */
1041 rank = YUV_ODD_BASE_RANK;
1044 case V4L2_PIX_FMT_YVU410: /* YVU9, 9 bits per pixel */
1045 rank = YUV_BASE_RANK + 3;
1047 case V4L2_PIX_FMT_YUV410: /* YUV9, 9 bits per pixel */
1048 rank = YUV_BASE_RANK + 2;
1050 case V4L2_PIX_FMT_YUV420: /* I420, 12 bits per pixel */
1051 case V4L2_PIX_FMT_YUV420M:
1052 rank = YUV_BASE_RANK + 7;
1054 case V4L2_PIX_FMT_YUYV: /* YUY2, 16 bits per pixel */
1055 rank = YUV_BASE_RANK + 10;
1057 case V4L2_PIX_FMT_YVU420: /* YV12, 12 bits per pixel */
1058 rank = YUV_BASE_RANK + 6;
1060 case V4L2_PIX_FMT_UYVY: /* UYVY, 16 bits per pixel */
1061 rank = YUV_BASE_RANK + 9;
1063 case V4L2_PIX_FMT_YUV444:
1064 rank = YUV_BASE_RANK + 6;
1066 case V4L2_PIX_FMT_Y41P: /* Y41P, 12 bits per pixel */
1067 rank = YUV_BASE_RANK + 5;
1069 case V4L2_PIX_FMT_YUV411P: /* Y41B, 12 bits per pixel */
1070 rank = YUV_BASE_RANK + 4;
1072 case V4L2_PIX_FMT_YUV422P: /* Y42B, 16 bits per pixel */
1073 rank = YUV_BASE_RANK + 8;
1076 case V4L2_PIX_FMT_DV:
1077 rank = DV_BASE_RANK;
1080 case V4L2_PIX_FMT_WNVA: /* Winnov hw compres */
1084 case V4L2_PIX_FMT_SBGGR8:
1085 case V4L2_PIX_FMT_SGBRG8:
1086 case V4L2_PIX_FMT_SGRBG8:
1087 case V4L2_PIX_FMT_SRGGB8:
1088 rank = BAYER_BASE_RANK;
1091 case V4L2_PIX_FMT_SN9C10X:
1092 rank = S910_BASE_RANK;
1095 case V4L2_PIX_FMT_PWC1:
1096 rank = PWC_BASE_RANK;
1098 case V4L2_PIX_FMT_PWC2:
1099 rank = PWC_BASE_RANK;
1107 /* All ranks are below 1<<15 so a shift by 15
1108 * will a) make all non-emulated formats larger
1109 * than emulated and b) will not overflow
1120 format_cmp_func (gconstpointer a, gconstpointer b)
1122 const struct v4l2_fmtdesc *fa = a;
1123 const struct v4l2_fmtdesc *fb = b;
1125 if (fa->pixelformat == fb->pixelformat)
1128 return gst_v4l2_object_format_get_rank (fb) -
1129 gst_v4l2_object_format_get_rank (fa);
1132 /******************************************************
1133 * gst_v4l2_object_fill_format_list():
1134 * create list of supported capture formats
1135 * return value: TRUE on success, FALSE on error
1136 ******************************************************/
1138 gst_v4l2_object_fill_format_list (GstV4l2Object * v4l2object,
1139 enum v4l2_buf_type type)
1142 struct v4l2_fmtdesc *format;
1144 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "getting src format enumerations");
1146 /* format enumeration */
1148 format = g_new0 (struct v4l2_fmtdesc, 1);
1151 format->type = type;
1153 if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_ENUM_FMT, format) < 0) {
1154 if (errno == EINVAL) {
1156 break; /* end of enumeration */
1162 GST_LOG_OBJECT (v4l2object->dbg_obj, "index: %u", format->index);
1163 GST_LOG_OBJECT (v4l2object->dbg_obj, "type: %d", format->type);
1164 GST_LOG_OBJECT (v4l2object->dbg_obj, "flags: %08x", format->flags);
1165 GST_LOG_OBJECT (v4l2object->dbg_obj, "description: '%s'",
1166 format->description);
1167 GST_LOG_OBJECT (v4l2object->dbg_obj, "pixelformat: %" GST_FOURCC_FORMAT,
1168 GST_FOURCC_ARGS (format->pixelformat));
1170 /* sort formats according to our preference; we do this, because caps
1171 * are probed in the order the formats are in the list, and the order of
1172 * formats in the final probed caps matters for things like fixation */
1173 v4l2object->formats = g_slist_insert_sorted (v4l2object->formats, format,
1174 (GCompareFunc) format_cmp_func);
1177 #ifndef GST_DISABLE_GST_DEBUG
1181 GST_INFO_OBJECT (v4l2object->dbg_obj, "got %d format(s):", n);
1182 for (l = v4l2object->formats; l != NULL; l = l->next) {
1185 GST_INFO_OBJECT (v4l2object->dbg_obj,
1186 " %" GST_FOURCC_FORMAT "%s", GST_FOURCC_ARGS (format->pixelformat),
1187 ((format->flags & V4L2_FMT_FLAG_EMULATED)) ? " (emulated)" : "");
1199 if (v4l2object->element)
1202 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
1203 (_("Failed to enumerate possible video formats device '%s' can work "
1204 "with"), v4l2object->videodev),
1205 ("Failed to get number %d in pixelformat enumeration for %s. (%d - %s)",
1206 n, v4l2object->videodev, errno, g_strerror (errno)));
1213 * Get the list of supported capture formats, a list of
1214 * <code>struct v4l2_fmtdesc</code>.
1217 gst_v4l2_object_get_format_list (GstV4l2Object * v4l2object)
1219 if (!v4l2object->formats) {
1221 /* check usual way */
1222 gst_v4l2_object_fill_format_list (v4l2object, v4l2object->type);
1224 /* if our driver supports multi-planar
1225 * and if formats are still empty then we can workaround driver bug
1226 * by also looking up formats as if our device was not supporting
1228 if (!v4l2object->formats) {
1229 switch (v4l2object->type) {
1230 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1231 gst_v4l2_object_fill_format_list (v4l2object,
1232 V4L2_BUF_TYPE_VIDEO_CAPTURE);
1235 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1236 gst_v4l2_object_fill_format_list (v4l2object,
1237 V4L2_BUF_TYPE_VIDEO_OUTPUT);
1245 return v4l2object->formats;
1248 static GstVideoFormat
1249 gst_v4l2_object_v4l2fourcc_to_video_format (guint32 fourcc)
1251 GstVideoFormat format;
1254 case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
1255 format = GST_VIDEO_FORMAT_GRAY8;
1257 case V4L2_PIX_FMT_Y16:
1258 format = GST_VIDEO_FORMAT_GRAY16_LE;
1260 case V4L2_PIX_FMT_Y16_BE:
1261 format = GST_VIDEO_FORMAT_GRAY16_BE;
1263 case V4L2_PIX_FMT_XRGB555:
1264 case V4L2_PIX_FMT_RGB555:
1265 format = GST_VIDEO_FORMAT_RGB15;
1267 case V4L2_PIX_FMT_XRGB555X:
1268 case V4L2_PIX_FMT_RGB555X:
1269 format = GST_VIDEO_FORMAT_BGR15;
1271 case V4L2_PIX_FMT_RGB565:
1272 format = GST_VIDEO_FORMAT_RGB16;
1274 case V4L2_PIX_FMT_RGB24:
1275 format = GST_VIDEO_FORMAT_RGB;
1277 case V4L2_PIX_FMT_BGR24:
1278 format = GST_VIDEO_FORMAT_BGR;
1280 case V4L2_PIX_FMT_XRGB32:
1281 case V4L2_PIX_FMT_RGB32:
1282 format = GST_VIDEO_FORMAT_xRGB;
1284 case V4L2_PIX_FMT_XBGR32:
1285 case V4L2_PIX_FMT_BGR32:
1286 format = GST_VIDEO_FORMAT_BGRx;
1288 case V4L2_PIX_FMT_ABGR32:
1289 format = GST_VIDEO_FORMAT_BGRA;
1291 case V4L2_PIX_FMT_ARGB32:
1292 format = GST_VIDEO_FORMAT_ARGB;
1294 case V4L2_PIX_FMT_NV12:
1295 case V4L2_PIX_FMT_NV12M:
1296 format = GST_VIDEO_FORMAT_NV12;
1298 case V4L2_PIX_FMT_NV12MT:
1299 format = GST_VIDEO_FORMAT_NV12_64Z32;
1301 case V4L2_PIX_FMT_NV21:
1302 case V4L2_PIX_FMT_NV21M:
1303 format = GST_VIDEO_FORMAT_NV21;
1305 case V4L2_PIX_FMT_YVU410:
1306 format = GST_VIDEO_FORMAT_YVU9;
1308 case V4L2_PIX_FMT_YUV410:
1309 format = GST_VIDEO_FORMAT_YUV9;
1311 case V4L2_PIX_FMT_YUV420:
1312 case V4L2_PIX_FMT_YUV420M:
1313 format = GST_VIDEO_FORMAT_I420;
1315 case V4L2_PIX_FMT_YUYV:
1316 format = GST_VIDEO_FORMAT_YUY2;
1318 case V4L2_PIX_FMT_YVU420:
1319 format = GST_VIDEO_FORMAT_YV12;
1321 case V4L2_PIX_FMT_UYVY:
1322 format = GST_VIDEO_FORMAT_UYVY;
1324 case V4L2_PIX_FMT_YUV411P:
1325 format = GST_VIDEO_FORMAT_Y41B;
1327 case V4L2_PIX_FMT_YUV422P:
1328 format = GST_VIDEO_FORMAT_Y42B;
1330 case V4L2_PIX_FMT_YVYU:
1331 format = GST_VIDEO_FORMAT_YVYU;
1333 case V4L2_PIX_FMT_NV16:
1334 case V4L2_PIX_FMT_NV16M:
1335 format = GST_VIDEO_FORMAT_NV16;
1337 case V4L2_PIX_FMT_NV61:
1338 case V4L2_PIX_FMT_NV61M:
1339 format = GST_VIDEO_FORMAT_NV61;
1341 case V4L2_PIX_FMT_NV24:
1342 format = GST_VIDEO_FORMAT_NV24;
1345 format = GST_VIDEO_FORMAT_UNKNOWN;
1353 gst_v4l2_object_v4l2fourcc_is_rgb (guint32 fourcc)
1355 gboolean ret = FALSE;
1358 case V4L2_PIX_FMT_XRGB555:
1359 case V4L2_PIX_FMT_RGB555:
1360 case V4L2_PIX_FMT_XRGB555X:
1361 case V4L2_PIX_FMT_RGB555X:
1362 case V4L2_PIX_FMT_RGB565:
1363 case V4L2_PIX_FMT_RGB24:
1364 case V4L2_PIX_FMT_BGR24:
1365 case V4L2_PIX_FMT_XRGB32:
1366 case V4L2_PIX_FMT_RGB32:
1367 case V4L2_PIX_FMT_XBGR32:
1368 case V4L2_PIX_FMT_BGR32:
1369 case V4L2_PIX_FMT_ABGR32:
1370 case V4L2_PIX_FMT_ARGB32:
1380 static GstStructure *
1381 gst_v4l2_object_v4l2fourcc_to_bare_struct (guint32 fourcc)
1383 GstStructure *structure = NULL;
1386 case V4L2_PIX_FMT_MJPEG: /* Motion-JPEG */
1387 case V4L2_PIX_FMT_PJPG: /* Progressive-JPEG */
1388 case V4L2_PIX_FMT_JPEG: /* JFIF JPEG */
1389 structure = gst_structure_new_empty ("image/jpeg");
1391 case V4L2_PIX_FMT_MPEG1:
1392 structure = gst_structure_new ("video/mpeg",
1393 "mpegversion", G_TYPE_INT, 2, NULL);
1395 case V4L2_PIX_FMT_MPEG2:
1396 structure = gst_structure_new ("video/mpeg",
1397 "mpegversion", G_TYPE_INT, 2, NULL);
1399 case V4L2_PIX_FMT_MPEG4:
1400 case V4L2_PIX_FMT_XVID:
1401 structure = gst_structure_new ("video/mpeg",
1402 "mpegversion", G_TYPE_INT, 4, "systemstream",
1403 G_TYPE_BOOLEAN, FALSE, NULL);
1405 case V4L2_PIX_FMT_H263:
1406 structure = gst_structure_new ("video/x-h263",
1407 "variant", G_TYPE_STRING, "itu", NULL);
1409 case V4L2_PIX_FMT_H264: /* H.264 */
1410 structure = gst_structure_new ("video/x-h264",
1411 "stream-format", G_TYPE_STRING, "byte-stream", "alignment",
1412 G_TYPE_STRING, "au", NULL);
1414 case V4L2_PIX_FMT_H264_NO_SC:
1415 structure = gst_structure_new ("video/x-h264",
1416 "stream-format", G_TYPE_STRING, "avc", "alignment",
1417 G_TYPE_STRING, "au", NULL);
1419 case V4L2_PIX_FMT_VC1_ANNEX_G:
1420 case V4L2_PIX_FMT_VC1_ANNEX_L:
1421 structure = gst_structure_new ("video/x-wmv",
1422 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1424 case V4L2_PIX_FMT_VP8:
1425 structure = gst_structure_new_empty ("video/x-vp8");
1427 case V4L2_PIX_FMT_VP9:
1428 structure = gst_structure_new_empty ("video/x-vp9");
1430 case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
1431 case V4L2_PIX_FMT_Y16:
1432 case V4L2_PIX_FMT_Y16_BE:
1433 case V4L2_PIX_FMT_XRGB555:
1434 case V4L2_PIX_FMT_RGB555:
1435 case V4L2_PIX_FMT_XRGB555X:
1436 case V4L2_PIX_FMT_RGB555X:
1437 case V4L2_PIX_FMT_RGB565:
1438 case V4L2_PIX_FMT_RGB24:
1439 case V4L2_PIX_FMT_BGR24:
1440 case V4L2_PIX_FMT_RGB32:
1441 case V4L2_PIX_FMT_XRGB32:
1442 case V4L2_PIX_FMT_ARGB32:
1443 case V4L2_PIX_FMT_BGR32:
1444 case V4L2_PIX_FMT_XBGR32:
1445 case V4L2_PIX_FMT_ABGR32:
1446 case V4L2_PIX_FMT_NV12: /* 12 Y/CbCr 4:2:0 */
1447 case V4L2_PIX_FMT_NV12M:
1448 case V4L2_PIX_FMT_NV12MT:
1449 case V4L2_PIX_FMT_NV21: /* 12 Y/CrCb 4:2:0 */
1450 case V4L2_PIX_FMT_NV21M:
1451 case V4L2_PIX_FMT_NV16: /* 16 Y/CbCr 4:2:2 */
1452 case V4L2_PIX_FMT_NV16M:
1453 case V4L2_PIX_FMT_NV61: /* 16 Y/CrCb 4:2:2 */
1454 case V4L2_PIX_FMT_NV61M:
1455 case V4L2_PIX_FMT_NV24: /* 24 Y/CrCb 4:4:4 */
1456 case V4L2_PIX_FMT_YVU410:
1457 case V4L2_PIX_FMT_YUV410:
1458 case V4L2_PIX_FMT_YUV420: /* I420/IYUV */
1459 case V4L2_PIX_FMT_YUV420M:
1460 case V4L2_PIX_FMT_YUYV:
1461 case V4L2_PIX_FMT_YVU420:
1462 case V4L2_PIX_FMT_UYVY:
1463 case V4L2_PIX_FMT_YUV422P:
1464 case V4L2_PIX_FMT_YVYU:
1465 case V4L2_PIX_FMT_YUV411P:{
1466 GstVideoFormat format;
1467 format = gst_v4l2_object_v4l2fourcc_to_video_format (fourcc);
1468 if (format != GST_VIDEO_FORMAT_UNKNOWN)
1469 structure = gst_structure_new ("video/x-raw",
1470 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
1473 case V4L2_PIX_FMT_DV:
1475 gst_structure_new ("video/x-dv", "systemstream", G_TYPE_BOOLEAN, TRUE,
1478 case V4L2_PIX_FMT_MPEG: /* MPEG */
1479 structure = gst_structure_new ("video/mpegts",
1480 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
1482 case V4L2_PIX_FMT_WNVA: /* Winnov hw compres */
1484 case V4L2_PIX_FMT_SBGGR8:
1485 case V4L2_PIX_FMT_SGBRG8:
1486 case V4L2_PIX_FMT_SGRBG8:
1487 case V4L2_PIX_FMT_SRGGB8:
1488 structure = gst_structure_new ("video/x-bayer", "format", G_TYPE_STRING,
1489 fourcc == V4L2_PIX_FMT_SBGGR8 ? "bggr" :
1490 fourcc == V4L2_PIX_FMT_SGBRG8 ? "gbrg" :
1491 fourcc == V4L2_PIX_FMT_SGRBG8 ? "grbg" :
1492 /* fourcc == V4L2_PIX_FMT_SRGGB8 ? */ "rggb", NULL);
1494 case V4L2_PIX_FMT_SN9C10X:
1495 structure = gst_structure_new_empty ("video/x-sonix");
1497 case V4L2_PIX_FMT_PWC1:
1498 structure = gst_structure_new_empty ("video/x-pwc1");
1500 case V4L2_PIX_FMT_PWC2:
1501 structure = gst_structure_new_empty ("video/x-pwc2");
1503 case V4L2_PIX_FMT_RGB332:
1504 case V4L2_PIX_FMT_BGR666:
1505 case V4L2_PIX_FMT_ARGB555X:
1506 case V4L2_PIX_FMT_RGB565X:
1507 case V4L2_PIX_FMT_RGB444:
1508 case V4L2_PIX_FMT_YYUV: /* 16 YUV 4:2:2 */
1509 case V4L2_PIX_FMT_HI240: /* 8 8-bit color */
1510 case V4L2_PIX_FMT_Y4:
1511 case V4L2_PIX_FMT_Y6:
1512 case V4L2_PIX_FMT_Y10:
1513 case V4L2_PIX_FMT_Y12:
1514 case V4L2_PIX_FMT_Y10BPACK:
1515 case V4L2_PIX_FMT_YUV444:
1516 case V4L2_PIX_FMT_YUV555:
1517 case V4L2_PIX_FMT_YUV565:
1518 case V4L2_PIX_FMT_Y41P:
1519 case V4L2_PIX_FMT_YUV32:
1520 case V4L2_PIX_FMT_NV12MT_16X16:
1521 case V4L2_PIX_FMT_NV42:
1522 case V4L2_PIX_FMT_H264_MVC:
1524 GST_DEBUG ("Unsupported fourcc 0x%08x %" GST_FOURCC_FORMAT,
1525 fourcc, GST_FOURCC_ARGS (fourcc));
1533 gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc)
1535 GstStructure *template;
1538 template = gst_v4l2_object_v4l2fourcc_to_bare_struct (fourcc);
1540 if (template == NULL)
1543 for (i = 0; i < GST_V4L2_FORMAT_COUNT; i++) {
1544 if (gst_v4l2_formats[i].format != fourcc)
1547 if (gst_v4l2_formats[i].dimensions) {
1548 gst_structure_set (template,
1549 "width", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1550 "height", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1551 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
1562 gst_v4l2_object_get_caps_helper (GstV4L2FormatFlags flags)
1564 GstStructure *structure;
1568 caps = gst_caps_new_empty ();
1569 for (i = 0; i < GST_V4L2_FORMAT_COUNT; i++) {
1571 if ((gst_v4l2_formats[i].flags & flags) == 0)
1575 gst_v4l2_object_v4l2fourcc_to_bare_struct (gst_v4l2_formats[i].format);
1578 GstStructure *alt_s = NULL;
1580 if (gst_v4l2_formats[i].dimensions) {
1581 gst_structure_set (structure,
1582 "width", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1583 "height", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1584 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
1587 switch (gst_v4l2_formats[i].format) {
1588 case V4L2_PIX_FMT_RGB32:
1589 alt_s = gst_structure_copy (structure);
1590 gst_structure_set (alt_s, "format", G_TYPE_STRING, "ARGB", NULL);
1592 case V4L2_PIX_FMT_BGR32:
1593 alt_s = gst_structure_copy (structure);
1594 gst_structure_set (alt_s, "format", G_TYPE_STRING, "BGRA", NULL);
1599 gst_caps_append_structure (caps, structure);
1602 gst_caps_append_structure (caps, alt_s);
1606 return gst_caps_simplify (caps);
1610 gst_v4l2_object_get_all_caps (void)
1612 static GstCaps *caps = NULL;
1614 if (g_once_init_enter (&caps)) {
1615 GstCaps *all_caps = gst_v4l2_object_get_caps_helper (GST_V4L2_ALL);
1616 GST_MINI_OBJECT_FLAG_SET (all_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
1617 g_once_init_leave (&caps, all_caps);
1624 gst_v4l2_object_get_raw_caps (void)
1626 static GstCaps *caps = NULL;
1628 if (g_once_init_enter (&caps)) {
1629 GstCaps *raw_caps = gst_v4l2_object_get_caps_helper (GST_V4L2_RAW);
1630 GST_MINI_OBJECT_FLAG_SET (raw_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
1631 g_once_init_leave (&caps, raw_caps);
1638 gst_v4l2_object_get_codec_caps (void)
1640 static GstCaps *caps = NULL;
1642 if (g_once_init_enter (&caps)) {
1643 GstCaps *codec_caps = gst_v4l2_object_get_caps_helper (GST_V4L2_CODEC);
1644 GST_MINI_OBJECT_FLAG_SET (codec_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
1645 g_once_init_leave (&caps, codec_caps);
1651 /* collect data for the given caps
1652 * @caps: given input caps
1653 * @format: location for the v4l format
1654 * @w/@h: location for width and height
1655 * @fps_n/@fps_d: location for framerate
1656 * @size: location for expected size of the frame or 0 if unknown
1659 gst_v4l2_object_get_caps_info (GstV4l2Object * v4l2object, GstCaps * caps,
1660 struct v4l2_fmtdesc **format, GstVideoInfo * info)
1662 GstStructure *structure;
1663 guint32 fourcc = 0, fourcc_nc = 0;
1664 const gchar *mimetype;
1665 struct v4l2_fmtdesc *fmt = NULL;
1667 structure = gst_caps_get_structure (caps, 0);
1669 mimetype = gst_structure_get_name (structure);
1671 if (!gst_video_info_from_caps (info, caps))
1672 goto invalid_format;
1674 if (g_str_equal (mimetype, "video/x-raw")) {
1675 switch (GST_VIDEO_INFO_FORMAT (info)) {
1676 case GST_VIDEO_FORMAT_I420:
1677 fourcc = V4L2_PIX_FMT_YUV420;
1678 fourcc_nc = V4L2_PIX_FMT_YUV420M;
1680 case GST_VIDEO_FORMAT_YUY2:
1681 fourcc = V4L2_PIX_FMT_YUYV;
1683 case GST_VIDEO_FORMAT_UYVY:
1684 fourcc = V4L2_PIX_FMT_UYVY;
1686 case GST_VIDEO_FORMAT_YV12:
1687 fourcc = V4L2_PIX_FMT_YVU420;
1689 case GST_VIDEO_FORMAT_Y41B:
1690 fourcc = V4L2_PIX_FMT_YUV411P;
1692 case GST_VIDEO_FORMAT_Y42B:
1693 fourcc = V4L2_PIX_FMT_YUV422P;
1695 case GST_VIDEO_FORMAT_NV12:
1696 fourcc = V4L2_PIX_FMT_NV12;
1697 fourcc_nc = V4L2_PIX_FMT_NV12M;
1699 case GST_VIDEO_FORMAT_NV12_64Z32:
1700 fourcc_nc = V4L2_PIX_FMT_NV12MT;
1702 case GST_VIDEO_FORMAT_NV21:
1703 fourcc = V4L2_PIX_FMT_NV21;
1704 fourcc_nc = V4L2_PIX_FMT_NV21M;
1706 case GST_VIDEO_FORMAT_NV16:
1707 fourcc = V4L2_PIX_FMT_NV16;
1708 fourcc_nc = V4L2_PIX_FMT_NV16M;
1710 case GST_VIDEO_FORMAT_NV61:
1711 fourcc = V4L2_PIX_FMT_NV61;
1712 fourcc_nc = V4L2_PIX_FMT_NV61M;
1714 case GST_VIDEO_FORMAT_NV24:
1715 fourcc = V4L2_PIX_FMT_NV24;
1717 case GST_VIDEO_FORMAT_YVYU:
1718 fourcc = V4L2_PIX_FMT_YVYU;
1720 case GST_VIDEO_FORMAT_RGB15:
1721 fourcc = V4L2_PIX_FMT_RGB555;
1722 fourcc_nc = V4L2_PIX_FMT_XRGB555;
1724 case GST_VIDEO_FORMAT_RGB16:
1725 fourcc = V4L2_PIX_FMT_RGB565;
1727 case GST_VIDEO_FORMAT_RGB:
1728 fourcc = V4L2_PIX_FMT_RGB24;
1730 case GST_VIDEO_FORMAT_BGR:
1731 fourcc = V4L2_PIX_FMT_BGR24;
1733 case GST_VIDEO_FORMAT_xRGB:
1734 fourcc = V4L2_PIX_FMT_RGB32;
1735 fourcc_nc = V4L2_PIX_FMT_XRGB32;
1737 case GST_VIDEO_FORMAT_ARGB:
1738 fourcc = V4L2_PIX_FMT_RGB32;
1739 fourcc_nc = V4L2_PIX_FMT_ARGB32;
1741 case GST_VIDEO_FORMAT_BGRx:
1742 fourcc = V4L2_PIX_FMT_BGR32;
1743 fourcc_nc = V4L2_PIX_FMT_XBGR32;
1745 case GST_VIDEO_FORMAT_BGRA:
1746 fourcc = V4L2_PIX_FMT_BGR32;
1747 fourcc_nc = V4L2_PIX_FMT_ABGR32;
1749 case GST_VIDEO_FORMAT_GRAY8:
1750 fourcc = V4L2_PIX_FMT_GREY;
1752 case GST_VIDEO_FORMAT_GRAY16_LE:
1753 fourcc = V4L2_PIX_FMT_Y16;
1755 case GST_VIDEO_FORMAT_GRAY16_BE:
1756 fourcc = V4L2_PIX_FMT_Y16_BE;
1762 if (g_str_equal (mimetype, "video/mpegts")) {
1763 fourcc = V4L2_PIX_FMT_MPEG;
1764 } else if (g_str_equal (mimetype, "video/x-dv")) {
1765 fourcc = V4L2_PIX_FMT_DV;
1766 } else if (g_str_equal (mimetype, "image/jpeg")) {
1767 fourcc = V4L2_PIX_FMT_JPEG;
1768 } else if (g_str_equal (mimetype, "video/mpeg")) {
1770 if (gst_structure_get_int (structure, "mpegversion", &version)) {
1773 fourcc = V4L2_PIX_FMT_MPEG1;
1776 fourcc = V4L2_PIX_FMT_MPEG2;
1779 fourcc = V4L2_PIX_FMT_MPEG4;
1780 fourcc_nc = V4L2_PIX_FMT_XVID;
1786 } else if (g_str_equal (mimetype, "video/x-h263")) {
1787 fourcc = V4L2_PIX_FMT_H263;
1788 } else if (g_str_equal (mimetype, "video/x-h264")) {
1789 const gchar *stream_format =
1790 gst_structure_get_string (structure, "stream-format");
1791 if (g_str_equal (stream_format, "avc"))
1792 fourcc = V4L2_PIX_FMT_H264_NO_SC;
1794 fourcc = V4L2_PIX_FMT_H264;
1795 } else if (g_str_equal (mimetype, "video/x-vp8")) {
1796 fourcc = V4L2_PIX_FMT_VP8;
1797 } else if (g_str_equal (mimetype, "video/x-vp9")) {
1798 fourcc = V4L2_PIX_FMT_VP9;
1799 } else if (g_str_equal (mimetype, "video/x-bayer")) {
1800 const gchar *format = gst_structure_get_string (structure, "format");
1802 if (!g_ascii_strcasecmp (format, "bggr"))
1803 fourcc = V4L2_PIX_FMT_SBGGR8;
1804 else if (!g_ascii_strcasecmp (format, "gbrg"))
1805 fourcc = V4L2_PIX_FMT_SGBRG8;
1806 else if (!g_ascii_strcasecmp (format, "grbg"))
1807 fourcc = V4L2_PIX_FMT_SGRBG8;
1808 else if (!g_ascii_strcasecmp (format, "rggb"))
1809 fourcc = V4L2_PIX_FMT_SRGGB8;
1811 } else if (g_str_equal (mimetype, "video/x-sonix")) {
1812 fourcc = V4L2_PIX_FMT_SN9C10X;
1813 } else if (g_str_equal (mimetype, "video/x-pwc1")) {
1814 fourcc = V4L2_PIX_FMT_PWC1;
1815 } else if (g_str_equal (mimetype, "video/x-pwc2")) {
1816 fourcc = V4L2_PIX_FMT_PWC2;
1821 /* Prefer the non-contiguous if supported */
1822 v4l2object->prefered_non_contiguous = TRUE;
1825 fmt = gst_v4l2_object_get_format_from_fourcc (v4l2object, fourcc_nc);
1826 else if (fourcc == 0)
1827 goto unhandled_format;
1830 fmt = gst_v4l2_object_get_format_from_fourcc (v4l2object, fourcc);
1831 v4l2object->prefered_non_contiguous = FALSE;
1835 goto unsupported_format;
1844 GST_DEBUG_OBJECT (v4l2object, "invalid format");
1849 GST_DEBUG_OBJECT (v4l2object, "unhandled format");
1854 GST_DEBUG_OBJECT (v4l2object, "unsupported format");
1860 gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
1861 guint32 pixelformat, gint * width, gint * height);
1864 gst_v4l2_object_add_aspect_ratio (GstV4l2Object * v4l2object, GstStructure * s)
1866 if (v4l2object->keep_aspect && v4l2object->par)
1867 gst_structure_set_value (s, "pixel-aspect-ratio", v4l2object->par);
1870 /* returns TRUE if the value was changed in place, otherwise FALSE */
1872 gst_v4l2src_value_simplify (GValue * val)
1874 /* simplify list of one value to one value */
1875 if (GST_VALUE_HOLDS_LIST (val) && gst_value_list_get_size (val) == 1) {
1876 const GValue *list_val;
1877 GValue new_val = G_VALUE_INIT;
1879 list_val = gst_value_list_get_value (val, 0);
1880 g_value_init (&new_val, G_VALUE_TYPE (list_val));
1881 g_value_copy (list_val, &new_val);
1882 g_value_unset (val);
1891 gst_v4l2_object_get_interlace_mode (enum v4l2_field field,
1892 GstVideoInterlaceMode * interlace_mode)
1894 /* NB: If you add new return values, please fix mode_strings in
1895 * gst_v4l2_object_add_interlace_mode */
1897 case V4L2_FIELD_ANY:
1899 ("Driver bug detected - check driver with v4l2-compliance from http://git.linuxtv.org/v4l-utils.git\n");
1901 case V4L2_FIELD_NONE:
1902 *interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
1904 case V4L2_FIELD_INTERLACED:
1905 case V4L2_FIELD_INTERLACED_TB:
1906 case V4L2_FIELD_INTERLACED_BT:
1907 *interlace_mode = GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
1910 GST_ERROR ("Unknown enum v4l2_field %d", field);
1916 gst_v4l2_object_get_colorspace (struct v4l2_format *fmt,
1917 GstVideoColorimetry * cinfo)
1920 gst_v4l2_object_v4l2fourcc_is_rgb (fmt->fmt.pix.pixelformat);
1921 enum v4l2_colorspace colorspace;
1922 enum v4l2_quantization range;
1923 enum v4l2_ycbcr_encoding matrix;
1924 enum v4l2_xfer_func transfer;
1925 gboolean ret = TRUE;
1927 if (V4L2_TYPE_IS_MULTIPLANAR (fmt->type)) {
1928 colorspace = fmt->fmt.pix_mp.colorspace;
1929 range = fmt->fmt.pix_mp.quantization;
1930 matrix = fmt->fmt.pix_mp.ycbcr_enc;
1931 transfer = fmt->fmt.pix_mp.xfer_func;
1933 colorspace = fmt->fmt.pix.colorspace;
1934 range = fmt->fmt.pix.quantization;
1935 matrix = fmt->fmt.pix.ycbcr_enc;
1936 transfer = fmt->fmt.pix.xfer_func;
1939 /* First step, set the defaults for each primaries */
1940 switch (colorspace) {
1941 case V4L2_COLORSPACE_SMPTE170M:
1942 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1943 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
1944 cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
1945 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTE170M;
1947 case V4L2_COLORSPACE_REC709:
1948 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1949 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT709;
1950 cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
1951 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT709;
1953 case V4L2_COLORSPACE_SRGB:
1954 case V4L2_COLORSPACE_JPEG:
1955 cinfo->range = GST_VIDEO_COLOR_RANGE_0_255;
1956 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
1957 cinfo->transfer = GST_VIDEO_TRANSFER_SRGB;
1958 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT709;
1960 case V4L2_COLORSPACE_ADOBERGB:
1961 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1962 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
1963 cinfo->transfer = GST_VIDEO_TRANSFER_ADOBERGB;
1964 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_ADOBERGB;
1966 case V4L2_COLORSPACE_BT2020:
1967 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1968 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT2020;
1969 cinfo->transfer = GST_VIDEO_TRANSFER_BT2020_12;
1970 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020;
1972 case V4L2_COLORSPACE_SMPTE240M:
1973 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1974 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_SMPTE240M;
1975 cinfo->transfer = GST_VIDEO_TRANSFER_SMPTE240M;
1976 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTE240M;
1978 case V4L2_COLORSPACE_470_SYSTEM_M:
1979 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1980 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
1981 cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
1982 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT470M;
1984 case V4L2_COLORSPACE_470_SYSTEM_BG:
1985 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1986 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
1987 cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
1988 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT470BG;
1990 case V4L2_COLORSPACE_RAW:
1991 /* Explicitly unknown */
1992 cinfo->range = GST_VIDEO_COLOR_RANGE_UNKNOWN;
1993 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_UNKNOWN;
1994 cinfo->transfer = GST_VIDEO_TRANSFER_UNKNOWN;
1995 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_UNKNOWN;
1998 GST_DEBUG ("Unknown enum v4l2_colorspace %d", colorspace);
2006 /* Second step, apply any custom variation */
2008 case V4L2_QUANTIZATION_FULL_RANGE:
2009 cinfo->range = GST_VIDEO_COLOR_RANGE_0_255;
2011 case V4L2_QUANTIZATION_LIM_RANGE:
2012 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
2014 case V4L2_QUANTIZATION_DEFAULT:
2015 /* replicated V4L2_MAP_QUANTIZATION_DEFAULT macro behavior */
2016 if (is_rgb && colorspace == V4L2_COLORSPACE_BT2020)
2017 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
2018 else if (is_rgb || matrix == V4L2_YCBCR_ENC_XV601
2019 || matrix == V4L2_YCBCR_ENC_XV709
2020 || colorspace == V4L2_COLORSPACE_JPEG)
2021 cinfo->range = GST_VIDEO_COLOR_RANGE_0_255;
2023 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
2026 GST_WARNING ("Unknown enum v4l2_quantization value %d", range);
2027 cinfo->range = GST_VIDEO_COLOR_RANGE_UNKNOWN;
2032 case V4L2_YCBCR_ENC_XV601:
2033 case V4L2_YCBCR_ENC_SYCC:
2034 GST_FIXME ("XV601 and SYCC not defined, assuming 601");
2036 case V4L2_YCBCR_ENC_601:
2037 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
2039 case V4L2_YCBCR_ENC_XV709:
2040 GST_FIXME ("XV709 not defined, assuming 709");
2042 case V4L2_YCBCR_ENC_709:
2043 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT709;
2045 case V4L2_YCBCR_ENC_BT2020_CONST_LUM:
2046 GST_FIXME ("BT2020 with constant luma is not defined, assuming BT2020");
2048 case V4L2_YCBCR_ENC_BT2020:
2049 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT2020;
2051 case V4L2_YCBCR_ENC_SMPTE240M:
2052 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_SMPTE240M;
2054 case V4L2_YCBCR_ENC_DEFAULT:
2055 /* nothing, just use defaults for colorspace */
2058 GST_WARNING ("Unknown enum v4l2_ycbcr_encoding value %d", matrix);
2059 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_UNKNOWN;
2063 /* Set identity matrix for R'G'B' formats to avoid creating
2064 * confusion. This though is cosmetic as it's now properly ignored by
2065 * the video info API and videoconvert. */
2067 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_RGB;
2070 case V4L2_XFER_FUNC_709:
2071 if (fmt->fmt.pix.height >= 2160)
2072 cinfo->transfer = GST_VIDEO_TRANSFER_BT2020_12;
2074 cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
2076 case V4L2_XFER_FUNC_SRGB:
2077 cinfo->transfer = GST_VIDEO_TRANSFER_SRGB;
2079 case V4L2_XFER_FUNC_ADOBERGB:
2080 cinfo->transfer = GST_VIDEO_TRANSFER_ADOBERGB;
2082 case V4L2_XFER_FUNC_SMPTE240M:
2083 cinfo->transfer = GST_VIDEO_TRANSFER_SMPTE240M;
2085 case V4L2_XFER_FUNC_NONE:
2086 cinfo->transfer = GST_VIDEO_TRANSFER_GAMMA10;
2088 case V4L2_XFER_FUNC_DEFAULT:
2089 /* nothing, just use defaults for colorspace */
2092 GST_WARNING ("Unknown enum v4l2_xfer_func value %d", transfer);
2093 cinfo->transfer = GST_VIDEO_TRANSFER_UNKNOWN;
2102 gst_v4l2_object_try_fmt (GstV4l2Object * v4l2object,
2103 struct v4l2_format *try_fmt)
2105 int fd = v4l2object->video_fd;
2106 struct v4l2_format fmt;
2109 memcpy (&fmt, try_fmt, sizeof (fmt));
2110 r = v4l2object->ioctl (fd, VIDIOC_TRY_FMT, &fmt);
2112 if (r < 0 && errno == ENOTTY) {
2113 /* The driver might not implement TRY_FMT, in which case we will try
2115 if (GST_V4L2_IS_ACTIVE (v4l2object))
2118 memcpy (&fmt, try_fmt, sizeof (fmt));
2119 r = v4l2object->ioctl (fd, VIDIOC_S_FMT, &fmt);
2121 memcpy (try_fmt, &fmt, sizeof (fmt));
2126 memcpy (try_fmt, &fmt, sizeof (fmt));
2127 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2128 "Unable to try format: %s", g_strerror (errno));
2134 gst_v4l2_object_add_interlace_mode (GstV4l2Object * v4l2object,
2135 GstStructure * s, guint32 width, guint32 height, guint32 pixelformat)
2137 struct v4l2_format fmt;
2138 GValue interlace_formats = { 0, };
2139 GstVideoInterlaceMode interlace_mode, prev = -1;
2141 const gchar *mode_strings[] = { "progressive",
2146 if (!g_str_equal (gst_structure_get_name (s), "video/x-raw"))
2149 if (v4l2object->never_interlaced) {
2150 gst_structure_set (s, "interlace-mode", G_TYPE_STRING, "progressive", NULL);
2154 g_value_init (&interlace_formats, GST_TYPE_LIST);
2156 /* Try twice - once for NONE, once for INTERLACED. */
2157 memset (&fmt, 0, sizeof (fmt));
2158 fmt.type = v4l2object->type;
2159 fmt.fmt.pix.width = width;
2160 fmt.fmt.pix.height = height;
2161 fmt.fmt.pix.pixelformat = pixelformat;
2162 fmt.fmt.pix.field = V4L2_FIELD_NONE;
2164 if (gst_v4l2_object_try_fmt (v4l2object, &fmt) == 0 &&
2165 gst_v4l2_object_get_interlace_mode (fmt.fmt.pix.field, &interlace_mode)) {
2166 GValue interlace_enum = { 0, };
2167 g_value_init (&interlace_enum, G_TYPE_STRING);
2168 g_value_set_string (&interlace_enum, mode_strings[interlace_mode]);
2169 gst_value_list_append_and_take_value (&interlace_formats, &interlace_enum);
2170 prev = interlace_mode;
2173 memset (&fmt, 0, sizeof (fmt));
2174 fmt.type = v4l2object->type;
2175 fmt.fmt.pix.width = width;
2176 fmt.fmt.pix.height = height;
2177 fmt.fmt.pix.pixelformat = pixelformat;
2178 fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
2180 if (gst_v4l2_object_try_fmt (v4l2object, &fmt) == 0 &&
2181 gst_v4l2_object_get_interlace_mode (fmt.fmt.pix.field, &interlace_mode) &&
2182 prev != interlace_mode) {
2183 GValue interlace_enum = { 0, };
2184 g_value_init (&interlace_enum, G_TYPE_STRING);
2185 g_value_set_string (&interlace_enum, mode_strings[interlace_mode]);
2186 gst_value_list_append_and_take_value (&interlace_formats, &interlace_enum);
2189 if (gst_v4l2src_value_simplify (&interlace_formats)
2190 || gst_value_list_get_size (&interlace_formats) > 0)
2191 gst_structure_take_value (s, "interlace-mode", &interlace_formats);
2193 GST_WARNING_OBJECT (v4l2object, "Failed to determine interlace mode");
2199 gst_v4l2_object_fill_colorimetry_list (GValue * list,
2200 GstVideoColorimetry * cinfo)
2202 GValue colorimetry = G_VALUE_INIT;
2205 gboolean found = FALSE;
2207 g_value_init (&colorimetry, G_TYPE_STRING);
2208 g_value_take_string (&colorimetry, gst_video_colorimetry_to_string (cinfo));
2210 /* only insert if no duplicate */
2211 size = gst_value_list_get_size (list);
2212 for (i = 0; i < size; i++) {
2215 tmp = gst_value_list_get_value (list, i);
2216 if (gst_value_compare (&colorimetry, tmp) == GST_VALUE_EQUAL) {
2223 gst_value_list_append_and_take_value (list, &colorimetry);
2225 g_value_unset (&colorimetry);
2229 gst_v4l2_object_add_colorspace (GstV4l2Object * v4l2object, GstStructure * s,
2230 guint32 width, guint32 height, guint32 pixelformat)
2232 struct v4l2_format fmt;
2233 GValue list = G_VALUE_INIT;
2234 GstVideoColorimetry cinfo;
2235 enum v4l2_colorspace req_cspace;
2237 memset (&fmt, 0, sizeof (fmt));
2238 fmt.type = v4l2object->type;
2239 fmt.fmt.pix.width = width;
2240 fmt.fmt.pix.height = height;
2241 fmt.fmt.pix.pixelformat = pixelformat;
2243 g_value_init (&list, GST_TYPE_LIST);
2245 /* step 1: get device default colorspace and insert it first as
2246 * it should be the preferred one */
2247 if (gst_v4l2_object_try_fmt (v4l2object, &fmt) == 0) {
2248 if (gst_v4l2_object_get_colorspace (&fmt, &cinfo))
2249 gst_v4l2_object_fill_colorimetry_list (&list, &cinfo);
2252 /* step 2: probe all colorspace other than default
2253 * We don't probe all colorspace, range, matrix and transfer combination to
2254 * avoid ioctl flooding which could greatly increase initialization time
2255 * with low-speed devices (UVC...) */
2256 for (req_cspace = V4L2_COLORSPACE_SMPTE170M;
2257 req_cspace <= V4L2_COLORSPACE_RAW; req_cspace++) {
2258 /* V4L2_COLORSPACE_BT878 is deprecated and shall not be used, so skip */
2259 if (req_cspace == V4L2_COLORSPACE_BT878)
2262 if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type))
2263 fmt.fmt.pix_mp.colorspace = req_cspace;
2265 fmt.fmt.pix.colorspace = req_cspace;
2267 if (gst_v4l2_object_try_fmt (v4l2object, &fmt) == 0) {
2268 enum v4l2_colorspace colorspace;
2270 if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type))
2271 colorspace = fmt.fmt.pix_mp.colorspace;
2273 colorspace = fmt.fmt.pix.colorspace;
2275 if (colorspace == req_cspace) {
2276 if (gst_v4l2_object_get_colorspace (&fmt, &cinfo))
2277 gst_v4l2_object_fill_colorimetry_list (&list, &cinfo);
2282 if (gst_value_list_get_size (&list) > 0)
2283 gst_structure_take_value (s, "colorimetry", &list);
2285 g_value_unset (&list);
2290 /* The frame interval enumeration code first appeared in Linux 2.6.19. */
2291 static GstStructure *
2292 gst_v4l2_object_probe_caps_for_format_and_size (GstV4l2Object * v4l2object,
2293 guint32 pixelformat,
2294 guint32 width, guint32 height, const GstStructure * template)
2296 gint fd = v4l2object->video_fd;
2297 struct v4l2_frmivalenum ival;
2300 GValue rates = { 0, };
2302 memset (&ival, 0, sizeof (struct v4l2_frmivalenum));
2304 ival.pixel_format = pixelformat;
2306 ival.height = height;
2308 GST_LOG_OBJECT (v4l2object->dbg_obj,
2309 "get frame interval for %ux%u, %" GST_FOURCC_FORMAT, width, height,
2310 GST_FOURCC_ARGS (pixelformat));
2312 /* keep in mind that v4l2 gives us frame intervals (durations); we invert the
2313 * fraction to get framerate */
2314 if (v4l2object->ioctl (fd, VIDIOC_ENUM_FRAMEINTERVALS, &ival) < 0)
2315 goto enum_frameintervals_failed;
2317 if (ival.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
2318 GValue rate = { 0, };
2320 g_value_init (&rates, GST_TYPE_LIST);
2321 g_value_init (&rate, GST_TYPE_FRACTION);
2324 num = ival.discrete.numerator;
2325 denom = ival.discrete.denominator;
2327 if (num > G_MAXINT || denom > G_MAXINT) {
2328 /* let us hope we don't get here... */
2333 GST_LOG_OBJECT (v4l2object->dbg_obj, "adding discrete framerate: %d/%d",
2336 /* swap to get the framerate */
2337 gst_value_set_fraction (&rate, denom, num);
2338 gst_value_list_append_value (&rates, &rate);
2341 } while (v4l2object->ioctl (fd, VIDIOC_ENUM_FRAMEINTERVALS, &ival) >= 0);
2342 } else if (ival.type == V4L2_FRMIVAL_TYPE_STEPWISE) {
2343 GValue min = { 0, };
2344 GValue step = { 0, };
2345 GValue max = { 0, };
2346 gboolean added = FALSE;
2347 guint32 minnum, mindenom;
2348 guint32 maxnum, maxdenom;
2350 g_value_init (&rates, GST_TYPE_LIST);
2352 g_value_init (&min, GST_TYPE_FRACTION);
2353 g_value_init (&step, GST_TYPE_FRACTION);
2354 g_value_init (&max, GST_TYPE_FRACTION);
2357 minnum = ival.stepwise.min.numerator;
2358 mindenom = ival.stepwise.min.denominator;
2359 if (minnum > G_MAXINT || mindenom > G_MAXINT) {
2363 GST_LOG_OBJECT (v4l2object->dbg_obj, "stepwise min frame interval: %d/%d",
2365 gst_value_set_fraction (&min, minnum, mindenom);
2368 maxnum = ival.stepwise.max.numerator;
2369 maxdenom = ival.stepwise.max.denominator;
2370 if (maxnum > G_MAXINT || maxdenom > G_MAXINT) {
2375 GST_LOG_OBJECT (v4l2object->dbg_obj, "stepwise max frame interval: %d/%d",
2377 gst_value_set_fraction (&max, maxnum, maxdenom);
2380 num = ival.stepwise.step.numerator;
2381 denom = ival.stepwise.step.denominator;
2382 if (num > G_MAXINT || denom > G_MAXINT) {
2387 if (num == 0 || denom == 0) {
2388 /* in this case we have a wrong fraction or no step, set the step to max
2389 * so that we only add the min value in the loop below */
2394 /* since we only have gst_value_fraction_subtract and not add, negate the
2396 GST_LOG_OBJECT (v4l2object->dbg_obj, "stepwise step frame interval: %d/%d",
2398 gst_value_set_fraction (&step, -num, denom);
2400 while (gst_value_compare (&min, &max) != GST_VALUE_GREATER_THAN) {
2401 GValue rate = { 0, };
2403 num = gst_value_get_fraction_numerator (&min);
2404 denom = gst_value_get_fraction_denominator (&min);
2405 GST_LOG_OBJECT (v4l2object->dbg_obj, "adding stepwise framerate: %d/%d",
2408 /* invert to get the framerate */
2409 g_value_init (&rate, GST_TYPE_FRACTION);
2410 gst_value_set_fraction (&rate, denom, num);
2411 gst_value_list_append_value (&rates, &rate);
2414 /* we're actually adding because step was negated above. This is because
2415 * there is no _add function... */
2416 if (!gst_value_fraction_subtract (&min, &min, &step)) {
2417 GST_WARNING_OBJECT (v4l2object->dbg_obj, "could not step fraction!");
2422 /* no range was added, leave the default range from the template */
2423 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2424 "no range added, leaving default");
2425 g_value_unset (&rates);
2427 } else if (ival.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) {
2428 guint32 maxnum, maxdenom;
2430 g_value_init (&rates, GST_TYPE_FRACTION_RANGE);
2432 num = ival.stepwise.min.numerator;
2433 denom = ival.stepwise.min.denominator;
2434 if (num > G_MAXINT || denom > G_MAXINT) {
2439 maxnum = ival.stepwise.max.numerator;
2440 maxdenom = ival.stepwise.max.denominator;
2441 if (maxnum > G_MAXINT || maxdenom > G_MAXINT) {
2446 GST_LOG_OBJECT (v4l2object->dbg_obj,
2447 "continuous frame interval %d/%d to %d/%d", maxdenom, maxnum, denom,
2450 gst_value_set_fraction_range_full (&rates, maxdenom, maxnum, denom, num);
2456 s = gst_structure_copy (template);
2457 gst_structure_set (s, "width", G_TYPE_INT, (gint) width,
2458 "height", G_TYPE_INT, (gint) height, NULL);
2460 gst_v4l2_object_add_aspect_ratio (v4l2object, s);
2462 if (!v4l2object->skip_try_fmt_probes) {
2463 gst_v4l2_object_add_interlace_mode (v4l2object, s, width, height,
2465 gst_v4l2_object_add_colorspace (v4l2object, s, width, height, pixelformat);
2468 if (G_IS_VALUE (&rates)) {
2469 gst_v4l2src_value_simplify (&rates);
2470 /* only change the framerate on the template when we have a valid probed new
2472 gst_structure_take_value (s, "framerate", &rates);
2473 } else if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
2474 v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
2475 gst_structure_set (s, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT,
2481 enum_frameintervals_failed:
2483 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
2484 "Unable to enumerate intervals for %" GST_FOURCC_FORMAT "@%ux%u",
2485 GST_FOURCC_ARGS (pixelformat), width, height);
2490 /* I don't see how this is actually an error, we ignore the format then */
2491 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2492 "Unknown frame interval type at %" GST_FOURCC_FORMAT "@%ux%u: %u",
2493 GST_FOURCC_ARGS (pixelformat), width, height, ival.type);
2499 sort_by_frame_size (GstStructure * s1, GstStructure * s2)
2503 gst_structure_get_int (s1, "width", &w1);
2504 gst_structure_get_int (s1, "height", &h1);
2505 gst_structure_get_int (s2, "width", &w2);
2506 gst_structure_get_int (s2, "height", &h2);
2508 /* I think it's safe to assume that this won't overflow for a while */
2509 return ((w2 * h2) - (w1 * h1));
2513 gst_v4l2_object_update_and_append (GstV4l2Object * v4l2object,
2514 guint32 format, GstCaps * caps, GstStructure * s)
2516 GstStructure *alt_s = NULL;
2518 /* Encoded stream on output buffer need to be parsed */
2519 if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT ||
2520 v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
2523 for (; i < GST_V4L2_FORMAT_COUNT; i++) {
2524 if (format == gst_v4l2_formats[i].format &&
2525 gst_v4l2_formats[i].flags & GST_V4L2_CODEC &&
2526 !(gst_v4l2_formats[i].flags & GST_V4L2_NO_PARSE)) {
2527 gst_structure_set (s, "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
2533 if (v4l2object->has_alpha_component &&
2534 (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
2535 v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) {
2537 case V4L2_PIX_FMT_RGB32:
2538 alt_s = gst_structure_copy (s);
2539 gst_structure_set (alt_s, "format", G_TYPE_STRING, "ARGB", NULL);
2541 case V4L2_PIX_FMT_BGR32:
2542 alt_s = gst_structure_copy (s);
2543 gst_structure_set (alt_s, "format", G_TYPE_STRING, "BGRA", NULL);
2550 gst_caps_append_structure (caps, s);
2553 gst_caps_append_structure (caps, alt_s);
2557 gst_v4l2_object_probe_caps_for_format (GstV4l2Object * v4l2object,
2558 guint32 pixelformat, const GstStructure * template)
2560 GstCaps *ret = gst_caps_new_empty ();
2562 gint fd = v4l2object->video_fd;
2563 struct v4l2_frmsizeenum size;
2564 GList *results = NULL;
2567 if (pixelformat == GST_MAKE_FOURCC ('M', 'P', 'E', 'G')) {
2568 gst_caps_append_structure (ret, gst_structure_copy (template));
2572 memset (&size, 0, sizeof (struct v4l2_frmsizeenum));
2574 size.pixel_format = pixelformat;
2576 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
2577 "Enumerating frame sizes for %" GST_FOURCC_FORMAT,
2578 GST_FOURCC_ARGS (pixelformat));
2580 if (v4l2object->ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &size) < 0)
2581 goto enum_framesizes_failed;
2583 if (size.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
2585 GST_LOG_OBJECT (v4l2object->dbg_obj, "got discrete frame size %dx%d",
2586 size.discrete.width, size.discrete.height);
2588 w = MIN (size.discrete.width, G_MAXINT);
2589 h = MIN (size.discrete.height, G_MAXINT);
2593 gst_v4l2_object_probe_caps_for_format_and_size (v4l2object,
2594 pixelformat, w, h, template);
2597 results = g_list_prepend (results, tmp);
2601 } while (v4l2object->ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &size) >= 0);
2602 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
2603 "done iterating discrete frame sizes");
2604 } else if (size.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
2605 guint32 maxw, maxh, step_w, step_h;
2607 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "we have stepwise frame sizes:");
2608 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min width: %d",
2609 size.stepwise.min_width);
2610 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min height: %d",
2611 size.stepwise.min_height);
2612 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "max width: %d",
2613 size.stepwise.max_width);
2614 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min height: %d",
2615 size.stepwise.max_height);
2616 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "step width: %d",
2617 size.stepwise.step_width);
2618 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "step height: %d",
2619 size.stepwise.step_height);
2621 w = MAX (size.stepwise.min_width, 1);
2622 h = MAX (size.stepwise.min_height, 1);
2623 maxw = MIN (size.stepwise.max_width, G_MAXINT);
2624 maxh = MIN (size.stepwise.max_height, G_MAXINT);
2626 step_w = MAX (size.stepwise.step_width, 1);
2627 step_h = MAX (size.stepwise.step_height, 1);
2629 /* FIXME: check for sanity and that min/max are multiples of the steps */
2631 /* we only query details for the max width/height since it's likely the
2632 * most restricted if there are any resolution-dependent restrictions */
2633 tmp = gst_v4l2_object_probe_caps_for_format_and_size (v4l2object,
2634 pixelformat, maxw, maxh, template);
2637 GValue step_range = G_VALUE_INIT;
2639 g_value_init (&step_range, GST_TYPE_INT_RANGE);
2640 gst_value_set_int_range_step (&step_range, w, maxw, step_w);
2641 gst_structure_set_value (tmp, "width", &step_range);
2643 gst_value_set_int_range_step (&step_range, h, maxh, step_h);
2644 gst_structure_take_value (tmp, "height", &step_range);
2646 /* no point using the results list here, since there's only one struct */
2647 gst_v4l2_object_update_and_append (v4l2object, pixelformat, ret, tmp);
2649 } else if (size.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) {
2652 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "we have continuous frame sizes:");
2653 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min width: %d",
2654 size.stepwise.min_width);
2655 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min height: %d",
2656 size.stepwise.min_height);
2657 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "max width: %d",
2658 size.stepwise.max_width);
2659 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min height: %d",
2660 size.stepwise.max_height);
2662 w = MAX (size.stepwise.min_width, 1);
2663 h = MAX (size.stepwise.min_height, 1);
2664 maxw = MIN (size.stepwise.max_width, G_MAXINT);
2665 maxh = MIN (size.stepwise.max_height, G_MAXINT);
2668 gst_v4l2_object_probe_caps_for_format_and_size (v4l2object, pixelformat,
2671 gst_structure_set (tmp, "width", GST_TYPE_INT_RANGE, (gint) w,
2672 (gint) maxw, "height", GST_TYPE_INT_RANGE, (gint) h, (gint) maxh,
2675 /* no point using the results list here, since there's only one struct */
2676 gst_v4l2_object_update_and_append (v4l2object, pixelformat, ret, tmp);
2682 /* we use an intermediary list to store and then sort the results of the
2683 * probing because we can't make any assumptions about the order in which
2684 * the driver will give us the sizes, but we want the final caps to contain
2685 * the results starting with the highest resolution and having the lowest
2686 * resolution last, since order in caps matters for things like fixation. */
2687 results = g_list_sort (results, (GCompareFunc) sort_by_frame_size);
2688 while (results != NULL) {
2689 gst_v4l2_object_update_and_append (v4l2object, pixelformat, ret,
2691 results = g_list_delete_link (results, results);
2694 if (gst_caps_is_empty (ret))
2695 goto enum_framesizes_no_results;
2700 enum_framesizes_failed:
2702 /* I don't see how this is actually an error */
2703 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
2704 "Failed to enumerate frame sizes for pixelformat %" GST_FOURCC_FORMAT
2705 " (%s)", GST_FOURCC_ARGS (pixelformat), g_strerror (errno));
2706 goto default_frame_sizes;
2708 enum_framesizes_no_results:
2710 /* it's possible that VIDIOC_ENUM_FRAMESIZES is defined but the driver in
2711 * question doesn't actually support it yet */
2712 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
2713 "No results for pixelformat %" GST_FOURCC_FORMAT
2714 " enumerating frame sizes, trying fallback",
2715 GST_FOURCC_ARGS (pixelformat));
2716 goto default_frame_sizes;
2720 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2721 "Unknown frame sizeenum type for pixelformat %" GST_FOURCC_FORMAT
2722 ": %u", GST_FOURCC_ARGS (pixelformat), size.type);
2723 goto default_frame_sizes;
2726 default_frame_sizes:
2728 gint min_w, max_w, min_h, max_h, fix_num = 0, fix_denom = 0;
2730 /* This code is for Linux < 2.6.19 */
2732 max_w = max_h = GST_V4L2_MAX_SIZE;
2733 if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &min_w,
2735 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2736 "Could not probe minimum capture size for pixelformat %"
2737 GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
2739 if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &max_w,
2741 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2742 "Could not probe maximum capture size for pixelformat %"
2743 GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
2746 /* Since we can't get framerate directly, try to use the current norm */
2747 if (v4l2object->tv_norm && v4l2object->norms) {
2749 GstTunerNorm *norm = NULL;
2750 GstTunerNorm *current =
2751 gst_v4l2_tuner_get_norm_by_std_id (v4l2object, v4l2object->tv_norm);
2753 for (norms = v4l2object->norms; norms != NULL; norms = norms->next) {
2754 norm = (GstTunerNorm *) norms->data;
2755 if (!strcmp (norm->label, current->label))
2758 /* If it's possible, set framerate to that (discrete) value */
2760 fix_num = gst_value_get_fraction_numerator (&norm->framerate);
2761 fix_denom = gst_value_get_fraction_denominator (&norm->framerate);
2765 tmp = gst_structure_copy (template);
2767 gst_structure_set (tmp, "framerate", GST_TYPE_FRACTION, fix_num,
2769 } else if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
2770 v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
2771 /* if norm can't be used, copy the template framerate */
2772 gst_structure_set (tmp, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1,
2777 gst_structure_set (tmp, "width", G_TYPE_INT, max_w, NULL);
2779 gst_structure_set (tmp, "width", GST_TYPE_INT_RANGE, min_w, max_w, NULL);
2782 gst_structure_set (tmp, "height", G_TYPE_INT, max_h, NULL);
2784 gst_structure_set (tmp, "height", GST_TYPE_INT_RANGE, min_h, max_h, NULL);
2786 gst_v4l2_object_add_aspect_ratio (v4l2object, tmp);
2788 if (!v4l2object->skip_try_fmt_probes) {
2789 /* We could consider setting interlace mode from min and max. */
2790 gst_v4l2_object_add_interlace_mode (v4l2object, tmp, max_w, max_h,
2792 /* We could consider to check colorspace for min too, in case it depends on
2793 * the size. But in this case, min and max could not be enough */
2794 gst_v4l2_object_add_colorspace (v4l2object, tmp, max_w, max_h,
2798 gst_v4l2_object_update_and_append (v4l2object, pixelformat, ret, tmp);
2804 gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
2805 guint32 pixelformat, gint * width, gint * height)
2807 struct v4l2_format fmt;
2808 gboolean ret = FALSE;
2809 GstVideoInterlaceMode interlace_mode;
2811 g_return_val_if_fail (width != NULL, FALSE);
2812 g_return_val_if_fail (height != NULL, FALSE);
2814 GST_LOG_OBJECT (v4l2object->dbg_obj,
2815 "getting nearest size to %dx%d with format %" GST_FOURCC_FORMAT,
2816 *width, *height, GST_FOURCC_ARGS (pixelformat));
2818 memset (&fmt, 0, sizeof (struct v4l2_format));
2820 /* get size delimiters */
2821 memset (&fmt, 0, sizeof (fmt));
2822 fmt.type = v4l2object->type;
2823 fmt.fmt.pix.width = *width;
2824 fmt.fmt.pix.height = *height;
2825 fmt.fmt.pix.pixelformat = pixelformat;
2826 fmt.fmt.pix.field = V4L2_FIELD_ANY;
2828 if (gst_v4l2_object_try_fmt (v4l2object, &fmt) < 0)
2831 GST_LOG_OBJECT (v4l2object->dbg_obj,
2832 "got nearest size %dx%d", fmt.fmt.pix.width, fmt.fmt.pix.height);
2834 *width = fmt.fmt.pix.width;
2835 *height = fmt.fmt.pix.height;
2837 if (!gst_v4l2_object_get_interlace_mode (fmt.fmt.pix.field, &interlace_mode)) {
2838 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2839 "Unsupported field type for %" GST_FOURCC_FORMAT "@%ux%u: %u",
2840 GST_FOURCC_ARGS (pixelformat), *width, *height, fmt.fmt.pix.field);
2848 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2849 "Unable to try format: %s", g_strerror (errno));
2856 gst_v4l2_object_is_dmabuf_supported (GstV4l2Object * v4l2object)
2858 gboolean ret = TRUE;
2859 struct v4l2_exportbuffer expbuf = {
2860 .type = v4l2object->type,
2863 .flags = O_CLOEXEC | O_RDWR,
2866 /* Expected to fail, but ENOTTY tells us that it is not implemented. */
2867 v4l2object->ioctl (v4l2object->video_fd, VIDIOC_EXPBUF, &expbuf);
2868 if (errno == ENOTTY)
2875 gst_v4l2_object_setup_pool (GstV4l2Object * v4l2object, GstCaps * caps)
2879 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "initializing the %s system",
2880 V4L2_TYPE_IS_OUTPUT (v4l2object->type) ? "output" : "capture");
2882 GST_V4L2_CHECK_OPEN (v4l2object);
2883 GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
2885 /* find transport */
2886 mode = v4l2object->req_mode;
2888 if (v4l2object->device_caps & V4L2_CAP_READWRITE) {
2889 if (v4l2object->req_mode == GST_V4L2_IO_AUTO)
2890 mode = GST_V4L2_IO_RW;
2891 } else if (v4l2object->req_mode == GST_V4L2_IO_RW)
2892 goto method_not_supported;
2894 if (v4l2object->device_caps & V4L2_CAP_STREAMING) {
2895 if (v4l2object->req_mode == GST_V4L2_IO_AUTO) {
2896 if (!V4L2_TYPE_IS_OUTPUT (v4l2object->type) &&
2897 gst_v4l2_object_is_dmabuf_supported (v4l2object)) {
2898 mode = GST_V4L2_IO_DMABUF;
2900 mode = GST_V4L2_IO_MMAP;
2903 } else if (v4l2object->req_mode == GST_V4L2_IO_MMAP)
2904 goto method_not_supported;
2906 /* if still no transport selected, error out */
2907 if (mode == GST_V4L2_IO_AUTO)
2908 goto no_supported_capture_method;
2910 GST_INFO_OBJECT (v4l2object->dbg_obj, "accessing buffers via mode %d", mode);
2911 v4l2object->mode = mode;
2913 /* If min_buffers is not set, the driver either does not support the control or
2914 it has not been asked yet via propose_allocation/decide_allocation. */
2915 if (!v4l2object->min_buffers)
2916 gst_v4l2_get_driver_min_buffers (v4l2object);
2918 /* Map the buffers */
2919 GST_LOG_OBJECT (v4l2object->dbg_obj, "initiating buffer pool");
2921 if (!(v4l2object->pool = gst_v4l2_buffer_pool_new (v4l2object, caps)))
2922 goto buffer_pool_new_failed;
2924 GST_V4L2_SET_ACTIVE (v4l2object);
2929 buffer_pool_new_failed:
2931 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, READ,
2932 (_("Could not map buffers from device '%s'"),
2933 v4l2object->videodev),
2934 ("Failed to create buffer pool: %s", g_strerror (errno)));
2937 method_not_supported:
2939 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, READ,
2940 (_("The driver of device '%s' does not support the IO method %d"),
2941 v4l2object->videodev, mode), (NULL));
2944 no_supported_capture_method:
2946 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, READ,
2947 (_("The driver of device '%s' does not support any known IO "
2948 "method."), v4l2object->videodev), (NULL));
2954 gst_v4l2_object_set_stride (GstVideoInfo * info, GstVideoAlignment * align,
2955 gint plane, gint stride)
2957 const GstVideoFormatInfo *finfo = info->finfo;
2959 if (GST_VIDEO_FORMAT_INFO_IS_TILED (finfo)) {
2960 gint x_tiles, y_tiles, ws, hs, tile_height, padded_height;
2963 ws = GST_VIDEO_FORMAT_INFO_TILE_WS (finfo);
2964 hs = GST_VIDEO_FORMAT_INFO_TILE_HS (finfo);
2965 tile_height = 1 << hs;
2967 padded_height = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (finfo, plane,
2968 info->height + align->padding_top + align->padding_bottom);
2969 padded_height = GST_ROUND_UP_N (padded_height, tile_height);
2971 x_tiles = stride >> ws;
2972 y_tiles = padded_height >> hs;
2973 info->stride[plane] = GST_VIDEO_TILE_MAKE_STRIDE (x_tiles, y_tiles);
2975 info->stride[plane] = stride;
2980 gst_v4l2_object_extrapolate_info (GstV4l2Object * v4l2object,
2981 GstVideoInfo * info, GstVideoAlignment * align, gint stride)
2983 const GstVideoFormatInfo *finfo = info->finfo;
2984 gint i, estride, padded_height;
2987 g_return_if_fail (v4l2object->n_v4l2_planes == 1);
2989 padded_height = info->height + align->padding_top + align->padding_bottom;
2991 for (i = 0; i < finfo->n_planes; i++) {
2992 estride = gst_v4l2_object_extrapolate_stride (finfo, i, stride);
2994 gst_v4l2_object_set_stride (info, align, i, estride);
2996 info->offset[i] = offs;
2998 GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (finfo, i, padded_height);
3000 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
3001 "Extrapolated for plane %d with base stride %d: "
3002 "stride %d, offset %" G_GSIZE_FORMAT, i, stride, info->stride[i],
3006 /* Update the image size according the amount of data we are going to
3007 * read/write. This workaround bugs in driver where the sizeimage provided
3008 * by TRY/S_FMT represent the buffer length (maximum size) rather then the expected
3009 * bytesused (buffer size). */
3010 if (offs < info->size)
3015 gst_v4l2_object_save_format (GstV4l2Object * v4l2object,
3016 struct v4l2_fmtdesc *fmtdesc, struct v4l2_format *format,
3017 GstVideoInfo * info, GstVideoAlignment * align)
3019 const GstVideoFormatInfo *finfo = info->finfo;
3020 gboolean standard_stride = TRUE;
3021 gint stride, padded_width, padded_height, i;
3023 if (GST_VIDEO_INFO_FORMAT (info) == GST_VIDEO_FORMAT_ENCODED) {
3024 v4l2object->n_v4l2_planes = 1;
3025 info->size = format->fmt.pix.sizeimage;
3029 /* adjust right padding */
3030 if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type))
3031 stride = format->fmt.pix_mp.plane_fmt[0].bytesperline;
3033 stride = format->fmt.pix.bytesperline;
3035 padded_width = stride / GST_VIDEO_FORMAT_INFO_PSTRIDE (finfo, 0);
3037 if (padded_width < format->fmt.pix.width)
3038 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3039 "Driver bug detected, stride is too small for the width");
3041 align->padding_right = padded_width - info->width - align->padding_left;
3043 /* adjust bottom padding */
3044 padded_height = format->fmt.pix.height;
3046 if (GST_VIDEO_FORMAT_INFO_IS_TILED (finfo)) {
3047 guint hs, tile_height;
3049 hs = GST_VIDEO_FORMAT_INFO_TILE_HS (finfo);
3050 tile_height = 1 << hs;
3052 padded_height = GST_ROUND_UP_N (padded_height, tile_height);
3055 align->padding_bottom = padded_height - info->height - align->padding_top;
3057 /* setup the strides and offset */
3058 if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type)) {
3059 struct v4l2_pix_format_mplane *pix_mp = &format->fmt.pix_mp;
3061 /* figure out the frame layout */
3062 v4l2object->n_v4l2_planes = MAX (1, pix_mp->num_planes);
3064 for (i = 0; i < v4l2object->n_v4l2_planes; i++) {
3065 stride = pix_mp->plane_fmt[i].bytesperline;
3067 if (info->stride[i] != stride)
3068 standard_stride = FALSE;
3070 gst_v4l2_object_set_stride (info, align, i, stride);
3071 info->offset[i] = info->size;
3072 info->size += pix_mp->plane_fmt[i].sizeimage;
3075 /* Extrapolate stride if planar format are being set in 1 v4l2 plane */
3076 if (v4l2object->n_v4l2_planes < finfo->n_planes) {
3077 stride = format->fmt.pix_mp.plane_fmt[0].bytesperline;
3078 gst_v4l2_object_extrapolate_info (v4l2object, info, align, stride);
3081 /* only one plane in non-MPLANE mode */
3082 v4l2object->n_v4l2_planes = 1;
3083 info->size = format->fmt.pix.sizeimage;
3084 stride = format->fmt.pix.bytesperline;
3086 if (info->stride[0] != stride)
3087 standard_stride = FALSE;
3089 gst_v4l2_object_extrapolate_info (v4l2object, info, align, stride);
3092 /* adjust the offset to take into account left and top */
3093 if (GST_VIDEO_FORMAT_INFO_IS_TILED (finfo)) {
3094 if ((align->padding_left + align->padding_top) > 0)
3095 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3096 "Left and top padding is not permitted for tiled formats");
3098 for (i = 0; i < finfo->n_planes; i++) {
3101 /* FIXME we assume plane as component as this is true for all supported
3102 * format we support. */
3104 hedge = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, i, align->padding_left);
3105 vedge = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (finfo, i, align->padding_top);
3107 info->offset[i] += (vedge * info->stride[i]) +
3108 (hedge * GST_VIDEO_INFO_COMP_PSTRIDE (info, i));
3113 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Got sizeimage %" G_GSIZE_FORMAT,
3116 /* to avoid copies we need video meta if there is padding */
3117 v4l2object->need_video_meta =
3118 ((align->padding_top + align->padding_left + align->padding_right +
3119 align->padding_bottom) != 0);
3121 /* ... or if stride is non "standard" */
3122 if (!standard_stride)
3123 v4l2object->need_video_meta = TRUE;
3125 /* ... or also video meta if we use multiple, non-contiguous, planes */
3126 if (v4l2object->n_v4l2_planes > 1)
3127 v4l2object->need_video_meta = TRUE;
3129 v4l2object->info = *info;
3130 v4l2object->align = *align;
3131 v4l2object->format = *format;
3132 v4l2object->fmtdesc = fmtdesc;
3134 /* if we have a framerate pre-calculate duration */
3135 if (info->fps_n > 0 && info->fps_d > 0) {
3136 v4l2object->duration = gst_util_uint64_scale_int (GST_SECOND, info->fps_d,
3139 v4l2object->duration = GST_CLOCK_TIME_NONE;
3144 gst_v4l2_object_extrapolate_stride (const GstVideoFormatInfo * finfo,
3145 gint plane, gint stride)
3149 switch (finfo->format) {
3150 case GST_VIDEO_FORMAT_NV12:
3151 case GST_VIDEO_FORMAT_NV12_64Z32:
3152 case GST_VIDEO_FORMAT_NV21:
3153 case GST_VIDEO_FORMAT_NV16:
3154 case GST_VIDEO_FORMAT_NV61:
3155 case GST_VIDEO_FORMAT_NV24:
3156 estride = (plane == 0 ? 1 : 2) *
3157 GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, plane, stride);
3160 estride = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, plane, stride);
3168 gst_v4l2_object_set_format_full (GstV4l2Object * v4l2object, GstCaps * caps,
3169 gboolean try_only, GstV4l2Error * error)
3171 gint fd = v4l2object->video_fd;
3172 struct v4l2_format format;
3173 struct v4l2_streamparm streamparm;
3174 enum v4l2_field field;
3175 guint32 pixelformat;
3176 struct v4l2_fmtdesc *fmtdesc;
3178 GstVideoAlignment align;
3179 gint width, height, fps_n, fps_d;
3183 enum v4l2_colorspace colorspace = 0;
3184 enum v4l2_quantization range = 0;
3185 enum v4l2_ycbcr_encoding matrix = 0;
3186 enum v4l2_xfer_func transfer = 0;
3189 g_return_val_if_fail (!v4l2object->skip_try_fmt_probes ||
3190 gst_caps_is_writable (caps), FALSE);
3192 GST_V4L2_CHECK_OPEN (v4l2object);
3194 GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
3196 is_mplane = V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type);
3198 gst_video_info_init (&info);
3199 gst_video_alignment_reset (&align);
3201 if (!gst_v4l2_object_get_caps_info (v4l2object, caps, &fmtdesc, &info))
3204 pixelformat = fmtdesc->pixelformat;
3205 width = GST_VIDEO_INFO_WIDTH (&info);
3206 height = GST_VIDEO_INFO_HEIGHT (&info);
3207 fps_n = GST_VIDEO_INFO_FPS_N (&info);
3208 fps_d = GST_VIDEO_INFO_FPS_D (&info);
3210 /* if encoded format (GST_VIDEO_INFO_N_PLANES return 0)
3211 * or if contiguous is prefered */
3212 n_v4l_planes = GST_VIDEO_INFO_N_PLANES (&info);
3213 if (!n_v4l_planes || !v4l2object->prefered_non_contiguous)
3216 if (GST_VIDEO_INFO_IS_INTERLACED (&info)) {
3217 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "interlaced video");
3218 /* ideally we would differentiate between types of interlaced video
3219 * but there is not sufficient information in the caps..
3221 field = V4L2_FIELD_INTERLACED;
3223 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "progressive video");
3224 field = V4L2_FIELD_NONE;
3227 if (V4L2_TYPE_IS_OUTPUT (v4l2object->type)) {
3228 /* We first pick th main colorspace from the primaries */
3229 switch (info.colorimetry.primaries) {
3230 case GST_VIDEO_COLOR_PRIMARIES_BT709:
3231 /* There is two colorspaces using these primaries, use the range to
3233 if (info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235)
3234 colorspace = V4L2_COLORSPACE_REC709;
3236 colorspace = V4L2_COLORSPACE_SRGB;
3238 case GST_VIDEO_COLOR_PRIMARIES_BT2020:
3239 colorspace = V4L2_COLORSPACE_BT2020;
3241 case GST_VIDEO_COLOR_PRIMARIES_BT470M:
3242 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
3244 case GST_VIDEO_COLOR_PRIMARIES_BT470BG:
3245 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
3247 case GST_VIDEO_COLOR_PRIMARIES_SMPTE170M:
3248 colorspace = V4L2_COLORSPACE_SMPTE170M;
3250 case GST_VIDEO_COLOR_PRIMARIES_SMPTE240M:
3251 colorspace = V4L2_COLORSPACE_SMPTE240M;
3254 case GST_VIDEO_COLOR_PRIMARIES_FILM:
3255 case GST_VIDEO_COLOR_PRIMARIES_UNKNOWN:
3256 /* We don't know, we will guess */
3260 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3261 "Unknown colorimetry primaries %d", info.colorimetry.primaries);
3265 switch (info.colorimetry.range) {
3266 case GST_VIDEO_COLOR_RANGE_0_255:
3267 range = V4L2_QUANTIZATION_FULL_RANGE;
3269 case GST_VIDEO_COLOR_RANGE_16_235:
3270 range = V4L2_QUANTIZATION_LIM_RANGE;
3272 case GST_VIDEO_COLOR_RANGE_UNKNOWN:
3273 /* We let the driver pick a default one */
3276 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3277 "Unknown colorimetry range %d", info.colorimetry.range);
3281 switch (info.colorimetry.matrix) {
3282 case GST_VIDEO_COLOR_MATRIX_RGB:
3283 /* Unspecified, leave to default */
3285 /* FCC is about the same as BT601 with less digit */
3286 case GST_VIDEO_COLOR_MATRIX_FCC:
3287 case GST_VIDEO_COLOR_MATRIX_BT601:
3288 matrix = V4L2_YCBCR_ENC_601;
3290 case GST_VIDEO_COLOR_MATRIX_BT709:
3291 matrix = V4L2_YCBCR_ENC_709;
3293 case GST_VIDEO_COLOR_MATRIX_SMPTE240M:
3294 matrix = V4L2_YCBCR_ENC_SMPTE240M;
3296 case GST_VIDEO_COLOR_MATRIX_BT2020:
3297 matrix = V4L2_YCBCR_ENC_BT2020;
3299 case GST_VIDEO_COLOR_MATRIX_UNKNOWN:
3300 /* We let the driver pick a default one */
3303 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3304 "Unknown colorimetry matrix %d", info.colorimetry.matrix);
3308 switch (info.colorimetry.transfer) {
3309 case GST_VIDEO_TRANSFER_GAMMA18:
3310 case GST_VIDEO_TRANSFER_GAMMA20:
3311 case GST_VIDEO_TRANSFER_GAMMA22:
3312 case GST_VIDEO_TRANSFER_GAMMA28:
3313 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3314 "GAMMA 18, 20, 22, 28 transfer functions not supported");
3316 case GST_VIDEO_TRANSFER_GAMMA10:
3317 transfer = V4L2_XFER_FUNC_NONE;
3319 case GST_VIDEO_TRANSFER_BT2020_12:
3320 case GST_VIDEO_TRANSFER_BT709:
3321 transfer = V4L2_XFER_FUNC_709;
3323 case GST_VIDEO_TRANSFER_SMPTE240M:
3324 transfer = V4L2_XFER_FUNC_SMPTE240M;
3326 case GST_VIDEO_TRANSFER_SRGB:
3327 transfer = V4L2_XFER_FUNC_SRGB;
3329 case GST_VIDEO_TRANSFER_LOG100:
3330 case GST_VIDEO_TRANSFER_LOG316:
3331 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3332 "LOG 100, 316 transfer functions not supported");
3333 /* FIXME No known sensible default, maybe AdobeRGB ? */
3335 case GST_VIDEO_TRANSFER_UNKNOWN:
3336 /* We let the driver pick a default one */
3339 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3340 "Unknown colorimetry tranfer %d", info.colorimetry.transfer);
3344 if (colorspace == 0) {
3345 /* Try to guess colorspace according to pixelformat and size */
3346 if (GST_VIDEO_INFO_IS_YUV (&info)) {
3347 /* SD streams likely use SMPTE170M and HD streams REC709 */
3348 if (width <= 720 && height <= 576)
3349 colorspace = V4L2_COLORSPACE_SMPTE170M;
3351 colorspace = V4L2_COLORSPACE_REC709;
3352 } else if (GST_VIDEO_INFO_IS_RGB (&info)) {
3353 colorspace = V4L2_COLORSPACE_SRGB;
3354 transfer = V4L2_XFER_FUNC_NONE;
3359 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Desired format %dx%d, format "
3360 "%" GST_FOURCC_FORMAT " stride: %d", width, height,
3361 GST_FOURCC_ARGS (pixelformat), GST_VIDEO_INFO_PLANE_STRIDE (&info, 0));
3363 memset (&format, 0x00, sizeof (struct v4l2_format));
3364 format.type = v4l2object->type;
3367 format.type = v4l2object->type;
3368 format.fmt.pix_mp.pixelformat = pixelformat;
3369 format.fmt.pix_mp.width = width;
3370 format.fmt.pix_mp.height = height;
3371 format.fmt.pix_mp.field = field;
3372 format.fmt.pix_mp.num_planes = n_v4l_planes;
3374 /* try to ask our prefered stride but it's not a failure if not
3376 for (i = 0; i < n_v4l_planes; i++) {
3377 gint stride = GST_VIDEO_INFO_PLANE_STRIDE (&info, i);
3379 if (GST_VIDEO_FORMAT_INFO_IS_TILED (info.finfo))
3380 stride = GST_VIDEO_TILE_X_TILES (stride) <<
3381 GST_VIDEO_FORMAT_INFO_TILE_WS (info.finfo);
3383 format.fmt.pix_mp.plane_fmt[i].bytesperline = stride;
3386 if (GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_ENCODED)
3387 format.fmt.pix_mp.plane_fmt[0].sizeimage = ENCODED_BUFFER_SIZE;
3389 gint stride = GST_VIDEO_INFO_PLANE_STRIDE (&info, 0);
3391 format.type = v4l2object->type;
3392 format.fmt.pix.width = width;
3393 format.fmt.pix.height = height;
3394 format.fmt.pix.pixelformat = pixelformat;
3395 format.fmt.pix.field = field;
3397 if (GST_VIDEO_FORMAT_INFO_IS_TILED (info.finfo))
3398 stride = GST_VIDEO_TILE_X_TILES (stride) <<
3399 GST_VIDEO_FORMAT_INFO_TILE_WS (info.finfo);
3401 /* try to ask our prefered stride */
3402 format.fmt.pix.bytesperline = stride;
3404 if (GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_ENCODED)
3405 format.fmt.pix.sizeimage = ENCODED_BUFFER_SIZE;
3408 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Desired format is %dx%d, format "
3409 "%" GST_FOURCC_FORMAT ", nb planes %d", format.fmt.pix.width,
3410 format.fmt.pix_mp.height,
3411 GST_FOURCC_ARGS (format.fmt.pix.pixelformat),
3412 is_mplane ? format.fmt.pix_mp.num_planes : 1);
3414 #ifndef GST_DISABLE_GST_DEBUG
3416 for (i = 0; i < format.fmt.pix_mp.num_planes; i++)
3417 GST_DEBUG_OBJECT (v4l2object->dbg_obj, " stride %d",
3418 format.fmt.pix_mp.plane_fmt[i].bytesperline);
3420 GST_DEBUG_OBJECT (v4l2object->dbg_obj, " stride %d",
3421 format.fmt.pix.bytesperline);
3425 if (V4L2_TYPE_IS_OUTPUT (v4l2object->type)) {
3427 format.fmt.pix_mp.colorspace = colorspace;
3428 format.fmt.pix_mp.quantization = range;
3429 format.fmt.pix_mp.ycbcr_enc = matrix;
3430 format.fmt.pix_mp.xfer_func = transfer;
3432 format.fmt.pix.colorspace = colorspace;
3433 format.fmt.pix.quantization = range;
3434 format.fmt.pix.ycbcr_enc = matrix;
3435 format.fmt.pix.xfer_func = transfer;
3438 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Desired colorspace is %d:%d:%d:%d",
3439 colorspace, range, matrix, transfer);
3443 if (v4l2object->ioctl (fd, VIDIOC_TRY_FMT, &format) < 0)
3444 goto try_fmt_failed;
3446 if (v4l2object->ioctl (fd, VIDIOC_S_FMT, &format) < 0)
3447 goto set_fmt_failed;
3450 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Got format of %dx%d, format "
3451 "%" GST_FOURCC_FORMAT ", nb planes %d, colorspace %d",
3452 format.fmt.pix.width, format.fmt.pix_mp.height,
3453 GST_FOURCC_ARGS (format.fmt.pix.pixelformat),
3454 is_mplane ? format.fmt.pix_mp.num_planes : 1,
3455 is_mplane ? format.fmt.pix_mp.colorspace : format.fmt.pix.colorspace);
3457 #ifndef GST_DISABLE_GST_DEBUG
3459 for (i = 0; i < format.fmt.pix_mp.num_planes; i++)
3460 GST_DEBUG_OBJECT (v4l2object->dbg_obj, " stride %d, sizeimage %d",
3461 format.fmt.pix_mp.plane_fmt[i].bytesperline,
3462 format.fmt.pix_mp.plane_fmt[i].sizeimage);
3464 GST_DEBUG_OBJECT (v4l2object->dbg_obj, " stride %d, sizeimage %d",
3465 format.fmt.pix.bytesperline, format.fmt.pix.sizeimage);
3469 if (format.fmt.pix.pixelformat != pixelformat)
3470 goto invalid_pixelformat;
3472 /* Only negotiate size with raw data.
3473 * For some codecs the dimensions are *not* in the bitstream, IIRC VC1
3474 * in ASF mode for example, there is also not reason for a driver to
3475 * change the size. */
3476 if (info.finfo->format != GST_VIDEO_FORMAT_ENCODED) {
3477 /* We can crop larger images */
3478 if (format.fmt.pix.width < width || format.fmt.pix.height < height)
3479 goto invalid_dimensions;
3481 /* Note, this will be adjusted if upstream has non-centered cropping. */
3482 align.padding_top = 0;
3483 align.padding_bottom = format.fmt.pix.height - height;
3484 align.padding_left = 0;
3485 align.padding_right = format.fmt.pix.width - width;
3488 if (is_mplane && format.fmt.pix_mp.num_planes != n_v4l_planes)
3489 goto invalid_planes;
3491 if ((is_mplane && format.fmt.pix_mp.field != field)
3492 || format.fmt.pix.field != field)
3495 gst_v4l2_object_get_colorspace (&format, &info.colorimetry);
3497 s = gst_caps_get_structure (caps, 0);
3498 if (gst_structure_has_field (s, "colorimetry")) {
3499 GstVideoColorimetry ci;
3500 if (!gst_video_colorimetry_from_string (&ci,
3501 gst_structure_get_string (s, "colorimetry"))
3502 || !gst_video_colorimetry_is_equal (&ci, &info.colorimetry))
3503 goto invalid_colorimetry;
3506 /* In case we have skipped the try_fmt probes, we'll need to set the
3507 * colorimetry and interlace-mode back into the caps. */
3508 if (v4l2object->skip_try_fmt_probes) {
3509 if (!gst_structure_has_field (s, "colorimetry")) {
3510 gchar *str = gst_video_colorimetry_to_string (&info.colorimetry);
3511 gst_structure_set (s, "colorimetry", G_TYPE_STRING, str, NULL);
3515 if (!gst_structure_has_field (s, "interlace-mode"))
3516 gst_structure_set (s, "interlace-mode", G_TYPE_STRING,
3517 gst_video_interlace_mode_to_string (info.interlace_mode), NULL);
3520 if (try_only) /* good enough for trying only */
3523 if (GST_VIDEO_INFO_HAS_ALPHA (&info)) {
3524 struct v4l2_control ctl = { 0, };
3525 ctl.id = V4L2_CID_ALPHA_COMPONENT;
3528 if (v4l2object->ioctl (fd, VIDIOC_S_CTRL, &ctl) < 0)
3529 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3530 "Failed to set alpha component value");
3533 /* Is there a reason we require the caller to always specify a framerate? */
3534 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Desired framerate: %u/%u", fps_n,
3537 memset (&streamparm, 0x00, sizeof (struct v4l2_streamparm));
3538 streamparm.type = v4l2object->type;
3540 if (v4l2object->ioctl (fd, VIDIOC_G_PARM, &streamparm) < 0)
3541 goto get_parm_failed;
3543 if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
3544 || v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
3545 GST_VIDEO_INFO_FPS_N (&info) =
3546 streamparm.parm.capture.timeperframe.denominator;
3547 GST_VIDEO_INFO_FPS_D (&info) =
3548 streamparm.parm.capture.timeperframe.numerator;
3550 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Got capture framerate: %u/%u",
3551 streamparm.parm.capture.timeperframe.denominator,
3552 streamparm.parm.capture.timeperframe.numerator);
3554 /* We used to skip frame rate setup if the camera was already setup
3555 * with the requested frame rate. This breaks some cameras though,
3556 * causing them to not output data (several models of Thinkpad cameras
3557 * have this problem at least).
3558 * So, don't skip. */
3559 GST_LOG_OBJECT (v4l2object->dbg_obj, "Setting capture framerate to %u/%u",
3561 /* We want to change the frame rate, so check whether we can. Some cheap USB
3562 * cameras don't have the capability */
3563 if ((streamparm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) == 0) {
3564 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
3565 "Not setting capture framerate (not supported)");
3569 /* Note: V4L2 wants the frame interval, we have the frame rate */
3570 streamparm.parm.capture.timeperframe.numerator = fps_d;
3571 streamparm.parm.capture.timeperframe.denominator = fps_n;
3573 /* some cheap USB cam's won't accept any change */
3574 if (v4l2object->ioctl (fd, VIDIOC_S_PARM, &streamparm) < 0)
3575 goto set_parm_failed;
3577 if (streamparm.parm.capture.timeperframe.numerator > 0 &&
3578 streamparm.parm.capture.timeperframe.denominator > 0) {
3579 /* get new values */
3580 fps_d = streamparm.parm.capture.timeperframe.numerator;
3581 fps_n = streamparm.parm.capture.timeperframe.denominator;
3583 GST_INFO_OBJECT (v4l2object->dbg_obj, "Set capture framerate to %u/%u",
3586 /* fix v4l2 capture driver to provide framerate values */
3587 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3588 "Reuse caps framerate %u/%u - fix v4l2 capture driver", fps_n, fps_d);
3591 GST_VIDEO_INFO_FPS_N (&info) = fps_n;
3592 GST_VIDEO_INFO_FPS_D (&info) = fps_d;
3593 } else if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT
3594 || v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
3595 GST_VIDEO_INFO_FPS_N (&info) =
3596 streamparm.parm.output.timeperframe.denominator;
3597 GST_VIDEO_INFO_FPS_D (&info) =
3598 streamparm.parm.output.timeperframe.numerator;
3600 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Got output framerate: %u/%u",
3601 streamparm.parm.output.timeperframe.denominator,
3602 streamparm.parm.output.timeperframe.numerator);
3604 GST_LOG_OBJECT (v4l2object->dbg_obj, "Setting output framerate to %u/%u",
3606 if ((streamparm.parm.output.capability & V4L2_CAP_TIMEPERFRAME) == 0) {
3607 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
3608 "Not setting output framerate (not supported)");
3612 /* Note: V4L2 wants the frame interval, we have the frame rate */
3613 streamparm.parm.output.timeperframe.numerator = fps_d;
3614 streamparm.parm.output.timeperframe.denominator = fps_n;
3616 if (v4l2object->ioctl (fd, VIDIOC_S_PARM, &streamparm) < 0)
3617 goto set_parm_failed;
3619 if (streamparm.parm.output.timeperframe.numerator > 0 &&
3620 streamparm.parm.output.timeperframe.denominator > 0) {
3621 /* get new values */
3622 fps_d = streamparm.parm.output.timeperframe.numerator;
3623 fps_n = streamparm.parm.output.timeperframe.denominator;
3625 GST_INFO_OBJECT (v4l2object->dbg_obj, "Set output framerate to %u/%u",
3628 /* fix v4l2 output driver to provide framerate values */
3629 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3630 "Reuse caps framerate %u/%u - fix v4l2 output driver", fps_n, fps_d);
3633 GST_VIDEO_INFO_FPS_N (&info) = fps_n;
3634 GST_VIDEO_INFO_FPS_D (&info) = fps_d;
3638 /* add boolean return, so we can fail on drivers bugs */
3639 gst_v4l2_object_save_format (v4l2object, fmtdesc, &format, &info, &align);
3641 /* now configure the pool */
3642 if (!gst_v4l2_object_setup_pool (v4l2object, caps))
3650 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "can't parse caps %" GST_PTR_FORMAT,
3656 if (errno == EINVAL) {
3657 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3658 (_("Device '%s' has no supported format"), v4l2object->videodev),
3659 ("Call to TRY_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
3660 GST_FOURCC_ARGS (pixelformat), width, height,
3661 g_strerror (errno)));
3663 GST_V4L2_ERROR (error, RESOURCE, FAILED,
3664 (_("Device '%s' failed during initialization"),
3665 v4l2object->videodev),
3666 ("Call to TRY_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
3667 GST_FOURCC_ARGS (pixelformat), width, height,
3668 g_strerror (errno)));
3674 if (errno == EBUSY) {
3675 GST_V4L2_ERROR (error, RESOURCE, BUSY,
3676 (_("Device '%s' is busy"), v4l2object->videodev),
3677 ("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
3678 GST_FOURCC_ARGS (pixelformat), width, height,
3679 g_strerror (errno)));
3680 } else if (errno == EINVAL) {
3681 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3682 (_("Device '%s' has no supported format"), v4l2object->videodev),
3683 ("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
3684 GST_FOURCC_ARGS (pixelformat), width, height,
3685 g_strerror (errno)));
3687 GST_V4L2_ERROR (error, RESOURCE, FAILED,
3688 (_("Device '%s' failed during initialization"),
3689 v4l2object->videodev),
3690 ("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
3691 GST_FOURCC_ARGS (pixelformat), width, height,
3692 g_strerror (errno)));
3698 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3699 (_("Device '%s' cannot capture at %dx%d"),
3700 v4l2object->videodev, width, height),
3701 ("Tried to capture at %dx%d, but device returned size %dx%d",
3702 width, height, format.fmt.pix.width, format.fmt.pix.height));
3705 invalid_pixelformat:
3707 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3708 (_("Device '%s' cannot capture in the specified format"),
3709 v4l2object->videodev),
3710 ("Tried to capture in %" GST_FOURCC_FORMAT
3711 ", but device returned format" " %" GST_FOURCC_FORMAT,
3712 GST_FOURCC_ARGS (pixelformat),
3713 GST_FOURCC_ARGS (format.fmt.pix.pixelformat)));
3718 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3719 (_("Device '%s' does support non-contiguous planes"),
3720 v4l2object->videodev),
3721 ("Device wants %d planes", format.fmt.pix_mp.num_planes));
3726 enum v4l2_field wanted_field;
3729 wanted_field = format.fmt.pix_mp.field;
3731 wanted_field = format.fmt.pix.field;
3733 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3734 (_("Device '%s' does not support %s interlacing"),
3735 v4l2object->videodev,
3736 field == V4L2_FIELD_NONE ? "progressive" : "interleaved"),
3737 ("Device wants %s interlacing",
3738 wanted_field == V4L2_FIELD_NONE ? "progressive" : "interleaved"));
3741 invalid_colorimetry:
3743 gchar *wanted_colorimetry;
3745 wanted_colorimetry = gst_video_colorimetry_to_string (&info.colorimetry);
3747 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3748 (_("Device '%s' does not support %s colorimetry"),
3749 v4l2object->videodev, gst_structure_get_string (s, "colorimetry")),
3750 ("Device wants %s colorimetry", wanted_colorimetry));
3752 g_free (wanted_colorimetry);
3757 /* it's possible that this call is not supported */
3758 if (errno != EINVAL && errno != ENOTTY) {
3759 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3760 (_("Could not get parameters on device '%s'"),
3761 v4l2object->videodev), GST_ERROR_SYSTEM);
3767 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3768 (_("Video device did not accept new frame rate setting.")),
3774 /* setup_pool already send the error */
3780 gst_v4l2_object_set_format (GstV4l2Object * v4l2object, GstCaps * caps,
3781 GstV4l2Error * error)
3783 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Setting format to %" GST_PTR_FORMAT,
3785 return gst_v4l2_object_set_format_full (v4l2object, caps, FALSE, error);
3789 gst_v4l2_object_try_format (GstV4l2Object * v4l2object, GstCaps * caps,
3790 GstV4l2Error * error)
3792 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Trying format %" GST_PTR_FORMAT,
3794 return gst_v4l2_object_set_format_full (v4l2object, caps, TRUE, error);
3798 * gst_v4l2_object_acquire_format:
3799 * @v4l2object the object
3800 * @info a GstVideoInfo to be filled
3802 * Acquire the driver choosen format. This is useful in decoder or encoder elements where
3803 * the output format is choosen by the HW.
3805 * Returns: %TRUE on success, %FALSE on failure.
3808 gst_v4l2_object_acquire_format (GstV4l2Object * v4l2object, GstVideoInfo * info)
3810 struct v4l2_fmtdesc *fmtdesc;
3811 struct v4l2_format fmt;
3812 struct v4l2_crop crop;
3813 struct v4l2_selection sel;
3814 struct v4l2_rect *r = NULL;
3815 GstVideoFormat format;
3816 guint width, height;
3817 GstVideoAlignment align;
3819 gst_video_info_init (info);
3820 gst_video_alignment_reset (&align);
3822 memset (&fmt, 0x00, sizeof (struct v4l2_format));
3823 fmt.type = v4l2object->type;
3824 if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_G_FMT, &fmt) < 0)
3825 goto get_fmt_failed;
3827 fmtdesc = gst_v4l2_object_get_format_from_fourcc (v4l2object,
3828 fmt.fmt.pix.pixelformat);
3829 if (fmtdesc == NULL)
3830 goto unsupported_format;
3832 /* No need to care about mplane, the four first params are the same */
3833 format = gst_v4l2_object_v4l2fourcc_to_video_format (fmt.fmt.pix.pixelformat);
3835 /* fails if we do no translate the fmt.pix.pixelformat to GstVideoFormat */
3836 if (format == GST_VIDEO_FORMAT_UNKNOWN)
3837 goto unsupported_format;
3839 if (fmt.fmt.pix.width == 0 || fmt.fmt.pix.height == 0)
3840 goto invalid_dimensions;
3842 width = fmt.fmt.pix.width;
3843 height = fmt.fmt.pix.height;
3845 /* Use the default compose rectangle */
3846 memset (&sel, 0, sizeof (struct v4l2_selection));
3847 sel.type = v4l2object->type;
3848 sel.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
3849 if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_G_SELECTION, &sel) >= 0) {
3852 /* For ancient kernels, fall back to G_CROP */
3853 memset (&crop, 0, sizeof (struct v4l2_crop));
3854 crop.type = v4l2object->type;
3855 if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_G_CROP, &crop) >= 0)
3859 align.padding_left = r->left;
3860 align.padding_top = r->top;
3861 align.padding_right = width - r->width - r->left;
3862 align.padding_bottom = height - r->height - r->top;
3867 gst_video_info_set_format (info, format, width, height);
3869 switch (fmt.fmt.pix.field) {
3870 case V4L2_FIELD_ANY:
3871 case V4L2_FIELD_NONE:
3872 info->interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
3874 case V4L2_FIELD_INTERLACED:
3875 case V4L2_FIELD_INTERLACED_TB:
3876 case V4L2_FIELD_INTERLACED_BT:
3877 info->interlace_mode = GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
3880 goto unsupported_field;
3883 gst_v4l2_object_get_colorspace (&fmt, &info->colorimetry);
3885 gst_v4l2_object_save_format (v4l2object, fmtdesc, &fmt, info, &align);
3887 /* Shall we setup the pool ? */
3893 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
3894 (_("Video device did not provide output format.")), GST_ERROR_SYSTEM);
3899 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
3900 (_("Video device returned invalid dimensions.")),
3901 ("Expected non 0 dimensions, got %dx%d", fmt.fmt.pix.width,
3902 fmt.fmt.pix.height));
3907 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
3908 (_("Video device uses an unsupported interlacing method.")),
3909 ("V4L2 field type %d not supported", fmt.fmt.pix.field));
3914 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
3915 (_("Video device uses an unsupported pixel format.")),
3916 ("V4L2 format %" GST_FOURCC_FORMAT " not supported",
3917 GST_FOURCC_ARGS (fmt.fmt.pix.pixelformat)));
3923 gst_v4l2_object_set_crop (GstV4l2Object * obj)
3925 struct v4l2_crop crop = { 0 };
3927 crop.type = obj->type;
3928 crop.c.left = obj->align.padding_left;
3929 crop.c.top = obj->align.padding_top;
3930 crop.c.width = obj->info.width;
3931 crop.c.height = obj->info.height;
3933 if (obj->align.padding_left + obj->align.padding_top +
3934 obj->align.padding_right + obj->align.padding_bottom == 0) {
3935 GST_DEBUG_OBJECT (obj->dbg_obj, "no cropping needed");
3939 GST_DEBUG_OBJECT (obj->dbg_obj,
3940 "Desired cropping left %u, top %u, size %ux%u", crop.c.left, crop.c.top,
3941 crop.c.width, crop.c.height);
3943 if (obj->ioctl (obj->video_fd, VIDIOC_S_CROP, &crop) < 0) {
3944 GST_WARNING_OBJECT (obj->dbg_obj, "VIDIOC_S_CROP failed");
3948 if (obj->ioctl (obj->video_fd, VIDIOC_G_CROP, &crop) < 0) {
3949 GST_WARNING_OBJECT (obj->dbg_obj, "VIDIOC_G_CROP failed");
3953 GST_DEBUG_OBJECT (obj->dbg_obj,
3954 "Got cropping left %u, top %u, size %ux%u", crop.c.left, crop.c.top,
3955 crop.c.width, crop.c.height);
3961 gst_v4l2_object_caps_equal (GstV4l2Object * v4l2object, GstCaps * caps)
3963 GstStructure *config;
3967 if (!v4l2object->pool)
3970 config = gst_buffer_pool_get_config (v4l2object->pool);
3971 gst_buffer_pool_config_get_params (config, &oldcaps, NULL, NULL, NULL);
3973 ret = oldcaps && gst_caps_is_equal (caps, oldcaps);
3975 gst_structure_free (config);
3981 gst_v4l2_object_unlock (GstV4l2Object * v4l2object)
3983 gboolean ret = TRUE;
3985 GST_LOG_OBJECT (v4l2object->dbg_obj, "start flushing");
3987 if (v4l2object->pool && gst_buffer_pool_is_active (v4l2object->pool))
3988 gst_buffer_pool_set_flushing (v4l2object->pool, TRUE);
3994 gst_v4l2_object_unlock_stop (GstV4l2Object * v4l2object)
3996 gboolean ret = TRUE;
3998 GST_LOG_OBJECT (v4l2object->dbg_obj, "stop flushing");
4000 if (v4l2object->pool && gst_buffer_pool_is_active (v4l2object->pool))
4001 gst_buffer_pool_set_flushing (v4l2object->pool, FALSE);
4007 gst_v4l2_object_stop (GstV4l2Object * v4l2object)
4009 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "stopping");
4011 if (!GST_V4L2_IS_OPEN (v4l2object))
4013 if (!GST_V4L2_IS_ACTIVE (v4l2object))
4016 if (v4l2object->pool) {
4017 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "deactivating pool");
4018 gst_buffer_pool_set_active (v4l2object->pool, FALSE);
4019 gst_object_unref (v4l2object->pool);
4020 v4l2object->pool = NULL;
4023 GST_V4L2_SET_INACTIVE (v4l2object);
4030 gst_v4l2_object_probe_caps (GstV4l2Object * v4l2object, GstCaps * filter)
4036 formats = gst_v4l2_object_get_format_list (v4l2object);
4038 ret = gst_caps_new_empty ();
4040 if (v4l2object->keep_aspect && !v4l2object->par) {
4041 struct v4l2_cropcap cropcap;
4043 memset (&cropcap, 0, sizeof (cropcap));
4045 cropcap.type = v4l2object->type;
4046 if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_CROPCAP, &cropcap) < 0) {
4047 if (errno != ENOTTY)
4048 GST_WARNING_OBJECT (v4l2object->dbg_obj,
4049 "Failed to probe pixel aspect ratio with VIDIOC_CROPCAP: %s",
4050 g_strerror (errno));
4052 v4l2object->par = g_new0 (GValue, 1);
4053 g_value_init (v4l2object->par, GST_TYPE_FRACTION);
4054 gst_value_set_fraction (v4l2object->par, cropcap.pixelaspect.numerator,
4055 cropcap.pixelaspect.denominator);
4059 for (walk = formats; walk; walk = walk->next) {
4060 struct v4l2_fmtdesc *format;
4061 GstStructure *template;
4064 format = (struct v4l2_fmtdesc *) walk->data;
4066 template = gst_v4l2_object_v4l2fourcc_to_bare_struct (format->pixelformat);
4069 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
4070 "unknown format %" GST_FOURCC_FORMAT,
4071 GST_FOURCC_ARGS (format->pixelformat));
4075 /* If we have a filter, check if we need to probe this format or not */
4077 GstCaps *format_caps = gst_caps_new_empty ();
4079 gst_caps_append_structure (format_caps, gst_structure_copy (template));
4081 if (!gst_caps_can_intersect (format_caps, filter)) {
4082 gst_caps_unref (format_caps);
4083 gst_structure_free (template);
4087 gst_caps_unref (format_caps);
4090 tmp = gst_v4l2_object_probe_caps_for_format (v4l2object,
4091 format->pixelformat, template);
4093 gst_caps_append (ret, tmp);
4095 gst_structure_free (template);
4102 ret = gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
4103 gst_caps_unref (tmp);
4106 GST_INFO_OBJECT (v4l2object->dbg_obj, "probed caps: %" GST_PTR_FORMAT, ret);
4112 gst_v4l2_object_get_caps (GstV4l2Object * v4l2object, GstCaps * filter)
4116 if (v4l2object->probed_caps == NULL)
4117 v4l2object->probed_caps = gst_v4l2_object_probe_caps (v4l2object, NULL);
4120 ret = gst_caps_intersect_full (filter, v4l2object->probed_caps,
4121 GST_CAPS_INTERSECT_FIRST);
4123 ret = gst_caps_ref (v4l2object->probed_caps);
4130 gst_v4l2_object_decide_allocation (GstV4l2Object * obj, GstQuery * query)
4133 GstBufferPool *pool = NULL, *other_pool = NULL;
4134 GstStructure *config;
4135 guint size, min, max, own_min = 0;
4137 gboolean has_video_meta;
4138 gboolean can_share_own_pool, pushing_from_our_pool = FALSE;
4139 GstAllocator *allocator = NULL;
4140 GstAllocationParams params = { 0 };
4142 GST_DEBUG_OBJECT (obj->dbg_obj, "decide allocation");
4144 g_return_val_if_fail (obj->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
4145 obj->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, FALSE);
4147 gst_query_parse_allocation (query, &caps, NULL);
4149 if (obj->pool == NULL) {
4150 if (!gst_v4l2_object_setup_pool (obj, caps))
4154 if (gst_query_get_n_allocation_params (query) > 0)
4155 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
4157 if (gst_query_get_n_allocation_pools (query) > 0) {
4158 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
4167 GST_DEBUG_OBJECT (obj->dbg_obj, "allocation: size:%u min:%u max:%u pool:%"
4168 GST_PTR_FORMAT, size, min, max, pool);
4171 gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
4173 can_share_own_pool = (has_video_meta || !obj->need_video_meta);
4175 gst_v4l2_get_driver_min_buffers (obj);
4176 /* We can't share our own pool, if it exceed V4L2 capacity */
4177 if (min + obj->min_buffers + 1 > VIDEO_MAX_FRAME)
4178 can_share_own_pool = FALSE;
4181 switch (obj->mode) {
4182 case GST_V4L2_IO_RW:
4184 /* in READ/WRITE mode, prefer a downstream pool because our own pool
4185 * doesn't help much, we have to write to it as well */
4186 GST_DEBUG_OBJECT (obj->dbg_obj,
4187 "read/write mode: using downstream pool");
4188 /* use the bigest size, when we use our own pool we can't really do any
4189 * other size than what the hardware gives us but for downstream pools
4191 size = MAX (size, obj->info.size);
4192 } else if (can_share_own_pool) {
4193 /* no downstream pool, use our own then */
4194 GST_DEBUG_OBJECT (obj->dbg_obj,
4195 "read/write mode: no downstream pool, using our own");
4196 pool = gst_object_ref (obj->pool);
4197 size = obj->info.size;
4198 pushing_from_our_pool = TRUE;
4202 case GST_V4L2_IO_USERPTR:
4203 case GST_V4L2_IO_DMABUF_IMPORT:
4204 /* in importing mode, prefer our own pool, and pass the other pool to
4205 * our own, so it can serve itself */
4207 goto no_downstream_pool;
4208 gst_v4l2_buffer_pool_set_other_pool (GST_V4L2_BUFFER_POOL (obj->pool),
4211 gst_object_unref (pool);
4212 pool = gst_object_ref (obj->pool);
4213 size = obj->info.size;
4216 case GST_V4L2_IO_MMAP:
4217 case GST_V4L2_IO_DMABUF:
4218 /* in streaming mode, prefer our own pool */
4219 /* Check if we can use it ... */
4220 if (can_share_own_pool) {
4222 gst_object_unref (pool);
4223 pool = gst_object_ref (obj->pool);
4224 size = obj->info.size;
4225 GST_DEBUG_OBJECT (obj->dbg_obj,
4226 "streaming mode: using our own pool %" GST_PTR_FORMAT, pool);
4227 pushing_from_our_pool = TRUE;
4229 GST_DEBUG_OBJECT (obj->dbg_obj,
4230 "streaming mode: copying to downstream pool %" GST_PTR_FORMAT,
4233 GST_DEBUG_OBJECT (obj->dbg_obj,
4234 "streaming mode: no usable pool, copying to generic pool");
4235 size = MAX (size, obj->info.size);
4238 case GST_V4L2_IO_AUTO:
4240 GST_WARNING_OBJECT (obj->dbg_obj, "unhandled mode");
4247 /* If pushing from our own pool, configure it with queried minimum,
4248 * otherwise use the minimum required */
4249 if (pushing_from_our_pool) {
4250 /* When pushing from our own pool, we need what downstream one, to be able
4251 * to fill the pipeline, the minimum required to decoder according to the
4252 * driver and 2 more, so we don't endup up with everything downstream or
4253 * held by the decoder. We account 2 buffers for v4l2 so when one is being
4254 * pushed downstream the other one can already be queued for the next
4256 own_min = min + obj->min_buffers + 2;
4258 /* If no allocation parameters where provided, allow for a little more
4259 * buffers and enable copy threshold */
4262 gst_v4l2_buffer_pool_copy_at_threshold (GST_V4L2_BUFFER_POOL (pool),
4265 gst_v4l2_buffer_pool_copy_at_threshold (GST_V4L2_BUFFER_POOL (pool),
4270 /* In this case we'll have to configure two buffer pool. For our buffer
4271 * pool, we'll need what the driver one, and one more, so we can dequeu */
4272 own_min = obj->min_buffers + 1;
4273 own_min = MAX (own_min, GST_V4L2_MIN_BUFFERS);
4275 /* for the downstream pool, we keep what downstream wants, though ensure
4276 * at least a minimum if downstream didn't suggest anything (we are
4277 * expecting the base class to create a default one for the context) */
4278 min = MAX (min, GST_V4L2_MIN_BUFFERS);
4280 /* To import we need the other pool to hold at least own_min */
4281 if (obj->pool == pool)
4285 /* Request a bigger max, if one was suggested but it's too small */
4287 max = MAX (min, max);
4289 /* First step, configure our own pool */
4290 config = gst_buffer_pool_get_config (obj->pool);
4292 if (obj->need_video_meta || has_video_meta) {
4293 GST_DEBUG_OBJECT (obj->dbg_obj, "activate Video Meta");
4294 gst_buffer_pool_config_add_option (config,
4295 GST_BUFFER_POOL_OPTION_VIDEO_META);
4298 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
4299 gst_buffer_pool_config_set_params (config, caps, size, own_min, 0);
4301 GST_DEBUG_OBJECT (obj->dbg_obj, "setting own pool config to %"
4302 GST_PTR_FORMAT, config);
4304 /* Our pool often need to adjust the value */
4305 if (!gst_buffer_pool_set_config (obj->pool, config)) {
4306 config = gst_buffer_pool_get_config (obj->pool);
4308 GST_DEBUG_OBJECT (obj->dbg_obj, "own pool config changed to %"
4309 GST_PTR_FORMAT, config);
4311 /* our pool will adjust the maximum buffer, which we are fine with */
4312 if (!gst_buffer_pool_set_config (obj->pool, config))
4316 /* Now configure the other pool if different */
4317 if (obj->pool != pool)
4321 config = gst_buffer_pool_get_config (other_pool);
4322 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
4323 gst_buffer_pool_config_set_params (config, caps, size, min, max);
4325 GST_DEBUG_OBJECT (obj->dbg_obj, "setting other pool config to %"
4326 GST_PTR_FORMAT, config);
4328 /* if downstream supports video metadata, add this to the pool config */
4329 if (has_video_meta) {
4330 GST_DEBUG_OBJECT (obj->dbg_obj, "activate Video Meta");
4331 gst_buffer_pool_config_add_option (config,
4332 GST_BUFFER_POOL_OPTION_VIDEO_META);
4335 if (!gst_buffer_pool_set_config (other_pool, config)) {
4336 config = gst_buffer_pool_get_config (other_pool);
4338 if (!gst_buffer_pool_config_validate_params (config, caps, size, min,
4340 gst_structure_free (config);
4344 if (!gst_buffer_pool_set_config (other_pool, config))
4350 /* For simplicity, simply read back the active configuration, so our base
4351 * class get the right information */
4352 config = gst_buffer_pool_get_config (pool);
4353 gst_buffer_pool_config_get_params (config, NULL, &size, &min, &max);
4354 gst_structure_free (config);
4358 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
4360 gst_query_add_allocation_pool (query, pool, size, min, max);
4363 gst_object_unref (allocator);
4366 gst_object_unref (pool);
4372 /* setup_pool already send the error */
4377 GST_ELEMENT_ERROR (obj->element, RESOURCE, SETTINGS,
4378 (_("Failed to configure internal buffer pool.")), (NULL));
4383 GST_ELEMENT_ERROR (obj->element, RESOURCE, SETTINGS,
4384 (_("Video device did not suggest any buffer size.")), (NULL));
4390 gst_object_unref (allocator);
4393 gst_object_unref (pool);
4398 GST_ELEMENT_ERROR (obj->element, RESOURCE, SETTINGS,
4399 (_("No downstream pool to import from.")),
4400 ("When importing DMABUF or USERPTR, we need a pool to import from"));
4406 gst_v4l2_object_propose_allocation (GstV4l2Object * obj, GstQuery * query)
4408 GstBufferPool *pool;
4409 /* we need at least 2 buffers to operate */
4410 guint size, min, max;
4414 /* Set defaults allocation parameters */
4415 size = obj->info.size;
4416 min = GST_V4L2_MIN_BUFFERS;
4417 max = VIDEO_MAX_FRAME;
4419 gst_query_parse_allocation (query, &caps, &need_pool);
4424 if ((pool = obj->pool))
4425 gst_object_ref (pool);
4429 GstStructure *config;
4431 /* we had a pool, check caps */
4432 config = gst_buffer_pool_get_config (pool);
4433 gst_buffer_pool_config_get_params (config, &pcaps, NULL, NULL, NULL);
4435 GST_DEBUG_OBJECT (obj->dbg_obj,
4436 "we had a pool with caps %" GST_PTR_FORMAT, pcaps);
4437 if (!gst_caps_is_equal (caps, pcaps)) {
4438 gst_structure_free (config);
4439 gst_object_unref (pool);
4440 goto different_caps;
4442 gst_structure_free (config);
4444 gst_v4l2_get_driver_min_buffers (obj);
4446 min = MAX (obj->min_buffers, GST_V4L2_MIN_BUFFERS);
4448 gst_query_add_allocation_pool (query, pool, size, min, max);
4450 /* we also support various metadata */
4451 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
4454 gst_object_unref (pool);
4461 GST_DEBUG_OBJECT (obj->dbg_obj, "no caps specified");
4466 /* different caps, we can't use this pool */
4467 GST_DEBUG_OBJECT (obj->dbg_obj, "pool has different caps");