3 * Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * 2006 Edgard Lima <edgard.lima@indt.org.br>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
32 #include <gudev/gudev.h>
35 #include "v4l2_calls.h"
36 #include "gstv4l2tuner.h"
38 #include "gstv4l2xoverlay.h"
40 #include "gstv4l2colorbalance.h"
42 #include "gst/gst-i18n-plugin.h"
44 /* videodev2.h is not versioned and we can't easily check for the presence
45 * of enum values at compile time, but the V4L2_CAP_VIDEO_OUTPUT_OVERLAY define
46 * was added in the same commit as V4L2_FIELD_INTERLACED_{TB,BT} (b2787845) */
47 #ifndef V4L2_CAP_VIDEO_OUTPUT_OVERLAY
48 #define V4L2_FIELD_INTERLACED_TB 8
49 #define V4L2_FIELD_INTERLACED_BT 9
52 GST_DEBUG_CATEGORY_EXTERN (v4l2_debug);
53 #define GST_CAT_DEFAULT v4l2_debug
56 #define DEFAULT_PROP_DEVICE_NAME NULL
57 #define DEFAULT_PROP_DEVICE_FD -1
58 #define DEFAULT_PROP_FLAGS 0
59 #define DEFAULT_PROP_TV_NORM 0
60 #define DEFAULT_PROP_CHANNEL NULL
61 #define DEFAULT_PROP_FREQUENCY 0
66 V4L2_STD_OBJECT_PROPS,
69 G_LOCK_DEFINE_STATIC (probe_lock);
72 gst_v4l2_probe_get_properties (GstPropertyProbe * probe)
74 GObjectClass *klass = G_OBJECT_GET_CLASS (probe);
75 static GList *list = NULL;
77 /* well, not perfect, but better than no locking at all.
78 * In the worst case we leak a list node, so who cares? */
82 list = g_list_append (NULL, g_object_class_find_property (klass, "device"));
85 G_UNLOCK (probe_lock);
90 static gboolean init = FALSE;
91 static GList *devices = NULL;
95 gst_v4l2_class_probe_devices_with_udev (GstElementClass * klass, gboolean check,
96 GList ** klass_devices)
98 GUdevClient *client = NULL;
103 gchar *device = devices->data;
104 devices = g_list_remove (devices, device);
108 GST_INFO ("Enumerating video4linux devices from udev");
109 client = g_udev_client_new (NULL);
111 GST_WARNING ("Failed to initialize gudev client");
115 item = g_udev_client_query_by_subsystem (client, "video4linux");
117 GUdevDevice *device = item->data;
118 gchar *devnode = g_strdup (g_udev_device_get_device_file (device));
119 gint api = g_udev_device_get_property_as_int (device, "ID_V4L_VERSION");
120 GST_INFO ("Found new device: %s, API: %d", devnode, api);
121 /* Append v4l2 devices only. If api is 0 probably v4l_id has
122 been stripped out of the current udev installation, append
126 ("Couldn't retrieve ID_V4L_VERSION, silly udev installation?");
128 if ((api == 2 || api == 0)) {
129 devices = g_list_append (devices, devnode);
133 g_object_unref (device);
142 g_object_unref (client);
145 *klass_devices = devices;
149 #endif /* HAVE_GUDEV */
152 gst_v4l2_class_probe_devices (GstElementClass * klass, gboolean check,
153 GList ** klass_devices)
156 const gchar *dev_base[] = { "/dev/video", "/dev/v4l2/video", NULL };
160 gchar *device = devices->data;
161 devices = g_list_remove (devices, device);
166 * detect /dev entries
168 for (n = 0; n < 64; n++) {
169 for (base = 0; dev_base[base] != NULL; base++) {
171 gchar *device = g_strdup_printf ("%s%d",
176 * does the /dev/ entry exist at all?
178 if (stat (device, &s) == 0) {
180 * yes: is a device attached?
182 if (S_ISCHR (s.st_mode)) {
184 if ((fd = open (device, O_RDWR | O_NONBLOCK)) > 0 || errno == EBUSY) {
188 devices = g_list_append (devices, device);
199 *klass_devices = devices;
205 gst_v4l2_probe_probe_property (GstPropertyProbe * probe,
206 guint prop_id, const GParamSpec * pspec, GList ** klass_devices)
208 GstElementClass *klass = GST_ELEMENT_GET_CLASS (probe);
213 if (!gst_v4l2_class_probe_devices_with_udev (klass, FALSE, klass_devices))
214 gst_v4l2_class_probe_devices (klass, FALSE, klass_devices);
215 #else /* !HAVE_GUDEV */
216 gst_v4l2_class_probe_devices (klass, FALSE, klass_devices);
217 #endif /* HAVE_GUDEV */
220 G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
226 gst_v4l2_probe_needs_probe (GstPropertyProbe * probe,
227 guint prop_id, const GParamSpec * pspec, GList ** klass_devices)
229 GstElementClass *klass = GST_ELEMENT_GET_CLASS (probe);
230 gboolean ret = FALSE;
236 !gst_v4l2_class_probe_devices_with_udev (klass, FALSE, klass_devices);
237 #else /* !HAVE_GUDEV */
238 ret = !gst_v4l2_class_probe_devices (klass, TRUE, klass_devices);
239 #endif /* HAVE_GUDEV */
242 G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
249 gst_v4l2_class_list_devices (GstElementClass * klass, GList ** klass_devices)
252 GValue value = { 0 };
258 array = g_value_array_new (g_list_length (*klass_devices));
259 item = *klass_devices;
260 g_value_init (&value, G_TYPE_STRING);
262 gchar *device = item->data;
264 g_value_set_string (&value, device);
265 g_value_array_append (array, &value);
269 g_value_unset (&value);
275 gst_v4l2_probe_get_values (GstPropertyProbe * probe,
276 guint prop_id, const GParamSpec * pspec, GList ** klass_devices)
278 GstElementClass *klass = GST_ELEMENT_GET_CLASS (probe);
279 GValueArray *array = NULL;
283 array = gst_v4l2_class_list_devices (klass, klass_devices);
286 G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
293 #define GST_TYPE_V4L2_DEVICE_FLAGS (gst_v4l2_device_get_type ())
295 gst_v4l2_device_get_type (void)
297 static GType v4l2_device_type = 0;
299 if (v4l2_device_type == 0) {
300 static const GFlagsValue values[] = {
301 {V4L2_CAP_VIDEO_CAPTURE, "Device supports video capture", "capture"},
302 {V4L2_CAP_VIDEO_OUTPUT, "Device supports video playback", "output"},
303 {V4L2_CAP_VIDEO_OVERLAY, "Device supports video overlay", "overlay"},
305 {V4L2_CAP_VBI_CAPTURE, "Device supports the VBI capture", "vbi-capture"},
306 {V4L2_CAP_VBI_OUTPUT, "Device supports the VBI output", "vbi-output"},
308 {V4L2_CAP_TUNER, "Device has a tuner or modulator", "tuner"},
309 {V4L2_CAP_AUDIO, "Device has audio inputs or outputs", "audio"},
315 g_flags_register_static ("GstV4l2DeviceTypeFlags", values);
318 return v4l2_device_type;
321 #define GST_TYPE_V4L2_TV_NORM (gst_v4l2_tv_norm_get_type ())
323 gst_v4l2_tv_norm_get_type (void)
325 static GType v4l2_tv_norm = 0;
328 static const GEnumValue tv_norms[] = {
331 {V4L2_STD_NTSC, "NTSC", "NTSC"},
332 {V4L2_STD_NTSC_M, "NTSC-M", "NTSC-M"},
333 {V4L2_STD_NTSC_M_JP, "NTSC-M-JP", "NTSC-M-JP"},
334 {V4L2_STD_NTSC_M_KR, "NTSC-M-KR", "NTSC-M-KR"},
335 {V4L2_STD_NTSC_443, "NTSC-443", "NTSC-443"},
337 {V4L2_STD_PAL, "PAL", "PAL"},
338 {V4L2_STD_PAL_BG, "PAL-BG", "PAL-BG"},
339 {V4L2_STD_PAL_B, "PAL-B", "PAL-B"},
340 {V4L2_STD_PAL_B1, "PAL-B1", "PAL-B1"},
341 {V4L2_STD_PAL_G, "PAL-G", "PAL-G"},
342 {V4L2_STD_PAL_H, "PAL-H", "PAL-H"},
343 {V4L2_STD_PAL_I, "PAL-I", "PAL-I"},
344 {V4L2_STD_PAL_DK, "PAL-DK", "PAL-DK"},
345 {V4L2_STD_PAL_D, "PAL-D", "PAL-D"},
346 {V4L2_STD_PAL_D1, "PAL-D1", "PAL-D1"},
347 {V4L2_STD_PAL_K, "PAL-K", "PAL-K"},
348 {V4L2_STD_PAL_M, "PAL-M", "PAL-M"},
349 {V4L2_STD_PAL_N, "PAL-N", "PAL-N"},
350 {V4L2_STD_PAL_Nc, "PAL-Nc", "PAL-Nc"},
351 {V4L2_STD_PAL_60, "PAL-60", "PAL-60"},
353 {V4L2_STD_SECAM, "SECAM", "SECAM"},
354 {V4L2_STD_SECAM_B, "SECAM-B", "SECAM-B"},
355 {V4L2_STD_SECAM_G, "SECAM-G", "SECAM-G"},
356 {V4L2_STD_SECAM_H, "SECAM-H", "SECAM-H"},
357 {V4L2_STD_SECAM_DK, "SECAM-DK", "SECAM-DK"},
358 {V4L2_STD_SECAM_D, "SECAM-D", "SECAM-D"},
359 {V4L2_STD_SECAM_K, "SECAM-K", "SECAM-K"},
360 {V4L2_STD_SECAM_K1, "SECAM-K1", "SECAM-K1"},
361 {V4L2_STD_SECAM_L, "SECAM-L", "SECAM-L"},
362 {V4L2_STD_SECAM_LC, "SECAM-Lc", "SECAM-Lc"},
367 v4l2_tv_norm = g_enum_register_static ("V4L2_TV_norms", tv_norms);
374 gst_v4l2_object_install_properties_helper (GObjectClass * gobject_class,
375 const char *default_device)
377 g_object_class_install_property (gobject_class, PROP_DEVICE,
378 g_param_spec_string ("device", "Device", "Device location",
379 default_device, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
380 g_object_class_install_property (gobject_class, PROP_DEVICE_NAME,
381 g_param_spec_string ("device-name", "Device name",
382 "Name of the device", DEFAULT_PROP_DEVICE_NAME,
383 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
384 g_object_class_install_property (gobject_class, PROP_DEVICE_FD,
385 g_param_spec_int ("device-fd", "File descriptor",
386 "File descriptor of the device", -1, G_MAXINT, DEFAULT_PROP_DEVICE_FD,
387 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
388 g_object_class_install_property (gobject_class, PROP_FLAGS,
389 g_param_spec_flags ("flags", "Flags", "Device type flags",
390 GST_TYPE_V4L2_DEVICE_FLAGS, DEFAULT_PROP_FLAGS,
391 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
394 * GstV4l2Src:brightness
396 * Picture brightness, or more precisely, the black level
400 g_object_class_install_property (gobject_class, PROP_BRIGHTNESS,
401 g_param_spec_int ("brightness", "Brightness",
402 "Picture brightness, or more precisely, the black level", G_MININT,
404 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
406 * GstV4l2Src:contrast
408 * Picture contrast or luma gain
412 g_object_class_install_property (gobject_class, PROP_CONTRAST,
413 g_param_spec_int ("contrast", "Contrast",
414 "Picture contrast or luma gain", G_MININT,
416 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
418 * GstV4l2Src:saturation
420 * Picture color saturation or chroma gain
424 g_object_class_install_property (gobject_class, PROP_SATURATION,
425 g_param_spec_int ("saturation", "Saturation",
426 "Picture color saturation or chroma gain", G_MININT,
428 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
432 * Hue or color balance
436 g_object_class_install_property (gobject_class, PROP_HUE,
437 g_param_spec_int ("hue", "Hue",
438 "Hue or color balance", G_MININT,
440 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
449 g_object_class_install_property (gobject_class, PROP_TV_NORM,
450 g_param_spec_enum ("norm", "TV norm",
452 GST_TYPE_V4L2_TV_NORM, DEFAULT_PROP_TV_NORM,
453 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
457 gst_v4l2_object_new (GstElement * element,
458 enum v4l2_buf_type type,
459 const char *default_device,
460 GstV4l2GetInOutFunction get_in_out_func,
461 GstV4l2SetInOutFunction set_in_out_func,
462 GstV4l2UpdateFpsFunction update_fps_func)
464 GstV4l2Object *v4l2object;
467 * some default values
469 v4l2object = g_new0 (GstV4l2Object, 1);
471 v4l2object->type = type;
472 v4l2object->formats = NULL;
474 v4l2object->element = element;
475 v4l2object->get_in_out_func = get_in_out_func;
476 v4l2object->set_in_out_func = set_in_out_func;
477 v4l2object->update_fps_func = update_fps_func;
479 v4l2object->video_fd = -1;
480 v4l2object->poll = gst_poll_new (TRUE);
481 v4l2object->buffer = NULL;
482 v4l2object->videodev = g_strdup (default_device);
484 v4l2object->norms = NULL;
485 v4l2object->channels = NULL;
486 v4l2object->colors = NULL;
488 v4l2object->xwindow_id = 0;
493 static gboolean gst_v4l2_object_clear_format_list (GstV4l2Object * v4l2object);
497 gst_v4l2_object_destroy (GstV4l2Object * v4l2object)
499 g_return_if_fail (v4l2object != NULL);
501 if (v4l2object->videodev)
502 g_free (v4l2object->videodev);
504 if (v4l2object->poll)
505 gst_poll_free (v4l2object->poll);
507 if (v4l2object->channel)
508 g_free (v4l2object->channel);
510 if (v4l2object->formats) {
511 gst_v4l2_object_clear_format_list (v4l2object);
519 gst_v4l2_object_clear_format_list (GstV4l2Object * v4l2object)
521 g_slist_foreach (v4l2object->formats, (GFunc) g_free, NULL);
522 g_slist_free (v4l2object->formats);
523 v4l2object->formats = NULL;
529 gst_v4l2_object_prop_to_cid (guint prop_id)
534 case PROP_BRIGHTNESS:
535 cid = V4L2_CID_BRIGHTNESS;
538 cid = V4L2_CID_CONTRAST;
540 case PROP_SATURATION:
541 cid = V4L2_CID_SATURATION;
547 GST_WARNING ("unmapped property id: %d", prop_id);
554 gst_v4l2_object_set_property_helper (GstV4l2Object * v4l2object,
555 guint prop_id, const GValue * value, GParamSpec * pspec)
559 g_free (v4l2object->videodev);
560 v4l2object->videodev = g_value_dup_string (value);
562 case PROP_BRIGHTNESS:
564 case PROP_SATURATION:
567 gint cid = gst_v4l2_object_prop_to_cid (prop_id);
570 if (GST_V4L2_IS_OPEN (v4l2object)) {
571 gst_v4l2_set_attribute (v4l2object, cid, g_value_get_int (value));
578 v4l2object->tv_norm = g_value_get_enum (value);
582 if (GST_V4L2_IS_OPEN (v4l2object)) {
583 GstTuner *tuner = GST_TUNER (v4l2object->element);
584 GstTunerChannel *channel = gst_tuner_find_channel_by_name (tuner,
585 (gchar *) g_value_get_string (value));
588 /* like gst_tuner_set_channel (tuner, channel)
589 without g_object_notify */
590 gst_v4l2_tuner_set_channel (v4l2object, channel);
593 g_free (v4l2object->channel);
594 v4l2object->channel = g_value_dup_string (value);
598 if (GST_V4L2_IS_OPEN (v4l2object)) {
599 GstTuner *tuner = GST_TUNER (v4l2object->element);
600 GstTunerChannel *channel = gst_tuner_get_channel (tuner);
603 GST_TUNER_CHANNEL_HAS_FLAG (channel, GST_TUNER_CHANNEL_FREQUENCY)) {
605 gst_tuner_set_frequency (tuner, channel, g_value_get_ulong (value))
606 without g_object_notify */
607 gst_v4l2_tuner_set_frequency (v4l2object, channel,
608 g_value_get_ulong (value));
611 v4l2object->frequency = g_value_get_ulong (value);
624 gst_v4l2_object_get_property_helper (GstV4l2Object * v4l2object,
625 guint prop_id, GValue * value, GParamSpec * pspec)
629 g_value_set_string (value, v4l2object->videodev);
631 case PROP_DEVICE_NAME:
633 const guchar *new = NULL;
635 if (GST_V4L2_IS_OPEN (v4l2object)) {
636 new = v4l2object->vcap.card;
637 } else if (gst_v4l2_open (v4l2object)) {
638 new = v4l2object->vcap.card;
639 gst_v4l2_close (v4l2object);
641 g_value_set_string (value, (gchar *) new);
646 if (GST_V4L2_IS_OPEN (v4l2object))
647 g_value_set_int (value, v4l2object->video_fd);
649 g_value_set_int (value, DEFAULT_PROP_DEVICE_FD);
656 if (GST_V4L2_IS_OPEN (v4l2object)) {
657 flags |= v4l2object->vcap.capabilities &
658 (V4L2_CAP_VIDEO_CAPTURE |
659 V4L2_CAP_VIDEO_OUTPUT |
660 V4L2_CAP_VIDEO_OVERLAY |
661 V4L2_CAP_VBI_CAPTURE |
662 V4L2_CAP_VBI_OUTPUT | V4L2_CAP_TUNER | V4L2_CAP_AUDIO);
664 g_value_set_flags (value, flags);
667 case PROP_BRIGHTNESS:
669 case PROP_SATURATION:
672 gint cid = gst_v4l2_object_prop_to_cid (prop_id);
675 if (GST_V4L2_IS_OPEN (v4l2object)) {
677 if (gst_v4l2_get_attribute (v4l2object, cid, &v)) {
678 g_value_set_int (value, v);
686 g_value_set_enum (value, v4l2object->tv_norm);
696 gst_v4l2_set_defaults (GstV4l2Object * v4l2object)
698 GstTunerNorm *norm = NULL;
699 GstTunerChannel *channel = NULL;
702 if (!GST_IS_TUNER (v4l2object->element))
705 tuner = GST_TUNER (v4l2object->element);
707 if (v4l2object->tv_norm)
708 norm = gst_v4l2_tuner_get_norm_by_std_id (v4l2object, v4l2object->tv_norm);
709 GST_DEBUG_OBJECT (v4l2object->element, "tv_norm=0x%" G_GINT64_MODIFIER "x, "
710 "norm=%p", (guint64) v4l2object->tv_norm, norm);
712 gst_tuner_set_norm (tuner, norm);
715 GST_TUNER_NORM (gst_tuner_get_norm (GST_TUNER (v4l2object->element)));
717 v4l2object->tv_norm =
718 gst_v4l2_tuner_get_std_id_by_norm (v4l2object, norm);
719 gst_tuner_norm_changed (tuner, norm);
723 if (v4l2object->channel)
724 channel = gst_tuner_find_channel_by_name (tuner, v4l2object->channel);
726 gst_tuner_set_channel (tuner, channel);
729 GST_TUNER_CHANNEL (gst_tuner_get_channel (GST_TUNER
730 (v4l2object->element)));
732 g_free (v4l2object->channel);
733 v4l2object->channel = g_strdup (channel->label);
734 gst_tuner_channel_changed (tuner, channel);
739 && GST_TUNER_CHANNEL_HAS_FLAG (channel, GST_TUNER_CHANNEL_FREQUENCY)) {
740 if (v4l2object->frequency != 0) {
741 gst_tuner_set_frequency (tuner, channel, v4l2object->frequency);
743 v4l2object->frequency = gst_tuner_get_frequency (tuner, channel);
744 if (v4l2object->frequency == 0) {
746 gst_tuner_set_frequency (tuner, channel, 1000);
754 gst_v4l2_object_start (GstV4l2Object * v4l2object)
756 if (gst_v4l2_open (v4l2object))
757 gst_v4l2_set_defaults (v4l2object);
762 gst_v4l2_xoverlay_start (v4l2object);
769 gst_v4l2_object_stop (GstV4l2Object * v4l2object)
772 gst_v4l2_xoverlay_stop (v4l2object);
775 if (!gst_v4l2_close (v4l2object))
778 if (v4l2object->formats) {
779 gst_v4l2_object_clear_format_list (v4l2object);
787 * common format / caps utilities:
795 static const GstV4L2FormatDesc gst_v4l2_formats[] = {
796 /* from Linux 2.6.15 videodev2.h */
797 {V4L2_PIX_FMT_RGB332, TRUE},
798 {V4L2_PIX_FMT_RGB555, TRUE},
799 {V4L2_PIX_FMT_RGB565, TRUE},
800 {V4L2_PIX_FMT_RGB555X, TRUE},
801 {V4L2_PIX_FMT_RGB565X, TRUE},
802 {V4L2_PIX_FMT_BGR24, TRUE},
803 {V4L2_PIX_FMT_RGB24, TRUE},
804 {V4L2_PIX_FMT_BGR32, TRUE},
805 {V4L2_PIX_FMT_RGB32, TRUE},
806 {V4L2_PIX_FMT_GREY, TRUE},
807 {V4L2_PIX_FMT_YVU410, TRUE},
808 {V4L2_PIX_FMT_YVU420, TRUE},
809 {V4L2_PIX_FMT_YUYV, TRUE},
810 {V4L2_PIX_FMT_UYVY, TRUE},
811 {V4L2_PIX_FMT_YUV422P, TRUE},
812 {V4L2_PIX_FMT_YUV411P, TRUE},
813 {V4L2_PIX_FMT_Y41P, TRUE},
815 /* two planes -- one Y, one Cr + Cb interleaved */
816 {V4L2_PIX_FMT_NV12, TRUE},
817 {V4L2_PIX_FMT_NV21, TRUE},
819 /* The following formats are not defined in the V4L2 specification */
820 {V4L2_PIX_FMT_YUV410, TRUE},
821 {V4L2_PIX_FMT_YUV420, TRUE},
822 {V4L2_PIX_FMT_YYUV, TRUE},
823 {V4L2_PIX_FMT_HI240, TRUE},
825 /* see http://www.siliconimaging.com/RGB%20Bayer.htm */
826 #ifdef V4L2_PIX_FMT_SBGGR8
827 {V4L2_PIX_FMT_SBGGR8, TRUE},
830 /* compressed formats */
831 {V4L2_PIX_FMT_MJPEG, TRUE},
832 {V4L2_PIX_FMT_JPEG, TRUE},
833 #ifdef V4L2_PIX_FMT_PJPG
834 {V4L2_PIX_FMT_PJPG, TRUE},
836 {V4L2_PIX_FMT_DV, TRUE},
837 {V4L2_PIX_FMT_MPEG, FALSE},
839 /* Vendor-specific formats */
840 {V4L2_PIX_FMT_WNVA, TRUE},
842 #ifdef V4L2_PIX_FMT_SN9C10X
843 {V4L2_PIX_FMT_SN9C10X, TRUE},
845 #ifdef V4L2_PIX_FMT_PWC1
846 {V4L2_PIX_FMT_PWC1, TRUE},
848 #ifdef V4L2_PIX_FMT_PWC2
849 {V4L2_PIX_FMT_PWC2, TRUE},
851 #ifdef V4L2_PIX_FMT_YVYU
852 {V4L2_PIX_FMT_YVYU, TRUE},
856 #define GST_V4L2_FORMAT_COUNT (G_N_ELEMENTS (gst_v4l2_formats))
859 static struct v4l2_fmtdesc *
860 gst_v4l2_object_get_format_from_fourcc (GstV4l2Object * v4l2object,
863 struct v4l2_fmtdesc *fmt;
869 walk = gst_v4l2_object_get_format_list (v4l2object);
871 fmt = (struct v4l2_fmtdesc *) walk->data;
872 if (fmt->pixelformat == fourcc)
874 /* special case for jpeg */
875 if (fmt->pixelformat == V4L2_PIX_FMT_MJPEG ||
876 fmt->pixelformat == V4L2_PIX_FMT_JPEG
877 #ifdef V4L2_PIX_FMT_PJPG
878 || fmt->pixelformat == V4L2_PIX_FMT_PJPG
881 if (fourcc == V4L2_PIX_FMT_JPEG || fourcc == V4L2_PIX_FMT_MJPEG
882 #ifdef V4L2_PIX_FMT_PJPG
883 || fourcc == V4L2_PIX_FMT_PJPG
889 walk = g_slist_next (walk);
897 /* complete made up ranking, the values themselves are meaningless */
898 /* These ranks MUST be X such that X<<15 fits on a signed int - see
899 the comment at the end of gst_v4l2_object_format_get_rank. */
900 #define YUV_BASE_RANK 1000
901 #define JPEG_BASE_RANK 500
902 #define DV_BASE_RANK 200
903 #define RGB_BASE_RANK 100
904 #define YUV_ODD_BASE_RANK 50
905 #define RGB_ODD_BASE_RANK 25
906 #define BAYER_BASE_RANK 15
907 #define S910_BASE_RANK 10
908 #define GREY_BASE_RANK 5
909 #define PWC_BASE_RANK 1
911 /* This flag is already used by libv4l2 although
912 * it was added to the Linux kernel in 2.6.32
914 #ifndef V4L2_FMT_FLAG_EMULATED
915 #define V4L2_FMT_FLAG_EMULATED 0x0002
919 gst_v4l2_object_format_get_rank (const struct v4l2_fmtdesc *fmt)
921 guint32 fourcc = fmt->pixelformat;
922 gboolean emulated = ((fmt->flags & V4L2_FMT_FLAG_EMULATED) != 0);
926 case V4L2_PIX_FMT_MJPEG:
927 #ifdef V4L2_PIX_FMT_PJPG
928 case V4L2_PIX_FMT_PJPG:
929 rank = JPEG_BASE_RANK;
932 case V4L2_PIX_FMT_JPEG:
933 rank = JPEG_BASE_RANK + 1;
935 case V4L2_PIX_FMT_MPEG: /* MPEG */
936 rank = JPEG_BASE_RANK + 2;
939 case V4L2_PIX_FMT_RGB332:
940 case V4L2_PIX_FMT_RGB555:
941 case V4L2_PIX_FMT_RGB555X:
942 case V4L2_PIX_FMT_RGB565:
943 case V4L2_PIX_FMT_RGB565X:
944 rank = RGB_ODD_BASE_RANK;
947 case V4L2_PIX_FMT_RGB24:
948 case V4L2_PIX_FMT_BGR24:
949 rank = RGB_BASE_RANK - 1;
952 case V4L2_PIX_FMT_RGB32:
953 case V4L2_PIX_FMT_BGR32:
954 rank = RGB_BASE_RANK;
957 case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
958 rank = GREY_BASE_RANK;
961 case V4L2_PIX_FMT_NV12: /* 12 Y/CbCr 4:2:0 */
962 case V4L2_PIX_FMT_NV21: /* 12 Y/CrCb 4:2:0 */
963 case V4L2_PIX_FMT_YYUV: /* 16 YUV 4:2:2 */
964 case V4L2_PIX_FMT_HI240: /* 8 8-bit color */
965 rank = YUV_ODD_BASE_RANK;
968 case V4L2_PIX_FMT_YVU410: /* YVU9, 9 bits per pixel */
969 rank = YUV_BASE_RANK + 3;
971 case V4L2_PIX_FMT_YUV410: /* YUV9, 9 bits per pixel */
972 rank = YUV_BASE_RANK + 2;
974 case V4L2_PIX_FMT_YUV420: /* I420, 12 bits per pixel */
975 rank = YUV_BASE_RANK + 7;
977 case V4L2_PIX_FMT_YUYV: /* YUY2, 16 bits per pixel */
978 rank = YUV_BASE_RANK + 10;
980 case V4L2_PIX_FMT_YVU420: /* YV12, 12 bits per pixel */
981 rank = YUV_BASE_RANK + 6;
983 case V4L2_PIX_FMT_UYVY: /* UYVY, 16 bits per pixel */
984 rank = YUV_BASE_RANK + 9;
986 case V4L2_PIX_FMT_Y41P: /* Y41P, 12 bits per pixel */
987 rank = YUV_BASE_RANK + 5;
989 case V4L2_PIX_FMT_YUV411P: /* Y41B, 12 bits per pixel */
990 rank = YUV_BASE_RANK + 4;
992 case V4L2_PIX_FMT_YUV422P: /* Y42B, 16 bits per pixel */
993 rank = YUV_BASE_RANK + 8;
996 case V4L2_PIX_FMT_DV:
1000 case V4L2_PIX_FMT_WNVA: /* Winnov hw compres */
1004 #ifdef V4L2_PIX_FMT_SBGGR8
1005 case V4L2_PIX_FMT_SBGGR8:
1006 rank = BAYER_BASE_RANK;
1010 #ifdef V4L2_PIX_FMT_SN9C10X
1011 case V4L2_PIX_FMT_SN9C10X:
1012 rank = S910_BASE_RANK;
1016 #ifdef V4L2_PIX_FMT_PWC1
1017 case V4L2_PIX_FMT_PWC1:
1018 rank = PWC_BASE_RANK;
1021 #ifdef V4L2_PIX_FMT_PWC2
1022 case V4L2_PIX_FMT_PWC2:
1023 rank = PWC_BASE_RANK;
1032 /* All ranks are below 1<<15 so a shift by 15
1033 * will a) make all non-emulated formats larger
1034 * than emulated and b) will not overflow
1045 format_cmp_func (gconstpointer a, gconstpointer b)
1047 const struct v4l2_fmtdesc *fa = a;
1048 const struct v4l2_fmtdesc *fb = b;
1050 if (fa->pixelformat == fb->pixelformat)
1053 return gst_v4l2_object_format_get_rank (fb) -
1054 gst_v4l2_object_format_get_rank (fa);
1057 /******************************************************
1058 * gst_v4l2_object_fill_format_list():
1059 * create list of supported capture formats
1060 * return value: TRUE on success, FALSE on error
1061 ******************************************************/
1063 gst_v4l2_object_fill_format_list (GstV4l2Object * v4l2object)
1066 struct v4l2_fmtdesc *format;
1068 GST_DEBUG_OBJECT (v4l2object->element, "getting src format enumerations");
1070 /* format enumeration */
1072 format = g_new0 (struct v4l2_fmtdesc, 1);
1075 format->type = v4l2object->type;
1077 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_ENUM_FMT, format) < 0) {
1078 if (errno == EINVAL) {
1080 break; /* end of enumeration */
1086 GST_LOG_OBJECT (v4l2object->element, "index: %u", format->index);
1087 GST_LOG_OBJECT (v4l2object->element, "type: %d", format->type);
1088 GST_LOG_OBJECT (v4l2object->element, "flags: %08x", format->flags);
1089 GST_LOG_OBJECT (v4l2object->element, "description: '%s'",
1090 format->description);
1091 GST_LOG_OBJECT (v4l2object->element, "pixelformat: %" GST_FOURCC_FORMAT,
1092 GST_FOURCC_ARGS (format->pixelformat));
1094 /* sort formats according to our preference; we do this, because caps
1095 * are probed in the order the formats are in the list, and the order of
1096 * formats in the final probed caps matters for things like fixation */
1097 v4l2object->formats = g_slist_insert_sorted (v4l2object->formats, format,
1098 (GCompareFunc) format_cmp_func);
1101 #ifndef GST_DISABLE_GST_DEBUG
1105 GST_INFO_OBJECT (v4l2object->element, "got %d format(s):", n);
1106 for (l = v4l2object->formats; l != NULL; l = l->next) {
1109 GST_INFO_OBJECT (v4l2object->element,
1110 " %" GST_FOURCC_FORMAT "%s", GST_FOURCC_ARGS (format->pixelformat),
1111 ((format->flags & V4L2_FMT_FLAG_EMULATED)) ? " (emulated)" : "");
1121 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
1122 (_("Failed to enumerate possible video formats device '%s' can work with"), v4l2object->videodev), ("Failed to get number %d in pixelformat enumeration for %s. (%d - %s)", n, v4l2object->videodev, errno, g_strerror (errno)));
1129 * Get the list of supported capture formats, a list of
1130 * <code>struct v4l2_fmtdesc</code>.
1133 gst_v4l2_object_get_format_list (GstV4l2Object * v4l2object)
1135 if (!v4l2object->formats)
1136 gst_v4l2_object_fill_format_list (v4l2object);
1137 return v4l2object->formats;
1142 gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc)
1144 GstStructure *structure = NULL;
1147 case V4L2_PIX_FMT_MJPEG: /* Motion-JPEG */
1148 #ifdef V4L2_PIX_FMT_PJPG
1149 case V4L2_PIX_FMT_PJPG: /* Progressive-JPEG */
1151 case V4L2_PIX_FMT_JPEG: /* JFIF JPEG */
1152 structure = gst_structure_new ("image/jpeg", NULL);
1154 case V4L2_PIX_FMT_RGB332:
1155 case V4L2_PIX_FMT_RGB555:
1156 case V4L2_PIX_FMT_RGB555X:
1157 case V4L2_PIX_FMT_RGB565:
1158 case V4L2_PIX_FMT_RGB565X:
1159 case V4L2_PIX_FMT_RGB24:
1160 case V4L2_PIX_FMT_BGR24:
1161 case V4L2_PIX_FMT_RGB32:
1162 case V4L2_PIX_FMT_BGR32:{
1163 guint depth = 0, bpp = 0;
1165 gint endianness = 0;
1167 guint32 r_mask = 0, b_mask = 0, g_mask = 0;
1170 case V4L2_PIX_FMT_RGB332:
1172 endianness = G_BYTE_ORDER; /* 'like, whatever' */
1177 case V4L2_PIX_FMT_RGB555:
1178 case V4L2_PIX_FMT_RGB555X:
1182 fourcc == V4L2_PIX_FMT_RGB555X ? G_BIG_ENDIAN : G_LITTLE_ENDIAN;
1187 case V4L2_PIX_FMT_RGB565:
1188 case V4L2_PIX_FMT_RGB565X:
1191 fourcc == V4L2_PIX_FMT_RGB565X ? G_BIG_ENDIAN : G_LITTLE_ENDIAN;
1196 case V4L2_PIX_FMT_RGB24:
1198 endianness = G_BIG_ENDIAN;
1203 case V4L2_PIX_FMT_BGR24:
1205 endianness = G_BIG_ENDIAN;
1210 case V4L2_PIX_FMT_RGB32:
1212 endianness = G_BIG_ENDIAN;
1213 r_mask = 0xff000000;
1214 g_mask = 0x00ff0000;
1215 b_mask = 0x0000ff00;
1217 case V4L2_PIX_FMT_BGR32:
1219 endianness = G_BIG_ENDIAN;
1220 r_mask = 0x000000ff;
1221 g_mask = 0x0000ff00;
1222 b_mask = 0x00ff0000;
1225 g_assert_not_reached ();
1228 structure = gst_structure_new ("video/x-raw-rgb",
1229 "bpp", G_TYPE_INT, bpp,
1230 "depth", G_TYPE_INT, depth,
1231 "red_mask", G_TYPE_INT, r_mask,
1232 "green_mask", G_TYPE_INT, g_mask,
1233 "blue_mask", G_TYPE_INT, b_mask,
1234 "endianness", G_TYPE_INT, endianness, NULL);
1237 case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
1238 structure = gst_structure_new ("video/x-raw-gray",
1239 "bpp", G_TYPE_INT, 8, NULL);
1241 case V4L2_PIX_FMT_YYUV: /* 16 YUV 4:2:2 */
1242 case V4L2_PIX_FMT_HI240: /* 8 8-bit color */
1243 /* FIXME: get correct fourccs here */
1245 case V4L2_PIX_FMT_NV12: /* 12 Y/CbCr 4:2:0 */
1246 case V4L2_PIX_FMT_NV21: /* 12 Y/CrCb 4:2:0 */
1247 case V4L2_PIX_FMT_YVU410:
1248 case V4L2_PIX_FMT_YUV410:
1249 case V4L2_PIX_FMT_YUV420: /* I420/IYUV */
1250 case V4L2_PIX_FMT_YUYV:
1251 case V4L2_PIX_FMT_YVU420:
1252 case V4L2_PIX_FMT_UYVY:
1253 case V4L2_PIX_FMT_Y41P:
1254 case V4L2_PIX_FMT_YUV422P:
1255 #ifdef V4L2_PIX_FMT_YVYU
1256 case V4L2_PIX_FMT_YVYU:
1258 case V4L2_PIX_FMT_YUV411P:{
1262 case V4L2_PIX_FMT_NV12:
1263 fcc = GST_MAKE_FOURCC ('N', 'V', '1', '2');
1265 case V4L2_PIX_FMT_NV21:
1266 fcc = GST_MAKE_FOURCC ('N', 'V', '2', '1');
1268 case V4L2_PIX_FMT_YVU410:
1269 fcc = GST_MAKE_FOURCC ('Y', 'V', 'U', '9');
1271 case V4L2_PIX_FMT_YUV410:
1272 fcc = GST_MAKE_FOURCC ('Y', 'U', 'V', '9');
1274 case V4L2_PIX_FMT_YUV420:
1275 fcc = GST_MAKE_FOURCC ('I', '4', '2', '0');
1277 case V4L2_PIX_FMT_YUYV:
1278 fcc = GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
1280 case V4L2_PIX_FMT_YVU420:
1281 fcc = GST_MAKE_FOURCC ('Y', 'V', '1', '2');
1283 case V4L2_PIX_FMT_UYVY:
1284 fcc = GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
1286 case V4L2_PIX_FMT_Y41P:
1287 fcc = GST_MAKE_FOURCC ('Y', '4', '1', 'P');
1289 case V4L2_PIX_FMT_YUV411P:
1290 fcc = GST_MAKE_FOURCC ('Y', '4', '1', 'B');
1292 case V4L2_PIX_FMT_YUV422P:
1293 fcc = GST_MAKE_FOURCC ('Y', '4', '2', 'B');
1295 #ifdef V4L2_PIX_FMT_YVYU
1296 case V4L2_PIX_FMT_YVYU:
1297 fcc = GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U');
1301 g_assert_not_reached ();
1304 structure = gst_structure_new ("video/x-raw-yuv",
1305 "format", GST_TYPE_FOURCC, fcc, NULL);
1308 case V4L2_PIX_FMT_DV:
1310 gst_structure_new ("video/x-dv", "systemstream", G_TYPE_BOOLEAN, TRUE,
1313 case V4L2_PIX_FMT_MPEG: /* MPEG */
1314 structure = gst_structure_new ("video/mpegts", NULL);
1316 case V4L2_PIX_FMT_WNVA: /* Winnov hw compres */
1318 #ifdef V4L2_PIX_FMT_SBGGR8
1319 case V4L2_PIX_FMT_SBGGR8:
1320 structure = gst_structure_new ("video/x-raw-bayer", NULL);
1323 #ifdef V4L2_PIX_FMT_SN9C10X
1324 case V4L2_PIX_FMT_SN9C10X:
1325 structure = gst_structure_new ("video/x-sonix", NULL);
1328 #ifdef V4L2_PIX_FMT_PWC1
1329 case V4L2_PIX_FMT_PWC1:
1330 structure = gst_structure_new ("video/x-pwc1", NULL);
1333 #ifdef V4L2_PIX_FMT_PWC2
1334 case V4L2_PIX_FMT_PWC2:
1335 structure = gst_structure_new ("video/x-pwc2", NULL);
1339 GST_DEBUG ("Unknown fourcc 0x%08x %" GST_FOURCC_FORMAT,
1340 fourcc, GST_FOURCC_ARGS (fourcc));
1350 gst_v4l2_object_get_all_caps (void)
1352 static GstCaps *caps = NULL;
1355 GstStructure *structure;
1359 caps = gst_caps_new_empty ();
1360 for (i = 0; i < GST_V4L2_FORMAT_COUNT; i++) {
1362 gst_v4l2_object_v4l2fourcc_to_structure (gst_v4l2_formats[i].format);
1364 if (gst_v4l2_formats[i].dimensions) {
1365 gst_structure_set (structure,
1366 "width", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1367 "height", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1368 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, 100, 1, NULL);
1370 gst_caps_append_structure (caps, structure);
1375 return gst_caps_ref (caps);
1379 /* collect data for the given caps
1380 * @caps: given input caps
1381 * @format: location for the v4l format
1382 * @w/@h: location for width and height
1383 * @fps_n/@fps_d: location for framerate
1384 * @size: location for expected size of the frame or 0 if unknown
1387 gst_v4l2_object_get_caps_info (GstV4l2Object * v4l2object, GstCaps * caps,
1388 struct v4l2_fmtdesc ** format, gint * w, gint * h,
1389 gboolean * interlaced, guint * fps_n, guint * fps_d, guint * size)
1391 GstStructure *structure;
1392 const GValue *framerate;
1394 const gchar *mimetype;
1397 /* default unknown values */
1401 structure = gst_caps_get_structure (caps, 0);
1403 mimetype = gst_structure_get_name (structure);
1405 if (strcmp (mimetype, "video/mpegts") == 0) {
1406 fourcc = V4L2_PIX_FMT_MPEG;
1412 if (!gst_structure_get_int (structure, "width", w))
1415 if (!gst_structure_get_int (structure, "height", h))
1418 if (!gst_structure_get_boolean (structure, "interlaced", interlaced))
1419 *interlaced = FALSE;
1421 framerate = gst_structure_get_value (structure, "framerate");
1425 *fps_n = gst_value_get_fraction_numerator (framerate);
1426 *fps_d = gst_value_get_fraction_denominator (framerate);
1428 if (!strcmp (mimetype, "video/x-raw-yuv")) {
1429 gst_structure_get_fourcc (structure, "format", &fourcc);
1432 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
1433 case GST_MAKE_FOURCC ('I', 'Y', 'U', 'V'):
1434 fourcc = V4L2_PIX_FMT_YUV420;
1435 outsize = GST_ROUND_UP_4 (*w) * GST_ROUND_UP_2 (*h);
1436 outsize += 2 * ((GST_ROUND_UP_8 (*w) / 2) * (GST_ROUND_UP_2 (*h) / 2));
1438 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
1439 fourcc = V4L2_PIX_FMT_YUYV;
1440 outsize = (GST_ROUND_UP_2 (*w) * 2) * *h;
1442 case GST_MAKE_FOURCC ('Y', '4', '1', 'P'):
1443 fourcc = V4L2_PIX_FMT_Y41P;
1444 outsize = (GST_ROUND_UP_2 (*w) * 2) * *h;
1446 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
1447 fourcc = V4L2_PIX_FMT_UYVY;
1448 outsize = (GST_ROUND_UP_2 (*w) * 2) * *h;
1450 case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
1451 fourcc = V4L2_PIX_FMT_YVU420;
1452 outsize = GST_ROUND_UP_4 (*w) * GST_ROUND_UP_2 (*h);
1453 outsize += 2 * ((GST_ROUND_UP_8 (*w) / 2) * (GST_ROUND_UP_2 (*h) / 2));
1455 case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
1456 fourcc = V4L2_PIX_FMT_YUV411P;
1457 outsize = GST_ROUND_UP_4 (*w) * *h;
1458 outsize += 2 * ((GST_ROUND_UP_8 (*w) / 4) * *h);
1460 case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
1461 fourcc = V4L2_PIX_FMT_YUV422P;
1462 outsize = GST_ROUND_UP_4 (*w) * *h;
1463 outsize += 2 * ((GST_ROUND_UP_8 (*w) / 2) * *h);
1465 case GST_MAKE_FOURCC ('N', 'V', '1', '2'):
1466 fourcc = V4L2_PIX_FMT_NV12;
1467 outsize = GST_ROUND_UP_4 (*w) * GST_ROUND_UP_2 (*h);
1468 outsize += (GST_ROUND_UP_4 (*w) * *h) / 2;
1470 case GST_MAKE_FOURCC ('N', 'V', '2', '1'):
1471 fourcc = V4L2_PIX_FMT_NV21;
1472 outsize = GST_ROUND_UP_4 (*w) * GST_ROUND_UP_2 (*h);
1473 outsize += (GST_ROUND_UP_4 (*w) * *h) / 2;
1475 #ifdef V4L2_PIX_FMT_YVYU
1476 case GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U'):
1477 fourcc = V4L2_PIX_FMT_YVYU;
1478 outsize = (GST_ROUND_UP_2 (*w) * 2) * *h;
1482 } else if (!strcmp (mimetype, "video/x-raw-rgb")) {
1483 gint depth, endianness, r_mask;
1485 gst_structure_get_int (structure, "depth", &depth);
1486 gst_structure_get_int (structure, "endianness", &endianness);
1487 gst_structure_get_int (structure, "red_mask", &r_mask);
1491 fourcc = V4L2_PIX_FMT_RGB332;
1494 fourcc = (endianness == G_LITTLE_ENDIAN) ?
1495 V4L2_PIX_FMT_RGB555 : V4L2_PIX_FMT_RGB555X;
1498 fourcc = (endianness == G_LITTLE_ENDIAN) ?
1499 V4L2_PIX_FMT_RGB565 : V4L2_PIX_FMT_RGB565X;
1502 fourcc = (r_mask == 0xFF) ? V4L2_PIX_FMT_BGR24 : V4L2_PIX_FMT_RGB24;
1505 fourcc = (r_mask == 0xFF) ? V4L2_PIX_FMT_BGR32 : V4L2_PIX_FMT_RGB32;
1508 } else if (strcmp (mimetype, "video/x-dv") == 0) {
1509 fourcc = V4L2_PIX_FMT_DV;
1510 } else if (strcmp (mimetype, "image/jpeg") == 0) {
1511 fourcc = V4L2_PIX_FMT_JPEG;
1512 #ifdef V4L2_PIX_FMT_SBGGR8
1513 } else if (strcmp (mimetype, "video/x-raw-bayer") == 0) {
1514 fourcc = V4L2_PIX_FMT_SBGGR8;
1516 #ifdef V4L2_PIX_FMT_SN9C10X
1517 } else if (strcmp (mimetype, "video/x-sonix") == 0) {
1518 fourcc = V4L2_PIX_FMT_SN9C10X;
1520 #ifdef V4L2_PIX_FMT_PWC1
1521 } else if (strcmp (mimetype, "video/x-pwc1") == 0) {
1522 fourcc = V4L2_PIX_FMT_PWC1;
1524 #ifdef V4L2_PIX_FMT_PWC2
1525 } else if (strcmp (mimetype, "video/x-pwc2") == 0) {
1526 fourcc = V4L2_PIX_FMT_PWC2;
1528 } else if (strcmp (mimetype, "video/x-raw-gray") == 0) {
1529 fourcc = V4L2_PIX_FMT_GREY;
1536 *format = gst_v4l2_object_get_format_from_fourcc (v4l2object, fourcc);
1544 gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
1545 guint32 pixelformat, gint * width, gint * height, gboolean * interlaced);
1548 /* The frame interval enumeration code first appeared in Linux 2.6.19. */
1549 #ifdef VIDIOC_ENUM_FRAMEINTERVALS
1550 static GstStructure *
1551 gst_v4l2_object_probe_caps_for_format_and_size (GstV4l2Object * v4l2object,
1552 guint32 pixelformat,
1553 guint32 width, guint32 height, const GstStructure * template)
1555 gint fd = v4l2object->video_fd;
1556 struct v4l2_frmivalenum ival;
1559 GValue rates = { 0, };
1560 gboolean interlaced;
1561 gint int_width = width;
1562 gint int_height = height;
1564 /* interlaced detection using VIDIOC_TRY/S_FMT */
1565 if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat,
1566 &int_width, &int_height, &interlaced))
1569 memset (&ival, 0, sizeof (struct v4l2_frmivalenum));
1571 ival.pixel_format = pixelformat;
1573 ival.height = height;
1575 GST_LOG_OBJECT (v4l2object->element,
1576 "get frame interval for %ux%u, %" GST_FOURCC_FORMAT, width, height,
1577 GST_FOURCC_ARGS (pixelformat));
1579 /* keep in mind that v4l2 gives us frame intervals (durations); we invert the
1580 * fraction to get framerate */
1581 if (v4l2_ioctl (fd, VIDIOC_ENUM_FRAMEINTERVALS, &ival) < 0)
1582 goto enum_frameintervals_failed;
1584 if (ival.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
1585 GValue rate = { 0, };
1587 g_value_init (&rates, GST_TYPE_LIST);
1588 g_value_init (&rate, GST_TYPE_FRACTION);
1591 num = ival.discrete.numerator;
1592 denom = ival.discrete.denominator;
1594 if (num > G_MAXINT || denom > G_MAXINT) {
1595 /* let us hope we don't get here... */
1600 GST_LOG_OBJECT (v4l2object->element, "adding discrete framerate: %d/%d",
1603 /* swap to get the framerate */
1604 gst_value_set_fraction (&rate, denom, num);
1605 gst_value_list_append_value (&rates, &rate);
1608 } while (v4l2_ioctl (fd, VIDIOC_ENUM_FRAMEINTERVALS, &ival) >= 0);
1609 } else if (ival.type == V4L2_FRMIVAL_TYPE_STEPWISE) {
1610 GValue min = { 0, };
1611 GValue step = { 0, };
1612 GValue max = { 0, };
1613 gboolean added = FALSE;
1614 guint32 minnum, mindenom;
1615 guint32 maxnum, maxdenom;
1617 g_value_init (&rates, GST_TYPE_LIST);
1619 g_value_init (&min, GST_TYPE_FRACTION);
1620 g_value_init (&step, GST_TYPE_FRACTION);
1621 g_value_init (&max, GST_TYPE_FRACTION);
1624 minnum = ival.stepwise.min.numerator;
1625 mindenom = ival.stepwise.min.denominator;
1626 if (minnum > G_MAXINT || mindenom > G_MAXINT) {
1630 GST_LOG_OBJECT (v4l2object->element, "stepwise min frame interval: %d/%d",
1632 gst_value_set_fraction (&min, minnum, mindenom);
1635 maxnum = ival.stepwise.max.numerator;
1636 maxdenom = ival.stepwise.max.denominator;
1637 if (maxnum > G_MAXINT || maxdenom > G_MAXINT) {
1642 GST_LOG_OBJECT (v4l2object->element, "stepwise max frame interval: %d/%d",
1644 gst_value_set_fraction (&max, maxnum, maxdenom);
1647 num = ival.stepwise.step.numerator;
1648 denom = ival.stepwise.step.denominator;
1649 if (num > G_MAXINT || denom > G_MAXINT) {
1654 if (num == 0 || denom == 0) {
1655 /* in this case we have a wrong fraction or no step, set the step to max
1656 * so that we only add the min value in the loop below */
1661 /* since we only have gst_value_fraction_subtract and not add, negate the
1663 GST_LOG_OBJECT (v4l2object->element, "stepwise step frame interval: %d/%d",
1665 gst_value_set_fraction (&step, -num, denom);
1667 while (gst_value_compare (&min, &max) != GST_VALUE_GREATER_THAN) {
1668 GValue rate = { 0, };
1670 num = gst_value_get_fraction_numerator (&min);
1671 denom = gst_value_get_fraction_denominator (&min);
1672 GST_LOG_OBJECT (v4l2object->element, "adding stepwise framerate: %d/%d",
1675 /* invert to get the framerate */
1676 g_value_init (&rate, GST_TYPE_FRACTION);
1677 gst_value_set_fraction (&rate, denom, num);
1678 gst_value_list_append_value (&rates, &rate);
1681 /* we're actually adding because step was negated above. This is because
1682 * there is no _add function... */
1683 if (!gst_value_fraction_subtract (&min, &min, &step)) {
1684 GST_WARNING_OBJECT (v4l2object->element, "could not step fraction!");
1689 /* no range was added, leave the default range from the template */
1690 GST_WARNING_OBJECT (v4l2object->element,
1691 "no range added, leaving default");
1692 g_value_unset (&rates);
1694 } else if (ival.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) {
1695 guint32 maxnum, maxdenom;
1697 g_value_init (&rates, GST_TYPE_FRACTION_RANGE);
1699 num = ival.stepwise.min.numerator;
1700 denom = ival.stepwise.min.denominator;
1701 if (num > G_MAXINT || denom > G_MAXINT) {
1706 maxnum = ival.stepwise.max.numerator;
1707 maxdenom = ival.stepwise.max.denominator;
1708 if (maxnum > G_MAXINT || maxdenom > G_MAXINT) {
1713 GST_LOG_OBJECT (v4l2object->element,
1714 "continuous frame interval %d/%d to %d/%d", maxdenom, maxnum, denom,
1717 gst_value_set_fraction_range_full (&rates, maxdenom, maxnum, denom, num);
1723 s = gst_structure_copy (template);
1724 gst_structure_set (s, "width", G_TYPE_INT, (gint) width,
1725 "height", G_TYPE_INT, (gint) height,
1726 "interlaced", G_TYPE_BOOLEAN, interlaced,
1727 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL);
1729 if (G_IS_VALUE (&rates)) {
1730 /* only change the framerate on the template when we have a valid probed new
1732 gst_structure_set_value (s, "framerate", &rates);
1733 g_value_unset (&rates);
1735 gst_structure_set (s, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, 100, 1,
1741 enum_frameintervals_failed:
1743 GST_DEBUG_OBJECT (v4l2object->element,
1744 "Unable to enumerate intervals for %" GST_FOURCC_FORMAT "@%ux%u",
1745 GST_FOURCC_ARGS (pixelformat), width, height);
1750 /* I don't see how this is actually an error, we ignore the format then */
1751 GST_WARNING_OBJECT (v4l2object->element,
1752 "Unknown frame interval type at %" GST_FOURCC_FORMAT "@%ux%u: %u",
1753 GST_FOURCC_ARGS (pixelformat), width, height, ival.type);
1757 #endif /* defined VIDIOC_ENUM_FRAMEINTERVALS */
1759 #ifdef VIDIOC_ENUM_FRAMESIZES
1761 sort_by_frame_size (GstStructure * s1, GstStructure * s2)
1765 gst_structure_get_int (s1, "width", &w1);
1766 gst_structure_get_int (s1, "height", &h1);
1767 gst_structure_get_int (s2, "width", &w2);
1768 gst_structure_get_int (s2, "height", &h2);
1770 /* I think it's safe to assume that this won't overflow for a while */
1771 return ((w2 * h2) - (w1 * h1));
1776 gst_v4l2_object_probe_caps_for_format (GstV4l2Object * v4l2object,
1777 guint32 pixelformat, const GstStructure * template)
1779 GstCaps *ret = gst_caps_new_empty ();
1782 #ifdef VIDIOC_ENUM_FRAMESIZES
1783 gint fd = v4l2object->video_fd;
1784 struct v4l2_frmsizeenum size;
1785 GList *results = NULL;
1788 if (pixelformat == GST_MAKE_FOURCC ('M', 'P', 'E', 'G'))
1789 return gst_caps_new_simple ("video/mpegts", NULL);
1791 memset (&size, 0, sizeof (struct v4l2_frmsizeenum));
1793 size.pixel_format = pixelformat;
1795 GST_DEBUG_OBJECT (v4l2object->element, "Enumerating frame sizes");
1797 if (v4l2_ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &size) < 0)
1798 goto enum_framesizes_failed;
1800 if (size.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
1802 GST_LOG_OBJECT (v4l2object->element, "got discrete frame size %dx%d",
1803 size.discrete.width, size.discrete.height);
1805 w = MIN (size.discrete.width, G_MAXINT);
1806 h = MIN (size.discrete.height, G_MAXINT);
1810 gst_v4l2_object_probe_caps_for_format_and_size (v4l2object,
1811 pixelformat, w, h, template);
1814 results = g_list_prepend (results, tmp);
1818 } while (v4l2_ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &size) >= 0);
1819 GST_DEBUG_OBJECT (v4l2object->element,
1820 "done iterating discrete frame sizes");
1821 } else if (size.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
1822 GST_DEBUG_OBJECT (v4l2object->element, "we have stepwise frame sizes:");
1823 GST_DEBUG_OBJECT (v4l2object->element, "min width: %d",
1824 size.stepwise.min_width);
1825 GST_DEBUG_OBJECT (v4l2object->element, "min height: %d",
1826 size.stepwise.min_height);
1827 GST_DEBUG_OBJECT (v4l2object->element, "max width: %d",
1828 size.stepwise.max_width);
1829 GST_DEBUG_OBJECT (v4l2object->element, "min height: %d",
1830 size.stepwise.max_height);
1831 GST_DEBUG_OBJECT (v4l2object->element, "step width: %d",
1832 size.stepwise.step_width);
1833 GST_DEBUG_OBJECT (v4l2object->element, "step height: %d",
1834 size.stepwise.step_height);
1836 for (w = size.stepwise.min_width, h = size.stepwise.min_height;
1837 w <= size.stepwise.max_width && h <= size.stepwise.max_height;
1838 w += size.stepwise.step_width, h += size.stepwise.step_height) {
1839 if (w == 0 || h == 0)
1843 gst_v4l2_object_probe_caps_for_format_and_size (v4l2object,
1844 pixelformat, w, h, template);
1847 results = g_list_prepend (results, tmp);
1849 GST_DEBUG_OBJECT (v4l2object->element,
1850 "done iterating stepwise frame sizes");
1851 } else if (size.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) {
1854 GST_DEBUG_OBJECT (v4l2object->element, "we have continuous frame sizes:");
1855 GST_DEBUG_OBJECT (v4l2object->element, "min width: %d",
1856 size.stepwise.min_width);
1857 GST_DEBUG_OBJECT (v4l2object->element, "min height: %d",
1858 size.stepwise.min_height);
1859 GST_DEBUG_OBJECT (v4l2object->element, "max width: %d",
1860 size.stepwise.max_width);
1861 GST_DEBUG_OBJECT (v4l2object->element, "min height: %d",
1862 size.stepwise.max_height);
1864 w = MAX (size.stepwise.min_width, 1);
1865 h = MAX (size.stepwise.min_height, 1);
1866 maxw = MIN (size.stepwise.max_width, G_MAXINT);
1867 maxh = MIN (size.stepwise.max_height, G_MAXINT);
1870 gst_v4l2_object_probe_caps_for_format_and_size (v4l2object, pixelformat,
1873 gst_structure_set (tmp, "width", GST_TYPE_INT_RANGE, (gint) w,
1874 (gint) maxw, "height", GST_TYPE_INT_RANGE, (gint) h, (gint) maxh,
1877 /* no point using the results list here, since there's only one struct */
1878 gst_caps_append_structure (ret, tmp);
1884 /* we use an intermediary list to store and then sort the results of the
1885 * probing because we can't make any assumptions about the order in which
1886 * the driver will give us the sizes, but we want the final caps to contain
1887 * the results starting with the highest resolution and having the lowest
1888 * resolution last, since order in caps matters for things like fixation. */
1889 results = g_list_sort (results, (GCompareFunc) sort_by_frame_size);
1890 while (results != NULL) {
1891 gst_caps_append_structure (ret, GST_STRUCTURE (results->data));
1892 results = g_list_delete_link (results, results);
1895 if (gst_caps_is_empty (ret))
1896 goto enum_framesizes_no_results;
1901 enum_framesizes_failed:
1903 /* I don't see how this is actually an error */
1904 GST_DEBUG_OBJECT (v4l2object->element,
1905 "Failed to enumerate frame sizes for pixelformat %" GST_FOURCC_FORMAT
1906 " (%s)", GST_FOURCC_ARGS (pixelformat), g_strerror (errno));
1907 goto default_frame_sizes;
1909 enum_framesizes_no_results:
1911 /* it's possible that VIDIOC_ENUM_FRAMESIZES is defined but the driver in
1912 * question doesn't actually support it yet */
1913 GST_DEBUG_OBJECT (v4l2object->element,
1914 "No results for pixelformat %" GST_FOURCC_FORMAT
1915 " enumerating frame sizes, trying fallback",
1916 GST_FOURCC_ARGS (pixelformat));
1917 goto default_frame_sizes;
1921 GST_WARNING_OBJECT (v4l2object->element,
1922 "Unknown frame sizeenum type for pixelformat %" GST_FOURCC_FORMAT
1923 ": %u", GST_FOURCC_ARGS (pixelformat), size.type);
1924 goto default_frame_sizes;
1926 default_frame_sizes:
1927 #endif /* defined VIDIOC_ENUM_FRAMESIZES */
1929 gint min_w, max_w, min_h, max_h, fix_num = 0, fix_denom = 0;
1930 gboolean interlaced;
1932 /* This code is for Linux < 2.6.19 */
1934 max_w = max_h = GST_V4L2_MAX_SIZE;
1935 if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &min_w,
1936 &min_h, &interlaced)) {
1937 GST_WARNING_OBJECT (v4l2object->element,
1938 "Could not probe minimum capture size for pixelformat %"
1939 GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
1941 if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &max_w,
1942 &max_h, &interlaced)) {
1943 GST_WARNING_OBJECT (v4l2object->element,
1944 "Could not probe maximum capture size for pixelformat %"
1945 GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
1948 /* Since we can't get framerate directly, try to use the current norm */
1949 if (v4l2object->tv_norm && v4l2object->norms) {
1951 GstTunerNorm *norm = NULL;
1952 GstTunerNorm *current =
1953 gst_v4l2_tuner_get_norm_by_std_id (v4l2object, v4l2object->tv_norm);
1955 for (norms = v4l2object->norms; norms != NULL; norms = norms->next) {
1956 norm = (GstTunerNorm *) norms->data;
1957 if (!strcmp (norm->label, current->label))
1960 /* If it's possible, set framerate to that (discrete) value */
1962 fix_num = gst_value_get_fraction_numerator (&norm->framerate);
1963 fix_denom = gst_value_get_fraction_denominator (&norm->framerate);
1967 tmp = gst_structure_copy (template);
1969 gst_structure_set (tmp, "framerate", GST_TYPE_FRACTION, fix_num,
1972 /* if norm can't be used, copy the template framerate */
1973 gst_structure_set (tmp, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1,
1978 gst_structure_set (tmp, "width", G_TYPE_INT, max_w, NULL);
1980 gst_structure_set (tmp, "width", GST_TYPE_INT_RANGE, min_w, max_w, NULL);
1983 gst_structure_set (tmp, "height", G_TYPE_INT, max_h, NULL);
1985 gst_structure_set (tmp, "height", GST_TYPE_INT_RANGE, min_h, max_h, NULL);
1987 gst_structure_set (tmp, "interlaced", G_TYPE_BOOLEAN, interlaced, NULL);
1988 gst_structure_set (tmp, "pixel-aspect-ratio",
1989 GST_TYPE_FRACTION, 1, 1, NULL);
1991 gst_caps_append_structure (ret, tmp);
1998 gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
1999 guint32 pixelformat, gint * width, gint * height, gboolean * interlaced)
2001 struct v4l2_format fmt, prevfmt;
2006 g_return_val_if_fail (width != NULL, FALSE);
2007 g_return_val_if_fail (height != NULL, FALSE);
2009 GST_LOG_OBJECT (v4l2object->element,
2010 "getting nearest size to %dx%d with format %" GST_FOURCC_FORMAT,
2011 *width, *height, GST_FOURCC_ARGS (pixelformat));
2013 fd = v4l2object->video_fd;
2015 /* Some drivers are buggy and will modify the currently set format
2016 when processing VIDIOC_TRY_FMT, so we remember what is set at the
2017 minute, and will reset it when done. */
2018 prevfmt_valid = (v4l2_ioctl (fd, VIDIOC_G_FMT, &prevfmt) >= 0);
2020 /* get size delimiters */
2021 memset (&fmt, 0, sizeof (fmt));
2022 fmt.type = v4l2object->type;
2023 fmt.fmt.pix.width = *width;
2024 fmt.fmt.pix.height = *height;
2025 fmt.fmt.pix.pixelformat = pixelformat;
2026 fmt.fmt.pix.field = V4L2_FIELD_NONE;
2028 r = v4l2_ioctl (fd, VIDIOC_TRY_FMT, &fmt);
2029 if (r < 0 && errno == EINVAL) {
2030 /* try again with interlaced video */
2031 fmt.fmt.pix.width = *width;
2032 fmt.fmt.pix.height = *height;
2033 fmt.fmt.pix.pixelformat = pixelformat;
2034 fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
2035 r = v4l2_ioctl (fd, VIDIOC_TRY_FMT, &fmt);
2039 /* The driver might not implement TRY_FMT, in which case we will try
2041 if (errno != ENOTTY)
2044 /* Only try S_FMT if we're not actively capturing yet, which we shouldn't
2045 be, because we're still probing */
2046 if (GST_V4L2_IS_ACTIVE (v4l2object))
2049 GST_LOG_OBJECT (v4l2object->element,
2050 "Failed to probe size limit with VIDIOC_TRY_FMT, trying VIDIOC_S_FMT");
2052 fmt.fmt.pix.width = *width;
2053 fmt.fmt.pix.height = *height;
2055 r = v4l2_ioctl (fd, VIDIOC_S_FMT, &fmt);
2056 if (r < 0 && errno == EINVAL) {
2057 /* try again with progressive video */
2058 fmt.fmt.pix.width = *width;
2059 fmt.fmt.pix.height = *height;
2060 fmt.fmt.pix.pixelformat = pixelformat;
2061 fmt.fmt.pix.field = V4L2_FIELD_NONE;
2062 r = v4l2_ioctl (fd, VIDIOC_S_FMT, &fmt);
2069 GST_LOG_OBJECT (v4l2object->element,
2070 "got nearest size %dx%d", fmt.fmt.pix.width, fmt.fmt.pix.height);
2072 *width = fmt.fmt.pix.width;
2073 *height = fmt.fmt.pix.height;
2075 switch (fmt.fmt.pix.field) {
2076 case V4L2_FIELD_ANY:
2077 case V4L2_FIELD_NONE:
2078 *interlaced = FALSE;
2080 case V4L2_FIELD_INTERLACED:
2081 case V4L2_FIELD_INTERLACED_TB:
2082 case V4L2_FIELD_INTERLACED_BT:
2086 GST_WARNING_OBJECT (v4l2object->element,
2087 "Unsupported field type for %" GST_FOURCC_FORMAT "@%ux%u",
2088 GST_FOURCC_ARGS (pixelformat), *width, *height);
2093 v4l2_ioctl (fd, VIDIOC_S_FMT, &prevfmt);
2098 v4l2_ioctl (fd, VIDIOC_S_FMT, &prevfmt);
2104 gst_v4l2_object_set_format (GstV4l2Object * v4l2object, guint32 pixelformat,
2105 guint32 width, guint32 height, gboolean interlaced)
2107 gint fd = v4l2object->video_fd;
2108 struct v4l2_format format;
2109 enum v4l2_field field;
2112 GST_DEBUG_OBJECT (v4l2object->element, "interlaced video");
2113 /* ideally we would differentiate between types of interlaced video
2114 * but there is not sufficient information in the caps..
2116 field = V4L2_FIELD_INTERLACED;
2118 GST_DEBUG_OBJECT (v4l2object->element, "progressive video");
2119 field = V4L2_FIELD_NONE;
2122 GST_DEBUG_OBJECT (v4l2object->element, "Setting format to %dx%d, format "
2123 "%" GST_FOURCC_FORMAT, width, height, GST_FOURCC_ARGS (pixelformat));
2125 GST_V4L2_CHECK_OPEN (v4l2object);
2126 GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
2128 /* Only unconditionally accept mpegts for sources */
2129 if ((v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
2130 (pixelformat == GST_MAKE_FOURCC ('M', 'P', 'E', 'G')))
2133 memset (&format, 0x00, sizeof (struct v4l2_format));
2134 format.type = v4l2object->type;
2136 if (v4l2_ioctl (fd, VIDIOC_G_FMT, &format) < 0)
2137 goto get_fmt_failed;
2139 if (format.type == v4l2object->type &&
2140 format.fmt.pix.width == width &&
2141 format.fmt.pix.height == height &&
2142 format.fmt.pix.pixelformat == pixelformat &&
2143 format.fmt.pix.field == field) {
2144 /* Nothing to do. We want to succeed immediately
2145 * here because setting the same format back
2146 * can still fail due to EBUSY. By short-circuiting
2147 * here, we allow pausing and re-playing pipelines
2148 * with changed caps, as long as the changed caps
2149 * do not change the webcam's format. Otherwise,
2150 * any caps change would require us to go to NULL
2151 * state to close the device and set format.
2156 format.type = v4l2object->type;
2157 format.fmt.pix.width = width;
2158 format.fmt.pix.height = height;
2159 format.fmt.pix.pixelformat = pixelformat;
2160 format.fmt.pix.field = field;
2162 if (v4l2_ioctl (fd, VIDIOC_S_FMT, &format) < 0) {
2163 goto set_fmt_failed;
2166 if (format.fmt.pix.width != width || format.fmt.pix.height != height)
2167 goto invalid_dimensions;
2169 if (format.fmt.pix.pixelformat != pixelformat)
2170 goto invalid_pixelformat;
2177 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
2178 (_("Device '%s' does not support video capture"),
2179 v4l2object->videodev),
2180 ("Call to G_FMT failed: (%s)", g_strerror (errno)));
2185 if (errno == EBUSY) {
2186 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, BUSY,
2187 (_("Device '%s' is busy"), v4l2object->videodev),
2188 ("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
2189 GST_FOURCC_ARGS (pixelformat), width, height,
2190 g_strerror (errno)));
2192 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
2193 (_("Device '%s' cannot capture at %dx%d"),
2194 v4l2object->videodev, width, height),
2195 ("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
2196 GST_FOURCC_ARGS (pixelformat), width, height,
2197 g_strerror (errno)));
2203 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
2204 (_("Device '%s' cannot capture at %dx%d"),
2205 v4l2object->videodev, width, height),
2206 ("Tried to capture at %dx%d, but device returned size %dx%d",
2207 width, height, format.fmt.pix.width, format.fmt.pix.height));
2210 invalid_pixelformat:
2212 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
2213 (_("Device '%s' cannot capture in the specified format"),
2214 v4l2object->videodev),
2215 ("Tried to capture in %" GST_FOURCC_FORMAT
2216 ", but device returned format" " %" GST_FOURCC_FORMAT,
2217 GST_FOURCC_ARGS (pixelformat),
2218 GST_FOURCC_ARGS (format.fmt.pix.pixelformat)));
2224 gst_v4l2_object_start_streaming (GstV4l2Object * v4l2object)
2226 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_STREAMON,
2227 &(v4l2object->type)) < 0) {
2228 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, OPEN_READ,
2229 (_("Error starting streaming on device '%s'."), v4l2object->videodev),
2237 gst_v4l2_object_stop_streaming (GstV4l2Object * v4l2object)
2239 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_STREAMOFF,
2240 &(v4l2object->type)) < 0) {
2241 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, OPEN_READ,
2242 (_("Error stopping streaming on device '%s'."), v4l2object->videodev),