[pulseaudio-discuss] Write callback during stream setup
arun at arunraghavan.net
Mon Jul 25 04:17:57 UTC 2016
On Sun, 17 Jul 2016, at 09:50 AM, Alexandros Chronopoulos wrote:
> I wonder if I can de-activate the auto call of write callback existing
> before uncork a stream.
> Reading the documentation I had the impression that if *prebuf *attribute
> is set to 0 and make use of PA_STREAM_START_CORKED flag in playback
> connect, playback will not start automatically. In practice using the
> does not prevent the write callback to be triggered once during the
> In order to achieve the desired behavior I register the write callback
> after calling the connect method and after stream get in ready state. In
> addition I had to combine this with the configuration above (prebuf == 0
> and the flag set). If prebuf==-1 and the flag is set with this workaround
> write callback is never called even after uncork the stream
> My question is if this is a valid method to achieve the desired behavior
> and if not which is the best way to do it?
Starting corked and the write callback are not necessarily related. The
idea there is that we want to make sure there's enough data to start
playback immediately on uncork, so the write callback will called
Next, prebuf=0 is going todecide whether PulseAudio continues playback
on your stream whether there's data in there or not.
So I guess my question is -- what are you trying to achieve? IIRC, your
flow looked something like:
1. Client says it will want to start playback at some point
2. Some arbitrary time passes
3. Client says it wants to start playback
3.1 Now you start providing data and start playback
My recollection is that In your current model, you connect the
pa_context and pa_stream in 1, and then want to start playback at step
I can see two solutions to your problem, then:
a. Use PA_STREAM_START_CORKED and prebuf=-1. Don't hook up the write
callback till step (3). When you hit (3), connect the write callback but
also do a pa_stream_writable_size() to see how much data you need, and
manually trigger your callback asking for that amount of data.
b. Redo your client code so you connect the pa_context in step (1) but
create and connect your stream in step (2) without
PA_STREAM_START_CORKED (you can choose prebuf=0 if you want, but it
might be less hairy to have it be -1 so you don't underrun right at the
start). This means you'll connect and start playback when the client
actually is ready to do so.
Hope this makes sense.
More information about the pulseaudio-discuss