From: Takashi Sakamoto Date: Fri, 30 Jun 2017 11:37:27 +0000 (+0900) Subject: pcm: hw: add a helper function to issue appl_ptr without side-effects X-Git-Tag: v1.1.5~25 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=de9fe69e40e6b705aeae9aa8d1408736d4a1e563;p=alsa-lib.git pcm: hw: add a helper function to issue appl_ptr without side-effects 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 Signed-off-by: Takashi Iwai --- 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