From 7a7a0a78b518180bfb48a42e23acac6c801ed5cf Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 12 Jul 2020 23:25:56 +0200 Subject: ao/pulse: fix reporting of playing state When get_state() corks the stream after an underrun happens priv->playing is incorrectly reset to true, which can cause the player to miss the underrun entirely. Stop resetting priv->playing during corking (but not uncorking) to fix this. --- audio/out/ao_pulse.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/audio/out/ao_pulse.c b/audio/out/ao_pulse.c index 31c84e06ff..6cea79103b 100644 --- a/audio/out/ao_pulse.c +++ b/audio/out/ao_pulse.c @@ -53,6 +53,7 @@ struct priv { int retval; bool playing; + bool underrun_signalled; char *cfg_host; int cfg_buffer; @@ -135,6 +136,7 @@ static void underflow_cb(pa_stream *s, void *userdata) struct ao *ao = userdata; struct priv *priv = ao->priv; priv->playing = false; + priv->underrun_signalled = true; ao_wakeup_playthread(ao); pa_threaded_mainloop_signal(priv->mainloop, 0); } @@ -497,7 +499,8 @@ static void cork(struct ao *ao, bool pause) if (waitop_no_unlock(priv, pa_stream_cork(priv->stream, pause, success_cb, ao)) && priv->retval) { - priv->playing = true; + if (!pause) + priv->playing = true; } else { GENERIC_ERR_MSG("pa_stream_cork() failed"); priv->playing = false; @@ -634,8 +637,10 @@ static void audio_get_state(struct ao *ao, struct mp_pcm_state *state) // Otherwise, PA will keep hammering us for underruns (which it does instead // of stopping the stream automatically). - if (!state->playing) + if (!state->playing && priv->underrun_signalled) { reset(ao); + priv->underrun_signalled = false; + } } /* A callback function that is called when the -- cgit v1.2.3