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,
70 gst_v4l2_probe_get_properties (GstPropertyProbe * probe)
72 GObjectClass *klass = G_OBJECT_GET_CLASS (probe);
73 static GList *list = NULL;
75 /* well, not perfect, but better than no locking at all.
76 * In the worst case we leak a list node, so who cares? */
77 GST_CLASS_LOCK (GST_OBJECT_CLASS (klass));
80 list = g_list_append (NULL, g_object_class_find_property (klass, "device"));
83 GST_CLASS_UNLOCK (GST_OBJECT_CLASS (klass));
88 static gboolean init = FALSE;
89 static GList *devices = NULL;
93 gst_v4l2_class_probe_devices_with_udev (GstElementClass * klass, gboolean check,
94 GList ** klass_devices)
96 GUdevClient *client = NULL;
101 gchar *device = devices->data;
102 devices = g_list_remove (devices, device);
106 GST_INFO ("Enumerating video4linux devices from udev");
107 client = g_udev_client_new (NULL);
109 GST_WARNING ("Failed to initialize gudev client");
113 item = g_udev_client_query_by_subsystem (client, "video4linux");
115 GUdevDevice *device = item->data;
116 gchar *devnode = g_strdup (g_udev_device_get_device_file (device));
117 gint api = g_udev_device_get_property_as_int (device, "ID_V4L_VERSION");
118 GST_INFO ("Found new device: %s, API: %d", devnode, api);
119 /* Append v4l2 devices only. If api is 0 probably v4l_id has
120 been stripped out of the current udev installation, append
124 ("Couldn't retrieve ID_V4L_VERSION, silly udev installation?");
126 if ((api == 2 || api == 0)) {
127 devices = g_list_append (devices, devnode);
131 g_object_unref (device);
140 g_object_unref (client);
143 *klass_devices = devices;
147 #endif /* HAVE_GUDEV */
150 gst_v4l2_class_probe_devices (GstElementClass * klass, gboolean check,
151 GList ** klass_devices)
154 const gchar *dev_base[] = { "/dev/video", "/dev/v4l2/video", NULL };
158 gchar *device = devices->data;
159 devices = g_list_remove (devices, device);
164 * detect /dev entries
166 for (n = 0; n < 64; n++) {
167 for (base = 0; dev_base[base] != NULL; base++) {
169 gchar *device = g_strdup_printf ("%s%d",
174 * does the /dev/ entry exist at all?
176 if (stat (device, &s) == 0) {
178 * yes: is a device attached?
180 if (S_ISCHR (s.st_mode)) {
182 if ((fd = open (device, O_RDWR | O_NONBLOCK)) > 0 || errno == EBUSY) {
186 devices = g_list_append (devices, device);
197 *klass_devices = devices;
203 gst_v4l2_probe_probe_property (GstPropertyProbe * probe,
204 guint prop_id, const GParamSpec * pspec, GList ** klass_devices)
206 GstElementClass *klass = GST_ELEMENT_GET_CLASS (probe);
211 if (!gst_v4l2_class_probe_devices_with_udev (klass, FALSE, klass_devices))
212 gst_v4l2_class_probe_devices (klass, FALSE, klass_devices);
213 #else /* !HAVE_GUDEV */
214 gst_v4l2_class_probe_devices (klass, FALSE, klass_devices);
215 #endif /* HAVE_GUDEV */
218 G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
224 gst_v4l2_probe_needs_probe (GstPropertyProbe * probe,
225 guint prop_id, const GParamSpec * pspec, GList ** klass_devices)
227 GstElementClass *klass = GST_ELEMENT_GET_CLASS (probe);
228 gboolean ret = FALSE;
234 !gst_v4l2_class_probe_devices_with_udev (klass, FALSE, klass_devices);
235 #else /* !HAVE_GUDEV */
236 ret = !gst_v4l2_class_probe_devices (klass, TRUE, klass_devices);
237 #endif /* HAVE_GUDEV */
240 G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
247 gst_v4l2_class_list_devices (GstElementClass * klass, GList ** klass_devices)
250 GValue value = { 0 };
256 array = g_value_array_new (g_list_length (*klass_devices));
257 item = *klass_devices;
258 g_value_init (&value, G_TYPE_STRING);
260 gchar *device = item->data;
262 g_value_set_string (&value, device);
263 g_value_array_append (array, &value);
267 g_value_unset (&value);
273 gst_v4l2_probe_get_values (GstPropertyProbe * probe,
274 guint prop_id, const GParamSpec * pspec, GList ** klass_devices)
276 GstElementClass *klass = GST_ELEMENT_GET_CLASS (probe);
277 GValueArray *array = NULL;
281 array = gst_v4l2_class_list_devices (klass, klass_devices);
284 G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
291 #define GST_TYPE_V4L2_DEVICE_FLAGS (gst_v4l2_device_get_type ())
293 gst_v4l2_device_get_type (void)
295 static GType v4l2_device_type = 0;
297 if (v4l2_device_type == 0) {
298 static const GFlagsValue values[] = {
299 {V4L2_CAP_VIDEO_CAPTURE, "Device supports video capture", "capture"},
300 {V4L2_CAP_VIDEO_OUTPUT, "Device supports video playback", "output"},
301 {V4L2_CAP_VIDEO_OVERLAY, "Device supports video overlay", "overlay"},
303 {V4L2_CAP_VBI_CAPTURE, "Device supports the VBI capture", "vbi-capture"},
304 {V4L2_CAP_VBI_OUTPUT, "Device supports the VBI output", "vbi-output"},
306 {V4L2_CAP_TUNER, "Device has a tuner or modulator", "tuner"},
307 {V4L2_CAP_AUDIO, "Device has audio inputs or outputs", "audio"},
313 g_flags_register_static ("GstV4l2DeviceTypeFlags", values);
316 return v4l2_device_type;
319 #define GST_TYPE_V4L2_TV_NORM (gst_v4l2_tv_norm_get_type ())
321 gst_v4l2_tv_norm_get_type (void)
323 static GType v4l2_tv_norm = 0;
326 static const GEnumValue tv_norms[] = {
329 {V4L2_STD_NTSC, "NTSC", "NTSC"},
330 {V4L2_STD_NTSC_M, "NTSC-M", "NTSC-M"},
331 {V4L2_STD_NTSC_M_JP, "NTSC-M-JP", "NTSC-M-JP"},
332 {V4L2_STD_NTSC_M_KR, "NTSC-M-KR", "NTSC-M-KR"},
333 {V4L2_STD_NTSC_443, "NTSC-443", "NTSC-443"},
335 {V4L2_STD_PAL, "PAL", "PAL"},
336 {V4L2_STD_PAL_BG, "PAL-BG", "PAL-BG"},
337 {V4L2_STD_PAL_B, "PAL-B", "PAL-B"},
338 {V4L2_STD_PAL_B1, "PAL-B1", "PAL-B1"},
339 {V4L2_STD_PAL_G, "PAL-G", "PAL-G"},
340 {V4L2_STD_PAL_H, "PAL-H", "PAL-H"},
341 {V4L2_STD_PAL_I, "PAL-I", "PAL-I"},
342 {V4L2_STD_PAL_DK, "PAL-DK", "PAL-DK"},
343 {V4L2_STD_PAL_D, "PAL-D", "PAL-D"},
344 {V4L2_STD_PAL_D1, "PAL-D1", "PAL-D1"},
345 {V4L2_STD_PAL_K, "PAL-K", "PAL-K"},
346 {V4L2_STD_PAL_M, "PAL-M", "PAL-M"},
347 {V4L2_STD_PAL_N, "PAL-N", "PAL-N"},
348 {V4L2_STD_PAL_Nc, "PAL-Nc", "PAL-Nc"},
349 {V4L2_STD_PAL_60, "PAL-60", "PAL-60"},
351 {V4L2_STD_SECAM, "SECAM", "SECAM"},
352 {V4L2_STD_SECAM_B, "SECAM-B", "SECAM-B"},
353 {V4L2_STD_SECAM_G, "SECAM-G", "SECAM-G"},
354 {V4L2_STD_SECAM_H, "SECAM-H", "SECAM-H"},
355 {V4L2_STD_SECAM_DK, "SECAM-DK", "SECAM-DK"},
356 {V4L2_STD_SECAM_D, "SECAM-D", "SECAM-D"},
357 {V4L2_STD_SECAM_K, "SECAM-K", "SECAM-K"},
358 {V4L2_STD_SECAM_K1, "SECAM-K1", "SECAM-K1"},
359 {V4L2_STD_SECAM_L, "SECAM-L", "SECAM-L"},
360 {V4L2_STD_SECAM_LC, "SECAM-Lc", "SECAM-Lc"},
365 v4l2_tv_norm = g_enum_register_static ("V4L2_TV_norms", tv_norms);
372 gst_v4l2_object_install_properties_helper (GObjectClass * gobject_class,
373 const char *default_device)
375 g_object_class_install_property (gobject_class, PROP_DEVICE,
376 g_param_spec_string ("device", "Device", "Device location",
377 default_device, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
378 g_object_class_install_property (gobject_class, PROP_DEVICE_NAME,
379 g_param_spec_string ("device-name", "Device name",
380 "Name of the device", DEFAULT_PROP_DEVICE_NAME,
381 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
382 g_object_class_install_property (gobject_class, PROP_DEVICE_FD,
383 g_param_spec_int ("device-fd", "File descriptor",
384 "File descriptor of the device", -1, G_MAXINT, DEFAULT_PROP_DEVICE_FD,
385 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
386 g_object_class_install_property (gobject_class, PROP_FLAGS,
387 g_param_spec_flags ("flags", "Flags", "Device type flags",
388 GST_TYPE_V4L2_DEVICE_FLAGS, DEFAULT_PROP_FLAGS,
389 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
392 * GstV4l2Src:brightness
394 * Picture brightness, or more precisely, the black level
398 g_object_class_install_property (gobject_class, PROP_BRIGHTNESS,
399 g_param_spec_int ("brightness", "Brightness",
400 "Picture brightness, or more precisely, the black level", G_MININT,
402 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
404 * GstV4l2Src:contrast
406 * Picture contrast or luma gain
410 g_object_class_install_property (gobject_class, PROP_CONTRAST,
411 g_param_spec_int ("contrast", "Contrast",
412 "Picture contrast or luma gain", G_MININT,
414 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
416 * GstV4l2Src:saturation
418 * Picture color saturation or chroma gain
422 g_object_class_install_property (gobject_class, PROP_SATURATION,
423 g_param_spec_int ("saturation", "Saturation",
424 "Picture color saturation or chroma gain", G_MININT,
426 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
430 * Hue or color balance
434 g_object_class_install_property (gobject_class, PROP_HUE,
435 g_param_spec_int ("hue", "Hue",
436 "Hue or color balance", G_MININT,
438 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
447 g_object_class_install_property (gobject_class, PROP_TV_NORM,
448 g_param_spec_enum ("norm", "TV norm",
450 GST_TYPE_V4L2_TV_NORM, DEFAULT_PROP_TV_NORM,
451 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
455 gst_v4l2_object_new (GstElement * element,
456 enum v4l2_buf_type type,
457 const char *default_device,
458 GstV4l2GetInOutFunction get_in_out_func,
459 GstV4l2SetInOutFunction set_in_out_func,
460 GstV4l2UpdateFpsFunction update_fps_func)
462 GstV4l2Object *v4l2object;
465 * some default values
467 v4l2object = g_new0 (GstV4l2Object, 1);
469 v4l2object->type = type;
470 v4l2object->formats = NULL;
472 v4l2object->element = element;
473 v4l2object->get_in_out_func = get_in_out_func;
474 v4l2object->set_in_out_func = set_in_out_func;
475 v4l2object->update_fps_func = update_fps_func;
477 v4l2object->video_fd = -1;
478 v4l2object->poll = gst_poll_new (TRUE);
479 v4l2object->buffer = NULL;
480 v4l2object->videodev = g_strdup (default_device);
482 v4l2object->norms = NULL;
483 v4l2object->channels = NULL;
484 v4l2object->colors = NULL;
486 v4l2object->xwindow_id = 0;
491 static gboolean gst_v4l2_object_clear_format_list (GstV4l2Object * v4l2object);
495 gst_v4l2_object_destroy (GstV4l2Object * v4l2object)
497 g_return_if_fail (v4l2object != NULL);
499 if (v4l2object->videodev)
500 g_free (v4l2object->videodev);
502 if (v4l2object->poll)
503 gst_poll_free (v4l2object->poll);
505 if (v4l2object->channel)
506 g_free (v4l2object->channel);
508 if (v4l2object->formats) {
509 gst_v4l2_object_clear_format_list (v4l2object);
517 gst_v4l2_object_clear_format_list (GstV4l2Object * v4l2object)
519 g_slist_foreach (v4l2object->formats, (GFunc) g_free, NULL);
520 g_slist_free (v4l2object->formats);
521 v4l2object->formats = NULL;
527 gst_v4l2_object_prop_to_cid (guint prop_id)
532 case PROP_BRIGHTNESS:
533 cid = V4L2_CID_BRIGHTNESS;
536 cid = V4L2_CID_CONTRAST;
538 case PROP_SATURATION:
539 cid = V4L2_CID_SATURATION;
545 GST_WARNING ("unmapped property id: %d", prop_id);
552 gst_v4l2_object_set_property_helper (GstV4l2Object * v4l2object,
553 guint prop_id, const GValue * value, GParamSpec * pspec)
557 g_free (v4l2object->videodev);
558 v4l2object->videodev = g_value_dup_string (value);
560 case PROP_BRIGHTNESS:
562 case PROP_SATURATION:
565 gint cid = gst_v4l2_object_prop_to_cid (prop_id);
568 if (GST_V4L2_IS_OPEN (v4l2object)) {
569 gst_v4l2_set_attribute (v4l2object, cid, g_value_get_int (value));
576 v4l2object->tv_norm = g_value_get_enum (value);
580 if (GST_V4L2_IS_OPEN (v4l2object)) {
581 GstTuner *tuner = GST_TUNER (v4l2object->element);
582 GstTunerChannel *channel = gst_tuner_find_channel_by_name (tuner,
583 (gchar *) g_value_get_string (value));
586 /* like gst_tuner_set_channel (tuner, channel)
587 without g_object_notify */
588 gst_v4l2_tuner_set_channel (v4l2object, channel);
591 g_free (v4l2object->channel);
592 v4l2object->channel = g_value_dup_string (value);
596 if (GST_V4L2_IS_OPEN (v4l2object)) {
597 GstTuner *tuner = GST_TUNER (v4l2object->element);
598 GstTunerChannel *channel = gst_tuner_get_channel (tuner);
601 GST_TUNER_CHANNEL_HAS_FLAG (channel, GST_TUNER_CHANNEL_FREQUENCY)) {
603 gst_tuner_set_frequency (tuner, channel, g_value_get_ulong (value))
604 without g_object_notify */
605 gst_v4l2_tuner_set_frequency (v4l2object, channel,
606 g_value_get_ulong (value));
609 v4l2object->frequency = g_value_get_ulong (value);
622 gst_v4l2_object_get_property_helper (GstV4l2Object * v4l2object,
623 guint prop_id, GValue * value, GParamSpec * pspec)
627 g_value_set_string (value, v4l2object->videodev);
629 case PROP_DEVICE_NAME:
631 const guchar *new = NULL;
633 if (GST_V4L2_IS_OPEN (v4l2object)) {
634 new = v4l2object->vcap.card;
635 } else if (gst_v4l2_open (v4l2object)) {
636 new = v4l2object->vcap.card;
637 gst_v4l2_close (v4l2object);
639 g_value_set_string (value, (gchar *) new);
644 if (GST_V4L2_IS_OPEN (v4l2object))
645 g_value_set_int (value, v4l2object->video_fd);
647 g_value_set_int (value, DEFAULT_PROP_DEVICE_FD);
654 if (GST_V4L2_IS_OPEN (v4l2object)) {
655 flags |= v4l2object->vcap.capabilities &
656 (V4L2_CAP_VIDEO_CAPTURE |
657 V4L2_CAP_VIDEO_OUTPUT |
658 V4L2_CAP_VIDEO_OVERLAY |
659 V4L2_CAP_VBI_CAPTURE |
660 V4L2_CAP_VBI_OUTPUT | V4L2_CAP_TUNER | V4L2_CAP_AUDIO);
662 g_value_set_flags (value, flags);
665 case PROP_BRIGHTNESS:
667 case PROP_SATURATION:
670 gint cid = gst_v4l2_object_prop_to_cid (prop_id);
673 if (GST_V4L2_IS_OPEN (v4l2object)) {
675 if (gst_v4l2_get_attribute (v4l2object, cid, &v)) {
676 g_value_set_int (value, v);
684 g_value_set_enum (value, v4l2object->tv_norm);
694 gst_v4l2_set_defaults (GstV4l2Object * v4l2object)
696 GstTunerNorm *norm = NULL;
697 GstTunerChannel *channel = NULL;
700 if (!GST_IS_TUNER (v4l2object->element))
703 tuner = GST_TUNER (v4l2object->element);
705 if (v4l2object->tv_norm)
706 norm = gst_v4l2_tuner_get_norm_by_std_id (v4l2object, v4l2object->tv_norm);
707 GST_DEBUG_OBJECT (v4l2object->element, "tv_norm=0x%" G_GINT64_MODIFIER "x, "
708 "norm=%p", (guint64) v4l2object->tv_norm, norm);
710 gst_tuner_set_norm (tuner, norm);
713 GST_TUNER_NORM (gst_tuner_get_norm (GST_TUNER (v4l2object->element)));
715 v4l2object->tv_norm =
716 gst_v4l2_tuner_get_std_id_by_norm (v4l2object, norm);
717 gst_tuner_norm_changed (tuner, norm);
721 if (v4l2object->channel)
722 channel = gst_tuner_find_channel_by_name (tuner, v4l2object->channel);
724 gst_tuner_set_channel (tuner, channel);
727 GST_TUNER_CHANNEL (gst_tuner_get_channel (GST_TUNER
728 (v4l2object->element)));
730 g_free (v4l2object->channel);
731 v4l2object->channel = g_strdup (channel->label);
732 gst_tuner_channel_changed (tuner, channel);
737 && GST_TUNER_CHANNEL_HAS_FLAG (channel, GST_TUNER_CHANNEL_FREQUENCY)) {
738 if (v4l2object->frequency != 0) {
739 gst_tuner_set_frequency (tuner, channel, v4l2object->frequency);
741 v4l2object->frequency = gst_tuner_get_frequency (tuner, channel);
742 if (v4l2object->frequency == 0) {
744 gst_tuner_set_frequency (tuner, channel, 1000);
752 gst_v4l2_object_start (GstV4l2Object * v4l2object)
754 if (gst_v4l2_open (v4l2object))
755 gst_v4l2_set_defaults (v4l2object);
760 gst_v4l2_xoverlay_start (v4l2object);
767 gst_v4l2_object_stop (GstV4l2Object * v4l2object)
770 gst_v4l2_xoverlay_stop (v4l2object);
773 if (!gst_v4l2_close (v4l2object))
776 if (v4l2object->formats) {
777 gst_v4l2_object_clear_format_list (v4l2object);
785 * common format / caps utilities:
793 static const GstV4L2FormatDesc gst_v4l2_formats[] = {
794 /* from Linux 2.6.15 videodev2.h */
795 {V4L2_PIX_FMT_RGB332, TRUE},
796 {V4L2_PIX_FMT_RGB555, TRUE},
797 {V4L2_PIX_FMT_RGB565, TRUE},
798 {V4L2_PIX_FMT_RGB555X, TRUE},
799 {V4L2_PIX_FMT_RGB565X, TRUE},
800 {V4L2_PIX_FMT_BGR24, TRUE},
801 {V4L2_PIX_FMT_RGB24, TRUE},
802 {V4L2_PIX_FMT_BGR32, TRUE},
803 {V4L2_PIX_FMT_RGB32, TRUE},
804 {V4L2_PIX_FMT_GREY, TRUE},
805 {V4L2_PIX_FMT_YVU410, TRUE},
806 {V4L2_PIX_FMT_YVU420, TRUE},
807 {V4L2_PIX_FMT_YUYV, TRUE},
808 {V4L2_PIX_FMT_UYVY, TRUE},
809 {V4L2_PIX_FMT_YUV422P, TRUE},
810 {V4L2_PIX_FMT_YUV411P, TRUE},
811 {V4L2_PIX_FMT_Y41P, TRUE},
813 /* two planes -- one Y, one Cr + Cb interleaved */
814 {V4L2_PIX_FMT_NV12, TRUE},
815 {V4L2_PIX_FMT_NV21, TRUE},
817 /* The following formats are not defined in the V4L2 specification */
818 {V4L2_PIX_FMT_YUV410, TRUE},
819 {V4L2_PIX_FMT_YUV420, TRUE},
820 {V4L2_PIX_FMT_YYUV, TRUE},
821 {V4L2_PIX_FMT_HI240, TRUE},
823 /* see http://www.siliconimaging.com/RGB%20Bayer.htm */
824 #ifdef V4L2_PIX_FMT_SBGGR8
825 {V4L2_PIX_FMT_SBGGR8, TRUE},
828 /* compressed formats */
829 {V4L2_PIX_FMT_MJPEG, TRUE},
830 {V4L2_PIX_FMT_JPEG, TRUE},
831 #ifdef V4L2_PIX_FMT_PJPG
832 {V4L2_PIX_FMT_PJPG, TRUE},
834 {V4L2_PIX_FMT_DV, TRUE},
835 {V4L2_PIX_FMT_MPEG, FALSE},
837 /* Vendor-specific formats */
838 {V4L2_PIX_FMT_WNVA, TRUE},
840 #ifdef V4L2_PIX_FMT_SN9C10X
841 {V4L2_PIX_FMT_SN9C10X, TRUE},
843 #ifdef V4L2_PIX_FMT_PWC1
844 {V4L2_PIX_FMT_PWC1, TRUE},
846 #ifdef V4L2_PIX_FMT_PWC2
847 {V4L2_PIX_FMT_PWC2, TRUE},
849 #ifdef V4L2_PIX_FMT_YVYU
850 {V4L2_PIX_FMT_YVYU, TRUE},
854 #define GST_V4L2_FORMAT_COUNT (G_N_ELEMENTS (gst_v4l2_formats))
857 static struct v4l2_fmtdesc *
858 gst_v4l2_object_get_format_from_fourcc (GstV4l2Object * v4l2object,
861 struct v4l2_fmtdesc *fmt;
867 walk = gst_v4l2_object_get_format_list (v4l2object);
869 fmt = (struct v4l2_fmtdesc *) walk->data;
870 if (fmt->pixelformat == fourcc)
872 /* special case for jpeg */
873 if (fmt->pixelformat == V4L2_PIX_FMT_MJPEG ||
874 fmt->pixelformat == V4L2_PIX_FMT_JPEG
875 #ifdef V4L2_PIX_FMT_PJPG
876 || fmt->pixelformat == V4L2_PIX_FMT_PJPG
879 if (fourcc == V4L2_PIX_FMT_JPEG || fourcc == V4L2_PIX_FMT_MJPEG
880 #ifdef V4L2_PIX_FMT_PJPG
881 || fourcc == V4L2_PIX_FMT_PJPG
887 walk = g_slist_next (walk);
895 /* complete made up ranking, the values themselves are meaningless */
896 /* These ranks MUST be X such that X<<15 fits on a signed int - see
897 the comment at the end of gst_v4l2_object_format_get_rank. */
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_RGB332:
1153 case V4L2_PIX_FMT_RGB555:
1154 case V4L2_PIX_FMT_RGB555X:
1155 case V4L2_PIX_FMT_RGB565:
1156 case V4L2_PIX_FMT_RGB565X:
1157 case V4L2_PIX_FMT_RGB24:
1158 case V4L2_PIX_FMT_BGR24:
1159 case V4L2_PIX_FMT_RGB32:
1160 case V4L2_PIX_FMT_BGR32:{
1161 guint depth = 0, bpp = 0;
1163 gint endianness = 0;
1165 guint32 r_mask = 0, b_mask = 0, g_mask = 0;
1168 case V4L2_PIX_FMT_RGB332:
1170 endianness = G_BYTE_ORDER; /* 'like, whatever' */
1175 case V4L2_PIX_FMT_RGB555:
1176 case V4L2_PIX_FMT_RGB555X:
1180 fourcc == V4L2_PIX_FMT_RGB555X ? G_BIG_ENDIAN : G_LITTLE_ENDIAN;
1185 case V4L2_PIX_FMT_RGB565:
1186 case V4L2_PIX_FMT_RGB565X:
1189 fourcc == V4L2_PIX_FMT_RGB565X ? G_BIG_ENDIAN : G_LITTLE_ENDIAN;
1194 case V4L2_PIX_FMT_RGB24:
1196 endianness = G_BIG_ENDIAN;
1201 case V4L2_PIX_FMT_BGR24:
1203 endianness = G_BIG_ENDIAN;
1208 case V4L2_PIX_FMT_RGB32:
1210 endianness = G_BIG_ENDIAN;
1211 r_mask = 0xff000000;
1212 g_mask = 0x00ff0000;
1213 b_mask = 0x0000ff00;
1215 case V4L2_PIX_FMT_BGR32:
1217 endianness = G_BIG_ENDIAN;
1218 r_mask = 0x000000ff;
1219 g_mask = 0x0000ff00;
1220 b_mask = 0x00ff0000;
1223 g_assert_not_reached ();
1226 structure = gst_structure_new ("video/x-raw-rgb",
1227 "bpp", G_TYPE_INT, bpp,
1228 "depth", G_TYPE_INT, depth,
1229 "red_mask", G_TYPE_INT, r_mask,
1230 "green_mask", G_TYPE_INT, g_mask,
1231 "blue_mask", G_TYPE_INT, b_mask,
1232 "endianness", G_TYPE_INT, endianness, NULL);
1235 case V4L2_PIX_FMT_GREY: /* 8 Greyscale */
1236 structure = gst_structure_new ("video/x-raw-gray",
1237 "bpp", G_TYPE_INT, 8, NULL);
1239 case V4L2_PIX_FMT_YYUV: /* 16 YUV 4:2:2 */
1240 case V4L2_PIX_FMT_HI240: /* 8 8-bit color */
1241 /* FIXME: get correct fourccs here */
1243 case V4L2_PIX_FMT_NV12: /* 12 Y/CbCr 4:2:0 */
1244 case V4L2_PIX_FMT_NV21: /* 12 Y/CrCb 4:2:0 */
1245 case V4L2_PIX_FMT_YVU410:
1246 case V4L2_PIX_FMT_YUV410:
1247 case V4L2_PIX_FMT_YUV420: /* I420/IYUV */
1248 case V4L2_PIX_FMT_YUYV:
1249 case V4L2_PIX_FMT_YVU420:
1250 case V4L2_PIX_FMT_UYVY:
1251 case V4L2_PIX_FMT_Y41P:
1252 case V4L2_PIX_FMT_YUV422P:
1253 #ifdef V4L2_PIX_FMT_YVYU
1254 case V4L2_PIX_FMT_YVYU:
1256 case V4L2_PIX_FMT_YUV411P:{
1260 case V4L2_PIX_FMT_NV12:
1261 fcc = GST_MAKE_FOURCC ('N', 'V', '1', '2');
1263 case V4L2_PIX_FMT_NV21:
1264 fcc = GST_MAKE_FOURCC ('N', 'V', '2', '1');
1266 case V4L2_PIX_FMT_YVU410:
1267 fcc = GST_MAKE_FOURCC ('Y', 'V', 'U', '9');
1269 case V4L2_PIX_FMT_YUV410:
1270 fcc = GST_MAKE_FOURCC ('Y', 'U', 'V', '9');
1272 case V4L2_PIX_FMT_YUV420:
1273 fcc = GST_MAKE_FOURCC ('I', '4', '2', '0');
1275 case V4L2_PIX_FMT_YUYV:
1276 fcc = GST_MAKE_FOURCC ('Y', 'U', 'Y', '2');
1278 case V4L2_PIX_FMT_YVU420:
1279 fcc = GST_MAKE_FOURCC ('Y', 'V', '1', '2');
1281 case V4L2_PIX_FMT_UYVY:
1282 fcc = GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y');
1284 case V4L2_PIX_FMT_Y41P:
1285 fcc = GST_MAKE_FOURCC ('Y', '4', '1', 'P');
1287 case V4L2_PIX_FMT_YUV411P:
1288 fcc = GST_MAKE_FOURCC ('Y', '4', '1', 'B');
1290 case V4L2_PIX_FMT_YUV422P:
1291 fcc = GST_MAKE_FOURCC ('Y', '4', '2', 'B');
1293 #ifdef V4L2_PIX_FMT_YVYU
1294 case V4L2_PIX_FMT_YVYU:
1295 fcc = GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U');
1299 g_assert_not_reached ();
1302 structure = gst_structure_new ("video/x-raw-yuv",
1303 "format", GST_TYPE_FOURCC, fcc, NULL);
1306 case V4L2_PIX_FMT_DV:
1308 gst_structure_new ("video/x-dv", "systemstream", G_TYPE_BOOLEAN, TRUE,
1311 case V4L2_PIX_FMT_MPEG: /* MPEG */
1312 structure = gst_structure_new ("video/mpegts", NULL);
1314 case V4L2_PIX_FMT_WNVA: /* Winnov hw compres */
1316 #ifdef V4L2_PIX_FMT_SBGGR8
1317 case V4L2_PIX_FMT_SBGGR8:
1318 structure = gst_structure_new ("video/x-raw-bayer", NULL);
1321 #ifdef V4L2_PIX_FMT_SN9C10X
1322 case V4L2_PIX_FMT_SN9C10X:
1323 structure = gst_structure_new ("video/x-sonix", NULL);
1326 #ifdef V4L2_PIX_FMT_PWC1
1327 case V4L2_PIX_FMT_PWC1:
1328 structure = gst_structure_new ("video/x-pwc1", NULL);
1331 #ifdef V4L2_PIX_FMT_PWC2
1332 case V4L2_PIX_FMT_PWC2:
1333 structure = gst_structure_new ("video/x-pwc2", NULL);
1337 GST_DEBUG ("Unknown fourcc 0x%08x %" GST_FOURCC_FORMAT,
1338 fourcc, GST_FOURCC_ARGS (fourcc));
1348 gst_v4l2_object_get_all_caps (void)
1350 static GstCaps *caps = NULL;
1353 GstStructure *structure;
1357 caps = gst_caps_new_empty ();
1358 for (i = 0; i < GST_V4L2_FORMAT_COUNT; i++) {
1360 gst_v4l2_object_v4l2fourcc_to_structure (gst_v4l2_formats[i].format);
1362 if (gst_v4l2_formats[i].dimensions) {
1363 gst_structure_set (structure,
1364 "width", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1365 "height", GST_TYPE_INT_RANGE, 1, GST_V4L2_MAX_SIZE,
1366 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, 100, 1, NULL);
1368 gst_caps_append_structure (caps, structure);
1373 return gst_caps_ref (caps);
1377 /* collect data for the given caps
1378 * @caps: given input caps
1379 * @format: location for the v4l format
1380 * @w/@h: location for width and height
1381 * @fps_n/@fps_d: location for framerate
1382 * @size: location for expected size of the frame or 0 if unknown
1385 gst_v4l2_object_get_caps_info (GstV4l2Object * v4l2object, GstCaps * caps,
1386 struct v4l2_fmtdesc ** format, gint * w, gint * h,
1387 gboolean * interlaced, guint * fps_n, guint * fps_d, guint * size)
1389 GstStructure *structure;
1390 const GValue *framerate;
1392 const gchar *mimetype;
1395 /* default unknown values */
1399 structure = gst_caps_get_structure (caps, 0);
1401 mimetype = gst_structure_get_name (structure);
1403 if (strcmp (mimetype, "video/mpegts") == 0) {
1404 fourcc = V4L2_PIX_FMT_MPEG;
1410 if (!gst_structure_get_int (structure, "width", w))
1413 if (!gst_structure_get_int (structure, "height", h))
1416 if (!gst_structure_get_boolean (structure, "interlaced", interlaced))
1417 *interlaced = FALSE;
1419 framerate = gst_structure_get_value (structure, "framerate");
1423 *fps_n = gst_value_get_fraction_numerator (framerate);
1424 *fps_d = gst_value_get_fraction_denominator (framerate);
1426 if (!strcmp (mimetype, "video/x-raw-yuv")) {
1427 gst_structure_get_fourcc (structure, "format", &fourcc);
1430 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
1431 case GST_MAKE_FOURCC ('I', 'Y', 'U', 'V'):
1432 fourcc = V4L2_PIX_FMT_YUV420;
1433 outsize = GST_ROUND_UP_4 (*w) * GST_ROUND_UP_2 (*h);
1434 outsize += 2 * ((GST_ROUND_UP_8 (*w) / 2) * (GST_ROUND_UP_2 (*h) / 2));
1436 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
1437 fourcc = V4L2_PIX_FMT_YUYV;
1438 outsize = (GST_ROUND_UP_2 (*w) * 2) * *h;
1440 case GST_MAKE_FOURCC ('Y', '4', '1', 'P'):
1441 fourcc = V4L2_PIX_FMT_Y41P;
1442 outsize = (GST_ROUND_UP_2 (*w) * 2) * *h;
1444 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
1445 fourcc = V4L2_PIX_FMT_UYVY;
1446 outsize = (GST_ROUND_UP_2 (*w) * 2) * *h;
1448 case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
1449 fourcc = V4L2_PIX_FMT_YVU420;
1450 outsize = GST_ROUND_UP_4 (*w) * GST_ROUND_UP_2 (*h);
1451 outsize += 2 * ((GST_ROUND_UP_8 (*w) / 2) * (GST_ROUND_UP_2 (*h) / 2));
1453 case GST_MAKE_FOURCC ('Y', '4', '1', 'B'):
1454 fourcc = V4L2_PIX_FMT_YUV411P;
1455 outsize = GST_ROUND_UP_4 (*w) * *h;
1456 outsize += 2 * ((GST_ROUND_UP_8 (*w) / 4) * *h);
1458 case GST_MAKE_FOURCC ('Y', '4', '2', 'B'):
1459 fourcc = V4L2_PIX_FMT_YUV422P;
1460 outsize = GST_ROUND_UP_4 (*w) * *h;
1461 outsize += 2 * ((GST_ROUND_UP_8 (*w) / 2) * *h);
1463 case GST_MAKE_FOURCC ('N', 'V', '1', '2'):
1464 fourcc = V4L2_PIX_FMT_NV12;
1465 outsize = GST_ROUND_UP_4 (*w) * GST_ROUND_UP_2 (*h);
1466 outsize += (GST_ROUND_UP_4 (*w) * *h) / 2;
1468 case GST_MAKE_FOURCC ('N', 'V', '2', '1'):
1469 fourcc = V4L2_PIX_FMT_NV21;
1470 outsize = GST_ROUND_UP_4 (*w) * GST_ROUND_UP_2 (*h);
1471 outsize += (GST_ROUND_UP_4 (*w) * *h) / 2;
1473 #ifdef V4L2_PIX_FMT_YVYU
1474 case GST_MAKE_FOURCC ('Y', 'V', 'Y', 'U'):
1475 fourcc = V4L2_PIX_FMT_YVYU;
1476 outsize = (GST_ROUND_UP_2 (*w) * 2) * *h;
1480 } else if (!strcmp (mimetype, "video/x-raw-rgb")) {
1481 gint depth, endianness, r_mask;
1483 gst_structure_get_int (structure, "depth", &depth);
1484 gst_structure_get_int (structure, "endianness", &endianness);
1485 gst_structure_get_int (structure, "red_mask", &r_mask);
1489 fourcc = V4L2_PIX_FMT_RGB332;
1492 fourcc = (endianness == G_LITTLE_ENDIAN) ?
1493 V4L2_PIX_FMT_RGB555 : V4L2_PIX_FMT_RGB555X;
1496 fourcc = (endianness == G_LITTLE_ENDIAN) ?
1497 V4L2_PIX_FMT_RGB565 : V4L2_PIX_FMT_RGB565X;
1500 fourcc = (r_mask == 0xFF) ? V4L2_PIX_FMT_BGR24 : V4L2_PIX_FMT_RGB24;
1503 fourcc = (r_mask == 0xFF) ? V4L2_PIX_FMT_BGR32 : V4L2_PIX_FMT_RGB32;
1506 } else if (strcmp (mimetype, "video/x-dv") == 0) {
1507 fourcc = V4L2_PIX_FMT_DV;
1508 } else if (strcmp (mimetype, "image/jpeg") == 0) {
1509 fourcc = V4L2_PIX_FMT_JPEG;
1510 #ifdef V4L2_PIX_FMT_SBGGR8
1511 } else if (strcmp (mimetype, "video/x-raw-bayer") == 0) {
1512 fourcc = V4L2_PIX_FMT_SBGGR8;
1514 #ifdef V4L2_PIX_FMT_SN9C10X
1515 } else if (strcmp (mimetype, "video/x-sonix") == 0) {
1516 fourcc = V4L2_PIX_FMT_SN9C10X;
1518 #ifdef V4L2_PIX_FMT_PWC1
1519 } else if (strcmp (mimetype, "video/x-pwc1") == 0) {
1520 fourcc = V4L2_PIX_FMT_PWC1;
1522 #ifdef V4L2_PIX_FMT_PWC2
1523 } else if (strcmp (mimetype, "video/x-pwc2") == 0) {
1524 fourcc = V4L2_PIX_FMT_PWC2;
1526 } else if (strcmp (mimetype, "video/x-raw-gray") == 0) {
1527 fourcc = V4L2_PIX_FMT_GREY;
1534 *format = gst_v4l2_object_get_format_from_fourcc (v4l2object, fourcc);
1542 gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
1543 guint32 pixelformat, gint * width, gint * height, gboolean * interlaced);
1546 /* The frame interval enumeration code first appeared in Linux 2.6.19. */
1547 #ifdef VIDIOC_ENUM_FRAMEINTERVALS
1548 static GstStructure *
1549 gst_v4l2_object_probe_caps_for_format_and_size (GstV4l2Object * v4l2object,
1550 guint32 pixelformat,
1551 guint32 width, guint32 height, const GstStructure * template)
1553 gint fd = v4l2object->video_fd;
1554 struct v4l2_frmivalenum ival;
1557 GValue rates = { 0, };
1558 gboolean interlaced;
1559 gint int_width = width;
1560 gint int_height = height;
1562 /* interlaced detection using VIDIOC_TRY/S_FMT */
1563 if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat,
1564 &int_width, &int_height, &interlaced))
1567 memset (&ival, 0, sizeof (struct v4l2_frmivalenum));
1569 ival.pixel_format = pixelformat;
1571 ival.height = height;
1573 GST_LOG_OBJECT (v4l2object->element,
1574 "get frame interval for %ux%u, %" GST_FOURCC_FORMAT, width, height,
1575 GST_FOURCC_ARGS (pixelformat));
1577 /* keep in mind that v4l2 gives us frame intervals (durations); we invert the
1578 * fraction to get framerate */
1579 if (v4l2_ioctl (fd, VIDIOC_ENUM_FRAMEINTERVALS, &ival) < 0)
1580 goto enum_frameintervals_failed;
1582 if (ival.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
1583 GValue rate = { 0, };
1585 g_value_init (&rates, GST_TYPE_LIST);
1586 g_value_init (&rate, GST_TYPE_FRACTION);
1589 num = ival.discrete.numerator;
1590 denom = ival.discrete.denominator;
1592 if (num > G_MAXINT || denom > G_MAXINT) {
1593 /* let us hope we don't get here... */
1598 GST_LOG_OBJECT (v4l2object->element, "adding discrete framerate: %d/%d",
1601 /* swap to get the framerate */
1602 gst_value_set_fraction (&rate, denom, num);
1603 gst_value_list_append_value (&rates, &rate);
1606 } while (v4l2_ioctl (fd, VIDIOC_ENUM_FRAMEINTERVALS, &ival) >= 0);
1607 } else if (ival.type == V4L2_FRMIVAL_TYPE_STEPWISE) {
1608 GValue min = { 0, };
1609 GValue step = { 0, };
1610 GValue max = { 0, };
1611 gboolean added = FALSE;
1612 guint32 minnum, mindenom;
1613 guint32 maxnum, maxdenom;
1615 g_value_init (&rates, GST_TYPE_LIST);
1617 g_value_init (&min, GST_TYPE_FRACTION);
1618 g_value_init (&step, GST_TYPE_FRACTION);
1619 g_value_init (&max, GST_TYPE_FRACTION);
1622 minnum = ival.stepwise.min.numerator;
1623 mindenom = ival.stepwise.min.denominator;
1624 if (minnum > G_MAXINT || mindenom > G_MAXINT) {
1628 GST_LOG_OBJECT (v4l2object->element, "stepwise min frame interval: %d/%d",
1630 gst_value_set_fraction (&min, minnum, mindenom);
1633 maxnum = ival.stepwise.max.numerator;
1634 maxdenom = ival.stepwise.max.denominator;
1635 if (maxnum > G_MAXINT || maxdenom > G_MAXINT) {
1640 GST_LOG_OBJECT (v4l2object->element, "stepwise max frame interval: %d/%d",
1642 gst_value_set_fraction (&max, maxnum, maxdenom);
1645 num = ival.stepwise.step.numerator;
1646 denom = ival.stepwise.step.denominator;
1647 if (num > G_MAXINT || denom > G_MAXINT) {
1652 if (num == 0 || denom == 0) {
1653 /* in this case we have a wrong fraction or no step, set the step to max
1654 * so that we only add the min value in the loop below */
1659 /* since we only have gst_value_fraction_subtract and not add, negate the
1661 GST_LOG_OBJECT (v4l2object->element, "stepwise step frame interval: %d/%d",
1663 gst_value_set_fraction (&step, -num, denom);
1665 while (gst_value_compare (&min, &max) <= 0) {
1666 GValue rate = { 0, };
1668 num = gst_value_get_fraction_numerator (&min);
1669 denom = gst_value_get_fraction_denominator (&min);
1670 GST_LOG_OBJECT (v4l2object->element, "adding stepwise framerate: %d/%d",
1673 /* invert to get the framerate */
1674 g_value_init (&rate, GST_TYPE_FRACTION);
1675 gst_value_set_fraction (&rate, denom, num);
1676 gst_value_list_append_value (&rates, &rate);
1679 /* we're actually adding because step was negated above. This is because
1680 * there is no _add function... */
1681 if (!gst_value_fraction_subtract (&min, &min, &step)) {
1682 GST_WARNING_OBJECT (v4l2object->element, "could not step fraction!");
1687 /* no range was added, leave the default range from the template */
1688 GST_WARNING_OBJECT (v4l2object->element,
1689 "no range added, leaving default");
1690 g_value_unset (&rates);
1692 } else if (ival.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) {
1693 guint32 maxnum, maxdenom;
1695 g_value_init (&rates, GST_TYPE_FRACTION_RANGE);
1697 num = ival.stepwise.min.numerator;
1698 denom = ival.stepwise.min.denominator;
1699 if (num > G_MAXINT || denom > G_MAXINT) {
1704 maxnum = ival.stepwise.max.numerator;
1705 maxdenom = ival.stepwise.max.denominator;
1706 if (maxnum > G_MAXINT || maxdenom > G_MAXINT) {
1711 GST_LOG_OBJECT (v4l2object->element,
1712 "continuous frame interval %d/%d to %d/%d", maxdenom, maxnum, denom,
1715 gst_value_set_fraction_range_full (&rates, maxdenom, maxnum, denom, num);
1721 s = gst_structure_copy (template);
1722 gst_structure_set (s, "width", G_TYPE_INT, (gint) width,
1723 "height", G_TYPE_INT, (gint) height,
1724 "interlaced", G_TYPE_BOOLEAN, interlaced,
1725 "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL);
1727 if (G_IS_VALUE (&rates)) {
1728 /* only change the framerate on the template when we have a valid probed new
1730 gst_structure_set_value (s, "framerate", &rates);
1731 g_value_unset (&rates);
1733 gst_structure_set (s, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, 100, 1,
1739 enum_frameintervals_failed:
1741 GST_DEBUG_OBJECT (v4l2object->element,
1742 "Unable to enumerate intervals for %" GST_FOURCC_FORMAT "@%ux%u",
1743 GST_FOURCC_ARGS (pixelformat), width, height);
1748 /* I don't see how this is actually an error, we ignore the format then */
1749 GST_WARNING_OBJECT (v4l2object->element,
1750 "Unknown frame interval type at %" GST_FOURCC_FORMAT "@%ux%u: %u",
1751 GST_FOURCC_ARGS (pixelformat), width, height, ival.type);
1755 #endif /* defined VIDIOC_ENUM_FRAMEINTERVALS */
1757 #ifdef VIDIOC_ENUM_FRAMESIZES
1759 sort_by_frame_size (GstStructure * s1, GstStructure * s2)
1763 gst_structure_get_int (s1, "width", &w1);
1764 gst_structure_get_int (s1, "height", &h1);
1765 gst_structure_get_int (s2, "width", &w2);
1766 gst_structure_get_int (s2, "height", &h2);
1768 /* I think it's safe to assume that this won't overflow for a while */
1769 return ((w2 * h2) - (w1 * h1));
1774 gst_v4l2_object_probe_caps_for_format (GstV4l2Object * v4l2object,
1775 guint32 pixelformat, const GstStructure * template)
1777 GstCaps *ret = gst_caps_new_empty ();
1780 #ifdef VIDIOC_ENUM_FRAMESIZES
1781 gint fd = v4l2object->video_fd;
1782 struct v4l2_frmsizeenum size;
1783 GList *results = NULL;
1786 if (pixelformat == GST_MAKE_FOURCC ('M', 'P', 'E', 'G'))
1787 return gst_caps_new_simple ("video/mpegts", NULL);
1789 memset (&size, 0, sizeof (struct v4l2_frmsizeenum));
1791 size.pixel_format = pixelformat;
1793 GST_DEBUG_OBJECT (v4l2object->element, "Enumerating frame sizes");
1795 if (v4l2_ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &size) < 0)
1796 goto enum_framesizes_failed;
1798 if (size.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
1800 GST_LOG_OBJECT (v4l2object->element, "got discrete frame size %dx%d",
1801 size.discrete.width, size.discrete.height);
1803 w = MIN (size.discrete.width, G_MAXINT);
1804 h = MIN (size.discrete.height, G_MAXINT);
1808 gst_v4l2_object_probe_caps_for_format_and_size (v4l2object,
1809 pixelformat, w, h, template);
1812 results = g_list_prepend (results, tmp);
1816 } while (v4l2_ioctl (fd, VIDIOC_ENUM_FRAMESIZES, &size) >= 0);
1817 GST_DEBUG_OBJECT (v4l2object->element,
1818 "done iterating discrete frame sizes");
1819 } else if (size.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
1820 GST_DEBUG_OBJECT (v4l2object->element, "we have stepwise frame sizes:");
1821 GST_DEBUG_OBJECT (v4l2object->element, "min width: %d",
1822 size.stepwise.min_width);
1823 GST_DEBUG_OBJECT (v4l2object->element, "min height: %d",
1824 size.stepwise.min_height);
1825 GST_DEBUG_OBJECT (v4l2object->element, "max width: %d",
1826 size.stepwise.max_width);
1827 GST_DEBUG_OBJECT (v4l2object->element, "min height: %d",
1828 size.stepwise.max_height);
1829 GST_DEBUG_OBJECT (v4l2object->element, "step width: %d",
1830 size.stepwise.step_width);
1831 GST_DEBUG_OBJECT (v4l2object->element, "step height: %d",
1832 size.stepwise.step_height);
1834 for (w = size.stepwise.min_width, h = size.stepwise.min_height;
1835 w < size.stepwise.max_width && h < size.stepwise.max_height;
1836 w += size.stepwise.step_width, h += size.stepwise.step_height) {
1837 if (w == 0 || h == 0)
1841 gst_v4l2_object_probe_caps_for_format_and_size (v4l2object,
1842 pixelformat, w, h, template);
1845 results = g_list_prepend (results, tmp);
1847 GST_DEBUG_OBJECT (v4l2object->element,
1848 "done iterating stepwise frame sizes");
1849 } else if (size.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) {
1852 GST_DEBUG_OBJECT (v4l2object->element, "we have continuous frame sizes:");
1853 GST_DEBUG_OBJECT (v4l2object->element, "min width: %d",
1854 size.stepwise.min_width);
1855 GST_DEBUG_OBJECT (v4l2object->element, "min height: %d",
1856 size.stepwise.min_height);
1857 GST_DEBUG_OBJECT (v4l2object->element, "max width: %d",
1858 size.stepwise.max_width);
1859 GST_DEBUG_OBJECT (v4l2object->element, "min height: %d",
1860 size.stepwise.max_height);
1862 w = MAX (size.stepwise.min_width, 1);
1863 h = MAX (size.stepwise.min_height, 1);
1864 maxw = MIN (size.stepwise.max_width, G_MAXINT);
1865 maxh = MIN (size.stepwise.max_height, G_MAXINT);
1868 gst_v4l2_object_probe_caps_for_format_and_size (v4l2object, pixelformat,
1871 gst_structure_set (tmp, "width", GST_TYPE_INT_RANGE, (gint) w,
1872 (gint) maxw, "height", GST_TYPE_INT_RANGE, (gint) h, (gint) maxh,
1875 /* no point using the results list here, since there's only one struct */
1876 gst_caps_append_structure (ret, tmp);
1882 /* we use an intermediary list to store and then sort the results of the
1883 * probing because we can't make any assumptions about the order in which
1884 * the driver will give us the sizes, but we want the final caps to contain
1885 * the results starting with the highest resolution and having the lowest
1886 * resolution last, since order in caps matters for things like fixation. */
1887 results = g_list_sort (results, (GCompareFunc) sort_by_frame_size);
1888 while (results != NULL) {
1889 gst_caps_append_structure (ret, GST_STRUCTURE (results->data));
1890 results = g_list_delete_link (results, results);
1893 if (gst_caps_is_empty (ret))
1894 goto enum_framesizes_no_results;
1899 enum_framesizes_failed:
1901 /* I don't see how this is actually an error */
1902 GST_DEBUG_OBJECT (v4l2object->element,
1903 "Failed to enumerate frame sizes for pixelformat %" GST_FOURCC_FORMAT
1904 " (%s)", GST_FOURCC_ARGS (pixelformat), g_strerror (errno));
1905 goto default_frame_sizes;
1907 enum_framesizes_no_results:
1909 /* it's possible that VIDIOC_ENUM_FRAMESIZES is defined but the driver in
1910 * question doesn't actually support it yet */
1911 GST_DEBUG_OBJECT (v4l2object->element,
1912 "No results for pixelformat %" GST_FOURCC_FORMAT
1913 " enumerating frame sizes, trying fallback",
1914 GST_FOURCC_ARGS (pixelformat));
1915 goto default_frame_sizes;
1919 GST_WARNING_OBJECT (v4l2object->element,
1920 "Unknown frame sizeenum type for pixelformat %" GST_FOURCC_FORMAT
1921 ": %u", GST_FOURCC_ARGS (pixelformat), size.type);
1922 goto default_frame_sizes;
1924 default_frame_sizes:
1925 #endif /* defined VIDIOC_ENUM_FRAMESIZES */
1927 gint min_w, max_w, min_h, max_h, fix_num = 0, fix_denom = 0;
1928 gboolean interlaced;
1930 /* This code is for Linux < 2.6.19 */
1932 max_w = max_h = GST_V4L2_MAX_SIZE;
1933 if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &min_w,
1934 &min_h, &interlaced)) {
1935 GST_WARNING_OBJECT (v4l2object->element,
1936 "Could not probe minimum capture size for pixelformat %"
1937 GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
1939 if (!gst_v4l2_object_get_nearest_size (v4l2object, pixelformat, &max_w,
1940 &max_h, &interlaced)) {
1941 GST_WARNING_OBJECT (v4l2object->element,
1942 "Could not probe maximum capture size for pixelformat %"
1943 GST_FOURCC_FORMAT, GST_FOURCC_ARGS (pixelformat));
1946 /* Since we can't get framerate directly, try to use the current norm */
1947 if (v4l2object->tv_norm && v4l2object->norms) {
1949 GstTunerNorm *norm = NULL;
1950 GstTunerNorm *current =
1951 gst_v4l2_tuner_get_norm_by_std_id (v4l2object, v4l2object->tv_norm);
1953 for (norms = v4l2object->norms; norms != NULL; norms = norms->next) {
1954 norm = (GstTunerNorm *) norms->data;
1955 if (!strcmp (norm->label, current->label))
1958 /* If it's possible, set framerate to that (discrete) value */
1960 fix_num = gst_value_get_fraction_numerator (&norm->framerate);
1961 fix_denom = gst_value_get_fraction_denominator (&norm->framerate);
1965 tmp = gst_structure_copy (template);
1967 gst_structure_set (tmp, "framerate", GST_TYPE_FRACTION, fix_num,
1970 /* if norm can't be used, copy the template framerate */
1971 gst_structure_set (tmp, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1,
1976 gst_structure_set (tmp, "width", G_TYPE_INT, max_w, NULL);
1978 gst_structure_set (tmp, "width", GST_TYPE_INT_RANGE, min_w, max_w, NULL);
1981 gst_structure_set (tmp, "height", G_TYPE_INT, max_h, NULL);
1983 gst_structure_set (tmp, "height", GST_TYPE_INT_RANGE, min_h, max_h, NULL);
1985 gst_structure_set (tmp, "interlaced", G_TYPE_BOOLEAN, interlaced, NULL);
1986 gst_structure_set (tmp, "pixel-aspect-ratio",
1987 GST_TYPE_FRACTION, 1, 1, NULL);
1989 gst_caps_append_structure (ret, tmp);
1996 gst_v4l2_object_get_nearest_size (GstV4l2Object * v4l2object,
1997 guint32 pixelformat, gint * width, gint * height, gboolean * interlaced)
1999 struct v4l2_format fmt, prevfmt;
2004 g_return_val_if_fail (width != NULL, FALSE);
2005 g_return_val_if_fail (height != NULL, FALSE);
2007 GST_LOG_OBJECT (v4l2object->element,
2008 "getting nearest size to %dx%d with format %" GST_FOURCC_FORMAT,
2009 *width, *height, GST_FOURCC_ARGS (pixelformat));
2011 fd = v4l2object->video_fd;
2013 /* Some drivers are buggy and will modify the currently set format
2014 when processing VIDIOC_TRY_FMT, so we remember what is set at the
2015 minute, and will reset it when done. */
2016 prevfmt_valid = (v4l2_ioctl (fd, VIDIOC_G_FMT, &prevfmt) >= 0);
2018 /* get size delimiters */
2019 memset (&fmt, 0, sizeof (fmt));
2020 fmt.type = v4l2object->type;
2021 fmt.fmt.pix.width = *width;
2022 fmt.fmt.pix.height = *height;
2023 fmt.fmt.pix.pixelformat = pixelformat;
2024 fmt.fmt.pix.field = V4L2_FIELD_NONE;
2026 r = v4l2_ioctl (fd, VIDIOC_TRY_FMT, &fmt);
2027 if (r < 0 && errno == EINVAL) {
2028 /* try again with interlaced video */
2029 fmt.fmt.pix.width = *width;
2030 fmt.fmt.pix.height = *height;
2031 fmt.fmt.pix.pixelformat = pixelformat;
2032 fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
2033 r = v4l2_ioctl (fd, VIDIOC_TRY_FMT, &fmt);
2037 /* The driver might not implement TRY_FMT, in which case we will try
2039 if (errno != ENOTTY)
2042 /* Only try S_FMT if we're not actively capturing yet, which we shouldn't
2043 be, because we're still probing */
2044 if (GST_V4L2_IS_ACTIVE (v4l2object))
2047 GST_LOG_OBJECT (v4l2object->element,
2048 "Failed to probe size limit with VIDIOC_TRY_FMT, trying VIDIOC_S_FMT");
2050 fmt.fmt.pix.width = *width;
2051 fmt.fmt.pix.height = *height;
2053 r = v4l2_ioctl (fd, VIDIOC_S_FMT, &fmt);
2054 if (r < 0 && errno == EINVAL) {
2055 /* try again with progressive video */
2056 fmt.fmt.pix.width = *width;
2057 fmt.fmt.pix.height = *height;
2058 fmt.fmt.pix.pixelformat = pixelformat;
2059 fmt.fmt.pix.field = V4L2_FIELD_NONE;
2060 r = v4l2_ioctl (fd, VIDIOC_S_FMT, &fmt);
2067 GST_LOG_OBJECT (v4l2object->element,
2068 "got nearest size %dx%d", fmt.fmt.pix.width, fmt.fmt.pix.height);
2070 *width = fmt.fmt.pix.width;
2071 *height = fmt.fmt.pix.height;
2073 switch (fmt.fmt.pix.field) {
2074 case V4L2_FIELD_ANY:
2075 case V4L2_FIELD_NONE:
2076 *interlaced = FALSE;
2078 case V4L2_FIELD_INTERLACED:
2079 case V4L2_FIELD_INTERLACED_TB:
2080 case V4L2_FIELD_INTERLACED_BT:
2084 GST_WARNING_OBJECT (v4l2object->element,
2085 "Unsupported field type for %" GST_FOURCC_FORMAT "@%ux%u",
2086 GST_FOURCC_ARGS (pixelformat), *width, *height);
2091 v4l2_ioctl (fd, VIDIOC_S_FMT, &prevfmt);
2096 v4l2_ioctl (fd, VIDIOC_S_FMT, &prevfmt);
2102 gst_v4l2_object_set_format (GstV4l2Object * v4l2object, guint32 pixelformat,
2103 guint32 width, guint32 height, gboolean interlaced)
2105 gint fd = v4l2object->video_fd;
2106 struct v4l2_format format;
2107 enum v4l2_field field;
2110 GST_DEBUG_OBJECT (v4l2object->element, "interlaced video");
2111 /* ideally we would differentiate between types of interlaced video
2112 * but there is not sufficient information in the caps..
2114 field = V4L2_FIELD_INTERLACED;
2116 GST_DEBUG_OBJECT (v4l2object->element, "progressive video");
2117 field = V4L2_FIELD_NONE;
2120 GST_DEBUG_OBJECT (v4l2object->element, "Setting format to %dx%d, format "
2121 "%" GST_FOURCC_FORMAT, width, height, GST_FOURCC_ARGS (pixelformat));
2123 GST_V4L2_CHECK_OPEN (v4l2object);
2124 GST_V4L2_CHECK_NOT_ACTIVE (v4l2object);
2126 /* Only unconditionally accept mpegts for sources */
2127 if ((v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
2128 (pixelformat == GST_MAKE_FOURCC ('M', 'P', 'E', 'G')))
2131 memset (&format, 0x00, sizeof (struct v4l2_format));
2132 format.type = v4l2object->type;
2134 if (v4l2_ioctl (fd, VIDIOC_G_FMT, &format) < 0)
2135 goto get_fmt_failed;
2137 if (format.type == v4l2object->type &&
2138 format.fmt.pix.width == width &&
2139 format.fmt.pix.height == height &&
2140 format.fmt.pix.pixelformat == pixelformat &&
2141 format.fmt.pix.field == field) {
2142 /* Nothing to do. We want to succeed immediately
2143 * here because setting the same format back
2144 * can still fail due to EBUSY. By short-circuiting
2145 * here, we allow pausing and re-playing pipelines
2146 * with changed caps, as long as the changed caps
2147 * do not change the webcam's format. Otherwise,
2148 * any caps change would require us to go to NULL
2149 * state to close the device and set format.
2154 format.type = v4l2object->type;
2155 format.fmt.pix.width = width;
2156 format.fmt.pix.height = height;
2157 format.fmt.pix.pixelformat = pixelformat;
2158 format.fmt.pix.field = field;
2160 if (v4l2_ioctl (fd, VIDIOC_S_FMT, &format) < 0) {
2161 goto set_fmt_failed;
2164 if (format.fmt.pix.width != width || format.fmt.pix.height != height)
2165 goto invalid_dimensions;
2167 if (format.fmt.pix.pixelformat != pixelformat)
2168 goto invalid_pixelformat;
2175 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
2176 (_("Device '%s' does not support video capture"),
2177 v4l2object->videodev),
2178 ("Call to G_FMT failed: (%s)", g_strerror (errno)));
2183 if (errno == EBUSY) {
2184 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, BUSY,
2185 (_("Device '%s' is busy"), v4l2object->videodev),
2186 ("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
2187 GST_FOURCC_ARGS (pixelformat), width, height,
2188 g_strerror (errno)));
2190 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
2191 (_("Device '%s' cannot capture at %dx%d"),
2192 v4l2object->videodev, width, height),
2193 ("Call to S_FMT failed for %" GST_FOURCC_FORMAT " @ %dx%d: %s",
2194 GST_FOURCC_ARGS (pixelformat), width, height,
2195 g_strerror (errno)));
2201 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
2202 (_("Device '%s' cannot capture at %dx%d"),
2203 v4l2object->videodev, width, height),
2204 ("Tried to capture at %dx%d, but device returned size %dx%d",
2205 width, height, format.fmt.pix.width, format.fmt.pix.height));
2208 invalid_pixelformat:
2210 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
2211 (_("Device '%s' cannot capture in the specified format"),
2212 v4l2object->videodev),
2213 ("Tried to capture in %" GST_FOURCC_FORMAT
2214 ", but device returned format" " %" GST_FOURCC_FORMAT,
2215 GST_FOURCC_ARGS (pixelformat),
2216 GST_FOURCC_ARGS (format.fmt.pix.pixelformat)));
2222 gst_v4l2_object_start_streaming (GstV4l2Object * v4l2object)
2224 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_STREAMON,
2225 &(v4l2object->type)) < 0) {
2226 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, OPEN_READ,
2227 (_("Error starting streaming on device '%s'."), v4l2object->videodev),
2235 gst_v4l2_object_stop_streaming (GstV4l2Object * v4l2object)
2237 if (v4l2_ioctl (v4l2object->video_fd, VIDIOC_STREAMOFF,
2238 &(v4l2object->type)) < 0) {
2239 GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, OPEN_READ,
2240 (_("Error stopping streaming on device '%s'."), v4l2object->videodev),