The open source OpenXR runtime
at main 135 lines 2.2 kB view raw
1// Copyright 2019-2022, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief V4L2 frameserver common definitions 6 * @author Pete Black <pblack@collabora.com> 7 * @author Jakob Bornecrantz <jakob@collabora.com> 8 * @ingroup drv_v4l2 9 */ 10 11 12#include "util/u_logging.h" 13#include "util/u_sink.h" 14#include "xrt/xrt_frameserver.h" 15#include <linux/videodev2.h> 16 17 18/* 19 * 20 * Defines. 21 * 22 */ 23 24#define V4L2_TRACE(d, ...) U_LOG_IFL_T(d->log_level, __VA_ARGS__) 25#define V4L2_DEBUG(d, ...) U_LOG_IFL_D(d->log_level, __VA_ARGS__) 26#define V4L2_INFO(d, ...) U_LOG_IFL_I(d->log_level, __VA_ARGS__) 27#define V4L2_WARN(d, ...) U_LOG_IFL_W(d->log_level, __VA_ARGS__) 28#define V4L2_ERROR(d, ...) U_LOG_IFL_E(d->log_level, __VA_ARGS__) 29 30#define NUM_V4L2_BUFFERS 32 31 32 33/* 34 * 35 * Structs 36 * 37 */ 38 39/*! 40 * @extends xrt_frame 41 * @ingroup drv_v4l2 42 */ 43struct v4l2_frame 44{ 45 struct xrt_frame base; 46 47 void *mem; //!< Data might be at an offset, so we need base memory. 48 49 struct v4l2_buffer v_buf; 50}; 51 52struct v4l2_state_want 53{ 54 bool active; 55 int value; 56}; 57 58/*! 59 * @ingroup drv_v4l2 60 */ 61struct v4l2_control_state 62{ 63 int id; 64 int force; 65 66 struct v4l2_state_want want[2]; 67 68 int value; 69 70 const char *name; 71}; 72 73/*! 74 * A single open v4l2 capture device, starts its own thread and waits on it. 75 * 76 * @implements xrt_frame_node 77 * @implements xrt_fs 78 */ 79struct v4l2_fs 80{ 81 struct xrt_fs base; 82 83 struct xrt_frame_node node; 84 85 struct u_sink_debug usd; 86 87 int fd; 88 89 struct 90 { 91 bool extended_format; 92 bool timeperframe; 93 } has; 94 95 enum xrt_fs_capture_type capture_type; 96 struct v4l2_control_state states[256]; 97 size_t num_states; 98 99 struct 100 { 101 bool ps4_cam; 102 } quirks; 103 104 struct v4l2_frame frames[NUM_V4L2_BUFFERS]; 105 uint32_t used_frames; 106 107 struct 108 { 109 bool mmap; 110 bool userptr; 111 } capture; 112 113 struct xrt_frame_sink *sink; 114 115 pthread_t stream_thread; 116 117 struct v4l2_source_descriptor *descriptors; 118 uint32_t num_descriptors; 119 uint32_t selected; 120 121 struct xrt_fs_capture_parameters capture_params; 122 123 bool is_configured; 124 bool is_running; 125 enum u_logging_level log_level; 126}; 127 128/*! 129 * Cast to derived type. 130 */ 131static inline struct v4l2_fs * 132v4l2_fs(struct xrt_fs *xfs) 133{ 134 return (struct v4l2_fs *)xfs; 135}