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: [alsa-lib][RFC][PATCH 5/9] pcm: add a helper function to query hwptr
Date: Thu, 22 Jun 2017 23:43:30 +0900	[thread overview]
Message-ID: <20170622144334.1306-6-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <20170622144334.1306-1-o-takashi@sakamocchi.jp>

Usual PCM drivers in kernel land can respond applications' request about
recent hardware-side position of data transmission. In most cases, the
request is issued by ioctl(2) with SNDRV_PCM_IOCTL_HWSYNC, then the
position is shared via mapped page frame. However, when failing the
mapping, applications use SNDRV_PCM_IOCTL_SYNC_PTR command to do the
same thing as a fallback.

This commit adds a helper function to unify the relevant codes for
readability. Original implementation has a side effect to issue current
application-side position and the size of avail_min, thus has a side
effect. This commit adds some flags to purge the effect.

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

diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c
index 23211cba..e3a4ee7c 100644
--- a/src/pcm/pcm_hw.c
+++ b/src/pcm/pcm_hw.c
@@ -160,6 +160,17 @@ static int sync_applptr(snd_pcm_hw_t *hw)
 	return sync_ptr1(hw, &ptr, 0);
 }
 
+static int query_hwptr(snd_pcm_hw_t *hw)
+{
+	if (!hw->mmap_status_fallbacked)
+		return 0;
+
+	return sync_ptr1(hw, hw->sync_ptr,
+			 SNDRV_PCM_SYNC_PTR_HWSYNC |
+			 SNDRV_PCM_SYNC_PTR_APPL |
+			 SNDRV_PCM_SYNC_PTR_AVAIL_MIN);
+}
+
 static int query_status(snd_pcm_hw_t *hw)
 {
 	if (!hw->mmap_status_fallbacked)
@@ -585,8 +596,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, hw->sync_ptr, SNDRV_PCM_SYNC_PTR_HWSYNC);
+		if (hw->mmap_status_fallbacked) {
+			err = query_hwptr(hw);
 			if (err < 0)
 				return err;
 		} else {
@@ -735,7 +746,7 @@ static snd_pcm_sframes_t snd_pcm_hw_forward(snd_pcm_t *pcm, snd_pcm_uframes_t fr
 	} else {
 		snd_pcm_sframes_t avail;
 
-		err = sync_ptr(hw, SNDRV_PCM_SYNC_PTR_HWSYNC);
+		err = query_hwptr(hw);
 		if (err < 0)
 			return err;
 		switch (FAST_PCM_STATE(hw)) {
-- 
2.11.0

  parent reply	other threads:[~2017-06-22 14:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-22 14:43 [alsa-lib][RFC][PATCH 0/9] pcm: handle status/control mapping independently Takashi Sakamoto
2017-06-22 14:43 ` [alsa-lib][RFC][PATCH 1/9] pcm: obsolete 'mmap_emulation' parameter of snd_pcm_hw_open_fd() Takashi Sakamoto
2017-06-22 14:43 ` [alsa-lib][RFC][PATCH 2/9] pcm: minor code refactoring for ioctl call Takashi Sakamoto
2017-06-22 14:43 ` [alsa-lib][RFC][PATCH 3/9] pcm: handle status/control mapping independently Takashi Sakamoto
2017-06-22 14:43 ` [alsa-lib][RFC][PATCH 4/9] pcm: add a helper function to query status of PCM substream Takashi Sakamoto
2017-06-22 14:43 ` Takashi Sakamoto [this message]
2017-06-22 14:43 ` [alsa-lib][RFC][PATCH 6/9] pcm: add a helper function to query applptr Takashi Sakamoto
2017-06-22 14:43 ` [alsa-lib][RFC][PATCH 7/9] pcm: add a helper function to issue avail_min Takashi Sakamoto
2017-06-22 14:43 ` [alsa-lib][RFC][PATCH 8/9] pcm: add a helper function to issue applptr Takashi Sakamoto
2017-06-22 14:43 ` [alsa-lib][RFC][PATCH 9/9] pcm: code refactoring to use helper functions 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=20170622144334.1306-6-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.