Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
/*	$NetBSD: uvideoreg.h,v 1.4 2011/12/23 00:51:49 jakllsch Exp $	*/

/*
 * Copyright (c) 2008 Patrick Mahoney
 * All rights reserved.
 *
 * This code was written by Patrick Mahoney (pat@polycrystal.org) as
 * part of Google Summer of Code 2008.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#define UVIDEO_VERSION		0x001

/* This is the standard GUID / UUID.  In USB, it comes in the usual
 * little-endian packed format. */

typedef struct {
	uDWord		data1;
	uWord		data2;
	uWord		data3;
	uByte		data4[8];
} UPACKED usb_guid_t;

typedef struct {
	uint32_t	data1;
	uint16_t	data2;
	uint16_t	data3;
	uint8_t		data4[8];
} guid_t;
#define GUID_LEN 16

/*
 * Video Control descriptors
 */

#define UDESC_VC_HEADER		0x01
#define UDESC_INPUT_TERMINAL	0x02
#define UDESC_OUTPUT_TERMINAL	0x03
#define UDESC_SELECTOR_UNIT	0x04
#define UDESC_PROCESSING_UNIT	0x05
#define UDESC_EXTENSION_UNIT	0x06

#define UDESC_VC_INTERRUPT_ENDPOINT	0x03

/* Terminal Types */
#define UVDIEO_TT_VENDOR_SPECIFIC	0x0100
#define UVIDEO_TT_STREAMING		0x0101

/* Input Terminal Types */
#define UVIDEO_ITT_VENDOR_SPECIFIC	0x0200
#define UVIDEO_ITT_CAMERA		0x0201
#define UVIDEO_ITT_MEDIA_TRANSPORT_INPUT 0x0202

/* Output Terminal Types */
#define UVIDEO_OTT_VENDOR_SPECIFIC	0x0300
#define UVIDEO_OTT_DISPLAY		0x0301
#define UVIDEO_OTT_MEDIA_TRANSPORT_OUTPUT 0x0302

/* generic descriptor with Subtype */
typedef struct {
	uByte	bLength;
	uByte	bDescriptorType;
	uByte	bDescriptorSubtype;
} uvideo_descriptor_t;

/* Class-specific Video Control Interface Header Descriptor */
typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uWord		bcdUVC;
	uWord		wTotalLength;
	uDWord		dwClockFrequency;
	uByte		bInCollection;
	/* followed by n bytes where n is equal to value of bInCollection */
	uByte		baInterfaceNr[];
} UPACKED uvideo_vc_header_descriptor_t;

/* Input Terminal Descriptor */
typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bTerminalID;
	uWord		wTerminalType;
	uByte		bAssocTerminal;
	uByte		iTerminal;
	/* possibly more, depending on Terminal type */
} UPACKED uvideo_input_terminal_descriptor_t;

/* Output Terminal Descriptor */
typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bTerminalID;
	uWord		wTerminalType;
	uByte		bAssocTerminal;
	uByte		bSourceID;
	uByte		iTerminal;
} UPACKED uvideo_output_terminal_descriptor_t;

/* Camera Terminal Descriptor */
typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype; 	/* UDESC_VC_INPUT_TERMINAL */
	uByte		bTerminalID;
	uWord		wTerminalType;		/* UVIDEO_ITT_CAMERA */
	uByte		bAssocTerminal;
	uByte		iTerminal;
	uWord		wObjectiveFocalLengthMin;
	uWord		wObjectiveFocalLengthMax;
	uWord		wOcularFocalLength;
	uByte		bControlSize;
	uByte		bmControls[];
} UPACKED uvideo_camera_terminal_descriptor_t;

