From e16c91d07ab2acfb83fdeaa6dcfcd25c97666504 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 9 Mar 2014 00:49:39 +0100 Subject: audio/out: make draining a separate operation Until now, this was always conflated with uninit. This was ugly, and also many AOs emulated this manually (or just ignored it). Make draining an explicit operation, so AOs which support it can provide it, and for all others generic code will emulate it. For ao_wasapi, we keep it simple and basically disable the internal draining implementation (maybe it should be restored later). Tested on Linux only. --- audio/out/ao.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'audio/out/ao.c') diff --git a/audio/out/ao.c b/audio/out/ao.c index f1e88d2a10..ee8bc2a254 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -235,11 +235,10 @@ done: return ao; } -// Uninitialize and destroy the AO. -// cut_audio: if false, block until all remaining audio was played. -void ao_uninit(struct ao *ao, bool cut_audio) +// Uninitialize and destroy the AO. Remaining audio must be dropped. +void ao_uninit(struct ao *ao) { - ao->api->uninit(ao, cut_audio); + ao->api->uninit(ao); talloc_free(ao); } @@ -315,13 +314,22 @@ void ao_resume(struct ao *ao) ao->api->resume(ao); } -// Wait until the audio buffer is drained. This can be used to emulate draining -// if native functionality is not available. -// Only call this on uninit (otherwise, deadlock trouble ahead). +// Be careful with locking void ao_wait_drain(struct ao *ao) { // This is probably not entirely accurate, but good enough. mp_sleep_us(ao_get_delay(ao) * 1000000); + ao_reset(ao); +} + +// Block until the current audio buffer has played completely. +void ao_drain(struct ao *ao) +{ + if (ao->api->drain) { + ao->api->drain(ao); + } else { + ao_wait_drain(ao); + } } bool ao_chmap_sel_adjust(struct ao *ao, const struct mp_chmap_sel *s, -- cgit v1.2.3