summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2015-07-27 15:53:26 +0200
committerWim Taymans <wtaymans@redhat.com>2015-09-30 10:18:09 +0200
commitd46b253d2112cba43fc11c9e40b637293e306883 (patch)
tree966adb78cc34a946c0d29e30ea37ad456cb17874
parent81a76853cff3a9a30a08a5cc02149dc24f157eee (diff)
v4l2deviceprovider: add properties to the devicev4l2-props
Add properties to the device with exactly the same keys and sematics as what pulseaudio uses as property keys.
-rw-r--r--sys/v4l2/gstv4l2deviceprovider.c109
1 files changed, 97 insertions, 12 deletions
diff --git a/sys/v4l2/gstv4l2deviceprovider.c b/sys/v4l2/gstv4l2deviceprovider.c
index 8e366d478..189e57835 100644
--- a/sys/v4l2/gstv4l2deviceprovider.c
+++ b/sys/v4l2/gstv4l2deviceprovider.c
@@ -39,7 +39,8 @@
#endif
static GstV4l2Device *gst_v4l2_device_new (const gchar * device_path,
- const gchar * device_name, GstCaps * caps, GstV4l2DeviceType type);
+ const gchar * device_name, GstCaps * caps, GstV4l2DeviceType type,
+ GstStructure * props);
G_DEFINE_TYPE (GstV4l2DeviceProvider, gst_v4l2_device_provider,
@@ -97,13 +98,14 @@ gst_v4l2_device_provider_finalize (GObject * object)
static GstV4l2Device *
gst_v4l2_device_provider_probe_device (GstV4l2DeviceProvider * provider,
- const gchar * device_path, const gchar * device_name)
+ const gchar * device_path, const gchar * device_name, GstStructure * props)
{
GstV4l2Object *v4l2obj;
GstCaps *caps;
GstV4l2Device *device = NULL;
struct stat st;
GstV4l2DeviceType type = GST_V4L2_DEVICE_TYPE_INVALID;
+ gchar *str;
if (stat (device_path, &st) == -1)
return NULL;
@@ -114,9 +116,32 @@ gst_v4l2_device_provider_probe_device (GstV4l2DeviceProvider * provider,
v4l2obj = gst_v4l2_object_new ((GstElement *) provider,
V4L2_BUF_TYPE_VIDEO_CAPTURE, device_path, NULL, NULL, NULL);
+ if (props == NULL)
+ props = gst_structure_new_empty ("v4l2deviceprovider");
+
if (!gst_v4l2_open (v4l2obj))
goto destroy;
+ gst_structure_set (props, "device.api", G_TYPE_STRING, "v4l2", NULL);
+ gst_structure_set (props, "device.path", G_TYPE_STRING, device_path, NULL);
+
+ gst_structure_set (props, "v4l2.device.driver", G_TYPE_STRING,
+ v4l2obj->vcap.driver, NULL);
+ gst_structure_set (props, "v4l2.device.card", G_TYPE_STRING,
+ v4l2obj->vcap.card, NULL);
+ gst_structure_set (props, "v4l2.device.bus_info", G_TYPE_STRING,
+ v4l2obj->vcap.bus_info, NULL);
+ str = g_strdup_printf ("%u", v4l2obj->vcap.version);
+ gst_structure_set (props, "v4l2.device.version", G_TYPE_STRING, str, NULL);
+ g_free (str);
+ str = g_strdup_printf ("0x%08x", v4l2obj->vcap.capabilities);
+ gst_structure_set (props, "v4l2.device.capabilities", G_TYPE_STRING, str,
+ NULL);
+ g_free (str);
+ str = g_strdup_printf ("0x%08x", v4l2obj->vcap.device_caps);
+ gst_structure_set (props, "v4l2.device.device_caps", G_TYPE_STRING, str,
+ NULL);
+ g_free (str);
if (v4l2obj->vcap.capabilities & V4L2_CAP_VIDEO_CAPTURE)
type = GST_V4L2_DEVICE_TYPE_SOURCE;
@@ -144,7 +169,8 @@ gst_v4l2_device_provider_probe_device (GstV4l2DeviceProvider * provider,
}
device = gst_v4l2_device_new (device_path,
- device_name ? device_name : (gchar *) v4l2obj->vcap.card, caps, type);
+ device_name ? device_name : (gchar *) v4l2obj->vcap.card, caps, type,
+ props);
gst_caps_unref (caps);
close:
@@ -155,6 +181,9 @@ destroy:
gst_v4l2_object_destroy (v4l2obj);
+ if (props)
+ gst_structure_free (props);
+
return device;
}
@@ -172,7 +201,8 @@ gst_v4l2_device_provider_probe (GstDeviceProvider * provider)
GstV4l2Device *device;
device =
- gst_v4l2_device_provider_probe_device (self, it->device_path, NULL);
+ gst_v4l2_device_provider_probe_device (self, it->device_path, NULL,
+ NULL);
if (device) {
gst_object_ref_sink (device);
@@ -193,16 +223,70 @@ gst_v4l2_device_provider_device_from_udev (GstV4l2DeviceProvider * provider,
{
GstV4l2Device *gstdev;
const gchar *device_path = g_udev_device_get_device_file (udev_device);
- const gchar *device_name;
+ const gchar *device_name, *str;
+ GstStructure *props;
+
+ props = gst_structure_new_empty ("v4l2deviceprovider");
+
+ str = g_udev_device_get_property (udev_device, "ID_PATH");
+ if (!(str && *str)) {
+ str = g_udev_device_get_sysfs_path (udev_device);
+ }
+ if (str && *str)
+ gst_structure_set (props, "device.bus_path", G_TYPE_STRING, str, NULL);
+
+ if ((str = g_udev_device_get_sysfs_path (udev_device)) && *str)
+ gst_structure_set (props, "sysfs.path", G_TYPE_STRING, str, NULL);
+
+ if ((str = g_udev_device_get_property (udev_device, "ID_ID")) && *str)
+ gst_structure_set (props, "udev.id", G_TYPE_STRING, str, NULL);
+
+ if ((str = g_udev_device_get_property (udev_device, "ID_BUS")) && *str)
+ gst_structure_set (props, "device.bus", G_TYPE_STRING, str, NULL);
+
+ if ((str = g_udev_device_get_property (udev_device, "SUBSYSTEM")) && *str)
+ gst_structure_set (props, "device.subsystem", G_TYPE_STRING, str, NULL);
+
+ if ((str = g_udev_device_get_property (udev_device, "ID_VENDOR_ID")) && *str)
+ gst_structure_set (props, "device.vendor.id", G_TYPE_STRING, str, NULL);
+
+ str = g_udev_device_get_property (udev_device, "ID_VENDOR_FROM_DATABASE");
+ if (!(str && *str)) {
+ str = g_udev_device_get_property (udev_device, "ID_VENDOR_ENC");
+ if (!(str && *str)) {
+ str = g_udev_device_get_property (udev_device, "ID_VENDOR");
+ }
+ }
+ if (str && *str)
+ gst_structure_set (props, "device.vendor.name", G_TYPE_STRING, str, NULL);
+
+ if ((str = g_udev_device_get_property (udev_device, "ID_MODEL_ID")) && *str)
+ gst_structure_set (props, "device.product.id", G_TYPE_STRING, str, NULL);
device_name = g_udev_device_get_property (udev_device, "ID_V4L_PRODUCT");
- if (!device_name)
- device_name = g_udev_device_get_property (udev_device, "ID_MODEL_ENC");
- if (!device_name)
- device_name = g_udev_device_get_property (udev_device, "ID_MODEL");
+ if (!(device_name && *device_name)) {
+ device_name =
+ g_udev_device_get_property (udev_device, "ID_MODEL_FROM_DATABASE");
+ if (!(device_name && *device_name)) {
+ device_name = g_udev_device_get_property (udev_device, "ID_MODEL_ENC");
+ if (!(device_name && *device_name)) {
+ device_name = g_udev_device_get_property (udev_device, "ID_MODEL");
+ }
+ }
+ }
+ if (device_name && *device_name)
+ gst_structure_set (props, "device.product.name", G_TYPE_STRING, device_name,
+ NULL);
+
+ if ((str = g_udev_device_get_property (udev_device, "ID_SERIAL")) && *str)
+ gst_structure_set (props, "device.serial", G_TYPE_STRING, str, NULL);
+
+ if ((str = g_udev_device_get_property (udev_device, "ID_V4L_CAPABILITIES"))
+ && *str)
+ gst_structure_set (props, "device.capabilities", G_TYPE_STRING, str, NULL);
gstdev = gst_v4l2_device_provider_probe_device (provider, device_path,
- device_name);
+ device_name, props);
if (gstdev)
gstdev->syspath = g_strdup (g_udev_device_get_sysfs_path (udev_device));
@@ -435,7 +519,7 @@ gst_v4l2_device_create_element (GstDevice * device, const gchar * name)
static GstV4l2Device *
gst_v4l2_device_new (const gchar * device_path, const gchar * device_name,
- GstCaps * caps, GstV4l2DeviceType type)
+ GstCaps * caps, GstV4l2DeviceType type, GstStructure * props)
{
GstV4l2Device *gstdev;
const gchar *element = NULL;
@@ -460,7 +544,8 @@ gst_v4l2_device_new (const gchar * device_path, const gchar * device_name,
}
gstdev = g_object_new (GST_TYPE_V4L2_DEVICE, "device-path", device_path,
- "display-name", device_name, "caps", caps, "device-class", klass, NULL);
+ "display-name", device_name, "caps", caps, "device-class", klass,
+ "properties", props, NULL);
gstdev->element = element;