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