diff options
author | wm4 <wm4@nowhere> | 2016-11-14 13:39:47 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-11-14 13:42:41 +0100 |
commit | a2b93e0c275931532dc15c2cf6a5ebeafec9ed6c (patch) | |
tree | 51dfce20114133504ecfb8a646159d2880e40b7a | |
parent | 84513ba58bcbcf6dfb17eb1ae6b7d2e6a1d7bb4b (diff) | |
download | mpv-a2b93e0c275931532dc15c2cf6a5ebeafec9ed6c.tar.bz2 mpv-a2b93e0c275931532dc15c2cf6a5ebeafec9ed6c.tar.xz |
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.
-rw-r--r-- | audio/out/ao.c | 21 |
1 files changed, 14 insertions, 7 deletions
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); |