From 8023d9492dfd1bbed93fd6eef1531c1968b6310a Mon Sep 17 00:00:00 2001 From: Edgard Lima Date: Sat, 25 Mar 2006 05:31:28 +0000 Subject: Just make few things more robust and also some identation. Original commit message from CVS: Just make few things more robust and also some identation. --- sys/v4l2/gstv4l2element.c | 134 +++++++++++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 54 deletions(-) (limited to 'sys/v4l2/gstv4l2element.c') diff --git a/sys/v4l2/gstv4l2element.c b/sys/v4l2/gstv4l2element.c index e5acbf87..d6f14d47 100644 --- a/sys/v4l2/gstv4l2element.c +++ b/sys/v4l2/gstv4l2element.c @@ -1,23 +1,17 @@ -/* GStreamer - * - * gstv4l2element.c: base class for V4L2 elements - * - * Copyright (C) 2001-2002 Ronald Bultje - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * +/* + * GStreamer gstv4l2element.c: base class for V4L2 elements Copyright + * (C) 2001-2002 Ronald Bultje This library + * is free software; you can redistribute it and/or modify it under the + * terms of the GNU Library General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. This library is distributed in the hope + * that it will be useful, but WITHOUT ANY WARRANTY; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Library General Public License for more details. * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. */ #ifdef HAVE_CONFIG_H @@ -56,8 +50,6 @@ static void gst_v4l2element_init_interfaces (GType type); GST_BOILERPLATE_FULL (GstV4l2Element, gst_v4l2element, GstPushSrc, GST_TYPE_PUSH_SRC, gst_v4l2element_init_interfaces) - - static void gst_v4l2element_dispose (GObject * object); static void gst_v4l2element_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); @@ -95,7 +87,9 @@ GST_BOILERPLATE_FULL (GstV4l2Element, gst_v4l2element, GstPushSrc, static void gst_v4l2_interface_init (GstImplementsInterfaceClass * klass) { - /* default virtual functions */ + /* + * default virtual functions + */ klass->supported = gst_v4l2_iface_supported; } @@ -130,21 +124,32 @@ gst_v4l2_class_probe_devices (GstV4l2ElementClass * klass, gboolean check) g_free (device); } - /* detect /dev entries */ + /* + * detect /dev entries + */ for (n = 0; n < 64; n++) { for (base = 0; dev_base[base] != NULL; base++) { struct stat s; - gchar *device = g_strdup_printf ("%s%d", dev_base[base], n); + gchar *device = g_strdup_printf ("%s%d", + dev_base[base], + n); - /* does the /dev/ entry exist at all? */ + /* + * does the /dev/ entry exist at all? + */ if (stat (device, &s) == 0) { - /* yes: is a device attached? */ - if ((fd = open (device, O_RDONLY)) > 0 || errno == EBUSY) { - if (fd > 0) - close (fd); - - devices = g_list_append (devices, device); - break; + /* + * yes: is a device attached? + */ + if (S_ISCHR (s.st_mode)) { + + if ((fd = open (device, O_RDWR | O_NONBLOCK)) > 0 || errno == EBUSY) { + if (fd > 0) + close (fd); + + devices = g_list_append (devices, device); + break; + } } } g_free (device); @@ -256,12 +261,22 @@ gst_v4l2_device_get_type (void) if (v4l2_device_type == 0) { static const GFlagsValue values[] = { - {V4L2_CAP_VIDEO_CAPTURE, "CAPTURE", "Device can capture"}, - {V4L2_CAP_VIDEO_OUTPUT, "PLAYBACK", "Device can playback"}, - {V4L2_CAP_VIDEO_OVERLAY, "OVERLAY", "Device can do overlay"}, - - {V4L2_CAP_TUNER, "TUNER", "Device has a tuner"}, - {V4L2_CAP_AUDIO, "AUDIO", "Device handles audio"}, + {V4L2_CAP_VIDEO_CAPTURE, "CAPTURE", + "Device supports video capture"}, + {V4L2_CAP_VIDEO_OUTPUT, "PLAYBACK", + "Device supports video playback"}, + {V4L2_CAP_VIDEO_OVERLAY, "OVERLAY", + "Device supports video overlay"}, + + {V4L2_CAP_VBI_CAPTURE, "VBI_CAPTURE", + "Device supports the VBI capture"}, + {V4L2_CAP_VBI_OUTPUT, "VBI_OUTPUT", + "Device supports the VBI output"}, + + {V4L2_CAP_TUNER, "TUNER", + "Device has a tuner or modulator"}, + {V4L2_CAP_AUDIO, "AUDIO", + "Device has audio inputs or outputs"}, {0, NULL, NULL} }; @@ -312,8 +327,8 @@ gst_v4l2element_init_interfaces (GType type) #endif g_type_add_interface_static (type, GST_TYPE_COLOR_BALANCE, &v4l2_colorbalance_info); - g_type_add_interface_static (type, - GST_TYPE_PROPERTY_PROBE, &v4l2_propertyprobe_info); + g_type_add_interface_static (type, GST_TYPE_PROPERTY_PROBE, + &v4l2_propertyprobe_info); } @@ -338,22 +353,26 @@ gst_v4l2element_class_init (GstV4l2ElementClass * klass) gobject_class->get_property = gst_v4l2element_get_property; g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DEVICE, - g_param_spec_string ("device", "Device", "Device location", - NULL, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DEVICE_NAME, - g_param_spec_string ("device_name", "Device name", "Name of the device", - NULL, G_PARAM_READABLE)); + g_param_spec_string ("device", + "Device", "Device location", NULL, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), + PROP_DEVICE_NAME, + g_param_spec_string ("device_name", + "Device name", "Name of the device", NULL, G_PARAM_READABLE)); g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_FLAGS, - g_param_spec_flags ("flags", "Flags", "Device type flags", + g_param_spec_flags ("flags", "Flags", + "Device type flags", GST_TYPE_V4L2_DEVICE_FLAGS, 0, G_PARAM_READABLE)); g_object_class_install_property (gobject_class, PROP_STD, g_param_spec_string ("std", "std", "standard (norm) to use", NULL, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_INPUT, - g_param_spec_string ("input", "input", + g_param_spec_string ("input", + "input", "input/output (channel) to switch to", NULL, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_FREQUENCY, - g_param_spec_ulong ("frequency", "frequency", + g_param_spec_ulong ("frequency", + "frequency", "frequency to tune to (in Hz)", 0, G_MAXULONG, 0, G_PARAM_READWRITE)); basesrc_class->start = gst_v4l2element_start; @@ -366,7 +385,9 @@ gst_v4l2element_class_init (GstV4l2ElementClass * klass) static void gst_v4l2element_init (GstV4l2Element * v4l2element, GstV4l2ElementClass * klass) { - /* some default values */ + /* + * some default values + */ v4l2element->video_fd = -1; v4l2element->buffer = NULL; v4l2element->videodev = g_strdup ("/dev/video0"); @@ -410,7 +431,8 @@ gst_v4l2element_set_property (GObject * object, if (GST_V4L2_IS_OPEN (v4l2element)) { GstTuner *tuner = GST_TUNER (v4l2element); GstTunerNorm *norm = gst_tuner_find_norm_by_name (tuner, - (gchar *) g_value_get_string (value)); + (gchar *) + g_value_get_string (value)); if (norm) { gst_tuner_set_norm (tuner, norm); @@ -425,7 +447,8 @@ gst_v4l2element_set_property (GObject * object, if (GST_V4L2_IS_OPEN (v4l2element)) { GstTuner *tuner = GST_TUNER (v4l2element); GstTunerChannel *channel = gst_tuner_find_channel_by_name (tuner, - (gchar *) g_value_get_string (value)); + (gchar *) + g_value_get_string (value)); if (channel) { gst_tuner_set_channel (tuner, channel); @@ -467,7 +490,8 @@ gst_v4l2element_get_property (GObject * object, case PROP_DEVICE: g_value_set_string (value, v4l2element->videodev); break; - case PROP_DEVICE_NAME:{ + case PROP_DEVICE_NAME: + { gchar *new = NULL; if (GST_V4L2_IS_OPEN (v4l2element)) @@ -475,12 +499,14 @@ gst_v4l2element_get_property (GObject * object, g_value_set_string (value, new); break; } - case PROP_FLAGS:{ + case PROP_FLAGS: + { guint flags = 0; if (GST_V4L2_IS_OPEN (v4l2element)) { flags |= v4l2element->vcap.capabilities & - (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT | + (V4L2_CAP_VIDEO_CAPTURE | + V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OVERLAY | V4L2_CAP_TUNER | V4L2_CAP_AUDIO); if (v4l2element->vcap.capabilities & V4L2_CAP_AUDIO) flags |= V4L2_FBUF_CAP_CHROMAKEY; -- cgit v1.2.1