[pulseaudio-discuss] calling pa_stream_update_timing_info in another thread

Georg Chini georg at chini.tk
Tue May 19 22:49:54 PDT 2015


Dear Lixin,

On 20.05.2015 04:10, golden wrote:
> Dear PulseAudio forks,
>
>
>      I`m making a function to get the buffer latency of pa_stream(with 
> PA_STREAM_AUTO_TIMING_UPDATE flag), here is what it looks like

What type of mainloop are you using?

>
>
>      void operation_done_callback(pa_stream* , bool, void*)
>     {
>        LOGD("operation_done");
>     }
>
>       int64_t audiostream::getBufferLatencySize()
>      {
>         // m_stream is a pointer of pa_stream
>         pa_operation* o = pa_stream_update_timing_info(m_stream, 
> operation_done_callback, this);
>         LOGD("enter PA_WAIT_OPEARION2DONE loop");
>         if (o != NULL) {
>             while (sync && pa_operation_get_state(o) != 
> PA_OPERATION_DONE)
> ;

Where does sync come from?
Maybe you try
while (sync && pa_operation_get_state(o) == PA_OPERATION_RUNNING)
instead, then at least the function should always return. The way you
implemented it, the function will never return if pa_operation_get_state()
returns PA_OPERATION_CANCELLED.

> pa_operation_unref(o);
>             o = NULL;
>         } else {
>             LOGD("PA_WAIT_OPEARION2DONE operation is NULL");
>         }
>
>         LOGD("exit PA_WAIT_OPEARION2DONE loop");
>
>        const pa_timing_info* t = pa_stream_get_timing_info(s);
>         if (!t) {
>             return -1;
>         }
>         return t->write_index - t->read_index;
> }
>
>     I want that the user can get the accurate result when he calls 
> this function,
>     so every time if user called getBufferLatencySize, I call 
> pa_stream_update_timing_info and wait this operation done, and this 
> function is called in user thread.
>
>      Sometimes this operation is never finished, and the operation 
> done callback is never called.
>
>      Don't know what I'm doing wrong, any advice will be appreciated, 
> Thanks!
>
>
>
>
> BR,
> Lixin
> _______________________________________________
> pulseaudio-discuss mailing list
> pulseaudio-discuss at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss



More information about the pulseaudio-discuss mailing list