162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 262306a36Sopenharmony_ci.. c:namespace:: V4L 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci.. _VIDIOC_DECODER_CMD: 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci************************************************ 762306a36Sopenharmony_ciioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD 862306a36Sopenharmony_ci************************************************ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciName 1162306a36Sopenharmony_ci==== 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciVIDIOC_DECODER_CMD - VIDIOC_TRY_DECODER_CMD - Execute an decoder command 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciSynopsis 1662306a36Sopenharmony_ci======== 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci.. c:macro:: VIDIOC_DECODER_CMD 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_DECODER_CMD, struct v4l2_decoder_cmd *argp)`` 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci.. c:macro:: VIDIOC_TRY_DECODER_CMD 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_TRY_DECODER_CMD, struct v4l2_decoder_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_decoder_cmd`. 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ciDescription 3662306a36Sopenharmony_ci=========== 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciThese ioctls control an audio/video (usually MPEG-) decoder. 3962306a36Sopenharmony_ci``VIDIOC_DECODER_CMD`` sends a command to the decoder, 4062306a36Sopenharmony_ci``VIDIOC_TRY_DECODER_CMD`` can be used to try a command without actually 4162306a36Sopenharmony_ciexecuting it. To send a command applications must initialize all fields 4262306a36Sopenharmony_ciof a struct :c:type:`v4l2_decoder_cmd` and call 4362306a36Sopenharmony_ci``VIDIOC_DECODER_CMD`` or ``VIDIOC_TRY_DECODER_CMD`` with a pointer to 4462306a36Sopenharmony_cithis structure. 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ciThe ``cmd`` field must contain the command code. Some commands use the 4762306a36Sopenharmony_ci``flags`` field for additional information. 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ciA :c:func:`write()` or :ref:`VIDIOC_STREAMON` 5062306a36Sopenharmony_cicall sends an implicit START command to the decoder if it has not been 5162306a36Sopenharmony_cistarted yet. Applies to both queues of mem2mem decoders. 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ciA :c:func:`close()` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>` 5462306a36Sopenharmony_cicall of a streaming file descriptor sends an implicit immediate STOP 5562306a36Sopenharmony_cicommand to the decoder, and all buffered data is discarded. Applies to both 5662306a36Sopenharmony_ciqueues of mem2mem decoders. 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ciIn principle, these ioctls are optional, not all drivers may support them. They were 5962306a36Sopenharmony_ciintroduced in Linux 3.3. They are, however, mandatory for stateful mem2mem decoders 6062306a36Sopenharmony_ci(as further documented in :ref:`decoder`). 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci.. tabularcolumns:: |p{2.0cm}|p{1.1cm}|p{2.2cm}|p{11.8cm}| 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci.. c:type:: v4l2_decoder_cmd 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci.. cssclass:: longtable 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci.. flat-table:: struct v4l2_decoder_cmd 6962306a36Sopenharmony_ci :header-rows: 0 7062306a36Sopenharmony_ci :stub-columns: 0 7162306a36Sopenharmony_ci :widths: 1 1 1 3 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci * - __u32 7462306a36Sopenharmony_ci - ``cmd`` 7562306a36Sopenharmony_ci - 7662306a36Sopenharmony_ci - The decoder command, see :ref:`decoder-cmds`. 7762306a36Sopenharmony_ci * - __u32 7862306a36Sopenharmony_ci - ``flags`` 7962306a36Sopenharmony_ci - 8062306a36Sopenharmony_ci - Flags to go with the command. If no flags are defined for this 8162306a36Sopenharmony_ci command, drivers and applications must set this field to zero. 8262306a36Sopenharmony_ci * - union { 8362306a36Sopenharmony_ci - (anonymous) 8462306a36Sopenharmony_ci * - struct 8562306a36Sopenharmony_ci - ``start`` 8662306a36Sopenharmony_ci - 8762306a36Sopenharmony_ci - Structure containing additional data for the 8862306a36Sopenharmony_ci ``V4L2_DEC_CMD_START`` command. 8962306a36Sopenharmony_ci * - 9062306a36Sopenharmony_ci - __s32 9162306a36Sopenharmony_ci - ``speed`` 9262306a36Sopenharmony_ci - Playback speed and direction. The playback speed is defined as 9362306a36Sopenharmony_ci ``speed``/1000 of the normal speed. So 1000 is normal playback. 9462306a36Sopenharmony_ci Negative numbers denote reverse playback, so -1000 does reverse 9562306a36Sopenharmony_ci playback at normal speed. Speeds -1, 0 and 1 have special 9662306a36Sopenharmony_ci meanings: speed 0 is shorthand for 1000 (normal playback). A speed 9762306a36Sopenharmony_ci of 1 steps just one frame forward, a speed of -1 steps just one 9862306a36Sopenharmony_ci frame back. 9962306a36Sopenharmony_ci * - 10062306a36Sopenharmony_ci - __u32 10162306a36Sopenharmony_ci - ``format`` 10262306a36Sopenharmony_ci - Format restrictions. This field is set by the driver, not the 10362306a36Sopenharmony_ci application. Possible values are ``V4L2_DEC_START_FMT_NONE`` if 10462306a36Sopenharmony_ci there are no format restrictions or ``V4L2_DEC_START_FMT_GOP`` if 10562306a36Sopenharmony_ci the decoder operates on full GOPs (*Group Of Pictures*). This is 10662306a36Sopenharmony_ci usually the case for reverse playback: the decoder needs full 10762306a36Sopenharmony_ci GOPs, which it can then play in reverse order. So to implement 10862306a36Sopenharmony_ci reverse playback the application must feed the decoder the last 10962306a36Sopenharmony_ci GOP in the video file, then the GOP before that, etc. etc. 11062306a36Sopenharmony_ci * - struct 11162306a36Sopenharmony_ci - ``stop`` 11262306a36Sopenharmony_ci - 11362306a36Sopenharmony_ci - Structure containing additional data for the ``V4L2_DEC_CMD_STOP`` 11462306a36Sopenharmony_ci command. 11562306a36Sopenharmony_ci * - 11662306a36Sopenharmony_ci - __u64 11762306a36Sopenharmony_ci - ``pts`` 11862306a36Sopenharmony_ci - Stop playback at this ``pts`` or immediately if the playback is 11962306a36Sopenharmony_ci already past that timestamp. Leave to 0 if you want to stop after 12062306a36Sopenharmony_ci the last frame was decoded. 12162306a36Sopenharmony_ci * - struct 12262306a36Sopenharmony_ci - ``raw`` 12362306a36Sopenharmony_ci * - 12462306a36Sopenharmony_ci - __u32 12562306a36Sopenharmony_ci - ``data``\ [16] 12662306a36Sopenharmony_ci - Reserved for future extensions. Drivers and applications must set 12762306a36Sopenharmony_ci the array to zero. 12862306a36Sopenharmony_ci * - } 12962306a36Sopenharmony_ci - 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci.. tabularcolumns:: |p{5.6cm}|p{0.6cm}|p{11.1cm}| 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci.. cssclass:: longtable 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci.. _decoder-cmds: 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci.. flat-table:: Decoder Commands 13962306a36Sopenharmony_ci :header-rows: 0 14062306a36Sopenharmony_ci :stub-columns: 0 14162306a36Sopenharmony_ci :widths: 56 6 113 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci * - ``V4L2_DEC_CMD_START`` 14462306a36Sopenharmony_ci - 0 14562306a36Sopenharmony_ci - Start the decoder. When the decoder is already running or paused, 14662306a36Sopenharmony_ci this command will just change the playback speed. That means that 14762306a36Sopenharmony_ci calling ``V4L2_DEC_CMD_START`` when the decoder was paused will 14862306a36Sopenharmony_ci *not* resume the decoder. You have to explicitly call 14962306a36Sopenharmony_ci ``V4L2_DEC_CMD_RESUME`` for that. This command has one flag: 15062306a36Sopenharmony_ci ``V4L2_DEC_CMD_START_MUTE_AUDIO``. If set, then audio will be 15162306a36Sopenharmony_ci muted when playing back at a non-standard speed. 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci For a device implementing the :ref:`decoder`, once the drain sequence 15462306a36Sopenharmony_ci is initiated with the ``V4L2_DEC_CMD_STOP`` command, it must be driven 15562306a36Sopenharmony_ci to completion before this command can be invoked. Any attempt to 15662306a36Sopenharmony_ci invoke the command while the drain sequence is in progress will trigger 15762306a36Sopenharmony_ci an ``EBUSY`` error code. The command may be also used to restart the 15862306a36Sopenharmony_ci decoder in case of an implicit stop initiated by the decoder itself, 15962306a36Sopenharmony_ci without the ``V4L2_DEC_CMD_STOP`` being called explicitly. See 16062306a36Sopenharmony_ci :ref:`decoder` for more details. 16162306a36Sopenharmony_ci * - ``V4L2_DEC_CMD_STOP`` 16262306a36Sopenharmony_ci - 1 16362306a36Sopenharmony_ci - Stop the decoder. When the decoder is already stopped, this 16462306a36Sopenharmony_ci command does nothing. This command has two flags: if 16562306a36Sopenharmony_ci ``V4L2_DEC_CMD_STOP_TO_BLACK`` is set, then the decoder will set 16662306a36Sopenharmony_ci the picture to black after it stopped decoding. Otherwise the last 16762306a36Sopenharmony_ci image will repeat. If 16862306a36Sopenharmony_ci ``V4L2_DEC_CMD_STOP_IMMEDIATELY`` is set, then the decoder stops 16962306a36Sopenharmony_ci immediately (ignoring the ``pts`` value), otherwise it will keep 17062306a36Sopenharmony_ci decoding until timestamp >= pts or until the last of the pending 17162306a36Sopenharmony_ci data from its internal buffers was decoded. 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci For a device implementing the :ref:`decoder`, the command will initiate 17462306a36Sopenharmony_ci the drain sequence as documented in :ref:`decoder`. No flags or other 17562306a36Sopenharmony_ci arguments are accepted in this case. Any attempt to invoke the command 17662306a36Sopenharmony_ci again before the sequence completes will trigger an ``EBUSY`` error 17762306a36Sopenharmony_ci code. 17862306a36Sopenharmony_ci * - ``V4L2_DEC_CMD_PAUSE`` 17962306a36Sopenharmony_ci - 2 18062306a36Sopenharmony_ci - Pause the decoder. When the decoder has not been started yet, the 18162306a36Sopenharmony_ci driver will return an ``EPERM`` error code. When the decoder is 18262306a36Sopenharmony_ci already paused, this command does nothing. This command has one 18362306a36Sopenharmony_ci flag: if ``V4L2_DEC_CMD_PAUSE_TO_BLACK`` is set, then set the 18462306a36Sopenharmony_ci decoder output to black when paused. 18562306a36Sopenharmony_ci * - ``V4L2_DEC_CMD_RESUME`` 18662306a36Sopenharmony_ci - 3 18762306a36Sopenharmony_ci - Resume decoding after a PAUSE command. When the decoder has not 18862306a36Sopenharmony_ci been started yet, the driver will return an ``EPERM`` error code. When 18962306a36Sopenharmony_ci the decoder is already running, this command does nothing. No 19062306a36Sopenharmony_ci flags are defined for this command. 19162306a36Sopenharmony_ci * - ``V4L2_DEC_CMD_FLUSH`` 19262306a36Sopenharmony_ci - 4 19362306a36Sopenharmony_ci - Flush any held capture buffers. Only valid for stateless decoders. 19462306a36Sopenharmony_ci This command is typically used when the application reached the 19562306a36Sopenharmony_ci end of the stream and the last output buffer had the 19662306a36Sopenharmony_ci ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` flag set. This would prevent 19762306a36Sopenharmony_ci dequeueing the capture buffer containing the last decoded frame. 19862306a36Sopenharmony_ci So this command can be used to explicitly flush that final decoded 19962306a36Sopenharmony_ci frame. This command does nothing if there are no held capture buffers. 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ciReturn Value 20262306a36Sopenharmony_ci============ 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set 20562306a36Sopenharmony_ciappropriately. The generic error codes are described at the 20662306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter. 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ciEBUSY 20962306a36Sopenharmony_ci A drain sequence of a device implementing the :ref:`decoder` is still in 21062306a36Sopenharmony_ci progress. It is not allowed to issue another decoder command until it 21162306a36Sopenharmony_ci completes. 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_ciEINVAL 21462306a36Sopenharmony_ci The ``cmd`` field is invalid. 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_ciEPERM 21762306a36Sopenharmony_ci The application sent a PAUSE or RESUME command when the decoder was 21862306a36Sopenharmony_ci not running. 219