From: Joonho Lee <mynameisjune111@gmail.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: Takashi Iwai <tiwai@suse.com>, Jaroslav Kysela <perex@perex.cz>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-api@vger.kernel.org
Subject: [RFC PATCH v3 1/2] ALSA: pcm: allow capture reads while draining
Date: Thu, 15 Oct 2026 00:24:22 +0900 [thread overview]
Message-ID: <rfc-v3-core-capture-drain-1.cf2e307fcac34b6a@gmail.com> (raw)
In-Reply-To: <rfc-v3-core-capture-drain-0.cf2e307fcac34b6a@gmail.com>
Allow capture transfer calls in DRAINING so already captured tail frames
remain readable until drain completes.
Assisted-by: LLM
Signed-off-by: Joonho Lee <mynameisjune111@gmail.com>
---
sound/core/pcm_lib.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 4d665b4148d7..de952f639d3b 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -2208,13 +2208,17 @@ static int pcm_sanity_check(struct snd_pcm_substream *substream)
return 0;
}
-static int pcm_accessible_state(struct snd_pcm_runtime *runtime)
+static int pcm_accessible_state(struct snd_pcm_substream *substream)
{
+ struct snd_pcm_runtime *runtime = substream->runtime;
+
switch (runtime->state) {
case SNDRV_PCM_STATE_PREPARED:
case SNDRV_PCM_STATE_RUNNING:
case SNDRV_PCM_STATE_PAUSED:
return 0;
+ case SNDRV_PCM_STATE_DRAINING:
+ return substream->stream == SNDRV_PCM_STREAM_CAPTURE ? 0 : -EBADFD;
case SNDRV_PCM_STATE_XRUN:
return -EPIPE;
case SNDRV_PCM_STATE_SUSPENDED:
@@ -2320,7 +2324,7 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
nonblock = !!(substream->f_flags & O_NONBLOCK);
snd_pcm_stream_lock_irq(substream);
- err = pcm_accessible_state(runtime);
+ err = pcm_accessible_state(substream);
if (err < 0)
goto _end_unlock;
@@ -2388,7 +2392,7 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
atomic_dec(&runtime->buffer_accessing);
if (err < 0)
goto _end_unlock;
- err = pcm_accessible_state(runtime);
+ err = pcm_accessible_state(substream);
if (err < 0)
goto _end_unlock;
appl_ptr += frames;
next prev parent reply other threads:[~2026-10-14 15:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 3:30 [RFC PATCH 0/2] ALSA: pcm: preserve capture tail during drain Joonho Lee
2026-10-14 3:30 ` [RFC PATCH 1/2] ALSA: pcm: allow capture reads while draining Joonho Lee
2026-10-14 3:30 ` [RFC PATCH 2/2] ALSA: pcm: refresh capture pointers before drain Joonho Lee
2026-10-14 8:15 ` Takashi Iwai
2026-10-14 8:35 ` Takashi Iwai
2026-10-14 15:20 ` Joonho Lee
2026-10-14 15:24 ` [RFC PATCH v3 0/2] ALSA: pcm: preserve capture tail during drain Joonho Lee
2026-10-14 15:24 ` Joonho Lee [this message]
2026-10-14 15:24 ` [RFC PATCH v3 2/2] ALSA: pcm: refresh capture pointers in the drain action Joonho Lee
2026-10-14 15:33 ` [RFC PATCH 2/2] ALSA: pcm: refresh capture pointers before drain Takashi Iwai
2026-10-14 8:15 ` [RFC PATCH v2 0/2] ALSA: pcm: preserve capture tail during drain Joonho Lee
2026-10-14 8:15 ` [RFC PATCH v2 1/2] ALSA: pcm: allow capture reads while draining Joonho Lee
2026-10-14 8:15 ` [RFC PATCH v2 2/2] ALSA: pcm: refresh capture pointers before drain Joonho Lee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=rfc-v3-core-capture-drain-1.cf2e307fcac34b6a@gmail.com \
--to=mynameisjune111@gmail.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.