Pulseaudio with Application Asterisk

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 25.02.08 14:43, Jim Duda (jim at duda.tzo.com) wrote:

> 
> 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?
> 

The code should look much the same as for the write case: Try to
write, if that fails, try to recover and try to rewrite
again. Basically, just do a s/writei/readi. And make sure to run
_prepare once before entering the loop.

It should be safer to never check for specific PCM states
manually. The ALSA state machine is not trivial, especially when it
comes to stuff like suspending, so this is easy to get
wrong. snd_pcm_recover() should do all what you need.

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


The lines above can probably just be dropped. But do a
snd_pcm_prepare() once before the loop (should be done for both the
wirte and the read case, btw)

>                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 */
>         }

This looks fine.

Lennart

-- 
Lennart Poettering                        Red Hat, Inc.
lennart [at] poettering [dot] net         ICQ# 11060553
http://0pointer.net/lennart/           GnuPG 0x1A015CC4



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux