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)
58 #if SIZEOF_OFF_T == 8 && !defined(mmap64)
65 V4L2_STD_OBJECT_PROPS,
69 * common format / caps utilities:
73 GST_V4L2_RAW = 1 << 0,
74 GST_V4L2_CODEC = 1 << 1,
75 GST_V4L2_TRANSPORT = 1 << 2,
76 GST_V4L2_NO_PARSE = 1 << 3,
84 GstV4L2FormatFlags flags;
87 static const GstV4L2FormatDesc gst_v4l2_formats[] = {
89 {V4L2_PIX_FMT_RGB332, TRUE, GST_V4L2_RAW},
90 {V4L2_PIX_FMT_ARGB555, TRUE, GST_V4L2_RAW},
91 {V4L2_PIX_FMT_XRGB555, TRUE, GST_V4L2_RAW},
92 {V4L2_PIX_FMT_ARGB555X, TRUE, GST_V4L2_RAW},
93 {V4L2_PIX_FMT_XRGB555X, TRUE, GST_V4L2_RAW},
94 {V4L2_PIX_FMT_RGB565, TRUE, GST_V4L2_RAW},
95 {V4L2_PIX_FMT_RGB565X, TRUE, GST_V4L2_RAW},
96 {V4L2_PIX_FMT_BGR666, TRUE, GST_V4L2_RAW},
97 {V4L2_PIX_FMT_BGR24, TRUE, GST_V4L2_RAW},
98 {V4L2_PIX_FMT_RGB24, TRUE, GST_V4L2_RAW},
99 {V4L2_PIX_FMT_ABGR32, TRUE, GST_V4L2_RAW},
100 {V4L2_PIX_FMT_XBGR32, TRUE, GST_V4L2_RAW},
101 {V4L2_PIX_FMT_ARGB32, TRUE, GST_V4L2_RAW},
102 {V4L2_PIX_FMT_XRGB32, TRUE, GST_V4L2_RAW},
104 /* Deprecated Packed RGB Image Formats (alpha ambiguity) */
105 {V4L2_PIX_FMT_RGB444, TRUE, GST_V4L2_RAW},
106 {V4L2_PIX_FMT_RGB555, TRUE, GST_V4L2_RAW},
107 {V4L2_PIX_FMT_RGB555X, TRUE, GST_V4L2_RAW},
108 {V4L2_PIX_FMT_BGR32, TRUE, GST_V4L2_RAW},
109 {V4L2_PIX_FMT_RGB32, TRUE, GST_V4L2_RAW},
112 {V4L2_PIX_FMT_GREY, TRUE, GST_V4L2_RAW},
113 {V4L2_PIX_FMT_Y4, TRUE, GST_V4L2_RAW},
114 {V4L2_PIX_FMT_Y6, TRUE, GST_V4L2_RAW},
115 {V4L2_PIX_FMT_Y10, TRUE, GST_V4L2_RAW},
116 {V4L2_PIX_FMT_Y12, TRUE, GST_V4L2_RAW},
117 {V4L2_PIX_FMT_Y16, TRUE, GST_V4L2_RAW},
118 {V4L2_PIX_FMT_Y16_BE, TRUE, GST_V4L2_RAW},
119 {V4L2_PIX_FMT_Y10BPACK, TRUE, GST_V4L2_RAW},
121 /* Palette formats */
122 {V4L2_PIX_FMT_PAL8, TRUE, GST_V4L2_RAW},
124 /* Chrominance formats */
125 {V4L2_PIX_FMT_UV8, TRUE, GST_V4L2_RAW},
127 /* Luminance+Chrominance formats */
128 {V4L2_PIX_FMT_YVU410, TRUE, GST_V4L2_RAW},
129 {V4L2_PIX_FMT_YVU420, TRUE, GST_V4L2_RAW},
130 {V4L2_PIX_FMT_YVU420M, TRUE, GST_V4L2_RAW},
131 {V4L2_PIX_FMT_YUYV, TRUE, GST_V4L2_RAW},
132 {V4L2_PIX_FMT_YYUV, TRUE, GST_V4L2_RAW},
133 {V4L2_PIX_FMT_YVYU, TRUE, GST_V4L2_RAW},
134 {V4L2_PIX_FMT_UYVY, TRUE, GST_V4L2_RAW},
135 {V4L2_PIX_FMT_VYUY, TRUE, GST_V4L2_RAW},
136 {V4L2_PIX_FMT_YUV422P, TRUE, GST_V4L2_RAW},
137 {V4L2_PIX_FMT_YUV411P, TRUE, GST_V4L2_RAW},
138 {V4L2_PIX_FMT_Y41P, TRUE, GST_V4L2_RAW},
139 {V4L2_PIX_FMT_YUV444, TRUE, GST_V4L2_RAW},
140 {V4L2_PIX_FMT_YUV555, TRUE, GST_V4L2_RAW},
141 {V4L2_PIX_FMT_YUV565, TRUE, GST_V4L2_RAW},
142 {V4L2_PIX_FMT_YUV32, TRUE, GST_V4L2_RAW},
143 {V4L2_PIX_FMT_YUV410, TRUE, GST_V4L2_RAW},
144 {V4L2_PIX_FMT_YUV420, TRUE, GST_V4L2_RAW},
145 {V4L2_PIX_FMT_YUV420M, TRUE, GST_V4L2_RAW},
146 {V4L2_PIX_FMT_HI240, TRUE, GST_V4L2_RAW},
147 {V4L2_PIX_FMT_HM12, TRUE, GST_V4L2_RAW},
148 {V4L2_PIX_FMT_M420, TRUE, GST_V4L2_RAW},
150 /* two planes -- one Y, one Cr + Cb interleaved */
151 {V4L2_PIX_FMT_NV12, TRUE, GST_V4L2_RAW},
152 {V4L2_PIX_FMT_NV12M, TRUE, GST_V4L2_RAW},
153 {V4L2_PIX_FMT_NV12MT, TRUE, GST_V4L2_RAW},
154 {V4L2_PIX_FMT_NV12MT_16X16, TRUE, GST_V4L2_RAW},
155 {V4L2_PIX_FMT_NV21, TRUE, GST_V4L2_RAW},
156 {V4L2_PIX_FMT_NV21M, TRUE, GST_V4L2_RAW},
157 {V4L2_PIX_FMT_NV16, TRUE, GST_V4L2_RAW},
158 {V4L2_PIX_FMT_NV16M, TRUE, GST_V4L2_RAW},
159 {V4L2_PIX_FMT_NV61, TRUE, GST_V4L2_RAW},
160 {V4L2_PIX_FMT_NV61M, TRUE, GST_V4L2_RAW},
161 {V4L2_PIX_FMT_NV24, TRUE, GST_V4L2_RAW},
162 {V4L2_PIX_FMT_NV42, TRUE, GST_V4L2_RAW},
164 /* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */
165 {V4L2_PIX_FMT_SBGGR8, TRUE, GST_V4L2_CODEC},
166 {V4L2_PIX_FMT_SGBRG8, TRUE, GST_V4L2_CODEC},
167 {V4L2_PIX_FMT_SGRBG8, TRUE, GST_V4L2_CODEC},
168 {V4L2_PIX_FMT_SRGGB8, TRUE, GST_V4L2_CODEC},
170 /* compressed formats */
171 {V4L2_PIX_FMT_MJPEG, FALSE, GST_V4L2_CODEC},
172 {V4L2_PIX_FMT_JPEG, FALSE, GST_V4L2_CODEC},
173 {V4L2_PIX_FMT_PJPG, FALSE, GST_V4L2_CODEC},
174 {V4L2_PIX_FMT_DV, FALSE, GST_V4L2_TRANSPORT},
175 {V4L2_PIX_FMT_MPEG, FALSE, GST_V4L2_TRANSPORT},
176 {V4L2_PIX_FMT_H264, FALSE, GST_V4L2_CODEC},
177 {V4L2_PIX_FMT_H264_NO_SC, FALSE, GST_V4L2_CODEC},
178 {V4L2_PIX_FMT_H264_MVC, FALSE, GST_V4L2_CODEC},
179 {V4L2_PIX_FMT_H263, FALSE, GST_V4L2_CODEC},
180 {V4L2_PIX_FMT_MPEG1, FALSE, GST_V4L2_CODEC},
181 {V4L2_PIX_FMT_MPEG2, FALSE, GST_V4L2_CODEC},
182 {V4L2_PIX_FMT_MPEG4, FALSE, GST_V4L2_CODEC},
183 {V4L2_PIX_FMT_XVID, FALSE, GST_V4L2_CODEC},
184 {V4L2_PIX_FMT_VC1_ANNEX_G, FALSE, GST_V4L2_CODEC},
185 {V4L2_PIX_FMT_VC1_ANNEX_L, FALSE, GST_V4L2_CODEC},
186 {V4L2_PIX_FMT_VP8, FALSE, GST_V4L2_CODEC | GST_V4L2_NO_PARSE},
187 {V4L2_PIX_FMT_VP9, FALSE, GST_V4L2_CODEC | GST_V4L2_NO_PARSE},
189 /* Vendor-specific formats */
190 {V4L2_PIX_FMT_WNVA, TRUE, GST_V4L2_CODEC},
191 {V4L2_PIX_FMT_SN9C10X, TRUE, GST_V4L2_CODEC},
192 {V4L2_PIX_FMT_PWC1, TRUE, GST_V4L2_CODEC},
193 {V4L2_PIX_FMT_PWC2, TRUE, GST_V4L2_CODEC},
196 #define GST_V4L2_FORMAT_COUNT (G_N_ELEMENTS (gst_v4l2_formats))
198 static GSList *gst_v4l2_object_get_format_list (GstV4l2Object * v4l2object);
201 #define GST_TYPE_V4L2_DEVICE_FLAGS (gst_v4l2_device_get_type ())
203 gst_v4l2_device_get_type (void)
205 static GType v4l2_device_type = 0;
207 if (v4l2_device_type == 0) {
208 static const GFlagsValue values[] = {
209 {V4L2_CAP_VIDEO_CAPTURE, "Device supports video capture", "capture"},
210 {V4L2_CAP_VIDEO_OUTPUT, "Device supports video playback", "output"},
211 {V4L2_CAP_VIDEO_OVERLAY, "Device supports video overlay", "overlay"},
213 {V4L2_CAP_VBI_CAPTURE, "Device supports the VBI capture", "vbi-capture"},
214 {V4L2_CAP_VBI_OUTPUT, "Device supports the VBI output", "vbi-output"},
216 {V4L2_CAP_TUNER, "Device has a tuner or modulator", "tuner"},
217 {V4L2_CAP_AUDIO, "Device has audio inputs or outputs", "audio"},
223 g_flags_register_static ("GstV4l2DeviceTypeFlags", values);
226 return v4l2_device_type;
229 #define GST_TYPE_V4L2_TV_NORM (gst_v4l2_tv_norm_get_type ())
231 gst_v4l2_tv_norm_get_type (void)
233 static GType v4l2_tv_norm = 0;
236 static const GEnumValue tv_norms[] = {
239 {V4L2_STD_NTSC, "NTSC", "NTSC"},
240 {V4L2_STD_NTSC_M, "NTSC-M", "NTSC-M"},
241 {V4L2_STD_NTSC_M_JP, "NTSC-M-JP", "NTSC-M-JP"},
242 {V4L2_STD_NTSC_M_KR, "NTSC-M-KR", "NTSC-M-KR"},
243 {V4L2_STD_NTSC_443, "NTSC-443", "NTSC-443"},
245 {V4L2_STD_PAL, "PAL", "PAL"},
246 {V4L2_STD_PAL_BG, "PAL-BG", "PAL-BG"},
247 {V4L2_STD_PAL_B, "PAL-B", "PAL-B"},
248 {V4L2_STD_PAL_B1, "PAL-B1", "PAL-B1"},
249 {V4L2_STD_PAL_G, "PAL-G", "PAL-G"},
250 {V4L2_STD_PAL_H, "PAL-H", "PAL-H"},
251 {V4L2_STD_PAL_I, "PAL-I", "PAL-I"},
252 {V4L2_STD_PAL_DK, "PAL-DK", "PAL-DK"},
253 {V4L2_STD_PAL_D, "PAL-D", "PAL-D"},
254 {V4L2_STD_PAL_D1, "PAL-D1", "PAL-D1"},
255 {V4L2_STD_PAL_K, "PAL-K", "PAL-K"},
256 {V4L2_STD_PAL_M, "PAL-M", "PAL-M"},
257 {V4L2_STD_PAL_N, "PAL-N", "PAL-N"},
258 {V4L2_STD_PAL_Nc, "PAL-Nc", "PAL-Nc"},
259 {V4L2_STD_PAL_60, "PAL-60", "PAL-60"},
261 {V4L2_STD_SECAM, "SECAM", "SECAM"},
262 {V4L2_STD_SECAM_B, "SECAM-B", "SECAM-B"},
263 {V4L2_STD_SECAM_G, "SECAM-G", "SECAM-G"},
264 {V4L2_STD_SECAM_H, "SECAM-H", "SECAM-H"},
265 {V4L2_STD_SECAM_DK, "SECAM-DK", "SECAM-DK"},
266 {V4L2_STD_SECAM_D, "SECAM-D", "SECAM-D"},
267 {V4L2_STD_SECAM_K, "SECAM-K", "SECAM-K"},
268 {V4L2_STD_SECAM_K1, "SECAM-K1", "SECAM-K1"},
269 {V4L2_STD_SECAM_L, "SECAM-L", "SECAM-L"},
270 {V4L2_STD_SECAM_LC, "SECAM-Lc", "SECAM-Lc"},
275 v4l2_tv_norm = g_enum_register_static ("V4L2_TV_norms", tv_norms);
282 gst_v4l2_io_mode_get_type (void)
284 static GType v4l2_io_mode = 0;
287 static const GEnumValue io_modes[] = {
288 {GST_V4L2_IO_AUTO, "GST_V4L2_IO_AUTO", "auto"},
289 {GST_V4L2_IO_RW, "GST_V4L2_IO_RW", "rw"},
290 {GST_V4L2_IO_MMAP, "GST_V4L2_IO_MMAP", "mmap"},
291 {GST_V4L2_IO_USERPTR, "GST_V4L2_IO_USERPTR", "userptr"},
292 {GST_V4L2_IO_DMABUF, "GST_V4L2_IO_DMABUF", "dmabuf"},
293 {GST_V4L2_IO_DMABUF_IMPORT, "GST_V4L2_IO_DMABUF_IMPORT",
298 v4l2_io_mode = g_enum_register_static ("GstV4l2IOMode", io_modes);
304 gst_v4l2_object_install_properties_helper (GObjectClass * gobject_class,
305 const char *default_device)
307 g_object_class_install_property (gobject_class, PROP_DEVICE,
308 g_param_spec_string ("device", "Device", "Device location",
309 default_device, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
310 g_object_class_install_property (gobject_class, PROP_DEVICE_NAME,
311 g_param_spec_string ("device-name", "Device name",
312 "Name of the device", DEFAULT_PROP_DEVICE_NAME,
313 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
314 g_object_class_install_property (gobject_class, PROP_DEVICE_FD,
315 g_param_spec_int ("device-fd", "File descriptor",
316 "File descriptor of the device", -1, G_MAXINT, DEFAULT_PROP_DEVICE_FD,
317 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
318 g_object_class_install_property (gobject_class, PROP_FLAGS,
319 g_param_spec_flags ("flags", "Flags", "Device type flags",
320 GST_TYPE_V4L2_DEVICE_FLAGS, DEFAULT_PROP_FLAGS,
321 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
324 * GstV4l2Src:brightness:
326 * Picture brightness, or more precisely, the black level
328 g_object_class_install_property (gobject_class, PROP_BRIGHTNESS,
329 g_param_spec_int ("brightness", "Brightness",
330 "Picture brightness, or more precisely, the black level", G_MININT,
332 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
334 * GstV4l2Src:contrast:
336 * Picture contrast or luma gain
338 g_object_class_install_property (gobject_class, PROP_CONTRAST,
339 g_param_spec_int ("contrast", "Contrast",
340 "Picture contrast or luma gain", G_MININT,
342 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
344 * GstV4l2Src:saturation:
346 * Picture color saturation or chroma gain
348 g_object_class_install_property (gobject_class, PROP_SATURATION,
349 g_param_spec_int ("saturation", "Saturation",
350 "Picture color saturation or chroma gain", G_MININT,
352 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
356 * Hue or color balance
358 g_object_class_install_property (gobject_class, PROP_HUE,
359 g_param_spec_int ("hue", "Hue",
360 "Hue or color balance", G_MININT,
362 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
369 g_object_class_install_property (gobject_class, PROP_TV_NORM,
370 g_param_spec_enum ("norm", "TV norm",
372 GST_TYPE_V4L2_TV_NORM, DEFAULT_PROP_TV_NORM,
373 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
376 * GstV4l2Src:io-mode:
380 g_object_class_install_property (gobject_class, PROP_IO_MODE,
381 g_param_spec_enum ("io-mode", "IO mode",
383 GST_TYPE_V4L2_IO_MODE, DEFAULT_PROP_IO_MODE,
384 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
387 * GstV4l2Src:extra-controls:
389 * Additional v4l2 controls for the device. The controls are identified
390 * by the control name (lowercase with '_' for any non-alphanumeric
395 g_object_class_install_property (gobject_class, PROP_EXTRA_CONTROLS,
396 g_param_spec_boxed ("extra-controls", "Extra Controls",
397 "Extra v4l2 controls (CIDs) for the device",
398 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
401 * GstV4l2Src:pixel-aspect-ratio:
403 * The pixel aspect ratio of the device. This overwrites the pixel aspect
404 * ratio queried from the device.
408 g_object_class_install_property (gobject_class, PROP_PIXEL_ASPECT_RATIO,
409 g_param_spec_string ("pixel-aspect-ratio", "Pixel Aspect Ratio",
410 "Overwrite the pixel aspect ratio of the device", "1/1",
411 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
414 * GstV4l2Src:force-aspect-ratio:
416 * When enabled, the pixel aspect ratio queried from the device or set
417 * with the pixel-aspect-ratio property will be enforced.
421 g_object_class_install_property (gobject_class, PROP_FORCE_ASPECT_RATIO,
422 g_param_spec_boolean ("force-aspect-ratio", "Force aspect ratio",
423 "When enabled, the pixel aspect ratio will be enforced", TRUE,
424 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
429 gst_v4l2_object_install_m2m_properties_helper (GObjectClass * gobject_class)
431 g_object_class_install_property (gobject_class, PROP_DEVICE,
432 g_param_spec_string ("device", "Device", "Device location",
433 NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
435 g_object_class_install_property (gobject_class, PROP_DEVICE_NAME,
436 g_param_spec_string ("device-name", "Device name",
437 "Name of the device", DEFAULT_PROP_DEVICE_NAME,
438 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
440 g_object_class_install_property (gobject_class, PROP_DEVICE_FD,
441 g_param_spec_int ("device-fd", "File descriptor",
442 "File descriptor of the device", -1, G_MAXINT, DEFAULT_PROP_DEVICE_FD,
443 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
445 g_object_class_install_property (gobject_class, PROP_OUTPUT_IO_MODE,
446 g_param_spec_enum ("output-io-mode", "Output IO mode",
447 "Output side I/O mode (matches sink pad)",
448 GST_TYPE_V4L2_IO_MODE, DEFAULT_PROP_IO_MODE,
449 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
451 g_object_class_install_property (gobject_class, PROP_CAPTURE_IO_MODE,
452 g_param_spec_enum ("capture-io-mode", "Capture IO mode",
453 "Capture I/O mode (matches src pad)",
454 GST_TYPE_V4L2_IO_MODE, DEFAULT_PROP_IO_MODE,
455 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
457 g_object_class_install_property (gobject_class, PROP_EXTRA_CONTROLS,
458 g_param_spec_boxed ("extra-controls", "Extra Controls",
459 "Extra v4l2 controls (CIDs) for the device",
460 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
464 gst_v4l2_object_new (GstElement * element,
465 GstObject * debug_object,
466 enum v4l2_buf_type type,
467 const char *default_device,
468 GstV4l2GetInOutFunction get_in_out_func,
469 GstV4l2SetInOutFunction set_in_out_func,
470 GstV4l2UpdateFpsFunction update_fps_func)
472 GstV4l2Object *v4l2object;
475 * some default values
477 v4l2object = g_new0 (GstV4l2Object, 1);
479 v4l2object->type = type;
480 v4l2object->formats = NULL;
482 v4l2object->element = element;
483 v4l2object->dbg_obj = debug_object;
484 v4l2object->get_in_out_func = get_in_out_func;
485 v4l2object->set_in_out_func = set_in_out_func;
486 v4l2object->update_fps_func = update_fps_func;
488 v4l2object->video_fd = -1;
489 v4l2object->active = FALSE;
490 v4l2object->videodev = g_strdup (default_device);
492 v4l2object->norms = NULL;
493 v4l2object->channels = NULL;
494 v4l2object->colors = NULL;
496 v4l2object->keep_aspect = TRUE;
498 v4l2object->n_v4l2_planes = 0;
500 v4l2object->no_initial_format = FALSE;
502 /* We now disable libv4l2 by default, but have an env to enable it. */
504 if (g_getenv ("GST_V4L2_USE_LIBV4L2")) {
505 v4l2object->fd_open = v4l2_fd_open;
506 v4l2object->close = v4l2_close;
507 v4l2object->dup = v4l2_dup;
508 v4l2object->ioctl = v4l2_ioctl;
509 v4l2object->read = v4l2_read;
510 v4l2object->mmap = v4l2_mmap;
511 v4l2object->munmap = v4l2_munmap;
515 v4l2object->fd_open = NULL;
516 v4l2object->close = close;
517 v4l2object->dup = dup;
518 v4l2object->ioctl = ioctl;
519 v4l2object->read = read;
520 v4l2object->mmap = mmap;
521 v4l2object->munmap = munmap;
527 static gboolean gst_v4l2_object_clear_format_list (GstV4l2Object * v4l2object);
531 gst_v4l2_object_destroy (GstV4l2Object * v4l2object)
533 g_return_if_fail (v4l2object != NULL);
535 g_free (v4l2object->videodev);
537 g_free (v4l2object->channel);
539 if (v4l2object->formats) {
540 gst_v4l2_object_clear_format_list (v4l2object);
543 if (v4l2object->probed_caps) {
544 gst_caps_unref (v4l2object->probed_caps);
547 if (v4l2object->extra_controls) {
548 gst_structure_free (v4l2object->extra_controls);
556 gst_v4l2_object_clear_format_list (GstV4l2Object * v4l2object)
558 g_slist_foreach (v4l2object->formats, (GFunc) g_free, NULL);
559 g_slist_free (v4l2object->formats);
560 v4l2object->formats = NULL;
566 gst_v4l2_object_prop_to_cid (guint prop_id)
571 case PROP_BRIGHTNESS:
572 cid = V4L2_CID_BRIGHTNESS;
575 cid = V4L2_CID_CONTRAST;
577 case PROP_SATURATION:
578 cid = V4L2_CID_SATURATION;
584 GST_WARNING ("unmapped property id: %d", prop_id);
591 gst_v4l2_object_set_property_helper (GstV4l2Object * v4l2object,
592 guint prop_id, const GValue * value, GParamSpec * pspec)
596 g_free (v4l2object->videodev);
597 v4l2object->videodev = g_value_dup_string (value);
599 case PROP_BRIGHTNESS:
601 case PROP_SATURATION:
604 gint cid = gst_v4l2_object_prop_to_cid (prop_id);
607 if (GST_V4L2_IS_OPEN (v4l2object)) {
608 gst_v4l2_set_attribute (v4l2object, cid, g_value_get_int (value));
615 v4l2object->tv_norm = g_value_get_enum (value);
619 if (GST_V4L2_IS_OPEN (v4l2object)) {
620 GstTuner *tuner = GST_TUNER (v4l2object->element);
621 GstTunerChannel *channel = gst_tuner_find_channel_by_name (tuner,
622 (gchar *) g_value_get_string (value));
625 /* like gst_tuner_set_channel (tuner, channel)
626 without g_object_notify */
627 gst_v4l2_tuner_set_channel (v4l2object, channel);
630 g_free (v4l2object->channel);
631 v4l2object->channel = g_value_dup_string (value);
635 if (GST_V4L2_IS_OPEN (v4l2object)) {
636 GstTuner *tuner = GST_TUNER (v4l2object->element);
637 GstTunerChannel *channel = gst_tuner_get_channel (tuner);
640 GST_TUNER_CHANNEL_HAS_FLAG (channel, GST_TUNER_CHANNEL_FREQUENCY)) {
642 gst_tuner_set_frequency (tuner, channel, g_value_get_ulong (value))
643 without g_object_notify */
644 gst_v4l2_tuner_set_frequency (v4l2object, channel,
645 g_value_get_ulong (value));
648 v4l2object->frequency = g_value_get_ulong (value);
654 v4l2object->req_mode = g_value_get_enum (value);
656 case PROP_CAPTURE_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_OUTPUT_IO_MODE:
661 g_return_val_if_fail (V4L2_TYPE_IS_OUTPUT (v4l2object->type), FALSE);
662 v4l2object->req_mode = g_value_get_enum (value);
664 case PROP_EXTRA_CONTROLS:{
665 const GstStructure *s = gst_value_get_structure (value);
667 if (v4l2object->extra_controls)
668 gst_structure_free (v4l2object->extra_controls);
670 v4l2object->extra_controls = s ? gst_structure_copy (s) : NULL;
671 if (GST_V4L2_IS_OPEN (v4l2object))
672 gst_v4l2_set_controls (v4l2object, v4l2object->extra_controls);
675 case PROP_PIXEL_ASPECT_RATIO:
676 if (v4l2object->par) {
677 g_value_unset (v4l2object->par);
678 g_free (v4l2object->par);
680 v4l2object->par = g_new0 (GValue, 1);
681 g_value_init (v4l2object->par, GST_TYPE_FRACTION);
682 if (!g_value_transform (value, v4l2object->par)) {
683 g_warning ("Could not transform string to aspect ratio");
684 gst_value_set_fraction (v4l2object->par, 1, 1);
687 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "set PAR to %d/%d",
688 gst_value_get_fraction_numerator (v4l2object->par),
689 gst_value_get_fraction_denominator (v4l2object->par));
691 case PROP_FORCE_ASPECT_RATIO:
692 v4l2object->keep_aspect = g_value_get_boolean (value);
703 gst_v4l2_object_get_property_helper (GstV4l2Object * v4l2object,
704 guint prop_id, GValue * value, GParamSpec * pspec)
708 g_value_set_string (value, v4l2object->videodev);
710 case PROP_DEVICE_NAME:
712 const guchar *new = NULL;
714 if (GST_V4L2_IS_OPEN (v4l2object)) {
715 new = v4l2object->vcap.card;
716 } else if (gst_v4l2_open (v4l2object)) {
717 new = v4l2object->vcap.card;
718 gst_v4l2_close (v4l2object);
720 g_value_set_string (value, (gchar *) new);
725 if (GST_V4L2_IS_OPEN (v4l2object))
726 g_value_set_int (value, v4l2object->video_fd);
728 g_value_set_int (value, DEFAULT_PROP_DEVICE_FD);
735 if (GST_V4L2_IS_OPEN (v4l2object)) {
736 flags |= v4l2object->device_caps &
737 (V4L2_CAP_VIDEO_CAPTURE |
738 V4L2_CAP_VIDEO_OUTPUT |
739 V4L2_CAP_VIDEO_OVERLAY |
740 V4L2_CAP_VBI_CAPTURE |
741 V4L2_CAP_VBI_OUTPUT | V4L2_CAP_TUNER | V4L2_CAP_AUDIO);
743 if (v4l2object->device_caps & V4L2_CAP_VIDEO_CAPTURE_MPLANE)
744 flags |= V4L2_CAP_VIDEO_CAPTURE;
746 if (v4l2object->device_caps & V4L2_CAP_VIDEO_OUTPUT_MPLANE)
747 flags |= V4L2_CAP_VIDEO_OUTPUT;
749 g_value_set_flags (value, flags);
752 case PROP_BRIGHTNESS:
754 case PROP_SATURATION:
757 gint cid = gst_v4l2_object_prop_to_cid (prop_id);
760 if (GST_V4L2_IS_OPEN (v4l2object)) {
762 if (gst_v4l2_get_attribute (v4l2object, cid, &v)) {
763 g_value_set_int (value, v);
771 g_value_set_enum (value, v4l2object->tv_norm);
774 g_value_set_enum (value, v4l2object->req_mode);
776 case PROP_CAPTURE_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_OUTPUT_IO_MODE:
781 g_return_val_if_fail (V4L2_TYPE_IS_OUTPUT (v4l2object->type), FALSE);
782 g_value_set_enum (value, v4l2object->req_mode);
784 case PROP_EXTRA_CONTROLS:
785 gst_value_set_structure (value, v4l2object->extra_controls);
787 case PROP_PIXEL_ASPECT_RATIO:
789 g_value_transform (v4l2object->par, value);
791 case PROP_FORCE_ASPECT_RATIO:
792 g_value_set_boolean (value, v4l2object->keep_aspect);
802 gst_v4l2_get_driver_min_buffers (GstV4l2Object * v4l2object)
804 struct v4l2_control control = { 0, };
806 g_return_if_fail (GST_V4L2_IS_OPEN (v4l2object));
808 if (V4L2_TYPE_IS_OUTPUT (v4l2object->type))
809 control.id = V4L2_CID_MIN_BUFFERS_FOR_OUTPUT;
811 control.id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE;
813 if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_G_CTRL, &control) == 0) {
814 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
815 "driver requires a minimum of %d buffers", control.value);
816 v4l2object->min_buffers = control.value;
818 v4l2object->min_buffers = 0;
823 gst_v4l2_set_defaults (GstV4l2Object * v4l2object)
825 GstTunerNorm *norm = NULL;
826 GstTunerChannel *channel = NULL;
829 if (!GST_IS_TUNER (v4l2object->element))
832 tuner = GST_TUNER (v4l2object->element);
834 if (v4l2object->tv_norm)
835 norm = gst_v4l2_tuner_get_norm_by_std_id (v4l2object, v4l2object->tv_norm);
836 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "tv_norm=0x%" G_GINT64_MODIFIER "x, "
837 "norm=%p", (guint64) v4l2object->tv_norm, norm);
839 gst_tuner_set_norm (tuner, norm);
842 GST_TUNER_NORM (gst_tuner_get_norm (GST_TUNER (v4l2object->element)));
844 v4l2object->tv_norm =
845 gst_v4l2_tuner_get_std_id_by_norm (v4l2object, norm);
846 gst_tuner_norm_changed (tuner, norm);
850 if (v4l2object->channel)
851 channel = gst_tuner_find_channel_by_name (tuner, v4l2object->channel);
853 gst_tuner_set_channel (tuner, channel);
856 GST_TUNER_CHANNEL (gst_tuner_get_channel (GST_TUNER
857 (v4l2object->element)));
859 g_free (v4l2object->channel);
860 v4l2object->channel = g_strdup (channel->label);
861 gst_tuner_channel_changed (tuner, channel);
866 && GST_TUNER_CHANNEL_HAS_FLAG (channel, GST_TUNER_CHANNEL_FREQUENCY)) {
867 if (v4l2object->frequency != 0) {
868 gst_tuner_set_frequency (tuner, channel, v4l2object->frequency);
870 v4l2object->frequency = gst_tuner_get_frequency (tuner, channel);
871 if (v4l2object->frequency == 0) {
873 gst_tuner_set_frequency (tuner, channel, 1000);
881 gst_v4l2_object_open (GstV4l2Object * v4l2object)
883 if (gst_v4l2_open (v4l2object))
884 gst_v4l2_set_defaults (v4l2object);
892 gst_v4l2_object_open_shared (GstV4l2Object * v4l2object, GstV4l2Object * other)
896 ret = gst_v4l2_dup (v4l2object, other);
902 gst_v4l2_object_close (GstV4l2Object * v4l2object)
904 if (!gst_v4l2_close (v4l2object))
907 gst_caps_replace (&v4l2object->probed_caps, NULL);
909 /* reset our copy of the device caps */
910 v4l2object->device_caps = 0;
912 if (v4l2object->formats) {
913 gst_v4l2_object_clear_format_list (v4l2object);
916 if (v4l2object->par) {
917 g_value_unset (v4l2object->par);
918 g_free (v4l2object->par);
919 v4l2object->par = NULL;
925 static struct v4l2_fmtdesc *
926 gst_v4l2_object_get_format_from_fourcc (GstV4l2Object * v4l2object,
929 struct v4l2_fmtdesc *fmt;
935 walk = gst_v4l2_object_get_format_list (v4l2object);
937 fmt = (struct v4l2_fmtdesc *) walk->data;
938 if (fmt->pixelformat == fourcc)
940 /* special case for jpeg */
941 if (fmt->pixelformat == V4L2_PIX_FMT_MJPEG ||
942 fmt->pixelformat == V4L2_PIX_FMT_JPEG ||
943 fmt->pixelformat == V4L2_PIX_FMT_PJPG) {
944 if (fourcc == V4L2_PIX_FMT_JPEG || fourcc == V4L2_PIX_FMT_MJPEG ||
945 fourcc == V4L2_PIX_FMT_PJPG) {
949 walk = g_slist_next (walk);
957 /* complete made up ranking, the values themselves are meaningless */
958 /* These ranks MUST be X such that X<<15 fits on a signed int - see
959 the comment at the end of gst_v4l2_object_format_get_rank. */
960 #define YUV_BASE_RANK 1000
961 #define JPEG_BASE_RANK 500
962 #define DV_BASE_RANK 200
963 #define RGB_BASE_RANK 100
964 #define YUV_ODD_BASE_RANK 50
965 #define RGB_ODD_BASE_RANK 25
966 #define BAYER_BASE_RANK 15
967 #define S910_BASE_RANK 10
968 #define GREY_BASE_RANK 5
969 #define PWC_BASE_RANK 1
972 gst_v4l2_object_format_get_rank (const struct v4l2_fmtdesc *fmt)
974 guint32 fourcc = fmt->pixelformat;
975 gboolean emulated = ((fmt->flags & V4L2_FMT_FLAG_EMULATED) != 0);
979 case V4L2_PIX_FMT_MJPEG:
980 case V4L2_PIX_FMT_PJPG:
981 rank = JPEG_BASE_RANK;
983 case V4L2_PIX_FMT_JPEG:
984 rank = JPEG_BASE_RANK + 1;
986 case V4L2_PIX_FMT_MPEG: /* MPEG */
987 rank = JPEG_BASE_RANK + 2;
990 case V4L2_PIX_FMT_RGB332:
991 case V4L2_PIX_FMT_ARGB555:
992 case V4L2_PIX_FMT_XRGB555:
993 case V4L2_PIX_FMT_RGB555:
994 case V4L2_PIX_FMT_ARGB555X:
995 case V4L2_PIX_FMT_XRGB555X:
996 case V4L2_PIX_FMT_RGB555X:
997 case V4L2_PIX_FMT_BGR666:
998 case V4L2_PIX_FMT_RGB565:
999 case V4L2_PIX_FMT_RGB565X:
1000 case V4L2_PIX_FMT_RGB444:
1001 case V4L2_PIX_FMT_Y4:
1002 case V4L2_PIX_FMT_Y6:
1003 case V4L2_PIX_FMT_Y10:
1004 case V4L2_PIX_FMT_Y12:
1005 case V4L2_PIX_FMT_Y10BPACK:
1006 case V4L2_PIX_FMT_YUV555:
1007 case V4L2_PIX_FMT_YUV565:
1008 case V4L2_PIX_FMT_YUV32:
1009 case V4L2_PIX_FMT_NV12MT_16X16:
1010 case V4L2_PIX_FMT_NV42:
1011 case V4L2_PIX_FMT_H264_MVC:
1012 rank = RGB_ODD_BASE_RANK;
1015 case V4L2_PIX_FMT_RGB24:
1016 case V4L2_PIX_FMT_BGR24:
1017 rank = RGB_BASE_RANK - 1;
1020 case V4L2_PIX_FMT_RGB32:
1021 case V4L2_PIX_FMT_BGR32:
1022 case V4L2_PIX_FMT_ABGR32:
1023 case V4L2_PIX_FMT_XBGR32:
1024 case V4L2_PIX_FMT_ARGB32:
1025 case V4L2_PIX_FMT_XRGB32:
1026 rank = RGB_BASE_RANK;
1029 case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
1030 rank = GREY_BASE_RANK;
1033 case V4L2_PIX_FMT_NV12: /* 12 Y/CbCr 4:2:0 */
1034 case V4L2_PIX_FMT_NV12M: /* Same as NV12 */
1035 case V4L2_PIX_FMT_NV12MT: /* NV12 64x32 tile */
1036 case V4L2_PIX_FMT_NV21: /* 12 Y/CrCb 4:2:0 */
1037 case V4L2_PIX_FMT_NV21M: /* Same as NV21 */
1038 case V4L2_PIX_FMT_YYUV: /* 16 YUV 4:2:2 */
1039 case V4L2_PIX_FMT_HI240: /* 8 8-bit color */
1040 case V4L2_PIX_FMT_NV16: /* 16 Y/CbCr 4:2:2 */
1041 case V4L2_PIX_FMT_NV16M: /* Same as NV16 */
1042 case V4L2_PIX_FMT_NV61: /* 16 Y/CrCb 4:2:2 */
1043 case V4L2_PIX_FMT_NV61M: /* Same as NV61 */
1044 case V4L2_PIX_FMT_NV24: /* 24 Y/CrCb 4:4:4 */
1045 rank = YUV_ODD_BASE_RANK;
1048 case V4L2_PIX_FMT_YVU410: /* YVU9, 9 bits per pixel */
1049 rank = YUV_BASE_RANK + 3;
1051 case V4L2_PIX_FMT_YUV410: /* YUV9, 9 bits per pixel */
1052 rank = YUV_BASE_RANK + 2;
1054 case V4L2_PIX_FMT_YUV420: /* I420, 12 bits per pixel */
1055 case V4L2_PIX_FMT_YUV420M:
1056 rank = YUV_BASE_RANK + 7;
1058 case V4L2_PIX_FMT_YUYV: /* YUY2, 16 bits per pixel */
1059 rank = YUV_BASE_RANK + 10;
1061 case V4L2_PIX_FMT_YVU420: /* YV12, 12 bits per pixel */
1062 rank = YUV_BASE_RANK + 6;
1064 case V4L2_PIX_FMT_UYVY: /* UYVY, 16 bits per pixel */
1065 rank = YUV_BASE_RANK + 9;
1067 case V4L2_PIX_FMT_YUV444:
1068 rank = YUV_BASE_RANK + 6;
1070 case V4L2_PIX_FMT_Y41P: /* Y41P, 12 bits per pixel */
1071 rank = YUV_BASE_RANK + 5;
1073 case V4L2_PIX_FMT_YUV411P: /* Y41B, 12 bits per pixel */
1074 rank = YUV_BASE_RANK + 4;
1076 case V4L2_PIX_FMT_YUV422P: /* Y42B, 16 bits per pixel */
1077 rank = YUV_BASE_RANK + 8;
1080 case V4L2_PIX_FMT_DV:
1081 rank = DV_BASE_RANK;
1084 case V4L2_PIX_FMT_WNVA: /* Winnov hw compres */
1088 case V4L2_PIX_FMT_SBGGR8:
1089 case V4L2_PIX_FMT_SGBRG8:
1090 case V4L2_PIX_FMT_SGRBG8:
1091 case V4L2_PIX_FMT_SRGGB8:
1092 rank = BAYER_BASE_RANK;
1095 case V4L2_PIX_FMT_SN9C10X:
1096 rank = S910_BASE_RANK;
1099 case V4L2_PIX_FMT_PWC1:
1100 rank = PWC_BASE_RANK;
1102 case V4L2_PIX_FMT_PWC2:
1103 rank = PWC_BASE_RANK;
1111 /* All ranks are below 1<<15 so a shift by 15
1112 * will a) make all non-emulated formats larger
1113 * than emulated and b) will not overflow
1124 format_cmp_func (gconstpointer a, gconstpointer b)
1126 const struct v4l2_fmtdesc *fa = a;
1127 const struct v4l2_fmtdesc *fb = b;
1129 if (fa->pixelformat == fb->pixelformat)
1132 return gst_v4l2_object_format_get_rank (fb) -
1133 gst_v4l2_object_format_get_rank (fa);
1136 /******************************************************
1137 * gst_v4l2_object_fill_format_list():
1138 * create list of supported capture formats
1139 * return value: TRUE on success, FALSE on error
1140 ******************************************************/
1142 gst_v4l2_object_fill_format_list (GstV4l2Object * v4l2object,
1143 enum v4l2_buf_type type)
1146 struct v4l2_fmtdesc *format;
1148 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "getting src format enumerations");
1150 /* format enumeration */
1152 format = g_new0 (struct v4l2_fmtdesc, 1);
1155 format->type = type;
1157 if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_ENUM_FMT, format) < 0) {
1158 if (errno == EINVAL) {
1160 break; /* end of enumeration */
1166 GST_LOG_OBJECT (v4l2object->dbg_obj, "index: %u", format->index);
1167 GST_LOG_OBJECT (v4l2object->dbg_obj, "type: %d", format->type);
1168 GST_LOG_OBJECT (v4l2object->dbg_obj, "flags: %08x", format->flags);
1169 GST_LOG_OBJECT (v4l2object->dbg_obj, "description: '%s'",
1170 format->description);
1171 GST_LOG_OBJECT (v4l2object->dbg_obj, "pixelformat: %" GST_FOURCC_FORMAT,
1172 GST_FOURCC_ARGS (format->pixelformat));
1174 /* sort formats according to our preference; we do this, because caps
1175 * are probed in the order the formats are in the list, and the order of
1176 * formats in the final probed caps matters for things like fixation */
1177 v4l2object->formats = g_slist_insert_sorted (v4l2object->formats, format,
1178 (GCompareFunc) format_cmp_func);
1181 #ifndef GST_DISABLE_GST_DEBUG
1185 GST_INFO_OBJECT (v4l2object->dbg_obj, "got %d format(s):", n);
1186 for (l = v4l2object->formats; l != NULL; l = l->next) {
1189 GST_INFO_OBJECT (v4l2object->dbg_obj,
1190 " %" GST_FOURCC_FORMAT "%s", GST_FOURCC_ARGS (format->pixelformat),
1191 ((format->flags & V4L2_FMT_FLAG_EMULATED)) ? " (emulated)" : "");
1203 if (v4l2object->element)
1206 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
1207 (_("Failed to enumerate possible video formats device '%s' can work "
1208 "with"), v4l2object->videodev),
1209 ("Failed to get number %d in pixelformat enumeration for %s. (%d - %s)",
1210 n, v4l2object->videodev, errno, g_strerror (errno)));
1217 * Get the list of supported capture formats, a list of
1218 * <code>struct v4l2_fmtdesc</code>.
1221 gst_v4l2_object_get_format_list (GstV4l2Object * v4l2object)
1223 if (!v4l2object->formats) {
1225 /* check usual way */
1226 gst_v4l2_object_fill_format_list (v4l2object, v4l2object->type);
1228 /* if our driver supports multi-planar
1229 * and if formats are still empty then we can workaround driver bug
1230 * by also looking up formats as if our device was not supporting
1232 if (!v4l2object->formats) {
1233 switch (v4l2object->type) {
1234 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1235 gst_v4l2_object_fill_format_list (v4l2object,
1236 V4L2_BUF_TYPE_VIDEO_CAPTURE);
1239 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1240 gst_v4l2_object_fill_format_list (v4l2object,
1241 V4L2_BUF_TYPE_VIDEO_OUTPUT);
1249 return v4l2object->formats;
1252 static GstVideoFormat
1253 gst_v4l2_object_v4l2fourcc_to_video_format (guint32 fourcc)
1255 GstVideoFormat format;
1258 case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
1259 format = GST_VIDEO_FORMAT_GRAY8;
1261 case V4L2_PIX_FMT_Y16:
1262 format = GST_VIDEO_FORMAT_GRAY16_LE;
1264 case V4L2_PIX_FMT_Y16_BE:
1265 format = GST_VIDEO_FORMAT_GRAY16_BE;
1267 case V4L2_PIX_FMT_XRGB555:
1268 case V4L2_PIX_FMT_RGB555:
1269 format = GST_VIDEO_FORMAT_RGB15;
1271 case V4L2_PIX_FMT_XRGB555X:
1272 case V4L2_PIX_FMT_RGB555X:
1273 format = GST_VIDEO_FORMAT_BGR15;
1275 case V4L2_PIX_FMT_RGB565:
1276 format = GST_VIDEO_FORMAT_RGB16;
1278 case V4L2_PIX_FMT_RGB24:
1279 format = GST_VIDEO_FORMAT_RGB;
1281 case V4L2_PIX_FMT_BGR24:
1282 format = GST_VIDEO_FORMAT_BGR;
1284 case V4L2_PIX_FMT_XRGB32:
1285 case V4L2_PIX_FMT_RGB32:
1286 format = GST_VIDEO_FORMAT_xRGB;
1288 case V4L2_PIX_FMT_XBGR32:
1289 case V4L2_PIX_FMT_BGR32:
1290 format = GST_VIDEO_FORMAT_BGRx;
1292 case V4L2_PIX_FMT_ABGR32:
1293 format = GST_VIDEO_FORMAT_BGRA;
1295 case V4L2_PIX_FMT_ARGB32:
1296 format = GST_VIDEO_FORMAT_ARGB;
1298 case V4L2_PIX_FMT_NV12:
1299 case V4L2_PIX_FMT_NV12M:
1300 format = GST_VIDEO_FORMAT_NV12;
1302 case V4L2_PIX_FMT_NV12MT:
1303 format = GST_VIDEO_FORMAT_NV12_64Z32;
1305 case V4L2_PIX_FMT_NV21:
1306 case V4L2_PIX_FMT_NV21M:
1307 format = GST_VIDEO_FORMAT_NV21;
1309 case V4L2_PIX_FMT_YVU410:
1310 format = GST_VIDEO_FORMAT_YVU9;
1312 case V4L2_PIX_FMT_YUV410:
1313 format = GST_VIDEO_FORMAT_YUV9;
1315 case V4L2_PIX_FMT_YUV420:
1316 case V4L2_PIX_FMT_YUV420M:
1317 format = GST_VIDEO_FORMAT_I420;
1319 case V4L2_PIX_FMT_YUYV:
1320 format = GST_VIDEO_FORMAT_YUY2;
1322 case V4L2_PIX_FMT_YVU420:
1323 format = GST_VIDEO_FORMAT_YV12;
1325 case V4L2_PIX_FMT_UYVY:
1326 format = GST_VIDEO_FORMAT_UYVY;
1328 case V4L2_PIX_FMT_YUV411P:
1329 format = GST_VIDEO_FORMAT_Y41B;
1331 case V4L2_PIX_FMT_YUV422P:
1332 format = GST_VIDEO_FORMAT_Y42B;
1334 case V4L2_PIX_FMT_YVYU:
1335 format = GST_VIDEO_FORMAT_YVYU;
1337 case V4L2_PIX_FMT_NV16:
1338 case V4L2_PIX_FMT_NV16M:
1339 format = GST_VIDEO_FORMAT_NV16;
1341 case V4L2_PIX_FMT_NV61:
1342 case V4L2_PIX_FMT_NV61M:
1343 format = GST_VIDEO_FORMAT_NV61;
1345 case V4L2_PIX_FMT_NV24:
1346 format = GST_VIDEO_FORMAT_NV24;
1349 format = GST_VIDEO_FORMAT_UNKNOWN;
1357 gst_v4l2_object_v4l2fourcc_is_rgb (guint32 fourcc)
1359 gboolean ret = FALSE;
1362 case V4L2_PIX_FMT_XRGB555:
1363 case V4L2_PIX_FMT_RGB555:
1364 case V4L2_PIX_FMT_XRGB555X:
1365 case V4L2_PIX_FMT_RGB555X:
1366 case V4L2_PIX_FMT_RGB565:
1367 case V4L2_PIX_FMT_RGB24:
1368 case V4L2_PIX_FMT_BGR24:
1369 case V4L2_PIX_FMT_XRGB32:
1370 case V4L2_PIX_FMT_RGB32:
1371 case V4L2_PIX_FMT_XBGR32:
1372 case V4L2_PIX_FMT_BGR32:
1373 case V4L2_PIX_FMT_ABGR32:
1374 case V4L2_PIX_FMT_ARGB32:
1384 static GstStructure *
1385 gst_v4l2_object_v4l2fourcc_to_bare_struct (guint32 fourcc)
1387 GstStructure *structure = NULL;
1390 case V4L2_PIX_FMT_MJPEG: /* Motion-JPEG */
1391 case V4L2_PIX_FMT_PJPG: /* Progressive-JPEG */
1392 case V4L2_PIX_FMT_JPEG: /* JFIF JPEG */
1393 structure = gst_structure_new_empty ("image/jpeg");
1395 case V4L2_PIX_FMT_MPEG1:
1396 structure = gst_structure_new ("video/mpeg",
1397 "mpegversion", G_TYPE_INT, 2, NULL);
1399 case V4L2_PIX_FMT_MPEG2:
1400 structure = gst_structure_new ("video/mpeg",
1401 "mpegversion", G_TYPE_INT, 2, NULL);
1403 case V4L2_PIX_FMT_MPEG4:
1404 case V4L2_PIX_FMT_XVID:
1405 structure = gst_structure_new ("video/mpeg",
1406 "mpegversion", G_TYPE_INT, 4, "systemstream",
1407 G_TYPE_BOOLEAN, FALSE, NULL);
1409 case V4L2_PIX_FMT_H263:
1410 structure = gst_structure_new ("video/x-h263",
1411 "variant", G_TYPE_STRING, "itu", NULL);
1413 case V4L2_PIX_FMT_H264: /* H.264 */
1414 structure = gst_structure_new ("video/x-h264",
1415 "stream-format", G_TYPE_STRING, "byte-stream", "alignment",
1416 G_TYPE_STRING, "au", NULL);
1418 case V4L2_PIX_FMT_H264_NO_SC:
1419 structure = gst_structure_new ("video/x-h264",
1420 "stream-format", G_TYPE_STRING, "avc", "alignment",
1421 G_TYPE_STRING, "au", NULL);
1423 case V4L2_PIX_FMT_VC1_ANNEX_G:
1424 case V4L2_PIX_FMT_VC1_ANNEX_L:
1425 structure = gst_structure_new ("video/x-wmv",
1426 "wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
1428 case V4L2_PIX_FMT_VP8:
1429 structure = gst_structure_new_empty ("video/x-vp8");
1431 case V4L2_PIX_FMT_VP9:
1432 structure = gst_structure_new_empty ("video/x-vp9");
1434 case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
1435 case V4L2_PIX_FMT_Y16:
1436 case V4L2_PIX_FMT_Y16_BE:
1437 case V4L2_PIX_FMT_XRGB555:
1438 case V4L2_PIX_FMT_RGB555:
1439 case V4L2_PIX_FMT_XRGB555X:
1440 case V4L2_PIX_FMT_RGB555X:
1441 case V4L2_PIX_FMT_RGB565:
1442 case V4L2_PIX_FMT_RGB24:
1443 case V4L2_PIX_FMT_BGR24:
1444 case V4L2_PIX_FMT_RGB32:
1445 case V4L2_PIX_FMT_XRGB32:
1446 case V4L2_PIX_FMT_ARGB32:
1447 case V4L2_PIX_FMT_BGR32:
1448 case V4L2_PIX_FMT_XBGR32:
1449 case V4L2_PIX_FMT_ABGR32:
1450 case V4L2_PIX_FMT_NV12: /* 12 Y/CbCr 4:2:0 */
1451 case V4L2_PIX_FMT_NV12M:
1452 case V4L2_PIX_FMT_NV12MT:
1453 case V4L2_PIX_FMT_NV21: /* 12 Y/CrCb 4:2:0 */
1454 case V4L2_PIX_FMT_NV21M:
1455 case V4L2_PIX_FMT_NV16: /* 16 Y/CbCr 4:2:2 */
1456 case V4L2_PIX_FMT_NV16M:
1457 case V4L2_PIX_FMT_NV61: /* 16 Y/CrCb 4:2:2 */
1458 case V4L2_PIX_FMT_NV61M:
1459 case V4L2_PIX_FMT_NV24: /* 24 Y/CrCb 4:4:4 */
1460 case V4L2_PIX_FMT_YVU410:
1461 case V4L2_PIX_FMT_YUV410:
1462 case V4L2_PIX_FMT_YUV420: /* I420/IYUV */
1463 case V4L2_PIX_FMT_YUV420M:
1464 case V4L2_PIX_FMT_YUYV:
1465 case V4L2_PIX_FMT_YVU420:
1466 case V4L2_PIX_FMT_UYVY:
1467 case V4L2_PIX_FMT_YUV422P:
1468 case V4L2_PIX_FMT_YVYU:
1469 case V4L2_PIX_FMT_YUV411P:{
1470 GstVideoFormat format;
1471 format = gst_v4l2_object_v4l2fourcc_to_video_format (fourcc);
1472 if (format != GST_VIDEO_FORMAT_UNKNOWN)
1473 structure = gst_structure_new ("video/x-raw",
1474 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
1477 case V4L2_PIX_FMT_DV:
1479 gst_structure_new ("video/x-dv", "systemstream", G_TYPE_BOOLEAN, TRUE,
1482 case V4L2_PIX_FMT_MPEG: /* MPEG */
1483 structure = gst_structure_new ("video/mpegts",
1484 "systemstream", G_TYPE_BOOLEAN, TRUE, NULL);
1486 case V4L2_PIX_FMT_WNVA: /* Winnov hw compres */
1488 case V4L2_PIX_FMT_SBGGR8:
1489 case V4L2_PIX_FMT_SGBRG8:
1490 case V4L2_PIX_FMT_SGRBG8:
1491 case V4L2_PIX_FMT_SRGGB8:
1492 structure = gst_structure_new ("video/x-bayer", "format", G_TYPE_STRING,
1493 fourcc == V4L2_PIX_FMT_SBGGR8 ? "bggr" :
1494 fourcc == V4L2_PIX_FMT_SGBRG8 ? "gbrg" :
1495 fourcc == V4L2_PIX_FMT_SGRBG8 ? "grbg" :
1496 /* fourcc == V4L2_PIX_FMT_SRGGB8 ? */ "rggb", NULL);
1498 case V4L2_PIX_FMT_SN9C10X:
1499 structure = gst_structure_new_empty ("video/x-sonix");
1501 case V4L2_PIX_FMT_PWC1:
1502 structure = gst_structure_new_empty ("video/x-pwc1");
1504 case V4L2_PIX_FMT_PWC2:
1505 structure = gst_structure_new_empty ("video/x-pwc2");
1507 case V4L2_PIX_FMT_RGB332:
1508 case V4L2_PIX_FMT_BGR666:
1509 case V4L2_PIX_FMT_ARGB555X:
1510 case V4L2_PIX_FMT_RGB565X:
1511 case V4L2_PIX_FMT_RGB444:
1512 case V4L2_PIX_FMT_YYUV: /* 16 YUV 4:2:2 */
1513 case V4L2_PIX_FMT_HI240: /* 8 8-bit color */
1514 case V4L2_PIX_FMT_Y4:
1515 case V4L2_PIX_FMT_Y6:
1516 case V4L2_PIX_FMT_Y10:
1517 case V4L2_PIX_FMT_Y12:
1518 case V4L2_PIX_FMT_Y10BPACK:
1519 case V4L2_PIX_FMT_YUV444:
1520 case V4L2_PIX_FMT_YUV555:
1521 case V4L2_PIX_FMT_YUV565:
1522 case V4L2_PIX_FMT_Y41P:
1523 case V4L2_PIX_FMT_YUV32:
1524 case V4L2_PIX_FMT_NV12MT_16X16:
1525 case V4L2_PIX_FMT_NV42:
1526 case V4L2_PIX_FMT_H264_MVC:
1528 GST_DEBUG ("Unsupported fourcc 0x%08x %" GST_FOURCC_FORMAT,
1529 fourcc, GST_FOURCC_ARGS (fourcc));
1537 gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc)
1539 GstStructure *template;
1542 template = gst_v4l2_object_v4l2fourcc_to_bare_struct (fourcc);
1544 if (template == NULL)
1547 for (i = 0; i < GST_V4L2_FORMAT_COUNT; i++) {
1548 if (gst_v4l2_formats[i].format != fourcc)
1551 if (gst_v4l2_formats[i].dimensions) {
1552 gst_structure_set (template,
1553 "width", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1554 "height", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1555 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
1566 gst_v4l2_object_get_caps_helper (GstV4L2FormatFlags flags)
1568 GstStructure *structure;
1572 caps = gst_caps_new_empty ();
1573 for (i = 0; i < GST_V4L2_FORMAT_COUNT; i++) {
1575 if ((gst_v4l2_formats[i].flags & flags) == 0)
1579 gst_v4l2_object_v4l2fourcc_to_bare_struct (gst_v4l2_formats[i].format);
1582 GstStructure *alt_s = NULL;
1584 if (gst_v4l2_formats[i].dimensions) {
1585 gst_structure_set (structure,
1586 "width", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1587 "height", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1588 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
1591 switch (gst_v4l2_formats[i].format) {
1592 case V4L2_PIX_FMT_RGB32:
1593 alt_s = gst_structure_copy (structure);
1594 gst_structure_set (alt_s, "format", G_TYPE_STRING, "ARGB", NULL);
1596 case V4L2_PIX_FMT_BGR32:
1597 alt_s = gst_structure_copy (structure);
1598 gst_structure_set (alt_s, "format", G_TYPE_STRING, "BGRA", NULL);
1603 gst_caps_append_structure (caps, structure);
1606 gst_caps_append_structure (caps, alt_s);
1610 return gst_caps_simplify (caps);
1614 gst_v4l2_object_get_all_caps (void)
1616 static GstCaps *caps = NULL;
1618 if (g_once_init_enter (&caps)) {
1619 GstCaps *all_caps = gst_v4l2_object_get_caps_helper (GST_V4L2_ALL);
1620 GST_MINI_OBJECT_FLAG_SET (all_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
1621 g_once_init_leave (&caps, all_caps);
1628 gst_v4l2_object_get_raw_caps (void)
1630 static GstCaps *caps = NULL;
1632 if (g_once_init_enter (&caps)) {
1633 GstCaps *raw_caps = gst_v4l2_object_get_caps_helper (GST_V4L2_RAW);
1634 GST_MINI_OBJECT_FLAG_SET (raw_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
1635 g_once_init_leave (&caps, raw_caps);
1642 gst_v4l2_object_get_codec_caps (void)
1644 static GstCaps *caps = NULL;
1646 if (g_once_init_enter (&caps)) {
1647 GstCaps *codec_caps = gst_v4l2_object_get_caps_helper (GST_V4L2_CODEC);
1648 GST_MINI_OBJECT_FLAG_SET (codec_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
1649 g_once_init_leave (&caps, codec_caps);
1655 /* collect data for the given caps
1656 * @caps: given input caps
1657 * @format: location for the v4l format
1658 * @w/@h: location for width and height
1659 * @fps_n/@fps_d: location for framerate
1660 * @size: location for expected size of the frame or 0 if unknown
1663 gst_v4l2_object_get_caps_info (GstV4l2Object * v4l2object, GstCaps * caps,
1664 struct v4l2_fmtdesc **format, GstVideoInfo * info)
1666 GstStructure *structure;
1667 guint32 fourcc = 0, fourcc_nc = 0;
1668 const gchar *mimetype;
1669 struct v4l2_fmtdesc *fmt = NULL;
1671 structure = gst_caps_get_structure (caps, 0);
1673 mimetype = gst_structure_get_name (structure);
1675 if (!gst_video_info_from_caps (info, caps))
1676 goto invalid_format;
1678 if (g_str_equal (mimetype, "video/x-raw")) {
1679 switch (GST_VIDEO_INFO_FORMAT (info)) {
1680 case GST_VIDEO_FORMAT_I420:
1681 fourcc = V4L2_PIX_FMT_YUV420;
1682 fourcc_nc = V4L2_PIX_FMT_YUV420M;
1684 case GST_VIDEO_FORMAT_YUY2:
1685 fourcc = V4L2_PIX_FMT_YUYV;
1687 case GST_VIDEO_FORMAT_UYVY:
1688 fourcc = V4L2_PIX_FMT_UYVY;
1690 case GST_VIDEO_FORMAT_YV12:
1691 fourcc = V4L2_PIX_FMT_YVU420;
1693 case GST_VIDEO_FORMAT_Y41B:
1694 fourcc = V4L2_PIX_FMT_YUV411P;
1696 case GST_VIDEO_FORMAT_Y42B:
1697 fourcc = V4L2_PIX_FMT_YUV422P;
1699 case GST_VIDEO_FORMAT_NV12:
1700 fourcc = V4L2_PIX_FMT_NV12;
1701 fourcc_nc = V4L2_PIX_FMT_NV12M;
1703 case GST_VIDEO_FORMAT_NV12_64Z32:
1704 fourcc_nc = V4L2_PIX_FMT_NV12MT;
1706 case GST_VIDEO_FORMAT_NV21:
1707 fourcc = V4L2_PIX_FMT_NV21;
1708 fourcc_nc = V4L2_PIX_FMT_NV21M;
1710 case GST_VIDEO_FORMAT_NV16:
1711 fourcc = V4L2_PIX_FMT_NV16;
1712 fourcc_nc = V4L2_PIX_FMT_NV16M;
1714 case GST_VIDEO_FORMAT_NV61:
1715 fourcc = V4L2_PIX_FMT_NV61;
1716 fourcc_nc = V4L2_PIX_FMT_NV61M;
1718 case GST_VIDEO_FORMAT_NV24:
1719 fourcc = V4L2_PIX_FMT_NV24;
1721 case GST_VIDEO_FORMAT_YVYU:
1722 fourcc = V4L2_PIX_FMT_YVYU;
1724 case GST_VIDEO_FORMAT_RGB15:
1725 fourcc = V4L2_PIX_FMT_RGB555;
1726 fourcc_nc = V4L2_PIX_FMT_XRGB555;
1728 case GST_VIDEO_FORMAT_RGB16:
1729 fourcc = V4L2_PIX_FMT_RGB565;
1731 case GST_VIDEO_FORMAT_RGB:
1732 fourcc = V4L2_PIX_FMT_RGB24;
1734 case GST_VIDEO_FORMAT_BGR:
1735 fourcc = V4L2_PIX_FMT_BGR24;
1737 case GST_VIDEO_FORMAT_xRGB:
1738 fourcc = V4L2_PIX_FMT_RGB32;
1739 fourcc_nc = V4L2_PIX_FMT_XRGB32;
1741 case GST_VIDEO_FORMAT_ARGB:
1742 fourcc = V4L2_PIX_FMT_RGB32;
1743 fourcc_nc = V4L2_PIX_FMT_ARGB32;
1745 case GST_VIDEO_FORMAT_BGRx:
1746 fourcc = V4L2_PIX_FMT_BGR32;
1747 fourcc_nc = V4L2_PIX_FMT_XBGR32;
1749 case GST_VIDEO_FORMAT_BGRA:
1750 fourcc = V4L2_PIX_FMT_BGR32;
1751 fourcc_nc = V4L2_PIX_FMT_ABGR32;
1753 case GST_VIDEO_FORMAT_GRAY8:
1754 fourcc = V4L2_PIX_FMT_GREY;
1756 case GST_VIDEO_FORMAT_GRAY16_LE:
1757 fourcc = V4L2_PIX_FMT_Y16;
1759 case GST_VIDEO_FORMAT_GRAY16_BE:
1760 fourcc = V4L2_PIX_FMT_Y16_BE;
1766 if (g_str_equal (mimetype, "video/mpegts")) {
1767 fourcc = V4L2_PIX_FMT_MPEG;
1768 } else if (g_str_equal (mimetype, "video/x-dv")) {
1769 fourcc = V4L2_PIX_FMT_DV;
1770 } else if (g_str_equal (mimetype, "image/jpeg")) {
1771 fourcc = V4L2_PIX_FMT_JPEG;
1772 } else if (g_str_equal (mimetype, "video/mpeg")) {
1774 if (gst_structure_get_int (structure, "mpegversion", &version)) {
1777 fourcc = V4L2_PIX_FMT_MPEG1;
1780 fourcc = V4L2_PIX_FMT_MPEG2;
1783 fourcc = V4L2_PIX_FMT_MPEG4;
1784 fourcc_nc = V4L2_PIX_FMT_XVID;
1790 } else if (g_str_equal (mimetype, "video/x-h263")) {
1791 fourcc = V4L2_PIX_FMT_H263;
1792 } else if (g_str_equal (mimetype, "video/x-h264")) {
1793 const gchar *stream_format =
1794 gst_structure_get_string (structure, "stream-format");
1795 if (g_str_equal (stream_format, "avc"))
1796 fourcc = V4L2_PIX_FMT_H264_NO_SC;
1798 fourcc = V4L2_PIX_FMT_H264;
1799 } else if (g_str_equal (mimetype, "video/x-vp8")) {
1800 fourcc = V4L2_PIX_FMT_VP8;
1801 } else if (g_str_equal (mimetype, "video/x-vp9")) {
1802 fourcc = V4L2_PIX_FMT_VP9;
1803 } else if (g_str_equal (mimetype, "video/x-bayer")) {
1804 const gchar *format = gst_structure_get_string (structure, "format");
1806 if (!g_ascii_strcasecmp (format, "bggr"))
1807 fourcc = V4L2_PIX_FMT_SBGGR8;
1808 else if (!g_ascii_strcasecmp (format, "gbrg"))
1809 fourcc = V4L2_PIX_FMT_SGBRG8;
1810 else if (!g_ascii_strcasecmp (format, "grbg"))
1811 fourcc = V4L2_PIX_FMT_SGRBG8;
1812 else if (!g_ascii_strcasecmp (format, "rggb"))
1813 fourcc = V4L2_PIX_FMT_SRGGB8;
1815 } else if (g_str_equal (mimetype, "video/x-sonix")) {
1816 fourcc = V4L2_PIX_FMT_SN9C10X;
1817 } else if (g_str_equal (mimetype, "video/x-pwc1")) {
1818 fourcc = V4L2_PIX_FMT_PWC1;
1819 } else if (g_str_equal (mimetype, "video/x-pwc2")) {
1820 fourcc = V4L2_PIX_FMT_PWC2;
1825 /* Prefer the non-contiguous if supported */
1826 v4l2object->prefered_non_contiguous = TRUE;
1829 fmt = gst_v4l2_object_get_format_from_fourcc (v4l2object, fourcc_nc);
1830 else if (fourcc == 0)
1831 goto unhandled_format;
1834 fmt = gst_v4l2_object_get_format_from_fourcc (v4l2object, fourcc);
1835 v4l2object->prefered_non_contiguous = FALSE;
1839 goto unsupported_format;
1848 GST_DEBUG_OBJECT (v4l2object, "invalid format");
1853 GST_DEBUG_OBJECT (v4l2object, "unhandled format");
1858 GST_DEBUG_OBJECT (v4l2object, "unsupported format");
1864 gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
1865 guint32 pixelformat, gint * width, gint * height);
1868 gst_v4l2_object_add_aspect_ratio (GstV4l2Object * v4l2object, GstStructure * s)
1870 if (v4l2object->keep_aspect && v4l2object->par)
1871 gst_structure_set_value (s, "pixel-aspect-ratio", v4l2object->par);
1874 /* returns TRUE if the value was changed in place, otherwise FALSE */
1876 gst_v4l2src_value_simplify (GValue * val)
1878 /* simplify list of one value to one value */
1879 if (GST_VALUE_HOLDS_LIST (val) && gst_value_list_get_size (val) == 1) {
1880 const GValue *list_val;
1881 GValue new_val = G_VALUE_INIT;
1883 list_val = gst_value_list_get_value (val, 0);
1884 g_value_init (&new_val, G_VALUE_TYPE (list_val));
1885 g_value_copy (list_val, &new_val);
1886 g_value_unset (val);
1895 gst_v4l2_object_get_interlace_mode (enum v4l2_field field,
1896 GstVideoInterlaceMode * interlace_mode)
1898 /* NB: If you add new return values, please fix mode_strings in
1899 * gst_v4l2_object_add_interlace_mode */
1901 case V4L2_FIELD_ANY:
1903 ("Driver bug detected - check driver with v4l2-compliance from http://git.linuxtv.org/v4l-utils.git\n");
1905 case V4L2_FIELD_NONE:
1906 *interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
1908 case V4L2_FIELD_INTERLACED:
1909 case V4L2_FIELD_INTERLACED_TB:
1910 case V4L2_FIELD_INTERLACED_BT:
1911 *interlace_mode = GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
1914 GST_ERROR ("Unknown enum v4l2_field %d", field);
1920 gst_v4l2_object_get_colorspace (struct v4l2_format *fmt,
1921 GstVideoColorimetry * cinfo)
1924 gst_v4l2_object_v4l2fourcc_is_rgb (fmt->fmt.pix.pixelformat);
1925 enum v4l2_colorspace colorspace;
1926 enum v4l2_quantization range;
1927 enum v4l2_ycbcr_encoding matrix;
1928 enum v4l2_xfer_func transfer;
1929 gboolean ret = TRUE;
1931 if (V4L2_TYPE_IS_MULTIPLANAR (fmt->type)) {
1932 colorspace = fmt->fmt.pix_mp.colorspace;
1933 range = fmt->fmt.pix_mp.quantization;
1934 matrix = fmt->fmt.pix_mp.ycbcr_enc;
1935 transfer = fmt->fmt.pix_mp.xfer_func;
1937 colorspace = fmt->fmt.pix.colorspace;
1938 range = fmt->fmt.pix.quantization;
1939 matrix = fmt->fmt.pix.ycbcr_enc;
1940 transfer = fmt->fmt.pix.xfer_func;
1943 /* First step, set the defaults for each primaries */
1944 switch (colorspace) {
1945 case V4L2_COLORSPACE_SMPTE170M:
1946 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1947 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
1948 cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
1949 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTE170M;
1951 case V4L2_COLORSPACE_REC709:
1952 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1953 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT709;
1954 cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
1955 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT709;
1957 case V4L2_COLORSPACE_SRGB:
1958 case V4L2_COLORSPACE_JPEG:
1959 cinfo->range = GST_VIDEO_COLOR_RANGE_0_255;
1960 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
1961 cinfo->transfer = GST_VIDEO_TRANSFER_SRGB;
1962 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT709;
1964 case V4L2_COLORSPACE_ADOBERGB:
1965 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1966 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
1967 cinfo->transfer = GST_VIDEO_TRANSFER_ADOBERGB;
1968 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_ADOBERGB;
1970 case V4L2_COLORSPACE_BT2020:
1971 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1972 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT2020;
1973 cinfo->transfer = GST_VIDEO_TRANSFER_BT2020_12;
1974 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020;
1976 case V4L2_COLORSPACE_SMPTE240M:
1977 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1978 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_SMPTE240M;
1979 cinfo->transfer = GST_VIDEO_TRANSFER_SMPTE240M;
1980 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_SMPTE240M;
1982 case V4L2_COLORSPACE_470_SYSTEM_M:
1983 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1984 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
1985 cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
1986 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT470M;
1988 case V4L2_COLORSPACE_470_SYSTEM_BG:
1989 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
1990 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
1991 cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
1992 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_BT470BG;
1994 case V4L2_COLORSPACE_RAW:
1995 /* Explicitly unknown */
1996 cinfo->range = GST_VIDEO_COLOR_RANGE_UNKNOWN;
1997 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_UNKNOWN;
1998 cinfo->transfer = GST_VIDEO_TRANSFER_UNKNOWN;
1999 cinfo->primaries = GST_VIDEO_COLOR_PRIMARIES_UNKNOWN;
2002 GST_DEBUG ("Unknown enum v4l2_colorspace %d", colorspace);
2010 /* Second step, apply any custom variation */
2012 case V4L2_QUANTIZATION_FULL_RANGE:
2013 cinfo->range = GST_VIDEO_COLOR_RANGE_0_255;
2015 case V4L2_QUANTIZATION_LIM_RANGE:
2016 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
2018 case V4L2_QUANTIZATION_DEFAULT:
2019 /* replicated V4L2_MAP_QUANTIZATION_DEFAULT macro behavior */
2020 if (is_rgb && colorspace == V4L2_COLORSPACE_BT2020)
2021 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
2022 else if (is_rgb || matrix == V4L2_YCBCR_ENC_XV601
2023 || matrix == V4L2_YCBCR_ENC_XV709
2024 || colorspace == V4L2_COLORSPACE_JPEG)
2025 cinfo->range = GST_VIDEO_COLOR_RANGE_0_255;
2027 cinfo->range = GST_VIDEO_COLOR_RANGE_16_235;
2030 GST_WARNING ("Unknown enum v4l2_quantization value %d", range);
2031 cinfo->range = GST_VIDEO_COLOR_RANGE_UNKNOWN;
2036 case V4L2_YCBCR_ENC_XV601:
2037 case V4L2_YCBCR_ENC_SYCC:
2038 GST_FIXME ("XV601 and SYCC not defined, assuming 601");
2040 case V4L2_YCBCR_ENC_601:
2041 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT601;
2043 case V4L2_YCBCR_ENC_XV709:
2044 GST_FIXME ("XV709 not defined, assuming 709");
2046 case V4L2_YCBCR_ENC_709:
2047 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT709;
2049 case V4L2_YCBCR_ENC_BT2020_CONST_LUM:
2050 GST_FIXME ("BT2020 with constant luma is not defined, assuming BT2020");
2052 case V4L2_YCBCR_ENC_BT2020:
2053 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_BT2020;
2055 case V4L2_YCBCR_ENC_SMPTE240M:
2056 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_SMPTE240M;
2058 case V4L2_YCBCR_ENC_DEFAULT:
2059 /* nothing, just use defaults for colorspace */
2062 GST_WARNING ("Unknown enum v4l2_ycbcr_encoding value %d", matrix);
2063 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_UNKNOWN;
2067 /* Set identity matrix for R'G'B' formats to avoid creating
2068 * confusion. This though is cosmetic as it's now properly ignored by
2069 * the video info API and videoconvert. */
2071 cinfo->matrix = GST_VIDEO_COLOR_MATRIX_RGB;
2074 case V4L2_XFER_FUNC_709:
2075 if (fmt->fmt.pix.height >= 2160)
2076 cinfo->transfer = GST_VIDEO_TRANSFER_BT2020_12;
2078 cinfo->transfer = GST_VIDEO_TRANSFER_BT709;
2080 case V4L2_XFER_FUNC_SRGB:
2081 cinfo->transfer = GST_VIDEO_TRANSFER_SRGB;
2083 case V4L2_XFER_FUNC_ADOBERGB:
2084 cinfo->transfer = GST_VIDEO_TRANSFER_ADOBERGB;
2086 case V4L2_XFER_FUNC_SMPTE240M:
2087 cinfo->transfer = GST_VIDEO_TRANSFER_SMPTE240M;
2089 case V4L2_XFER_FUNC_NONE:
2090 cinfo->transfer = GST_VIDEO_TRANSFER_GAMMA10;
2092 case V4L2_XFER_FUNC_DEFAULT:
2093 /* nothing, just use defaults for colorspace */
2096 GST_WARNING ("Unknown enum v4l2_xfer_func value %d", transfer);
2097 cinfo->transfer = GST_VIDEO_TRANSFER_UNKNOWN;
2106 gst_v4l2_object_try_fmt (GstV4l2Object * v4l2object,
2107 struct v4l2_format *try_fmt)
2109 int fd = v4l2object->video_fd;
2110 struct v4l2_format fmt;
2113 memcpy (&fmt, try_fmt, sizeof (fmt));
2114 r = v4l2object->ioctl (fd, VIDIOC_TRY_FMT, &fmt);
2116 if (r < 0 && errno == ENOTTY) {
2117 /* The driver might not implement TRY_FMT, in which case we will try
2119 if (GST_V4L2_IS_ACTIVE (v4l2object))
2122 memcpy (&fmt, try_fmt, sizeof (fmt));
2123 r = v4l2object->ioctl (fd, VIDIOC_S_FMT, &fmt);
2125 memcpy (try_fmt, &fmt, sizeof (fmt));
2130 memcpy (try_fmt, &fmt, sizeof (fmt));
2131 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2132 "Unable to try format: %s", g_strerror (errno));
2138 gst_v4l2_object_add_interlace_mode (GstV4l2Object * v4l2object,
2139 GstStructure * s, guint32 width, guint32 height, guint32 pixelformat)
2141 struct v4l2_format fmt;
2142 GValue interlace_formats = { 0, };
2143 GstVideoInterlaceMode interlace_mode, prev = -1;
2145 const gchar *mode_strings[] = { "progressive",
2150 if (!g_str_equal (gst_structure_get_name (s), "video/x-raw"))
2153 if (v4l2object->never_interlaced) {
2154 gst_structure_set (s, "interlace-mode", G_TYPE_STRING, "progressive", NULL);
2158 g_value_init (&interlace_formats, GST_TYPE_LIST);
2160 /* Try twice - once for NONE, once for INTERLACED. */
2161 memset (&fmt, 0, sizeof (fmt));
2162 fmt.type = v4l2object->type;
2163 fmt.fmt.pix.width = width;
2164 fmt.fmt.pix.height = height;
2165 fmt.fmt.pix.pixelformat = pixelformat;
2166 fmt.fmt.pix.field = V4L2_FIELD_NONE;
2168 if (gst_v4l2_object_try_fmt (v4l2object, &fmt) == 0 &&
2169 gst_v4l2_object_get_interlace_mode (fmt.fmt.pix.field, &interlace_mode)) {
2170 GValue interlace_enum = { 0, };
2171 g_value_init (&interlace_enum, G_TYPE_STRING);
2172 g_value_set_string (&interlace_enum, mode_strings[interlace_mode]);
2173 gst_value_list_append_and_take_value (&interlace_formats, &interlace_enum);
2174 prev = interlace_mode;
2177 memset (&fmt, 0, sizeof (fmt));
2178 fmt.type = v4l2object->type;
2179 fmt.fmt.pix.width = width;
2180 fmt.fmt.pix.height = height;
2181 fmt.fmt.pix.pixelformat = pixelformat;
2182 fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
2184 if (gst_v4l2_object_try_fmt (v4l2object, &fmt) == 0 &&
2185 gst_v4l2_object_get_interlace_mode (fmt.fmt.pix.field, &interlace_mode) &&
2186 prev != interlace_mode) {
2187 GValue interlace_enum = { 0, };
2188 g_value_init (&interlace_enum, G_TYPE_STRING);
2189 g_value_set_string (&interlace_enum, mode_strings[interlace_mode]);
2190 gst_value_list_append_and_take_value (&interlace_formats, &interlace_enum);
2193 if (gst_v4l2src_value_simplify (&interlace_formats)
2194 || gst_value_list_get_size (&interlace_formats) > 0)
2195 gst_structure_take_value (s, "interlace-mode", &interlace_formats);
2197 GST_WARNING_OBJECT (v4l2object, "Failed to determine interlace mode");
2203 gst_v4l2_object_fill_colorimetry_list (GValue * list,
2204 GstVideoColorimetry * cinfo)
2206 GValue colorimetry = G_VALUE_INIT;
2209 gboolean found = FALSE;
2211 g_value_init (&colorimetry, G_TYPE_STRING);
2212 g_value_take_string (&colorimetry, gst_video_colorimetry_to_string (cinfo));
2214 /* only insert if no duplicate */
2215 size = gst_value_list_get_size (list);
2216 for (i = 0; i < size; i++) {
2219 tmp = gst_value_list_get_value (list, i);
2220 if (gst_value_compare (&colorimetry, tmp) == GST_VALUE_EQUAL) {
2227 gst_value_list_append_and_take_value (list, &colorimetry);
2229 g_value_unset (&colorimetry);
2233 gst_v4l2_object_add_colorspace (GstV4l2Object * v4l2object, GstStructure * s,
2234 guint32 width, guint32 height, guint32 pixelformat)
2236 struct v4l2_format fmt;
2237 GValue list = G_VALUE_INIT;
2238 GstVideoColorimetry cinfo;
2239 enum v4l2_colorspace req_cspace;
2241 memset (&fmt, 0, sizeof (fmt));
2242 fmt.type = v4l2object->type;
2243 fmt.fmt.pix.width = width;
2244 fmt.fmt.pix.height = height;
2245 fmt.fmt.pix.pixelformat = pixelformat;
2247 g_value_init (&list, GST_TYPE_LIST);
2249 /* step 1: get device default colorspace and insert it first as
2250 * it should be the preferred one */
2251 if (gst_v4l2_object_try_fmt (v4l2object, &fmt) == 0) {
2252 if (gst_v4l2_object_get_colorspace (&fmt, &cinfo))
2253 gst_v4l2_object_fill_colorimetry_list (&list, &cinfo);
2256 /* step 2: probe all colorspace other than default
2257 * We don't probe all colorspace, range, matrix and transfer combination to
2258 * avoid ioctl flooding which could greatly increase initialization time
2259 * with low-speed devices (UVC...) */
2260 for (req_cspace = V4L2_COLORSPACE_SMPTE170M;
2261 req_cspace <= V4L2_COLORSPACE_RAW; req_cspace++) {
2262 /* V4L2_COLORSPACE_BT878 is deprecated and shall not be used, so skip */
2263 if (req_cspace == V4L2_COLORSPACE_BT878)
2266 if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type))
2267 fmt.fmt.pix_mp.colorspace = req_cspace;
2269 fmt.fmt.pix.colorspace = req_cspace;
2271 if (gst_v4l2_object_try_fmt (v4l2object, &fmt) == 0) {
2272 enum v4l2_colorspace colorspace;
2274 if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type))
2275 colorspace = fmt.fmt.pix_mp.colorspace;
2277 colorspace = fmt.fmt.pix.colorspace;
2279 if (colorspace == req_cspace) {
2280 if (gst_v4l2_object_get_colorspace (&fmt, &cinfo))
2281 gst_v4l2_object_fill_colorimetry_list (&list, &cinfo);
2286 if (gst_value_list_get_size (&list) > 0)
2287 gst_structure_take_value (s, "colorimetry", &list);
2289 g_value_unset (&list);
2294 /* The frame interval enumeration code first appeared in Linux 2.6.19. */
2295 static GstStructure *
2296 gst_v4l2_object_probe_caps_for_format_and_size (GstV4l2Object * v4l2object,
2297 guint32 pixelformat,
2298 guint32 width, guint32 height, const GstStructure * template)
2300 gint fd = v4l2object->video_fd;
2301 struct v4l2_frmivalenum ival;
2304 GValue rates = { 0, };
2306 memset (&ival, 0, sizeof (struct v4l2_frmivalenum));
2308 ival.pixel_format = pixelformat;
2310 ival.height = height;
2312 GST_LOG_OBJECT (v4l2object->dbg_obj,
2313 "get frame interval for %ux%u, %" GST_FOURCC_FORMAT, width, height,
2314 GST_FOURCC_ARGS (pixelformat));
2316 /* keep in mind that v4l2 gives us frame intervals (durations); we invert the
2317 * fraction to get framerate */
2318 if (v4l2object->ioctl (fd, VIDIOC_ENUM_FRAMEINTERVALS, &ival) < 0)
2319 goto enum_frameintervals_failed;
2321 if (ival.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
2322 GValue rate = { 0, };
2324 g_value_init (&rates, GST_TYPE_LIST);
2325 g_value_init (&rate, GST_TYPE_FRACTION);
2328 num = ival.discrete.numerator;
2329 denom = ival.discrete.denominator;
2331 if (num > G_MAXINT || denom > G_MAXINT) {
2332 /* let us hope we don't get here... */
2337 GST_LOG_OBJECT (v4l2object->dbg_obj, "adding discrete framerate: %d/%d",
2340 /* swap to get the framerate */
2341 gst_value_set_fraction (&rate, denom, num);
2342 gst_value_list_append_value (&rates, &rate);
2345 } while (v4l2object->ioctl (fd, VIDIOC_ENUM_FRAMEINTERVALS, &ival) >= 0);
2346 } else if (ival.type == V4L2_FRMIVAL_TYPE_STEPWISE) {
2347 GValue min = { 0, };
2348 GValue step = { 0, };
2349 GValue max = { 0, };
2350 gboolean added = FALSE;
2351 guint32 minnum, mindenom;
2352 guint32 maxnum, maxdenom;
2354 g_value_init (&rates, GST_TYPE_LIST);
2356 g_value_init (&min, GST_TYPE_FRACTION);
2357 g_value_init (&step, GST_TYPE_FRACTION);
2358 g_value_init (&max, GST_TYPE_FRACTION);
2361 minnum = ival.stepwise.min.numerator;
2362 mindenom = ival.stepwise.min.denominator;
2363 if (minnum > G_MAXINT || mindenom > G_MAXINT) {
2367 GST_LOG_OBJECT (v4l2object->dbg_obj, "stepwise min frame interval: %d/%d",
2369 gst_value_set_fraction (&min, minnum, mindenom);
2372 maxnum = ival.stepwise.max.numerator;
2373 maxdenom = ival.stepwise.max.denominator;
2374 if (maxnum > G_MAXINT || maxdenom > G_MAXINT) {
2379 GST_LOG_OBJECT (v4l2object->dbg_obj, "stepwise max frame interval: %d/%d",
2381 gst_value_set_fraction (&max, maxnum, maxdenom);
2384 num = ival.stepwise.step.numerator;
2385 denom = ival.stepwise.step.denominator;
2386 if (num > G_MAXINT || denom > G_MAXINT) {
2391 if (num == 0 || denom == 0) {
2392 /* in this case we have a wrong fraction or no step, set the step to max
2393 * so that we only add the min value in the loop below */
2398 /* since we only have gst_value_fraction_subtract and not add, negate the
2400 GST_LOG_OBJECT (v4l2object->dbg_obj, "stepwise step frame interval: %d/%d",
2402 gst_value_set_fraction (&step, -num, denom);
2404 while (gst_value_compare (&min, &max) != GST_VALUE_GREATER_THAN) {
2405 GValue rate = { 0, };
2407 num = gst_value_get_fraction_numerator (&min);
2408 denom = gst_value_get_fraction_denominator (&min);
2409 GST_LOG_OBJECT (v4l2object->dbg_obj, "adding stepwise framerate: %d/%d",
2412 /* invert to get the framerate */
2413 g_value_init (&rate, GST_TYPE_FRACTION);
2414 gst_value_set_fraction (&rate, denom, num);
2415 gst_value_list_append_value (&rates, &rate);
2418 /* we're actually adding because step was negated above. This is because
2419 * there is no _add function... */
2420 if (!gst_value_fraction_subtract (&min, &min, &step)) {
2421 GST_WARNING_OBJECT (v4l2object->dbg_obj, "could not step fraction!");
2426 /* no range was added, leave the default range from the template */
2427 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2428 "no range added, leaving default");
2429 g_value_unset (&rates);
2431 } else if (ival.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) {
2432 guint32 maxnum, maxdenom;
2434 g_value_init (&rates, GST_TYPE_FRACTION_RANGE);
2436 num = ival.stepwise.min.numerator;
2437 denom = ival.stepwise.min.denominator;
2438 if (num > G_MAXINT || denom > G_MAXINT) {
2443 maxnum = ival.stepwise.max.numerator;
2444 maxdenom = ival.stepwise.max.denominator;
2445 if (maxnum > G_MAXINT || maxdenom > G_MAXINT) {
2450 GST_LOG_OBJECT (v4l2object->dbg_obj,
2451 "continuous frame interval %d/%d to %d/%d", maxdenom, maxnum, denom,
2454 gst_value_set_fraction_range_full (&rates, maxdenom, maxnum, denom, num);
2460 s = gst_structure_copy (template);
2461 gst_structure_set (s, "width", G_TYPE_INT, (gint) width,
2462 "height", G_TYPE_INT, (gint) height, NULL);
2464 gst_v4l2_object_add_aspect_ratio (v4l2object, s);
2466 if (!v4l2object->skip_try_fmt_probes) {
2467 gst_v4l2_object_add_interlace_mode (v4l2object, s, width, height,
2469 gst_v4l2_object_add_colorspace (v4l2object, s, width, height, pixelformat);
2472 if (G_IS_VALUE (&rates)) {
2473 gst_v4l2src_value_simplify (&rates);
2474 /* only change the framerate on the template when we have a valid probed new
2476 gst_structure_take_value (s, "framerate", &rates);
2477 } else if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
2478 v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
2479 gst_structure_set (s, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT,
2485 enum_frameintervals_failed:
2487 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
2488 "Unable to enumerate intervals for %" GST_FOURCC_FORMAT "@%ux%u",
2489 GST_FOURCC_ARGS (pixelformat), width, height);
2494 /* I don't see how this is actually an error, we ignore the format then */
2495 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2496 "Unknown frame interval type at %" GST_FOURCC_FORMAT "@%ux%u: %u",
2497 GST_FOURCC_ARGS (pixelformat), width, height, ival.type);
2503 sort_by_frame_size (GstStructure * s1, GstStructure * s2)
2507 gst_structure_get_int (s1, "width", &w1);
2508 gst_structure_get_int (s1, "height", &h1);
2509 gst_structure_get_int (s2, "width", &w2);
2510 gst_structure_get_int (s2, "height", &h2);
2512 /* I think it's safe to assume that this won't overflow for a while */
2513 return ((w2 * h2) - (w1 * h1));
2517 gst_v4l2_object_update_and_append (GstV4l2Object * v4l2object,
2518 guint32 format, GstCaps * caps, GstStructure * s)
2520 GstStructure *alt_s = NULL;
2522 /* Encoded stream on output buffer need to be parsed */
2523 if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT ||
2524 v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
2527 for (; i < GST_V4L2_FORMAT_COUNT; i++) {
2528 if (format == gst_v4l2_formats[i].format &&
2529 gst_v4l2_formats[i].flags & GST_V4L2_CODEC &&
2530 !(gst_v4l2_formats[i].flags & GST_V4L2_NO_PARSE)) {
2531 gst_structure_set (s, "parsed", G_TYPE_BOOLEAN, TRUE, NULL);
2537 if (v4l2object->has_alpha_component &&
2538 (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
2539 v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) {
2541 case V4L2_PIX_FMT_RGB32:
2542 alt_s = gst_structure_copy (s);
2543 gst_structure_set (alt_s, "format", G_TYPE_STRING, "ARGB", NULL);
2545 case V4L2_PIX_FMT_BGR32:
2546 alt_s = gst_structure_copy (s);
2547 gst_structure_set (alt_s, "format", G_TYPE_STRING, "BGRA", NULL);
2554 gst_caps_append_structure (caps, s);
2557 gst_caps_append_structure (caps, alt_s);
2561 gst_v4l2_object_probe_caps_for_format (GstV4l2Object * v4l2object,
2562 guint32 pixelformat, const GstStructure * template)
2564 GstCaps *ret = gst_caps_new_empty ();
2566 gint fd = v4l2object->video_fd;
2567 struct v4l2_frmsizeenum size;
2568 GList *results = NULL;
2571 if (pixelformat == GST_MAKE_FOURCC ('M', 'P', 'E', 'G')) {
2572 gst_caps_append_structure (ret, gst_structure_copy (template));
2576 memset (&size, 0, sizeof (struct v4l2_frmsizeenum));
2578 size.pixel_format = pixelformat;
2580 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
2581 "Enumerating frame sizes for %" GST_FOURCC_FORMAT,
2582 GST_FOURCC_ARGS (pixelformat));
2584 if (v4l2object->ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &size) < 0)
2585 goto enum_framesizes_failed;
2587 if (size.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
2589 GST_LOG_OBJECT (v4l2object->dbg_obj, "got discrete frame size %dx%d",
2590 size.discrete.width, size.discrete.height);
2592 w = MIN (size.discrete.width, G_MAXINT);
2593 h = MIN (size.discrete.height, G_MAXINT);
2597 gst_v4l2_object_probe_caps_for_format_and_size (v4l2object,
2598 pixelformat, w, h, template);
2601 results = g_list_prepend (results, tmp);
2605 } while (v4l2object->ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &size) >= 0);
2606 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
2607 "done iterating discrete frame sizes");
2608 } else if (size.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
2609 guint32 maxw, maxh, step_w, step_h;
2611 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "we have stepwise frame sizes:");
2612 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min width: %d",
2613 size.stepwise.min_width);
2614 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min height: %d",
2615 size.stepwise.min_height);
2616 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "max width: %d",
2617 size.stepwise.max_width);
2618 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min height: %d",
2619 size.stepwise.max_height);
2620 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "step width: %d",
2621 size.stepwise.step_width);
2622 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "step height: %d",
2623 size.stepwise.step_height);
2625 w = MAX (size.stepwise.min_width, 1);
2626 h = MAX (size.stepwise.min_height, 1);
2627 maxw = MIN (size.stepwise.max_width, G_MAXINT);
2628 maxh = MIN (size.stepwise.max_height, G_MAXINT);
2630 step_w = MAX (size.stepwise.step_width, 1);
2631 step_h = MAX (size.stepwise.step_height, 1);
2633 /* FIXME: check for sanity and that min/max are multiples of the steps */
2635 /* we only query details for the max width/height since it's likely the
2636 * most restricted if there are any resolution-dependent restrictions */
2637 tmp = gst_v4l2_object_probe_caps_for_format_and_size (v4l2object,
2638 pixelformat, maxw, maxh, template);
2641 GValue step_range = G_VALUE_INIT;
2643 g_value_init (&step_range, GST_TYPE_INT_RANGE);
2644 gst_value_set_int_range_step (&step_range, w, maxw, step_w);
2645 gst_structure_set_value (tmp, "width", &step_range);
2647 gst_value_set_int_range_step (&step_range, h, maxh, step_h);
2648 gst_structure_take_value (tmp, "height", &step_range);
2650 /* no point using the results list here, since there's only one struct */
2651 gst_v4l2_object_update_and_append (v4l2object, pixelformat, ret, tmp);
2653 } else if (size.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) {
2656 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "we have continuous frame sizes:");
2657 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min width: %d",
2658 size.stepwise.min_width);
2659 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min height: %d",
2660 size.stepwise.min_height);
2661 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "max width: %d",
2662 size.stepwise.max_width);
2663 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "min height: %d",
2664 size.stepwise.max_height);
2666 w = MAX (size.stepwise.min_width, 1);
2667 h = MAX (size.stepwise.min_height, 1);
2668 maxw = MIN (size.stepwise.max_width, G_MAXINT);
2669 maxh = MIN (size.stepwise.max_height, G_MAXINT);
2672 gst_v4l2_object_probe_caps_for_format_and_size (v4l2object, pixelformat,
2675 gst_structure_set (tmp, "width", GST_TYPE_INT_RANGE, (gint) w,
2676 (gint) maxw, "height", GST_TYPE_INT_RANGE, (gint) h, (gint) maxh,
2679 /* no point using the results list here, since there's only one struct */
2680 gst_v4l2_object_update_and_append (v4l2object, pixelformat, ret, tmp);
2686 /* we use an intermediary list to store and then sort the results of the
2687 * probing because we can't make any assumptions about the order in which
2688 * the driver will give us the sizes, but we want the final caps to contain
2689 * the results starting with the highest resolution and having the lowest
2690 * resolution last, since order in caps matters for things like fixation. */
2691 results = g_list_sort (results, (GCompareFunc) sort_by_frame_size);
2692 while (results != NULL) {
2693 gst_v4l2_object_update_and_append (v4l2object, pixelformat, ret,
2695 results = g_list_delete_link (results, results);
2698 if (gst_caps_is_empty (ret))
2699 goto enum_framesizes_no_results;
2704 enum_framesizes_failed:
2706 /* I don't see how this is actually an error */
2707 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
2708 "Failed to enumerate frame sizes for pixelformat %" GST_FOURCC_FORMAT
2709 " (%s)", GST_FOURCC_ARGS (pixelformat), g_strerror (errno));
2710 goto default_frame_sizes;
2712 enum_framesizes_no_results:
2714 /* it's possible that VIDIOC_ENUM_FRAMESIZES is defined but the driver in
2715 * question doesn't actually support it yet */
2716 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
2717 "No results for pixelformat %" GST_FOURCC_FORMAT
2718 " enumerating frame sizes, trying fallback",
2719 GST_FOURCC_ARGS (pixelformat));
2720 goto default_frame_sizes;
2724 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2725 "Unknown frame sizeenum type for pixelformat %" GST_FOURCC_FORMAT
2726 ": %u", GST_FOURCC_ARGS (pixelformat), size.type);
2727 goto default_frame_sizes;
2730 default_frame_sizes:
2732 gint min_w, max_w, min_h, max_h, fix_num = 0, fix_denom = 0;
2734 /* This code is for Linux < 2.6.19 */
2736 max_w = max_h = GST_V4L2_MAX_SIZE;
2737 if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &min_w,
2739 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2740 "Could not probe minimum capture size for pixelformat %"
2741 GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
2743 if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &max_w,
2745 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2746 "Could not probe maximum capture size for pixelformat %"
2747 GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
2750 /* Since we can't get framerate directly, try to use the current norm */
2751 if (v4l2object->tv_norm && v4l2object->norms) {
2753 GstTunerNorm *norm = NULL;
2754 GstTunerNorm *current =
2755 gst_v4l2_tuner_get_norm_by_std_id (v4l2object, v4l2object->tv_norm);
2757 for (norms = v4l2object->norms; norms != NULL; norms = norms->next) {
2758 norm = (GstTunerNorm *) norms->data;
2759 if (!strcmp (norm->label, current->label))
2762 /* If it's possible, set framerate to that (discrete) value */
2764 fix_num = gst_value_get_fraction_numerator (&norm->framerate);
2765 fix_denom = gst_value_get_fraction_denominator (&norm->framerate);
2769 tmp = gst_structure_copy (template);
2771 gst_structure_set (tmp, "framerate", GST_TYPE_FRACTION, fix_num,
2773 } else if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
2774 v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
2775 /* if norm can't be used, copy the template framerate */
2776 gst_structure_set (tmp, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1,
2781 gst_structure_set (tmp, "width", G_TYPE_INT, max_w, NULL);
2783 gst_structure_set (tmp, "width", GST_TYPE_INT_RANGE, min_w, max_w, NULL);
2786 gst_structure_set (tmp, "height", G_TYPE_INT, max_h, NULL);
2788 gst_structure_set (tmp, "height", GST_TYPE_INT_RANGE, min_h, max_h, NULL);
2790 gst_v4l2_object_add_aspect_ratio (v4l2object, tmp);
2792 if (!v4l2object->skip_try_fmt_probes) {
2793 /* We could consider setting interlace mode from min and max. */
2794 gst_v4l2_object_add_interlace_mode (v4l2object, tmp, max_w, max_h,
2796 /* We could consider to check colorspace for min too, in case it depends on
2797 * the size. But in this case, min and max could not be enough */
2798 gst_v4l2_object_add_colorspace (v4l2object, tmp, max_w, max_h,
2802 gst_v4l2_object_update_and_append (v4l2object, pixelformat, ret, tmp);
2808 gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
2809 guint32 pixelformat, gint * width, gint * height)
2811 struct v4l2_format fmt;
2812 gboolean ret = FALSE;
2813 GstVideoInterlaceMode interlace_mode;
2815 g_return_val_if_fail (width != NULL, FALSE);
2816 g_return_val_if_fail (height != NULL, FALSE);
2818 GST_LOG_OBJECT (v4l2object->dbg_obj,
2819 "getting nearest size to %dx%d with format %" GST_FOURCC_FORMAT,
2820 *width, *height, GST_FOURCC_ARGS (pixelformat));
2822 memset (&fmt, 0, sizeof (struct v4l2_format));
2824 /* get size delimiters */
2825 memset (&fmt, 0, sizeof (fmt));
2826 fmt.type = v4l2object->type;
2827 fmt.fmt.pix.width = *width;
2828 fmt.fmt.pix.height = *height;
2829 fmt.fmt.pix.pixelformat = pixelformat;
2830 fmt.fmt.pix.field = V4L2_FIELD_ANY;
2832 if (gst_v4l2_object_try_fmt (v4l2object, &fmt) < 0)
2835 GST_LOG_OBJECT (v4l2object->dbg_obj,
2836 "got nearest size %dx%d", fmt.fmt.pix.width, fmt.fmt.pix.height);
2838 *width = fmt.fmt.pix.width;
2839 *height = fmt.fmt.pix.height;
2841 if (!gst_v4l2_object_get_interlace_mode (fmt.fmt.pix.field, &interlace_mode)) {
2842 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2843 "Unsupported field type for %" GST_FOURCC_FORMAT "@%ux%u: %u",
2844 GST_FOURCC_ARGS (pixelformat), *width, *height, fmt.fmt.pix.field);
2852 GST_WARNING_OBJECT (v4l2object->dbg_obj,
2853 "Unable to try format: %s", g_strerror (errno));
2860 gst_v4l2_object_is_dmabuf_supported (GstV4l2Object * v4l2object)
2862 gboolean ret = TRUE;
2863 struct v4l2_exportbuffer expbuf = {
2864 .type = v4l2object->type,
2867 .flags = O_CLOEXEC | O_RDWR,
2870 /* Expected to fail, but ENOTTY tells us that it is not implemented. */
2871 v4l2object->ioctl (v4l2object->video_fd, VIDIOC_EXPBUF, &expbuf);
2872 if (errno == ENOTTY)
2879 gst_v4l2_object_setup_pool (GstV4l2Object * v4l2object, GstCaps * caps)
2883 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "initializing the %s system",
2884 V4L2_TYPE_IS_OUTPUT (v4l2object->type) ? "output" : "capture");
2886 GST_V4L2_CHECK_OPEN (v4l2object);
2887 GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
2889 /* find transport */
2890 mode = v4l2object->req_mode;
2892 if (v4l2object->device_caps & V4L2_CAP_READWRITE) {
2893 if (v4l2object->req_mode == GST_V4L2_IO_AUTO)
2894 mode = GST_V4L2_IO_RW;
2895 } else if (v4l2object->req_mode == GST_V4L2_IO_RW)
2896 goto method_not_supported;
2898 if (v4l2object->device_caps & V4L2_CAP_STREAMING) {
2899 if (v4l2object->req_mode == GST_V4L2_IO_AUTO) {
2900 if (!V4L2_TYPE_IS_OUTPUT (v4l2object->type) &&
2901 gst_v4l2_object_is_dmabuf_supported (v4l2object)) {
2902 mode = GST_V4L2_IO_DMABUF;
2904 mode = GST_V4L2_IO_MMAP;
2907 } else if (v4l2object->req_mode == GST_V4L2_IO_MMAP)
2908 goto method_not_supported;
2910 /* if still no transport selected, error out */
2911 if (mode == GST_V4L2_IO_AUTO)
2912 goto no_supported_capture_method;
2914 GST_INFO_OBJECT (v4l2object->dbg_obj, "accessing buffers via mode %d", mode);
2915 v4l2object->mode = mode;
2917 /* If min_buffers is not set, the driver either does not support the control or
2918 it has not been asked yet via propose_allocation/decide_allocation. */
2919 if (!v4l2object->min_buffers)
2920 gst_v4l2_get_driver_min_buffers (v4l2object);
2922 /* Map the buffers */
2923 GST_LOG_OBJECT (v4l2object->dbg_obj, "initiating buffer pool");
2925 if (!(v4l2object->pool = gst_v4l2_buffer_pool_new (v4l2object, caps)))
2926 goto buffer_pool_new_failed;
2928 GST_V4L2_SET_ACTIVE (v4l2object);
2933 buffer_pool_new_failed:
2935 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, READ,
2936 (_("Could not map buffers from device '%s'"),
2937 v4l2object->videodev),
2938 ("Failed to create buffer pool: %s", g_strerror (errno)));
2941 method_not_supported:
2943 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, READ,
2944 (_("The driver of device '%s' does not support the IO method %d"),
2945 v4l2object->videodev, mode), (NULL));
2948 no_supported_capture_method:
2950 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, READ,
2951 (_("The driver of device '%s' does not support any known IO "
2952 "method."), v4l2object->videodev), (NULL));
2958 gst_v4l2_object_set_stride (GstVideoInfo * info, GstVideoAlignment * align,
2959 gint plane, gint stride)
2961 const GstVideoFormatInfo *finfo = info->finfo;
2963 if (GST_VIDEO_FORMAT_INFO_IS_TILED (finfo)) {
2964 gint x_tiles, y_tiles, ws, hs, tile_height, padded_height;
2967 ws = GST_VIDEO_FORMAT_INFO_TILE_WS (finfo);
2968 hs = GST_VIDEO_FORMAT_INFO_TILE_HS (finfo);
2969 tile_height = 1 << hs;
2971 padded_height = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (finfo, plane,
2972 info->height + align->padding_top + align->padding_bottom);
2973 padded_height = GST_ROUND_UP_N (padded_height, tile_height);
2975 x_tiles = stride >> ws;
2976 y_tiles = padded_height >> hs;
2977 info->stride[plane] = GST_VIDEO_TILE_MAKE_STRIDE (x_tiles, y_tiles);
2979 info->stride[plane] = stride;
2984 gst_v4l2_object_extrapolate_info (GstV4l2Object * v4l2object,
2985 GstVideoInfo * info, GstVideoAlignment * align, gint stride)
2987 const GstVideoFormatInfo *finfo = info->finfo;
2988 gint i, estride, padded_height;
2991 g_return_if_fail (v4l2object->n_v4l2_planes == 1);
2993 padded_height = info->height + align->padding_top + align->padding_bottom;
2995 for (i = 0; i < finfo->n_planes; i++) {
2996 estride = gst_v4l2_object_extrapolate_stride (finfo, i, stride);
2998 gst_v4l2_object_set_stride (info, align, i, estride);
3000 info->offset[i] = offs;
3002 GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (finfo, i, padded_height);
3004 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
3005 "Extrapolated for plane %d with base stride %d: "
3006 "stride %d, offset %" G_GSIZE_FORMAT, i, stride, info->stride[i],
3010 /* Update the image size according the amount of data we are going to
3011 * read/write. This workaround bugs in driver where the sizeimage provided
3012 * by TRY/S_FMT represent the buffer length (maximum size) rather then the expected
3013 * bytesused (buffer size). */
3014 if (offs < info->size)
3019 gst_v4l2_object_save_format (GstV4l2Object * v4l2object,
3020 struct v4l2_fmtdesc *fmtdesc, struct v4l2_format *format,
3021 GstVideoInfo * info, GstVideoAlignment * align)
3023 const GstVideoFormatInfo *finfo = info->finfo;
3024 gboolean standard_stride = TRUE;
3025 gint stride, padded_width, padded_height, i;
3027 if (GST_VIDEO_INFO_FORMAT (info) == GST_VIDEO_FORMAT_ENCODED) {
3028 v4l2object->n_v4l2_planes = 1;
3029 info->size = format->fmt.pix.sizeimage;
3033 /* adjust right padding */
3034 if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type))
3035 stride = format->fmt.pix_mp.plane_fmt[0].bytesperline;
3037 stride = format->fmt.pix.bytesperline;
3039 padded_width = stride / GST_VIDEO_FORMAT_INFO_PSTRIDE (finfo, 0);
3041 if (padded_width < format->fmt.pix.width)
3042 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3043 "Driver bug detected, stride is too small for the width");
3045 align->padding_right = padded_width - info->width - align->padding_left;
3047 /* adjust bottom padding */
3048 padded_height = format->fmt.pix.height;
3050 if (GST_VIDEO_FORMAT_INFO_IS_TILED (finfo)) {
3051 guint hs, tile_height;
3053 hs = GST_VIDEO_FORMAT_INFO_TILE_HS (finfo);
3054 tile_height = 1 << hs;
3056 padded_height = GST_ROUND_UP_N (padded_height, tile_height);
3059 align->padding_bottom = padded_height - info->height - align->padding_top;
3061 /* setup the strides and offset */
3062 if (V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type)) {
3063 struct v4l2_pix_format_mplane *pix_mp = &format->fmt.pix_mp;
3065 /* figure out the frame layout */
3066 v4l2object->n_v4l2_planes = MAX (1, pix_mp->num_planes);
3068 for (i = 0; i < v4l2object->n_v4l2_planes; i++) {
3069 stride = pix_mp->plane_fmt[i].bytesperline;
3071 if (info->stride[i] != stride)
3072 standard_stride = FALSE;
3074 gst_v4l2_object_set_stride (info, align, i, stride);
3075 info->offset[i] = info->size;
3076 info->size += pix_mp->plane_fmt[i].sizeimage;
3079 /* Extrapolate stride if planar format are being set in 1 v4l2 plane */
3080 if (v4l2object->n_v4l2_planes < finfo->n_planes) {
3081 stride = format->fmt.pix_mp.plane_fmt[0].bytesperline;
3082 gst_v4l2_object_extrapolate_info (v4l2object, info, align, stride);
3085 /* only one plane in non-MPLANE mode */
3086 v4l2object->n_v4l2_planes = 1;
3087 info->size = format->fmt.pix.sizeimage;
3088 stride = format->fmt.pix.bytesperline;
3090 if (info->stride[0] != stride)
3091 standard_stride = FALSE;
3093 gst_v4l2_object_extrapolate_info (v4l2object, info, align, stride);
3096 /* adjust the offset to take into account left and top */
3097 if (GST_VIDEO_FORMAT_INFO_IS_TILED (finfo)) {
3098 if ((align->padding_left + align->padding_top) > 0)
3099 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3100 "Left and top padding is not permitted for tiled formats");
3102 for (i = 0; i < finfo->n_planes; i++) {
3105 /* FIXME we assume plane as component as this is true for all supported
3106 * format we support. */
3108 hedge = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, i, align->padding_left);
3109 vedge = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (finfo, i, align->padding_top);
3111 info->offset[i] += (vedge * info->stride[i]) +
3112 (hedge * GST_VIDEO_INFO_COMP_PSTRIDE (info, i));
3117 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Got sizeimage %" G_GSIZE_FORMAT,
3120 /* to avoid copies we need video meta if there is padding */
3121 v4l2object->need_video_meta =
3122 ((align->padding_top + align->padding_left + align->padding_right +
3123 align->padding_bottom) != 0);
3125 /* ... or if stride is non "standard" */
3126 if (!standard_stride)
3127 v4l2object->need_video_meta = TRUE;
3129 /* ... or also video meta if we use multiple, non-contiguous, planes */
3130 if (v4l2object->n_v4l2_planes > 1)
3131 v4l2object->need_video_meta = TRUE;
3133 v4l2object->info = *info;
3134 v4l2object->align = *align;
3135 v4l2object->format = *format;
3136 v4l2object->fmtdesc = fmtdesc;
3138 /* if we have a framerate pre-calculate duration */
3139 if (info->fps_n > 0 && info->fps_d > 0) {
3140 v4l2object->duration = gst_util_uint64_scale_int (GST_SECOND, info->fps_d,
3143 v4l2object->duration = GST_CLOCK_TIME_NONE;
3148 gst_v4l2_object_extrapolate_stride (const GstVideoFormatInfo * finfo,
3149 gint plane, gint stride)
3153 switch (finfo->format) {
3154 case GST_VIDEO_FORMAT_NV12:
3155 case GST_VIDEO_FORMAT_NV12_64Z32:
3156 case GST_VIDEO_FORMAT_NV21:
3157 case GST_VIDEO_FORMAT_NV16:
3158 case GST_VIDEO_FORMAT_NV61:
3159 case GST_VIDEO_FORMAT_NV24:
3160 estride = (plane == 0 ? 1 : 2) *
3161 GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, plane, stride);
3164 estride = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, plane, stride);
3172 gst_v4l2_object_set_format_full (GstV4l2Object * v4l2object, GstCaps * caps,
3173 gboolean try_only, GstV4l2Error * error)
3175 gint fd = v4l2object->video_fd;
3176 struct v4l2_format format;
3177 struct v4l2_streamparm streamparm;
3178 enum v4l2_field field;
3179 guint32 pixelformat;
3180 struct v4l2_fmtdesc *fmtdesc;
3182 GstVideoAlignment align;
3183 gint width, height, fps_n, fps_d;
3187 enum v4l2_colorspace colorspace = 0;
3188 enum v4l2_quantization range = 0;
3189 enum v4l2_ycbcr_encoding matrix = 0;
3190 enum v4l2_xfer_func transfer = 0;
3193 g_return_val_if_fail (!v4l2object->skip_try_fmt_probes ||
3194 gst_caps_is_writable (caps), FALSE);
3196 GST_V4L2_CHECK_OPEN (v4l2object);
3198 GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
3200 is_mplane = V4L2_TYPE_IS_MULTIPLANAR (v4l2object->type);
3202 gst_video_info_init (&info);
3203 gst_video_alignment_reset (&align);
3205 if (!gst_v4l2_object_get_caps_info (v4l2object, caps, &fmtdesc, &info))
3208 pixelformat = fmtdesc->pixelformat;
3209 width = GST_VIDEO_INFO_WIDTH (&info);
3210 height = GST_VIDEO_INFO_HEIGHT (&info);
3211 fps_n = GST_VIDEO_INFO_FPS_N (&info);
3212 fps_d = GST_VIDEO_INFO_FPS_D (&info);
3214 /* if encoded format (GST_VIDEO_INFO_N_PLANES return 0)
3215 * or if contiguous is prefered */
3216 n_v4l_planes = GST_VIDEO_INFO_N_PLANES (&info);
3217 if (!n_v4l_planes || !v4l2object->prefered_non_contiguous)
3220 if (GST_VIDEO_INFO_IS_INTERLACED (&info)) {
3221 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "interlaced video");
3222 /* ideally we would differentiate between types of interlaced video
3223 * but there is not sufficient information in the caps..
3225 field = V4L2_FIELD_INTERLACED;
3227 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "progressive video");
3228 field = V4L2_FIELD_NONE;
3231 if (V4L2_TYPE_IS_OUTPUT (v4l2object->type)) {
3232 /* We first pick th main colorspace from the primaries */
3233 switch (info.colorimetry.primaries) {
3234 case GST_VIDEO_COLOR_PRIMARIES_BT709:
3235 /* There is two colorspaces using these primaries, use the range to
3237 if (info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235)
3238 colorspace = V4L2_COLORSPACE_REC709;
3240 colorspace = V4L2_COLORSPACE_SRGB;
3242 case GST_VIDEO_COLOR_PRIMARIES_BT2020:
3243 colorspace = V4L2_COLORSPACE_BT2020;
3245 case GST_VIDEO_COLOR_PRIMARIES_BT470M:
3246 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
3248 case GST_VIDEO_COLOR_PRIMARIES_BT470BG:
3249 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
3251 case GST_VIDEO_COLOR_PRIMARIES_SMPTE170M:
3252 colorspace = V4L2_COLORSPACE_SMPTE170M;
3254 case GST_VIDEO_COLOR_PRIMARIES_SMPTE240M:
3255 colorspace = V4L2_COLORSPACE_SMPTE240M;
3258 case GST_VIDEO_COLOR_PRIMARIES_FILM:
3259 case GST_VIDEO_COLOR_PRIMARIES_UNKNOWN:
3260 /* We don't know, we will guess */
3264 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3265 "Unknown colorimetry primaries %d", info.colorimetry.primaries);
3269 switch (info.colorimetry.range) {
3270 case GST_VIDEO_COLOR_RANGE_0_255:
3271 range = V4L2_QUANTIZATION_FULL_RANGE;
3273 case GST_VIDEO_COLOR_RANGE_16_235:
3274 range = V4L2_QUANTIZATION_LIM_RANGE;
3276 case GST_VIDEO_COLOR_RANGE_UNKNOWN:
3277 /* We let the driver pick a default one */
3280 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3281 "Unknown colorimetry range %d", info.colorimetry.range);
3285 switch (info.colorimetry.matrix) {
3286 case GST_VIDEO_COLOR_MATRIX_RGB:
3287 /* Unspecified, leave to default */
3289 /* FCC is about the same as BT601 with less digit */
3290 case GST_VIDEO_COLOR_MATRIX_FCC:
3291 case GST_VIDEO_COLOR_MATRIX_BT601:
3292 matrix = V4L2_YCBCR_ENC_601;
3294 case GST_VIDEO_COLOR_MATRIX_BT709:
3295 matrix = V4L2_YCBCR_ENC_709;
3297 case GST_VIDEO_COLOR_MATRIX_SMPTE240M:
3298 matrix = V4L2_YCBCR_ENC_SMPTE240M;
3300 case GST_VIDEO_COLOR_MATRIX_BT2020:
3301 matrix = V4L2_YCBCR_ENC_BT2020;
3303 case GST_VIDEO_COLOR_MATRIX_UNKNOWN:
3304 /* We let the driver pick a default one */
3307 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3308 "Unknown colorimetry matrix %d", info.colorimetry.matrix);
3312 switch (info.colorimetry.transfer) {
3313 case GST_VIDEO_TRANSFER_GAMMA18:
3314 case GST_VIDEO_TRANSFER_GAMMA20:
3315 case GST_VIDEO_TRANSFER_GAMMA22:
3316 case GST_VIDEO_TRANSFER_GAMMA28:
3317 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3318 "GAMMA 18, 20, 22, 28 transfer functions not supported");
3320 case GST_VIDEO_TRANSFER_GAMMA10:
3321 transfer = V4L2_XFER_FUNC_NONE;
3323 case GST_VIDEO_TRANSFER_BT2020_12:
3324 case GST_VIDEO_TRANSFER_BT709:
3325 transfer = V4L2_XFER_FUNC_709;
3327 case GST_VIDEO_TRANSFER_SMPTE240M:
3328 transfer = V4L2_XFER_FUNC_SMPTE240M;
3330 case GST_VIDEO_TRANSFER_SRGB:
3331 transfer = V4L2_XFER_FUNC_SRGB;
3333 case GST_VIDEO_TRANSFER_LOG100:
3334 case GST_VIDEO_TRANSFER_LOG316:
3335 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3336 "LOG 100, 316 transfer functions not supported");
3337 /* FIXME No known sensible default, maybe AdobeRGB ? */
3339 case GST_VIDEO_TRANSFER_UNKNOWN:
3340 /* We let the driver pick a default one */
3343 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3344 "Unknown colorimetry tranfer %d", info.colorimetry.transfer);
3348 if (colorspace == 0) {
3349 /* Try to guess colorspace according to pixelformat and size */
3350 if (GST_VIDEO_INFO_IS_YUV (&info)) {
3351 /* SD streams likely use SMPTE170M and HD streams REC709 */
3352 if (width <= 720 && height <= 576)
3353 colorspace = V4L2_COLORSPACE_SMPTE170M;
3355 colorspace = V4L2_COLORSPACE_REC709;
3356 } else if (GST_VIDEO_INFO_IS_RGB (&info)) {
3357 colorspace = V4L2_COLORSPACE_SRGB;
3358 transfer = V4L2_XFER_FUNC_NONE;
3363 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Desired format %dx%d, format "
3364 "%" GST_FOURCC_FORMAT " stride: %d", width, height,
3365 GST_FOURCC_ARGS (pixelformat), GST_VIDEO_INFO_PLANE_STRIDE (&info, 0));
3367 memset (&format, 0x00, sizeof (struct v4l2_format));
3368 format.type = v4l2object->type;
3371 format.type = v4l2object->type;
3372 format.fmt.pix_mp.pixelformat = pixelformat;
3373 format.fmt.pix_mp.width = width;
3374 format.fmt.pix_mp.height = height;
3375 format.fmt.pix_mp.field = field;
3376 format.fmt.pix_mp.num_planes = n_v4l_planes;
3378 /* try to ask our prefered stride but it's not a failure if not
3380 for (i = 0; i < n_v4l_planes; i++) {
3381 gint stride = GST_VIDEO_INFO_PLANE_STRIDE (&info, i);
3383 if (GST_VIDEO_FORMAT_INFO_IS_TILED (info.finfo))
3384 stride = GST_VIDEO_TILE_X_TILES (stride) <<
3385 GST_VIDEO_FORMAT_INFO_TILE_WS (info.finfo);
3387 format.fmt.pix_mp.plane_fmt[i].bytesperline = stride;
3390 if (GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_ENCODED)
3391 format.fmt.pix_mp.plane_fmt[0].sizeimage = ENCODED_BUFFER_SIZE;
3393 gint stride = GST_VIDEO_INFO_PLANE_STRIDE (&info, 0);
3395 format.type = v4l2object->type;
3397 format.fmt.pix.width = width;
3398 format.fmt.pix.height = height;
3399 format.fmt.pix.pixelformat = pixelformat;
3400 format.fmt.pix.field = field;
3402 if (GST_VIDEO_FORMAT_INFO_IS_TILED (info.finfo))
3403 stride = GST_VIDEO_TILE_X_TILES (stride) <<
3404 GST_VIDEO_FORMAT_INFO_TILE_WS (info.finfo);
3406 /* try to ask our prefered stride */
3407 format.fmt.pix.bytesperline = stride;
3409 if (GST_VIDEO_INFO_FORMAT (&info) == GST_VIDEO_FORMAT_ENCODED)
3410 format.fmt.pix.sizeimage = ENCODED_BUFFER_SIZE;
3413 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Desired format is %dx%d, format "
3414 "%" GST_FOURCC_FORMAT ", nb planes %d", format.fmt.pix.width,
3415 format.fmt.pix_mp.height,
3416 GST_FOURCC_ARGS (format.fmt.pix.pixelformat),
3417 is_mplane ? format.fmt.pix_mp.num_planes : 1);
3419 #ifndef GST_DISABLE_GST_DEBUG
3421 for (i = 0; i < format.fmt.pix_mp.num_planes; i++)
3422 GST_DEBUG_OBJECT (v4l2object->dbg_obj, " stride %d",
3423 format.fmt.pix_mp.plane_fmt[i].bytesperline);
3425 GST_DEBUG_OBJECT (v4l2object->dbg_obj, " stride %d",
3426 format.fmt.pix.bytesperline);
3430 if (V4L2_TYPE_IS_OUTPUT (v4l2object->type)) {
3432 format.fmt.pix_mp.colorspace = colorspace;
3433 format.fmt.pix_mp.quantization = range;
3434 format.fmt.pix_mp.ycbcr_enc = matrix;
3435 format.fmt.pix_mp.xfer_func = transfer;
3437 format.fmt.pix.colorspace = colorspace;
3438 format.fmt.pix.quantization = range;
3439 format.fmt.pix.ycbcr_enc = matrix;
3440 format.fmt.pix.xfer_func = transfer;
3443 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Desired colorspace is %d:%d:%d:%d",
3444 colorspace, range, matrix, transfer);
3448 if (v4l2object->ioctl (fd, VIDIOC_TRY_FMT, &format) < 0)
3449 goto try_fmt_failed;
3451 if (v4l2object->ioctl (fd, VIDIOC_S_FMT, &format) < 0)
3452 goto set_fmt_failed;
3455 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Got format of %dx%d, format "
3456 "%" GST_FOURCC_FORMAT ", nb planes %d, colorspace %d",
3457 format.fmt.pix.width, format.fmt.pix_mp.height,
3458 GST_FOURCC_ARGS (format.fmt.pix.pixelformat),
3459 is_mplane ? format.fmt.pix_mp.num_planes : 1,
3460 is_mplane ? format.fmt.pix_mp.colorspace : format.fmt.pix.colorspace);
3462 #ifndef GST_DISABLE_GST_DEBUG
3464 for (i = 0; i < format.fmt.pix_mp.num_planes; i++)
3465 GST_DEBUG_OBJECT (v4l2object->dbg_obj, " stride %d, sizeimage %d",
3466 format.fmt.pix_mp.plane_fmt[i].bytesperline,
3467 format.fmt.pix_mp.plane_fmt[i].sizeimage);
3469 GST_DEBUG_OBJECT (v4l2object->dbg_obj, " stride %d, sizeimage %d",
3470 format.fmt.pix.bytesperline, format.fmt.pix.sizeimage);
3474 if (format.fmt.pix.pixelformat != pixelformat)
3475 goto invalid_pixelformat;
3477 /* Only negotiate size with raw data.
3478 * For some codecs the dimensions are *not* in the bitstream, IIRC VC1
3479 * in ASF mode for example, there is also not reason for a driver to
3480 * change the size. */
3481 if (info.finfo->format != GST_VIDEO_FORMAT_ENCODED) {
3482 /* We can crop larger images */
3483 if (format.fmt.pix.width < width || format.fmt.pix.height < height)
3484 goto invalid_dimensions;
3486 /* Note, this will be adjusted if upstream has non-centered cropping. */
3487 align.padding_top = 0;
3488 align.padding_bottom = format.fmt.pix.height - height;
3489 align.padding_left = 0;
3490 align.padding_right = format.fmt.pix.width - width;
3493 if (is_mplane && format.fmt.pix_mp.num_planes != n_v4l_planes)
3494 goto invalid_planes;
3496 if ((is_mplane && format.fmt.pix_mp.field != field)
3497 || format.fmt.pix.field != field)
3500 gst_v4l2_object_get_colorspace (&format, &info.colorimetry);
3502 s = gst_caps_get_structure (caps, 0);
3503 if (gst_structure_has_field (s, "colorimetry")) {
3504 GstVideoColorimetry ci;
3505 if (!gst_video_colorimetry_from_string (&ci,
3506 gst_structure_get_string (s, "colorimetry"))
3507 || !gst_video_colorimetry_is_equal (&ci, &info.colorimetry))
3508 goto invalid_colorimetry;
3511 /* In case we have skipped the try_fmt probes, we'll need to set the
3512 * colorimetry and interlace-mode back into the caps. */
3513 if (v4l2object->skip_try_fmt_probes) {
3514 if (!gst_structure_has_field (s, "colorimetry")) {
3515 gchar *str = gst_video_colorimetry_to_string (&info.colorimetry);
3516 gst_structure_set (s, "colorimetry", G_TYPE_STRING, str, NULL);
3520 if (!gst_structure_has_field (s, "interlace-mode"))
3521 gst_structure_set (s, "interlace-mode", G_TYPE_STRING,
3522 gst_video_interlace_mode_to_string (info.interlace_mode), NULL);
3525 if (try_only) /* good enough for trying only */
3528 if (GST_VIDEO_INFO_HAS_ALPHA (&info)) {
3529 struct v4l2_control ctl = { 0, };
3530 ctl.id = V4L2_CID_ALPHA_COMPONENT;
3533 if (v4l2object->ioctl (fd, VIDIOC_S_CTRL, &ctl) < 0)
3534 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3535 "Failed to set alpha component value");
3538 /* Is there a reason we require the caller to always specify a framerate? */
3539 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Desired framerate: %u/%u", fps_n,
3542 memset (&streamparm, 0x00, sizeof (struct v4l2_streamparm));
3543 streamparm.type = v4l2object->type;
3545 if (v4l2object->ioctl (fd, VIDIOC_G_PARM, &streamparm) < 0)
3546 goto get_parm_failed;
3548 if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE
3549 || v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
3550 GST_VIDEO_INFO_FPS_N (&info) =
3551 streamparm.parm.capture.timeperframe.denominator;
3552 GST_VIDEO_INFO_FPS_D (&info) =
3553 streamparm.parm.capture.timeperframe.numerator;
3555 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Got capture framerate: %u/%u",
3556 streamparm.parm.capture.timeperframe.denominator,
3557 streamparm.parm.capture.timeperframe.numerator);
3559 /* We used to skip frame rate setup if the camera was already setup
3560 * with the requested frame rate. This breaks some cameras though,
3561 * causing them to not output data (several models of Thinkpad cameras
3562 * have this problem at least).
3563 * So, don't skip. */
3564 GST_LOG_OBJECT (v4l2object->dbg_obj, "Setting capture framerate to %u/%u",
3566 /* We want to change the frame rate, so check whether we can. Some cheap USB
3567 * cameras don't have the capability */
3568 if ((streamparm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) == 0) {
3569 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
3570 "Not setting capture framerate (not supported)");
3574 /* Note: V4L2 wants the frame interval, we have the frame rate */
3575 streamparm.parm.capture.timeperframe.numerator = fps_d;
3576 streamparm.parm.capture.timeperframe.denominator = fps_n;
3578 /* some cheap USB cam's won't accept any change */
3579 if (v4l2object->ioctl (fd, VIDIOC_S_PARM, &streamparm) < 0)
3580 goto set_parm_failed;
3582 if (streamparm.parm.capture.timeperframe.numerator > 0 &&
3583 streamparm.parm.capture.timeperframe.denominator > 0) {
3584 /* get new values */
3585 fps_d = streamparm.parm.capture.timeperframe.numerator;
3586 fps_n = streamparm.parm.capture.timeperframe.denominator;
3588 GST_INFO_OBJECT (v4l2object->dbg_obj, "Set capture framerate to %u/%u",
3591 /* fix v4l2 capture driver to provide framerate values */
3592 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3593 "Reuse caps framerate %u/%u - fix v4l2 capture driver", fps_n, fps_d);
3596 GST_VIDEO_INFO_FPS_N (&info) = fps_n;
3597 GST_VIDEO_INFO_FPS_D (&info) = fps_d;
3598 } else if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT
3599 || v4l2object->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
3600 GST_VIDEO_INFO_FPS_N (&info) =
3601 streamparm.parm.output.timeperframe.denominator;
3602 GST_VIDEO_INFO_FPS_D (&info) =
3603 streamparm.parm.output.timeperframe.numerator;
3605 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Got output framerate: %u/%u",
3606 streamparm.parm.output.timeperframe.denominator,
3607 streamparm.parm.output.timeperframe.numerator);
3609 GST_LOG_OBJECT (v4l2object->dbg_obj, "Setting output framerate to %u/%u",
3611 if ((streamparm.parm.output.capability & V4L2_CAP_TIMEPERFRAME) == 0) {
3612 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
3613 "Not setting output framerate (not supported)");
3617 /* Note: V4L2 wants the frame interval, we have the frame rate */
3618 streamparm.parm.output.timeperframe.numerator = fps_d;
3619 streamparm.parm.output.timeperframe.denominator = fps_n;
3621 if (v4l2object->ioctl (fd, VIDIOC_S_PARM, &streamparm) < 0)
3622 goto set_parm_failed;
3624 if (streamparm.parm.output.timeperframe.numerator > 0 &&
3625 streamparm.parm.output.timeperframe.denominator > 0) {
3626 /* get new values */
3627 fps_d = streamparm.parm.output.timeperframe.numerator;
3628 fps_n = streamparm.parm.output.timeperframe.denominator;
3630 GST_INFO_OBJECT (v4l2object->dbg_obj, "Set output framerate to %u/%u",
3633 /* fix v4l2 output driver to provide framerate values */
3634 GST_WARNING_OBJECT (v4l2object->dbg_obj,
3635 "Reuse caps framerate %u/%u - fix v4l2 output driver", fps_n, fps_d);
3638 GST_VIDEO_INFO_FPS_N (&info) = fps_n;
3639 GST_VIDEO_INFO_FPS_D (&info) = fps_d;
3643 /* add boolean return, so we can fail on drivers bugs */
3644 gst_v4l2_object_save_format (v4l2object, fmtdesc, &format, &info, &align);
3646 /* now configure the pool */
3647 if (!gst_v4l2_object_setup_pool (v4l2object, caps))
3655 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "can't parse caps %" GST_PTR_FORMAT,
3661 if (errno == EINVAL) {
3662 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3663 (_("Device '%s' has no supported format"), v4l2object->videodev),
3664 ("Call to TRY_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
3665 GST_FOURCC_ARGS (pixelformat), width, height,
3666 g_strerror (errno)));
3668 GST_V4L2_ERROR (error, RESOURCE, FAILED,
3669 (_("Device '%s' failed during initialization"),
3670 v4l2object->videodev),
3671 ("Call to TRY_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
3672 GST_FOURCC_ARGS (pixelformat), width, height,
3673 g_strerror (errno)));
3679 if (errno == EBUSY) {
3680 GST_V4L2_ERROR (error, RESOURCE, BUSY,
3681 (_("Device '%s' is busy"), v4l2object->videodev),
3682 ("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
3683 GST_FOURCC_ARGS (pixelformat), width, height,
3684 g_strerror (errno)));
3685 } else if (errno == EINVAL) {
3686 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3687 (_("Device '%s' has no supported format"), v4l2object->videodev),
3688 ("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
3689 GST_FOURCC_ARGS (pixelformat), width, height,
3690 g_strerror (errno)));
3692 GST_V4L2_ERROR (error, RESOURCE, FAILED,
3693 (_("Device '%s' failed during initialization"),
3694 v4l2object->videodev),
3695 ("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
3696 GST_FOURCC_ARGS (pixelformat), width, height,
3697 g_strerror (errno)));
3703 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3704 (_("Device '%s' cannot capture at %dx%d"),
3705 v4l2object->videodev, width, height),
3706 ("Tried to capture at %dx%d, but device returned size %dx%d",
3707 width, height, format.fmt.pix.width, format.fmt.pix.height));
3710 invalid_pixelformat:
3712 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3713 (_("Device '%s' cannot capture in the specified format"),
3714 v4l2object->videodev),
3715 ("Tried to capture in %" GST_FOURCC_FORMAT
3716 ", but device returned format" " %" GST_FOURCC_FORMAT,
3717 GST_FOURCC_ARGS (pixelformat),
3718 GST_FOURCC_ARGS (format.fmt.pix.pixelformat)));
3723 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3724 (_("Device '%s' does support non-contiguous planes"),
3725 v4l2object->videodev),
3726 ("Device wants %d planes", format.fmt.pix_mp.num_planes));
3731 enum v4l2_field wanted_field;
3734 wanted_field = format.fmt.pix_mp.field;
3736 wanted_field = format.fmt.pix.field;
3738 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3739 (_("Device '%s' does not support %s interlacing"),
3740 v4l2object->videodev,
3741 field == V4L2_FIELD_NONE ? "progressive" : "interleaved"),
3742 ("Device wants %s interlacing",
3743 wanted_field == V4L2_FIELD_NONE ? "progressive" : "interleaved"));
3746 invalid_colorimetry:
3748 gchar *wanted_colorimetry;
3750 wanted_colorimetry = gst_video_colorimetry_to_string (&info.colorimetry);
3752 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3753 (_("Device '%s' does not support %s colorimetry"),
3754 v4l2object->videodev, gst_structure_get_string (s, "colorimetry")),
3755 ("Device wants %s colorimetry", wanted_colorimetry));
3757 g_free (wanted_colorimetry);
3762 /* it's possible that this call is not supported */
3763 if (errno != EINVAL && errno != ENOTTY) {
3764 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3765 (_("Could not get parameters on device '%s'"),
3766 v4l2object->videodev), GST_ERROR_SYSTEM);
3772 GST_V4L2_ERROR (error, RESOURCE, SETTINGS,
3773 (_("Video device did not accept new frame rate setting.")),
3779 /* setup_pool already send the error */
3785 gst_v4l2_object_set_format (GstV4l2Object * v4l2object, GstCaps * caps,
3786 GstV4l2Error * error)
3788 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Setting format to %" GST_PTR_FORMAT,
3790 return gst_v4l2_object_set_format_full (v4l2object, caps, FALSE, error);
3794 gst_v4l2_object_try_format (GstV4l2Object * v4l2object, GstCaps * caps,
3795 GstV4l2Error * error)
3797 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "Trying format %" GST_PTR_FORMAT,
3799 return gst_v4l2_object_set_format_full (v4l2object, caps, TRUE, error);
3803 * gst_v4l2_object_acquire_format:
3804 * @v4l2object the object
3805 * @info a GstVideoInfo to be filled
3807 * Acquire the driver choosen format. This is useful in decoder or encoder elements where
3808 * the output format is choosen by the HW.
3810 * Returns: %TRUE on success, %FALSE on failure.
3813 gst_v4l2_object_acquire_format (GstV4l2Object * v4l2object, GstVideoInfo * info)
3815 struct v4l2_fmtdesc *fmtdesc;
3816 struct v4l2_format fmt;
3817 struct v4l2_crop crop;
3818 struct v4l2_selection sel;
3819 struct v4l2_rect *r = NULL;
3820 GstVideoFormat format;
3821 guint width, height;
3822 GstVideoAlignment align;
3824 gst_video_info_init (info);
3825 gst_video_alignment_reset (&align);
3827 memset (&fmt, 0x00, sizeof (struct v4l2_format));
3828 fmt.type = v4l2object->type;
3829 if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_G_FMT, &fmt) < 0)
3830 goto get_fmt_failed;
3832 fmtdesc = gst_v4l2_object_get_format_from_fourcc (v4l2object,
3833 fmt.fmt.pix.pixelformat);
3834 if (fmtdesc == NULL)
3835 goto unsupported_format;
3837 /* No need to care about mplane, the four first params are the same */
3838 format = gst_v4l2_object_v4l2fourcc_to_video_format (fmt.fmt.pix.pixelformat);
3840 /* fails if we do no translate the fmt.pix.pixelformat to GstVideoFormat */
3841 if (format == GST_VIDEO_FORMAT_UNKNOWN)
3842 goto unsupported_format;
3844 if (fmt.fmt.pix.width == 0 || fmt.fmt.pix.height == 0)
3845 goto invalid_dimensions;
3847 width = fmt.fmt.pix.width;
3848 height = fmt.fmt.pix.height;
3850 /* Use the default compose rectangle */
3851 memset (&sel, 0, sizeof (struct v4l2_selection));
3852 sel.type = v4l2object->type;
3853 sel.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
3854 if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_G_SELECTION, &sel) >= 0) {
3857 /* For ancient kernels, fall back to G_CROP */
3858 memset (&crop, 0, sizeof (struct v4l2_crop));
3859 crop.type = v4l2object->type;
3860 if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_G_CROP, &crop) >= 0)
3864 align.padding_left = r->left;
3865 align.padding_top = r->top;
3866 align.padding_right = width - r->width - r->left;
3867 align.padding_bottom = height - r->height - r->top;
3872 gst_video_info_set_format (info, format, width, height);
3874 switch (fmt.fmt.pix.field) {
3875 case V4L2_FIELD_ANY:
3876 case V4L2_FIELD_NONE:
3877 info->interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
3879 case V4L2_FIELD_INTERLACED:
3880 case V4L2_FIELD_INTERLACED_TB:
3881 case V4L2_FIELD_INTERLACED_BT:
3882 info->interlace_mode = GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
3885 goto unsupported_field;
3888 gst_v4l2_object_get_colorspace (&fmt, &info->colorimetry);
3890 gst_v4l2_object_save_format (v4l2object, fmtdesc, &fmt, info, &align);
3892 /* Shall we setup the pool ? */
3898 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
3899 (_("Video device did not provide output format.")), GST_ERROR_SYSTEM);
3904 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
3905 (_("Video device returned invalid dimensions.")),
3906 ("Expected non 0 dimensions, got %dx%d", fmt.fmt.pix.width,
3907 fmt.fmt.pix.height));
3912 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
3913 (_("Video device uses an unsupported interlacing method.")),
3914 ("V4L2 field type %d not supported", fmt.fmt.pix.field));
3919 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
3920 (_("Video device uses an unsupported pixel format.")),
3921 ("V4L2 format %" GST_FOURCC_FORMAT " not supported",
3922 GST_FOURCC_ARGS (fmt.fmt.pix.pixelformat)));
3928 gst_v4l2_object_set_crop (GstV4l2Object * obj)
3930 struct v4l2_crop crop = { 0 };
3932 crop.type = obj->type;
3933 crop.c.left = obj->align.padding_left;
3934 crop.c.top = obj->align.padding_top;
3935 crop.c.width = obj->info.width;
3936 crop.c.height = obj->info.height;
3938 if (obj->align.padding_left + obj->align.padding_top +
3939 obj->align.padding_right + obj->align.padding_bottom == 0) {
3940 GST_DEBUG_OBJECT (obj->dbg_obj, "no cropping needed");
3944 GST_DEBUG_OBJECT (obj->dbg_obj,
3945 "Desired cropping left %u, top %u, size %ux%u", crop.c.left, crop.c.top,
3946 crop.c.width, crop.c.height);
3948 if (obj->ioctl (obj->video_fd, VIDIOC_S_CROP, &crop) < 0) {
3949 GST_WARNING_OBJECT (obj->dbg_obj, "VIDIOC_S_CROP failed");
3953 if (obj->ioctl (obj->video_fd, VIDIOC_G_CROP, &crop) < 0) {
3954 GST_WARNING_OBJECT (obj->dbg_obj, "VIDIOC_G_CROP failed");
3958 GST_DEBUG_OBJECT (obj->dbg_obj,
3959 "Got cropping left %u, top %u, size %ux%u", crop.c.left, crop.c.top,
3960 crop.c.width, crop.c.height);
3966 gst_v4l2_object_caps_equal (GstV4l2Object * v4l2object, GstCaps * caps)
3968 GstStructure *config;
3972 if (!v4l2object->pool)
3975 config = gst_buffer_pool_get_config (v4l2object->pool);
3976 gst_buffer_pool_config_get_params (config, &oldcaps, NULL, NULL, NULL);
3978 ret = oldcaps && gst_caps_is_equal (caps, oldcaps);
3980 gst_structure_free (config);
3986 gst_v4l2_object_unlock (GstV4l2Object * v4l2object)
3988 gboolean ret = TRUE;
3990 GST_LOG_OBJECT (v4l2object->dbg_obj, "start flushing");
3992 if (v4l2object->pool && gst_buffer_pool_is_active (v4l2object->pool))
3993 gst_buffer_pool_set_flushing (v4l2object->pool, TRUE);
3999 gst_v4l2_object_unlock_stop (GstV4l2Object * v4l2object)
4001 gboolean ret = TRUE;
4003 GST_LOG_OBJECT (v4l2object->dbg_obj, "stop flushing");
4005 if (v4l2object->pool && gst_buffer_pool_is_active (v4l2object->pool))
4006 gst_buffer_pool_set_flushing (v4l2object->pool, FALSE);
4012 gst_v4l2_object_stop (GstV4l2Object * v4l2object)
4014 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "stopping");
4016 if (!GST_V4L2_IS_OPEN (v4l2object))
4018 if (!GST_V4L2_IS_ACTIVE (v4l2object))
4021 if (v4l2object->pool) {
4022 GST_DEBUG_OBJECT (v4l2object->dbg_obj, "deactivating pool");
4023 gst_buffer_pool_set_active (v4l2object->pool, FALSE);
4024 gst_object_unref (v4l2object->pool);
4025 v4l2object->pool = NULL;
4028 GST_V4L2_SET_INACTIVE (v4l2object);
4035 gst_v4l2_object_probe_caps (GstV4l2Object * v4l2object, GstCaps * filter)
4041 formats = gst_v4l2_object_get_format_list (v4l2object);
4043 ret = gst_caps_new_empty ();
4045 if (v4l2object->keep_aspect && !v4l2object->par) {
4046 struct v4l2_cropcap cropcap;
4048 memset (&cropcap, 0, sizeof (cropcap));
4050 cropcap.type = v4l2object->type;
4051 if (v4l2object->ioctl (v4l2object->video_fd, VIDIOC_CROPCAP, &cropcap) < 0) {
4052 if (errno != ENOTTY)
4053 GST_WARNING_OBJECT (v4l2object->dbg_obj,
4054 "Failed to probe pixel aspect ratio with VIDIOC_CROPCAP: %s",
4055 g_strerror (errno));
4057 v4l2object->par = g_new0 (GValue, 1);
4058 g_value_init (v4l2object->par, GST_TYPE_FRACTION);
4059 gst_value_set_fraction (v4l2object->par, cropcap.pixelaspect.numerator,
4060 cropcap.pixelaspect.denominator);
4064 for (walk = formats; walk; walk = walk->next) {
4065 struct v4l2_fmtdesc *format;
4066 GstStructure *template;
4069 format = (struct v4l2_fmtdesc *) walk->data;
4071 template = gst_v4l2_object_v4l2fourcc_to_bare_struct (format->pixelformat);
4074 GST_DEBUG_OBJECT (v4l2object->dbg_obj,
4075 "unknown format %" GST_FOURCC_FORMAT,
4076 GST_FOURCC_ARGS (format->pixelformat));
4080 /* If we have a filter, check if we need to probe this format or not */
4082 GstCaps *format_caps = gst_caps_new_empty ();
4084 gst_caps_append_structure (format_caps, gst_structure_copy (template));
4086 if (!gst_caps_can_intersect (format_caps, filter)) {
4087 gst_caps_unref (format_caps);
4088 gst_structure_free (template);
4092 gst_caps_unref (format_caps);
4095 tmp = gst_v4l2_object_probe_caps_for_format (v4l2object,
4096 format->pixelformat, template);
4098 gst_caps_append (ret, tmp);
4100 gst_structure_free (template);
4107 ret = gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
4108 gst_caps_unref (tmp);
4111 GST_INFO_OBJECT (v4l2object->dbg_obj, "probed caps: %" GST_PTR_FORMAT, ret);
4117 gst_v4l2_object_get_caps (GstV4l2Object * v4l2object, GstCaps * filter)
4121 if (v4l2object->probed_caps == NULL)
4122 v4l2object->probed_caps = gst_v4l2_object_probe_caps (v4l2object, NULL);
4125 ret = gst_caps_intersect_full (filter, v4l2object->probed_caps,
4126 GST_CAPS_INTERSECT_FIRST);
4128 ret = gst_caps_ref (v4l2object->probed_caps);
4135 gst_v4l2_object_decide_allocation (GstV4l2Object * obj, GstQuery * query)
4138 GstBufferPool *pool = NULL, *other_pool = NULL;
4139 GstStructure *config;
4140 guint size, min, max, own_min = 0;
4142 gboolean has_video_meta;
4143 gboolean can_share_own_pool, pushing_from_our_pool = FALSE;
4144 GstAllocator *allocator = NULL;
4145 GstAllocationParams params = { 0 };
4147 GST_DEBUG_OBJECT (obj->dbg_obj, "decide allocation");
4149 g_return_val_if_fail (obj->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
4150 obj->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, FALSE);
4152 gst_query_parse_allocation (query, &caps, NULL);
4154 if (obj->pool == NULL) {
4155 if (!gst_v4l2_object_setup_pool (obj, caps))
4159 if (gst_query_get_n_allocation_params (query) > 0)
4160 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
4162 if (gst_query_get_n_allocation_pools (query) > 0) {
4163 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
4172 GST_DEBUG_OBJECT (obj->dbg_obj, "allocation: size:%u min:%u max:%u pool:%"
4173 GST_PTR_FORMAT, size, min, max, pool);
4176 gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
4178 can_share_own_pool = (has_video_meta || !obj->need_video_meta);
4180 gst_v4l2_get_driver_min_buffers (obj);
4181 /* We can't share our own pool, if it exceed V4L2 capacity */
4182 if (min + obj->min_buffers + 1 > VIDEO_MAX_FRAME)
4183 can_share_own_pool = FALSE;
4186 switch (obj->mode) {
4187 case GST_V4L2_IO_RW:
4189 /* in READ/WRITE mode, prefer a downstream pool because our own pool
4190 * doesn't help much, we have to write to it as well */
4191 GST_DEBUG_OBJECT (obj->dbg_obj,
4192 "read/write mode: using downstream pool");
4193 /* use the bigest size, when we use our own pool we can't really do any
4194 * other size than what the hardware gives us but for downstream pools
4196 size = MAX (size, obj->info.size);
4197 } else if (can_share_own_pool) {
4198 /* no downstream pool, use our own then */
4199 GST_DEBUG_OBJECT (obj->dbg_obj,
4200 "read/write mode: no downstream pool, using our own");
4201 pool = gst_object_ref (obj->pool);
4202 size = obj->info.size;
4203 pushing_from_our_pool = TRUE;
4207 case GST_V4L2_IO_USERPTR:
4208 case GST_V4L2_IO_DMABUF_IMPORT:
4209 /* in importing mode, prefer our own pool, and pass the other pool to
4210 * our own, so it can serve itself */
4212 goto no_downstream_pool;
4213 gst_v4l2_buffer_pool_set_other_pool (GST_V4L2_BUFFER_POOL (obj->pool),
4216 gst_object_unref (pool);
4217 pool = gst_object_ref (obj->pool);
4218 size = obj->info.size;
4221 case GST_V4L2_IO_MMAP:
4222 case GST_V4L2_IO_DMABUF:
4223 /* in streaming mode, prefer our own pool */
4224 /* Check if we can use it ... */
4225 if (can_share_own_pool) {
4227 gst_object_unref (pool);
4228 pool = gst_object_ref (obj->pool);
4229 size = obj->info.size;
4230 GST_DEBUG_OBJECT (obj->dbg_obj,
4231 "streaming mode: using our own pool %" GST_PTR_FORMAT, pool);
4232 pushing_from_our_pool = TRUE;
4234 GST_DEBUG_OBJECT (obj->dbg_obj,
4235 "streaming mode: copying to downstream pool %" GST_PTR_FORMAT,
4238 GST_DEBUG_OBJECT (obj->dbg_obj,
4239 "streaming mode: no usable pool, copying to generic pool");
4240 size = MAX (size, obj->info.size);
4243 case GST_V4L2_IO_AUTO:
4245 GST_WARNING_OBJECT (obj->dbg_obj, "unhandled mode");
4252 /* If pushing from our own pool, configure it with queried minimum,
4253 * otherwise use the minimum required */
4254 if (pushing_from_our_pool) {
4255 /* When pushing from our own pool, we need what downstream one, to be able
4256 * to fill the pipeline, the minimum required to decoder according to the
4257 * driver and 2 more, so we don't endup up with everything downstream or
4258 * held by the decoder. We account 2 buffers for v4l2 so when one is being
4259 * pushed downstream the other one can already be queued for the next
4261 own_min = min + obj->min_buffers + 2;
4263 /* If no allocation parameters where provided, allow for a little more
4264 * buffers and enable copy threshold */
4267 gst_v4l2_buffer_pool_copy_at_threshold (GST_V4L2_BUFFER_POOL (pool),
4270 gst_v4l2_buffer_pool_copy_at_threshold (GST_V4L2_BUFFER_POOL (pool),
4275 /* In this case we'll have to configure two buffer pool. For our buffer
4276 * pool, we'll need what the driver one, and one more, so we can dequeu */
4277 own_min = obj->min_buffers + 1;
4278 own_min = MAX (own_min, GST_V4L2_MIN_BUFFERS);
4280 /* for the downstream pool, we keep what downstream wants, though ensure
4281 * at least a minimum if downstream didn't suggest anything (we are
4282 * expecting the base class to create a default one for the context) */
4283 min = MAX (min, GST_V4L2_MIN_BUFFERS);
4285 /* To import we need the other pool to hold at least own_min */
4286 if (obj->pool == pool)
4290 /* Request a bigger max, if one was suggested but it's too small */
4292 max = MAX (min, max);
4294 /* First step, configure our own pool */
4295 config = gst_buffer_pool_get_config (obj->pool);
4297 if (obj->need_video_meta || has_video_meta) {
4298 GST_DEBUG_OBJECT (obj->dbg_obj, "activate Video Meta");
4299 gst_buffer_pool_config_add_option (config,
4300 GST_BUFFER_POOL_OPTION_VIDEO_META);
4303 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
4304 gst_buffer_pool_config_set_params (config, caps, size, own_min, 0);
4306 GST_DEBUG_OBJECT (obj->dbg_obj, "setting own pool config to %"
4307 GST_PTR_FORMAT, config);
4309 /* Our pool often need to adjust the value */
4310 if (!gst_buffer_pool_set_config (obj->pool, config)) {
4311 config = gst_buffer_pool_get_config (obj->pool);
4313 GST_DEBUG_OBJECT (obj->dbg_obj, "own pool config changed to %"
4314 GST_PTR_FORMAT, config);
4316 /* our pool will adjust the maximum buffer, which we are fine with */
4317 if (!gst_buffer_pool_set_config (obj->pool, config))
4321 /* Now configure the other pool if different */
4322 if (obj->pool != pool)
4326 config = gst_buffer_pool_get_config (other_pool);
4327 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
4328 gst_buffer_pool_config_set_params (config, caps, size, min, max);
4330 GST_DEBUG_OBJECT (obj->dbg_obj, "setting other pool config to %"
4331 GST_PTR_FORMAT, config);
4333 /* if downstream supports video metadata, add this to the pool config */
4334 if (has_video_meta) {
4335 GST_DEBUG_OBJECT (obj->dbg_obj, "activate Video Meta");
4336 gst_buffer_pool_config_add_option (config,
4337 GST_BUFFER_POOL_OPTION_VIDEO_META);
4340 if (!gst_buffer_pool_set_config (other_pool, config)) {
4341 config = gst_buffer_pool_get_config (other_pool);
4343 if (!gst_buffer_pool_config_validate_params (config, caps, size, min,
4345 gst_structure_free (config);
4349 if (!gst_buffer_pool_set_config (other_pool, config))
4355 /* For simplicity, simply read back the active configuration, so our base
4356 * class get the right information */
4357 config = gst_buffer_pool_get_config (pool);
4358 gst_buffer_pool_config_get_params (config, NULL, &size, &min, &max);
4359 gst_structure_free (config);
4363 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
4365 gst_query_add_allocation_pool (query, pool, size, min, max);
4368 gst_object_unref (allocator);
4371 gst_object_unref (pool);
4377 /* setup_pool already send the error */
4382 GST_ELEMENT_ERROR (obj->element, RESOURCE, SETTINGS,
4383 (_("Failed to configure internal buffer pool.")), (NULL));
4388 GST_ELEMENT_ERROR (obj->element, RESOURCE, SETTINGS,
4389 (_("Video device did not suggest any buffer size.")), (NULL));
4395 gst_object_unref (allocator);
4398 gst_object_unref (pool);
4403 GST_ELEMENT_ERROR (obj->element, RESOURCE, SETTINGS,
4404 (_("No downstream pool to import from.")),
4405 ("When importing DMABUF or USERPTR, we need a pool to import from"));
4411 gst_v4l2_object_propose_allocation (GstV4l2Object * obj, GstQuery * query)
4413 GstBufferPool *pool;
4414 /* we need at least 2 buffers to operate */
4415 guint size, min, max;
4419 /* Set defaults allocation parameters */
4420 size = obj->info.size;
4421 min = GST_V4L2_MIN_BUFFERS;
4422 max = VIDEO_MAX_FRAME;
4424 gst_query_parse_allocation (query, &caps, &need_pool);
4429 if ((pool = obj->pool))
4430 gst_object_ref (pool);
4434 GstStructure *config;
4436 /* we had a pool, check caps */
4437 config = gst_buffer_pool_get_config (pool);
4438 gst_buffer_pool_config_get_params (config, &pcaps, NULL, NULL, NULL);
4440 GST_DEBUG_OBJECT (obj->dbg_obj,
4441 "we had a pool with caps %" GST_PTR_FORMAT, pcaps);
4442 if (!gst_caps_is_equal (caps, pcaps)) {
4443 gst_structure_free (config);
4444 gst_object_unref (pool);
4445 goto different_caps;
4447 gst_structure_free (config);
4449 gst_v4l2_get_driver_min_buffers (obj);
4451 min = MAX (obj->min_buffers, GST_V4L2_MIN_BUFFERS);
4453 gst_query_add_allocation_pool (query, pool, size, min, max);
4455 /* we also support various metadata */
4456 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
4459 gst_object_unref (pool);
4466 GST_DEBUG_OBJECT (obj->dbg_obj, "no caps specified");
4471 /* different caps, we can't use this pool */
4472 GST_DEBUG_OBJECT (obj->dbg_obj, "pool has different caps");