/* bmControls fields of uvideo_camera_terminal_descriptor_t */
#define UVIDEO_CAMERA_CONTROL_SCANNING_MODE		(1<<0)
#define UVIDEO_CAMERA_CONTROL_AUTO_EXPOSURE_MODE	(1<<1)
#define UVIDEO_CAMERA_CONTROL_AUTO_EXPOSURE_PRIO	(1<<2)
#define UVIDEO_CAMERA_CONTROL_EXPOSURE_TIME_ABSOLUTE	(1<<3)
#define UVIDEO_CAMERA_CONTROL_EXPOSURE_TIME_RELATIVE	(1<<4)
#define UVIDEO_CAMERA_CONTROL_FOCUS_ABSOLUTE		(1<<5)
#define UVIDEO_CAMERA_CONTROL_FOCUS_RELATIVE		(1<<6)
#define UVIDEO_CAMERA_CONTROL_IRIS_ABSOLUTE		(1<<7)
#define UVIDEO_CAMERA_CONTROL_IRIS_RELATIVE		(1<<8)
#define UVIDEO_CAMERA_CONTROL_ZOOM_ABSOLUTE		(1<<9)
#define UVIDEO_CAMERA_CONTROL_ZOOM_RELATIVE		(1<<10)
#define UVIDEO_CAMERA_CONTROL_PANTILT_ABSOLUTE		(1<<11)
#define UVIDEO_CAMERA_CONTROL_PANTILT_RELATIVE		(1<<12)
#define UVIDEO_CAMERA_CONTROL_ROLL_ABSOLUTE		(1<<13)
#define UVIDEO_CAMERA_CONTROL_ROLL_RELATIVE		(1<<14)
/* 15,16 reserved */
#define UVIDEO_CAMERA_CONTROL_FOCUS_AUTO		(1<<17)
#define UVIDEO_CAMERA_CONTROL_PRIVACY			(1<<18)

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bUnitID;
	uByte		bNrInPins;
	uByte		baSourceID[];
	/* The position of the next field is baSourceID[0] + bNrInPins
	 * and should be accessed via a function. */
/*      uByte           iSelector */
} UPACKED uvideo_selector_unit_descriptor_t;

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bUnitID;
	uByte		bSourceID;
	uWord		wMaxMultiplier;
	uByte		bControlSize;
	uByte		bmControls[];
/*      uByte           iProcessing */
/*      uByte           bmVideoStandards */
#define PU_GET_VIDEO_STANDARDS(desc)	\
	(*((desc)->bmControls + (desc)->bControlSize))
#define UVIDEO_STANDARD_NONE		(1<<0)
#define UVIDEO_STANDARD_NTSC_525_60	(1<<1)
#define UVIDEO_STANDARD_PAL_625_50	(1<<2)
#define UVIDEO_STANDARD_SECAM_625_50	(1<<3)
#define UVIDEO_STANDARD_NTSC_625_50	(1<<4)
#define UVIDEO_STANDARD_PAL_525_60	(1<<5)
} UPACKED uvideo_processing_unit_descriptor_t;

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bUnitID;
	usb_guid_t	guidExtensionCode;
	uByte		bNumControls;
	uByte		bNrInPins;
	uByte		baSourceID[];
/*      uByte           bControlSize */
/*      uByte           bmControls */
#define XU_GET_CONTROL_SIZE(desc)			\
	(*((desc)->baSourceID + (desc)->bNrInPins))
#define XU_GET_CONTROLS(desc)				\
	((desc)->baSourceID + (desc)->bNrInPins + 1)
/*      uByte           iExtension */
} UPACKED uvideo_extension_unit_descriptor_t;

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType; /* UDESC_ENDPOINT */
	uByte		bDescriptorSubtype;
	uWord		wMaxTransferSize;
} UPACKED uvideo_vc_interrupt_endpoint_descriptor_t;



/*
 * Video Streaming descriptors
 */

