]> git.sesse.net Git - vlc/blobdiff - modules/services_discovery/udev.c
udev: minor simplification
[vlc] / modules / services_discovery / udev.c
index 0c64b5f68216c9dcc42874012a498c743c9c235d..95b6b1a8288cce931af8cdb04218600bbcea9d2d 100644 (file)
@@ -88,7 +88,7 @@ static int vlc_sd_probe_Open (vlc_object_t *obj)
         vlc_sd_probe_Add (probe, "alsa{longname=\"Audio capture\"}",
                           N_("Audio capture"), SD_CAT_DEVICES);
         vlc_sd_probe_Add (probe, "disc{longname=\"Discs\"}", N_("Discs"),
-                          SD_CAT_MYCOMPUTER);
+                          SD_CAT_DEVICES);
         udev_monitor_unref (mon);
     }
     udev_unref (udev);
@@ -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 ***/
@@ -526,14 +538,14 @@ static char *disc_get_mrl (struct udev_device *dev)
     if (val && !strcmp (val, "blank"))
         return NULL; /* ignore empty drives and virgin recordable discs */
 
-    const char *scheme = "invalid";
+    const char *scheme = NULL;
     val = udev_device_get_property_value (dev,
                                           "ID_CDROM_MEDIA_TRACK_COUNT_AUDIO");
     if (val && atoi (val))
         scheme = "cdda"; /* Audio CD rather than file system */
     val = udev_device_get_property_value (dev, "ID_CDROM_MEDIA_DVD");
     if (val && atoi (val))
-        scheme = "file";
+        scheme = "dvd";
 
     val = udev_device_get_property_value (dev, "ID_CDROM_MEDIA_BD");
     if (val && atoi (val))
@@ -546,7 +558,7 @@ static char *disc_get_mrl (struct udev_device *dev)
 
     /* We didn't get any property that could tell we have optical disc
        that we can play */
-    if( !strcmp( scheme, "invalid" ) )
+    if (scheme == NULL)
         return NULL;
 
     val = udev_device_get_devnode (dev);