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
This commit is contained in:
Tilghman Lesher
2009-01-01 00:01:22 +00:00
parent f3f0f40223
commit 30fe8c619d

View 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;