[alsa-devel] handling of underrunning snd_pcm_writei

Mads Kiilerich mads at kiilerich.com
Wed Nov 11 19:12:24 CET 2009

On 11/11/2009 05:50 PM, Mads Kiilerich wrote:

> http://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m.html#gf13067c0ebde29118ca05af76e5b17a9
> says about snd_pcm_writei:
>> Returns: a positive number of frames actually written otherwise a
>> negative error code
>> ...
>> Return values:
>> ...
>> -EPIPE an underrun occurred
>> ...
>> The count of bytes can be less only if a signal or underrun occurred.
> It surprises me that snd_pcm_writei shows non-blocking behaviour in case
> of underruns and don't use all the offered data. I would guess that it
> either blocked and enjoyed the data it finally got, or that it gave an
> error and didn't take any data at all. But if this is how it is, then
> ... that is how it is ;-)

Ok, experiments indicates that the documented blocking behaviour only 
applies in SND_PCM_STATE_RUNNING. snd_pcm_writei apparently behaves 
non-blocking in SND_PCM_STATE_PREPARED. I can see how that kind of makes 
sense - I just didn't expect that. Is that correctly understood?


More information about the Alsa-devel mailing list