[cheese/wip/albfan/device-from-path] Allow device parameter to understand api.v4l2.path
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cheese/wip/albfan/device-from-path] Allow device parameter to understand api.v4l2.path
- Date: Thu, 10 Sep 2020 10:21:00 +0000 (UTC)
commit 104c8d0ce5b21546b0f70aad3f9a72b22c4f458e
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 | 41 ++++++++++++++++++++++++++++++++++++++++
libcheese/cheese-camera-device.h | 1 +
libcheese/cheese-camera.c | 5 ++++-
src/vapi/cheese-common.vapi | 5 ++++-
4 files changed, 50 insertions(+), 2 deletions(-)
---
diff --git a/libcheese/cheese-camera-device.c b/libcheese/cheese-camera-device.c
index 08a0a26a..a5408436 100644
--- a/libcheese/cheese-camera-device.c
+++ b/libcheese/cheese-camera-device.c
@@ -86,6 +86,7 @@ enum
{
PROP_0,
PROP_NAME,
+ PROP_PATH,
PROP_DEVICE,
PROP_LAST
};
@@ -98,6 +99,7 @@ typedef struct
gchar *name;
GstCaps *caps;
GList *formats; /* list members are CheeseVideoFormatFull structs. */
+ gchar *path;
GError *construct_error;
} CheeseCameraDevicePrivate;
@@ -590,6 +592,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;
@@ -614,6 +619,11 @@ 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);
+ 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);
@@ -666,6 +676,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:
*
@@ -769,6 +791,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 4f5d819f..1790f9fa 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);
G_END_DECLS
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index 7aa38066..5214a697 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -1560,7 +1560,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]