diff options
Diffstat (limited to 'audio/out/push.c')
-rw-r--r-- | audio/out/push.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/audio/out/push.c b/audio/out/push.c index f0608dd3a4..228fa25ba4 100644 --- a/audio/out/push.c +++ b/audio/out/push.c @@ -122,9 +122,23 @@ static int get_space(struct ao *ao) { struct ao_push_state *p = ao->api_priv; pthread_mutex_lock(&p->lock); - int s = mp_audio_buffer_get_write_available(p->buffer); + int space = mp_audio_buffer_get_write_available(p->buffer); + if (ao->driver->get_space) { + // The following code attempts to keep the total buffered audio to + // MIN_BUFFER in order to improve latency. + int device_space = ao->driver->get_space(ao); + int device_buffered = ao->device_buffer - device_space; + int soft_buffered = mp_audio_buffer_samples(p->buffer); + int min_buffer = MIN_BUFFER * ao->samplerate; + int missing = min_buffer - device_buffered - soft_buffered; + // But always keep the device's buffer filled as much as we can. + int device_missing = device_space - soft_buffered; + missing = MPMAX(missing, device_missing); + space = MPMIN(space, missing); + space = MPMAX(0, space); + } pthread_mutex_unlock(&p->lock); - return s; + return space; } static int play(struct ao *ao, void **data, int samples, int flags) |