From: Tilghman Lesher Date: Thu, 1 Jan 2009 00:01:22 +0000 (+0000) Subject: Repeat attempts to write when we receive -EAGAIN from the driver, as detailed X-Git-Tag: 1.4.23-testing~2^2~36 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=30fe8c619d750ee743f477169a01b1b7c1486464;p=thirdparty%2Fasterisk.git 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) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@167095 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/channels/chan_alsa.c b/channels/chan_alsa.c index c0e77c5a36..03db26b6a2 100644 --- a/channels/chan_alsa.c +++ b/channels/chan_alsa.c @@ -266,7 +266,9 @@ static int send_sound(void) 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 @@ static int alsa_write(struct ast_channel *chan, struct ast_frame *f) 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;