1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2407e84cdSMauro Carvalho Chehab.. c:namespace:: V4L 354f38fcaSMauro Carvalho Chehab 454f38fcaSMauro Carvalho Chehab.. _VIDIOC_ENCODER_CMD: 554f38fcaSMauro Carvalho Chehab 654f38fcaSMauro Carvalho Chehab************************************************ 754f38fcaSMauro Carvalho Chehabioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD 854f38fcaSMauro Carvalho Chehab************************************************ 954f38fcaSMauro Carvalho Chehab 1054f38fcaSMauro Carvalho ChehabName 1154f38fcaSMauro Carvalho Chehab==== 1254f38fcaSMauro Carvalho Chehab 1354f38fcaSMauro Carvalho ChehabVIDIOC_ENCODER_CMD - VIDIOC_TRY_ENCODER_CMD - Execute an encoder command 1454f38fcaSMauro Carvalho Chehab 1554f38fcaSMauro Carvalho ChehabSynopsis 1654f38fcaSMauro Carvalho Chehab======== 1754f38fcaSMauro Carvalho Chehab 18407e84cdSMauro Carvalho Chehab.. c:macro:: VIDIOC_ENCODER_CMD 1954f38fcaSMauro Carvalho Chehab 20407e84cdSMauro Carvalho Chehab``int ioctl(int fd, VIDIOC_ENCODER_CMD, struct v4l2_encoder_cmd *argp)`` 2154f38fcaSMauro Carvalho Chehab 22407e84cdSMauro Carvalho Chehab.. c:macro:: VIDIOC_TRY_ENCODER_CMD 23407e84cdSMauro Carvalho Chehab 24407e84cdSMauro Carvalho Chehab``int ioctl(int fd, VIDIOC_TRY_ENCODER_CMD, struct v4l2_encoder_cmd *argp)`` 2554f38fcaSMauro Carvalho Chehab 2654f38fcaSMauro Carvalho ChehabArguments 2754f38fcaSMauro Carvalho Chehab========= 2854f38fcaSMauro Carvalho Chehab 2954f38fcaSMauro Carvalho Chehab``fd`` 30407e84cdSMauro Carvalho Chehab File descriptor returned by :c:func:`open()`. 3154f38fcaSMauro Carvalho Chehab 3254f38fcaSMauro Carvalho Chehab``argp`` 3354f38fcaSMauro Carvalho Chehab Pointer to struct :c:type:`v4l2_encoder_cmd`. 3454f38fcaSMauro Carvalho Chehab 3554f38fcaSMauro Carvalho ChehabDescription 3654f38fcaSMauro Carvalho Chehab=========== 3754f38fcaSMauro Carvalho Chehab 3854f38fcaSMauro Carvalho ChehabThese ioctls control an audio/video (usually MPEG-) encoder. 3954f38fcaSMauro Carvalho Chehab``VIDIOC_ENCODER_CMD`` sends a command to the encoder, 4054f38fcaSMauro Carvalho Chehab``VIDIOC_TRY_ENCODER_CMD`` can be used to try a command without actually 4154f38fcaSMauro Carvalho Chehabexecuting it. 4254f38fcaSMauro Carvalho Chehab 4354f38fcaSMauro Carvalho ChehabTo send a command applications must initialize all fields of a struct 4454f38fcaSMauro Carvalho Chehab:c:type:`v4l2_encoder_cmd` and call 4554f38fcaSMauro Carvalho Chehab``VIDIOC_ENCODER_CMD`` or ``VIDIOC_TRY_ENCODER_CMD`` with a pointer to 4654f38fcaSMauro Carvalho Chehabthis structure. 4754f38fcaSMauro Carvalho Chehab 489ec656cfSTomasz FigaThe ``cmd`` field must contain the command code. Some commands use the 499ec656cfSTomasz Figa``flags`` field for additional information. 5054f38fcaSMauro Carvalho Chehab 51407e84cdSMauro Carvalho ChehabAfter a STOP command, :c:func:`read()` calls will read 5254f38fcaSMauro Carvalho Chehabthe remaining data buffered by the driver. When the buffer is empty, 53407e84cdSMauro Carvalho Chehab:c:func:`read()` will return zero and the next :c:func:`read()` 5454f38fcaSMauro Carvalho Chehabcall will restart the encoder. 5554f38fcaSMauro Carvalho Chehab 56407e84cdSMauro Carvalho ChehabA :c:func:`read()` or :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` 579ec656cfSTomasz Figacall sends an implicit START command to the encoder if it has not been 589ec656cfSTomasz Figastarted yet. Applies to both queues of mem2mem encoders. 599ec656cfSTomasz Figa 60407e84cdSMauro Carvalho ChehabA :c:func:`close()` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>` 6154f38fcaSMauro Carvalho Chehabcall of a streaming file descriptor sends an implicit immediate STOP to 629ec656cfSTomasz Figathe encoder, and all buffered data is discarded. Applies to both queues of 639ec656cfSTomasz Figamem2mem encoders. 6454f38fcaSMauro Carvalho Chehab 6554f38fcaSMauro Carvalho ChehabThese ioctls are optional, not all drivers may support them. They were 669ec656cfSTomasz Figaintroduced in Linux 2.6.21. They are, however, mandatory for stateful mem2mem 679ec656cfSTomasz Figaencoders (as further documented in :ref:`encoder`). 6854f38fcaSMauro Carvalho Chehab 69*fea13a69SMauro Carvalho Chehab.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}| 7054f38fcaSMauro Carvalho Chehab 7154f38fcaSMauro Carvalho Chehab.. c:type:: v4l2_encoder_cmd 7254f38fcaSMauro Carvalho Chehab 7354f38fcaSMauro Carvalho Chehab.. flat-table:: struct v4l2_encoder_cmd 7454f38fcaSMauro Carvalho Chehab :header-rows: 0 7554f38fcaSMauro Carvalho Chehab :stub-columns: 0 7654f38fcaSMauro Carvalho Chehab :widths: 1 1 2 7754f38fcaSMauro Carvalho Chehab 7854f38fcaSMauro Carvalho Chehab * - __u32 7954f38fcaSMauro Carvalho Chehab - ``cmd`` 8054f38fcaSMauro Carvalho Chehab - The encoder command, see :ref:`encoder-cmds`. 8154f38fcaSMauro Carvalho Chehab * - __u32 8254f38fcaSMauro Carvalho Chehab - ``flags`` 8354f38fcaSMauro Carvalho Chehab - Flags to go with the command, see :ref:`encoder-flags`. If no 8454f38fcaSMauro Carvalho Chehab flags are defined for this command, drivers and applications must 8554f38fcaSMauro Carvalho Chehab set this field to zero. 8654f38fcaSMauro Carvalho Chehab * - __u32 8754f38fcaSMauro Carvalho Chehab - ``data``\ [8] 8854f38fcaSMauro Carvalho Chehab - Reserved for future extensions. Drivers and applications must set 8954f38fcaSMauro Carvalho Chehab the array to zero. 9054f38fcaSMauro Carvalho Chehab 9154f38fcaSMauro Carvalho Chehab 92*fea13a69SMauro Carvalho Chehab.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}| 9354f38fcaSMauro Carvalho Chehab 9454f38fcaSMauro Carvalho Chehab.. _encoder-cmds: 9554f38fcaSMauro Carvalho Chehab 9654f38fcaSMauro Carvalho Chehab.. flat-table:: Encoder Commands 9754f38fcaSMauro Carvalho Chehab :header-rows: 0 9854f38fcaSMauro Carvalho Chehab :stub-columns: 0 9954f38fcaSMauro Carvalho Chehab :widths: 3 1 4 10054f38fcaSMauro Carvalho Chehab 10154f38fcaSMauro Carvalho Chehab * - ``V4L2_ENC_CMD_START`` 10254f38fcaSMauro Carvalho Chehab - 0 10354f38fcaSMauro Carvalho Chehab - Start the encoder. When the encoder is already running or paused, 10454f38fcaSMauro Carvalho Chehab this command does nothing. No flags are defined for this command. 1059ec656cfSTomasz Figa 1069ec656cfSTomasz Figa For a device implementing the :ref:`encoder`, once the drain sequence 1079ec656cfSTomasz Figa is initiated with the ``V4L2_ENC_CMD_STOP`` command, it must be driven 1089ec656cfSTomasz Figa to completion before this command can be invoked. Any attempt to 1099ec656cfSTomasz Figa invoke the command while the drain sequence is in progress will trigger 1109ec656cfSTomasz Figa an ``EBUSY`` error code. See :ref:`encoder` for more details. 11154f38fcaSMauro Carvalho Chehab * - ``V4L2_ENC_CMD_STOP`` 11254f38fcaSMauro Carvalho Chehab - 1 11354f38fcaSMauro Carvalho Chehab - Stop the encoder. When the ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag 11454f38fcaSMauro Carvalho Chehab is set, encoding will continue until the end of the current *Group 11554f38fcaSMauro Carvalho Chehab Of Pictures*, otherwise encoding will stop immediately. When the 1169ec656cfSTomasz Figa encoder is already stopped, this command does nothing. 1179ec656cfSTomasz Figa 1189ec656cfSTomasz Figa For a device implementing the :ref:`encoder`, the command will initiate 1199ec656cfSTomasz Figa the drain sequence as documented in :ref:`encoder`. No flags or other 1209ec656cfSTomasz Figa arguments are accepted in this case. Any attempt to invoke the command 1219ec656cfSTomasz Figa again before the sequence completes will trigger an ``EBUSY`` error 1229ec656cfSTomasz Figa code. 12354f38fcaSMauro Carvalho Chehab * - ``V4L2_ENC_CMD_PAUSE`` 12454f38fcaSMauro Carvalho Chehab - 2 12554f38fcaSMauro Carvalho Chehab - Pause the encoder. When the encoder has not been started yet, the 12654f38fcaSMauro Carvalho Chehab driver will return an ``EPERM`` error code. When the encoder is 12754f38fcaSMauro Carvalho Chehab already paused, this command does nothing. No flags are defined 12854f38fcaSMauro Carvalho Chehab for this command. 12954f38fcaSMauro Carvalho Chehab * - ``V4L2_ENC_CMD_RESUME`` 13054f38fcaSMauro Carvalho Chehab - 3 13154f38fcaSMauro Carvalho Chehab - Resume encoding after a PAUSE command. When the encoder has not 13254f38fcaSMauro Carvalho Chehab been started yet, the driver will return an ``EPERM`` error code. When 13354f38fcaSMauro Carvalho Chehab the encoder is already running, this command does nothing. No 13454f38fcaSMauro Carvalho Chehab flags are defined for this command. 13554f38fcaSMauro Carvalho Chehab 136*fea13a69SMauro Carvalho Chehab.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}| 13754f38fcaSMauro Carvalho Chehab 13854f38fcaSMauro Carvalho Chehab.. _encoder-flags: 13954f38fcaSMauro Carvalho Chehab 14054f38fcaSMauro Carvalho Chehab.. flat-table:: Encoder Command Flags 14154f38fcaSMauro Carvalho Chehab :header-rows: 0 14254f38fcaSMauro Carvalho Chehab :stub-columns: 0 14354f38fcaSMauro Carvalho Chehab :widths: 3 1 4 14454f38fcaSMauro Carvalho Chehab 14554f38fcaSMauro Carvalho Chehab * - ``V4L2_ENC_CMD_STOP_AT_GOP_END`` 14654f38fcaSMauro Carvalho Chehab - 0x0001 14754f38fcaSMauro Carvalho Chehab - Stop encoding at the end of the current *Group Of Pictures*, 14854f38fcaSMauro Carvalho Chehab rather than immediately. 14954f38fcaSMauro Carvalho Chehab 1509ec656cfSTomasz Figa Does not apply to :ref:`encoder`. 1519ec656cfSTomasz Figa 15254f38fcaSMauro Carvalho ChehabReturn Value 15354f38fcaSMauro Carvalho Chehab============ 15454f38fcaSMauro Carvalho Chehab 15554f38fcaSMauro Carvalho ChehabOn success 0 is returned, on error -1 and the ``errno`` variable is set 15654f38fcaSMauro Carvalho Chehabappropriately. The generic error codes are described at the 15754f38fcaSMauro Carvalho Chehab:ref:`Generic Error Codes <gen-errors>` chapter. 15854f38fcaSMauro Carvalho Chehab 1599ec656cfSTomasz FigaEBUSY 1609ec656cfSTomasz Figa A drain sequence of a device implementing the :ref:`encoder` is still in 1619ec656cfSTomasz Figa progress. It is not allowed to issue another encoder command until it 1629ec656cfSTomasz Figa completes. 1639ec656cfSTomasz Figa 16454f38fcaSMauro Carvalho ChehabEINVAL 16554f38fcaSMauro Carvalho Chehab The ``cmd`` field is invalid. 16654f38fcaSMauro Carvalho Chehab 16754f38fcaSMauro Carvalho ChehabEPERM 16854f38fcaSMauro Carvalho Chehab The application sent a PAUSE or RESUME command when the encoder was 16954f38fcaSMauro Carvalho Chehab not running. 170