[cheese] Move handling of one UDI into its own function
- From: Bastien Nocera <hadess src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [cheese] Move handling of one UDI into its own function
- Date: Wed, 2 Dec 2009 18:01:29 +0000 (UTC)
commit c8c331b7776cfc44f12888796462962de68418b8
Author: Bastien Nocera <hadess hadess net>
Date: Wed Dec 2 17:22:25 2009 +0000
Move handling of one UDI into its own function
libcheese/cheese-camera-device-monitor.c | 262 ++++++++++++++++--------------
1 files changed, 137 insertions(+), 125 deletions(-)
---
diff --git a/libcheese/cheese-camera-device-monitor.c b/libcheese/cheese-camera-device-monitor.c
index 967a1b2..a44f6d5 100644
--- a/libcheese/cheese-camera-device-monitor.c
+++ b/libcheese/cheese-camera-device-monitor.c
@@ -67,16 +67,147 @@ cheese_camera_device_monitor_error_quark (void)
return g_quark_from_static_string ("cheese-camera-error-quark");
}
+static void
+cheese_camera_device_monitor_handle_udi (CheeseCameraDeviceMonitor *monitor,
+ LibHalContext *hal_ctx,
+ const char *udi)
+{
+ char *device_path;
+ char *parent_udi = NULL;
+ char *subsystem = NULL;
+ char *gstreamer_src, *product_name;
+ struct v4l2_capability v2cap;
+ struct video_capability v1cap;
+ gint vendor_id = 0;
+ gint product_id = 0;
+ gchar *property_name = NULL;
+ CheeseCameraDevice *device;
+ DBusError error;
+ int fd, ok;
+
+ parent_udi = libhal_device_get_property_string (hal_ctx, udi, "info.parent", &error);
+ if (dbus_error_is_set (&error))
+ {
+ g_warning ("error getting parent for %s: %s: %s", udi, error.name, error.message);
+ dbus_error_free (&error);
+ }
+
+ if (parent_udi != NULL)
+ {
+ subsystem = libhal_device_get_property_string (hal_ctx, parent_udi, "info.subsystem", NULL);
+ if (subsystem == NULL)
+ return;
+ property_name = g_strjoin (".", subsystem, "vendor_id", NULL);
+ vendor_id = libhal_device_get_property_int (hal_ctx, parent_udi, property_name, &error);
+ if (dbus_error_is_set (&error))
+ {
+ g_warning ("error getting vendor id: %s: %s", error.name, error.message);
+ dbus_error_free (&error);
+ }
+ g_free (property_name);
+
+ property_name = g_strjoin (".", subsystem, "product_id", NULL);
+ product_id = libhal_device_get_property_int (hal_ctx, parent_udi, property_name, &error);
+ if (dbus_error_is_set (&error))
+ {
+ g_warning ("error getting product id: %s: %s", error.name, error.message);
+ dbus_error_free (&error);
+ }
+ g_free (property_name);
+ libhal_free_string (subsystem);
+ libhal_free_string (parent_udi);
+ }
+
+ g_print ("Found device %04x:%04x, getting capabilities...\n", vendor_id, product_id);
+
+ device_path = libhal_device_get_property_string (hal_ctx, udi, "video4linux.device", &error);
+ if (dbus_error_is_set (&error))
+ {
+ g_warning ("error getting V4L device for %s: %s: %s", udi, error.name, error.message);
+ dbus_error_free (&error);
+ return;
+ }
+
+ /* vbi devices support capture capability too, but cannot be used,
+ * so detect them by device name */
+ if (strstr (device_path, "vbi"))
+ {
+ g_print ("Skipping vbi device: %s\n", device_path);
+ libhal_free_string (device_path);
+ return;
+ }
+
+ if ((fd = open (device_path, O_RDONLY | O_NONBLOCK)) < 0)
+ {
+ g_warning ("Failed to open %s: %s", device_path, strerror (errno));
+ libhal_free_string (device_path);
+ return;
+ }
+ ok = ioctl (fd, VIDIOC_QUERYCAP, &v2cap);
+ if (ok < 0)
+ {
+ ok = ioctl (fd, VIDIOCGCAP, &v1cap);
+ if (ok < 0)
+ {
+ g_warning ("Error while probing v4l capabilities for %s: %s",
+ device_path, strerror (errno));
+ libhal_free_string (device_path);
+ close (fd);
+ return;
+ }
+ g_print ("Detected v4l device: %s\n", v1cap.name);
+ g_print ("Device type: %d\n", v1cap.type);
+ gstreamer_src = "v4lsrc";
+ product_name = v1cap.name;
+ }
+ else
+ {
+ guint cap = v2cap.capabilities;
+ g_print ("Detected v4l2 device: %s\n", v2cap.card);
+ g_print ("Driver: %s, version: %d\n", v2cap.driver, v2cap.version);
+
+ /* g_print ("Bus info: %s\n", v2cap.bus_info); */ /* Doesn't seem anything useful */
+ g_print ("Capabilities: 0x%08X\n", v2cap.capabilities);
+ if (!(cap & V4L2_CAP_VIDEO_CAPTURE))
+ {
+ g_print ("Device %s seems to not have the capture capability, (radio tuner?)\n"
+ "Removing it from device list.\n", device_path);
+ libhal_free_string (device_path);
+ close (fd);
+ return;
+ }
+ gstreamer_src = "v4l2src";
+ product_name = (char *) v2cap.card;
+ }
+
+ g_print ("\n");
+
+ device = g_new0 (CheeseCameraDevice, 1);
+
+ device->hal_udi = g_strdup (udi);
+ device->video_device = g_strdup (device_path);
+ device->gstreamer_src = g_strdup (gstreamer_src);
+ device->product_name = g_strdup (product_name);
+ device->num_video_formats = 0;
+ device->video_formats = g_array_new (FALSE, FALSE, sizeof (CheeseVideoFormat));
+ device->supported_resolutions =
+ g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ //FIXME This will leak a device, we should ref/unref it instead
+ g_signal_emit (monitor, monitor_signals[ADDED], 0, device);
+ libhal_free_string (device_path);
+ close (fd);
+}
+
void
cheese_camera_device_monitor_coldplug (CheeseCameraDeviceMonitor *monitor)
{
// CheeseCameraDeviceMonitorPrivate *priv = CHEESE_CAMERA_DEVICE_MONITOR_GET_PRIVATE (camera);
- int i, fd, ok;
+ int i;
int num_udis = 0;
char **udis;
- DBusError error;
LibHalContext *hal_ctx;
+ DBusError error;
g_print ("Probing devices with HAL...\n");
@@ -119,129 +250,7 @@ cheese_camera_device_monitor_coldplug (CheeseCameraDeviceMonitor *monitor)
/* Initialize camera structures */
for (i = 0; i < num_udis; i++)
- {
- char *device_path;
- char *parent_udi = NULL;
- char *subsystem = NULL;
- char *gstreamer_src, *product_name;
- struct v4l2_capability v2cap;
- struct video_capability v1cap;
- gint vendor_id = 0;
- gint product_id = 0;
- gchar *property_name = NULL;
- CheeseCameraDevice *device;
-
- parent_udi = libhal_device_get_property_string (hal_ctx, udis[i], "info.parent", &error);
- if (dbus_error_is_set (&error))
- {
- g_warning ("error getting parent for %s: %s: %s", udis[i], error.name, error.message);
- dbus_error_free (&error);
- }
-
- if (parent_udi != NULL)
- {
- subsystem = libhal_device_get_property_string (hal_ctx, parent_udi, "info.subsystem", NULL);
- if (subsystem == NULL) continue;
- property_name = g_strjoin (".", subsystem, "vendor_id", NULL);
- vendor_id = libhal_device_get_property_int (hal_ctx, parent_udi, property_name, &error);
- if (dbus_error_is_set (&error))
- {
- g_warning ("error getting vendor id: %s: %s", error.name, error.message);
- dbus_error_free (&error);
- }
- g_free (property_name);
-
- property_name = g_strjoin (".", subsystem, "product_id", NULL);
- product_id = libhal_device_get_property_int (hal_ctx, parent_udi, property_name, &error);
- if (dbus_error_is_set (&error))
- {
- g_warning ("error getting product id: %s: %s", error.name, error.message);
- dbus_error_free (&error);
- }
- g_free (property_name);
- libhal_free_string (subsystem);
- libhal_free_string (parent_udi);
- }
-
- g_print ("Found device %04x:%04x, getting capabilities...\n", vendor_id, product_id);
-
- device_path = libhal_device_get_property_string (hal_ctx, udis[i], "video4linux.device", &error);
- if (dbus_error_is_set (&error))
- {
- g_warning ("error getting V4L device for %s: %s: %s", udis[i], error.name, error.message);
- dbus_error_free (&error);
- continue;
- }
-
- /* vbi devices support capture capability too, but cannot be used,
- * so detect them by device name */
- if (strstr (device_path, "vbi"))
- {
- g_print ("Skipping vbi device: %s\n", device_path);
- libhal_free_string (device_path);
- continue;
- }
-
- if ((fd = open (device_path, O_RDONLY | O_NONBLOCK)) < 0)
- {
- g_warning ("Failed to open %s: %s", device_path, strerror (errno));
- libhal_free_string (device_path);
- continue;
- }
- ok = ioctl (fd, VIDIOC_QUERYCAP, &v2cap);
- if (ok < 0)
- {
- ok = ioctl (fd, VIDIOCGCAP, &v1cap);
- if (ok < 0)
- {
- g_warning ("Error while probing v4l capabilities for %s: %s",
- device_path, strerror (errno));
- libhal_free_string (device_path);
- close (fd);
- continue;
- }
- g_print ("Detected v4l device: %s\n", v1cap.name);
- g_print ("Device type: %d\n", v1cap.type);
- gstreamer_src = "v4lsrc";
- product_name = v1cap.name;
- }
- else
- {
- guint cap = v2cap.capabilities;
- g_print ("Detected v4l2 device: %s\n", v2cap.card);
- g_print ("Driver: %s, version: %d\n", v2cap.driver, v2cap.version);
-
- /* g_print ("Bus info: %s\n", v2cap.bus_info); */ /* Doesn't seem anything useful */
- g_print ("Capabilities: 0x%08X\n", v2cap.capabilities);
- if (!(cap & V4L2_CAP_VIDEO_CAPTURE))
- {
- g_print ("Device %s seems to not have the capture capability, (radio tuner?)\n"
- "Removing it from device list.\n", device_path);
- libhal_free_string (device_path);
- close (fd);
- continue;
- }
- gstreamer_src = "v4l2src";
- product_name = (char *) v2cap.card;
- }
-
- g_print ("\n");
-
- device = g_new0 (CheeseCameraDevice, 1);
-
- device->hal_udi = g_strdup (udis[i]);
- device->video_device = g_strdup (device_path);
- device->gstreamer_src = g_strdup (gstreamer_src);
- device->product_name = g_strdup (product_name);
- device->num_video_formats = 0;
- device->video_formats = g_array_new (FALSE, FALSE, sizeof (CheeseVideoFormat));
- device->supported_resolutions =
- g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
- //FIXME This will leak a device, we should ref/unref it instead
- g_signal_emit (monitor, monitor_signals[ADDED], 0, device);
- libhal_free_string (device_path);
- close (fd);
- }
+ cheese_camera_device_monitor_handle_udi (monitor, hal_ctx, udis[i]);
libhal_free_string_array (udis);
}
@@ -294,3 +303,6 @@ cheese_camera_device_monitor_new (void)
return g_object_new (CHEESE_TYPE_CAMERA_DEVICE_MONITOR, NULL);
}
+/*
+ * vim: sw=2 ts=8 cindent noai bs=2
+ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]