uvc摄像头代码解析4
7.uvc_parse_format7.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_inte易做图ce *intf = streaming->intf; //获取usb接口
struct usb_host_inte易做图ce *alts = intf->cur_altsetting; //获取usb_host_inte易做图ce
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 inte易做图ce %d FORMAT error\n",dev->udev->devnum,alts->desc.bInte易做图ceNumber);
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 inte易做图ce %d FORMAT error\n",dev->udev->devnum,alts->desc.bInte易做图ceNumber);
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 inte易做图ce %d FORMAT error\n",dev->udev->devnum,alts->desc.bInte易做图ceNumber);
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 inte易做图ce %d: unknown DV format %u\n",dev->udev->devnum,alts->desc.bInte易做图ceNumber, 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++ ,
上一个:uvc摄像头代码解析5
下一个:uvc摄像头代码解析3
- 更多C/C++疑问解答:
- 关于c++的cout输出的问题。
- 在学校里学过C和C++,不过学的很一般,现在自学C#,会不会很难?
- 全国计算机二级C语言笔试题
- 已知某树有2个2度结点,3个3度结点,4个4度结点,问有几个叶子结点?
- c++数据结构内部排序问题,整数排序
- 2012九月计算机二级C语言全国题库,,急求急求
- 如果assert只有一个字符串作为参数,是什么意思呢?
- C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,谢谢了!
- 为什么用结构体编写的程序输入是,0输不出来啊~~~
- 将IEEE—754的十六进制转化为十进制浮点类型,用C或C++都行,多谢各位大侠啊,非常感谢!
- 为什么这个程序求不出公式?
- 这个链表倒置的算法请大家分析下
- c语言函数库调用
- C语言unsigned int纠错
- C语言快排求解啊