[vlc-devel] [PATCH] udev discovery: remove categories
Rafaël Carré
funman at videolan.org
Wed Feb 8 20:24:29 CET 2012
There will be so few video/audio/disc devices that they can all appear
under the same root.
Merge previous category name into the name of each entry
Vendor for audio/video, disc type (DVD,CD,BLURAY..) for disc
---
modules/services_discovery/udev.c | 77 +++++++++++++++++++-----------------
1 files changed, 41 insertions(+), 36 deletions(-)
diff --git a/modules/services_discovery/udev.c b/modules/services_discovery/udev.c
index 56b42e2..052ffa4 100644
--- a/modules/services_discovery/udev.c
+++ b/modules/services_discovery/udev.c
@@ -114,7 +114,6 @@ struct subsys
const char *name;
char * (*get_mrl) (struct udev_device *dev);
char * (*get_name) (struct udev_device *dev);
- char * (*get_cat) (struct udev_device *dev);
int item_type;
};
@@ -193,10 +192,8 @@ static int AddDevice (services_discovery_t *sd, struct udev_device *dev)
*dp = d;
}
- name = p_sys->subsys->get_cat (dev);
- services_discovery_AddItem (sd, item, name ? name : "Generic");
+ services_discovery_AddItem (sd, item, NULL);
d->sd = sd;
- free (name);
return 0;
}
@@ -430,19 +427,21 @@ static char *v4l_get_mrl (struct udev_device *dev)
static char *v4l_get_name (struct udev_device *dev)
{
+ char *ven = decode_property (dev, "ID_VENDOR_ENC");
const char *prd = udev_device_get_property_value (dev, "ID_V4L_PRODUCT");
- return prd ? strdup (prd) : NULL;
-}
-static char *v4l_get_cat (struct udev_device *dev)
-{
- return decode_property (dev, "ID_VENDOR_ENC");
+ char *name = NULL;
+ if (asprintf(&name, "%s - %s", ven ? ven : "?", prd ? prd : "?") < 0)
+ name = NULL;
+
+ free(ven);
+ return name;
}
int OpenV4L (vlc_object_t *obj)
{
static const struct subsys subsys = {
- "video4linux", v4l_get_mrl, v4l_get_name, v4l_get_cat, ITEM_TYPE_CARD,
+ "video4linux", v4l_get_mrl, v4l_get_name, ITEM_TYPE_CARD,
};
return Open (obj, &subsys);
@@ -484,9 +483,24 @@ static char *alsa_get_mrl (struct udev_device *dev)
return mrl;
}
+static const char *alsa_get_vendor (struct udev_device *dev)
+{
+ const char *vnd;
+
+ dev = udev_device_get_parent (dev);
+ if (dev == NULL)
+ return NULL;
+
+ vnd = udev_device_get_property_value (dev, "ID_VENDOR_FROM_DATABASE");
+ if (vnd == NULL)
+ /* FIXME: USB may take time to settle... the parent device */
+ vnd = udev_device_get_property_value (dev, "ID_BUS");
+ return vnd;
+}
+
static char *alsa_get_name (struct udev_device *dev)
{
- char *name = NULL;
+ char *fullname = NULL;
unsigned card, device;
if (alsa_get_device (dev, &card, &device))
@@ -507,31 +521,20 @@ static char *alsa_get_name (struct udev_device *dev)
if (snd_ctl_pcm_info (ctl, pcm_info))
goto out;
- name = strdup (snd_pcm_info_get_name (pcm_info));
+ const char *name = snd_pcm_info_get_name (pcm_info);
+ const char *ven = alsa_get_vendor(dev);
+ if (asprintf(&fullname, "%s - %s", ven ? ven : "?", name ? name : "?") < 0)
+ fullname = NULL;
+
out:
snd_ctl_close (ctl);
- return name;
-}
-
-static char *alsa_get_cat (struct udev_device *dev)
-{
- const char *vnd;
-
- dev = udev_device_get_parent (dev);
- if (dev == NULL)
- return NULL;
-
- vnd = udev_device_get_property_value (dev, "ID_VENDOR_FROM_DATABASE");
- if (vnd == NULL)
- /* FIXME: USB may take time to settle... the parent device */
- vnd = udev_device_get_property_value (dev, "ID_BUS");
- return vnd ? strdup (vnd) : NULL;
+ return fullname;
}
int OpenALSA (vlc_object_t *obj)
{
static const struct subsys subsys = {
- "sound", alsa_get_mrl, alsa_get_name, alsa_get_cat, ITEM_TYPE_CARD,
+ "sound", alsa_get_mrl, alsa_get_name, ITEM_TYPE_CARD,
};
return Open (obj, &subsys);
@@ -581,11 +584,7 @@ static char *disc_get_mrl (struct udev_device *dev)
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)
-{
+ char *name = NULL;
struct udev_list_entry *list, *entry;
list = udev_device_get_properties_list_entry (dev);
@@ -618,13 +617,19 @@ static char *disc_get_cat (struct udev_device *dev)
if (cat == NULL)
cat = N_("Unknown type");
- return strdup (vlc_gettext (cat));
+
+ const char *label = decode_property (dev, "ID_FS_LABEL_ENC");
+
+ if (asprintf(&name, "%s (%s)", label, vlc_gettext(cat)) < 0)
+ name = NULL;
+
+ return name;
}
int OpenDisc (vlc_object_t *obj)
{
static const struct subsys subsys = {
- "block", disc_get_mrl, disc_get_name, disc_get_cat, ITEM_TYPE_DISC,
+ "block", disc_get_mrl, disc_get_name, ITEM_TYPE_DISC,
};
return Open (obj, &subsys);
--
1.7.8.3
More information about the vlc-devel
mailing list