aux/util: Add split sink

This commit is contained in:
Jakob Bornecrantz 2019-09-03 10:07:20 +01:00
parent 798ef43342
commit 2abc98dbec
3 changed files with 73 additions and 0 deletions

View file

@ -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

View file

@ -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
}

View file

@ -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 <jakob@collabora.com>
* @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;
}