当前位置:编程学习 > C/C++ >>

uvc摄像头代码解析4

7.uvc_parse_format
7.1 uvc格式描述符
[cpp]  
struct uvc_format_desc { //uvc格式描述符  
char *name; //uvc格式描述符名字  
__u8 guid[16];//全局唯一ID  
__u32 fcc; //压缩格式  
};  
7.2 uvc解析1个格式描述符
[cpp] 
static int uvc_parse_format(struct uvc_device *dev,struct uvc_streaming *streaming, struct uvc_format *format,__u32 **intervals, unsigned char *buffer, int buflen)  
{  
    struct usb_interface *intf = streaming->intf;    //获取usb接口  
    struct usb_host_interface *alts = intf->cur_altsetting;  //获取usb_host_interface  
    struct uvc_format_desc *fmtdesc;    //uvc格式描述符  
    struct uvc_frame *frame;    //uvc帧  
    const unsigned char *start = buffer;  
    unsigned int interval;  
    unsigned int i, n;  
    __u8 ftype;  
  
    format->type = buffer[2];    //uvc格式类型  
    format->index = buffer[3];   //uvc格式索引  
    switch (buffer[2]) {    //uvc格式类型  
    case UVC_VS_FORMAT_UNCOMPRESSED:  
 
[cpp]  
case UVC_VS_FORMAT_FRAME_BASED:  
 
[cpp]  
    n = buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED ? 27 : 28;  //获取描述符大小  
    if (buflen < n) {    //检验buflen大小  
        uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface %d FORMAT error\n",dev->udev->devnum,alts->desc.bInterfaceNumber);  
        return -EINVAL;  
    }  
    /* Find the format descriptor from its GUID. */  
    fmtdesc = uvc_format_by_guid(&buffer[5]);   //获取uvc格式描述符  
    if (fmtdesc != NULL) {  //设置uvc格式编码格式名字  
        strlcpy(format->name, fmtdesc->name,sizeof format->name);  
        format->fcc = fmtdesc->fcc;   //设置uvc格式的fcc(压缩格式)  
    }   
    else {  //不能识别的格式  
        uvc_printk(KERN_INFO, "Unknown video format %pUl\n",&buffer[5]);  
        snprintf(format->name, sizeof(format->name), "%pUl\n",&buffer[5]);  
        format->fcc = 0;  
    }  
    format->bpp = buffer[21];    //设置uvc格式bpp(每像素多少位)  
    if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {  
        ftype = UVC_VS_FRAME_UNCOMPRESSED;  //设置ftype(frame type)  
    }   
 else {  
        ftype = UVC_VS_FRAME_FRAME_BASED;   //设置ftype(frame type)  
        if (buffer[27])  
            format->flags = UVC_FMT_FLAG_COMPRESSED; //设置uvc格式标志(压缩的)  
    }  
    break;  
case UVC_VS_FORMAT_MJPEG:  
 
[cpp] 
    if (buflen < 11) {   //检验buflen大小  
        uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface %d FORMAT error\n",dev->udev->devnum,alts->desc.bInterfaceNumber);  
        return -EINVAL;  
    }  
    strlcpy(format->name, "MJPEG", sizeof format->name);  //设置uvc格式编码格式名字“MJPEG”  
    format->fcc = V4L2_PIX_FMT_MJPEG;    //设置uvc格式的fcc(压缩格式)  
    format->flags = UVC_FMT_FLAG_COMPRESSED; //设置uvc格式标志(压缩的)  
    format->bpp = 0; //设置uvc格式bpp(每像素多少位)  
    ftype = UVC_VS_FRAME_MJPEG; //设置ftype(frame type)  
    break;  
case UVC_VS_FORMAT_DV:  
 
[cpp]  
        if (buflen < 9) {    //检验buflen大小  
            uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface %d FORMAT error\n",dev->udev->devnum,alts->desc.bInterfaceNumber);  
            return -EINVAL;  
        }  
        switch (buffer[8] & 0x7f) { //bFormatType格式类型  
        case 0: //设置uvc格式编码格式名字 "SD-DV"  
            strlcpy(format->name, "SD-DV", sizeof format->name);  
            break;  
        case 1: //设置uvc格式编码格式名字 "SDL-DV"  
            strlcpy(format->name, "SDL-DV", sizeof format->name);  
            break;  
        case 2: //设置uvc格式编码格式名字 "HD-DV"  
            strlcpy(format->name, "HD-DV", sizeof format->name);  
            break;  
        default:  
            uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming interface %d: unknown DV format %u\n",dev->udev->devnum,alts->desc.bInterfaceNumber, buffer[8]);  
            return -EINVAL;  
        }  
        strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",sizeof format->name);    //扫描格式eg("HD-DV 60Hz")  
        format->fcc = V4L2_PIX_FMT_DV;   //设置uvc格式的fcc(压缩格式)  
        format->flags = UVC_FMT_FLAG_COMPRESSED | UVC_FMT_FLAG_STREAM;   //设置uvc格式标志(压缩的|数据流)  
        format->bpp = 0; //设置uvc格式bpp(每像素多少位)  
        ftype = 0;  //设置ftype(frame type)  
        /* Create a dummy frame descriptor. 创建插入一个帧描述符*/  
        frame = &format->frame[0];   //获取uvc格式的第一个帧地址  
        memset(&format->frame[0], 0, sizeof format->frame[0]);    //初始化uvc帧  
        frame->bFrameIntervalType = 1;   //uvc帧间隔类型  
        frame->dwDefaultFrameInterval = 1;   //uvc帧默认间隔  
补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,