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.
60typedef bool (*get_frame_timestamp_t)(void *user_data, //< The user data pointer provided when setting the callback
61 timepoint_ns *timestamp, //< The output timestamp of the frame
62 uint32_t pts //< The PTS value from the UVC payload header
63);
64
66{
67 enum xrt_format format;
68 uint32_t width;
69 uint32_t height;
70 size_t stride;
71};
72
73struct uvc_fs;
74
75int
76uvc_set_cur(libusb_device_handle *devh,
77 uint8_t usb_interface,
78 uint8_t entity,
79 uint8_t selector,
80 void *data,
81 uint16_t data_length);
82int
83uvc_get_cur(libusb_device_handle *devh,
84 uint8_t usb_interface,
85 uint8_t entity,
86 uint8_t selector,
87 void *data,
88 uint16_t data_length);
89
90//! Callback to setup stream parameters based on USB device parameters
92 uint16_t vid, //< The VID of the USB device
93 uint16_t pid, //< The PID of the USB device
94 bool is_usb2, //< True if the device is USB2, false if USB3
95 libusb_device_handle *devh, //< The libusb device handle
96 struct uvc_probe_commit_control *control, //< The output probe/commit control structure
97 struct uvc_stream_parameters *parameters, //< The output stream parameters
98 size_t *packet_size, //< The output packet size
99 int *alt_setting, //< The output alternate setting
100 void *user_data //< The user data pointer provided when setting the callback
101);
102
103//! Called after initialization in-case any extra device-specific setup is required (like on CV1 sensors over USB2)
104typedef bool (*post_init_callback_t)(uint16_t vid, //< The VID of the USB device
105 uint16_t pid, //< The PID of the USB device
106 bool is_usb2, //< True if the device is USB2, false if USB3
107 libusb_device_handle *devh, //< The libusb device handle
108 void *user_data //< The user data pointer provided when setting the callback
109);
110
111int
112uvc_fs_create(libusb_context *usb_ctx,
113 libusb_device_handle *devh,
114 const struct libusb_device_descriptor *desc,
115 setup_stream_parameters_callback_t setup_stream_parameters_callback,
116 post_init_callback_t post_init_callback,
117 void *user_data,
118 struct xrt_frame_context *xfctx,
119 struct xrt_fs **stream);
120
121int
122uvc_fs_destroy(struct xrt_fs *stream);
123
124void
125uvc_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:66
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(* 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:104
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:91
bool(* get_frame_timestamp_t)(void *user_data, timepoint_ns *timestamp, 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
Endian-specific byte order defines.
xrt_format
Common formats, use u_format_* functions to reason about them.
Definition xrt_defines.h:193
Data frame header.
Frameserver interface for video drivers.