]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: hw: add a helper function to issue avail_min without side-effects
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Fri, 30 Jun 2017 11:37:28 +0000 (20:37 +0900)
committerTakashi Iwai <tiwai@suse.de>
Fri, 30 Jun 2017 14:39:11 +0000 (16:39 +0200)
At present, applications can change avail_min parameter of PCM substream
by two ways; via mapped control data, and by executing ioctl(2) with
SNDRV_PCM_IOCTL_SYNC_PTR. The former is available in a case that the
applications map the data successfully.

When utilizing alsa-lib API, the above is done by a call of
'snd_pcm_sw_params()' to hw PCM plugin. In current implementation, this
call has an side-effect to issue appl_ptr unexpectedly.

This commit adds a helper function to issue avail_min without the
side-effect.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/pcm/pcm_hw.c

index 5151230642025a0c726d8a69297f1515a90f1682..9c8fc3f6d81f88bc27e46fd88fb7770dbee2a83b 100644 (file)
@@ -151,6 +151,15 @@ static int sync_ptr(snd_pcm_hw_t *hw, unsigned int flags)
        return 0;
 }
 
+static int issue_avail_min(snd_pcm_hw_t *hw)
+{
+       if (!hw->mmap_control_fallbacked)
+               return 0;
+
+       /* Avoid unexpected change of applptr in kernel space. */
+       return sync_ptr1(hw, SNDRV_PCM_SYNC_PTR_APPL);
+}
+
 static int issue_applptr(snd_pcm_hw_t *hw)
 {
        if (!hw->mmap_control_fallbacked)
@@ -506,7 +515,7 @@ static int snd_pcm_hw_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t * params)
            params->silence_size == pcm->silence_size &&
            old_period_event == hw->period_event) {
                hw->mmap_control->avail_min = params->avail_min;
-               return sync_ptr(hw, 0);
+               return issue_avail_min(hw);
        }
        if (params->tstamp_type == SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW &&
            hw->version < SNDRV_PROTOCOL_VERSION(2, 0, 12)) {