[pulseaudio-discuss] calling pa_stream_update_timing_info in another thread

golden magic.lixin at gmail.com
Tue May 19 23:11:34 PDT 2015


Dear Georg,

      Yes, I missed the cancel case.
      mainloop type is threaded mainloop.

      I change my code to something like this:

         pa_threaded_mainloop_lock(m_mainloop);
         pa_operation* o = pa_stream_update_timing_info(s, NULL, NULL);
         LOGD("enter PA_WAIT_OPEARION2DONE loop");
         if (o != NULL) {
             while (1)
             {
                 pa_operation_state_t  state = pa_operation_get_state(o);
                 LOGD("state=%d", state);
                 if (state != PA_OPERATION_RUNNING)
                 {
                     LOGD("pa_operation_get_state(o) = %d", state);
                     break;
                 }
             }
             pa_operation_unref(o);
             o = NULL;
         } else {
             LOGD("PA_WAIT_OPEARION2DONE operation is NULL");
         }

         NCLOGD("exit PA_WAIT_OPEARION2DONE loop");
         pa_threaded_mainloop_unlock(m_mainloop);

      It never ends, always printing state=0.


BR,
Lixin


在 2015年05月20日 13:49, Georg Chini 写道:
> 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
>
> _______________________________________________
> 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