summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-10-09 21:22:44 +0200
committerwm4 <wm4@nowhere>2014-10-09 21:22:44 +0200
commitf1efd83ef7e79c0f88c080c9d0dbb3272a8dc99c (patch)
tree6bacff752b7b2fa3b2b06ed297c682620fb15d3a
parent35649a990a5d468b6e9539c9e362d1e5a351c9c4 (diff)
downloadmpv-f1efd83ef7e79c0f88c080c9d0dbb3272a8dc99c.tar.bz2
mpv-f1efd83ef7e79c0f88c080c9d0dbb3272a8dc99c.tar.xz
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.
-rw-r--r--audio/out/ao_alsa.c27
1 files changed, 27 insertions, 0 deletions
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,