162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
262306a36Sopenharmony_ci.. c:namespace:: V4L
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci.. _VIDIOC_ENCODER_CMD:
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci************************************************
762306a36Sopenharmony_ciioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD
862306a36Sopenharmony_ci************************************************
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciName
1162306a36Sopenharmony_ci====
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ciVIDIOC_ENCODER_CMD - VIDIOC_TRY_ENCODER_CMD - Execute an encoder command
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ciSynopsis
1662306a36Sopenharmony_ci========
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci.. c:macro:: VIDIOC_ENCODER_CMD
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_ENCODER_CMD, struct v4l2_encoder_cmd *argp)``
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci.. c:macro:: VIDIOC_TRY_ENCODER_CMD
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_TRY_ENCODER_CMD, struct v4l2_encoder_cmd *argp)``
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciArguments
2762306a36Sopenharmony_ci=========
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci``fd``
3062306a36Sopenharmony_ci    File descriptor returned by :c:func:`open()`.
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci``argp``
3362306a36Sopenharmony_ci    Pointer to struct :c:type:`v4l2_encoder_cmd`.
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ciDescription
3662306a36Sopenharmony_ci===========
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ciThese ioctls control an audio/video (usually MPEG-) encoder.
3962306a36Sopenharmony_ci``VIDIOC_ENCODER_CMD`` sends a command to the encoder,
4062306a36Sopenharmony_ci``VIDIOC_TRY_ENCODER_CMD`` can be used to try a command without actually
4162306a36Sopenharmony_ciexecuting it.
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ciTo send a command applications must initialize all fields of a struct
4462306a36Sopenharmony_ci:c:type:`v4l2_encoder_cmd` and call
4562306a36Sopenharmony_ci``VIDIOC_ENCODER_CMD`` or ``VIDIOC_TRY_ENCODER_CMD`` with a pointer to
4662306a36Sopenharmony_cithis structure.
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ciThe ``cmd`` field must contain the command code. Some commands use the
4962306a36Sopenharmony_ci``flags`` field for additional information.
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ciAfter a STOP command, :c:func:`read()` calls will read
5262306a36Sopenharmony_cithe remaining data buffered by the driver. When the buffer is empty,
5362306a36Sopenharmony_ci:c:func:`read()` will return zero and the next :c:func:`read()`
5462306a36Sopenharmony_cicall will restart the encoder.
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ciA :c:func:`read()` or :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>`
5762306a36Sopenharmony_cicall sends an implicit START command to the encoder if it has not been
5862306a36Sopenharmony_cistarted yet. Applies to both queues of mem2mem encoders.
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ciA :c:func:`close()` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
6162306a36Sopenharmony_cicall of a streaming file descriptor sends an implicit immediate STOP to
6262306a36Sopenharmony_cithe encoder, and all buffered data is discarded. Applies to both queues of
6362306a36Sopenharmony_cimem2mem encoders.
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ciThese ioctls are optional, not all drivers may support them. They were
6662306a36Sopenharmony_ciintroduced in Linux 2.6.21. They are, however, mandatory for stateful mem2mem
6762306a36Sopenharmony_ciencoders (as further documented in :ref:`encoder`).
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci.. c:type:: v4l2_encoder_cmd
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci.. flat-table:: struct v4l2_encoder_cmd
7462306a36Sopenharmony_ci    :header-rows:  0
7562306a36Sopenharmony_ci    :stub-columns: 0
7662306a36Sopenharmony_ci    :widths:       1 1 2
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci    * - __u32
7962306a36Sopenharmony_ci      - ``cmd``
8062306a36Sopenharmony_ci      - The encoder command, see :ref:`encoder-cmds`.
8162306a36Sopenharmony_ci    * - __u32
8262306a36Sopenharmony_ci      - ``flags``
8362306a36Sopenharmony_ci      - Flags to go with the command, see :ref:`encoder-flags`. If no
8462306a36Sopenharmony_ci	flags are defined for this command, drivers and applications must
8562306a36Sopenharmony_ci	set this field to zero.
8662306a36Sopenharmony_ci    * - __u32
8762306a36Sopenharmony_ci      - ``data``\ [8]
8862306a36Sopenharmony_ci      - Reserved for future extensions. Drivers and applications must set
8962306a36Sopenharmony_ci	the array to zero.
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci.. _encoder-cmds:
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci.. flat-table:: Encoder Commands
9762306a36Sopenharmony_ci    :header-rows:  0
9862306a36Sopenharmony_ci    :stub-columns: 0
9962306a36Sopenharmony_ci    :widths:       3 1 4
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci    * - ``V4L2_ENC_CMD_START``
10262306a36Sopenharmony_ci      - 0
10362306a36Sopenharmony_ci      - Start the encoder. When the encoder is already running or paused,
10462306a36Sopenharmony_ci	this command does nothing. No flags are defined for this command.
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci	For a device implementing the :ref:`encoder`, once the drain sequence
10762306a36Sopenharmony_ci	is initiated with the ``V4L2_ENC_CMD_STOP`` command, it must be driven
10862306a36Sopenharmony_ci	to completion before this command can be invoked.  Any attempt to
10962306a36Sopenharmony_ci	invoke the command while the drain sequence is in progress will trigger
11062306a36Sopenharmony_ci	an ``EBUSY`` error code. See :ref:`encoder` for more details.
11162306a36Sopenharmony_ci    * - ``V4L2_ENC_CMD_STOP``
11262306a36Sopenharmony_ci      - 1
11362306a36Sopenharmony_ci      - Stop the encoder. When the ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag
11462306a36Sopenharmony_ci	is set, encoding will continue until the end of the current *Group
11562306a36Sopenharmony_ci	Of Pictures*, otherwise encoding will stop immediately. When the
11662306a36Sopenharmony_ci	encoder is already stopped, this command does nothing.
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci	For a device implementing the :ref:`encoder`, the command will initiate
11962306a36Sopenharmony_ci	the drain sequence as documented in :ref:`encoder`. No flags or other
12062306a36Sopenharmony_ci	arguments are accepted in this case. Any attempt to invoke the command
12162306a36Sopenharmony_ci	again before the sequence completes will trigger an ``EBUSY`` error
12262306a36Sopenharmony_ci	code.
12362306a36Sopenharmony_ci    * - ``V4L2_ENC_CMD_PAUSE``
12462306a36Sopenharmony_ci      - 2
12562306a36Sopenharmony_ci      - Pause the encoder. When the encoder has not been started yet, the
12662306a36Sopenharmony_ci	driver will return an ``EPERM`` error code. When the encoder is
12762306a36Sopenharmony_ci	already paused, this command does nothing. No flags are defined
12862306a36Sopenharmony_ci	for this command.
12962306a36Sopenharmony_ci    * - ``V4L2_ENC_CMD_RESUME``
13062306a36Sopenharmony_ci      - 3
13162306a36Sopenharmony_ci      - Resume encoding after a PAUSE command. When the encoder has not
13262306a36Sopenharmony_ci	been started yet, the driver will return an ``EPERM`` error code. When
13362306a36Sopenharmony_ci	the encoder is already running, this command does nothing. No
13462306a36Sopenharmony_ci	flags are defined for this command.
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci.. _encoder-flags:
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci.. flat-table:: Encoder Command Flags
14162306a36Sopenharmony_ci    :header-rows:  0
14262306a36Sopenharmony_ci    :stub-columns: 0
14362306a36Sopenharmony_ci    :widths:       3 1 4
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci    * - ``V4L2_ENC_CMD_STOP_AT_GOP_END``
14662306a36Sopenharmony_ci      - 0x0001
14762306a36Sopenharmony_ci      - Stop encoding at the end of the current *Group Of Pictures*,
14862306a36Sopenharmony_ci	rather than immediately.
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci        Does not apply to :ref:`encoder`.
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ciReturn Value
15362306a36Sopenharmony_ci============
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set
15662306a36Sopenharmony_ciappropriately. The generic error codes are described at the
15762306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ciEBUSY
16062306a36Sopenharmony_ci    A drain sequence of a device implementing the :ref:`encoder` is still in
16162306a36Sopenharmony_ci    progress. It is not allowed to issue another encoder command until it
16262306a36Sopenharmony_ci    completes.
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ciEINVAL
16562306a36Sopenharmony_ci    The ``cmd`` field is invalid.
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ciEPERM
16862306a36Sopenharmony_ci    The application sent a PAUSE or RESUME command when the encoder was
16962306a36Sopenharmony_ci    not running.
170