From f1efd83ef7e79c0f88c080c9d0dbb3272a8dc99c Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 9 Oct 2014 21:22:44 +0200 Subject: ao_alsa: implement device listing & selection Unfortunately, ALSA is particularly bad with this, because mpv has to add all sorts of magic crap to the device name to make things work. The device selection overrides this, so explicitly selecting devices will most likely break your audio. This has yet to be solved. --- audio/out/ao_alsa.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'audio/out') diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c index 52f410cf5e..1b0703cea6 100644 --- a/audio/out/ao_alsa.c +++ b/audio/out/ao_alsa.c @@ -365,6 +365,8 @@ static int init(struct ao *ao) device = talloc_asprintf(ao, "plug:%s", device); } } + if (ao->device) + device = ao->device; if (p->cfg_device && p->cfg_device[0]) device = p->cfg_device; @@ -731,6 +733,30 @@ alsa_error: return -1; } +static void list_devs(const struct ao_driver *d, struct ao_device_list *list) +{ + void **hints; + if (snd_device_name_hint(-1, "pcm", &hints) < 0) + return; + + for (int n = 0; hints[n]; n++) { + char *name = snd_device_name_get_hint(hints[n], "NAME"); + char *desc = snd_device_name_get_hint(hints[n], "DESC"); + char *io = snd_device_name_get_hint(hints[n], "IOID"); + if (io && strcmp(io, "Output") != 0) + continue; + char desc2[1024]; + snprintf(desc2, sizeof(desc2), "%s", desc ? desc : ""); + for (int i = 0; desc2[i]; i++) { + if (desc2[i] == '\n') + desc2[i] = '/'; + } + ao_device_list_add(list, d, &(struct ao_device_desc){name, desc2}); + } + + snd_device_name_free_hint(hints); +} + #define OPT_BASE_STRUCT struct priv const struct ao_driver audio_out_alsa = { @@ -748,6 +774,7 @@ const struct ao_driver audio_out_alsa = { .drain = drain, .wait = audio_wait, .wakeup = ao_wakeup_poll, + .list_devs = list_devs, .priv_size = sizeof(struct priv), .priv_defaults = &(const struct priv) { .cfg_block = 1, -- cgit v1.2.3