Skip to contentSkip to conversation

add SNDRV_PCM_TRIGGER_DRAIN trigger

PATCH Applied [email protected] 2 participants 3 messages Dec 31, 2014 – Jan 1, 2015 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add SNDRV_PCM_TRIGGER_DRAIN trigger

From: Libin Yang <[email protected]>

Add SNDRV_PCM_TRIGGER_DRAIN trigger for pcm drain.

Some audio devices require notification of drain events in order to properly drain and shutdown an audio stream.

---
 include/sound/pcm.h         |  1 +
 include/uapi/sound/asound.h |  1 +
 sound/core/pcm_native.c     | 10 +++++++++-
 3 files changed, 11 insertions(+), 1 deletion(-)
include/sound/pcm.h +1 -0
index 3652c94..bf32cea 100644
@@ -106,6 +106,7 @@ struct snd_pcm_ops {
 #define SNDRV_PCM_TRIGGER_PAUSE_RELEASE	4
 #define SNDRV_PCM_TRIGGER_SUSPEND	5
 #define SNDRV_PCM_TRIGGER_RESUME	6
+#define SNDRV_PCM_TRIGGER_DRAIN		7
 
 #define SNDRV_PCM_POS_XRUN		((snd_pcm_uframes_t)-1)
 
include/uapi/sound/asound.h +1 -0
index 1f23cd6..0e88e7a 100644
@@ -268,6 +268,7 @@ typedef int __bitwise snd_pcm_subformat_t;
 #define SNDRV_PCM_INFO_SYNC_START	0x00400000	/* pcm support some kind of sync go */
 #define SNDRV_PCM_INFO_NO_PERIOD_WAKEUP	0x00800000	/* period wakeup can be disabled */
 #define SNDRV_PCM_INFO_HAS_WALL_CLOCK   0x01000000      /* has audio wall clock for audio/system time sync */
+#define SNDRV_PCM_INFO_DRAIN_TRIGGER	0x40000000		/* internal kernel flag - trigger in drain */
 #define SNDRV_PCM_INFO_FIFO_IN_FRAMES	0x80000000	/* internal kernel flag - FIFO size is in frames */
 
 typedef int __bitwise snd_pcm_state_t;
sound/core/pcm_native.c +9 -1
index 095d957..a5fe336 100644
@@ -420,7 +420,8 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
 
 	hw = &substream->runtime->hw;
 	if (!params->info) {
-		params->info = hw->info & ~SNDRV_PCM_INFO_FIFO_IN_FRAMES;
+		params->info = hw->info & ~(SNDRV_PCM_INFO_FIFO_IN_FRAMES |
+					  SNDRV_PCM_INFO_DRAIN_TRIGGER);
 		if (!hw_support_mmap(substream))
 			params->info &= ~(SNDRV_PCM_INFO_MMAP |
 					  SNDRV_PCM_INFO_MMAP_VALID);
@@ -1566,6 +1567,13 @@ static int snd_pcm_do_drain_init(struct snd_pcm_substream *substream, int state)
 			snd_pcm_post_stop(substream, new_state);
 		}
 	}
+
+	if (runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
+		substream->runtime->trigger_master == substream &&
+		(substream->runtime->hw.info & SNDRV_PCM_INFO_DRAIN_TRIGGER))
+		return substream->ops->trigger(substream,
+				SNDRV_PCM_TRIGGER_DRAIN);
+
 	return 0;
 }
 
Signature · 1 line
1.9.1
Applied
#1 lore raw

At Wed, 31 Dec 2014 22:09:54 +0800,

Quoted 9 lines · [email protected] wrote:

From: Libin Yang <[email protected]>

Add SNDRV_PCM_TRIGGER_DRAIN trigger for pcm drain.

Some audio devices require notification of drain events in order to properly drain and shutdown an audio stream.

Thanks, applied now with micro optimizations (replacing substream->runtime with runtime) and space alignment.

Takashi

Quoted 61 lines
---
 include/sound/pcm.h         |  1 +
 include/uapi/sound/asound.h |  1 +
 sound/core/pcm_native.c     | 10 +++++++++-
 3 files changed, 11 insertions(+), 1 deletion(-)
