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

Linux 6.18.37 · 사용자 공간 API

VIDIOC_G_FMT·VIDIOC_S_FMT·VIDIOC_TRY_FMT ioctl

V4L2 stream의 현재 데이터 형식을 조회하고, 하드웨어 능력에 맞춰 실제 설정하거나 상태 변경 없이 시험하는 ioctl과 buffer type별 v4l2_format union을 설명합니다.

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

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

1. 요약·해설

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

요약·해설

vidioc-g-fmt.rst:1-154

V4L2 stream의 현재 데이터 형식을 조회하고, 하드웨어 능력에 맞춰 실제 설정하거나 상태 변경 없이 시험하는 ioctl과 buffer type별 v4l2_format union을 설명합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2 .. c:namespace:: V4L
3
4 .. _VIDIOC_G_FMT:
5
6 ************************************************
7 ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT
8 ************************************************
9
10 Name
11 ====
12
13 VIDIOC_G_FMT - VIDIOC_S_FMT - VIDIOC_TRY_FMT - Get or set the data format, try a format
14
15 Synopsis
16 ========
17
18 .. c:macro:: VIDIOC_G_FMT
19
20 ``int ioctl(int fd, VIDIOC_G_FMT, struct v4l2_format *argp)``
21
22 .. c:macro:: VIDIOC_S_FMT
23
24 ``int ioctl(int fd, VIDIOC_S_FMT, struct v4l2_format *argp)``
25
26 .. c:macro:: VIDIOC_TRY_FMT
27
28 ``int ioctl(int fd, VIDIOC_TRY_FMT, struct v4l2_format *argp)``
29
30 Arguments
31 =========
32
33 ``fd``
34 File descriptor returned by :c:func:`open()`.
35
36 ``argp``
37 Pointer to struct :c:type:`v4l2_format`.
38
39 Description
40 ===========
41
42 These ioctls are used to negotiate the format of data (typically image
43 format) exchanged between driver and application.
44
45 To query the current parameters applications set the ``type`` field of a
46 struct :c:type:`v4l2_format` to the respective buffer (stream)
47 type. For example video capture devices use
48 ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` or
49 ``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``. When the application calls the
50 :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl with a pointer to this structure the driver fills
51 the respective member of the ``fmt`` union. In case of video capture
52 devices that is either the struct
53 :c:type:`v4l2_pix_format` ``pix`` or the struct
54 :c:type:`v4l2_pix_format_mplane` ``pix_mp``
55 member. When the requested buffer type is not supported drivers return
56 an ``EINVAL`` error code.
57
58 To change the current format parameters applications initialize the
59 ``type`` field and all fields of the respective ``fmt`` union member.
60 For details see the documentation of the various devices types in
61 :ref:`devices`. Good practice is to query the current parameters
62 first, and to modify only those parameters not suitable for the
63 application. When the application calls the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
64 a pointer to a struct :c:type:`v4l2_format` structure the driver
65 checks and adjusts the parameters against hardware abilities. Drivers
66 should not return an error code unless the ``type`` field is invalid,
67 this is a mechanism to fathom device capabilities and to approach
68 parameters acceptable for both the application and driver. On success
69 the driver may program the hardware, allocate resources and generally
70 prepare for data exchange. Finally the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl returns
71 the current format parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does. Very simple,
72 inflexible devices may even ignore all input and always return the
73 default parameters. However all V4L2 devices exchanging data with the
74 application must implement the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
75 ioctl. When the requested buffer type is not supported drivers return an
76 EINVAL error code on a :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` attempt. When I/O is already in
77 progress or the resource is not available for other reasons drivers
78 return the ``EBUSY`` error code.
79
80 The :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl is equivalent to :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` with one
81 exception: it does not change driver state. It can also be called at any
82 time, never returning ``EBUSY``. This function is provided to negotiate
83 parameters, to learn about hardware limitations, without disabling I/O
84 or possibly time consuming hardware preparations. Although strongly
85 recommended drivers are not required to implement this ioctl.
86
87 The format as returned by :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` must be identical to what
88 :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` returns for the same input or output.
89
90 .. c:type:: v4l2_format
91
92 .. tabularcolumns:: |p{7.4cm}|p{4.4cm}|p{5.5cm}|
93
94 .. flat-table:: struct v4l2_format
95 :header-rows: 0
96 :stub-columns: 0
97
98 * - __u32
99 - ``type``
100 - Type of the data stream, see :c:type:`v4l2_buf_type`.
101 * - union {
102 - ``fmt``
103 * - struct :c:type:`v4l2_pix_format`
104 - ``pix``
105 - Definition of an image format, see :ref:`pixfmt`, used by video
106 capture and output devices.
107 * - struct :c:type:`v4l2_pix_format_mplane`
108 - ``pix_mp``
109 - Definition of an image format, see :ref:`pixfmt`, used by video
110 capture and output devices that support the
111 :ref:`multi-planar version of the API <planar-apis>`.
112 * - struct :c:type:`v4l2_window`
113 - ``win``
114 - Definition of an overlaid image, see :ref:`overlay`, used by
115 video overlay devices.
116 * - struct :c:type:`v4l2_vbi_format`
117 - ``vbi``
118 - Raw VBI capture or output parameters. This is discussed in more
119 detail in :ref:`raw-vbi`. Used by raw VBI capture and output
120 devices.
121 * - struct :c:type:`v4l2_sliced_vbi_format`
122 - ``sliced``
123 - Sliced VBI capture or output parameters. See :ref:`sliced` for
124 details. Used by sliced VBI capture and output devices.
125 * - struct :c:type:`v4l2_sdr_format`
126 - ``sdr``
127 - Definition of a data format, see :ref:`pixfmt`, used by SDR
128 capture and output devices.
129 * - struct :c:type:`v4l2_meta_format`
130 - ``meta``
131 - Definition of a metadata format, see :ref:`meta-formats`, used by
132 metadata capture devices.
133 * - __u8
134 - ``raw_data``\ [200]
135 - Place holder for future extensions.
136 * - }
137 -
138
139 Return Value
140 ============
141
142 On success 0 is returned, on error -1 and the ``errno`` variable is set
143 appropriately. The generic error codes are described at the
144 :ref:`Generic Error Codes <gen-errors>` chapter.
145
146 EINVAL
147 The struct :c:type:`v4l2_format` ``type`` field is
148 invalid or the requested buffer type not supported.
149
150 EBUSY
151 The device is busy and cannot change the format. This could be
152 because or the device is streaming or buffers are allocated or
153 queued to the driver. Relevant for :ref:`VIDIOC_S_FMT
154 <VIDIOC_G_FMT>` only.
155

3. 한국어 전문 번역

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

목적, 호출 형식과 인자

1-38

`VIDIOC_G_FMT`, `VIDIOC_S_FMT`, `VIDIOC_TRY_FMT`는 드라이버와 애플리케이션 사이에서 교환하는 데이터 형식, 일반적으로 영상 형식을 조회·설정하거나 시험합니다.

세 ioctl은 모두 `struct v4l2_format *argp`를 받습니다. `fd`는 `open()`이 반환한 파일 디스크립터이고, `argp`는 stream type과 해당 형식 구조체를 담은 `v4l2_format`을 가리킵니다.

format ioctl
명령동작드라이버 상태 변경
`VIDIOC_G_FMT`현재 데이터 형식 조회없음
`VIDIOC_S_FMT`형식 협상 후 실제 설정있을 수 있음
`VIDIOC_TRY_FMT`형식 유효성·하드웨어 한계 시험없음

조회, 실제 설정, 상태 없는 시험을 구분합니다.

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

.. _VIDIOC_G_FMT:

************************************************
ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT
************************************************

Name
====

VIDIOC_G_FMT - VIDIOC_S_FMT - VIDIOC_TRY_FMT - Get or set the data format, try a format

Synopsis
========

.. c:macro:: VIDIOC_G_FMT

``int ioctl(int fd, VIDIOC_G_FMT, struct v4l2_format *argp)``

.. c:macro:: VIDIOC_S_FMT

``int ioctl(int fd, VIDIOC_S_FMT, struct v4l2_format *argp)``

.. c:macro:: VIDIOC_TRY_FMT

``int ioctl(int fd, VIDIOC_TRY_FMT, struct v4l2_format *argp)``

Arguments
=========

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

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

현재 형식 조회

39-57

현재 매개변수를 조회하려면 `v4l2_format.type`을 대상 buffer 또는 stream type으로 설정합니다. 영상 캡처 장치는 예를 들어 `V4L2_BUF_TYPE_VIDEO_CAPTURE` 또는 `V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`을 사용합니다.

`VIDIOC_G_FMT`를 호출하면 드라이버가 `fmt` union의 대응 멤버를 채웁니다. 단일 plane 영상 캡처에서는 `struct v4l2_pix_format pix`, multi-planar 캡처에서는 `struct v4l2_pix_format_mplane pix_mp`입니다.

요청한 buffer type을 장치가 지원하지 않으면 `EINVAL`을 반환합니다. union 멤버는 반드시 `type`에 대응하는 형식으로 해석해야 합니다.

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

These ioctls are used to negotiate the format of data (typically image
format) exchanged between driver and application.

To query the current parameters applications set the ``type`` field of a
struct :c:type:`v4l2_format` to the respective buffer (stream)
type. For example video capture devices use
``V4L2_BUF_TYPE_VIDEO_CAPTURE`` or
``V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE``. When the application calls the
:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl with a pointer to this structure the driver fills
the respective member of the ``fmt`` union. In case of video capture
devices that is either the struct
:c:type:`v4l2_pix_format` ``pix`` or the struct
:c:type:`v4l2_pix_format_mplane` ``pix_mp``
member. When the requested buffer type is not supported drivers return
an ``EINVAL`` error code.

형식 설정과 상태 없는 시험

58-89

현재 형식을 바꾸려면 `type`과 그 type에 대응하는 `fmt` union 멤버의 모든 필드를 초기화합니다. 먼저 현재 매개변수를 조회하고 애플리케이션에 맞지 않는 값만 수정하는 방식이 권장됩니다.

`VIDIOC_S_FMT`를 호출하면 드라이버는 하드웨어 능력에 맞춰 값을 검사하고 조정합니다. `type`이 잘못된 경우 외에는 되도록 오류를 반환하지 않아야 하며, 이 조정 과정으로 양쪽이 받아들일 수 있는 매개변수와 장치 한계를 탐색합니다.

성공한 S_FMT는 하드웨어를 프로그램하고 자원을 할당해 데이터 교환을 준비할 수 있습니다. 마지막에는 G_FMT와 같은 현재 형식 매개변수를 구조체에 반환합니다. 단순하고 유연하지 않은 장치는 입력을 모두 무시하고 기본값만 반환할 수도 있습니다.

애플리케이션과 데이터를 교환하는 모든 V4L2 장치는 G_FMT와 S_FMT를 구현해야 합니다. S_FMT에서 지원하지 않는 buffer type은 `EINVAL`, I/O 진행 중이거나 자원을 사용할 수 없으면 `EBUSY`입니다.

`VIDIOC_TRY_FMT`는 드라이버 상태를 바꾸지 않는다는 점을 제외하면 S_FMT와 같습니다. 언제든 호출할 수 있고 `EBUSY`를 반환하지 않으며, I/O를 중단하거나 시간이 오래 걸리는 하드웨어 준비 없이 형식을 협상하고 하드웨어 한계를 확인합니다.

TRY_FMT 구현은 강력히 권장되지만 의무는 아닙니다. 구현된 경우 동일한 입력 또는 출력에 대해 TRY_FMT가 반환하는 형식은 S_FMT의 반환 형식과 반드시 같아야 합니다.

권장 format 협상
type을 대상 stream type으로 설정VIDIOC_G_FMT로 현재 형식 조회필요한 필드만 수정VIDIOC_TRY_FMT로 조정 결과와 한계 확인동일한 입력으로 VIDIOC_S_FMT 호출반환된 최종 현재 형식 저장

현재값을 출발점으로 시험한 뒤 확정 형식을 설정합니다.

To change the current format parameters applications initialize the
``type`` field and all fields of the respective ``fmt`` union member.
For details see the documentation of the various devices types in
:ref:`devices`. Good practice is to query the current parameters
first, and to modify only those parameters not suitable for the
application. When the application calls the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with
a pointer to a struct :c:type:`v4l2_format` structure the driver
checks and adjusts the parameters against hardware abilities. Drivers
should not return an error code unless the ``type`` field is invalid,
this is a mechanism to fathom device capabilities and to approach
parameters acceptable for both the application and driver. On success
the driver may program the hardware, allocate resources and generally
prepare for data exchange. Finally the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl returns
the current format parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does. Very simple,
inflexible devices may even ignore all input and always return the
default parameters. However all V4L2 devices exchanging data with the
application must implement the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
ioctl. When the requested buffer type is not supported drivers return an
EINVAL error code on a :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` attempt. When I/O is already in
progress or the resource is not available for other reasons drivers
return the ``EBUSY`` error code.

