vidioc-encoder-cmd.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. .. -*- coding: utf-8; mode: rst -*-
  2. .. _VIDIOC_ENCODER_CMD:
  3. ************************************************
  4. ioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD
  5. ************************************************
  6. Name
  7. ====
  8. VIDIOC_ENCODER_CMD - VIDIOC_TRY_ENCODER_CMD - Execute an encoder command
  9. Synopsis
  10. ========
  11. .. c:function:: int ioctl( int fd, VIDIOC_ENCODER_CMD, struct v4l2_encoder_cmd *argp )
  12. :name: VIDIOC_ENCODER_CMD
  13. .. c:function:: int ioctl( int fd, VIDIOC_TRY_ENCODER_CMD, struct v4l2_encoder_cmd *argp )
  14. :name: VIDIOC_TRY_ENCODER_CMD
  15. Arguments
  16. =========
  17. ``fd``
  18. File descriptor returned by :ref:`open() <func-open>`.
  19. ``argp``
  20. Description
  21. ===========
  22. These ioctls control an audio/video (usually MPEG-) encoder.
  23. ``VIDIOC_ENCODER_CMD`` sends a command to the encoder,
  24. ``VIDIOC_TRY_ENCODER_CMD`` can be used to try a command without actually
  25. executing it.
  26. To send a command applications must initialize all fields of a struct
  27. :c:type:`v4l2_encoder_cmd` and call
  28. ``VIDIOC_ENCODER_CMD`` or ``VIDIOC_TRY_ENCODER_CMD`` with a pointer to
  29. this structure.
  30. The ``cmd`` field must contain the command code. The ``flags`` field is
  31. currently only used by the STOP command and contains one bit: If the
  32. ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag is set, encoding will continue
  33. until the end of the current *Group Of Pictures*, otherwise it will stop
  34. immediately.
  35. A :ref:`read() <func-read>` or :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>`
  36. call sends an implicit START command to the encoder if it has not been
  37. started yet. After a STOP command, :ref:`read() <func-read>` calls will read
  38. the remaining data buffered by the driver. When the buffer is empty,
  39. :ref:`read() <func-read>` will return zero and the next :ref:`read() <func-read>`
  40. call will restart the encoder.
  41. A :ref:`close() <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.
  44. These ioctls are optional, not all drivers may support them. They were
  45. introduced in Linux 2.6.21.
  46. .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
  47. .. c:type:: v4l2_encoder_cmd
  48. .. flat-table:: struct v4l2_encoder_cmd
  49. :header-rows: 0
  50. :stub-columns: 0
  51. :widths: 1 1 2
  52. * - __u32
  53. - ``cmd``
  54. - The encoder command, see :ref:`encoder-cmds`.
  55. * - __u32
  56. - ``flags``
  57. - Flags to go with the command, see :ref:`encoder-flags`. If no
  58. flags are defined for this command, drivers and applications must
  59. set this field to zero.
  60. * - __u32
  61. - ``data``\ [8]
  62. - Reserved for future extensions. Drivers and applications must set
  63. the array to zero.
  64. .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
  65. .. _encoder-cmds:
  66. .. flat-table:: Encoder Commands
  67. :header-rows: 0
  68. :stub-columns: 0
  69. :widths: 3 1 4
  70. * - ``V4L2_ENC_CMD_START``
  71. - 0
  72. - Start the encoder. When the encoder is already running or paused,
  73. this command does nothing. No flags are defined for this command.
  74. * - ``V4L2_ENC_CMD_STOP``
  75. - 1
  76. - Stop the encoder. When the ``V4L2_ENC_CMD_STOP_AT_GOP_END`` flag
  77. is set, encoding will continue until the end of the current *Group
  78. Of Pictures*, otherwise encoding will stop immediately. When the
  79. encoder is already stopped, this command does nothing. mem2mem
  80. encoders will send a ``V4L2_EVENT_EOS`` event when the last frame
  81. has been encoded and all frames are ready to be dequeued and will
  82. set the ``V4L2_BUF_FLAG_LAST`` buffer flag on the last buffer of
  83. the capture queue to indicate there will be no new buffers
  84. produced to dequeue. This buffer may be empty, indicated by the
  85. driver setting the ``bytesused`` field to 0. Once the
  86. ``V4L2_BUF_FLAG_LAST`` flag was set, the
  87. :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will not block anymore,
  88. but return an ``EPIPE`` error code.
  89. * - ``V4L2_ENC_CMD_PAUSE``
  90. - 2
  91. - Pause the encoder. When the encoder has not been started yet, the
  92. driver will return an ``EPERM`` error code. When the encoder is
  93. already paused, this command does nothing. No flags are defined
  94. for this command.
  95. * - ``V4L2_ENC_CMD_RESUME``
  96. - 3
  97. - Resume encoding after a PAUSE command. When the encoder has not
  98. been started yet, the driver will return an ``EPERM`` error code. When
  99. the encoder is already running, this command does nothing. No
  100. flags are defined for this command.
  101. .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
  102. .. _encoder-flags:
  103. .. flat-table:: Encoder Command Flags
  104. :header-rows: 0
  105. :stub-columns: 0
  106. :widths: 3 1 4
  107. * - ``V4L2_ENC_CMD_STOP_AT_GOP_END``
  108. - 0x0001
  109. - Stop encoding at the end of the current *Group Of Pictures*,
  110. rather than immediately.
  111. Return Value
  112. ============
  113. On success 0 is returned, on error -1 and the ``errno`` variable is set
  114. appropriately. The generic error codes are described at the
  115. :ref:`Generic Error Codes <gen-errors>` chapter.
  116. EINVAL
  117. The ``cmd`` field is invalid.
  118. EPERM
  119. The application sent a PAUSE or RESUME command when the encoder was
  120. not running.