pcm: dmix: Handle slave PCM xrun and unexpected states properly

Currently, dmix & co plugins ignore the XRUN state of the slave PCM.
It's (supposedly) because dmix deals with the PCM in a free-wheel
mode, which is equivalent with XRUN.  But, this difference (whether
the correct freewheel or XRUN) should be done by the kernel, and we
may have an XRUN state indeed (e.g. via xrun injection).

This patch fixes this lack of behavior, to handle PCM xrun and does
prepare when the slave PCM is in such a state.

Also, the patch consolidates the prepare callback for all dmix, dsnoop
and dshare plugins, and fix/cleanup a bit for dshare/dsnoop codes to
align with dsnoop code.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2015-10-30 17:13:50 +01:00
parent 99dc70f023
commit 8985742d91
5 changed files with 42 additions and 44 deletions

View file

@ -807,6 +807,28 @@ int snd_pcm_direct_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
return snd_pcm_set_chmap(dmix->spcm, map);
}
int snd_pcm_direct_prepare(snd_pcm_t *pcm)
{
snd_pcm_direct_t *dmix = pcm->private_data;
int err;
switch (snd_pcm_state(dmix->spcm)) {
case SND_PCM_STATE_XRUN:
case SND_PCM_STATE_SUSPENDED:
case SND_PCM_STATE_DISCONNECTED:
err = snd_pcm_prepare(dmix->spcm);
if (err < 0)
return err;
snd_pcm_start(dmix->spcm);
break;
}
snd_pcm_direct_check_interleave(dmix, pcm);
dmix->state = SND_PCM_STATE_PREPARED;
dmix->appl_ptr = dmix->last_appl_ptr = 0;
dmix->hw_ptr = 0;
return snd_pcm_direct_set_timer_params(dmix);
}
int snd_pcm_direct_resume(snd_pcm_t *pcm)
{
snd_pcm_direct_t *dmix = pcm->private_data;