diff options
author | wm4 <wm4@nowhere> | 2020-06-01 15:48:45 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-06-01 15:48:45 +0200 |
commit | c5158b057c8d0936ea12c5bc3153903263f03947 (patch) | |
tree | b4de2e885f54db7d3e04594c6f27d4cfa6de88a2 /audio/out/buffer.c | |
parent | 57462580180ecc9006b625b94e895a38e1118f69 (diff) | |
download | mpv-c5158b057c8d0936ea12c5bc3153903263f03947.tar.bz2 mpv-c5158b057c8d0936ea12c5bc3153903263f03947.tar.xz |
audio: reduce extra wakeups caused by recent changes
The feeder thread basically woke up the core and itself too often, and
caused some CPU overhead. This was caused by the recent buffer.c
changes.
For one, do not let ao_read_data() wake up the core, and instead rely on
the feeder thread's own buffer management. This is a bit strange, since
the change intended to unify the buffer management, but being more
consequent about it is better deferred to later, when the buffer
management changes again anyway. And also, the "more" condition in the
feeder thread seems outdated, or at least what made it make sense has
been destroyed, so do something that may or may not be better. In any
case, I'm still not getting underruns with ao_alsa, but the wakeup
hammering is gone.
Diffstat (limited to 'audio/out/buffer.c')
-rw-r--r-- | audio/out/buffer.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/audio/out/buffer.c b/audio/out/buffer.c index 0e92ef5911..f8cf966ae6 100644 --- a/audio/out/buffer.c +++ b/audio/out/buffer.c @@ -239,7 +239,8 @@ int ao_read_data(struct ao *ao, void **data, int samples, int64_t out_time_us) mp_ring_read(p->buffers[n], data[n], bytes); // Half of the buffer played -> request more. - need_wakeup = buffered_bytes - bytes <= mp_ring_size(p->buffers[0]) / 2; + if (!ao->driver->write) + need_wakeup = buffered_bytes - bytes <= mp_ring_size(p->buffers[0]) / 2; end: @@ -652,11 +653,9 @@ static void ao_play_data(struct ao *ao) p->ao_wait_low_buffer = space == 0 || written > 0 || p->draining; p->still_playing |= samples > 0 && !play_silence; - // If we just filled the AO completely (r == space), don't refill for a - // while. Prevents wakeup feedback with byte-granular AOs. + // Request more data if we're below some random buffer level. int needed = unlocked_get_space(ao); - bool more = needed >= (written == space ? ao->device_buffer / 4 : 1) && - !p->final_chunk; + bool more = needed >= ao->device_buffer / 4 && !p->final_chunk; if (more) ao->wakeup_cb(ao->wakeup_ctx); // request more data MP_TRACE(ao, "in=%d eof=%d space=%d r=%d wa/pl/dr=%d/%d/%d needed=%d more=%d\n", |