vidioc-decoder-cmd.rst 7.6 KB

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