Bootstrap

V4L2架构分析(一)

V4L2架构图:


 用到的IOCTL如下:

VIDIOC_QUERYCAP 查询设备的属性
VIDIOC_ENUM_FMT 帧格式
VIDIOC_S_FMT 设置视频帧格式,对应struct v4l2_format
VIDIOC_G_FMT 获取视频帧格式等
VIDIOC_REQBUFS 请求/申请若干个帧缓冲区,一般为不少于3个
VIDIOC_QUERYBUF 查询帧缓冲区在内核空间的长度和偏移量
VIDIOC_QBUF 将申请到的帧缓冲区全部放入视频采集输出队列
VIDIOC_STREAMON 开始视频流数据的采集
VIDIOC_DQBUF 应用程序从视频采集输出队列中取出已含有采集数据的帧缓冲区
VIDIOC_STREAMOFF 应用程序将该帧缓冲区重新挂入输入队列

2.struct v4l2_device在v4l2_framework中具有超然的地位,实际上,它应该叫做v4l2_root更能体现它的位置.在一个实现中仅此一个,没有副本,一般是代表设备的的对象,比如 struct platform_device, uvc device 或者PCI device. 中嵌入定义,如下图所示:

平台设备注册:

uvc中的注册:

它的作用包括:

  1. 管理一堆的sub-devices列表
  2. notify callback for sub-devices.
  3. release callback for sub-devices.

注册流程有两种:

第一种:直接在设备探测的时候调用,通过平台接口调用v4l2_device_register/v4l2_device_register_subdev_nodes直接注册:

usb_interface_probe->uvc_driver(struct usb_driver)->uvc_probe->v4l2_device_register/v4l2_device_register_subdev_nodes->........

或者全志的vin驱动也是类似的做法:

platform_driver_probe->vin_probe->v4l2_device_register->.....

第二种 通过struct v4l2_async_notifier_operations的complete注册

platform_device probe->v4l2_async_notifier_register -> .... > v4l2_device_register_subdev_nodes->complete->v4l2_device_register_subdev_nodes->......

uvc_driver其实就是usb_driver.

3.另一个重要结构 struct video_device:

表示video/vbi/ratio/v4l2_subdev device node in /dev.

以struct v4l2_file_operations 为文件操作表

以v4l2_ioctl_ops为ioctl operations.

通常也表示存在一个dma engine,这个dma engine通过vb2_queue 管理buffer.

4.关于V4L2 struct v4l2_ioctl_info v4l2_ioctls[]函数中的套壳定义.

 4.从面向对象继承的角度看待V4L2的设备模型:

5:VB2帧队列管理模型:

4

6.V4L2框架的调用架构:

 架构调用细节:

v4l2_subdev_call是一个宏,它的实现很有意思,隐藏了很多的东西:

;