Monado OpenXR Runtime
u_sink.h
Go to the documentation of this file.
1// Copyright 2019-2022, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief @ref xrt_frame_sink converters and other helpers.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @author Moshi Turner <moshiturner@protonmail.com>
8 * @ingroup aux_util
9 */
10
11#pragma once
12
13#include "os/os_threading.h"
14#include "xrt/xrt_frame.h"
15#include "xrt/xrt_tracking.h"
16
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#define U_SINK_MAX_SPLIT_DOWNSTREAMS 5
23
24/*!
25 * @see u_sink_quirk_create
26 */
28{
29 bool stereo_sbs;
30 bool ps4_cam;
31 bool leap_motion;
32};
33
34/*!
35 * @public @memberof xrt_frame_sink
36 * @see xrt_frame_context
37 */
38void
40 enum xrt_format f,
41 struct xrt_frame_sink *downstream,
42 struct xrt_frame_sink **out_xfs);
43
44/*!
45 * @public @memberof xrt_frame_sink
46 * @see xrt_frame_context
47 */
48void
50 struct xrt_frame_sink *downstream,
51 struct xrt_frame_sink **out_xfs);
52
53/*!
54 * @public @memberof xrt_frame_sink
55 * @see xrt_frame_context
56 */
57void
59 struct xrt_frame_sink *downstream,
60 struct xrt_frame_sink **out_xfs);
61
62/*!
63 * @public @memberof xrt_frame_sink
64 * @see xrt_frame_context
65 */
66void
68 struct xrt_frame_sink *downstream,
69 struct xrt_frame_sink **out_xfs);
70
71/*!
72 * @public @memberof xrt_frame_sink
73 * @see xrt_frame_context
74 */
75void
77 struct xrt_frame_sink *downstream,
78 struct xrt_frame_sink **out_xfs);
79
80/*!
81 * @public @memberof xrt_frame_sink
82 * @see xrt_frame_context
83 */
84void
86 struct xrt_frame_sink *downstream,
87 struct xrt_frame_sink **out_xfs);
88
89void
90u_sink_create_half_scale(struct xrt_frame_context *xfctx,
91 struct xrt_frame_sink *downstream,
92 struct xrt_frame_sink **out_xfs);
93
94/*!
95 * @public @memberof xrt_frame_sink
96 * @see xrt_frame_context
97 */
98void
100 struct xrt_frame_sink *downstream,
101 struct xrt_frame_sink **out_xfs);
102/*!
103 * @public @memberof xrt_frame_sink
104 * @see xrt_frame_context
105 */
106void
108 struct xrt_frame_sink *downstream,
109 struct xrt_frame_sink **out_xfs);
110
111/*!
112 * @public @memberof xrt_frame_sink
113 * @see xrt_frame_context
114 */
115bool
117 uint64_t max_size,
118 struct xrt_frame_sink *downstream,
119 struct xrt_frame_sink **out_xfs);
120
121
122/*!
123 * @public @memberof xrt_frame_sink
124 * @see xrt_frame_context
125 */
126bool
128 struct xrt_frame_sink *downstream,
129 struct xrt_frame_sink **out_xfs);
130
131/*!
132 * @public @memberof xrt_frame_sink
133 * @see xrt_frame_context
134 */
135void
137 struct xrt_frame_sink *downstream,
138 struct u_sink_quirk_params *params,
139 struct xrt_frame_sink **out_xfs);
140
141/*!
142 * @public @memberof xrt_frame_sink
143 * @see xrt_frame_context
144 * Takes a frame and pushes it to a maximum of U_SINK_MAX_SPLIT_DOWNSTREAMS sinks
145 */
146void
148 struct xrt_frame_sink **downstreams,
149 size_t downstream_count,
150 struct xrt_frame_sink **out_xfs);
151
152/*!
153 * @public @memberof xrt_frame_sink
154 * @see xrt_frame_context
155 * Takes a frame and pushes it to two sinks
156 */
157void
159 struct xrt_frame_sink *left,
160 struct xrt_frame_sink *right,
161 struct xrt_frame_sink **out_xfs);
162
163/*!
164 * Splits Stereo SBS frames into two independent frames
165 */
166void
168 struct xrt_frame_sink *downstream_left,
169 struct xrt_frame_sink *downstream_right,
170 struct xrt_frame_sink **out_xfs);
171
172/*!
173 * Combines stereo frames.
174 * Opposite of u_sink_stereo_sbs_to_slam_sbs_create
175 */
176bool
178 struct xrt_frame_sink *downstream,
179 struct xrt_frame_sink **out_left_xfs,
180 struct xrt_frame_sink **out_right_xfs);
181
182/*!
183 * Enforces left-right push order on frames and forces them to be within a reasonable amount of time from each other
184 */
185bool
187 struct xrt_frame_sink *downstream_left,
188 struct xrt_frame_sink *downstream_right,
189 struct xrt_frame_sink **out_left_xfs,
190 struct xrt_frame_sink **out_right_xfs);
191
192
193/*
194 *
195 * Debugging sink,
196 *
197 */
198
199/*!
200 * Allows more safely to debug sink inputs and outputs.
201 */
203{
204 //! Is initialised/destroyed when added or root is removed.
206
207 // Protected by mutex, mutex must be held when frame is being pushed.
208 struct xrt_frame_sink *sink;
209};
210
211static inline void
212u_sink_debug_init(struct u_sink_debug *usd)
213{
214 os_mutex_init(&usd->mutex);
215}
216
217static inline bool
218u_sink_debug_is_active(struct u_sink_debug *usd)
219{
220 os_mutex_lock(&usd->mutex);
221 bool active = usd->sink != NULL;
222 os_mutex_unlock(&usd->mutex);
223
224 return active;
225}
226
227static inline void
228u_sink_debug_push_frame(struct u_sink_debug *usd, struct xrt_frame *xf)
229{
230 os_mutex_lock(&usd->mutex);
231 if (usd->sink != NULL) {
232 xrt_sink_push_frame(usd->sink, xf);
233 }
234 os_mutex_unlock(&usd->mutex);
235}
236
237static inline void
238u_sink_debug_set_sink(struct u_sink_debug *usd, struct xrt_frame_sink *xfs)
239{
240 os_mutex_lock(&usd->mutex);
241 usd->sink = xfs;
242 os_mutex_unlock(&usd->mutex);
243}
244
245static inline void
246u_sink_debug_destroy(struct u_sink_debug *usd)
247{
248 os_mutex_destroy(&usd->mutex);
249}
250
251
252/*!
253 * @public @memberof xrt_imu_sink
254 * @see xrt_frame_context
255 * Takes an IMU sample and pushes it to two sinks
256 */
257void
259 struct xrt_imu_sink *downstream_one,
260 struct xrt_imu_sink *downstream_two,
261 struct xrt_imu_sink **out_imu_sink);
262
263
264/*!
265 * @public @memberof xrt_imu_sink
266 * @see xrt_frame_context
267 * Takes an IMU sample and only pushes it if its timestamp has monotonically increased.
268 * Useful for handling hardware inconsistencies.
269 */
270void
272 struct xrt_imu_sink *downstream,
273 struct xrt_imu_sink **out_imu_sink);
274
275
276#ifdef __cplusplus
277}
278#endif
static int os_mutex_init(struct os_mutex *om)
Init.
Definition: os_threading.h:70
static void os_mutex_lock(struct os_mutex *om)
Lock.
Definition: os_threading.h:86
static void os_mutex_unlock(struct os_mutex *om)
Unlock.
Definition: os_threading.h:110
static void os_mutex_destroy(struct os_mutex *om)
Clean up.
Definition: os_threading.h:122
Wrapper around OS threading native functions.
A wrapper around a native mutex.
Definition: os_threading.h:55
Allows more safely to debug sink inputs and outputs.
Definition: u_sink.h:203
struct os_mutex mutex
Is initialised/destroyed when added or root is removed.
Definition: u_sink.h:205
Definition: u_sink.h:28
Object used to track all sinks and frame producers in a graph.
Definition: xrt_frame.h:108
A object that is sent frames.
Definition: xrt_frame.h:58
bool u_sink_queue_create(struct xrt_frame_context *xfctx, uint64_t max_size, struct xrt_frame_sink *downstream, struct xrt_frame_sink **out_xfs)
Definition: u_sink_queue.c:258
void u_sink_deinterleaver_create(struct xrt_frame_context *xfctx, struct xrt_frame_sink *downstream, struct xrt_frame_sink **out_xfs)
Definition: u_sink_deinterleaver.c:136
void u_sink_create_to_yuv_or_yuyv(struct xrt_frame_context *xfctx, struct xrt_frame_sink *downstream, struct xrt_frame_sink **out_xfs)
Definition: u_sink_converter.c:1024
void u_sink_create_format_converter(struct xrt_frame_context *xfctx, enum xrt_format f, struct xrt_frame_sink *downstream, struct xrt_frame_sink **out_xfs)
Definition: u_sink_converter.c:895
void u_sink_split_multi_create(struct xrt_frame_context *xfctx, struct xrt_frame_sink **downstreams, size_t downstream_count, struct xrt_frame_sink **out_xfs)
Definition: u_sink_split.c:65
void u_sink_quirk_create(struct xrt_frame_context *xfctx, struct xrt_frame_sink *downstream, struct u_sink_quirk_params *params, struct xrt_frame_sink **out_xfs)
Definition: u_sink_quirk.c:96
void u_sink_create_to_r8g8b8_r8g8b8a8_r8g8b8x8_or_l8(struct xrt_frame_context *xfctx, struct xrt_frame_sink *downstream, struct xrt_frame_sink **out_xfs)
Definition: u_sink_converter.c:948
void u_sink_create_to_r8g8b8_or_l8(struct xrt_frame_context *xfctx, struct xrt_frame_sink *downstream, struct xrt_frame_sink **out_xfs)
Definition: u_sink_converter.c:926
void u_sink_split_create(struct xrt_frame_context *xfctx, struct xrt_frame_sink *left, struct xrt_frame_sink *right, struct xrt_frame_sink **out_xfs)
Definition: u_sink_split.c:87
static void xrt_sink_push_frame(struct xrt_frame_sink *sink, struct xrt_frame *frame)
Push a frame into the sink.
Definition: xrt_frame.h:73
void u_sink_create_to_r8g8b8_bayer_or_l8(struct xrt_frame_context *xfctx, struct xrt_frame_sink *downstream, struct xrt_frame_sink **out_xfs)
Definition: u_sink_converter.c:970
void u_sink_create_to_rgb_yuv_yuyv_uyvy_or_l8(struct xrt_frame_context *xfctx, struct xrt_frame_sink *downstream, struct xrt_frame_sink **out_xfs)
Definition: u_sink_converter.c:988
bool u_sink_simple_queue_create(struct xrt_frame_context *xfctx, struct xrt_frame_sink *downstream, struct xrt_frame_sink **out_xfs)
Definition: u_sink_simple_queue.c:184
void u_sink_create_to_yuv_yuyv_uyvy_or_l8(struct xrt_frame_context *xfctx, struct xrt_frame_sink *downstream, struct xrt_frame_sink **out_xfs)
Definition: u_sink_converter.c:1006
Basic frame data structure - holds a pointer to buffer.
Definition: xrt_frame.h:25
An object to send IMU samples to.
Definition: xrt_tracking.h:169
void u_imu_sink_force_monotonic_create(struct xrt_frame_context *xfctx, struct xrt_imu_sink *downstream, struct xrt_imu_sink **out_imu_sink)
Definition: u_imu_sink_force_monotonic.c:74
void u_imu_sink_split_create(struct xrt_frame_context *xfctx, struct xrt_imu_sink *downstream_one, struct xrt_imu_sink *downstream_two, struct xrt_imu_sink **out_imu_sink)
Definition: u_imu_sink_split.c:60
void u_sink_stereo_sbs_to_slam_sbs_create(struct xrt_frame_context *xfctx, struct xrt_frame_sink *downstream_left, struct xrt_frame_sink *downstream_right, struct xrt_frame_sink **out_xfs)
Splits Stereo SBS frames into two independent frames.
Definition: u_sink_stereo_sbs_to_slam_sbs.c:89
bool u_sink_force_genlock_create(struct xrt_frame_context *xfctx, struct xrt_frame_sink *downstream_left, struct xrt_frame_sink *downstream_right, struct xrt_frame_sink **out_left_xfs, struct xrt_frame_sink **out_right_xfs)
Enforces left-right push order on frames and forces them to be within a reasonable amount of time fro...
Definition: u_sink_force_genlock.c:260
bool u_sink_combiner_create(struct xrt_frame_context *xfctx, struct xrt_frame_sink *downstream, struct xrt_frame_sink **out_left_xfs, struct xrt_frame_sink **out_right_xfs)
Combines stereo frames.
Definition: u_sink_combiner.c:280
xrt_format
Common formats, use u_format_* functions to reason about them.
Definition: xrt_defines.h:177
Data frame header.
Header defining the tracking system integration in Monado.