pcm: direct: Fix for sync issue on xrun recover

If using very short periods, DSHARE/DSNOOP/DMIX may report underruns while in
status 'prepared'. This prohibits correct recovery. Now slave xrun conditions
for DSHARE/DSNOOP/DMIX are being handled properly.

Signed-off-by: Andreas Pape <apape@de.adit-jv.com>
Signed-off-by: Joshua Frkuska <joshua_frkuska@mentor.com>
Signed-off-by: Mounesh Sutar <mounesh_sutar@mentor.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Andreas Pape 2017-01-10 12:03:36 +05:30 committed by Takashi Iwai
parent 3f0dc404f1
commit 1a9bd0f044
5 changed files with 162 additions and 16 deletions

View file

@ -550,6 +550,101 @@ int snd_pcm_direct_timer_stop(snd_pcm_direct_t *dmix)
return 0;
}
/*
* Recover slave on XRUN.
* Even if direct plugins disable xrun detection, there might be an xrun
* raised directly by some drivers.
* The first client recovers slave pcm.
* Each client needs to execute sw xrun handling afterwards
*/
int snd_pcm_direct_slave_recover(snd_pcm_direct_t *direct)
{
int ret;
int semerr;
semerr = snd_pcm_direct_semaphore_down(direct,
DIRECT_IPC_SEM_CLIENT);
if (semerr < 0) {
SNDERR("SEMDOWN FAILED with err %d", semerr);
return semerr;
}
if (snd_pcm_state(direct->spcm) != SND_PCM_STATE_XRUN) {
/* ignore... someone else already did recovery */
semerr = snd_pcm_direct_semaphore_up(direct,
DIRECT_IPC_SEM_CLIENT);
if (semerr < 0) {
SNDERR("SEMUP FAILED with err %d", semerr);
return semerr;
}
return 0;
}
ret = snd_pcm_prepare(direct->spcm);
if (ret < 0) {
SNDERR("recover: unable to prepare slave");
semerr = snd_pcm_direct_semaphore_up(direct,
DIRECT_IPC_SEM_CLIENT);
if (semerr < 0) {
SNDERR("SEMUP FAILED with err %d", semerr);
return semerr;
}
return ret;
}
if (direct->type == SND_PCM_TYPE_DSHARE) {
const snd_pcm_channel_area_t *dst_areas;
dst_areas = snd_pcm_mmap_areas(direct->spcm);
snd_pcm_areas_silence(dst_areas, 0, direct->spcm->channels,
direct->spcm->buffer_size,
direct->spcm->format);
}
ret = snd_pcm_start(direct->spcm);
if (ret < 0) {
SNDERR("recover: unable to start slave");
semerr = snd_pcm_direct_semaphore_up(direct,
DIRECT_IPC_SEM_CLIENT);
if (semerr < 0) {
SNDERR("SEMUP FAILED with err %d", semerr);
return semerr;
}
return ret;
}
direct->shmptr->recoveries++;
semerr = snd_pcm_direct_semaphore_up(direct,
DIRECT_IPC_SEM_CLIENT);
if (semerr < 0) {
SNDERR("SEMUP FAILED with err %d", semerr);
return semerr;
}
return 0;
}
/*
* enter xrun state, if slave xrun occurred
* @return: 0 - no xrun >0: xrun happened
*/
int snd_pcm_direct_client_chk_xrun(snd_pcm_direct_t *direct, snd_pcm_t *pcm)
{
if (direct->shmptr->recoveries != direct->recoveries) {
/* no matter how many xruns we missed -
* so don't increment but just update to actual counter
*/
direct->recoveries = direct->shmptr->recoveries;
pcm->fast_ops->drop(pcm);
/* trigger_tstamp update is missing in drop callbacks */
gettimestamp(&direct->trigger_tstamp, pcm->tstamp_type);
/* no timer clear:
* if slave already entered xrun again the event is lost.
* snd_pcm_direct_clear_timer_queue(direct);
*/
direct->state = SND_PCM_STATE_XRUN;
return 1;
}
return 0;
}
int snd_pcm_direct_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
{
snd_pcm_direct_t *dmix = pcm->private_data;
@ -572,6 +667,12 @@ int snd_pcm_direct_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned in
}
switch (snd_pcm_state(dmix->spcm)) {
case SND_PCM_STATE_XRUN:
/* recover slave and update client state to xrun
* before returning POLLERR
*/
snd_pcm_direct_slave_recover(dmix);
snd_pcm_direct_client_chk_xrun(dmix, pcm);
/* fallthrough */
case SND_PCM_STATE_SUSPENDED:
case SND_PCM_STATE_SETUP:
events |= POLLERR;
@ -1382,6 +1483,7 @@ int snd_pcm_direct_open_secondary_client(snd_pcm_t **spcmp, snd_pcm_direct_t *dm
dmix->slave_buffer_size = spcm->buffer_size;
dmix->slave_period_size = dmix->shmptr->s.period_size;
dmix->slave_boundary = spcm->boundary;
dmix->recoveries = dmix->shmptr->recoveries;
ret = snd_pcm_mmap(spcm);
if (ret < 0) {