Monado OpenXR Runtime
Loading...
Searching...
No Matches
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 "xrt/xrt_frame.h"
14#include "xrt/xrt_tracking.h"
15
16#include "os/os_threading.h"
17
19
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#define U_SINK_MAX_SPLIT_DOWNSTREAMS 5
26
27/*!
28 * @see u_sink_quirk_create
29 */
31{
32 //! Marks frames passing through as side-by-side stereo.
34 /*!
35 * Marks the frames passing through as side-by-side stereo, and fixes up the camera's data offset to be readable
36 * as a standard side-by-side frame.
37 */
38 bool ps4_cam;
39 //! Sets the stereo format to the correct one for the leap motion and fixes image width.
41 //! Reinterprets a raw bayer image as a monochrome L8 image.
43};
44
45/*!
46 * @public @memberof xrt_frame_sink
47 * @see xrt_frame_context
48 */
49void
50u_sink_create_format_converter(struct xrt_frame_context *xfctx,
51 enum xrt_format f,
52 struct xrt_frame_sink *downstream,
53 struct xrt_frame_sink **out_xfs);
54
55/*!
56 * @public @memberof xrt_frame_sink
57 * @see xrt_frame_context
58 */
59void
60u_sink_create_to_r8g8b8_or_l8(struct xrt_frame_context *xfctx,
61 struct xrt_frame_sink *downstream,
62 struct xrt_frame_sink **out_xfs);
63
64/*!
65 * @public @memberof xrt_frame_sink
66 * @see xrt_frame_context
67 */
68void
69u_sink_create_to_r8g8b8_bayer_or_l8(struct xrt_frame_context *xfctx,
70 struct xrt_frame_sink *downstream,
71 struct xrt_frame_sink **out_xfs);
72
73/*!
74 * @public @memberof xrt_frame_sink
75 * @see xrt_frame_context
76 */
77void
78u_sink_create_to_rgb_yuv_yuyv_uyvy_or_l8(struct xrt_frame_context *xfctx,
79 struct xrt_frame_sink *downstream,
80 struct xrt_frame_sink **out_xfs);
81
82/*!
83 * @public @memberof xrt_frame_sink
84 * @see xrt_frame_context
85 */
86void
87u_sink_create_to_yuv_yuyv_uyvy_or_l8(struct xrt_frame_context *xfctx,
88 struct xrt_frame_sink *downstream,
89 struct xrt_frame_sink **out_xfs);
90
91/*!
92 * @public @memberof xrt_frame_sink
93 * @see xrt_frame_context
94 */
95void
96u_sink_create_to_yuv_or_yuyv(struct xrt_frame_context *xfctx,
97 struct xrt_frame_sink *downstream,
98 struct xrt_frame_sink **out_xfs);
99
100void
101u_sink_create_half_scale(struct xrt_frame_context *xfctx,
102 struct xrt_frame_sink *downstream,
103 struct xrt_frame_sink **out_xfs);
104
105/*!
106 * @public @memberof xrt_frame_sink
107 * @see xrt_frame_context
108 */
109void
110u_sink_create_to_r8g8b8_r8g8b8a8_r8g8b8x8_or_l8(struct xrt_frame_context *xfctx,
111 struct xrt_frame_sink *downstream,
112 struct xrt_frame_sink **out_xfs);
113/*!
114 * @public @memberof xrt_frame_sink
115 * @see xrt_frame_context
116 */
117void
118u_sink_deinterleaver_create(struct xrt_frame_context *xfctx,
119 struct xrt_frame_sink *downstream,
120 struct xrt_frame_sink **out_xfs);
121
122/*!
123 * @public @memberof xrt_frame_sink
124 * @see xrt_frame_context
125 */
126bool
127u_sink_queue_create(struct xrt_frame_context *xfctx,
128 uint64_t max_size,
129 struct xrt_frame_sink *downstream,
130 struct xrt_frame_sink **out_xfs);
131
132
133/*!
134 * @public @memberof xrt_frame_sink
135 * @see xrt_frame_context
136 */
137bool
138u_sink_simple_queue_create(struct xrt_frame_context *xfctx,
139 struct xrt_frame_sink *downstream,
140 struct xrt_frame_sink **out_xfs);
141
142/*!
143 * @public @memberof xrt_frame_sink
144 * @see xrt_frame_context
145 */
146void
147u_sink_quirk_create(struct xrt_frame_context *xfctx,
148 struct xrt_frame_sink *downstream,
149 struct u_sink_quirk_params *params,
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 a maximum of U_SINK_MAX_SPLIT_DOWNSTREAMS sinks
156 */
157void
158u_sink_split_multi_create(struct xrt_frame_context *xfctx,
159 struct xrt_frame_sink **downstreams,
160 size_t downstream_count,
161 struct xrt_frame_sink **out_xfs);
162
163/*!
164 * @public @memberof xrt_frame_sink
165 * @see xrt_frame_context
166 * Takes a frame and pushes it to two sinks
167 */
168void
169u_sink_split_create(struct xrt_frame_context *xfctx,
170 struct xrt_frame_sink *left,
171 struct xrt_frame_sink *right,
172 struct xrt_frame_sink **out_xfs);
173
174/*!
175 * Splits Stereo SBS frames into two independent frames
176 */
177void
179 struct xrt_frame_sink *downstream_left,
180 struct xrt_frame_sink *downstream_right,
181 struct xrt_frame_sink **out_xfs);
182
183/*!
184 * Combines stereo frames.
185 * Opposite of u_sink_stereo_sbs_split_create
186 */
187bool
189 struct xrt_frame_sink *downstream,
190 struct xrt_frame_sink **out_left_xfs,
191 struct xrt_frame_sink **out_right_xfs);
192
193/*!
194 * Enforces left-right push order on frames and forces them to be within a reasonable amount of time from each other
195 */
196bool
198 struct xrt_frame_sink *downstream_left,
199 struct xrt_frame_sink *downstream_right,
200 struct xrt_frame_sink **out_left_xfs,
201 struct xrt_frame_sink **out_right_xfs);
202
203
204/*
205 *
206 * Debugging sink,
207 *
208 */
209
210/*!
211 * Allows more safely to debug sink inputs and outputs.
212 */
214{
215 //! Is initialised/destroyed when added or root is removed.
217
218 // Protected by mutex, mutex must be held when frame is being pushed.
219 struct xrt_frame_sink *sink;
220};
221
222static inline void
223u_sink_debug_init(struct u_sink_debug *usd)
224{
225 os_mutex_init(&usd->mutex);
226}
227
228static inline bool
229u_sink_debug_is_active(struct u_sink_debug *usd)
230{
231 os_mutex_lock(&usd->mutex);
232 bool active = usd->sink != NULL;
233 os_mutex_unlock(&usd->mutex);
234
235 return active;
236}
237
238static inline void
239u_sink_debug_push_frame(struct u_sink_debug *usd, struct xrt_frame *xf)
240{
241 os_mutex_lock(&usd->mutex);
242 if (usd->sink != NULL) {
243 xrt_sink_push_frame(usd->sink, xf);
244 }
245 os_mutex_unlock(&usd->mutex);
246}
247
248static inline void
249u_sink_debug_set_sink(struct u_sink_debug *usd, struct xrt_frame_sink *xfs)
250{
251 os_mutex_lock(&usd->mutex);
252 usd->sink = xfs;
253 os_mutex_unlock(&usd->mutex);
254}
255
256static inline void
257u_sink_debug_destroy(struct u_sink_debug *usd)
258{
259 os_mutex_destroy(&usd->mutex);
260}
261
262
263/*!
264 * @public @memberof xrt_imu_sink
265 * @see xrt_frame_context
266 * Takes an IMU sample and pushes it to two sinks
267 */
268void
269u_imu_sink_split_create(struct xrt_frame_context *xfctx,
270 struct xrt_imu_sink *downstream_one,
271 struct xrt_imu_sink *downstream_two,
272 struct xrt_imu_sink **out_imu_sink);
273
274
275/*!
276 * @public @memberof xrt_imu_sink
277 * @see xrt_frame_context
278 * Takes an IMU sample and only pushes it if its timestamp has monotonically increased.
279 * Useful for handling hardware inconsistencies.
280 */
281void
282u_imu_sink_force_monotonic_create(struct xrt_frame_context *xfctx,
283 struct xrt_imu_sink *downstream,
284 struct xrt_imu_sink **out_imu_sink);
285
286
287/*!
288 * @public @memberof xrt_blob_sink
289 * @see xrt_frame_context
290 * Visualizes blobs by rendering them to a frame and pushing that frame to a downstream sink.
291 * Useful for debugging blob detection.
292 *
293 * @param[in] xfctx The frame context to add this sink to.
294 * @param[in] downstream_blob_sink The blob sink to forward the blobs to.
295 * @param[in] downstream_frame_sink The frame sink to push the visualized frames to.
296 * @param[in] frame_width The width of the frames to render the blobs to.
297 * @param[in] frame_height The height of the frames to render the blobs to.
298 * @param[out] out_xbs The created blob sink.
299 */
300void
301u_sink_blob_visualizer_create(struct xrt_frame_context *xfctx,
302 struct t_blob_sink *downstream_blob_sink,
303 struct u_sink_debug *downstream_frame_sink,
304 uint32_t frame_width,
305 uint32_t frame_height,
306 struct t_blob_sink **out_xbs);
307
308
309#ifdef __cplusplus
310}
311#endif
Wrapper around OS threading native functions.
A wrapper around a native mutex.
Definition os_threading.h:69
A generic interface to allow a tracking system to receive "snapshots" of seen t_blob in a frame.
Definition t_constellation.h:86
Allows more safely to debug sink inputs and outputs.
Definition u_sink.h:214
struct os_mutex mutex
Is initialised/destroyed when added or root is removed.
Definition u_sink.h:216
Definition u_sink.h:31
bool stereo_sbs
Marks frames passing through as side-by-side stereo.
Definition u_sink.h:33
bool bayer_as_l8
Reinterprets a raw bayer image as a monochrome L8 image.
Definition u_sink.h:42
bool leap_motion
Sets the stereo format to the correct one for the leap motion and fixes image width.
Definition u_sink.h:40
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:38
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
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
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:173
Header defining the tracking system integration in Monado.
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
void u_sink_stereo_sbs_split_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_split.c:89
xrt_format
Common formats, use u_format_* functions to reason about them.
Definition xrt_defines.h:193
Data frame header.
Header defining the tracking system integration in Monado.