mirror of
https://github.com/mpv-player/mpv
synced 2025-03-25 04:38:01 +00: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:
parent
dd357a7d53
commit
8f82dc92aa
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user