include/sound/pcm.h +1 -0
index 3652c94..bf32cea 100644
@@ -106,6 +106,7 @@ struct snd_pcm_ops {
 #define SNDRV_PCM_TRIGGER_PAUSE_RELEASE	4
 #define SNDRV_PCM_TRIGGER_SUSPEND	5
 #define SNDRV_PCM_TRIGGER_RESUME	6
+#define SNDRV_PCM_TRIGGER_DRAIN		7
 
 #define SNDRV_PCM_POS_XRUN		((snd_pcm_uframes_t)-1)
 
include/uapi/sound/asound.h +1 -0
index 1f23cd6..0e88e7a 100644
@@ -268,6 +268,7 @@ typedef int __bitwise snd_pcm_subformat_t;
 #define SNDRV_PCM_INFO_SYNC_START	0x00400000	/* pcm support some kind of sync go */
 #define SNDRV_PCM_INFO_NO_PERIOD_WAKEUP	0x00800000	/* period wakeup can be disabled */
 #define SNDRV_PCM_INFO_HAS_WALL_CLOCK   0x01000000      /* has audio wall clock for audio/system time sync */
+#define SNDRV_PCM_INFO_DRAIN_TRIGGER	0x40000000		/* internal kernel flag - trigger in drain */
 #define SNDRV_PCM_INFO_FIFO_IN_FRAMES	0x80000000	/* internal kernel flag - FIFO size is in frames */
 
 typedef int __bitwise snd_pcm_state_t;
sound/core/pcm_native.c +9 -1
index 095d957..a5fe336 100644
@@ -420,7 +420,8 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
 
 	hw = &substream->runtime->hw;
 	if (!params->info) {
-		params->info = hw->info & ~SNDRV_PCM_INFO_FIFO_IN_FRAMES;
+		params->info = hw->info & ~(SNDRV_PCM_INFO_FIFO_IN_FRAMES |
+					  SNDRV_PCM_INFO_DRAIN_TRIGGER);
 		if (!hw_support_mmap(substream))
 			params->info &= ~(SNDRV_PCM_INFO_MMAP |
 					  SNDRV_PCM_INFO_MMAP_VALID);
@@ -1566,6 +1567,13 @@ static int snd_pcm_do_drain_init(struct snd_pcm_substream *substream, int state)
 			snd_pcm_post_stop(substream, new_state);
 		}
 	}
+
+	if (runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
+		substream->runtime->trigger_master == substream &&
+		(substream->runtime->hw.info & SNDRV_PCM_INFO_DRAIN_TRIGGER))
+		return substream->ops->trigger(substream,
+				SNDRV_PCM_TRIGGER_DRAIN);
+
 	return 0;
 }
 
Signature · 1 line
1.9.1
#2 lore raw

Hi Takashi,

Quoted 14 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Thursday, January 01, 2015 12:18 AM
To: Yang, Libin
Cc: [email protected]; [email protected]; Jie, Yang
Subject: Re: [PATCH] [ALSA] add SNDRV_PCM_TRIGGER_DRAIN trigger

At Wed, 31 Dec 2014 22:09:54 +0800,

Quoted 5 lines · [email protected] wrote:

From: Libin Yang <[email protected]>

Add SNDRV_PCM_TRIGGER_DRAIN trigger for pcm drain.

Quoted 7 lines
Quoted 4 lines

Some audio devices require notification of drain events in order to properly drain and shutdown an audio stream.

Thanks, applied now with micro optimizations (replacing substream->runtime with runtime) and space alignment.

Thanks for help.

Quoted 74 lines

Takashi

Quoted 23 lines
---
 include/sound/pcm.h         |  1 +
 include/uapi/sound/asound.h |  1 +
 sound/core/pcm_native.c     | 10 +++++++++-
 3 files changed, 11 insertions(+), 1 deletion(-)
include/sound/pcm.h index renamed from include/sound/pcm.h +0 -0

3652c94..bf32cea 100644

