]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: hw: add a helper function to request hwsync without side-effects
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Fri, 30 Jun 2017 11:37:26 +0000 (20:37 +0900)
committerTakashi Iwai <tiwai@suse.de>
Fri, 30 Jun 2017 14:38:32 +0000 (16:38 +0200)
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>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/pcm/pcm_hw.c

index 38d975afef0aa3a31f8756789a044a4c06d13d28..8455baaf526184d9af3327f27aa86cfae0e624a2 100644 (file)
@@ -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_status_and_control_data(snd_pcm_hw_t *hw)
 {
        if (!hw->mmap_control_fallbacked)
@@ -593,8 +608,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 {