Monado OpenXR Runtime
Loading...
Searching...
No Matches
uvc_interface.h
Go to the documentation of this file.
1// Copyright 2017, Philipp Zabel
2// Copyright 2019-2021, Jan Schmidt
3// Copyright 2025-2026, Beyley Cardellio
4// SPDX-License-Identifier: BSL-1.0
5/*!
6 * @file
7 * @brief Public interface for userspace UVC frameserver implementation
8 * @author Philipp Zabel <philipp.zabel@gmail.com>
9 * @author Jan Schmidt <jan@centricular.com>
10 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
11 * @ingroup drv_uvc
12 */
13
14#pragma once
15
16#include "xrt/xrt_byte_order.h"
17#include "xrt/xrt_frame.h"
18#include "xrt/xrt_frameserver.h"
19
20#include "util/u_time.h"
21
22#include <libusb.h>
23#include <stdbool.h>
24#include <stdint.h>
25
26
27#pragma pack(push, 1)
28
30{
31 uint8_t bHeaderLength;
32 uint8_t bmHeaderInfo;
33 __le32 dwPresentationTime;
34 __le16 wSofCounter;
35 __le32 scrSourceClock;
36};
37static_assert(sizeof(struct uvc_payload_header) == 0xC, "bad struct size");
38
40{
41 __le16 bmHint;
42 uint8_t bFormatIndex;
43 uint8_t bFrameIndex;
44 __le32 dwFrameInterval;
45 __le16 wKeyFrameRate;
46 __le16 wPFrameRate;
47 __le16 wCompQuality;
48 __le16 wCompWindowSize;
49 __le16 wDelay;
50 __le32 dwMaxVideoFrameSize;
51 __le32 dwMaxPayloadTransferSize;
52 __le32 dwClockFrequency;
53 uint8_t bmFramingInfo;
54};
55static_assert(sizeof(struct uvc_probe_commit_control) == 0x1F, "bad struct size");
56
57#pragma pack(pop)
58
59//! Called to get the timestamp of a specific frame, if a callee has a more precise way of timestamping frames.
61 void *user_data, //< The user data pointer provided when setting the callback
62 timepoint_ns *out_timestamp, //< The output timestamp of the frame
63 uint64_t *out_sequence_id, //< The output sequence ID of the frame
64 timepoint_ns frame_start_ns, //< When the frame's first payload packet arrived, in local monotonic time
65 uint32_t pts //< The PTS value from the UVC payload header
66);
67
69{
70 enum xrt_format format;
71 uint32_t width;
72 uint32_t height;
73 size_t stride;
74};
75
76struct uvc_fs;
77
78int
79uvc_set_cur(libusb_device_handle *devh,
80 uint8_t usb_interface,
81 uint8_t entity,
82 uint8_t selector,
83 void *data,
84 uint16_t data_length);
85int
86uvc_get_cur(libusb_device_handle *devh,
87 uint8_t usb_interface,
88 uint8_t entity,
89 uint8_t selector,
90 void *data,
91 uint16_t data_length);
92
93//! Callback to setup stream parameters based on USB device parameters
95 uint16_t vid, //< The VID of the USB device
96 uint16_t pid, //< The PID of the USB device
97 bool is_usb2, //< True if the device is USB2, false if USB3
98 libusb_device_handle *devh, //< The libusb device handle
99 struct uvc_probe_commit_control *control, //< The output probe/commit control structure
100 struct uvc_stream_parameters *parameters, //< The output stream parameters
101 size_t *packet_size, //< The output packet size
102 int *alt_setting, //< The output alternate setting
103 void *user_data //< The user data pointer provided when setting the callback
104);
105
106//! Called after initialization in-case any extra device-specific setup is required (like on CV1 sensors over USB2)
107typedef bool (*post_init_callback_t)(uint16_t vid, //< The VID of the USB device
108 uint16_t pid, //< The PID of the USB device
109 bool is_usb2, //< True if the device is USB2, false if USB3
110 libusb_device_handle *devh, //< The libusb device handle
111 void *user_data //< The user data pointer provided when setting the callback
112);
113
114int
115uvc_fs_create(libusb_context *usb_ctx,
116 libusb_device_handle *devh,
117 const struct libusb_device_descriptor *desc,
118 setup_stream_parameters_callback_t setup_stream_parameters_callback,
119 post_init_callback_t post_init_callback,
120 void *user_data,
121 struct xrt_frame_context *xfctx,
122 struct xrt_fs **stream);
123
124int
125uvc_fs_destroy(struct xrt_fs *stream);
126
127void
128uvc_fs_set_source_timestamp_callback(struct xrt_fs *stream, get_frame_timestamp_t callback, void *user_data);
int64_t timepoint_ns
Integer timestamp type.
Definition u_time.h:77
Definition uvc_internal.h:26
Definition uvc_interface.h:30
Definition uvc_interface.h:40
Definition uvc_interface.h:69
Object used to track all sinks and frame producers in a graph.
Definition xrt_frame.h:108
Frameserver that generates frames.
Definition xrt_frameserver.h:70
Time-keeping: a clock that is steady, convertible to system time, and ideally high-resolution.
bool(* get_frame_timestamp_t)(void *user_data, timepoint_ns *out_timestamp, uint64_t *out_sequence_id, timepoint_ns frame_start_ns, uint32_t pts)
Called to get the timestamp of a specific frame, if a callee has a more precise way of timestamping f...
Definition uvc_interface.h:60
bool(* post_init_callback_t)(uint16_t vid, uint16_t pid, bool is_usb2, libusb_device_handle *devh, void *user_data)
Called after initialization in-case any extra device-specific setup is required (like on CV1 sensors ...
Definition uvc_interface.h:107
bool(* setup_stream_parameters_callback_t)(uint16_t vid, uint16_t pid, bool is_usb2, libusb_device_handle *devh, struct uvc_probe_commit_control *control, struct uvc_stream_parameters *parameters, size_t *packet_size, int *alt_setting, void *user_data)
Callback to setup stream parameters based on USB device parameters.
Definition uvc_interface.h:94
Endian-specific byte order defines.
xrt_format
Common formats, use u_format_* functions to reason about them.
Definition xrt_defines.h:204
Data frame header.
Frameserver interface for video drivers.