[vlc-commits] commit: udev: use ALSA to find capture device names ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Sat Jul 17 19:30:09 CEST 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Jul 17 20:25:35 2010 +0300| [0c6062ece8e73986a031a22c440f2b2b5f5a9a12] | committer: Rémi Denis-Courmont 

udev: use ALSA to find capture device names

This is a little bit more understandable than device numbers.
Unfortunately, hot plug is as flaky as before: udev reports the device
before it is ready. alsa-lib provides no event interface (that I know),
so we have to stick with udev for now though.

Also, alsa-lib is _not_ used to fetch the card name. In my opinion, the
udev vendor string is a lot better. Compare:
- "USB Device 0xccd:0x77" (alsa card name) with
  "TerraTec Electronic GmbH" (udev vendor), or
- "Intel ICH6" (alsa card name) with "Intel Corporation" (udev vendor).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0c6062ece8e73986a031a22c440f2b2b5f5a9a12
---

 modules/services_discovery/Modules.am |   12 ++++++++++-
 modules/services_discovery/udev.c     |   34 ++++++++++++++++++++++----------
 2 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/modules/services_discovery/Modules.am b/modules/services_discovery/Modules.am
index bb60329..a14c60a 100644
--- a/modules/services_discovery/Modules.am
+++ b/modules/services_discovery/Modules.am
@@ -5,7 +5,15 @@ SOURCES_bonjour = bonjour.c
 SOURCES_podcast = podcast.c
 SOURCES_mtp = mtp.c
 SOURCES_mediadirs = mediadirs.c
-SOURCES_udev = udev.c
+
+libudev_plugin_la_SOURCES = udev.c
+libudev_plugin_la_CFLAGS = $(AM_CFLAGS) $(UDEV_CFLAGS)
+libudev_plugin_la_LIBADD = $(AM_LIBADD) $(UDEV_LIBS)
+libudev_plugin_la_DEPENDENCIES =
+if HAVE_ALSA
+libudev_plugin_la_CFLAGS += $(ALSA_CFLAGS) -DHAVE_ALSA
+libudev_plugin_la_LIBADD += $(ALSA_LIBS)
+endif
 
 libxcb_apps_plugin_la_SOURCES = xcb_apps.c
 libxcb_apps_plugin_la_CFLAGS = $(AM_CFLAGS) \
@@ -15,9 +23,11 @@ libxcb_apps_plugin_la_LIBADD = $(AM_LIBADD) \
 libxcb_apps_plugin_la_DEPENDENCIES =
 
 EXTRA_LTLIBRARIES += \
+	libudev_plugin.la \
 	libxcb_apps_plugin.la
 libvlc_LTLIBRARIES += \
 	libmediadirs_plugin.la \
 	libpodcast_plugin.la \
 	libsap_plugin.la \
+	$(LTLIBudev) \
 	$(LTLIBxcb_apps)
diff --git a/modules/services_discovery/udev.c b/modules/services_discovery/udev.c
index ea677d6..e39f43a 100644
--- a/modules/services_discovery/udev.c
+++ b/modules/services_discovery/udev.c
@@ -435,7 +435,10 @@ int OpenV4L (vlc_object_t *obj)
 }
 
 
+#ifdef HAVE_ALSA
 /*** Advanced Linux Sound Architecture support ***/
+#include <alsa/asoundlib.h>
+
 static int alsa_get_device (struct udev_device *dev, unsigned *restrict pcard,
                             unsigned *restrict pdevice)
 {
@@ -469,22 +472,30 @@ static char *alsa_get_mrl (struct udev_device *dev)
 
 static char *alsa_get_name (struct udev_device *dev)
 {
-    const char *model = NULL;
-    char *name;
+    char *name = NULL;
     unsigned card, device;
 
     if (alsa_get_device (dev, &card, &device))
         return NULL;
 
-    dev = udev_device_get_parent (dev);
-    if (dev != NULL)
-        model = udev_device_get_property_value (dev,
-                                                "ID_MODEL_FROM_DATABASE");
-    if (model == NULL)
-        model = _("Device");
-
-    if (asprintf (&name, "%s (%u)", model, device) == -1)
-        name = NULL;
+    char card_name[4 + 3 * sizeof (int)];
+    snprintf (card_name, sizeof (card_name), "hw:%u", card);
+
+    snd_ctl_t *ctl;
+    if (snd_ctl_open (&ctl, card_name, 0))
+        return NULL;
+
+    snd_pcm_info_t *pcm_info;
+    snd_pcm_info_alloca (&pcm_info);
+    snd_pcm_info_set_device (pcm_info, device);
+    snd_pcm_info_set_subdevice (pcm_info, 0);
+    snd_pcm_info_set_stream (pcm_info, SND_PCM_STREAM_CAPTURE);
+    if (snd_ctl_pcm_info (ctl, pcm_info))
+        goto out;
+
+    name = strdup (snd_pcm_info_get_name (pcm_info));
+out:
+    snd_ctl_close (ctl);
     return name;
 }
 
@@ -511,6 +522,7 @@ int OpenALSA (vlc_object_t *obj)
 
     return Open (obj, &subsys);
 }
+#endif /* HAVE_ALSA */
 
 
 /*** Discs support ***/



More information about the vlc-commits mailing list