요약·해설과 원문, 전문 번역을 서로 분리했습니다. 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_DECODER_CMD:
************************************************
ioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD
************************************************
Name
====
VIDIOC_DECODER_CMD - VIDIOC_TRY_DECODER_CMD - Execute an decoder command
Synopsis
========
.. c:macro:: VIDIOC_DECODER_CMD
``int ioctl(int fd, VIDIOC_DECODER_CMD, struct v4l2_decoder_cmd *argp)``
.. c:macro:: VIDIOC_TRY_DECODER_CMD
``int ioctl(int fd, VIDIOC_TRY_DECODER_CMD, struct v4l2_decoder_cmd *argp)``
Arguments
=========
``fd``
File descriptor returned by :c:func:`open()`.
``argp``
pointer to struct :c:type:`v4l2_decoder_cmd`.
Description
===========
These ioctls control an audio/video (usually MPEG-) decoder.
``VIDIOC_DECODER_CMD`` sends a command to the decoder,
``VIDIOC_TRY_DECODER_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_decoder_cmd` and call
``VIDIOC_DECODER_CMD`` or ``VIDIOC_TRY_DECODER_CMD`` with a pointer to
this structure.
The ``cmd`` field must contain the command code. Some commands use the
``flags`` field for additional information.
A :c:func:`write()` or :ref:`VIDIOC_STREAMON`
call sends an implicit START command to the decoder if it has not been
started yet. Applies to both queues of mem2mem decoders.
A :c:func:`close()` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
call of a streaming file descriptor sends an implicit immediate STOP
command to the decoder, and all buffered data is discarded. Applies to both
queues of mem2mem decoders.
In principle, these ioctls are optional, not all drivers may support them. They were
introduced in Linux 3.3. They are, however, mandatory for stateful mem2mem decoders
(as further documented in :ref:`decoder`).
.. tabularcolumns:: |p{2.0cm}|p{1.1cm}|p{2.2cm}|p{11.8cm}|
.. c:type:: v4l2_decoder_cmd
.. cssclass:: longtable
.. flat-table:: struct v4l2_decoder_cmd
:header-rows: 0
:stub-columns: 0
:widths: 1 1 1 3
* - __u32
- ``cmd``
-
- The decoder command, see :ref:`decoder-cmds`.
* - __u32
- ``flags``
-
- Flags to go with the command. If no flags are defined for this
command, drivers and applications must set this field to zero.
* - union {
- (anonymous)
* - struct
- ``start``
-
- Structure containing additional data for the
``V4L2_DEC_CMD_START`` command.
* -
- __s32
- ``speed``
- Playback speed and direction. The playback speed is defined as
``speed``/1000 of the normal speed. So 1000 is normal playback.
Negative numbers denote reverse playback, so -1000 does reverse
playback at normal speed. Speeds -1, 0 and 1 have special
meanings: speed 0 is shorthand for 1000 (normal playback). A speed
of 1 steps just one frame forward, a speed of -1 steps just one
frame back.
* -
- __u32
- ``format``
- Format restrictions. This field is set by the driver, not the
application. Possible values are ``V4L2_DEC_START_FMT_NONE`` if
there are no format restrictions or ``V4L2_DEC_START_FMT_GOP`` if
the decoder operates on full GOPs (*Group Of Pictures*). This is
usually the case for reverse playback: the decoder needs full
GOPs, which it can then play in reverse order. So to implement
reverse playback the application must feed the decoder the last
GOP in the video file, then the GOP before that, etc. etc.
* - struct
- ``stop``
-
- Structure containing additional data for the ``V4L2_DEC_CMD_STOP``
command.
* -
- __u64
- ``pts``
- Stop playback at this ``pts`` or immediately if the playback is
already past that timestamp. Leave to 0 if you want to stop after
the last frame was decoded.
* - struct
- ``raw``
* -
- __u32
- ``data``\ [16]
- Reserved for future extensions. Drivers and applications must set
the array to zero.
* - }
-
.. tabularcolumns:: |p{5.6cm}|p{0.6cm}|p{11.1cm}|
.. cssclass:: longtable
.. _decoder-cmds:
.. flat-table:: Decoder Commands
:header-rows: 0
:stub-columns: 0
:widths: 56 6 113
* - ``V4L2_DEC_CMD_START``
- 0
- Start the decoder. When the decoder is already running or paused,
this command will just change the playback speed. That means that
calling ``V4L2_DEC_CMD_START`` when the decoder was paused will
*not* resume the decoder. You have to explicitly call
``V4L2_DEC_CMD_RESUME`` for that. This command has one flag:
``V4L2_DEC_CMD_START_MUTE_AUDIO``. If set, then audio will be
muted when playing back at a non-standard speed.
For a device implementing the :ref:`decoder`, once the drain sequence
is initiated with the ``V4L2_DEC_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. The command may be also used to restart the
decoder in case of an implicit stop initiated by the decoder itself,
without the ``V4L2_DEC_CMD_STOP`` being called explicitly. See
:ref:`decoder` for more details.
* - ``V4L2_DEC_CMD_STOP``
- 1
- Stop the decoder. When the decoder is already stopped, this
command does nothing. This command has two flags: if
``V4L2_DEC_CMD_STOP_TO_BLACK`` is set, then the decoder will set
the picture to black after it stopped decoding. Otherwise the last
image will repeat. If
``V4L2_DEC_CMD_STOP_IMMEDIATELY`` is set, then the decoder stops
immediately (ignoring the ``pts`` value), otherwise it will keep
decoding until timestamp >= pts or until the last of the pending
data from its internal buffers was decoded.
For a device implementing the :ref:`decoder`, the command will initiate
the drain sequence as documented in :ref:`decoder`. 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_DEC_CMD_PAUSE``
- 2
- Pause the decoder. When the decoder has not been started yet, the
driver will return an ``EPERM`` error code. When the decoder is
already paused, this command does nothing. This command has one
flag: if ``V4L2_DEC_CMD_PAUSE_TO_BLACK`` is set, then set the
decoder output to black when paused.
* - ``V4L2_DEC_CMD_RESUME``
- 3
- Resume decoding after a PAUSE command. When the decoder has not
been started yet, the driver will return an ``EPERM`` error code. When
the decoder is already running, this command does nothing. No
flags are defined for this command.
* - ``V4L2_DEC_CMD_FLUSH``
- 4
- Flush any held capture buffers. Only valid for stateless decoders.
This command is typically used when the application reached the
end of the stream and the last output buffer had the
``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` flag set. This would prevent
dequeueing the capture buffer containing the last decoded frame.
So this command can be used to explicitly flush that final decoded
frame. This command does nothing if there are no held capture buffers.
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:`decoder` is still in
progress. It is not allowed to issue another decoder command until it
completes.
EINVAL
The ``cmd`` field is invalid.
EPERM
The application sent a PAUSE or RESUME command when the decoder was
not running.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
이름, 호출 형식과 인자
1-34`VIDIOC_DECODER_CMD`는 오디오·비디오 디코더에 명령을 실행하고, `VIDIOC_TRY_DECODER_CMD`는 같은 명령을 실제로 실행하지 않은 채 지원 여부와 인자 유효성을 시험합니다. 두 호출 모두 `struct v4l2_decoder_cmd *argp`를 사용합니다.
`fd`는 `open()`이 반환한 파일 디스크립터이고, `argp`는 응용 프로그램이 모든 필드를 초기화한 `struct v4l2_decoder_cmd`를 가리킵니다.
.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. c:namespace:: V4L
.. _VIDIOC_DECODER_CMD:
************************************************
ioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD
************************************************
Name
====
VIDIOC_DECODER_CMD - VIDIOC_TRY_DECODER_CMD - Execute an decoder command
Synopsis
========
.. c:macro:: VIDIOC_DECODER_CMD
``int ioctl(int fd, VIDIOC_DECODER_CMD, struct v4l2_decoder_cmd *argp)``
.. c:macro:: VIDIOC_TRY_DECODER_CMD
``int ioctl(int fd, VIDIOC_TRY_DECODER_CMD, struct v4l2_decoder_cmd *argp)``
Arguments
=========
``fd``
File descriptor returned by :c:func:`open()`.
``argp``
pointer to struct :c:type:`v4l2_decoder_cmd`.
명령 전송과 암시적 시작·정지
35-61`cmd`에는 디코더 명령 코드를 넣고 일부 명령은 `flags`로 추가 동작을 지정합니다. `VIDIOC_TRY_DECODER_CMD`는 드라이버가 명령을 받아들일지 확인할 때 사용하며 디코더 상태 자체는 바꾸지 않습니다.
아직 시작하지 않은 디코더에 `write()` 또는 `VIDIOC_STREAMON`을 호출하면 암시적 START 명령이 전달됩니다. 스트리밍 파일 디스크립터를 `close()`하거나 `VIDIOC_STREAMOFF`를 호출하면 암시적 즉시 STOP이 전달되고 버퍼링된 모든 데이터가 폐기됩니다. 두 규칙은 mem2mem 디코더의 양쪽 큐 모두에 적용됩니다.
이 ioctl은 원칙적으로 선택 기능이며 Linux 3.3에서 도입됐습니다. 다만 stateful mem2mem 디코더에는 필수입니다.
스트리밍 API와 디코더 명령 사이의 대응입니다.
Description
===========
These ioctls control an audio/video (usually MPEG-) decoder.
``VIDIOC_DECODER_CMD`` sends a command to the decoder,
``VIDIOC_TRY_DECODER_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_decoder_cmd` and call
``VIDIOC_DECODER_CMD`` or ``VIDIOC_TRY_DECODER_CMD`` with a pointer to
this structure.
The ``cmd`` field must contain the command code. Some commands use the
``flags`` field for additional information.
A :c:func:`write()` or :ref:`VIDIOC_STREAMON`
call sends an implicit START command to the decoder if it has not been
started yet. Applies to both queues of mem2mem decoders.
A :c:func:`close()` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
call of a streaming file descriptor sends an implicit immediate STOP
command to the decoder, and all buffered data is discarded. Applies to both
queues of mem2mem decoders.
In principle, these ioctls are optional, not all drivers may support them. They were
introduced in Linux 3.3. They are, however, mandatory for stateful mem2mem decoders
(as further documented in :ref:`decoder`).
v4l2_decoder_cmd 구조체
62-131구조체의 `cmd`와 `flags` 뒤에는 명령별 추가 인자를 담는 익명 union이 있습니다. 해당 명령에 정의된 플래그가 없으면 드라이버와 응용 프로그램 모두 `flags`를 0으로 설정해야 합니다.
START의 `speed`는 정상 속도의 1/1000 단위입니다. 1000은 정방향 정상 재생, -1000은 역방향 정상 재생입니다. 특수값 0은 1000의 축약이고, 1은 한 프레임 전진, -1은 한 프레임 후진입니다.
START의 `format`은 응용 프로그램이 아니라 드라이버가 설정합니다. `V4L2_DEC_START_FMT_NONE`은 제한 없음, `V4L2_DEC_START_FMT_GOP`는 완전한 GOP 단위가 필요함을 뜻합니다. 역재생에서 GOP 제한이 있으면 응용 프로그램은 파일의 마지막 GOP부터 그 이전 GOP 순서로 공급해야 합니다.
STOP의 `pts`는 정지할 프레젠테이션 타임스탬프입니다. 이미 그 시각을 지났으면 즉시 정지하고, 0이면 마지막 프레임을 디코딩한 뒤 정지합니다. `raw.data[16]`은 미래 확장용이므로 드라이버와 응용 프로그램 모두 0으로 설정해야 합니다.
명령 공통 필드와 union의 START·STOP 데이터를 원문 순서대로 정리합니다.
.. tabularcolumns:: |p{2.0cm}|p{1.1cm}|p{2.2cm}|p{11.8cm}|
.. c:type:: v4l2_decoder_cmd
.. cssclass:: longtable
.. flat-table:: struct v4l2_decoder_cmd
:header-rows: 0
:stub-columns: 0
:widths: 1 1 1 3
* - __u32
- ``cmd``
-
- The decoder command, see :ref:`decoder-cmds`.
* - __u32
- ``flags``
-
- Flags to go with the command. If no flags are defined for this
command, drivers and applications must set this field to zero.
* - union {
- (anonymous)
* - struct
- ``start``
-
- Structure containing additional data for the
``V4L2_DEC_CMD_START`` command.
* -
- __s32
- ``speed``
- Playback speed and direction. The playback speed is defined as
``speed``/1000 of the normal speed. So 1000 is normal playback.
Negative numbers denote reverse playback, so -1000 does reverse
playback at normal speed. Speeds -1, 0 and 1 have special
meanings: speed 0 is shorthand for 1000 (normal playback). A speed
of 1 steps just one frame forward, a speed of -1 steps just one
frame back.
* -
- __u32
- ``format``
- Format restrictions. This field is set by the driver, not the
application. Possible values are ``V4L2_DEC_START_FMT_NONE`` if
there are no format restrictions or ``V4L2_DEC_START_FMT_GOP`` if
the decoder operates on full GOPs (*Group Of Pictures*). This is
usually the case for reverse playback: the decoder needs full
GOPs, which it can then play in reverse order. So to implement
reverse playback the application must feed the decoder the last
GOP in the video file, then the GOP before that, etc. etc.
* - struct
- ``stop``
-
- Structure containing additional data for the ``V4L2_DEC_CMD_STOP``
command.
* -
- __u64
- ``pts``
- Stop playback at this ``pts`` or immediately if the playback is
already past that timestamp. Leave to 0 if you want to stop after
the last frame was decoded.
* - struct
- ``raw``
* -
- __u32
- ``data``\ [16]
- Reserved for future extensions. Drivers and applications must set
the array to zero.
* - }
-
START와 STOP 명령
132-177`V4L2_DEC_CMD_START` 값은 0이며 디코더를 시작합니다. 이미 실행 중이거나 일시 정지 중이면 재생 속도만 바꾸므로, PAUSE 상태에서 START를 호출해도 재개되지 않습니다. 재개에는 `V4L2_DEC_CMD_RESUME`이 필요합니다. `V4L2_DEC_CMD_START_MUTE_AUDIO`는 비표준 속도 재생 중 오디오를 음소거합니다.
stateful 디코더에서 STOP으로 drain을 시작했다면 완료되기 전 START를 호출할 수 없고 `EBUSY`가 발생합니다. 디코더가 자체적으로 암시적 정지를 수행한 경우에는 명시적 STOP 없이 START로 다시 시작할 수 있습니다.
`V4L2_DEC_CMD_STOP` 값은 1입니다. 이미 정지 상태면 아무 일도 하지 않습니다. `V4L2_DEC_CMD_STOP_TO_BLACK`은 정지 후 검은 화면을 출력하며, 플래그가 없으면 마지막 영상을 반복합니다. `V4L2_DEC_CMD_STOP_IMMEDIATELY`는 `pts`를 무시하고 즉시 정지합니다. 그렇지 않으면 timestamp가 pts 이상이 되거나 내부 보류 데이터가 모두 디코딩될 때까지 계속합니다.
stateful 디코더에서는 STOP이 drain sequence를 시작하며 플래그나 다른 인자를 받지 않습니다. 완료 전에 STOP을 다시 호출하면 `EBUSY`입니다.
상태 전이와 플래그를 비교합니다.
drain 중에는 다른 디코더 명령을 허용하지 않습니다.
.. tabularcolumns:: |p{5.6cm}|p{0.6cm}|p{11.1cm}|
.. cssclass:: longtable
.. _decoder-cmds:
.. flat-table:: Decoder Commands
:header-rows: 0
:stub-columns: 0
:widths: 56 6 113
* - ``V4L2_DEC_CMD_START``
- 0
- Start the decoder. When the decoder is already running or paused,
this command will just change the playback speed. That means that
calling ``V4L2_DEC_CMD_START`` when the decoder was paused will
*not* resume the decoder. You have to explicitly call
``V4L2_DEC_CMD_RESUME`` for that. This command has one flag:
``V4L2_DEC_CMD_START_MUTE_AUDIO``. If set, then audio will be
muted when playing back at a non-standard speed.
For a device implementing the :ref:`decoder`, once the drain sequence
is initiated with the ``V4L2_DEC_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. The command may be also used to restart the
decoder in case of an implicit stop initiated by the decoder itself,
without the ``V4L2_DEC_CMD_STOP`` being called explicitly. See
:ref:`decoder` for more details.
* - ``V4L2_DEC_CMD_STOP``
- 1
- Stop the decoder. When the decoder is already stopped, this
command does nothing. This command has two flags: if
``V4L2_DEC_CMD_STOP_TO_BLACK`` is set, then the decoder will set
the picture to black after it stopped decoding. Otherwise the last
image will repeat. If
``V4L2_DEC_CMD_STOP_IMMEDIATELY`` is set, then the decoder stops
immediately (ignoring the ``pts`` value), otherwise it will keep
decoding until timestamp >= pts or until the last of the pending
data from its internal buffers was decoded.
For a device implementing the :ref:`decoder`, the command will initiate
the drain sequence as documented in :ref:`decoder`. 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.
PAUSE, RESUME과 FLUSH 명령
178-200`V4L2_DEC_CMD_PAUSE` 값은 2입니다. 디코더가 시작되지 않았다면 `EPERM`, 이미 일시 정지 상태면 아무 일도 하지 않습니다. `V4L2_DEC_CMD_PAUSE_TO_BLACK`을 설정하면 일시 정지 중 출력 화면을 검게 만듭니다.
`V4L2_DEC_CMD_RESUME` 값은 3이며 PAUSE 뒤 디코딩을 재개합니다. 시작 전에는 `EPERM`, 이미 실행 중이면 아무 일도 하지 않으며 정의된 플래그가 없습니다.
`V4L2_DEC_CMD_FLUSH` 값은 4이며 stateless 디코더에서만 유효합니다. 스트림 끝의 마지막 출력 버퍼에 `V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`가 있어 마지막 디코딩 프레임의 capture 버퍼를 dequeue할 수 없을 때, 보류된 최종 프레임을 명시적으로 내보냅니다. 보류 capture 버퍼가 없으면 아무 일도 하지 않습니다.
실행 전 상태와 적용 대상을 구분합니다.
* - ``V4L2_DEC_CMD_PAUSE``
- 2
- Pause the decoder. When the decoder has not been started yet, the
driver will return an ``EPERM`` error code. When the decoder is
already paused, this command does nothing. This command has one
flag: if ``V4L2_DEC_CMD_PAUSE_TO_BLACK`` is set, then set the
decoder output to black when paused.
* - ``V4L2_DEC_CMD_RESUME``
- 3
- Resume decoding after a PAUSE command. When the decoder has not
been started yet, the driver will return an ``EPERM`` error code. When
the decoder is already running, this command does nothing. No
flags are defined for this command.
* - ``V4L2_DEC_CMD_FLUSH``
- 4
- Flush any held capture buffers. Only valid for stateless decoders.
This command is typically used when the application reached the
end of the stream and the last output buffer had the
``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` flag set. This would prevent
dequeueing the capture buffer containing the last decoded frame.
So this command can be used to explicitly flush that final decoded
frame. This command does nothing if there are no held capture buffers.
반환값과 오류
201-218성공하면 0을 반환하고 실패하면 -1과 적절한 `errno`를 반환합니다. 공통 오류는 Generic Error Codes 절을 따릅니다.
명령 상태와 인자 오류를 구분합니다.
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:`decoder` is still in
progress. It is not allowed to issue another decoder command until it
completes.
EINVAL
The ``cmd`` field is invalid.
EPERM
The application sent a PAUSE or RESUME command when the decoder was
not running.
요약·해설
vidioc-decoder-cmd.rst:1-218VIDIOC_DECODER_CMD와 TRY 변형으로 디코더를 시작·정지·일시 정지·재개·flush하고 stateful drain 및 stateless 보류 프레임을 처리하는 규칙입니다.