From 08b198aab49f73829bb02a25bc46bd159b6f9c6e Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 2 Jun 2020 20:30:59 +0200 Subject: audio: further simplify internal audio API somewhat Instead of the relatively subtle underflow handling, simply signal whether the stream is in a playing state. Should make it more robust. Should affect ao_alsa and ao_pulse only (and ao_openal, but it's broken). For ao_pulse, I'm just guessing. How the hell do you query whether a stream is playing? Who knows. Seems to work, judging from very superficial testing. --- audio/out/ao_pulse.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'audio/out/ao_pulse.c') diff --git a/audio/out/ao_pulse.c b/audio/out/ao_pulse.c index 563848b523..c826a6c993 100644 --- a/audio/out/ao_pulse.c +++ b/audio/out/ao_pulse.c @@ -52,7 +52,7 @@ struct priv { struct pa_sink_input_info pi; int retval; - bool underrun; + bool playing; char *cfg_host; int cfg_buffer; @@ -134,7 +134,7 @@ static void underflow_cb(pa_stream *s, void *userdata) { struct ao *ao = userdata; struct priv *priv = ao->priv; - priv->underrun = true; + priv->playing = false; ao_wakeup_playthread(ao); pa_threaded_mainloop_signal(priv->mainloop, 0); } @@ -486,9 +486,15 @@ static void cork(struct ao *ao, bool pause) struct priv *priv = ao->priv; pa_threaded_mainloop_lock(priv->mainloop); priv->retval = 0; - if (!waitop(priv, pa_stream_cork(priv->stream, pause, success_cb, ao)) || - !priv->retval) + if (waitop_no_unlock(priv, pa_stream_cork(priv->stream, pause, success_cb, ao)) + && priv->retval) + { + priv->playing = true; + } else { GENERIC_ERR_MSG("pa_stream_cork() failed"); + priv->playing = false; + } + pa_threaded_mainloop_unlock(priv->mainloop); } // Play the specified data to the pulseaudio server @@ -614,14 +620,13 @@ static void audio_get_state(struct ao *ao, struct mp_pcm_state *state) state->delay = get_delay_pulse(ao); } - state->underrun = priv->underrun; - priv->underrun = false; + state->playing = priv->playing; pa_threaded_mainloop_unlock(priv->mainloop); // Otherwise, PA will keep hammering us for underruns (which it does instead // of stopping the stream automatically). - if (state->underrun) + if (!state->playing) cork(ao, true); } -- cgit v1.2.3