#define UDESC_VS_INPUT_HEADER		0x01
#define UDESC_VS_OUTPUT_HEADER		0x02
#define UDESC_VS_STILL_IMAGE_FRAME	0x03
#define UDESC_VS_FORMAT_UNCOMPRESSED	0x04
#define UDESC_VS_FRAME_UNCOMPRESSED	0x05
#define UDESC_VS_FORMAT_MJPEG		0x06
#define UDESC_VS_FRAME_MJPEG		0x07
/* reserved in spec v1.1		0x08 */
/* reserved in spec v1.1		0x09 */
#define UDESC_VS_FORMAT_MPEG2TS		0x0A
/* reserved in spec v 1.1		0x0B */
#define UDESC_VS_FORMAT_DV		0x0C
#define UDESC_VS_COLORFORMAT		0x0D
/* reserved in spec v1.1		0x0E */
/* reserved in spec v1.1		0x0F */
#define UDESC_VS_FORMAT_FRAME_BASED	0x10
#define UDESC_VS_FRAME_FRAME_BASED	0x11
#define UDESC_VS_FORMAT_STREAM_BASED	0x12

/* Copy protection state */
#define UVIDEO_NO_RESTRICTIONS		0
#define UVIDEO_RESTRICT_DUP		1

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bNumFormats;
	uWord		wTotalLength;
	uByte		bEndpointAddress;
	uByte		bmInfo;
	uByte		bTerminalLink;
	uByte		bStillCaptureMethod;
	uByte		bTriggerSupport;
	uByte		bTriggerUsage;
	uByte		bControlSize;
	uByte		bmaControls[];
#define UVIDEO_VS_KEYFRAME_RATE	(1<<0)
#define UVIDEO_VS_PFRAME_RATE	(1<<1)
#define UVIDEO_VS_COMP_QUALITY	(1<<2)
#define UVIDEO_VS_COMP_WINDOW_SIZE	(1<<3)
#define UVIDEO_VS_GENERATE_KEYFRAME	(1<<4)
#define UVIDEO_VS_UPDATE_FRAME_SEGMENT	(1<<5)
} UPACKED uvideo_vs_input_header_descriptor_t;

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bNumFormats;
	uWord		wTotalLength;
	uByte		bEndpointAddress;
	uByte		bTerminalLink;
	uByte		bControlSize;
	uByte		bmaControls[];
} UPACKED uvideo_vs_output_header_descriptor_t;


typedef struct {
	uWord		wWidth;
	uWord		wHeight;
} UPACKED uvideo_still_image_frame_dimensions_t;

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bEndpointAddress;
	uByte		bNumImageSizePatterns;
	uvideo_still_image_frame_dimensions_t wwaDimensions[];
	/* position dependent on size of previous item */
	/* uByte	bNumCompressionPattern */
	/* uByte	bCompression[] */
} UPACKED uvideo_still_image_frame_descriptor_t;


/* Color matching information */

/* bColroPrimaries */
#define UVIDEO_COLOR_PRIMARIES_UNSPECIFIED	0
#define UVIDEO_COLOR_PRIMARIES_sRGB		1 /* same as BT709 */
#define UVIDEO_COLOR_PRIMARIES_BT709		1 /* default */
#define UVIDEO_COLOR_PRIMARIES_BT470_2_M       	2
#define UVIDEO_COLOR_PRIMARIES_BT470_2_BG      	3
#define UVIDEO_COLOR_PRIMARIES_SMPTE_170M      	4
#define UVIDEO_COLOR_PRIMARIES_SMPTE_240M      	5

/* bTransferCharacteristics */
#define UVIDEO_GAMMA_FUNCTION_UNSPECIFIED	0
#define UVIDEO_GAMMA_FUNCTION_BT709		1 /* default */
#define UVIDEO_GAMMA_FUNCTION_BT470_2_M       	2
#define UVIDEO_GAMMA_FUNCTION_BT470_2_BG      	3
#define UVIDEO_GAMMA_FUNCTION_SMPTE_170M      	4
#define UVIDEO_GAMMA_FUNCTION_SMPTE_240M      	5
#define UVIDEO_GAMMA_FUNCTION_LINEAR		6	
#define UVIDEO_GAMMA_FUNCTION_sRGB		7 /* similar to BT709 */

