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 Moses Turner <moses@collabora.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
19 extern "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  */
36 void
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  */
46 void
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  */
55 void
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  */
64 void
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  */
73 void
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  */
82 void
84  struct xrt_frame_sink *downstream,
85  struct xrt_frame_sink **out_xfs);
86 
87 /*!
88  * @public @memberof xrt_frame_sink
89  * @see xrt_frame_context
90  */
91 void
93  struct xrt_frame_sink *downstream,
94  struct xrt_frame_sink **out_xfs);
95 /*!
96  * @public @memberof xrt_frame_sink
97  * @see xrt_frame_context
98  */
99 void
101  struct xrt_frame_sink *downstream,
102  struct xrt_frame_sink **out_xfs);
103 
104 /*!
105  * @public @memberof xrt_frame_sink
106  * @see xrt_frame_context
107  */
108 bool
110  uint64_t max_size,
111  struct xrt_frame_sink *downstream,
112  struct xrt_frame_sink **out_xfs);
113 
114 
115 /*!
116  * @public @memberof xrt_frame_sink
117  * @see xrt_frame_context
118  */
119 bool
121  struct xrt_frame_sink *downstream,
122  struct xrt_frame_sink **out_xfs);
123 
124 /*!
125  * @public @memberof xrt_frame_sink
126  * @see xrt_frame_context
127  */
128 void
130  struct xrt_frame_sink *downstream,
131  struct u_sink_quirk_params *params,
132  struct xrt_frame_sink **out_xfs);
133 
134 /*!
135  * @public @memberof xrt_frame_sink
136  * @see xrt_frame_context
137  * Takes a frame and pushes it to two sinks
138  */
139 void
141  struct xrt_frame_sink *left,
142  struct xrt_frame_sink *right,
143  struct xrt_frame_sink **out_xfs);
144 
145 /*!
146  * Splits Stereo SBS frames into two independent frames
147  */
148 void
150  struct xrt_frame_sink *downstream_left,
151  struct xrt_frame_sink *downstream_right,
152  struct xrt_frame_sink **out_xfs);
153 
154 /*!
155  * Combines stereo frames.
156  * Opposite of u_sink_stereo_sbs_to_slam_sbs_create
157  */
158 bool
160  struct xrt_frame_sink *downstream,
161  struct xrt_frame_sink **out_left_xfs,
162  struct xrt_frame_sink **out_right_xfs);
163 
164 /*!
165  * Enforces left-right push order on frames and forces them to be within a reasonable amount of time from each other
166  */
167 bool
169  struct xrt_frame_sink *downstream_left,
170  struct xrt_frame_sink *downstream_right,
171  struct xrt_frame_sink **out_left_xfs,
172  struct xrt_frame_sink **out_right_xfs);
173 
174 
175 /*
176  *
177  * Debugging sink,
178  *
179  */
180 
181 /*!
182  * Allows more safely to debug sink inputs and outputs.
183  */
185 {
186  //! Is initialised/destroyed when added or root is removed.
187  struct os_mutex mutex;
188 
189  // Protected by mutex, mutex must be held when frame is being pushed.
190  struct xrt_frame_sink *sink;
191 };
192 
193 static inline void
194 u_sink_debug_init(struct u_sink_debug *usd)
195 {
196  os_mutex_init(&usd->mutex);
197 }
198 
199 static inline bool
200 u_sink_debug_is_active(struct u_sink_debug *usd)
201 {
202  os_mutex_lock(&usd->mutex);
203  bool active = usd->sink != NULL;
204  os_mutex_unlock(&usd->mutex);
205 
206  return active;
207 }
208 
209 static inline void
210 u_sink_debug_push_frame(struct u_sink_debug *usd, struct xrt_frame *xf)
211 {
212  os_mutex_lock(&usd->mutex);
213  if (usd->sink != NULL) {
214  xrt_sink_push_frame(usd->sink, xf);
215  }
216  os_mutex_unlock(&usd->mutex);
217 }
218 
219 static inline void
220 u_sink_debug_set_sink(struct u_sink_debug *usd, struct xrt_frame_sink *xfs)
221 {
222  os_mutex_lock(&usd->mutex);
223  usd->sink = xfs;
224  os_mutex_unlock(&usd->mutex);
225 }
226 
227 static inline void
228 u_sink_debug_destroy(struct u_sink_debug *usd)
229 {
230  os_mutex_destroy(&usd->mutex);
231 }
232 
233 
234 /*!
235  * @public @memberof xrt_imu_sink
236  * @see xrt_frame_context
237  * Takes an IMU sample and pushes it to two sinks
238  */
239 void
241  struct xrt_imu_sink *downstream_one,
242  struct xrt_imu_sink *downstream_two,
243  struct xrt_imu_sink **out_imu_sink);
244 
245 
246 /*!
247  * @public @memberof xrt_imu_sink
248  * @see xrt_frame_context
249  * Takes an IMU sample and only pushes it if its timestamp has monotonically increased.
250  * Useful for handling hardware inconsistencies.
251  */
252 void
254  struct xrt_imu_sink *downstream,
255  struct xrt_imu_sink **out_imu_sink);
256 
257 
258 #ifdef __cplusplus
259 }
260 #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:185
struct os_mutex mutex
Is initialised/destroyed when added or root is removed.
Definition: u_sink.h:187
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:254
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:972
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:843
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:896
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:874
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:918
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:936
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:183
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:954
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:75
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:261
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:253
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.