[PATCH] add a video4linux capabilities probe

Guillem Jover guillem.jover at nokia.com
Wed Jun 13 12:06:13 PDT 2007


Probe the v4l device and add its capabilities, and the device name.
Document the video4linux namespace and the new capability namespaces
in the spec.
---
 doc/spec/hal-spec-properties.xml       |   96 +++++++++++++++++++++
 hald/linux/device.c                    |   17 ++++-
 hald/linux/probing/.gitignore          |    1 +
 hald/linux/probing/Makefile.am         |   18 ++++-
 hald/linux/probing/probe-video4linux.c |  143 ++++++++++++++++++++++++++++++++
 5 files changed, 271 insertions(+), 4 deletions(-)
 create mode 100644 hald/linux/probing/probe-video4linux.c

diff --git a/doc/spec/hal-spec-properties.xml b/doc/spec/hal-spec-properties.xml
index 730f826..cfd2146 100644
--- a/doc/spec/hal-spec-properties.xml
+++ b/doc/spec/hal-spec-properties.xml
@@ -6611,6 +6611,102 @@ org.freedesktop.Hal.Device.Volume.method_signatures = {'ssas', 'as', 'as'}
         </tgroup>
       </informaltable>
     </sect2>
+    <sect2 id="device-properties-video4linux">
+      <title>
+        video4linux namespace
+      </title>
+      <para>
+        Device objects with the capability <literal>video4linux</literal>
+        represent Video4Linux devices.
+      </para>
+      <informaltable>
+        <tgroup cols="2">
+          <thead>
+            <row>
+              <entry>Key (type)</entry>
+              <entry>Values</entry>
+              <entry>Mandatory</entry>
+              <entry>Description</entry>
+            </row>
+          </thead>
+          <tbody>
+            <row>
+              <entry>
+                <literal>video4linux.device</literal> (string)
+              </entry>
+              <entry>Example: /dev/video0</entry>
+              <entry>Yes</entry>
+              <entry>The device node to access the Video4Linux device.</entry>
+            </row>
+            <row>
+              <entry>
+                <literal>video4linux.version</literal> (string)
+              </entry>
+              <entry>Example: 2</entry>
+              <entry>Yes</entry>
+              <entry>
+                The highest Video4Linux API version supported by the device.
+              </entry>
+            </row>
+          </tbody>
+        </tgroup>
+      </informaltable>
+    </sect2>
+    <sect2 id="device-properties-video4linux-video-capture">
+      <title>
+        video4linux.video_capture namespace
+      </title>
+      <para>
+        The video4linux device can capture video.
+        No namespace specific properties.
+      </para>
+    </sect2>
+    <sect2 id="device-properties-video4linux-video-output">
+      <title>
+        video4linux.video_output namespace
+      </title>
+      <para>
+        The video4linux device can output video.
+        No namespace specific properties.
+      </para>
+    </sect2>
+    <sect2 id="device-properties-video4linux-video-overlay">
+      <title>
+        video4linux.video_overlay namespace
+      </title>
+      <para>
+        The video4linux device can overlay video.
+        No namespace specific properties.
+      </para>
+    </sect2>
+    <sect2 id="device-properties-video4linux-audio">
+      <title>
+        video4linux.audio namespace
+      </title>
+      <para>
+        The video4linux device has audio inputs or outputs.
+        No namespace specific properties.
+      </para>
+    </sect2>
+    <sect2 id="device-properties-video4linux-tuner">
+      <title>
+        video4linux.tuner namespace
+      </title>
+      <para>
+        The video4linux device has some sort of tuner or modulator to receive
+        or emit RF-modulated video signals.
+        No namespace specific properties.
+      </para>
+    </sect2>
+    <sect2 id="device-properties-video4linux-radio">
+      <title>
+        video4linux.radio namespace
+      </title>
+      <para>
+        The video4linux device is a radio device.
+        No namespace specific properties.
+      </para>
+    </sect2>
   </sect1>
 
   <sect1 id="properties-misc">
