mirror of
https://github.com/mpv-player/mpv
synced 2025-01-29 19:22:48 +00:00
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:
parent
416d3f2c00
commit
baa7b5c8dd
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user