/* bMatrixCoefficients */
#define UVIDEO_LUMA_CHROMA_MATRIX_UNSPECIFIED	0
#define UVIDEO_LUMA_CHROMA_MATRIX_BT709		1
#define UVIDEO_LUMA_CHROMA_MATRIX_FCC       	2
#define UVIDEO_LUMA_CHROMA_MATRIX_BT470_2_BG	3
#define UVIDEO_LUMA_CHROMA_MATRIX_SMPTE_170M	4 /* default */
#define UVIDEO_LUMA_CHROMA_MATRIX_SMPTE_240M	5

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bColorPrimaries;
	uByte		bTransferCharacteristics;
	uByte		bMatrixCoefficients;
} UPACKED uvideo_color_matching_descriptor_t;

/*
 * Format and Frame descriptors
 */

#define UVIDEO_FRAME_CAP_STILL_IMAGE	1<<0
#define UVIDEO_FRAME_CAP_FIXED_RATE	1<<1

#define UVIDEO_FRAME_INTERVAL_CONTINUOUS 0

/* TODO: interlace flags */


typedef struct {
	uDWord		dwMinFrameInterval;
	uDWord		dwMaxFrameInterval;
	uDWord		dwFrameIntervalStep;
} UPACKED uvideo_frame_interval_continuous_t;

typedef struct {
	uDWord	dwFrameInterval[1]; /* length depends on bFrameIntervalType */
} UPACKED uvideo_frame_interval_discrete_t;

typedef union {
	uvideo_frame_interval_continuous_t	continuous;
	uvideo_frame_interval_discrete_t	discrete;
} uvideo_frame_interval_t;

/* generic format descriptor header */
typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bFormatIndex;
} UPACKED uvideo_vs_format_descriptor_t;

/* generic frame descriptor header */
typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bFrameIndex;
} UPACKED uvideo_vs_frame_descriptor_t;


/*  uncompressed format and frame descriptors */
static const guid_t uvideo_guid_format_yuy2 = {
	0x32595559,
	0x0000,
	0x0010,
	{0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71}
};

static const guid_t uvideo_guid_format_nv12 = {
	0x3231564E,
	0x0000,
	0x0010,
	{0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71}
};

static const guid_t uvideo_guid_format_uyvy = {
	0x59565955,
	0x0000,
	0x0010,
	{0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71}
};

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bFormatIndex;
	uByte		bNumFrameDescriptors;
	usb_guid_t	guidFormat;
	uByte		bBitsPerPixel;
	uByte		bDefaultFrameIndex;
	uByte		bAspectRatioX;
	uByte		bAspectRatioY;
	uByte		bmInterlaceFlags;
	uByte		bCopyProtect;
} UPACKED uvideo_vs_format_uncompressed_descriptor_t;

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bFrameIndex;
	uByte		bmCapabilities;
	uWord		wWidth;
	uWord		wHeight;
	uDWord		dwMinBitRate;
	uDWord		dwMaxBitRate;
	uDWord		dwMaxVideoFrameBufferSize;
	uDWord		dwDefaultFrameInterval;
	uByte		bFrameIntervalType;
	uvideo_frame_interval_t uFrameInterval;
} UPACKED uvideo_vs_frame_uncompressed_descriptor_t;


/* Frame based Format and Frame descriptors.  This is for generic
 * frame based payloads not covered by other types (e.g, uncompressed
 * or MJPEG). */

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bFormatIndex;
	uByte		bNumFrameDescriptors;
	usb_guid_t	guidFormat;
	uByte		bBitsPerPixel;
	uByte		bDefaultFrameIndex;
	uByte		bAspectRatioX;
	uByte		bAspectRatioY;
	uByte		bmInterlaceFlags;
	uByte		bCopyProtect;
} UPACKED uvideo_format_frame_based_descriptor_t;

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bFrameIndex;
	uByte		bmCapabilities;
	uWord		wWidth;
	uWord		wHeight;
	uDWord		dwMinBitRate;
	uDWord		dwMaxBitRate;
	uDWord		dwDefaultFrameInterval;
	uByte		bFrameIntervalType;
	uDWord		dwBytesPerLine;
	uvideo_frame_interval_t uFrameInterval;
} UPACKED uvideo_frame_frame_based_descriptor_t;


