[cheese/wip/albfan/device-from-path: 15/15] Allow device parameter to understand api.v4l2.path




commit 281ef84654f2aa9a8fb053d22c01fad084fc0c71
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Thu Sep 10 12:19:43 2020 +0200

    Allow device parameter to understand api.v4l2.path

 libcheese/cheese-camera-device.c | 43 ++++++++++++++++++++++++++++++++++++++++
 libcheese/cheese-camera-device.h |  1 +
 libcheese/cheese-camera.c        |  5 ++++-
 src/vapi/cheese-common.vapi      |  5 ++++-
 4 files changed, 52 insertions(+), 2 deletions(-)
---
diff --git a/libcheese/cheese-camera-device.c b/libcheese/cheese-camera-device.c
index 6d91bd9e..f11dd828 100644
--- a/libcheese/cheese-camera-device.c
+++ b/libcheese/cheese-camera-device.c
@@ -87,6 +87,7 @@ enum
 {
   PROP_0,
   PROP_NAME,
+  PROP_PATH,
   PROP_DEVICE,
   PROP_LAST
 };
@@ -99,6 +100,7 @@ typedef struct
   gchar     *name;
   GstCaps   *caps;
   GList     *formats; /* list members are CheeseVideoFormatFull structs. */
+  gchar     *path;
 
   GError    *construct_error;
 } CheeseCameraDevicePrivate;
@@ -602,6 +604,9 @@ cheese_camera_device_get_property (GObject *object, guint prop_id, GValue *value
     case PROP_DEVICE:
       g_value_set_object (value, priv->device);
       break;
+    case PROP_PATH:
+      g_value_set_string (value, priv->path);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -626,6 +631,12 @@ cheese_camera_device_set_property (GObject *object, guint prop_id, const GValue
       priv->device = g_value_dup_object (value);
       g_free (priv->name);
       priv->name = gst_device_get_display_name (priv->device);
+      g_free (priv->path);
+      priv->path = g_value_dup_string (gst_structure_get_value (gst_device_get_properties (priv->device), 
"api.v4l2.path"));
+      break;
+    case PROP_PATH:
+      g_free (priv->path);
+      priv->path = g_value_dup_string (value);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -641,6 +652,7 @@ cheese_camera_device_finalize (GObject *object)
 
   g_object_unref (priv->device);
   g_free (priv->name);
+  g_free (priv->path);
 
   gst_caps_unref (priv->caps);
   free_format_list (device);
@@ -678,6 +690,18 @@ cheese_camera_device_class_init (CheeseCameraDeviceClass *klass)
                                                G_PARAM_CONSTRUCT_ONLY |
                                                G_PARAM_STATIC_STRINGS);
 
+  /**
+   * CheeseCameraDevice:path:
+   *
+   * Path of the video capture device.
+   */
+  properties[PROP_PATH] = g_param_spec_string ("path",
+                                               "Device path",
+                                               "Path of the video capture device",
+                                               NULL,
+                                               G_PARAM_READWRITE |
+                                               G_PARAM_CONSTRUCT_ONLY |
+                                               G_PARAM_STATIC_STRINGS);
   /**
    * CheeseCameraDevice:device:
    *
@@ -781,6 +805,25 @@ cheese_camera_device_get_format_list (CheeseCameraDevice *device)
     return g_list_copy (priv->formats);
 }
 
+/**
+ * cheese_camera_device_get_path:
+ * @device: a #CheeseCameraDevice
+ *
+ * Get path for the device, as reported by udev.
+ *
+ * Returns: (transfer none): the path of the video capture device
+ */
+const gchar *
+cheese_camera_device_get_path (CheeseCameraDevice *device)
+{
+  CheeseCameraDevicePrivate *priv;
+
+  g_return_val_if_fail (CHEESE_IS_CAMERA_DEVICE (device), NULL);
+
+  priv = cheese_camera_device_get_instance_private (device);
+
+  return priv->path;
+}
 /**
  * cheese_camera_device_get_name:
  * @device: a #CheeseCameraDevice
diff --git a/libcheese/cheese-camera-device.h b/libcheese/cheese-camera-device.h
index 5e6b3ca5..860757d7 100644
--- a/libcheese/cheese-camera-device.h
+++ b/libcheese/cheese-camera-device.h
@@ -73,6 +73,7 @@ CheeseVideoFormat *cheese_camera_device_get_best_format (CheeseCameraDevice *dev
 GList *            cheese_camera_device_get_format_list (CheeseCameraDevice *device);
 
 const gchar *cheese_camera_device_get_name (CheeseCameraDevice *device);
+const gchar *cheese_camera_device_get_path (CheeseCameraDevice *device);
 GstElement * cheese_camera_device_get_src (CheeseCameraDevice *device);
 
 GstCaps * cheese_camera_device_supported_format_caps (void);
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index c6cb44a2..6ccdbeaf 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -1595,7 +1595,10 @@ cheese_camera_setup (CheeseCamera *camera, CheeseCameraDevice *device, GError **
       device = g_ptr_array_index (priv->camera_devices, i);
 
       if (g_strcmp0 (cheese_camera_device_get_name (device),
-                     priv->initial_name) == 0)
+                     priv->initial_name) == 0
+          || g_strcmp0 (cheese_camera_device_get_path (device),
+                     priv->initial_name) == 0
+         )
       {
         cheese_camera_set_device (camera, device);
         break;
diff --git a/src/vapi/cheese-common.vapi b/src/vapi/cheese-common.vapi
index 2ee13f18..0c3a5607 100644
--- a/src/vapi/cheese-common.vapi
+++ b/src/vapi/cheese-common.vapi
@@ -78,11 +78,14 @@ namespace Cheese
     public Gst.Caps get_caps_for_format (Cheese.VideoFormat format);
     public GLib.List<unowned Cheese.VideoFormat> get_format_list ();
     public unowned string             get_name ();
+    public unowned string             get_path ();
     public Gst.Element                get_src ();
     [NoAccessorMethod]
-    public Gst.Device device {get; construct;}
+    public Gst.Device device {owned get; construct;}
     [NoAccessorMethod]
     public string name {get;}
+    [NoAccessorMethod]
+    public string path {get;}
   }
 
   [CCode (cheader_filename = "cheese-camera-device-monitor.h")]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]