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