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

Linux 6.18.37 · 사용자 공간 API

VIDIOC_ENCODER_CMD와 VIDIOC_TRY_ENCODER_CMD ioctl

VIDIOC_ENCODER_CMD와 TRY 변형으로 인코더를 시작·정지·일시 정지·재개하고 STOP 뒤 남은 데이터, GOP 종료 플래그와 stateful drain을 처리합니다.

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

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

1. 요약·해설

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

요약·해설

vidioc-encoder-cmd.rst:1-169

VIDIOC_ENCODER_CMD와 TRY 변형으로 인코더를 시작·정지·일시 정지·재개하고 STOP 뒤 남은 데이터, GOP 종료 플래그와 stateful drain을 처리합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2 .. c:namespace:: V4L
3
4 .. _VIDIOC_ENCODER_CMD:
5
6 ************************************************
7 ioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD
8 ************************************************
9
10 Name
11 ====
12
13 VIDIOC_ENCODER_CMD - VIDIOC_TRY_ENCODER_CMD - Execute an encoder command
14
15 Synopsis
16 ========
17
18 .. c:macro:: VIDIOC_ENCODER_CMD
19
20 ``int ioctl(int fd, VIDIOC_ENCODER_CMD, struct v4l2_encoder_cmd *argp)``
21
22 .. c:macro:: VIDIOC_TRY_ENCODER_CMD
23
24 ``int ioctl(int fd, VIDIOC_TRY_ENCODER_CMD, struct v4l2_encoder_cmd *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_encoder_cmd`.
34
35 Description
36 ===========
37
38 These ioctls control an audio/video (usually MPEG-) encoder.
39 ``VIDIOC_ENCODER_CMD`` sends a command to the encoder,
40 ``VIDIOC_TRY_ENCODER_CMD`` can be used to try a command without actually
41 executing it.
42
43 To send a command applications must initialize all fields of a struct
44 :c:type:`v4l2_encoder_cmd` and call
45 ``VIDIOC_ENCODER_CMD`` or ``VIDIOC_TRY_ENCODER_CMD`` with a pointer to
46 this structure.
47
48 The ``cmd`` field must contain the command code. Some commands use the
49 ``flags`` field for additional information.
50
51 After a STOP command, :c:func:`read()` calls will read
52 the remaining data buffered by the driver. When the buffer is empty,
53 :c:func:`read()` will return zero and the next :c:func:`read()`
54 call will restart the encoder.
55
56 A :c:func:`read()` or :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>`
57 call sends an implicit START command to the encoder if it has not been
58 started yet. Applies to both queues of mem2mem encoders.
59
60 A :c:func:`close()` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
61 call of a streaming file descriptor sends an implicit immediate STOP to
62 the encoder, and all buffered data is discarded. Applies to both queues of
63 mem2mem encoders.
64
65 These ioctls are optional, not all drivers may support them. They were
66 introduced in Linux 2.6.21. They are, however, mandatory for stateful mem2mem
67 encoders (as further documented in :ref:`encoder`).
68
69 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
70
71 .. c:type:: v4l2_encoder_cmd
72
73 .. flat-table:: struct v4l2_encoder_cmd
74 :header-rows: 0
75 :stub-columns: 0
76 :widths: 1 1 2
77
78 * - __u32
79 - ``cmd``
80 - The encoder command, see :ref:`encoder-cmds`.
81 * - __u32
82 - ``flags``
83 - Flags to go with the command, see :ref:`encoder-flags`. If no
84 flags are defined for this command, drivers and applications must
85 set this field to zero.
86 * - __u32
87 - ``data``\ [8]
88 - Reserved for future extensions. Drivers and applications must set
89 the array to zero.
90
91
92 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|
93
94 .. _encoder-cmds:
95
96 .. flat-table:: Encoder Commands
97 :header-rows: 0
98 :stub-columns: 0
99 :widths: 3 1 4
100
101 * - ``V4L2_ENC_CMD_START``
102 - 0
103 - Start the encoder. When the encoder is already running or paused,
104 this command does nothing. No flags are defined for this command.
105
106 For a device implementing the :ref:`encoder`, once the drain sequence
107 is initiated with the ``V4L2_ENC_CMD_STOP`` command, it must be driven
108 to completion before this command can be invoked. Any attempt to
109 invoke the command while the drain sequence is in progress will trigger
110 an ``EBUSY`` error code. See :ref:`encoder` for more details.
111 * - ``V4L2_ENC_CMD_STOP``
112 - 1
113 - Stop the encoder. When the ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag
114 is set, encoding will continue until the end of the current *Group
115 Of Pictures*, otherwise encoding will stop immediately. When the
116 encoder is already stopped, this command does nothing.
117
118 For a device implementing the :ref:`encoder`, the command will initiate
119 the drain sequence as documented in :ref:`encoder`. No flags or other
120 arguments are accepted in this case. Any attempt to invoke the command
121 again before the sequence completes will trigger an ``EBUSY`` error
122 code.
123 * - ``V4L2_ENC_CMD_PAUSE``
124 - 2
125 - Pause the encoder. When the encoder has not been started yet, the
126 driver will return an ``EPERM`` error code. When the encoder is
127 already paused, this command does nothing. No flags are defined
128 for this command.
129 * - ``V4L2_ENC_CMD_RESUME``
130 - 3
131 - Resume encoding after a PAUSE command. When the encoder has not
132 been started yet, the driver will return an ``EPERM`` error code. When
133 the encoder is already running, this command does nothing. No
134 flags are defined for this command.
135
136 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|
137
138 .. _encoder-flags:
139
140 .. flat-table:: Encoder Command Flags
141 :header-rows: 0
142 :stub-columns: 0
143 :widths: 3 1 4
144
145 * - ``V4L2_ENC_CMD_STOP_AT_GOP_END``
146 - 0x0001
147 - Stop encoding at the end of the current *Group Of Pictures*,
148 rather than immediately.
149
150 Does not apply to :ref:`encoder`.
151
152 Return Value
153 ============
154
155 On success 0 is returned, on error -1 and the ``errno`` variable is set
156 appropriately. The generic error codes are described at the
157 :ref:`Generic Error Codes <gen-errors>` chapter.
158
159 EBUSY
160 A drain sequence of a device implementing the :ref:`encoder` is still in
161 progress. It is not allowed to issue another encoder command until it
162 completes.
163
164 EINVAL
165 The ``cmd`` field is invalid.
166
167 EPERM
168 The application sent a PAUSE or RESUME command when the encoder was
169 not running.
170

3. 한국어 전문 번역

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

이름, 호출 형식과 인자

1-34

`VIDIOC_ENCODER_CMD`는 오디오·비디오 인코더에 명령을 실행하고, `VIDIOC_TRY_ENCODER_CMD`는 명령을 실제로 실행하지 않은 채 지원 여부와 인자를 시험합니다. 두 호출 모두 `struct v4l2_encoder_cmd *argp`를 사용합니다.

`fd`는 `open()`이 반환한 파일 디스크립터이고 `argp`는 응용 프로그램이 모든 필드를 초기화한 `struct v4l2_encoder_cmd`를 가리킵니다.

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

.. _VIDIOC_ENCODER_CMD:

************************************************
ioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD
************************************************

Name
====

VIDIOC_ENCODER_CMD - VIDIOC_TRY_ENCODER_CMD - Execute an encoder command

Synopsis
========

.. c:macro:: VIDIOC_ENCODER_CMD

``int ioctl(int fd, VIDIOC_ENCODER_CMD, struct v4l2_encoder_cmd *argp)``

.. c:macro:: VIDIOC_TRY_ENCODER_CMD

``int ioctl(int fd, VIDIOC_TRY_ENCODER_CMD, struct v4l2_encoder_cmd *argp)``

Arguments
=========

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

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

명령 전송과 스트림의 암시적 제어

35-68

`cmd`에는 명령 코드를 넣고 일부 명령은 `flags`로 추가 동작을 지정합니다. `VIDIOC_TRY_ENCODER_CMD`는 인코더 상태를 바꾸지 않고 명령을 검증합니다.

STOP 뒤의 `read()`는 드라이버에 버퍼링된 남은 인코딩 데이터를 계속 읽습니다. 버퍼가 비면 `read()`가 0을 반환하고 그 다음 `read()` 호출은 인코더를 다시 시작합니다.

아직 시작하지 않은 인코더에 `read()` 또는 `VIDIOC_STREAMON`을 호출하면 암시적 START가 전달됩니다. 스트리밍 파일 디스크립터를 `close()`하거나 `VIDIOC_STREAMOFF`를 호출하면 암시적 즉시 STOP이 전달되고 모든 버퍼링 데이터가 폐기됩니다. 두 규칙은 mem2mem 인코더의 양쪽 큐에 적용됩니다.

이 ioctl은 Linux 2.6.21에 도입된 선택 기능이지만 stateful mem2mem 인코더에는 필수입니다.

인코더 스트림 수명
read 또는 VIDIOC_STREAMON -> implicit STARTVIDIOC_ENCODER_CMD -> 명시적 상태 제어STOP 뒤 read -> 남은 데이터 배출read가 0 -> 버퍼 비움다음 read -> 인코더 재시작close 또는 STREAMOFF -> immediate STOP과 데이터 폐기

명시적 명령과 파일 I/O가 인코더 상태에 미치는 영향입니다.

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

These ioctls control an audio/video (usually MPEG-) encoder.
``VIDIOC_ENCODER_CMD`` sends a command to the encoder,
``VIDIOC_TRY_ENCODER_CMD`` can be used to try a command without actually
executing it.

To send a command applications must initialize all fields of a struct
:c:type:`v4l2_encoder_cmd` and call
``VIDIOC_ENCODER_CMD`` or ``VIDIOC_TRY_ENCODER_CMD`` with a pointer to
this structure.

The ``cmd`` field must contain the command code. Some commands use the
``flags`` field for additional information.

After a STOP command, :c:func:`read()` calls will read
the remaining data buffered by the driver. When the buffer is empty,
:c:func:`read()` will return zero and the next :c:func:`read()`
call will restart the encoder.

A :c:func:`read()` or :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>`
call sends an implicit START command to the encoder if it has not been
started yet. Applies to both queues of mem2mem encoders.

A :c:func:`close()` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
call of a streaming file descriptor sends an implicit immediate STOP to
the encoder, and all buffered data is discarded. Applies to both queues of
mem2mem encoders.

These ioctls are optional, not all drivers may support them. They were
introduced in Linux 2.6.21. They are, however, mandatory for stateful mem2mem
encoders (as further documented in :ref:`encoder`).

v4l2_encoder_cmd 구조체

69-90

구조체는 `cmd`, `flags`, 미래 확장용 `data[8]`로 이루어집니다. 명령에 정의된 플래그가 없다면 드라이버와 응용 프로그램 모두 `flags`를 0으로 설정해야 하며 `data` 배열도 항상 0으로 초기화해야 합니다.

struct v4l2_encoder_cmd
형식필드의미
`__u32``cmd`실행하거나 시험할 인코더 명령
`__u32``flags`명령별 플래그; 정의되지 않으면 0
`__u32[8]``data`미래 확장용이며 드라이버와 응용 프로그램 모두 0

명령 입력과 예약 공간을 원문 순서대로 보존합니다.

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

.. c:type:: v4l2_encoder_cmd

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

    * - __u32
      - ``cmd``
      - The encoder command, see :ref:`encoder-cmds`.
    * - __u32
      - ``flags``
      - Flags to go with the command, see :ref:`encoder-flags`. If no
	flags are defined for this command, drivers and applications must
	set this field to zero.
    * - __u32
      - ``data``\ [8]
      - Reserved for future extensions. Drivers and applications must set
	the array to zero.

START, STOP, PAUSE와 RESUME

91-134

`V4L2_ENC_CMD_START` 값은 0입니다. 인코더가 이미 실행 중이거나 일시 정지 상태면 아무 일도 하지 않으며 플래그는 없습니다. stateful drain이 진행 중이면 완료 전 START가 `EBUSY`를 반환합니다.

`V4L2_ENC_CMD_STOP` 값은 1입니다. `V4L2_ENC_CMD_STOP_AT_GOP_END`가 있으면 현재 GOP 끝까지 인코딩하고, 없으면 즉시 정지합니다. 이미 정지 상태면 아무 일도 하지 않습니다.

stateful 인코더에서 STOP은 drain sequence를 시작하며 플래그나 다른 인자를 허용하지 않습니다. drain 완료 전에 STOP을 다시 호출하거나 다른 명령을 보내면 `EBUSY`입니다.

`V4L2_ENC_CMD_PAUSE` 값은 2이고 `V4L2_ENC_CMD_RESUME` 값은 3입니다. 시작 전 PAUSE 또는 RESUME은 `EPERM`입니다. 이미 목표 상태라면 아무 일도 하지 않으며 두 명령 모두 플래그가 없습니다.

Encoder Commands
명령동작상태·플래그
`V4L2_ENC_CMD_START`0인코더 시작실행·일시 정지 중이면 무동작; 플래그 없음
`V4L2_ENC_CMD_STOP`1즉시 정지 또는 GOP 끝 정지stateful에서는 drain, 인자 없음
`V4L2_ENC_CMD_PAUSE`2인코더 일시 정지미시작이면 EPERM; 플래그 없음
`V4L2_ENC_CMD_RESUME`3PAUSE 뒤 인코딩 재개미시작이면 EPERM; 플래그 없음

명령값, 상태 효과와 제약을 비교합니다.

stateful drain 규칙
V4L2_ENC_CMD_STOPdrain sequence 진행중간 명령은 EBUSYdrain 완료다음 START 또는 상태 명령 허용

STOP이 시작한 drain이 끝나기 전에는 다음 명령을 허용하지 않습니다.


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

.. _encoder-cmds:

.. flat-table:: Encoder Commands
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4

    * - ``V4L2_ENC_CMD_START``
      - 0
      - Start the encoder. When the encoder is already running or paused,
	this command does nothing. No flags are defined for this command.

	For a device implementing the :ref:`encoder`, once the drain sequence
	is initiated with the ``V4L2_ENC_CMD_STOP`` command, it must be driven
	to completion before this command can be invoked.  Any attempt to
	invoke the command while the drain sequence is in progress will trigger
	an ``EBUSY`` error code. See :ref:`encoder` for more details.
    * - ``V4L2_ENC_CMD_STOP``
      - 1
      - Stop the encoder. When the ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag
	is set, encoding will continue until the end of the current *Group
	Of Pictures*, otherwise encoding will stop immediately. When the
	encoder is already stopped, this command does nothing.

	For a device implementing the :ref:`encoder`, the command will initiate
	the drain sequence as documented in :ref:`encoder`. No flags or other
	arguments are accepted in this case. Any attempt to invoke the command
	again before the sequence completes will trigger an ``EBUSY`` error
	code.
    * - ``V4L2_ENC_CMD_PAUSE``
      - 2
      - Pause the encoder. When the encoder has not been started yet, the
	driver will return an ``EPERM`` error code. When the encoder is
	already paused, this command does nothing. No flags are defined
	for this command.
    * - ``V4L2_ENC_CMD_RESUME``
      - 3
      - Resume encoding after a PAUSE command. When the encoder has not
	been started yet, the driver will return an ``EPERM`` error code. When
	the encoder is already running, this command does nothing. No
	flags are defined for this command.

Encoder Command Flags

135-151

`V4L2_ENC_CMD_STOP_AT_GOP_END` 값은 `0x0001`입니다. STOP을 즉시 수행하는 대신 현재 Group Of Pictures가 끝날 때 정지합니다. 이 플래그는 stateful mem2mem encoder 인터페이스에는 적용되지 않습니다.

Encoder Command Flags
플래그의미
`V4L2_ENC_CMD_STOP_AT_GOP_END``0x0001`현재 GOP 끝에서 인코딩 정지; stateful encoder에는 미적용

현재 정의된 명령 플래그입니다.


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

.. _encoder-flags:

.. flat-table:: Encoder Command Flags
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4

    * - ``V4L2_ENC_CMD_STOP_AT_GOP_END``
      - 0x0001
      - Stop encoding at the end of the current *Group Of Pictures*,
	rather than immediately.

        Does not apply to :ref:`encoder`.

반환값과 오류

152-169

성공하면 0을 반환하고 실패하면 -1과 적절한 `errno`를 반환합니다. 일반 오류 코드는 Generic Error Codes 절을 따릅니다.

인코더 명령 오류
errno의미
`EBUSY`stateful 인코더 drain이 진행 중이라 다른 명령을 허용하지 않음
`EINVAL``cmd` 필드가 유효하지 않음
`EPERM`인코더가 실행 중이 아닌데 PAUSE 또는 RESUME을 보냄

drain 상태, 명령 코드와 실행 상태 오류입니다.

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
    A drain sequence of a device implementing the :ref:`encoder` is still in
    progress. It is not allowed to issue another encoder command until it
    completes.

EINVAL
    The ``cmd`` field is invalid.

EPERM
    The application sent a PAUSE or RESUME command when the encoder was
    not running.