[alsa-devel] snd_pcm_writei returns -EAGAIN after poll

Raymond Yau superquad.vortex2 at gmail.com
Sun Mar 20 03:40:59 CET 2011


2011/3/20 Ivan Sorokin <sorokin at rain.ifmo.ru>

> Hello!
>
> I use slightly modified test/pcm.c in write_and_poll mode.
>
> My program looks like this:
>
> snd_pcm_open with SND_PCM_NONBLOCK
> snd_pcm_set_params
>
> infinite loop
>    poll for snd_pcm_poll_descriptors
>    snd_pcm_poll_descriptors_revents
>    if POLLOUT flag is set
>       snd_pcm_writei
>
> Everything works, but snd_pcm_writei sometimes returns -EAGAIN. The
> probability of when snd_pcm_writei returns -EAGAIN depends on buffer
> size that I pass to it. ExperimentallyI found out that when I call
> snd_pcm_writei with 940 bytes buffers (maybe something related to period
> size?) it never returns -EAGAIN.
>
> Why poll returns when there is no place for new data? Is it ok to ignore
> EAGAIN and just start another poll? Is there any recommended buffer size
> for snd_pcm_writei?
>
> My test program:
> https://github.com/sorokin/asoundpp/blob/master/sine_async.cpp (94 LOC)
>


Most sound cards does not have 0.5 second buffer , only a few sound card
(e.g. snd-hda-intel has 4Mb buffer but snd-intel8x0 only has 64Kb buffer


d.set_params(SND_PCM_FORMAT_S16,
                   SND_PCM_ACCESS_RW_INTERLEAVED,
                   1,
                   RATE,
                   true,
                   500000);


More information about the Alsa-devel mailing list