]> git.sesse.net Git - vlc/blobdiff - modules/services_discovery/udev.c
We need to free the model name.
[vlc] / modules / services_discovery / udev.c
index 93861efaff1bf5a910e3da38368c3285dfe4d5dd..b7b7c7f078f4985756e1db982443a911edbd5906 100644 (file)
@@ -28,6 +28,7 @@
 #include <vlc_common.h>
 #include <vlc_services_discovery.h>
 #include <vlc_plugin.h>
+#include <vlc_url.h>
 #include <search.h>
 #include <poll.h>
 #include <errno.h>
@@ -88,7 +89,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 +436,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 +473,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 +523,7 @@ int OpenALSA (vlc_object_t *obj)
 
     return Open (obj, &subsys);
 }
+#endif /* HAVE_ALSA */
 
 
 /*** Discs support ***/
@@ -523,19 +536,18 @@ static char *disc_get_mrl (struct udev_device *dev)
         return NULL; /* Ignore non-optical block devices */
 
     val = udev_device_get_property_value (dev, "ID_CDROM_MEDIA_STATE");
-    if ((val == NULL) || !strcmp (val, "blank"))
+    if (val && !strcmp (val, "blank"))
         return NULL; /* ignore empty drives and virgin recordable discs */
 
-    const char *scheme = "file";
+    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 */
-#if 0 /* we can use file:// for DVDs */
     val = udev_device_get_property_value (dev, "ID_CDROM_MEDIA_DVD");
     if (val && atoi (val))
         scheme = "dvd";
-#endif
+
     val = udev_device_get_property_value (dev, "ID_CDROM_MEDIA_BD");
     if (val && atoi (val))
         scheme = "bd";
@@ -545,12 +557,13 @@ static char *disc_get_mrl (struct udev_device *dev)
         scheme = "hddvd";
 #endif
 
-    val = udev_device_get_devnode (dev);
-    char *mrl;
+    /* We didn't get any property that could tell we have optical disc
+       that we can play */
+    if (scheme == NULL)
+        return NULL;
 
-    if (asprintf (&mrl, "%s://%s", scheme, val) == -1)
-        mrl = NULL;
-    return mrl;
+    val = udev_device_get_devnode (dev);
+    return make_URI (val, scheme);
 }
 
 static char *disc_get_name (struct udev_device *dev)
@@ -560,32 +573,39 @@ static char *disc_get_name (struct udev_device *dev)
 
 static char *disc_get_cat (struct udev_device *dev)
 {
-    const char *val;
-    const char *name;
-    int i_val;
-    const char *cat = _("Unknown Type");
+    struct udev_list_entry *list, *entry;
 
-    struct udev_list_entry *prop_list
-        = udev_device_get_properties_list_entry( dev );
+    list = udev_device_get_properties_list_entry (dev);
+    if (unlikely(list == NULL))
+        return NULL;
 
-    udev_list_entry_foreach( prop_list, prop_list )
+    const char *cat = NULL;
+    udev_list_entry_foreach (entry, list)
     {
-        name = udev_list_entry_get_name ( prop_list );
-        i_val = atoi( udev_list_entry_get_value ( prop_list ) );
-        if( !i_val ) continue;
-        if( strncmp( name, "ID_CDROM_MEDIA_CD", strlen( "ID_CDROM_MEDIA_CD" ) ) )
-            cat = _("CD");
-        else if( !strncmp( name, "ID_CDROM_MEDIA_DVD", strlen( "ID_CDROM_MEDIA_DVD" ) ) )
-            cat = _("DVD");
-        else if( !strncmp( name, "ID_CDROM_MEDIA_BD", strlen( "ID_CDROM_MEDIA_BD" ) ) )
-            cat = _("Blu-Ray");
-        else if( !strncmp( name, "ID_CDROM_MEDIA_HDDVD", strlen( "ID_CDROM_MEDIA_HDDVD" ) ) )
-            cat = _("HD DVD");
-    }
+        const char *name = udev_list_entry_get_name (entry);
 
-    free( prop_list );
+        if (strncmp (name, "ID_CDROM_MEDIA_", 15))
+            continue;
+        if (!atoi (udev_list_entry_get_value (entry)))
+            continue;
+        name += 15;
+
+        if (!strncmp (name, "CD", 2))
+            cat = N_("CD");
+        else if (!strncmp (name, "DVD", 3))
+            cat = N_("DVD");
+        else if (!strncmp (name, "BD", 2))
+            cat = N_("Blu-Ray");
+        else if (!strncmp (name, "HDDVD", 5))
+            cat = N_("HD DVD");
+
+        if (cat != NULL)
+            break;
+    }
 
-    return strdup (cat);
+    if (cat == NULL)
+        cat = N_("Unknown type");
+    return strdup (vlc_gettext (cat));
 }
 
 int OpenDisc (vlc_object_t *obj)