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/*!
23 * @see u_sink_quirk_create
24 */
26{
27 bool stereo_sbs;
28 bool ps4_cam;
29 bool leap_motion;
30};
31
32/*!
33 * @public @memberof xrt_frame_sink
34 * @see xrt_frame_context
35 */
36void
38 enum xrt_format f,
39 struct xrt_frame_sink *downstream,
40 struct xrt_frame_sink **out_xfs);
41
42/*!
43 * @public @memberof xrt_frame_sink
44 * @see xrt_frame_context
45 */
46void
48 struct xrt_frame_sink *downstream,
49 struct xrt_frame_sink **out_xfs);
50
51/*!
52 * @public @memberof xrt_frame_sink
53 * @see xrt_frame_context
54 */
55void
57 struct xrt_frame_sink *downstream,
58 struct xrt_frame_sink **out_xfs);
59
60/*!
61 * @public @memberof xrt_frame_sink
62 * @see xrt_frame_context
63 */
64void
66 struct xrt_frame_sink *downstream,
67 struct xrt_frame_sink **out_xfs);
68
69/*!
70 * @public @memberof xrt_frame_sink
71 * @see xrt_frame_context
72 */
73void
75 struct xrt_frame_sink *downstream,
76 struct xrt_frame_sink **out_xfs);
77
78/*!
79 * @public @memberof xrt_frame_sink
80 * @see xrt_frame_context
81 */
82void
84 struct xrt_frame_sink *downstream,
85 struct xrt_frame_sink **out_xfs);
86
87void
88u_sink_create_half_scale(struct xrt_frame_context *xfctx,
89 struct xrt_frame_sink *downstream,
90 struct xrt_frame_sink **out_xfs);
91
92/*!
93 * @public @memberof xrt_frame_sink
94 * @see xrt_frame_context
95 */
96void
98 struct xrt_frame_sink *downstream,
99 struct xrt_frame_sink **out_xfs);
100/*!
101 * @public @memberof xrt_frame_sink
102 * @see xrt_frame_context
103 */
104void
106 struct xrt_frame_sink *downstream,
107 struct xrt_frame_sink **out_xfs);
108
109/*!
110 * @public @memberof xrt_frame_sink
111 * @see xrt_frame_context
112 */
113bool
115 uint64_t max_size,
116 struct xrt_frame_sink *downstream,
117 struct xrt_frame_sink **out_xfs);
118
119
120/*!
121 * @public @memberof xrt_frame_sink
122 * @see xrt_frame_context
123 */
124bool
126 struct xrt_frame_sink *downstream,
127 struct xrt_frame_sink **out_xfs);
128
129/*!
130 * @public @memberof xrt_frame_sink
131 * @see xrt_frame_context
132 */
133void
135 struct xrt_frame_sink *downstream,
136 struct u_sink_quirk_params *params,
137 struct xrt_frame_sink **out_xfs);
138
139/*!
140 * @public @memberof xrt_frame_sink
141 * @see xrt_frame_context
142 * Takes a frame and pushes it to two sinks
143 */
144void
146 struct xrt_frame_sink *left,
147 struct xrt_frame_sink *right,
148 struct xrt_frame_sink **out_xfs);
149
150/*!
151 * Splits Stereo SBS frames into two independent frames
152 */
153void
155 struct xrt_frame_sink *downstream_left,
156 struct xrt_frame_sink *downstream_right,
157 struct xrt_frame_sink **out_xfs);
158
159/*!
160 * Combines stereo frames.
161 * Opposite of u_sink_stereo_sbs_to_slam_sbs_create
162 */
163bool
165 struct xrt_frame_sink *downstream,
166 struct xrt_frame_sink **out_left_xfs,
167 struct xrt_frame_sink **out_right_xfs);
168
169/*!
170 * Enforces left-right push order on frames and forces them to be within a reasonable amount of time from each other
171 */
172bool
174 struct xrt_frame_sink *downstream_left,
175 struct xrt_frame_sink *downstream_right,
176 struct xrt_frame_sink **out_left_xfs,
177 struct xrt_frame_sink **out_right_xfs);
178
179
180/*
181 *
182 * Debugging sink,
183 *
184 */
185
186/*!
187 * Allows more safely to debug sink inputs and outputs.
188 */
190{
191 //! Is initialised/destroyed when added or root is removed.
193
194 // Protected by mutex, mutex must be held when frame is being pushed.
195 struct xrt_frame_sink *sink;
196};
197
198static inline void
199u_sink_debug_init(struct u_sink_debug *usd)
200{
201 os_mutex_init(&usd->mutex);
202}
203
204static inline bool
205u_sink_debug_is_active(struct u_sink_debug *usd)
206{
207 os_mutex_lock(&usd->mutex);
208 bool active = usd->sink != NULL;
209 os_mutex_unlock(&usd->mutex);
210
211 return active;
212}
213
214static inline void
215u_sink_debug_push_frame(struct u_sink_debug *usd, struct xrt_frame *xf)
216{
217 os_mutex_lock(&usd->mutex);
218 if (usd->sink != NULL) {
219 xrt_sink_push_frame(usd->sink, xf);
220 }
221 os_mutex_unlock(&usd->mutex);
222}
223
224static inline void
225u_sink_debug_set_sink(struct u_sink_debug *usd, struct xrt_frame_sink *xfs)
226{
227 os_mutex_lock(&usd->mutex);
228 usd->sink = xfs;
229 os_mutex_unlock(&usd->mutex);
230}
231
232static inline void
233u_sink_debug_destroy(struct u_sink_debug *usd)
234{
235 os_mutex_destroy(&usd->mutex);
236}
237
238
239/*!
240 * @public @memberof xrt_imu_sink
241 * @see xrt_frame_context
242 * Takes an IMU sample and pushes it to two sinks
243 */
244void
246 struct xrt_imu_sink *downstream_one,
247 struct xrt_imu_sink *downstream_two,
248 struct xrt_imu_sink **out_imu_sink);
249
250
251/*!
252 * @public @memberof xrt_imu_sink
253 * @see xrt_frame_context
254 * Takes an IMU sample and only pushes it if its timestamp has monotonically increased.
255 * Useful for handling hardware inconsistencies.
256 */
257void
259 struct xrt_imu_sink *downstream,
260 struct xrt_imu_sink **out_imu_sink);
261
262
263#ifdef __cplusplus
264}
265#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:190
struct os_mutex mutex
Is initialised/destroyed when added or root is removed.
Definition: u_sink.h:192
Definition: u_sink.h:26
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:1010
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:881
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:934
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:912
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:62
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:956
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:974
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:992
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:176
Data frame header.
Header defining the tracking system integration in Monado.