Documentation/driver-api/media/v4l2-intro.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API

Introduction

V4L2 driver의 복잡성, 계층 구조와 framework object 대응을 설명하는 전문 번역입니다.

Source pathDocumentation/driver-api/media/v4l2-intro.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

v4l2-intro.rst:1-76

V4L2 framework는 복잡한 bridge·sub-device·device node·file handle 관계에 공통 building block과 Media framework 연동을 제공합니다.

문서 구성
원문 줄내용
1-36Framework 동기와 skeleton driver
37-65V4L driver 계층 구조
66-76Framework 구조체 대응

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 Introduction
4 ------------
5
6 The V4L2 drivers tend to be very complex due to the complexity of the
7 hardware: most devices have multiple ICs, export multiple device nodes in
8 /dev, and create also non-V4L2 devices such as DVB, ALSA, FB, I2C and input
9 (IR) devices.
10
11 Especially the fact that V4L2 drivers have to setup supporting ICs to
12 do audio/video muxing/encoding/decoding makes it more complex than most.
13 Usually these ICs are connected to the main bridge driver through one or
14 more I2C buses, but other buses can also be used. Such devices are
15 called 'sub-devices'.
16
17 For a long time the framework was limited to the video_device struct for
18 creating V4L device nodes and video_buf for handling the video buffers
19 (note that this document does not discuss the video_buf framework).
20
21 This meant that all drivers had to do the setup of device instances and
22 connecting to sub-devices themselves. Some of this is quite complicated
23 to do right and many drivers never did do it correctly.
24
25 There is also a lot of common code that could never be refactored due to
26 the lack of a framework.
27
28 So this framework sets up the basic building blocks that all drivers
29 need and this same framework should make it much easier to refactor
30 common code into utility functions shared by all drivers.
31
32 A good example to look at as a reference is the v4l2-pci-skeleton.c
33 source that is available in samples/v4l/. It is a skeleton driver for
34 a PCI capture card, and demonstrates how to use the V4L2 driver
35 framework. It can be used as a template for real PCI video capture driver.
36
37 Structure of a V4L driver
38 -------------------------
39
40 All drivers have the following structure:
41
42 1) A struct for each device instance containing the device state.
43
44 2) A way of initializing and commanding sub-devices (if any).
45
46 3) Creating V4L2 device nodes (/dev/videoX, /dev/vbiX and /dev/radioX)
47 and keeping track of device-node specific data.
48
49 4) Filehandle-specific structs containing per-filehandle data;
50
51 5) video buffer handling.
52
53 This is a rough schematic of how it all relates:
54
55 .. code-block:: none
56
57 device instances
58 |
59 +-sub-device instances
60 |
61 \-V4L2 device nodes
62 |
63 \-filehandle instances
64
65
66 Structure of the V4L2 framework
67 -------------------------------
68
69 The framework closely resembles the driver structure: it has a v4l2_device
70 struct for the device instance data, a v4l2_subdev struct to refer to
71 sub-device instances, the video_device struct stores V4L2 device node data
72 and the v4l2_fh struct keeps track of filehandle instances.
73
74 The V4L2 framework also optionally integrates with the media framework. If a
75 driver sets the struct v4l2_device mdev field, sub-devices and video nodes
76 will automatically appear in the media framework as entities.
77

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

V4L2 framework가 필요한 이유

1-36

V4L2 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으로 사용할 수 있습니다.

V4L2 driver 복잡성
원인Framework의 대응
여러 IC와 busSub-device 추상화
여러 V4L2·비V4L2 node공통 device building block
반복되는 초기화·연결 code공유 utility와 일관된 수명주기
참고 구현 필요`samples/v4l/v4l2-pci-skeleton.c`

.. 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가 연결되는 형태입니다.

V4L driver 관계도
Device instanceSub-device instance
Device instanceV4L2 device nodeFile handle instance
V4L2 device nodeVideo buffer handling

원문의 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-76

Framework 구조는 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로 자동 표시됩니다.

Driver 개념과 V4L2 구조체
Driver 개념Framework 구조체
Device instance`v4l2_device`
Sub-device instance`v4l2_subdev`
V4L2 device node`video_device`
File handle instance`v4l2_fh`
Media integration`v4l2_device.mdev`

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.