vidioc-encoder-cmd.rst 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
  2. .. c:namespace:: V4L
  3. .. _VIDIOC_ENCODER_CMD:
  4. ************************************************
  5. ioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD
  6. ************************************************
  7. Name
  8. ====
  9. VIDIOC_ENCODER_CMD - VIDIOC_TRY_ENCODER_CMD - Execute an encoder command
  10. Synopsis
  11. ========
  12. .. c:macro:: VIDIOC_ENCODER_CMD
  13. ``int ioctl(int fd, VIDIOC_ENCODER_CMD, struct v4l2_encoder_cmd *argp)``
  14. .. c:macro:: VIDIOC_TRY_ENCODER_CMD
  15. ``int ioctl(int fd, VIDIOC_TRY_ENCODER_CMD, struct v4l2_encoder_cmd *argp)``
  16. Arguments
  17. =========
  18. ``fd``
  19. File descriptor returned by :c:func:`open()`.
  20. ``argp``
  21. Pointer to struct :c:type:`v4l2_encoder_cmd`.
  22. Description
  23. ===========
  24. These ioctls control an audio/video (usually MPEG-) encoder.
  25. ``VIDIOC_ENCODER_CMD`` sends a command to the encoder,
  26. ``VIDIOC_TRY_ENCODER_CMD`` can be used to try a command without actually
  27. executing it.
  28. To send a command applications must initialize all fields of a struct
  29. :c:type:`v4l2_encoder_cmd` and call
  30. ``VIDIOC_ENCODER_CMD`` or ``VIDIOC_TRY_ENCODER_CMD`` with a pointer to
  31. this structure.
  32. The ``cmd`` field must contain the command code. Some commands use the
  33. ``flags`` field for additional information.
  34. After a STOP command, :c:func:`read()` calls will read
  35. the remaining data buffered by the driver. When the buffer is empty,
  36. :c:func:`read()` will return zero and the next :c:func:`read()`
  37. call will restart the encoder.
  38. A :c:func:`read()` or :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>`
  39. call sends an implicit START command to the encoder if it has not been
  40. started yet. Applies to both queues of mem2mem encoders.
  41. A :c:func:`close()` or :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
  42. call of a streaming file descriptor sends an implicit immediate STOP to
  43. the encoder, and all buffered data is discarded. Applies to both queues of
  44. mem2mem encoders.
  45. These ioctls are optional, not all drivers may support them. They were
  46. introduced in Linux 2.6.21. They are, however, mandatory for stateful mem2mem
  47. encoders (as further documented in :ref:`encoder`).
  48. .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
  49. .. c:type:: v4l2_encoder_cmd
  50. .. flat-table:: struct v4l2_encoder_cmd
  51. :header-rows: 0
  52. :stub-columns: 0
  53. :widths: 1 1 2
  54. * - __u32
  55. - ``cmd``
  56. - The encoder command, see :ref:`encoder-cmds`.
  57. * - __u32
  58. - ``flags``
  59. - Flags to go with the command, see :ref:`encoder-flags`. If no
  60. flags are defined for this command, drivers and applications must
  61. set this field to zero.
  62. * - __u32
  63. - ``data``\ [8]
  64. - Reserved for future extensions. Drivers and applications must set
  65. the array to zero.
  66. .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|
  67. .. _encoder-cmds:
  68. .. flat-table:: Encoder Commands
  69. :header-rows: 0
  70. :stub-columns: 0
  71. :widths: 3 1 4
  72. * - ``V4L2_ENC_CMD_START``
  73. - 0
  74. - Start the encoder. When the encoder is already running or paused,
  75. this command does nothing. No flags are defined for this command.
  76. For a device implementing the :ref:`encoder`, once the drain sequence
  77. is initiated with the ``V4L2_ENC_CMD_STOP`` command, it must be driven
  78. to completion before this command can be invoked. Any attempt to
  79. invoke the command while the drain sequence is in progress will trigger
  80. an ``EBUSY`` error code. See :ref:`encoder` for more details.
  81. * - ``V4L2_ENC_CMD_STOP``
  82. - 1
  83. - Stop the encoder. When the ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag
  84. is set, encoding will continue until the end of the current *Group
  85. Of Pictures*, otherwise encoding will stop immediately. When the
  86. encoder is already stopped, this command does nothing.
  87. For a device implementing the :ref:`encoder`, the command will initiate
  88. the drain sequence as documented in :ref:`encoder`. No flags or other
  89. arguments are accepted in this case. Any attempt to invoke the command
  90. again before the sequence completes will trigger an ``EBUSY`` error
  91. code.
  92. * - ``V4L2_ENC_CMD_PAUSE``
  93. - 2
  94. - Pause the encoder. When the encoder has not been started yet, the
  95. driver will return an ``EPERM`` error code. When the encoder is
  96. already paused, this command does nothing. No flags are defined
  97. for this command.
  98. * - ``V4L2_ENC_CMD_RESUME``
  99. - 3
  100. - Resume encoding after a PAUSE command. When the encoder has not
  101. been started yet, the driver will return an ``EPERM`` error code. When
  102. the encoder is already running, this command does nothing. No
  103. flags are defined for this command.
  104. .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|
  105. .. _encoder-flags:
  106. .. flat-table:: Encoder Command Flags
  107. :header-rows: 0
  108. :stub-columns: 0
  109. :widths: 3 1 4
  110. * - ``V4L2_ENC_CMD_STOP_AT_GOP_END``
  111. - 0x0001
  112. - Stop encoding at the end of the current *Group Of Pictures*,
  113. rather than immediately.
  114. Does not apply to :ref:`encoder`.
  115. Return Value
  116. ============
  117. On success 0 is returned, on error -1 and the ``errno`` variable is set
  118. appropriately. The generic error codes are described at the
  119. :ref:`Generic Error Codes <gen-errors>` chapter.
  120. EBUSY
  121. A drain sequence of a device implementing the :ref:`encoder` is still in
  122. progress. It is not allowed to issue another encoder command until it
  123. completes.
  124. EINVAL
  125. The ``cmd`` field is invalid.
  126. EPERM
  127. The application sent a PAUSE or RESUME command when the encoder was
  128. not running.