All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: tiwai@suse.de
Cc: alsa-devel@alsa-project.org
Subject: [PATCH alsa-lib v2 4/6] pcm: hw: add a helper function to issue appl_ptr without side-effects
Date: Fri, 30 Jun 2017 20:37:27 +0900	[thread overview]
Message-ID: <20170630113729.13656-5-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <20170630113729.13656-1-o-takashi@sakamocchi.jp>

After starting, PCM substream shift its state to running and applications
can move appl_ptr by several ways. When status and control data of runtime
of the PCM substream is not mapped, the applications should issue appl_ptr
to kernel land. In this case, when any PCM frames is handled by mmap
operation, the applications should issue appl_ptr to update.

This commit adds a helper function for this purpose. To avoid unexpected
change of avail_min, this commit uses a flag just to update appl_ptr.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/pcm/pcm_hw.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c
index 8455baaf..51512306 100644
--- a/src/pcm/pcm_hw.c
+++ b/src/pcm/pcm_hw.c
@@ -151,6 +151,15 @@ static int sync_ptr(snd_pcm_hw_t *hw, unsigned int flags)
 	return 0;
 }
 
+static int issue_applptr(snd_pcm_hw_t *hw)
+{
+	if (!hw->mmap_control_fallbacked)
+		return 0;
+
+	/* Avoid unexpected change of avail_min in kernel space. */
+	return sync_ptr1(hw, SNDRV_PCM_SYNC_PTR_AVAIL_MIN);
+}
+
 static int request_hwsync(snd_pcm_hw_t *hw)
 {
 	if (!hw->mmap_status_fallbacked)
@@ -667,7 +676,7 @@ static int snd_pcm_hw_start(snd_pcm_t *pcm)
 	assert(pcm->stream != SND_PCM_STREAM_PLAYBACK ||
 	       snd_pcm_mmap_playback_hw_avail(pcm) > 0);
 #endif
-	sync_ptr(hw, 0);
+	issue_applptr(hw);
 	if (ioctl(hw->fd, SNDRV_PCM_IOCTL_START) < 0) {
 		err = -errno;
 		SYSMSG("SNDRV_PCM_IOCTL_START failed (%i)", err);
@@ -1081,7 +1090,7 @@ static snd_pcm_sframes_t snd_pcm_hw_mmap_commit(snd_pcm_t *pcm,
 	snd_pcm_hw_t *hw = pcm->private_data;
 
 	snd_pcm_mmap_appl_forward(pcm, size);
-	sync_ptr(hw, 0);
+	issue_applptr(hw);
 #ifdef DEBUG_MMAP
 	fprintf(stderr, "appl_forward: hw_ptr = %li, appl_ptr = %li, size = %li\n", *pcm->hw.ptr, *pcm->appl.ptr, size);
 #endif
-- 
2.11.0

  parent reply	other threads:[~2017-06-30 11:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-30 11:37 [PATCH alsa-lib v2 0/6] pcm: hw: optimization for v2.0.14 of PCM protocol/interface Takashi Sakamoto
2017-06-30 11:37 ` [PATCH alsa-lib v2 1/6] pcm: hw: add a helper function to query status/control data Takashi Sakamoto
2017-06-30 11:37 ` [PATCH alsa-lib v2 2/6] pcm: hw: add a helper function just to query status data Takashi Sakamoto
2017-06-30 11:37 ` [PATCH alsa-lib v2 3/6] pcm: hw: add a helper function to request hwsync without side-effects Takashi Sakamoto
2017-06-30 11:37 ` Takashi Sakamoto [this message]
2017-06-30 11:37 ` [PATCH alsa-lib v2 5/6] pcm: hw: add a helper function to issue avail_min " Takashi Sakamoto
2017-06-30 11:37 ` [PATCH alsa-lib v2 6/6] pcm: hw: remove superfluous code to call of SNDRV_PCM_IOCTL_SYNC_PTR in snd_pcm_hw_forward() Takashi Sakamoto
2017-06-30 14:43 ` [PATCH alsa-lib v2 0/6] pcm: hw: optimization for v2.0.14 of PCM protocol/interface Takashi Iwai

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=20170630113729.13656-5-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --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.