OSDN Git Service

pcm: hw: add a helper function to issue appl_ptr without side-effects
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Fri, 30 Jun 2017 11:37:27 +0000 (20:37 +0900)
committerTakashi Iwai <tiwai@suse.de>
Fri, 30 Jun 2017 14:38:40 +0000 (16:38 +0200)
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>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/pcm/pcm_hw.c

index 8455baa..5151230 100644 (file)
@@ -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