diff options
author | wm4 <wm4@nowhere> | 2020-08-29 16:27:56 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-08-29 16:27:56 +0200 |
commit | 478d39c57492107ce8d5a33e80d5624db330ceab (patch) | |
tree | 71c4cd38145f5256fdbfd06403fbd8da7a988c14 /audio/out/buffer.c | |
parent | 3427aa4776b73ce0b9c8996bc4ef38da87fe1557 (diff) | |
download | mpv-478d39c57492107ce8d5a33e80d5624db330ceab.tar.bz2 mpv-478d39c57492107ce8d5a33e80d5624db330ceab.tar.xz |
audio: fix inefficient behavior with ao_alsa, remove period_size field
It is now the AO's responsibility to handle period size alignment. The
ao->period_size alignment field is unused as of the recent audio
refactor commit. Remove it.
It turns out that ao_alsa shows extremely inefficient behavior as a
consequence of the removal of period size aligned writes in the
mentioned refactor commit. This is because it could get into a state
where it repeatedly wrote single samples (as small as 1 sample), and
starved the rest of the player as a consequence. Too bad. Explicitly
align the size in ao_alsa. Other AOs, which need this, should do the
same.
One reason why it broke so badly with ao_alsa was that it retried the
write() even if all reported space could be written. So stop doing that
too. Retry the write only if we somehow wrote less.
I'm not sure about ao_pulse.
Diffstat (limited to 'audio/out/buffer.c')
-rw-r--r-- | audio/out/buffer.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/audio/out/buffer.c b/audio/out/buffer.c index 4c08a26b0b..9cd7717000 100644 --- a/audio/out/buffer.c +++ b/audio/out/buffer.c @@ -619,7 +619,7 @@ static bool ao_play_data(struct ao *ao) if (got_eof) goto eof; - return samples > 0; + return samples > 0 && (samples < space || ao->untimed); eof: MP_VERBOSE(ao, "audio end or underrun\n"); @@ -642,14 +642,14 @@ static void *playthread(void *arg) while (1) { pthread_mutex_lock(&p->lock); - bool progress = false; + bool retry = false; if (!ao->driver->initially_blocked || p->initial_unblocked) - progress = ao_play_data(ao); + retry = ao_play_data(ao); // Wait until the device wants us to write more data to it. // Fallback to guessing. double timeout = INFINITY; - if (p->streaming && !p->paused && !progress) { + if (p->streaming && !p->paused && !retry) { // 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. @@ -663,7 +663,7 @@ static void *playthread(void *arg) pthread_mutex_unlock(&p->pt_lock); break; } - if (!p->need_wakeup && !progress) { + if (!p->need_wakeup && !retry) { MP_STATS(ao, "start audio wait"); struct timespec ts = mp_rel_time_to_timespec(timeout); pthread_cond_timedwait(&p->pt_wakeup, &p->pt_lock, &ts); |