/* MJPEG format and frame descriptors */

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bFormatIndex;
	uByte		bNumFrameDescriptors;
	uByte		bmFlags;
#define UVIDEO_NO_FIXED_SIZE_SAMPLES 0
#define UVIDEO_FIXED_SIZE_SAMPLES 1
	uByte		bDefaultFrameIndex;
	uByte		bAspectRatioX;
	uByte		bAspectRatioY;
	uByte		bmInterlaceFlags;
	uByte		bCopyProtect;
} UPACKED uvideo_vs_format_mjpeg_descriptor_t;

typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bFrameIndex;
	uByte		bmCapabilities;
	uWord		wWidth;
	uWord		wHeight;
	uDWord		dwMinBitRate;
	uDWord		dwMaxBitRate;
	uDWord		dwMaxVideoFrameBufferSize;
	uDWord		dwDefaultFrameInterval;
	uByte		bFrameIntervalType;
	uvideo_frame_interval_t uFrameInterval;
} UPACKED uvideo_vs_frame_mjpeg_descriptor_t;


typedef struct {
	uByte		bLength;
	uByte		bDescriptorType;
	uByte		bDescriptorSubtype;
	uByte		bFormatIndex;
	uDWord		dwMaxVideoFrameBufferSize;
	uByte		bFormatType;
#define UVIDEO_GET_DV_FREQ(ubyte) (((ubyte)>>7) & 1)
#define UVIDEO_DV_FORMAT_FREQ_50HZ 0
#define UVIDEO_DV_FORMAT_FREQ_60HZ 1
#define UVIDEO_GET_DV_FORMAT(ubyte) ((ubyte) & 0x3f)
#define UVIDEO_DV_FORMAT_SD_DV	0
#define UVIDEO_DV_FORMAT_SDL_DV	1
#define UVIDEO_DV_FORMAT_HD_DV	2
} UPACKED uvideo_vs_format_dv_descriptor_t;



/*
 * Video Control requests
 */

/* Pseudo bitmasks that only work when bitwise OR onto a zeroed value */
#define UVIDEO_REQUEST_TYPE_INTERFACE		(0x0001)
#define UVIDEO_REQUEST_TYPE_ENDPOINT		(0x0010)
#define UVIDEO_REQUEST_TYPE_CLASS_SPECIFIC	(0x01 << 5)
#define UVIDEO_REQUEST_TYPE_SET			(0x0 << 7)
#define UVIDEO_REQUEST_TYPE_GET			(0x1 << 7)

typedef enum {
	UVIDEO_REQUEST_DESC_INTERFACE,
	UVIDEO_REQUEST_DESC_ENDPOINT
} uvideo_request_descriptor;

typedef enum {
	UR_RC_UNDEFINED = 0x00,
	UR_SET_CUR	= 0x01,
	UR_GET_CUR	= 0x81,
	UR_GET_MIN	= 0x82,
	UR_GET_MAX	= 0x83,
	UR_GET_RES	= 0x84,
	UR_GET_LEN	= 0x85,
	UR_GET_INFO	= 0x86,
	UR_GET_DEF	= 0x87,
} uvideo_request;

/* camera terminal control selectors */
#define UVIDEO_CT_CONTROL_UNDEFINED		0x00
#define UVIDEO_CT_SCANNING_MODE_CONTROL		0x01
#define UVIDEO_CT_AE_MODE_CONTROL		0x02
#define UVIDEO_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL 0x04
#define UVIDEO_CT_EXPOSURE_TIME_RELATIVE_CONTROL 0x05
#define UVIDEO_CT_FOCUS_ABSOLUTE_CONTROL	0x06
#define UVIDEO_CT_FOCUS_RELATIVE_CONTROL	0x07
#define UVIDEO_CT_IRIS_ABSOLUTE_CONTROL		0x09
#define UVIDEO_CT_IRIS_RELATIVE_CONTROL		0x0A
#define UVIDEO_CT_ZOOM_ABSOLUTE_CONTROL		0x0B
#define UVIDEO_CT_ZOOM_RELATIVE_CONTROL		0x0C
#define UVIDEO_CT_PANTILT_ABSOLUTE_CONTROL	0x0D
#define UVIDEO_CT_PANTILT_RELATIVE_CONTROL	0x0E
#define UVIDEO_CT_ROLL_ABSOLUTE_CONTROL		0x0F
#define UVIDEO_CT_ROLL_RELATIVE_CONTROL		0x10
#define UVIDEO_CT_PRIVACY_CONTROL		0x11

