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 //! Marks frames passing through as side-by-side stereo.
31 /*!
32 * Marks the frames passing through as side-by-side stereo, and fixes up the camera's data offset to be readable
33 * as a standard side-by-side frame.
34 */
35 bool ps4_cam;
36 //! Sets the stereo format to the correct one for the leap motion and fixes image width.
38 //! Reinterprets a raw bayer image as a monochrome L8 image.
40};
41
42/*!
43 * @public @memberof xrt_frame_sink
44 * @see xrt_frame_context
45 */
46void
48 enum xrt_format f,
49 struct xrt_frame_sink *downstream,
50 struct xrt_frame_sink **out_xfs);
51
52/*!
53 * @public @memberof xrt_frame_sink
54 * @see xrt_frame_context
55 */
56void
58 struct xrt_frame_sink *downstream,
59 struct xrt_frame_sink **out_xfs);
60
61/*!
62 * @public @memberof xrt_frame_sink
63 * @see xrt_frame_context
64 */
65void
67 struct xrt_frame_sink *downstream,
68 struct xrt_frame_sink **out_xfs);
69
70/*!
71 * @public @memberof xrt_frame_sink
72 * @see xrt_frame_context
73 */
74void
76 struct xrt_frame_sink *downstream,
77 struct xrt_frame_sink **out_xfs);
78
79/*!
80 * @public @memberof xrt_frame_sink
81 * @see xrt_frame_context
82 */
83void
85 struct xrt_frame_sink *downstream,
86 struct xrt_frame_sink **out_xfs);
87
88/*!
89 * @public @memberof xrt_frame_sink
90 * @see xrt_frame_context
91 */
92void
94 struct xrt_frame_sink *downstream,
95 struct xrt_frame_sink **out_xfs);
96
97void
98u_sink_create_half_scale(struct xrt_frame_context *xfctx,
99 struct xrt_frame_sink *downstream,
100 struct xrt_frame_sink **out_xfs);
101
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 * @public @memberof xrt_frame_sink
112 * @see xrt_frame_context
113 */
114void
116 struct xrt_frame_sink *downstream,
117 struct xrt_frame_sink **out_xfs);
118
119/*!
120 * @public @memberof xrt_frame_sink
121 * @see xrt_frame_context
122 */
123bool
125 uint64_t max_size,
126 struct xrt_frame_sink *downstream,
127 struct xrt_frame_sink **out_xfs);
128
129
130/*!
131 * @public @memberof xrt_frame_sink
132 * @see xrt_frame_context
133 */
134bool
136 struct xrt_frame_sink *downstream,
137 struct xrt_frame_sink **out_xfs);
138
139/*!
140 * @public @memberof xrt_frame_sink
141 * @see xrt_frame_context
142 */
143void
145 struct xrt_frame_sink *downstream,
146 struct u_sink_quirk_params *params,
147 struct xrt_frame_sink **out_xfs);
148
149/*!
150 * @public @memberof xrt_frame_sink
151 * @see xrt_frame_context
152 * Takes a frame and pushes it to a maximum of U_SINK_MAX_SPLIT_DOWNSTREAMS sinks
153 */
154void
156 struct xrt_frame_sink **downstreams,
157 size_t downstream_count,
158 struct xrt_frame_sink **out_xfs);
159
160/*!
161 * @public @memberof xrt_frame_sink
162 * @see xrt_frame_context
163 * Takes a frame and pushes it to two sinks
164 */
165void
167 struct xrt_frame_sink *left,
168 struct xrt_frame_sink *right,
169 struct xrt_frame_sink **out_xfs);
170
171/*!
172 * Splits Stereo SBS frames into two independent frames
173 */
174void
176 struct xrt_frame_sink *downstream_left,
177 struct xrt_frame_sink *downstream_right,
178 struct xrt_frame_sink **out_xfs);
179
180/*!
181 * Combines stereo frames.
182 * Opposite of u_sink_stereo_sbs_to_slam_sbs_create
183 */
184bool
186 struct xrt_frame_sink *downstream,
187 struct xrt_frame_sink **out_left_xfs,
188 struct xrt_frame_sink **out_right_xfs);
189
190/*!
191 * Enforces left-right push order on frames and forces them to be within a reasonable amount of time from each other
192 */
193bool
195 struct xrt_frame_sink *downstream_left,
196 struct xrt_frame_sink *downstream_right,
197 struct xrt_frame_sink **out_left_xfs,
198 struct xrt_frame_sink **out_right_xfs);
199
200
201/*
202 *
203 * Debugging sink,
204 *
205 */
206
207/*!
208 * Allows more safely to debug sink inputs and outputs.
209 */
211{
212 //! Is initialised/destroyed when added or root is removed.
214
215 // Protected by mutex, mutex must be held when frame is being pushed.
216 struct xrt_frame_sink *sink;
217};
218
219static inline void
220u_sink_debug_init(struct u_sink_debug *usd)
221{
222 os_mutex_init(&usd->mutex);
223}
224
225static inline bool
226u_sink_debug_is_active(struct u_sink_debug *usd)
227{
228 os_mutex_lock(&usd->mutex);
229 bool active = usd->sink != NULL;
230 os_mutex_unlock(&usd->mutex);
231
232 return active;
233}
234
235static inline void
236u_sink_debug_push_frame(struct u_sink_debug *usd, struct xrt_frame *xf)
237{
238 os_mutex_lock(&usd->mutex);
239 if (usd->sink != NULL) {
240 xrt_sink_push_frame(usd->sink, xf);
241 }
242 os_mutex_unlock(&usd->mutex);
243}
244
245static inline void
246u_sink_debug_set_sink(struct u_sink_debug *usd, struct xrt_frame_sink *xfs)
247{
248 os_mutex_lock(&usd->mutex);
249 usd->sink = xfs;
250 os_mutex_unlock(&usd->mutex);
251}
252
253static inline void
254u_sink_debug_destroy(struct u_sink_debug *usd)
255{
256 os_mutex_destroy(&usd->mutex);
257}
258
259
260/*!
261 * @public @memberof xrt_imu_sink
262 * @see xrt_frame_context
263 * Takes an IMU sample and pushes it to two sinks
264 */
265void
267 struct xrt_imu_sink *downstream_one,
268 struct xrt_imu_sink *downstream_two,
269 struct xrt_imu_sink **out_imu_sink);
270
271
272/*!
273 * @public @memberof xrt_imu_sink
274 * @see xrt_frame_context
275 * Takes an IMU sample and only pushes it if its timestamp has monotonically increased.
276 * Useful for handling hardware inconsistencies.
277 */
278void
280 struct xrt_imu_sink *downstream,
281 struct xrt_imu_sink **out_imu_sink);
282
283
284#ifdef __cplusplus
285}
286#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:211
struct os_mutex mutex
Is initialised/destroyed when added or root is removed.
Definition: u_sink.h:213
Definition: u_sink.h:28
bool stereo_sbs
Marks frames passing through as side-by-side stereo.
Definition: u_sink.h:30
bool bayer_as_l8
Reinterprets a raw bayer image as a monochrome L8 image.
Definition: u_sink.h:39
bool leap_motion
Sets the stereo format to the correct one for the leap motion and fixes image width.
Definition: u_sink.h:37
bool ps4_cam
Marks the frames passing through as side-by-side stereo, and fixes up the camera's data offset to be ...
Definition: u_sink.h:35
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:1036
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:907
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:98
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:960
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:938
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:982
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:1000
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:1018
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:178
Data frame header.
Header defining the tracking system integration in Monado.