2008-09-07 14:09:51 +00:00
|
|
|
/*
|
|
|
|
* OpenAL audio output driver for MPlayer
|
2006-02-16 20:45:25 +00:00
|
|
|
*
|
2007-07-09 19:50:36 +00:00
|
|
|
* Copyleft 2006 by Reimar Döffinger (Reimar.Doeffinger@stud.uni-karlsruhe.de)
|
2008-09-07 14:09:51 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2008-09-07 14:09:51 +00:00
|
|
|
*
|
2017-06-24 12:10:14 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2008-09-07 14:09:51 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2008-09-07 14:09:51 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-06-24 12:10:14 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2008-09-07 14:09:51 +00:00
|
|
|
*
|
2017-06-24 12:10:14 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2006-02-16 20:45:25 +00:00
|
|
|
*/
|
|
|
|
|
2006-12-10 14:07:08 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2006-02-18 12:45:00 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2006-02-16 20:45:25 +00:00
|
|
|
#include <inttypes.h>
|
2006-12-10 14:07:08 +00:00
|
|
|
#ifdef OPENAL_AL_H
|
|
|
|
#include <OpenAL/alc.h>
|
|
|
|
#include <OpenAL/al.h>
|
2012-03-12 23:24:38 +00:00
|
|
|
#include <OpenAL/alext.h>
|
2006-12-10 14:07:08 +00:00
|
|
|
#else
|
2006-02-16 20:45:25 +00:00
|
|
|
#include <AL/alc.h>
|
|
|
|
#include <AL/al.h>
|
2012-03-12 23:24:38 +00:00
|
|
|
#include <AL/alext.h>
|
2006-12-10 14:07:08 +00:00
|
|
|
#endif
|
2006-02-16 20:45:25 +00:00
|
|
|
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2006-02-16 20:45:25 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "ao.h"
|
2014-03-07 14:24:32 +00:00
|
|
|
#include "internal.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "audio/format.h"
|
2006-02-16 20:45:25 +00:00
|
|
|
#include "osdep/timer.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2006-02-16 20:45:25 +00:00
|
|
|
|
2013-05-09 16:06:26 +00:00
|
|
|
#define MAX_CHANS MP_NUM_CHANNELS
|
2018-04-01 13:26:45 +00:00
|
|
|
#define MAX_BUF 128
|
|
|
|
#define MAX_SAMPLES 32768
|
|
|
|
static ALuint buffers[MAX_BUF];
|
|
|
|
static ALuint buffer_size[MAX_BUF];
|
2018-03-26 00:39:59 +00:00
|
|
|
static ALuint source;
|
2006-02-16 20:45:25 +00:00
|
|
|
|
2018-03-26 00:39:59 +00:00
|
|
|
static int cur_buf;
|
|
|
|
static int unqueue_buf;
|
2006-02-16 20:45:25 +00:00
|
|
|
|
2013-06-03 23:42:57 +00:00
|
|
|
static struct ao *ao_data;
|
|
|
|
|
2013-07-21 20:23:12 +00:00
|
|
|
struct priv {
|
2015-11-17 09:16:51 +00:00
|
|
|
ALenum al_format;
|
2018-04-01 13:26:45 +00:00
|
|
|
int num_buffers;
|
|
|
|
int num_samples;
|
2018-03-28 13:33:38 +00:00
|
|
|
int direct_channels;
|
2013-07-21 20:23:12 +00:00
|
|
|
};
|
|
|
|
|
2013-06-03 23:42:57 +00:00
|
|
|
static int control(struct ao *ao, enum aocontrol cmd, void *arg)
|
2013-06-03 23:34:53 +00:00
|
|
|
{
|
|
|
|
switch (cmd) {
|
2006-12-10 22:45:32 +00:00
|
|
|
case AOCONTROL_GET_VOLUME:
|
|
|
|
case AOCONTROL_SET_VOLUME: {
|
2013-06-03 23:34:53 +00:00
|
|
|
ALfloat volume;
|
2022-12-31 03:46:44 +00:00
|
|
|
float *vol = arg;
|
2013-06-03 23:34:53 +00:00
|
|
|
if (cmd == AOCONTROL_SET_VOLUME) {
|
2022-12-31 03:46:44 +00:00
|
|
|
volume = *vol / 100.0;
|
2013-06-03 23:34:53 +00:00
|
|
|
alListenerf(AL_GAIN, volume);
|
|
|
|
}
|
|
|
|
alGetListenerf(AL_GAIN, &volume);
|
2022-12-31 03:46:44 +00:00
|
|
|
*vol = volume * 100;
|
2013-06-03 23:34:53 +00:00
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
2018-03-26 14:38:21 +00:00
|
|
|
case AOCONTROL_GET_MUTE:
|
|
|
|
case AOCONTROL_SET_MUTE: {
|
|
|
|
bool mute = *(bool *)arg;
|
2018-04-14 22:18:53 +00:00
|
|
|
|
|
|
|
// openal has no mute control, only gain.
|
|
|
|
// Thus reverse the muted state to get required gain
|
2018-03-26 14:38:21 +00:00
|
|
|
ALfloat al_mute = (ALfloat)(!mute);
|
|
|
|
if (cmd == AOCONTROL_SET_MUTE) {
|
|
|
|
alSourcef(source, AL_GAIN, al_mute);
|
|
|
|
}
|
|
|
|
alGetSourcef(source, AL_GAIN, &al_mute);
|
|
|
|
*(bool *)arg = !((bool)al_mute);
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-12-10 22:45:32 +00:00
|
|
|
}
|
2013-06-03 23:34:53 +00:00
|
|
|
return CONTROL_UNKNOWN;
|
2006-02-16 20:45:25 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:41:06 +00:00
|
|
|
static enum af_format get_supported_format(int format)
|
2015-11-17 09:16:51 +00:00
|
|
|
{
|
|
|
|
switch (format) {
|
2018-03-26 00:39:59 +00:00
|
|
|
case AF_FORMAT_U8:
|
2018-03-28 17:41:06 +00:00
|
|
|
if (alGetEnumValue((ALchar*)"AL_FORMAT_MONO8"))
|
|
|
|
return AF_FORMAT_U8;
|
2018-03-26 00:39:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_FORMAT_S16:
|
2018-03-28 17:41:06 +00:00
|
|
|
if (alGetEnumValue((ALchar*)"AL_FORMAT_MONO16"))
|
|
|
|
return AF_FORMAT_S16;
|
2018-03-26 00:39:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_FORMAT_S32:
|
|
|
|
if (strstr(alGetString(AL_RENDERER), "X-Fi") != NULL)
|
2018-03-28 17:41:06 +00:00
|
|
|
return AF_FORMAT_S32;
|
2018-03-26 00:39:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_FORMAT_FLOAT:
|
2015-11-17 09:16:51 +00:00
|
|
|
if (alIsExtensionPresent((ALchar*)"AL_EXT_float32") == AL_TRUE)
|
2018-03-28 17:41:06 +00:00
|
|
|
return AF_FORMAT_FLOAT;
|
2015-11-17 09:16:51 +00:00
|
|
|
break;
|
2018-03-26 00:39:59 +00:00
|
|
|
}
|
|
|
|
return AL_FALSE;
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:41:06 +00:00
|
|
|
static ALenum get_supported_layout(int format, int channels)
|
2018-03-26 00:39:59 +00:00
|
|
|
{
|
2018-03-28 17:41:06 +00:00
|
|
|
const char *channel_str[] = {
|
|
|
|
[1] = "MONO",
|
|
|
|
[2] = "STEREO",
|
|
|
|
[4] = "QUAD",
|
|
|
|
[6] = "51CHN",
|
|
|
|
[7] = "61CHN",
|
|
|
|
[8] = "71CHN",
|
|
|
|
};
|
|
|
|
const char *format_str[] = {
|
|
|
|
[AF_FORMAT_U8] = "8",
|
|
|
|
[AF_FORMAT_S16] = "16",
|
|
|
|
[AF_FORMAT_S32] = "32",
|
|
|
|
[AF_FORMAT_FLOAT] = "_FLOAT32",
|
|
|
|
};
|
|
|
|
if (channel_str[channels] == NULL || format_str[format] == NULL)
|
|
|
|
return AL_FALSE;
|
|
|
|
|
|
|
|
char enum_name[32];
|
|
|
|
// AF_FORMAT_FLOAT uses same enum name as AF_FORMAT_S32 for multichannel
|
|
|
|
// playback, while it is different for mono and stereo.
|
|
|
|
// OpenAL Soft does not support AF_FORMAT_S32 and seems to reuse the names.
|
|
|
|
if (channels > 2 && format == AF_FORMAT_FLOAT)
|
|
|
|
format = AF_FORMAT_S32;
|
|
|
|
snprintf(enum_name, sizeof(enum_name), "AL_FORMAT_%s%s", channel_str[channels],
|
|
|
|
format_str[format]);
|
|
|
|
|
|
|
|
if (alGetEnumValue((ALchar*)enum_name)) {
|
|
|
|
return alGetEnumValue((ALchar*)enum_name);
|
2015-11-17 09:16:51 +00:00
|
|
|
}
|
|
|
|
return AL_FALSE;
|
|
|
|
}
|
|
|
|
|
2015-11-17 09:10:05 +00:00
|
|
|
// close audio device
|
|
|
|
static void uninit(struct ao *ao)
|
|
|
|
{
|
2018-04-01 13:26:45 +00:00
|
|
|
struct priv *p = ao->priv;
|
2018-03-26 00:39:59 +00:00
|
|
|
alSourceStop(source);
|
|
|
|
alSourcei(source, AL_BUFFER, 0);
|
|
|
|
|
2018-04-01 13:26:45 +00:00
|
|
|
alDeleteBuffers(p->num_buffers, buffers);
|
2018-03-26 00:39:59 +00:00
|
|
|
alDeleteSources(1, &source);
|
|
|
|
|
2015-11-17 09:10:05 +00:00
|
|
|
ALCcontext *ctx = alcGetCurrentContext();
|
|
|
|
ALCdevice *dev = alcGetContextsDevice(ctx);
|
|
|
|
alcMakeContextCurrent(NULL);
|
|
|
|
alcDestroyContext(ctx);
|
|
|
|
alcCloseDevice(dev);
|
|
|
|
ao_data = NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-22 20:57:51 +00:00
|
|
|
static int init(struct ao *ao)
|
2013-04-05 21:06:22 +00:00
|
|
|
{
|
2013-06-03 23:34:53 +00:00
|
|
|
float position[3] = {0, 0, 0};
|
2015-11-17 15:03:31 +00:00
|
|
|
float direction[6] = {0, 0, -1, 0, 1, 0};
|
2013-06-03 23:34:53 +00:00
|
|
|
ALCdevice *dev = NULL;
|
|
|
|
ALCcontext *ctx = NULL;
|
|
|
|
ALCint freq = 0;
|
2013-06-03 23:42:57 +00:00
|
|
|
ALCint attribs[] = {ALC_FREQUENCY, ao->samplerate, 0, 0};
|
2013-07-21 20:23:12 +00:00
|
|
|
struct priv *p = ao->priv;
|
2013-06-03 23:42:57 +00:00
|
|
|
if (ao_data) {
|
2013-08-22 21:12:35 +00:00
|
|
|
MP_FATAL(ao, "Not reentrant!\n");
|
2013-06-03 23:42:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ao_data = ao;
|
2017-04-23 15:44:26 +00:00
|
|
|
char *dev_name = ao->device;
|
2014-10-13 14:42:56 +00:00
|
|
|
dev = alcOpenDevice(dev_name && dev_name[0] ? dev_name : NULL);
|
2013-06-03 23:34:53 +00:00
|
|
|
if (!dev) {
|
2013-08-22 21:12:35 +00:00
|
|
|
MP_FATAL(ao, "could not open device\n");
|
2013-06-03 23:34:53 +00:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
ctx = alcCreateContext(dev, attribs);
|
|
|
|
alcMakeContextCurrent(ctx);
|
|
|
|
alListenerfv(AL_POSITION, position);
|
|
|
|
alListenerfv(AL_ORIENTATION, direction);
|
2018-03-26 00:39:59 +00:00
|
|
|
|
|
|
|
alGenSources(1, &source);
|
2021-11-19 23:17:01 +00:00
|
|
|
if (p->direct_channels) {
|
|
|
|
if (alIsExtensionPresent("AL_SOFT_direct_channels_remix")) {
|
|
|
|
alSourcei(source,
|
|
|
|
alGetEnumValue((ALchar*)"AL_DIRECT_CHANNELS_SOFT"),
|
|
|
|
alcGetEnumValue(dev, "AL_REMIX_UNMATCHED_SOFT"));
|
|
|
|
} else {
|
|
|
|
MP_WARN(ao, "Direct channels aren't supported by this version of OpenAL\n");
|
|
|
|
}
|
2018-03-28 13:33:38 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 00:39:59 +00:00
|
|
|
cur_buf = 0;
|
|
|
|
unqueue_buf = 0;
|
2018-04-01 13:26:45 +00:00
|
|
|
for (int i = 0; i < p->num_buffers; ++i) {
|
|
|
|
buffer_size[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
alGenBuffers(p->num_buffers, buffers);
|
2018-03-26 00:39:59 +00:00
|
|
|
|
2013-06-03 23:34:53 +00:00
|
|
|
alcGetIntegerv(dev, ALC_FREQUENCY, 1, &freq);
|
|
|
|
if (alcGetError(dev) == ALC_NO_ERROR && freq)
|
2013-06-03 23:42:57 +00:00
|
|
|
ao->samplerate = freq;
|
2015-11-17 09:16:51 +00:00
|
|
|
|
2018-03-28 17:41:06 +00:00
|
|
|
// Check sample format
|
2018-01-23 23:02:13 +00:00
|
|
|
int try_formats[AF_FORMAT_COUNT + 1];
|
2018-03-28 17:41:06 +00:00
|
|
|
enum af_format sample_format = 0;
|
2015-11-17 09:16:51 +00:00
|
|
|
af_get_best_sample_formats(ao->format, try_formats);
|
|
|
|
for (int n = 0; try_formats[n]; n++) {
|
2018-03-28 17:41:06 +00:00
|
|
|
sample_format = get_supported_format(try_formats[n]);
|
|
|
|
if (sample_format != AF_FORMAT_UNKNOWN) {
|
2015-11-17 09:16:51 +00:00
|
|
|
ao->format = try_formats[n];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:41:06 +00:00
|
|
|
if (sample_format == AF_FORMAT_UNKNOWN) {
|
2015-11-17 09:16:51 +00:00
|
|
|
MP_FATAL(ao, "Can't find appropriate sample format.\n");
|
|
|
|
uninit(ao);
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:41:06 +00:00
|
|
|
// Check if OpenAL driver supports the desired number of channels.
|
|
|
|
int num_channels = ao->channels.num;
|
|
|
|
do {
|
|
|
|
p->al_format = get_supported_layout(sample_format, num_channels);
|
|
|
|
if (p->al_format == AL_FALSE) {
|
|
|
|
num_channels = num_channels - 1;
|
|
|
|
}
|
|
|
|
} while (p->al_format == AL_FALSE && num_channels > 1);
|
|
|
|
|
|
|
|
// Request number of speakers for output from ao.
|
|
|
|
const struct mp_chmap possible_layouts[] = {
|
|
|
|
{0}, // empty
|
|
|
|
MP_CHMAP_INIT_MONO, // mono
|
|
|
|
MP_CHMAP_INIT_STEREO, // stereo
|
|
|
|
{0}, // 2.1
|
|
|
|
MP_CHMAP4(FL, FR, BL, BR), // 4.0
|
|
|
|
{0}, // 5.0
|
|
|
|
MP_CHMAP6(FL, FR, FC, LFE, BL, BR), // 5.1
|
2018-04-01 13:26:45 +00:00
|
|
|
MP_CHMAP7(FL, FR, FC, LFE, SL, SR, BC), // 6.1
|
2018-03-28 17:41:06 +00:00
|
|
|
MP_CHMAP8(FL, FR, FC, LFE, BL, BR, SL, SR), // 7.1
|
|
|
|
};
|
|
|
|
ao->channels = possible_layouts[num_channels];
|
|
|
|
if (!ao->channels.num)
|
|
|
|
mp_chmap_set_unknown(&ao->channels, num_channels);
|
|
|
|
|
|
|
|
if (p->al_format == AL_FALSE || !mp_chmap_is_valid(&ao->channels)) {
|
|
|
|
MP_FATAL(ao, "Can't find appropriate channel layout.\n");
|
|
|
|
uninit(ao);
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2020-08-31 14:04:17 +00:00
|
|
|
ao->device_buffer = p->num_buffers * p->num_samples;
|
2013-06-03 23:42:57 +00:00
|
|
|
return 0;
|
2006-02-16 20:45:25 +00:00
|
|
|
|
|
|
|
err_out:
|
2016-01-16 02:29:06 +00:00
|
|
|
ao_data = NULL;
|
2013-06-03 23:42:57 +00:00
|
|
|
return -1;
|
2006-02-16 20:45:25 +00:00
|
|
|
}
|
|
|
|
|
2018-04-01 13:26:45 +00:00
|
|
|
static void unqueue_buffers(struct ao *ao)
|
2013-06-03 23:34:53 +00:00
|
|
|
{
|
2018-04-01 13:26:45 +00:00
|
|
|
struct priv *q = ao->priv;
|
2013-06-03 23:34:53 +00:00
|
|
|
ALint p;
|
2018-04-01 13:26:45 +00:00
|
|
|
int till_wrap = q->num_buffers - unqueue_buf;
|
2018-03-26 00:39:59 +00:00
|
|
|
alGetSourcei(source, AL_BUFFERS_PROCESSED, &p);
|
|
|
|
if (p >= till_wrap) {
|
|
|
|
alSourceUnqueueBuffers(source, till_wrap, &buffers[unqueue_buf]);
|
|
|
|
unqueue_buf = 0;
|
|
|
|
p -= till_wrap;
|
|
|
|
}
|
|
|
|
if (p) {
|
|
|
|
alSourceUnqueueBuffers(source, p, &buffers[unqueue_buf]);
|
|
|
|
unqueue_buf += p;
|
2006-02-16 20:45:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-03 23:42:57 +00:00
|
|
|
static void reset(struct ao *ao)
|
2013-06-03 23:34:53 +00:00
|
|
|
{
|
2018-03-26 00:39:59 +00:00
|
|
|
alSourceStop(source);
|
2018-04-01 13:26:45 +00:00
|
|
|
unqueue_buffers(ao);
|
2006-02-16 20:45:25 +00:00
|
|
|
}
|
|
|
|
|
audio: redo internal AO API
This affects "pull" AOs only: ao_alsa, ao_pulse, ao_openal, ao_pcm,
ao_lavc. There are changes to the other AOs too, but that's only about
renaming ao_driver.resume to ao_driver.start.
ao_openal is broken because I didn't manage to fix it, so it exits with
an error message. If you want it, why don't _you_ put effort into it? I
see no reason to waste my own precious lifetime over this (I realize the
irony).
ao_alsa loses the poll() mechanism, but it was mostly broken and didn't
really do what it was supposed to. There doesn't seem to be anything in
the ALSA API to watch the playback status without polling (unless you
want to use raw UNIX signals).
No idea if ao_pulse is correct, or whether it's subtly broken now. There
is no documentation, so I can't tell what is correct, without reverse
engineering the whole project. I recommend using ALSA.
This was supposed to be just a simple fix, but somehow it expanded scope
like a train wreck. Very high chance of regressions, but probably only
for the AOs listed above. The rest you can figure out from reading the
diff.
2020-05-31 13:00:35 +00:00
|
|
|
static bool audio_set_pause(struct ao *ao, bool pause)
|
2013-06-03 23:34:53 +00:00
|
|
|
{
|
audio: redo internal AO API
This affects "pull" AOs only: ao_alsa, ao_pulse, ao_openal, ao_pcm,
ao_lavc. There are changes to the other AOs too, but that's only about
renaming ao_driver.resume to ao_driver.start.
ao_openal is broken because I didn't manage to fix it, so it exits with
an error message. If you want it, why don't _you_ put effort into it? I
see no reason to waste my own precious lifetime over this (I realize the
irony).
ao_alsa loses the poll() mechanism, but it was mostly broken and didn't
really do what it was supposed to. There doesn't seem to be anything in
the ALSA API to watch the playback status without polling (unless you
want to use raw UNIX signals).
No idea if ao_pulse is correct, or whether it's subtly broken now. There
is no documentation, so I can't tell what is correct, without reverse
engineering the whole project. I recommend using ALSA.
This was supposed to be just a simple fix, but somehow it expanded scope
like a train wreck. Very high chance of regressions, but probably only
for the AOs listed above. The rest you can figure out from reading the
diff.
2020-05-31 13:00:35 +00:00
|
|
|
if (pause) {
|
|
|
|
alSourcePause(source);
|
|
|
|
} else {
|
|
|
|
alSourcePlay(source);
|
|
|
|
}
|
|
|
|
return true;
|
2006-02-16 20:45:25 +00:00
|
|
|
}
|
|
|
|
|
audio: redo internal AO API
This affects "pull" AOs only: ao_alsa, ao_pulse, ao_openal, ao_pcm,
ao_lavc. There are changes to the other AOs too, but that's only about
renaming ao_driver.resume to ao_driver.start.
ao_openal is broken because I didn't manage to fix it, so it exits with
an error message. If you want it, why don't _you_ put effort into it? I
see no reason to waste my own precious lifetime over this (I realize the
irony).
ao_alsa loses the poll() mechanism, but it was mostly broken and didn't
really do what it was supposed to. There doesn't seem to be anything in
the ALSA API to watch the playback status without polling (unless you
want to use raw UNIX signals).
No idea if ao_pulse is correct, or whether it's subtly broken now. There
is no documentation, so I can't tell what is correct, without reverse
engineering the whole project. I recommend using ALSA.
This was supposed to be just a simple fix, but somehow it expanded scope
like a train wreck. Very high chance of regressions, but probably only
for the AOs listed above. The rest you can figure out from reading the
diff.
2020-05-31 13:00:35 +00:00
|
|
|
static bool audio_write(struct ao *ao, void **data, int samples)
|
2013-06-03 23:34:53 +00:00
|
|
|
{
|
2015-11-17 09:16:51 +00:00
|
|
|
struct priv *p = ao->priv;
|
2018-04-01 13:26:45 +00:00
|
|
|
|
audio: redo internal AO API
This affects "pull" AOs only: ao_alsa, ao_pulse, ao_openal, ao_pcm,
ao_lavc. There are changes to the other AOs too, but that's only about
renaming ao_driver.resume to ao_driver.start.
ao_openal is broken because I didn't manage to fix it, so it exits with
an error message. If you want it, why don't _you_ put effort into it? I
see no reason to waste my own precious lifetime over this (I realize the
irony).
ao_alsa loses the poll() mechanism, but it was mostly broken and didn't
really do what it was supposed to. There doesn't seem to be anything in
the ALSA API to watch the playback status without polling (unless you
want to use raw UNIX signals).
No idea if ao_pulse is correct, or whether it's subtly broken now. There
is no documentation, so I can't tell what is correct, without reverse
engineering the whole project. I recommend using ALSA.
This was supposed to be just a simple fix, but somehow it expanded scope
like a train wreck. Very high chance of regressions, but probably only
for the AOs listed above. The rest you can figure out from reading the
diff.
2020-05-31 13:00:35 +00:00
|
|
|
int num = (samples + p->num_samples - 1) / p->num_samples;
|
2018-04-01 13:26:45 +00:00
|
|
|
|
2013-11-10 22:39:22 +00:00
|
|
|
for (int i = 0; i < num; i++) {
|
2018-03-28 17:41:06 +00:00
|
|
|
char *d = *data;
|
audio: redo internal AO API
This affects "pull" AOs only: ao_alsa, ao_pulse, ao_openal, ao_pcm,
ao_lavc. There are changes to the other AOs too, but that's only about
renaming ao_driver.resume to ao_driver.start.
ao_openal is broken because I didn't manage to fix it, so it exits with
an error message. If you want it, why don't _you_ put effort into it? I
see no reason to waste my own precious lifetime over this (I realize the
irony).
ao_alsa loses the poll() mechanism, but it was mostly broken and didn't
really do what it was supposed to. There doesn't seem to be anything in
the ALSA API to watch the playback status without polling (unless you
want to use raw UNIX signals).
No idea if ao_pulse is correct, or whether it's subtly broken now. There
is no documentation, so I can't tell what is correct, without reverse
engineering the whole project. I recommend using ALSA.
This was supposed to be just a simple fix, but somehow it expanded scope
like a train wreck. Very high chance of regressions, but probably only
for the AOs listed above. The rest you can figure out from reading the
diff.
2020-05-31 13:00:35 +00:00
|
|
|
buffer_size[cur_buf] =
|
2020-08-31 14:04:17 +00:00
|
|
|
MPMIN(samples - i * p->num_samples, p->num_samples);
|
2018-04-01 13:26:45 +00:00
|
|
|
d += i * buffer_size[cur_buf] * ao->sstride;
|
|
|
|
alBufferData(buffers[cur_buf], p->al_format, d,
|
|
|
|
buffer_size[cur_buf] * ao->sstride, ao->samplerate);
|
2018-03-26 00:39:59 +00:00
|
|
|
alSourceQueueBuffers(source, 1, &buffers[cur_buf]);
|
2018-04-01 13:26:45 +00:00
|
|
|
cur_buf = (cur_buf + 1) % p->num_buffers;
|
2006-02-16 20:45:25 +00:00
|
|
|
}
|
2018-04-01 13:26:45 +00:00
|
|
|
|
audio: redo internal AO API
This affects "pull" AOs only: ao_alsa, ao_pulse, ao_openal, ao_pcm,
ao_lavc. There are changes to the other AOs too, but that's only about
renaming ao_driver.resume to ao_driver.start.
ao_openal is broken because I didn't manage to fix it, so it exits with
an error message. If you want it, why don't _you_ put effort into it? I
see no reason to waste my own precious lifetime over this (I realize the
irony).
ao_alsa loses the poll() mechanism, but it was mostly broken and didn't
really do what it was supposed to. There doesn't seem to be anything in
the ALSA API to watch the playback status without polling (unless you
want to use raw UNIX signals).
No idea if ao_pulse is correct, or whether it's subtly broken now. There
is no documentation, so I can't tell what is correct, without reverse
engineering the whole project. I recommend using ALSA.
This was supposed to be just a simple fix, but somehow it expanded scope
like a train wreck. Very high chance of regressions, but probably only
for the AOs listed above. The rest you can figure out from reading the
diff.
2020-05-31 13:00:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-04-01 13:26:45 +00:00
|
|
|
|
audio: redo internal AO API
This affects "pull" AOs only: ao_alsa, ao_pulse, ao_openal, ao_pcm,
ao_lavc. There are changes to the other AOs too, but that's only about
renaming ao_driver.resume to ao_driver.start.
ao_openal is broken because I didn't manage to fix it, so it exits with
an error message. If you want it, why don't _you_ put effort into it? I
see no reason to waste my own precious lifetime over this (I realize the
irony).
ao_alsa loses the poll() mechanism, but it was mostly broken and didn't
really do what it was supposed to. There doesn't seem to be anything in
the ALSA API to watch the playback status without polling (unless you
want to use raw UNIX signals).
No idea if ao_pulse is correct, or whether it's subtly broken now. There
is no documentation, so I can't tell what is correct, without reverse
engineering the whole project. I recommend using ALSA.
This was supposed to be just a simple fix, but somehow it expanded scope
like a train wreck. Very high chance of regressions, but probably only
for the AOs listed above. The rest you can figure out from reading the
diff.
2020-05-31 13:00:35 +00:00
|
|
|
static void audio_start(struct ao *ao)
|
|
|
|
{
|
|
|
|
alSourcePlay(source);
|
2006-02-16 20:45:25 +00:00
|
|
|
}
|
|
|
|
|
audio: redo internal AO API
This affects "pull" AOs only: ao_alsa, ao_pulse, ao_openal, ao_pcm,
ao_lavc. There are changes to the other AOs too, but that's only about
renaming ao_driver.resume to ao_driver.start.
ao_openal is broken because I didn't manage to fix it, so it exits with
an error message. If you want it, why don't _you_ put effort into it? I
see no reason to waste my own precious lifetime over this (I realize the
irony).
ao_alsa loses the poll() mechanism, but it was mostly broken and didn't
really do what it was supposed to. There doesn't seem to be anything in
the ALSA API to watch the playback status without polling (unless you
want to use raw UNIX signals).
No idea if ao_pulse is correct, or whether it's subtly broken now. There
is no documentation, so I can't tell what is correct, without reverse
engineering the whole project. I recommend using ALSA.
This was supposed to be just a simple fix, but somehow it expanded scope
like a train wreck. Very high chance of regressions, but probably only
for the AOs listed above. The rest you can figure out from reading the
diff.
2020-05-31 13:00:35 +00:00
|
|
|
static void get_state(struct ao *ao, struct mp_pcm_state *state)
|
2013-06-03 23:34:53 +00:00
|
|
|
{
|
2018-04-01 13:26:45 +00:00
|
|
|
struct priv *p = ao->priv;
|
audio: redo internal AO API
This affects "pull" AOs only: ao_alsa, ao_pulse, ao_openal, ao_pcm,
ao_lavc. There are changes to the other AOs too, but that's only about
renaming ao_driver.resume to ao_driver.start.
ao_openal is broken because I didn't manage to fix it, so it exits with
an error message. If you want it, why don't _you_ put effort into it? I
see no reason to waste my own precious lifetime over this (I realize the
irony).
ao_alsa loses the poll() mechanism, but it was mostly broken and didn't
really do what it was supposed to. There doesn't seem to be anything in
the ALSA API to watch the playback status without polling (unless you
want to use raw UNIX signals).
No idea if ao_pulse is correct, or whether it's subtly broken now. There
is no documentation, so I can't tell what is correct, without reverse
engineering the whole project. I recommend using ALSA.
This was supposed to be just a simple fix, but somehow it expanded scope
like a train wreck. Very high chance of regressions, but probably only
for the AOs listed above. The rest you can figure out from reading the
diff.
2020-05-31 13:00:35 +00:00
|
|
|
|
2013-06-03 23:34:53 +00:00
|
|
|
ALint queued;
|
2018-04-01 13:26:45 +00:00
|
|
|
unqueue_buffers(ao);
|
2018-03-26 00:39:59 +00:00
|
|
|
alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);
|
2018-03-28 14:09:19 +00:00
|
|
|
|
2020-08-31 14:04:17 +00:00
|
|
|
double source_offset = 0;
|
2018-03-28 14:09:19 +00:00
|
|
|
if(alIsExtensionPresent("AL_SOFT_source_latency")) {
|
|
|
|
ALdouble offsets[2];
|
|
|
|
LPALGETSOURCEDVSOFT alGetSourcedvSOFT = alGetProcAddress("alGetSourcedvSOFT");
|
|
|
|
alGetSourcedvSOFT(source, AL_SEC_OFFSET_LATENCY_SOFT, offsets);
|
|
|
|
// Additional latency to the play buffer, the remaining seconds to be
|
|
|
|
// played minus the offset (seconds already played)
|
2020-08-31 14:04:17 +00:00
|
|
|
source_offset = offsets[1] - offsets[0];
|
2018-03-28 14:09:19 +00:00
|
|
|
} else {
|
|
|
|
float offset = 0;
|
|
|
|
alGetSourcef(source, AL_SEC_OFFSET, &offset);
|
2020-08-31 14:04:17 +00:00
|
|
|
source_offset = -offset;
|
2018-03-28 14:09:19 +00:00
|
|
|
}
|
|
|
|
|
2018-04-01 13:26:45 +00:00
|
|
|
int queued_samples = 0;
|
|
|
|
for (int i = 0, index = cur_buf; i < queued; ++i) {
|
|
|
|
queued_samples += buffer_size[index];
|
|
|
|
index = (index + 1) % p->num_buffers;
|
|
|
|
}
|
audio: redo internal AO API
This affects "pull" AOs only: ao_alsa, ao_pulse, ao_openal, ao_pcm,
ao_lavc. There are changes to the other AOs too, but that's only about
renaming ao_driver.resume to ao_driver.start.
ao_openal is broken because I didn't manage to fix it, so it exits with
an error message. If you want it, why don't _you_ put effort into it? I
see no reason to waste my own precious lifetime over this (I realize the
irony).
ao_alsa loses the poll() mechanism, but it was mostly broken and didn't
really do what it was supposed to. There doesn't seem to be anything in
the ALSA API to watch the playback status without polling (unless you
want to use raw UNIX signals).
No idea if ao_pulse is correct, or whether it's subtly broken now. There
is no documentation, so I can't tell what is correct, without reverse
engineering the whole project. I recommend using ALSA.
This was supposed to be just a simple fix, but somehow it expanded scope
like a train wreck. Very high chance of regressions, but probably only
for the AOs listed above. The rest you can figure out from reading the
diff.
2020-05-31 13:00:35 +00:00
|
|
|
|
2020-08-31 14:04:17 +00:00
|
|
|
state->delay = queued_samples / (double)ao->samplerate + source_offset;
|
audio: redo internal AO API
This affects "pull" AOs only: ao_alsa, ao_pulse, ao_openal, ao_pcm,
ao_lavc. There are changes to the other AOs too, but that's only about
renaming ao_driver.resume to ao_driver.start.
ao_openal is broken because I didn't manage to fix it, so it exits with
an error message. If you want it, why don't _you_ put effort into it? I
see no reason to waste my own precious lifetime over this (I realize the
irony).
ao_alsa loses the poll() mechanism, but it was mostly broken and didn't
really do what it was supposed to. There doesn't seem to be anything in
the ALSA API to watch the playback status without polling (unless you
want to use raw UNIX signals).
No idea if ao_pulse is correct, or whether it's subtly broken now. There
is no documentation, so I can't tell what is correct, without reverse
engineering the whole project. I recommend using ALSA.
This was supposed to be just a simple fix, but somehow it expanded scope
like a train wreck. Very high chance of regressions, but probably only
for the AOs listed above. The rest you can figure out from reading the
diff.
2020-05-31 13:00:35 +00:00
|
|
|
|
|
|
|
state->queued_samples = queued_samples;
|
|
|
|
state->free_samples = MPMAX(p->num_buffers - queued, 0) * p->num_samples;
|
2020-08-31 14:04:17 +00:00
|
|
|
|
|
|
|
ALint source_state = 0;
|
|
|
|
alGetSourcei(source, AL_SOURCE_STATE, &source_state);
|
|
|
|
state->playing = source_state == AL_PLAYING;
|
2006-02-16 20:45:25 +00:00
|
|
|
}
|
2013-06-03 23:42:57 +00:00
|
|
|
|
2013-07-21 20:23:12 +00:00
|
|
|
#define OPT_BASE_STRUCT struct priv
|
|
|
|
|
2013-06-03 23:42:57 +00:00
|
|
|
const struct ao_driver audio_out_openal = {
|
2013-10-23 17:07:27 +00:00
|
|
|
.description = "OpenAL audio output",
|
|
|
|
.name = "openal",
|
2013-06-03 23:42:57 +00:00
|
|
|
.init = init,
|
|
|
|
.uninit = uninit,
|
|
|
|
.control = control,
|
audio: redo internal AO API
This affects "pull" AOs only: ao_alsa, ao_pulse, ao_openal, ao_pcm,
ao_lavc. There are changes to the other AOs too, but that's only about
renaming ao_driver.resume to ao_driver.start.
ao_openal is broken because I didn't manage to fix it, so it exits with
an error message. If you want it, why don't _you_ put effort into it? I
see no reason to waste my own precious lifetime over this (I realize the
irony).
ao_alsa loses the poll() mechanism, but it was mostly broken and didn't
really do what it was supposed to. There doesn't seem to be anything in
the ALSA API to watch the playback status without polling (unless you
want to use raw UNIX signals).
No idea if ao_pulse is correct, or whether it's subtly broken now. There
is no documentation, so I can't tell what is correct, without reverse
engineering the whole project. I recommend using ALSA.
This was supposed to be just a simple fix, but somehow it expanded scope
like a train wreck. Very high chance of regressions, but probably only
for the AOs listed above. The rest you can figure out from reading the
diff.
2020-05-31 13:00:35 +00:00
|
|
|
.get_state = get_state,
|
|
|
|
.write = audio_write,
|
|
|
|
.start = audio_start,
|
|
|
|
.set_pause = audio_set_pause,
|
2013-06-03 23:42:57 +00:00
|
|
|
.reset = reset,
|
2013-07-21 20:23:12 +00:00
|
|
|
.priv_size = sizeof(struct priv),
|
2018-04-01 13:26:45 +00:00
|
|
|
.priv_defaults = &(const struct priv) {
|
|
|
|
.num_buffers = 4,
|
|
|
|
.num_samples = 8192,
|
2021-11-19 23:17:01 +00:00
|
|
|
.direct_channels = 1,
|
2018-04-01 13:26:45 +00:00
|
|
|
},
|
2018-03-28 13:33:38 +00:00
|
|
|
.options = (const struct m_option[]) {
|
options: change option macros and all option declarations
Change all OPT_* macros such that they don't define the entire m_option
initializer, and instead expand only to a part of it, which sets certain
fields. This requires changing almost every option declaration, because
they all use these macros. A declaration now always starts with
{"name", ...
followed by designated initializers only (possibly wrapped in macros).
The OPT_* macros now initialize the .offset and .type fields only,
sometimes also .priv and others.
I think this change makes the option macros less tricky. The old code
had to stuff everything into macro arguments (and attempted to allow
setting arbitrary fields by letting the user pass designated
initializers in the vararg parts). Some of this was made messy due to
C99 and C11 not allowing 0-sized varargs with ',' removal. It's also
possible that this change is pointless, other than cosmetic preferences.
Not too happy about some things. For example, the OPT_CHOICE()
indentation I applied looks a bit ugly.
Much of this change was done with regex search&replace, but some places
required manual editing. In particular, code in "obscure" areas (which I
didn't include in compilation) might be broken now.
In wayland_common.c the author of some option declarations confused the
flags parameter with the default value (though the default value was
also properly set below). I fixed this with this change.
2020-03-14 20:28:01 +00:00
|
|
|
{"num-buffers", OPT_INT(num_buffers), M_RANGE(2, MAX_BUF)},
|
|
|
|
{"num-samples", OPT_INT(num_samples), M_RANGE(256, MAX_SAMPLES)},
|
|
|
|
{"direct-channels", OPT_FLAG(direct_channels)},
|
2018-03-28 13:33:38 +00:00
|
|
|
{0}
|
|
|
|
},
|
|
|
|
.options_prefix = "openal",
|
2013-06-03 23:42:57 +00:00
|
|
|
};
|