diff options
author | wm4 <wm4@nowhere> | 2013-11-13 19:39:18 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-11-13 20:10:17 +0100 |
commit | 621cff80df1f17f883e2ec028a4fe3d1f2470c0f (patch) | |
tree | 8df6048434fca83a10c02d18e79eaa868b78a23c /audio/out/ao_null.c | |
parent | 894bf603e8ecb370dcf31b25c1598b4e5f454997 (diff) | |
download | mpv-621cff80df1f17f883e2ec028a4fe3d1f2470c0f.tar.bz2 mpv-621cff80df1f17f883e2ec028a4fe3d1f2470c0f.tar.xz |
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.
Diffstat (limited to 'audio/out/ao_null.c')
-rw-r--r-- | audio/out/ao_null.c | 18 |
1 files changed, 14 insertions, 4 deletions
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, }; - |