The :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl is equivalent to :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` with one
exception: it does not change driver state. It can also be called at any
time, never returning ``EBUSY``. This function is provided to negotiate
parameters, to learn about hardware limitations, without disabling I/O
or possibly time consuming hardware preparations. Although strongly
recommended drivers are not required to implement this ioctl.

The format as returned by :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` must be identical to what
:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` returns for the same input or output.

struct v4l2_format

90-138

`v4l2_format.type`은 `enum v4l2_buf_type`의 데이터 stream type입니다. 익명 union `fmt`에서는 이 type에 대응하는 멤버 하나만 유효합니다.

v4l2_format fmt union
형식멤버사용 대상
`struct v4l2_pix_format``pix`단일 plane video capture·output 영상 형식
`struct v4l2_pix_format_mplane``pix_mp`multi-planar API를 지원하는 video capture·output 영상 형식
`struct v4l2_window``win`video overlay 장치의 overlay 영상
`struct v4l2_vbi_format``vbi`raw VBI capture·output 매개변수
`struct v4l2_sliced_vbi_format``sliced`sliced VBI capture·output 매개변수
`struct v4l2_sdr_format``sdr`SDR capture·output 데이터 형식
`struct v4l2_meta_format``meta`metadata capture 장치의 metadata 형식
`__u8[200]``raw_data[200]`미래 확장을 위한 자리

buffer type과 장치 종류에 따라 사용할 형식 구조체를 선택합니다.

`pix`와 `pix_mp`는 같은 영상 목적이지만 각각 single-planar와 multi-planar API에 대응합니다. `win`, `vbi`, `sliced`, `sdr`, `meta`는 서로 다른 stream type의 배치와 매개변수를 정의하므로 type을 바꿀 때 union 내용도 전부 다시 초기화해야 합니다.

.. c:type:: v4l2_format

.. tabularcolumns::  |p{7.4cm}|p{4.4cm}|p{5.5cm}|

.. flat-table:: struct v4l2_format
    :header-rows:  0
    :stub-columns: 0

    * - __u32
      - ``type``
      - Type of the data stream, see :c:type:`v4l2_buf_type`.
    * - union {
      - ``fmt``
    * - struct :c:type:`v4l2_pix_format`
      - ``pix``
      - Definition of an image format, see :ref:`pixfmt`, used by video
	capture and output devices.
    * - struct :c:type:`v4l2_pix_format_mplane`
      - ``pix_mp``
      - Definition of an image format, see :ref:`pixfmt`, used by video
	capture and output devices that support the
	:ref:`multi-planar version of the API <planar-apis>`.
    * - struct :c:type:`v4l2_window`
      - ``win``
      - Definition of an overlaid image, see :ref:`overlay`, used by
	video overlay devices.
    * - struct :c:type:`v4l2_vbi_format`
      - ``vbi``
      - Raw VBI capture or output parameters. This is discussed in more
	detail in :ref:`raw-vbi`. Used by raw VBI capture and output
	devices.
    * - struct :c:type:`v4l2_sliced_vbi_format`
      - ``sliced``
      - Sliced VBI capture or output parameters. See :ref:`sliced` for
	details. Used by sliced VBI capture and output devices.
    * - struct :c:type:`v4l2_sdr_format`
      - ``sdr``
      - Definition of a data format, see :ref:`pixfmt`, used by SDR
	capture and output devices.
    * - struct :c:type:`v4l2_meta_format`
      - ``meta``
      - Definition of a metadata format, see :ref:`meta-formats`, used by
	metadata capture devices.
    * - __u8
      - ``raw_data``\ [200]
      - Place holder for future extensions.
    * - }
      -

반환값과 오류

139-154

성공하면 0을 반환합니다. 오류가 발생하면 -1을 반환하고 `errno`를 설정하며, 아래 전용 오류 외에도 Generic Error Codes 장의 공통 오류가 적용됩니다.

format 오류
errno조건적용 명령
`EINVAL``v4l2_format.type`이 잘못됐거나 요청한 buffer type을 지원하지 않음G_FMT·S_FMT·TRY_FMT
`EBUSY`streaming 중이거나 buffer가 할당·queue되어 형식을 바꿀 수 없음S_FMT만 해당

buffer type과 장치 상태에 따른 오류입니다.

TRY_FMT는 어떤 시점에도 상태를 바꾸지 않고 호출할 수 있으므로 `EBUSY`를 반환하지 않습니다. S_FMT의 `EBUSY`가 예상되면 TRY_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.

EINVAL
    The struct :c:type:`v4l2_format` ``type`` field is
    invalid or the requested buffer type not supported.

EBUSY
    The device is busy and cannot change the format. This could be
    because or the device is streaming or buffers are allocated or
    queued to the driver. Relevant for :ref:`VIDIOC_S_FMT
    <VIDIOC_G_FMT>` only.