6.uvc解析uvc视频流
6.1 重要结构体
6.1.1 uvc数据流
[cpp]
struct uvc_streaming {
struct list_head list; //uvc视频流链表头
struct uvc_device *dev; //uvc设备
struct video_device *vdev; //V4L2视频设备
struct uvc_video_chain *chain; //uvc视频链
atomic_t active;
struct usb_inte易做图ce *intf; //usb接口设备
int intfnum; //usb接口号
__u16 maxpsize; //最大包尺寸
struct uvc_streaming_header header; //uvc视频流头部
enum v4l2_buf_type type; //V4L2缓冲区类型 输入/输出
unsigned int nformats; //uvc格式个数
struct uvc_format *format; //uvc格式指针
struct uvc_streaming_control ctrl; //uvc数据流控制
struct uvc_format *cur_format; //当前uvc格式指针
struct uvc_frame *cur_frame; //当前uvc帧指针
struct mutex mutex;
unsigned int frozen : 1;
struct uvc_video_queue queue; //uvc视频队列
void (*decode) (struct urb *urb, struct uvc_streaming *video,struct uvc_buffer *buf);//解码函数
struct {
__u8 header[256];
unsigned int header_size;
int skip_payload;
__u32 payload_size;
__u32 max_payload_size;
} bulk;
struct urb *urb[UVC_URBS];//urb数组
char *urb_buffer[UVC_URBS]; //urb缓冲区
dma_addr_t urb_dma[UVC_URBS];//urb DMA缓冲区
unsigned int urb_size;
__u32 sequence;
__u8 last_fid;
};
6.1.2 uvc格式
[cpp]
struct uvc_format { //uvc格式
__u8 type; //类型
__u8 index; //索引
__u8 bpp; //bits per pixel 每像素位数
__u8 colorspace; //颜色空间
__u32 fcc; //压缩格式
__u32 flags; //标记
char name[32]; //名字
unsigned int nframes; //所含uvc帧个数
struct uvc_frame *frame; //uvc帧指针
};
6.1.3 uvc帧
[cpp]
struct uvc_frame { //uvc帧
__u8 bFrameIndex; //帧索引号
__u8 bmCapabilities; //uvc帧兼容性
__u16 wWidth; //宽度
__u16 wHeight; //高度
__u32 dwMinBitRate; //最新位流
__u32 dwMaxBitRate; //最大位流
__u32 dwMaxVideoFrameBufferSize; //最大视频帧缓冲区
__u8 bFrameIntervalType; //间隙类型
__u32 dwDefaultFrameInterval; //默认帧间隙
__u32 *dwFrameInterval; //帧间隙指针
};
6.2 uvc_parse_streaming函数
[cpp]
static int uvc_parse_streaming(struct uvc_device *dev,struct usb_inte易做图ce *intf)
{
struct uvc_streaming *streaming = NULL; //uvc数据流
struct uvc_format *format; //uvc格式
struct uvc_frame *frame; //uvc帧
struct usb_host_inte易做图ce *alts = &intf->altsetting[0]; //获取usb接口第一个usb_host_inte易做图ce (Alt.Setting 0)
unsigned char *_buffer, *buffer = alts->extra; //获取额外描述符
int _buflen, buflen = alts->extralen; //获取额外描述符长度
unsigned int nformats = 0, nframes = 0, nintervals = 0;
unsigned int size, i, n, p;
__u32 *interval;
__u16 psize;
int ret = -EINVAL;
if (intf->cur_altsetting->desc.bInte易做图ceSubClass != UVC_SC_VIDEOSTREAMING) { //判读usb接口描述符子类是否为视频数据流接口子类
uvc_trace(UVC_TRACE_DESCR, "device %d inte易做图ce %d isn't a video streaming inte易做图ce\n", dev->udev->devnum,intf->altsetting[0].desc.bInte易做图ceNumber);
return -EINVAL;
}
if (usb_driver_claim_inte易做图ce(&uvc_driver.driver, intf, dev)) { //绑定uvc设备的usb驱动和usb接口
uvc_trace(UVC_TRACE_DESCR, "device %d inte易做图ce %d is already claimed\n", dev->udev->devnum,intf->altsetting[0].desc.bInte易做图ceNumber);
return -EINVAL;
}
streaming = kzalloc(sizeof *streaming, GFP_KERNEL); //分配uvc数据流内存
if (streaming == NULL) {
usb_driver_release_inte易做图ce(&uvc_driver.driver, intf);
return -EINVAL;
}
mutex_init(&streaming->mutex);
streaming->dev = dev; //uvc数据流和uvc设备易做图
streaming->intf = usb_get_intf(intf); //uvc数据流和usb接口易做图,并增加引用计数
streaming->intfnum = intf->cur_altsetting->desc.bInte易做图ceNumber; //设置接口号
/* The Pico iMage webcam has its class-specific inte易做图ce descriptors after the endpoint descriptors. */
if (buflen == 0) { //Pico iMage webcam 特殊处理
for (i = 0; i < alts->desc.bNumEndpoints; ++i) {
struct usb_host_endpoint *ep = &alts->endpoint[i];
if (ep->extralen == 0)
continue;
if (ep->extralen > 2 && ep->extra[1] == USB_DT_CS_INTERFACE) {
uvc_trace(UVC_TRACE_DESCR, "trying extra data from endpoint %u.\n", i);
buffer = alts->endpoint[i].extra;
buflen = alts->endpoint[i].extralen;