diff --git a/hald/linux/device.c b/hald/linux/device.c
index a5240b6..15f15f2 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -896,13 +896,26 @@ video4linux_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *p
 	hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev));
 	hal_device_property_set_string (d, "info.category", "video4linux");
 	hal_device_add_capability (d, "video4linux");
-	hal_device_property_set_string (d, "info.product", "Video Device");
+	hal_device_property_set_string (d, "info.product", "Multimedia Device");
 	hal_device_property_set_string (d, "video4linux.device", device_file);
 
 out:
 	return d;
 }
 
+static const gchar *
+video4linux_get_prober (HalDevice *d)
+{
+	const char *prober = NULL;
+
+	/* run prober only for video4linux devices */
+	if (hal_device_has_capability (d, "video4linux")) {
+		prober = "hald-probe-video4linux";
+	}
+
+	return prober;
+}
+
 static gboolean
 video4linux_compute_udi (HalDevice *d)
 {
@@ -3053,7 +3066,7 @@ static DevHandler dev_handler_video4linux =
 { 
 	.subsystem    = "video4linux",
 	.add          = video4linux_add,
-	.get_prober   = NULL,
+	.get_prober   = video4linux_get_prober,
 	.post_probing = NULL,
 	.compute_udi  = video4linux_compute_udi,
 	.remove       = dev_remove
diff --git a/hald/linux/probing/.gitignore b/hald/linux/probing/.gitignore
index 40d62d6..d537ee3 100644
--- a/hald/linux/probing/.gitignore
+++ b/hald/linux/probing/.gitignore
@@ -14,5 +14,6 @@ hald-probe-storage
 hald-probe-volume
 hald-probe-serial
 hald-probe-ieee1394-unit
+hald-probe-video4linux
 *.o
 *~
diff --git a/hald/linux/probing/Makefile.am b/hald/linux/probing/Makefile.am
index 9b2f1bd..62e8b64 100644
--- a/hald/linux/probing/Makefile.am
+++ b/hald/linux/probing/Makefile.am
@@ -9,8 +9,18 @@ AM_CPPFLAGS = \
 	@GLIB_CFLAGS@ @DBUS_CFLAGS@ @VOLUME_ID_CFLAGS@
 
 if HALD_COMPILE_LINUX
-libexec_PROGRAMS = hald-probe-input hald-probe-hiddev hald-probe-storage hald-probe-volume hald-probe-printer \
-	           hald-probe-pc-floppy hald-probe-smbios hald-probe-serial hald-probe-ieee1394-unit hald-probe-net-bluetooth
+libexec_PROGRAMS = \
+	hald-probe-input \
+	hald-probe-hiddev \
+	hald-probe-storage \
+	hald-probe-volume \
+	hald-probe-printer \
+	hald-probe-pc-floppy \
+	hald-probe-smbios \
+	hald-probe-serial \
+	hald-probe-ieee1394-unit \
+	hald-probe-net-bluetooth \
+	hald-probe-video4linux
 endif
 
 hald_probe_smbios_SOURCES = probe-smbios.c ../../logger.c
@@ -42,3 +52,7 @@ hald_probe_ieee1394_unit_LDADD = $(top_builddir)/libhal/libhal.la
 
 hald_probe_net_bluetooth_SOURCES = probe-net-bluetooth.c ../../logger.c
 hald_probe_net_bluetooth_LDADD = $(top_builddir)/libhal/libhal.la
+
+hald_probe_video4linux_SOURCES = probe-video4linux.c ../../logger.c
+hald_probe_video4linux_LDADD = $(top_builddir)/libhal/libhal.la
+
diff --git a/hald/linux/probing/probe-video4linux.c b/hald/linux/probing/probe-video4linux.c
new file mode 100644
index 0000000..fec1a33
--- /dev/null
+++ b/hald/linux/probing/probe-video4linux.c
@@ -0,0 +1,143 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * probe-video4linux.c : Probe video4linux devices
+ *
+ * Copyright (C) 2007 Nokia Corporation
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <linux/videodev.h>
+#include <linux/videodev2.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "libhal/libhal.h"
+#include "../../logger.h"
+
+int
+main (int argc, char *argv[])
+{
+	int fd = -1;
+	int ret = -1;
+	char *udi;
+	char *device_file;
+	struct video_capability v1cap;
+	struct v4l2_capability v2cap;
+	LibHalContext *ctx = NULL;
+	LibHalChangeSet *cset;
+	DBusError error;
+
+	setup_logger ();
+
+	device_file = getenv ("HAL_PROP_VIDEO4LINUX_DEVICE");
+	if (device_file == NULL)
+		goto out;
+
+	udi = getenv ("UDI");
+	if (udi == NULL)
+		goto out;
+
+	dbus_error_init (&error);
+	ctx = libhal_ctx_init_direct (&error);
+	if (ctx == NULL)
+		goto out;
+
+	cset = libhal_device_new_changeset (udi);
+
+	HAL_DEBUG (("Doing probe-video4linux for %s (udi=%s)", device_file, udi));
+
+	fd = open (device_file, O_RDONLY);
+	if (fd < 0) {
+		HAL_ERROR (("Cannot open %s: %s", device_file, strerror (errno)));
+		goto out;
+	}
+
+	if (ioctl (fd, VIDIOC_QUERYCAP, &v2cap) == 0) {
+		libhal_changeset_set_property_string (cset,
+		                                      "video4linux.version", "2");
+
+		libhal_changeset_set_property_string (cset,
+		                                      "info.product", v2cap.card);
+
+		if ((v2cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) > 0)
+			libhal_device_add_capability (ctx, udi, "video4linux.video_capture", &error);
+		if ((v2cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) > 0)
+			libhal_device_add_capability (ctx, udi, "video4linux.video_output", &error);
+		if ((v2cap.capabilities & V4L2_CAP_VIDEO_OVERLAY) > 0)
+			libhal_device_add_capability (ctx, udi, "video4linux.video_overlay", &error);
+		if ((v2cap.capabilities & V4L2_CAP_AUDIO) > 0)
+			libhal_device_add_capability (ctx, udi, "video4linux.audio", &error);
+		if ((v2cap.capabilities & V4L2_CAP_TUNER) > 0)
+			libhal_device_add_capability (ctx, udi, "video4linux.tuner", &error);
+		if ((v2cap.capabilities & V4L2_CAP_RADIO) > 0)
+			libhal_device_add_capability (ctx, udi, "video4linux.radio", &error);
+	} else
+		HAL_DEBUG (("ioctl VIDIOC_QUERYCAP failed"));
+
+	if (ioctl (fd, VIDIOCGCAP, &v1cap) == 0) {
+		libhal_changeset_set_property_string (cset,
+		                                      "video4linux.version", "1");
+
+		libhal_changeset_set_property_string (cset,
+		                                      "info.product", v1cap.name);
+
+		if ((v1cap.type & VID_TYPE_CAPTURE) > 0)
+			libhal_device_add_capability (ctx, udi, "video4linux.video_capture", &error);
+		if ((v1cap.type & VID_TYPE_OVERLAY) > 0)
+			libhal_device_add_capability (ctx, udi, "video4linux.video_overlay", &error);
+		if (v1cap.audios > 0)
+			libhal_device_add_capability (ctx, udi, "video4linux.audio", &error);
+		if ((v1cap.type & VID_TYPE_TUNER) > 0)
+			libhal_device_add_capability (ctx, udi, "video4linux.tuner", &error);
+	} else
+		HAL_DEBUG (("ioctl VIDIOCGCAP failed"));
+
+	libhal_device_commit_changeset (ctx, cset, &error);
+	libhal_device_free_changeset (cset);
+
+	close (fd);
+
+	ret = 0;
+
+out:
+	if (fd >= 0)
+		close (fd);
+
+	if (ctx != NULL) {
+		dbus_error_init (&error);
+		libhal_ctx_shutdown (ctx, &error);
+		libhal_ctx_free (ctx);
+	}
+
+	return ret;
+}
+
-- 
1.5.2.1



More information about the hal mailing list