From 976fcf57c17da91e37be781cb86664d4510bbe4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= Date: Wed, 4 Nov 2020 23:30:54 +0200 Subject: ao_alsa: always initialize state if passed Based on ao_play_data's assert, we are always expected to give non-default values back from an AO's get_state. --- audio/out/ao_alsa.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c index 24f3355047..cbb3bc7c78 100644 --- a/audio/out/ao_alsa.c +++ b/audio/out/ao_alsa.c @@ -915,7 +915,7 @@ static int init(struct ao *ao) // Function for dealing with playback state. This attempts to recover the ALSA // state (bring it into SND_PCM_STATE_{PREPARED,RUNNING,PAUSED,UNDERRUN}). If -// state!=NULL, fill it after recovery. +// state!=NULL, fill it after recovery is attempted. // Returns true if PCM is in one the expected states. static bool recover_and_get_state(struct ao *ao, struct mp_pcm_state *state) { @@ -983,19 +983,20 @@ static bool recover_and_get_state(struct ao *ao, struct mp_pcm_state *state) ao_request_reload(ao); p->device_lost = true; } - return false; + goto alsa_error; } } if (!state_ok) { MP_ERR(ao, "could not recover\n"); - return false; } +alsa_error: + if (state) { - snd_pcm_sframes_t del = snd_pcm_status_get_delay(st); + snd_pcm_sframes_t del = state_ok ? snd_pcm_status_get_delay(st) : 0; state->delay = MPMAX(del, 0) / (double)ao->samplerate; - state->free_samples = snd_pcm_status_get_avail(st); + state->free_samples = state_ok ? snd_pcm_status_get_avail(st) : 0; state->free_samples = MPCLAMP(state->free_samples, 0, ao->device_buffer); // Align to period size. state->free_samples = state->free_samples / p->outburst * p->outburst; @@ -1004,10 +1005,7 @@ static bool recover_and_get_state(struct ao *ao, struct mp_pcm_state *state) pcmst == SND_PCM_STATE_PAUSED; } - return true; - -alsa_error: - return false; + return state_ok; } static void audio_get_state(struct ao *ao, struct mp_pcm_state *state) -- cgit v1.2.3