Hi Georg static void pa_stream_timing_callback(pa_stream*s, int success, void *userdata) { NCLOGD("pa_stream_timing_callback -"); pa_threaded_mainloop_signal((pa_threaded_mainloop*)userdata, 0); } int64_t audiostream::getBufferLatencySize() { pa_threaded_mainloop_lock(m_mainloop); pa_operation* o = pa_stream_update_timing_info(s, pa_stream_timing_callback, m_mainloop); LOGD("enter PA_WAIT_OPEARION2DONE loop"); if (o != NULL) { while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) { pa_threaded_mainloop_wait(m_mainloop); NCLOGD("pa_operation_get_state(o) = %d", pa_operation_get_state(o)); } 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); const pa_timing_info* t = pa_stream_get_timing_info(s); if (!t) { return -1; } return t->write_index - t->read_index; } this is the modified code, still the same problem. It feels like if auto timing update is enabled, pa_stream_update_timing_info called in another thread will be missed, and callback is not notified any more. That`s my test result. 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