From a2b93e0c275931532dc15c2cf6a5ebeafec9ed6c Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 14 Nov 2016 13:39:47 +0100 Subject: audio: make empty device ID mean default device This will make it easier for AOs to add explicit default device entries. (See next commit.) Hopefully this change doesn't lead accidentally to bogus "Default" entries to appear, but then it can only happen if the device ID is empty, which would mean the underlying audio API returned bogus entries. --- audio/out/ao.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'audio/out') diff --git a/audio/out/ao.c b/audio/out/ao.c index 9846869f2c..b624f4196c 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -529,14 +529,10 @@ struct ao_hotplug *ao_hotplug_create(struct mpv_global *global, static void get_devices(struct ao *ao, struct ao_device_list *list) { - int num = list->num_devices; if (ao->driver->list_devs) { ao->driver->list_devs(ao, list); } else { - char name[80] = "Default"; - if (num > 1) - mp_snprintf_cat(name, sizeof(name), " (%s)", ao->driver->name); - ao_device_list_add(list, ao, &(struct ao_device_desc){"", name}); + ao_device_list_add(list, ao, &(struct ao_device_desc){"", ""}); } } @@ -599,8 +595,19 @@ void ao_device_list_add(struct ao_device_list *list, struct ao *ao, { struct ao_device_desc c = *e; const char *dname = ao->driver->name; - if ((!c.desc || !c.desc[0]) && c.name) - c.desc = c.name; + char buf[80]; + if (!c.desc || !c.desc[0]) { + if (c.name && c.name[0]) { + c.desc = c.name; + } else if (list->num_devices) { + // Assume this is the default device. + snprintf(buf, sizeof(buf), "Default (%s)", dname); + c.desc = buf; + } else { + // First default device (and maybe the only one). + c.desc = "Default"; + } + } c.name = c.name[0] ? talloc_asprintf(list, "%s/%s", dname, c.name) : talloc_strdup(list, dname); c.desc = talloc_strdup(list, c.desc); -- cgit v1.2.3