18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 28c2ecf20Sopenharmony_ci.. c:namespace:: V4L 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci.. _VIDIOC_DECODER_CMD: 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci************************************************ 78c2ecf20Sopenharmony_ciioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD 88c2ecf20Sopenharmony_ci************************************************ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciName 118c2ecf20Sopenharmony_ci==== 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciVIDIOC_DECODER_CMD - VIDIOC_TRY_DECODER_CMD - Execute an decoder command 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ciSynopsis 168c2ecf20Sopenharmony_ci======== 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_DECODER_CMD 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_DECODER_CMD, struct v4l2_decoder_cmd *argp)`` 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_TRY_DECODER_CMD 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_TRY_DECODER_CMD, struct v4l2_decoder_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_decoder_cmd`. 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ciDescription 368c2ecf20Sopenharmony_ci=========== 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ciThese ioctls control an audio/video (usually MPEG-) decoder. 398c2ecf20Sopenharmony_ci``VIDIOC_DECODER_CMD`` sends a command to the decoder, 408c2ecf20Sopenharmony_ci``VIDIOC_TRY_DECODER_CMD`` can be used to try a command without actually 418c2ecf20Sopenharmony_ciexecuting it. To send a command applications must initialize all fields 428c2ecf20Sopenharmony_ciof a struct :c:type:`v4l2_decoder_cmd` and call 438c2ecf20Sopenharmony_ci``VIDIOC_DECODER_CMD`` or ``VIDIOC_TRY_DECODER_CMD`` with a pointer to 448c2ecf20Sopenharmony_cithis structure. 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ciThe ``cmd`` field must contain the command code. Some commands use the 478c2ecf20Sopenharmony_ci``flags`` field for additional information. 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ciA :c:func:`write()` or :ref:`VIDIOC_STREAMON` 508c2ecf20Sopenharmony_cicall sends an implicit START command to the decoder if it has not been 518c2ecf20Sopenharmony_cistarted yet. Applies to both queues of mem2mem decoders. 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ciA :c:func:`close()` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>` 548c2ecf20Sopenharmony_cicall of a streaming file descriptor sends an implicit immediate STOP 558c2ecf20Sopenharmony_cicommand to the decoder, and all buffered data is discarded. Applies to both 568c2ecf20Sopenharmony_ciqueues of mem2mem decoders. 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ciIn principle, these ioctls are optional, not all drivers may support them. They were 598c2ecf20Sopenharmony_ciintroduced in Linux 3.3. They are, however, mandatory for stateful mem2mem decoders 608c2ecf20Sopenharmony_ci(as further documented in :ref:`decoder`). 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{1.1cm}|p{2.4cm}|p{1.2cm}|p{1.6cm}|p{10.6cm}| 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci.. c:type:: v4l2_decoder_cmd 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci.. cssclass:: longtable 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci.. flat-table:: struct v4l2_decoder_cmd 698c2ecf20Sopenharmony_ci :header-rows: 0 708c2ecf20Sopenharmony_ci :stub-columns: 0 718c2ecf20Sopenharmony_ci :widths: 1 1 1 3 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci * - __u32 748c2ecf20Sopenharmony_ci - ``cmd`` 758c2ecf20Sopenharmony_ci - 768c2ecf20Sopenharmony_ci - The decoder command, see :ref:`decoder-cmds`. 778c2ecf20Sopenharmony_ci * - __u32 788c2ecf20Sopenharmony_ci - ``flags`` 798c2ecf20Sopenharmony_ci - 808c2ecf20Sopenharmony_ci - Flags to go with the command. If no flags are defined for this 818c2ecf20Sopenharmony_ci command, drivers and applications must set this field to zero. 828c2ecf20Sopenharmony_ci * - union { 838c2ecf20Sopenharmony_ci - (anonymous) 848c2ecf20Sopenharmony_ci * - struct 858c2ecf20Sopenharmony_ci - ``start`` 868c2ecf20Sopenharmony_ci - 878c2ecf20Sopenharmony_ci - Structure containing additional data for the 888c2ecf20Sopenharmony_ci ``V4L2_DEC_CMD_START`` command. 898c2ecf20Sopenharmony_ci * - 908c2ecf20Sopenharmony_ci - __s32 918c2ecf20Sopenharmony_ci - ``speed`` 928c2ecf20Sopenharmony_ci - Playback speed and direction. The playback speed is defined as 938c2ecf20Sopenharmony_ci ``speed``/1000 of the normal speed. So 1000 is normal playback. 948c2ecf20Sopenharmony_ci Negative numbers denote reverse playback, so -1000 does reverse 958c2ecf20Sopenharmony_ci playback at normal speed. Speeds -1, 0 and 1 have special 968c2ecf20Sopenharmony_ci meanings: speed 0 is shorthand for 1000 (normal playback). A speed 978c2ecf20Sopenharmony_ci of 1 steps just one frame forward, a speed of -1 steps just one 988c2ecf20Sopenharmony_ci frame back. 998c2ecf20Sopenharmony_ci * - 1008c2ecf20Sopenharmony_ci - __u32 1018c2ecf20Sopenharmony_ci - ``format`` 1028c2ecf20Sopenharmony_ci - Format restrictions. This field is set by the driver, not the 1038c2ecf20Sopenharmony_ci application. Possible values are ``V4L2_DEC_START_FMT_NONE`` if 1048c2ecf20Sopenharmony_ci there are no format restrictions or ``V4L2_DEC_START_FMT_GOP`` if 1058c2ecf20Sopenharmony_ci the decoder operates on full GOPs (*Group Of Pictures*). This is 1068c2ecf20Sopenharmony_ci usually the case for reverse playback: the decoder needs full 1078c2ecf20Sopenharmony_ci GOPs, which it can then play in reverse order. So to implement 1088c2ecf20Sopenharmony_ci reverse playback the application must feed the decoder the last 1098c2ecf20Sopenharmony_ci GOP in the video file, then the GOP before that, etc. etc. 1108c2ecf20Sopenharmony_ci * - struct 1118c2ecf20Sopenharmony_ci - ``stop`` 1128c2ecf20Sopenharmony_ci - 1138c2ecf20Sopenharmony_ci - Structure containing additional data for the ``V4L2_DEC_CMD_STOP`` 1148c2ecf20Sopenharmony_ci command. 1158c2ecf20Sopenharmony_ci * - 1168c2ecf20Sopenharmony_ci - __u64 1178c2ecf20Sopenharmony_ci - ``pts`` 1188c2ecf20Sopenharmony_ci - Stop playback at this ``pts`` or immediately if the playback is 1198c2ecf20Sopenharmony_ci already past that timestamp. Leave to 0 if you want to stop after 1208c2ecf20Sopenharmony_ci the last frame was decoded. 1218c2ecf20Sopenharmony_ci * - struct 1228c2ecf20Sopenharmony_ci - ``raw`` 1238c2ecf20Sopenharmony_ci * - 1248c2ecf20Sopenharmony_ci - __u32 1258c2ecf20Sopenharmony_ci - ``data``\ [16] 1268c2ecf20Sopenharmony_ci - Reserved for future extensions. Drivers and applications must set 1278c2ecf20Sopenharmony_ci the array to zero. 1288c2ecf20Sopenharmony_ci * - } 1298c2ecf20Sopenharmony_ci - 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{5.6cm}|p{0.6cm}|p{11.3cm}| 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci.. _decoder-cmds: 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci.. flat-table:: Decoder Commands 1378c2ecf20Sopenharmony_ci :header-rows: 0 1388c2ecf20Sopenharmony_ci :stub-columns: 0 1398c2ecf20Sopenharmony_ci :widths: 56 6 113 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci * - ``V4L2_DEC_CMD_START`` 1428c2ecf20Sopenharmony_ci - 0 1438c2ecf20Sopenharmony_ci - Start the decoder. When the decoder is already running or paused, 1448c2ecf20Sopenharmony_ci this command will just change the playback speed. That means that 1458c2ecf20Sopenharmony_ci calling ``V4L2_DEC_CMD_START`` when the decoder was paused will 1468c2ecf20Sopenharmony_ci *not* resume the decoder. You have to explicitly call 1478c2ecf20Sopenharmony_ci ``V4L2_DEC_CMD_RESUME`` for that. This command has one flag: 1488c2ecf20Sopenharmony_ci ``V4L2_DEC_CMD_START_MUTE_AUDIO``. If set, then audio will be 1498c2ecf20Sopenharmony_ci muted when playing back at a non-standard speed. 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci For a device implementing the :ref:`decoder`, once the drain sequence 1528c2ecf20Sopenharmony_ci is initiated with the ``V4L2_DEC_CMD_STOP`` command, it must be driven 1538c2ecf20Sopenharmony_ci to completion before this command can be invoked. Any attempt to 1548c2ecf20Sopenharmony_ci invoke the command while the drain sequence is in progress will trigger 1558c2ecf20Sopenharmony_ci an ``EBUSY`` error code. The command may be also used to restart the 1568c2ecf20Sopenharmony_ci decoder in case of an implicit stop initiated by the decoder itself, 1578c2ecf20Sopenharmony_ci without the ``V4L2_DEC_CMD_STOP`` being called explicitly. See 1588c2ecf20Sopenharmony_ci :ref:`decoder` for more details. 1598c2ecf20Sopenharmony_ci * - ``V4L2_DEC_CMD_STOP`` 1608c2ecf20Sopenharmony_ci - 1 1618c2ecf20Sopenharmony_ci - Stop the decoder. When the decoder is already stopped, this 1628c2ecf20Sopenharmony_ci command does nothing. This command has two flags: if 1638c2ecf20Sopenharmony_ci ``V4L2_DEC_CMD_STOP_TO_BLACK`` is set, then the decoder will set 1648c2ecf20Sopenharmony_ci the picture to black after it stopped decoding. Otherwise the last 1658c2ecf20Sopenharmony_ci image will repeat. If 1668c2ecf20Sopenharmony_ci ``V4L2_DEC_CMD_STOP_IMMEDIATELY`` is set, then the decoder stops 1678c2ecf20Sopenharmony_ci immediately (ignoring the ``pts`` value), otherwise it will keep 1688c2ecf20Sopenharmony_ci decoding until timestamp >= pts or until the last of the pending 1698c2ecf20Sopenharmony_ci data from its internal buffers was decoded. 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci For a device implementing the :ref:`decoder`, the command will initiate 1728c2ecf20Sopenharmony_ci the drain sequence as documented in :ref:`decoder`. No flags or other 1738c2ecf20Sopenharmony_ci arguments are accepted in this case. Any attempt to invoke the command 1748c2ecf20Sopenharmony_ci again before the sequence completes will trigger an ``EBUSY`` error 1758c2ecf20Sopenharmony_ci code. 1768c2ecf20Sopenharmony_ci * - ``V4L2_DEC_CMD_PAUSE`` 1778c2ecf20Sopenharmony_ci - 2 1788c2ecf20Sopenharmony_ci - Pause the decoder. When the decoder has not been started yet, the 1798c2ecf20Sopenharmony_ci driver will return an ``EPERM`` error code. When the decoder is 1808c2ecf20Sopenharmony_ci already paused, this command does nothing. This command has one 1818c2ecf20Sopenharmony_ci flag: if ``V4L2_DEC_CMD_PAUSE_TO_BLACK`` is set, then set the 1828c2ecf20Sopenharmony_ci decoder output to black when paused. 1838c2ecf20Sopenharmony_ci * - ``V4L2_DEC_CMD_RESUME`` 1848c2ecf20Sopenharmony_ci - 3 1858c2ecf20Sopenharmony_ci - Resume decoding after a PAUSE command. When the decoder has not 1868c2ecf20Sopenharmony_ci been started yet, the driver will return an ``EPERM`` error code. When 1878c2ecf20Sopenharmony_ci the decoder is already running, this command does nothing. No 1888c2ecf20Sopenharmony_ci flags are defined for this command. 1898c2ecf20Sopenharmony_ci * - ``V4L2_DEC_CMD_FLUSH`` 1908c2ecf20Sopenharmony_ci - 4 1918c2ecf20Sopenharmony_ci - Flush any held capture buffers. Only valid for stateless decoders. 1928c2ecf20Sopenharmony_ci This command is typically used when the application reached the 1938c2ecf20Sopenharmony_ci end of the stream and the last output buffer had the 1948c2ecf20Sopenharmony_ci ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` flag set. This would prevent 1958c2ecf20Sopenharmony_ci dequeueing the capture buffer containing the last decoded frame. 1968c2ecf20Sopenharmony_ci So this command can be used to explicitly flush that final decoded 1978c2ecf20Sopenharmony_ci frame. This command does nothing if there are no held capture buffers. 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ciReturn Value 2008c2ecf20Sopenharmony_ci============ 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set 2038c2ecf20Sopenharmony_ciappropriately. The generic error codes are described at the 2048c2ecf20Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter. 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ciEBUSY 2078c2ecf20Sopenharmony_ci A drain sequence of a device implementing the :ref:`decoder` is still in 2088c2ecf20Sopenharmony_ci progress. It is not allowed to issue another decoder command until it 2098c2ecf20Sopenharmony_ci completes. 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ciEINVAL 2128c2ecf20Sopenharmony_ci The ``cmd`` field is invalid. 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ciEPERM 2158c2ecf20Sopenharmony_ci The application sent a PAUSE or RESUME command when the decoder was 2168c2ecf20Sopenharmony_ci not running. 217