1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-29 19:22:48 +00:00

ao_openal: restore working condition with new push API

This commit is contained in:
LAGonauta 2020-08-31 11:04:17 -03:00 committed by wm4
parent a805a152c1
commit 0ac724f002

View File

@ -175,9 +175,6 @@ static void uninit(struct ao *ao)
static int init(struct ao *ao)
{
MP_FATAL(ao, "broken.\n");
return -1;
float position[3] = {0, 0, 0};
float direction[6] = {0, 0, -1, 0, 1, 0};
ALCdevice *dev = NULL;
@ -267,6 +264,7 @@ static int init(struct ao *ao)
goto err_out;
}
ao->device_buffer = p->num_buffers * p->num_samples;
return 0;
err_out:
@ -316,7 +314,7 @@ static bool audio_write(struct ao *ao, void **data, int samples)
for (int i = 0; i < num; i++) {
char *d = *data;
buffer_size[cur_buf] =
MPMIN(samples - num * p->num_samples, p->num_samples);
MPMIN(samples - i * p->num_samples, p->num_samples);
d += i * buffer_size[cur_buf] * ao->sstride;
alBufferData(buffers[cur_buf], p->al_format, d,
buffer_size[cur_buf] * ao->sstride, ao->samplerate);
@ -340,18 +338,18 @@ static void get_state(struct ao *ao, struct mp_pcm_state *state)
unqueue_buffers(ao);
alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);
double soft_source_latency = 0;
double source_offset = 0;
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)
soft_source_latency = offsets[1] - offsets[0];
source_offset = offsets[1] - offsets[0];
} else {
float offset = 0;
alGetSourcef(source, AL_SEC_OFFSET, &offset);
soft_source_latency = -offset;
source_offset = -offset;
}
int queued_samples = 0;
@ -360,10 +358,14 @@ static void get_state(struct ao *ao, struct mp_pcm_state *state)
index = (index + 1) % p->num_buffers;
}
state->delay = queued_samples / (double)ao->samplerate + soft_source_latency;
state->delay = queued_samples / (double)ao->samplerate + source_offset;
state->queued_samples = queued_samples;
state->free_samples = MPMAX(p->num_buffers - queued, 0) * p->num_samples;
ALint source_state = 0;
alGetSourcei(source, AL_SOURCE_STATE, &source_state);
state->playing = source_state == AL_PLAYING;
}
#define OPT_BASE_STRUCT struct priv