[pulseaudio-discuss] Rendering data from sink with 0.9.7

Lennart Poettering lennart at poettering.net
Wed Oct 24 06:32:42 PDT 2007

On Wed, 24.10.07 10:20, Jyri Sarha (lepbtetfmvbz at spammotel.com) wrote:


> 	To ensure minimal latencies I have configure alsa sink and
> source to use only two 10ms fragments. While running the daemon with
> real-time priority the sound plays without a glitch (without
> RT-priority mouse movement etc. activity causes buffer under
> runs). However every now and then alsa-sink or -source unloads just
> out of the blue. This seems to happen more often when fragment size is
> smaller, but not often enough to really bother me at the moment. I just
> wonder if this is a known problem.

I fixed something like this a while back. Are you running latest SVN?

>   if (u->sink_memchunk.memblock == NULL) {
>     pa_memchunk lchunk;
>     while (pa_memblockq_get_length(u->sink_memblockq) < u->window_size) {
>       pa_sink_render(u->sink, u->window_size - pa_memblockq_get_length(u->sink_memblockq), &lchunk);

I think you want to be using pa_sink_render_full() here, which will
render as much data as you want and doesn't do unnecessary buffering.

> 	The memblockq_to_chunk() just copies and drops specified amount
> of data to chunk. The function allocates a new memblock and does the
> actual copying only if necessary. I have tested the function quite
> thoroughly and there should be no problem there (maybe the function
> could be added to memblockq API).
> 	When the module with the code above is loaded the daemon
> crashes almost immediately in memblock refcount assertion failure under
> pa_sink_input_peek. I have been debugging this for a few days now
> but I can not find an error in my code. Is forcibly rendering 10ms
> from sink evil? Or have I just overlooked something?

pa_sink_render_full() is what you want to use here.

But I think the problem you are experiencing here is that the _peek()
is supposed hand out the memblock with incremented ref
count. I.e. After your "*chunk = u->sink_memchunk;" you should do a
"pa_memblock_ref(chunk->memblock);" -- so that the local copy you keep
and the copy you hand out both have a reference counted in the

>              if ((ret = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
>                  goto finish;
> -
> +           else
> +             *use_mmap = 0;
>      } else if ((ret = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) 
>          goto finish;
> -    else if (*use_mmap)
> -        *use_mmap = 0;

Great! This is indeed an error! Thank you very much for the
patch! Commited to r1950.



Lennart Poettering                        Red Hat, Inc.
lennart [at] poettering [dot] net         ICQ# 11060553
http://0pointer.net/lennart/           GnuPG 0x1A015CC4

More information about the pulseaudio-discuss mailing list