/* processing unit control selectors */
#define UVIDEO_PU_CONTROL_UNDEFINED			0x00
#define UVIDEO_PU_BACKLIGHT_COMPENSATION_CONTROL	0x01
#define UVIDEO_PU_BRIGHTNESS_CONTROL			0x02
#define UVIDEO_PU_CONTRAST_CONTROL			0x03
#define UVIDEO_PU_GAIN_CONTROL				0x04
#define UVIDEO_PU_POWER_LINE_FREQUENCY_CONTROL		0x05
#define UVIDEO_PU_HUE_CONTROL				0x06
#define UVIDEO_PU_SATURATION_CONTROL			0x07
#define UVIDEO_PU_SHARPNESS_CONTROL			0x08
#define UVIDEO_PU_GAMMA_CONTROL				0x09
#define UVIDEO_PU_WHITE_BALANCE_TEMPERATURE_CONTROL	0x0A
#define UVIDEO_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL 0x0B
#define UVIDEO_PU_WHITE_BALANCE_COMPONENT_CONTROL	0x0C
#define UVIDEO_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL	0x0D
#define UVIDEO_PU_DIGITAL_MULTIPLIER_CONTROL		0x0E
#define UVIDEO_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL	0x0F
#define UVIDEO_PU_HUE_AUTO_CONTROL			0x10
#define UVIDEO_PU_ANALOG_VIDEO_STANDARD_CONTROL		0x11
#define UVIDEO_PU_ANALOG_LOCK_STATUS_CONTROL		0x12

/* extension unit control selectors */
#define UVIDEO_XU_CONTROL_UNDEFINED	0x00

/* VideoStreaming Interface control selectors */
#define UVIDEO_VS_CONTROL_UNDEFINED		0x00
#define UVIDEO_VS_PROBE_CONTROL			0x01
#define UVIDEO_VS_COMMIT_CONTROL		0x02
#define UVIDEO_VS_STILL_PROBE_CONTROL		0x03
#define UVIDEO_VS_STILL_COMMIT_CONTROL		0x04
#define UVIDEO_VS_STILL_IMAGE_TRIGGER_CONTROL	0x05
#define UVIDEO_VS_STREAM_ERROR_CODE_CONTROL	0x06
#define UVIDEO_VS_GENERATE_KEY_FRAME_CONTROL	0x07
#define UVIDEO_VS_UPDATE_FRAME_SEGMENT_CONTROL	0x08
#define UVIDEO_VS_SYNCH_DELAY_CONTROL		0x09

/* bitmask result of GET_INFO on a control */
#define UVIDEO_CONTROL_INFO_SUPPORTS_GET	(1<<0)
#define UVIDEO_CONTROL_INFO_SUPPORTS_SET	(1<<1)
#define UVIDEO_CONTROL_INFO_DISABLED		(1<<2)
#define UVIDEO_CONTROL_INFO_AUTOUPDATE		(1<<3)
#define UVIDEO_CONTROL_INFO_ASYNC		(1<<4)


