usb.txt(temp)

来源:互联网 发布:数据挖掘会议 2017 编辑:程序博客网 时间:2024/06/05 14:54

 
. USB枚举过程
http://blog.csdn.net/myarrow/article/details/8270029

 

 

    Each configuration consists of one or more interfaces.  Each
    interface serves a distinct "function", which is typically bound
    to a different USB device driver.  One common example is a USB
    speaker with an audio interface for playback, and a HID interface
    for use with software volume control.

- Execution of an URB is inherently an asynchronous operation, i.e. the
  usb_submit_urb(urb) call returns immediately after it has successfully
  queued the requested action.
 
usb_submit_urb() -->
usb_hcd_link_urb_to_ep() // add an urb to host endpoint


 case USBDEVFS_IOCTL:
  snoop(&dev->dev, "%s: IOCTL\n", __func__);
  ret = proc_ioctl_default(ps, p);
  break;


usb_probe_interface
1. 在这个函数中,usb_match_id检查usb接口是否能和uvc_driver.c中的usb_driver结构中的id_table(如果是uvc驱动,它的值就是uvc_ids)
匹配,如果不能匹配,调用usb_match_dynamic_id检查这个usb接口能否和usb_driver结构(同样是uvc_driver.c中的结构)中的dynids动态id table匹配。
但是这个usb_driver中的dynids好像是空的。
2. 调用usb_set_interface,在这个函数中会执行usb_create_sysfs_intf_files在/sys/devices/xxx/目录下创建device属性文件
3. 调用uvc_driver.c中usb_driver结构中的probe函数(uvc_probe)

uvc_probe函数

uvc_parse_standard_control
1. 在这个函数中,在一个UVC_VC_HEADER的case的循环中调用uvc_parse_streaming解析所有的usb视频流接口。uvc_parse_streaming主要做的事情:
(1). 设置usb接口结构(usb_interface)中的device结构中的device_driver指针为uvc_driver.c中的usb_driver结构(是uvc_driver的成员)中的usbdrv_wrap结构中的device_driver成员
(这个成员在uvc_driver.c中注册uvc_driver设备过程中被设置)。
(2). 通过函数usb_set_intfdata将usb接口的device结构的device_private结构的driver_data成员设置为在uvc_probe函数中分配设置的uvc_device结构。然后
将usb接口的状态设置为USB_INTERFACE_BOUND。
(3). 调用device_bind_driver/driver_sysfs_add函数创建链接文件:
A. 在/sys/bus/platform/drivers/usbcamera目录下创建链接文件usbcamera.0,指向
/sys/devices/platform/usbcamera.0目录;
B. 在/sys/devices/platform/usbcamera.0目录下创建driver链接文件,指向
/sys/bus/platform/drivers/usbcamera目录。


. 如果stream的type是V4L2_BUF_TYPE_VIDEO_CAPTURE,stream的decode函数是decode类型,如果不是,decode函数是encode类型(in uvc_video_init)

.
帧起始(SOF)17. What is a time stamp?

They are two types of time stamps:
The first type is usually called a reference time stamp. This time stamp is the indication of time mentioned in the previous question.
Reference time stamps are to be found in the PES syntax (ESCR), in the program syntax (SCR), and in the transport syntax (PCR).
The second type of time stamp is called DTS (Decoding Time Stamp) or PTS (Presentation Time Stamp). They indicate the exact moment
where a video frame or an audio frame has to be decoded or presented to the user respectively.

scr (system_clock_reference)系统参考时钟 存在于ts流和program流中,用于多节目流间的同步;

pcr (program-_clock_reference)节目参考时钟 存在于ts流里,用于确定同一节目的解码时序;

pts (presentation_time_stamp) 显示时钟标签 pes里的字段;

dts (decod_time-stamp)解码时间标签 pes里的字段,用于指明一个访问单元在系统目标解码器(std)里的的解码时间。当解码时间不同于显示时间时出现。

 

 

 

 

 

 

uvc specification
*************************************************************************************************************************
. Video Probe and Commit Controls这个对应uvc驱动中的uvc_streaming_control结构
搜索这个字符串可以找到video probe and commit control相关的内容,在uvc 1.5 specification文件中。

 


/* 4.3.1.1. Video Probe and Commit Controls */
struct uvc_streaming_control {
 __u16 bmHint;
 __u8  bFormatIndex;
 __u8  bFrameIndex;
 __u32 dwFrameInterval; // 这个数值的单位是100ns
 __u16 wKeyFrameRate;
 __u16 wPFrameRate;
 __u16 wCompQuality;
 __u16 wCompWindowSize;
 __u16 wDelay;
 __u32 dwMaxVideoFrameSize;
 __u32 dwMaxPayloadTransferSize;
 __u32 dwClockFrequency;
 __u8  bmFramingInfo;
 __u8  bPreferedVersion;
 __u8  bMinVersion;
 __u8  bMaxVersion;
} __attribute__((__packed__));

