[alsa-devel] ALSA calling pcm_pointer excessively?

Jassi Brar jassisinghbrar at gmail.com
Thu May 10 19:47:25 CEST 2012


On Thu, May 10, 2012 at 10:35 PM, Clemens Ladisch <clemens at ladisch.de> wrote:
>
> --- a/sound/core/pcm_lib.c
> +++ b/sound/core/pcm_lib.c
> @@ -1894,7 +1894,7 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
>        struct snd_pcm_runtime *runtime = substream->runtime;
>        snd_pcm_uframes_t xfer = 0;
>        snd_pcm_uframes_t offset = 0;
> -       int err = 0;
> +       int busy_loops = 0, err = 0;
>
>        if (size == 0)
>                return 0;
> @@ -1919,12 +1919,17 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
>        runtime->twake = runtime->control->avail_min ? : 1;
>        while (size > 0) {
>                snd_pcm_uframes_t frames, appl_ptr, appl_ofs;
> -               snd_pcm_uframes_t avail;
> +               snd_pcm_uframes_t avail, avail_wait_max;
>                snd_pcm_uframes_t cont;
> +
> +               if (busy_loops < 5)
> +                       avail_wait_max = 0;
> +               else
> +                       avail_wait_max = min(runtime->control->avail_min, size);
>                if (runtime->status->state == SNDRV_PCM_STATE_RUNNING)
>                        snd_pcm_update_hw_ptr(substream);
>                avail = snd_pcm_playback_avail(runtime);
> -               if (!avail) {
> +               if (avail <= avail_wait_max) {
>                        if (nonblock) {
>                                err = -EAGAIN;
>                                goto _end_unlock;
> @@ -1934,6 +1939,9 @@ static snd_pcm_sframes_t snd_pcm_lib_write1(struct snd_pcm_substream *substream,
>                        err = wait_for_avail(substream, &avail);
>                        if (err < 0)
>                                goto _end_unlock;
> +                       busy_loops = 0;
> +               } else {
> +                       busy_loops++;
>                }
>                frames = size > avail ? avail : size;
>                cont = runtime->buffer_size - runtime->control->appl_ptr % runtime->buffer_size;
>
Hi Clemens,

If we really want to change the behavior of play, wouldn't we want to do that
for capture(snd_pcm_lib_read1) as well ?


More information about the Alsa-devel mailing list