요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. 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`.
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`).
.. 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.
.. 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.
.. 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`.
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.
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 인코더에는 필수입니다.
명시적 명령과 파일 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으로 초기화해야 합니다.
명령 입력과 예약 공간을 원문 순서대로 보존합니다.
.. 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`입니다. 이미 목표 상태라면 아무 일도 하지 않으며 두 명령 모두 플래그가 없습니다.
명령값, 상태 효과와 제약을 비교합니다.
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 인터페이스에는 적용되지 않습니다.
현재 정의된 명령 플래그입니다.
.. 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 절을 따릅니다.
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.
요약·해설
vidioc-encoder-cmd.rst:1-169VIDIOC_ENCODER_CMD와 TRY 변형으로 인코더를 시작·정지·일시 정지·재개하고 STOP 뒤 남은 데이터, GOP 종료 플래그와 stateful drain을 처리합니다.