From 9885952c2a0698e88ec34a2cb9fcef7a6fd69fbb Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 27 May 2020 21:04:32 +0200 Subject: audio: remove ao_driver.drain The recent change to the common code removed all calls to ->drain. It's currently emulated via a timed sleep and polling ao_eof_reached(). That is actually fallback code for AOs which lacked draining. I could just readd the drain call, but it was a bad idea anyway. My plan to handle this better is to require the AO to signal a underrun, even if AOPLAY_FINAL_CHUNK is not set. Also reinstate not possibly waiting for ao_lavc.c. ao_pcm.c did not have anything to handle this; whatever. --- audio/out/buffer.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'audio/out/buffer.c') diff --git a/audio/out/buffer.c b/audio/out/buffer.c index d890497113..0096d2f1f4 100644 --- a/audio/out/buffer.c +++ b/audio/out/buffer.c @@ -403,19 +403,21 @@ void ao_drain(struct ao *ao) p->final_chunk = true; wakeup_playthread(ao); double left = 0; - if (p->playing && !p->paused) + if (p->playing && !p->paused && !ao->driver->encode) left = mp_ring_buffered(p->buffers[0]) / (double)ao->bps * 1e6; pthread_mutex_unlock(&p->lock); - // Wait for lower bound. - mp_sleep_us(left); - // And then poll for actual end. (Unfortunately, this code considers - // audio APIs which do not want you to use mutexes in the audio - // callback, and an extra semaphore would require slightly more effort.) - // Limit to arbitrary ~250ms max. waiting for robustness. - int64_t max = mp_time_us() + 250000; - while (mp_time_us() < max && !ao_eof_reached(ao)) - mp_sleep_us(1); + if (left > 0) { + // Wait for lower bound. + mp_sleep_us(left); + // And then poll for actual end. (Unfortunately, this code considers + // audio APIs which do not want you to use mutexes in the audio + // callback, and an extra semaphore would require slightly more effort.) + // Limit to arbitrary ~250ms max. waiting for robustness. + int64_t max = mp_time_us() + 250000; + while (mp_time_us() < max && !ao_eof_reached(ao)) + mp_sleep_us(1); + } ao_reset(ao); } -- cgit v1.2.3