[asterisk-commits] tilghman: branch 1.4 r167095 - /branches/1.4/channels/chan_alsa.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 31 18:01:22 CST 2008


Author: tilghman
Date: Wed Dec 31 18:01:22 2008
New Revision: 167095

URL: http://svn.digium.com/view/asterisk?view=rev&rev=167095
Log:
Repeat attempts to write when we receive -EAGAIN from the driver, as detailed
in the ALSA sample code (see http://www.alsa-project.org/alsa-doc/alsa-lib/_2test_2pcm_8c-example.html#a32)
Reported by: Jerry Geis (via the -users list)
Fixed by: me (license 14)

Modified:
    branches/1.4/channels/chan_alsa.c

Modified: branches/1.4/channels/chan_alsa.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_alsa.c?view=diff&rev=167095&r1=167094&r2=167095
==============================================================================
--- branches/1.4/channels/chan_alsa.c (original)
+++ branches/1.4/channels/chan_alsa.c Wed Dec 31 18:01:22 2008
@@ -266,7 +266,9 @@
 	state = snd_pcm_state(alsa.ocard);
 	if (state == SND_PCM_STATE_XRUN)
 		snd_pcm_prepare(alsa.ocard);
-	res = snd_pcm_writei(alsa.ocard, frame, res);
+	while ((res = snd_pcm_writei(alsa.ocard, frame, res)) == -EAGAIN) {
+		usleep(1);
+	}
 	if (res > 0)
 		return 0;
 	return 0;
@@ -629,13 +631,17 @@
 		state = snd_pcm_state(alsa.ocard);
 		if (state == SND_PCM_STATE_XRUN)
 			snd_pcm_prepare(alsa.ocard);
-		res = snd_pcm_writei(alsa.ocard, sizbuf, len / 2);
+		while ((res = snd_pcm_writei(alsa.ocard, sizbuf, len / 2)) == -EAGAIN) {
+			usleep(1);
+		}
 		if (res == -EPIPE) {
 #if DEBUG
 			ast_log(LOG_DEBUG, "XRUN write\n");
 #endif
 			snd_pcm_prepare(alsa.ocard);
-			res = snd_pcm_writei(alsa.ocard, sizbuf, len / 2);
+			while ((res = snd_pcm_writei(alsa.ocard, sizbuf, len / 2)) == -EAGAIN) {
+				usleep(1);
+			}
 			if (res != len / 2) {
 				ast_log(LOG_ERROR, "Write error: %s\n", snd_strerror(res));
 				res = -1;




More information about the asterisk-commits mailing list