summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLAGonauta <lagonauta@gmail.com>2018-03-28 11:09:19 -0300
committerJan Ekström <jeebjp@gmail.com>2018-04-15 00:57:01 +0300
commit8f82dc92aa288659284b46ed4c233970fbd28903 (patch)
treeb766c4651952a990217ee9df1d88aa875985d1ae
parentdd357a7d53aba4a8146fb466251aed162f68785a (diff)
downloadmpv-8f82dc92aa288659284b46ed4c233970fbd28903.tar.bz2
mpv-8f82dc92aa288659284b46ed4c233970fbd28903.tar.xz
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.
-rw-r--r--audio/out/ao_openal.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/audio/out/ao_openal.c b/audio/out/ao_openal.c
index ab61c80763..c23fd27b90 100644
--- a/audio/out/ao_openal.c
+++ b/audio/out/ao_openal.c
@@ -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