mirror of https://github.com/mpv-player/mpv
ao_openal: use new option API
This commit is contained in:
parent
ce89ba6d75
commit
73dc678c25
|
@ -40,7 +40,7 @@
|
||||||
#include "ao.h"
|
#include "ao.h"
|
||||||
#include "audio/format.h"
|
#include "audio/format.h"
|
||||||
#include "osdep/timer.h"
|
#include "osdep/timer.h"
|
||||||
#include "core/subopt-helper.h"
|
#include "core/m_option.h"
|
||||||
|
|
||||||
#define MAX_CHANS MP_NUM_CHANNELS
|
#define MAX_CHANS MP_NUM_CHANNELS
|
||||||
#define NUM_BUF 128
|
#define NUM_BUF 128
|
||||||
|
@ -54,6 +54,10 @@ static int16_t *tmpbuf;
|
||||||
|
|
||||||
static struct ao *ao_data;
|
static struct ao *ao_data;
|
||||||
|
|
||||||
|
struct priv {
|
||||||
|
char *cfg_device;
|
||||||
|
};
|
||||||
|
|
||||||
static void reset(struct ao *ao);
|
static void reset(struct ao *ao);
|
||||||
|
|
||||||
static int control(struct ao *ao, enum aocontrol cmd, void *arg)
|
static int control(struct ao *ao, enum aocontrol cmd, void *arg)
|
||||||
|
@ -75,33 +79,23 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
|
||||||
return CONTROL_UNKNOWN;
|
return CONTROL_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static int validate_device_opt(const m_option_t *opt, struct bstr name,
|
||||||
* \brief print suboption usage help
|
struct bstr param)
|
||||||
*/
|
|
||||||
static void print_help(void)
|
|
||||||
{
|
|
||||||
mp_msg(MSGT_AO, MSGL_FATAL,
|
|
||||||
"\n-ao openal commandline help:\n"
|
|
||||||
"Example: mpv -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 (bstr_equals0(param, "help")) {
|
||||||
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_TRUE) {
|
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_TRUE) {
|
||||||
mp_msg(MSGT_AO, MSGL_FATAL, "Device listing not supported.\n");
|
mp_msg(MSGT_AO, MSGL_FATAL, "Device listing not supported.\n");
|
||||||
return;
|
return M_OPT_EXIT;
|
||||||
}
|
}
|
||||||
const char *list = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
|
const char *list = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
|
||||||
mp_msg(MSGT_AO, MSGL_FATAL, "OpenAL devices:\n");
|
mp_msg(MSGT_AO, MSGL_INFO, "OpenAL devices:\n");
|
||||||
while (list && *list) {
|
while (list && *list) {
|
||||||
mp_msg(MSGT_AO, MSGL_FATAL, " '%s'\n", list);
|
mp_msg(MSGT_AO, MSGL_INFO, " '%s'\n", list);
|
||||||
list = list + strlen(list) + 1;
|
list = list + strlen(list) + 1;
|
||||||
}
|
}
|
||||||
|
return M_OPT_EXIT - 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct speaker {
|
struct speaker {
|
||||||
|
@ -131,25 +125,13 @@ static int init(struct ao *ao, char *params)
|
||||||
ALCint freq = 0;
|
ALCint freq = 0;
|
||||||
ALCint attribs[] = {ALC_FREQUENCY, ao->samplerate, 0, 0};
|
ALCint attribs[] = {ALC_FREQUENCY, ao->samplerate, 0, 0};
|
||||||
int i;
|
int i;
|
||||||
char *device = NULL;
|
struct priv *p = ao->priv;
|
||||||
const opt_t subopts[] = {
|
|
||||||
{"device", OPT_ARG_MSTRZ, &device, NULL},
|
|
||||||
{NULL}
|
|
||||||
};
|
|
||||||
if (ao_data) {
|
if (ao_data) {
|
||||||
mp_msg(MSGT_AO, MSGL_FATAL, "[OpenAL] Not reentrant!\n");
|
mp_msg(MSGT_AO, MSGL_FATAL, "[OpenAL] Not reentrant!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ao_data = ao;
|
ao_data = ao;
|
||||||
ao->no_persistent_volume = true;
|
ao->no_persistent_volume = true;
|
||||||
if (subopt_parse(params, subopts) != 0) {
|
|
||||||
print_help();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (device && strcmp(device, "help") == 0) {
|
|
||||||
list_devices();
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
struct mp_chmap_sel sel = {0};
|
struct mp_chmap_sel sel = {0};
|
||||||
for (i = 0; speaker_pos[i].id != -1; i++)
|
for (i = 0; speaker_pos[i].id != -1; i++)
|
||||||
mp_chmap_sel_add_speaker(&sel, speaker_pos[i].id);
|
mp_chmap_sel_add_speaker(&sel, speaker_pos[i].id);
|
||||||
|
@ -167,7 +149,7 @@ static int init(struct ao *ao, char *params)
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dev = alcOpenDevice(device);
|
dev = alcOpenDevice(p->cfg_device && p->cfg_device[0] ? p->cfg_device : NULL);
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
mp_msg(MSGT_AO, MSGL_FATAL, "[OpenAL] could not open device\n");
|
mp_msg(MSGT_AO, MSGL_FATAL, "[OpenAL] could not open device\n");
|
||||||
goto err_out;
|
goto err_out;
|
||||||
|
@ -189,11 +171,9 @@ static int init(struct ao *ao, char *params)
|
||||||
ao->samplerate = freq;
|
ao->samplerate = freq;
|
||||||
ao->format = AF_FORMAT_S16_NE;
|
ao->format = AF_FORMAT_S16_NE;
|
||||||
tmpbuf = malloc(CHUNK_SIZE);
|
tmpbuf = malloc(CHUNK_SIZE);
|
||||||
free(device);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_out:
|
err_out:
|
||||||
free(device);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,6 +289,8 @@ static float get_delay(struct ao *ao)
|
||||||
return queued * CHUNK_SIZE / 2 / (float)ao->samplerate;
|
return queued * CHUNK_SIZE / 2 / (float)ao->samplerate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define OPT_BASE_STRUCT struct priv
|
||||||
|
|
||||||
const struct ao_driver audio_out_openal = {
|
const struct ao_driver audio_out_openal = {
|
||||||
.info = &(const struct ao_info) {
|
.info = &(const struct ao_info) {
|
||||||
"OpenAL audio output",
|
"OpenAL audio output",
|
||||||
|
@ -325,4 +307,9 @@ const struct ao_driver audio_out_openal = {
|
||||||
.pause = audio_pause,
|
.pause = audio_pause,
|
||||||
.resume = audio_resume,
|
.resume = audio_resume,
|
||||||
.reset = reset,
|
.reset = reset,
|
||||||
|
.priv_size = sizeof(struct priv),
|
||||||
|
.options = (const struct m_option[]) {
|
||||||
|
OPT_STRING_VALIDATE("device", cfg_device, 0, validate_device_opt),
|
||||||
|
{0}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue