요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
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 also non-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/video muxing/encoding/decoding makes it more complex than most.
Usually these ICs are connected to the main bridge driver through one or
more I2C buses, but other buses 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.
A good example to look at as a reference is the v4l2-pci-skeleton.c
source that is available in samples/v4l/. It is a skeleton driver for
a PCI capture card, and demonstrates how to use the V4L2 driver
framework. It can be used as a template for real PCI video capture driver.
Structure of a V4L 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 V4L2 device nodes (/dev/videoX, /dev/vbiX and /dev/radioX)
and keeping track of device-node specific data.
4) Filehandle-specific structs containing per-filehandle data;
5) video buffer handling.
This is a rough schematic of how it all relates:
.. code-block:: none
device instances
|
+-sub-device instances
|
\-V4L2 device nodes
|
\-filehandle instances
Structure of the V4L2 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 filehandle 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.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
V4L2 framework가 필요한 이유
1-36V4L2 driver는 hardware 자체가 복잡해지는 경향이 있습니다. 대부분 장치는 여러 IC를 포함하고 `/dev`에 여러 device node를 노출하며 DVB, ALSA, framebuffer, I2C, input IR처럼 V4L2가 아닌 장치도 만듭니다.
특히 audio·video muxing, encoding, decoding을 담당하는 보조 IC를 설정해야 하므로 일반 driver보다 복잡합니다. 보통 이런 IC는 하나 이상의 I2C bus로 주 bridge driver에 연결되지만 다른 bus도 사용할 수 있으며, 이러한 장치를 sub-device라고 합니다.
오랫동안 framework는 V4L device node 생성을 위한 `video_device`와 video buffer 처리를 위한 `video_buf`에 한정되었습니다. 이 문서는 `video_buf` framework를 설명하지 않습니다.
그 결과 각 driver가 device instance 설정과 sub-device 연결을 직접 구현해야 했습니다. 이 작업은 정확히 구현하기 어렵고 실제로 많은 driver가 올바르게 처리하지 못했습니다.
공통 framework가 없어서 공유 code를 refactoring하기도 어려웠습니다. 현재 framework는 모든 driver에 필요한 기본 building block을 제공하고 공통 code를 utility 함수로 옮겨 driver들이 공유하기 쉽게 합니다.
참고 구현은 `samples/v4l/v4l2-pci-skeleton.c`입니다. PCI capture card의 skeleton driver로 V4L2 driver framework 사용법을 보여 주며 실제 PCI video capture driver의 template으로 사용할 수 있습니다.
.. SPDX-License-Identifier: GPL-2.0
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 also non-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/video muxing/encoding/decoding makes it more complex than most.
Usually these ICs are connected to the main bridge driver through one or
more I2C buses, but other buses 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.
A good example to look at as a reference is the v4l2-pci-skeleton.c
source that is available in samples/v4l/. It is a skeleton driver for
a PCI capture card, and demonstrates how to use the V4L2 driver
framework. It can be used as a template for real PCI video capture driver.
V4L driver 구조
37-65모든 V4L driver에는 장치 상태를 담는 device instance별 구조체가 있습니다. 필요한 경우 sub-device를 초기화하고 명령하는 방법도 제공합니다.
Driver는 `/dev/videoX`, `/dev/vbiX`, `/dev/radioX` 같은 V4L2 device node를 만들고 node별 자료를 추적합니다. 또한 file handle별 자료를 담는 구조체와 video buffer 처리 계층을 가집니다.
관계 구조는 device instance 아래에 sub-device instance와 V4L2 device node가 있고, 각 V4L2 device node 아래에 file handle instance가 연결되는 형태입니다.
원문의 ASCII 구조를 계층형 flow로 다시 구성했습니다.
Structure of a V4L 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 V4L2 device nodes (/dev/videoX, /dev/vbiX and /dev/radioX)
and keeping track of device-node specific data.
4) Filehandle-specific structs containing per-filehandle data;
5) video buffer handling.
This is a rough schematic of how it all relates:
.. code-block:: none
device instances
|
+-sub-device instances
|
\-V4L2 device nodes
|
\-filehandle instances
V4L2 framework 구조
66-76Framework 구조는 driver 구조와 밀접하게 대응합니다. `v4l2_device`는 device instance 자료, `v4l2_subdev`는 sub-device instance, `video_device`는 V4L2 device node 자료, `v4l2_fh`는 file handle instance를 나타냅니다.
V4L2 framework는 선택적으로 Media framework와 통합됩니다. Driver가 `v4l2_device.mdev`를 설정하면 sub-device와 video node가 Media framework에 entity로 자동 표시됩니다.
Structure of the V4L2 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 filehandle 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-intro.rst:1-76V4L2 framework는 복잡한 bridge·sub-device·device node·file handle 관계에 공통 building block과 Media framework 연동을 제공합니다.