context: use clock time as rttime when using our loop

This commit is contained in:
Wim Taymans 2020-10-23 20:37:04 +02:00
parent 520c2a0e16
commit 3255bc8eae
4 changed files with 46 additions and 7 deletions

View file

@ -69,3 +69,38 @@ struct timeval* pa_rtclock_from_wallclock(struct timeval *tv)
return tv;
}
struct timeval* pa_rtclock_to_wallclock(struct timeval *tv)
{
struct timeval wc_now, rt_now;
pa_assert(tv);
pa_gettimeofday(&wc_now);
pa_rtclock_get(&rt_now);
if (pa_timeval_cmp(&rt_now, tv) < 0)
pa_timeval_add(&wc_now, pa_timeval_diff(tv, &rt_now));
else
pa_timeval_sub(&wc_now, pa_timeval_diff(&rt_now, tv));
*tv = wc_now;
return tv;
}
struct timeval* pa_timeval_rtstore(struct timeval *tv, pa_usec_t v, bool rtclock)
{
pa_assert(tv);
if (v == PA_USEC_INVALID)
return NULL;
pa_timeval_store(tv, v);
if (rtclock)
tv->tv_usec |= PA_TIMEVAL_RTCLOCK;
else
pa_rtclock_to_wallclock(tv);
return tv;
}