The open source OpenXR runtime

a/util: Make sink split support >2 downstreams

I needed this for the constellation tracker, as we have (in theory
unlimited) cameras running at once, and each camera gets it's own copy
of the frame. We hardcode a group of cameras of 5 right now.

This uses the same limit as the constellation tracker. This limit should
be increased whenever a usecase needs more than 5 downstreams.

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2498>

authored by

Beyley Cardellio and committed by
Marge Bot
799515f3 c6a7804c

+40 -10
+13
src/xrt/auxiliary/util/u_sink.h
··· 19 19 extern "C" { 20 20 #endif 21 21 22 + #define U_SINK_MAX_SPLIT_DOWNSTREAMS 5 23 + 22 24 /*! 23 25 * @see u_sink_quirk_create 24 26 */ ··· 135 137 struct xrt_frame_sink *downstream, 136 138 struct u_sink_quirk_params *params, 137 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 + */ 146 + void 147 + u_sink_split_multi_create(struct xrt_frame_context *xfctx, 148 + struct xrt_frame_sink **downstreams, 149 + size_t downstream_count, 150 + struct xrt_frame_sink **out_xfs); 138 151 139 152 /*! 140 153 * @public @memberof xrt_frame_sink
+27 -10
src/xrt/auxiliary/util/u_sink_split.c
··· 22 22 struct xrt_frame_sink base; 23 23 struct xrt_frame_node node; 24 24 25 - struct xrt_frame_sink *left; 26 - struct xrt_frame_sink *right; 25 + struct xrt_frame_sink *downstreams[U_SINK_MAX_SPLIT_DOWNSTREAMS]; 26 + size_t downstream_count; 27 27 }; 28 28 29 29 static void ··· 33 33 34 34 struct u_sink_split *s = (struct u_sink_split *)xfs; 35 35 36 - s->left->push_frame(s->left, xf); 37 - s->right->push_frame(s->right, xf); 36 + for (size_t i = 0; i < s->downstream_count; i++) { 37 + if (s->downstreams[i]) { 38 + xrt_sink_push_frame(s->downstreams[i], xf); 39 + } 40 + } 38 41 } 39 42 40 43 static void ··· 59 62 */ 60 63 61 64 void 62 - u_sink_split_create(struct xrt_frame_context *xfctx, 63 - struct xrt_frame_sink *left, 64 - struct xrt_frame_sink *right, 65 - struct xrt_frame_sink **out_xfs) 65 + u_sink_split_multi_create(struct xrt_frame_context *xfctx, 66 + struct xrt_frame_sink **downstreams, 67 + size_t downstream_count, 68 + struct xrt_frame_sink **out_xfs) 66 69 { 70 + assert(downstream_count <= U_SINK_MAX_SPLIT_DOWNSTREAMS); 71 + 67 72 struct u_sink_split *s = U_TYPED_CALLOC(struct u_sink_split); 68 73 69 74 s->base.push_frame = split_frame; 70 75 s->node.break_apart = split_break_apart; 71 76 s->node.destroy = split_destroy; 72 - s->left = left; 73 - s->right = right; 77 + 78 + memcpy(s->downstreams, downstreams, sizeof(s->downstreams[0]) * downstream_count); 79 + s->downstream_count = downstream_count; 74 80 75 81 xrt_frame_context_add(xfctx, &s->node); 76 82 77 83 *out_xfs = &s->base; 78 84 } 85 + 86 + void 87 + u_sink_split_create(struct xrt_frame_context *xfctx, 88 + struct xrt_frame_sink *left, 89 + struct xrt_frame_sink *right, 90 + struct xrt_frame_sink **out_xfs) 91 + { 92 + struct xrt_frame_sink *downstreams[2] = {left, right}; 93 + 94 + u_sink_split_multi_create(xfctx, downstreams, 2, out_xfs); 95 + }