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.
This commit is contained in:
wm4 2020-06-03 15:22:18 +02:00
parent 416d3f2c00
commit baa7b5c8dd
1 changed files with 4 additions and 6 deletions

View File

@ -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);