[pulseaudio-discuss] making a custom mainloop robust to clock changes
tanuk at iki.fi
Fri May 22 04:45:20 PDT 2015
On Mon, May 18, 2015, at 21:56, Sébastien Barthélémy wrote:
> I'm looking at how our pulseaudio client behaves if the CLOCK_REALTIME is
> So I'm changing set the clock randomly every second and watching the
> In some cases our application fails to get the stream latency: our
> callback, which was set using pa_stream_update_timing_info(), is called
> stream_get_timing_info_callback ) with o->stream->timing_info_valid
> My guess is that, in the test a bit above (). we have
> Is there any way to test that hypothesis?
The callback given to pa_stream_update_timing_info() has type
pa_context_success_cb_t, which has the "success" argument. If "success"
is false, you can get the error code with pa_context_errno(). If the
operation failed due to a timeout, the error code should be
> It seems indeed that one sets a callback timeout using a pa_rtclock time
> point  (and not just a the timeout duration), which is then (see
> pa_timeval_rtstore ) converted to a CLOCK_REALTIME time point.
> I expect that pa_rtclock uses CLOCK_MONOTONIC internally,
You're probably correct, but I can't confirm without digging deeper in
> but converting
> to CLOCK_REALTIME makes the timeout mechanism vulnerable to clock
> There is apparently some mechanism (enabled at , back in 2009 ) to
> use pa_rtclock time points for the timeout, but if found no way to enable
> it for our custom mainloop. Did I miss something?
No, you didn't miss anything. pa_context seems to only support this for
> Moreover, it involves setting some magical bit in the timeval to indicate
> this is a "rtclock" one. Does someone recall the reason for this trick,
> opposed to, say, a (simpler) boolean option when setting up the mainloop?
I don't know (or remember) the reason. I would guess that it has to do
with maintaining a stable public API and avoiding unnecessary complexity
in the API. However, if there's need for enabling the rtclock stuff for
custom mainloops, I'd expect there to be some way to implement that
without breaking backwards compatibility.
More information about the pulseaudio-discuss