精华内容
下载资源
问答
  • uvc摄像头驱动程序

    2011-08-12 14:27:37
    用于uvc摄像头的驱动,支持市场上的大部分uvc类型的摄像头驱动
  • 香橙派PC笔记-05-编译linux内核和UVC摄像头驱动笔记-附件资源
  • UVC 摄像头驱动(一)硬件描述 http://blog.csdn.net/lizuobin2/ https://blog.csdn.net/lizuobin2/article/details/53144378 虚拟摄像头驱动vivi 内核中使用 video_device 结构来描述一个 video 设备,以虚拟...

     

    UVC 摄像头驱动(一)硬件描述

    http://blog.csdn.net/lizuobin2/ https://blog.csdn.net/lizuobin2/article/details/53144378

    虚拟摄像头驱动vivi

    内核中使用 video_device 结构来描述一个 video 设备,以虚拟摄像头驱动 vivi 为例,整体框架无非是:

    • 分配一个 video_device
    • 设置 video_device 的众多的 ioctl 等
    • 注册 video_register_device

    对于一个虚拟摄像头驱动来说,上层应用程序无论是来查询视频格式,还是设置格式,我们都是伪造的,视频缓冲区的数据也更是伪造的。那么对于一个真正的usb 摄像头来说,设备的信息比如它支持的视频格式等,我们就要通过分析 usb 的描述符,视频数据要通过访问 usb 设备来获取。

    uvc摄像头驱动

    uvc 摄像头驱动,首先它是一个 usb 设备驱动,对于 usb 设备驱动整体框架也可以分为三步:

    • 分配 usb_driver 结构体
    • 设置 usb_driver 结构 
      • 设置 it_table 表示驱动支持哪些 usb 设备
      • probe 函数 
        • 分配 video_device
        • 设置 video_deivce
        • 注册 video_register_device
    • 注册 usb_register

    摄像头硬件模型

    协议下载

    uvc == usb video class ,标准协议可以从 usb.org下载,所有的标准协议都可以下载到,比如 Mass Storage 、HID …

    硬件模型

    摄像头硬件模型可以大致分为以下两部分,VC interface 和 VS interface 
    这里写图片描述
    VC interface 用于控制,内部又分为多个 unit 和 terminal ,unit 用于内部处理,terminal 用于内外链接。 
    VS interface 用于传输,内部包括视频数据传输的端点以及摄像头支持的视频格式等信息。

    功能特性(翻译)

    Each video function has a single VideoControl (VC) interface and can have several VideoStreaming (VS) interfaces 
    The VideoControl (VC) interface is used to access the device controls of the function whereas 
    the VideoStreaming (VS) interfaces are used to transport data streams into and out of the function. 
    每个视频有且仅有1个VideoControl (VC)接口和可有多个 VideoStreaming (VS) 接口,VC接口用于设备功能控制,VS接口用于传输数据流进出 
    VC 内部抽象出了两个概念 unit 和 terminal

    Unit

    Units provide the basic building blocks to fully describe most video functions ,A Unit has one or more Input Pins and a single Output Pin, 
    Unit提供了基础模块来全面描述大部分的视频功能,一个Unit可以由一个或多个输入引脚和仅一个输出引脚(这里的每一个pin代表一个逻辑上的数据流) 
    这里写图片描述 
    Unit可以通过pin引脚连接在一起,一个输出pin可以连接多个输入pin,但一个输入pin只能连接一个输出pin 
    这里写图片描述

    Select Unit

    The Selector Unit (SU) selects from n input data streams and routes them unaltered to the single output stream. 
    选择Unit (SU)选择多个输入数据流并路由它们到单一的输出流 
    这里写图片描述

    Processing Unit

    The Processing Unit (PU) controls image attributes of the video being streamed through it. 
    这里写图片描述 
    处理Unit (PU)控制流经它的视频流图像属性。 
    User Controls

    • Brightness
    • Hue
    • Saturation
    • Sharpness
    • Gamma
    • Digital Multiplier (Zoom)

    Auto Controls

    • White Balance Temperature
    • White Balance Component
    • Backlight Compensation
    • Contrast

    Other

    • Gain
    • Power Line Frequency
    • Analog Video Standard
    • Analog Video Lock Status

    Terminal

    Terminals have one Input or Output Pin that is always numbered one. 
    Terminal只有1个输入或一个输出引脚pin

    Input Terminal

    An Output Terminal (OT) represents an ending point for data streams. 
    一个输出Terminal (OT)终端是一个实体代表数据流的结束端点 
    这里写图片描述

    Out Terminal

    An Output Terminal (OT) represents an ending point for data streams. 
    一个输出Terminal (OT)终端是一个实体代表数据流的结束端点 
    这里写图片描述

    Camera Terminal

    The Camera Terminal (CT) controls mechanical (or equivalent digital) features of the device component that transmits the video stream. 
    CameraTerminal (CT)控制传输视频流的设备组件特性

    • Scanning Mode扫描模式
    • Auto-Exposure Mode自动曝光模式
    • Auto-Exposure Priority自动曝光优先级
    • Exposure Time 曝光时间
    • Focus聚焦
    • Auto-Focus自动聚焦
    • Simple Focus简单聚焦
    • Iris红外
    • Zoom放大
    • Pan摇动
    • Roll滚动
    • Tilt倾斜
    • Digital Windowing数字窗口

     

    展开全文
  • UVC 摄像头驱动(二)描述符分析 http://blog.csdn.net/lizuobin2/ https://blog.csdn.net/lizuobin2/article/details/53149583  当一个 usb 设备接入时,usb 主机控制器会与设备交互,读取出设备的所有的描述符...

     

    UVC 摄像头驱动(二)描述符分析

    http://blog.csdn.net/lizuobin2/ https://blog.csdn.net/lizuobin2/article/details/53149583

      当一个 usb 设备接入时,usb 主机控制器会与设备交互,读取出设备的所有的描述符,并且调用相应 usb_driver 的 probe 函数,同时传入一个接口的指针,因为一个接口代表一个逻辑上的 usb 设备。如果 usb 设备含有多个接口,同时都被这个 usb_driver 支持的话,probe 函数就会被调用多次。 
      对于一个 usb 设备来说,首先它有一个设备描述符,一个设备可能会拥有多个配置,每一个配置都拥有一个配置描述符,配置可以理解成多个接口的组合。那么一个配置会拥有多个接口,每一个接口会拥有一个接口描述符,同时一个接口又会有多个设置,设置可以理解成多个端点的组合,每一个端点拥有一个端点描述符。关于详细的设备、配置、接口、设置、端点之间的关系请参考我之前的文章《USB驱动——设备、配置、接口、设置、端点之前的关系以及它们的获取过程分析》那么对于 usb video class 它在标准的 usb 协议上进行了扩展,扩展的部分称为 class specific ,完整的关系如下图所示: 



      在 UVC 1.5 Class specification 的第三章,有专门对 UVC 的描述符进行解释,在第 3.1 节,给出了一个完整uvc设备描述符的布局如下图所示: 


    这里写图片描述


    其中,Device 等白色的描述符为标准描述符,灰色是 class specific 描述符。

     

    IAD Interface Association Descriptor

      一个设备需要用一个联合接口描述符(IAD)来描述一个视频接口集合,对于每一个设备功能需要一个视频控制接口(VideoControl Interface)和一个或者多个视频流接口(VideoStreaming Interface)。标准的视频接口联合描述符和标准接口联合描述符定义相同。在代码中,它体现在“配置”中。

    struct usb_host_config {  
        struct usb_config_descriptor    desc;   // 配置描述符  
    
        char *string;         
        struct usb_interface_assoc_descriptor *intf_assoc[USB_MAXIADS];//IAD
        struct usb_interface *interface[USB_MAXINTERFACES]; // 接口  
        struct usb_interface_cache *intf_cache[USB_MAXINTERFACES];  
        unsigned char *extra;   
        int extralen;  
    };  
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    那么这个联合接口描述符(IAD)有什么含义呢? 



    举例:

     

    Interface Association:
          bLength                 8
          bDescriptorType        11
          bFirstInterface         0
          bInterfaceCount         2
          bFunctionClass         14 Video
          bFunctionSubClass       3 Video Interface Collection
          bFunctionProtocol       0 
          iFunction        
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    该接口联合描述符中表明了,它是两个接口的集合,起始接口为 0 ,其实没啥意义。大致可以知道是一个控制接口和一个流接口。

    VideoControl Interface Descriptors

     

    这里写图片描述


      它包含两部分,一个是白色标准视频控制接口描述符,其余的灰色是UVC类特殊的视频控制接口描述符。

     

    Standard VC Interface Descriptor

      标准 VC 接口描述符和标准接口描述符的定义是一样的,定义在 section 9.6.5 “Interface” of USB Specification Revision 2.0 。代码中,它包含在接口的设置里。

    struct usb_host_interface {  
        struct usb_interface_descriptor desc;   // 接口描述符  
        struct usb_host_endpoint *endpoint;  
        char *string;       /* iInterface string, if present */  
        unsigned char *extra;   /* Class-Specific VC Interface Descriptor */  
        int extralen;  
    };  
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

     



    举例:

     

    Interface Descriptor:
          bLength                 9
          bDescriptorType         4
          bInterfaceNumber        0
          bAlternateSetting       0
          bNumEndpoints           1
          bInterfaceClass        14 Video
          bInterfaceSubClass      1 Video Control
          bInterfaceProtocol      0 
          iInterface              2 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    主要信息:这是第0号接口,是一个 video_control 接口。

    Class-Specific VC Interface Descriptor

      UVC 类特殊接口描述符是一连串的描述符,它包含了所有用来描述设备功能的描述符,比如 unit 和 terminal 描述符。它和标准接口描述符为与同一个结构体里。

    struct usb_host_interface {  
        struct usb_interface_descriptor desc;   // 接口描述符  
        struct usb_host_endpoint *endpoint;  
        char *string;       /* iInterface string, if present */  
        unsigned char *extra;   /* Class-Specific VC Interface Descriptor */  
        int extralen;  /* lenth of Class-Specific VC Interface Descriptor */  
    };  
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    举例:

    VideoControl Interface Descriptor:
            bLength                13
            bDescriptorType        36
            bDescriptorSubtype      1 (HEADER)
            bcdUVC               1.00
            wTotalLength          109
            dwClockFrequency       48.000000MHz
            bInCollection           1
            baInterfaceNr( 0)       1
          VideoControl Interface Descriptor:
            bLength                18
            bDescriptorType        36
            bDescriptorSubtype      2 (INPUT_TERMINAL)
            bTerminalID             1
            wTerminalType      0x0201 Camera Sensor
            bAssocTerminal          0
            iTerminal               0 
            wObjectiveFocalLengthMin      0
            wObjectiveFocalLengthMax      0
            wOcularFocalLength            0
            bControlSize                  3
            bmControls           0x00000006
              Auto-Exposure Mode
              Auto-Exposure Priority
          VideoControl Interface Descriptor:
            bLength                11
            bDescriptorType        36
            bDescriptorSubtype      5 (PROCESSING_UNIT)
          Warning: Descriptor too short
            bUnitID                 2
            bSourceID               1
            wMaxMultiplier      16384
            bControlSize            2
            bmControls     0x0000153f
              Brightness
              Contrast
              Hue
              Saturation
              Sharpness
              Gamma
              Backlight Compensation
              Power Line Frequency
              White Balance Temperature, Auto
            iProcessing             0 
            bmVideoStandards     0x1d
              None
              PAL - 625/50
              SECAM - 625/50
              NTSC - 625/50
          VideoControl Interface Descriptor:
            bLength                29
            bDescriptorType        36
            bDescriptorSubtype      6 (EXTENSION_UNIT)
            bUnitID                 3
            guidExtensionCode         {82066163-7050-ab49-b8cc-b3855e8d221d}
            bNumControl             0
            bNrPins                 1
            baSourceID( 0)          2
            bControlSize            4
            bmControls( 0)       0xff
            bmControls( 1)       0xff
            bmControls( 2)       0x1d
            bmControls( 3)       0x00
            iExtension              0 
          VideoControl Interface Descriptor:
            bLength                29
            bDescriptorType        36
            bDescriptorSubtype      6 (EXTENSION_UNIT)
            bUnitID                 4
            guidExtensionCode         {64e7c624-515f-7e43-9089-28ffa487bdca}
            bNumControl             0
            bNrPins                 1
            baSourceID( 0)          3
            bControlSize            4
            bmControls( 0)       0x0f
            bmControls( 1)       0x00
            bmControls( 2)       0x00
            bmControls( 3)       0x00
            iExtension              0 
          VideoControl Interface Descriptor:
            bLength                 9
            bDescriptorType        36
            bDescriptorSubtype      3 (OUTPUT_TERMINAL)
            bTerminalID             5
            wTerminalType      0x0101 USB Streaming
            bAssocTerminal          0
            bSourceID               4
            iTerminal               0 
          Endpoint Descriptor:
            bLength                 7
            bDescriptorType         5
            bEndpointAddress     0x87  EP 7 IN
            bmAttributes            3
              Transfer Type            Interrupt
              Synch Type               None
              Usage Type               Data
            wMaxPacketSize     0x0010  1x 16 bytes
            bInterval               8
    • 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

      根据上面的信息,控制接口描述符有很多子类,前面在摄像头硬件描述中,我们说在控制接口中抽象出了两个概念,一个是 unit 另一个 terminal ,unit 和 terminal 的信息就包含在这些描述符信息中了。它们直连的链接关系可以通过描述符中的 bSourceID 或者 baSourceID 来分析,比如这款摄像头,它的硬件模型就是: 
      IT -> PU ->EU -> EU ->OT 具体的描述符含义,参考 UVC 1.5 Class specification Table 3-3 到 3-10 .这里只分析一下 header 描述符。 


    这里写图片描述


      在 header 描述符的第11位,bInCollection 指出了该设备拥有的VS接口的数量,从第12位起,是每一个 VS 接口的接口号。

     

    VC Interrupt Endpoint Descriptors

    中断端点描述符也分为标准中断端点描述符和UVC类特殊的中断端点描述符

    • Standard VC Interrupt Endpoint Descriptor
    • Class-specific VC Interrupt Endpoint Descriptor

    它们在代码中位于 “端点”中:

    struct usb_host_endpoint {  
        struct usb_endpoint_descriptor  desc;   // 端点描述符  
        struct list_head        urb_list;   // 该端点的 urb 队列  
        void                *hcpriv;  
        struct ep_device        *ep_dev;    /* For sysfs info */  
        struct usb_host_ss_ep_comp  *ss_ep_comp;    /* For SS devices */  
        unsigned char *extra;/* Class-specific VC Interrupt Endpoint Descriptor */  
        int extralen;/* lenth of Class-specific VC Interrupt Endpoint Descriptor */  
        int enabled;  
    }; 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    具体的定义与说明参考: 
      UVC 1.5 Class specification Table 3-11 
      UVC 1.5 Class specification Table 3-12

    VideoStreaming Interface Descriptors

     


    这里写图片描述


    视频流接口描述符包含了所有用来描述视频流接口特性的相关信息。

     

    Standard VS Interface Descriptor

      标准视频流接口描述符和标准接口描述符的定义相同,在section 9.6.5 “Interface” of USB Specification Revision 2.0 or USB Specification Revision 3.0 中定义. 



    举例:

     

        Interface Descriptor:
          bLength                 9
          bDescriptorType         4
          bInterfaceNumber        1
          bAlternateSetting       0
          bNumEndpoints           0
          bInterfaceClass        14 Video
          bInterfaceSubClass      2 Video Streaming
          bInterfaceProtocol      0 
          iInterface              0 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    主要信息,它是第1号接口,接口类型是 video_streaming

    Class-Specific VS Interface Descriptors

      UVC 类特殊视频流接口由 input header 、oupt header 、format 和 frame 描述符组成,每一个视频流接口都有一个单独的 input 或者 output header 描述符,对于它支持的每一个 format 都有一个单独的 format 描述符,对于每一个 format 描述符如果需要的话会包含多个 frame 描述符。format 和 frame 描述符仅仅会定义在接口的第0号设置中。 
    定义参考: 
      Table 3-14 Class-specific VS Interface Input Header Descriptor 
      USB_Video_Payload_Uncompressed_1.5 
      USB_Video_Payload_MJPEG_1.5 
      USB_Video_Payload_Frame_Based_1.5 
    举例:

    VideoStreaming Interface Descriptor:
            bLength                            15
            bDescriptorType                    36
            bDescriptorSubtype                  1 (INPUT_HEADER)
            bNumFormats                         2
            wTotalLength                      525
            bEndPointAddress                  129
            bmInfo                              0
            bTerminalLink                       5
            bStillCaptureMethod                 1
            bTriggerSupport                     1
            bTriggerUsage                       0
            bControlSize                        1
            bmaControls( 0)                    27
            bmaControls( 1)                    27
          VideoStreaming Interface Descriptor:
            bLength                            27
            bDescriptorType                    36
            bDescriptorSubtype                  4 (FORMAT_UNCOMPRESSED)
            bFormatIndex                        1
            bNumFrameDescriptors                7
            guidFormat                            {59555932-0000-1000-8000-00aa00389b71}
            bBitsPerPixel                      16
            bDefaultFrameIndex                  1
            bAspectRatioX                       0
            bAspectRatioY                       0
            bmInterlaceFlags                 0x00
              Interlaced stream or variable: No
              Fields per frame: 2 fields
              Field 1 first: No
              Field pattern: Field 1 only
              bCopyProtect                      0
          VideoStreaming Interface Descriptor:
            bLength                            34
            bDescriptorType                    36
            bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
            bFrameIndex                         1
            bmCapabilities                   0x01
              Still image supported
            wWidth                            640
            wHeight                           480
            dwMinBitRate                 73728000
            dwMaxBitRate                147456000
            dwMaxVideoFrameBufferSize      614400
            dwDefaultFrameInterval         333333
            bFrameIntervalType                  2
            dwFrameInterval( 0)            333333
            dwFrameInterval( 1)            666666
          VideoStreaming Interface Descriptor:
            bLength                            34
            bDescriptorType                    36
            bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
            bFrameIndex                         2
            bmCapabilities                   0x01
              Still image supported
            wWidth                            160
            wHeight                           120
            dwMinBitRate                  4608000
            dwMaxBitRate                  9216000
            dwMaxVideoFrameBufferSize       38400
            dwDefaultFrameInterval         333333
            bFrameIntervalType                  2
            dwFrameInterval( 0)            333333
            dwFrameInterval( 1)            666666
          VideoStreaming Interface Descriptor:
            bLength                            34
            bDescriptorType                    36
            bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
            bFrameIndex                         3
            bmCapabilities                   0x01
              Still image supported
            wWidth                            176
            wHeight                           144
            dwMinBitRate                  6082560
            dwMaxBitRate                 12165120
            dwMaxVideoFrameBufferSize       50688
            dwDefaultFrameInterval         333333
            bFrameIntervalType                  2
            dwFrameInterval( 0)            333333
            dwFrameInterval( 1)            666666
          VideoStreaming Interface Descriptor:
            bLength                            34
            bDescriptorType                    36
            bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
            bFrameIndex                         4
            bmCapabilities                   0x01
              Still image supported
            wWidth                            320
            wHeight                           240
            dwMinBitRate                 18432000
            dwMaxBitRate                 36864000
            dwMaxVideoFrameBufferSize      153600
            dwDefaultFrameInterval         333333
            bFrameIntervalType                  2
            dwFrameInterval( 0)            333333
            dwFrameInterval( 1)            666666
          VideoStreaming Interface Descriptor:
            bLength                            34
            bDescriptorType                    36
            bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
            bFrameIndex                         5
            bmCapabilities                   0x01
              Still image supported
            wWidth                            352
            wHeight                           288
            dwMinBitRate                 24330240
            dwMaxBitRate                 48660480
            dwMaxVideoFrameBufferSize      202752
            dwDefaultFrameInterval         333333
            bFrameIntervalType                  2
            dwFrameInterval( 0)            333333
            dwFrameInterval( 1)            666666
          VideoStreaming Interface Descriptor:
            bLength                            30
            bDescriptorType                    36
            bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
            bFrameIndex                         6
            bmCapabilities                   0x01
              Still image supported
            wWidth                           1280
            wHeight                           720
            dwMinBitRate                147456000
            dwMaxBitRate                147456000
            dwMaxVideoFrameBufferSize     1843200
            dwDefaultFrameInterval        1000000
            bFrameIntervalType                  1
            dwFrameInterval( 0)           1000000
          VideoStreaming Interface Descriptor:
            bLength                            30
            bDescriptorType                    36
            bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
            bFrameIndex                         7
            bmCapabilities                   0x01
              Still image supported
            wWidth                           1280
            wHeight                           800
            dwMinBitRate                163840000
            dwMaxBitRate                163840000
            dwMaxVideoFrameBufferSize     2048000
            dwDefaultFrameInterval        1000000
            bFrameIntervalType                  1
            dwFrameInterval( 0)           1000000
          VideoStreaming Interface Descriptor:
            bLength                             6
            bDescriptorType                    36
            bDescriptorSubtype                 13 (COLORFORMAT)
            bColorPrimaries                     1 (BT.709,sRGB)
            bTransferCharacteristics            1 (BT.709)
            bMatrixCoefficients                 4 (SMPTE 170M (BT.601))
          VideoStreaming Interface Descriptor:
            bLength                            11
            bDescriptorType                    36
            bDescriptorSubtype                  6 (FORMAT_MJPEG)
            bFormatIndex                        2
            bNumFrameDescriptors                7
            bFlags                              1
              Fixed-size samples: Yes
            bDefaultFrameIndex                  1
            bAspectRatioX                       0
            bAspectRatioY                       0
            bmInterlaceFlags                 0x00
              Interlaced stream or variable: No
              Fields per frame: 1 fields
              Field 1 first: No
              Field pattern: Field 1 only
              bCopyProtect                      0
          VideoStreaming Interface Descriptor:
            bLength                            34
            bDescriptorType                    36
            bDescriptorSubtype                  7 (FRAME_MJPEG)
            bFrameIndex                         1
            bmCapabilities                   0x01
              Still image supported
            wWidth                            640
            wHeight                           480
            dwMinBitRate                 73728000
            dwMaxBitRate                147456000
            dwMaxVideoFrameBufferSize      614400
            dwDefaultFrameInterval         333333
            bFrameIntervalType                  2
            dwFrameInterval( 0)            333333
            dwFrameInterval( 1)            666666
          VideoStreaming Interface Descriptor:
            bLength                            34
            bDescriptorType                    36
            bDescriptorSubtype                  7 (FRAME_MJPEG)
            bFrameIndex                         2
            bmCapabilities                   0x01
              Still image supported
            wWidth                            160
            wHeight                           120
            dwMinBitRate                  4608000
            dwMaxBitRate                  9216000
            dwMaxVideoFrameBufferSize       38400
            dwDefaultFrameInterval         333333
            bFrameIntervalType                  2
            dwFrameInterval( 0)            333333
            dwFrameInterval( 1)            666666
          VideoStreaming Interface Descriptor:
            bLength                            34
            bDescriptorType                    36
            bDescriptorSubtype                  7 (FRAME_MJPEG)
            bFrameIndex                         3
            bmCapabilities                   0x01
              Still image supported
            wWidth                            176
            wHeight                           144
            dwMinBitRate                  6082560
            dwMaxBitRate                 12165120
            dwMaxVideoFrameBufferSize       50688
            dwDefaultFrameInterval         333333
            bFrameIntervalType                  2
            dwFrameInterval( 0)            333333
            dwFrameInterval( 1)            666666
          VideoStreaming Interface Descriptor:
            bLength                            34
            bDescriptorType                    36
            bDescriptorSubtype                  7 (FRAME_MJPEG)
            bFrameIndex                         4
            bmCapabilities                   0x01
              Still image supported
            wWidth                            320
            wHeight                           240
            dwMinBitRate                 18432000
            dwMaxBitRate                 36864000
            dwMaxVideoFrameBufferSize      153600
            dwDefaultFrameInterval         333333
            bFrameIntervalType                  2
            dwFrameInterval( 0)            333333
            dwFrameInterval( 1)            666666
          VideoStreaming Interface Descriptor:
            bLength                            34
            bDescriptorType                    36
            bDescriptorSubtype                  7 (FRAME_MJPEG)
            bFrameIndex                         5
            bmCapabilities                   0x01
              Still image supported
            wWidth                            352
            wHeight                           288
            dwMinBitRate                 24330240
            dwMaxBitRate                 48660480
            dwMaxVideoFrameBufferSize      202752
            dwDefaultFrameInterval         333333
            bFrameIntervalType                  2
            dwFrameInterval( 0)            333333
            dwFrameInterval( 1)            666666
          VideoStreaming Interface Descriptor:
            bLength                            30
            bDescriptorType                    36
            bDescriptorSubtype                  7 (FRAME_MJPEG)
            bFrameIndex                         6
            bmCapabilities                   0x01
              Still image supported
            wWidth                           1280
            wHeight                           720
            dwMinBitRate                442368000
            dwMaxBitRate                442368000
            dwMaxVideoFrameBufferSize     1843200
            dwDefaultFrameInterval         333333
            bFrameIntervalType                  1
            dwFrameInterval( 0)            333333
          VideoStreaming Interface Descriptor:
            bLength                            30
            bDescriptorType                    36
            bDescriptorSubtype                  7 (FRAME_MJPEG)
            bFrameIndex                         7
            bmCapabilities                   0x01
              Still image supported
            wWidth                           1280
            wHeight                           800
            dwMinBitRate                491520000
            dwMaxBitRate                491520000
            dwMaxVideoFrameBufferSize     2048000
            dwDefaultFrameInterval         333333
            bFrameIntervalType                  1
            dwFrameInterval( 0)            333333
          VideoStreaming Interface Descriptor:
            bLength                             6
            bDescriptorType                    36
            bDescriptorSubtype                 13 (COLORFORMAT)
            bColorPrimaries                     1 (BT.709,sRGB)
            bTransferCharacteristics            1 (BT.709)
            bMatrixCoefficients                 4 (SMPTE 170M (BT.601))
    • 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

      可以看到,这款摄像头支持两种 format 一种是未压缩的,另一种是压缩的 MJPEG ,对于每一个 format 下面又有多个 frame ,frame 的区别比如像素大小。

    VideoStreaming Endpoint Descriptors

      The following sections describe all possible endpoint-related descriptors for the VideoStreaming 
    interface.

    VS Video Data Endpoint Descriptors

    Standard VS Isochronous Video Data Endpoint Descriptor

      Table 3-20 Standard VS Isochronous Video Data Endpoint Descriptor

    Standard VS Bulk Video Data Endpoint Descriptor

      Table 3-21 Standard VS Bulk Video Data Endpoint Descriptor

    VS Bulk Still Image Data Endpoint Descriptors

    Standard VS Bulk Still Image Data Endpoint Descriptor

      Table 3-22 Standard VS Bulk Still Image Data Endpoint Descriptor

    打印描述符

      根据上述的分析过程,我们可以把所有的描述符信息打印出来,前面举例是lsusb 打印出来的信息,那么,为了方便,我们可以参考 lsusb 的源码来写打印程序。

    #include <linux/kernel.h>
    #include <linux/list.h>
    #include <linux/module.h>
    #include <linux/usb.h>
    #include <linux/videodev2.h>
    #include <linux/vmalloc.h>
    #include <linux/wait.h>
    #include <asm/atomic.h>
    #include <asm/unaligned.h>
    
    #include <media/v4l2-common.h>
    
    static const char *get_guid(const unsigned char *buf)
    {
        static char guid[39];
    
        /* NOTE:  see RFC 4122 for more information about GUID/UUID
         * structure.  The first fields fields are historically big
         * endian numbers, dating from Apollo mc68000 workstations.
         */
        sprintf(guid, "{%02x%02x%02x%02x"
                "-%02x%02x"
                "-%02x%02x"
                "-%02x%02x"
                "-%02x%02x%02x%02x%02x%02x}",
               buf[0], buf[1], buf[2], buf[3],
               buf[4], buf[5],
               buf[6], buf[7],
               buf[8], buf[9],
               buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]);
        return guid;
    }
    
    static void parse_videocontrol_interface(struct usb_interface *intf, unsigned char *buf, int buflen)
    {
        static const char * const ctrlnames[] = {
            "Brightness", "Contrast", "Hue", "Saturation", "Sharpness", "Gamma",
            "White Balance Temperature", "White Balance Component", "Backlight Compensation",
            "Gain", "Power Line Frequency", "Hue, Auto", "White Balance Temperature, Auto",
            "White Balance Component, Auto", "Digital Multiplier", "Digital Multiplier Limit",
            "Analog Video Standard", "Analog Video Lock Status"
        };
        static const char * const camctrlnames[] = {
            "Scanning Mode", "Auto-Exposure Mode", "Auto-Exposure Priority",
            "Exposure Time (Absolute)", "Exposure Time (Relative)", "Focus (Absolute)",
            "Focus (Relative)", "Iris (Absolute)", "Iris (Relative)", "Zoom (Absolute)",
            "Zoom (Relative)", "PanTilt (Absolute)", "PanTilt (Relative)",
            "Roll (Absolute)", "Roll (Relative)", "Reserved", "Reserved", "Focus, Auto",
            "Privacy"
        };
        static const char * const stdnames[] = {
            "None", "NTSC - 525/60", "PAL - 625/50", "SECAM - 625/50",
            "NTSC - 625/50", "PAL - 525/60" };
        unsigned int i, ctrls, stds, n, p, termt, freq;
    
        while (buflen > 0)
        {
    
            if (buf[1] != USB_DT_CS_INTERFACE)
                printk("      Warning: Invalid descriptor\n");
            else if (buf[0] < 3)
                printk("      Warning: Descriptor too short\n");
            printk("      VideoControl Interface Descriptor:\n"
                   "        bLength             %5u\n"
                   "        bDescriptorType     %5u\n"
                   "        bDescriptorSubtype  %5u ",
                   buf[0], buf[1], buf[2]);
            switch (buf[2]) {
            case 0x01:  /* HEADER */
                printk("(HEADER)\n");
                n = buf[11];
                if (buf[0] < 12+n)
                    printk("      Warning: Descriptor too short\n");
                freq = buf[7] | (buf[8] << 8) | (buf[9] << 16) | (buf[10] << 24);
                printk("        bcdUVC              %2x.%02x\n"
                       "        wTotalLength        %5u\n"
                       "        dwClockFrequency    %5u.%06uMHz\n"
                       "        bInCollection       %5u\n",
                       buf[4], buf[3], buf[5] | (buf[6] << 8), freq / 1000000,
                       freq % 1000000, n);
                for (i = 0; i < n; i++)
                    printk("        baInterfaceNr(%2u)   %5u\n", i, buf[12+i]);
                break;
    
            case 0x02:  /* INPUT_TERMINAL */
                printk("(INPUT_TERMINAL)\n");
                termt = buf[4] | (buf[5] << 8);
                n = termt == 0x0201 ? 7 : 0;
                if (buf[0] < 8 + n)
                    printk("      Warning: Descriptor too short\n");
                printk("        bTerminalID         %5u\n"
                       "        wTerminalType      0x%04x\n"
                       "        bAssocTerminal      %5u\n",
                       buf[3], termt, buf[6]);
                printk("        iTerminal           %5u\n",
                       buf[7]);
                if (termt == 0x0201) {
                    n += buf[14];
                    printk("        wObjectiveFocalLengthMin  %5u\n"
                           "        wObjectiveFocalLengthMax  %5u\n"
                           "        wOcularFocalLength        %5u\n"
                           "        bControlSize              %5u\n",
                           buf[8] | (buf[9] << 8), buf[10] | (buf[11] << 8),
                           buf[12] | (buf[13] << 8), buf[14]);
                    ctrls = 0;
                    for (i = 0; i < 3 && i < buf[14]; i++)
                        ctrls = (ctrls << 8) | buf[8+n-i-1];
                    printk("        bmControls           0x%08x\n", ctrls);
                    for (i = 0; i < 19; i++)
                        if ((ctrls >> i) & 1)
                            printk("          %s\n", camctrlnames[i]);
                }
                break;
    
            case 0x03:  /* OUTPUT_TERMINAL */
                printk("(OUTPUT_TERMINAL)\n");
                termt = buf[4] | (buf[5] << 8);
                if (buf[0] < 9)
                    printk("      Warning: Descriptor too short\n");
                printk("        bTerminalID         %5u\n"
                       "        wTerminalType      0x%04x\n"
                       "        bAssocTerminal      %5u\n"
                       "        bSourceID           %5u\n"
                       "        iTerminal           %5u\n",
                       buf[3], termt, buf[6], buf[7], buf[8]);
                break;
    
            case 0x04:  /* SELECTOR_UNIT */
                printk("(SELECTOR_UNIT)\n");
                p = buf[4];
                if (buf[0] < 6+p)
                    printk("      Warning: Descriptor too short\n");
    
                printk("        bUnitID             %5u\n"
                       "        bNrInPins           %5u\n",
                       buf[3], p);
                for (i = 0; i < p; i++)
                    printk("        baSource(%2u)        %5u\n", i, buf[5+i]);
                printk("        iSelector           %5u\n",
                       buf[5+p]);
                break;
    
            case 0x05:  /* PROCESSING_UNIT */
                printk("(PROCESSING_UNIT)\n");
                n = buf[7];
                if (buf[0] < 10+n)
                    printk("      Warning: Descriptor too short\n");
                printk("        bUnitID             %5u\n"
                       "        bSourceID           %5u\n"
                       "        wMaxMultiplier      %5u\n"
                       "        bControlSize        %5u\n",
                       buf[3], buf[4], buf[5] | (buf[6] << 8), n);
                ctrls = 0;
                for (i = 0; i < 3 && i < n; i++)
                    ctrls = (ctrls << 8) | buf[8+n-i-1];
                printk("        bmControls     0x%08x\n", ctrls);
                for (i = 0; i < 18; i++)
                    if ((ctrls >> i) & 1)
                        printk("          %s\n", ctrlnames[i]);
                stds = buf[9+n];
                printk("        iProcessing         %5u\n"
                       "        bmVideoStandards     0x%2x\n", buf[8+n], stds);
                for (i = 0; i < 6; i++)
                    if ((stds >> i) & 1)
                        printk("          %s\n", stdnames[i]);
                break;
    
            case 0x06:  /* EXTENSION_UNIT */
                printk("(EXTENSION_UNIT)\n");
                p = buf[21];
                n = buf[22+p];
                if (buf[0] < 24+p+n)
                    printk("      Warning: Descriptor too short\n");
                printk("        bUnitID             %5u\n"
                       "        guidExtensionCode         %s\n"
                       "        bNumControl         %5u\n"
                       "        bNrPins             %5u\n",
                       buf[3], get_guid(&buf[4]), buf[20], buf[21]);
                for (i = 0; i < p; i++)
                    printk("        baSourceID(%2u)      %5u\n", i, buf[22+i]);
                printk("        bControlSize        %5u\n", buf[22+p]);
                for (i = 0; i < n; i++)
                    printk("        bmControls(%2u)       0x%02x\n", i, buf[23+p+i]);
                printk("        iExtension          %5u\n",
                       buf[23+p+n]);
                break;
    
            default:
                printk("(unknown)\n"
                       "        Invalid desc subtype:");
                break;
            }
    
            buflen -= buf[0];
            buf    += buf[0];
        }
    }
    
    
    static void parse_videostreaming_interface(struct usb_interface *intf, unsigned char *buf, int buflen)
    {
        static const char * const colorPrims[] = { "Unspecified", "BT.709,sRGB",
            "BT.470-2 (M)", "BT.470-2 (B,G)", "SMPTE 170M", "SMPTE 240M" };
        static const char * const transferChars[] = { "Unspecified", "BT.709",
            "BT.470-2 (M)", "BT.470-2 (B,G)", "SMPTE 170M", "SMPTE 240M",
            "Linear", "sRGB"};
        static const char * const matrixCoeffs[] = { "Unspecified", "BT.709",
            "FCC", "BT.470-2 (B,G)", "SMPTE 170M (BT.601)", "SMPTE 240M" };
        unsigned int i, m, n, p, flags, len;
    
        while (buflen > 0)
        {
    
            if (buf[1] != USB_DT_CS_INTERFACE)
                printk("      Warning: Invalid descriptor\n");
            else if (buf[0] < 3)
                printk("      Warning: Descriptor too short\n");
            printk("      VideoStreaming Interface Descriptor:\n"
                   "        bLength                         %5u\n"
                   "        bDescriptorType                 %5u\n"
                   "        bDescriptorSubtype              %5u ",
                   buf[0], buf[1], buf[2]);
            switch (buf[2]) {
            case 0x01: /* INPUT_HEADER */
                printk("(INPUT_HEADER)\n");
                p = buf[3];
                n = buf[12];
                if (buf[0] < 13+p*n)
                    printk("      Warning: Descriptor too short\n");
                printk("        bNumFormats                     %5u\n"
                       "        wTotalLength                    %5u\n"
                       "        bEndPointAddress                %5u\n"
                       "        bmInfo                          %5u\n"
                       "        bTerminalLink                   %5u\n"
                       "        bStillCaptureMethod             %5u\n"
                       "        bTriggerSupport                 %5u\n"
                       "        bTriggerUsage                   %5u\n"
                       "        bControlSize                    %5u\n",
                       p, buf[4] | (buf[5] << 8), buf[6], buf[7], buf[8],
                       buf[9], buf[10], buf[11], n);
                for (i = 0; i < p; i++)
                    printk(
                    "        bmaControls(%2u)                 %5u\n",
                        i, buf[13+p*n]);
                break;
    
            case 0x02: /* OUTPUT_HEADER */
                printk("(OUTPUT_HEADER)\n");
                p = buf[3];
                n = buf[8];
                if (buf[0] < 9+p*n)
                    printk("      Warning: Descriptor too short\n");
                printk("        bNumFormats                 %5u\n"
                       "        wTotalLength                %5u\n"
                       "        bEndpointAddress            %5u\n"
                       "        bTerminalLink               %5u\n"
                       "        bControlSize                %5u\n",
                       p, buf[4] | (buf[5] << 8), buf[6], buf[7], n);
                for (i = 0; i < p; i++)
                    printk(
                    "        bmaControls(%2u)             %5u\n",
                        i, buf[9+p*n]);
                break;
    
            case 0x03: /* STILL_IMAGE_FRAME */
                printk("(STILL_IMAGE_FRAME)\n");
                n = buf[4];
                m = buf[5+4*n];
                if (buf[0] < 6+4*n+m)
                    printk("      Warning: Descriptor too short\n");
                printk("        bEndpointAddress                %5u\n"
                       "        bNumImageSizePatterns             %3u\n",
                       buf[3], n);
                for (i = 0; i < n; i++)
                    printk("        wWidth(%2u)                      %5u\n"
                           "        wHeight(%2u)                     %5u\n",
                           i, buf[5+4*i] | (buf[6+4*i] << 8),
                           i, buf[7+4*i] | (buf[8+4*i] << 8));
                printk("        bNumCompressionPatterns           %3u\n", n);
                for (i = 0; i < m; i++)
                    printk("        bCompression(%2u)                %5u\n",
                           i, buf[6+4*n+i]);
                break;
    
            case 0x04: /* FORMAT_UNCOMPRESSED */
            case 0x10: /* FORMAT_FRAME_BASED */
                if (buf[2] == 0x04) {
                    printk("(FORMAT_UNCOMPRESSED)\n");
                    len = 27;
                } else {
                    printk("(FORMAT_FRAME_BASED)\n");
                    len = 28;
                }
                if (buf[0] < len)
                    printk("      Warning: Descriptor too short\n");
                flags = buf[25];
                printk("        bFormatIndex                    %5u\n"
                       "        bNumFrameDescriptors            %5u\n"
                       "        guidFormat                            %s\n"
                       "        bBitsPerPixel                   %5u\n"
                       "        bDefaultFrameIndex              %5u\n"
                       "        bAspectRatioX                   %5u\n"
                       "        bAspectRatioY                   %5u\n"
                       "        bmInterlaceFlags                 0x%02x\n",
                       buf[3], buf[4], get_guid(&buf[5]), buf[21], buf[22],
                       buf[23], buf[24], flags);
                printk("          Interlaced stream or variable: %s\n",
                       (flags & (1 << 0)) ? "Yes" : "No");
                printk("          Fields per frame: %u fields\n",
                       (flags & (1 << 1)) ? 1 : 2);
                printk("          Field 1 first: %s\n",
                       (flags & (1 << 2)) ? "Yes" : "No");
                printk("          Field pattern: ");
                switch ((flags >> 4) & 0x03) {
                case 0:
                    printk("Field 1 only\n");
                    break;
                case 1:
                    printk("Field 2 only\n");
                    break;
                case 2:
                    printk("Regular pattern of fields 1 and 2\n");
                    break;
                case 3:
                    printk("Random pattern of fields 1 and 2\n");
                    break;
                }
                printk("          bCopyProtect                  %5u\n", buf[26]);
                if (buf[2] == 0x10)
                    printk("          bVariableSize                 %5u\n", buf[27]);
                break;
    
            case 0x05: /* FRAME UNCOMPRESSED */
            case 0x07: /* FRAME_MJPEG */
            case 0x11: /* FRAME_FRAME_BASED */
                if (buf[2] == 0x05) {
                    printk("(FRAME_UNCOMPRESSED)\n");
                    n = 25;
                } else if (buf[2] == 0x07) {
                    printk("(FRAME_MJPEG)\n");
                    n = 25;
                } else {
                    printk("(FRAME_FRAME_BASED)\n");
                    n = 21;
                }
                len = (buf[n] != 0) ? (26+buf[n]*4) : 38;
                if (buf[0] < len)
                    printk("      Warning: Descriptor too short\n");
                flags = buf[4];
                printk("        bFrameIndex                     %5u\n"
                       "        bmCapabilities                   0x%02x\n",
                       buf[3], flags);
                printk("          Still image %ssupported\n",
                       (flags & (1 << 0)) ? "" : "un");
                if (flags & (1 << 1))
                    printk("          Fixed frame-rate\n");
                printk("        wWidth                          %5u\n"
                       "        wHeight                         %5u\n"
                       "        dwMinBitRate                %9u\n"
                       "        dwMaxBitRate                %9u\n",
                       buf[5] | (buf[6] <<  8), buf[7] | (buf[8] << 8),
                       buf[9] | (buf[10] << 8) | (buf[11] << 16) | (buf[12] << 24),
                       buf[13] | (buf[14] << 8) | (buf[15] << 16) | (buf[16] << 24));
                if (buf[2] == 0x11)
                    printk("        dwDefaultFrameInterval      %9u\n"
                           "        bFrameIntervalType              %5u\n"
                           "        dwBytesPerLine              %9u\n",
                           buf[17] | (buf[18] << 8) | (buf[19] << 16) | (buf[20] << 24),
                           buf[21],
                           buf[22] | (buf[23] << 8) | (buf[24] << 16) | (buf[25] << 24));
                else
                    printk("        dwMaxVideoFrameBufferSize   %9u\n"
                           "        dwDefaultFrameInterval      %9u\n"
                           "        bFrameIntervalType              %5u\n",
                           buf[17] | (buf[18] << 8) | (buf[19] << 16) | (buf[20] << 24),
                           buf[21] | (buf[22] << 8) | (buf[23] << 16) | (buf[24] << 24),
                           buf[25]);
                if (buf[n] == 0)
                    printk("        dwMinFrameInterval          %9u\n"
                           "        dwMaxFrameInterval          %9u\n"
                           "        dwFrameIntervalStep         %9u\n",
                           buf[26] | (buf[27] << 8) | (buf[28] << 16) | (buf[29] << 24),
                           buf[30] | (buf[31] << 8) | (buf[32] << 16) | (buf[33] << 24),
                           buf[34] | (buf[35] << 8) | (buf[36] << 16) | (buf[37] << 24));
                else
                    for (i = 0; i < buf[n]; i++)
                        printk("        dwFrameInterval(%2u)         %9u\n",
                               i, buf[26+4*i] | (buf[27+4*i] << 8) |
                               (buf[28+4*i] << 16) | (buf[29+4*i] << 24));
                break;
    
            case 0x06: /* FORMAT_MJPEG */
                printk("(FORMAT_MJPEG)\n");
                if (buf[0] < 11)
                    printk("      Warning: Descriptor too short\n");
                flags = buf[5];
                printk("        bFormatIndex                    %5u\n"
                       "        bNumFrameDescriptors            %5u\n"
                       "        bFlags                          %5u\n",
                       buf[3], buf[4], flags);
                printk("          Fixed-size samples: %s\n",
                       (flags & (1 << 0)) ? "Yes" : "No");
                flags = buf[9];
                printk("        bDefaultFrameIndex              %5u\n"
                       "        bAspectRatioX                   %5u\n"
                       "        bAspectRatioY                   %5u\n"
                       "        bmInterlaceFlags                 0x%02x\n",
                       buf[6], buf[7], buf[8], flags);
                printk("          Interlaced stream or variable: %s\n",
                       (flags & (1 << 0)) ? "Yes" : "No");
                printk("          Fields per frame: %u fields\n",
                       (flags & (1 << 1)) ? 2 : 1);
                printk("          Field 1 first: %s\n",
                       (flags & (1 << 2)) ? "Yes" : "No");
                printk("          Field pattern: ");
                switch ((flags >> 4) & 0x03) {
                case 0:
                    printk("Field 1 only\n");
                    break;
                case 1:
                    printk("Field 2 only\n");
                    break;
                case 2:
                    printk("Regular pattern of fields 1 and 2\n");
                    break;
                case 3:
                    printk("Random pattern of fields 1 and 2\n");
                    break;
                }
                printk("          bCopyProtect                  %5u\n", buf[10]);
                break;
    
            case 0x0a: /* FORMAT_MPEG2TS */
                printk("(FORMAT_MPEG2TS)\n");
                len = buf[0] < 23 ? 7 : 23;
                if (buf[0] < len)
                    printk("      Warning: Descriptor too short\n");
                printk("        bFormatIndex                    %5u\n"
                       "        bDataOffset                     %5u\n"
                       "        bPacketLength                   %5u\n"
                       "        bStrideLength                   %5u\n",
                       buf[3], buf[4], buf[5], buf[6]);
                if (len > 7)
                    printk("        guidStrideFormat                      %s\n",
                           get_guid(&buf[7]));
                break;
    
            case 0x0d: /* COLORFORMAT */
                printk("(COLORFORMAT)\n");
                if (buf[0] < 6)
                    printk("      Warning: Descriptor too short\n");
                printk("        bColorPrimaries                 %5u (%s)\n",
                       buf[3], (buf[3] <= 5) ? colorPrims[buf[3]] : "Unknown");
                printk("        bTransferCharacteristics        %5u (%s)\n",
                       buf[4], (buf[4] <= 7) ? transferChars[buf[4]] : "Unknown");
                printk("        bMatrixCoefficients             %5u (%s)\n",
                       buf[5], (buf[5] <= 5) ? matrixCoeffs[buf[5]] : "Unknown");
                break;
    
            default:
                printk("        Invalid desc subtype:");
                break;
            }
            buflen -= buf[0];
            buf    += buf[0];
        }
    }
    
    
    static void dump_endpoint(const struct usb_endpoint_descriptor *endpoint)
    {
        static const char * const typeattr[] = {
            "Control",
            "Isochronous",
            "Bulk",
            "Interrupt"
        };
        static const char * const syncattr[] = {
            "None",
            "Asynchronous",
            "Adaptive",
            "Synchronous"
        };
        static const char * const usage[] = {
            "Data",
            "Feedback",
            "Implicit feedback Data",
            "(reserved)"
        };
        static const char * const hb[] = { "1x", "2x", "3x", "(?\?)" };
        unsigned wmax = le16_to_cpu(endpoint->wMaxPacketSize);
    
        printk("      Standard Endpoint Descriptor:\n"
               "        bLength             %5u\n"
               "        bDescriptorType     %5u\n"
               "        bEndpointAddress     0x%02x  EP %u %s\n"
               "        bmAttributes        %5u\n"
               "          Transfer Type            %s\n"
               "          Synch Type               %s\n"
               "          Usage Type               %s\n"
               "        wMaxPacketSize     0x%04x  %s %d bytes\n"
               "        bInterval           %5u\n",
               endpoint->bLength,
               endpoint->bDescriptorType,
               endpoint->bEndpointAddress,
               endpoint->bEndpointAddress & 0x0f,
               (endpoint->bEndpointAddress & 0x80) ? "IN" : "OUT",
               endpoint->bmAttributes,
               typeattr[endpoint->bmAttributes & 3],
               syncattr[(endpoint->bmAttributes >> 2) & 3],
               usage[(endpoint->bmAttributes >> 4) & 3],
               wmax, hb[(wmax >> 11) & 3], wmax & 0x7ff,
               endpoint->bInterval);
        /* only for audio endpoints */
        if (endpoint->bLength == 9)
            printk("        bRefresh            %5u\n"
                   "        bSynchAddress       %5u\n",
                   endpoint->bRefresh, endpoint->bSynchAddress);
    
    }
    
    
    static int myuvc_probe(struct usb_interface *intf,
                 const struct usb_device_id *id)
    {
        static int cnt = 0;
        struct usb_device *dev = interface_to_usbdev(intf);
        struct usb_device_descriptor *descriptor = &dev->descriptor;
        struct usb_host_config *hostconfig;
        struct usb_config_descriptor *config;
        struct usb_interface_assoc_descriptor *assoc_desc;
        struct usb_interface_descriptor *interface;
        struct usb_endpoint_descriptor  *endpoint;
        int i, j, k, l, m;
        unsigned char *buffer;
        int buflen;
        int desc_len;
        int desc_cnt;
    
        printk("myuvc_probe : cnt = %d\n", cnt++);
    
        /* 打印设备描述符 */
        printk("Device Descriptor:\n"
               "  bLength             %5u\n"
               "  bDescriptorType     %5u\n"
               "  bcdUSB              %2x.%02x\n"
               "  bDeviceClass        %5u \n"
               "  bDeviceSubClass     %5u \n"
               "  bDeviceProtocol     %5u \n"
               "  bMaxPacketSize0     %5u\n"
               "  idVendor           0x%04x \n"
               "  idProduct          0x%04x \n"
               "  bcdDevice           %2x.%02x\n"
               "  iManufacturer       %5u\n"
               "  iProduct            %5u\n"
               "  iSerial             %5u\n"
               "  bNumConfigurations  %5u\n",
               descriptor->bLength, descriptor->bDescriptorType,
               descriptor->bcdUSB >> 8, descriptor->bcdUSB & 0xff,
               descriptor->bDeviceClass, 
               descriptor->bDeviceSubClass,
               descriptor->bDeviceProtocol, 
               descriptor->bMaxPacketSize0,
               descriptor->idVendor,  descriptor->idProduct,
               descriptor->bcdDevice >> 8, descriptor->bcdDevice & 0xff,
               descriptor->iManufacturer, 
               descriptor->iProduct, 
               descriptor->iSerialNumber, 
               descriptor->bNumConfigurations);
    
        for (i = 0; i < descriptor->bNumConfigurations; i++)
        {
            hostconfig = &dev->config[i];
            config     = &hostconfig->desc;
            // 配置描述符
            printk("  Configuration Descriptor %d:\n"
                   "    bLength             %5u\n"
                   "    bDescriptorType     %5u\n"
                   "    wTotalLength        %5u\n"
                   "    bNumInterfaces      %5u\n"
                   "    bConfigurationValue %5u\n"
                   "    iConfiguration      %5u\n"
                   "    bmAttributes         0x%02x\n",
                   i, 
                   config->bLength, config->bDescriptorType,
                   le16_to_cpu(config->wTotalLength),
                   config->bNumInterfaces, config->bConfigurationValue,
                   config->iConfiguration,
                   config->bmAttributes);
            // 接口联合描述符
            assoc_desc = hostconfig->intf_assoc[0];
            printk("    Interface Association Descriptor:\n"
                   "      bLength             %5u\n"
                   "      bDescriptorType     %5u\n"
                   "      bFirstInterface     %5u\n"
                   "      bInterfaceCount     %5u\n"
                   "      bFunctionClass      %5u\n"
                   "      bFunctionSubClass   %5u\n"
                   "      bFunctionProtocol   %5u\n"
                   "      iFunction           %5u\n",
                assoc_desc->bLength,
                assoc_desc->bDescriptorType,
                assoc_desc->bFirstInterface,
                assoc_desc->bInterfaceCount,
                assoc_desc->bFunctionClass,
                assoc_desc->bFunctionSubClass,
                assoc_desc->bFunctionProtocol,
                assoc_desc->iFunction);    
    
                // 打印当前 probe 传进来接口的每一个设置的接口描述符
                for (j = 0; j < intf->num_altsetting; j++)
                {
                    interface = &intf->altsetting[j].desc;
                    // Standard Interface Descriptor
                    printk("    Standard Interface Descriptor -> altsetting %d:\n"
                           "      bLength             %5u\n"
                           "      bDescriptorType     %5u\n"
                           "      bInterfaceNumber    %5u\n"
                           "      bAlternateSetting   %5u\n"
                           "      bNumEndpoints       %5u\n"
                           "      bInterfaceClass     %5u\n"
                           "      bInterfaceSubClass  %5u\n"
                           "      bInterfaceProtocol  %5u\n"
                           "      iInterface          %5u\n",
                           j, 
                           interface->bLength, interface->bDescriptorType, interface->bInterfaceNumber,
                           interface->bAlternateSetting, interface->bNumEndpoints, interface->bInterfaceClass,
                           interface->bInterfaceSubClass, interface->bInterfaceProtocol,
                           interface->iInterface);
    
                    /* 打印端点描述符 */
                    for (m = 0; m < interface->bNumEndpoints; m++)
                    {
                        endpoint = &intf->altsetting[j].endpoint[m].desc;
                        dump_endpoint(endpoint);
    
                        /* class specific endpoint Descriptor */
                        buffer = &intf->altsetting[j].endpoint[m].extra;
                        buflen = intf->altsetting[j].endpoint[m].enabled;
                        printk("      Class-specific Endpoint Descriptor:\n");
                        k = 0;
                        desc_cnt = 0;
                        while (k < buflen)
                        {
                            desc_len = buffer[k];
                            printk("extra desc %d: ", desc_cnt);
                            for (l = 0; l < desc_len; l++, k++)
                            {
                                printk("%02x ", buffer[k]);
                            }
                            desc_cnt++;
                            printk("\n");
                        }
                    }
                } 
                // 只打印当前设置的 class specific Descriptor
                buffer = intf->cur_altsetting->extra;
                // Class-specific Interface Descriptor
                printk("    Class-specific Interface Descriptor\n");
                buflen = intf->cur_altsetting->extralen;
                printk("extra buffer of interface %d:\n", cnt-1);
                k = 0;
                desc_cnt = 0;
                while (k < buflen)
                {
                    desc_len = buffer[k];
                    printk("extra desc %d: ", desc_cnt);
                    for (l = 0; l < desc_len; l++, k++)
                    {
                        printk("%02x ", buffer[k]);
                    }
                    desc_cnt++;
                    printk("\n");
                }
                // 解析 Class-specific Interface Descriptor 
                interface = &intf->cur_altsetting->desc;
                if ((buffer[1] == USB_DT_CS_INTERFACE) && (interface->bInterfaceSubClass == 1))
                {
                    parse_videocontrol_interface(intf, buffer, buflen);
                }
                if ((buffer[1] == USB_DT_CS_INTERFACE) && (interface->bInterfaceSubClass == 2))
                {
                    parse_videostreaming_interface(intf, buffer, buflen);
                }           
        }    
        return 0;
    }
    
    static void myuvc_disconnect(struct usb_interface *intf)
    {
        static int cnt = 0;
        printk("myuvc_disconnect : cnt = %d\n", cnt++);
    }
    
    static struct usb_device_id myuvc_ids[] = {
        /* Generic USB Video Class */
        { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },  /* VideoControl Interface */
        { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 2, 0) },  /* VideoStreaming Interface */
        {}
    };
    
    /* 1. 分配usb_driver */
    /* 2. 设置 */
    static struct usb_driver myuvc_driver = {
        .name       = "myuvc",
        .probe      = myuvc_probe,
        .disconnect = myuvc_disconnect,
        .id_table   = myuvc_ids,
    };
    
    static int myuvc_init(void)
    {
        /* 3. 注册 */
        usb_register(&myuvc_driver);
        return 0;
    }
    
    static void myuvc_exit(void)
    {
        usb_deregister(&myuvc_driver);
    }
    
    module_init(myuvc_init);
    module_exit(myuvc_exit);
    MODULE_LICENSE("GPL");
    
    • 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
    • 720
    • 721
    • 722
    • 723
    • 724
    • 725
    • 726

    描述符打印信息

     myuvc_probe : cnt = 0
     Device Descriptor:
       bLength                18
       bDescriptorType         1
       bcdUSB               2.00
       bDeviceClass          239 
       bDeviceSubClass         2 
       bDeviceProtocol         1 
       bMaxPacketSize0        64
       idVendor           0x04f2 
       idProduct          0xb26a 
       bcdDevice           52.68
       iManufacturer           1
       iProduct                2
       iSerial                 0
       bNumConfigurations      1
       Configuration Descriptor 0:
         bLength                 9
         bDescriptorType         2
         wTotalLength          857
         bNumInterfaces          2
         bConfigurationValue     1
         iConfiguration          0
         bmAttributes         0x80
         Interface Association Descriptor:
           bLength                 8
           bDescriptorType        11
           bFirstInterface         0
           bInterfaceCount         2
           bFunctionClass         14
           bFunctionSubClass       3
           bFunctionProtocol       0
           iFunction               2
         Standard Interface Descriptor -> altsetting 0:
           bLength                 9
           bDescriptorType         4
           bInterfaceNumber        0
           bAlternateSetting       0
           bNumEndpoints           1
           bInterfaceClass        14
           bInterfaceSubClass      1
           bInterfaceProtocol      0
           iInterface              2
           Standard Endpoint Descriptor:
             bLength                 7
             bDescriptorType         5
             bEndpointAddress     0x87  EP 7 IN
             bmAttributes            3
               Transfer Type            Interrupt
               Synch Type               None
               Usage Type               Data
             wMaxPacketSize     0x0010  1x 16 bytes
             bInterval               8
        Class-specific Endpoint Descriptor:
            extra desc 0: 05 25 03 10 00 
        Class-specific Interface Descriptor
            extra buffer of interface 0:
            extra desc 0: 0d 24 01 00 01 6d 00 00 6c dc 02 01 01 
            extra desc 1: 12 24 02 01 01 02 00 00 00 00 00 00 00 00 03 06 00 00 
            extra desc 2: 0b 24 05 02 01 00 40 02 3f 15 00 
            extra desc 3: 1d 24 06 03 82 06 61 63 70 50 ab 49 b8 cc b3 85 5e 8d 22 1d 00 01 02 04 ff ff 1d 00 00 
            extra desc 4: 1d 24 06 04 64 e7 c6 24 51 5f 7e 43 90 89 28 ff a4 87 bd ca 00 01 03 04 0f 00 00 00 00 
            extra desc 5: 09 24 03 05 01 01 00 04 00 
           VideoControl Interface Descriptor:
             bLength                13
             bDescriptorType        36
             bDescriptorSubtype      1 (HEADER)
             bcdUVC               1.00
             wTotalLength          109
             dwClockFrequency       48.000000MHz
             bInCollection           1
             baInterfaceNr( 0)       1
           VideoControl Interface Descriptor:
             bLength                18
             bDescriptorType        36
             bDescriptorSubtype      2 (INPUT_TERMINAL)
             bTerminalID             1
             wTerminalType      0x0201
             bAssocTerminal          0
             iTerminal               0
             wObjectiveFocalLengthMin      0
             wObjectiveFocalLengthMax      0
             wOcularFocalLength            0
             bControlSize                  3
             bmControls           0x00000006
               Auto-Exposure Mode
               Auto-Exposure Priority
           VideoControl Interface Descriptor:
             bLength                11
             bDescriptorType        36
             bDescriptorSubtype      5 (PROCESSING_UNIT)
           Warning: Descriptor too short
             bUnitID                 2
             bSourceID               1
             wMaxMultiplier      16384
             bControlSize            2
             bmControls     0x0000153f
               Brightness
               Contrast
               Hue
               Saturation
               Sharpness
               Gamma
               Backlight Compensation
               Power Line Frequency
               White Balance Temperature, Auto
             iProcessing             0
             bmVideoStandards     0x1d
               None
               PAL - 625/50
               SECAM - 625/50
               NTSC - 625/50
           VideoControl Interface Descriptor:
             bLength                29
             bDescriptorType        36
             bDescriptorSubtype      6 (EXTENSION_UNIT)
             bUnitID                 3
             guidExtensionCode         {82066163-7050-ab49-b8cc-b3855e8d221d}
             bNumControl             0
             bNrPins                 1
             baSourceID( 0)          2
             bControlSize            4
             bmControls( 0)       0xff
             bmControls( 1)       0xff
             bmControls( 2)       0x1d
             bmControls( 3)       0x00
             iExtension              0
           VideoControl Interface Descriptor:
             bLength                29
             bDescriptorType        36
             bDescriptorSubtype      6 (EXTENSION_UNIT)
             bUnitID                 4
             guidExtensionCode         {64e7c624-515f-7e43-9089-28ffa487bdca}
             bNumControl             0
             bNrPins                 1
             baSourceID( 0)          3
             bControlSize            4
             bmControls( 0)       0x0f
             bmControls( 1)       0x00
             bmControls( 2)       0x00
             bmControls( 3)       0x00
             iExtension              0
           VideoControl Interface Descriptor:
             bLength                 9
             bDescriptorType        36
             bDescriptorSubtype      3 (OUTPUT_TERMINAL)
             bTerminalID             5
             wTerminalType      0x0101
             bAssocTerminal          0
             bSourceID               4
             iTerminal               0
     myuvc_probe : cnt = 1
     Device Descriptor:
       bLength                18
       bDescriptorType         1
       bcdUSB               2.00
       bDeviceClass          239 
       bDeviceSubClass         2 
       bDeviceProtocol         1 
       bMaxPacketSize0        64
       idVendor           0x04f2 
       idProduct          0xb26a 
       bcdDevice           52.68
       iManufacturer           1
       iProduct                2
       iSerial                 0
       bNumConfigurations      1
       Configuration Descriptor 0:
         bLength                 9
         bDescriptorType         2
         wTotalLength          857
         bNumInterfaces          2
         bConfigurationValue     1
         iConfiguration          0
         bmAttributes         0x80
         Interface Association Descriptor:
           bLength                 8
           bDescriptorType        11
           bFirstInterface         0
           bInterfaceCount         2
           bFunctionClass         14
           bFunctionSubClass       3
           bFunctionProtocol       0
           iFunction               2
         Standard Interface Descriptor -> altsetting 0:
           bLength                 9
           bDescriptorType         4
           bInterfaceNumber        1
           bAlternateSetting       0
           bNumEndpoints           0
           bInterfaceClass        14
           bInterfaceSubClass      2
           bInterfaceProtocol      0
           iInterface              0
         Standard Interface Descriptor -> altsetting 1:
           bLength                 9
           bDescriptorType         4
           bInterfaceNumber        1
           bAlternateSetting       1
           bNumEndpoints           1
           bInterfaceClass        14
           bInterfaceSubClass      2
           bInterfaceProtocol      0
           iInterface              0
           Standard Endpoint Descriptor:
             bLength                 7
             bDescriptorType         5
             bEndpointAddress     0x81  EP 1 IN
             bmAttributes            5
               Transfer Type            Isochronous
               Synch Type               Asynchronous
               Usage Type               Data
             wMaxPacketSize     0x00c0  1x 192 bytes
             bInterval               1
           Class-specific Endpoint Descriptor:
         Standard Interface Descriptor -> altsetting 2:
           bLength                 9
           bDescriptorType         4
           bInterfaceNumber        1
           bAlternateSetting       2
           bNumEndpoints           1
           bInterfaceClass        14
           bInterfaceSubClass      2
           bInterfaceProtocol      0
           iInterface              0
           Standard Endpoint Descriptor:
             bLength                 7
             bDescriptorType         5
             bEndpointAddress     0x81  EP 1 IN
             bmAttributes            5
               Transfer Type            Isochronous
               Synch Type               Asynchronous
               Usage Type               Data
             wMaxPacketSize     0x0180  1x 384 bytes
             bInterval               1
           Class-specific Endpoint Descriptor:
         Standard Interface Descriptor -> altsetting 3:
           bLength                 9
           bDescriptorType         4
           bInterfaceNumber        1
           bAlternateSetting       3
           bNumEndpoints           1
           bInterfaceClass        14
           bInterfaceSubClass      2
           bInterfaceProtocol      0
           iInterface              0
           Standard Endpoint Descriptor:
             bLength                 7
             bDescriptorType         5
             bEndpointAddress     0x81  EP 1 IN
             bmAttributes            5
               Transfer Type            Isochronous
               Synch Type               Asynchronous
               Usage Type               Data
             wMaxPacketSize     0x0200  1x 512 bytes
             bInterval               1
           Class-specific Endpoint Descriptor:
         Standard Interface Descriptor -> altsetting 4:
           bLength                 9
           bDescriptorType         4
           bInterfaceNumber        1
           bAlternateSetting       4
           bNumEndpoints           1
           bInterfaceClass        14
           bInterfaceSubClass      2
           bInterfaceProtocol      0
           iInterface              0
           Standard Endpoint Descriptor:
             bLength                 7
             bDescriptorType         5
             bEndpointAddress     0x81  EP 1 IN
             bmAttributes            5
               Transfer Type            Isochronous
               Synch Type               Asynchronous
               Usage Type               Data
             wMaxPacketSize     0x0280  1x 640 bytes
             bInterval               1
           Class-specific Endpoint Descriptor:
         Standard Interface Descriptor -> altsetting 5:
           bLength                 9
           bDescriptorType         4
           bInterfaceNumber        1
           bAlternateSetting       5
           bNumEndpoints           1
           bInterfaceClass        14
           bInterfaceSubClass      2
           bInterfaceProtocol      0
           iInterface              0
           Standard Endpoint Descriptor:
             bLength                 7
             bDescriptorType         5
             bEndpointAddress     0x81  EP 1 IN
             bmAttributes            5
               Transfer Type            Isochronous
               Synch Type               Asynchronous
               Usage Type               Data
             wMaxPacketSize     0x0320  1x 800 bytes
             bInterval               1
           Class-specific Endpoint Descriptor:
         Standard Interface Descriptor -> altsetting 6:
           bLength                 9
           bDescriptorType         4
           bInterfaceNumber        1
           bAlternateSetting       6
           bNumEndpoints           1
           bInterfaceClass        14
           bInterfaceSubClass      2
           bInterfaceProtocol      0
           iInterface              0
           Standard Endpoint Descriptor:
             bLength                 7
             bDescriptorType         5
             bEndpointAddress     0x81  EP 1 IN
             bmAttributes            5
               Transfer Type            Isochronous
               Synch Type               Asynchronous
               Usage Type               Data
             wMaxPacketSize     0x03b0  1x 944 bytes
             bInterval               1
           Class-specific Endpoint Descriptor:
         Standard Interface Descriptor -> altsetting 7:
           bLength                 9
           bDescriptorType         4
           bInterfaceNumber        1
           bAlternateSetting       7
           bNumEndpoints           1
           bInterfaceClass        14
           bInterfaceSubClass      2
           bInterfaceProtocol      0
           iInterface              0
           Standard Endpoint Descriptor:
             bLength                 7
             bDescriptorType         5
             bEndpointAddress     0x81  EP 1 IN
             bmAttributes            5
               Transfer Type            Isochronous
               Synch Type               Asynchronous
               Usage Type               Data
             wMaxPacketSize     0x0a80  2x 640 bytes
             bInterval               1
           Class-specific Endpoint Descriptor:
         Standard Interface Descriptor -> altsetting 8:
           bLength                 9
           bDescriptorType         4
           bInterfaceNumber        1
           bAlternateSetting       8
           bNumEndpoints           1
           bInterfaceClass        14
           bInterfaceSubClass      2
           bInterfaceProtocol      0
           iInterface              0
           Standard Endpoint Descriptor:
             bLength                 7
             bDescriptorType         5
             bEndpointAddress     0x81  EP 1 IN
             bmAttributes            5
               Transfer Type            Isochronous
               Synch Type               Asynchronous
               Usage Type               Data
             wMaxPacketSize     0x0b20  2x 800 bytes
             bInterval               1
           Class-specific Endpoint Descriptor:
         Standard Interface Descriptor -> altsetting 9:
           bLength                 9
           bDescriptorType         4
           bInterfaceNumber        1
           bAlternateSetting       9
           bNumEndpoints           1
           bInterfaceClass        14
           bInterfaceSubClass      2
           bInterfaceProtocol      0
           iInterface              0
           Standard Endpoint Descriptor:
             bLength                 7
             bDescriptorType         5
             bEndpointAddress     0x81  EP 1 IN
             bmAttributes            5
               Transfer Type            Isochronous
               Synch Type               Asynchronous
               Usage Type               Data
             wMaxPacketSize     0x0be0  2x 992 bytes
             bInterval               1
           Class-specific Endpoint Descriptor:
         Standard Interface Descriptor -> altsetting 10:
           bLength                 9
           bDescriptorType         4
           bInterfaceNumber        1
           bAlternateSetting      10
           bNumEndpoints           1
           bInterfaceClass        14
           bInterfaceSubClass      2
           bInterfaceProtocol      0
           iInterface              0
           Standard Endpoint Descriptor:
             bLength                 7
             bDescriptorType         5
             bEndpointAddress     0x81  EP 1 IN
             bmAttributes            5
               Transfer Type            Isochronous
               Synch Type               Asynchronous
               Usage Type               Data
             wMaxPacketSize     0x1380  3x 896 bytes
             bInterval               1
           Class-specific Endpoint Descriptor:
         Standard Interface Descriptor -> altsetting 11:
           bLength                 9
           bDescriptorType         4
           bInterfaceNumber        1
           bAlternateSetting      11
           bNumEndpoints           1
           bInterfaceClass        14
           bInterfaceSubClass      2
           bInterfaceProtocol      0
           iInterface              0
           Standard Endpoint Descriptor:
             bLength                 7
             bDescriptorType         5
             bEndpointAddress     0x81  EP 1 IN
             bmAttributes            5
               Transfer Type            Isochronous
               Synch Type               Asynchronous
               Usage Type               Data
             wMaxPacketSize     0x13fc  3x 1020 bytes
             bInterval               1
        Class-specific Endpoint Descriptor:
        Class-specific Interface Descriptor
            extra buffer of interface 1:
            extra desc 0: 0f 24 01 02 0d 02 81 00 05 01 01 00 01 00 04 
            extra desc 1: 1b 24 04 01 07 59 55 59 32 00 00 10 00 80 00 00 aa 00 38 9b 71 10 01 00 00 00 00 
            extra desc 2: 22 24 05 01 01 80 02 e0 01 00 00 65 04 00 00 ca 08 00 60 09 00 15 16 05 00 02 15 16 05 00 2a 2c 0a 00 
            extra desc 3: 22 24 05 02 01 a0 00 78 00 00 50 46 00 00 a0 8c 00 00 96 00 00 15 16 05 00 02 15 16 05 00 2a 2c 0a 00 
            extra desc 4: 22 24 05 03 01 b0 00 90 00 00 d0 5c 00 00 a0 b9 00 00 c6 00 00 15 16 05 00 02 15 16 05 00 2a 2c 0a 00 
            extra desc 5: 22 24 05 04 01 40 01 f0 00 00 40 19 01 00 80 32 02 00 58 02 00 15 16 05 00 02 15 16 05 00 2a 2c 0a 00 
            extra desc 6: 22 24 05 05 01 60 01 20 01 00 40 73 01 00 80 e6 02 00 18 03 00 15 16 05 00 02 15 16 05 00 2a 2c 0a 00 
            extra desc 7: 1e 24 05 06 01 00 05 d0 02 00 00 ca 08 00 00 ca 08 00 20 1c 00 40 42 0f 00 01 40 42 0f 00 
            extra desc 8: 1e 24 05 07 01 00 05 20 03 00 00 c4 09 00 00 c4 09 00 40 1f 00 40 42 0f 00 01 40 42 0f 00 
            extra desc 9: 06 24 0d 01 01 04 
            extra desc 10: 0b 24 06 02 07 01 01 00 00 00 00 
            extra desc 11: 22 24 07 01 01 80 02 e0 01 00 00 65 04 00 00 ca 08 00 60 09 00 15 16 05 00 02 15 16 05 00 2a 2c 0a 00 
            extra desc 12: 22 24 07 02 01 a0 00 78 00 00 50 46 00 00 a0 8c 00 00 96 00 00 15 16 05 00 02 15 16 05 00 2a 2c 0a 00 
            extra desc 13: 22 24 07 03 01 b0 00 90 00 00 d0 5c 00 00 a0 b9 00 00 c6 00 00 15 16 05 00 02 15 16 05 00 2a 2c 0a 00 
            extra desc 14: 22 24 07 04 01 40 01 f0 00 00 40 19 01 00 80 32 02 00 58 02 00 15 16 05 00 02 15 16 05 00 2a 2c 0a 00 
            extra desc 15: 22 24 07 05 01 60 01 20 01 00 40 73 01 00 80 e6 02 00 18 03 00 15 16 05 00 02 15 16 05 00 2a 2c 0a 00 
            extra desc 16: 1e 24 07 06 01 00 05 d0 02 00 00 5e 1a 00 00 5e 1a 00 20 1c 00 15 16 05 00 01 15 16 05 00 
            extra desc 17: 1e 24 07 07 01 00 05 20 03 00 00 4c 1d 00 00 4c 1d 00 40 1f 00 15 16 05 00 01 15 16 05 00 
            extra desc 18: 06 24 0d 01 01 04 
           VideoStreaming Interface Descriptor:
             bLength                            15
             bDescriptorType                    36
             bDescriptorSubtype                  1 (INPUT_HEADER)
             bNumFormats                         2
             wTotalLength                      525
             bEndPointAddress                  129
             bmInfo                              0
             bTerminalLink                       5
             bStillCaptureMethod                 1
             bTriggerSupport                     1
             bTriggerUsage                       0
             bControlSize                        1
             bmaControls( 0)                    27
             bmaControls( 1)                    27
           VideoStreaming Interface Descriptor:
             bLength                            27
             bDescriptorType                    36
             bDescriptorSubtype                  4 (FORMAT_UNCOMPRESSED)
             bFormatIndex                        1
             bNumFrameDescriptors                7
             guidFormat                            {59555932-0000-1000-8000-00aa00389b71}
             bBitsPerPixel                      16
             bDefaultFrameIndex                  1
             bAspectRatioX                       0
             bAspectRatioY                       0
             bmInterlaceFlags                 0x00
               Interlaced stream or variable: No
               Fields per frame: 2 fields
               Field 1 first: No
               Field pattern: Field 1 only
               bCopyProtect                      0
           VideoStreaming Interface Descriptor:
             bLength                            34
             bDescriptorType                    36
             bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
             bFrameIndex                         1
             bmCapabilities                   0x01
               Still image supported
             wWidth                            640
             wHeight                           480
             dwMinBitRate                 73728000
             dwMaxBitRate                147456000
             dwMaxVideoFrameBufferSize      614400
             dwDefaultFrameInterval         333333
             bFrameIntervalType                  2
             dwFrameInterval( 0)            333333
             dwFrameInterval( 1)            666666
           VideoStreaming Interface Descriptor:
             bLength                            34
             bDescriptorType                    36
             bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
             bFrameIndex                         2
             bmCapabilities                   0x01
               Still image supported
             wWidth                            160
             wHeight                           120
             dwMinBitRate                  4608000
             dwMaxBitRate                  9216000
             dwMaxVideoFrameBufferSize       38400
             dwDefaultFrameInterval         333333
             bFrameIntervalType                  2
             dwFrameInterval( 0)            333333
             dwFrameInterval( 1)            666666
           VideoStreaming Interface Descriptor:
             bLength                            34
             bDescriptorType                    36
             bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
             bFrameIndex                         3
             bmCapabilities                   0x01
               Still image supported
             wWidth                            176
             wHeight                           144
             dwMinBitRate                  6082560
             dwMaxBitRate                 12165120
             dwMaxVideoFrameBufferSize       50688
             dwDefaultFrameInterval         333333
             bFrameIntervalType                  2
             dwFrameInterval( 0)            333333
             dwFrameInterval( 1)            666666
           VideoStreaming Interface Descriptor:
             bLength                            34
             bDescriptorType                    36
             bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
             bFrameIndex                         4
             bmCapabilities                   0x01
               Still image supported
             wWidth                            320
             wHeight                           240
             dwMinBitRate                 18432000
             dwMaxBitRate                 36864000
             dwMaxVideoFrameBufferSize      153600
             dwDefaultFrameInterval         333333
             bFrameIntervalType                  2
             dwFrameInterval( 0)            333333
             dwFrameInterval( 1)            666666
           VideoStreaming Interface Descriptor:
             bLength                            34
             bDescriptorType                    36
             bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
             bFrameIndex                         5
             bmCapabilities                   0x01
               Still image supported
             wWidth                            352
             wHeight                           288
             dwMinBitRate                 24330240
             dwMaxBitRate                 48660480
             dwMaxVideoFrameBufferSize      202752
             dwDefaultFrameInterval         333333
             bFrameIntervalType                  2
             dwFrameInterval( 0)            333333
             dwFrameInterval( 1)            666666
           VideoStreaming Interface Descriptor:
             bLength                            30
             bDescriptorType                    36
             bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
             bFrameIndex                         6
             bmCapabilities                   0x01
               Still image supported
             wWidth                           1280
             wHeight                           720
             dwMinBitRate                147456000
             dwMaxBitRate                147456000
             dwMaxVideoFrameBufferSize     1843200
             dwDefaultFrameInterval        1000000
             bFrameIntervalType                  1
             dwFrameInterval( 0)           1000000
           VideoStreaming Interface Descriptor:
             bLength                            30
             bDescriptorType                    36
             bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
             bFrameIndex                         7
             bmCapabilities                   0x01
               Still image supported
             wWidth                           1280
             wHeight                           800
             dwMinBitRate                163840000
             dwMaxBitRate                163840000
             dwMaxVideoFrameBufferSize     2048000
             dwDefaultFrameInterval        1000000
             bFrameIntervalType                  1
             dwFrameInterval( 0)           1000000
           VideoStreaming Interface Descriptor:
             bLength                             6
             bDescriptorType                    36
             bDescriptorSubtype                 13 (COLORFORMAT)
             bColorPrimaries                     1 (BT.709,sRGB)
             bTransferCharacteristics            1 (BT.709)
             bMatrixCoefficients                 4 (SMPTE 170M (BT.601))
           VideoStreaming Interface Descriptor:
             bLength                            11
             bDescriptorType                    36
             bDescriptorSubtype                  6 (FORMAT_MJPEG)
             bFormatIndex                        2
             bNumFrameDescriptors                7
             bFlags                              1
               Fixed-size samples: Yes
             bDefaultFrameIndex                  1
             bAspectRatioX                       0
             bAspectRatioY                       0
             bmInterlaceFlags                 0x00
               Interlaced stream or variable: No
               Fields per frame: 1 fields
               Field 1 first: No
               Field pattern: Field 1 only
               bCopyProtect                      0
           VideoStreaming Interface Descriptor:
             bLength                            34
             bDescriptorType                    36
             bDescriptorSubtype                  7 (FRAME_MJPEG)
             bFrameIndex                         1
             bmCapabilities                   0x01
               Still image supported
             wWidth                            640
             wHeight                           480
             dwMinBitRate                 73728000
             dwMaxBitRate                147456000
             dwMaxVideoFrameBufferSize      614400
             dwDefaultFrameInterval         333333
             bFrameIntervalType                  2
             dwFrameInterval( 0)            333333
             dwFrameInterval( 1)            666666
           VideoStreaming Interface Descriptor:
             bLength                            34
             bDescriptorType                    36
             bDescriptorSubtype                  7 (FRAME_MJPEG)
             bFrameIndex                         2
             bmCapabilities                   0x01
               Still image supported
             wWidth                            160
             wHeight                           120
             dwMinBitRate                  4608000
             dwMaxBitRate                  9216000
             dwMaxVideoFrameBufferSize       38400
             dwDefaultFrameInterval         333333
             bFrameIntervalType                  2
             dwFrameInterval( 0)            333333
             dwFrameInterval( 1)            666666
           VideoStreaming Interface Descriptor:
             bLength                            34
             bDescriptorType                    36
             bDescriptorSubtype                  7 (FRAME_MJPEG)
             bFrameIndex                         3
             bmCapabilities                   0x01
               Still image supported
             wWidth                            176
             wHeight                           144
             dwMinBitRate                  6082560
             dwMaxBitRate                 12165120
             dwMaxVideoFrameBufferSize       50688
             dwDefaultFrameInterval         333333
             bFrameIntervalType                  2
             dwFrameInterval( 0)            333333
             dwFrameInterval( 1)            666666
           VideoStreaming Interface Descriptor:
             bLength                            34
             bDescriptorType                    36
             bDescriptorSubtype                  7 (FRAME_MJPEG)
             bFrameIndex                         4
             bmCapabilities                   0x01
               Still image supported
             wWidth                            320
             wHeight                           240
             dwMinBitRate                 18432000
             dwMaxBitRate                 36864000
             dwMaxVideoFrameBufferSize      153600
             dwDefaultFrameInterval         333333
             bFrameIntervalType                  2
             dwFrameInterval( 0)            333333
             dwFrameInterval( 1)            666666
           VideoStreaming Interface Descriptor:
             bLength                            34
             bDescriptorType                    36
             bDescriptorSubtype                  7 (FRAME_MJPEG)
             bFrameIndex                         5
             bmCapabilities                   0x01
               Still image supported
             wWidth                            352
             wHeight                           288
             dwMinBitRate                 24330240
             dwMaxBitRate                 48660480
             dwMaxVideoFrameBufferSize      202752
             dwDefaultFrameInterval         333333
             bFrameIntervalType                  2
             dwFrameInterval( 0)            333333
             dwFrameInterval( 1)            666666
           VideoStreaming Interface Descriptor:
             bLength                            30
             bDescriptorType                    36
             bDescriptorSubtype                  7 (FRAME_MJPEG)
             bFrameIndex                         6
             bmCapabilities                   0x01
               Still image supported
             wWidth                           1280
             wHeight                           720
             dwMinBitRate                442368000
             dwMaxBitRate                442368000
             dwMaxVideoFrameBufferSize     1843200
             dwDefaultFrameInterval         333333
             bFrameIntervalType                  1
             dwFrameInterval( 0)            333333
           VideoStreaming Interface Descriptor:
             bLength                            30
             bDescriptorType                    36
             bDescriptorSubtype                  7 (FRAME_MJPEG)
             bFrameIndex                         7
             bmCapabilities                   0x01
               Still image supported
             wWidth                           1280
             wHeight                           800
             dwMinBitRate                491520000
             dwMaxBitRate                491520000
             dwMaxVideoFrameBufferSize     2048000
             dwDefaultFrameInterval         333333
             bFrameIntervalType                  1
             dwFrameInterval( 0)            333333
           VideoStreaming Interface Descriptor:
             bLength                             6
             bDescriptorType                    36
             bDescriptorSubtype                 13 (COLORFORMAT)
             bColorPrimaries                     1 (BT.709,sRGB)
             bTransferCharacteristics            1 (BT.709)
             bMatrixCoefficients                 4 (SMPTE 170M (BT.601))
    • 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
    • 720
    • 721
    • 722
    • 723
    • 724
    • 725
    • 726
    • 727
    • 728
    • 729

     

    展开全文
  • Linux uvc 摄像头驱动

    2010-09-03 15:53:03
    这是一个Linux内核的摄像头驱动程序,是大家学习些驱动的好例子。。网上好多编译不过的。此驱动ubuntu下编译通过的
  • USB video class又称为USB video device class or UVC就是USB device class视频产品在不需要安装任何的驱动程序下即插即用,包括摄像头,数字摄影机,模拟视频转换器,电视卡及静态视频相机,V4L2就是用来管理UVC设备的...

    前言

    USB video class又称为USB video device class or UVC就是USB device class视频产品在不需要安装任何的驱动程序下即插即用,包括摄像头,数字摄影机,模拟视频转换器,电视卡及静态视频相机,V4L2就是用来管理UVC设备的并且能够提供视频相关的一些API
    在这里插入图片描述
    摄像头插入后内核打印出此信息,这是UVC机制的支持,即插即用不用我们自己写usb的驱动程序根据此信息可以定位到
    drivers\media\usb\uvc\uvc_driver.c文件,该层为硬件相关层,根据以往的经验和平台设备驱动模型,该层肯定会分配,设置一个driver结构体,然后向上层核心层注册

    struct uvc_driver uvc_driver = {
        .driver = {
            .name       = "uvcvideo",
            .probe      = uvc_probe,//支持的video设备插入就会进入
            .disconnect = uvc_disconnect,
            .suspend    = uvc_suspend,
            .resume     = uvc_resume,
            .reset_resume   = uvc_reset_resume,
            .id_table   = uvc_ids,//表示能够支持哪一些usb设备
            .supports_autosuspend = 1,
        },
    };
    

    该文件会去注册一个名字为uvc_driver的结构体,当匹配到usb设备时就会调用里面的uvc_probe函数

    static int uvc_probe(struct usb_interface *intf,
                 const struct usb_device_id *id)
    {
        struct usb_device *udev = interface_to_usbdev(intf);
        struct uvc_device *dev;
        int ret;
    
        /*省略部分内容*/
        if ((dev = kzalloc(sizeof *dev, GFP_KERNEL)) == NULL)//【1】
            return -ENOMEM;
        /*省略部分内容*/
        dev->udev = usb_get_dev(udev);//【2】
        dev->intf = usb_get_intf(intf);
        dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
        dev->quirks = (uvc_quirks_param == -1)
                ? id->driver_info : uvc_quirks_param;
        /*省略部分内容*/
        /* Parse the Video Class control descriptor. */
        if (uvc_parse_control(dev) < 0) {//【3】
            uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
                "descriptors.\n");
            goto error;
        }
        uvc_printk(KERN_INFO, "Found UVC %u.%02x device %s (%04x:%04x)\n",
    		dev->uvc_version >> 8, dev->uvc_version & 0xff,
    		udev->product ? udev->product : "<unnamed>",8/*省略部分内容*/
        if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)//【4】
            goto error;
        /* Initialize controls. */
        if (uvc_ctrl_init_device(dev) < 0)//【5】
            goto error;
        /* Scan the device for video chains. */
        if (uvc_scan_device(dev) < 0)
            goto error;
        /* Register video device nodes. */
        if (uvc_register_chains(dev) < 0)//【6】
            goto error;
        /*省略部分内容*/
        /* Initialize the interrupt URB. */
        if ((ret = uvc_status_init(dev)) < 0) {//【7】uvc状态的处理由中断端点来控制处理
        /*省略部分内容*/
        return 0;
    error:
        uvc_unregister_video(dev);
        return -ENODEV;
    }
    
    

    可以看出我们的打印信息就是匹配到usb设备后从[8]处打印出来的信息,下面是各个步骤的解析
    【1】分配一个dev
    【2】给dev设置各种参数,如dev->udevudev
    【3】调用uvc_parse_control函数分析设备的控制描述符
    【4】调用v4l2_device_register函数初始化v4l2_dev
    【5】调用uvc_ctrl_init_device函数初始化uvc控制设备
    【6】调用uvc_register_chains函数注册所有通道
    【7】调用uvc_status_init函数初始化uvc状态
    我们重点关注[6]调用uvc_register_chains函数:
    调用关系:

    uvc_register_chains//这里才是实际的注册v4l2管理结构
        uvc_register_terms(dev, chain)
            uvc_stream_by_id
            uvc_register_video
                video_device_alloc();//分配一个struct video_device类型的结构体名为vdev
                vdev->v4l2_dev = &dev->vdev;
                vdev->fops = &uvc_fops;//v4l2操作函数集
                vdev->ioctl_ops = &uvc_ioctl_ops;//设置真正的ioctl操作集
                vdev->release = uvc_release;//释放方法
                  /*
                   根据第二个参数type确定设备名称,也就是我们在/dev/下生成的video啊之类的,得到根据偏移值得到次设备号,把vdev存进去以该次设备号
                   为下标的video_device数组             
                   注册该vdev结构体,最终调用__video_register_device函数,该函数在v412_dev.c里,也就是向上层注册(v412_device.c),在该函数
                   中调用cdev_alloc()分配一个字符设备到vdev->cdev中,这里就设置了vdev->cdev->ops = &v4l2_fops,里面就是
                   真正的用户空间操作集合,最后调用cdev_init注册该结构体,当app层调用read,write时就是调用v4l2_fops中的操作函数进
                   而转向底层,调用底层设备注册的fops中的操作函数
                  */
                video_register_device(vdev, VFL_TYPE_GRABBER, -1);
                vdev->cdev = cdev_alloc();
                vdev->cdev->ops = &v4l2_fops;
                cdev_add
        uvc_mc_register_entities(chain)
    

    可以看出我们的UVC摄像头其实是在V4L2框架的支持下实现的

    UVC拓扑框图

    在这里插入图片描述
    从上图看出USB摄像头它分为两部分,一部分叫做视频控制接口(用于控制,调节亮度等等),一部分叫做视频流接口(用于传输,读取视频流数据),我们的视频功能是由视频接口实现的,每一个视频设备由一个VC和多个VS组成,VC内部抽象出两个概念,unit和terminal,unit用来提供基本的模板来描述大部分功能,比如上图的SU(select unit)和PU(process unit)就是一个unit,terminal用于内外连接,由上图可知terminal有CT(camera terminal),OT(output terminal),IT(intput terminal)三部分组成 ,SU单元用来选择CT或者IT一路作为输入

    分析UVC ioctl函数

    我们上文中说UVC是基于V4L2框架实现,所以函数调用过程之间的联系和我们在之前分析的vivi驱动类似,只是其实对数据格式的规定和设置有所不同,我们着重看下ioctl函数的内容
    VIDIOC_QUERYCAP

    static int uvc_ioctl_querycap(struct file *file, void *fh,
                      struct v4l2_capability *cap)
    {  
        .......
        strlcpy(cap->driver, "uvcvideo", sizeof(cap->driver));
        strlcpy(cap->card, vdev->name, sizeof(cap->card));
        usb_make_path(stream->dev->udev, cap->bus_info, sizeof(cap->bus_info));
        cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING
                  | chain->caps;//表明这是一个摄像头设备
        if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)//如果是视频捕获设备将设置可捕捉而且是流式数据,ideo->streaming->type 应该是在设备被枚举时分析描述符时设置的
            cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
        else
            cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
        return 0;
    }
    

    该调用就是想说明这个是什么设备而已
    VIDIOC_ENUM_FMT

    static int uvc_ioctl_enum_fmt(struct uvc_streaming *stream,struct v4l2_fmtdesc *fmt)
    {
        /*省略部分内容*/
        struct uvc_format *format;
        format = &stream->format[fmt->index];//从uvc_fmts找出支持的格式,format数组应是在设备被枚举时设置的
        strlcpy(fmt->description, format->name, sizeof(fmt->description));//存放到description
        fmt->description[sizeof(fmt->description) - 1] = 0;
        fmt->pixelformat = format->fcc;
    }
    

    主要就是列举出支持的格式
    VIDIOC_G_FMT

    static int uvc_v4l2_get_format(struct uvc_streaming *stream,struct v4l2_format *fmt)
    {
        /*部分内容省略*/
        format = stream->cur_format;//从stream获取当前格式
        frame = stream->cur_frame;//从stream获取当前分辨率
    
        fmt->fmt.pix.pixelformat = format->fcc;
        fmt->fmt.pix.width = frame->wWidth;
        fmt->fmt.pix.height = frame->wHeight;
        fmt->fmt.pix.field = V4L2_FIELD_NONE;
        fmt->fmt.pix.bytesperline = uvc_v4l2_get_bytesperline(format, frame);
        fmt->fmt.pix.sizeimage = stream->ctrl.dwMaxVideoFrameSize;
        fmt->fmt.pix.colorspace = format->colorspace;
        fmt->fmt.pix.priv = 0;
    }
    

    USB摄像头支持多种格式fromat, 每种格式下有多种frame(比如分辨率),该函数主要是获取格式,分辨率
    VIDIOC_TRY_FMT

    static int uvc_v4l2_try_format(struct uvc_streaming *stream,
        struct v4l2_format *fmt, struct uvc_streaming_control *probe,
        struct uvc_format **uvc_format, struct uvc_frame **uvc_frame)
    {
        /*部分内容省略*/
        for (i = 0; i < stream->nformats; ++i) {//在format查找支持的格式是否有请求的格式
            format = &stream->format[i];
            if (format->fcc == fmt->fmt.pix.pixelformat)
                break;
        }
        if (i == stream->nformats) {//如果没有
            format = stream->def_format;//使用默认的格式
            fmt->fmt.pix.pixelformat = format->fcc;
        }
        rw = fmt->fmt.pix.width;
        rh = fmt->fmt.pix.height;
        maxd = (unsigned int)-1;
    
        for (i = 0; i < format->nframes; ++i) {//查找最接近的图像分辨率
           ......
        }
    
        interval = frame->dwDefaultFrameInterval;//每一帧的间隙
        ......
        ret = uvc_probe_video(stream, probe);//里面调用uvc_set_video_ctrl
    
        fmt->fmt.pix.width = frame->wWidth;//设置具体的参数
        fmt->fmt.pix.height = frame->wHeight;//分辨率
        fmt->fmt.pix.field = V4L2_FIELD_NONE;
        fmt->fmt.pix.bytesperline = uvc_v4l2_get_bytesperline(format, frame);
        fmt->fmt.pix.sizeimage = probe->dwMaxVideoFrameSize;//一桢大小
        fmt->fmt.pix.colorspace = format->colorspace;
        fmt->fmt.pix.priv = 0;
    }
    

    该函数主要检查硬件是否支持该格式,查找最接近的图像分辨率设置它
    VIDIOC_S_FMT

    static int uvc_v4l2_set_format(struct uvc_streaming *stream,
        struct v4l2_format *fmt)
    {
        /*部分内容省略*/
        ret = uvc_v4l2_try_format(stream, fmt, &probe, &format, &frame);//测试好参数
        /*把参数保存在stream,供uvc_v4l2_get_format函数调用*/
        stream->ctrl = probe;
        stream->cur_format = format;//把格式foramt保存起来
        stream->cur_frame = frame;//把分辨率frame保存起来
    }
    

    只是把参数保存起来,还没有发给USB摄像头
    VIDIOC_REQBUFS

    int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,unsigned int *count)
    {
        /*部分内容省略*/
        __vb2_queue_cancel(q);//清理任何缓冲的准备或排队队列状态
        memset(q->alloc_devs, 0, sizeof(q->alloc_devs));//初始化清零
        q->memory = memory;//指向内存
        ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes,
                   plane_sizes, q->alloc_devs);//查询需要多少缓冲区buffers,设置缓存区队列
        allocated_buffers =
            __vb2_queue_alloc(q, memory, num_buffers, num_planes, plane_sizes);//申请缓存区
    }
    

    VIDIOC_QUERYBUF

    uvc_query_buffer
        vb2_querybuf
            vb2_core_querybuf
                call_void_bufop(q, fill_user_buffer, q->bufs[index], pb);
    

    根据传进来的参数,查找到使用到的缓存,会调用fill_user_buffer返回bufs[]给用户空间.
    VIDIOC_QBUF

      uvc_queue_buffer
            	list_add_tail(&buf->stream, &queue->mainqueue);
            	list_add_tail(&buf->queue, &queue->irqqueue);
    

    将对应的buf放到队列中去
    poll

     uvc_v4l2_poll            
                uvc_queue_poll
                    poll_wait(file, &buf->wait, wait);  // 休眠等待有数据
    

    VIDIOC_STREAMON

     uvc_video_enable(video, 1)  // 把所设置的参数发给硬件,然后启动摄像头
                /* Commit the streaming parameters. */
                uvc_commit_video
                    uvc_set_video_ctrl  /* 设置格式fromat, frame */
                        	ret = __uvc_query_ctrl(video->dev /* 哪一个USB设备 */, SET_CUR, 0,
                        		video->streaming->intfnum  /* 哪一个接口: VS */,
                        		probe ? VS_PROBE_CONTROL : VS_COMMIT_CONTROL, data, size,
                        		uvc_timeout_param);
                        
                /* 启动:Initialize isochronous/bulk URBs and allocate transfer buffers. */
                uvc_init_video(video, GFP_KERNEL);
                        uvc_init_video_isoc / uvc_init_video_bulk
                            urb->complete = uvc_video_complete; (收到数据后此函数被调用,它又调用video->decode(urb, video, buf); ==> uvc_video_decode_isoc(实时传输)/uvc_video_encode_bulk(突发传输) => uvc_queue_next_buffer => wake_up(&buf->wait);)
                            
                        usb_submit_urb                    	
    

    VIDIOC_DQBUF

         uvc_dequeue_buffer
            	list_del(&buf->stream);
    

    从队列中删除buf
    VIDIOC_STREAMOFF

     uvc_video_enable(video, 0);
        		usb_kill_urb(urb);
        		usb_free_urb(urb);
    

    总结

    在这里插入图片描述

    编程思路

    在这里插入图片描述

    展开全文
  • uvc摄像头驱动从0编写

    千次阅读 2019-05-23 15:08:25
    一:将ucv摄像头驱动编译生成uvc模块,我这边采用的是海思3536提供的linux系统时linux-3.10 模块生成参考一下地址 http://www.coin163.com/it/1305375058925494518: 其中模块生成是: Device Drivers -> ...

    一:将ucv摄像头驱动编译生成uvc模块,我这边采用的是海思3536提供的linux系统时linux-3.10

    模块生成参考一下地址

    http://www.coin163.com/it/1305375058925494518:

    其中模块生成是:

    Device Drivers -> Multimedia support -> Video capture adapters -> V4L USB Devices -> USB Video Class (UVC),这个选项就是在make menuconfig的时候对应的Kconfig中的内容,在编译内核是采用该命令生成uvc 内核模块,还有其他的配置选项,主要文件(driver/media/v4l2-core  driver/media/usb/uvc)(如果是默认的,需要配置多个选项)然后通过config去配置make menuconfig

    注意:刚开始老不能生成.ko文件,最后查找资料发现在make uIamge之后生成然后采用make modules生成模块,才能生成.ko文件。

    主要是需要添加ucv摄像头的id_table。

    内核中的驱动对应的文件夹是:\linux-3.10.y\drivers\media\usb\uvc在该文件夹下就是用来生成uvc模块的程序。

    linux-3.10.y\drivers\media\v4l2-core文件夹程序是基础的uvc程序,用来进行itocl以及内存的分配函数。最好用两个文件夹参考程序。

    二:查看摄像头参数(操作平台:虚拟机中查看usb设备参数)

    lsusb:用来查看摄像头设备。
    lsusb -s 003(Bus):004(device) -v(查看usb设备的详细参数)

    https://www.cnblogs.com/tureno/articles/6888794.html  用来分析一个usb的描述符参数

    参考程序:dev/gadget、uvc_v412

    我们先找一个切入点:v4l2_file_operations结构体

    以上是准备工作。下面才是我们正常的uvc摄像头流程分析。

    找到ioctal的设置,

    1:一些基本结构体:获取设备支持的操作模式struct v4l2_capability 与 VIDIOC_QUERYCA

    struct v4l2_capability {
        __u8    driver[16];     /* i.e. "bttv" */
        __u8    card[32];       /* i.e. "Hauppauge WinTV" */
        __u8    bus_info[32];   /* "PCI:" + pci_name(pci_dev) */
        __u32   version;        /* should use KERNEL_VERSION() */
        __u32    capabilities;   /* Device capabilities */
        __u32    reserved[4];
    };

    2:通过结构 v4l2_format 初始化捕获视频的格式

    struct v4l2_format {
        __u32     type;
        union {
            struct v4l2_pix_format        pix;     /* V4L2_BUF_TYPE_VIDEO_CAPTURE */
            struct v4l2_pix_format_mplane    pix_mp;  /* V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE */
            struct v4l2_window        win;     /* V4L2_BUF_TYPE_VIDEO_OVERLAY */
            struct v4l2_vbi_format        vbi;     /* V4L2_BUF_TYPE_VBI_CAPTURE */
            struct v4l2_sliced_vbi_format    sliced;  /* V4L2_BUF_TYPE_SLICED_VBI_CAPTURE */
            __u8    raw_data[200];                   /* user-defined */
        } fmt;
    };

    3:VIDIOC_REQBUFS 命令通过结构 v4l2_requestbuffers 请求驱动申请一片连续的内存用于缓存视频信息:

    struct v4l2_requestbuffers {
        __u32            count;
        __u32            type;        /* enum v4l2_buf_type */
        __u32            memory;        /* enum v4l2_memory */
        __u32            reserved[2];
    };

    4:

    struct uvc_video
    {
        struct usb_ep *ep;

        /* Frame parameters */
        u8 bpp;
        u32 fcc;
        unsigned int width;
        unsigned int height;
        unsigned int imagesize;

        /* Requests */
        unsigned int req_size;
        struct usb_request *req[UVC_NUM_REQUESTS];
        __u8 *req_buffer[UVC_NUM_REQUESTS];
        struct list_head req_free;
        spinlock_t req_lock;

        void (*encode) (struct usb_request *req, struct uvc_video *video,
                struct uvc_buffer *buf);

        /* Context data used by the completion handler */
        __u32 payload_size;
        __u32 max_payload_size;

        struct uvc_video_queue queue;
        unsigned int fid;
    };

    struct uvc_device //uvc的设备描述,用来配置摄像头的接口参数,用来配置基本的usb的配置参数以及terminal和unit

    {
        struct usb_device *udev; //usb的设备指针
        struct usb_interface *intf; //usb的接口指针
        unsigned long warnings;
        __u32 quirks;
        int intfnum;  //usb的接口数
        char name[32]; //设备名

        enum uvc_device_state state; //uvc的设备状态
        atomic_t users;
        atomic_t nmappings;
    #ifdef CONFIG_MEDIA_CONTROLLER
        struct media_device mdev;
    #endif
        struct v4l2_device vdev; //uvc的子设备v4l2设备(一个父设备分为好几个子设备)
        __u16 uvc_version;
        __u32 clock_frequency; //时钟频率

        struct list_head entities; //uvc实体链表头(挂着uvc设备的terminal和unit)
        struct list_head chains; //uvc视频链表头
        struct list_head streams; //uvc的视频流链表头 (结构体对应的设备接口)
        atomic_t nstreams; //视频流个数
        struct usb_host_endpoint *int_ep;//usb_host_endpoint的对象
        struct urb *int_urb; //中断urb
        __u8 *status; //uvc的设备状态
        struct input_dev *input; //输入设备
        char input_phys[64]; //输入设备节点路径
    }

    三:uvc_probe函数:

    3.1:当插入摄像头后会根据:通过usb_register注册usb摄像头struct uvc_driver uvc_driver程序中的id_table来判断该驱动是否支持不同类型的usb 设备,,如果没有该变量,则usb中的探测回调函数则不会被调用,(有兴趣的朋友可以仔细分析该探测函数)。

    当UVC摄像头被正常调用后,通过.probe = uvc_probe,调用uvc的处理函数:传递两个参数(usb接口参数,USB的id_table参数)。static struct usb_device_id uvc_ids[]中有一个id_table:    { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) },可以配置所有的摄像头参数

    struct usb_device *udev = interface_to_usbdev(intf);(这个时候已经得到usb的设备的基本参数了,我们要做的就是分析usb的参数的信息),

    注意一个比较重要的结构体:usb_interface,一个usb_interface代表一个功能,,每个usb驱动控制器控制一个usb_interface,所有的驱动控制器都是由usb_interface和usb_core惊醒通信,usb_interface就是我们的入口参数。usb_device通常具备一个或多个usb_host_config;一个usb_host_config通常具备一个或多个usb_interface。(usb_device是爷爷,usb_host_config是爸爸,usb_interface是孩子),我们可以自己打印查看这些usb的配置的 过程描述符

    3.2:摄像头的接口参数配置

    if (uvc_parse_control(dev) < 0)用来解析usb的参数;(这里注意数据的排列顺序不一样:简称的大头小头)。

    https://blog.csdn.net/eternity9255/article/details/53522966 用来介绍unit和terminal的参数

    unit可以理解为构建UVC设备功能的各功能单元,多个unit按照一定的规则链接后就是一个完整的uvc功能设备,unit有一个或者多个入口,一个出口。

    Processing Unit代表对采集单元的数据进行处理的单元,负责对采集到的图像进行调整,当host端要求设定这些Processing Unit负责范围内的功能特性时,SPEC定义要求PU单元负责相应Host端对图像特性的调整。

    Terminal指整个UVC功能的入口和出口,Input Terminal可以理解为整个UVC功能的数据源头,它仅有一个outPin,可以连接到其他Unit的Input Pin作为该Unit的输入源。Output Terminal则可以理解为当图像数据流程UVC设备内部的整个处理流程后的输出点,它仅有一个Input Pin, 整个UVC处理流程上的最后一个Unit会将它的Output Pin与Output Terminal的Input Pin连接在一起。

    我们可以看出该USB Camera大致有三个逻辑功能意义上的Entity:CT(代表硬件上的图像数据采集源,Sensor),PU(代表Sensor中可对采集所得图像数据进行加工的功能单元),OT(代表实际中USB模块的的ISO In端点),并无SU单元来控制图像数据采集源的切换和选择(只有一个输入源),此外也没有对采集所得的数据进行个性化处理的功能,故也没有EU单元的存在(无EU描述符)。

    通过usb的host得到接口配置参数,通过该参数填充所需的配置格式,配置

    https://blog.csdn.net/u010783226/article/details/93298993  用来分析各种接口配置描述符,联合接口描述符,配置描述符的功能。

    接口描述符的参数:bInterfaceNumber    用来描述接口号,根据接口号,配置不同的接口,eg:vc控制接口。vc流接口

    uvc摄像头有四个接口,接口号0:控制接口,接口1:流接口,用来设置接口格式,帧大小等参数。(H264,MJPEG,颜色域)

    if ((ret = uvc_parse_standard_control(dev, buffer, buflen)) < 0)解析标准的uvc设备。是uvc的特殊的一连串的接口描述符,是用来描述设备功能的描述符,比如unit和terminal的描述,通过:bDescriptorSubtype参数来描述不同的控制接口功能描述符。

    uvc_parse_standard_control:用来解析控制接口描述符,一个设备需要一个联合接口描述符来描述视频接口集合,对于每个设备功能需要一个视频控制接口或者多个视频流接口,标准的视频接口联合描述符。

    端点号:0x80(输入)端点号:0x81(输出),用来控制vc头,输入terminal,输出terminal,unit,扩展unit参数功能。

    UVC_VC_HEADER:控制接口描述头,uvc_parse_format:根据不同的参数解析不同的格式

    UVC_VC_INPUT_TERMINAL,输入terminal,UVC_VC_OUTPUT_TERMINAL:输出list_add_tail(&term->list, &dev->entities);根据不同的操作terminal对uvc不同的操作

    terminal,UVC_VC_SELECTOR_UNIT:选择unit  UVC_VC_PROCESSING_UNIT:扩展unit

    根据buffer[2]参数的不同解析不同的uvc功能:uvc_parse_streaming(dev, intf);解析uvc的流接口,添加数据流的头

    struct usb_host_interface *alts = &intf->altsetting[0];用来得到流接口描述符。

    videostreaming:VS Interface Descriptors:主要报货视频流接口input header output headerformat frame描述符组成,每个视频流接口都有一个单独的input或者output描述符,,得到摄像头为捕捉设备

    streaming->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

    根据输入头描述符(INPUT_HEAD 1的到format的个数为2(配置为2个,配置bDescriptorSubtype 为4(得到帧格式数为5(类型,格式通道号1),9(个数))13(颜色帧格式配置符),6(MJPEG format的格式,得到2个format格式类型 7,个数(11)格式通道号2)))

    端点号:0x82(输入)

    对支持的每个format都有一个单独的format描述符,对于每一个format描述符有多个frame描述符,format和frame描述符仅定义在接口的第0号设置中

        streaming->header.bNumFormats = p; //得到的格式种类号
        streaming->header.bEndpointAddress = buffer[6];//得到的端点地址

    uvc_parse_streaming(struct uvc_device *dev,    struct usb_interface *intf):用来解析视频流接口参数

    list_add_tail(&streaming->list, &dev->streams);;最终将参数添加到该数据链表中

    (其中主要就是一些参数的填充,根据不同的参数,执行不同的流程,一些uvc定义好的死规定,有兴趣有兴趣的还可以打印参数)。

    最终解析完流参数,填充到:struct uvc_streaming *streaming(该结构体中)

    以上为uvc接口解析的主要函数。

    if (media_device_register(&dev->mdev) < 0)media设备的注册注册一个流媒体设备,用于运行时设备的控制,运行时设备能达到控制节点的效果

    if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)注册一个v4l2结构体。

    if (uvc_ctrl_init_device(dev) < 0)初始化一个控制结构体

    if (uvc_register_chains(dev) < 0):注册uvc视频流

    if ((ret = uvc_status_init(dev)) < 0):初始化中断urb

    uvc_register_chains->ret = uvc_register_terms(dev, chain);->ret = uvc_register_video(dev, stream);主要功能呢注册uvc_stream流

    ret = uvc_video_init(stream);接口初始化:

    vdev = video_device_alloc();    //分配一个video_device结构体,1:队列初始化,2:设置和得到摄像头的参数uvc_get_video_ctrl->__uvc_query_ctrl通过该函数来设置数据图像格式等摄像头的参数。

    vdev->fops = &uvc_fops; //操作函数

      ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);    //注册video_device结构体

    通过填充的video_device结构体中的fops函数来操作摄像头

    摄像头主要是填充该操作函数:

    const struct v4l2_file_operations uvc_fops = {
        .owner        = THIS_MODULE,
        .open        = uvc_v4l2_open,
        .release    = uvc_v4l2_release,
        .unlocked_ioctl    = uvc_v4l2_ioctl,
        .read        = uvc_v4l2_read,
        .mmap        = uvc_v4l2_mmap,
        .poll        = uvc_v4l2_poll,

    };

    展开全文
  • ros uvc摄像头驱动安装

    2020-01-10 19:52:36
    USB插入win10系统设备管理器/照相机/属性...linux下输入,安装驱动: sudo apt-get install ros-kinetic-libuvc-camera sudo apt-get install ros-kinetic-uvc-camera 二次开发程序源码: http://wiki.ros.org/u...
  • 一、写一个USB摄像头驱动程序1.构造一个usb_driver2.设置&nbsp; &nbsp;probe:&nbsp; &nbsp; &nbsp; &nbsp; 2.1. 分配video_device:video_device_alloc&nbsp; &nbsp; &nbsp; &...
  • UVC: USB Video Class UVC驱动:drivers\media\video\uvc\ uvc_driver.c分析: 1. usb_register(&uvc_driver.driver); 2. uvc_probe  uvc_register_video  vdev = video_device_alloc();
  • 一、写一个USB摄像头驱动程序1.构造一个usb_driver2.设置 probe: 2.1. 分配video_device:video_device_alloc 2.2. 设置 .fops .ioctl_ops (里面需要设置11项) 如果要用内核提供的缓冲区操作函数,还需要构造一个...
  • 自己写的uvc摄像头驱动程序

    千次阅读 2017-07-27 09:54:03
    * 注:此usb摄像头驱动程序是基于linux2.6.31.14内核。 * 功能:这个uvc驱动程序仅仅是为了帮助学习uvc驱动的结构而已,这个程序有很多不足 * 比如,很多参数是我们通过手工来去读取设备描述符来获得的。读很多...
  • ros中uvc摄像头驱动

    千次阅读 2018-04-16 11:49:21
    如果没有额外的需求,只需要显示拍摄到的图片,使用apt-get命令下载ros软件库放置的软件即可sudo apt-get install ros-indigo-uvc-camera rosrun uvc_camera uvc_camernode如果需要修改原生代码,则参考链接:...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 460
精华内容 184
关键字:

uvc摄像头驱动