1.. Permission is granted to copy, distribute and/or modify this 2.. document under the terms of the GNU Free Documentation License, 3.. Version 1.1 or any later version published by the Free Software 4.. Foundation, with no Invariant Sections, no Front-Cover Texts 5.. and no Back-Cover Texts. A copy of the license is included at 6.. Documentation/userspace-api/media/fdl-appendix.rst. 7.. 8.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections 9 10.. _VIDIOC_DECODER_CMD: 11 12************************************************ 13ioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD 14************************************************ 15 16Name 17==== 18 19VIDIOC_DECODER_CMD - VIDIOC_TRY_DECODER_CMD - Execute an decoder command 20 21 22Synopsis 23======== 24 25.. c:function:: int ioctl( int fd, VIDIOC_DECODER_CMD, struct v4l2_decoder_cmd *argp ) 26 :name: VIDIOC_DECODER_CMD 27 28 29.. c:function:: int ioctl( int fd, VIDIOC_TRY_DECODER_CMD, struct v4l2_decoder_cmd *argp ) 30 :name: VIDIOC_TRY_DECODER_CMD 31 32 33Arguments 34========= 35 36``fd`` 37 File descriptor returned by :ref:`open() <func-open>`. 38 39``argp`` 40 pointer to struct :c:type:`v4l2_decoder_cmd`. 41 42 43Description 44=========== 45 46These ioctls control an audio/video (usually MPEG-) decoder. 47``VIDIOC_DECODER_CMD`` sends a command to the decoder, 48``VIDIOC_TRY_DECODER_CMD`` can be used to try a command without actually 49executing it. To send a command applications must initialize all fields 50of a struct :c:type:`v4l2_decoder_cmd` and call 51``VIDIOC_DECODER_CMD`` or ``VIDIOC_TRY_DECODER_CMD`` with a pointer to 52this structure. 53 54The ``cmd`` field must contain the command code. Some commands use the 55``flags`` field for additional information. 56 57A :ref:`write() <func-write>` or :ref:`VIDIOC_STREAMON` 58call sends an implicit START command to the decoder if it has not been 59started yet. Applies to both queues of mem2mem decoders. 60 61A :ref:`close() <func-close>` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>` 62call of a streaming file descriptor sends an implicit immediate STOP 63command to the decoder, and all buffered data is discarded. Applies to both 64queues of mem2mem decoders. 65 66In principle, these ioctls are optional, not all drivers may support them. They were 67introduced in Linux 3.3. They are, however, mandatory for stateful mem2mem decoders 68(as further documented in :ref:`decoder`). 69 70 71.. tabularcolumns:: |p{1.1cm}|p{2.4cm}|p{1.2cm}|p{1.6cm}|p{10.6cm}| 72 73.. c:type:: v4l2_decoder_cmd 74 75.. cssclass:: longtable 76 77.. flat-table:: struct v4l2_decoder_cmd 78 :header-rows: 0 79 :stub-columns: 0 80 :widths: 1 1 1 3 81 82 * - __u32 83 - ``cmd`` 84 - 85 - The decoder command, see :ref:`decoder-cmds`. 86 * - __u32 87 - ``flags`` 88 - 89 - Flags to go with the command. If no flags are defined for this 90 command, drivers and applications must set this field to zero. 91 * - union { 92 - (anonymous) 93 * - struct 94 - ``start`` 95 - 96 - Structure containing additional data for the 97 ``V4L2_DEC_CMD_START`` command. 98 * - 99 - __s32 100 - ``speed`` 101 - Playback speed and direction. The playback speed is defined as 102 ``speed``/1000 of the normal speed. So 1000 is normal playback. 103 Negative numbers denote reverse playback, so -1000 does reverse 104 playback at normal speed. Speeds -1, 0 and 1 have special 105 meanings: speed 0 is shorthand for 1000 (normal playback). A speed 106 of 1 steps just one frame forward, a speed of -1 steps just one 107 frame back. 108 * - 109 - __u32 110 - ``format`` 111 - Format restrictions. This field is set by the driver, not the 112 application. Possible values are ``V4L2_DEC_START_FMT_NONE`` if 113 there are no format restrictions or ``V4L2_DEC_START_FMT_GOP`` if 114 the decoder operates on full GOPs (*Group Of Pictures*). This is 115 usually the case for reverse playback: the decoder needs full 116 GOPs, which it can then play in reverse order. So to implement 117 reverse playback the application must feed the decoder the last 118 GOP in the video file, then the GOP before that, etc. etc. 119 * - struct 120 - ``stop`` 121 - 122 - Structure containing additional data for the ``V4L2_DEC_CMD_STOP`` 123 command. 124 * - 125 - __u64 126 - ``pts`` 127 - Stop playback at this ``pts`` or immediately if the playback is 128 already past that timestamp. Leave to 0 if you want to stop after 129 the last frame was decoded. 130 * - struct 131 - ``raw`` 132 * - 133 - __u32 134 - ``data``\ [16] 135 - Reserved for future extensions. Drivers and applications must set 136 the array to zero. 137 * - } 138 - 139 140 141 142.. tabularcolumns:: |p{5.6cm}|p{0.6cm}|p{11.3cm}| 143 144.. _decoder-cmds: 145 146.. flat-table:: Decoder Commands 147 :header-rows: 0 148 :stub-columns: 0 149 :widths: 56 6 113 150 151 * - ``V4L2_DEC_CMD_START`` 152 - 0 153 - Start the decoder. When the decoder is already running or paused, 154 this command will just change the playback speed. That means that 155 calling ``V4L2_DEC_CMD_START`` when the decoder was paused will 156 *not* resume the decoder. You have to explicitly call 157 ``V4L2_DEC_CMD_RESUME`` for that. This command has one flag: 158 ``V4L2_DEC_CMD_START_MUTE_AUDIO``. If set, then audio will be 159 muted when playing back at a non-standard speed. 160 161 For a device implementing the :ref:`decoder`, once the drain sequence 162 is initiated with the ``V4L2_DEC_CMD_STOP`` command, it must be driven 163 to completion before this command can be invoked. Any attempt to 164 invoke the command while the drain sequence is in progress will trigger 165 an ``EBUSY`` error code. The command may be also used to restart the 166 decoder in case of an implicit stop initiated by the decoder itself, 167 without the ``V4L2_DEC_CMD_STOP`` being called explicitly. See 168 :ref:`decoder` for more details. 169 * - ``V4L2_DEC_CMD_STOP`` 170 - 1 171 - Stop the decoder. When the decoder is already stopped, this 172 command does nothing. This command has two flags: if 173 ``V4L2_DEC_CMD_STOP_TO_BLACK`` is set, then the decoder will set 174 the picture to black after it stopped decoding. Otherwise the last 175 image will repeat. If 176 ``V4L2_DEC_CMD_STOP_IMMEDIATELY`` is set, then the decoder stops 177 immediately (ignoring the ``pts`` value), otherwise it will keep 178 decoding until timestamp >= pts or until the last of the pending 179 data from its internal buffers was decoded. 180 181 For a device implementing the :ref:`decoder`, the command will initiate 182 the drain sequence as documented in :ref:`decoder`. No flags or other 183 arguments are accepted in this case. Any attempt to invoke the command 184 again before the sequence completes will trigger an ``EBUSY`` error 185 code. 186 * - ``V4L2_DEC_CMD_PAUSE`` 187 - 2 188 - Pause the decoder. When the decoder has not been started yet, the 189 driver will return an ``EPERM`` error code. When the decoder is 190 already paused, this command does nothing. This command has one 191 flag: if ``V4L2_DEC_CMD_PAUSE_TO_BLACK`` is set, then set the 192 decoder output to black when paused. 193 * - ``V4L2_DEC_CMD_RESUME`` 194 - 3 195 - Resume decoding after a PAUSE command. When the decoder has not 196 been started yet, the driver will return an ``EPERM`` error code. When 197 the decoder is already running, this command does nothing. No 198 flags are defined for this command. 199 * - ``V4L2_DEC_CMD_FLUSH`` 200 - 4 201 - Flush any held capture buffers. Only valid for stateless decoders. 202 This command is typically used when the application reached the 203 end of the stream and the last output buffer had the 204 ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` flag set. This would prevent 205 dequeueing the capture buffer containing the last decoded frame. 206 So this command can be used to explicitly flush that final decoded 207 frame. This command does nothing if there are no held capture buffers. 208 209Return Value 210============ 211 212On success 0 is returned, on error -1 and the ``errno`` variable is set 213appropriately. The generic error codes are described at the 214:ref:`Generic Error Codes <gen-errors>` chapter. 215 216EBUSY 217 A drain sequence of a device implementing the :ref:`decoder` is still in 218 progress. It is not allowed to issue another decoder command until it 219 completes. 220 221EINVAL 222 The ``cmd`` field is invalid. 223 224EPERM 225 The application sent a PAUSE or RESUME command when the decoder was 226 not running. 227