← Documents Documentation/userspace-api/media/v4l/vidioc-subdev-g-fmt.rst GitHub 원문 ↗

Linux 6.18.37 · 사용자 공간 API

VIDIOC_SUBDEV_G_FMT 및 VIDIOC_SUBDEV_S_FMT ioctl

서브디바이스 pad의 media-bus 형식을 ACTIVE 또는 파일 핸들별 TRY 상태로 협상하는 절차를 설명합니다.

Source pathDocumentation/userspace-api/media/v4l/vidioc-subdev-g-fmt.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약·해설

vidioc-subdev-g-fmt.rst:1-154

파이프라인 형식 협상은 입력 pad의 TRY 상태부터 출력 pad 방향으로 진행하고, 매 S_FMT 뒤에는 드라이버가 조정한 반환 형식을 기준으로 다음 단계를 계산해야 합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2 .. c:namespace:: V4L
3
4 .. _VIDIOC_SUBDEV_G_FMT:
5
6 **********************************************
7 ioctl VIDIOC_SUBDEV_G_FMT, VIDIOC_SUBDEV_S_FMT
8 **********************************************
9
10 Name
11 ====
12
13 VIDIOC_SUBDEV_G_FMT - VIDIOC_SUBDEV_S_FMT - Get or set the data format on a subdev pad
14
15 Synopsis
16 ========
17
18 .. c:macro:: VIDIOC_SUBDEV_G_FMT
19
20 ``int ioctl(int fd, VIDIOC_SUBDEV_G_FMT, struct v4l2_subdev_format *argp)``
21
22 .. c:macro:: VIDIOC_SUBDEV_S_FMT
23
24 ``int ioctl(int fd, VIDIOC_SUBDEV_S_FMT, struct v4l2_subdev_format *argp)``
25
26 Arguments
27 =========
28
29 ``fd``
30 File descriptor returned by :c:func:`open()`.
31
32 ``argp``
33 Pointer to struct :c:type:`v4l2_subdev_format`.
34
35 Description
36 ===========
37
38 These ioctls are used to negotiate the frame format at specific subdev
39 pads in the image pipeline.
40
41 To retrieve the current format applications set the ``pad`` field of a
42 struct :c:type:`v4l2_subdev_format` to the desired
43 pad number as reported by the media API and the ``which`` field to
44 ``V4L2_SUBDEV_FORMAT_ACTIVE``. When they call the
45 ``VIDIOC_SUBDEV_G_FMT`` ioctl with a pointer to this structure the
46 driver fills the members of the ``format`` field.
47
48 To change the current format applications set both the ``pad`` and
49 ``which`` fields and all members of the ``format`` field. When they call
50 the ``VIDIOC_SUBDEV_S_FMT`` ioctl with a pointer to this structure the
51 driver verifies the requested format, adjusts it based on the hardware
52 capabilities and configures the device. Upon return the struct
53 :c:type:`v4l2_subdev_format` contains the current
54 format as would be returned by a ``VIDIOC_SUBDEV_G_FMT`` call.
55
56 Applications can query the device capabilities by setting the ``which``
57 to ``V4L2_SUBDEV_FORMAT_TRY``. When set, 'try' formats are not applied
58 to the device by the driver, but are changed exactly as active formats
59 and stored in the sub-device file handle. Two applications querying the
60 same sub-device would thus not interact with each other.
61
62 For instance, to try a format at the output pad of a sub-device,
63 applications would first set the try format at the sub-device input with
64 the ``VIDIOC_SUBDEV_S_FMT`` ioctl. They would then either retrieve the
65 default format at the output pad with the ``VIDIOC_SUBDEV_G_FMT`` ioctl,
66 or set the desired output pad format with the ``VIDIOC_SUBDEV_S_FMT``
67 ioctl and check the returned value.
68
69 Try formats do not depend on active formats, but can depend on the
70 current links configuration or sub-device controls value. For instance,
71 a low-pass noise filter might crop pixels at the frame boundaries,
72 modifying its output frame size.
73
74 If the subdev device node has been registered in read-only mode, calls to
75 ``VIDIOC_SUBDEV_S_FMT`` are only valid if the ``which`` field is set to
76 ``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno
77 variable is set to ``-EPERM``.
78
79 Drivers must not return an error solely because the requested format
80 doesn't match the device capabilities. They must instead modify the
81 format to match what the hardware can provide. The modified format
82 should be as close as possible to the original request.
83
84 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
85
86 .. c:type:: v4l2_subdev_format
87
88 .. flat-table:: struct v4l2_subdev_format
89 :header-rows: 0
90 :stub-columns: 0
91 :widths: 1 1 2
92
93 * - __u32
94 - ``pad``
95 - Pad number as reported by the media controller API.
96 * - __u32
97 - ``which``
98 - Format to modified, from enum
99 :ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`.
100 * - struct :c:type:`v4l2_mbus_framefmt`
101 - ``format``
102 - Definition of an image format, see :c:type:`v4l2_mbus_framefmt` for
103 details.
104 * - __u32
105 - ``stream``
106 - Stream identifier.
107 * - __u32
108 - ``reserved``\ [7]
109 - Reserved for future extensions. Applications and drivers must set
110 the array to zero.
111
112
113 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|
114
115 .. _v4l2-subdev-format-whence:
116
117 .. flat-table:: enum v4l2_subdev_format_whence
118 :header-rows: 0
119 :stub-columns: 0
120 :widths: 3 1 4
121
122 * - V4L2_SUBDEV_FORMAT_TRY
123 - 0
124 - Try formats, used for querying device capabilities.
125 * - V4L2_SUBDEV_FORMAT_ACTIVE
126 - 1
127 - Active formats, applied to the hardware.
128
129 Return Value
130 ============
131
132 On success 0 is returned, on error -1 and the ``errno`` variable is set
133 appropriately. The generic error codes are described at the
134 :ref:`Generic Error Codes <gen-errors>` chapter.
135
136 EBUSY
137 The format can't be changed because the pad is currently busy. This
138 can be caused, for instance, by an active video stream on the pad.
139 The ioctl must not be retried without performing another action to
140 fix the problem first. Only returned by ``VIDIOC_SUBDEV_S_FMT``
141
142 EINVAL
143 The struct :c:type:`v4l2_subdev_format` ``pad`` references a non-existing
144 pad, or the ``which`` field has an unsupported value.
145
146 EPERM
147 The ``VIDIOC_SUBDEV_S_FMT`` ioctl has been called on a read-only subdevice
148 and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``.
149
150 ============
151
152 On success 0 is returned, on error -1 and the ``errno`` variable is set
153 appropriately. The generic error codes are described at the
154 :ref:`Generic Error Codes <gen-errors>` chapter.
155

3. 한국어 전문 번역

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

목적, 호출 형식과 인자

1-34

`VIDIOC_SUBDEV_G_FMT`과 `VIDIOC_SUBDEV_S_FMT`은 이미지 파이프라인의 특정 서브디바이스 pad에서 프레임 형식을 협상합니다. `argp`는 `struct v4l2_subdev_format`을 가리킵니다.

.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. c:namespace:: V4L

.. _VIDIOC_SUBDEV_G_FMT:

**********************************************
ioctl VIDIOC_SUBDEV_G_FMT, VIDIOC_SUBDEV_S_FMT
**********************************************

Name
====

VIDIOC_SUBDEV_G_FMT - VIDIOC_SUBDEV_S_FMT - Get or set the data format on a subdev pad

Synopsis
========

.. c:macro:: VIDIOC_SUBDEV_G_FMT

``int ioctl(int fd, VIDIOC_SUBDEV_G_FMT, struct v4l2_subdev_format *argp)``

.. c:macro:: VIDIOC_SUBDEV_S_FMT

``int ioctl(int fd, VIDIOC_SUBDEV_S_FMT, struct v4l2_subdev_format *argp)``

Arguments
=========

``fd``
    File descriptor returned by :c:func:`open()`.

``argp``
    Pointer to struct :c:type:`v4l2_subdev_format`.

형식 조회·설정과 TRY 협상

35-83

현재 형식을 조회하려면 `pad`를 원하는 pad 번호로, `which`를 `V4L2_SUBDEV_FORMAT_ACTIVE`로 설정하고 G_FMT을 호출합니다. 드라이버는 `format` 필드를 채웁니다.

형식을 바꾸려면 `pad`, `which`, `format`의 모든 멤버를 설정해 S_FMT을 호출합니다. 드라이버는 요청을 하드웨어 capability에 맞게 가장 가까운 지원 형식으로 조정하고 장치를 구성한 뒤, 현재 형식을 구조체에 되돌려 줍니다.

`which = V4L2_SUBDEV_FORMAT_TRY`이면 실제 장치에는 적용하지 않고 ACTIVE와 같은 조정 규칙으로 계산한 결과를 파일 핸들에 저장합니다. 파일 핸들마다 try 상태가 분리되므로 두 응용 프로그램이 서로 간섭하지 않습니다.

출력 pad의 형식을 시험하려면 먼저 입력 pad에 S_FMT으로 try 형식을 설정합니다. 이어서 출력 pad의 기본 try 형식을 G_FMT으로 읽거나 원하는 출력 형식을 S_FMT으로 설정한 뒤 반환값을 확인합니다.

Try format은 active format에 의존하지 않지만 현재 링크 구성과 서브디바이스 control 값에는 의존할 수 있습니다. 예를 들어 저역 통과 잡음 필터가 경계 픽셀을 잘라 출력 크기를 바꿀 수 있습니다.

읽기 전용 노드의 S_FMT은 TRY에만 허용되며 ACTIVE 요청은 `EPERM`입니다. 단순히 요청 형식이 capability와 맞지 않는 경우에는 오류 대신 가장 가까운 지원 형식으로 수정해야 합니다.

파이프라인 TRY 형식 협상
입력 pad에 TRY 형식 설정드라이버가 입력 형식을 지원값으로 조정링크와 control을 반영해 출력 후보 계산출력 pad를 G_FMT으로 조회하거나 S_FMT으로 시험반환된 조정 결과를 실제 지원 형식으로 사용

입력에서 출력 방향으로 try 상태를 전파해 결과를 확인합니다.

Description
===========

These ioctls are used to negotiate the frame format at specific subdev
pads in the image pipeline.

To retrieve the current format applications set the ``pad`` field of a
struct :c:type:`v4l2_subdev_format` to the desired
pad number as reported by the media API and the ``which`` field to
``V4L2_SUBDEV_FORMAT_ACTIVE``. When they call the
``VIDIOC_SUBDEV_G_FMT`` ioctl with a pointer to this structure the
driver fills the members of the ``format`` field.

To change the current format applications set both the ``pad`` and
``which`` fields and all members of the ``format`` field. When they call
the ``VIDIOC_SUBDEV_S_FMT`` ioctl with a pointer to this structure the
driver verifies the requested format, adjusts it based on the hardware
capabilities and configures the device. Upon return the struct
:c:type:`v4l2_subdev_format` contains the current
format as would be returned by a ``VIDIOC_SUBDEV_G_FMT`` call.

Applications can query the device capabilities by setting the ``which``
to ``V4L2_SUBDEV_FORMAT_TRY``. When set, 'try' formats are not applied
to the device by the driver, but are changed exactly as active formats
and stored in the sub-device file handle. Two applications querying the
same sub-device would thus not interact with each other.

For instance, to try a format at the output pad of a sub-device,
applications would first set the try format at the sub-device input with
the ``VIDIOC_SUBDEV_S_FMT`` ioctl. They would then either retrieve the
default format at the output pad with the ``VIDIOC_SUBDEV_G_FMT`` ioctl,
or set the desired output pad format with the ``VIDIOC_SUBDEV_S_FMT``
ioctl and check the returned value.

Try formats do not depend on active formats, but can depend on the
current links configuration or sub-device controls value. For instance,
a low-pass noise filter might crop pixels at the frame boundaries,
modifying its output frame size.

If the subdev device node has been registered in read-only mode, calls to
``VIDIOC_SUBDEV_S_FMT`` are only valid if the ``which`` field is set to
``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno
variable is set to ``-EPERM``.

Drivers must not return an error solely because the requested format
doesn't match the device capabilities. They must instead modify the
format to match what the hardware can provide. The modified format
should be as close as possible to the original request.

구조체와 format whence

84-128
v4l2_subdev_format 필드
형식필드의미
`__u32``pad`Media Controller API가 보고한 pad 번호
`__u32``which`수정할 형식 상태인 TRY 또는 ACTIVE
`struct v4l2_mbus_framefmt``format`이미지의 media-bus 프레임 형식 정의
`__u32``stream`스트림 식별자
`__u32[7]``reserved[7]`향후 확장용이며 응용 프로그램과 드라이버가 모두 0으로 설정

pad와 상태를 선택하고 media-bus 프레임 형식을 전달합니다.

enum v4l2_subdev_format_whence
상수의미
`V4L2_SUBDEV_FORMAT_TRY``0`장치 capability 조회에 쓰는 try format
`V4L2_SUBDEV_FORMAT_ACTIVE``1`하드웨어에 적용되는 active format

협상용 파일 핸들 상태와 실제 하드웨어 상태를 선택합니다.

.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|

.. c:type:: v4l2_subdev_format

.. flat-table:: struct v4l2_subdev_format
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2

    * - __u32
      - ``pad``
      - Pad number as reported by the media controller API.
    * - __u32
      - ``which``
      - Format to modified, from enum
	:ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`.
    * - struct :c:type:`v4l2_mbus_framefmt`
      - ``format``
      - Definition of an image format, see :c:type:`v4l2_mbus_framefmt` for
	details.
    * - __u32
      - ``stream``
      - Stream identifier.
    * - __u32
      - ``reserved``\ [7]
      - Reserved for future extensions. Applications and drivers must set
	the array to zero.


