[pulseaudio-discuss] Pulseaudio with Application Asterisk

Jim Duda jim at duda.tzo.com
Thu Feb 14 17:10:13 PST 2008


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?

I'm still working on running with gdb.

Jim

static int alsa_write(struct ast_channel *chan, struct ast_frame *f)
{
	static char sizbuf[8000];
	static int sizpos = 0;
	int len = sizpos;
	int pos;
	int res = 0;
	/* size_t frames = 0; */
	snd_pcm_state_t state;

	ast_mutex_lock(&alsalock);

	/* We have to digest the frame in 160-byte portions */
	if (f->datalen > sizeof(sizbuf) - sizpos) {
		ast_log(LOG_WARNING, "Frame too large\n");
		res = -1;
	} else {
		memcpy(sizbuf + sizpos, f->data, f->datalen);
		len += f->datalen;
		pos = 0;
		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);
		if (res == -EPIPE) {
#if DEBUG
			ast_debug(1, "XRUN write\n");
#endif
			snd_pcm_prepare(alsa.ocard);
			res = snd_pcm_writei(alsa.ocard, sizbuf, len / 2);
			if (res != len / 2) {
				ast_log(LOG_ERROR, "Write error: %s\n", snd_strerror(res));
				res = -1;
			} else if (res < 0) {
				ast_log(LOG_ERROR, "Write error %s\n", snd_strerror(res));
				res = -1;
			}
		} else if (res == -EIO) {
		        res = snd_pcm_recover ( alsa.ocard, res, 1);
			if (res != 0) {
			  ast_log(LOG_ERROR, "snd_pcm_recover failed %s\n", snd_strerror(res));
                         }
                 }
                 else {
			if (res == -ESTRPIPE)
				ast_log(LOG_ERROR, "You've got some big problems\n");
			else if (res < 0)
				ast_log(LOG_NOTICE, "Error %d on write\n", res);
		}
	}
	ast_mutex_unlock(&alsalock);

	return res >= 0 ? 0 : res;
}


Jim Duda wrote:
> Lennart,
> 
> Asterisk does not call snd_pcm_recover( ) after receiving EIO.
> There is no specific trap for EIO.
> 
> Thanks for the reply, I will start with gdb and report back my findings.
> 
> Jim
> 
> 
> "Lennart Poettering" <lennart at poettering.net> wrote in message news:20080213115403.GA13794 at tango.0pointer.de...
>> On Sun, 03.02.08 16:38, Jim Duda (jim at duda.tzo.com) wrote:
>>
>>> When I directly connect Asterisk to the sound card, everything works
>>> fine.  However, when I attempt to connect to the sound card through
>>> Pulseaudio, the Asterisk application will crash after making the second
>>> call connection.
>>>
>>> The only evidence of something I currently see going wrong is that the
>>> alsa interface for Asterisk receives a -5 (-EIO) on a write to the alsa
>>> interface.  I don't know if that is the eventual cause of the crash.
>> There are multiple reasons why ALSA or our ALSA backend might return
>> EIO to the application. From this remote perspective it is not really
>> possible for me to find out what the exact problem is.
>>
>> Please install the debugging symbols for alsa-plugins and use gdb to
>> find out what the reason for the EIO might be.
>>
>> Does Asterisk call snd_pcm_recover() after getting the EIO?
>>
>> Lennart
>>
>> -- 
>> Lennart Poettering                        Red Hat, Inc.
>> lennart [at] poettering [dot] net         ICQ# 11060553
>> http://0pointer.net/lennart/           GnuPG 0x1A015CC4 




More information about the pulseaudio-discuss mailing list