diff --git a/src/xrt/auxiliary/CMakeLists.txt b/src/xrt/auxiliary/CMakeLists.txt index 8a4ecf041..7848ab8c4 100644 --- a/src/xrt/auxiliary/CMakeLists.txt +++ b/src/xrt/auxiliary/CMakeLists.txt @@ -45,6 +45,7 @@ set(UTIL_SOURCE_FILES util/u_sink.h util/u_sink_converter.c util/u_sink_queue.c + util/u_sink_split.c util/u_time.cpp util/u_time.h util/u_var.cpp diff --git a/src/xrt/auxiliary/util/u_sink.h b/src/xrt/auxiliary/util/u_sink.h index bc74d9b6b..7a374f2e1 100644 --- a/src/xrt/auxiliary/util/u_sink.h +++ b/src/xrt/auxiliary/util/u_sink.h @@ -32,6 +32,12 @@ u_sink_queue_create(struct xrt_frame_context *xfctx, struct xrt_frame_sink *downstream, struct xrt_frame_sink **out_xfs); +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); + #ifdef __cplusplus } diff --git a/src/xrt/auxiliary/util/u_sink_split.c b/src/xrt/auxiliary/util/u_sink_split.c new file mode 100644 index 000000000..b0f94c7ae --- /dev/null +++ b/src/xrt/auxiliary/util/u_sink_split.c @@ -0,0 +1,66 @@ +// Copyright 2019, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief A @ref xrt_frame_sink splitter. + * @author Jakob Bornecrantz + * @ingroup aux_util + */ + +#include "util/u_misc.h" +#include "util/u_sink.h" + + +struct u_sink_split +{ + struct xrt_frame_sink base; + struct xrt_frame_node node; + + struct xrt_frame_sink *left; + struct xrt_frame_sink *right; +}; + +static void +split_frame(struct xrt_frame_sink *xfs, struct xrt_frame *xf) +{ + struct u_sink_split *s = (struct u_sink_split *)xfs; + + s->left->push_frame(s->left, xf); + s->right->push_frame(s->right, xf); +} + +static void +break_apart(struct xrt_frame_node *node) +{} + +static void +destroy(struct xrt_frame_node *node) +{ + struct u_sink_split *s = container_of(node, struct u_sink_split, node); + + free(s); +} + + +/* + * + * Exported functions. + * + */ + +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) +{ + struct u_sink_split *s = U_TYPED_CALLOC(struct u_sink_split); + + s->base.push_frame = split_frame; + s->node.break_apart = break_apart; + s->node.destroy = destroy; + s->left = left; + s->right = right; + + *out_xfs = &s->base; +}