[alsa-devel] XRUN handling

melwyn lobo linux.melwyn at gmail.com
Wed Jul 14 12:17:12 CEST 2010

Another query, if setting runtime parameters like:
runtime->silence_threshold = runtime->boundary;
runtime->silence_size = runtime->boundary;
runtime->stop_threshold = runtime->boundary;

Also to avoid the bug in snd_pcm_playback_silence()  i.e.,
snd_BUG_ON(frames > runtime->buffer_size),
I have added a tweak in the driver IRQ handler:

              if(substream->stream == SNDRV_PCM_STREAM_PLAYBACK
snd_pcm_playback_hw_avail(runtime) == 0) {

                        /* Hardware is continously running so it is
                         * playing silence so that should be OK.
                         * And we played all valid samples, so no data
                         * is lost. Not stopping intentionally

                          runtime->control->appl_ptr += runtime->period_size;
                        if(runtime->control->appl_ptr >= runtime->boundary)
                                runtime->control->appl_ptr -= runtime->boundary;

                        offset = runtime->control->appl_ptr -
                        if (offset < 0)
                                offset += runtime->boundary;
                        if ((snd_pcm_uframes_t)offset < runtime->silence_filled)
                                runtime->silence_filled -= offset;
                                runtime->silence_filled = 0;

                        runtime->silence_start = runtime->control->appl_ptr;

This avoids the bug above, but aplay does not stop after reading all
the samples from the file. It plays silence infinitely.
Should not this condition be detected by the aplay and stop the stream
when EOF on the file happens.


More information about the Alsa-devel mailing list