diff mbox series

[RFC,2/4] ALSA: core: Allow polling for detection

Message ID 20241016130228.1013227-3-amadeuszx.slawinski@linux.intel.com (mailing list archive)
State Superseded
Headers show
Series Add support for detection | expand

Commit Message

Amadeusz Sławiński Oct. 16, 2024, 1:02 p.m. UTC
In order for userspace to wait for detection event to happen, there
needs to be possibility to wait in some way. Add API allowing to poll
for event when stream is in detection state.

Signed-off-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
---
 include/sound/pcm.h     |  4 ++++
 sound/core/pcm_native.c | 12 ++++++++++++
 2 files changed, 16 insertions(+)
diff mbox series

Patch

diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index f06ef7c718733..28df5bc5c131c 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -448,6 +448,9 @@  struct snd_pcm_runtime {
 	struct snd_pcm_audio_tstamp_report audio_tstamp_report;
 	struct timespec64 driver_tstamp;
 
+	/* -- detection -- */
+	unsigned int detected:1;	/* detection was triggered */
+
 #if IS_ENABLED(CONFIG_SND_PCM_OSS)
 	/* -- OSS things -- */
 	struct snd_pcm_oss_runtime oss;
@@ -592,6 +595,7 @@  int snd_pcm_start(struct snd_pcm_substream *substream);
 int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t status);
 int snd_pcm_drain_done(struct snd_pcm_substream *substream);
 int snd_pcm_stop_xrun(struct snd_pcm_substream *substream);
+void snd_pcm_detected(struct snd_pcm_substream *substream);
 #ifdef CONFIG_PM
 int snd_pcm_suspend_all(struct snd_pcm *pcm);
 #else
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 4fe1d2f41149c..c024eb0ed74ff 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3662,6 +3662,14 @@  static ssize_t snd_pcm_writev(struct kiocb *iocb, struct iov_iter *from)
 	return result;
 }
 
+void snd_pcm_detected(struct snd_pcm_substream *substream)
+{
+	substream->runtime->detected = 1;
+
+	wake_up(&substream->runtime->sleep);
+}
+EXPORT_SYMBOL_GPL(snd_pcm_detected);
+
 static __poll_t snd_pcm_poll(struct file *file, poll_table *wait)
 {
 	struct snd_pcm_file *pcm_file;
@@ -3690,6 +3698,10 @@  static __poll_t snd_pcm_poll(struct file *file, poll_table *wait)
 	guard(pcm_stream_lock_irq)(substream);
 	avail = snd_pcm_avail(substream);
 	switch (runtime->state) {
+	case SNDRV_PCM_STATE_DETECTING:
+		if (runtime->detected)
+			mask = ok;
+		break;
 	case SNDRV_PCM_STATE_RUNNING:
 	case SNDRV_PCM_STATE_PREPARED:
 	case SNDRV_PCM_STATE_PAUSED: