18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
28c2ecf20Sopenharmony_ci.. c:namespace:: V4L
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci.. _VIDIOC_ENCODER_CMD:
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci************************************************
78c2ecf20Sopenharmony_ciioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD
88c2ecf20Sopenharmony_ci************************************************
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciName
118c2ecf20Sopenharmony_ci====
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciVIDIOC_ENCODER_CMD - VIDIOC_TRY_ENCODER_CMD - Execute an encoder command
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciSynopsis
168c2ecf20Sopenharmony_ci========
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_ENCODER_CMD
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_ENCODER_CMD, struct v4l2_encoder_cmd *argp)``
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_TRY_ENCODER_CMD
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_TRY_ENCODER_CMD, struct v4l2_encoder_cmd *argp)``
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciArguments
278c2ecf20Sopenharmony_ci=========
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci``fd``
308c2ecf20Sopenharmony_ci    File descriptor returned by :c:func:`open()`.
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci``argp``
338c2ecf20Sopenharmony_ci    Pointer to struct :c:type:`v4l2_encoder_cmd`.
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciDescription
368c2ecf20Sopenharmony_ci===========
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ciThese ioctls control an audio/video (usually MPEG-) encoder.
398c2ecf20Sopenharmony_ci``VIDIOC_ENCODER_CMD`` sends a command to the encoder,
408c2ecf20Sopenharmony_ci``VIDIOC_TRY_ENCODER_CMD`` can be used to try a command without actually
418c2ecf20Sopenharmony_ciexecuting it.
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciTo send a command applications must initialize all fields of a struct
448c2ecf20Sopenharmony_ci:c:type:`v4l2_encoder_cmd` and call
458c2ecf20Sopenharmony_ci``VIDIOC_ENCODER_CMD`` or ``VIDIOC_TRY_ENCODER_CMD`` with a pointer to
468c2ecf20Sopenharmony_cithis structure.
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciThe ``cmd`` field must contain the command code. Some commands use the
498c2ecf20Sopenharmony_ci``flags`` field for additional information.
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ciAfter a STOP command, :c:func:`read()` calls will read
528c2ecf20Sopenharmony_cithe remaining data buffered by the driver. When the buffer is empty,
538c2ecf20Sopenharmony_ci:c:func:`read()` will return zero and the next :c:func:`read()`
548c2ecf20Sopenharmony_cicall will restart the encoder.
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ciA :c:func:`read()` or :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>`
578c2ecf20Sopenharmony_cicall sends an implicit START command to the encoder if it has not been
588c2ecf20Sopenharmony_cistarted yet. Applies to both queues of mem2mem encoders.
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ciA :c:func:`close()` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
618c2ecf20Sopenharmony_cicall of a streaming file descriptor sends an implicit immediate STOP to
628c2ecf20Sopenharmony_cithe encoder, and all buffered data is discarded. Applies to both queues of
638c2ecf20Sopenharmony_cimem2mem encoders.
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciThese ioctls are optional, not all drivers may support them. They were
668c2ecf20Sopenharmony_ciintroduced in Linux 2.6.21. They are, however, mandatory for stateful mem2mem
678c2ecf20Sopenharmony_ciencoders (as further documented in :ref:`encoder`).
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci.. c:type:: v4l2_encoder_cmd
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci.. flat-table:: struct v4l2_encoder_cmd
748c2ecf20Sopenharmony_ci    :header-rows:  0
758c2ecf20Sopenharmony_ci    :stub-columns: 0
768c2ecf20Sopenharmony_ci    :widths:       1 1 2
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci    * - __u32
798c2ecf20Sopenharmony_ci      - ``cmd``
808c2ecf20Sopenharmony_ci      - The encoder command, see :ref:`encoder-cmds`.
818c2ecf20Sopenharmony_ci    * - __u32
828c2ecf20Sopenharmony_ci      - ``flags``
838c2ecf20Sopenharmony_ci      - Flags to go with the command, see :ref:`encoder-flags`. If no
848c2ecf20Sopenharmony_ci	flags are defined for this command, drivers and applications must
858c2ecf20Sopenharmony_ci	set this field to zero.
868c2ecf20Sopenharmony_ci    * - __u32
878c2ecf20Sopenharmony_ci      - ``data``\ [8]
888c2ecf20Sopenharmony_ci      - Reserved for future extensions. Drivers and applications must set
898c2ecf20Sopenharmony_ci	the array to zero.
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci.. _encoder-cmds:
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci.. flat-table:: Encoder Commands
978c2ecf20Sopenharmony_ci    :header-rows:  0
988c2ecf20Sopenharmony_ci    :stub-columns: 0
998c2ecf20Sopenharmony_ci    :widths:       3 1 4
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci    * - ``V4L2_ENC_CMD_START``
1028c2ecf20Sopenharmony_ci      - 0
1038c2ecf20Sopenharmony_ci      - Start the encoder. When the encoder is already running or paused,
1048c2ecf20Sopenharmony_ci	this command does nothing. No flags are defined for this command.
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	For a device implementing the :ref:`encoder`, once the drain sequence
1078c2ecf20Sopenharmony_ci	is initiated with the ``V4L2_ENC_CMD_STOP`` command, it must be driven
1088c2ecf20Sopenharmony_ci	to completion before this command can be invoked.  Any attempt to
1098c2ecf20Sopenharmony_ci	invoke the command while the drain sequence is in progress will trigger
1108c2ecf20Sopenharmony_ci	an ``EBUSY`` error code. See :ref:`encoder` for more details.
1118c2ecf20Sopenharmony_ci    * - ``V4L2_ENC_CMD_STOP``
1128c2ecf20Sopenharmony_ci      - 1
1138c2ecf20Sopenharmony_ci      - Stop the encoder. When the ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag
1148c2ecf20Sopenharmony_ci	is set, encoding will continue until the end of the current *Group
1158c2ecf20Sopenharmony_ci	Of Pictures*, otherwise encoding will stop immediately. When the
1168c2ecf20Sopenharmony_ci	encoder is already stopped, this command does nothing.
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	For a device implementing the :ref:`encoder`, the command will initiate
1198c2ecf20Sopenharmony_ci	the drain sequence as documented in :ref:`encoder`. No flags or other
1208c2ecf20Sopenharmony_ci	arguments are accepted in this case. Any attempt to invoke the command
1218c2ecf20Sopenharmony_ci	again before the sequence completes will trigger an ``EBUSY`` error
1228c2ecf20Sopenharmony_ci	code.
1238c2ecf20Sopenharmony_ci    * - ``V4L2_ENC_CMD_PAUSE``
1248c2ecf20Sopenharmony_ci      - 2
1258c2ecf20Sopenharmony_ci      - Pause the encoder. When the encoder has not been started yet, the
1268c2ecf20Sopenharmony_ci	driver will return an ``EPERM`` error code. When the encoder is
1278c2ecf20Sopenharmony_ci	already paused, this command does nothing. No flags are defined
1288c2ecf20Sopenharmony_ci	for this command.
1298c2ecf20Sopenharmony_ci    * - ``V4L2_ENC_CMD_RESUME``
1308c2ecf20Sopenharmony_ci      - 3
1318c2ecf20Sopenharmony_ci      - Resume encoding after a PAUSE command. When the encoder has not
1328c2ecf20Sopenharmony_ci	been started yet, the driver will return an ``EPERM`` error code. When
1338c2ecf20Sopenharmony_ci	the encoder is already running, this command does nothing. No
1348c2ecf20Sopenharmony_ci	flags are defined for this command.
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci.. _encoder-flags:
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci.. flat-table:: Encoder Command Flags
1418c2ecf20Sopenharmony_ci    :header-rows:  0
1428c2ecf20Sopenharmony_ci    :stub-columns: 0
1438c2ecf20Sopenharmony_ci    :widths:       3 1 4
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci    * - ``V4L2_ENC_CMD_STOP_AT_GOP_END``
1468c2ecf20Sopenharmony_ci      - 0x0001
1478c2ecf20Sopenharmony_ci      - Stop encoding at the end of the current *Group Of Pictures*,
1488c2ecf20Sopenharmony_ci	rather than immediately.
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci        Does not apply to :ref:`encoder`.
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ciReturn Value
1538c2ecf20Sopenharmony_ci============
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set
1568c2ecf20Sopenharmony_ciappropriately. The generic error codes are described at the
1578c2ecf20Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ciEBUSY
1608c2ecf20Sopenharmony_ci    A drain sequence of a device implementing the :ref:`encoder` is still in
1618c2ecf20Sopenharmony_ci    progress. It is not allowed to issue another encoder command until it
1628c2ecf20Sopenharmony_ci    completes.
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ciEINVAL
1658c2ecf20Sopenharmony_ci    The ``cmd`` field is invalid.
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ciEPERM
1688c2ecf20Sopenharmony_ci    The application sent a PAUSE or RESUME command when the encoder was
1698c2ecf20Sopenharmony_ci    not running.
170