Monado OpenXR Runtime
xrt_frame.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Data frame header.
6  * @author Jakob Bornecrantz <jakob@collabora.com>
7  * @ingroup xrt_iface
8  */
9 
10 #pragma once
11 
12 #include "xrt/xrt_defines.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 
19 /*!
20  * Basic frame data structure - holds a pointer to buffer.
21  *
22  * @ingroup xrt_iface
23  */
24 struct xrt_frame
25 {
26  struct xrt_reference reference;
27  void (*destroy)(struct xrt_frame *);
28  void *owner;
29 
30  uint32_t width;
31  uint32_t height;
32  size_t stride;
33  size_t size;
34  uint8_t *data;
35 
36  enum xrt_format format;
37  enum xrt_stereo_format stereo_format;
38 
39  uint64_t timestamp;
40  uint64_t source_timestamp;
41  uint64_t source_sequence; //!< sequence id
42  uint64_t source_id; //!< Which @ref xrt_fs this frame originated from.
43 };
44 
45 
46 /*!
47  * A object that is sent frames.
48  *
49  * @ingroup xrt_iface
50  */
52 {
53  /*!
54  * Push a frame into the sink.
55  */
56  void (*push_frame)(struct xrt_frame_sink *sink,
57  struct xrt_frame *frame);
58 };
59 
60 /*!
61  * A interface object used for destroying a frame graph.
62  *
63  * @see container_of
64  * @ingroup xrt_iface
65  */
67 {
68  struct xrt_frame_node *next;
69 
70  /*!
71  * Called first in when the graph is being destroyed, remove any
72  * references frames and other objects and stop threads.
73  */
74  void (*break_apart)(struct xrt_frame_node *node);
75 
76  /*!
77  * Do the actual freeing of the objects.
78  */
79  void (*destroy)(struct xrt_frame_node *node);
80 };
81 
82 /*!
83  * Object used to track all sinks and frame producers in a graph.
84  *
85  * @ingroup xrt_iface
86  */
88 {
89  struct xrt_frame_node *nodes;
90 };
91 
92 
93 /*
94  *
95  * Inline functions.
96  *
97  */
98 
99 /*!
100  * Update the reference counts on frame(s).
101  *
102  * @param dst Pointer to a object reference, if the object reference is
103  * non-null will decrement it's counter. The reference that
104  * @p dst points to will be set to @p src.
105  * @param[in] src Object to be have it's refcount increased @p dst is set to
106  * this.
107  * @ingroup xrt_iface
108  */
109 static inline void
110 xrt_frame_reference(struct xrt_frame **dst, struct xrt_frame *src)
111 {
112  struct xrt_frame *old_dst = *dst;
113 
114  if (old_dst == src) {
115  return;
116  }
117 
118  if (src) {
119  xrt_reference_inc(&src->reference);
120  }
121 
122  *dst = src;
123 
124  if (old_dst) {
125  if (xrt_reference_dec(&old_dst->reference)) {
126  old_dst->destroy(old_dst);
127  }
128  }
129 }
130 
131 /*!
132  * Add a node to a context.
133  *
134  * @ingroup xrt_iface
135  */
136 static inline void
137 xrt_frame_context_add(struct xrt_frame_context *xfctx,
138  struct xrt_frame_node *node)
139 {
140  node->next = xfctx->nodes;
141  xfctx->nodes = node;
142 }
143 
144 /*!
145  * Destroy all child nodes, but free the context itself.
146  *
147  * @ingroup xrt_iface
148  */
149 static inline void
150 xrt_frame_context_destroy_nodes(struct xrt_frame_context *xfctx)
151 {
152  struct xrt_frame_node *next = NULL;
153  struct xrt_frame_node *node = xfctx->nodes;
154 
155  while (node != NULL) {
156  next = node->next;
157  node->break_apart(node);
158  node = next;
159  }
160 
161  node = xfctx->nodes;
162  while (node != NULL) {
163  next = node->next;
164  node->destroy(node);
165  node = next;
166  }
167 
168  xfctx->nodes = NULL;
169 }
170 
171 
172 #ifdef __cplusplus
173 }
174 #endif
void(* destroy)(struct xrt_frame_node *node)
Do the actual freeing of the objects.
Definition: xrt_frame.h:79
void(* break_apart)(struct xrt_frame_node *node)
Called first in when the graph is being destroyed, remove any references frames and other objects and...
Definition: xrt_frame.h:74
xrt_stereo_format
What type of stereo format a frame has.
Definition: xrt_defines.h:84
A object that is sent frames.
Definition: xrt_frame.h:51
Common defines and enums for XRT.
Object used to track all sinks and frame producers in a graph.
Definition: xrt_frame.h:87
Basic frame data structure - holds a pointer to buffer.
Definition: xrt_frame.h:24
uint64_t source_id
Which xrt_fs this frame originated from.
Definition: xrt_frame.h:42
A interface object used for destroying a frame graph.
Definition: xrt_frame.h:66
uint64_t source_sequence
sequence id
Definition: xrt_frame.h:41
xrt_format
Common formats, use u_format_* functions to reason about them.
Definition: xrt_defines.h:60
A base class for reference counted objects.
Definition: xrt_defines.h:24