/* Video Probe and Commit Controls request data */
typedef struct {
	uWord		bmHint;
#define UVIDEO_HINT_FRAME_INTERVAL	(1<<0)
#define UVIDEO_HINT_KEYFRAME_RATE	(1<<1)
#define UVIDEO_HINT_PFRAME_RATE		(1<<2)
#define UVIDEO_HINT_COMP_QUALITY	(1<<3)
#define UVIDEO_HINT_COMP_WINDOW_SIZE	(1<<4)
	uByte		bFormatIndex;
	uByte		bFrameIndex;
	uDWord		dwFrameInterval;
#define UVIDEO_100NS_PER_MS 10000
#define UVIDEO_FRAME_INTERVAL_UNITS_PER_USB_FRAME UVIDEO_100NS_PER_MS
	uWord		wKeyFrameRate;
	uWord		wPFrameRate;
	uWord		wCompQuality;
	uWord		wCompWindowSize;
	uWord		wDelay;
	uDWord		dwMaxVideoFrameSize;
	uDWord		dwMaxPayloadTransferSize;
	/* Following fields are not in v1.0 of UVC.  Will have to do
	 * UR_GET_LEN to discover the length of this descriptor. */
	uDWord		dwClockFrequency;
	uByte		bmFramingInfo;
#define UVIDEO_FRAMING_INFO_FID	(1<<0)
#define UVIDEO_FRAMING_INFO_EOF	(1<<1)
	uByte		bPreferedVersion;
	uByte		bMinVersion;
	uByte		bMaxVersion;
} UPACKED uvideo_probe_and_commit_data_t;

/* Video Still Probe and Still Commit Controls request data */
typedef struct {
	uByte		bFormatIndex;
	uByte		bFrameIndex;
	uByte		bCompressionIndex;
	uDWord		dwMaxVideoFrameSize;
	uDWord		dwMaxPayloadTransferSize;
} UPACKED uvideo_still_probe_and_still_commit_data_t;
#define UVIDEO_STILL_PROBE_AND_STILL_COMMIT_DATA_SIZE 11;



/* common header for Video Control and Video Stream status */
typedef struct {
	uByte		bStatusType;
#define UV_STATUS_TYPE_CONTROL	0x02
#define UV_STATUS_TYPE_STREAM	0x04
	uByte		bOriginator;
} UPACKED uvideo_status_t;

typedef struct {
	uByte		bStatusType;
	uByte		bOriginator;
	uByte		bEvent;
#define UV_CONTROL_CHANGE	0x00 /* any other value is Reserved */
	uByte		bSelector;
	uByte		bAttribute;
#define UV_CONTROL_VALUE_CHANGE		0x00
#define UV_CONTROL_INFO_CHANGE		0x01
#define UV_CONTROL_FAILURE_CHANGE	0x02
	uByte		bValue;
} UPACKED uvideo_control_status_t;

typedef struct {
	uByte		bStatusType;
	uByte		bOriginator;
	uByte		bEvent;
#define UV_BUTTON_PRESS	0x00 /* any other value is Stream Error */
	uByte		bValue;
#define UV_BUTTON_RELEASED	0x00
#define UV_BUTTON_PRESSED	0x01
} UPACKED uvideo_streaming_status_t;

typedef struct {
	uByte		bHeaderLength;
	uByte		bmHeaderInfo;
#define UV_FRAME_ID	1<<0
#define UV_END_OF_FRAME	1<<1
#define UV_PRES_TIME	1<<2
#define UV_SRC_CLOCK	1<<3
/* D4: Reserved */
#define UV_STILL_IMAGE	1<<5
#define UV_ERROR	1<<6
#define UV_END_OF_HDR	1<<7
/* other fields depend on which bits are set above and have no fixed offset */
/*	uDWord		dwPresentationTime; */
#define UVIDEO_PTS_SIZE 4
/*	uByte		scrSourceClock[UVIDEO_SOURCE_CLOCK_SIZE]; */
#define UVIDEO_SOURCE_CLOCK_SIZE 6
#define UV_GET_SOURCE_TIME_CLOCK(sc) (UGETDW(sc))
/* bits 42..32 */
#define UV_GET_SOF_COUNTER(sc) (((sc)[4] | ((sc)[5] << 8)) &0x7ff)
} UPACKED uvideo_payload_header_t;

/* Note: this might be larger depending on presence of source clock,
   SOF counter, or other things... bHeaderLength is actual length. */
#define UVIDEO_PAYLOAD_HEADER_SIZE 12