aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2009-01-01 00:01:22 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2009-01-01 00:01:22 +0000
commitc3ecb6a1532fbddc64348b23dd46b88adbf9b70b (patch)
tree5569eadd32103499719665ebba4a37d4b5a9fd75
parente606f99f646cdd6689108d5a83339e989a37fda1 (diff)
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: http://svn.digium.com/svn/asterisk/branches/1.4@167095 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--channels/chan_alsa.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/channels/chan_alsa.c b/channels/chan_alsa.c
index c0e77c5a3..03db26b6a 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;