From 621cff80df1f17f883e2ec028a4fe3d1f2470c0f Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 13 Nov 2013 19:39:18 +0100 Subject: ao_null: support pausing properly ao_null should simulate a "perfect" AO, but framestepping behaved quite badly with it. Framstepping usually exposes problems with AOs dropping their buffers on pause, and that's what happened here. --- audio/out/ao_null.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'audio') diff --git a/audio/out/ao_null.c b/audio/out/ao_null.c index 9fe289e3e4..3e51df8a4f 100644 --- a/audio/out/ao_null.c +++ b/audio/out/ao_null.c @@ -29,6 +29,7 @@ #include "ao.h" struct priv { + bool paused; double last_time; // All values are in samples float buffered; @@ -40,6 +41,9 @@ static void drain(struct ao *ao) { struct priv *priv = ao->priv; + if (priv->paused) + return; + double now = mp_time_sec(); priv->buffered -= (now - priv->last_time) * ao->samplerate; if (priv->buffered < 0) @@ -86,13 +90,19 @@ static void reset(struct ao *ao) // stop playing, keep buffers (for pause) static void pause(struct ao *ao) { - // for now, just call reset(); - reset(ao); + struct priv *priv = ao->priv; + + priv->paused = true; } -// resume playing, after audio_pause() +// resume playing, after pause() static void resume(struct ao *ao) { + struct priv *priv = ao->priv; + + drain(ao); + priv->paused = false; + priv->last_time = mp_time_sec(); } static int get_space(struct ao *ao) @@ -107,6 +117,7 @@ static int play(struct ao *ao, void **data, int samples, int flags) { struct priv *priv = ao->priv; + resume(ao); int maxbursts = (priv->buffersize - priv->buffered) / priv->outburst; int playbursts = samples / priv->outburst; int bursts = playbursts > maxbursts ? maxbursts : playbursts; @@ -134,4 +145,3 @@ const struct ao_driver audio_out_null = { .pause = pause, .resume = resume, }; - -- cgit v1.2.3