Monado OpenXR Runtime
Loading...
Searching...
No Matches
t_led_sync_refinement.c File Reference

A routine to automatically refine latency offsets of LED blink times using constellation samples. More...

Include dependency graph for t_led_sync_refinement.c:

Macros

#define PERIOD_ESTIMATE_FRAMES   600
 How many frames the period estimate is measured over, ~10s at 60 fps.
 
#define PERIOD_ESTIMATE_MAX_ERROR   200e-6
 How far a run may be from the per-frame interval before it's taken as a timestamp jump.
 
#define PERIOD_ESTIMATE_AGREEMENT   10e-6
 How closely two runs in a row have to agree before the estimate is trusted.
 

Functions

static time_duration_ns change_good_cutoff (struct t_led_sync_refinement *refinement)
 The amount of time of which a change under this amount is considered "good" and we can exit the binary search.
 
static uint32_t frames_since_sample_apply (struct t_led_sync_refinement *refinement, timepoint_ns now_ns)
 The amount of frames since the sample was applied to the controller.
 
static time_duration_ns get_search_period_locked (struct t_led_sync_refinement *refinement)
 Gets the period to iterate over when searching for an offset.
 
static void update_period_estimate (struct t_led_sync_refinement *refinement, const struct t_timing_event_camera_exposure_start *event)
 Measures the frame period over many frames, the per-frame interval is too noisy to trim the LED cycle from.
 
static void handle_find_initial_offset (struct t_led_sync_refinement *refinement)
 
static void handle_find_right_edge (struct t_led_sync_refinement *refinement)
 
static void handle_find_left_edge (struct t_led_sync_refinement *refinement)
 
static void handle_refine_blink_duration (struct t_led_sync_refinement *refinement)
 
static void handle_maintain_offset (struct t_led_sync_refinement *refinement)
 
static void handle_timing_event_locked (struct t_led_sync_refinement *refinement, const struct t_timing_event_camera_exposure_start *event)
 
static void handle_constellation_sample_locked (struct t_led_sync_refinement *refinement, const struct t_constellation_tracker_sample *sample)
 
int t_led_sync_refinement_init (struct t_led_sync_refinement *refinement, const struct t_led_sync_refinement_options *options)
 
void t_led_sync_refinement_destroy (struct t_led_sync_refinement *refinement)
 
void t_led_sync_push_timing_event (struct t_led_sync_refinement *refinement, const struct t_timing_event_camera_exposure_start *event)
 
void t_led_sync_push_constellation_sample (struct t_led_sync_refinement *refinement, const struct t_constellation_tracker_sample *sample)
 
bool t_led_sync_get_sample (struct t_led_sync_refinement *refinement, struct t_led_sync_sample *out_sample)
 
void t_led_sync_mark_latest_sample_applied (struct t_led_sync_refinement *refinement, timepoint_ns apply_time_ns)
 
void t_led_sync_push_host_device_clock_offset (struct t_led_sync_refinement *refinement, time_duration_ns clock_offset_ns)
 Pushes a clock offset to the refinement routine, this is the offset from the host to the device.
 

Detailed Description

A routine to automatically refine latency offsets of LED blink times using constellation samples.

Author
Beyley Cardellio ep1cm.nosp@m.1n10.nosp@m.n123@.nosp@m.gmai.nosp@m.l.com

Macro Definition Documentation

◆ PERIOD_ESTIMATE_AGREEMENT

#define PERIOD_ESTIMATE_AGREEMENT   10e-6

How closely two runs in a row have to agree before the estimate is trusted.

◆ PERIOD_ESTIMATE_FRAMES

#define PERIOD_ESTIMATE_FRAMES   600

How many frames the period estimate is measured over, ~10s at 60 fps.

◆ PERIOD_ESTIMATE_MAX_ERROR

#define PERIOD_ESTIMATE_MAX_ERROR   200e-6

How far a run may be from the per-frame interval before it's taken as a timestamp jump.

Function Documentation

◆ change_good_cutoff()

static time_duration_ns change_good_cutoff ( struct t_led_sync_refinement *  refinement)
static

The amount of time of which a change under this amount is considered "good" and we can exit the binary search.

References t_led_sync_refinement::current_blink_duration_ns, t_led_sync_refinement::exposure_time_ns, and MIN.

◆ frames_since_sample_apply()

static uint32_t frames_since_sample_apply ( struct t_led_sync_refinement *  refinement,
timepoint_ns  now_ns 
)
static

The amount of frames since the sample was applied to the controller.

References t_led_sync_refinement::exposure_interval_ns, and t_led_sync_refinement::last_sample_apply_time_ns.

◆ get_search_period_locked()

static time_duration_ns get_search_period_locked ( struct t_led_sync_refinement *  refinement)
static

◆ t_led_sync_push_host_device_clock_offset()

void t_led_sync_push_host_device_clock_offset ( struct t_led_sync_refinement *  refinement,
time_duration_ns  clock_offset_ns 
)

Pushes a clock offset to the refinement routine, this is the offset from the host to the device.

To convert a timestamp from host -> device domain, you would do: device_timestamp = host_timestamp + clock_offset_ns

References t_led_sync_refinement::driver_host_device_clock_offset_ns, and t_led_sync_refinement::initialized.

◆ update_period_estimate()

static void update_period_estimate ( struct t_led_sync_refinement *  refinement,
const struct t_timing_event_camera_exposure_start *  event 
)
static