The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/vf: Tidy

authored by

Jakob Bornecrantz and committed by
Jakob Bornecrantz
f04a1136 162915f0

+133 -119
+133 -119
src/xrt/drivers/vf/vf_driver.c
··· 1 - // Copyright 2020, Collabora, Ltd. 1 + // Copyright 2020-2021, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file ··· 19 19 #include "util/u_frame.h" 20 20 #include "util/u_logging.h" 21 21 22 + #include "vf_interface.h" 22 23 23 24 #include <stdio.h> 24 25 #include <assert.h> 25 26 26 - #include "vf_interface.h" 27 - 27 + #include <glib.h> 28 28 #include <gst/gst.h> 29 29 #include <gst/app/gstappsink.h> 30 - #include <glib.h> 30 + #include <gst/video/video-frame.h> 31 + 31 32 32 33 /* 33 34 * ··· 90 91 enum u_logging_level ll; 91 92 }; 92 93 93 - /*! 94 - * Cast to derived type. 95 - */ 96 - static inline struct vf_fs * 97 - vf_fs(struct xrt_fs *xfs) 98 - { 99 - return (struct vf_fs *)xfs; 100 - } 101 94 102 95 /* 103 96 * ··· 105 98 * 106 99 */ 107 100 108 - 109 - /* 110 - * 111 - * Exported functions. 112 - * 101 + /*! 102 + * Cast to derived type. 113 103 */ 114 - 115 - static bool 116 - vf_fs_enumerate_modes(struct xrt_fs *xfs, struct xrt_fs_mode **out_modes, uint32_t *out_count) 117 - { 118 - struct vf_fs *vid = vf_fs(xfs); 119 - 120 - struct xrt_fs_mode *modes = U_TYPED_ARRAY_CALLOC(struct xrt_fs_mode, 1); 121 - if (modes == NULL) { 122 - return false; 123 - } 124 - 125 - modes[0].width = vid->width; 126 - modes[0].height = vid->height; 127 - modes[0].format = vid->format; 128 - modes[0].stereo_format = vid->stereo_format; 129 - 130 - *out_modes = modes; 131 - *out_count = 1; 132 - 133 - return true; 134 - } 135 - 136 - static bool 137 - vf_fs_configure_capture(struct xrt_fs *xfs, struct xrt_fs_capture_parameters *cp) 138 - { 139 - // struct vf_fs *vid = vf_fs(xfs); 140 - //! @todo 141 - return false; 142 - } 143 - 144 - static bool 145 - vf_fs_stream_start(struct xrt_fs *xfs, 146 - struct xrt_frame_sink *xs, 147 - enum xrt_fs_capture_type capture_type, 148 - uint32_t descriptor_index) 149 - { 150 - struct vf_fs *vid = vf_fs(xfs); 151 - 152 - vid->sink = xs; 153 - vid->is_running = true; 154 - vid->capture_type = capture_type; 155 - vid->selected = descriptor_index; 156 - 157 - gst_element_set_state(vid->source, GST_STATE_PLAYING); 158 - 159 - VF_TRACE(vid, "info: Started!"); 160 - 161 - // we're off to the races! 162 - return true; 163 - } 164 - 165 - static bool 166 - vf_fs_stream_stop(struct xrt_fs *xfs) 104 + static inline struct vf_fs * 105 + vf_fs(struct xrt_fs *xfs) 167 106 { 168 - struct vf_fs *vid = vf_fs(xfs); 169 - 170 - if (!vid->is_running) { 171 - return true; 172 - } 173 - 174 - vid->is_running = false; 175 - gst_element_set_state(vid->source, GST_STATE_PAUSED); 176 - 177 - return true; 178 - } 179 - 180 - static bool 181 - vf_fs_is_running(struct xrt_fs *xfs) 182 - { 183 - struct vf_fs *vid = vf_fs(xfs); 184 - 185 - GstState current = GST_STATE_NULL; 186 - GstState pending; 187 - gst_element_get_state(vid->source, &current, &pending, 0); 188 - 189 - return current == GST_STATE_PLAYING; 107 + return (struct vf_fs *)xfs; 190 108 } 191 109 192 110 static void 193 - vf_fs_destroy(struct vf_fs *vid) 194 - { 195 - g_main_loop_quit(vid->loop); 196 - 197 - os_thread_helper_stop(&vid->play_thread); 198 - os_thread_helper_destroy(&vid->play_thread); 199 - 200 - free(vid); 201 - } 202 - 203 - static void 204 - vf_fs_node_break_apart(struct xrt_frame_node *node) 205 - { 206 - struct vf_fs *vid = container_of(node, struct vf_fs, node); 207 - vf_fs_stream_stop(&vid->base); 208 - } 209 - 210 - static void 211 - vf_fs_node_destroy(struct xrt_frame_node *node) 212 - { 213 - struct vf_fs *vid = container_of(node, struct vf_fs, node); 214 - vf_fs_destroy(vid); 215 - } 216 - 217 - #include <gst/video/video-frame.h> 218 - 219 - void 220 111 vf_fs_frame(struct vf_fs *vid, GstSample *sample) 221 112 { 222 113 GstBuffer *buffer; ··· 345 236 346 237 return NULL; 347 238 } 239 + 240 + 241 + /* 242 + * 243 + * Frame server methods. 244 + * 245 + */ 246 + 247 + static bool 248 + vf_fs_enumerate_modes(struct xrt_fs *xfs, struct xrt_fs_mode **out_modes, uint32_t *out_count) 249 + { 250 + struct vf_fs *vid = vf_fs(xfs); 251 + 252 + struct xrt_fs_mode *modes = U_TYPED_ARRAY_CALLOC(struct xrt_fs_mode, 1); 253 + if (modes == NULL) { 254 + return false; 255 + } 256 + 257 + modes[0].width = vid->width; 258 + modes[0].height = vid->height; 259 + modes[0].format = vid->format; 260 + modes[0].stereo_format = vid->stereo_format; 261 + 262 + *out_modes = modes; 263 + *out_count = 1; 264 + 265 + return true; 266 + } 267 + 268 + static bool 269 + vf_fs_configure_capture(struct xrt_fs *xfs, struct xrt_fs_capture_parameters *cp) 270 + { 271 + // struct vf_fs *vid = vf_fs(xfs); 272 + //! @todo 273 + return false; 274 + } 275 + 276 + static bool 277 + vf_fs_stream_start(struct xrt_fs *xfs, 278 + struct xrt_frame_sink *xs, 279 + enum xrt_fs_capture_type capture_type, 280 + uint32_t descriptor_index) 281 + { 282 + struct vf_fs *vid = vf_fs(xfs); 283 + 284 + vid->sink = xs; 285 + vid->is_running = true; 286 + vid->capture_type = capture_type; 287 + vid->selected = descriptor_index; 288 + 289 + gst_element_set_state(vid->source, GST_STATE_PLAYING); 290 + 291 + VF_TRACE(vid, "info: Started!"); 292 + 293 + // we're off to the races! 294 + return true; 295 + } 296 + 297 + static bool 298 + vf_fs_stream_stop(struct xrt_fs *xfs) 299 + { 300 + struct vf_fs *vid = vf_fs(xfs); 301 + 302 + if (!vid->is_running) { 303 + return true; 304 + } 305 + 306 + vid->is_running = false; 307 + gst_element_set_state(vid->source, GST_STATE_PAUSED); 308 + 309 + return true; 310 + } 311 + 312 + static bool 313 + vf_fs_is_running(struct xrt_fs *xfs) 314 + { 315 + struct vf_fs *vid = vf_fs(xfs); 316 + 317 + GstState current = GST_STATE_NULL; 318 + GstState pending; 319 + gst_element_get_state(vid->source, &current, &pending, 0); 320 + 321 + return current == GST_STATE_PLAYING; 322 + } 323 + 324 + static void 325 + vf_fs_destroy(struct vf_fs *vid) 326 + { 327 + g_main_loop_quit(vid->loop); 328 + 329 + os_thread_helper_stop(&vid->play_thread); 330 + os_thread_helper_destroy(&vid->play_thread); 331 + 332 + free(vid); 333 + } 334 + 335 + 336 + /* 337 + * 338 + * Node methods. 339 + * 340 + */ 341 + 342 + static void 343 + vf_fs_node_break_apart(struct xrt_frame_node *node) 344 + { 345 + struct vf_fs *vid = container_of(node, struct vf_fs, node); 346 + vf_fs_stream_stop(&vid->base); 347 + } 348 + 349 + static void 350 + vf_fs_node_destroy(struct xrt_frame_node *node) 351 + { 352 + struct vf_fs *vid = container_of(node, struct vf_fs, node); 353 + vf_fs_destroy(vid); 354 + } 355 + 356 + 357 + /* 358 + * 359 + * Exported create functions and helper. 360 + * 361 + */ 348 362 349 363 static struct xrt_fs * 350 364 alloc_and_init_common(struct xrt_frame_context *xfctx, //