Monado OpenXR Runtime
m_clock_tracking.h File Reference

Helpers to estimate offsets between clocks. More...

#include "xrt/xrt_defines.h"
#include "util/u_time.h"
Include dependency graph for m_clock_tracking.h:

Go to the source code of this file.

Functions

static timepoint_ns m_clock_offset_a2b (float freq, timepoint_ns a, timepoint_ns b, time_duration_ns *inout_a2b)
 Helper to estimate the offset between two clocks using exponential smoothing. More...
 
struct m_clock_windowed_skew_trackerm_clock_windowed_skew_tracker_alloc (const size_t window_samples)
 Allocate a struct m_clock_windowed_skew_tracker with a window of. More...
 
void m_clock_windowed_skew_tracker_reset (struct m_clock_windowed_skew_tracker *t)
 
void m_clock_windowed_skew_tracker_destroy (struct m_clock_windowed_skew_tracker *t)
 
void m_clock_windowed_skew_tracker_push (struct m_clock_windowed_skew_tracker *t, const timepoint_ns local_ts, const timepoint_ns remote_ts)
 
bool m_clock_windowed_skew_tracker_to_local (struct m_clock_windowed_skew_tracker *t, const timepoint_ns remote_ts, timepoint_ns *local_ts)
 
bool m_clock_windowed_skew_tracker_to_remote (struct m_clock_windowed_skew_tracker *t, const timepoint_ns local_ts, timepoint_ns *remote_ts)
 

Detailed Description

Helpers to estimate offsets between clocks.

Author
Mateo de Mayo mateo.nosp@m..dem.nosp@m.ayo@c.nosp@m.olla.nosp@m.bora..nosp@m.com

Function Documentation

◆ m_clock_offset_a2b()

static timepoint_ns m_clock_offset_a2b ( float  freq,
timepoint_ns  a,
timepoint_ns  b,
time_duration_ns inout_a2b 
)
inlinestatic

Helper to estimate the offset between two clocks using exponential smoothing.

Given a sample from two timestamp domains A and B that should have been sampled as close as possible, together with an estimate of the offset between A clock and B clock (or zero), it applies a smoothing average on the estimated offset and returns a in B clock.

This estimator can be used when clock observations are arriving with a low delay and small jitter, or when accuracy is less important (on the order of the jitter that is present). It is very computationally cheap.

Parameters
freqAbout how many times per second this function is called. Helps setting a good decay value.
aTimestamp in clock A of the event
bTimestamp in clock B of the event
[in,out]inout_a2bPointer to the current offset estimate from A to B, or 0 if unknown. Value pointed-to will be updated.
Returns
timepoint_ns a in B clock

Referenced by receive_imu_sample().

◆ m_clock_windowed_skew_tracker_alloc()

struct m_clock_windowed_skew_tracker * m_clock_windowed_skew_tracker_alloc ( const size_t  window_samples)

Allocate a struct m_clock_windowed_skew_tracker with a window of.

Parameters
window_samplessamples.

References U_TYPED_ARRAY_CALLOC, and U_TYPED_CALLOC.