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  * @interface xrt_frame_sink
48  *
49  * A object that is sent frames.
50  *
51  * All objects that implement @ref xrt_frame_sink **must** also implement @ref
52  * xrt_frame_node, and should take an @ref xrt_frame_context to register
53  * themselves with in their constructor.
54  *
55  * @ingroup xrt_iface
56  */
58 {
59  /*!
60  * Push a frame into the sink.
61  */
62  void (*push_frame)(struct xrt_frame_sink *sink, struct xrt_frame *frame);
63 };
64 
65 /*!
66  * @copydoc xrt_frame_sink::push_frame
67  *
68  * Helper for calling through the function pointer.
69  *
70  * @public @memberof xrt_frame_sink
71  */
72 static inline void
74 {
75  sink->push_frame(sink, frame);
76 }
77 
78 /*!
79  * @interface xrt_frame_node
80  *
81  * A interface object used for destroying a frame graph.
82  *
83  * @see container_of
84  * @ingroup xrt_iface
85  */
87 {
88  struct xrt_frame_node *next;
89 
90  /*!
91  * Called first in when the graph is being destroyed, remove any
92  * references frames and other objects and stop threads.
93  */
94  void (*break_apart)(struct xrt_frame_node *node);
95 
96  /*!
97  * Do the actual freeing of the objects.
98  */
99  void (*destroy)(struct xrt_frame_node *node);
100 };
101 
102 /*!
103  * Object used to track all sinks and frame producers in a graph.
104  *
105  * @ingroup xrt_iface
106  */
108 {
109  struct xrt_frame_node *nodes;
110 };
111 
112 
113 /*
114  *
115  * Inline functions.
116  *
117  */
118 
119 /*!
120  * Update the reference counts on frame(s).
121  *
122  * @param[in,out] dst Pointer to a object reference: if the object reference is
123  * non-null will decrement its counter. The reference that
124  * @p dst points to will be set to @p src.
125  * @param[in] src New object for @p dst to refer to (may be null).
126  * If non-null, will have its refcount increased.
127  * @ingroup xrt_iface
128  * @relates xrt_frame
129  */
130 static inline void
131 xrt_frame_reference(struct xrt_frame **dst, struct xrt_frame *src)
132 {
133  struct xrt_frame *old_dst = *dst;
134 
135  if (old_dst == src) {
136  return;
137  }
138 
139  if (src) {
140  xrt_reference_inc(&src->reference);
141  }
142 
143  *dst = src;
144 
145  if (old_dst) {
146  if (xrt_reference_dec_and_is_zero(&old_dst->reference)) {
147  old_dst->destroy(old_dst);
148  }
149  }
150 }
151 
152 /*!
153  * Add a node to a context.
154  *
155  * @public @memberof xrt_frame_context
156  */
157 static inline void
159 {
160  node->next = xfctx->nodes;
161  xfctx->nodes = node;
162 }
163 
164 /*!
165  * Destroy all child nodes, but do not free the context itself.
166  *
167  * @public @memberof xrt_frame_context
168  */
169 static inline void
171 {
172  struct xrt_frame_node *next = NULL;
173  struct xrt_frame_node *node = xfctx->nodes;
174 
175  while (node != NULL) {
176  next = node->next;
177  node->break_apart(node);
178  node = next;
179  }
180 
181  node = xfctx->nodes;
182  while (node != NULL) {
183  next = node->next;
184  node->destroy(node);
185  node = next;
186  }
187 
188  xfctx->nodes = NULL;
189 }
190 
191 
192 #ifdef __cplusplus
193 }
194 #endif
xrt_stereo_format
What type of stereo format a frame has.
Definition: xrt_defines.h:203
static XRT_CHECK_RESULT bool xrt_reference_dec_and_is_zero(struct xrt_reference *xref)
Decrement the reference and return true if the value is now zero.
Definition: xrt_defines.h:1598
static void xrt_reference_inc(struct xrt_reference *xref)
Increment the reference, probably want xrt_reference_inc_and_was_zero.
Definition: xrt_defines.h:1561
static void xrt_frame_reference(struct xrt_frame **dst, struct xrt_frame *src)
Update the reference counts on frame(s).
Definition: xrt_frame.h:131
Definition: u_pacing_compositor.c:55
Object used to track all sinks and frame producers in a graph.
Definition: xrt_frame.h:108
static void xrt_frame_context_add(struct xrt_frame_context *xfctx, struct xrt_frame_node *node)
Add a node to a context.
Definition: xrt_frame.h:158
static void xrt_frame_context_destroy_nodes(struct xrt_frame_context *xfctx)
Destroy all child nodes, but do not free the context itself.
Definition: xrt_frame.h:170
A interface object used for destroying a frame graph.
Definition: xrt_frame.h:87
void(* destroy)(struct xrt_frame_node *node)
Do the actual freeing of the objects.
Definition: xrt_frame.h:99
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:94
A object that is sent frames.
Definition: xrt_frame.h:58
void(* push_frame)(struct xrt_frame_sink *sink, struct xrt_frame *frame)
Push a frame into the sink.
Definition: xrt_frame.h: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
Basic frame data structure - holds a pointer to buffer.
Definition: xrt_frame.h:25
uint64_t source_sequence
sequence id
Definition: xrt_frame.h:41
uint64_t source_id
Which xrt_fs this frame originated from.
Definition: xrt_frame.h:42
A base class for reference counted objects.
Definition: xrt_defines.h:96
Common defines and enums for XRT.
xrt_format
Common formats, use u_format_* functions to reason about them.
Definition: xrt_defines.h:176