[alsa-devel] bug in alsa-lib/snd_pcm_plugin_delay for capture?

Raymond Yau superquad.vortex2 at gmail.com
Sat Nov 27 08:23:23 CET 2010

2010/11/22 Jaroslav Kysela <perex at perex.cz>

> On Mon, 22 Nov 2010, pl bossart wrote:
> >>> Since the PulseAudio commit 29acfd0e0413a9bd126782763ee2dcf10357546 I
> >>> am seeing errors messages telling me that the information reported by
> >>> snd_pcm_avail_delay is not accurate on the capture path, more
> >>> specifically the delay is lower than the available samples.
> >>
> >> Could you test patch bellow?
> >>
> >>
> http://git.alsa-project.org/?p=alsa-lib.git;a=commitdiff;h=ba9332e9192814a5431a3a2505d25d74a9232124
> >
> > Nah, no luck. PulseAudio still reports an error and if I add
> > assert(*delayp >= *availp) the code bombs out.
> > Here is one way to solve the problem. I don't claim it's the right
> > one, but it's compatible with the way the availp value is computed,
> > and it makes the error message go away in PulseAudio.
> The double avail_update() calling seems too expensive to me. Could you
> test to use snd_pcm_mmap_capture_avail() instead snd_pcm_avail_update()
> calls (to assign both slave_avail and plugin_avail local variables)?
> Also, remove the assert. I think that it may be raised when the stream is
> in some xrun state (with xrun checks disabled). The avail_update can
> return the negative values in this specific configuration.
The point is the documentation does not mention that the state still remain
as SND_PCM_STATE_RUNNING even when the distance between the application ptr
and the hw_ptr is more than a buffer size , it only mention the device will
do the endless loop.

The only way to know overrun/underrun is to check the avail is larger than
the buffer size when the application set the stop threshold to boundary
instead of buffer size.

so it is incorrect for PA to say this is a driver bug since it disable the
automatic stop when underrun/overrun occur

e.g. dmix also set stop threshold to boundary but aplay can still get xrun
when using small buffer size with plug:dmix

if you set the boudnary to buffer size instead of boundary in
alsa-time-test.c , alsa-lib will tell you that the program is


PCM is automatically stopped in SND_PCM_STATE_XRUN state when available
frames is >= threshold. If the stop threshold is equal to boundary (also
software parameter - sw_param) then automatic stop will be disabled (thus
device will do the endless loop in the ring buffer).

More information about the Alsa-devel mailing list