1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
4 .. _VIDIOC_DECODER_CMD:
6 ************************************************
7 ioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD
8 ************************************************
13 VIDIOC_DECODER_CMD - VIDIOC_TRY_DECODER_CMD - Execute an decoder command
18 .. c:macro:: VIDIOC_DECODER_CMD
20 ``int ioctl(int fd, VIDIOC_DECODER_CMD, struct v4l2_decoder_cmd *argp)``
22 .. c:macro:: VIDIOC_TRY_DECODER_CMD
24 ``int ioctl(int fd, VIDIOC_TRY_DECODER_CMD, struct v4l2_decoder_cmd *argp)``
30 File descriptor returned by :c:func:`open()`.
33 pointer to struct :c:type:`v4l2_decoder_cmd`.
38 These ioctls control an audio/video (usually MPEG-) decoder.
39 ``VIDIOC_DECODER_CMD`` sends a command to the decoder,
40 ``VIDIOC_TRY_DECODER_CMD`` can be used to try a command without actually
41 executing it. To send a command applications must initialize all fields
42 of a struct :c:type:`v4l2_decoder_cmd` and call
43 ``VIDIOC_DECODER_CMD`` or ``VIDIOC_TRY_DECODER_CMD`` with a pointer to
46 The ``cmd`` field must contain the command code. Some commands use the
47 ``flags`` field for additional information.
49 A :c:func:`write()` or :ref:`VIDIOC_STREAMON`
50 call sends an implicit START command to the decoder if it has not been
51 started yet. Applies to both queues of mem2mem decoders.
53 A :c:func:`close()` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
54 call of a streaming file descriptor sends an implicit immediate STOP
55 command to the decoder, and all buffered data is discarded. Applies to both
56 queues of mem2mem decoders.
58 In principle, these ioctls are optional, not all drivers may support them. They were
59 introduced in Linux 3.3. They are, however, mandatory for stateful mem2mem decoders
60 (as further documented in :ref:`decoder`).
62 .. tabularcolumns:: |p{1.1cm}|p{2.4cm}|p{1.2cm}|p{1.6cm}|p{10.6cm}|
64 .. c:type:: v4l2_decoder_cmd
66 .. cssclass:: longtable
68 .. flat-table:: struct v4l2_decoder_cmd
76 - The decoder command, see :ref:`decoder-cmds`.
80 - Flags to go with the command. If no flags are defined for this
81 command, drivers and applications must set this field to zero.
87 - Structure containing additional data for the
88 ``V4L2_DEC_CMD_START`` command.
92 - Playback speed and direction. The playback speed is defined as
93 ``speed``/1000 of the normal speed. So 1000 is normal playback.
94 Negative numbers denote reverse playback, so -1000 does reverse
95 playback at normal speed. Speeds -1, 0 and 1 have special
96 meanings: speed 0 is shorthand for 1000 (normal playback). A speed
97 of 1 steps just one frame forward, a speed of -1 steps just one
102 - Format restrictions. This field is set by the driver, not the
103 application. Possible values are ``V4L2_DEC_START_FMT_NONE`` if
104 there are no format restrictions or ``V4L2_DEC_START_FMT_GOP`` if
105 the decoder operates on full GOPs (*Group Of Pictures*). This is
106 usually the case for reverse playback: the decoder needs full
107 GOPs, which it can then play in reverse order. So to implement
108 reverse playback the application must feed the decoder the last
109 GOP in the video file, then the GOP before that, etc. etc.
113 - Structure containing additional data for the ``V4L2_DEC_CMD_STOP``
118 - Stop playback at this ``pts`` or immediately if the playback is
119 already past that timestamp. Leave to 0 if you want to stop after
120 the last frame was decoded.
126 - Reserved for future extensions. Drivers and applications must set
132 .. tabularcolumns:: |p{5.6cm}|p{0.6cm}|p{11.3cm}|
136 .. flat-table:: Decoder Commands
141 * - ``V4L2_DEC_CMD_START``
143 - Start the decoder. When the decoder is already running or paused,
144 this command will just change the playback speed. That means that
145 calling ``V4L2_DEC_CMD_START`` when the decoder was paused will
146 *not* resume the decoder. You have to explicitly call
147 ``V4L2_DEC_CMD_RESUME`` for that. This command has one flag:
148 ``V4L2_DEC_CMD_START_MUTE_AUDIO``. If set, then audio will be
149 muted when playing back at a non-standard speed.
151 For a device implementing the :ref:`decoder`, once the drain sequence
152 is initiated with the ``V4L2_DEC_CMD_STOP`` command, it must be driven
153 to completion before this command can be invoked. Any attempt to
154 invoke the command while the drain sequence is in progress will trigger
155 an ``EBUSY`` error code. The command may be also used to restart the
156 decoder in case of an implicit stop initiated by the decoder itself,
157 without the ``V4L2_DEC_CMD_STOP`` being called explicitly. See
158 :ref:`decoder` for more details.
159 * - ``V4L2_DEC_CMD_STOP``
161 - Stop the decoder. When the decoder is already stopped, this
162 command does nothing. This command has two flags: if
163 ``V4L2_DEC_CMD_STOP_TO_BLACK`` is set, then the decoder will set
164 the picture to black after it stopped decoding. Otherwise the last
165 image will repeat. If
166 ``V4L2_DEC_CMD_STOP_IMMEDIATELY`` is set, then the decoder stops
167 immediately (ignoring the ``pts`` value), otherwise it will keep
168 decoding until timestamp >= pts or until the last of the pending
169 data from its internal buffers was decoded.
171 For a device implementing the :ref:`decoder`, the command will initiate
172 the drain sequence as documented in :ref:`decoder`. No flags or other
173 arguments are accepted in this case. Any attempt to invoke the command
174 again before the sequence completes will trigger an ``EBUSY`` error
176 * - ``V4L2_DEC_CMD_PAUSE``
178 - Pause the decoder. When the decoder has not been started yet, the
179 driver will return an ``EPERM`` error code. When the decoder is
180 already paused, this command does nothing. This command has one
181 flag: if ``V4L2_DEC_CMD_PAUSE_TO_BLACK`` is set, then set the
182 decoder output to black when paused.
183 * - ``V4L2_DEC_CMD_RESUME``
185 - Resume decoding after a PAUSE command. When the decoder has not
186 been started yet, the driver will return an ``EPERM`` error code. When
187 the decoder is already running, this command does nothing. No
188 flags are defined for this command.
189 * - ``V4L2_DEC_CMD_FLUSH``
191 - Flush any held capture buffers. Only valid for stateless decoders.
192 This command is typically used when the application reached the
193 end of the stream and the last output buffer had the
194 ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` flag set. This would prevent
195 dequeueing the capture buffer containing the last decoded frame.
196 So this command can be used to explicitly flush that final decoded
197 frame. This command does nothing if there are no held capture buffers.
202 On success 0 is returned, on error -1 and the ``errno`` variable is set
203 appropriately. The generic error codes are described at the
204 :ref:`Generic Error Codes <gen-errors>` chapter.
207 A drain sequence of a device implementing the :ref:`decoder` is still in
208 progress. It is not allowed to issue another decoder command until it
212 The ``cmd`` field is invalid.
215 The application sent a PAUSE or RESUME command when the decoder was