Blame SOURCES/alsa-git.patch

f29710
From ad8c8e5503980295dd8e5e54a6285d2d7e32eb1e Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Thu, 22 Oct 2020 20:57:32 +0200
f29710
Subject: [PATCH 01/49] dlmisc: the snd_plugin_dir_set / snd_plugin_dir must be
f29710
 declared even for \!DL_ORIGIN_AVAILABLE
f29710
f29710
Fixes: 8580c081c2 ("dlsym: add support for ALSA_PLUGIN_DIR environment variable")
f29710
BugLink: https://github.com/alsa-project/alsa-lib/issues/91
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/dlmisc.c | 2 --
f29710
 1 file changed, 2 deletions(-)
f29710
f29710
diff --git a/src/dlmisc.c b/src/dlmisc.c
f29710
index c9517c55..f20eb593 100644
f29710
--- a/src/dlmisc.c
f29710
+++ b/src/dlmisc.c
f29710
@@ -42,11 +42,9 @@
f29710
 #ifndef PIC
f29710
 struct snd_dlsym_link *snd_dlsym_start = NULL;
f29710
 #endif
f29710
-#ifdef DL_ORIGIN_AVAILABLE
f29710
 static int snd_plugin_dir_set = 0;
f29710
 static char *snd_plugin_dir = NULL;
f29710
 #endif
f29710
-#endif
c4a1f5
 
f29710
 #if defined(DL_ORIGIN_AVAILABLE) && defined(HAVE_LIBPTHREAD)
f29710
 static pthread_mutex_t snd_dlpath_mutex = PTHREAD_MUTEX_INITIALIZER;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 1d993b37ab4e0b9b6e6b795d7be84ce97b29e20b Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Thu, 29 Oct 2020 20:31:19 +0100
f29710
Subject: [PATCH 02/49] dlmisc: fix snd_plugin_dir locking for not
f29710
 DL_ORIGIN_AVAILABLE
f29710
f29710
Fixes: 8580c081c2 ("dlsym: add support for ALSA_PLUGIN_DIR environment variable")
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/dlmisc.c | 4 +---
f29710
 1 file changed, 1 insertion(+), 3 deletions(-)
f29710
f29710
diff --git a/src/dlmisc.c b/src/dlmisc.c
f29710
index f20eb593..1dd91356 100644
f29710
--- a/src/dlmisc.c
f29710
+++ b/src/dlmisc.c
f29710
@@ -46,7 +46,7 @@ static int snd_plugin_dir_set = 0;
f29710
 static char *snd_plugin_dir = NULL;
f29710
 #endif
c4a1f5
 
f29710
-#if defined(DL_ORIGIN_AVAILABLE) && defined(HAVE_LIBPTHREAD)
f29710
+#ifdef HAVE_LIBPTHREAD
f29710
 static pthread_mutex_t snd_dlpath_mutex = PTHREAD_MUTEX_INITIALIZER;
f29710
 
f29710
 static inline void snd_dlpath_lock(void)
f29710
@@ -440,12 +440,10 @@ void snd_dlobj_cache_cleanup(void)
f29710
 		free(c);
f29710
 	}
f29710
 	snd_dlobj_unlock();
f29710
-#ifdef DL_ORIGIN_AVAILABLE
f29710
 	snd_dlpath_lock();
f29710
 	snd_plugin_dir_set = 0;
f29710
 	free(snd_plugin_dir);
f29710
 	snd_plugin_dir = NULL;
f29710
 	snd_dlpath_unlock();
f29710
-#endif
f29710
 }
f29710
 #endif
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 2757191e3b85d491705b31c6ecca2dbd96d26ade Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Thu, 29 Oct 2020 20:34:17 +0100
f29710
Subject: [PATCH 03/49] pcm: snd_pcm_mmap_readi - fix typo in comment
f29710
f29710
\param size frames to be *read*
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_mmap.c | 2 +-
f29710
 1 file changed, 1 insertion(+), 1 deletion(-)
f29710
f29710
diff --git a/src/pcm/pcm_mmap.c b/src/pcm/pcm_mmap.c
f29710
index 9600c383..9cbaae05 100644
f29710
--- a/src/pcm/pcm_mmap.c
f29710
+++ b/src/pcm/pcm_mmap.c
f29710
@@ -183,7 +183,7 @@ snd_pcm_sframes_t snd_pcm_mmap_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_ufram
f29710
  * \brief Read interleaved frames from a PCM using direct buffer (mmap)
f29710
  * \param pcm PCM handle
f29710
  * \param buffer frames containing buffer
f29710
- * \param size frames to be written
f29710
+ * \param size frames to be read
f29710
  * \return a positive number of frames actually read otherwise a
f29710
  * negative error code
f29710
  * \retval -EBADFD PCM is not in the right state (#SND_PCM_STATE_PREPARED or #SND_PCM_STATE_RUNNING)
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 39bd0e1a5be3620f9123f7fe72ffa6cb7d463b21 Mon Sep 17 00:00:00 2001
f29710
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
f29710
Date: Thu, 12 Nov 2020 10:29:38 -0600
f29710
Subject: [PATCH 04/49] topology: use inclusive language for bclk
f29710
f29710
use bclk_provider for structure fields, 'codec_provider' and
f29710
'codec_consumer' for options and modify #defines to use CP and CC
f29710
suffixes.
f29710
f29710
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 include/sound/uapi/asoc.h | 11 +++++++----
f29710
 include/topology.h        |  2 +-
f29710
 src/topology/pcm.c        | 36 ++++++++++++++++++++++++++----------
f29710
 3 files changed, 34 insertions(+), 15 deletions(-)
f29710
c4a1f5
diff --git a/include/sound/uapi/asoc.h b/include/sound/uapi/asoc.h
f29710
index 4efb4ec4..ceafb1a9 100644
c4a1f5
--- a/include/sound/uapi/asoc.h
c4a1f5
+++ b/include/sound/uapi/asoc.h
f29710
@@ -169,10 +169,13 @@
c4a1f5
 #define SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP            (1 << 3)
c4a1f5
 
c4a1f5
 /* DAI topology BCLK parameter
c4a1f5
- * For the backwards capability, by default codec is bclk master
c4a1f5
+ * For the backwards capability, by default codec is bclk provider
c4a1f5
  */
c4a1f5
-#define SND_SOC_TPLG_BCLK_CM         0 /* codec is bclk master */
c4a1f5
-#define SND_SOC_TPLG_BCLK_CS         1 /* codec is bclk slave */
c4a1f5
+#define SND_SOC_TPLG_BCLK_CP         0 /* codec is bclk provider */
c4a1f5
+#define SND_SOC_TPLG_BCLK_CC         1 /* codec is bclk consumer */
c4a1f5
+/* keep previous definitions for compatibility */
c4a1f5
+#define SND_SOC_TPLG_BCLK_CM         SND_SOC_TPLG_BCLK_CP
c4a1f5
+#define SND_SOC_TPLG_BCLK_CS         SND_SOC_TPLG_BCLK_CC
c4a1f5
 
c4a1f5
 /* DAI topology FSYNC parameter
f29710
  * For the backwards capability, by default codec is fsync master
f29710
@@ -335,7 +338,7 @@ struct snd_soc_tplg_hw_config {
f29710
 	__u8 clock_gated;	/* SND_SOC_TPLG_DAI_CLK_GATE_ value */
f29710
 	__u8 invert_bclk;	/* 1 for inverted BCLK, 0 for normal */
f29710
 	__u8 invert_fsync;	/* 1 for inverted frame clock, 0 for normal */
f29710
-	__u8 bclk_master;	/* SND_SOC_TPLG_BCLK_ value */
f29710
+	__u8 bclk_provider;	/* SND_SOC_TPLG_BCLK_ value */
f29710
 	__u8 fsync_master;	/* SND_SOC_TPLG_FSYNC_ value */
f29710
 	__u8 mclk_direction;    /* SND_SOC_TPLG_MCLK_ value */
f29710
 	__le16 reserved;	/* for 32bit alignment */
f29710
diff --git a/include/topology.h b/include/topology.h
f29710
index 1f52e66e..6c970649 100644
f29710
--- a/include/topology.h
f29710
+++ b/include/topology.h
f29710
@@ -1028,7 +1028,7 @@ struct snd_tplg_hw_config_template {
f29710
 	unsigned char clock_gated;      /* SND_SOC_TPLG_DAI_CLK_GATE_ value */
f29710
 	unsigned char  invert_bclk;     /* 1 for inverted BCLK, 0 for normal */
f29710
 	unsigned char  invert_fsync;    /* 1 for inverted frame clock, 0 for normal */
f29710
-	unsigned char  bclk_master;     /* SND_SOC_TPLG_BCLK_ value */
f29710
+	unsigned char  bclk_provider;   /* SND_SOC_TPLG_BCLK_ value */
f29710
 	unsigned char  fsync_master;    /* SND_SOC_TPLG_FSYNC_ value */
f29710
 	unsigned char  mclk_direction;  /* SND_SOC_TPLG_MCLK_ value */
f29710
 	unsigned short reserved;        /* for 32bit alignment */
f29710
diff --git a/src/topology/pcm.c b/src/topology/pcm.c
f29710
index 191b7a0a..f05df348 100644
f29710
--- a/src/topology/pcm.c
f29710
+++ b/src/topology/pcm.c
f29710
@@ -1411,6 +1411,7 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
f29710
 	snd_config_t *n;
f29710
 	const char *id, *val = NULL;
f29710
 	int ret, ival;
f29710
+	bool provider_legacy;
f29710
 
f29710
 	elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_HW_CONFIG);
f29710
 	if (!elem)
f29710
@@ -1451,8 +1452,15 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
f29710
 			continue;
f29710
 		}
f29710
 
f29710
-		if (strcmp(id, "bclk") == 0 ||
f29710
-		    strcmp(id, "bclk_master") == 0) {
f29710
+		provider_legacy = false;
f29710
+		if (strcmp(id, "bclk_master") == 0) {
f29710
+			SNDERR("deprecated option %s, please use 'bclk'\n", id);
f29710
+			provider_legacy = true;
f29710
+		}
f29710
+
f29710
+		if (provider_legacy ||
f29710
+		    strcmp(id, "bclk") == 0) {
f29710
+
f29710
 			if (snd_config_get_string(n, &val) < 0)
f29710
 				return -EINVAL;
f29710
 
f29710
@@ -1462,11 +1470,19 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
f29710
 				 */
f29710
 				SNDERR("deprecated bclk value '%s'", val);
f29710
 
f29710
-				hw_cfg->bclk_master = SND_SOC_TPLG_BCLK_CS;
f29710
+				hw_cfg->bclk_provider = SND_SOC_TPLG_BCLK_CC;
f29710
 			} else if (!strcmp(val, "codec_slave")) {
f29710
-				hw_cfg->bclk_master = SND_SOC_TPLG_BCLK_CS;
f29710
+				SNDERR("deprecated bclk value '%s', use 'codec_consumer'", val);
f29710
+
f29710
+				hw_cfg->bclk_provider = SND_SOC_TPLG_BCLK_CC;
f29710
+			} else if (!strcmp(val, "codec_consumer")) {
f29710
+				hw_cfg->bclk_provider = SND_SOC_TPLG_BCLK_CC;
f29710
 			} else if (!strcmp(val, "codec_master")) {
f29710
-				hw_cfg->bclk_master = SND_SOC_TPLG_BCLK_CM;
f29710
+				SNDERR("deprecated bclk value '%s', use 'codec_provider", val);
f29710
+
f29710
+				hw_cfg->bclk_provider = SND_SOC_TPLG_BCLK_CP;
f29710
+			} else if (!strcmp(val, "codec_provider")) {
f29710
+				hw_cfg->bclk_provider = SND_SOC_TPLG_BCLK_CP;
f29710
 			}
f29710
 			continue;
f29710
 		}
f29710
@@ -1623,10 +1639,10 @@ int tplg_save_hw_config(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
f29710
 	if (err >= 0 && hc->fmt)
f29710
 		err = tplg_save_printf(dst, pfx, "\tformat '%s'\n",
f29710
 				       get_audio_hw_format_name(hc->fmt));
f29710
-	if (err >= 0 && hc->bclk_master)
f29710
+	if (err >= 0 && hc->bclk_provider)
f29710
 		err = tplg_save_printf(dst, pfx, "\tbclk '%s'\n",
f29710
-				       hc->bclk_master == SND_SOC_TPLG_BCLK_CS ?
f29710
-						"codec_slave" : "codec_master");
f29710
+				       hc->bclk_provider == SND_SOC_TPLG_BCLK_CC ?
f29710
+						"codec_consumer" : "codec_provider");
f29710
 	if (err >= 0 && hc->bclk_rate)
f29710
 		err = tplg_save_printf(dst, pfx, "\tbclk_freq %u\n",
f29710
 				       hc->bclk_rate);
