Overview of the V4L2 driver framework
V4L2驱动框架概览
=====================================
This text documents the various structures provided by the V4L2 framework and their relationships.
本文档描述 V4L2框架所提供的各种结构和它们之间的关系。
Introduction
介绍
------------
The V4L2 drivers tend to be very complex due to the complexity of the hardware: most devices have multiple ICs, export multiple device nodes in /dev, and create alsonon-V4L2 devices such as DVB, ALSA, FB, I2C and input (IR) devices.
Especially the fact that V4L2 drivers have to setup supporting ICs to do audio/videomuxing/encoding/decoding makes it more complex than most. Usually these ICs are connected to the main bridge driver through one or more I2C busses, but other busses can also be used. Such devices are called 'sub-devices'.
For a long time the framework was limited to the video_device struct for creating V4L device nodes and video_buf for handling the video buffers (note that this document does not discuss the video_buf framework).
This meant that all drivers had to do the setup of device instances and connecting to sub-devices themselves. Some of this is quite complicated to do right and many drivers never did do it correctly.
There is also a lot of common code that could never be refactored due to the lack of a framework.
So this framework sets up the basic building blocks that all drivers need and this same framework should make it much easier to refactor common code into utility functions shared by all drivers.
由于硬件的复杂性,V4L2驱动程序往往非常复杂:大多数设备具有多个IC,在/ dev中导出多个设备节点,还创建非V4L2设备,如DVB,ALSA,FB,I2C和输入) 设备。
特别是V4L2驱动程序必须设置支持IC做音频/视频复用/编码/解码的事实,使得它比大多数复杂。通常这些IC通过一个或多个I2C总线连接到主桥驱动器,但是也可以使用其他总线。这样的设备被称为“子设备”。
很长一段时间,框架仅限于用于创建V4L设备节点的video_device结构和用于处理视频缓冲区的video_buf(请注意,本文档不讨论video_buf框架)。
这意味着所有驱动程序都必须进行设备实例的设置和连接到子设备本身。有些是相当复杂的做正确的,许多驱动从来没有做到正确。
还有很多常见的代码,由于缺乏一个框架,永远不能重构。
所以这个框架设置了所有驱动程序需要的基本构建块,这个相同的框架应该更容易将公共代码重构为所有驱动程序共享的效用函数。
Structure of a driver
驱动程序的结构
---------------------
All drivers have the following structure:
1) A struct for each device instance containing the device state.
2) A way of initializing and commanding sub-devices (if any).
3) Creating V4L2device nodes (/dev/videoX, /dev/vbiX and /dev/radioX) and keeping track of device-node specific data.
4)File handle-specific structs containing per-file handle data;
5) video buffer handling.
This is a rough schematic of how it all relates:
device instances
|
+-sub-device instances
|
\-V4L2 device nodes
|
\-filehandle instances
所有驱动程序具有以下结构:
1)包含设备状态的每个设备实例的结构。
2)初始化和命令子设备(如果有)的方式。
3)创建V4L2设备节点(/ dev/ videoX,/ dev / vbiX和/ dev / radioX)并跟踪设备节点特定数据。
4)包含每个文件句柄数据的文件句柄特定结构;
5)视频缓冲器处理。
这是一个大致的示意图,它如何相关:
设备实例
|
+ -子设备实例
|
\ -V4L2设备节点
|
\ -filehandle实例
Structure of the framework
框架的结构
--------------------------
The framework closely resembles the driver structure: it has a v4l2_device struct for the device instance data, a v4l2_subdev struct to refer to sub-device instances,the video_device struct stores V4L2 device node data and the v4l2_fh struct keeps track of file handle instances.
The V4L2 framework also optionally integrates with the media framework. If a driver sets the struct v4l2_device mdev field, sub-devices and video nodes will automatically appear in the media framework as entities.
该框架非常类似于驱动程序结构:它具有用于设备实例数据的v4l2_device结构,用于引用子设备实例的v4l2_subdev结构,video_device结构存储V4L2设备节点数据,v4l2_fh结构保持跟踪文件句柄实例。
V4L2框架还可选地与媒体框架集成。如果驱动程序设置structv4l2_device mdev字段,则子设备和视频节点将自动作为实体出现在媒体框架中。