Monado OpenXR Runtime
Loading...
Searching...
No Matches
t_time_sync.h
Go to the documentation of this file.
1// Copyright 2026, Beyley Cardellio
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Header defining interfaces for time synchronization in Monado.
6 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
7 * @ingroup xrt_iface
8 */
9
10#pragma once
11
12#include "xrt/xrt_defines.h"
13
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
20{
21 //! Marks the beginning of an exposure.
23};
24
25/*!
26 * Marks beginning of a camera exposure, pushed from the source to the sink.
27 */
29{
30 /*!
31 * The sequence ID of this frame. These may have semantic meaning depending on the source, for example, on a
32 * device with a SLAM/CONTROLLER/CONTROLLER cadence, `sequence_id % 3` will indicate which type of frame is
33 * being exposed.
34 *
35 * This is intentionally left as a generic uint32_t, and not an enum to allow for matching source/sync types to
36 * smuggle this data through while keeping the interface generic to any sink that wants to listen anyway, since
37 * WMR controllers sync to each SLAM frame, and blink on their own for the next two frames.
38 */
39 uint32_t sequence_id;
40 //! The timestamp of the event, in local monotonic domain. See @ref os_monotonic_get_ns.
41 int64_t timestamp_ns;
42 //! Estimated frame period. May be 0 if unknown.
44 //! Estimated exposure time of the frame. May be 0 if unknown.
46};
47
49{
50 enum t_timing_event_type type;
51
52 union {
53 struct t_timing_event_camera_exposure_start camera_exposure_start;
54 };
55};
56
57/*!
58 * @interface t_timing_event_sink
59 *
60 * A time sync sink is a component that receives timing events from a stable timing source, such as the exposure of
61 * a camera frame. This allows the sink to attempt to synchronize its internal timing to the source. This is most
62 * useful for devices such as the PS Sense controllers, or the WMR controllers, which need to synchronize their LED
63 * flashes with a camera.
64 *
65 * Objects implementing t_timing_event_sink should likely also implement @ref xrt_frame_node and live within the
66 * lifetime of an @ref xrt_frame_context.
67 */
69{
70 /*!
71 * A function that the timing event sink will call to push a new timing event.
72 *
73 * @param sink The sink to push the timing event to.
74 * @param event The timing event being pushed.
75 */
76 void (*push_timing_event)(struct t_timing_event_sink *sink, const struct t_timing_event *event);
77};
78
79/*!
80 * Helper function for @ref t_timing_event_sink::push_timing_event.
81 *
82 * @copydoc t_timing_event_sink::push_timing_event
83 *
84 * @public @memberof t_timing_event_sink
85 */
86XRT_NONNULL_ALL static inline void
88{
89 sink->push_timing_event(sink, event);
90}
91
92
93/*!
94 * @interface t_timing_event_source
95 *
96 * A time sync source is a component that generates timing events for an @ref t_timing_event_sink to consume.
97 *
98 * Objects implementing t_timing_event_source should likely also implement @ref xrt_frame_node and live within the
99 * lifetime of an @ref xrt_frame_context.
100 */
102{
103 /*!
104 * Adds an event sink to this source
105 *
106 * @param source The source to add the sink to.
107 * @param sink The sink to add to the source.
108 *
109 * @return 0 on success, or a negative value on failure (for example, the source is full).
110 */
111 int (*add_sink)(struct t_timing_event_source *source, struct t_timing_event_sink *sink);
112
113 /*!
114 * Removes an event sink from this source
115 *
116 * @param source The source to remove the sink from.
117 * @param sink The sink to remove from the source.
118 */
119 void (*remove_sink)(struct t_timing_event_source *source, struct t_timing_event_sink *sink);
120};
121
122/*!
123 * Helper function for @ref t_timing_event_source::add_sink.
124 *
125 * @copydoc t_timing_event_source::add_sink
126 *
127 * @public @memberof t_timing_event_source
128 */
129XRT_NONNULL_ALL static inline int
131{
132 return source->add_sink(source, sink);
133}
134
135/*!
136 * Helper function for @ref t_timing_event_source::remove_sink.
137 *
138 * @copydoc t_timing_event_source::remove_sink
139 *
140 * @public @memberof t_timing_event_source
141 */
142XRT_NONNULL_ALL static inline void
144{
145 source->remove_sink(source, sink);
146}
147
148#ifdef __cplusplus
149}
150#endif
Marks beginning of a camera exposure, pushed from the source to the sink.
Definition t_time_sync.h:29
uint64_t frame_period_ns
Estimated frame period. May be 0 if unknown.
Definition t_time_sync.h:43
uint32_t sequence_id
The sequence ID of this frame.
Definition t_time_sync.h:39
int64_t timestamp_ns
The timestamp of the event, in local monotonic domain. See os_monotonic_get_ns.
Definition t_time_sync.h:41
uint64_t exposure_time_ns
Estimated exposure time of the frame. May be 0 if unknown.
Definition t_time_sync.h:45
A time sync sink is a component that receives timing events from a stable timing source,...
Definition t_time_sync.h:69
void(* push_timing_event)(struct t_timing_event_sink *sink, const struct t_timing_event *event)
A function that the timing event sink will call to push a new timing event.
Definition t_time_sync.h:76
static XRT_NONNULL_ALL void t_timing_event_sink_push_timing_event(struct t_timing_event_sink *sink, const struct t_timing_event *event)
Helper function for t_timing_event_sink::push_timing_event.
Definition t_time_sync.h:87
A time sync source is a component that generates timing events for an t_timing_event_sink to consume.
Definition t_time_sync.h:102
static XRT_NONNULL_ALL int t_timing_event_source_add_sink(struct t_timing_event_source *source, struct t_timing_event_sink *sink)
Helper function for t_timing_event_source::add_sink.
Definition t_time_sync.h:130
int(* add_sink)(struct t_timing_event_source *source, struct t_timing_event_sink *sink)
Adds an event sink to this source.
Definition t_time_sync.h:111
static XRT_NONNULL_ALL void t_timing_event_source_remove_sink(struct t_timing_event_source *source, struct t_timing_event_sink *sink)
Helper function for t_timing_event_source::remove_sink.
Definition t_time_sync.h:143
void(* remove_sink)(struct t_timing_event_source *source, struct t_timing_event_sink *sink)
Removes an event sink from this source.
Definition t_time_sync.h:119
Definition t_time_sync.h:49
t_timing_event_type
Definition t_time_sync.h:20
@ T_TIMING_EVENT_TYPE_CAMERA_EXPOSURE_START
Marks the beginning of an exposure.
Definition t_time_sync.h:22
Common defines and enums for XRT.