f29710
@@ -1791,7 +1807,7 @@ static int set_link_hw_config(struct snd_soc_tplg_hw_config *cfg,
f29710
 	cfg->clock_gated = tpl->clock_gated;
f29710
 	cfg->invert_bclk = tpl->invert_bclk;
f29710
 	cfg->invert_fsync = tpl->invert_fsync;
f29710
-	cfg->bclk_master = tpl->bclk_master;
f29710
+	cfg->bclk_provider = tpl->bclk_provider;
f29710
 	cfg->fsync_master = tpl->fsync_master;
f29710
 	cfg->mclk_direction = tpl->mclk_direction;
f29710
 	cfg->reserved = tpl->reserved;
f29710
@@ -2174,7 +2190,7 @@ next:
f29710
 		hw->clock_gated = link->hw_config[i].clock_gated;
f29710
 		hw->invert_bclk = link->hw_config[i].invert_bclk;
f29710
 		hw->invert_fsync = link->hw_config[i].invert_fsync;
f29710
-		hw->bclk_master = link->hw_config[i].bclk_master;
f29710
+		hw->bclk_provider = link->hw_config[i].bclk_provider;
f29710
 		hw->fsync_master = link->hw_config[i].fsync_master;
f29710
 		hw->mclk_direction = link->hw_config[i].mclk_direction;
f29710
 		hw->mclk_rate = link->hw_config[i].mclk_rate;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 706192341d1d0bbb906d690b227b9dee5c1fc4b5 Mon Sep 17 00:00:00 2001
f29710
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
f29710
Date: Thu, 12 Nov 2020 10:29:39 -0600
f29710
Subject: [PATCH 05/49] topology: use inclusive language for fsync
f29710
f29710
use fsync_provider for structure fields, 'codec_provider' and
f29710
'codec_consumer' for options and modify #defines to use CP and CC
f29710
suffixes.
f29710
f29710
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 include/sound/uapi/asoc.h | 11 +++++++----
f29710
 include/topology.h        |  2 +-
f29710
 src/topology/pcm.c        | 37 ++++++++++++++++++++++++++-----------
f29710
 3 files changed, 34 insertions(+), 16 deletions(-)
f29710
f29710
diff --git a/include/sound/uapi/asoc.h b/include/sound/uapi/asoc.h
f29710
index ceafb1a9..f32c5697 100644
f29710
--- a/include/sound/uapi/asoc.h
f29710
+++ b/include/sound/uapi/asoc.h
f29710
@@ -178,10 +178,13 @@
f29710
 #define SND_SOC_TPLG_BCLK_CS         SND_SOC_TPLG_BCLK_CC
f29710
 
f29710
 /* DAI topology FSYNC parameter
c4a1f5
- * For the backwards capability, by default codec is fsync master
c4a1f5
+ * For the backwards capability, by default codec is fsync provider
c4a1f5
  */
c4a1f5
-#define SND_SOC_TPLG_FSYNC_CM         0 /* codec is fsync master */
c4a1f5
-#define SND_SOC_TPLG_FSYNC_CS         1 /* codec is fsync slave */
c4a1f5
+#define SND_SOC_TPLG_FSYNC_CP         0 /* codec is fsync provider */
c4a1f5
+#define SND_SOC_TPLG_FSYNC_CC         1 /* codec is fsync consumer */
c4a1f5
+/* keep previous definitions for compatibility */
c4a1f5
+#define SND_SOC_TPLG_FSYNC_CM         SND_SOC_TPLG_FSYNC_CP
c4a1f5
+#define SND_SOC_TPLG_FSYNC_CS         SND_SOC_TPLG_FSYNC_CC
c4a1f5
 
c4a1f5
 /*
c4a1f5
  * Block Header.
f29710
@@ -339,7 +342,7 @@ struct snd_soc_tplg_hw_config {
c4a1f5
 	__u8 invert_bclk;	/* 1 for inverted BCLK, 0 for normal */
c4a1f5
 	__u8 invert_fsync;	/* 1 for inverted frame clock, 0 for normal */
f29710
 	__u8 bclk_provider;	/* SND_SOC_TPLG_BCLK_ value */
c4a1f5
-	__u8 fsync_master;	/* SND_SOC_TPLG_FSYNC_ value */
c4a1f5
+	__u8 fsync_provider;	/* SND_SOC_TPLG_FSYNC_ value */
c4a1f5
 	__u8 mclk_direction;    /* SND_SOC_TPLG_MCLK_ value */
c4a1f5
 	__le16 reserved;	/* for 32bit alignment */
c4a1f5
 	__le32 mclk_rate;	/* MCLK or SYSCLK freqency in Hz */
c4a1f5
diff --git a/include/topology.h b/include/topology.h
f29710
index 6c970649..4ade20df 100644
c4a1f5
--- a/include/topology.h
c4a1f5
+++ b/include/topology.h
f29710
@@ -1029,7 +1029,7 @@ struct snd_tplg_hw_config_template {
c4a1f5
 	unsigned char  invert_bclk;     /* 1 for inverted BCLK, 0 for normal */
c4a1f5
 	unsigned char  invert_fsync;    /* 1 for inverted frame clock, 0 for normal */
f29710
 	unsigned char  bclk_provider;   /* SND_SOC_TPLG_BCLK_ value */
c4a1f5
-	unsigned char  fsync_master;    /* SND_SOC_TPLG_FSYNC_ value */
c4a1f5
+	unsigned char  fsync_provider;  /* SND_SOC_TPLG_FSYNC_ value */
c4a1f5
 	unsigned char  mclk_direction;  /* SND_SOC_TPLG_MCLK_ value */
c4a1f5
 	unsigned short reserved;        /* for 32bit alignment */
c4a1f5
 	unsigned int mclk_rate;	        /* MCLK or SYSCLK freqency in Hz */
f29710
diff --git a/src/topology/pcm.c b/src/topology/pcm.c
f29710
index f05df348..c8f41862 100644
f29710
--- a/src/topology/pcm.c
f29710
+++ b/src/topology/pcm.c
f29710
@@ -1504,8 +1504,15 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
f29710
 			continue;
f29710
 		}
c4a1f5
 
f29710
-		if (strcmp(id, "fsync") == 0 ||
f29710
-		    strcmp(id, "fsync_master") == 0) {
f29710
+		provider_legacy = false;
f29710
+		if (strcmp(id, "fsync_master") == 0) {
f29710
+			SNDERR("deprecated option %s, please use 'fsync'\n", id);
f29710
+			provider_legacy = true;
f29710
+		}
f29710
+
f29710
+		if (provider_legacy ||
f29710
+		    strcmp(id, "fsync") == 0) {
f29710
+
f29710
 			if (snd_config_get_string(n, &val) < 0)
f29710
 				return -EINVAL;
c4a1f5
 
f29710
@@ -1515,11 +1522,19 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg,
f29710
 				 */
f29710
 				SNDERR("deprecated fsync value '%s'", val);
c4a1f5
 
f29710
-				hw_cfg->fsync_master = SND_SOC_TPLG_FSYNC_CS;
f29710
+				hw_cfg->fsync_provider = SND_SOC_TPLG_FSYNC_CC;
f29710
 			} else if (!strcmp(val, "codec_slave")) {
f29710
-				hw_cfg->fsync_master = SND_SOC_TPLG_FSYNC_CS;
f29710
+				SNDERR("deprecated fsync value '%s', use 'codec_consumer'", val);
f29710
+
f29710
+				hw_cfg->fsync_provider = SND_SOC_TPLG_FSYNC_CC;
f29710
+			} else if (!strcmp(val, "codec_consumer")) {
f29710
+				hw_cfg->fsync_provider = SND_SOC_TPLG_FSYNC_CC;
f29710
 			} else if (!strcmp(val, "codec_master")) {
f29710
-				hw_cfg->fsync_master = SND_SOC_TPLG_FSYNC_CM;
f29710
+				SNDERR("deprecated fsync value '%s', use 'codec_provider'", val);
f29710
+
f29710
+				hw_cfg->fsync_provider = SND_SOC_TPLG_FSYNC_CP;
f29710
+			} else if (!strcmp(val, "codec_provider")) {
f29710
+				hw_cfg->fsync_provider = SND_SOC_TPLG_FSYNC_CP;
f29710
 			}
f29710
 			continue;
f29710
 		}
f29710
@@ -1648,10 +1663,10 @@ int tplg_save_hw_config(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
f29710
 				       hc->bclk_rate);
f29710
 	if (err >= 0 && hc->invert_bclk)
f29710
 		err = tplg_save_printf(dst, pfx, "\tbclk_invert 1\n");
f29710
-	if (err >= 0 && hc->fsync_master)
f29710
-		err = tplg_save_printf(dst, pfx, "\tfsync_master '%s'\n",
f29710
-				       hc->fsync_master == SND_SOC_TPLG_FSYNC_CS ?
f29710
-						"codec_slave" : "codec_master");
f29710
+	if (err >= 0 && hc->fsync_provider)
f29710
+		err = tplg_save_printf(dst, pfx, "\tfsync_provider '%s'\n",
f29710
+				       hc->fsync_provider == SND_SOC_TPLG_FSYNC_CC ?
f29710
+						"codec_consumer" : "codec_provider");
f29710
 	if (err >= 0 && hc->fsync_rate)
f29710
 		err = tplg_save_printf(dst, pfx, "\tfsync_freq %u\n",
f29710
 				       hc->fsync_rate);
f29710
@@ -1808,7 +1823,7 @@ static int set_link_hw_config(struct snd_soc_tplg_hw_config *cfg,
f29710
 	cfg->invert_bclk = tpl->invert_bclk;
f29710
 	cfg->invert_fsync = tpl->invert_fsync;
f29710
 	cfg->bclk_provider = tpl->bclk_provider;
f29710
-	cfg->fsync_master = tpl->fsync_master;
f29710
+	cfg->fsync_provider = tpl->fsync_provider;
f29710
 	cfg->mclk_direction = tpl->mclk_direction;
f29710
 	cfg->reserved = tpl->reserved;
f29710
 	cfg->mclk_rate = tpl->mclk_rate;
f29710
@@ -2191,7 +2206,7 @@ next:
f29710
 		hw->invert_bclk = link->hw_config[i].invert_bclk;
f29710
 		hw->invert_fsync = link->hw_config[i].invert_fsync;
f29710
 		hw->bclk_provider = link->hw_config[i].bclk_provider;
f29710
-		hw->fsync_master = link->hw_config[i].fsync_master;
f29710
+		hw->fsync_provider = link->hw_config[i].fsync_provider;
f29710
 		hw->mclk_direction = link->hw_config[i].mclk_direction;
f29710
 		hw->mclk_rate = link->hw_config[i].mclk_rate;
f29710
 		hw->bclk_rate = link->hw_config[i].bclk_rate;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From e5c350d7bc6f3d45702059c0ae8d32b3603273c1 Mon Sep 17 00:00:00 2001
f29710
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
f29710
Date: Thu, 12 Nov 2020 10:29:40 -0600
f29710
Subject: [PATCH 06/49] topology: use inclusive language in documentation
f29710
f29710
Use codec_provider and codec_consumer for bclk and fsync
f29710
f29710
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 include/topology.h | 4 ++--
f29710
 1 file changed, 2 insertions(+), 2 deletions(-)
f29710
f29710
diff --git a/include/topology.h b/include/topology.h
f29710
index 4ade20df..d1feee4d 100644
f29710
--- a/include/topology.h
f29710
+++ b/include/topology.h
f29710
@@ -658,8 +658,8 @@ extern "C" {
f29710
  *
f29710
  *	id "1"				# used for binding to the config
f29710
  *	format "I2S"			# physical audio format.
f29710
- *	bclk   "master"			# Platform is master of bit clock
f29710
- *	fsync  "slave"			# Platform is slave of fsync
f29710
+ *	bclk   "codec_provider"		# Codec provides the bit clock
f29710
+ *	fsync  "codec_consumer"		# Codec follows the fsync
f29710
  * }
f29710
  * 
f29710
  *
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 7d36895225d09ae26868997382445cc7ad2e9513 Mon Sep 17 00:00:00 2001
f29710
From: Jonas Holmberg <jonashg@axis.com>
f29710
Date: Wed, 4 Nov 2020 14:49:56 +0100
f29710
Subject: [PATCH 07/49] pcm: set the snd_pcm_ioplug_status() tstamp field
f29710
f29710
Set the status tstamp field so that it can be accessed with
f29710
snd_pcm_status_get_htstamp().
f29710
f29710
Signed-off-by: Jonas Holmberg <jonashg@axis.com>
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 src/pcm/pcm_ioplug.c | 1 +
f29710
 1 file changed, 1 insertion(+)
f29710
c4a1f5
diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c
f29710
index a437ca32..9b1b8ac3 100644
c4a1f5
--- a/src/pcm/pcm_ioplug.c
c4a1f5
+++ b/src/pcm/pcm_ioplug.c
f29710
@@ -115,6 +115,7 @@ static int snd_pcm_ioplug_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
c4a1f5
 	snd_pcm_ioplug_hw_ptr_update(pcm);
c4a1f5
 	status->state = io->data->state;
c4a1f5
 	status->trigger_tstamp = io->trigger_tstamp;
c4a1f5
+	gettimestamp(&status->tstamp, pcm->tstamp_type);
c4a1f5
 	status->avail = snd_pcm_mmap_avail(pcm);
c4a1f5
 	status->avail_max = io->avail_max;
c4a1f5
 	return 0;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 6d3311fefb1b41c7484fd728e4ad4a6fb5b55ad4 Mon Sep 17 00:00:00 2001
f29710
From: Takashi Iwai <tiwai@suse.de>
f29710
Date: Thu, 10 Dec 2020 10:36:41 +0100
f29710
Subject: [PATCH 08/49] Makefile: Add README.md to EXTRA_DIST
f29710
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 Makefile.am | 2 +-
f29710
 1 file changed, 1 insertion(+), 1 deletion(-)
f29710
f29710
diff --git a/Makefile.am b/Makefile.am
f29710
index c484d4da..ff4c963a 100644
f29710
--- a/Makefile.am
f29710
+++ b/Makefile.am
f29710
@@ -16,7 +16,7 @@ SUBDIRS += alsalisp
f29710
 endif
f29710
 endif
f29710
 SUBDIRS += test utils
f29710
-EXTRA_DIST=ChangeLog INSTALL TODO NOTES configure gitcompile libtool \
f29710
+EXTRA_DIST=README.md ChangeLog INSTALL TODO NOTES configure gitcompile libtool \
f29710
 	   depcomp version MEMORY-LEAK m4/attributes.m4
f29710
 AUTOMAKE_OPTIONS=foreign
f29710
 
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From ea02dbd20a535085638c63c6b8bec94e628486c4 Mon Sep 17 00:00:00 2001
f29710
From: David Henningsson <diwic@ubuntu.com>
f29710
Date: Wed, 16 Dec 2020 19:55:22 +0100
f29710
Subject: [PATCH 09/49] pcm: Add snd_pcm_audio_tstamp_type_t constants
f29710
f29710
These are mostly a copy-paste from the kernel headers. But since functions
f29710
snd_pcm_audio_tstamp_config make use of these they should be added to the
f29710
public API as well.
f29710
f29710
Reported-by: Alex Moon <alex.r.moon@gmail.com>
f29710
Signed-off-by: David Henningsson <diwic@ubuntu.com>
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 include/pcm.h | 14 ++++++++++++++
f29710
 1 file changed, 14 insertions(+)
f29710
f29710
diff --git a/include/pcm.h b/include/pcm.h
f29710
index 5b078231..cf1eea8b 100644
f29710
--- a/include/pcm.h
f29710
+++ b/include/pcm.h
f29710
@@ -350,6 +350,20 @@ typedef enum _snd_pcm_tstamp_type {
f29710
 	SND_PCM_TSTAMP_TYPE_LAST = SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW,
f29710
 } snd_pcm_tstamp_type_t;
f29710
 
f29710
+typedef enum _snd_pcm_audio_tstamp_type {
f29710
+	/**
f29710
+	 * first definition for backwards compatibility only,
f29710
+	 * maps to wallclock/link time for HDAudio playback and DEFAULT/DMA time for everything else
f29710
+	 */
f29710
+	SND_PCM_AUDIO_TSTAMP_TYPE_COMPAT = 0,
f29710
+	SND_PCM_AUDIO_TSTAMP_TYPE_DEFAULT = 1,           /**< DMA time, reported as per hw_ptr */
f29710
+	SND_PCM_AUDIO_TSTAMP_TYPE_LINK = 2,	           /**< link time reported by sample or wallclock counter, reset on startup */
f29710
+	SND_PCM_AUDIO_TSTAMP_TYPE_LINK_ABSOLUTE = 3,	   /**< link time reported by sample or wallclock counter, not reset on startup */
f29710
+	SND_PCM_AUDIO_TSTAMP_TYPE_LINK_ESTIMATED = 4,    /**< link time estimated indirectly */
f29710
+	SND_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED = 5, /**< link time synchronized with system time */
f29710
+	SND_PCM_AUDIO_TSTAMP_TYPE_LAST = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED
f29710
+} snd_pcm_audio_tstamp_type_t;
f29710
+
f29710
 typedef struct _snd_pcm_audio_tstamp_config {
f29710
 	/* 5 of max 16 bits used */
f29710
 	unsigned int type_requested:4;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From dcda999d0000cbdabe61d3d175943b5f23c30057 Mon Sep 17 00:00:00 2001
f29710
From: David Henningsson <diwic@ubuntu.com>
f29710
Date: Wed, 16 Dec 2020 20:02:52 +0100
f29710
Subject: [PATCH 10/49] test/audio_time: Make use of SND_PCM_AUDIO_TSTAMP_TYPE
f29710
 constants
f29710
f29710
Also fixup the usage row which seemed wrong to me.
f29710
f29710
Signed-off-by: David Henningsson <diwic@ubuntu.com>
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 test/audio_time.c | 26 +++++++++++++-------------
f29710
 1 file changed, 13 insertions(+), 13 deletions(-)
f29710
f29710
diff --git a/test/audio_time.c b/test/audio_time.c
f29710
index 530922d9..e4d4a944 100644
f29710
--- a/test/audio_time.c
f29710
+++ b/test/audio_time.c
f29710
@@ -32,7 +32,7 @@ static void usage(char *command)
f29710
 		"-d, --delay             add delay \n"
f29710
 		"-D, --device=NAME       select PCM by name \n"
f29710
 		"-p, --playback          playback tstamps \n"
f29710
-		"-t, --ts_type=TYPE      Default(0),link(1),link_estimated(2),synchronized(3) \n"
f29710
+		"-t, --ts_type=TYPE      Compat(0),default(1),link(2),link_absolute(3),link_estimated(4),link_synchronized(5) \n"
f29710
 		"-r, --report            show audio timestamp and accuracy validity\n"
f29710
 		, command);
c4a1f5
 }
f29710
@@ -201,17 +201,17 @@ int main(int argc, char *argv[])
f29710
 			goto _exit;
f29710
 		}
