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 {
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 
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 {
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 {
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
uint64_t timestamp
Definition: xrt_frame.h:39
uint32_t width
Definition: xrt_frame.h:30
struct xrt_frame_node * nodes
Definition: xrt_frame.h:89
struct xrt_reference reference
Definition: xrt_frame.h:26
uint64_t source_timestamp
Definition: xrt_frame.h:40
xrt_stereo_format
What type of stereo format a frame has.
Definition: xrt_defines.h:86
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
enum xrt_format format
Definition: xrt_frame.h:36
uint8_t * data
Definition: xrt_frame.h:34
struct xrt_frame_node * next
Definition: xrt_frame.h:68
void * owner
Definition: xrt_frame.h:28
xrt_format
Common formats, use u_format_* functions to reason about them.
Definition: xrt_defines.h:61
A base class for reference counted objects.
Definition: xrt_defines.h:25
uint32_t height
Definition: xrt_frame.h:31
size_t size
Definition: xrt_frame.h:33
enum xrt_stereo_format stereo_format
Definition: xrt_frame.h:37
void(* destroy)(struct xrt_frame *)
Definition: xrt_frame.h:27
size_t stride
Definition: xrt_frame.h:32