File 0038-dmix-plugin-fix-drain-for-nonblock-mode.patch of Package alsa.openSUSE_Leap_42.2_Update

From fdc898d41135b26772d0fffe07e9eb0de6597125 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Mon, 20 Mar 2017 08:34:33 +0100
Subject: [PATCH 38/43] dmix plugin: fix drain for nonblock mode

---
 src/pcm/pcm_dmix.c |   24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

--- a/src/pcm/pcm_dmix.c
+++ b/src/pcm/pcm_dmix.c
@@ -628,7 +628,7 @@ static int __snd_pcm_dmix_drain(snd_pcm_
 {
 	snd_pcm_direct_t *dmix = pcm->private_data;
 	snd_pcm_uframes_t stop_threshold;
-	int err;
+	int err = 0;
 
 	switch (snd_pcm_state(dmix->spcm)) {
 	case SND_PCM_STATE_SUSPENDED:
@@ -639,8 +639,6 @@ static int __snd_pcm_dmix_drain(snd_pcm_
 
 	if (dmix->state == SND_PCM_STATE_OPEN)
 		return -EBADFD;
-	if (pcm->mode & SND_PCM_NONBLOCK)
-		return -EAGAIN;
 	if (dmix->state == SND_PCM_STATE_PREPARED) {
 		if (snd_pcm_mmap_playback_hw_avail(pcm) > 0)
 			snd_pcm_dmix_start(pcm);
@@ -663,23 +661,33 @@ static int __snd_pcm_dmix_drain(snd_pcm_
 		err = snd_pcm_dmix_sync_ptr(pcm);
 		if (err < 0) {
 			snd_pcm_dmix_drop(pcm);
-			return err;
+			goto done;
 		}
 		if (dmix->state == SND_PCM_STATE_DRAINING) {
 			snd_pcm_dmix_sync_area(pcm);
-			snd_pcm_wait_nocheck(pcm, -1);
-			snd_pcm_direct_clear_timer_queue(dmix); /* force poll to wait */
+			if ((pcm->mode & SND_PCM_NONBLOCK) == 0) {
+				snd_pcm_wait_nocheck(pcm, -1);
+				snd_pcm_direct_clear_timer_queue(dmix); /* force poll to wait */
+			}
 
 			switch (snd_pcm_state(dmix->spcm)) {
 			case SND_PCM_STATE_SUSPENDED:
-				return -ESTRPIPE;
+				err = -ESTRPIPE;
+				goto done;
+			case SND_PCM_STATE_DRAINING:
+				if (pcm->mode & SND_PCM_NONBLOCK) {
+					err = -EAGAIN;
+					goto done;
+				}
+				break;
 			default:
 				break;
 			}
 		}
 	} while (dmix->state == SND_PCM_STATE_DRAINING);
+done:
 	pcm->stop_threshold = stop_threshold;
-	return 0;
+	return err;
 }
 
 static int snd_pcm_dmix_drain(snd_pcm_t *pcm)
openSUSE Build Service is sponsored by