From 00421e5eec3271c0c15543ba97a97e304ed2dcb0 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 13 Mar 2012 00:24:38 +0100 Subject: [PATCH] ao_openal: allow setting the OpenAL sub-device Now "-ao openal:device=" will pass as device to OpenAL. This allows selecting both the OpenAL backend (OS-level audio API) and the physical output device. The available devices can be listed with "-ao openal:device=help". --- libao2/ao_openal.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/libao2/ao_openal.c b/libao2/ao_openal.c index 490aac0eb8..263aed34fb 100644 --- a/libao2/ao_openal.c +++ b/libao2/ao_openal.c @@ -28,9 +28,11 @@ #ifdef OPENAL_AL_H #include #include +#include #else #include #include +#include #endif #include "mp_msg.h" @@ -86,11 +88,27 @@ static int control(int cmd, void *arg) { static void print_help(void) { mp_msg(MSGT_AO, MSGL_FATAL, "\n-ao openal commandline help:\n" - "Example: mplayer -ao openal\n" + "Example: mplayer -ao openal:device=subdevice\n" "\nOptions:\n" + " device=subdevice\n" + " Audio device OpenAL should use. Devices can be listed\n" + " with -ao openal:device=help\n" ); } +static void list_devices(void) { + if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_TRUE) { + mp_msg(MSGT_AO, MSGL_FATAL, "Device listing not supported.\n"); + return; + } + const char *list = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER); + mp_msg(MSGT_AO, MSGL_FATAL, "OpenAL devices:\n"); + while (list && *list) { + mp_msg(MSGT_AO, MSGL_FATAL, " '%s'\n", list); + list = list + strlen(list) + 1; + } +} + static int init(int rate, int channels, int format, int flags) { float position[3] = {0, 0, 0}; float direction[6] = {0, 0, 1, 0, -1, 0}; @@ -105,7 +123,9 @@ static int init(int rate, int channels, int format, int flags) { ALCint freq = 0; ALCint attribs[] = {ALC_FREQUENCY, rate, 0, 0}; int i; + char *device = NULL; const opt_t subopts[] = { + {"device", OPT_ARG_MSTRZ, &device, NULL}, {NULL} }; global_ao->no_persistent_volume = true; @@ -113,11 +133,15 @@ static int init(int rate, int channels, int format, int flags) { print_help(); return 0; } + if (strcmp(device, "help") == 0) { + list_devices(); + goto err_out; + } if (channels > MAX_CHANS) { mp_msg(MSGT_AO, MSGL_FATAL, "[OpenAL] Invalid number of channels: %i\n", channels); goto err_out; } - dev = alcOpenDevice(NULL); + dev = alcOpenDevice(device); if (!dev) { mp_msg(MSGT_AO, MSGL_FATAL, "[OpenAL] could not open device\n"); goto err_out; @@ -146,9 +170,11 @@ static int init(int rate, int channels, int format, int flags) { ao_data.buffersize = CHUNK_SIZE * NUM_BUF; ao_data.outburst = channels * CHUNK_SIZE; tmpbuf = malloc(CHUNK_SIZE); + free(device); return 1; err_out: + free(device); return 0; }