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 #include <gst/video/video.h>
46 /* videodev2.h is not versioned and we can't easily check for the presence
47 * of enum values at compile time, but the V4L2_CAP_VIDEO_OUTPUT_OVERLAY define
48 * was added in the same commit as V4L2_FIELD_INTERLACED_{TB,BT} (b2787845) */
49 #ifndef V4L2_CAP_VIDEO_OUTPUT_OVERLAY
50 #define V4L2_FIELD_INTERLACED_TB 8
51 #define V4L2_FIELD_INTERLACED_BT 9
54 GST_DEBUG_CATEGORY_EXTERN (v4l2_debug);
55 #define GST_CAT_DEFAULT v4l2_debug
58 #define DEFAULT_PROP_DEVICE_NAME NULL
59 #define DEFAULT_PROP_DEVICE_FD -1
60 #define DEFAULT_PROP_FLAGS 0
61 #define DEFAULT_PROP_TV_NORM 0
62 #define DEFAULT_PROP_CHANNEL NULL
63 #define DEFAULT_PROP_FREQUENCY 0
68 V4L2_STD_OBJECT_PROPS,
71 G_LOCK_DEFINE_STATIC (probe_lock);
74 gst_v4l2_probe_get_properties (GstPropertyProbe * probe)
76 GObjectClass *klass = G_OBJECT_GET_CLASS (probe);
77 static GList *list = NULL;
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->active = FALSE;
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=%d, norm=%p",
710 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 #define YUV_BASE_RANK 1000
899 #define JPEG_BASE_RANK 500
900 #define DV_BASE_RANK 200
901 #define RGB_BASE_RANK 100
902 #define YUV_ODD_BASE_RANK 50
903 #define RGB_ODD_BASE_RANK 25
904 #define BAYER_BASE_RANK 15
905 #define S910_BASE_RANK 10
906 #define GREY_BASE_RANK 5
907 #define PWC_BASE_RANK 1
909 /* This flag is already used by libv4l2 although
910 * it was added to the Linux kernel in 2.6.32
912 #ifndef V4L2_FMT_FLAG_EMULATED
913 #define V4L2_FMT_FLAG_EMULATED 0x0002
917 gst_v4l2_object_format_get_rank (const struct v4l2_fmtdesc *fmt)
919 guint32 fourcc = fmt->pixelformat;
920 gboolean emulated = ((fmt->flags & V4L2_FMT_FLAG_EMULATED) != 0);
924 case V4L2_PIX_FMT_MJPEG:
925 #ifdef V4L2_PIX_FMT_PJPG
926 case V4L2_PIX_FMT_PJPG:
927 rank = JPEG_BASE_RANK;
930 case V4L2_PIX_FMT_JPEG:
931 rank = JPEG_BASE_RANK + 1;
933 case V4L2_PIX_FMT_MPEG: /* MPEG */
934 rank = JPEG_BASE_RANK + 2;
937 case V4L2_PIX_FMT_RGB332:
938 case V4L2_PIX_FMT_RGB555:
939 case V4L2_PIX_FMT_RGB555X:
940 case V4L2_PIX_FMT_RGB565:
941 case V4L2_PIX_FMT_RGB565X:
942 rank = RGB_ODD_BASE_RANK;
945 case V4L2_PIX_FMT_RGB24:
946 case V4L2_PIX_FMT_BGR24:
947 rank = RGB_BASE_RANK - 1;
950 case V4L2_PIX_FMT_RGB32:
951 case V4L2_PIX_FMT_BGR32:
952 rank = RGB_BASE_RANK;
955 case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
956 rank = GREY_BASE_RANK;
959 case V4L2_PIX_FMT_NV12: /* 12 Y/CbCr 4:2:0 */
960 case V4L2_PIX_FMT_NV21: /* 12 Y/CrCb 4:2:0 */
961 case V4L2_PIX_FMT_YYUV: /* 16 YUV 4:2:2 */
962 case V4L2_PIX_FMT_HI240: /* 8 8-bit color */
963 rank = YUV_ODD_BASE_RANK;
966 case V4L2_PIX_FMT_YVU410: /* YVU9, 9 bits per pixel */
967 rank = YUV_BASE_RANK + 3;
969 case V4L2_PIX_FMT_YUV410: /* YUV9, 9 bits per pixel */
970 rank = YUV_BASE_RANK + 2;
972 case V4L2_PIX_FMT_YUV420: /* I420, 12 bits per pixel */
973 rank = YUV_BASE_RANK + 7;
975 case V4L2_PIX_FMT_YUYV: /* YUY2, 16 bits per pixel */
976 rank = YUV_BASE_RANK + 10;
978 case V4L2_PIX_FMT_YVU420: /* YV12, 12 bits per pixel */
979 rank = YUV_BASE_RANK + 6;
981 case V4L2_PIX_FMT_UYVY: /* UYVY, 16 bits per pixel */
982 rank = YUV_BASE_RANK + 9;
984 case V4L2_PIX_FMT_Y41P: /* Y41P, 12 bits per pixel */
985 rank = YUV_BASE_RANK + 5;
987 case V4L2_PIX_FMT_YUV411P: /* Y41B, 12 bits per pixel */
988 rank = YUV_BASE_RANK + 4;
990 case V4L2_PIX_FMT_YUV422P: /* Y42B, 16 bits per pixel */
991 rank = YUV_BASE_RANK + 8;
994 case V4L2_PIX_FMT_DV:
998 case V4L2_PIX_FMT_WNVA: /* Winnov hw compres */
1002 #ifdef V4L2_PIX_FMT_SBGGR8
1003 case V4L2_PIX_FMT_SBGGR8:
1004 rank = BAYER_BASE_RANK;
1008 #ifdef V4L2_PIX_FMT_SN9C10X
1009 case V4L2_PIX_FMT_SN9C10X:
1010 rank = S910_BASE_RANK;
1014 #ifdef V4L2_PIX_FMT_PWC1
1015 case V4L2_PIX_FMT_PWC1:
1016 rank = PWC_BASE_RANK;
1019 #ifdef V4L2_PIX_FMT_PWC2
1020 case V4L2_PIX_FMT_PWC2:
1021 rank = PWC_BASE_RANK;
1030 /* All ranks are below 1<<15 so a shift by 15
1031 * will a) make all non-emulated formats larger
1032 * than emulated and b) will not overflow
1043 format_cmp_func (gconstpointer a, gconstpointer b)
1045 const struct v4l2_fmtdesc *fa = a;
1046 const struct v4l2_fmtdesc *fb = b;
1048 if (fa->pixelformat == fb->pixelformat)
1051 return gst_v4l2_object_format_get_rank (fb) -
1052 gst_v4l2_object_format_get_rank (fa);
1055 /******************************************************
1056 * gst_v4l2_object_fill_format_list():
1057 * create list of supported capture formats
1058 * return value: TRUE on success, FALSE on error
1059 ******************************************************/
1061 gst_v4l2_object_fill_format_list (GstV4l2Object * v4l2object)
1064 struct v4l2_fmtdesc *format;
1066 GST_DEBUG_OBJECT (v4l2object->element, "getting src format enumerations");
1068 /* format enumeration */
1070 format = g_new0 (struct v4l2_fmtdesc, 1);
1073 format->type = v4l2object->type;
1075 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_ENUM_FMT, format) < 0) {
1076 if (errno == EINVAL) {
1078 break; /* end of enumeration */
1084 GST_LOG_OBJECT (v4l2object->element, "index: %u", format->index);
1085 GST_LOG_OBJECT (v4l2object->element, "type: %d", format->type);
1086 GST_LOG_OBJECT (v4l2object->element, "flags: %08x", format->flags);
1087 GST_LOG_OBJECT (v4l2object->element, "description: '%s'",
1088 format->description);
1089 GST_LOG_OBJECT (v4l2object->element, "pixelformat: %" GST_FOURCC_FORMAT,
1090 GST_FOURCC_ARGS (format->pixelformat));
1092 /* sort formats according to our preference; we do this, because caps
1093 * are probed in the order the formats are in the list, and the order of
1094 * formats in the final probed caps matters for things like fixation */
1095 v4l2object->formats = g_slist_insert_sorted (v4l2object->formats, format,
1096 (GCompareFunc) format_cmp_func);
1099 #ifndef GST_DISABLE_GST_DEBUG
1103 GST_INFO_OBJECT (v4l2object->element, "got %d format(s):", n);
1104 for (l = v4l2object->formats; l != NULL; l = l->next) {
1107 GST_INFO_OBJECT (v4l2object->element,
1108 " %" GST_FOURCC_FORMAT "%s", GST_FOURCC_ARGS (format->pixelformat),
1109 ((format->flags & V4L2_FMT_FLAG_EMULATED)) ? " (emulated)" : "");
1119 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
1120 (_("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)));
1127 * Get the list of supported capture formats, a list of
1128 * <code>struct v4l2_fmtdesc</code>.
1131 gst_v4l2_object_get_format_list (GstV4l2Object * v4l2object)
1133 if (!v4l2object->formats)
1134 gst_v4l2_object_fill_format_list (v4l2object);
1135 return v4l2object->formats;
1140 gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc)
1142 GstStructure *structure = NULL;
1145 case V4L2_PIX_FMT_MJPEG: /* Motion-JPEG */
1146 #ifdef V4L2_PIX_FMT_PJPG
1147 case V4L2_PIX_FMT_PJPG: /* Progressive-JPEG */
1149 case V4L2_PIX_FMT_JPEG: /* JFIF JPEG */
1150 structure = gst_structure_new ("image/jpeg", NULL);
1152 case V4L2_PIX_FMT_YYUV: /* 16 YUV 4:2:2 */
1153 case V4L2_PIX_FMT_HI240: /* 8 8-bit color */
1154 /* FIXME: get correct fourccs here */
1156 case V4L2_PIX_FMT_RGB332:
1157 case V4L2_PIX_FMT_RGB555X:
1158 case V4L2_PIX_FMT_RGB565X:
1159 /* FIXME: get correct fourccs here */
1161 case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
1162 case V4L2_PIX_FMT_RGB555:
1163 case V4L2_PIX_FMT_RGB565:
1164 case V4L2_PIX_FMT_RGB24:
1165 case V4L2_PIX_FMT_BGR24:
1166 case V4L2_PIX_FMT_RGB32:
1167 case V4L2_PIX_FMT_BGR32:
1168 case V4L2_PIX_FMT_NV12: /* 12 Y/CbCr 4:2:0 */
1169 case V4L2_PIX_FMT_NV21: /* 12 Y/CrCb 4:2:0 */
1170 case V4L2_PIX_FMT_YVU410:
1171 case V4L2_PIX_FMT_YUV410:
1172 case V4L2_PIX_FMT_YUV420: /* I420/IYUV */
1173 case V4L2_PIX_FMT_YUYV:
1174 case V4L2_PIX_FMT_YVU420:
1175 case V4L2_PIX_FMT_UYVY:
1177 case V4L2_PIX_FMT_Y41P:
1179 case V4L2_PIX_FMT_YUV422P:
1180 #ifdef V4L2_PIX_FMT_YVYU
1181 case V4L2_PIX_FMT_YVYU:
1183 case V4L2_PIX_FMT_YUV411P:{
1184 GstVideoFormat format;
1187 case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
1188 format = GST_VIDEO_FORMAT_GRAY8;
1190 case V4L2_PIX_FMT_RGB555:
1191 format = GST_VIDEO_FORMAT_RGB15;
1193 case V4L2_PIX_FMT_RGB565:
1194 format = GST_VIDEO_FORMAT_RGB16;
1196 case V4L2_PIX_FMT_RGB24:
1197 format = GST_VIDEO_FORMAT_RGB;
1199 case V4L2_PIX_FMT_BGR24:
1200 format = GST_VIDEO_FORMAT_BGR;
1202 case V4L2_PIX_FMT_RGB32:
1203 format = GST_VIDEO_FORMAT_RGBx;
1205 case V4L2_PIX_FMT_BGR32:
1206 format = GST_VIDEO_FORMAT_BGRx;
1208 case V4L2_PIX_FMT_NV12:
1209 format = GST_VIDEO_FORMAT_NV12;
1211 case V4L2_PIX_FMT_NV21:
1212 format = GST_VIDEO_FORMAT_NV21;
1214 case V4L2_PIX_FMT_YVU410:
1215 format = GST_VIDEO_FORMAT_YVU9;
1217 case V4L2_PIX_FMT_YUV410:
1218 format = GST_VIDEO_FORMAT_YUV9;
1220 case V4L2_PIX_FMT_YUV420:
1221 format = GST_VIDEO_FORMAT_I420;
1223 case V4L2_PIX_FMT_YUYV:
1224 format = GST_VIDEO_FORMAT_YUY2;
1226 case V4L2_PIX_FMT_YVU420:
1227 format = GST_VIDEO_FORMAT_YV12;
1229 case V4L2_PIX_FMT_UYVY:
1230 format = GST_VIDEO_FORMAT_UYVY;
1233 case V4L2_PIX_FMT_Y41P:
1234 format = GST_VIDEO_FORMAT_Y41P;
1237 case V4L2_PIX_FMT_YUV411P:
1238 format = GST_VIDEO_FORMAT_Y41B;
1240 case V4L2_PIX_FMT_YUV422P:
1241 format = GST_VIDEO_FORMAT_Y42B;
1243 #ifdef V4L2_PIX_FMT_YVYU
1244 case V4L2_PIX_FMT_YVYU:
1245 format = GST_VIDEO_FORMAT_YVYU;
1249 g_assert_not_reached ();
1252 structure = gst_structure_new ("video/x-raw",
1253 "format", G_TYPE_STRING, gst_video_format_to_string (format), NULL);
1256 case V4L2_PIX_FMT_DV:
1258 gst_structure_new ("video/x-dv", "systemstream", G_TYPE_BOOLEAN, TRUE,
1261 case V4L2_PIX_FMT_MPEG: /* MPEG */
1262 structure = gst_structure_new ("video/mpegts", NULL);
1264 case V4L2_PIX_FMT_WNVA: /* Winnov hw compres */
1266 #ifdef V4L2_PIX_FMT_SBGGR8
1267 case V4L2_PIX_FMT_SBGGR8:
1268 structure = gst_structure_new ("video/x-raw-bayer", NULL);
1271 #ifdef V4L2_PIX_FMT_SN9C10X
1272 case V4L2_PIX_FMT_SN9C10X:
1273 structure = gst_structure_new ("video/x-sonix", NULL);
1276 #ifdef V4L2_PIX_FMT_PWC1
1277 case V4L2_PIX_FMT_PWC1:
1278 structure = gst_structure_new ("video/x-pwc1", NULL);
1281 #ifdef V4L2_PIX_FMT_PWC2
1282 case V4L2_PIX_FMT_PWC2:
1283 structure = gst_structure_new ("video/x-pwc2", NULL);
1287 GST_DEBUG ("Unknown fourcc 0x%08x %" GST_FOURCC_FORMAT,
1288 fourcc, GST_FOURCC_ARGS (fourcc));
1298 gst_v4l2_object_get_all_caps (void)
1300 static GstCaps *caps = NULL;
1303 GstStructure *structure;
1307 caps = gst_caps_new_empty ();
1308 for (i = 0; i < GST_V4L2_FORMAT_COUNT; i++) {
1310 gst_v4l2_object_v4l2fourcc_to_structure (gst_v4l2_formats[i].format);
1312 if (gst_v4l2_formats[i].dimensions) {
1313 gst_structure_set (structure,
1314 "width", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1315 "height", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1316 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, 100, 1, NULL);
1318 gst_caps_append_structure (caps, structure);
1323 return gst_caps_ref (caps);
1327 /* collect data for the given caps
1328 * @caps: given input caps
1329 * @format: location for the v4l format
1330 * @w/@h: location for width and height
1331 * @fps_n/@fps_d: location for framerate
1332 * @size: location for expected size of the frame or 0 if unknown
1335 gst_v4l2_object_get_caps_info (GstV4l2Object * v4l2object, GstCaps * caps,
1336 struct v4l2_fmtdesc **format, GstVideoInfo * info)
1338 GstStructure *structure;
1340 const gchar *mimetype;
1342 /* default unknown values */
1345 structure = gst_caps_get_structure (caps, 0);
1347 mimetype = gst_structure_get_name (structure);
1349 if (g_str_equal (mimetype, "video/x-raw")) {
1350 /* raw caps, parse into video info */
1351 if (!gst_video_info_from_caps (info, caps))
1352 goto invalid_format;
1354 switch (GST_VIDEO_INFO_FORMAT (info)) {
1355 case GST_VIDEO_FORMAT_I420:
1356 fourcc = V4L2_PIX_FMT_YUV420;
1358 case GST_VIDEO_FORMAT_YUY2:
1359 fourcc = V4L2_PIX_FMT_YUYV;
1362 case GST_VIDEO_FORMAT_Y41P:
1363 fourcc = V4L2_PIX_FMT_Y41P;
1366 case GST_VIDEO_FORMAT_UYVY:
1367 fourcc = V4L2_PIX_FMT_UYVY;
1369 case GST_VIDEO_FORMAT_YV12:
1370 fourcc = V4L2_PIX_FMT_YVU420;
1372 case GST_VIDEO_FORMAT_Y41B:
1373 fourcc = V4L2_PIX_FMT_YUV411P;
1375 case GST_VIDEO_FORMAT_Y42B:
1376 fourcc = V4L2_PIX_FMT_YUV422P;
1378 case GST_VIDEO_FORMAT_NV12:
1379 fourcc = V4L2_PIX_FMT_NV12;
1381 case GST_VIDEO_FORMAT_NV21:
1382 fourcc = V4L2_PIX_FMT_NV21;
1384 #ifdef V4L2_PIX_FMT_YVYU
1385 case GST_VIDEO_FORMAT_YVYU:
1386 fourcc = V4L2_PIX_FMT_YVYU;
1389 case GST_VIDEO_FORMAT_RGB15:
1390 fourcc = V4L2_PIX_FMT_RGB555;
1392 case GST_VIDEO_FORMAT_RGB16:
1393 fourcc = V4L2_PIX_FMT_RGB565;
1395 case GST_VIDEO_FORMAT_RGB:
1396 fourcc = V4L2_PIX_FMT_RGB24;
1398 case GST_VIDEO_FORMAT_BGR:
1399 fourcc = V4L2_PIX_FMT_BGR24;
1401 case GST_VIDEO_FORMAT_RGBx:
1402 case GST_VIDEO_FORMAT_RGBA:
1403 fourcc = V4L2_PIX_FMT_RGB32;
1405 case GST_VIDEO_FORMAT_BGRx:
1406 case GST_VIDEO_FORMAT_BGRA:
1407 fourcc = V4L2_PIX_FMT_BGR32;
1409 case GST_VIDEO_FORMAT_GRAY8:
1410 fourcc = V4L2_PIX_FMT_GREY;
1415 gboolean dimensions = TRUE;
1417 /* no video caps, construct videoinfo ourselves */
1418 gst_video_info_init (info);
1420 if (g_str_equal (mimetype, "video/mpegts")) {
1421 fourcc = V4L2_PIX_FMT_MPEG;
1423 } else if (g_str_equal (mimetype, "video/x-dv")) {
1424 fourcc = V4L2_PIX_FMT_DV;
1425 } else if (g_str_equal (mimetype, "image/jpeg")) {
1426 fourcc = V4L2_PIX_FMT_JPEG;
1427 #ifdef V4L2_PIX_FMT_SBGGR8
1428 } else if (g_str_equal (mimetype, "video/x-raw-bayer")) {
1429 fourcc = V4L2_PIX_FMT_SBGGR8;
1431 #ifdef V4L2_PIX_FMT_SN9C10X
1432 } else if (g_str_equal (mimetype, "video/x-sonix")) {
1433 fourcc = V4L2_PIX_FMT_SN9C10X;
1435 #ifdef V4L2_PIX_FMT_PWC1
1436 } else if (g_str_equal (mimetype, "video/x-pwc1")) {
1437 fourcc = V4L2_PIX_FMT_PWC1;
1439 #ifdef V4L2_PIX_FMT_PWC2
1440 } else if (g_str_equal (mimetype, "video/x-pwc2")) {
1441 fourcc = V4L2_PIX_FMT_PWC2;
1446 gboolean interlaced;
1448 if (!gst_structure_get_int (structure, "width", &info->width))
1451 if (!gst_structure_get_int (structure, "height", &info->height))
1454 if (!gst_structure_get_boolean (structure, "interlaced", &interlaced))
1457 info->flags |= GST_VIDEO_FLAG_INTERLACED;
1459 if (!gst_structure_get_fraction (structure, "framerate", &info->fps_n,
1466 goto unhandled_format;
1468 *format = gst_v4l2_object_get_format_from_fourcc (v4l2object, fourcc);
1475 GST_DEBUG_OBJECT (v4l2object, "no width");
1480 GST_DEBUG_OBJECT (v4l2object, "no height");
1485 GST_DEBUG_OBJECT (v4l2object, "no framerate");
1490 GST_DEBUG_OBJECT (v4l2object, "invalid format");
1495 GST_DEBUG_OBJECT (v4l2object, "unhandled format");
1502 gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
1503 guint32 pixelformat, gint * width, gint * height, gboolean * interlaced);
1506 /* The frame interval enumeration code first appeared in Linux 2.6.19. */
1507 #ifdef VIDIOC_ENUM_FRAMEINTERVALS
1508 static GstStructure *
1509 gst_v4l2_object_probe_caps_for_format_and_size (GstV4l2Object * v4l2object,
1510 guint32 pixelformat,
1511 guint32 width, guint32 height, const GstStructure * template)
1513 gint fd = v4l2object->video_fd;
1514 struct v4l2_frmivalenum ival;
1517 GValue rates = { 0, };
1518 gboolean interlaced;
1519 gint int_width = width;
1520 gint int_height = height;
1522 /* interlaced detection using VIDIOC_TRY/S_FMT */
1523 if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat,
1524 &int_width, &int_height, &interlaced))
1527 memset (&ival, 0, sizeof (struct v4l2_frmivalenum));
1529 ival.pixel_format = pixelformat;
1531 ival.height = height;
1533 GST_LOG_OBJECT (v4l2object->element,
1534 "get frame interval for %ux%u, %" GST_FOURCC_FORMAT, width, height,
1535 GST_FOURCC_ARGS (pixelformat));
1537 /* keep in mind that v4l2 gives us frame intervals (durations); we invert the
1538 * fraction to get framerate */
1539 if (v4l2_ioctl (fd, VIDIOC_ENUM_FRAMEINTERVALS, &ival) < 0)
1540 goto enum_frameintervals_failed;
1542 if (ival.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
1543 GValue rate = { 0, };
1545 g_value_init (&rates, GST_TYPE_LIST);
1546 g_value_init (&rate, GST_TYPE_FRACTION);
1549 num = ival.discrete.numerator;
1550 denom = ival.discrete.denominator;
1552 if (num > G_MAXINT || denom > G_MAXINT) {
1553 /* let us hope we don't get here... */
1558 GST_LOG_OBJECT (v4l2object->element, "adding discrete framerate: %d/%d",
1561 /* swap to get the framerate */
1562 gst_value_set_fraction (&rate, denom, num);
1563 gst_value_list_append_value (&rates, &rate);
1566 } while (v4l2_ioctl (fd, VIDIOC_ENUM_FRAMEINTERVALS, &ival) >= 0);
1567 } else if (ival.type == V4L2_FRMIVAL_TYPE_STEPWISE) {
1568 GValue min = { 0, };
1569 GValue step = { 0, };
1570 GValue max = { 0, };
1571 gboolean added = FALSE;
1572 guint32 minnum, mindenom;
1573 guint32 maxnum, maxdenom;
1575 g_value_init (&rates, GST_TYPE_LIST);
1577 g_value_init (&min, GST_TYPE_FRACTION);
1578 g_value_init (&step, GST_TYPE_FRACTION);
1579 g_value_init (&max, GST_TYPE_FRACTION);
1582 minnum = ival.stepwise.min.numerator;
1583 mindenom = ival.stepwise.min.denominator;
1584 if (minnum > G_MAXINT || mindenom > G_MAXINT) {
1588 GST_LOG_OBJECT (v4l2object->element, "stepwise min frame interval: %d/%d",
1590 gst_value_set_fraction (&min, minnum, mindenom);
1593 maxnum = ival.stepwise.max.numerator;
1594 maxdenom = ival.stepwise.max.denominator;
1595 if (maxnum > G_MAXINT || maxdenom > G_MAXINT) {
1600 GST_LOG_OBJECT (v4l2object->element, "stepwise max frame interval: %d/%d",
1602 gst_value_set_fraction (&max, maxnum, maxdenom);
1605 num = ival.stepwise.step.numerator;
1606 denom = ival.stepwise.step.denominator;
1607 if (num > G_MAXINT || denom > G_MAXINT) {
1612 if (num == 0 || denom == 0) {
1613 /* in this case we have a wrong fraction or no step, set the step to max
1614 * so that we only add the min value in the loop below */
1619 /* since we only have gst_value_fraction_subtract and not add, negate the
1621 GST_LOG_OBJECT (v4l2object->element, "stepwise step frame interval: %d/%d",
1623 gst_value_set_fraction (&step, -num, denom);
1625 while (gst_value_compare (&min, &max) <= 0) {
1626 GValue rate = { 0, };
1628 num = gst_value_get_fraction_numerator (&min);
1629 denom = gst_value_get_fraction_denominator (&min);
1630 GST_LOG_OBJECT (v4l2object->element, "adding stepwise framerate: %d/%d",
1633 /* invert to get the framerate */
1634 g_value_init (&rate, GST_TYPE_FRACTION);
1635 gst_value_set_fraction (&rate, denom, num);
1636 gst_value_list_append_value (&rates, &rate);
1639 /* we're actually adding because step was negated above. This is because
1640 * there is no _add function... */
1641 if (!gst_value_fraction_subtract (&min, &min, &step)) {
1642 GST_WARNING_OBJECT (v4l2object->element, "could not step fraction!");
1647 /* no range was added, leave the default range from the template */
1648 GST_WARNING_OBJECT (v4l2object->element,
1649 "no range added, leaving default");
1650 g_value_unset (&rates);
1652 } else if (ival.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) {
1653 guint32 maxnum, maxdenom;
1655 g_value_init (&rates, GST_TYPE_FRACTION_RANGE);
1657 num = ival.stepwise.min.numerator;
1658 denom = ival.stepwise.min.denominator;
1659 if (num > G_MAXINT || denom > G_MAXINT) {
1664 maxnum = ival.stepwise.max.numerator;
1665 maxdenom = ival.stepwise.max.denominator;
1666 if (maxnum > G_MAXINT || maxdenom > G_MAXINT) {
1671 GST_LOG_OBJECT (v4l2object->element,
1672 "continuous frame interval %d/%d to %d/%d", maxdenom, maxnum, denom,
1675 gst_value_set_fraction_range_full (&rates, maxdenom, maxnum, denom, num);
1681 s = gst_structure_copy (template);
1682 gst_structure_set (s, "width", G_TYPE_INT, (gint) width,
1683 "height", G_TYPE_INT, (gint) height,
1684 "interlaced", G_TYPE_BOOLEAN, interlaced, NULL);
1686 if (G_IS_VALUE (&rates)) {
1687 /* only change the framerate on the template when we have a valid probed new
1689 gst_structure_set_value (s, "framerate", &rates);
1690 g_value_unset (&rates);
1692 gst_structure_set (s, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, 100, 1,
1698 enum_frameintervals_failed:
1700 GST_DEBUG_OBJECT (v4l2object->element,
1701 "Unable to enumerate intervals for %" GST_FOURCC_FORMAT "@%ux%u",
1702 GST_FOURCC_ARGS (pixelformat), width, height);
1707 /* I don't see how this is actually an error, we ignore the format then */
1708 GST_WARNING_OBJECT (v4l2object->element,
1709 "Unknown frame interval type at %" GST_FOURCC_FORMAT "@%ux%u: %u",
1710 GST_FOURCC_ARGS (pixelformat), width, height, ival.type);
1714 #endif /* defined VIDIOC_ENUM_FRAMEINTERVALS */
1716 #ifdef VIDIOC_ENUM_FRAMESIZES
1718 sort_by_frame_size (GstStructure * s1, GstStructure * s2)
1722 gst_structure_get_int (s1, "width", &w1);
1723 gst_structure_get_int (s1, "height", &h1);
1724 gst_structure_get_int (s2, "width", &w2);
1725 gst_structure_get_int (s2, "height", &h2);
1727 /* I think it's safe to assume that this won't overflow for a while */
1728 return ((w2 * h2) - (w1 * h1));
1733 gst_v4l2_object_probe_caps_for_format (GstV4l2Object * v4l2object,
1734 guint32 pixelformat, const GstStructure * template)
1736 GstCaps *ret = gst_caps_new_empty ();
1739 #ifdef VIDIOC_ENUM_FRAMESIZES
1740 gint fd = v4l2object->video_fd;
1741 struct v4l2_frmsizeenum size;
1742 GList *results = NULL;
1745 if (pixelformat == GST_MAKE_FOURCC ('M', 'P', 'E', 'G'))
1746 return gst_caps_new_simple ("video/mpegts", NULL);
1748 memset (&size, 0, sizeof (struct v4l2_frmsizeenum));
1750 size.pixel_format = pixelformat;
1752 GST_DEBUG_OBJECT (v4l2object->element, "Enumerating frame sizes");
1754 if (v4l2_ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &size) < 0)
1755 goto enum_framesizes_failed;
1757 if (size.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
1759 GST_LOG_OBJECT (v4l2object->element, "got discrete frame size %dx%d",
1760 size.discrete.width, size.discrete.height);
1762 w = MIN (size.discrete.width, G_MAXINT);
1763 h = MIN (size.discrete.height, G_MAXINT);
1767 gst_v4l2_object_probe_caps_for_format_and_size (v4l2object,
1768 pixelformat, w, h, template);
1771 results = g_list_prepend (results, tmp);
1775 } while (v4l2_ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &size) >= 0);
1776 GST_DEBUG_OBJECT (v4l2object->element,
1777 "done iterating discrete frame sizes");
1778 } else if (size.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
1779 GST_DEBUG_OBJECT (v4l2object->element, "we have stepwise frame sizes:");
1780 GST_DEBUG_OBJECT (v4l2object->element, "min width: %d",
1781 size.stepwise.min_width);
1782 GST_DEBUG_OBJECT (v4l2object->element, "min height: %d",
1783 size.stepwise.min_height);
1784 GST_DEBUG_OBJECT (v4l2object->element, "max width: %d",
1785 size.stepwise.max_width);
1786 GST_DEBUG_OBJECT (v4l2object->element, "min height: %d",
1787 size.stepwise.max_height);
1788 GST_DEBUG_OBJECT (v4l2object->element, "step width: %d",
1789 size.stepwise.step_width);
1790 GST_DEBUG_OBJECT (v4l2object->element, "step height: %d",
1791 size.stepwise.step_height);
1793 for (w = size.stepwise.min_width, h = size.stepwise.min_height;
1794 w < size.stepwise.max_width && h < size.stepwise.max_height;
1795 w += size.stepwise.step_width, h += size.stepwise.step_height) {
1796 if (w == 0 || h == 0)
1800 gst_v4l2_object_probe_caps_for_format_and_size (v4l2object,
1801 pixelformat, w, h, template);
1804 results = g_list_prepend (results, tmp);
1806 GST_DEBUG_OBJECT (v4l2object->element,
1807 "done iterating stepwise frame sizes");
1808 } else if (size.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) {
1811 GST_DEBUG_OBJECT (v4l2object->element, "we have continuous frame sizes:");
1812 GST_DEBUG_OBJECT (v4l2object->element, "min width: %d",
1813 size.stepwise.min_width);
1814 GST_DEBUG_OBJECT (v4l2object->element, "min height: %d",
1815 size.stepwise.min_height);
1816 GST_DEBUG_OBJECT (v4l2object->element, "max width: %d",
1817 size.stepwise.max_width);
1818 GST_DEBUG_OBJECT (v4l2object->element, "min height: %d",
1819 size.stepwise.max_height);
1821 w = MAX (size.stepwise.min_width, 1);
1822 h = MAX (size.stepwise.min_height, 1);
1823 maxw = MIN (size.stepwise.max_width, G_MAXINT);
1824 maxh = MIN (size.stepwise.max_height, G_MAXINT);
1827 gst_v4l2_object_probe_caps_for_format_and_size (v4l2object, pixelformat,
1830 gst_structure_set (tmp, "width", GST_TYPE_INT_RANGE, (gint) w,
1831 (gint) maxw, "height", GST_TYPE_INT_RANGE, (gint) h, (gint) maxh,
1834 /* no point using the results list here, since there's only one struct */
1835 gst_caps_append_structure (ret, tmp);
1841 /* we use an intermediary list to store and then sort the results of the
1842 * probing because we can't make any assumptions about the order in which
1843 * the driver will give us the sizes, but we want the final caps to contain
1844 * the results starting with the highest resolution and having the lowest
1845 * resolution last, since order in caps matters for things like fixation. */
1846 results = g_list_sort (results, (GCompareFunc) sort_by_frame_size);
1847 while (results != NULL) {
1848 gst_caps_append_structure (ret, GST_STRUCTURE (results->data));
1849 results = g_list_delete_link (results, results);
1852 if (gst_caps_is_empty (ret))
1853 goto enum_framesizes_no_results;
1858 enum_framesizes_failed:
1860 /* I don't see how this is actually an error */
1861 GST_DEBUG_OBJECT (v4l2object->element,
1862 "Failed to enumerate frame sizes for pixelformat %" GST_FOURCC_FORMAT
1863 " (%s)", GST_FOURCC_ARGS (pixelformat), g_strerror (errno));
1864 goto default_frame_sizes;
1866 enum_framesizes_no_results:
1868 /* it's possible that VIDIOC_ENUM_FRAMESIZES is defined but the driver in
1869 * question doesn't actually support it yet */
1870 GST_DEBUG_OBJECT (v4l2object->element,
1871 "No results for pixelformat %" GST_FOURCC_FORMAT
1872 " enumerating frame sizes, trying fallback",
1873 GST_FOURCC_ARGS (pixelformat));
1874 goto default_frame_sizes;
1878 GST_WARNING_OBJECT (v4l2object->element,
1879 "Unknown frame sizeenum type for pixelformat %" GST_FOURCC_FORMAT
1880 ": %u", GST_FOURCC_ARGS (pixelformat), size.type);
1881 goto default_frame_sizes;
1883 default_frame_sizes:
1884 #endif /* defined VIDIOC_ENUM_FRAMESIZES */
1886 gint min_w, max_w, min_h, max_h, fix_num = 0, fix_denom = 0;
1887 gboolean interlaced;
1889 /* This code is for Linux < 2.6.19 */
1891 max_w = max_h = GST_V4L2_MAX_SIZE;
1892 if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &min_w,
1893 &min_h, &interlaced)) {
1894 GST_WARNING_OBJECT (v4l2object->element,
1895 "Could not probe minimum capture size for pixelformat %"
1896 GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
1898 if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &max_w,
1899 &max_h, &interlaced)) {
1900 GST_WARNING_OBJECT (v4l2object->element,
1901 "Could not probe maximum capture size for pixelformat %"
1902 GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
1905 /* Since we can't get framerate directly, try to use the current norm */
1906 if (v4l2object->tv_norm && v4l2object->norms) {
1908 GstTunerNorm *norm = NULL;
1909 GstTunerNorm *current =
1910 gst_v4l2_tuner_get_norm_by_std_id (v4l2object, v4l2object->tv_norm);
1912 for (norms = v4l2object->norms; norms != NULL; norms = norms->next) {
1913 norm = (GstTunerNorm *) norms->data;
1914 if (!strcmp (norm->label, current->label))
1917 /* If it's possible, set framerate to that (discrete) value */
1919 fix_num = gst_value_get_fraction_numerator (&norm->framerate);
1920 fix_denom = gst_value_get_fraction_denominator (&norm->framerate);
1924 tmp = gst_structure_copy (template);
1926 gst_structure_set (tmp, "framerate", GST_TYPE_FRACTION, fix_num,
1929 /* if norm can't be used, copy the template framerate */
1930 gst_structure_set (tmp, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1,
1935 gst_structure_set (tmp, "width", G_TYPE_INT, max_w, NULL);
1937 gst_structure_set (tmp, "width", GST_TYPE_INT_RANGE, min_w, max_w, NULL);
1940 gst_structure_set (tmp, "height", G_TYPE_INT, max_h, NULL);
1942 gst_structure_set (tmp, "height", GST_TYPE_INT_RANGE, min_h, max_h, NULL);
1944 gst_structure_set (tmp, "interlaced", G_TYPE_BOOLEAN, interlaced, NULL);
1946 gst_caps_append_structure (ret, tmp);
1953 gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
1954 guint32 pixelformat, gint * width, gint * height, gboolean * interlaced)
1956 struct v4l2_format fmt;
1960 g_return_val_if_fail (width != NULL, FALSE);
1961 g_return_val_if_fail (height != NULL, FALSE);
1963 GST_LOG_OBJECT (v4l2object->element,
1964 "getting nearest size to %dx%d with format %" GST_FOURCC_FORMAT,
1965 *width, *height, GST_FOURCC_ARGS (pixelformat));
1967 fd = v4l2object->video_fd;
1969 /* get size delimiters */
1970 memset (&fmt, 0, sizeof (fmt));
1971 fmt.type = v4l2object->type;
1972 fmt.fmt.pix.width = *width;
1973 fmt.fmt.pix.height = *height;
1974 fmt.fmt.pix.pixelformat = pixelformat;
1975 fmt.fmt.pix.field = V4L2_FIELD_NONE;
1977 r = v4l2_ioctl (fd, VIDIOC_TRY_FMT, &fmt);
1978 if (r < 0 && errno == EINVAL) {
1979 /* try again with interlaced video */
1980 fmt.fmt.pix.width = *width;
1981 fmt.fmt.pix.height = *height;
1982 fmt.fmt.pix.pixelformat = pixelformat;
1983 fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
1984 r = v4l2_ioctl (fd, VIDIOC_TRY_FMT, &fmt);
1988 /* The driver might not implement TRY_FMT, in which case we will try
1990 if (errno != ENOTTY)
1993 /* Only try S_FMT if we're not actively capturing yet, which we shouldn't
1994 be, because we're still probing */
1995 if (GST_V4L2_IS_ACTIVE (v4l2object))
1998 GST_LOG_OBJECT (v4l2object->element,
1999 "Failed to probe size limit with VIDIOC_TRY_FMT, trying VIDIOC_S_FMT");
2001 fmt.fmt.pix.width = *width;
2002 fmt.fmt.pix.height = *height;
2004 r = v4l2_ioctl (fd, VIDIOC_S_FMT, &fmt);
2005 if (r < 0 && errno == EINVAL) {
2006 /* try again with progressive video */
2007 fmt.fmt.pix.width = *width;
2008 fmt.fmt.pix.height = *height;
2009 fmt.fmt.pix.pixelformat = pixelformat;
2010 fmt.fmt.pix.field = V4L2_FIELD_NONE;
2011 r = v4l2_ioctl (fd, VIDIOC_S_FMT, &fmt);
2018 GST_LOG_OBJECT (v4l2object->element,
2019 "got nearest size %dx%d", fmt.fmt.pix.width, fmt.fmt.pix.height);
2021 *width = fmt.fmt.pix.width;
2022 *height = fmt.fmt.pix.height;
2024 switch (fmt.fmt.pix.field) {
2025 case V4L2_FIELD_ANY:
2026 case V4L2_FIELD_NONE:
2027 *interlaced = FALSE;
2029 case V4L2_FIELD_INTERLACED:
2030 case V4L2_FIELD_INTERLACED_TB:
2031 case V4L2_FIELD_INTERLACED_BT:
2035 GST_WARNING_OBJECT (v4l2object->element,
2036 "Unsupported field type for %" GST_FOURCC_FORMAT "@%ux%u",
2037 GST_FOURCC_ARGS (pixelformat), *width, *height);
2044 /* Note about fraction simplification
2045 * * n1/d1 == n2/d2 is also written as n1 == ( n2 * d1 ) / d2
2047 #define fractions_are_equal(n1,d1,n2,d2) ((n1) == gst_util_uint64_scale_int((n2), (d1), (d2)))
2050 gst_v4l2_object_set_format (GstV4l2Object * v4l2object, GstCaps * caps)
2052 gint fd = v4l2object->video_fd;
2053 struct v4l2_format format;
2054 struct v4l2_streamparm streamparm;
2055 enum v4l2_field field;
2056 guint32 pixelformat;
2057 struct v4l2_fmtdesc *fmtdesc;
2059 gint width, height, fps_n, fps_d, stride;
2061 if (!gst_v4l2_object_get_caps_info (v4l2object, caps, &fmtdesc, &info))
2064 pixelformat = fmtdesc->pixelformat;
2065 width = GST_VIDEO_INFO_WIDTH (&info);
2066 height = GST_VIDEO_INFO_HEIGHT (&info);
2067 fps_n = GST_VIDEO_INFO_FPS_N (&info);
2068 fps_d = GST_VIDEO_INFO_FPS_D (&info);
2069 stride = GST_VIDEO_INFO_PLANE_STRIDE (&info, 0);
2071 if (info.flags & GST_VIDEO_FLAG_INTERLACED) {
2072 GST_DEBUG_OBJECT (v4l2object->element, "interlaced video");
2073 /* ideally we would differentiate between types of interlaced video
2074 * but there is not sufficient information in the caps..
2076 field = V4L2_FIELD_INTERLACED;
2078 GST_DEBUG_OBJECT (v4l2object->element, "progressive video");
2079 field = V4L2_FIELD_NONE;
2082 GST_DEBUG_OBJECT (v4l2object->element, "Desired format %dx%d, format "
2083 "%" GST_FOURCC_FORMAT, width, height, GST_FOURCC_ARGS (pixelformat));
2085 GST_V4L2_CHECK_OPEN (v4l2object);
2086 GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
2088 /* Only unconditionally accept mpegts for sources */
2089 if ((v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
2090 (pixelformat == GST_MAKE_FOURCC ('M', 'P', 'E', 'G')))
2093 memset (&format, 0x00, sizeof (struct v4l2_format));
2094 format.type = v4l2object->type;
2096 if (v4l2_ioctl (fd, VIDIOC_G_FMT, &format) < 0)
2097 goto get_fmt_failed;
2099 GST_DEBUG_OBJECT (v4l2object->element, "Got format to %dx%d, format "
2100 "%" GST_FOURCC_FORMAT " bytesperline %d", format.fmt.pix.width,
2101 format.fmt.pix.height, GST_FOURCC_ARGS (format.fmt.pix.pixelformat),
2102 format.fmt.pix.bytesperline);
2104 if (format.type != v4l2object->type ||
2105 format.fmt.pix.width != width ||
2106 format.fmt.pix.height != height ||
2107 format.fmt.pix.pixelformat != pixelformat ||
2108 format.fmt.pix.field != field || format.fmt.pix.bytesperline != stride) {
2109 /* something different, set the format */
2110 GST_DEBUG_OBJECT (v4l2object->element, "Setting format to %dx%d, format "
2111 "%" GST_FOURCC_FORMAT " bytesperline %d", width, height,
2112 GST_FOURCC_ARGS (pixelformat), stride);
2114 format.type = v4l2object->type;
2115 format.fmt.pix.width = width;
2116 format.fmt.pix.height = height;
2117 format.fmt.pix.pixelformat = pixelformat;
2118 format.fmt.pix.field = field;
2119 /* try to ask our prefered stride */
2120 format.fmt.pix.bytesperline = stride;
2122 if (v4l2_ioctl (fd, VIDIOC_S_FMT, &format) < 0)
2123 goto set_fmt_failed;
2125 GST_DEBUG_OBJECT (v4l2object->element, "Got format to %dx%d, format "
2126 "%" GST_FOURCC_FORMAT " stride %d", format.fmt.pix.width,
2127 format.fmt.pix.height, GST_FOURCC_ARGS (format.fmt.pix.pixelformat),
2128 format.fmt.pix.bytesperline);
2130 if (format.fmt.pix.width != width || format.fmt.pix.height != height)
2131 goto invalid_dimensions;
2133 if (format.fmt.pix.pixelformat != pixelformat)
2134 goto invalid_pixelformat;
2136 v4l2object->bytesperline = format.fmt.pix.bytesperline;
2139 /* Is there a reason we require the caller to always specify a framerate? */
2140 GST_DEBUG_OBJECT (v4l2object->element, "Desired framerate: %u/%u", fps_n,
2143 memset (&streamparm, 0x00, sizeof (struct v4l2_streamparm));
2144 streamparm.type = v4l2object->type;
2146 if (v4l2_ioctl (fd, VIDIOC_G_PARM, &streamparm) < 0)
2147 goto get_parm_failed;
2149 GST_VIDEO_INFO_FPS_N (&info) =
2150 streamparm.parm.capture.timeperframe.denominator;
2151 GST_VIDEO_INFO_FPS_D (&info) = streamparm.parm.capture.timeperframe.numerator;
2153 if (v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2154 GST_DEBUG_OBJECT (v4l2object->element, "Got framerate: %u/%u",
2155 streamparm.parm.capture.timeperframe.denominator,
2156 streamparm.parm.capture.timeperframe.numerator);
2158 /* Note: V4L2 provides the frame interval, we have the frame rate */
2159 if (!fractions_are_equal (streamparm.parm.capture.timeperframe.numerator,
2160 streamparm.parm.capture.timeperframe.denominator, fps_d, fps_n)) {
2161 GST_LOG_OBJECT (v4l2object->element, "Setting framerate to %u/%u", fps_n,
2163 /* We want to change the frame rate, so check whether we can. Some cheap USB
2164 * cameras don't have the capability */
2165 if ((streamparm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) == 0) {
2166 GST_DEBUG_OBJECT (v4l2object->element,
2167 "Not setting framerate (not supported)");
2171 /* Note: V4L2 wants the frame interval, we have the frame rate */
2172 streamparm.parm.capture.timeperframe.numerator = fps_d;
2173 streamparm.parm.capture.timeperframe.denominator = fps_n;
2175 /* some cheap USB cam's won't accept any change */
2176 if (v4l2_ioctl (fd, VIDIOC_S_PARM, &streamparm) < 0)
2177 goto set_parm_failed;
2179 /* get new values */
2180 fps_d = streamparm.parm.capture.timeperframe.numerator;
2181 fps_n = streamparm.parm.capture.timeperframe.denominator;
2183 GST_INFO_OBJECT (v4l2object->element, "Set framerate to %u/%u", fps_n,
2186 GST_VIDEO_INFO_FPS_N (&info) = fps_n;
2187 GST_VIDEO_INFO_FPS_D (&info) = fps_d;
2192 /* if we have a framerate pre-calculate duration */
2193 if (fps_n > 0 && fps_d > 0) {
2194 v4l2object->duration = gst_util_uint64_scale_int (GST_SECOND, fps_d, fps_n);
2196 v4l2object->duration = GST_CLOCK_TIME_NONE;
2198 v4l2object->info = info;
2199 v4l2object->fmtdesc = fmtdesc;
2206 GST_DEBUG_OBJECT (v4l2object->element, "can't parse caps %" GST_PTR_FORMAT,
2212 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
2213 (_("Device '%s' does not support video capture"),
2214 v4l2object->videodev),
2215 ("Call to G_FMT failed: (%s)", g_strerror (errno)));
2220 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
2221 (_("Device '%s' cannot capture at %dx%d"),
2222 v4l2object->videodev, width, height),
2223 ("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
2224 GST_FOURCC_ARGS (pixelformat), width, height, g_strerror (errno)));
2229 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
2230 (_("Device '%s' cannot capture at %dx%d"),
2231 v4l2object->videodev, width, height),
2232 ("Tried to capture at %dx%d, but device returned size %dx%d",
2233 width, height, format.fmt.pix.width, format.fmt.pix.height));
2236 invalid_pixelformat:
2238 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
2239 (_("Device '%s' cannot capture in the specified format"),
2240 v4l2object->videodev),
2241 ("Tried to capture in %" GST_FOURCC_FORMAT
2242 ", but device returned format" " %" GST_FOURCC_FORMAT,
2243 GST_FOURCC_ARGS (pixelformat),
2244 GST_FOURCC_ARGS (format.fmt.pix.pixelformat)));
2249 /* it's possible that this call is not supported */
2250 if (errno != EINVAL) {
2251 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
2252 (_("Could not get parameters on device '%s'"),
2253 v4l2object->videodev), GST_ERROR_SYSTEM);
2259 GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, SETTINGS,
2260 (_("Video input device did not accept new frame rate setting.")),
2267 gst_v4l2_object_start_streaming (GstV4l2Object * v4l2object)
2269 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_STREAMON,
2270 &(v4l2object->type)) < 0)
2278 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, OPEN_READ,
2279 (_("Error starting streaming on device '%s'."), v4l2object->videodev),
2286 gst_v4l2_object_stop_streaming (GstV4l2Object * v4l2object)
2288 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_STREAMOFF,
2289 &(v4l2object->type)) < 0)
2297 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, OPEN_READ,
2298 (_("Error stopping streaming on device '%s'."), v4l2object->videodev),