From cafbe3a363e5e843fbacad5af0ebbb48254f5a3f Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Fri, 16 Oct 2009 22:09:06 +0300 Subject: [PATCH] udev: partial support for optical discs It should work with CDDA, DVD and Blu-rays, but I only tested DVD. FIXME: This does not detect media change (eject/insert) properly yet. --- modules/services_discovery/udev.c | 87 ++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/modules/services_discovery/udev.c b/modules/services_discovery/udev.c index b23c363c3f..9215008277 100644 --- a/modules/services_discovery/udev.c +++ b/modules/services_discovery/udev.c @@ -32,6 +32,7 @@ #include static int OpenV4L (vlc_object_t *); +static int OpenDisc (vlc_object_t *); static void Close (vlc_object_t *); /* @@ -44,8 +45,17 @@ vlc_module_begin () set_subcategory (SUBCAT_PLAYLIST_SD) set_capability ("services_discovery", 0) set_callbacks (OpenV4L, Close) + add_shortcut ("v4l") + + add_submodule () + set_shortname (N_("Discs")) + set_description (N_("Discs")) + set_category (CAT_PLAYLIST) + set_subcategory (SUBCAT_PLAYLIST_SD) + set_capability ("services_discovery", 0) + set_callbacks (OpenDisc, Close) + add_shortcut ("disc") - add_shortcut ("udev") vlc_module_end () struct subsys @@ -335,3 +345,78 @@ int OpenV4L (vlc_object_t *obj) return Open (obj, &subsys); } + +/*** Discs support ***/ +static char *disc_get_mrl (struct udev_device *dev) +{ + const char *val; + + val = udev_device_get_property_value (dev, "ID_CDROM"); + if (val == NULL) + return NULL; /* Ignore non-optical block devices */ + + val = udev_device_get_property_value (dev, "ID_CDROM_MEDIA_STATE"); + if ((val == NULL) || !strcmp (val, "blank")) + return NULL; /* ignore empty drives and virgin recordable discs */ + + const char *scheme = "file"; + 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"; +#ifdef LOL + val = udev_device_get_property_value (dev, "ID_CDROM_MEDIA_HDDVD"); + if (val && atoi (val)) + scheme = "hddvd"; +#endif + + val = udev_device_get_devnode (dev); + char *mrl; + + if (asprintf (&mrl, "%s://%s", scheme, val) == -1) + mrl = NULL; + return mrl; +} + +static char *disc_get_name (struct udev_device *dev) +{ + return decode_property (dev, "ID_FS_LABEL_ENC"); +} + +static char *disc_get_cat (struct udev_device *dev) +{ + const char *val; + const char *cat = "Unknown"; + + val = udev_device_get_property_value (dev, "ID_CDROM_MEDIA_CD"); + if (val && atoi (val)) + cat = "CD"; + val = udev_device_get_property_value (dev, "ID_CDROM_MEDIA_DVD"); + if (val && atoi (val)) + cat = "DVD"; + val = udev_device_get_property_value (dev, "ID_CDROM_MEDIA_BD"); + if (val && atoi (val)) + cat = "Blue-ray disc"; + val = udev_device_get_property_value (dev, "ID_CDROM_MEDIA_HDDVD"); + if (val && atoi (val)) + cat = "HD DVD"; + + return strdup (cat); +} + +int OpenDisc (vlc_object_t *obj) +{ + static const struct subsys subsys = { + "block", disc_get_mrl, disc_get_name, disc_get_cat, + }; + + return Open (obj, &subsys); +} -- 2.39.5