[alsa] Avoid call to snd_pcm_prepare if already in the right state

This commit is contained in:
ejurgensen 2016-04-12 23:23:29 +02:00
parent 19181007f4
commit e23fed4ac4

View File

@ -531,15 +531,23 @@ static void
playback_start(struct alsa_session *as, uint64_t pos, uint64_t start_pos) playback_start(struct alsa_session *as, uint64_t pos, uint64_t start_pos)
{ {
snd_output_t *output; snd_output_t *output;
snd_pcm_state_t state;
char *debug_pcm_cfg; char *debug_pcm_cfg;
int ret; int ret;
state = snd_pcm_state(hdl);
if (state != SND_PCM_STATE_PREPARED)
{
if (state == SND_PCM_STATE_RUNNING)
snd_pcm_drop(hdl);
ret = snd_pcm_prepare(hdl); ret = snd_pcm_prepare(hdl);
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_LAUDIO, "Could not prepare ALSA device '%s': %s\n", as->devname, snd_strerror(ret)); DPRINTF(E_LOG, L_LAUDIO, "Could not prepare ALSA device '%s' (state %d): %s\n", as->devname, state, snd_strerror(ret));
return; return;
} }
}
// Clear prebuffer in case start somehow got called twice without a stop in between // Clear prebuffer in case start somehow got called twice without a stop in between
prebuf_free(as); prebuf_free(as);