0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

ao/openal: Add OpenAL Soft extension to get the correct latency

OpenAL Soft's AL_SOFT_source_latency extension allows one to correctly
get the device output latency, facilitating the syncronization with
video.
Also added a simpler generic fallback that does not take into account
latency of the device.
This commit is contained in:
LAGonauta 2018-03-28 11:09:19 -03:00 committed by Jan Ekström
parent dd357a7d53
commit 8f82dc92aa

View File

@ -435,7 +435,22 @@ static double get_delay(struct ao *ao)
ALint queued;
unqueue_buffers();
alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);
return queued * CHUNK_SAMPLES / (double)ao->samplerate;
double soft_source_latency = 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];
} else {
float offset = 0;
alGetSourcef(source, AL_SEC_OFFSET, &offset);
soft_source_latency = -offset;
}
return (queued * CHUNK_SAMPLES / (double)ao->samplerate) + soft_source_latency;
}
#define OPT_BASE_STRUCT struct priv