Lennart, Your code loop appears to have resolved the issues between asterisk and pulse in the write direction, now I have to resolve the read direction. Can you provide some guidance on a preferred processing loop for reading from pulse? I took a stab, how does this look? for (;;) { state = snd_pcm_state(alsa.icard); if ((state != SND_PCM_STATE_PREPARED) && (state != SND_PCM_STATE_RUNNING)) { snd_pcm_prepare(alsa.icard); } if (state == SND_PCM_STATE_XRUN) snd_pcm_prepare(alsa.icard); buf = __buf + AST_FRIENDLY_OFFSET / 2; r = snd_pcm_readi(alsa.icard, buf + readpos, left); if (r >= 0) /* Success */ off -= r; break; /* Failure, try to recover */ if ((r = snd_pcm_recover( alsa.icard, r, 1)) < 0) { /* Failed to recover, we have a real issue */ ast_log(LOG_NOTICE, "snd_pcm_recover failed: %s", snd_strerror(r)); break; } /* Recovered, let's try another read */ } "Lennart Poettering" <lennart at poettering.net> wrote in message news:20080215221012.GA18000 at tango.0pointer.de... > On Thu, 14.02.08 20:10, Jim Duda (jim at duda.tzo.com) wrote: > >> >> Here is the Asterisk alsa write code loop. I added the trap for -EIO. >> I'm getting an negative return from snd_pcm_recover. >> >> [Feb 14 20:08:25] ERROR[3085]: chan_alsa.c:404 alsa_write: >> snd_pcm_recover failed Input/output error >> >> Is there anything obvious which needs to be done to make this more pulse >> friendly? > > Not sure. The general logic of snd_pcm_recover should be like this: > > for (;;) { > if ((err = snd_pcm_writei(....)) >= 0) > /* Success */ > break; > > /* Failure, try to recover */ > if ((err = snd_pcm_recover(..., err)) < 0) { > > /* Failed to recover, we have a real issue */ > fprintf(stderr, "Things went very wrong: %s", snd_strerror(err)); > break; > } > > /* Recovered, let's try another write */ > } > > This probably won't fix your issue, but it will shorten your code > quite a bit I would say and make it more robust. > > snd_pcm_prepare() should be called only once after > init. snd_pcm_recover() will implicitly call _prepare() in all other > cases. > > Lennart > > -- > Lennart Poettering Red Hat, Inc. > lennart [at] poettering [dot] net ICQ# 11060553 > http://0pointer.net/lennart/ GnuPG 0x1A015CC4