blob: 925b5b66a9ee349a2232836e1ea5404c5df4f297 [file] [log] [blame]
Adam Barth57eacf52020-11-04 00:38:09 +00001// Copyright 2017 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SYSROOT_ZIRCON_HW_USB_VIDEO_H_
6#define SYSROOT_ZIRCON_HW_USB_VIDEO_H_
7
8// clang-format off
9
10#include <zircon/compiler.h>
11#include <stdint.h>
12
13__BEGIN_CDECLS;
14
15// video interface subclasses
16#define USB_SUBCLASS_VIDEO_CONTROL 0x01
17#define USB_SUBCLASS_VIDEO_STREAMING 0x02
18#define USB_SUBCLASS_VIDEO_INTERFACE_COLLECTION 0x03
19
20// video class specific descriptor types
21#define USB_VIDEO_CS_DEVICE 0x21
22#define USB_VIDEO_CS_CONFIGURATION 0x22
23#define USB_VIDEO_CS_STRING 0x23
24#define USB_VIDEO_CS_INTERFACE 0x24
25#define USB_VIDEO_CS_ENDPOINT 0x25
26
27// video class specific VC interface descriptor subtypes
28#define USB_VIDEO_VC_HEADER 0x01
29#define USB_VIDEO_VC_INPUT_TERMINAL 0x02
30#define USB_VIDEO_VC_OUTPUT_TERMINAL 0x03
31#define USB_VIDEO_VC_SELECTOR_UNIT 0x04
32#define USB_VIDEO_VC_PROCESSING_UNIT 0x05
33#define USB_VIDEO_VC_EXTENSION_UNIT 0x06
34#define USB_VIDEO_VC_ENCODING_UNIT 0x07
35
36// video class specific VS interface descriptor subtypes
37#define USB_VIDEO_VS_INPUT_HEADER 0x01
38#define USB_VIDEO_VS_OUTPUT_HEADER 0x02
39#define USB_VIDEO_VS_STILL_IMAGE_FRAME 0x03
40#define USB_VIDEO_VS_FORMAT_UNCOMPRESSED 0x04
41#define USB_VIDEO_VS_FRAME_UNCOMPRESSED 0x05
42#define USB_VIDEO_VS_FORMAT_MJPEG 0x06
43#define USB_VIDEO_VS_FRAME_MJPEG 0x07
44#define USB_VIDEO_VS_FORMAT_MPEG2TS 0x0A
45#define USB_VIDEO_VS_FORMAT_DV 0x0C
46#define USB_VIDEO_VS_COLORFORMAT 0x0D
47#define USB_VIDEO_VS_FORMAT_FRAME_BASED 0x10
48#define USB_VIDEO_VS_FRAME_FRAME_BASED 0x11
49#define USB_VIDEO_VS_FORMAT_STREAM_BASED 0x12
50#define USB_VIDEO_VS_FORMAT_H264 0x13
51#define USB_VIDEO_VS_FRAME_H264 0x14
52#define USB_VIDEO_VS_FORMAT_H264_SIMULCAST 0x15
53#define USB_VIDEO_VS_FORMAT_VP8 0x16
54#define USB_VIDEO_VS_FRAME_VP8 0x17
55#define USB_VIDEO_VS_FORMAT_VP8_SIMULCAST 0x18
56
57// video class specific endpoint descriptor subtypes
58#define USB_VIDEO_EP_GENERAL 0x01
59#define USB_VIDEO_EP_ENDPOINT 0x02
60#define USB_VIDEO_EP_INTERRUPT 0x03
61
62// video class specific request codes
63#define USB_VIDEO_SET_CUR 0x01
64#define USB_VIDEO_SET_CUR_ALL 0x11
65#define USB_VIDEO_GET_CUR 0x81
66#define USB_VIDEO_GET_MIN 0x82
67#define USB_VIDEO_GET_MAX 0x83
68#define USB_VIDEO_GET_RES 0x84
69#define USB_VIDEO_GET_LEN 0x85
70#define USB_VIDEO_GET_INFO 0x86
71#define USB_VIDEO_GET_DEF 0x87
72#define USB_VIDEO_GET_CUR_ALL 0x91
73#define USB_VIDEO_GET_MIN_ALL 0x92
74#define USB_VIDEO_GET_MAX_ALL 0x93
75#define USB_VIDEO_GET_RES_ALL 0x94
76#define USB_VIDEO_GET_DEF_ALL 0x97
77
78// video streaming interface control selectors
79#define USB_VIDEO_VS_PROBE_CONTROL 0x01
80#define USB_VIDEO_VS_COMMIT_CONTROL 0x02
81#define USB_VIDEO_VS_STILL_PROBE_CONTROL 0x03
82#define USB_VIDEO_VS_STILL_COMMIT_CONTROL 0x04
83#define USB_VIDEO_VS_STILL_IMAGE_TRIGGER_CONTROL 0x05
84#define USB_VIDEO_VS_STREAM_ERROR_CODE_CONTROL 0x06
85#define USB_VIDEO_VS_GENERATE_KEY_FRAME_CONTROL 0x07
86#define USB_VIDEO_VS_UPDATE_FRAME_SEGMENT_CONTROL 0x08
87#define USB_VIDEO_VS_SYNCH_DELAY_CONTROL 0x09
88
89// header for usb_video_vc_* below
90typedef struct {
91 uint8_t bLength;
92 uint8_t bDescriptorType; // USB_VIDEO_CS_INTERFACE
93 uint8_t bDescriptorSubtype;
94} __PACKED usb_video_vc_desc_header;
95
96typedef struct {
97 uint8_t bLength;
98 uint8_t bDescriptorType; // USB_VIDEO_CS_INTERFACE
99 uint8_t bDescriptorSubtype; // USB_VIDEO_VC_HEADER
100 uint16_t bcdUVC;
101 uint16_t wTotalLength;
102 uint32_t dwClockFrequency;
103 uint8_t bInCollection;
104 uint8_t baInterfaceNr[];
105} __PACKED usb_video_vc_header_desc;
106
107typedef struct {
108 uint8_t bLength;
109 uint8_t bDescriptorType; // USB_VIDEO_CS_INTERFACE
110 uint8_t bDescriptorSubtype; // USB_VIDEO_VC_INPUT_TERMINAL
111 uint8_t bTerminalID;
112 uint16_t wTerminalType;
113 uint8_t bAssocTerminal;
114 uint8_t iTerminal;
115} __PACKED usb_video_vc_input_terminal_desc;
116
117typedef struct {
118 uint8_t bLength;
119 uint8_t bDescriptorType; // USB_VIDEO_CS_INTERFACE
120 uint8_t bDescriptorSubtype; // USB_VIDEO_VC_OUTPUT_TERMINAL
121 uint8_t bTerminalID;
122 uint16_t wTerminalType;
123 uint8_t bAssocTerminal;
124 uint8_t bSourceID;
125 uint8_t iTerminal;
126} __PACKED usb_video_vc_output_terminal_desc;
127
128// class specific VC interrupt endpoint descriptor
129typedef struct {
130 uint8_t bLength;
131 uint8_t bDescriptorType; // USB_VIDEO_CS_ENDPOINT
132 uint8_t bDescriptorSubtype; // USB_ENDPOINT_INTERRUPT
133 uint16_t wMaxTransferSize;
134} __PACKED usb_video_vc_interrupt_endpoint_desc;
135
136typedef struct {
137 uint8_t bLength;
138 uint8_t bDescriptorType; // USB_VIDEO_CS_INTERFACE
139 uint8_t bDescriptorSubtype; // USB_VIDEO_VS_HEADER
140 uint8_t bNumFormats;
141 uint16_t wTotalLength;
142 uint8_t bEndpointAddress;
143 uint8_t bmInfo;
144 uint8_t bTerminalLink;
145 uint8_t bStillCaptureMethod;
146 uint8_t bTriggerSupport;
147 uint8_t bTriggerUsage;
148 uint8_t bControlSize;
149 uint8_t bmaControls[];
150} __PACKED usb_video_vs_input_header_desc;
151
152#define GUID_LENGTH 16
153
154// A GUID consists of a:
155// - four-byte integer
156// - two-byte integer
157// - two-byte integer
158// - eight-byte array
159//
160// The string representation uses big endian format, so to convert it
161// to a byte array we need to reverse the byte order of the three integers.
162//
163// See USB Video Class revision 1.5, FAQ section 2.9
164// for GUID Data Structure Layout.
165
166#define USB_VIDEO_GUID_YUY2_STRING "32595559-0000-0010-8000-00AA00389B71"
167#define USB_VIDEO_GUID_YUY2_VALUE { \
168 0x59, 0x55, 0x59, 0x32, \
169 0x00, 0x00, \
170 0x10, 0x00, \
171 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 \
172}
173
174#define USB_VIDEO_GUID_NV12_STRING "3231564E-0000-0010-8000-00AA00389B71"
175#define USB_VIDEO_GUID_NV12_VALUE { \
176 0x4e, 0x56, 0x31, 0x32, \
177 0x00, 0x00, \
178 0x10, 0x00, \
179 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 \
180}
181
182#define USB_VIDEO_GUID_M420_STRING "3032344D-0000-0010-8000-00AA00389B71"
183#define USB_VIDEO_GUID_M420_VALUE { \
184 0x4d, 0x34, 0x32, 0x30, \
185 0x00, 0x00, \
186 0x10, 0x00, \
187 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 \
188}
189
190#define USB_VIDEO_GUID_I420_STRING "30323449-0000-0010-8000-00AA00389B71"
191#define USB_VIDEO_GUID_I420_VALUE { \
192 0x49, 0x34, 0x32, 0x30, \
193 0x00, 0x00, \
194 0x10, 0x00, \
195 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 \
196}
197
198// USB Video Payload Uncompressed
199typedef struct {
200 uint8_t bLength;
201 uint8_t bDescriptorType; // USB_VIDEO_CS_INTERFACE
202 uint8_t bDescriptorSubType; // USB_VIDEO_VS_FORMAT_UNCOMPRESSED
203 uint8_t bFormatIndex;
204 uint8_t bNumFrameDescriptors;
205 uint8_t guidFormat[GUID_LENGTH];
206 uint8_t bBitsPerPixel;
207 uint8_t bDefaultFrameIndex;
208 uint8_t bAspectRatioX;
209 uint8_t bAspectRatioY;
210 uint8_t bmInterfaceFlags;
211 uint8_t bCopyProtect;
212} __PACKED usb_video_vs_uncompressed_format_desc;
213
214// USB Video Payload MJPEG
215typedef struct {
216 uint8_t bLength;
217 uint8_t bDescriptorType; // USB_VIDEO_CS_INTERFACE
218 uint8_t bDescriptorSubType; // USB_VIDEO_VS_FORMAT_MJPEG
219 uint8_t bFormatIndex;
220 uint8_t bNumFrameDescriptors;
221 uint8_t bmFlags;
222 uint8_t bDefaultFrameIndex;
223 uint8_t bAspectRatioX;
224 uint8_t bAspectRatioY;
225 uint8_t bmInterfaceFlags;
226 uint8_t bCopyProtect;
227} __PACKED usb_video_vs_mjpeg_format_desc;
228
229// Uncompressed and MJPEG formats have the same frame descriptor structure.
230typedef struct {
231 uint8_t bLength;
232 uint8_t bDescriptorType; // USB_VIDEO_CS_INTERFACE
233 uint8_t bDescriptorSubType; // USB_VIDEO_VS_FRAME_UNCOMPRESSED / USB_VIDEO_VS_FRAME_MJPEG
234 uint8_t bFrameIndex;
235 uint8_t bmCapabilities;
236 uint16_t wWidth;
237 uint16_t wHeight;
238 uint32_t dwMinBitRate;
239 uint32_t dwMaxBitRate;
240 uint32_t dwMaxVideoFrameBufferSize;
241 uint32_t dwDefaultFrameInterval;
242 uint8_t bFrameIntervalType;
243 uint32_t dwFrameInterval[];
244} __PACKED usb_video_vs_frame_desc;
245
246// Stream negotiation
247#define USB_VIDEO_BM_HINT_FRAME_INTERVAL (1 << 0)
248#define USB_VIDEO_BM_HINT_KEY_FRAME_RATE (1 << 1)
249#define USB_VIDEO_BM_HINT_P_FRAME_RATE (1 << 2)
250#define USB_VIDEO_BM_HINT_COMP_QUALITY (1 << 3)
251#define USB_VIDEO_BM_HINT_COMP_WINDOW_SIZE (1 << 4)
252
253typedef struct {
254 uint16_t bmHint;
255 uint8_t bFormatIndex;
256 uint8_t bFrameIndex;
257 uint32_t dwFrameInterval;
258 uint16_t wKeyFrameRate;
259 uint16_t wPFrameRate;
260 uint16_t wCompQuality;
261 uint16_t wCompWindowSize;
262 uint16_t wDelay;
263 uint32_t dwMaxVideoFrameSize;
264 uint32_t dwMaxPayloadTransferSize;
265 // The following fields are optional.
266 uint32_t dwClockFrequency;
267 uint8_t bmFramingInfo;
268 uint8_t bPreferedVersion;
269 uint8_t bMinVersion;
270 uint8_t bMaxVersion;
271 uint8_t bUsage;
272 uint8_t bBitDepthLuma;
273 uint8_t bmSettings;
274 uint8_t bMaxNumberOfRefFramesPlus1;
275 uint16_t bmRateControlModes;
276 uint32_t bmLayoutPerStream;
277} __PACKED usb_video_vc_probe_and_commit_controls;
278
279// For accessing payload bmHeaderInfo bitmap
280#define USB_VIDEO_VS_PAYLOAD_HEADER_FID (1 << 0)
281#define USB_VIDEO_VS_PAYLOAD_HEADER_EOF (1 << 1)
282#define USB_VIDEO_VS_PAYLOAD_HEADER_PTS (1 << 2)
283#define USB_VIDEO_VS_PAYLOAD_HEADER_SCR (1 << 3)
284#define USB_VIDEO_VS_PAYLOAD_HEADER_RES (1 << 4)
285#define USB_VIDEO_VS_PAYLOAD_HEADER_STI (1 << 5)
286#define USB_VIDEO_VS_PAYLOAD_HEADER_ERR (1 << 6)
287#define USB_VIDEO_VS_PAYLOAD_HEADER_EOH (1 << 7)
288
289// Common header for all payloads.
290typedef struct {
291 uint8_t bHeaderLength;
292 uint8_t bmHeaderInfo;
293
294} __PACKED usb_video_vs_payload_header;
295
296typedef struct {
297 uint8_t bHeaderLength;
298 uint8_t bmHeaderInfo;
299 uint32_t dwPresentationTime;
300 uint32_t scrSourceTimeClock;
301 // Frame number when the source clock was sampled.
302 uint16_t scrSourceClockSOFCounter;
303} __PACKED usb_video_vs_uncompressed_payload_header;
304
305__END_CDECLS;
306
307
308#endif // SYSROOT_ZIRCON_HW_USB_VIDEO_H_