Linux系统中USB摄像头一般都采用的是UVC硬件架构设计,因此我们在分析USB摄像头驱动的重点在于分析UVC框架。它融合了usb驱动框架和v4l2驱动框架,我们可以从中抽象出一个通用的USB摄像头驱动框架。
uvc架构官方手册参考网上:uvc 1.5 specifications
http://www.usb.org/developers/docs/devclass_docs/ 的Video Class的Video Class 1.5 document set
只需查看UVC 1.5 Class specification 和 USB_Video_Example 1.5
在USB_Video_Example 1.5 里的12页USB Video Camera Topology 即可大致了解USB摄像头大致框架
Video functions are addressed through their video interfaces. 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.
这个uvc框架包含两大接口:
1. VideoControl (VC) interface:
控制接口 包含 CT(Camera Terminal) IT(Input Terminal) OT(Output Terminal) SU(Selector Unit) PU (Process Unit)
2.VideoStreaming (VS)interface:
视频数据接口,主要产生视频数据
一、USB摄像头驱动框架:
1.构造一个usb_driver结构体
2.设置
在probe函数中:
分配video_device :video_device_alloc
设置:fops,ioctl_fops(里面有11项)
如果要用内核提供的缓冲区操作函数,还要构造一个video_buf_queue_ops
注册:video_register_device
id_table:表示支持哪些usb设备
3.注册
在Linux内核里自带usb摄像头驱动程序,它支持uvc规格的摄像头(uvc即usb video class),它在drivers/media/video/uvc 下的uvc_driver.c。
以下是uvc_driver.c 分析:
从入口函数开始
uvc_init
usb_register(&uvc_driver.driver);
struct uvc_driver uvc_driver = {
.driver = {
.name = "uvcvideo",
.probe = uvc_probe,
.disconnect = uvc_disconnect,
.suspend = uvc_suspend,
.resume = uvc_resume,