c4a1f5
 
f29710
-		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, 0))
f29710
+		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, SND_PCM_AUDIO_TSTAMP_TYPE_COMPAT))
f29710
 			printf("Playback supports audio compat timestamps\n");
f29710
-		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, 1))
f29710
+		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, SND_PCM_AUDIO_TSTAMP_TYPE_DEFAULT))
f29710
 			printf("Playback supports audio default timestamps\n");
f29710
-		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, 2))
f29710
+		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, SND_PCM_AUDIO_TSTAMP_TYPE_LINK))
f29710
 			printf("Playback supports audio link timestamps\n");
f29710
-		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, 3))
f29710
+		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, SND_PCM_AUDIO_TSTAMP_TYPE_LINK_ABSOLUTE))
f29710
 			printf("Playback supports audio link absolute timestamps\n");
f29710
-		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, 4))
f29710
+		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, SND_PCM_AUDIO_TSTAMP_TYPE_LINK_ESTIMATED))
f29710
 			printf("Playback supports audio link estimated timestamps\n");
f29710
-		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, 5))
f29710
+		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_p, SND_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED))
f29710
 			printf("Playback supports audio link synchronized timestamps\n");
f29710
 
f29710
 		snd_pcm_sw_params_alloca(&swparams_p);
f29710
@@ -269,17 +269,17 @@ int main(int argc, char *argv[])
f29710
 			goto _exit;
f29710
 		}
f29710
 
f29710
-		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, 0))
f29710
+		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, SND_PCM_AUDIO_TSTAMP_TYPE_COMPAT))
f29710
 			printf("Capture supports audio compat timestamps\n");
f29710
-		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, 1))
f29710
+		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, SND_PCM_AUDIO_TSTAMP_TYPE_DEFAULT))
f29710
 			printf("Capture supports audio default timestamps\n");
f29710
-		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, 2))
f29710
+		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, SND_PCM_AUDIO_TSTAMP_TYPE_LINK))
f29710
 			printf("Capture supports audio link timestamps\n");
f29710
-		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, 3))
f29710
+		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, SND_PCM_AUDIO_TSTAMP_TYPE_LINK_ABSOLUTE))
f29710
 			printf("Capture supports audio link absolute timestamps\n");
f29710
-		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, 4))
f29710
+		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, SND_PCM_AUDIO_TSTAMP_TYPE_LINK_ESTIMATED))
f29710
 			printf("Capture supports audio link estimated timestamps\n");
f29710
-		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, 5))
f29710
+		if (snd_pcm_hw_params_supports_audio_ts_type(hwparams_c, SND_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED))
f29710
 			printf("Capture supports audio link synchronized timestamps\n");
f29710
 
f29710
 		snd_pcm_sw_params_alloca(&swparams_c);
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From a9cbfecd87777d76a83e5a912ca9bdcf48e31fa9 Mon Sep 17 00:00:00 2001
f29710
From: Takashi Iwai <tiwai@suse.de>
f29710
Date: Tue, 22 Dec 2020 16:10:16 +0100
f29710
Subject: [PATCH 11/49] pcm: Fix a typo in SND_PCM_AUDIO_TSTAMP_TYPE_LAST
f29710
 definition
f29710
f29710
It was wrongly defined with SNDRV_ prefix.  Fix it.
f29710
f29710
Fixes: ea02dbd20a53 ("pcm: Add snd_pcm_audio_tstamp_type_t constants")
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 include/pcm.h | 2 +-
f29710
 1 file changed, 1 insertion(+), 1 deletion(-)
f29710
f29710
diff --git a/include/pcm.h b/include/pcm.h
f29710
index cf1eea8b..e300b951 100644
f29710
--- a/include/pcm.h
f29710
+++ b/include/pcm.h
f29710
@@ -361,7 +361,7 @@ typedef enum _snd_pcm_audio_tstamp_type {
f29710
 	SND_PCM_AUDIO_TSTAMP_TYPE_LINK_ABSOLUTE = 3,	   /**< link time reported by sample or wallclock counter, not reset on startup */
f29710
 	SND_PCM_AUDIO_TSTAMP_TYPE_LINK_ESTIMATED = 4,    /**< link time estimated indirectly */
f29710
 	SND_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED = 5, /**< link time synchronized with system time */
f29710
-	SND_PCM_AUDIO_TSTAMP_TYPE_LAST = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED
f29710
+	SND_PCM_AUDIO_TSTAMP_TYPE_LAST = SND_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED
f29710
 } snd_pcm_audio_tstamp_type_t;
f29710
 
f29710
 typedef struct _snd_pcm_audio_tstamp_config {
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 5275d170e05639473e68e5feb349aec65bf26428 Mon Sep 17 00:00:00 2001
f29710
From: Alex Henrie <alexhenrie24@gmail.com>
f29710
Date: Sat, 26 Dec 2020 14:35:39 -0700
f29710
Subject: [PATCH 12/49] conf: fix use after free in
f29710
 _snd_config_load_with_include
f29710
f29710
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 src/conf.c | 4 +++-
f29710
 1 file changed, 3 insertions(+), 1 deletion(-)
f29710
f29710
diff --git a/src/conf.c b/src/conf.c
f29710
index 7df2b4e7..44d1bfde 100644
f29710
--- a/src/conf.c
f29710
+++ b/src/conf.c
f29710
@@ -1970,7 +1970,9 @@ int _snd_config_load_with_include(snd_config_t *config, snd_input_t *in,
f29710
 		SNDERR("%s:%d:%d:%s", fd->name ? fd->name : "_toplevel_", fd->line, fd->column, str);
f29710
 		goto _end;
f29710
 	}
f29710
-	if (get_char(&input) != LOCAL_UNEXPECTED_EOF) {
f29710
+	err = get_char(&input);
f29710
+	fd = input.current;
f29710
+	if (err != LOCAL_UNEXPECTED_EOF) {
f29710
 		SNDERR("%s:%d:%d:Unexpected }", fd->name ? fd->name : "", fd->line, fd->column);
f29710
 		err = -EINVAL;
f29710
 		goto _end;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 0f4821ec1729cd72a3dde3ea63f7857e92a10919 Mon Sep 17 00:00:00 2001
f29710
From: Alex Henrie <alexhenrie24@gmail.com>
f29710
Date: Sat, 26 Dec 2020 14:35:40 -0700
f29710
Subject: [PATCH 13/49] ucm: fix bad frees in get_list0 and get_list20
f29710
f29710
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 src/ucm/main.c | 4 ++--
f29710
 1 file changed, 2 insertions(+), 2 deletions(-)
f29710
f29710
diff --git a/src/ucm/main.c b/src/ucm/main.c
f29710
index 3871d5aa..754b967e 100644
f29710
--- a/src/ucm/main.c
f29710
+++ b/src/ucm/main.c
f29710
@@ -666,7 +666,7 @@ static int get_list0(struct list_head *list,
f29710
 	}
f29710
 	return cnt;
f29710
       __fail:
f29710
-        snd_use_case_free_list((const char **)res, cnt);
f29710
+        snd_use_case_free_list(*result, cnt);
f29710
         return -ENOMEM;
c4a1f5
 }
c4a1f5
 
f29710
@@ -724,7 +724,7 @@ static int get_list20(struct list_head *list,
f29710
 	}
f29710
 	return cnt;
f29710
       __fail:
f29710
-        snd_use_case_free_list((const char **)res, cnt);
f29710
+        snd_use_case_free_list(*result, cnt);
f29710
         return -ENOMEM;
f29710
 }
f29710
 
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From c56278cfda55b9f5d106890c7354176dba8c8f4d Mon Sep 17 00:00:00 2001
f29710
From: Alex Henrie <alexhenrie24@gmail.com>
f29710
Date: Sat, 26 Dec 2020 14:35:41 -0700
f29710
Subject: [PATCH 14/49] rawmidi: fix memory leak in snd_rawmidi_virtual_open
f29710
f29710
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 src/rawmidi/rawmidi_virt.c | 3 ++-
f29710
 1 file changed, 2 insertions(+), 1 deletion(-)
f29710
f29710
diff --git a/src/rawmidi/rawmidi_virt.c b/src/rawmidi/rawmidi_virt.c
f29710
index 2c4c27f5..884b8ff8 100644
f29710
--- a/src/rawmidi/rawmidi_virt.c
f29710
+++ b/src/rawmidi/rawmidi_virt.c
f29710
@@ -315,7 +315,7 @@ int snd_rawmidi_virtual_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
f29710
 			     int merge, int mode)
c4a1f5
 {
f29710
 	int err;
f29710
-	snd_rawmidi_t *rmidi;
f29710
+	snd_rawmidi_t *rmidi = NULL;
f29710
 	snd_rawmidi_virtual_t *virt = NULL;
f29710
 	struct pollfd pfd;
f29710
 
f29710
@@ -392,6 +392,7 @@ int snd_rawmidi_virtual_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
f29710
 		free(*inputp);
f29710
 	if (outputp)
f29710
 		free(*outputp);
f29710
+	free(rmidi);
f29710
 	return err;
c4a1f5
 }
c4a1f5
 
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From aa28847248f2f416d9ecc6cbfa75192455400f6f Mon Sep 17 00:00:00 2001
f29710
From: Alex Henrie <alexhenrie24@gmail.com>
f29710
Date: Sat, 26 Dec 2020 14:35:43 -0700
f29710
Subject: [PATCH 15/49] timer: fix sizeof operator mismatch in
f29710
 snd_timer_query_hw_open
f29710
f29710
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 src/timer/timer_query_hw.c | 2 +-
f29710
 1 file changed, 1 insertion(+), 1 deletion(-)
f29710
f29710
diff --git a/src/timer/timer_query_hw.c b/src/timer/timer_query_hw.c
f29710
index dad228c8..d8bac6e7 100644
f29710
--- a/src/timer/timer_query_hw.c
f29710
+++ b/src/timer/timer_query_hw.c
f29710
@@ -104,7 +104,7 @@ int snd_timer_query_hw_open(snd_timer_query_t **handle, const char *name, int mo
f29710
 		close(fd);
f29710
 		return -SND_ERROR_INCOMPATIBLE_VERSION;
f29710
 	}
