[pulseaudio-discuss] call pa_stream_drain() for multiple streams

Sean Greenslade sean at seangreenslade.com
Sat Mar 12 08:02:40 UTC 2022


On Fri, Mar 11, 2022 at 04:28:00AM +0800, su wrote:
> At first I would like to take this chance to express my gratitude to PulseAudio dev. team and those warm-hearted members at this community  :)
> 
> I have a minor question about calling pa_stream_drain()  for multiple streams at the same context. It seems I cannot issue this command 
> 
> for multiple streams at the same time : 
> 
> for ( int stream_index = 0 ; stream_index < 2 ; stream_index++)
> 
> {
> 
>     pa_operation* pa_op= pa_stream_drain( pa_stream *  audio_stream[ stream_index ]  ,
> 
>                 my_pa_stream_success_cb_t, NULL );
> 
> 
> 
> 
>     while (pa_operation_get_state(pa_op) != PA_OPERATION_DONE) {
> 
>     sleep(1);
> 
>     }
> 
> }   
> 
> How to wait for the done signal to pa_stream_drain() the next stream  efficiently  ?

I don't believe there is any problem with issuing drains for multiple
streams. As far as I know, you could issue them all at once then wait
for them all to finish.

You example code above has some typos, so I'm assuming it's not exactly
what you are running. Can you describe more specifically what is going
wrong with your code? How exactly is it not working?

One possible bug I can foresee is that pa_operation_get_state() could
also return _CANCELLED, so it would be more robust to do something like
the following:

while(pa_operation_get_state(pa_op) == PA_OPERATION_RUNNING) sleep(1);


--Sean



More information about the pulseaudio-discuss mailing list