From: Takashi Iwai Date: Thu, 29 Mar 2018 07:18:00 +0000 (+0200) Subject: pcm: Skip avail_min check during draining X-Git-Tag: android-x86-9.0-r1~220 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=d3d42f60a6ba9e2684fe82ee311ef41e58e15921;p=android-x86%2Fexternal-alsa-lib.git pcm: Skip avail_min check during draining snd_pcm_wait() & co checks the current avail value and returns immediately if it satisfies <= avail_min condition. It's good in general except for one situation: draining. When the draining is being performed in the non-blocking mode, apps are supposed to wait via poll(), typically via snd_pcm_wait(). So this ends up with the busy loop because of the immediate return from snd_pcm_wait(). A simple workaround is to put the PCM state check and ignore the avail_min condition if it's DRAINING state. The equivalent check is found in the kernel xfer code, too. Signed-off-by: Takashi Iwai --- diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index ed47cb51..11aec805 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -2751,7 +2751,9 @@ int __snd_pcm_wait_in_lock(snd_pcm_t *pcm, int timeout) { int err; - if (!snd_pcm_may_wait_for_avail_min(pcm, snd_pcm_mmap_avail(pcm))) { + /* NOTE: avail_min check can be skipped during draining */ + if (__snd_pcm_state(pcm) != SND_PCM_STATE_DRAINING && + !snd_pcm_may_wait_for_avail_min(pcm, snd_pcm_mmap_avail(pcm))) { /* check more precisely */ err = pcm_state_to_error(__snd_pcm_state(pcm)); return err < 0 ? err : 1;