File 0003-alsaloop-another-try-to-force-correct-formats-for-li.patch of Package alsa-utils

From 3801e25964070390c525b9f2c39913e6ea1eb864 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Tue, 8 Mar 2011 12:56:56 +0100
Subject: [PATCH 03/16] alsaloop: another try to force correct formats for
 libsamplerate

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
 alsaloop/pcmjob.c |   22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/alsaloop/pcmjob.c b/alsaloop/pcmjob.c
index 6b50cf0..bfac2d3 100644
--- a/alsaloop/pcmjob.c
+++ b/alsaloop/pcmjob.c
@@ -1358,11 +1358,11 @@ static void lhandle_start(struct loopback_handle *lhandle)
 	lhandle->total_queued = 0;
 }
 
-static void fix_format(struct loopback *loop)
+static void fix_format(struct loopback *loop, int force)
 {
 	snd_pcm_format_t format = loop->capt->format;
 
-	if (loop->sync != SYNC_TYPE_SAMPLERATE)
+	if (!force && loop->sync != SYNC_TYPE_SAMPLERATE)
 		return;
 	if (format == SND_PCM_FORMAT_S16 ||
 	    format == SND_PCM_FORMAT_S32)
@@ -1400,7 +1400,7 @@ int pcmjob_start(struct loopback *loop)
 		if (err < 0)
 			goto __error;
 		loop->play->format = loop->capt->format = err;
-		fix_format(loop);
+		fix_format(loop, 0);
 		err = get_rate(loop->capt);
 		if (err < 0)
 			goto __error;
@@ -1412,6 +1412,7 @@ int pcmjob_start(struct loopback *loop)
 	}
 	loop->reinit = 0;
 	loop->use_samplerate = 0;
+__again:
 	if (loop->latency_req) {
 		loop->latency_reqtime = frames_to_time(loop->play->rate_req,
 						       loop->latency_req);
@@ -1460,10 +1461,19 @@ int pcmjob_start(struct loopback *loop)
 			goto __error;
 		if ((err = init_handle(loop->capt, 1)) < 0)
 			goto __error;
-		if (loop->play->rate_req != loop->play->rate)
-			loop->use_samplerate = 1;
-		if (loop->capt->rate_req != loop->capt->rate)
+		if (loop->play->rate_req != loop->play->rate ||
+                    loop->capt->rate_req != loop->capt->rate) {
+                        snd_pcm_format_t format1, format2;
 			loop->use_samplerate = 1;
+                        format1 = loop->play->format;
+                        format2 = loop->capt->format;
+                        fix_format(loop, 1);
+                        if (loop->play->format != format1 ||
+                            loop->capt->format != format2) {
+                                pcmjob_stop(loop);
+                                goto __again;
+                        }
+                }
 	}
 #ifdef USE_SAMPLERATE
 	if (loop->sync == SYNC_TYPE_SAMPLERATE)
-- 
1.7.5.3
openSUSE Build Service is sponsored by