f29710
-	tmr = (snd_timer_query_t *) calloc(1, sizeof(snd_timer_t));
f29710
+	tmr = (snd_timer_query_t *) calloc(1, sizeof(snd_timer_query_t));
f29710
 	if (tmr == NULL) {
f29710
 		close(fd);
f29710
 		return -ENOMEM;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 2e470d59d84a563a9efa81572ddc48d9858ceb92 Mon Sep 17 00:00:00 2001
f29710
From: Alex Henrie <alexhenrie24@gmail.com>
f29710
Date: Sat, 26 Dec 2020 14:35:44 -0700
f29710
Subject: [PATCH 16/49] pcm: remove dead assignments from
f29710
 snd_pcm_rate_(commit_area|grab_next_period)
f29710
f29710
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 src/pcm/pcm_rate.c | 2 --
f29710
 1 file changed, 2 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c
f29710
index 5bf7dbb9..dc38e95e 100644
f29710
--- a/src/pcm/pcm_rate.c
f29710
+++ b/src/pcm/pcm_rate.c
f29710
@@ -746,7 +746,6 @@ static int snd_pcm_rate_commit_area(snd_pcm_t *pcm, snd_pcm_rate_t *rate,
f29710
 		if (result < 0)
f29710
 			return result;
f29710
 	      __partial:
f29710
-		xfer = 0;
f29710
 		cont = slave_frames;
f29710
 		if (cont > slave_size)
f29710
 			cont = slave_size;
f29710
@@ -846,7 +845,6 @@ static int snd_pcm_rate_grab_next_period(snd_pcm_t *pcm, snd_pcm_uframes_t hw_of
f29710
 		if (result < 0)
f29710
 			return result;
f29710
 	      __partial:
f29710
-		xfer = 0;
f29710
 		cont = slave_frames;
f29710
 		if (cont > rate->gen.slave->period_size)
f29710
 			cont = rate->gen.slave->period_size;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From fc719bfe4e97bbfce899cc7e67df08ecd573c5d3 Mon Sep 17 00:00:00 2001
f29710
From: Alex Henrie <alexhenrie24@gmail.com>
f29710
Date: Sat, 26 Dec 2020 14:35:45 -0700
f29710
Subject: [PATCH 17/49] pcm_multi: remove dead assignment from
f29710
 _snd_pcm_multi_open
f29710
f29710
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 src/pcm/pcm_multi.c | 1 -
f29710
 1 file changed, 1 deletion(-)
f29710
c4a1f5
diff --git a/src/pcm/pcm_multi.c b/src/pcm/pcm_multi.c
c4a1f5
index 53c414d5..5fa09b9b 100644
c4a1f5
--- a/src/pcm/pcm_multi.c
c4a1f5
+++ b/src/pcm/pcm_multi.c
c4a1f5
@@ -1323,7 +1323,6 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
c4a1f5
 		err = -ENOMEM;
c4a1f5
 		goto _free;
c4a1f5
 	}
c4a1f5
-	idx = 0;
c4a1f5
 	for (idx = 0; idx < channels_count; ++idx)
c4a1f5
 		channels_sidx[idx] = -1;
c4a1f5
 	idx = 0;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 9ebd29d2d31df0f8967f3e60cf24bb63c95d4984 Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Sun, 27 Dec 2020 13:17:26 +0100
f29710
Subject: [PATCH 18/49] conf: fix get_hexachar() return value
f29710
f29710
Reported-by: Alex Henrie <alexhenrie24@gmail.com>
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/conf.c | 2 +-
f29710
 1 file changed, 1 insertion(+), 1 deletion(-)
f29710
f29710
diff --git a/src/conf.c b/src/conf.c
f29710
index 44d1bfde..6cfe65bf 100644
f29710
--- a/src/conf.c
f29710
+++ b/src/conf.c
f29710
@@ -887,7 +887,7 @@ static inline int get_hexachar(input_t *input)
f29710
 	if (c >= '0' && c <= '9') num |= (c - '0') << 0;
f29710
 	else if (c >= 'a' && c <= 'f') num |= (c - 'a') << 0;
f29710
 	else if (c >= 'A' && c <= 'F') num |= (c - 'A') << 0;
f29710
-	return c;
f29710
+	return num;
f29710
 }
f29710
 
f29710
 static int get_quotedchar(input_t *input)
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 36aff79747b23b9535e81befe8b7b2972837bce3 Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Sun, 27 Dec 2020 13:29:33 +0100
f29710
Subject: [PATCH 19/49] pcm: fix __snd_pcm_state() return value
f29710
f29710
The __snd_pcm_state() must return a valid state, not an error value
f29710
when the plugin callback is not defined. Use the first state
f29710
SND_PCM_STATE_OPEN - the other functions will return the error
f29710
code depending on this state.
f29710
f29710
Link: https://lore.kernel.org/alsa-devel/20201226213547.175071-10-alexhenrie24@gmail.com/
f29710
Reported-by: Alex Henrie <alexhenrie24@gmail.com>
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_local.h | 2 +-
f29710
 1 file changed, 1 insertion(+), 1 deletion(-)
f29710
f29710
diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h
f29710
index fe77e50d..bec5a408 100644
f29710
--- a/src/pcm/pcm_local.h
f29710
+++ b/src/pcm/pcm_local.h
f29710
@@ -444,7 +444,7 @@ static inline int __snd_pcm_start(snd_pcm_t *pcm)
f29710
 static inline snd_pcm_state_t __snd_pcm_state(snd_pcm_t *pcm)
f29710
 {
f29710
 	if (!pcm->fast_ops->state)
f29710
-		return -ENOSYS;
f29710
+		return SND_PCM_STATE_OPEN;
f29710
 	return pcm->fast_ops->state(pcm->fast_op_arg);
f29710
 }
f29710
 
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From a92ad2fea4b36d7282f4a571275fb492dd1bba75 Mon Sep 17 00:00:00 2001
f29710
From: Alex Henrie <alexhenrie24@gmail.com>
f29710
Date: Sun, 27 Dec 2020 18:43:15 -0700
f29710
Subject: [PATCH 20/49] confmisc: fix memory leak in snd_func_concat
f29710
f29710
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
---
f29710
 src/confmisc.c | 3 +--
f29710
 1 file changed, 1 insertion(+), 2 deletions(-)
f29710
f29710
diff --git a/src/confmisc.c b/src/confmisc.c
f29710
index eb8218c1..3ce95c7a 100644
f29710
--- a/src/confmisc.c
f29710
+++ b/src/confmisc.c
f29710
@@ -419,7 +419,6 @@ int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
f29710
 				tmp = realloc(res, len + len1 + 1);
f29710
 				if (tmp == NULL) {
f29710
 					free(ptr);
f29710
-					free(res);
f29710
 					err = -ENOMEM;
f29710
 					goto __error;
f29710
 				}
f29710
@@ -440,8 +439,8 @@ int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
f29710
 	err = snd_config_get_id(src, &id;;
f29710
 	if (err >= 0)
f29710
 		err = snd_config_imake_string(dst, id, res);
f29710
-	free(res);
f29710
       __error:
f29710
+	free(res);
f29710
 	return err;
f29710
 }
f29710
 #ifndef DOC_HIDDEN
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 6c24cd2e60cc9c1fca809ffeeb7ffe8af94b201e Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Tue, 29 Dec 2020 11:15:46 +0100
f29710
Subject: [PATCH 21/49] conf: fix return code in _snd_config_load_with_include
f29710
f29710
Fixes: 5275d170e0 ("conf: fix use after free in _snd_config_load_with_include")
f29710
BugLink: https://github.com/alsa-project/alsa-lib/issues/108
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/conf.c | 1 +
f29710
 1 file changed, 1 insertion(+)
f29710
f29710
diff --git a/src/conf.c b/src/conf.c
f29710
index 6cfe65bf..3c943db2 100644
f29710
--- a/src/conf.c
f29710
+++ b/src/conf.c
f29710
@@ -1977,6 +1977,7 @@ int _snd_config_load_with_include(snd_config_t *config, snd_input_t *in,
f29710
 		err = -EINVAL;
f29710
 		goto _end;
f29710
 	}
f29710
+	err = 0;
f29710
  _end:
f29710
 	while (fd->next) {
f29710
 		fd_next = fd->next;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From afe6ff3b33ee6e5ea3511fe458bfd4e516b10bcf Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Wed, 30 Dec 2020 09:31:10 +0100
f29710
Subject: [PATCH 22/49] pcm: plugin status - fix the return value (regression)
f29710
f29710
The snd_pcm_plugin_avail_update() error code in snd_pcm_plugin_status()
f29710
should not be reported to the caller. The state errors can be determined
f29710
using the state member in the status structure.
f29710
f29710
Fixes: 4f90392f07e ("pcm: fix the snd_pcm_plugin_status() avail and delay fields")
f29710
BugLink: https://github.com/alsa-project/alsa-lib/issues/107
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_plugin.c | 8 +++-----
f29710
 1 file changed, 3 insertions(+), 5 deletions(-)
f29710
c4a1f5
diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
f29710
index 5739cfc2..76a524fa 100644
c4a1f5
--- a/src/pcm/pcm_plugin.c
c4a1f5
+++ b/src/pcm/pcm_plugin.c
f29710
@@ -541,19 +541,17 @@ static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
f29710
 static int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
f29710
 {
f29710
 	snd_pcm_plugin_t *plugin = pcm->private_data;
f29710
-	snd_pcm_sframes_t err, avail;
f29710
+	snd_pcm_sframes_t err;
f29710
 
f29710
 	/* sync with the latest hw and appl ptrs */
f29710
-	avail = snd_pcm_plugin_avail_update(pcm);
f29710
-	if (avail < 0)
f29710
-		return avail;
f29710
+	snd_pcm_plugin_avail_update(pcm);
f29710
 
f29710
 	err = snd_pcm_status(plugin->gen.slave, status);
c4a1f5
 	if (err < 0)
c4a1f5
 		return err;
f29710
 	status->appl_ptr = *pcm->appl.ptr;
f29710
 	status->hw_ptr = *pcm->hw.ptr;
f29710
-	status->avail = avail;
f29710
+	status->avail = snd_pcm_mmap_avail(pcm);
f29710
 	status->delay = snd_pcm_mmap_delay(pcm);
f29710
 	return 0;
f29710
 }
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 49eea5d7bc7d39f9a4cc1f3b3a813e90b90519eb Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Sun, 3 Jan 2021 16:16:10 +0100
f29710
Subject: [PATCH 23/49] pcm: plugin status - revert the recent changes
f29710
f29710
It's no reason to sync the avail/delay fields using the mirrored
f29710
buffer pointers. The slave information must be valid.
f29710
f29710
The original report probably tries to fix something for
f29710
the specific plugin. Revert all changes.
f29710
f29710
Fixes: afe6ff3b33e ("pcm: plugin status - fix the return value (regression)")
f29710
Fixes: 4f90392f07e ("pcm: fix the snd_pcm_plugin_status() avail and delay fields")
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_plugin.c | 2 --
f29710
 1 file changed, 2 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
f29710
index 76a524fa..ea60eb98 100644
f29710
--- a/src/pcm/pcm_plugin.c
f29710
+++ b/src/pcm/pcm_plugin.c
f29710
@@ -551,8 +551,6 @@ static int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
f29710
 		return err;
f29710
 	status->appl_ptr = *pcm->appl.ptr;
f29710
 	status->hw_ptr = *pcm->hw.ptr;
f29710
-	status->avail = snd_pcm_mmap_avail(pcm);
f29710
-	status->delay = snd_pcm_mmap_delay(pcm);
c4a1f5
 	return 0;
c4a1f5
 }
f29710
 
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From fa1895aa2b4f3f154e537bee92860fe793045643 Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Sun, 3 Jan 2021 16:34:04 +0100
f29710
Subject: [PATCH 24/49] pcm: plugin - tidy snd_pcm_plugin_avail_update()
f29710
f29710
No functional changes - move the code to snd_pcm_plugin_sync_hw_ptr()
f29710
and put the mmap capture updates to separate function for readability.
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_plugin.c | 142 +++++++++++++++++++++++--------------------
f29710
 1 file changed, 76 insertions(+), 66 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
f29710
index ea60eb98..83793397 100644
f29710
--- a/src/pcm/pcm_plugin.c
f29710
+++ b/src/pcm/pcm_plugin.c
f29710
@@ -460,82 +460,92 @@ snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
c4a1f5
 	return xfer > 0 ? xfer : err;
c4a1f5
 }
c4a1f5
 
c4a1f5
-static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
c4a1f5
+static snd_pcm_sframes_t
c4a1f5
+snd_pcm_plugin_sync_hw_ptr_capture(snd_pcm_t *pcm,
c4a1f5
+				   snd_pcm_sframes_t slave_size)
c4a1f5
 {
c4a1f5
 	snd_pcm_plugin_t *plugin = pcm->private_data;
c4a1f5
 	snd_pcm_t *slave = plugin->gen.slave;
c4a1f5
-	snd_pcm_sframes_t slave_size;
c4a1f5
+	const snd_pcm_channel_area_t *areas;
c4a1f5
+	snd_pcm_uframes_t xfer, hw_offset, size;
c4a1f5
 	int err;
c4a1f5
 
c4a1f5
-	slave_size = snd_pcm_avail_update(slave);
c4a1f5
+	xfer = snd_pcm_mmap_capture_avail(pcm);
c4a1f5
+	size = pcm->buffer_size - xfer;
c4a1f5
+	areas = snd_pcm_mmap_areas(pcm);
c4a1f5
+	hw_offset = snd_pcm_mmap_hw_offset(pcm);
c4a1f5
+	while (size > 0 && slave_size > 0) {
c4a1f5
+		snd_pcm_uframes_t frames = size;
c4a1f5
+		snd_pcm_uframes_t cont = pcm->buffer_size - hw_offset;
c4a1f5
+		const snd_pcm_channel_area_t *slave_areas;
c4a1f5
+		snd_pcm_uframes_t slave_offset;
c4a1f5
+		snd_pcm_uframes_t slave_frames = ULONG_MAX;
c4a1f5
+		snd_pcm_sframes_t result;
c4a1f5
+		/* As mentioned in the ALSA API (see pcm/pcm.c:942):
c4a1f5
+		 * The function #snd_pcm_avail_update()
c4a1f5
+		 * have to be called before any mmap begin+commit operation.
c4a1f5
+		 * Otherwise the snd_pcm_areas_copy will not called a second time.
c4a1f5
+		 * But this is needed, if the ring buffer wrap is reached and
c4a1f5
+		 * there is more data available.
c4a1f5
+		 */
c4a1f5
+		slave_size = snd_pcm_avail_update(slave);
c4a1f5
+		result = snd_pcm_mmap_begin(slave, &slave_areas, &slave_offset, &slave_frames);
c4a1f5
+		if (result < 0) {
c4a1f5
+			err = result;
c4a1f5
+			goto error;
c4a1f5
+		}
c4a1f5
+		if (frames > cont)
c4a1f5
+			frames = cont;
c4a1f5
+		frames = (plugin->read)(pcm, areas, hw_offset, frames,
c4a1f5
+					slave_areas, slave_offset, &slave_frames);
c4a1f5
+		result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
c4a1f5
+		if (result > 0 && (snd_pcm_uframes_t)result != slave_frames) {
c4a1f5
+			snd_pcm_sframes_t res;
c4a1f5
+			res = plugin->undo_read(slave, areas, hw_offset, frames, slave_frames - result);
c4a1f5
+			if (res < 0) {
c4a1f5
+				err = res;
c4a1f5
+				goto error;
c4a1f5
+			}
c4a1f5
+			frames -= res;
c4a1f5
+		}
c4a1f5
+		if (result <= 0) {
c4a1f5
+			err = result;
c4a1f5
+			goto error;
c4a1f5
+		}
c4a1f5
+		snd_pcm_mmap_hw_forward(pcm, frames);
c4a1f5
+		if (frames == cont)
c4a1f5
+			hw_offset = 0;
c4a1f5
+		else
c4a1f5
+			hw_offset += frames;
c4a1f5
+		size -= frames;
c4a1f5
+		slave_size -= slave_frames;
c4a1f5
+		xfer += frames;
c4a1f5
+	}
c4a1f5
+	return (snd_pcm_sframes_t)xfer;
c4a1f5
+error:
c4a1f5
+	return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
c4a1f5
+}
c4a1f5
+
c4a1f5
+static snd_pcm_sframes_t snd_pcm_plugin_sync_hw_ptr(snd_pcm_t *pcm,
c4a1f5
+						    snd_pcm_uframes_t slave_hw_ptr,
c4a1f5
+						    snd_pcm_sframes_t slave_size)
c4a1f5
+{
c4a1f5
 	if (pcm->stream == SND_PCM_STREAM_CAPTURE &&
c4a1f5
 	    pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED &&
c4a1f5
 	    pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED)
c4a1f5
-		goto _capture;
c4a1f5
-        *pcm->hw.ptr = *slave->hw.ptr;
c4a1f5
+		return snd_pcm_plugin_sync_hw_ptr_capture(pcm, slave_size);
c4a1f5
+        *pcm->hw.ptr = slave_hw_ptr;
c4a1f5
         return slave_size;
c4a1f5
- _capture:
c4a1f5
- 	{
c4a1f5
-		const snd_pcm_channel_area_t *areas;
c4a1f5
-		snd_pcm_uframes_t xfer, hw_offset, size;
c4a1f5
-		
c4a1f5
-		xfer = snd_pcm_mmap_capture_avail(pcm);
c4a1f5
-		size = pcm->buffer_size - xfer;
c4a1f5
-		areas = snd_pcm_mmap_areas(pcm);
c4a1f5
-		hw_offset = snd_pcm_mmap_hw_offset(pcm);
c4a1f5
-		while (size > 0 && slave_size > 0) {
c4a1f5
-			snd_pcm_uframes_t frames = size;
c4a1f5
-			snd_pcm_uframes_t cont = pcm->buffer_size - hw_offset;
c4a1f5
-			const snd_pcm_channel_area_t *slave_areas;
c4a1f5
-			snd_pcm_uframes_t slave_offset;
c4a1f5
-			snd_pcm_uframes_t slave_frames = ULONG_MAX;
c4a1f5
-			snd_pcm_sframes_t result;
c4a1f5
-			/* As mentioned in the ALSA API (see pcm/pcm.c:942):
c4a1f5
-			 * The function #snd_pcm_avail_update()
c4a1f5
-			 * have to be called before any mmap begin+commit operation.
c4a1f5
-			 * Otherwise the snd_pcm_areas_copy will not called a second time.
c4a1f5
-			 * But this is needed, if the ring buffer wrap is reached and
c4a1f5
-			 * there is more data available.
c4a1f5
-			 */
c4a1f5
-			slave_size = snd_pcm_avail_update(slave);
c4a1f5
-			result = snd_pcm_mmap_begin(slave, &slave_areas, &slave_offset, &slave_frames);
c4a1f5
-			if (result < 0) {
c4a1f5
-				err = result;
c4a1f5
-				goto error;
c4a1f5
-			}
c4a1f5
-			if (frames > cont)
c4a1f5
-				frames = cont;
c4a1f5
-			frames = (plugin->read)(pcm, areas, hw_offset, frames,
c4a1f5
-					      slave_areas, slave_offset, &slave_frames);
c4a1f5
-			result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
c4a1f5
-			if (result > 0 && (snd_pcm_uframes_t)result != slave_frames) {
c4a1f5
-				snd_pcm_sframes_t res;
c4a1f5
-				
c4a1f5
-				res = plugin->undo_read(slave, areas, hw_offset, frames, slave_frames - result);
c4a1f5
-				if (res < 0) {
c4a1f5
-					err = res;
c4a1f5
-					goto error;
c4a1f5
-				}
c4a1f5
-				frames -= res;
c4a1f5
-			}
c4a1f5
-			if (result <= 0) {
c4a1f5
-				err = result;
c4a1f5
-				goto error;
c4a1f5
-			}
c4a1f5
-			snd_pcm_mmap_hw_forward(pcm, frames);
c4a1f5
-			if (frames == cont)
c4a1f5
-				hw_offset = 0;
c4a1f5
-			else
c4a1f5
-				hw_offset += frames;
c4a1f5
-			size -= frames;
c4a1f5
-			slave_size -= slave_frames;
c4a1f5
-			xfer += frames;
c4a1f5
-		}
c4a1f5
-		return (snd_pcm_sframes_t)xfer;
c4a1f5
+}
c4a1f5
 
c4a1f5
-	error:
c4a1f5
-		return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
c4a1f5
-	}
c4a1f5
+static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
c4a1f5
+{
c4a1f5
+	snd_pcm_plugin_t *plugin = pcm->private_data;
c4a1f5
+	snd_pcm_t *slave = plugin->gen.slave;
c4a1f5
+	snd_pcm_sframes_t slave_size;
c4a1f5
+
c4a1f5
+	slave_size = snd_pcm_avail_update(slave);
c4a1f5
+	return snd_pcm_plugin_sync_hw_ptr(pcm, *slave->hw.ptr, slave_size);
c4a1f5
 }
