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 08/12] pcm: hw: add a helper function to request hwsync without side-effects
Date: Fri, 30 Jun 2017 08:58:24 +0900	[thread overview]
Message-ID: <20170629235828.18076-9-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <20170629235828.18076-1-o-takashi@sakamocchi.jp>

SNDRV_PCM_IOCTL_SYNC_PTR command for ioctl(2) with
SNDRV_PCM_SYNC_PTR_HWSYNC flag has an effect to update hw_ptr.
This is an alternative of SNDRV_PCM_IOCTL_HWSYNC but caller can get
current status simultaneously.

This commit adds a helper function just to issue hwsync. To avoid
side-effect to change appl_ptr and avail_min, this commit uses
SNDRV_PCM_SYNC_PTR_APPL and SNDRV_PCM_SYNC_PTR_AVAIL_MIN flags.

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

diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c
index c6abf170..43c37b83 100644
--- a/src/pcm/pcm_hw.c
+++ b/src/pcm/pcm_hw.c
@@ -151,6 +151,21 @@ static int sync_ptr(snd_pcm_hw_t *hw, unsigned int flags)
 	return 0;
 }
 
+static int request_hwsync(snd_pcm_hw_t *hw)
+{
+	if (!hw->mmap_status_fallbacked)
+		return 0;
+
+	/*
+	 * Query both of control/status data to avoid unexpected change of
+	 * control data in kernel space.
+	 */
+	return sync_ptr1(hw,
+			 SNDRV_PCM_SYNC_PTR_HWSYNC |
+			 SNDRV_PCM_SYNC_PTR_APPL |
+			 SNDRV_PCM_SYNC_PTR_AVAIL_MIN);
+}
+
 static int query_state(snd_pcm_hw_t *hw)
 {
 	if (!hw->mmap_status_fallbacked)
@@ -579,8 +594,8 @@ static int snd_pcm_hw_hwsync(snd_pcm_t *pcm)
 	snd_pcm_hw_t *hw = pcm->private_data;
 	int fd = hw->fd, err;
 	if (SNDRV_PROTOCOL_VERSION(2, 0, 3) <= hw->version) {
-		if (hw->sync_ptr) {
-			err = sync_ptr1(hw, SNDRV_PCM_SYNC_PTR_HWSYNC);
+		if (hw->mmap_status_fallbacked) {
+			err = request_hwsync(hw);
 			if (err < 0)
 				return err;
 		} else {
-- 
2.11.0

  parent reply	other threads:[~2017-06-29 23:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-29 23:58 [PATCH alsa-lib 00/12] pcm: hw: optimization for v2.0.14 of PCM protocol/interface Takashi Sakamoto
2017-06-29 23:58 ` [PATCH alsa-lib 01/12] pcm: hw: fix to initialize function local variable Takashi Sakamoto
2017-06-29 23:58 ` [PATCH alsa-lib 02/12] pcm: hw: add a helper function just to query status/control data of PCM substream Takashi Sakamoto
2017-06-29 23:58 ` [PATCH alsa-lib 03/12] pcm: hw: use heler function to query status/control data after reading/writing PCM frames Takashi Sakamoto
2017-06-29 23:58 ` [PATCH alsa-lib 04/12] pcm: hw: use helper function to query status/control data after HW_PARAMS call Takashi Sakamoto
2017-06-29 23:58 ` [PATCH alsa-lib 05/12] pcm: hw: use helper function to query status/control data after PREPARE/RESET call Takashi Sakamoto
2017-06-29 23:58 ` [PATCH alsa-lib 06/12] pcm: hw: use helper function to query status/control data after REWIND/FORWARD call Takashi Sakamoto
2017-06-29 23:58 ` [PATCH alsa-lib 07/12] pcm: hw: use helper function to query status/control data for calculation of available space on PCM buffer Takashi Sakamoto
2017-06-29 23:58 ` Takashi Sakamoto [this message]
2017-06-29 23:58 ` [PATCH alsa-lib 09/12] pcm: hw: add a helper function to issue appl_ptr without sub-effects Takashi Sakamoto
2017-06-29 23:58 ` [PATCH alsa-lib 10/12] pcm: hw: add a helper function to issue avail_min " Takashi Sakamoto
2017-06-29 23:58 ` [PATCH alsa-lib 11/12] pcm: hw: remove superfluous code to call of SNDRV_PCM_IOCTL_SYNC_PTR in snd_pcm_hw_forward() Takashi Sakamoto
2017-06-29 23:58 ` [PATCH alsa-lib 12/12] pcm: hw: minor refactoring for initialization of control data Takashi Sakamoto
2017-06-30  6:43 ` [PATCH alsa-lib 00/12] pcm: hw: optimization for v2.0.14 of PCM protocol/interface Takashi Sakamoto

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=20170629235828.18076-9-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.