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/ao_alsa.c | 7 ------- audio/out/ao_lavc.c | 6 ------ audio/out/ao_null.c | 1 - audio/out/ao_openal.c | 11 ----------- audio/out/ao_pulse.c | 10 ---------- audio/out/buffer.c | 22 ++++++++++++---------- audio/out/internal.h | 3 --- 7 files changed, 12 insertions(+), 48 deletions(-) (limited to 'audio') diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c index b4fa18891b..e100c0fb12 100644 --- a/audio/out/ao_alsa.c +++ b/audio/out/ao_alsa.c @@ -944,12 +944,6 @@ static int init(struct ao *ao) return r; } -static void drain(struct ao *ao) -{ - struct priv *p = ao->priv; - snd_pcm_drain(p->alsa); -} - static int get_space(struct ao *ao) { struct priv *p = ao->priv; @@ -1260,7 +1254,6 @@ const struct ao_driver audio_out_alsa = { .pause = audio_pause, .resume = audio_resume, .reset = reset, - .drain = drain, .wait = audio_wait, .wakeup = ao_wakeup_poll, .list_devs = list_devs, diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c index a38c01e0b2..ad3865964c 100644 --- a/audio/out/ao_lavc.c +++ b/audio/out/ao_lavc.c @@ -345,11 +345,6 @@ static int play(struct ao *ao, void **data, int samples, int flags) return taken; } -static void drain(struct ao *ao) -{ - // pretend we support it, so generic code doesn't force a wait -} - const struct ao_driver audio_out_lavc = { .encode = true, .description = "audio encoding using libavcodec", @@ -361,7 +356,6 @@ const struct ao_driver audio_out_lavc = { .uninit = uninit, .get_space = get_space, .play = play, - .drain = drain, }; // vim: sw=4 ts=4 et tw=80 diff --git a/audio/out/ao_null.c b/audio/out/ao_null.c index 7e15b58e00..3c3ecc36a8 100644 --- a/audio/out/ao_null.c +++ b/audio/out/ao_null.c @@ -229,7 +229,6 @@ const struct ao_driver audio_out_null = { .get_delay = get_delay, .pause = pause, .resume = resume, - .drain = wait_drain, .priv_size = sizeof(struct priv), .priv_defaults = &(const struct priv) { .bufferlen = 0.2, diff --git a/audio/out/ao_openal.c b/audio/out/ao_openal.c index 53fcaca05e..aa20fb8bed 100644 --- a/audio/out/ao_openal.c +++ b/audio/out/ao_openal.c @@ -274,16 +274,6 @@ err_out: return -1; } -static void drain(struct ao *ao) -{ - ALint state; - alGetSourcei(source, AL_SOURCE_STATE, &state); - while (state == AL_PLAYING) { - mp_sleep_us(10000); - alGetSourcei(source, AL_SOURCE_STATE, &state); - } -} - static void unqueue_buffers(struct ao *ao) { struct priv *q = ao->priv; @@ -420,7 +410,6 @@ const struct ao_driver audio_out_openal = { .pause = audio_pause, .resume = audio_resume, .reset = reset, - .drain = drain, .priv_size = sizeof(struct priv), .priv_defaults = &(const struct priv) { .num_buffers = 4, diff --git a/audio/out/ao_pulse.c b/audio/out/ao_pulse.c index fc5fb0caeb..c90ee255c9 100644 --- a/audio/out/ao_pulse.c +++ b/audio/out/ao_pulse.c @@ -278,15 +278,6 @@ static bool select_chmap(struct ao *ao, pa_channel_map *dst) chmap_pa_from_mp(dst, &ao->channels); } -static void drain(struct ao *ao) -{ - struct priv *priv = ao->priv; - if (priv->stream) { - pa_threaded_mainloop_lock(priv->mainloop); - waitop(priv, pa_stream_drain(priv->stream, success_cb, ao)); - } -} - static void uninit(struct ao *ao) { struct priv *priv = ao->priv; @@ -826,7 +817,6 @@ const struct ao_driver audio_out_pulse = { .get_delay = get_delay, .pause = pause, .resume = resume, - .drain = drain, .wait = wait_audio, .wakeup = wakeup, .hotplug_init = hotplug_init, 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); } diff --git a/audio/out/internal.h b/audio/out/internal.h index c036ebad16..71f98304be 100644 --- a/audio/out/internal.h +++ b/audio/out/internal.h @@ -107,7 +107,6 @@ bool init_buffer_post(struct ao *ao); * resume * Optional: * control - * drain * wait * wakeup * b) ->play must be NULL. ->resume must be provided, and should make the @@ -162,8 +161,6 @@ struct ao_driver { int (*play)(struct ao *ao, void **data, int samples, int flags); // push based: see ao_get_delay() double (*get_delay)(struct ao *ao); - // push based: block until all queued audio is played (optional) - void (*drain)(struct ao *ao); // Optional. Return true if audio has stopped in any way. bool (*get_eof)(struct ao *ao); // Wait until the audio buffer needs to be refilled. The lock is the -- cgit v1.2.3