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