]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Repeat attempts to write when we receive -EAGAIN from the driver, as detailed
authorTilghman Lesher <tilghman@meg.abyt.es>
Thu, 1 Jan 2009 00:01:22 +0000 (00:01 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Thu, 1 Jan 2009 00:01:22 +0000 (00:01 +0000)
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

channels/chan_alsa.c

index c0e77c5a36c203164256c5a05535d55289badc52..03db26b6a2e7ebc46122b6b2a19f7c58440b4c13 100644 (file)
@@ -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;