include/sound/pcm.h +1 -0
@@ -106,6 +106,7 @@ struct snd_pcm_ops {
 #define SNDRV_PCM_TRIGGER_PAUSE_RELEASE	4
 #define SNDRV_PCM_TRIGGER_SUSPEND	5
 #define SNDRV_PCM_TRIGGER_RESUME	6
+#define SNDRV_PCM_TRIGGER_DRAIN		7
 
 #define SNDRV_PCM_POS_XRUN		((snd_pcm_uframes_t)-1)
 
include/uapi/sound/asound.h +0 -0
index 1f23cd6..0e88e7a 100644

include/uapi/sound/asound.h typedef int __bitwise snd_pcm_subformat_t; · line 268

Quoted 1 line
include/uapi/sound/asound.h +0 -0
@@ -268,6 +268,7 @@ typedef int __bitwise snd_pcm_subformat_t;
 #define SNDRV_PCM_INFO_SYNC_START	0x00400000	/* pcm

support some kind of sync go */

include/uapi/sound/asound.h typedef int __bitwise snd_pcm_subformat_t; · line 269

Quoted 1 line
include/uapi/sound/asound.h +0 -0
 #define SNDRV_PCM_INFO_NO_PERIOD_WAKEUP	0x00800000	/*

period wakeup can be disabled */

include/uapi/sound/asound.h typedef int __bitwise snd_pcm_subformat_t; · line 270

Quoted 1 line
include/uapi/sound/asound.h +0 -0
 #define SNDRV_PCM_INFO_HAS_WALL_CLOCK   0x01000000      /* has

audio wall clock for audio/system time sync */

include/uapi/sound/asound.h typedef int __bitwise snd_pcm_subformat_t; · line 271

Quoted 1 line
include/uapi/sound/asound.h +1 -0
+#define SNDRV_PCM_INFO_DRAIN_TRIGGER	0x40000000
	/* internal kernel flag - trigger in drain */

include/uapi/sound/asound.h typedef int __bitwise snd_pcm_subformat_t; · line 272

Quoted 1 line
include/uapi/sound/asound.h +0 -0
 #define SNDRV_PCM_INFO_FIFO_IN_FRAMES	0x80000000	/*

internal kernel flag - FIFO size is in frames */

sound/core/pcm_native.c int snd_pcm_hw_refine(struct

Quoted 7 lines
include/uapi/sound/asound.h +0 -0
 typedef int __bitwise snd_pcm_state_t; diff --git

a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 095d957..a5fe336 100644

sound/core/pcm_native.c +0 -0
@@ -420,7 +420,8 @@ int snd_pcm_hw_refine(struct

snd_pcm_substream

sound/core/pcm_native.c int snd_pcm_hw_refine(struct snd_pcm_substream *substream,

Quoted 5 lines
sound/core/pcm_native.c +0 -1
 *substream,
 
 	hw = &substream->runtime->hw;
 	if (!params->info) {
-		params->info = hw->info &

~SNDRV_PCM_INFO_FIFO_IN_FRAMES;

sound/core/pcm_native.c int snd_pcm_hw_refine(struct · line 424

Quoted 1 line
sound/core/pcm_native.c +1 -0
+		params->info = hw->info &

~(SNDRV_PCM_INFO_FIFO_IN_FRAMES |

sound/core/pcm_native.c int snd_pcm_hw_refine(struct · line 425

Quoted 1 line
sound/core/pcm_native.c +1 -0
+

SNDRV_PCM_INFO_DRAIN_TRIGGER);

sound/core/pcm_native.c static int snd_pcm_do_drain_init(struct

Quoted 4 lines
sound/core/pcm_native.c +0 -0
 		if (!hw_support_mmap(substream))
 			params->info &= ~(SNDRV_PCM_INFO_MMAP |
sound/core/pcm_native.c +0 -0
 					  SNDRV_PCM_INFO_MMAP_VALID);
@@ -1566,6 +1567,13 @@ static int snd_pcm_do_drain_init(struct

snd_pcm_substream *substream, int state)

sound/core/pcm_native.c static int snd_pcm_do_drain_init(struct snd_pcm_substream *substream, int state)

Quoted 7 lines
sound/core/pcm_native.c +4 -0
 			snd_pcm_post_stop(substream, new_state);
 		}
 	}
+
+	if (runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
+		substream->runtime->trigger_master == substream &&
+		(substream->runtime->hw.info &

SNDRV_PCM_INFO_DRAIN_TRIGGER))

Quoted 6 lines
sound/core/pcm_native.c +3 -0
+		return substream->ops->trigger(substream,
+				SNDRV_PCM_TRIGGER_DRAIN);
+
 	return 0;
 }
 
Quoted 3 lines
Quoted 3 lines

--
1.9.1

Regards,
Libin