c4a1f5
 
c4a1f5
 static int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 28cc099d9ea3962b033cb1cb9c3e07db828d9ff7 Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Sun, 3 Jan 2021 16:41:29 +0100
f29710
Subject: [PATCH 25/49] pcm: plugin - optimize sync in snd_pcm_plugin_status()
f29710
f29710
Do hw_ptr sync only once after the status call. This avoids
f29710
double update.
f29710
f29710
Also, the application pointer must not change when
f29710
the status is called. Add assert() call for this condition.
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_plugin.c | 7 ++-----
f29710
 1 file changed, 2 insertions(+), 5 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
f29710
index 83793397..6a815145 100644
f29710
--- a/src/pcm/pcm_plugin.c
f29710
+++ b/src/pcm/pcm_plugin.c
f29710
@@ -553,14 +553,11 @@ static int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
c4a1f5
 	snd_pcm_plugin_t *plugin = pcm->private_data;
f29710
 	snd_pcm_sframes_t err;
c4a1f5
 
f29710
-	/* sync with the latest hw and appl ptrs */
f29710
-	snd_pcm_plugin_avail_update(pcm);
f29710
-
c4a1f5
 	err = snd_pcm_status(plugin->gen.slave, status);
c4a1f5
 	if (err < 0)
c4a1f5
 		return err;
c4a1f5
-	status->appl_ptr = *pcm->appl.ptr;
c4a1f5
-	status->hw_ptr = *pcm->hw.ptr;
f29710
+	assert(status->appl_ptr == *pcm->appl.ptr);
c4a1f5
+	snd_pcm_plugin_sync_hw_ptr(pcm, status->hw_ptr, status->avail);
c4a1f5
 	return 0;
c4a1f5
 }
c4a1f5
 
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 21549e6583f1dfe5b2fe1aaa88345e4645dd96d0 Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Wed, 30 Dec 2020 17:49:33 +0100
f29710
Subject: [PATCH 26/49] Revert "pcm_plugin: fix delay"
f29710
f29710
This reverts commit aba87e509898ec9ddb3e319267d7c267409ff100.
f29710
f29710
The commit does not look good. The plugins must handle
f29710
the delay value correctly.
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_plugin.c | 6 ------
f29710
 1 file changed, 6 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
f29710
index 6a815145..5787a43d 100644
f29710
--- a/src/pcm/pcm_plugin.c
f29710
+++ b/src/pcm/pcm_plugin.c
f29710
@@ -142,12 +142,6 @@ static int snd_pcm_plugin_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
f29710
 	int err = snd_pcm_delay(plugin->gen.slave, &sd);
f29710
 	if (err < 0)
f29710
 		return err;
f29710
-        if (pcm->stream == SND_PCM_STREAM_CAPTURE &&
f29710
-	    pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED &&
f29710
-	    pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
f29710
-                sd += snd_pcm_mmap_capture_avail(pcm);
f29710
-        }        
c4a1f5
-
f29710
 	*delayp = sd;
f29710
 	return 0;
f29710
 }
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 6ca01c07ee13435d6c2db4e9121d9a86cc4b1457 Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Wed, 30 Dec 2020 19:14:25 +0100
f29710
Subject: [PATCH 27/49] pcm: ioplug - fix the delay calculation in the status
f29710
 callback
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_ioplug.c | 32 ++++++++++++++++++--------------
f29710
 1 file changed, 18 insertions(+), 14 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c
f29710
index 9b1b8ac3..f2315a10 100644
f29710
--- a/src/pcm/pcm_ioplug.c
f29710
+++ b/src/pcm/pcm_ioplug.c
f29710
@@ -107,9 +107,24 @@ static int snd_pcm_ioplug_channel_info(snd_pcm_t *pcm, snd_pcm_channel_info_t *i
f29710
 	return snd_pcm_channel_info_shm(pcm, info, -1);
f29710
 }
c4a1f5
 
f29710
+static int snd_pcm_ioplug_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
f29710
+{
f29710
+	ioplug_priv_t *io = pcm->private_data;
f29710
+
f29710
+	if (io->data->version >= 0x010001 &&
f29710
+	    io->data->callback->delay)
f29710
+		return io->data->callback->delay(io->data, delayp);
f29710
+	else {
f29710
+		snd_pcm_ioplug_hw_ptr_update(pcm);
f29710
+		*delayp = snd_pcm_mmap_hw_avail(pcm);
f29710
+	}
f29710
+	return 0;
f29710
+}
f29710
+
f29710
 static int snd_pcm_ioplug_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
c4a1f5
 {
f29710
 	ioplug_priv_t *io = pcm->private_data;
f29710
+	snd_pcm_sframes_t sd;
c4a1f5
 
f29710
 	memset(status, 0, sizeof(*status));
f29710
 	snd_pcm_ioplug_hw_ptr_update(pcm);
f29710
@@ -118,6 +133,9 @@ static int snd_pcm_ioplug_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
f29710
 	gettimestamp(&status->tstamp, pcm->tstamp_type);
f29710
 	status->avail = snd_pcm_mmap_avail(pcm);
f29710
 	status->avail_max = io->avail_max;
f29710
+	if (snd_pcm_ioplug_delay(pcm, &sd) < 0)
f29710
+		sd = snd_pcm_mmap_delay(pcm);
f29710
+	status->delay = sd;
f29710
 	return 0;
c4a1f5
 }
c4a1f5
 
f29710
@@ -133,20 +151,6 @@ static int snd_pcm_ioplug_hwsync(snd_pcm_t *pcm)
c4a1f5
 	return 0;
c4a1f5
 }
c4a1f5
 
f29710
-static int snd_pcm_ioplug_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
f29710
-{
f29710
-	ioplug_priv_t *io = pcm->private_data;
f29710
-
f29710
-	if (io->data->version >= 0x010001 &&
f29710
-	    io->data->callback->delay)
f29710
-		return io->data->callback->delay(io->data, delayp);
f29710
-	else {
f29710
-		snd_pcm_ioplug_hw_ptr_update(pcm);
f29710
-		*delayp = snd_pcm_mmap_hw_avail(pcm);
f29710
-	}
f29710
-	return 0;
f29710
-}
f29710
-
f29710
 static int snd_pcm_ioplug_reset(snd_pcm_t *pcm)
