summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Ekström <jeebjp@gmail.com>2020-11-04 23:30:54 +0200
committersfan5 <sfan5@live.de>2020-11-09 16:12:49 +0100
commit976fcf57c17da91e37be781cb86664d4510bbe4e (patch)
tree116510c138ab8c1d22d17c2860ba7bf0b2066bb3
parent4c4d9d6d5249f2fc35e05c71d01775b040198073 (diff)
downloadmpv-976fcf57c17da91e37be781cb86664d4510bbe4e.tar.bz2
mpv-976fcf57c17da91e37be781cb86664d4510bbe4e.tar.xz
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.
-rw-r--r--audio/out/ao_alsa.c16
1 files 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)