[alsa-devel] handling of underrunning snd_pcm_writei
tiwai at suse.de
Thu Nov 12 08:12:23 CET 2009
At Wed, 11 Nov 2009 17:50:12 +0100,
Mads Kiilerich wrote:
> > 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.
> So what is returned in case of underrun? Error code or count of bytes?
First it returns the actually written frames, then -EPIPE.
But, it might return -EPIPE first, depending on the plugin, I guess.
> Should snd_pcm_recover always be used to get the byte count after
> -EPIPE? snd_pcm_recover is neither mentioned in the link above nor in
> http://www.alsa-project.org/alsa-doc/alsa-lib/pcm.html , so I don't feel
> confident about that.
Yes, snd_pcm_recover() is *recommended*. You can write the recovery
routine by yourself. The function isn't referred here just because
it's relatively new. Better to be documented, indeed.
> And is it measured in "positive number of frames actually written" or
> "count of bytes"?
Frames. Should be corrected.
For both fixes, a patch from contributors is always welcome ;)
> 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 ;-)
It's because the XRUN isn't recovered automatically but the operation
stops. It's analogous to a disk-full error.
More information about the Alsa-devel