diff options
author | wm4 <wm4@nowhere> | 2020-06-03 15:22:18 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-06-03 15:22:18 +0200 |
commit | baa7b5c8dd35365a8a62aa39c84394e5315b79e0 (patch) | |
tree | d842d639e4190ee8a0636f0986d0a05b5e285a11 | |
parent | 416d3f2c0071f22125a4e9e09475610961c0bec7 (diff) | |
download | mpv-baa7b5c8dd35365a8a62aa39c84394e5315b79e0.tar.bz2 mpv-baa7b5c8dd35365a8a62aa39c84394e5315b79e0.tar.xz |
audio: adjust wait duration
I feel like this makes slightly more sense. At least it doesn't include
the potentially arbitrary constant latency that is generally included in
the delay value. Also, the buffer status doesn't matter - either we've
filled the entire buffer (then we can wait this long), or there's not
enough data anyway (then the core will wake up the thread if new data is
available).
But ultimately, we have to guess, unless the AO does notify us with
ao_wakeup_playthread().
Draining may now wait for no reason up to 1/4th of the total buffer
time. Shouldn't be a disimprovement in practice.
-rw-r--r-- | audio/out/buffer.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/audio/out/buffer.c b/audio/out/buffer.c index a274fc9f7c..c69ef6d813 100644 --- a/audio/out/buffer.c +++ b/audio/out/buffer.c @@ -687,13 +687,11 @@ static void *playthread(void *arg) // Fallback to guessing. double timeout = INFINITY; if (p->ao_wait_low_buffer) { - struct mp_pcm_state state; - get_dev_state(ao, &state); - timeout = state.delay * 0.25; // wake up if 25% played + // Wake up again if half of the audio buffer has been played. + // Since audio could play at a faster or slower pace, wake up twice + // as often as ideally needed. + timeout = ao->device_buffer / (double)ao->samplerate * 0.25; p->ao_wait_low_buffer = false; - // If the AO doesn't tell us, we need to guess. - if (p->draining) - timeout = MPMAX(timeout, 0.1); } pthread_mutex_unlock(&p->lock); |