f29710
 {
f29710
 	ioplug_priv_t *io = pcm->private_data;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 5988bb3ff42827ab4c13f248291ad1767c8d973d Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Sun, 3 Jan 2021 16:56:38 +0100
f29710
Subject: [PATCH 28/49] pcm: rate - tidy up snd_pcm_rate_avail_update()
f29710
f29710
No functional change - just move the capture code to
f29710
a separate function for the better readability.
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_rate.c | 37 +++++++++++++++++++++----------------
f29710
 1 file changed, 21 insertions(+), 16 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c
f29710
index dc38e95e..7073f8ab 100644
f29710
--- a/src/pcm/pcm_rate.c
f29710
+++ b/src/pcm/pcm_rate.c
f29710
@@ -964,29 +964,18 @@ static snd_pcm_sframes_t snd_pcm_rate_mmap_commit(snd_pcm_t *pcm,
c4a1f5
 	return size;
c4a1f5
 }
c4a1f5
 
c4a1f5
-static snd_pcm_sframes_t snd_pcm_rate_avail_update(snd_pcm_t *pcm)
c4a1f5
+static snd_pcm_sframes_t snd_pcm_rate_avail_update_capture(snd_pcm_t *pcm,
c4a1f5
+							   snd_pcm_sframes_t slave_size)
c4a1f5
 {
c4a1f5
 	snd_pcm_rate_t *rate = pcm->private_data;
c4a1f5
 	snd_pcm_t *slave = rate->gen.slave;
c4a1f5
-	snd_pcm_sframes_t slave_size;
c4a1f5
-
c4a1f5
-	slave_size = snd_pcm_avail_update(slave);
c4a1f5
-	if (slave_size < 0)
c4a1f5
-		return slave_size;
c4a1f5
-
c4a1f5
-	if (pcm->stream == SND_PCM_STREAM_CAPTURE)
c4a1f5
-		goto _capture;
c4a1f5
-	snd_pcm_rate_sync_hwptr(pcm);
c4a1f5
-	snd_pcm_rate_sync_playback_area(pcm, rate->appl_ptr);
c4a1f5
-	return snd_pcm_mmap_avail(pcm);
c4a1f5
- _capture: {
c4a1f5
 	snd_pcm_uframes_t xfer, hw_offset, size;
c4a1f5
 	
c4a1f5
 	xfer = snd_pcm_mmap_capture_avail(pcm);
c4a1f5
 	size = pcm->buffer_size - xfer;
c4a1f5
 	hw_offset = snd_pcm_mmap_hw_offset(pcm);
c4a1f5
 	while (size >= pcm->period_size &&
c4a1f5
-	       (snd_pcm_uframes_t)slave_size >= rate->gen.slave->period_size) {
c4a1f5
+	       (snd_pcm_uframes_t)slave_size >= slave->period_size) {
c4a1f5
 		int err = snd_pcm_rate_grab_next_period(pcm, hw_offset);
c4a1f5
 		if (err < 0)
c4a1f5
 			return err;
f29710
@@ -994,13 +983,29 @@ static snd_pcm_sframes_t snd_pcm_rate_avail_update(snd_pcm_t *pcm)
c4a1f5
 			return (snd_pcm_sframes_t)xfer;
c4a1f5
 		xfer += pcm->period_size;
c4a1f5
 		size -= pcm->period_size;
c4a1f5
-		slave_size -= rate->gen.slave->period_size;
c4a1f5
+		slave_size -= slave->period_size;
c4a1f5
 		hw_offset += pcm->period_size;
c4a1f5
 		hw_offset %= pcm->buffer_size;
c4a1f5
 		snd_pcm_mmap_hw_forward(pcm, pcm->period_size);
c4a1f5
 	}
c4a1f5
 	return (snd_pcm_sframes_t)xfer;
c4a1f5
- }
c4a1f5
+}
c4a1f5
+
c4a1f5
+static snd_pcm_sframes_t snd_pcm_rate_avail_update(snd_pcm_t *pcm)
c4a1f5
+{
c4a1f5
+	snd_pcm_rate_t *rate = pcm->private_data;
c4a1f5
+	snd_pcm_sframes_t slave_size;
c4a1f5
+
c4a1f5
+	slave_size = snd_pcm_avail_update(rate->gen.slave);
c4a1f5
+	if (slave_size < 0)
c4a1f5
+		return slave_size;
c4a1f5
+
c4a1f5
+	if (pcm->stream == SND_PCM_STREAM_CAPTURE)
c4a1f5
+		return snd_pcm_rate_avail_update_capture(pcm, slave_size);
c4a1f5
+
c4a1f5
+	snd_pcm_rate_sync_hwptr(pcm);
c4a1f5
+	snd_pcm_rate_sync_playback_area(pcm, rate->appl_ptr);
c4a1f5
+	return snd_pcm_mmap_avail(pcm);
c4a1f5
 }
c4a1f5
 
f29710
 static int snd_pcm_rate_htimestamp(snd_pcm_t *pcm,
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 6cee452eabc5cfdf0a6955033b8ac8f6e12ea883 Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Sun, 3 Jan 2021 17:13:50 +0100
f29710
Subject: [PATCH 29/49] pcm: ioplug - fix the delay calculation for old plugins
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_ioplug.c | 2 +-
f29710
 1 file changed, 1 insertion(+), 1 deletion(-)
f29710
f29710
diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c
f29710
index f2315a10..e141b1f9 100644
f29710
--- a/src/pcm/pcm_ioplug.c
f29710
+++ b/src/pcm/pcm_ioplug.c
f29710
@@ -116,7 +116,7 @@ static int snd_pcm_ioplug_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
f29710
 		return io->data->callback->delay(io->data, delayp);
f29710
 	else {
f29710
 		snd_pcm_ioplug_hw_ptr_update(pcm);
f29710
-		*delayp = snd_pcm_mmap_hw_avail(pcm);
f29710
+		*delayp = snd_pcm_mmap_delay(pcm);
f29710
 	}
f29710
 	return 0;
f29710
 }
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From fc0f7af9ee7bd4c31c2bab229e8e79eb96e908fa Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Mon, 4 Jan 2021 12:29:00 +0100
f29710
Subject: [PATCH 30/49] pcm: rate - use pcm_frame_diff() in
f29710
 snd_pcm_rate_playback_internal_delay()
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_rate.c | 6 +-----
f29710
 1 file changed, 1 insertion(+), 5 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c
f29710
index 7073f8ab..abb2753f 100644
f29710
--- a/src/pcm/pcm_rate.c
f29710
+++ b/src/pcm/pcm_rate.c
f29710
@@ -612,11 +612,7 @@ static snd_pcm_uframes_t snd_pcm_rate_playback_internal_delay(snd_pcm_t *pcm)
f29710
 {
f29710
 	snd_pcm_rate_t *rate = pcm->private_data;
f29710
 
f29710
-	if (rate->appl_ptr < rate->last_commit_ptr) {
f29710
-		return rate->appl_ptr - rate->last_commit_ptr + pcm->boundary;
f29710
-	} else {
f29710
-		return rate->appl_ptr - rate->last_commit_ptr;
f29710
-	}
f29710
+	return pcm_frame_diff(rate->appl_ptr, rate->last_commit_ptr, pcm->boundary);
f29710
 }
f29710
 
f29710
 static int snd_pcm_rate_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From da5b70d3fae091a8568b80a476c1cf340965805a Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Mon, 4 Jan 2021 12:32:25 +0100
f29710
Subject: [PATCH 31/49] pcm: plugin - fix status code for capture
f29710
f29710
The recent updates do not take in account the possible
f29710
calls for the capture stream. Fix the avail and delay
f29710
inconsistencies (and assert).
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_plugin.c | 21 +++++++++++++++++++--
f29710
 1 file changed, 19 insertions(+), 2 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
f29710
index 5787a43d..7ed6f25a 100644
f29710
--- a/src/pcm/pcm_plugin.c
f29710
+++ b/src/pcm/pcm_plugin.c
f29710
@@ -545,13 +545,30 @@ static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
f29710
 static int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
f29710
 {
f29710
 	snd_pcm_plugin_t *plugin = pcm->private_data;
f29710
-	snd_pcm_sframes_t err;
f29710
+	snd_pcm_sframes_t err, diff;
f29710
 
f29710
 	err = snd_pcm_status(plugin->gen.slave, status);
f29710
 	if (err < 0)
f29710
 		return err;
f29710
-	assert(status->appl_ptr == *pcm->appl.ptr);
f29710
 	snd_pcm_plugin_sync_hw_ptr(pcm, status->hw_ptr, status->avail);
f29710
+	/*
f29710
+	 * For capture stream, the situation is more complicated, because
f29710
+	 * snd_pcm_plugin_avail_update() commits the data to the slave pcm.
f29710
+	 * It means that the slave appl_ptr is updated. Calculate diff and
f29710
+	 * update the delay and avail.
f29710
+	 *
f29710
+	 * This resolves the data inconsistency for immediate calls:
f29710
+	 *    snd_pcm_avail_update()
f29710
+	 *    snd_pcm_status()
f29710
+	 */
f29710
+	if (pcm->stream == SND_PCM_STREAM_CAPTURE) {
f29710
+		status->appl_ptr = *pcm->appl.ptr;
f29710
+		diff = pcm_frame_diff(status->appl_ptr, *pcm->appl.ptr, pcm->boundary);
f29710
+		status->avail += diff;
f29710
+		status->delay += diff;
f29710
+	} else {
f29710
+		assert(status->appl_ptr == *pcm->appl.ptr);
f29710
+	}
f29710
 	return 0;
f29710
 }
f29710
 
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From ac520b2ed11f31e789a4da1d55e360e3eaeac50d Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Mon, 4 Jan 2021 17:14:42 +0100
f29710
Subject: [PATCH 32/49] pcm: rate - use pcm_frame_diff() on related places
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_rate.c | 20 +++++++-------------
f29710
 1 file changed, 7 insertions(+), 13 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c
f29710
index abb2753f..3d301d0e 100644
f29710
--- a/src/pcm/pcm_rate.c
f29710
+++ b/src/pcm/pcm_rate.c
f29710
@@ -561,17 +561,16 @@ snd_pcm_rate_read_areas1(snd_pcm_t *pcm,
f29710
 
f29710
 static inline void snd_pcm_rate_sync_hwptr0(snd_pcm_t *pcm, snd_pcm_uframes_t slave_hw_ptr)
f29710
 {
f29710
-	snd_pcm_rate_t *rate = pcm->private_data;
f29710
-
f29710
-	snd_pcm_sframes_t slave_hw_ptr_diff = slave_hw_ptr - rate->last_slave_hw_ptr;
f29710
+	snd_pcm_rate_t *rate;
f29710
+	snd_pcm_sframes_t slave_hw_ptr_diff;
f29710
 	snd_pcm_sframes_t last_slave_hw_ptr_frac;
f29710
 
f29710
 	if (pcm->stream != SND_PCM_STREAM_PLAYBACK)
f29710
 		return;
f29710
 
f29710
-	if (slave_hw_ptr_diff < 0)
f29710
-		slave_hw_ptr_diff += rate->gen.slave->boundary; /* slave boundary wraparound */
f29710
-	else if (slave_hw_ptr_diff == 0)
f29710
+	rate = pcm->private_data;
f29710
+	slave_hw_ptr_diff = pcm_frame_diff(slave_hw_ptr, rate->last_slave_hw_ptr, rate->gen.slave->boundary);
f29710
+	if (slave_hw_ptr_diff == 0)
f29710
 		return;
f29710
 	last_slave_hw_ptr_frac = rate->last_slave_hw_ptr % rate->gen.slave->period_size;
f29710
 	/* While handling fraction part fo slave period, rounded value will be
f29710
@@ -922,10 +921,7 @@ static int snd_pcm_rate_sync_playback_area(snd_pcm_t *pcm, snd_pcm_uframes_t app
f29710
 	if (slave_size < 0)
f29710
 		return slave_size;
f29710
 
f29710
-	if (appl_ptr < rate->last_commit_ptr)
f29710
-		xfer = appl_ptr - rate->last_commit_ptr + pcm->boundary;
f29710
-	else
f29710
-		xfer = appl_ptr - rate->last_commit_ptr;
f29710
+	xfer = pcm_frame_diff(appl_ptr, rate->last_commit_ptr, pcm->boundary);
f29710
 	while (xfer >= pcm->period_size &&
f29710
 	       (snd_pcm_uframes_t)slave_size >= rate->gen.slave->period_size) {
f29710
 		err = snd_pcm_rate_commit_next_period(pcm, rate->last_commit_ptr % pcm->buffer_size);
f29710
@@ -1059,9 +1055,7 @@ static int snd_pcm_rate_drain(snd_pcm_t *pcm)
c4a1f5
 		sw_params.avail_min = 1;
c4a1f5
 		snd_pcm_sw_params(rate->gen.slave, &sw_params);
c4a1f5
 
c4a1f5
-		size = rate->appl_ptr - rate->last_commit_ptr;
c4a1f5
-		if (size > pcm->boundary)
c4a1f5
-			size -= pcm->boundary;
c4a1f5
+		size = pcm_frame_diff(rate->appl_ptr, rate->last_commit_ptr, pcm->boundary);
c4a1f5
 		ofs = rate->last_commit_ptr % pcm->buffer_size;
c4a1f5
 		while (size > 0) {
c4a1f5
 			snd_pcm_uframes_t psize, spsize;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From b62f66442bfbcea7c11afe4917e196fa95a65083 Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Mon, 4 Jan 2021 17:27:32 +0100
f29710
Subject: [PATCH 33/49] pcm: rate - fix the capture delay values
f29710
f29710
Use the correct snd_pcm_mmap_capture_delay() function instead
f29710
snd_pcm_mmap_capture_hw_avail().
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_rate.c | 8 ++------
f29710
 1 file changed, 2 insertions(+), 6 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c
f29710
index 3d301d0e..770aafea 100644
f29710
--- a/src/pcm/pcm_rate.c
f29710
+++ b/src/pcm/pcm_rate.c
f29710
@@ -632,7 +632,7 @@ static int snd_pcm_rate_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
f29710
 				+ snd_pcm_rate_playback_internal_delay(pcm);
f29710
 	} else {
f29710
 		*delayp = rate->ops.output_frames(rate->obj, slave_delay)
f29710
-				+ snd_pcm_mmap_capture_hw_avail(pcm);
f29710
+				+ snd_pcm_mmap_capture_delay(pcm);
f29710
 	}
f29710
 	return 0;
f29710
 }
f29710
@@ -1157,12 +1157,8 @@ static int snd_pcm_rate_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
c4a1f5
 		status->avail = snd_pcm_mmap_playback_avail(pcm);
c4a1f5
 		status->avail_max = rate->ops.input_frames(rate->obj, status->avail_max);
c4a1f5
 	} else {
c4a1f5
-		/* FIXME: Maybe possible to somthing similar to
c4a1f5
-		 * snd_pcm_rate_playback_internal_delay()
c4a1f5
-		 * for the capture case.
c4a1f5
-		 */
c4a1f5
 		status->delay = rate->ops.output_frames(rate->obj, status->delay)
c4a1f5
-					+ snd_pcm_mmap_capture_hw_avail(pcm);
c4a1f5
+					+ snd_pcm_mmap_capture_delay(pcm);
c4a1f5
 		status->avail = snd_pcm_mmap_capture_avail(pcm);
c4a1f5
 		status->avail_max = rate->ops.output_frames(rate->obj, status->avail_max);
c4a1f5
 	}
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 437b5b3aae8b1d9f65289f563deb0fa6356a0fa6 Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Thu, 7 Jan 2021 17:32:11 +0100
f29710
Subject: [PATCH 34/49] ucm: fix possible memory leak in parse_verb_file()
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/ucm/parser.c | 2 +-
f29710
 1 file changed, 1 insertion(+), 1 deletion(-)
f29710
f29710
diff --git a/src/ucm/parser.c b/src/ucm/parser.c
f29710
index 75b78826..c8bee1f2 100644
f29710
--- a/src/ucm/parser.c
f29710
+++ b/src/ucm/parser.c
f29710
@@ -1575,7 +1575,7 @@ static int parse_verb_file(snd_use_case_mgr_t *uc_mgr,
f29710
 	/* in-place evaluation */
f29710
 	err = uc_mgr_evaluate_inplace(uc_mgr, cfg);
f29710
 	if (err < 0)
f29710
-		return err;
f29710
+		goto _err;
f29710
 
f29710
 	/* parse master config sections */
f29710
 	snd_config_for_each(i, next, cfg) {
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From d0bb8f84c92357bfd0e024efe5f6d53a963c4d7a Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Thu, 7 Jan 2021 17:34:00 +0100
f29710
Subject: [PATCH 35/49] topology: tplg_pprint_integer() fix coverity
f29710
 uninitalized variable error
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/topology/save.c | 2 ++
f29710
 1 file changed, 2 insertions(+)
f29710
c4a1f5
diff --git a/src/topology/save.c b/src/topology/save.c
f29710
index c7a5a801..f7af7af3 100644
c4a1f5
--- a/src/topology/save.c
c4a1f5
+++ b/src/topology/save.c
c4a1f5
@@ -133,6 +133,8 @@ static int tplg_pprint_integer(snd_config_t *n, char **ret)
c4a1f5
 		if (llval < INT_MIN || llval > UINT_MAX)
c4a1f5
 			return snd_config_get_ascii(n, ret);
c4a1f5
 		lval = llval;
c4a1f5
+	} else {
c4a1f5
+		lval = 0;
c4a1f5
 	}
c4a1f5
 	err = tplg_nice_value_format(buf, sizeof(buf), (unsigned int)lval);
c4a1f5
 	if (err < 0)
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From b8764a061b83284be60adc01c1f7b035c4484ace Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Thu, 7 Jan 2021 17:36:04 +0100
f29710
Subject: [PATCH 36/49] topology: tplg_add_widget_object() - do not use invalid
f29710
 elem_ctl
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/topology/dapm.c | 1 +
f29710
 1 file changed, 1 insertion(+)
f29710
f29710
diff --git a/src/topology/dapm.c b/src/topology/dapm.c
f29710
index 92dc01aa..f6a84a60 100644
f29710
--- a/src/topology/dapm.c
f29710
+++ b/src/topology/dapm.c
f29710
@@ -836,6 +836,7 @@ int tplg_add_widget_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
f29710
 		default:
f29710
 			SNDERR("widget %s: invalid type %d for ctl %d",
f29710
 				wt->name, ct->type, i);
f29710
+			ret = -EINVAL;
f29710
 			break;
f29710
 		}
f29710
 
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 0dbaba95f4bc59602bf2d3fb12a60db7444e5892 Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Thu, 7 Jan 2021 17:38:50 +0100
f29710
Subject: [PATCH 37/49] topology: tplg_decode_pcm() - add missing log argument
f29710
 (compress)
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/topology/pcm.c | 2 +-
f29710
 1 file changed, 1 insertion(+), 1 deletion(-)
f29710
f29710
diff --git a/src/topology/pcm.c b/src/topology/pcm.c
f29710
index c8f41862..a473b59b 100644
f29710
--- a/src/topology/pcm.c
f29710
+++ b/src/topology/pcm.c
f29710
@@ -2020,7 +2020,7 @@ next:
f29710
 	pt->playback = pcm->playback;
f29710
 	pt->capture = pcm->capture;
f29710
 	pt->compress = pcm->compress;
f29710
-	tplg_log(tplg, 'D', pos, "pcm: playback %d capture %d compress",
f29710
+	tplg_log(tplg, 'D', pos, "pcm: playback %d capture %d compress %d",
f29710
 		 pt->playback, pt->capture, pt->compress);
f29710
 	pt->num_streams = pcm->num_streams;
f29710
 	pt->flag_mask = pcm->flag_mask;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 51e1d486ce4535923692bd1d7e59d5aa3a29cd50 Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Thu, 7 Jan 2021 17:40:42 +0100
f29710
Subject: [PATCH 38/49] topology: parse_tuple_set() - remove dead condition
f29710
 code
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/topology/data.c | 2 +-
f29710
 1 file changed, 1 insertion(+), 1 deletion(-)
f29710
f29710
diff --git a/src/topology/data.c b/src/topology/data.c
f29710
index c2931bd2..5633cdc3 100644
f29710
--- a/src/topology/data.c
f29710
+++ b/src/topology/data.c
f29710
@@ -860,7 +860,7 @@ static int parse_tuple_set(snd_config_t *cfg,
f29710
 			}
f29710
 
f29710
 			if ((type == SND_SOC_TPLG_TUPLE_TYPE_WORD
f29710
-					&& tuple_val > UINT_MAX)
f29710
+					/* && tuple_val > UINT_MAX */)
f29710
 				|| (type == SND_SOC_TPLG_TUPLE_TYPE_SHORT
f29710
 					&& tuple_val > USHRT_MAX)
f29710
 				|| (type == SND_SOC_TPLG_TUPLE_TYPE_BYTE
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 3f63dc26445ae7c215e48a57af83b6da325f166d Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Thu, 7 Jan 2021 17:41:38 +0100
f29710
Subject: [PATCH 39/49] ucm: uc_mgr_substitute_tree() fix use after free
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/ucm/ucm_subs.c | 3 ++-
f29710
 1 file changed, 2 insertions(+), 1 deletion(-)
f29710
f29710
diff --git a/src/ucm/ucm_subs.c b/src/ucm/ucm_subs.c
f29710
index f608bb09..df6d736f 100644
f29710
--- a/src/ucm/ucm_subs.c
f29710
+++ b/src/ucm/ucm_subs.c
f29710
@@ -417,11 +417,12 @@ int uc_mgr_substitute_tree(snd_use_case_mgr_t *uc_mgr, snd_config_t *node)
f29710
 		if (err < 0)
f29710
 			return err;
f29710
 		err = snd_config_set_id(node, s);
f29710
-		free(s);
f29710
 		if (err < 0) {
f29710
 			uc_error("unable to set substituted id '%s' (old id '%s')", s, id);
f29710
+			free(s);
f29710
 			return err;
f29710
 		}
f29710
+		free(s);
f29710
 	}
f29710
 	if (snd_config_get_type(node) != SND_CONFIG_TYPE_COMPOUND) {
f29710
 		if (snd_config_get_type(node) == SND_CONFIG_TYPE_STRING) {
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 45f503632acf24877c466a7c1c74d8a26414bf3e Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Thu, 7 Jan 2021 17:45:27 +0100
f29710
Subject: [PATCH 40/49] topology: sort_config() cleanups - use goto for the
f29710
 error path
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/topology/save.c | 15 +++++++--------
f29710
 1 file changed, 7 insertions(+), 8 deletions(-)
f29710
f29710
diff --git a/src/topology/save.c b/src/topology/save.c
f29710
index f7af7af3..fecbc6a5 100644
f29710
--- a/src/topology/save.c
f29710
+++ b/src/topology/save.c
f29710
@@ -180,29 +180,28 @@ static snd_config_t *sort_config(const char *id, snd_config_t *src)
c4a1f5
 	}
c4a1f5
 	if (array <= 0)
c4a1f5
 		qsort(a, count, sizeof(a[0]), _compar);
c4a1f5
-	if (snd_config_make_compound(&dst, id, count == 1)) {
c4a1f5
-		free(a);
c4a1f5
-		return NULL;
c4a1f5
-	}
c4a1f5
+	if (snd_config_make_compound(&dst, id, count == 1))
c4a1f5
+		goto lerr;
c4a1f5
 	for (index = 0; index < count; index++) {
c4a1f5
 		snd_config_t *s = a[index];
c4a1f5
 		const char *id2;
c4a1f5
 		if (snd_config_get_id(s, &id2)) {
c4a1f5
 			snd_config_delete(dst);
c4a1f5
-			free(a);
c4a1f5
-			return NULL;
c4a1f5
+			goto lerr;
c4a1f5
 		}
c4a1f5
 		s = sort_config(id2, s);
c4a1f5
 		if (s == NULL || snd_config_add(dst, s)) {
c4a1f5
 			if (s)
c4a1f5
 				snd_config_delete(s);
c4a1f5
 			snd_config_delete(dst);
c4a1f5
-			free(a);
c4a1f5
-			return NULL;
c4a1f5
+			goto lerr;
c4a1f5
 		}
c4a1f5
 	}
c4a1f5
 	free(a);
c4a1f5
 	return dst;
c4a1f5
+lerr:
c4a1f5
+	free(a);
c4a1f5
+	return NULL;
c4a1f5
 }
c4a1f5
 
c4a1f5
 static int tplg_check_quoted(const unsigned char *p)
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 93752fb4de397554e92a4eb9079f77dabaec7d7f Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Thu, 7 Jan 2021 17:49:25 +0100
f29710
Subject: [PATCH 41/49] conf: USB - add "Xonar U7 MKII" to
f29710
 USB-Audio.pcm.iec958_device
f29710
f29710
BugLink: https://github.com/alsa-project/alsa-lib/issues/100
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/conf/cards/USB-Audio.conf | 1 +
f29710
 1 file changed, 1 insertion(+)
f29710
f29710
diff --git a/src/conf/cards/USB-Audio.conf b/src/conf/cards/USB-Audio.conf
f29710
index 9b64af3c..b1b74b02 100644
f29710
--- a/src/conf/cards/USB-Audio.conf
f29710
+++ b/src/conf/cards/USB-Audio.conf
f29710
@@ -39,6 +39,7 @@ USB-Audio.pcm.iec958_device {
f29710
 	# "NoiseBlaster 3000" 42
f29710
 	"USB Sound Blaster HD" 1
f29710
 	"Xonar U7" 1
f29710
+	"Xonar U7 MKII" 1
f29710
 	"ASUS XONAR U5" 1
f29710
 	"XONAR U5" 1
f29710
 	"XONAR SOUND CARD" 1
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 644514e85da169670e4a490b7b15b5ecfcec92c0 Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Mon, 18 Jan 2021 21:09:43 +0100
f29710
Subject: [PATCH 42/49] pcm_plugin: set the initial hw_ptr/appl_ptr from the
f29710
 child pcm
f29710
f29710
The direct plugins (dmix & etc.) sets own initial
f29710
hw_ptr and appl_ptr. Use this initial settings
f29710
to export correct values in snd_pcm_status().
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_plugin.c | 32 +++++++++++++++++---------------
f29710
 1 file changed, 17 insertions(+), 15 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
f29710
index 7ed6f25a..ff254eba 100644
f29710
--- a/src/pcm/pcm_plugin.c
f29710
+++ b/src/pcm/pcm_plugin.c
f29710
@@ -146,15 +146,14 @@ static int snd_pcm_plugin_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
f29710
 	return 0;
c4a1f5
 }
c4a1f5
 
f29710
-static int snd_pcm_plugin_prepare(snd_pcm_t *pcm)
f29710
+static int snd_pcm_plugin_call_init_cb(snd_pcm_t *pcm, snd_pcm_plugin_t *plugin)
f29710
 {
f29710
-	snd_pcm_plugin_t *plugin = pcm->private_data;
f29710
+	snd_pcm_t *slave = plugin->gen.slave;
f29710
 	int err;
f29710
-	err = snd_pcm_prepare(plugin->gen.slave);
f29710
-	if (err < 0)
f29710
-		return err;
f29710
-	*pcm->hw.ptr = 0;
f29710
-	*pcm->appl.ptr = 0;
f29710
+
f29710
+	assert(pcm->boundary == slave->boundary);
f29710
+	*pcm->hw.ptr = *slave->hw.ptr;
f29710
+	*pcm->appl.ptr = *slave->appl.ptr;
f29710
 	if (plugin->init) {
f29710
 		err = plugin->init(pcm);
f29710
 		if (err < 0)
f29710
@@ -163,6 +162,16 @@ static int snd_pcm_plugin_prepare(snd_pcm_t *pcm)
f29710
 	return 0;
c4a1f5
 }
c4a1f5
 
f29710
+static int snd_pcm_plugin_prepare(snd_pcm_t *pcm)
f29710
+{
f29710
+	snd_pcm_plugin_t *plugin = pcm->private_data;
f29710
+	int err;
f29710
+	err = snd_pcm_prepare(plugin->gen.slave);
f29710
+	if (err < 0)
f29710
+		return err;
f29710
+	return snd_pcm_plugin_call_init_cb(pcm, plugin);
f29710
+}
f29710
+
f29710
 static int snd_pcm_plugin_reset(snd_pcm_t *pcm)
f29710
 {
f29710
 	snd_pcm_plugin_t *plugin = pcm->private_data;
f29710
@@ -170,14 +179,7 @@ static int snd_pcm_plugin_reset(snd_pcm_t *pcm)
f29710
 	err = snd_pcm_reset(plugin->gen.slave);
c4a1f5
 	if (err < 0)
f29710
 		return err;
f29710
-	*pcm->hw.ptr = 0;
f29710
-	*pcm->appl.ptr = 0;
f29710
-	if (plugin->init) {
f29710
-		err = plugin->init(pcm);
f29710
-		if (err < 0)
f29710
-			return err;
f29710
-	}
f29710
-	return 0;
f29710
+	return snd_pcm_plugin_call_init_cb(pcm, plugin);
f29710
 }
c4a1f5
 
f29710
 static snd_pcm_sframes_t snd_pcm_plugin_rewindable(snd_pcm_t *pcm)
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 0de72e63d7bd180566c71f6fb01d7719525ee326 Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Tue, 19 Jan 2021 11:17:00 +0100
f29710
Subject: [PATCH 43/49] pcm: dmix/dshare - delay calculation fixes and cleanups
f29710
f29710
Unfortunately, we cannot use status->avail from slave, because this value
f29710
does not wrap to the buffer size and it may even overflow slave boundary
f29710
(endless run). We can use only hw_ptr from slave.
f29710
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_dmix.c   | 5 ++---
f29710
 src/pcm/pcm_dshare.c | 5 ++---
f29710
 2 files changed, 4 insertions(+), 6 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c
f29710
index 5b7472d9..be2675af 100644
f29710
--- a/src/pcm/pcm_dmix.c
f29710
+++ b/src/pcm/pcm_dmix.c
f29710
@@ -488,8 +488,7 @@ static int snd_pcm_dmix_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
f29710
 	case SNDRV_PCM_STATE_DRAINING:
f29710
 	case SNDRV_PCM_STATE_RUNNING:
f29710
 		snd_pcm_dmix_sync_ptr0(pcm, status->hw_ptr);
f29710
-		status->delay += snd_pcm_mmap_playback_delay(pcm)
f29710
-				+ status->avail - dmix->spcm->buffer_size;
f29710
+		status->delay = snd_pcm_mmap_playback_delay(pcm);
f29710
 		break;
f29710
 	default:
f29710
 		break;
f29710
@@ -518,7 +517,7 @@ static int snd_pcm_dmix_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
f29710
 	case SNDRV_PCM_STATE_PREPARED:
f29710
 	case SNDRV_PCM_STATE_SUSPENDED:
f29710
 	case STATE_RUN_PENDING:
f29710
-		*delayp = snd_pcm_mmap_playback_hw_avail(pcm);
f29710
+		*delayp = snd_pcm_mmap_playback_delay(pcm);
f29710
 		return 0;
f29710
 	case SNDRV_PCM_STATE_XRUN:
f29710
 		return -EPIPE;
f29710
diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c
f29710
index 8a672572..10243013 100644
f29710
--- a/src/pcm/pcm_dshare.c
f29710
+++ b/src/pcm/pcm_dshare.c
f29710
@@ -237,8 +237,7 @@ static int snd_pcm_dshare_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
f29710
 	case SNDRV_PCM_STATE_DRAINING:
f29710
 	case SNDRV_PCM_STATE_RUNNING:
f29710
 		snd_pcm_dshare_sync_ptr0(pcm, status->hw_ptr);
f29710
-		status->delay += snd_pcm_mmap_playback_delay(pcm)
f29710
-				+ status->avail - dshare->spcm->buffer_size;
f29710
+		status->delay += snd_pcm_mmap_playback_delay(pcm);
f29710
 		break;
f29710
 	default:
f29710
 		break;
f29710
@@ -290,7 +289,7 @@ static int snd_pcm_dshare_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
f29710
 	case SNDRV_PCM_STATE_PREPARED:
f29710
 	case SNDRV_PCM_STATE_SUSPENDED:
f29710
 	case STATE_RUN_PENDING:
f29710
-		*delayp = snd_pcm_mmap_playback_hw_avail(pcm);
f29710
+		*delayp = snd_pcm_mmap_playback_delay(pcm);
f29710
 		return 0;
f29710
 	case SNDRV_PCM_STATE_XRUN:
f29710
 		return -EPIPE;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From ae7362c996e0b991c399cc26c6d0b3c8e295e83c Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Wed, 20 Jan 2021 16:58:33 +0100
f29710
Subject: [PATCH 44/49] topology: fix 'parse_tuple_set() - remove dead
f29710
 condition code'
f29710
f29710
The whole SND_SOC_TPLG_TUPLE_TYPE_WORD condition part must be
f29710
commented out, otherwise the condition is always true.
f29710
f29710
Fixes: 51e1d486ce ("topology: parse_tuple_set() - remove dead condition code")
f29710
BugLink: https://github.com/alsa-project/alsa-lib/issues/114
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/topology/data.c | 10 +++++-----
f29710
 1 file changed, 5 insertions(+), 5 deletions(-)
f29710
f29710
diff --git a/src/topology/data.c b/src/topology/data.c
f29710
index 5633cdc3..0546d63e 100644
f29710
--- a/src/topology/data.c
f29710
+++ b/src/topology/data.c
f29710
@@ -859,11 +859,11 @@ static int parse_tuple_set(snd_config_t *cfg,
f29710
 				goto err;
f29710
 			}
f29710
 
f29710
-			if ((type == SND_SOC_TPLG_TUPLE_TYPE_WORD
f29710
-					/* && tuple_val > UINT_MAX */)
f29710
-				|| (type == SND_SOC_TPLG_TUPLE_TYPE_SHORT
f29710
-					&& tuple_val > USHRT_MAX)
f29710
-				|| (type == SND_SOC_TPLG_TUPLE_TYPE_BYTE
f29710
+			if (/* (type == SND_SOC_TPLG_TUPLE_TYPE_WORD
f29710
+					&& tuple_val > UINT_MAX) || */
f29710
+				(type == SND_SOC_TPLG_TUPLE_TYPE_SHORT
f29710
+					&& tuple_val > USHRT_MAX) ||
f29710
+				(type == SND_SOC_TPLG_TUPLE_TYPE_BYTE
f29710
 					&& tuple_val > UCHAR_MAX)) {
f29710
 				SNDERR("tuple %s: invalid value", id);
f29710
 				goto err;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From f2c1a9f3279a30cbd8dcba1eaf0d52f50b56b886 Mon Sep 17 00:00:00 2001
f29710
From: Takashi Iwai <tiwai@suse.de>
f29710
Date: Fri, 22 Jan 2021 15:48:39 +0100
f29710
Subject: [PATCH 45/49] pcm: direct: Fix the missing appl_ptr update
f29710
f29710
A snd_pcm_status() call for the direct plugins receives the status
f29710
from the slave PCM, but this doesn't contain a valid appl_ptr, since
f29710
the slave PCM for the direct plugins is in a free-wheel mode, hence
f29710
the appl_ptr is always zero.  This result in the inconsistent
f29710
status->appl_ptr and pcm->appl.ptr, hitting the recently introduced
f29710
assert() call.
f29710
f29710
Fix it by transferring the plugin's appl_ptr to the upper caller.
f29710
f29710
BugLink: https://bugzilla.opensuse.org/show_bug.cgi?id=1181194
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_dmix.c   | 1 +
f29710
 src/pcm/pcm_dshare.c | 1 +
f29710
 src/pcm/pcm_dsnoop.c | 1 +
f29710
 3 files changed, 3 insertions(+)
f29710
f29710
diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c
f29710
index be2675af..d8495065 100644
f29710
--- a/src/pcm/pcm_dmix.c
f29710
+++ b/src/pcm/pcm_dmix.c
f29710
@@ -495,6 +495,7 @@ static int snd_pcm_dmix_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
c4a1f5
 	}
f29710
 
f29710
 	status->state = snd_pcm_dmix_state(pcm);
f29710
+	status->appl_ptr = *pcm->appl.ptr; /* slave PCM doesn't set appl_ptr */
f29710
 	status->trigger_tstamp = dmix->trigger_tstamp;
f29710
 	status->avail = snd_pcm_mmap_playback_avail(pcm);
f29710
 	status->avail_max = status->avail > dmix->avail_max ? status->avail : dmix->avail_max;
f29710
diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c
f29710
index 10243013..dccb137b 100644
f29710
--- a/src/pcm/pcm_dshare.c
f29710
+++ b/src/pcm/pcm_dshare.c
f29710
@@ -243,6 +243,7 @@ static int snd_pcm_dshare_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
f29710
 		break;
f29710
 	}
f29710
 	status->state = snd_pcm_dshare_state(pcm);
f29710
+	status->appl_ptr = *pcm->appl.ptr; /* slave PCM doesn't set appl_ptr */
f29710
 	status->trigger_tstamp = dshare->trigger_tstamp;
f29710
 	status->avail = snd_pcm_mmap_playback_avail(pcm);
f29710
 	status->avail_max = status->avail > dshare->avail_max ? status->avail : dshare->avail_max;
f29710
diff --git a/src/pcm/pcm_dsnoop.c b/src/pcm/pcm_dsnoop.c
f29710
index c6e8cd27..695bf4aa 100644
f29710
--- a/src/pcm/pcm_dsnoop.c
f29710
+++ b/src/pcm/pcm_dsnoop.c
f29710
@@ -193,6 +193,7 @@ static int snd_pcm_dsnoop_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
f29710
 	snd_pcm_status(dsnoop->spcm, status);
f29710
 	state = snd_pcm_state(dsnoop->spcm);
f29710
 	status->state = state == SND_PCM_STATE_RUNNING ? dsnoop->state : state;
f29710
+	status->appl_ptr = *pcm->appl.ptr; /* slave PCM doesn't set appl_ptr */
f29710
 	status->trigger_tstamp = dsnoop->trigger_tstamp;
f29710
 	status->avail = snd_pcm_mmap_capture_avail(pcm);
f29710
 	status->avail_max = status->avail > dsnoop->avail_max ? status->avail : dsnoop->avail_max;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 26fdcb98e6be186016d53f87d06ae47aabe5b7fc Mon Sep 17 00:00:00 2001
f29710
From: Takashi Iwai <tiwai@suse.de>
f29710
Date: Fri, 22 Jan 2021 15:48:40 +0100
f29710
Subject: [PATCH 46/49] pcm: ioplug: Pass appl_ptr and hw_ptr in
f29710
 snd_pcm_status()
f29710
f29710
The snd_pcm_status() of the ioplug doesn't return the current
f29710
positions of hw_ptr and appl_ptr as advertised.  Fix it by copying the
f29710
current values stored in the plugin data.
f29710
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_ioplug.c | 2 ++
f29710
 1 file changed, 2 insertions(+)
f29710
f29710
diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c
f29710
index e141b1f9..a1463bf6 100644
f29710
--- a/src/pcm/pcm_ioplug.c
f29710
+++ b/src/pcm/pcm_ioplug.c
f29710
@@ -133,6 +133,8 @@ static int snd_pcm_ioplug_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
f29710
 	gettimestamp(&status->tstamp, pcm->tstamp_type);
f29710
 	status->avail = snd_pcm_mmap_avail(pcm);
f29710
 	status->avail_max = io->avail_max;
f29710
+	status->appl_ptr = *pcm->appl.ptr;
f29710
+	status->hw_ptr = *pcm->hw.ptr;
f29710
 	if (snd_pcm_ioplug_delay(pcm, &sd) < 0)
f29710
 		sd = snd_pcm_mmap_delay(pcm);
f29710
 	status->delay = sd;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From bcc762f99ad642cc0dd9eaceb51f228eba9fe68c Mon Sep 17 00:00:00 2001
f29710
From: Takashi Iwai <tiwai@suse.de>
f29710
Date: Fri, 22 Jan 2021 15:48:41 +0100
f29710
Subject: [PATCH 47/49] pcm: null: Pass appl_ptr and hw_ptr in snd_pcm_status()
f29710
f29710
Just like the previous fix for ioplug, the null plugin also misses the
f29710
appl_ptr and hw_ptr updates for snd_pcm_status().  Fix it as well.
f29710
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_null.c | 2 ++
f29710
 1 file changed, 2 insertions(+)
f29710
f29710
diff --git a/src/pcm/pcm_null.c b/src/pcm/pcm_null.c
f29710
index 1d815485..c8ea9b38 100644
f29710
--- a/src/pcm/pcm_null.c
f29710
+++ b/src/pcm/pcm_null.c
f29710
@@ -96,6 +96,8 @@ static int snd_pcm_null_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
f29710
 	memset(status, 0, sizeof(*status));
f29710
 	status->state = null->state;
f29710
 	status->trigger_tstamp = null->trigger_tstamp;
f29710
+	status->appl_ptr = *pcm->appl.ptr;
f29710
+	status->hw_ptr = *pcm->hw.ptr;
f29710
 	gettimestamp(&status->tstamp, pcm->tstamp_type);
f29710
 	status->avail = snd_pcm_null_avail_update(pcm);
f29710
 	status->avail_max = pcm->buffer_size;
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 55d59821ffb8f44395cf2b7a424d6523da58e66a Mon Sep 17 00:00:00 2001
f29710
From: Takashi Iwai <tiwai@suse.de>
f29710
Date: Fri, 22 Jan 2021 15:48:42 +0100
f29710
Subject: [PATCH 48/49] pcm: share: Pass appl_ptr and hw_ptr in
f29710
 snd_pcm_status()
f29710
f29710
This one also has the same problem as others; the appl_ptr and hw_ptr
f29710
of share plugin aren't updated in snd_pcm_status() call.  Fix it.
f29710
f29710
Signed-off-by: Takashi Iwai <tiwai@suse.de>
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm_share.c | 2 ++
f29710
 1 file changed, 2 insertions(+)
f29710
f29710
diff --git a/src/pcm/pcm_share.c b/src/pcm/pcm_share.c
f29710
index bff9507d..72509491 100644
f29710
--- a/src/pcm/pcm_share.c
f29710
+++ b/src/pcm/pcm_share.c
f29710
@@ -711,6 +711,8 @@ static int snd_pcm_share_status(snd_pcm_t *pcm, snd_pcm_status_t *status)
f29710
  _notrunning:
f29710
 	status->delay = sd + d;
f29710
 	status->state = share->state;
f29710
+	status->appl_ptr = *pcm->appl.ptr;
f29710
+	status->hw_ptr = *pcm->hw.ptr;
f29710
 	status->trigger_tstamp = share->trigger_tstamp;
f29710
  _end:
f29710
 	Pthread_mutex_unlock(&slave->mutex);
f29710
-- 
f29710
2.29.2
f29710
f29710
f29710
From 00eafe98eebff8ecd1ecdc58470068bfd610cc8d Mon Sep 17 00:00:00 2001
f29710
From: Jaroslav Kysela <perex@perex.cz>
f29710
Date: Thu, 21 Jan 2021 15:45:49 +0100
f29710
Subject: [PATCH 49/49] pcm: pcm_ioplug - fix the avail_update mmap capture
f29710
 copy issue
f29710
f29710
It seems that the commit "pcm: ioplug: Transfer all available data"
f29710
introduced new regressions (wrong memory access). The second issue
f29710
is that the avail_update in ioplug does not move appl_ptr nor hw_ptr,
f29710
so it's possible that the transfers may be repetitive.
f29710
f29710
This patch moves the transfer calls to mmap_begin callback where it
f29710
should be. The pointer wraps are handled by design now.
f29710
f29710
Fixes: 1714332719 ("pcm: ioplug: Transfer all available data")
f29710
BugLink: https://github.com/alsa-project/alsa-lib/pull/103
f29710
Tested-by: Andreas Pape <apape@de.adit-jv.com>
f29710
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f29710
---
f29710
 src/pcm/pcm.c        | 20 ++++++++++-----
f29710
 src/pcm/pcm_ioplug.c | 60 +++++++++++++++++++++++++-------------------
f29710
 src/pcm/pcm_local.h  |  2 ++
f29710
 3 files changed, 50 insertions(+), 32 deletions(-)
f29710
f29710
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
f29710
index 24030b31..a57ce5d9 100644
f29710
--- a/src/pcm/pcm.c
f29710
+++ b/src/pcm/pcm.c
f29710
@@ -7218,9 +7218,8 @@ int snd_pcm_mmap_begin(snd_pcm_t *pcm,
c4a1f5
 }
c4a1f5
 
f29710
 #ifndef DOC_HIDDEN
f29710
-/* locked version */
f29710
-int __snd_pcm_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
f29710
-		       snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
f29710
+int __snd_pcm_mmap_begin_generic(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
f29710
+				 snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
f29710
 {
f29710
 	snd_pcm_uframes_t cont;
f29710
 	snd_pcm_uframes_t f;
f29710
@@ -7229,9 +7228,6 @@ int __snd_pcm_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
c4a1f5
 
f29710
 	assert(pcm && areas && offset && frames);
c4a1f5
 
f29710
-	if (pcm->fast_ops->mmap_begin)
f29710
-		return pcm->fast_ops->mmap_begin(pcm->fast_op_arg, areas, offset, frames);
f29710
-
f29710
 	/* fallback for plugins that do not specify new callback */
f29710
 	xareas = snd_pcm_mmap_areas(pcm);
f29710
 	if (xareas == NULL)
f29710
@@ -7250,6 +7246,18 @@ int __snd_pcm_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
f29710
 	*frames = f;
f29710
 	return 0;
f29710
 }
f29710
+
f29710
+/* locked version */
f29710
+int __snd_pcm_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
f29710
+			 snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
f29710
+{
f29710
+	assert(pcm && areas && offset && frames);
f29710
+
f29710
+	if (pcm->fast_ops->mmap_begin)
f29710
+		return pcm->fast_ops->mmap_begin(pcm->fast_op_arg, areas, offset, frames);
f29710
+
f29710
+	return __snd_pcm_mmap_begin_generic(pcm, areas, offset, frames);
f29710
+}
f29710
 #endif
c4a1f5
 
f29710
 /**
f29710
diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c
f29710
index a1463bf6..98184398 100644
f29710
--- a/src/pcm/pcm_ioplug.c
f29710
+++ b/src/pcm/pcm_ioplug.c
f29710
@@ -697,6 +697,38 @@ static snd_pcm_sframes_t snd_pcm_ioplug_readn(snd_pcm_t *pcm, void **bufs, snd_p
f29710
 	}
f29710
 }
f29710
 
f29710
+static int snd_pcm_ioplug_mmap_begin_capture(snd_pcm_t *pcm,
f29710
+					     const snd_pcm_channel_area_t **areas,
f29710
+					     snd_pcm_uframes_t *offset,
f29710
+					     snd_pcm_uframes_t *frames)
f29710
+{
f29710
+	ioplug_priv_t *io = pcm->private_data;
f29710
+	int err;
f29710
+
f29710
+	err = __snd_pcm_mmap_begin_generic(pcm, areas, offset, frames);
f29710
+	if (err < 0)
f29710
+		return err;
f29710
+
f29710
+	if (io->data->callback->transfer &&
f29710
+	    pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED &&
f29710
+	    pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
f29710
+		snd_pcm_sframes_t result;
f29710
+		result = io->data->callback->transfer(io->data, *areas, *offset, *frames);
f29710
+		if (result < 0)
f29710
+			return result;
f29710
+	}
f29710
+
f29710
+	return err;
f29710
+}
f29710
+
f29710
+static int snd_pcm_ioplug_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
f29710
+				     snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
f29710
+{
f29710
+	if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
f29710
+		return __snd_pcm_mmap_begin_generic(pcm, areas, offset, frames);
f29710
+	return snd_pcm_ioplug_mmap_begin_capture(pcm, areas, offset, frames);
f29710
+}
f29710
+
f29710
 static snd_pcm_sframes_t snd_pcm_ioplug_mmap_commit(snd_pcm_t *pcm,
f29710
 						    snd_pcm_uframes_t offset,
f29710
 						    snd_pcm_uframes_t size)
f29710
@@ -707,7 +739,7 @@ static snd_pcm_sframes_t snd_pcm_ioplug_mmap_commit(snd_pcm_t *pcm,
f29710
 		const snd_pcm_channel_area_t *areas;
f29710
 		snd_pcm_uframes_t ofs, frames = size;
f29710
 
f29710
-		__snd_pcm_mmap_begin(pcm, &areas, &ofs, &frames);
f29710
+		__snd_pcm_mmap_begin_generic(pcm, &areas, &ofs, &frames);
f29710
 		if (ofs != offset)
f29710
 			return -EIO;
f29710
 		return ioplug_priv_transfer_areas(pcm, areas, offset, frames);
f29710
@@ -727,31 +759,6 @@ static snd_pcm_sframes_t snd_pcm_ioplug_avail_update(snd_pcm_t *pcm)
f29710
 		return -EPIPE;
f29710
 
f29710
 	avail = snd_pcm_mmap_avail(pcm);
f29710
-	if (pcm->stream == SND_PCM_STREAM_CAPTURE &&
f29710
-	    pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED &&
f29710
-	    pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED) {
f29710
-		if (io->data->callback->transfer) {
f29710
-			const snd_pcm_channel_area_t *areas;
f29710
-			snd_pcm_uframes_t offset, size = UINT_MAX;
f29710
-			snd_pcm_sframes_t result;
f29710
-
f29710
-			__snd_pcm_mmap_begin(pcm, &areas, &offset, &size);
f29710
-			result = io->data->callback->transfer(io->data, areas, offset, size);
f29710
-			if (result < 0)
f29710
-				return result;
f29710
-
f29710
-			/* If the available data doesn't fit in the
f29710
-			   contiguous area at the end of the mmap we
f29710
-			   must transfer the remaining data to the
f29710
-			   beginning of the mmap. */
f29710
-			if (size < avail) {
f29710
-				result = io->data->callback->transfer(io->data, areas,
f29710
-								      0, avail - size);
f29710
-				if (result < 0)
f29710
-					return result;
f29710
-			}
f29710
-		}
f29710
-	}
f29710
 	if (avail > io->avail_max)
f29710
 		io->avail_max = avail;
f29710
 	return (snd_pcm_sframes_t)avail;
f29710
@@ -947,6 +954,7 @@ static const snd_pcm_fast_ops_t snd_pcm_ioplug_fast_ops = {
f29710
 	.poll_descriptors_count = snd_pcm_ioplug_poll_descriptors_count,
f29710
 	.poll_descriptors = snd_pcm_ioplug_poll_descriptors,
f29710
 	.poll_revents = snd_pcm_ioplug_poll_revents,
f29710
+	.mmap_begin = snd_pcm_ioplug_mmap_begin,
f29710
 };
f29710
 
f29710
 #endif /* !DOC_HIDDEN */
f29710
diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h
f29710
index bec5a408..a63f4be0 100644
f29710
--- a/src/pcm/pcm_local.h
f29710
+++ b/src/pcm/pcm_local.h
f29710
@@ -420,6 +420,8 @@ int _snd_pcm_poll_descriptor(snd_pcm_t *pcm);
f29710
 #define _snd_pcm_async_descriptor _snd_pcm_poll_descriptor /* FIXME */
f29710
 
f29710
 /* locked versions */
f29710
+int __snd_pcm_mmap_begin_generic(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
f29710
+				 snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames);
f29710
 int __snd_pcm_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
f29710
 			 snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames);
f29710
 snd_pcm_sframes_t __snd_pcm_mmap_commit(snd_pcm_t *pcm,
f29710
-- 
f29710
2.29.2
f29710