- Backport upstream fix patches, including the deadlock fix for aplay/arecord (boo#1031525): 0001-ucm-Add-ATTRIBUTE_UNUSED-for-unused-parameters-of-ex.patch 0002-ucm-parser-needs-limits.h.patch 0003-pcm-direct-allow-users-to-configure-different-period.patch 0004-pcm-dshare-enable-silence.patch 0005-pcm-rate-fix-the-hw_ptr-update-until-the-boundary-av.patch 0006-plugin-dynamically-update-avail_min-on-slave.patch 0007-rate-dynamic-update-avail_min-on-slave.patch 0008-topology-fix-unused-const-variable-warning.patch 0009-seq-improve-documentation-about-new-get-pid-card-fun.patch 0010-pcm-direct-returning-semop-error-code-for-semaphore-.patch 0011-pcm-direct-Fix-for-sync-issue-on-xrun-recover.patch 0012-pcm-direct-check-state-before-enter-poll-on-timer.patch 0013-pcm-direct-don-t-return-bogus-buffer-levels-in-xrun-.patch 0014-conf-ucm-broxton-add-broxton-rt298-conf-files.patch 0015-pcm-direct-Fix-deadlock-in-poll_descriptors.patch 0016-ucm-Assure-the-user-input-card-name-not-to-exceed-ma.patch 0017-ucm-Load-device-specific-configuration-file-based-on.patch 0018-ucm-Add-command-get-_file-to-get-the-config-file-nam.patch 0019-topology-Fix-incorrect-license-in-source-comments.patch 0020-conf-cards-add-support-for-pistachio-card.patch 0021-pcm-multi-Drop-the-fixed-slave_map-in-snd_pcm_multi_.patch 0022-conf-Add-card-config-for-Intel-HDMI-DP-LPE-audio.patch 0023-pcm-Avoid-lock-for-snd_pcm_nonblock.patch 0024-pcm-Disable-locking-in-async-mode.patch 0025-pcm-dmix-Allow-disabling-x86-optimizations.patch 0026-pcm-dmix_rewind-corrupts-application-pointer-fix.patch 0027-pcm-direct-fix-race-on-clearing-timer-events.patch 0028-pcm-file-Enable-file-writing-for-capture-path.patch OBS-URL: https://build.opensuse.org/request/show/483406 OBS-URL: https://build.opensuse.org/package/show/multimedia:libs/alsa?expand=0&rev=210
371 lines
11 KiB
Diff
371 lines
11 KiB
Diff
From 1a9bd0f0448106b917ae7f7bedccfcbf6ce84802 Mon Sep 17 00:00:00 2001
|
|
From: Andreas Pape <apape@de.adit-jv.com>
|
|
Date: Tue, 10 Jan 2017 12:03:36 +0530
|
|
Subject: [PATCH 11/43] 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>
|
|
---
|
|
src/pcm/pcm_direct.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
src/pcm/pcm_direct.h | 5 ++
|
|
src/pcm/pcm_dmix.c | 27 ++++++++++---
|
|
src/pcm/pcm_dshare.c | 29 +++++++++++---
|
|
src/pcm/pcm_dsnoop.c | 15 ++++++-
|
|
5 files changed, 162 insertions(+), 16 deletions(-)
|
|
|
|
--- a/src/pcm/pcm_direct.c
|
|
+++ b/src/pcm/pcm_direct.c
|
|
@@ -550,6 +550,101 @@ int snd_pcm_direct_timer_stop(snd_pcm_di
|
|
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_
|
|
}
|
|
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
|
|
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) {
|
|
--- a/src/pcm/pcm_direct.h
|
|
+++ b/src/pcm/pcm_direct.h
|
|
@@ -66,6 +66,7 @@ typedef struct {
|
|
char socket_name[256]; /* name of communication socket */
|
|
snd_pcm_type_t type; /* PCM type (currently only hw) */
|
|
int use_server;
|
|
+ unsigned int recoveries; /* no of executed recoveries on slave*/
|
|
struct {
|
|
unsigned int format;
|
|
snd_interval_t rate;
|
|
@@ -157,6 +158,7 @@ struct snd_pcm_direct {
|
|
int var_periodsize; /* allow variable period size if max_periods is != -1*/
|
|
unsigned int channels; /* client's channels */
|
|
unsigned int *bindings;
|
|
+ unsigned int recoveries; /* mirror of executed recoveries on slave */
|
|
union {
|
|
struct {
|
|
int shmid_sum; /* IPC global sum ring buffer memory identification */
|
|
@@ -324,7 +326,8 @@ int snd_pcm_direct_open_secondary_client
|
|
snd_pcm_chmap_query_t **snd_pcm_direct_query_chmaps(snd_pcm_t *pcm);
|
|
snd_pcm_chmap_t *snd_pcm_direct_get_chmap(snd_pcm_t *pcm);
|
|
int snd_pcm_direct_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map);
|
|
-
|
|
+int snd_pcm_direct_slave_recover(snd_pcm_direct_t *direct);
|
|
+int snd_pcm_direct_client_chk_xrun(snd_pcm_direct_t *direct, snd_pcm_t *pcm);
|
|
int snd_timer_async(snd_timer_t *timer, int sig, pid_t pid);
|
|
struct timespec snd_pcm_hw_fast_tstamp(snd_pcm_t *pcm);
|
|
|
|
--- a/src/pcm/pcm_dmix.c
|
|
+++ b/src/pcm/pcm_dmix.c
|
|
@@ -434,15 +434,21 @@ static int snd_pcm_dmix_sync_ptr0(snd_pc
|
|
static int snd_pcm_dmix_sync_ptr(snd_pcm_t *pcm)
|
|
{
|
|
snd_pcm_direct_t *dmix = pcm->private_data;
|
|
+ int err;
|
|
|
|
switch (snd_pcm_state(dmix->spcm)) {
|
|
case SND_PCM_STATE_DISCONNECTED:
|
|
dmix->state = SND_PCM_STATE_DISCONNECTED;
|
|
return -ENODEV;
|
|
+ case SND_PCM_STATE_XRUN:
|
|
+ if ((err = snd_pcm_direct_slave_recover(dmix)) < 0)
|
|
+ return err;
|
|
+ break;
|
|
default:
|
|
break;
|
|
}
|
|
-
|
|
+ if (snd_pcm_direct_client_chk_xrun(dmix, pcm))
|
|
+ return -EPIPE;
|
|
if (dmix->slowptr)
|
|
snd_pcm_hwsync(dmix->spcm);
|
|
|
|
@@ -828,12 +834,16 @@ static snd_pcm_sframes_t snd_pcm_dmix_mm
|
|
|
|
switch (snd_pcm_state(dmix->spcm)) {
|
|
case SND_PCM_STATE_XRUN:
|
|
- return -EPIPE;
|
|
+ if ((err = snd_pcm_direct_slave_recover(dmix)) < 0)
|
|
+ return err;
|
|
+ break;
|
|
case SND_PCM_STATE_SUSPENDED:
|
|
return -ESTRPIPE;
|
|
default:
|
|
break;
|
|
}
|
|
+ if (snd_pcm_direct_client_chk_xrun(dmix, pcm))
|
|
+ return -EPIPE;
|
|
if (! size)
|
|
return 0;
|
|
snd_pcm_mmap_appl_forward(pcm, size);
|
|
@@ -841,8 +851,10 @@ static snd_pcm_sframes_t snd_pcm_dmix_mm
|
|
if ((err = snd_pcm_dmix_start_timer(pcm, dmix)) < 0)
|
|
return err;
|
|
} else if (dmix->state == SND_PCM_STATE_RUNNING ||
|
|
- dmix->state == SND_PCM_STATE_DRAINING)
|
|
- snd_pcm_dmix_sync_ptr(pcm);
|
|
+ dmix->state == SND_PCM_STATE_DRAINING) {
|
|
+ if ((err = snd_pcm_dmix_sync_ptr(pcm)) < 0)
|
|
+ return err;
|
|
+ }
|
|
if (dmix->state == SND_PCM_STATE_RUNNING ||
|
|
dmix->state == SND_PCM_STATE_DRAINING) {
|
|
/* ok, we commit the changes after the validation of area */
|
|
@@ -858,10 +870,13 @@ static snd_pcm_sframes_t snd_pcm_dmix_mm
|
|
static snd_pcm_sframes_t snd_pcm_dmix_avail_update(snd_pcm_t *pcm)
|
|
{
|
|
snd_pcm_direct_t *dmix = pcm->private_data;
|
|
+ int err;
|
|
|
|
if (dmix->state == SND_PCM_STATE_RUNNING ||
|
|
- dmix->state == SND_PCM_STATE_DRAINING)
|
|
- snd_pcm_dmix_sync_ptr(pcm);
|
|
+ dmix->state == SND_PCM_STATE_DRAINING) {
|
|
+ if ((err = snd_pcm_dmix_sync_ptr(pcm)) < 0)
|
|
+ return err;
|
|
+ }
|
|
return snd_pcm_mmap_playback_avail(pcm);
|
|
}
|
|
|
|
--- a/src/pcm/pcm_dshare.c
|
|
+++ b/src/pcm/pcm_dshare.c
|
|
@@ -162,7 +162,7 @@ static int snd_pcm_dshare_sync_ptr0(snd_
|
|
snd_pcm_direct_t *dshare = pcm->private_data;
|
|
snd_pcm_uframes_t old_slave_hw_ptr, avail;
|
|
snd_pcm_sframes_t diff;
|
|
-
|
|
+
|
|
old_slave_hw_ptr = dshare->slave_hw_ptr;
|
|
dshare->slave_hw_ptr = slave_hw_ptr;
|
|
diff = slave_hw_ptr - old_slave_hw_ptr;
|
|
@@ -202,15 +202,21 @@ static int snd_pcm_dshare_sync_ptr0(snd_
|
|
static int snd_pcm_dshare_sync_ptr(snd_pcm_t *pcm)
|
|
{
|
|
snd_pcm_direct_t *dshare = pcm->private_data;
|
|
+ int err;
|
|
|
|
switch (snd_pcm_state(dshare->spcm)) {
|
|
case SND_PCM_STATE_DISCONNECTED:
|
|
dshare->state = SNDRV_PCM_STATE_DISCONNECTED;
|
|
return -ENODEV;
|
|
+ case SND_PCM_STATE_XRUN:
|
|
+ if ((err = snd_pcm_direct_slave_recover(dshare)) < 0)
|
|
+ return err;
|
|
+ break;
|
|
default:
|
|
break;
|
|
}
|
|
-
|
|
+ if (snd_pcm_direct_client_chk_xrun(dshare, pcm))
|
|
+ return -EPIPE;
|
|
if (dshare->slowptr)
|
|
snd_pcm_hwsync(dshare->spcm);
|
|
|
|
@@ -516,12 +522,16 @@ static snd_pcm_sframes_t snd_pcm_dshare_
|
|
|
|
switch (snd_pcm_state(dshare->spcm)) {
|
|
case SND_PCM_STATE_XRUN:
|
|
- return -EPIPE;
|
|
+ if ((err = snd_pcm_direct_slave_recover(dshare)) < 0)
|
|
+ return err;
|
|
+ break;
|
|
case SND_PCM_STATE_SUSPENDED:
|
|
return -ESTRPIPE;
|
|
default:
|
|
break;
|
|
}
|
|
+ if (snd_pcm_direct_client_chk_xrun(dshare, pcm))
|
|
+ return -EPIPE;
|
|
if (! size)
|
|
return 0;
|
|
snd_pcm_mmap_appl_forward(pcm, size);
|
|
@@ -529,8 +539,10 @@ static snd_pcm_sframes_t snd_pcm_dshare_
|
|
if ((err = snd_pcm_dshare_start_timer(dshare)) < 0)
|
|
return err;
|
|
} else if (dshare->state == SND_PCM_STATE_RUNNING ||
|
|
- dshare->state == SND_PCM_STATE_DRAINING)
|
|
- snd_pcm_dshare_sync_ptr(pcm);
|
|
+ dshare->state == SND_PCM_STATE_DRAINING) {
|
|
+ if ((err = snd_pcm_dshare_sync_ptr(pcm)) < 0)
|
|
+ return err;
|
|
+ }
|
|
if (dshare->state == SND_PCM_STATE_RUNNING ||
|
|
dshare->state == SND_PCM_STATE_DRAINING) {
|
|
/* ok, we commit the changes after the validation of area */
|
|
@@ -546,10 +558,13 @@ static snd_pcm_sframes_t snd_pcm_dshare_
|
|
static snd_pcm_sframes_t snd_pcm_dshare_avail_update(snd_pcm_t *pcm)
|
|
{
|
|
snd_pcm_direct_t *dshare = pcm->private_data;
|
|
+ int err;
|
|
|
|
if (dshare->state == SND_PCM_STATE_RUNNING ||
|
|
- dshare->state == SND_PCM_STATE_DRAINING)
|
|
- snd_pcm_dshare_sync_ptr(pcm);
|
|
+ dshare->state == SND_PCM_STATE_DRAINING) {
|
|
+ if ((err = snd_pcm_dshare_sync_ptr(pcm)) < 0)
|
|
+ return err;
|
|
+ }
|
|
return snd_pcm_mmap_playback_avail(pcm);
|
|
}
|
|
|
|
--- a/src/pcm/pcm_dsnoop.c
|
|
+++ b/src/pcm/pcm_dsnoop.c
|
|
@@ -132,14 +132,21 @@ static int snd_pcm_dsnoop_sync_ptr(snd_p
|
|
snd_pcm_direct_t *dsnoop = pcm->private_data;
|
|
snd_pcm_uframes_t slave_hw_ptr, old_slave_hw_ptr, avail;
|
|
snd_pcm_sframes_t diff;
|
|
-
|
|
+ int err;
|
|
+
|
|
switch (snd_pcm_state(dsnoop->spcm)) {
|
|
case SND_PCM_STATE_DISCONNECTED:
|
|
dsnoop->state = SNDRV_PCM_STATE_DISCONNECTED;
|
|
return -ENODEV;
|
|
+ case SND_PCM_STATE_XRUN:
|
|
+ if ((err = snd_pcm_direct_slave_recover(dsnoop)) < 0)
|
|
+ return err;
|
|
+ break;
|
|
default:
|
|
break;
|
|
}
|
|
+ if (snd_pcm_direct_client_chk_xrun(dsnoop, pcm))
|
|
+ return -EPIPE;
|
|
if (dsnoop->slowptr)
|
|
snd_pcm_hwsync(dsnoop->spcm);
|
|
old_slave_hw_ptr = dsnoop->slave_hw_ptr;
|
|
@@ -410,12 +417,16 @@ static snd_pcm_sframes_t snd_pcm_dsnoop_
|
|
|
|
switch (snd_pcm_state(dsnoop->spcm)) {
|
|
case SND_PCM_STATE_XRUN:
|
|
- return -EPIPE;
|
|
+ if ((err = snd_pcm_direct_slave_recover(dsnoop)) < 0)
|
|
+ return err;
|
|
+ break;
|
|
case SND_PCM_STATE_SUSPENDED:
|
|
return -ESTRPIPE;
|
|
default:
|
|
break;
|
|
}
|
|
+ if (snd_pcm_direct_client_chk_xrun(dsnoop, pcm))
|
|
+ return -EPIPE;
|
|
if (dsnoop->state == SND_PCM_STATE_RUNNING) {
|
|
err = snd_pcm_dsnoop_sync_ptr(pcm);
|
|
if (err < 0)
|