. struct uvc_format {
 __u8 type;
 __u8 index;
 __u8 bpp; // the number of video frames per second(帧率,fps)
 __u8 colorspace;
 __u32 fcc;
 __u32 flags;

 char name[32];

 unsigned int nframes;
 struct uvc_frame *frame;
};


. VS Interface Output Header Descriptor中的bmaControls的大小n是这个描述符中的bControlSize


. 如何在uvc specification中查找描述符的格式
Table A- 5 Video Class-Specific VC Interface Descriptor Subtypes
VC_DESCRIPTOR_UNDEFINED 0x00
VC_HEADER 0x01
VC_INPUT_TERMINAL 0x02
VC_OUTPUT_TERMINAL 0x03
VC_SELECTOR_UNIT 0x04
VC_PROCESSING_UNIT 0x05
VC_EXTENSION_UNIT 0x06
VC_ENCODING_UNIT 0x07
在uvc1.5 class specification.pdf文件的尾部,搜索这些关键字,就可以查找到对应的discriptor的格式说明
 
Table A- 6 Video Class-Specific VS Interface Descriptor Subtypes
VS_ UNDEFINED 0x00
VS_INPUT_HEADER 0x01
VS_OUTPUT_HEADER 0x02
VS_STILL_IMAGE_FRAME 0x03
VS_FORMAT_UNCOMPRESSED 0x04
在uvc1.5 class specification.pdf文件中尾部,搜索这些关键字,就可以查找到对应的discriptor的格式说明
例如查找VS_OUTPUT_HEADER就可以找到VS Interface Output Header Descriptor


struct usb_device_descriptor {
 __u8  bLength;
 __u8  bDescriptorType;

 __le16 bcdUSB;
 __u8  bDeviceClass;
 __u8  bDeviceSubClass;
 __u8  bDeviceProtocol;
 __u8  bMaxPacketSize0;
 __le16 idVendor;
 __le16 idProduct;
 __le16 bcdDevice;
 __u8  iManufacturer;
 __u8  iProduct;
 __u8  iSerialNumber;
 __u8  bNumConfigurations;
} __attribute__ ((packed));


. uvc probe and commit请求代码
/* A.8. Video Class-Specific Request Codes */
#define UVC_RC_UNDEFINED    0x00
#define UVC_SET_CUR     0x01
#define UVC_GET_CUR     0x81
#define UVC_GET_MIN     0x82
#define UVC_GET_MAX     0x83
#define UVC_GET_RES     0x84
#define UVC_GET_LEN     0x85
#define UVC_GET_INFO     0x86
#define UVC_GET_DEF     0x87


. dwFrameInterval
Frame interval in 100 ns units.
是Video Probe and Commit Controls

. 下面这个标志是Video and Still Image Payload Headers中bmHeaderInfo字节中的位,Video and Still Image Payload Headers的说明在uvc 1.5 specification中。
可以通过目录直接找到。
uvc_video_decode_start,这个函数decode Format of the Payload Header
/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
#define UVC_STREAM_EOH (1 << 7)
#define UVC_STREAM_ERR (1 << 6)
#define UVC_STREAM_STI (1 << 5)
#define UVC_STREAM_RES (1 << 4)
#define UVC_STREAM_SCR (1 << 3)
#define UVC_STREAM_PTS (1 << 2)
#define UVC_STREAM_EOF (1 << 1)
#define UVC_STREAM_FID (1 << 0) // 帧id


. 设置uvc驱动打印的级别
> rmmod uvcvideo
> modprobe uvcvideo trace=0x1ff
> This will set uvcvideo up to include debugging output.
或者
sudo echo 0xffff > /sys/module/uvcvideo/parameters/trace

.
~# rmmod uvcvideo
~# modprobe uvcvideo quirks=6

 


. uvcvideo: Allocated 5 URB buffers of 32x3072 bytes each.
一个urb的大小是32*3072字节、一个包的大小是3072,一共有32个packet。一个urb对应一个video frame大小。


. bFrameIntervalType
在Motion-JPEG Video Frame Descriptor中的bFrameIntervalType,
如果bFrameIntervalType等于零,表示是连续interval模式,在这个描述符中定义了interval的最小值、最大值、step值(这些值的单位是100ns);
若干bFrameIntervalType不等于零,它的取值只能是1-255,比如它的值是10,表示支持10种interval,这10个interval的值会列在这个描述符中,
这10个interval值的单位100ns。

. IRP
I/O Request Packet An identifiable request by a software client to move data between itself (on the
host) and an endpoint of a device in an appropriate direction.

 

 

 

 

 

 

 

 


 

0 0