.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|

.. _v4l2-subdev-format-whence:

.. flat-table:: enum v4l2_subdev_format_whence
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4

    * - V4L2_SUBDEV_FORMAT_TRY
      - 0
      - Try formats, used for querying device capabilities.
    * - V4L2_SUBDEV_FORMAT_ACTIVE
      - 1
      - Active formats, applied to the hardware.

반환값, 오류와 원문 중복 문단

129-154

성공하면 0, 오류이면 -1을 반환하고 `errno`를 설정합니다. 원문 150~154행에는 같은 일반 반환 설명이 반복되어 있으며, 이 전문 번역 페이지에서도 해당 원문과 줄 좌표를 그대로 보존합니다.

Format ioctl 오류
errno조건
`EBUSY`활성 스트림 등으로 pad가 사용 중이라 형식을 바꿀 수 없음. 문제를 해결하는 다른 동작 전에는 재시도하지 않으며 S_FMT만 반환
`EINVAL`pad가 존재하지 않거나 which 값이 지원되지 않음
`EPERM`읽기 전용 서브디바이스에서 S_FMT으로 ACTIVE 형식을 변경하려 함

S_FMT 전용 상태 오류와 공통 입력 오류입니다.

Return Value
============

On success 0 is returned, on error -1 and the ``errno`` variable is set
appropriately. The generic error codes are described at the
:ref:`Generic Error Codes <gen-errors>` chapter.

EBUSY
    The format can't be changed because the pad is currently busy. This
    can be caused, for instance, by an active video stream on the pad.
    The ioctl must not be retried without performing another action to
    fix the problem first. Only returned by ``VIDIOC_SUBDEV_S_FMT``

EINVAL
    The struct :c:type:`v4l2_subdev_format` ``pad`` references a non-existing
    pad, or the ``which`` field has an unsupported value.

EPERM
    The ``VIDIOC_SUBDEV_S_FMT`` ioctl has been called on a read-only subdevice
    and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``.

============

On success 0 is returned, on error -1 and the ``errno`` variable is set
appropriately. The generic error codes are described at the
:ref:`Generic Error Codes <gen-errors>` chapter.