mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
mainloop: convert from wallclock to rtclock
This is needed for the mainloop timeouts
This commit is contained in:
parent
70e9e622eb
commit
413c233b9a
3 changed files with 58 additions and 24 deletions
|
|
@ -23,7 +23,9 @@
|
|||
|
||||
#include <pipewire/log.h>
|
||||
|
||||
#include <pulse/timeval.h>
|
||||
#include <pulse/rtclock.h>
|
||||
#include "internal.h"
|
||||
|
||||
SPA_EXPORT
|
||||
pa_usec_t pa_rtclock_now(void)
|
||||
|
|
@ -36,3 +38,34 @@ pa_usec_t pa_rtclock_now(void)
|
|||
return res;
|
||||
}
|
||||
|
||||
static struct timeval *pa_rtclock_get(struct timeval *tv)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
pa_assert(tv);
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
tv->tv_sec = ts.tv_sec;
|
||||
tv->tv_usec = ts.tv_nsec / PA_NSEC_PER_USEC;
|
||||
return tv;
|
||||
}
|
||||
|
||||
struct timeval* pa_rtclock_from_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(&wc_now, tv) < 0)
|
||||
pa_timeval_add(&rt_now, pa_timeval_diff(tv, &wc_now));
|
||||
else
|
||||
pa_timeval_sub(&rt_now, pa_timeval_diff(&wc_now, tv));
|
||||
|
||||
*tv = rt_now;
|
||||
|
||||
return tv;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue