@@ -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
@@ -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:
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(+)