Ticket #5940: USB_video.patch

File USB_video.patch, 22.8 KB (added by Karvjorm, 11 years ago)

A patch to add USB_video.h to svn tree

  • headers/os/drivers/usb/USB_video.h

     
     1/*
     2 * Copyright 2010 Jorma Karvonen, karvonen.jorma_at_gmail.com
     3 * All rights reserved. Distributed under the terms of the MIT License.
     4 */
     5 
     6#ifndef USB_VIDEO_H
     7#define USB_VIDEO_H
     8
     9// USB Class Definitions for Video Devices, version 1.1
     10// Reference: http://www.usb.org/developers/devclass_docs/USB_Video_Class_1_1.zip
     11
     12#include <BeBuild.h>    // for _PACKED definition
     13
     14#include <lendian_bitfield.h>
     15
     16#define USB_VIDEO_DEVICE_CLASS          0x0e
     17#define USB_VIDEO_CLASS_VERSION         0x0101
     18
     19
     20enum { // Video Interface Class Code
     21    USB_VIDEO_INTERFACE_VIDEO_CLASS     = 0x0e
     22};
     23
     24
     25enum { // Video Interface Subclass Codes
     26    USB_VIDEO_SC_UNDEFINED = 0x00,
     27    USB_VIDEO_SC_VIDEOCONTROL = 0x01,
     28    USB_VIDEO_SC_VIDEOSTREAMING = 0x02,
     29    USB_VIDEO_SC_INTERFACE_COLLECTION = 0x03
     30};
     31
     32
     33enum { // Video Interface Protocol Codesb
     34    USB_VIDEO_PC_PROTOCOL_UNDEFINED = 0x00
     35};
     36
     37
     38enum { // Video Class-Specific Descriptor Types
     39    USB_VIDEO_CS_UNDEFINED = 0x20,
     40    USB_VIDEO_CS_DEVICE = 0x21,
     41    USB_VIDEO_CS_CONFIGURATION = 0x22,
     42    USB_VIDEO_CS_STRING = 0x23,
     43    USB_VIDEO_CS_INTERFACE = 0x24,
     44    USB_VIDEO_CS_ENDPOINT = 0x25
     45};
     46
     47
     48enum { // Video Class-Specific VC Interface Descriptor Subtypes
     49    USB_VIDEO_VC_DESCRIPTOR_UNDEFINED = 0x00,
     50    USB_VIDEO_VC_HEADER = 0x01,
     51    USB_VIDEO_VC_INPUT_TERMINAL = 0x02,
     52    USB_VIDEO_VC_OUTPUT_TERMINAL = 0x03,
     53    USB_VIDEO_VC_SELECTOR_UNIT = 0x04,
     54    USB_VIDEO_VC_PROCESSING_UNIT = 0x05,
     55    USB_VIDEO_VC_EXTENSION_UNIT = 0x06
     56};
     57
     58
     59enum { // Video Class-Specific VS Interface Descriptor Subtypes
     60    USB_VIDEO_VS_UNDEFINED = 0x00,
     61    USB_VIDEO_VS_INPUT_HEADER = 0x01,
     62    USB_VIDEO_VS_OUTPUT_HEADER = 0x02,
     63    USB_VIDEO_VS_STILL_IMAGE_FRAME = 0x03,
     64    USB_VIDEO_VS_FORMAT_UNCOMPRESSED = 0x04,
     65    USB_VIDEO_VS_FRAME_UNCOMPRESSED = 0x05,
     66    USB_VIDEO_VS_FORMAT_MJPEG = 0x06,
     67    USB_VIDEO_VS_FRAME_MJPEG = 0x07,
     68    USB_VIDEO_VS_FORMAT_MPEG2TS = 0x0A,
     69    USB_VIDEO_VS_FORMAT_DV = 0x0C,
     70    USB_VIDEO_VS_COLORFORMAT = 0x0D,
     71    USB_VIDEO_VS_FORMAT_FRAME_BASED = 0x10,
     72    USB_VIDEO_VS_FRAME_FRAME_BASED = 0x11,
     73    USB_VIDEO_VS_FORMAT_STREAM_BASED = 0x12
     74};
     75
     76
     77enum { // Video Class-Specific Endpoint Descriptor Subtypes
     78    USB_VIDEO_EP_UNDEFINED = 0x00,
     79    USB_VIDEO_EP_GENERAL = 0x01,
     80    USB_VIDEO_EP_ENDPOINT = 0x02,
     81    USB_VIDEO_EP_INTERRUPT = 0x03
     82};
     83
     84
     85enum { // Video Class-Specific Request Codes
     86    USB_VIDEO_RC_UNDEFINED = 0x00,
     87    USB_VIDEO_SET_CUR = 0x01,
     88    USB_VIDEO_GET_CUR = 0x81,
     89    USB_VIDEO_GET_MIN = 0x82,
     90    USB_VIDEO_GET_MAX = 0x83,
     91    USB_VIDEO_GET_RES = 0x84,
     92    USB_VIDEO_GET_LEN = 0x85,
     93    USB_VIDEO_GET_INFO = 0x86,
     94    USB_VIDEO_GET_DEF = 0x87
     95};
     96
     97
     98enum { // Video Control Interface Control Selectors
     99    USB_VIDEO_VC_CONTROL_UNDEFINED = 0x00,
     100    USB_VIDEO_VC_VIDEO_POWER_MODE_CONTROL = 0x01,
     101    USB_VIDEO_VC_REQUEST_ERROR_CODE_CONTROL = 0x02
     102};
     103
     104
     105enum { // Terminal Control Selectors
     106    USB_VIDEO_TE_CONTROL_UNDEFINED = 0x00
     107};
     108
     109
     110enum { // Selector Unit Control Selectors
     111    USB_VIDEO_SU_CONTROL_UNDEFINED = 0x00,
     112    USB_VIDEO_SU_INPUT_SELECT_CONTROL = 0x01
     113};
     114
     115
     116enum { // Camera Terminal Control Selectors
     117    USB_VIDEO_CT_CONTROL_UNDEFINED = 0x00,
     118    USB_VIDEO_CT_SCANNING_MODE_CONTROL = 0x01,
     119    USB_VIDEO_CT_AE_MODE_CONTROL = 0x02,
     120    USB_VIDEO_CT_AE_PRIORITY_CONTROL = 0x03,
     121    USB_VIDEO_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL = 0x04,
     122    USB_VIDEO_CT_EXPOSURE_TIME_RELATIVE_CONTROL = 0x05,
     123    USB_VIDEO_CT_FOCUS_ABSOLUTE_CONTROL = 0x06,
     124    USB_VIDEO_CT_FOCUS_RELATIVE_CONTROL = 0x07,
     125    USB_VIDEO_CT_FOCUS_AUTO_CONTROL = 0x08,
     126    USB_VIDEO_CT_IRIS_ABSOLUTE_CONTROL = 0x09,
     127    USB_VIDEO_CT_IRIS_RELATIVE_CONTROL = 0x0A,
     128    USB_VIDEO_CT_ZOOM_ABSOLUTE_CONTROL = 0x0B,
     129    USB_VIDEO_CT_ZOOM_RELATIVE_CONTROL = 0x0C,
     130    USB_VIDEO_CT_PANTILT_ABSOLUTE_CONTROL = 0x0D,
     131    USB_VIDEO_CT_PANTILT_RELATIVE_CONTROL = 0x0E,
     132    USB_VIDEO_CT_ROLL_ABSOLUTE_CONTROL = 0x0F,
     133    USB_VIDEO_CT_ROLL_RELATIVE_CONTROL = 0x10,
     134    USB_VIDEO_CT_PRIVACY_CONTROL = 0x11
     135};
     136
     137
     138enum { // Processing Unit Control Selectors
     139    USB_VIDEO_PU_CONTROL_UNDEFINED = 0x00,
     140    USB_VIDEO_PU_BACKLIGHT_COMPENSATION_CONTROL = 0x01,
     141    USB_VIDEO_PU_BRIGHTNESS_CONTROL = 0x02,
     142    USB_VIDEO_PU_CONTRAST_CONTROL = 0x03,
     143    USB_VIDEO_PU_GAIN_CONTROL = 0x04,
     144    USB_VIDEO_PU_POWER_LINE_FREQUENCY_CONTROL = 0x05,
     145    USB_VIDEO_PU_HUE_CONTROL = 0x06,
     146    USB_VIDEO_PU_SATURATION_CONTROL = 0x07,
     147    USB_VIDEO_PU_SHARPNESS_CONTROL = 0x08,
     148    USB_VIDEO_PU_GAMMA_CONTROL = 0x09,
     149    USB_VIDEO_PU_WHITE_BALANCE_TEMPERATURE_CONTROL = 0x0A,
     150    USB_VIDEO_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL = 0x0B,
     151    USB_VIDEO_PU_WHITE_BALANCE_TEMPERATURE_COMPONENT_CONTROL = 0x0C,
     152    USB_VIDEO_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL = 0x0D,
     153    USB_VIDEO_PU_DIGITAL_MULTIPLEXER_CONTROL = 0x0E,
     154    USB_VIDEO_PU_DIGITAL_MULTIPLEXER_LIMIT_CONTROL = 0x0F,
     155    USB_VIDEO_PU_HUE_AUTO_CONTROL = 0x10,
     156    USB_VIDEO_PU_ANALOG_VIDEO_STANDARD_CONTROL = 0x11,
     157    USB_VIDEO_PU_ANALOG_LOCK_STATUS_CONTROL = 0x12
     158};
     159
     160
     161enum { // Extension Unit Control Selectors
     162    USB_VIDEO_XU_CONTROL_UNDEFINED = 0x00
     163};
     164
     165
     166enum { // Video Streaming Interface Control Selectors
     167    USB_VIDEO_VS_CONTROL_UNDEFINED = 0x00,
     168    USB_VIDEO_VS_PROBE_CONTROL = 0x01,
     169    USB_VIDEO_VS_COMMIT_CONTROL = 0x02,
     170    USB_VIDEO_VS_STILL_PROBE_CONTROL = 0x03,
     171    USB_VIDEO_VS_STILL_COMMIT_CONTROL = 0x04,
     172    USB_VIDEO_VS_STILL_IMAGE_TRIGGER_CONTROL = 0x05,
     173    USB_VIDEO_VS_STREAM_ERROR_CODE_CONTROL = 0x06,
     174    USB_VIDEO_VS_GENERATE_KEY_FRAME_CONTROL = 0x07,
     175    USB_VIDEO_VS_UPDATE_FRAME_SEGMENT_CONTROL = 0x08,
     176    USB_VIDEO_VS_SYNCH_DELAY_CONTROL = 0x09
     177};
     178
     179
     180enum { // USB Terminal types
     181    USB_VIDEO_TT_VENDOR_SPECIFIC = 0x0100,
     182    USB_VIDEO_TT_STREAMING = 0x0101
     183};
     184
     185
     186enum { // Input terminal types
     187    USB_VIDEO_ITT_VENDOR_SPECIFIC = 0x0200,
     188    USB_VIDEO_ITT_CAMERA = 0x0201,
     189    USB_VIDEO_ITT_MEDIA_TRANSPORT_INPUT = 0x0202
     190};
     191
     192
     193enum { // Output terminal types
     194    USB_VIDEO_OTT_VENDOR_SPECIFIC = 0x0300,
     195    USB_VIDEO_OTT_DISPLAY = 0x0301,
     196    USB_VIDEO_OTT_MEDIA_TRANSPORT_OUTPUT = 0x0302
     197};
     198
     199
     200enum { // External terminal types
     201    USB_VIDEO_EXTERNAL_VENDOR_SPECIFIC = 0x0400,
     202    USB_VIDEO_COMPOSITE_CONNECTOR = 0x0401,
     203    USB_VIDEO_SVIDEO_CONNECTOR = 0x0402,
     204    USB_VIDEO_COMPONENT_CONNECTOR = 0x0403
     205};
     206
     207/*!
     208    Struct status_packet_format includes two common fields and other fields
     209    that depend on the type of the originator field of the first status_type
     210    struct. The orignator bitfield of the status_type struct can have the
     211    following values: 0 = reserved, 1 = VideoControl interface,
     212    2 = VideoStreaming interface. The second common status_packet_format field
     213    orignator includes ID of the Terminal, Unit or Interface that reports the
     214    interrupt.
     215    If the orginator bitfield value is 1 (VideoControl interface) then third
     216    field of the status_packet_format is event field that includes value 0x00
     217    for control change. Other values (0x01 - 0xFF) are reserved.
     218    The fourth field selector reports the Control Selector of the control that
     219    have issued the interrupt.
     220    The fifth field attribute specifies the type of control change: 0x00 is
     221    Control value change, 0x01 is Control info change, 0x02 is Control failure
     222    change and values 0x03 - 0xFF are reserved.
     223    After that can be several value fields that can include values 0x00, 0x01
     224    and 0x02.
     225    If the originator bitfield value is 2 (VideoStreaming interface) then
     226    third field of the status_packet_format is event field that can have
     227    value 0x00 (Button Press) or values 0x01 - 0xFF (Stream errors).
     228    If event value is 0x00 (Button Press) there is only one value field. It
     229    can include values 0x00 (Button released) or 0x01 (Button pressed). If
     230    event value was some Stream error value, then there can be several value
     231    fields.
     232*/
     233typedef struct status_packet_format {
     234    struct status_type {
     235        LBITFIELD8_2 (
     236            originator: 4,
     237            reserved: 4
     238        );
     239    } _status_type;
     240    uint8 originator;
     241    union {
     242        struct videocontrol_interface_as_orignator {
     243            uint8 event;
     244            uint8 selector;
     245            uint8 attribute;
     246            uint8* value;
     247        } _videocontrol_interface_as_orignator;
     248        struct videostreaming_interface_as_originator {
     249            uint8 event;
     250            uint8* value;
     251        } _videostreaming_interface_as_originator;
     252    } originators;
     253} _PACKED usb_video_status_packet_format;
     254
     255
     256typedef struct payload_header_format {
     257    uint8 header_length;
     258    struct header_info {
     259        LBITFIELD8_8 (
     260            frame_id: 1,
     261            end_of_frame: 1,
     262            presentation_time: 1,
     263            source_clock_reference: 1,
     264            reserved: 1,
     265            still_image: 1,
     266            error: 1,
     267            end_of_header: 1
     268        );
     269    } _header_info;
     270} _PACKED usb_video_payload_header_format;
     271
     272
     273struct payload_header_format_extended_fields {
     274    uint32 presentation_time;
     275    uint8 source_clock[6];
     276} _PACKED usb_video_payload_header_format_extended_fields;
     277
     278
     279typedef struct std_video_interface_collection_iad {
     280    uint8 length; // 8 bytes
     281    uint8 descriptor_type;
     282    uint8 first_interface;
     283    uint8 interface_count;
     284    uint8 function_class;
     285    uint8 function_sub_class;
     286    // Not used. Must be set to USB_VIDEO_PC_PROTOCOL_UNDEFINED
     287    uint8 function_protocol;
     288    uint8 function;
     289} _PACKED usb_video_standard_video_interface_collection_iad;
     290
     291
     292typedef struct std_vc_interface_descriptor {
     293    uint8 length; // 9 bytes
     294    uint8 descriptor_type;
     295    uint8 interface_number;
     296    uint8 alternate_setting;
     297    uint8 num_endpoints;
     298    uint8 interface_class;
     299    uint8 interface_sub_class;
     300    // Not used. Must be set to USB_VIDEO_PC_PROTOCOL_UNDEFINED
     301    uint8 interface_protocol;
     302    uint8 interface;
     303} _PACKED usb_video_standard_vc_interface_descriptor;
     304
     305
     306typedef struct class_specific_vc_interface_header_descriptor {
     307    uint8 length; // 12 + in_collection bytes
     308    uint8 descriptor_type;
     309    uint8 descriptor_sub_type;
     310    uint16 bcdUVC;
     311    uint16 total_length;
     312    uint32 clock_frequency;
     313    uint8 in_collection;
     314    uint8* interface_nr;
     315} _PACKED usb_video_vc_interface_header_descriptor;
     316
     317
     318typedef struct input_terminal_descriptor {
     319    uint8 length; // 8 bytes + x
     320    uint8 descriptor_type;
     321    uint8 descriptor_sub_type;
     322    uint8 terminal_id;
     323    uint16 terminal_type;
     324    uint8 assoc_terminal;
     325    union {
     326        uint8 terminal;
     327        struct {
     328            uint8 terminal;
     329            uint8* additional_fields;
     330         } some_terminals;
     331    } terminal;
     332} _PACKED usb_video_input_terminal_descriptor;
     333
     334
     335typedef struct output_terminal_descriptor {
     336    uint8 length; // 9 bytes + x
     337    uint8 descriptor_type;
     338    uint8 descriptor_sub_type;
     339    uint8 terminal_id;
     340    uint16 terminal_type;
     341    uint8 assoc_terminal;
     342    uint8 source_id;
     343    union {
     344        uint8 terminal;
     345        struct  {
     346            uint8 terminal;
     347            uint8* additional_fields;
     348        } some_terminals;
     349    } terminal;
     350} _PACKED usb_video_output_terminal_descriptor;
     351
     352
     353typedef struct camera_terminal_descriptor {
     354    uint8 length; // 15 + control_size bytes
     355    uint8 descriptor_type;
     356    uint8 descriptor_sub_type;
     357    uint8 terminal_id;
     358    uint16 terminal_type;
     359    uint8 assoc_terminal;
     360    uint8 terminal;
     361    uint16 objective_focal_length_min;
     362    uint16 objective_focal_length_max;
     363    uint16 ocular_focal_length;
     364    uint8 control_size;
     365#if B_HOST_IS_LENDIAN
     366    struct controls {
     367        struct control_a {
     368            LBITFIELD16 (
     369                scanning_mode: 1,
     370                auto_exposure_mode: 1,
     371                auto_exposure_priority: 1,
     372                exposure_time_absolute: 1,
     373                exposure_time_relative: 1,
     374                focus_absolute: 1,
     375                focus_relative: 1,
     376                iris_absolute: 1,
     377                iris_relative: 1,
     378                zoom_absolute: 1,
     379                zoom_relative: 1,
     380                pan_tilt_absolute: 1,
     381                pan_tilt_relative: 1,
     382                roll_absolute: 1,
     383                roll_relative: 1,
     384                reserved15: 1
     385            );
     386        } _control_a;
     387        struct control_b {
     388            LBITFIELD4 (
     389                reserved16: 1,
     390                focus_auto: 1,
     391                privacy: 1,
     392                // D19...(control_size*8-1): Reserved, set to zero.
     393                reserved: 13
     394            );
     395        } _contorl_b;
     396    } _controls;
     397#else
     398    struct controls {
     399        struct control_b {
     400            LBITFIELD4 (
     401                reserved16: 1,
     402                focus_auto: 1,
     403                privacy: 1,
     404                // D19...(control_size*8-1): Reserved, set to zero.
     405                reserved: 13
     406            );
     407        } _contorl_b;
     408        struct control_a {
     409            LBITFIELD16 (
     410                scanning_mode: 1,
     411                auto_exposure_mode: 1,
     412                auto_exposure_priority: 1,
     413                exposure_time_absolute: 1,
     414                exposure_time_relative: 1,
     415                focus_absolute: 1,
     416                focus_relative: 1,
     417                iris_absolute: 1,
     418                iris_relative: 1,
     419                zoom_absolute: 1,
     420                zoom_relative: 1,
     421                pan_tilt_absolute: 1,
     422                pan_tilt_relative: 1,
     423                roll_absolute: 1,
     424                roll_relative: 1,
     425                reserved15: 1
     426            );
     427        } _control_a;
     428    } _controls;
     429#endif
     430} _PACKED usb_video_camera_terminal_descriptor;
     431
     432
     433typedef struct selector_unit_descriptor {
     434    uint8 length; // 6 bytes + nr_in_pins
     435    uint8 descriptor_type;
     436    uint8 descriptor_sub_type;
     437    uint8 unit_id;
     438    uint8 nr_in_pins;
     439    uint8* source_id;
     440    uint8 selector;
     441} _PACKED usb_video_selector_unit_descriptor;
     442
     443
     444typedef struct processing_unit_descriptor {
     445    uint8 length; // 10 bytes + control_size
     446    uint8 descriptor_type;
     447    uint8 descriptor_sub_type;
     448    uint8 unit_id;
     449    uint8 source_id;
     450    uint16 max_multiplier;
     451    uint8 control_size;
     452#if B_HOST_IS_LENDIAN
     453    struct controls {
     454        struct control_a {
     455            LBITFIELD16 (
     456                brightness: 1,
     457                contrast: 1,
     458                hue: 1,
     459                saturation: 1,
     460                sharpness: 1,
     461                gamma: 1,
     462                white_balance_temperature: 1,
     463                white_balance_component: 1,
     464                backlight_compensation: 1,
     465                gain: 1,
     466                power_line_frequency: 1,
     467                hue_auto: 1,
     468                white_balance_temperature_auto: 1,
     469                white_balance_component_auto: 1,
     470                digital_multiplier: 1,
     471                digital_multiplier_limit: 1
     472            );
     473        } _control_a;
     474        struct control_b {
     475            LBITFIELD3 (
     476                analog_video_standard: 1,
     477                analog_video_lock_status: 1,
     478                reserved: 14 // Reserved. Se to zero.
     479            );
     480        } _control_b;
     481    } _controls;
     482#else
     483    struct controls {
     484        struct control_b {
     485            LBITFIELD3 (
     486                analog_video_standard: 1,
     487                analog_video_lock_status: 1,
     488                reserved: 14 // Reserved. Se to zero.
     489            );
     490        } _control_b;
     491        struct control_a {
     492            LBITFIELD16 (
     493                brightness: 1,
     494                contrast: 1,
     495                hue: 1,
     496                saturation: 1,
     497                sharpness: 1,
     498                gamma: 1,
     499                white_balance_temperature: 1,
     500                white_balance_component: 1,
     501                backlight_compensation: 1,
     502                gain: 1,
     503                power_line_frequency: 1,
     504                hue_auto: 1,
     505                white_balance_temperature_auto: 1,
     506                white_balance_component_auto: 1,
     507                digital_multiplier: 1,
     508                digital_multiplier_limit: 1
     509            );
     510        } _control_a;
     511    } _controls;
     512#endif
     513    uint8 processing;
     514    struct video_standards {
     515        LBITFIELD8_8 (
     516            none: 1,
     517            ntsc_525_60: 1,
     518            pal_625_50: 1,
     519            secam_625_50: 1,
     520            ntsc_625_50: 1,
     521            pal_525_60: 1,
     522            reserved6: 1, // Reserved. Set to zero.
     523            reserved7: 1  // Reserved. Set to zero.
     524        );
     525    } _video_standards;
     526} _PACKED usb_video_processing_unit_descriptor;
     527
     528
     529typedef struct extension_unit_descriptor {
     530    uint8 length; // 24 bytes + nr_in_pins + control_size
     531    uint8 descriptor_type;
     532    uint8 descriptor_sub_type;
     533    uint8 unit_id;
     534    uint8 guid_extension_code[16];
     535    uint8 num_controls;
     536    uint8 nr_in_pins;
     537    uint8* source_id;
     538    uint8 control_size;
     539    struct controls {
     540        LBITFIELD8_8 (
     541            vendor_specific0 : 1,
     542            vendor_specific1 : 1,
     543            vendor_specific2 : 1,
     544            vendor_specific3 : 1,
     545            vendor_specific4 : 1,
     546            vendor_specific5 : 1,
     547            vendor_specific6 : 1,
     548            vendor_specific7 : 1
     549        );
     550    } * _controls;
     551    uint8 extension;
     552} _PACKED usb_video_extension_unit_descriptor;
     553
     554
     555typedef struct std_vc_interrupt_endpoint_descriptor {
     556    uint8 length; // 7 bytes
     557    uint8 descriptor_type;
     558    struct end_point_address {
     559        LBITFIELD8_3 (
     560            endpoint_number: 4, // Determined by the designer
     561            reserved: 3, // Reserved. Set to zero.
     562            direction: 1 // 0 = OUT, 1 = IN
     563        );
     564    } _end_point_address;
     565    struct attributes {
     566        LBITFIELD8_3 (
     567            transfer_type: 2, // Must be set to 11 (Interrupt)
     568            synchronization_type: 2, // Must be set to 00 (None)
     569            reserved: 4 // Reserved. Must be set to zero
     570        );
     571    } _attributes;
     572    uint16 max_packet_size;
     573    uint8 interval;
     574} _PACKED usb_video_vc_interrupt_endpoint_descriptor;
     575
     576typedef struct class_specific_vc_interrupt_endpoint_descriptor {
     577    uint8 length; // 5 bytes
     578    uint8 descriptor_type;
     579    uint8 descriptor_sub_type;
     580    uint16 max_transfer_size;
     581} _PACKED usb_video_class_specific_vc_interrupt_endpoint_descriptor;
     582
     583
     584typedef struct std_vs_interface_descriptor {
     585    uint8 length; // 9 bytes
     586    uint8 descriptor_type;
     587    uint8 interface_number;
     588    uint8 alternate_setting;
     589    uint8 num_endpoints;
     590    uint8 interface_class;
     591    uint8 interface_sub_class;
     592    // Not used. Must be set to USB_VIDEO_PC_PROTOCOL_UNDEFINED
     593    uint8 interface_protocol;
     594    uint8 interface;
     595} _PACKED usb_video_standard_vs_interface_descriptor;
     596
     597
     598typedef struct class_specific_vs_interface_input_header_descriptor {
     599    uint8 length; // 13 bytes + (num_formats*control_size)
     600    uint8 descriptor_type;
     601    uint8 descriptor_sub_type;
     602    uint8 num_formats;
     603    uint16 total_length;
     604    struct endpoint_address {
     605        LBITFIELD8_3 (
     606            endpoint_number: 4, // Determined by the designer
     607            reserved: 3, // Set to zero.
     608            direction: 1 // 0 = OUT, 1 = IN
     609        );
     610    }  _endpoint_address;
     611    struct info {
     612        LBITFIELD8_2 (
     613            dynamic_format_change_support: 1,
     614            reserved: 7 // Set to zero.
     615        );
     616    } _info;
     617    uint8 terminal_link;
     618    uint8 still_capture_method;
     619    uint8 trigger_support;
     620    uint8 trigger_usage;
     621    uint8 control_size;
     622    struct ma_controls {
     623        // For four first bits, a bit set to 1 indicates that the named field
     624        // is supported by the Video Probe and Commit Control when
     625        // its format_index is 1:
     626        LBITFIELD8_7 (
     627            key_frame_rate: 1,
     628            p_frame_rate: 1,
     629            comp_quality: 1,
     630            comp_window_size: 1,
     631            // For the next two bits, a bit set to 1 indicates that the named
     632            // control is supported by the device when
     633            // format_index is 1:
     634            generate_key_frame: 1,
     635            update_frame_segment: 1,
     636            reserved: 2 // (control_size*8-1): Set to zero.
     637        );
     638    } * _ma_controls;
     639} _PACKED usb_video_class_specific_vs_interface_input_header_descriptor;
     640
     641
     642typedef struct class_specific_vs_interface_output_header_descriptor {
     643    uint8 length; // 9 + (num_formats*control_size)
     644    uint8 descriptor_type;
     645    uint8 descriptor_sub_type;
     646    uint8 num_formats;
     647    uint16 total_length;
     648    struct endpoint_address {
     649        LBITFIELD8_3 (
     650            endpoint_number: 4, // Determined by the designer
     651            reserved: 3, // Set to zero.
     652            direction: 1 // 0 = OUT
     653        );
     654    } _endpoint_address;
     655    uint8 terminal_link;
     656    uint8 control_size;
     657    struct ma_controls {
     658        // For four first bits, a bit set to 1 indicates that the named field
     659        // is supported by the Video Probe and Commit Control when its
     660        // format_index is 1:
     661        LBITFIELD8_5 (
     662            key_frame_rate: 1,
     663            p_frame_rate: 1,
     664            comp_quality: 1,
     665            comp_window_size: 1,
     666            reserved: 4 // (control_size*8-1) Set to zero.
     667        );
     668    } * _ma_controls;
     669} _PACKED usb_video_class_specific_vs_interface_output_header_descriptor;
     670
     671
     672typedef struct still_image_frame_descriptor {
     673    // 10 bytes + (4 * num_image_size_patterns) - 4 + num_compression_pattern
     674    uint8 length;
     675    uint8 descriptor_type;
     676    uint8 descriptor_sub_type;
     677    uint8 endpoint_address;
     678    uint8 num_image_size_patterns;
     679    struct pattern_size {
     680        uint16 width;
     681        uint16 height;
     682    } * _pattern_size;
     683    uint8 num_compression_pattern;
     684    uint8* compression;
     685} _PACKED usb_video_still_image_frame_descriptor;
     686
     687
     688typedef struct color_matching_descriptor {
     689    uint8 length; // 6 bytes
     690    uint8 descriptor_type;
     691    uint8 descriptor_sub_type;
     692    uint8 color_primaries;
     693    uint8 transfer_characteristics;
     694    uint8 matrix_coefficients;
     695} _PACKED usb_video_color_matching_descriptor;
     696
     697
     698typedef struct std_vs_isochronous_video_data_endpoint_descriptor {
     699    uint8 length; // 7 bytes
     700    uint8 descriptor_type;
     701    struct endpoint_address {
     702        LBITFIELD8_3 (
     703            endpoint_number: 4, // Determined by the designer
     704            reserved: 3, // Reset to zero.
     705            direction: 1 // 0 = OUT endpoint, 1 = IN endpoint
     706        );
     707    } _endpoint_address;
     708    struct attributes {
     709        LBITFIELD8_3 (
     710            transfer_type: 2, // 01 = isochronous
     711            synchronization_type: 2, // 01 = asynchronous
     712            reserved: 4
     713        );
     714    } _attributes;
     715    uint16 max_packet_size;
     716    uint8 interval;
     717} _PACKED usb_video_std_vs_isochronous_video_data_endpoint_descriptor;
     718
     719
     720typedef struct std_vs_bulk_video_data_endpoint_descriptor {
     721    uint8 length; // 7 bytes
     722    uint8 descriptor_type;
     723    struct endpoint_address {
     724        LBITFIELD8_3 (
     725            endpoint_number: 4, // Determined by the designer
     726            reserved: 3, // Reset to zero.
     727            direction: 1 // 0 = OUT endpoint
     728        );
     729    } _endpoint_address;
     730    struct attributes {
     731        LBITFIELD8_2 (
     732            transfer_type: 2, // Set to 10 = Bulk
     733            reserved: 6
     734        );
     735    } _attributes;
     736    uint16 max_packet_size;
     737    uint8 interval;
     738} _PACKED usb_video_standard_vs_bulk_video_data_endpoint_descriptor;
     739
     740
     741typedef struct std_vs_bulk_still_image_data_endpoint_descriptor {
     742    uint8 length; // 7 bytes
     743    struct endpoint_address {
     744        LBITFIELD8_3 (
     745            endpoint_number: 4, // Determined by the designer
     746            reserved: 3,
     747            direction: 1 // Set to 1 = IN endpoint)
     748        );
     749    } _endpoint_address;
     750    struct attributes {
     751        LBITFIELD8_2 (
     752            transfer_type: 2, // Set to 10 = Bulk
     753            reserved: 6
     754        );
     755    } _attributes;
     756    uint16 max_packet_size;
     757    uint8 interval;
     758} _PACKED usb_video_standard_vs_bulk_still_image_data_endpoint_descriptor;
     759
     760
     761typedef struct video_probe_and_commit_controls {
     762    uint8 length; // 34 bytes
     763    struct hint {
     764        LBITFIELD5 (
     765            frame_interval: 1,
     766            key_frame_rate: 1,
     767            p_frame_rate: 1,
     768            comp_quality: 1,
     769            reserved: 12
     770        );
     771    } _hint;
     772    uint8 format_index;
     773    uint8 frame_index;
     774    uint32 frame_interval;
     775    uint16 key_frame_rate;
     776    uint16 p_frame_rate;
     777    uint16 comp_quality;
     778    uint16 comp_window_size;
     779    uint16 delay;
     780    uint32 max_video_frame_size;
     781    uint32 max_payload_transfer_size;
     782    uint32 clock_frequency;
     783    struct framing_info {
     784        LBITFIELD8_3 (
     785            is_frame_id_required: 1,
     786            is_end_of_frame_present: 1,
     787            reserved: 6
     788        );
     789    } _framing_info;
     790    uint8 prefered_version;
     791    uint8 min_version;
     792    uint8 max_version;
     793} _PACKED usb_video_video_probe_and_commit_controls;
     794
     795
     796typedef struct video_still_probe_control_and_still_commit_control {
     797    uint8 length; // 11 bytes
     798    uint8 frame_index;
     799    uint8 compression_index;
     800    uint32 max_video_frame_size;
     801    uint32 max_payload_transfer_size;
     802} _PACKED usb_video_video_still_probe_control_and_still_commit_control;
     803
     804
     805#endif  // USB_VIDEO_H