Blame SOURCES/alsa-lib-1.0.28-post.patch

484952
From 7a748af4db17cb0b26d19e5f9939d277128ec94b Mon Sep 17 00:00:00 2001
484952
From: Tanu Kaskinen <tanu.kaskinen@linux.intel.com>
484952
Date: Thu, 26 Jun 2014 13:30:25 +0300
484952
Subject: [PATCH 01/35] ucm: Document PlaybackPCMIsDummy and CapturePCMIsDummy
484952
 values
484952
484952
At least PulseAudio needs special handling for dummy devices. To allow
484952
that to happen automatically, the UCM configuration should contain the
484952
information about which PCMs are dummy.
484952
484952
Signed-off-by: Tanu Kaskinen <tanu.kaskinen@linux.intel.com>
484952
Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 include/use-case.h | 10 ++++++++++
484952
 1 file changed, 10 insertions(+)
484952
484952
diff --git a/include/use-case.h b/include/use-case.h
484952
index 4e13249..f30168f 100644
484952
--- a/include/use-case.h
484952
+++ b/include/use-case.h
484952
@@ -258,7 +258,17 @@ int snd_use_case_get_list(snd_use_case_mgr_t *uc_mgr,
484952
  * Recommended names for values:
484952
  *   TQ			- Tone Quality
484952
  *   PlaybackPCM	- full PCM playback device name
484952
+ *   PlaybackPCMIsDummy	- Valid values: "yes" and "no". If set to "yes", the
484952
+ *			  PCM named by the PlaybackPCM value is a dummy device,
484952
+ *			  meaning that opening it enables an audio path in the
484952
+ *			  hardware, but writing to the PCM device has no
484952
+ *			  effect.
484952
  *   CapturePCM		- full PCM capture device name
484952
+ *   CapturePCMIsDummy	- Valid values: "yes" and "no". If set to "yes", the
484952
+ *			  PCM named by the CapturePCM value is a dummy device,
484952
+ *			  meaning that opening it enables an audio path in the
484952
+ *			  hardware, but reading from the PCM device has no
484952
+ *			  effect.
484952
  *   PlaybackRate	- playback device sample rate
484952
  *   PlaybackChannels	- playback device channel count
484952
  *   PlaybackCTL	- playback control device name
484952
-- 
484952
1.9.3
484952
484952
484952
From 27cc710b5784cb3ab68cff2a9d9daf9fa479149e Mon Sep 17 00:00:00 2001
484952
From: "Alexander E. Patrakov" <patrakov@gmail.com>
484952
Date: Tue, 1 Jul 2014 00:40:48 +0600
484952
Subject: [PATCH 02/35] ICE1712: add surround71 pcm definition
484952
484952
The M-Audio Delta 1010 card has 7.1 analog output, but no ready-made pcm
484952
definition to use it.
484952
484952
Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
484952
Reported-and-tested-by: Matt Zagrabelny <mzagrabe@d.umn.edu>
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 src/conf/cards/ICE1712.conf | 22 ++++++++++++++++++++++
484952
 1 file changed, 22 insertions(+)
484952
484952
diff --git a/src/conf/cards/ICE1712.conf b/src/conf/cards/ICE1712.conf
484952
index 398fa7a..db62684 100644
484952
--- a/src/conf/cards/ICE1712.conf
484952
+++ b/src/conf/cards/ICE1712.conf
484952
@@ -78,6 +78,7 @@ ICE1712.pcm.surround40.0 {
484952
 <confdir:pcm/surround41.conf>
484952
 <confdir:pcm/surround50.conf>
484952
 <confdir:pcm/surround51.conf>
484952
+<confdir:pcm/surround71.conf>
484952
 
484952
 ICE1712.pcm.surround51.0 {
484952
 	@args [ CARD ]
484952
@@ -98,6 +99,27 @@ ICE1712.pcm.surround51.0 {
484952
 	slave.channels 10
484952
 }
484952
 
484952
+ICE1712.pcm.surround71.0 {
484952
+	@args [ CARD ]
484952
+	@args.CARD {
484952
+		type string
484952
+	}
484952
+	type route
484952
+	ttable.0.0 1
484952
+	ttable.1.1 1
484952
+	ttable.2.2 1
484952
+	ttable.3.3 1
484952
+	ttable.4.4 1
484952
+	ttable.5.5 1
484952
+	ttable.6.6 1
484952
+	ttable.7.7 1
484952
+	slave.pcm {
484952
+		type hw
484952
+		card $CARD
484952
+	}
484952
+	slave.channels 10
484952
+}
484952
+
484952
 <confdir:pcm/iec958.conf>
484952
 
484952
 ICE1712.pcm.iec958.0 {
484952
-- 
484952
1.9.3
484952
484952
484952
From ea865bba4615d906144ae5d4f72a4aad2baffe1f Mon Sep 17 00:00:00 2001
484952
From: Anssi Hannula <anssi.hannula@iki.fi>
484952
Date: Tue, 8 Jul 2014 11:19:20 +0300
484952
Subject: [PATCH 03/35] USB-Audio: Add second S/PDIF device on Phiree U2
484952
484952
Phiree U2 has an unusual configuration. It only has S/PDIF output, but
484952
there are still two devices presented:
484952
- device 0: PCM audio, subject to volume control
484952
- device 1: non-PCM data (passthrough), not subject to volume control
484952
484952
It looks like the AES bits are set according to the selected device,
484952
since outputting PCM data via device 1 will not work (silence).
484952
484952
Currently only the device 0 is shown via the "iec958" alias, and the
484952
second device is not accessible via hinted aliases.
484952
484952
Simply provide access to both of these devices via the "iec958" alias.
484952
484952
Reported-by: touc @ XBMC forum
484952
Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 src/conf/cards/USB-Audio.conf | 40 ++++++++++++++++++++++++++++++++++++++++
484952
 1 file changed, 40 insertions(+)
484952
484952
diff --git a/src/conf/cards/USB-Audio.conf b/src/conf/cards/USB-Audio.conf
484952
index ce3ae01..77a48b9 100644
484952
--- a/src/conf/cards/USB-Audio.conf
484952
+++ b/src/conf/cards/USB-Audio.conf
484952
@@ -52,6 +52,11 @@ USB-Audio.pcm.iec958_device {
484952
 	"USB Device 0x46d:0x992" 999
484952
 }
484952
 
484952
+# Second iec958 device number, if any.
484952
+USB-Audio.pcm.iec958_2_device {
484952
+	"PHIREE U2" 1  # 0 = PCM S/PDIF, 1 = non-PCM S/PDIF
484952
+}
484952
+
484952
 
484952
 # If a device requires non-standard definitions for front, surround40,
484952
 # surround51, surround71 or iec958, they can be defined here.
484952
@@ -422,4 +427,39 @@ USB-Audio.pcm.iec958.0 {
484952
 	}
484952
 }
484952
 
484952
+USB-Audio.pcm.iec958.1 {
484952
+	@args [ CARD AES0 AES1 AES2 AES3 ]
484952
+	@args.CARD { type string }
484952
+	@args.AES0 { type integer }
484952
+	@args.AES1 { type integer }
484952
+	@args.AES2 { type integer }
484952
+	@args.AES3 { type integer }
484952
+	@func refer
484952
+	name {
484952
+		@func concat
484952
+		strings [
484952
+			"cards.USB-Audio."
484952
+			{ @func card_name card $CARD }
484952
+			".pcm.iec958_2:CARD=" $CARD
484952
+			",AES0=" $AES0 ",AES1=" $AES1 ",AES2=" $AES2 ",AES3=" $AES3
484952
+		]
484952
+	}
484952
+	default {
484952
+		# FIXME: we cannot set the AES parameters
484952
+		type hw
484952
+		card $CARD
484952
+		device {
484952
+			@func refer
484952
+			name {
484952
+				@func concat
484952
+				strings [
484952
+					"cards.USB-Audio.pcm.iec958_2_device."
484952
+					{ @func card_name card $CARD }
484952
+				]
484952
+			}
484952
+			default 999
484952
+		}
484952
+	}
484952
+}
484952
+
484952
 # vim: ft=alsaconf
484952
-- 
484952
1.9.3
484952
484952
484952
From 035f196bcdc1e9903ed52ad1859dc23d3aa74e72 Mon Sep 17 00:00:00 2001
484952
From: Shengjiu Wang <shengjiu.wang@freescale.com>
484952
Date: Mon, 14 Jul 2014 16:55:48 +0800
484952
Subject: [PATCH 04/35] pcm: rate: fix hw_ptr exceed the boundary
484952
484952
For long time test case, the hw_ptr will exceed the boundary, then cause
484952
the avail size wrong.
484952
484952
Signed-off-by: Shengjiu Wang <shengjiu.wang@freescale.com>
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 src/pcm/pcm_rate.c | 2 ++
484952
 1 file changed, 2 insertions(+)
484952
484952
diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c
484952
index 7f667d4..2563d82 100644
484952
--- a/src/pcm/pcm_rate.c
484952
+++ b/src/pcm/pcm_rate.c
484952
@@ -574,6 +574,8 @@ static inline void snd_pcm_rate_sync_hwptr(snd_pcm_t *pcm)
484952
 	rate->hw_ptr =
484952
 		(slave_hw_ptr / rate->gen.slave->period_size) * pcm->period_size +
484952
 		rate->ops.input_frames(rate->obj, slave_hw_ptr % rate->gen.slave->period_size);
484952
+
484952
+	rate->hw_ptr %= pcm->boundary;
484952
 }
484952
 
484952
 static int snd_pcm_rate_hwsync(snd_pcm_t *pcm)
484952
-- 
484952
1.9.3
484952
484952
484952
From 85e4704151677b8fcc5ccfc396071828e9ec1b8e Mon Sep 17 00:00:00 2001
484952
From: Mark Brown <broonie@linaro.org>
484952
Date: Tue, 8 Jul 2014 16:52:32 +0200
484952
Subject: [PATCH 05/35] pcm: Provide a CLOCK_MONOTONIC_RAW timestamp type
484952
484952
For applications which need to synchronise with external timebases such
484952
as broadcast TV applications the kernel monotonic time is not optimal as
484952
it includes adjustments from NTP and so may still include discontinuities
484952
due to that. A raw monotonic time which does not include any adjustments
484952
is available in the kernel from getrawmonotonic() so provide userspace with
484952
a new timestamp type SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW which provides
484952
timestamps based on this as an option.
484952
484952
Reported-by: Daniel Thompson <daniel.thompson@linaro.org>
484952
Signed-off-by: Mark Brown <broonie@linaro.org>
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 include/sound/asound.h | 3 ++-
484952
 1 file changed, 2 insertions(+), 1 deletion(-)
484952
484952
diff --git a/include/sound/asound.h b/include/sound/asound.h
484952
index 1774a5c..9061cdd 100644
484952
--- a/include/sound/asound.h
484952
+++ b/include/sound/asound.h
484952
@@ -457,7 +457,8 @@ struct snd_xfern {
484952
 enum {
484952
 	SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY = 0,	/* gettimeofday equivalent */
484952
 	SNDRV_PCM_TSTAMP_TYPE_MONOTONIC,	/* posix_clock_monotonic equivalent */
484952
-	SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC,
484952
+	SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW,	/* monotonic_raw (no NTP) */
484952
+	SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW,
484952
 };
484952
 
484952
 /* channel positions */
484952
-- 
484952
1.9.3
484952
484952
484952
From 5250a8e212fd927735cfc27612b060c31dc3a230 Mon Sep 17 00:00:00 2001
484952
From: Takashi Iwai <tiwai@suse.de>
484952
Date: Thu, 10 Jul 2014 14:22:33 +0200
484952
Subject: [PATCH 06/35] Add timestamp type to sw_params (internal only)
484952
484952
This patch is just the udpate of sound/asound.h taken from the kernel
484952
commit.  The API changes and PCM structure changes will follow after
484952
this.
484952
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 include/sound/asound.h | 6 ++++--
484952
 1 file changed, 4 insertions(+), 2 deletions(-)
484952
484952
diff --git a/include/sound/asound.h b/include/sound/asound.h
484952
index 9061cdd..552f41b 100644
484952
--- a/include/sound/asound.h
484952
+++ b/include/sound/asound.h
484952
@@ -136,7 +136,7 @@ struct snd_hwdep_dsp_image {
484952
  *                                                                           *
484952
  *****************************************************************************/
484952
 
484952
-#define SNDRV_PCM_VERSION		SNDRV_PROTOCOL_VERSION(2, 0, 11)
484952
+#define SNDRV_PCM_VERSION		SNDRV_PROTOCOL_VERSION(2, 0, 12)
484952
 
484952
 typedef unsigned long snd_pcm_uframes_t;
484952
 typedef signed long snd_pcm_sframes_t;
484952
@@ -386,7 +386,9 @@ struct snd_pcm_sw_params {
484952
 	snd_pcm_uframes_t silence_threshold;	/* min distance from noise for silence filling */
484952
 	snd_pcm_uframes_t silence_size;		/* silence block size */
484952
 	snd_pcm_uframes_t boundary;		/* pointers wrap point */
484952
-	unsigned char reserved[64];		/* reserved for future */
484952
+	unsigned int tstamp_type;		/* timestamp type */
484952
+	int pads;				/* alignment, reserved */
484952
+	unsigned char reserved[56];		/* reserved for future */
484952
 };
484952
 
484952
 struct snd_pcm_channel_info {
484952
-- 
484952
1.9.3
484952
484952
484952
From 0d393c29a272b6fc97e9fca3252fb1c58f86e75b Mon Sep 17 00:00:00 2001
484952
From: Takashi Iwai <tiwai@suse.de>
484952
Date: Thu, 10 Jul 2014 14:26:37 +0200
484952
Subject: [PATCH 07/35] pcm: Add sw_params API functions to get/set timestamp
484952
 type
484952
484952
For obtaining / changing the timestamp type, add the corresponding
484952
sw_params accessor API functions together with the public definitions
484952
of timestamp types.
484952
484952
This patch only adds the functions and defines but doesn't bring the
484952
functional changes yet.
484952
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 include/pcm.h        |  9 +++++++++
484952
 src/pcm/pcm.c        | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
484952
 src/pcm/pcm_local.h  |  1 +
484952
 src/pcm/pcm_params.c |  1 +
484952
 4 files changed, 64 insertions(+)
484952
484952
diff --git a/include/pcm.h b/include/pcm.h
484952
index 95b8aed..11e9f0d 100644
484952
--- a/include/pcm.h
484952
+++ b/include/pcm.h
484952
@@ -317,6 +317,13 @@ typedef enum _snd_pcm_tstamp {
484952
 	SND_PCM_TSTAMP_LAST = SND_PCM_TSTAMP_ENABLE
484952
 } snd_pcm_tstamp_t;
484952
 
484952
+typedef enum _snd_pcm_tstamp_type {
484952
+	SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY = 0,	/** gettimeofday equivalent */
484952
+	SND_PCM_TSTAMP_TYPE_MONOTONIC,	/** posix_clock_monotonic equivalent */
484952
+	SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW,	/** monotonic_raw (no NTP) */
484952
+	SND_PCM_TSTAMP_TYPE_LAST = SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW,
484952
+} snd_pcm_tstamp_type_t;
484952
+
484952
 /** Unsigned frames quantity */
484952
 typedef unsigned long snd_pcm_uframes_t;
484952
 /** Signed frames quantity */
484952
@@ -844,6 +851,8 @@ int snd_pcm_sw_params_get_boundary(const snd_pcm_sw_params_t *params, snd_pcm_uf
484952
 
484952
 int snd_pcm_sw_params_set_tstamp_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_t val);
484952
 int snd_pcm_sw_params_get_tstamp_mode(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val);
484952
+int snd_pcm_sw_params_set_tstamp_type(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t val);
484952
+int snd_pcm_sw_params_get_tstamp_type(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t *val);
484952
 int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
484952
 int snd_pcm_sw_params_get_avail_min(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val);
484952
 int snd_pcm_sw_params_set_period_event(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, int val);
484952
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
484952
index 7e46014..8984443 100644
484952
--- a/src/pcm/pcm.c
484952
+++ b/src/pcm/pcm.c
484952
@@ -1483,6 +1483,7 @@ int snd_pcm_poll_descriptors_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsign
484952
 #define XRUN(v) [SND_PCM_XRUN_##v] = #v
484952
 #define SILENCE(v) [SND_PCM_SILENCE_##v] = #v
484952
 #define TSTAMP(v) [SND_PCM_TSTAMP_##v] = #v
484952
+#define TSTAMP_TYPE(v) [SND_PCM_TSTAMP_TYPE_##v] = #v
484952
 #define ACCESS(v) [SND_PCM_ACCESS_##v] = #v
484952
 #define START(v) [SND_PCM_START_##v] = #v
484952
 #define HW_PARAM(v) [SND_PCM_HW_PARAM_##v] = #v
484952
@@ -1680,6 +1681,12 @@ static const char *const snd_pcm_tstamp_mode_names[] = {
484952
 	TSTAMP(NONE),
484952
 	TSTAMP(ENABLE),
484952
 };
484952
+
484952
+static const char *const snd_pcm_tstamp_type_names[] = {
484952
+	TSTAMP_TYPE(GETTIMEOFDAY),
484952
+	TSTAMP_TYPE(MONOTONIC),
484952
+	TSTAMP_TYPE(MONOTONIC_RAW),
484952
+};
484952
 #endif
484952
 
484952
 /**
484952
@@ -1826,6 +1833,18 @@ const char *snd_pcm_tstamp_mode_name(snd_pcm_tstamp_t mode)
484952
 }
484952
 
484952
 /**
484952
+ * \brief get name of PCM tstamp type setting
484952
+ * \param mode PCM tstamp type
484952
+ * \return ascii name of PCM tstamp type setting
484952
+ */
484952
+const char *snd_pcm_tstamp_type_name(snd_pcm_tstamp_t type)
484952
+{
484952
+	if (type > SND_PCM_TSTAMP_TYPE_LAST)
484952
+		return NULL;
484952
+	return snd_pcm_tstamp_type_names[type];
484952
+}
484952
+
484952
+/**
484952
  * \brief get name of PCM state
484952
  * \param state PCM state
484952
  * \return ascii name of PCM state
484952
@@ -1899,6 +1918,7 @@ int snd_pcm_dump_sw_setup(snd_pcm_t *pcm, snd_output_t *out)
484952
 		return -EIO;
484952
 	}
484952
 	snd_output_printf(out, "  tstamp_mode  : %s\n", snd_pcm_tstamp_mode_name(pcm->tstamp_mode));
484952
+	snd_output_printf(out, "  tstamp_type  : %s\n", snd_pcm_tstamp_type_name(pcm->tstamp_mode));
484952
 	snd_output_printf(out, "  period_step  : %d\n", pcm->period_step);
484952
 	snd_output_printf(out, "  avail_min    : %ld\n", pcm->avail_min);
484952
 	snd_output_printf(out, "  period_event : %i\n", pcm->period_event);
484952
@@ -5591,6 +5611,7 @@ int snd_pcm_sw_params_current(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
484952
 		return -EIO;
484952
 	}
484952
 	params->tstamp_mode = pcm->tstamp_mode;
484952
+	params->tstamp_type = pcm->tstamp_type;
484952
 	params->period_step = pcm->period_step;
484952
 	params->sleep_min = 0;
484952
 	params->avail_min = pcm->avail_min;
484952
@@ -5613,6 +5634,7 @@ int snd_pcm_sw_params_current(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
484952
 int snd_pcm_sw_params_dump(snd_pcm_sw_params_t *params, snd_output_t *out)
484952
 {
484952
 	snd_output_printf(out, "tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(params->tstamp_mode));
484952
+	snd_output_printf(out, "tstamp_type: %s\n", snd_pcm_tstamp_type_name(params->tstamp_type));
484952
 	snd_output_printf(out, "period_step: %u\n", params->period_step);
484952
 	snd_output_printf(out, "avail_min: %lu\n", params->avail_min);
484952
 	snd_output_printf(out, "start_threshold: %ld\n", params->start_threshold);
484952
@@ -5811,6 +5833,37 @@ int snd_pcm_sw_params_get_tstamp_mode(const snd_pcm_sw_params_t *params, snd_pcm
484952
 }
484952
 
484952
 /**
484952
+ * \brief Set timestamp type inside a software configuration container
484952
+ * \param pcm PCM handle
484952
+ * \param params Software configuration container
484952
+ * \param val Timestamp type
484952
+ * \return 0 otherwise a negative error code
484952
+ */
484952
+int snd_pcm_sw_params_set_tstamp_type(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t val)
484952
+{
484952
+	assert(pcm && params);
484952
+	if (CHECK_SANITY(val > SND_PCM_TSTAMP_TYPE_LAST)) {
484952
+		SNDMSG("invalid tstamp_type value %d", val);
484952
+		return -EINVAL;
484952
+	}
484952
+	params->tstamp_type = val;
484952
+	return 0;
484952
+}
484952
+
484952
+/**
484952
+ * \brief Get timestamp type from a software configuration container
484952
+ * \param params Software configuration container
484952
+ * \param val Returned timestamp type
484952
+ * \return 0 otherwise a negative error code
484952
+ */
484952
+int snd_pcm_sw_params_get_tstamp_type(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t *val)
484952
+{
484952
+	assert(params && val);
484952
+	*val = params->tstamp_type;
484952
+	return 0;
484952
+}
484952
+
484952
+/**
484952
  * \brief (DEPRECATED) Set minimum number of ticks to sleep inside a software configuration container
484952
  * \param pcm PCM handle
484952
  * \param params Software configuration container
484952
diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h
484952
index 8a6c743..3ed7e1a 100644
484952
--- a/src/pcm/pcm_local.h
484952
+++ b/src/pcm/pcm_local.h
484952
@@ -202,6 +202,7 @@ struct _snd_pcm {
484952
 	unsigned int period_time;	/* period duration */
484952
 	snd_interval_t periods;
484952
 	snd_pcm_tstamp_t tstamp_mode;	/* timestamp mode */
484952
+	snd_pcm_tstamp_type_t tstamp_type;	/* timestamp type */
484952
 	unsigned int period_step;
484952
 	snd_pcm_uframes_t avail_min;	/* min avail frames for wakeup */
484952
 	int period_event;
484952
diff --git a/src/pcm/pcm_params.c b/src/pcm/pcm_params.c
484952
index 0b66e8c..4adbefa 100644
484952
--- a/src/pcm/pcm_params.c
484952
+++ b/src/pcm/pcm_params.c
484952
@@ -2258,6 +2258,7 @@ static int snd_pcm_sw_params_default(snd_pcm_t *pcm, snd_pcm_sw_params_t *params
484952
 	assert(pcm && params);
484952
 	assert(pcm->setup);
484952
 	params->tstamp_mode = SND_PCM_TSTAMP_NONE;
484952
+	params->tstamp_type = pcm->tstamp_type;
484952
 	params->period_step = 1;
484952
 	params->sleep_min = 0;
484952
 	params->avail_min = pcm->period_size;
484952
-- 
484952
1.9.3
484952
484952
484952
From 9b716075de4f2f7f15e428ee7efaa8960ef45b9c Mon Sep 17 00:00:00 2001
484952
From: Takashi Iwai <tiwai@suse.de>
484952
Date: Thu, 10 Jul 2014 14:32:50 +0200
484952
Subject: [PATCH 08/35] pcm: Implement timestamp type setup in hw plugin
484952
484952
This patch implements the support for sw_params timestamp type in PCM
484952
hw layer.  As gettimestamp() is still unchanged, the resultant
484952
timstamps may be still with CLOCK_MONOTONIC even if you pass monotonic
484952
raw type.  More fixes will follow.
484952
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 src/pcm/pcm_hw.c | 37 ++++++++++++++++++++++++++++++++-----
484952
 1 file changed, 32 insertions(+), 5 deletions(-)
484952
484952
diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c
484952
index ed83197..bafa8de 100644
484952
--- a/src/pcm/pcm_hw.c
484952
+++ b/src/pcm/pcm_hw.c
484952
@@ -304,7 +304,8 @@ static int snd_pcm_hw_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
484952
 
484952
 	if (params->info != ~0U) {
484952
 		params->info &= ~0xf0000000;
484952
-		params->info |= (pcm->monotonic ? SND_PCM_INFO_MONOTONIC : 0);
484952
+		if (pcm->tstamp_type != SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY)
484952
+			params->info |= SND_PCM_INFO_MONOTONIC;
484952
 	}
484952
 	
484952
 	return 0;
484952
@@ -328,7 +329,8 @@ static int snd_pcm_hw_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
484952
 		return err;
484952
 	}
484952
 	params->info &= ~0xf0000000;
484952
-	params->info |= (pcm->monotonic ? SND_PCM_INFO_MONOTONIC : 0);
484952
+	if (pcm->tstamp_type != SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY)
484952
+		params->info |= SND_PCM_INFO_MONOTONIC;
484952
 	err = sync_ptr(hw, 0);
484952
 	if (err < 0)
484952
 		return err;
484952
@@ -435,6 +437,7 @@ static int snd_pcm_hw_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t * params)
484952
 	int old_period_event = sw_get_period_event(params);
484952
 	sw_set_period_event(params, 0);
484952
 	if ((snd_pcm_tstamp_t) params->tstamp_mode == pcm->tstamp_mode &&
484952
+	    (snd_pcm_tstamp_type_t) params->tstamp_type == pcm->tstamp_type &&
484952
 	    params->period_step == pcm->period_step &&
484952
 	    params->start_threshold == pcm->start_threshold &&
484952
 	    params->stop_threshold == pcm->stop_threshold &&
484952
@@ -444,11 +447,33 @@ static int snd_pcm_hw_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t * params)
484952
 		hw->mmap_control->avail_min = params->avail_min;
484952
 		return sync_ptr(hw, 0);
484952
 	}
484952
+	if (params->tstamp_type == SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW &&
484952
+	    hw->version < SNDRV_PROTOCOL_VERSION(2, 0, 12)) {
484952
+		SYSMSG("Kernel doesn't support SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW");
484952
+		return -EINVAL;
484952
+	}
484952
+	if (params->tstamp_type == SND_PCM_TSTAMP_TYPE_MONOTONIC &&
484952
+	    hw->version < SNDRV_PROTOCOL_VERSION(2, 0, 5)) {
484952
+		SYSMSG("Kernel doesn't support SND_PCM_TSTAMP_TYPE_MONOTONIC");
484952
+		return -EINVAL;
484952
+	}
484952
 	if (ioctl(fd, SNDRV_PCM_IOCTL_SW_PARAMS, params) < 0) {
484952
 		err = -errno;
484952
 		SYSMSG("SNDRV_PCM_IOCTL_SW_PARAMS failed (%i)", err);
484952
 		return err;
484952
 	}
484952
+	if ((snd_pcm_tstamp_type_t) params->tstamp_type != pcm->tstamp_type) {
484952
+		if (hw->version < SNDRV_PROTOCOL_VERSION(2, 0, 12)) {
484952
+			int on = (snd_pcm_tstamp_type_t) params->tstamp_type ==
484952
+				SND_PCM_TSTAMP_TYPE_MONOTONIC;
484952
+			if (ioctl(fd, SNDRV_PCM_IOCTL_TSTAMP, &on) < 0) {
484952
+				err = -errno;
484952
+				SNDMSG("TSTAMP failed\n");
484952
+				return err;
484952
+			}
484952
+		}
484952
+		pcm->tstamp_type = params->tstamp_type;
484952
+	}
484952
 	sw_set_period_event(params, old_period_event);
484952
 	hw->mmap_control->avail_min = params->avail_min;
484952
 	if (hw->period_event != old_period_event) {
484952
@@ -1381,7 +1406,8 @@ int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name,
484952
 		       int fd, int mmap_emulation ATTRIBUTE_UNUSED,
484952
 		       int sync_ptr_ioctl)
484952
 {
484952
-	int ver, mode, monotonic = 0;
484952
+	int ver, mode;
484952
+	snd_pcm_tstamp_type_t tstamp_type = SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY;
484952
 	long fmode;
484952
 	snd_pcm_t *pcm = NULL;
484952
 	snd_pcm_hw_t *hw = NULL;
484952
@@ -1429,7 +1455,7 @@ int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name,
484952
 				SNDMSG("TTSTAMP failed\n");
484952
 				return ret;
484952
 			}
484952
-			monotonic = 1;
484952
+			tstamp_type = SND_PCM_TSTAMP_TYPE_MONOTONIC;
484952
 		}
484952
 	} else
484952
 #endif
484952
@@ -1471,7 +1497,8 @@ int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name,
484952
 	pcm->private_data = hw;
484952
 	pcm->poll_fd = fd;
484952
 	pcm->poll_events = info.stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN;
484952
-	pcm->monotonic = monotonic;
484952
+	pcm->tstamp_type = tstamp_type;
484952
+	pcm->monotonic = tstamp_type != SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY;
484952
 
484952
 	ret = snd_pcm_hw_mmap_status(pcm);
484952
 	if (ret < 0) {
484952
-- 
484952
1.9.3
484952
484952
484952
From 65ff6fdafb705b5e2e6d4b9a94a80e5de89f5de1 Mon Sep 17 00:00:00 2001
484952
From: Takashi Iwai <tiwai@suse.de>
484952
Date: Thu, 10 Jul 2014 14:37:49 +0200
484952
Subject: [PATCH 09/35] pcm: Implement timestamp type handling in all plugins
484952
484952
Now all PCM plugins do support the proper timestamp type or pass it
484952
over slaves.  The internal monotonic flag is dropped and replaced with
484952
tstamp_type in all places.
484952
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 src/pcm/pcm_adpcm.c     |  2 +-
484952
 src/pcm/pcm_alaw.c      |  2 +-
484952
 src/pcm/pcm_copy.c      |  2 +-
484952
 src/pcm/pcm_direct.c    |  4 ++--
484952
 src/pcm/pcm_direct.h    |  2 +-
484952
 src/pcm/pcm_dmix.c      |  8 ++++----
484952
 src/pcm/pcm_dshare.c    |  8 ++++----
484952
 src/pcm/pcm_dsnoop.c    |  4 ++--
484952
 src/pcm/pcm_file.c      |  6 +++---
484952
 src/pcm/pcm_generic.c   |  2 +-
484952
 src/pcm/pcm_hooks.c     |  2 +-
484952
 src/pcm/pcm_hw.c        |  1 -
484952
 src/pcm/pcm_iec958.c    |  2 +-
484952
 src/pcm/pcm_ioplug.c    |  9 ++++++---
484952
 src/pcm/pcm_ladspa.c    |  2 +-
484952
 src/pcm/pcm_lfloat.c    |  2 +-
484952
 src/pcm/pcm_linear.c    |  2 +-
484952
 src/pcm/pcm_local.h     | 45 +++++++++++++++++++++++++++++----------------
484952
 src/pcm/pcm_meter.c     |  2 +-
484952
 src/pcm/pcm_mmap_emul.c |  2 +-
484952
 src/pcm/pcm_mulaw.c     |  2 +-
484952
 src/pcm/pcm_multi.c     |  2 +-
484952
 src/pcm/pcm_null.c      |  2 +-
484952
 src/pcm/pcm_plug.c      |  2 +-
484952
 src/pcm/pcm_rate.c      |  4 ++--
484952
 src/pcm/pcm_route.c     |  2 +-
484952
 src/pcm/pcm_share.c     |  6 +++---
484952
 src/pcm/pcm_softvol.c   |  2 +-
484952
 28 files changed, 73 insertions(+), 58 deletions(-)
484952
484952
diff --git a/src/pcm/pcm_adpcm.c b/src/pcm/pcm_adpcm.c
484952
index 6f0e7c4..1a83c5a 100644
484952
--- a/src/pcm/pcm_adpcm.c
484952
+++ b/src/pcm/pcm_adpcm.c
484952
@@ -579,7 +579,7 @@ int snd_pcm_adpcm_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfor
484952
 	pcm->private_data = adpcm;
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_set_hw_ptr(pcm, &adpcm->plug.hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &adpcm->plug.appl_ptr, -1, 0);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_alaw.c b/src/pcm/pcm_alaw.c
484952
index 1b1bab8..db759e3 100644
484952
--- a/src/pcm/pcm_alaw.c
484952
+++ b/src/pcm/pcm_alaw.c
484952
@@ -453,7 +453,7 @@ int snd_pcm_alaw_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sform
484952
 	pcm->private_data = alaw;
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_set_hw_ptr(pcm, &alaw->plug.hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &alaw->plug.appl_ptr, -1, 0);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_copy.c b/src/pcm/pcm_copy.c
484952
index 56a1f6b..66d3a47 100644
484952
--- a/src/pcm/pcm_copy.c
484952
+++ b/src/pcm/pcm_copy.c
484952
@@ -209,7 +209,7 @@ int snd_pcm_copy_open(snd_pcm_t **pcmp, const char *name, snd_pcm_t *slave, int
484952
 	pcm->private_data = copy;
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_set_hw_ptr(pcm, &copy->plug.hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &copy->plug.appl_ptr, -1, 0);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c
484952
index 5416cf7..8e37bcb 100644
484952
--- a/src/pcm/pcm_direct.c
484952
+++ b/src/pcm/pcm_direct.c
484952
@@ -840,6 +840,7 @@ static void save_slave_setting(snd_pcm_direct_t *dmix, snd_pcm_t *spcm)
484952
 	COPY_SLAVE(period_time);
484952
 	COPY_SLAVE(periods);
484952
 	COPY_SLAVE(tstamp_mode);
484952
+	COPY_SLAVE(tstamp_type);
484952
 	COPY_SLAVE(period_step);
484952
 	COPY_SLAVE(avail_min);
484952
 	COPY_SLAVE(start_threshold);
484952
@@ -857,7 +858,6 @@ static void save_slave_setting(snd_pcm_direct_t *dmix, snd_pcm_t *spcm)
484952
 	COPY_SLAVE(buffer_time);
484952
 	COPY_SLAVE(sample_bits);
484952
 	COPY_SLAVE(frame_bits);
484952
-	COPY_SLAVE(monotonic);
484952
 }
484952
 
484952
 #undef COPY_SLAVE
484952
@@ -1204,6 +1204,7 @@ static void copy_slave_setting(snd_pcm_direct_t *dmix, snd_pcm_t *spcm)
484952
 	COPY_SLAVE(period_time);
484952
 	COPY_SLAVE(periods);
484952
 	COPY_SLAVE(tstamp_mode);
484952
+	COPY_SLAVE(tstamp_type);
484952
 	COPY_SLAVE(period_step);
484952
 	COPY_SLAVE(avail_min);
484952
 	COPY_SLAVE(start_threshold);
484952
@@ -1221,7 +1222,6 @@ static void copy_slave_setting(snd_pcm_direct_t *dmix, snd_pcm_t *spcm)
484952
 	COPY_SLAVE(buffer_time);
484952
 	COPY_SLAVE(sample_bits);
484952
 	COPY_SLAVE(frame_bits);
484952
-	COPY_SLAVE(monotonic);
484952
 
484952
 	spcm->info &= ~SND_PCM_INFO_PAUSE;
484952
 	spcm->boundary = recalc_boundary_size(dmix->shmptr->s.boundary, spcm->buffer_size);
484952
diff --git a/src/pcm/pcm_direct.h b/src/pcm/pcm_direct.h
484952
index 5ae39c0..9b1ddbc 100644
484952
--- a/src/pcm/pcm_direct.h
484952
+++ b/src/pcm/pcm_direct.h
484952
@@ -85,8 +85,8 @@ typedef struct {
484952
 		unsigned int period_size;
484952
 		unsigned int period_time;
484952
 		snd_interval_t periods;
484952
-		unsigned int monotonic;
484952
 		snd_pcm_tstamp_t tstamp_mode;
484952
+		snd_pcm_tstamp_type_t tstamp_type;
484952
 		unsigned int period_step;
484952
 		unsigned int sleep_min; /* not used */
484952
 		unsigned int avail_min;
484952
diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c
484952
index 4aa6d4e..7c53509 100644
484952
--- a/src/pcm/pcm_dmix.c
484952
+++ b/src/pcm/pcm_dmix.c
484952
@@ -428,7 +428,7 @@ static int snd_pcm_dmix_sync_ptr(snd_pcm_t *pcm)
484952
 		dmix->avail_max = avail;
484952
 	if (avail >= pcm->stop_threshold) {
484952
 		snd_timer_stop(dmix->timer);
484952
-		gettimestamp(&dmix->trigger_tstamp, pcm->monotonic);
484952
+		gettimestamp(&dmix->trigger_tstamp, pcm->tstamp_type);
484952
 		if (dmix->state == SND_PCM_STATE_RUNNING) {
484952
 			dmix->state = SND_PCM_STATE_XRUN;
484952
 			return -EPIPE;
484952
@@ -477,7 +477,7 @@ static int snd_pcm_dmix_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
484952
 	memset(status, 0, sizeof(*status));
484952
 	status->state = snd_pcm_dmix_state(pcm);
484952
 	status->trigger_tstamp = dmix->trigger_tstamp;
484952
-	gettimestamp(&status->tstamp, pcm->monotonic);
484952
+	gettimestamp(&status->tstamp, pcm->tstamp_type);
484952
 	status->avail = snd_pcm_mmap_playback_avail(pcm);
484952
 	status->avail_max = status->avail > dmix->avail_max ? status->avail : dmix->avail_max;
484952
 	dmix->avail_max = 0;
484952
@@ -596,7 +596,7 @@ static int snd_pcm_dmix_start(snd_pcm_t *pcm)
484952
 			return err;
484952
 		snd_pcm_dmix_sync_area(pcm);
484952
 	}
484952
-	gettimestamp(&dmix->trigger_tstamp, pcm->monotonic);
484952
+	gettimestamp(&dmix->trigger_tstamp, pcm->tstamp_type);
484952
 	return 0;
484952
 }
484952
 
484952
@@ -1104,7 +1104,7 @@ int snd_pcm_dmix_open(snd_pcm_t **pcmp, const char *name,
484952
 		
484952
 	pcm->poll_fd = dmix->poll_fd;
484952
 	pcm->poll_events = POLLIN;	/* it's different than other plugins */
484952
-	pcm->monotonic = spcm->monotonic;
484952
+	pcm->tstamp_type = spcm->tstamp_type;
484952
 	pcm->mmap_rw = 1;
484952
 	snd_pcm_set_hw_ptr(pcm, &dmix->hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &dmix->appl_ptr, -1, 0);
484952
diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c
484952
index f2d1103..b985172 100644
484952
--- a/src/pcm/pcm_dshare.c
484952
+++ b/src/pcm/pcm_dshare.c
484952
@@ -195,7 +195,7 @@ static int snd_pcm_dshare_sync_ptr(snd_pcm_t *pcm)
484952
 		dshare->avail_max = avail;
484952
 	if (avail >= pcm->stop_threshold) {
484952
 		snd_timer_stop(dshare->timer);
484952
-		gettimestamp(&dshare->trigger_tstamp, pcm->monotonic);
484952
+		gettimestamp(&dshare->trigger_tstamp, pcm->tstamp_type);
484952
 		if (dshare->state == SND_PCM_STATE_RUNNING) {
484952
 			dshare->state = SND_PCM_STATE_XRUN;
484952
 			return -EPIPE;
484952
@@ -226,7 +226,7 @@ static int snd_pcm_dshare_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
484952
 	memset(status, 0, sizeof(*status));
484952
 	status->state = snd_pcm_state(dshare->spcm);
484952
 	status->trigger_tstamp = dshare->trigger_tstamp;
484952
-	gettimestamp(&status->tstamp, pcm->monotonic);
484952
+	gettimestamp(&status->tstamp, pcm->tstamp_type);
484952
 	status->avail = snd_pcm_mmap_playback_avail(pcm);
484952
 	status->avail_max = status->avail > dshare->avail_max ? status->avail : dshare->avail_max;
484952
 	dshare->avail_max = 0;
484952
@@ -346,7 +346,7 @@ static int snd_pcm_dshare_start(snd_pcm_t *pcm)
484952
 			return err;
484952
 		snd_pcm_dshare_sync_area(pcm);
484952
 	}
484952
-	gettimestamp(&dshare->trigger_tstamp, pcm->monotonic);
484952
+	gettimestamp(&dshare->trigger_tstamp, pcm->tstamp_type);
484952
 	return 0;
484952
 }
484952
 
484952
@@ -792,7 +792,7 @@ int snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name,
484952
 
484952
 	pcm->poll_fd = dshare->poll_fd;
484952
 	pcm->poll_events = POLLIN;	/* it's different than other plugins */
484952
-	pcm->monotonic = spcm->monotonic;
484952
+	pcm->tstamp_type = spcm->tstamp_type;
484952
 	pcm->mmap_rw = 1;
484952
 	snd_pcm_set_hw_ptr(pcm, &dshare->hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &dshare->appl_ptr, -1, 0);
484952
diff --git a/src/pcm/pcm_dsnoop.c b/src/pcm/pcm_dsnoop.c
484952
index 7637914..0f9c9df 100644
484952
--- a/src/pcm/pcm_dsnoop.c
484952
+++ b/src/pcm/pcm_dsnoop.c
484952
@@ -159,7 +159,7 @@ static int snd_pcm_dsnoop_sync_ptr(snd_pcm_t *pcm)
484952
 	if (pcm->stop_threshold >= pcm->boundary)	/* don't care */
484952
 		return 0;
484952
 	if ((avail = snd_pcm_mmap_capture_hw_avail(pcm)) >= pcm->stop_threshold) {
484952
-		gettimestamp(&dsnoop->trigger_tstamp, pcm->monotonic);
484952
+		gettimestamp(&dsnoop->trigger_tstamp, pcm->tstamp_type);
484952
 		dsnoop->state = SND_PCM_STATE_XRUN;
484952
 		dsnoop->avail_max = avail;
484952
 		return -EPIPE;
484952
@@ -690,7 +690,7 @@ int snd_pcm_dsnoop_open(snd_pcm_t **pcmp, const char *name,
484952
 
484952
 	pcm->poll_fd = dsnoop->poll_fd;
484952
 	pcm->poll_events = POLLIN;	/* it's different than other plugins */
484952
-	pcm->monotonic = spcm->monotonic;
484952
+	pcm->tstamp_type = spcm->tstamp_type;
484952
 	pcm->mmap_rw = 1;
484952
 	snd_pcm_set_hw_ptr(pcm, &dsnoop->hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &dsnoop->appl_ptr, -1, 0);
484952
diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c
484952
index b139f7f..a0b8bf4 100644
484952
--- a/src/pcm/pcm_file.c
484952
+++ b/src/pcm/pcm_file.c
484952
@@ -781,10 +781,10 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
 	pcm->mmap_shadow = 1;
484952
+	pcm->tstamp_type = SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY;
484952
 #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
484952
-	pcm->monotonic = clock_gettime(CLOCK_MONOTONIC, &timespec) == 0;
484952
-#else
484952
-	pcm->monotonic = 0;
484952
+	if (clock_gettime(CLOCK_MONOTONIC, &timespec) == 0)
484952
+		pcm->tstamp_type = SND_PCM_TSTAMP_TYPE_MONOTONIC;
484952
 #endif
484952
 	pcm->stream = stream;
484952
 	snd_pcm_link_hw_ptr(pcm, slave);
484952
diff --git a/src/pcm/pcm_generic.c b/src/pcm/pcm_generic.c
484952
index f068ee2..9b60591 100644
484952
--- a/src/pcm/pcm_generic.c
484952
+++ b/src/pcm/pcm_generic.c
484952
@@ -294,7 +294,7 @@ int snd_pcm_generic_real_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail,
484952
 		if (ok && (snd_pcm_uframes_t)avail1 == *avail)
484952
 			break;
484952
 		*avail = avail1;
484952
-		gettimestamp(tstamp, pcm->monotonic);
484952
+		gettimestamp(tstamp, pcm->tstamp_type);
484952
 		ok = 1;
484952
 	}
484952
 	return 0;
484952
diff --git a/src/pcm/pcm_hooks.c b/src/pcm/pcm_hooks.c
484952
index f837282..0b93c64 100644
484952
--- a/src/pcm/pcm_hooks.c
484952
+++ b/src/pcm/pcm_hooks.c
484952
@@ -240,7 +240,7 @@ int snd_pcm_hooks_open(snd_pcm_t **pcmp, const char *name, snd_pcm_t *slave, int
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
 	pcm->mmap_shadow = 1;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_link_hw_ptr(pcm, slave);
484952
 	snd_pcm_link_appl_ptr(pcm, slave);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c
484952
index bafa8de..74cff67 100644
484952
--- a/src/pcm/pcm_hw.c
484952
+++ b/src/pcm/pcm_hw.c
484952
@@ -1498,7 +1498,6 @@ int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name,
484952
 	pcm->poll_fd = fd;
484952
 	pcm->poll_events = info.stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN;
484952
 	pcm->tstamp_type = tstamp_type;
484952
-	pcm->monotonic = tstamp_type != SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY;
484952
 
484952
 	ret = snd_pcm_hw_mmap_status(pcm);
484952
 	if (ret < 0) {
484952
diff --git a/src/pcm/pcm_iec958.c b/src/pcm/pcm_iec958.c
484952
index 0c61fc1..38c4ce7 100644
484952
--- a/src/pcm/pcm_iec958.c
484952
+++ b/src/pcm/pcm_iec958.c
484952
@@ -534,7 +534,7 @@ int snd_pcm_iec958_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfo
484952
 	pcm->private_data = iec;
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_set_hw_ptr(pcm, &iec->plug.hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &iec->plug.appl_ptr, -1, 0);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c
484952
index c1c3a98..85a8891 100644
484952
--- a/src/pcm/pcm_ioplug.c
484952
+++ b/src/pcm/pcm_ioplug.c
484952
@@ -448,7 +448,7 @@ static int snd_pcm_ioplug_start(snd_pcm_t *pcm)
484952
 	if (err < 0)
484952
 		return err;
484952
 
484952
-	gettimestamp(&io->trigger_tstamp, pcm->monotonic);
484952
+	gettimestamp(&io->trigger_tstamp, pcm->tstamp_type);
484952
 	io->data->state = SND_PCM_STATE_RUNNING;
484952
 
484952
 	return 0;
484952
@@ -463,7 +463,7 @@ static int snd_pcm_ioplug_drop(snd_pcm_t *pcm)
484952
 
484952
 	io->data->callback->stop(io->data);
484952
 
484952
-	gettimestamp(&io->trigger_tstamp, pcm->monotonic);
484952
+	gettimestamp(&io->trigger_tstamp, pcm->tstamp_type);
484952
 	io->data->state = SND_PCM_STATE_SETUP;
484952
 
484952
 	return 0;
484952
@@ -1069,7 +1069,10 @@ int snd_pcm_ioplug_reinit_status(snd_pcm_ioplug_t *ioplug)
484952
 {
484952
 	ioplug->pcm->poll_fd = ioplug->poll_fd;
484952
 	ioplug->pcm->poll_events = ioplug->poll_events;
484952
-	ioplug->pcm->monotonic = (ioplug->flags & SND_PCM_IOPLUG_FLAG_MONOTONIC) != 0;
484952
+	if (ioplug->flags & SND_PCM_IOPLUG_FLAG_MONOTONIC)
484952
+		ioplug->pcm->tstamp_type = SND_PCM_TSTAMP_TYPE_MONOTONIC;
484952
+	else
484952
+		ioplug->pcm->tstamp_type = SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY;
484952
 	ioplug->pcm->mmap_rw = ioplug->mmap_rw;
484952
 	return 0;
484952
 }
484952
diff --git a/src/pcm/pcm_ladspa.c b/src/pcm/pcm_ladspa.c
484952
index 7d1e3df..631ee0f 100644
484952
--- a/src/pcm/pcm_ladspa.c
484952
+++ b/src/pcm/pcm_ladspa.c
484952
@@ -1641,7 +1641,7 @@ int snd_pcm_ladspa_open(snd_pcm_t **pcmp, const char *name,
484952
 	pcm->private_data = ladspa;
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_set_hw_ptr(pcm, &ladspa->plug.hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &ladspa->plug.appl_ptr, -1, 0);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_lfloat.c b/src/pcm/pcm_lfloat.c
484952
index bbf72c2..324282f 100644
484952
--- a/src/pcm/pcm_lfloat.c
484952
+++ b/src/pcm/pcm_lfloat.c
484952
@@ -412,7 +412,7 @@ int snd_pcm_lfloat_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfo
484952
 	pcm->private_data = lfloat;
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_set_hw_ptr(pcm, &lfloat->plug.hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &lfloat->plug.appl_ptr, -1, 0);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_linear.c b/src/pcm/pcm_linear.c
484952
index 7aa8941..3d5bbb8 100644
484952
--- a/src/pcm/pcm_linear.c
484952
+++ b/src/pcm/pcm_linear.c
484952
@@ -484,7 +484,7 @@ int snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfo
484952
 	pcm->private_data = linear;
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_set_hw_ptr(pcm, &linear->plug.hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &linear->plug.appl_ptr, -1, 0);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h
484952
index 3ed7e1a..2206afe 100644
484952
--- a/src/pcm/pcm_local.h
484952
+++ b/src/pcm/pcm_local.h
484952
@@ -191,7 +191,6 @@ struct _snd_pcm {
484952
 	int poll_fd;
484952
 	unsigned short poll_events;
484952
 	int setup: 1,
484952
-	    monotonic: 1,
484952
 	    compat: 1;
484952
 	snd_pcm_access_t access;	/* access mode */
484952
 	snd_pcm_format_t format;	/* SND_PCM_FORMAT_* */
484952
@@ -960,26 +959,40 @@ typedef union snd_tmp_double {
484952
 } snd_tmp_double_t;
484952
 
484952
 /* get the current timestamp */
484952
-static inline void gettimestamp(snd_htimestamp_t *tstamp, int monotonic)
484952
+#ifdef HAVE_CLOCK_GETTIME
484952
+static inline void gettimestamp(snd_htimestamp_t *tstamp,
484952
+				snd_pcm_tstamp_type_t tstamp_type)
484952
 {
484952
-#if defined(HAVE_CLOCK_GETTIME)
484952
-#if defined(CLOCK_MONOTONIC)
484952
-	if (monotonic) {
484952
-		clock_gettime(CLOCK_MONOTONIC, tstamp);
484952
-	} else {
484952
-#endif
484952
-		clock_gettime(CLOCK_REALTIME, tstamp);
484952
-#else
484952
-		struct timeval tv;
484952
+	clockid_t id;
484952
 
484952
-		gettimeofday(&tv, 0);
484952
-		tstamp->tv_sec = tv.tv_sec;
484952
-		tstamp->tv_nsec = tv.tv_usec * 1000L;
484952
+	switch (tstamp_type) {
484952
+#ifdef CLOCK_MONOTONIC_RAW
484952
+	case SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
484952
+		id = CLOCK_MONOTONIC_RAW;
484952
+		break;
484952
 #endif
484952
-#if defined(HAVE_CLOCK_GETTIME)
484952
-	}
484952
+#ifdef CLOCK_MONOTONIC
484952
+	case SND_PCM_TSTAMP_TYPE_MONOTONIC:
484952
+		id = CLOCK_MONOTONIC;
484952
+		break;
484952
 #endif
484952
+	default:
484952
+		id = CLOCK_REALTIME;
484952
+		break;
484952
+	}
484952
+	clock_gettime(id, tstamp);
484952
+}
484952
+#else /* HAVE_CLOCK_GETTIME */
484952
+static inline void gettimestamp(snd_htimestamp_t *tstamp,
484952
+				snd_pcm_tstamp_type_t tstamp_type)
484952
+{
484952
+	struct timeval tv;
484952
+
484952
+	gettimeofday(&tv, 0);
484952
+	tstamp->tv_sec = tv.tv_sec;
484952
+	tstamp->tv_nsec = tv.tv_usec * 1000L;
484952
 }
484952
+#endif /* HAVE_CLOCK_GETTIME */
484952
 
484952
 snd_pcm_chmap_query_t **
484952
 _snd_pcm_make_single_query_chmaps(const snd_pcm_chmap_t *src);
484952
diff --git a/src/pcm/pcm_meter.c b/src/pcm/pcm_meter.c
484952
index 676fbef..034f582 100644
484952
--- a/src/pcm/pcm_meter.c
484952
+++ b/src/pcm/pcm_meter.c
484952
@@ -591,7 +591,7 @@ int snd_pcm_meter_open(snd_pcm_t **pcmp, const char *name, unsigned int frequenc
484952
 	pcm->private_data = meter;
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_link_hw_ptr(pcm, slave);
484952
 	snd_pcm_link_appl_ptr(pcm, slave);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_mmap_emul.c b/src/pcm/pcm_mmap_emul.c
484952
index 63789bc..b2b15ef 100644
484952
--- a/src/pcm/pcm_mmap_emul.c
484952
+++ b/src/pcm/pcm_mmap_emul.c
484952
@@ -428,7 +428,7 @@ int __snd_pcm_mmap_emul_open(snd_pcm_t **pcmp, const char *name,
484952
 	pcm->private_data = map;
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_set_hw_ptr(pcm, &map->hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &map->appl_ptr, -1, 0);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_mulaw.c b/src/pcm/pcm_mulaw.c
484952
index 7adce38..011b2a5 100644
484952
--- a/src/pcm/pcm_mulaw.c
484952
+++ b/src/pcm/pcm_mulaw.c
484952
@@ -467,7 +467,7 @@ int snd_pcm_mulaw_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfor
484952
 	pcm->private_data = mulaw;
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_set_hw_ptr(pcm, &mulaw->plug.hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &mulaw->plug.appl_ptr, -1, 0);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_multi.c b/src/pcm/pcm_multi.c
484952
index a84e0ce..4b8299e 100644
484952
--- a/src/pcm/pcm_multi.c
484952
+++ b/src/pcm/pcm_multi.c
484952
@@ -1077,7 +1077,7 @@ int snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
484952
 	pcm->private_data = multi;
484952
 	pcm->poll_fd = multi->slaves[master_slave].pcm->poll_fd;
484952
 	pcm->poll_events = multi->slaves[master_slave].pcm->poll_events;
484952
-	pcm->monotonic = multi->slaves[master_slave].pcm->monotonic;
484952
+	pcm->tstamp_type = multi->slaves[master_slave].pcm->tstamp_type;
484952
 	snd_pcm_link_hw_ptr(pcm, multi->slaves[master_slave].pcm);
484952
 	snd_pcm_link_appl_ptr(pcm, multi->slaves[master_slave].pcm);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_null.c b/src/pcm/pcm_null.c
484952
index 655261f..f11a102 100644
484952
--- a/src/pcm/pcm_null.c
484952
+++ b/src/pcm/pcm_null.c
484952
@@ -100,7 +100,7 @@ static int snd_pcm_null_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
484952
 	memset(status, 0, sizeof(*status));
484952
 	status->state = null->state;
484952
 	status->trigger_tstamp = null->trigger_tstamp;
484952
-	gettimestamp(&status->tstamp, pcm->monotonic);
484952
+	gettimestamp(&status->tstamp, pcm->tstamp_type);
484952
 	status->avail = snd_pcm_null_avail_update(pcm);
484952
 	status->avail_max = pcm->buffer_size;
484952
 	return 0;
484952
diff --git a/src/pcm/pcm_plug.c b/src/pcm/pcm_plug.c
484952
index 7a6c2b9..5639b9e 100644
484952
--- a/src/pcm/pcm_plug.c
484952
+++ b/src/pcm/pcm_plug.c
484952
@@ -1127,7 +1127,7 @@ int snd_pcm_plug_open(snd_pcm_t **pcmp,
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
 	pcm->mmap_shadow = 1;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_link_hw_ptr(pcm, slave);
484952
 	snd_pcm_link_appl_ptr(pcm, slave);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c
484952
index 2563d82..5e811bb 100644
484952
--- a/src/pcm/pcm_rate.c
484952
+++ b/src/pcm/pcm_rate.c
484952
@@ -1069,7 +1069,7 @@ static int snd_pcm_rate_start(snd_pcm_t *pcm)
484952
 	if (snd_pcm_state(rate->gen.slave) != SND_PCM_STATE_PREPARED)
484952
 		return -EBADFD;
484952
 
484952
-	gettimestamp(&rate->trigger_tstamp, pcm->monotonic);
484952
+	gettimestamp(&rate->trigger_tstamp, pcm->tstamp_type);
484952
 
484952
 	avail = snd_pcm_mmap_playback_hw_avail(rate->gen.slave);
484952
 	if (avail == 0) {
484952
@@ -1372,7 +1372,7 @@ int snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name,
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
 	pcm->mmap_rw = 1;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_set_hw_ptr(pcm, &rate->hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &rate->appl_ptr, -1, 0);
484952
 	*pcmp = pcm;
484952
diff --git a/src/pcm/pcm_route.c b/src/pcm/pcm_route.c
484952
index 751e36f..2f0be38 100644
484952
--- a/src/pcm/pcm_route.c
484952
+++ b/src/pcm/pcm_route.c
484952
@@ -1122,7 +1122,7 @@ int snd_pcm_route_open(snd_pcm_t **pcmp, const char *name,
484952
 	pcm->private_data = route;
484952
 	pcm->poll_fd = slave->poll_fd;
484952
 	pcm->poll_events = slave->poll_events;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_set_hw_ptr(pcm, &route->plug.hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &route->plug.appl_ptr, -1, 0);
484952
 	err = route_load_ttable(&route->params, pcm->stream, tt_ssize, ttable, tt_cused, tt_sused);
484952
diff --git a/src/pcm/pcm_share.c b/src/pcm/pcm_share.c
484952
index 118ab26..9770544 100644
484952
--- a/src/pcm/pcm_share.c
484952
+++ b/src/pcm/pcm_share.c
484952
@@ -971,7 +971,7 @@ static int snd_pcm_share_start(snd_pcm_t *pcm)
484952
 	}
484952
 	slave->running_count++;
484952
 	_snd_pcm_share_update(pcm);
484952
-	gettimestamp(&share->trigger_tstamp, pcm->monotonic);
484952
+	gettimestamp(&share->trigger_tstamp, pcm->tstamp_type);
484952
  _end:
484952
 	Pthread_mutex_unlock(&slave->mutex);
484952
 	return err;
484952
@@ -1126,7 +1126,7 @@ static void _snd_pcm_share_stop(snd_pcm_t *pcm, snd_pcm_state_t state)
484952
 		return;
484952
 	}
484952
 #endif
484952
-	gettimestamp(&share->trigger_tstamp, pcm->monotonic);
484952
+	gettimestamp(&share->trigger_tstamp, pcm->tstamp_type);
484952
 	if (pcm->stream == SND_PCM_STREAM_CAPTURE) {
484952
 		snd_pcm_areas_copy(pcm->stopped_areas, 0,
484952
 				   pcm->running_areas, 0,
484952
@@ -1526,7 +1526,7 @@ int snd_pcm_share_open(snd_pcm_t **pcmp, const char *name, const char *sname,
484952
 	pcm->private_data = share;
484952
 	pcm->poll_fd = share->client_socket;
484952
 	pcm->poll_events = stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN;
484952
-	pcm->monotonic = slave->pcm->monotonic;
484952
+	pcm->tstamp_type = slave->pcm->tstamp_type;
484952
 	snd_pcm_set_hw_ptr(pcm, &share->hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &share->appl_ptr, -1, 0);
484952
 
484952
diff --git a/src/pcm/pcm_softvol.c b/src/pcm/pcm_softvol.c
484952
index 5da9204..c6cfd88 100644
484952
--- a/src/pcm/pcm_softvol.c
484952
+++ b/src/pcm/pcm_softvol.c
484952
@@ -903,7 +903,7 @@ int snd_pcm_softvol_open(snd_pcm_t **pcmp, const char *name,
484952
 	 * an extra buffer.
484952
 	 */
484952
 	pcm->mmap_shadow = 1;
484952
-	pcm->monotonic = slave->monotonic;
484952
+	pcm->tstamp_type = slave->tstamp_type;
484952
 	snd_pcm_set_hw_ptr(pcm, &svol->plug.hw_ptr, -1, 0);
484952
 	snd_pcm_set_appl_ptr(pcm, &svol->plug.appl_ptr, -1, 0);
484952
 	*pcmp = pcm;
484952
-- 
484952
1.9.3
484952
484952
484952
From 52444bd43afbadb8637f5fac3fe5fd90575ee216 Mon Sep 17 00:00:00 2001
484952
From: Takashi Iwai <tiwai@suse.de>
484952
Date: Mon, 14 Jul 2014 18:12:49 +0200
484952
Subject: [PATCH 10/35] test/audio_time: Set timestamp type explicitly
484952
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 test/audio_time.c | 13 +++++++++++++
484952
 1 file changed, 13 insertions(+)
484952
484952
diff --git a/test/audio_time.c b/test/audio_time.c
484952
index 03817c7..7435db6 100644
484952
--- a/test/audio_time.c
484952
+++ b/test/audio_time.c
484952
@@ -57,6 +57,7 @@ void gettimestamp(snd_pcm_t *handle, snd_htimestamp_t *timestamp,
484952
 #define TRACK_PLAYBACK  /* dump playback timing info */
484952
 #define TRACK_SAMPLE_COUNTS /* show difference between sample counters and audiotimestamps returned by driver */
484952
 #define PLAYBACK_BUFFERS 4
484952
+#define TSTAMP_TYPE	SND_PCM_TSTAMP_TYPE_MONOTONIC
484952
 
484952
 
484952
 int main(void)
484952
@@ -128,6 +129,12 @@ int main(void)
484952
 		goto _exit;
484952
 	}
484952
 
484952
+	err = snd_pcm_sw_params_set_tstamp_type(handle_p, swparams_p, TSTAMP_TYPE);
484952
+	if (err < 0) {
484952
+		printf("Unable to set tstamp type : %s\n", snd_strerror(err));
484952
+		goto _exit;
484952
+	}
484952
+
484952
 	/* write the sw parameters */
484952
 	err = snd_pcm_sw_params(handle_p, swparams_p);
484952
 	if (err < 0) {
484952
@@ -177,6 +184,12 @@ int main(void)
484952
 		goto _exit;
484952
 	}
484952
 
484952
+	err = snd_pcm_sw_params_set_tstamp_type(handle_c, swparams_c, TSTAMP_TYPE);
484952
+	if (err < 0) {
484952
+		printf("Unable to set tstamp type : %s\n", snd_strerror(err));
484952
+		goto _exit;
484952
+	}
484952
+
484952
 	/* write the sw parameters */
484952
 	err = snd_pcm_sw_params(handle_c, swparams_c);
484952
 	if (err < 0) {
484952
-- 
484952
1.9.3
484952
484952
484952
From de63b942acf520a25ff469cf338a99eb3da65570 Mon Sep 17 00:00:00 2001
484952
From: Takashi Iwai <tiwai@suse.de>
484952
Date: Mon, 21 Jul 2014 16:30:54 +0200
484952
Subject: [PATCH 11/35] pcm: route: Use get/put labels for all 3 byte formats
484952
484952
So far, use_getput flag is set only when the src or dest format is
484952
24bit physical width.  But, also 18 and 20 bit physical width formats
484952
should set the flag, too.  This patch makes the check broader to cover
484952
all 3 bytes formats.
484952
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 src/pcm/pcm_route.c | 6 ++++--
484952
 1 file changed, 4 insertions(+), 2 deletions(-)
484952
484952
diff --git a/src/pcm/pcm_route.c b/src/pcm/pcm_route.c
484952
index 2f0be38..72c198c 100644
484952
--- a/src/pcm/pcm_route.c
484952
+++ b/src/pcm/pcm_route.c
484952
@@ -644,8 +644,10 @@ static int snd_pcm_route_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
484952
 	}
484952
 	if (err < 0)
484952
 		return err;
484952
-	route->params.use_getput = snd_pcm_format_physical_width(src_format) == 24 ||
484952
-		snd_pcm_format_physical_width(dst_format) == 24;
484952
+	/* 3 bytes formats? */
484952
+	route->params.use_getput =
484952
+		(snd_pcm_format_physical_width(src_format) + 7) / 3 == 3 ||
484952
+		(snd_pcm_format_physical_width(dst_format) + 7) / 3 == 3;
484952
 	route->params.get_idx = snd_pcm_linear_get_index(src_format, SND_PCM_FORMAT_S16);
484952
 	route->params.put_idx = snd_pcm_linear_put32_index(SND_PCM_FORMAT_S32, dst_format);
484952
 	route->params.conv_idx = snd_pcm_linear_convert_index(src_format, dst_format);
484952
-- 
484952
1.9.3
484952
484952
484952
From 55c53625212702debf55c719ec62f6c81c780927 Mon Sep 17 00:00:00 2001
484952
From: Takashi Iwai <tiwai@suse.de>
484952
Date: Wed, 16 Jul 2014 17:48:34 +0200
484952
Subject: [PATCH 12/35] pcm: Fill sw_params proto field
484952
484952
Fill the new proto field introduced to sw_params with the current PCM
484952
protocol version.  This makes tstamp_type evaluated properly in the
484952
kernel.
484952
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 include/sound/asound.h | 4 ++--
484952
 src/pcm/pcm.c          | 1 +
484952
 src/pcm/pcm_params.c   | 1 +
484952
 3 files changed, 4 insertions(+), 2 deletions(-)
484952
484952
diff --git a/include/sound/asound.h b/include/sound/asound.h
484952
index 552f41b..c819df4 100644
484952
--- a/include/sound/asound.h
484952
+++ b/include/sound/asound.h
484952
@@ -386,8 +386,8 @@ struct snd_pcm_sw_params {
484952
 	snd_pcm_uframes_t silence_threshold;	/* min distance from noise for silence filling */
484952
 	snd_pcm_uframes_t silence_size;		/* silence block size */
484952
 	snd_pcm_uframes_t boundary;		/* pointers wrap point */
484952
-	unsigned int tstamp_type;		/* timestamp type */
484952
-	int pads;				/* alignment, reserved */
484952
+	unsigned int proto;			/* protocol version */
484952
+	unsigned int tstamp_type;		/* timestamp type (req. proto >= 2.0.12) */
484952
 	unsigned char reserved[56];		/* reserved for future */
484952
 };
484952
 
484952
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
484952
index 8984443..1399a5b 100644
484952
--- a/src/pcm/pcm.c
484952
+++ b/src/pcm/pcm.c
484952
@@ -5610,6 +5610,7 @@ int snd_pcm_sw_params_current(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
484952
 		SNDMSG("PCM not set up");
484952
 		return -EIO;
484952
 	}
484952
+	params->proto = SNDRV_PCM_VERSION;
484952
 	params->tstamp_mode = pcm->tstamp_mode;
484952
 	params->tstamp_type = pcm->tstamp_type;
484952
 	params->period_step = pcm->period_step;
484952
diff --git a/src/pcm/pcm_params.c b/src/pcm/pcm_params.c
484952
index 4adbefa..6e57904 100644
484952
--- a/src/pcm/pcm_params.c
484952
+++ b/src/pcm/pcm_params.c
484952
@@ -2257,6 +2257,7 @@ static int snd_pcm_sw_params_default(snd_pcm_t *pcm, snd_pcm_sw_params_t *params
484952
 {
484952
 	assert(pcm && params);
484952
 	assert(pcm->setup);
484952
+	params->proto = SNDRV_PCM_VERSION;
484952
 	params->tstamp_mode = SND_PCM_TSTAMP_NONE;
484952
 	params->tstamp_type = pcm->tstamp_type;
484952
 	params->period_step = 1;
484952
-- 
484952
1.9.3
484952
484952
484952
From fd84adc63e307572d05274be44c782a787087cda Mon Sep 17 00:00:00 2001
484952
From: Takashi Iwai <tiwai@suse.de>
484952
Date: Tue, 22 Jul 2014 11:55:40 +0200
484952
Subject: [PATCH 13/35] pcm: route: Use get32 for multi-source route
484952
 calculation
484952
484952
The PCM route plugin can assign the destination value from average of
484952
multiple sources with attenuation.  This requires the read of each
484952
channel value, sums and writes the resultant value in the requested
484952
format.
484952
484952
Currently, get_labels is used for reading source values while
484952
put32_labels is used for writing the dest value.  This is, however,
484952
a buggy implementation; get_labels gives the value as is only with
484952
endianness and signedness conversions, but put32_labels assumes that
484952
the value is normalized to 32bit int and it shifts down to the dest
484952
format.  In addition, the current code lacks get_labels entries for
484952
the 24bit formats, as Shengjiu Wang spotted out.
484952
484952
For fixing these bugs, this patch replaces the read with
484952
get32_labels and use always 64bit int for sum.  This simplifies the
484952
code a lot and drops many lines.
484952
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 src/pcm/pcm_route.c  | 128 +++++++++------------------------------------------
484952
 src/pcm/plugin_ops.h |  81 --------------------------------
484952
 2 files changed, 23 insertions(+), 186 deletions(-)
484952
484952
diff --git a/src/pcm/pcm_route.c b/src/pcm/pcm_route.c
484952
index 72c198c..5dac7eb 100644
484952
--- a/src/pcm/pcm_route.c
484952
+++ b/src/pcm/pcm_route.c
484952
@@ -60,7 +60,7 @@ typedef struct {
484952
 typedef struct snd_pcm_route_ttable_dst snd_pcm_route_ttable_dst_t;
484952
 
484952
 typedef struct {
484952
-	enum {UINT32=0, UINT64=1, FLOAT=2} sum_idx;
484952
+	enum {UINT64, FLOAT} sum_idx;
484952
 	unsigned int get_idx;
484952
 	unsigned int put_idx;
484952
 	unsigned int conv_idx;
484952
@@ -233,55 +233,34 @@ static void snd_pcm_route_convert1_many(const snd_pcm_channel_area_t *dst_area,
484952
 					const snd_pcm_route_ttable_dst_t* ttable,
484952
 					const snd_pcm_route_params_t *params)
484952
 {
484952
-#define GETS_LABELS
484952
+#define GET32_LABELS
484952
 #define PUT32_LABELS
484952
 #include "plugin_ops.h"
484952
-#undef GETS_LABELS
484952
+#undef GET32_LABELS
484952
 #undef PUT32_LABELS
484952
-	static void *const zero_labels[3] = {
484952
-		&&zero_int32, &&zero_int64,
484952
+	static void *const zero_labels[2] = {
484952
+		&&zero_int64,
484952
 #if SND_PCM_PLUGIN_ROUTE_FLOAT
484952
 		&&zero_float
484952
 #endif
484952
 	};
484952
 	/* sum_type att */
484952
-	static void *const add_labels[3 * 2] = {
484952
-		&&add_int32_noatt, &&add_int32_att,
484952
+	static void *const add_labels[2 * 2] = {
484952
 		&&add_int64_noatt, &&add_int64_att,
484952
 #if SND_PCM_PLUGIN_ROUTE_FLOAT
484952
 		&&add_float_noatt, &&add_float_att
484952
 #endif
484952
 	};
484952
-	/* sum_type att shift */
484952
-	static void *const norm_labels[3 * 2 * 4] = {
484952
-		0,
484952
-		&&norm_int32_8_noatt,
484952
-		&&norm_int32_16_noatt,
484952
-		&&norm_int32_24_noatt,
484952
-		0,
484952
-		&&norm_int32_8_att,
484952
-		&&norm_int32_16_att,
484952
-		&&norm_int32_24_att,
484952
-		&&norm_int64_0_noatt,
484952
-		&&norm_int64_8_noatt,
484952
-		&&norm_int64_16_noatt,
484952
-		&&norm_int64_24_noatt,
484952
-		&&norm_int64_0_att,
484952
-		&&norm_int64_8_att,
484952
-		&&norm_int64_16_att,
484952
-		&&norm_int64_24_att,
484952
+	/* sum_type att */
484952
+	static void *const norm_labels[2 * 2] = {
484952
+		&&norm_int64_noatt,
484952
+		&&norm_int64_att,
484952
 #if SND_PCM_PLUGIN_ROUTE_FLOAT
484952
-		&&norm_float_0,
484952
-		&&norm_float_8,
484952
-		&&norm_float_16,
484952
-		&&norm_float_24,
484952
-		&&norm_float_0,
484952
-		&&norm_float_8,
484952
-		&&norm_float_16,
484952
-		&&norm_float_24,
484952
+		&&norm_float,
484952
+		&&norm_float,
484952
 #endif
484952
 	};
484952
-	void *zero, *get, *add, *norm, *put32;
484952
+	void *zero, *get32, *add, *norm, *put32;
484952
 	int nsrcs = ttable->nsrcs;
484952
 	char *dst;
484952
 	int dst_step;
484952
@@ -323,9 +302,9 @@ static void snd_pcm_route_convert1_many(const snd_pcm_channel_area_t *dst_area,
484952
 	}
484952
 
484952
 	zero = zero_labels[params->sum_idx];
484952
-	get = gets_labels[params->get_idx];
484952
+	get32 = get32_labels[params->get_idx];
484952
 	add = add_labels[params->sum_idx * 2 + ttable->att];
484952
-	norm = norm_labels[params->sum_idx * 8 + ttable->att * 4 + 4 - params->src_size];
484952
+	norm = norm_labels[params->sum_idx * 2 + ttable->att];
484952
 	put32 = put32_labels[params->put_idx];
484952
 	dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
484952
 	dst_step = snd_pcm_channel_area_step(dst_area);
484952
@@ -336,9 +315,6 @@ static void snd_pcm_route_convert1_many(const snd_pcm_channel_area_t *dst_area,
484952
 
484952
 		/* Zero sum */
484952
 		goto *zero;
484952
-	zero_int32:
484952
-		sum.as_sint32 = 0;
484952
-		goto zero_end;
484952
 	zero_int64: 
484952
 		sum.as_sint64 = 0;
484952
 		goto zero_end;
484952
@@ -352,21 +328,14 @@ static void snd_pcm_route_convert1_many(const snd_pcm_channel_area_t *dst_area,
484952
 			const char *src = srcs[srcidx];
484952
 			
484952
 			/* Get sample */
484952
-			goto *get;
484952
-#define GETS_END after_get
484952
+			goto *get32;
484952
+#define GET32_END after_get
484952
 #include "plugin_ops.h"
484952
-#undef GETS_END
484952
+#undef GET32_END
484952
 		after_get:
484952
 
484952
 			/* Sum */
484952
 			goto *add;
484952
-		add_int32_att:
484952
-			sum.as_sint32 += sample * ttp->as_int;
484952
-			goto after_sum;
484952
-		add_int32_noatt:
484952
-			if (ttp->as_int)
484952
-				sum.as_sint32 += sample;
484952
-			goto after_sum;
484952
 		add_int64_att:
484952
 			sum.as_sint64 += (int64_t) sample * ttp->as_int;
484952
 			goto after_sum;
484952
@@ -390,48 +359,10 @@ static void snd_pcm_route_convert1_many(const snd_pcm_channel_area_t *dst_area,
484952
 		
484952
 		/* Normalization */
484952
 		goto *norm;
484952
-	norm_int32_8_att:
484952
-		sum.as_sint64 = sum.as_sint32;
484952
-	norm_int64_8_att:
484952
-		sum.as_sint64 <<= 8;
484952
-	norm_int64_0_att:
484952
+	norm_int64_att:
484952
 		div(sum.as_sint64);
484952
-		goto norm_int;
484952
-
484952
-	norm_int32_16_att:
484952
-		sum.as_sint64 = sum.as_sint32;
484952
-	norm_int64_16_att:
484952
-		sum.as_sint64 <<= 16;
484952
-		div(sum.as_sint64);
484952
-		goto norm_int;
484952
-
484952
-	norm_int32_24_att:
484952
-		sum.as_sint64 = sum.as_sint32;
484952
-	norm_int64_24_att:
484952
-		sum.as_sint64 <<= 24;
484952
-		div(sum.as_sint64);
484952
-		goto norm_int;
484952
-
484952
-	norm_int32_8_noatt:
484952
-		sum.as_sint64 = sum.as_sint32;
484952
-	norm_int64_8_noatt:
484952
-		sum.as_sint64 <<= 8;
484952
-		goto norm_int;
484952
-
484952
-	norm_int32_16_noatt:
484952
-		sum.as_sint64 = sum.as_sint32;
484952
-	norm_int64_16_noatt:
484952
-		sum.as_sint64 <<= 16;
484952
-		goto norm_int;
484952
-
484952
-	norm_int32_24_noatt:
484952
-		sum.as_sint64 = sum.as_sint32;
484952
-	norm_int64_24_noatt:
484952
-		sum.as_sint64 <<= 24;
484952
-		goto norm_int;
484952
-
484952
-	norm_int64_0_noatt:
484952
-	norm_int:
484952
+		/* fallthru */
484952
+	norm_int64_noatt:
484952
 		if (sum.as_sint64 > (int64_t)0x7fffffff)
484952
 			sample = 0x7fffffff;	/* maximum positive value */
484952
 		else if (sum.as_sint64 < -(int64_t)0x80000000)
484952
@@ -441,16 +372,6 @@ static void snd_pcm_route_convert1_many(const snd_pcm_channel_area_t *dst_area,
484952
 		goto after_norm;
484952
 
484952
 #if SND_PCM_PLUGIN_ROUTE_FLOAT
484952
-	norm_float_8:
484952
-		sum.as_float *= 1 << 8;
484952
-		goto norm_float;
484952
-	norm_float_16:
484952
-		sum.as_float *= 1 << 16;
484952
-		goto norm_float;
484952
-	norm_float_24:
484952
-		sum.as_float *= 1 << 24;
484952
-		goto norm_float;
484952
-	norm_float_0:
484952
 	norm_float:
484952
 		sum.as_float = rint(sum.as_float);
484952
 		if (sum.as_float > (int64_t)0x7fffffff)
484952
@@ -648,7 +569,7 @@ static int snd_pcm_route_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
484952
 	route->params.use_getput =
484952
 		(snd_pcm_format_physical_width(src_format) + 7) / 3 == 3 ||
484952
 		(snd_pcm_format_physical_width(dst_format) + 7) / 3 == 3;
484952
-	route->params.get_idx = snd_pcm_linear_get_index(src_format, SND_PCM_FORMAT_S16);
484952
+	route->params.get_idx = snd_pcm_linear_get32_index(src_format, SND_PCM_FORMAT_S32);
484952
 	route->params.put_idx = snd_pcm_linear_put32_index(SND_PCM_FORMAT_S32, dst_format);
484952
 	route->params.conv_idx = snd_pcm_linear_convert_index(src_format, dst_format);
484952
 	route->params.src_size = snd_pcm_format_width(src_format) / 8;
484952
@@ -656,10 +577,7 @@ static int snd_pcm_route_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
484952
 #if SND_PCM_PLUGIN_ROUTE_FLOAT
484952
 	route->params.sum_idx = FLOAT;
484952
 #else
484952
-	if (snd_pcm_format_width(src_format) == 32)
484952
-		route->params.sum_idx = UINT64;
484952
-	else
484952
-		route->params.sum_idx = UINT32;
484952
+	route->params.sum_idx = UINT64;
484952
 #endif
484952
 	return 0;
484952
 }
484952
diff --git a/src/pcm/plugin_ops.h b/src/pcm/plugin_ops.h
484952
index 21535c9..eb8c2c4 100644
484952
--- a/src/pcm/plugin_ops.h
484952
+++ b/src/pcm/plugin_ops.h
484952
@@ -668,87 +668,6 @@ getu_1234_C321: sample = bswap_32(as_u32c(src) ^ 0x80); goto GETU_END;
484952
 }
484952
 #endif
484952
 
484952
-#ifdef GETS_LABELS
484952
-/* width endswap sign_toggle */
484952
-static void *const gets_labels[4 * 2 * 2] = {
484952
-	&&gets_1_1,		/*  8h ->  8h */
484952
-	&&gets_1_9,		/*  8h ^>  8h */
484952
-	&&gets_1_1,		/*  8s ->  8h */
484952
-	&&gets_1_9,		/*  8s ^>  8h */
484952
-	&&gets_12_12,		/* 16h -> 16h */
484952
-	&&gets_12_92,		/* 16h ^> 16h */
484952
-	&&gets_12_21,		/* 16s -> 16h */
484952
-	&&gets_12_A1,		/* 16s ^> 16h */
484952
-	&&gets_0123_0123,	/* 24h -> 24h */
484952
-	&&gets_0123_0923,	/* 24h ^> 24h */
484952
-	&&gets_1230_0321,	/* 24s -> 24h */
484952
-	&&gets_1230_0B21,	/* 24s ^> 24h */
484952
-	&&gets_1234_1234,	/* 32h -> 32h */
484952
-	&&gets_1234_9234,	/* 32h ^> 32h */
484952
-	&&gets_1234_4321,	/* 32s -> 32h */
484952
-	&&gets_1234_C321,	/* 32s ^> 32h */
484952
-};
484952
-#endif
484952
-
484952
-#ifdef GETS_END
484952
-while (0) {
484952
-gets_1_1: sample = as_s8c(src); goto GETS_END;
484952
-gets_1_9: sample = (int8_t)(as_s8c(src) ^ 0x80); goto GETS_END;
484952
-gets_12_12: sample = as_s16c(src); goto GETS_END;
484952
-gets_12_92: sample = (int16_t)(as_s16c(src) ^ 0x8000); goto GETS_END;
484952
-gets_12_21: sample = (int16_t)bswap_16(as_s16c(src)); goto GETS_END;
484952
-gets_12_A1: sample = (int16_t)bswap_16(as_s16c(src) ^ 0x80); goto GETS_END;
484952
-gets_0123_0123: sample = sx24((int32_t)(as_s32c(src) << 8) >> 8); goto GETS_END;
484952
-gets_0123_0923: sample = sx24((int32_t)((as_s32c(src) ^ 0x800000) << 8) >> 8); goto GETS_END;
484952
-gets_1230_0321: sample = sx24((int32_t)(bswap_32(as_s32c(src)) << 8) >> 8); goto GETS_END;
484952
-gets_1230_0B21: sample = sx24((int32_t)(bswap_32(as_s32c(src) ^ 0x8000) << 8) >> 8); goto GETS_END;
484952
-gets_1234_1234: sample = as_s32c(src); goto GETS_END;
484952
-gets_1234_9234: sample = (int32_t)(as_s32c(src) ^ 0x80000000); goto GETS_END;
484952
-gets_1234_4321: sample = (int32_t)bswap_32(as_s32c(src)); goto GETS_END;
484952
-gets_1234_C321: sample = (int32_t)bswap_32(as_s32c(src) ^ 0x80); goto GETS_END;
484952
-}
484952
-#endif
484952
-
484952
-#ifdef PUT_LABELS
484952
-/* width endswap sign_toggle */
484952
-static void *const put_labels[4 * 2 * 2] = {
484952
-	&&put_1_1,		/*  8h ->  8h */
484952
-	&&put_1_9,		/*  8h ^>  8h */
484952
-	&&put_1_1,		/*  8h ->  8s */
484952
-	&&put_1_9,		/*  8h ^>  8s */
484952
-	&&put_12_12,		/* 16h -> 16h */
484952
-	&&put_12_92,		/* 16h ^> 16h */
484952
-	&&put_12_21,		/* 16h -> 16s */
484952
-	&&put_12_29,		/* 16h ^> 16s */
484952
-	&&put_0123_0123,	/* 24h -> 24h */
484952
-	&&put_0123_0923,	/* 24h ^> 24h */
484952
-	&&put_0123_3210,	/* 24h -> 24s */
484952
-	&&put_0123_3290,	/* 24h ^> 24s */
484952
-	&&put_1234_1234,	/* 32h -> 32h */
484952
-	&&put_1234_9234,	/* 32h ^> 32h */
484952
-	&&put_1234_4321,	/* 32h -> 32s */
484952
-	&&put_1234_4329,	/* 32h ^> 32s */
484952
-};
484952
-#endif
484952
-
484952
-#ifdef PUT_END
484952
-put_1_1: as_s8(dst) = sample; goto PUT_END;
484952
-put_1_9: as_u8(dst) = sample ^ 0x80; goto PUT_END;
484952
-put_12_12: as_s16(dst) = sample; goto PUT_END;
484952
-put_12_92: as_u16(dst) = sample ^ 0x8000; goto PUT_END;
484952
-put_12_21: as_s16(dst) = bswap_16(sample); goto PUT_END;
484952
-put_12_29: as_u16(dst) = bswap_16(sample) ^ 0x80; goto PUT_END;
484952
-/* this always writes the unused byte in 24-bit formats as 0x00 */
484952
-put_0123_0123: as_s32(dst) = sx24(sample & 0x00ffffff); goto PUT_END;
484952
-put_0123_0923: as_u32(dst) = sx24((sample & 0x00ffffff) ^ 0x800000); goto PUT_END;
484952
-put_0123_3210: as_s32(dst) = sx24s(bswap_32(sample) & 0xffffff00); goto PUT_END;
484952
-put_0123_3290: as_u32(dst) = sx24s((bswap_32(sample) & 0xffffff00) ^ 0x8000); goto PUT_END;
484952
-put_1234_1234: as_s32(dst) = sample; goto PUT_END;
484952
-put_1234_9234: as_u32(dst) = sample ^ 0x80000000; goto PUT_END;
484952
-put_1234_4321: as_s32(dst) = bswap_32(sample); goto PUT_END;
484952
-put_1234_4329: as_u32(dst) = bswap_32(sample) ^ 0x80; goto PUT_END;
484952
-#endif
484952
-
484952
 #ifdef PUT32F_LABELS
484952
 /* type (0 = float, 1 = float64), endswap */
484952
 static void *const put32float_labels[2 * 2] = {
484952
-- 
484952
1.9.3
484952
484952
484952
From 7a5646f58ba2e8154a274a5ae0f8ec963f331f97 Mon Sep 17 00:00:00 2001
484952
From: Takashi Iwai <tiwai@suse.de>
484952
Date: Tue, 22 Jul 2014 12:20:50 +0200
484952
Subject: [PATCH 14/35] pcm: Drop snd_pcm_linear_{get|put}32_index()
484952
484952
These are identical with snd_pcm_linear_{get|put}_index().
484952
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 src/pcm/pcm_lfloat.c |  4 ++--
484952
 src/pcm/pcm_linear.c | 44 ++++----------------------------------------
484952
 src/pcm/pcm_plugin.h |  4 ----
484952
 src/pcm/pcm_route.c  |  4 ++--
484952
 4 files changed, 8 insertions(+), 48 deletions(-)
484952
484952
diff --git a/src/pcm/pcm_lfloat.c b/src/pcm/pcm_lfloat.c
484952
index 324282f..2f3e578 100644
484952
--- a/src/pcm/pcm_lfloat.c
484952
+++ b/src/pcm/pcm_lfloat.c
484952
@@ -286,11 +286,11 @@ static int snd_pcm_lfloat_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
484952
 		err = INTERNAL(snd_pcm_hw_params_get_format)(params, &dst_format);
484952
 	}
484952
 	if (snd_pcm_format_linear(src_format)) {
484952
-		lfloat->int32_idx = snd_pcm_linear_get32_index(src_format, SND_PCM_FORMAT_S32);
484952
+		lfloat->int32_idx = snd_pcm_linear_get_index(src_format, SND_PCM_FORMAT_S32);
484952
 		lfloat->float32_idx = snd_pcm_lfloat_put_s32_index(dst_format);
484952
 		lfloat->func = snd_pcm_lfloat_convert_integer_float;
484952
 	} else {
484952
-		lfloat->int32_idx = snd_pcm_linear_put32_index(SND_PCM_FORMAT_S32, dst_format);
484952
+		lfloat->int32_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S32, dst_format);
484952
 		lfloat->float32_idx = snd_pcm_lfloat_get_s32_index(src_format);
484952
 		lfloat->func = snd_pcm_lfloat_convert_float_integer;
484952
 	}
484952
diff --git a/src/pcm/pcm_linear.c b/src/pcm/pcm_linear.c
484952
index 3d5bbb8..9a92abd 100644
484952
--- a/src/pcm/pcm_linear.c
484952
+++ b/src/pcm/pcm_linear.c
484952
@@ -107,11 +107,6 @@ int snd_pcm_linear_get_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_f
484952
 	}
484952
 }
484952
 
484952
-int snd_pcm_linear_get32_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format)
484952
-{
484952
-	return snd_pcm_linear_get_index(src_format, dst_format);
484952
-}
484952
-
484952
 int snd_pcm_linear_put_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format)
484952
 {
484952
 	int sign, width, pwidth, endian;
484952
@@ -143,37 +138,6 @@ int snd_pcm_linear_put_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_f
484952
 	}
484952
 }
484952
 
484952
-int snd_pcm_linear_put32_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format)
484952
-{
484952
-	int sign, width, pwidth, endian;
484952
-	sign = (snd_pcm_format_signed(src_format) != 
484952
-		snd_pcm_format_signed(dst_format));
484952
-#ifdef SND_LITTLE_ENDIAN
484952
-	endian = snd_pcm_format_big_endian(dst_format);
484952
-#else
484952
-	endian = snd_pcm_format_little_endian(dst_format);
484952
-#endif
484952
-	if (endian < 0)
484952
-		endian = 0;
484952
-	pwidth = snd_pcm_format_physical_width(dst_format);
484952
-	width = snd_pcm_format_width(dst_format);
484952
-	if (pwidth == 24) {
484952
-		switch (width) {
484952
-		case 24:
484952
-			width = 0; break;
484952
-		case 20:
484952
-			width = 1; break;
484952
-		case 18:
484952
-		default:
484952
-			width = 2; break;
484952
-		}
484952
-		return width * 4 + endian * 2 + sign + 16;
484952
-	} else {
484952
-		width = width / 8 - 1;
484952
-		return width * 4 + endian * 2 + sign;
484952
-	}
484952
-}
484952
-
484952
 void snd_pcm_linear_convert(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
484952
 			    const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
484952
 			    unsigned int channels, snd_pcm_uframes_t frames,
484952
@@ -342,11 +306,11 @@ static int snd_pcm_linear_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
484952
 			      snd_pcm_format_physical_width(linear->sformat) == 24);
484952
 	if (linear->use_getput) {
484952
 		if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
484952
-			linear->get_idx = snd_pcm_linear_get32_index(format, SND_PCM_FORMAT_S32);
484952
-			linear->put_idx = snd_pcm_linear_put32_index(SND_PCM_FORMAT_S32, linear->sformat);
484952
+			linear->get_idx = snd_pcm_linear_get_index(format, SND_PCM_FORMAT_S32);
484952
+			linear->put_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S32, linear->sformat);
484952
 		} else {
484952
-			linear->get_idx = snd_pcm_linear_get32_index(linear->sformat, SND_PCM_FORMAT_S32);
484952
-			linear->put_idx = snd_pcm_linear_put32_index(SND_PCM_FORMAT_S32, format);
484952
+			linear->get_idx = snd_pcm_linear_get_index(linear->sformat, SND_PCM_FORMAT_S32);
484952
+			linear->put_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S32, format);
484952
 		}
484952
 	} else {
484952
 		if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
484952
diff --git a/src/pcm/pcm_plugin.h b/src/pcm/pcm_plugin.h
484952
index 19e82c3..b0a3e18 100644
484952
--- a/src/pcm/pcm_plugin.h
484952
+++ b/src/pcm/pcm_plugin.h
484952
@@ -86,8 +86,6 @@ snd_pcm_sframes_t snd_pcm_plugin_undo_write_generic
484952
 /* make local functions really local */
484952
 #define snd_pcm_linear_get_index	snd1_pcm_linear_get_index
484952
 #define snd_pcm_linear_put_index	snd1_pcm_linear_put_index
484952
-#define snd_pcm_linear_get32_index	snd1_pcm_linear_get32_index
484952
-#define snd_pcm_linear_put32_index	snd1_pcm_linear_put32_index
484952
 #define snd_pcm_linear_convert_index	snd1_pcm_linear_convert_index
484952
 #define snd_pcm_linear_convert	snd1_pcm_linear_convert
484952
 #define snd_pcm_linear_getput	snd1_pcm_linear_getput
484952
@@ -100,8 +98,6 @@ snd_pcm_sframes_t snd_pcm_plugin_undo_write_generic
484952
 
484952
 int snd_pcm_linear_get_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
484952
 int snd_pcm_linear_put_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
484952
-int snd_pcm_linear_get32_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
484952
-int snd_pcm_linear_put32_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
484952
 int snd_pcm_linear_convert_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
484952
 
484952
 void snd_pcm_linear_convert(const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
484952
diff --git a/src/pcm/pcm_route.c b/src/pcm/pcm_route.c
484952
index 5dac7eb..e7de9b5 100644
484952
--- a/src/pcm/pcm_route.c
484952
+++ b/src/pcm/pcm_route.c
484952
@@ -569,8 +569,8 @@ static int snd_pcm_route_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
484952
 	route->params.use_getput =
484952
 		(snd_pcm_format_physical_width(src_format) + 7) / 3 == 3 ||
484952
 		(snd_pcm_format_physical_width(dst_format) + 7) / 3 == 3;
484952
-	route->params.get_idx = snd_pcm_linear_get32_index(src_format, SND_PCM_FORMAT_S32);
484952
-	route->params.put_idx = snd_pcm_linear_put32_index(SND_PCM_FORMAT_S32, dst_format);
484952
+	route->params.get_idx = snd_pcm_linear_get_index(src_format, SND_PCM_FORMAT_S32);
484952
+	route->params.put_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S32, dst_format);
484952
 	route->params.conv_idx = snd_pcm_linear_convert_index(src_format, dst_format);
484952
 	route->params.src_size = snd_pcm_format_width(src_format) / 8;
484952
 	route->params.dst_sfmt = dst_format;
484952
-- 
484952
1.9.3
484952
484952
484952
From f6b879e7cc87d83343f5004369146881d1d1e335 Mon Sep 17 00:00:00 2001
484952
From: Shengjiu Wang <shengjiu.wang@freescale.com>
484952
Date: Wed, 23 Jul 2014 15:09:58 +0800
484952
Subject: [PATCH 15/35] pcm: pcm_local.h: include <time.h> to enable
484952
 CLOCK_MONOTONIC
484952
484952
CLOCK_MONITONIC is defined in <bits/time.h>, add <time.h> before
484952
<sys/time.h>.
484952
484952
Signed-off-by: Shengjiu Wang <shengjiu.wang@freescale.com>
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 src/pcm/pcm_local.h | 1 +
484952
 1 file changed, 1 insertion(+)
484952
484952
diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h
484952
index 2206afe..80bbe59 100644
484952
--- a/src/pcm/pcm_local.h
484952
+++ b/src/pcm/pcm_local.h
484952
@@ -24,6 +24,7 @@
484952
 #include <stdlib.h>
484952
 #include <limits.h>
484952
 #include <sys/uio.h>
484952
+#include <time.h>
484952
 #include <sys/time.h>
484952
 
484952
 #define _snd_mask sndrv_mask
484952
-- 
484952
1.9.3
484952
484952
484952
From 87df9f3b7a650418b9aef943ac246549c132672a Mon Sep 17 00:00:00 2001
484952
From: Jurgen Kramer <gtmkramer@xs4all.nl>
484952
Date: Sat, 9 Aug 2014 12:09:21 +0200
484952
Subject: [PATCH 16/35] pcm: Fix DSD formats userland usability
484952
484952
Support for DSD sample formats has been added a while ago. This patch makes
484952
those sample formats beter usable from userland (e.g. aplay).
484952
484952
[These implementation details have been forgotten in the previous DSD
484952
 support patch -- tiwai]
484952
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 include/sound/asound.h | 4 +++-
484952
 src/pcm/pcm_misc.c     | 4 ++++
484952
 2 files changed, 7 insertions(+), 1 deletion(-)
484952
484952
diff --git a/include/sound/asound.h b/include/sound/asound.h
484952
index c819df4..5194524 100644
484952
--- a/include/sound/asound.h
484952
+++ b/include/sound/asound.h
484952
@@ -214,7 +214,9 @@ typedef int __bitwise snd_pcm_format_t;
484952
 #define	SNDRV_PCM_FORMAT_G723_24_1B	((__force snd_pcm_format_t) 45) /* 1 sample in 1 byte */
484952
 #define	SNDRV_PCM_FORMAT_G723_40	((__force snd_pcm_format_t) 46) /* 8 Samples in 5 bytes */
484952
 #define	SNDRV_PCM_FORMAT_G723_40_1B	((__force snd_pcm_format_t) 47) /* 1 sample in 1 byte */
484952
-#define	SNDRV_PCM_FORMAT_LAST		SNDRV_PCM_FORMAT_G723_40_1B
484952
+#define SNDRV_PCM_FORMAT_DSD_U8		((__force snd_pcm_format_t) 48) /* 8 1-bit samples in 1 byte */
484952
+#define SNDRV_PCM_FORMAT_DSD_U16_LE	((__force snd_pcm_format_t) 49) /* 16 1-bit samples in 2 bytes */
484952
+#define	SNDRV_PCM_FORMAT_LAST		SNDRV_PCM_FORMAT_DSD_U16_LE
484952
 
484952
 #ifdef SNDRV_LITTLE_ENDIAN
484952
 #define	SNDRV_PCM_FORMAT_S16		SNDRV_PCM_FORMAT_S16_LE
484952
diff --git a/src/pcm/pcm_misc.c b/src/pcm/pcm_misc.c
484952
index d52160c..44bb89c 100644
484952
--- a/src/pcm/pcm_misc.c
484952
+++ b/src/pcm/pcm_misc.c
484952
@@ -195,11 +195,13 @@ int snd_pcm_format_width(snd_pcm_format_t format)
484952
 	switch (format) {
484952
 	case SNDRV_PCM_FORMAT_S8:
484952
 	case SNDRV_PCM_FORMAT_U8:
484952
+	case SNDRV_PCM_FORMAT_DSD_U8:
484952
 		return 8;
484952
 	case SNDRV_PCM_FORMAT_S16_LE:
484952
 	case SNDRV_PCM_FORMAT_S16_BE:
484952
 	case SNDRV_PCM_FORMAT_U16_LE:
484952
 	case SNDRV_PCM_FORMAT_U16_BE:
484952
+	case SNDRV_PCM_FORMAT_DSD_U16_LE:
484952
 		return 16;
484952
 	case SNDRV_PCM_FORMAT_S18_3LE:
484952
 	case SNDRV_PCM_FORMAT_S18_3BE:
484952
@@ -253,11 +255,13 @@ int snd_pcm_format_physical_width(snd_pcm_format_t format)
484952
 	switch (format) {
484952
 	case SNDRV_PCM_FORMAT_S8:
484952
 	case SNDRV_PCM_FORMAT_U8:
484952
+	case SNDRV_PCM_FORMAT_DSD_U8:
484952
 		return 8;
484952
 	case SNDRV_PCM_FORMAT_S16_LE:
484952
 	case SNDRV_PCM_FORMAT_S16_BE:
484952
 	case SNDRV_PCM_FORMAT_U16_LE:
484952
 	case SNDRV_PCM_FORMAT_U16_BE:
484952
+	case SNDRV_PCM_FORMAT_DSD_U16_LE:
484952
 		return 16;
484952
 	case SNDRV_PCM_FORMAT_S18_3LE:
484952
 	case SNDRV_PCM_FORMAT_S18_3BE:
484952
-- 
484952
1.9.3
484952
484952
484952
From 717ae3dd90c37f3a5ea9809370bdf56e2590a1c4 Mon Sep 17 00:00:00 2001
484952
From: Takashi Iwai <tiwai@suse.de>
484952
Date: Mon, 11 Aug 2014 11:51:29 +0200
484952
Subject: [PATCH 17/35] Sync include/sound/asound.h with 3.17-rc1 kernel
484952
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 include/sound/asound.h | 13 +++++++++----
484952
 1 file changed, 9 insertions(+), 4 deletions(-)
484952
484952
diff --git a/include/sound/asound.h b/include/sound/asound.h
484952
index 5194524..32168f7 100644
484952
--- a/include/sound/asound.h
484952
+++ b/include/sound/asound.h
484952
@@ -93,9 +93,12 @@ enum {
484952
 	SNDRV_HWDEP_IFACE_SB_RC,	/* SB Extigy/Audigy2NX remote control */
484952
 	SNDRV_HWDEP_IFACE_HDA,		/* HD-audio */
484952
 	SNDRV_HWDEP_IFACE_USB_STREAM,	/* direct access to usb stream */
484952
+	SNDRV_HWDEP_IFACE_FW_DICE,	/* TC DICE FireWire device */
484952
+	SNDRV_HWDEP_IFACE_FW_FIREWORKS,	/* Echo Audio Fireworks based device */
484952
+	SNDRV_HWDEP_IFACE_FW_BEBOB,	/* BridgeCo BeBoB based device */
484952
 
484952
 	/* Don't forget to change the following: */
484952
-	SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_USB_STREAM
484952
+	SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_BEBOB
484952
 };
484952
 
484952
 struct snd_hwdep_info {
484952
@@ -214,8 +217,8 @@ typedef int __bitwise snd_pcm_format_t;
484952
 #define	SNDRV_PCM_FORMAT_G723_24_1B	((__force snd_pcm_format_t) 45) /* 1 sample in 1 byte */
484952
 #define	SNDRV_PCM_FORMAT_G723_40	((__force snd_pcm_format_t) 46) /* 8 Samples in 5 bytes */
484952
 #define	SNDRV_PCM_FORMAT_G723_40_1B	((__force snd_pcm_format_t) 47) /* 1 sample in 1 byte */
484952
-#define SNDRV_PCM_FORMAT_DSD_U8		((__force snd_pcm_format_t) 48) /* 8 1-bit samples in 1 byte */
484952
-#define SNDRV_PCM_FORMAT_DSD_U16_LE	((__force snd_pcm_format_t) 49) /* 16 1-bit samples in 2 bytes */
484952
+#define	SNDRV_PCM_FORMAT_DSD_U8		((__force snd_pcm_format_t) 48) /* DSD, 1-byte samples DSD (x8) */
484952
+#define	SNDRV_PCM_FORMAT_DSD_U16_LE	((__force snd_pcm_format_t) 49) /* DSD, 2-byte samples DSD (x16), little endian */
484952
 #define	SNDRV_PCM_FORMAT_LAST		SNDRV_PCM_FORMAT_DSD_U16_LE
484952
 
484952
 #ifdef SNDRV_LITTLE_ENDIAN
484952
@@ -461,7 +464,7 @@ struct snd_xfern {
484952
 enum {
484952
 	SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY = 0,	/* gettimeofday equivalent */
484952
 	SNDRV_PCM_TSTAMP_TYPE_MONOTONIC,	/* posix_clock_monotonic equivalent */
484952
-	SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW,	/* monotonic_raw (no NTP) */
484952
+	SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW,    /* monotonic_raw (no NTP) */
484952
 	SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW,
484952
 };
484952
 
484952
@@ -820,6 +823,8 @@ typedef int __bitwise snd_ctl_elem_iface_t;
484952
 #define SNDRV_CTL_POWER_D3hot		(SNDRV_CTL_POWER_D3|0x0000)	/* Off, with power */
484952
 #define SNDRV_CTL_POWER_D3cold		(SNDRV_CTL_POWER_D3|0x0001)	/* Off, without power */
484952
 
484952
+#define SNDRV_CTL_ELEM_ID_NAME_MAXLEN	44
484952
+
484952
 struct snd_ctl_elem_id {
484952
 	unsigned int numid;		/* numeric identifier, zero = invalid */
484952
 	snd_ctl_elem_iface_t iface;	/* interface identifier */
484952
-- 
484952
1.9.3
484952
484952
484952
From e8e54811339b13d6df648bb48b35157d9fba352c Mon Sep 17 00:00:00 2001
484952
From: Takashi Iwai <tiwai@suse.de>
484952
Date: Mon, 11 Aug 2014 11:55:03 +0200
484952
Subject: [PATCH 18/35] pcm: Add missing signed and endianess definitions for
484952
 DSD formats
484952
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 src/pcm/pcm_misc.c | 4 ++++
484952
 1 file changed, 4 insertions(+)
484952
484952
diff --git a/src/pcm/pcm_misc.c b/src/pcm/pcm_misc.c
484952
index 44bb89c..24d52f9 100644
484952
--- a/src/pcm/pcm_misc.c
484952
+++ b/src/pcm/pcm_misc.c
484952
@@ -62,6 +62,8 @@ int snd_pcm_format_signed(snd_pcm_format_t format)
484952
 	case SNDRV_PCM_FORMAT_U20_3BE:
484952
 	case SNDRV_PCM_FORMAT_U18_3LE:
484952
 	case SNDRV_PCM_FORMAT_U18_3BE:
484952
+	case SNDRV_PCM_FORMAT_DSD_U8:
484952
+	case SNDRV_PCM_FORMAT_DSD_U16_LE:
484952
 		return 0;
484952
 	default:
484952
 		return -EINVAL;
484952
@@ -150,6 +152,8 @@ int snd_pcm_format_little_endian(snd_pcm_format_t format)
484952
 	case SNDRV_PCM_FORMAT_U24_3BE:
484952
 	case SNDRV_PCM_FORMAT_U20_3BE:
484952
 	case SNDRV_PCM_FORMAT_U18_3BE:
484952
+	case SNDRV_PCM_FORMAT_DSD_U8:
484952
+	case SNDRV_PCM_FORMAT_DSD_U16_LE:
484952
 		return 0;
484952
 	default:
484952
 		return -EINVAL;
484952
-- 
484952
1.9.3
484952
484952
484952
From dfc3bf97bf45bd78d498d20fcf930541350f836d Mon Sep 17 00:00:00 2001
484952
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
484952
Date: Mon, 18 Aug 2014 18:45:17 +0900
484952
Subject: [PATCH 19/35] Sync enum snd_hwdep_iface_t with
484952
 include/asound/asound.h
484952
484952
Some members in this enumerated type has not updated for 9 years, although
484952
kernel-drivers added them during this period. This commit adds them following
484952
to a commit 87df9f3 'sync include/asound/asound.h with 3.17-rc1 kernel'.
484952
484952
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 include/hwdep.h | 9 +++++++--
484952
 1 file changed, 7 insertions(+), 2 deletions(-)
484952
484952
diff --git a/include/hwdep.h b/include/hwdep.h
484952
index ab12822..6496fa2 100644
484952
--- a/include/hwdep.h
484952
+++ b/include/hwdep.h
484952
@@ -68,8 +68,13 @@ typedef enum _snd_hwdep_iface {
484952
 	SND_HWDEP_IFACE_USX2Y_PCM,	/**< Tascam US122, US224 & US428 raw USB PCM */
484952
 	SND_HWDEP_IFACE_PCXHR,		/**< Digigram PCXHR */
484952
 	SND_HWDEP_IFACE_SB_RC,		/**< SB Extigy/Audigy2NX remote control */
484952
-                
484952
-	SND_HWDEP_IFACE_LAST = SND_HWDEP_IFACE_SB_RC  /**< last known hwdep interface */
484952
+	SND_HWDEP_IFACE_HDA,		/**< HD-audio */
484952
+	SND_HWDEP_IFACE_USB_STREAM,	/**< direct access to usb stream */
484952
+	SND_HWDEP_IFACE_FW_DICE,	/**< TC DICE FireWire device */
484952
+	SND_HWDEP_IFACE_FW_FIREWORKS,	/**< Echo Audio Fireworks based device */
484952
+	SND_HWDEP_IFACE_FW_BEBOB,	/**< BridgeCo BeBoB based device */
484952
+
484952
+	SND_HWDEP_IFACE_LAST = SND_HWDEP_IFACE_FW_BEBOB  /**< last known hwdep interface */
484952
 } snd_hwdep_iface_t;
484952
 
484952
 /** open for reading */
484952
-- 
484952
1.9.3
484952
484952
484952
From b9f58dcc6f91fde42e6dd2bb831d6063855512a7 Mon Sep 17 00:00:00 2001
484952
From: Jurgen Kramer <gtmkramer@xs4all.nl>
484952
Date: Fri, 22 Aug 2014 10:15:10 +0200
484952
Subject: [PATCH 20/35] pcm: 2nd round of pcm_misc DSD fixes
484952
484952
Functions 'snd_pcm_format_silence_64' and 'snd_pcm_format_size' also need to be
484952
able to handle the DSD smaple format.
484952
484952
Changes from v1:
484952
- Correct silence pattern for DSD
484952
484952
Signed-off-by: Jurgen Kramer <gtmkramer@xs4all.nl>
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 src/pcm/pcm_misc.c | 5 +++++
484952
 1 file changed, 5 insertions(+)
484952
484952
diff --git a/src/pcm/pcm_misc.c b/src/pcm/pcm_misc.c
484952
index 24d52f9..46fc771 100644
484952
--- a/src/pcm/pcm_misc.c
484952
+++ b/src/pcm/pcm_misc.c
484952
@@ -317,11 +317,13 @@ ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples)
484952
 	switch (format) {
484952
 	case SNDRV_PCM_FORMAT_S8:
484952
 	case SNDRV_PCM_FORMAT_U8:
484952
+	case SNDRV_PCM_FORMAT_DSD_U8:
484952
 		return samples;
484952
 	case SNDRV_PCM_FORMAT_S16_LE:
484952
 	case SNDRV_PCM_FORMAT_S16_BE:
484952
 	case SNDRV_PCM_FORMAT_U16_LE:
484952
 	case SNDRV_PCM_FORMAT_U16_BE:
484952
+	case SNDRV_PCM_FORMAT_DSD_U16_LE:
484952
 		return samples * 2;
484952
 	case SNDRV_PCM_FORMAT_S18_3LE:
484952
 	case SNDRV_PCM_FORMAT_S18_3BE:
484952
@@ -390,6 +392,9 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
484952
 		return 0;
484952
 	case SNDRV_PCM_FORMAT_U8:
484952
 		return 0x8080808080808080ULL;
484952
+	case SNDRV_PCM_FORMAT_DSD_U8:
484952
+	case SNDRV_PCM_FORMAT_DSD_U16_LE:
484952
+		return 0x6969696969696969ULL;
484952
 #ifdef SNDRV_LITTLE_ENDIAN
484952
 	case SNDRV_PCM_FORMAT_U16_LE:
484952
 		return 0x8000800080008000ULL;
484952
-- 
484952
1.9.3
484952
484952
484952
From 5f1960e3d8d56aa63afe2c37c6a3f4aa03571627 Mon Sep 17 00:00:00 2001
484952
From: Dmitry Voytik <voytikd@gmail.com>
484952
Date: Fri, 22 Aug 2014 14:17:10 +0400
484952
Subject: [PATCH 21/35] doc: fix cross-compiling example
484952
484952
Simplest way to configure cross-compilation with configure
484952
script is to pass '--host' option.
484952
Passing just '--target' doesn't work.
484952
484952
Signed-off-by: Dmitry Voytik <voytikd@gmail.com>
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 INSTALL | 9 +++------
484952
 1 file changed, 3 insertions(+), 6 deletions(-)
484952
484952
diff --git a/INSTALL b/INSTALL
484952
index 91a8648..47086e3 100644
484952
--- a/INSTALL
484952
+++ b/INSTALL
484952
@@ -78,16 +78,13 @@ When you would like to cross-compile ALSA library (e.g. compile on
484952
 i686 host but for arm architecture) you will need to call ./configure
484952
 script with additional parameters:
484952
 
484952
-CC=arm-linux-gcc ./configure --target=arm-linux
484952
+CC=arm-linux-gcc ./configure --host=arm-linux
484952
 
484952
-In this example host where the library is build is guessed (should be
484952
-given with --host=platform) and target for which is the library build is
484952
-Linux on ARM architecture.  You should omit setting 'CC' variable and
484952
-cross-compiler will be guessed too.
484952
+You can omit setting 'CC' variable and cross-compiler will be guessed too.
484952
 
484952
 So simplest version would be:
484952
 
484952
-./configure --target=arm-linux
484952
+./configure --host=arm-linux
484952
 
484952
 For platform names in the form cpu-vendor-os (or aliases for this)
484952
 you should look in 'config.guess' script. Target and all paths
484952
-- 
484952
1.9.3
484952
484952
484952
From 99a2254f5f2a085b81efcc80950033a2b6110ecd Mon Sep 17 00:00:00 2001
484952
From: "Alexander E. Patrakov" <patrakov@gmail.com>
484952
Date: Sun, 31 Aug 2014 22:23:47 +0600
484952
Subject: [PATCH 22/35] pcm: fix snd_pcm_mmap_hw_avail() near the boundary
484952
484952
This function returned incorrect results when hw.ptr was near the
484952
boundary and hw.appl_ptr was near zero. Here "incorrect" means "greater
484952
than the boundary".
484952
484952
The result was incorrect, because it was used as a return value of
484952
various *_rewindable() functions and also as the delay for ioplug.
484952
484952
Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 src/pcm/pcm_local.h | 8 +-------
484952
 1 file changed, 1 insertion(+), 7 deletions(-)
484952
484952
diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h
484952
index 80bbe59..74ebd60 100644
484952
--- a/src/pcm/pcm_local.h
484952
+++ b/src/pcm/pcm_local.h
484952
@@ -461,13 +461,7 @@ static inline snd_pcm_sframes_t snd_pcm_mmap_capture_hw_avail(snd_pcm_t *pcm)
484952
 
484952
 static inline snd_pcm_sframes_t snd_pcm_mmap_hw_avail(snd_pcm_t *pcm)
484952
 {
484952
-	snd_pcm_sframes_t avail;
484952
-	avail = *pcm->hw.ptr - *pcm->appl.ptr;
484952
-	if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
484952
-		avail += pcm->buffer_size;
484952
-	if (avail < 0)
484952
-		avail += pcm->boundary;
484952
-	return pcm->buffer_size - avail;
484952
+	return pcm->buffer_size - snd_pcm_mmap_avail(pcm);
484952
 }
484952
 
484952
 static inline const snd_pcm_channel_area_t *snd_pcm_mmap_areas(snd_pcm_t *pcm)
484952
-- 
484952
1.9.3
484952
484952
484952
From 622b1b6bdbb34baca885b65643d4796057574eb7 Mon Sep 17 00:00:00 2001
484952
From: "Alexander E. Patrakov" <patrakov@gmail.com>
484952
Date: Tue, 2 Sep 2014 01:29:36 +0600
484952
Subject: [PATCH 23/35] pcm: fix return value of snd_pcm_share_slave_avail
484952
484952
The return value was wrong for playback if slave->hw_ptr was near the
484952
boundary and *pcm->appl.ptr was near zero. The wrong result was greater
484952
than the boundary.
484952
484952
Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 src/pcm/pcm_share.c | 2 ++
484952
 1 file changed, 2 insertions(+)
484952
484952
diff --git a/src/pcm/pcm_share.c b/src/pcm/pcm_share.c
484952
index 9770544..c301c7a 100644
484952
--- a/src/pcm/pcm_share.c
484952
+++ b/src/pcm/pcm_share.c
484952
@@ -128,6 +128,8 @@ static snd_pcm_uframes_t snd_pcm_share_slave_avail(snd_pcm_share_slave_t *slave)
484952
 		avail += pcm->buffer_size;
484952
 	if (avail < 0)
484952
 		avail += pcm->boundary;
484952
+	else if ((snd_pcm_uframes_t) avail >= pcm->boundary)
484952
+		avail -= pcm->boundary;
484952
 	return avail;
484952
 }
484952
 
484952
-- 
484952
1.9.3
484952
484952
484952
From e59ffbf30ec13f7f1615ba266ec2f3e770801d6f Mon Sep 17 00:00:00 2001
484952
From: Jurgen Kramer <gtmkramer@xs4all.nl>
484952
Date: Wed, 10 Sep 2014 09:00:28 +0200
484952
Subject: [PATCH 24/35] pcm: add new 32-bit DSD sample format
484952
484952
Add the new DSD_U32_LE sample format to alsa-lib.
484952
484952
NB include/pcm.h and include/sound/asound.h are updated so a new sync with the
484952
kernel headers is not needed
484952
484952
Signed-off-by: Jurgen Kramer <gtmkramer@xs4all.nl>
484952
Signed-off-by: Takashi Iwai <tiwai@suse.de>
484952
---
484952
 include/pcm.h          | 4 +++-
484952
 include/sound/asound.h | 3 ++-
484952
 src/pcm/pcm.c          | 2 ++
484952
 src/pcm/pcm_misc.c     | 6 ++++++
484952
 4 files changed, 13 insertions(+), 2 deletions(-)
484952
484952
diff --git a/include/pcm.h b/include/pcm.h
484952
index 11e9f0d..db88ad5 100644
484952
--- a/include/pcm.h
484952
+++ b/include/pcm.h
484952
@@ -211,7 +211,9 @@ typedef enum _snd_pcm_format {
484952
 	SND_PCM_FORMAT_DSD_U8,
484952
 	/* Direct Stream Digital (DSD) in 2-byte samples (x16) */
484952
 	SND_PCM_FORMAT_DSD_U16_LE,
484952
-	SND_PCM_FORMAT_LAST = SND_PCM_FORMAT_DSD_U16_LE,
484952
+	/* Direct Stream Digital (DSD) in 4-byte samples (x32) */
484952
+	SND_PCM_FORMAT_DSD_U32_LE,
484952
+	SND_PCM_FORMAT_LAST = SND_PCM_FORMAT_DSD_U32_LE,
484952
 
484952
 #if __BYTE_ORDER == __LITTLE_ENDIAN
484952
 	/** Signed 16 bit CPU endian */
484952
diff --git a/include/sound/asound.h b/include/sound/asound.h
484952
index 32168f7..6ee5867 100644
484952
--- a/include/sound/asound.h
484952
+++ b/include/sound/asound.h
484952
@@ -219,7 +219,8 @@ typedef int __bitwise snd_pcm_format_t;
484952
 #define	SNDRV_PCM_FORMAT_G723_40_1B	((__force snd_pcm_format_t) 47) /* 1 sample in 1 byte */
484952
 #define	SNDRV_PCM_FORMAT_DSD_U8		((__force snd_pcm_format_t) 48) /* DSD, 1-byte samples DSD (x8) */
484952
 #define	SNDRV_PCM_FORMAT_DSD_U16_LE	((__force snd_pcm_format_t) 49) /* DSD, 2-byte samples DSD (x16), little endian */
484952
-#define	SNDRV_PCM_FORMAT_LAST		SNDRV_PCM_FORMAT_DSD_U16_LE
484952
+#define	SNDRV_PCM_FORMAT_DSD_U32_LE	((__force snd_pcm_format_t) 50) /* DSD, 4-byte samples DSD (x32), little endian */
484952
+#define	SNDRV_PCM_FORMAT_LAST		SNDRV_PCM_FORMAT_DSD_U32_LE
484952
 
484952
 #ifdef SNDRV_LITTLE_ENDIAN
484952
 #define	SNDRV_PCM_FORMAT_S16		SNDRV_PCM_FORMAT_S16_LE
484952
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
484952
index 1399a5b..2e24338 100644
484952
--- a/src/pcm/pcm.c
484952
+++ b/src/pcm/pcm.c
484952
@@ -1565,6 +1565,7 @@ static const char *const snd_pcm_format_names[] = {
484952
 	FORMAT(G723_40_1B),
484952
 	FORMAT(DSD_U8),
484952
 	FORMAT(DSD_U16_LE),
484952
+	FORMAT(DSD_U32_LE),
484952
 };
484952
 
484952
 static const char *const snd_pcm_format_aliases[SND_PCM_FORMAT_LAST+1] = {
484952
@@ -1624,6 +1625,7 @@ static const char *const snd_pcm_format_descriptions[] = {
484952
 	FORMATD(G723_40_1B, "G.723 (ADPCM) 40 kbit/s, 1 sample in 1 byte"),
484952
 	FORMATD(DSD_U8,  "Direct Stream Digital, 1-byte (x8), oldest bit in MSB"),
484952
 	FORMATD(DSD_U16_LE, "Direct Stream Digital, 2-byte (x16), little endian, oldest bits in MSB"),
484952
+	FORMATD(DSD_U32_LE, "Direct Stream Digital, 4-byte (x32), little endian, oldest bits in MSB"),
484952
 };
484952
 
484952
 static const char *const snd_pcm_type_names[] = {
484952
diff --git a/src/pcm/pcm_misc.c b/src/pcm/pcm_misc.c
484952
index 46fc771..9272179 100644
484952
--- a/src/pcm/pcm_misc.c
484952
+++ b/src/pcm/pcm_misc.c
484952
@@ -64,6 +64,7 @@ int snd_pcm_format_signed(snd_pcm_format_t format)
484952
 	case SNDRV_PCM_FORMAT_U18_3BE:
484952
 	case SNDRV_PCM_FORMAT_DSD_U8:
484952
 	case SNDRV_PCM_FORMAT_DSD_U16_LE:
484952
+	case SNDRV_PCM_FORMAT_DSD_U32_LE:
484952
 		return 0;
484952
 	default:
484952
 		return -EINVAL;
484952
@@ -154,6 +155,7 @@ int snd_pcm_format_little_endian(snd_pcm_format_t format)
484952
 	case SNDRV_PCM_FORMAT_U18_3BE:
484952
 	case SNDRV_PCM_FORMAT_DSD_U8:
484952
 	case SNDRV_PCM_FORMAT_DSD_U16_LE:
484952
+	case SNDRV_PCM_FORMAT_DSD_U32_LE:
484952
 		return 0;
484952
 	default:
484952
 		return -EINVAL;
484952
@@ -232,6 +234,7 @@ int snd_pcm_format_width(snd_pcm_format_t format)
484952
 	case SNDRV_PCM_FORMAT_U32_BE:
484952
 	case SNDRV_PCM_FORMAT_FLOAT_LE:
484952
 	case SNDRV_PCM_FORMAT_FLOAT_BE:
484952
+	case SNDRV_PCM_FORMAT_DSD_U32_LE:
484952
 		return 32;
484952
 	case SNDRV_PCM_FORMAT_FLOAT64_LE:
484952
 	case SNDRV_PCM_FORMAT_FLOAT64_BE:
484952
@@ -292,6 +295,7 @@ int snd_pcm_format_physical_width(snd_pcm_format_t format)
484952
 	case SNDRV_PCM_FORMAT_FLOAT_BE:
484952
 	case SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE:
484952
 	case SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE:
484952
+	case SNDRV_PCM_FORMAT_DSD_U32_LE:
484952
 		return 32;
484952
 	case SNDRV_PCM_FORMAT_FLOAT64_LE:
484952
 	case SNDRV_PCM_FORMAT_FLOAT64_BE:
484952
@@ -348,6 +352,7 @@ ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples)
484952
 	case SNDRV_PCM_FORMAT_U32_BE:
484952
 	case SNDRV_PCM_FORMAT_FLOAT_LE:
484952
 	case SNDRV_PCM_FORMAT_FLOAT_BE:
484952
+	case SNDRV_PCM_FORMAT_DSD_U32_LE:
484952
 		return samples * 4;
484952
 	case SNDRV_PCM_FORMAT_FLOAT64_LE:
484952
 	case SNDRV_PCM_FORMAT_FLOAT64_BE:
484952
@@ -394,6 +399,7 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
484952
 		return 0x8080808080808080ULL;
484952
 	case SNDRV_PCM_FORMAT_DSD_U8:
484952
 	case SNDRV_PCM_FORMAT_DSD_U16_LE:
484952
+	case SNDRV_PCM_FORMAT_DSD_U32_LE:
484952
 		return 0x6969696969696969ULL;
484952
 #ifdef SNDRV_LITTLE_ENDIAN
484952
 	case SNDRV_PCM_FORMAT_U16_LE:
484952
-- 
484952
1.9.3
484952
484952
484952
From 9a56a673a6cd7343a9345921e2b1cbbb43fb725f Mon Sep 17 00:00:00 2001
484952
From: "Alexander E. Patrakov" <patrakov@gmail.com>
484952
Date: Sun, 14 Sep 2014 00:30:13 +0600
484952
Subject: [PATCH 25/35] dmix: actually rewind when running or being drained
484952
484952
Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
484952
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
484952
---
484952
 src/pcm/pcm_dmix.c | 8 ++++++--
484952
 1 file changed, 6 insertions(+), 2 deletions(-)
484952
484952
diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c
484952
index 7c53509..73cbe3f 100644
484952
--- a/src/pcm/pcm_dmix.c
484952
+++ b/src/pcm/pcm_dmix.c
484952
@@ -669,11 +669,15 @@ static snd_pcm_sframes_t snd_pcm_dmix_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t f
484952
 	snd_pcm_direct_t *dmix = pcm->private_data;
484952
 	snd_pcm_uframes_t slave_appl_ptr, slave_size;
484952
 	snd_pcm_uframes_t appl_ptr, size, transfer, result;
484952
+	int err;
484952
 	const snd_pcm_channel_area_t *src_areas, *dst_areas;
484952
 
484952
 	if (dmix->state == SND_PCM_STATE_RUNNING ||
484952
-	    dmix->state == SND_PCM_STATE_DRAINING)
484952
-	    	return snd_pcm_dmix_hwsync(pcm);
484952
+	    dmix->state == SND_PCM_STATE_DRAINING) {
484952
+		err = snd_pcm_dmix_hwsync(pcm);
484952
+		if (err < 0)
484952
+			return err;
484952
+	}
484952
 
484952
 	if (dmix->last_appl_ptr < dmix->appl_ptr)
484952
 		size = dmix->appl_ptr - dmix->last_appl_ptr;
484952
-- 
484952
1.9.3
484952
484952
484952
From 9a43dc15b2979ed6d8850b033b594fbef829c991 Mon Sep 17 00:00:00 2001
484952
From: "Alexander E. Patrakov" <patrakov@gmail.com>
484952
Date: Sun, 14 Sep 2014 00:30:14 +0600
484952
Subject: [PATCH 26/35] pcm: express the rewind size limitation logic better
484952
484952
There are a few places where the argument of the .rewind or .forward
484952
callback is checked against the same value as returned by .rewindable or
484952
.forwardable. Express this "don't rewind more than rewindable" logic
484952
explicitly, so that the future fixes to the rewindable size can go to
484952
one function instead of two.
484952
484952
While at it, take advantage of the fact that snd_pcm_mmap_avail() cannot
484952
return negative values (except due to integer overflow, which is AFAICS
484952
impossible given the current boundary choice).
484952
484952
Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
484952
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
484952
---
484952
 src/pcm/pcm_dmix.c   | 4 +---
484952
 src/pcm/pcm_dshare.c | 6 ++----
484952
 src/pcm/pcm_dsnoop.c | 6 ++----
484952
 src/pcm/pcm_plugin.c | 4 ++--
484952
 4 files changed, 7 insertions(+), 13 deletions(-)
484952
484952
diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c
484952
index 73cbe3f..ffde12a 100644
484952
--- a/src/pcm/pcm_dmix.c
484952
+++ b/src/pcm/pcm_dmix.c
484952
@@ -751,9 +751,7 @@ static snd_pcm_sframes_t snd_pcm_dmix_forward(snd_pcm_t *pcm, snd_pcm_uframes_t
484952
 {
484952
 	snd_pcm_sframes_t avail;
484952
 
484952
-	avail = snd_pcm_mmap_playback_avail(pcm);
484952
-	if (avail < 0)
484952
-		return 0;
484952
+	avail = snd_pcm_dmix_forwardable(pcm);
484952
 	if (frames > (snd_pcm_uframes_t)avail)
484952
 		frames = avail;
484952
 	snd_pcm_mmap_appl_forward(pcm, frames);
484952
diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c
484952
index b985172..f1a1a1d 100644
484952
--- a/src/pcm/pcm_dshare.c
484952
+++ b/src/pcm/pcm_dshare.c
484952
@@ -419,7 +419,7 @@ static snd_pcm_sframes_t snd_pcm_dshare_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t
484952
 {
484952
 	snd_pcm_sframes_t avail;
484952
 
484952
-	avail = snd_pcm_mmap_playback_hw_avail(pcm);
484952
+	avail = snd_pcm_dshare_rewindable(pcm);
484952
 	if (avail < 0)
484952
 		return 0;
484952
 	if (frames > (snd_pcm_uframes_t)avail)
484952
@@ -437,9 +437,7 @@ static snd_pcm_sframes_t snd_pcm_dshare_forward(snd_pcm_t *pcm, snd_pcm_uframes_
484952
 {
484952
 	snd_pcm_sframes_t avail;
484952
 
484952
-	avail = snd_pcm_mmap_playback_avail(pcm);
484952
-	if (avail < 0)
484952
-		return 0;
484952
+	avail = snd_pcm_dshare_forwardable(pcm);
484952
 	if (frames > (snd_pcm_uframes_t)avail)
484952
 		frames = avail;
484952
 	snd_pcm_mmap_appl_forward(pcm, frames);
484952
diff --git a/src/pcm/pcm_dsnoop.c b/src/pcm/pcm_dsnoop.c
484952
index 0f9c9df..e56e402 100644
484952
--- a/src/pcm/pcm_dsnoop.c
484952
+++ b/src/pcm/pcm_dsnoop.c
484952
@@ -342,9 +342,7 @@ static snd_pcm_sframes_t snd_pcm_dsnoop_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t
484952
 {
484952
 	snd_pcm_sframes_t avail;
484952
 
484952
-	avail = snd_pcm_mmap_capture_avail(pcm);
484952
-	if (avail < 0)
484952
-		return 0;
484952
+	avail = snd_pcm_dsnoop_rewindable(pcm);
484952
 	if (frames > (snd_pcm_uframes_t)avail)
484952
 		frames = avail;
484952
 	snd_pcm_mmap_appl_backward(pcm, frames);
484952
@@ -360,7 +358,7 @@ static snd_pcm_sframes_t snd_pcm_dsnoop_forward(snd_pcm_t *pcm, snd_pcm_uframes_
484952
 {
484952
 	snd_pcm_sframes_t avail;
484952
 
484952
-	avail = snd_pcm_mmap_capture_hw_avail(pcm);
484952
+	avail = snd_pcm_dsnoop_forwardable(pcm);
484952
 	if (avail < 0)
484952
 		return 0;
484952
 	if (frames > (snd_pcm_uframes_t)avail)
484952
diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
484952
index 4ddf10c..a607ccf 100644
484952
--- a/src/pcm/pcm_plugin.c
484952
+++ b/src/pcm/pcm_plugin.c
484952
@@ -204,7 +204,7 @@ static snd_pcm_sframes_t snd_pcm_plugin_rewindable(snd_pcm_t *pcm)
484952
 snd_pcm_sframes_t snd_pcm_plugin_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
484952
 {
484952
 	snd_pcm_plugin_t *plugin = pcm->private_data;
484952
-	snd_pcm_sframes_t n = snd_pcm_mmap_hw_avail(pcm);
484952
+	snd_pcm_sframes_t n = snd_pcm_plugin_rewindable(pcm);
484952
 	snd_pcm_sframes_t sframes;
484952
 
484952
 	if ((snd_pcm_uframes_t)n < frames)
484952
@@ -232,7 +232,7 @@ static snd_pcm_sframes_t snd_pcm_plugin_forwardable(snd_pcm_t *pcm)
484952
 snd_pcm_sframes_t snd_pcm_plugin_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
484952
 {
484952
 	snd_pcm_plugin_t *plugin = pcm->private_data;
484952
-	snd_pcm_sframes_t n = snd_pcm_mmap_avail(pcm);
484952
+	snd_pcm_sframes_t n = snd_pcm_plugin_forwardable(pcm);
484952
 	snd_pcm_sframes_t sframes;
484952
 
484952
 	if ((snd_pcm_uframes_t)n < frames)
484952
-- 
484952
1.9.3
484952
484952
484952
From 78c804fc9348e4c29f1c77dd4b6ad586393aa628 Mon Sep 17 00:00:00 2001
484952
From: "Alexander E. Patrakov" <patrakov@gmail.com>
484952
Date: Sun, 14 Sep 2014 00:30:15 +0600
484952
Subject: [PATCH 27/35] pcm: handle negative values from snd_pcm_mmap_hw_avail
484952
484952
Such negative values can happen when an underrun happens and xrun
484952
detection is disabled. Another situation is if the device updated the
484952
pointer before alsa-lib has a chance to detect the xrun.
484952
484952
The problem is that these negative values could propagate to the
484952
snd_pcm_rewindable return value, where it is specified that negative
484952
returns must be interpreted as error codes and not as negative amount of
484952
samples.
484952
484952
Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
484952
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
484952
---
484952
 src/pcm/pcm_dmix.c   |  2 +-
484952
 src/pcm/pcm_dshare.c |  4 +---
484952
 src/pcm/pcm_hw.c     |  2 +-
484952
 src/pcm/pcm_ioplug.c |  2 +-
484952
 src/pcm/pcm_local.h  | 18 ++++++++++++++++++
484952
 src/pcm/pcm_plugin.c |  2 +-
484952
 6 files changed, 23 insertions(+), 7 deletions(-)
484952
484952
diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c
484952
index ffde12a..babde6a 100644
484952
--- a/src/pcm/pcm_dmix.c
484952
+++ b/src/pcm/pcm_dmix.c
484952
@@ -661,7 +661,7 @@ static int snd_pcm_dmix_pause(snd_pcm_t *pcm ATTRIBUTE_UNUSED, int enable ATTRIB
484952
 
484952
 static snd_pcm_sframes_t snd_pcm_dmix_rewindable(snd_pcm_t *pcm)
484952
 {
484952
-	return snd_pcm_mmap_hw_avail(pcm);
484952
+	return snd_pcm_mmap_playback_hw_rewindable(pcm);
484952
 }
484952
 
484952
 static snd_pcm_sframes_t snd_pcm_dmix_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
484952
diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c
484952
index f1a1a1d..020e6f7 100644
484952
--- a/src/pcm/pcm_dshare.c
484952
+++ b/src/pcm/pcm_dshare.c
484952
@@ -412,7 +412,7 @@ static int snd_pcm_dshare_pause(snd_pcm_t *pcm ATTRIBUTE_UNUSED, int enable ATTR
484952
 
484952
 static snd_pcm_sframes_t snd_pcm_dshare_rewindable(snd_pcm_t *pcm)
484952
 {
484952
-	return snd_pcm_mmap_playback_hw_avail(pcm);
484952
+	return snd_pcm_mmap_playback_hw_rewindable(pcm);
484952
 }
484952
 
484952
 static snd_pcm_sframes_t snd_pcm_dshare_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
484952
@@ -420,8 +420,6 @@ static snd_pcm_sframes_t snd_pcm_dshare_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t
484952
 	snd_pcm_sframes_t avail;
484952
 
484952
 	avail = snd_pcm_dshare_rewindable(pcm);
484952
-	if (avail < 0)
484952
-		return 0;
484952
 	if (frames > (snd_pcm_uframes_t)avail)
484952
 		frames = avail;
484952
 	snd_pcm_mmap_appl_backward(pcm, frames);
484952
diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c
484952
index 74cff67..c34b766 100644
484952
--- a/src/pcm/pcm_hw.c
484952
+++ b/src/pcm/pcm_hw.c
484952
@@ -659,7 +659,7 @@ static int snd_pcm_hw_pause(snd_pcm_t *pcm, int enable)
484952
 
484952
 static snd_pcm_sframes_t snd_pcm_hw_rewindable(snd_pcm_t *pcm)
484952
 {
484952
-	return snd_pcm_mmap_hw_avail(pcm);
484952
+	return snd_pcm_mmap_hw_rewindable(pcm);
484952
 }
484952
 
484952
 static snd_pcm_sframes_t snd_pcm_hw_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
484952
diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c
484952
index 85a8891..fe9347c 100644
484952
--- a/src/pcm/pcm_ioplug.c
484952
+++ b/src/pcm/pcm_ioplug.c
484952
@@ -503,7 +503,7 @@ static int snd_pcm_ioplug_pause(snd_pcm_t *pcm, int enable)
484952
 
484952
 static snd_pcm_sframes_t snd_pcm_ioplug_rewindable(snd_pcm_t *pcm)
484952
 {
484952
-	return snd_pcm_mmap_hw_avail(pcm);
484952
+	return snd_pcm_mmap_hw_rewindable(pcm);
484952
 }
484952
 
484952
 static snd_pcm_sframes_t snd_pcm_ioplug_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
484952
diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h
484952
index 74ebd60..394505f 100644
484952
--- a/src/pcm/pcm_local.h
484952
+++ b/src/pcm/pcm_local.h
484952
@@ -464,6 +464,24 @@ static inline snd_pcm_sframes_t snd_pcm_mmap_hw_avail(snd_pcm_t *pcm)
484952
 	return pcm->buffer_size - snd_pcm_mmap_avail(pcm);
484952
 }
484952
 
484952
+static inline snd_pcm_sframes_t snd_pcm_mmap_playback_hw_rewindable(snd_pcm_t *pcm)
484952
+{
484952
+	snd_pcm_sframes_t ret = snd_pcm_mmap_playback_hw_avail(pcm);
484952
+	return (ret >= 0) ? ret : 0;
484952
+}
484952
+
484952
+static inline snd_pcm_sframes_t snd_pcm_mmap_capture_hw_rewindable(snd_pcm_t *pcm)
484952
+{
484952
+	snd_pcm_sframes_t ret = snd_pcm_mmap_capture_hw_avail(pcm);
484952
+	return (ret >= 0) ? ret : 0;
484952
+}
484952
+
484952
+static inline snd_pcm_uframes_t snd_pcm_mmap_hw_rewindable(snd_pcm_t *pcm)
484952
+{
484952
+	snd_pcm_sframes_t ret = snd_pcm_mmap_hw_avail(pcm);
484952
+	return (ret >= 0) ? ret : 0;
484952
+}
484952
+
484952
 static inline const snd_pcm_channel_area_t *snd_pcm_mmap_areas(snd_pcm_t *pcm)
484952
 {
484952
 	if (pcm->stopped_areas &&
484952
diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
484952
index a607ccf..c19e2f1 100644
484952
--- a/src/pcm/pcm_plugin.c
484952
+++ b/src/pcm/pcm_plugin.c
484952
@@ -198,7 +198,7 @@ static int snd_pcm_plugin_reset(snd_pcm_t *pcm)
484952
 
484952
 static snd_pcm_sframes_t snd_pcm_plugin_rewindable(snd_pcm_t *pcm)
484952
 {
484952
-	return snd_pcm_mmap_hw_avail(pcm);
484952
+	return snd_pcm_mmap_hw_rewindable(pcm);
484952
 }
484952
 
484952
 snd_pcm_sframes_t snd_pcm_plugin_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
484952
-- 
484952
1.9.3
484952
484952
484952
From 0889e9470667dd68d5a0ce47a10a8c6d61b7bc79 Mon Sep 17 00:00:00 2001
484952
From: "Alexander E. Patrakov" <patrakov@gmail.com>
484952
Date: Sun, 14 Sep 2014 00:30:16 +0600
484952
Subject: [PATCH 28/35] pcm, rate: use the snd_pcm_mmap_hw_avail function
484952
484952
instead of the open-coded equivalent
484952
484952
Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
484952
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
484952
---
484952
 src/pcm/pcm_rate.c | 5 +----
484952
 1 file changed, 1 insertion(+), 4 deletions(-)
484952
484952
diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c
484952
index 5e811bb..b436a8e 100644
484952
--- a/src/pcm/pcm_rate.c
484952
+++ b/src/pcm/pcm_rate.c
484952
@@ -593,10 +593,7 @@ static int snd_pcm_rate_hwsync(snd_pcm_t *pcm)
484952
 static int snd_pcm_rate_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
484952
 {
484952
 	snd_pcm_rate_hwsync(pcm);
484952
-	if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
484952
-		*delayp = snd_pcm_mmap_playback_hw_avail(pcm);
484952
-	else
484952
-		*delayp = snd_pcm_mmap_capture_hw_avail(pcm);
484952
+	*delayp = snd_pcm_mmap_hw_avail(pcm);
484952
 	return 0;
484952
 }
484952
 
484952
-- 
484952
1.9.3
484952
484952
484952
From 4fafa468d4bb4618cfde7183f820d8fdd373dcb1 Mon Sep 17 00:00:00 2001
484952
From: "Alexander E. Patrakov" <patrakov@gmail.com>
484952
Date: Sun, 14 Sep 2014 00:30:17 +0600
484952
Subject: [PATCH 29/35] pcm, null: use the snd_pcm_mmap_avail function
484952
484952
instead of the open-coded equivalent
484952
484952
Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
484952
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
484952
---
484952
 src/pcm/pcm_null.c | 5 +----
484952
 1 file changed, 1 insertion(+), 4 deletions(-)
484952
484952
diff --git a/src/pcm/pcm_null.c b/src/pcm/pcm_null.c
484952
index f11a102..0529820 100644
484952
--- a/src/pcm/pcm_null.c
484952
+++ b/src/pcm/pcm_null.c
484952
@@ -86,10 +86,7 @@ static snd_pcm_sframes_t snd_pcm_null_avail_update(snd_pcm_t *pcm)
484952
         if (null->state == SND_PCM_STATE_PREPARED) {
484952
                 /* it is required to return the correct avail count for */
484952
                 /* the prepared stream, otherwise the start is not called */
484952
-                if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
484952
-                        return snd_pcm_mmap_playback_avail(pcm);
484952
-                else
484952
-                        return snd_pcm_mmap_capture_avail(pcm);
484952
+                return snd_pcm_mmap_avail(pcm);
484952
         }
484952
 	return pcm->buffer_size;
484952
 }
484952
-- 
484952
1.9.3
484952
484952
484952
From ff9d213ff80f6fe0456565d4f524366443217174 Mon Sep 17 00:00:00 2001
484952
From: "Alexander E. Patrakov" <patrakov@gmail.com>
484952
Date: Sun, 14 Sep 2014 00:30:18 +0600
484952
Subject: [PATCH 30/35] rate: handle negative values from
484952
 snd_pcm_mmap_playback_hw_avail
484952
484952
Such negative returns are possible during an underrun if xrun detection
484952
is disabled.
484952
484952
So, don't store the result in an unsigned variable (where it will
484952
overflow), and postpone the trigger in such case, too.
484952
484952
Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
484952
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
484952
---
484952
 src/pcm/pcm_rate.c | 4 ++--
484952
 1 file changed, 2 insertions(+), 2 deletions(-)
484952
484952
diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c
484952
index b436a8e..736d558 100644
484952
--- a/src/pcm/pcm_rate.c
484952
+++ b/src/pcm/pcm_rate.c
484952
@@ -1058,7 +1058,7 @@ static snd_pcm_state_t snd_pcm_rate_state(snd_pcm_t *pcm)
484952
 static int snd_pcm_rate_start(snd_pcm_t *pcm)
484952
 {
484952
 	snd_pcm_rate_t *rate = pcm->private_data;
484952
-	snd_pcm_uframes_t avail;
484952
+	snd_pcm_sframes_t avail;
484952
 		
484952
 	if (pcm->stream == SND_PCM_STREAM_CAPTURE)
484952
 		return snd_pcm_start(rate->gen.slave);
484952
@@ -1069,7 +1069,7 @@ static int snd_pcm_rate_start(snd_pcm_t *pcm)
484952
 	gettimestamp(&rate->trigger_tstamp, pcm->tstamp_type);
484952
 
484952
 	avail = snd_pcm_mmap_playback_hw_avail(rate->gen.slave);
484952
-	if (avail == 0) {
484952
+	if (avail <= 0) {
484952
 		/* postpone the trigger since we have no data committed yet */
484952
 		rate->start_pending = 1;
484952
 		return 0;
484952
-- 
484952
1.9.3
484952
484952
484952
From e5e1af83881e4dbe20749a314703db7d0fd091c7 Mon Sep 17 00:00:00 2001
484952
From: "Alexander E. Patrakov" <patrakov@gmail.com>
484952
Date: Sun, 14 Sep 2014 00:30:19 +0600
484952
Subject: [PATCH 31/35] dsnoop: rewindable and forwardable logic was swapped
484952
484952
Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
484952
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
484952
---
484952
 src/pcm/pcm_dsnoop.c | 6 ++----
484952
 1 file changed, 2 insertions(+), 4 deletions(-)
484952
484952
diff --git a/src/pcm/pcm_dsnoop.c b/src/pcm/pcm_dsnoop.c
484952
index e56e402..8333eef 100644
484952
--- a/src/pcm/pcm_dsnoop.c
484952
+++ b/src/pcm/pcm_dsnoop.c
484952
@@ -335,7 +335,7 @@ static int snd_pcm_dsnoop_pause(snd_pcm_t *pcm ATTRIBUTE_UNUSED, int enable ATTR
484952
 
484952
 static snd_pcm_sframes_t snd_pcm_dsnoop_rewindable(snd_pcm_t *pcm)
484952
 {
484952
-	return snd_pcm_mmap_capture_avail(pcm);
484952
+	return snd_pcm_mmap_capture_hw_avail(pcm);
484952
 }
484952
 
484952
 static snd_pcm_sframes_t snd_pcm_dsnoop_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
484952
@@ -351,7 +351,7 @@ static snd_pcm_sframes_t snd_pcm_dsnoop_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t
484952
 
484952
 static snd_pcm_sframes_t snd_pcm_dsnoop_forwardable(snd_pcm_t *pcm)
484952
 {
484952
-	return snd_pcm_mmap_capture_hw_avail(pcm);
484952
+	return snd_pcm_mmap_capture_avail(pcm);
484952
 }
484952
 
484952
 static snd_pcm_sframes_t snd_pcm_dsnoop_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
484952
@@ -359,8 +359,6 @@ static snd_pcm_sframes_t snd_pcm_dsnoop_forward(snd_pcm_t *pcm, snd_pcm_uframes_
484952
 	snd_pcm_sframes_t avail;
484952
 
484952
 	avail = snd_pcm_dsnoop_forwardable(pcm);
484952
-	if (avail < 0)
484952
-		return 0;
484952
 	if (frames > (snd_pcm_uframes_t)avail)
484952
 		frames = avail;
484952
 	snd_pcm_mmap_appl_forward(pcm, frames);
484952
-- 
484952
1.9.3
484952
484952
484952
From 650b8c975cd5c3f7dca6e78e74db587b57bcdfd8 Mon Sep 17 00:00:00 2001
484952
From: Jaroslav Kysela <perex@perex.cz>
484952
Date: Tue, 16 Sep 2014 09:00:39 +0200
484952
Subject: [PATCH 35/35] pcm route: Fix the bad condition (always false)
484952
484952
---
484952
 src/pcm/pcm_route.c | 2 +-
484952
 1 file changed, 1 insertion(+), 1 deletion(-)
484952
484952
diff --git a/src/pcm/pcm_route.c b/src/pcm/pcm_route.c
484952
index e7de9b5..2a437e8 100644
484952
--- a/src/pcm/pcm_route.c
484952
+++ b/src/pcm/pcm_route.c
484952
@@ -1147,7 +1147,7 @@ static int _snd_pcm_route_load_ttable(snd_config_t *tt, snd_pcm_route_ttable_ent
484952
 		snd_config_iterator_t j, jnext;
484952
 		long cchannel;
484952
 		const char *id;
484952
-		if (!snd_config_get_id(in, &id) < 0)
484952
+		if (snd_config_get_id(in, &id) < 0)
484952
 			continue;
484952
 		err = safe_strtol(id, &cchannel);
484952
 		if (err < 0 || 
484952
-- 
484952
1.9.3
484952