summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-03-13 00:24:38 +0100
committerwm4 <wm4@mplayer2.org>2012-03-17 21:06:30 +0100
commit00421e5eec3271c0c15543ba97a97e304ed2dcb0 (patch)
tree1872bc5ced18c3e3cfc936af3f32f38f0fc59f83
parentc48c0f453bde933170ec2fa32c8abca1bd650fc6 (diff)
downloadmpv-00421e5eec3271c0c15543ba97a97e304ed2dcb0.tar.bz2
mpv-00421e5eec3271c0c15543ba97a97e304ed2dcb0.tar.xz
ao_openal: allow setting the OpenAL sub-device
Now "-ao openal:device=<subdevice>" will pass <subdevice> 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".
-rw-r--r--libao2/ao_openal.c30
1 files 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 <OpenAL/alc.h>
#include <OpenAL/al.h>
+#include <OpenAL/alext.h>
#else
#include <AL/alc.h>
#include <AL/al.h>
+#include <AL/alext.h>
#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;
}