vidioc-qbuf.xml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <refentry id="vidioc-qbuf">
  2. <refmeta>
  3. <refentrytitle>ioctl VIDIOC_QBUF, VIDIOC_DQBUF</refentrytitle>
  4. &manvol;
  5. </refmeta>
  6. <refnamediv>
  7. <refname>VIDIOC_QBUF</refname>
  8. <refname>VIDIOC_DQBUF</refname>
  9. <refpurpose>Exchange a buffer with the driver</refpurpose>
  10. </refnamediv>
  11. <refsynopsisdiv>
  12. <funcsynopsis>
  13. <funcprototype>
  14. <funcdef>int <function>ioctl</function></funcdef>
  15. <paramdef>int <parameter>fd</parameter></paramdef>
  16. <paramdef>int <parameter>request</parameter></paramdef>
  17. <paramdef>struct v4l2_buffer *<parameter>argp</parameter></paramdef>
  18. </funcprototype>
  19. </funcsynopsis>
  20. </refsynopsisdiv>
  21. <refsect1>
  22. <title>Arguments</title>
  23. <variablelist>
  24. <varlistentry>
  25. <term><parameter>fd</parameter></term>
  26. <listitem>
  27. <para>&fd;</para>
  28. </listitem>
  29. </varlistentry>
  30. <varlistentry>
  31. <term><parameter>request</parameter></term>
  32. <listitem>
  33. <para>VIDIOC_QBUF, VIDIOC_DQBUF</para>
  34. </listitem>
  35. </varlistentry>
  36. <varlistentry>
  37. <term><parameter>argp</parameter></term>
  38. <listitem>
  39. <para></para>
  40. </listitem>
  41. </varlistentry>
  42. </variablelist>
  43. </refsect1>
  44. <refsect1>
  45. <title>Description</title>
  46. <para>Applications call the <constant>VIDIOC_QBUF</constant> ioctl
  47. to enqueue an empty (capturing) or filled (output) buffer in the
  48. driver's incoming queue. The semantics depend on the selected I/O
  49. method.</para>
  50. <para>To enqueue a buffer applications set the <structfield>type</structfield>
  51. field of a &v4l2-buffer; to the same buffer type as was previously used
  52. with &v4l2-format; <structfield>type</structfield> and &v4l2-requestbuffers;
  53. <structfield>type</structfield>. Applications must also set the
  54. <structfield>index</structfield> field. Valid index numbers range from
  55. zero to the number of buffers allocated with &VIDIOC-REQBUFS;
  56. (&v4l2-requestbuffers; <structfield>count</structfield>) minus one. The
  57. contents of the struct <structname>v4l2_buffer</structname> returned
  58. by a &VIDIOC-QUERYBUF; ioctl will do as well. When the buffer is
  59. intended for output (<structfield>type</structfield> is
  60. <constant>V4L2_BUF_TYPE_VIDEO_OUTPUT</constant>,
  61. <constant>V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE</constant>, or
  62. <constant>V4L2_BUF_TYPE_VBI_OUTPUT</constant>) applications must also
  63. initialize the <structfield>bytesused</structfield>,
  64. <structfield>field</structfield> and
  65. <structfield>timestamp</structfield> fields, see <xref
  66. linkend="buffer" /> for details.
  67. Applications must also set <structfield>flags</structfield> to 0.
  68. The <structfield>reserved2</structfield> and
  69. <structfield>reserved</structfield> fields must be set to 0. When using
  70. the <link linkend="planar-apis">multi-planar API</link>, the
  71. <structfield>m.planes</structfield> field must contain a userspace pointer
  72. to a filled-in array of &v4l2-plane; and the <structfield>length</structfield>
  73. field must be set to the number of elements in that array.
  74. </para>
  75. <para>To enqueue a <link linkend="mmap">memory mapped</link>
  76. buffer applications set the <structfield>memory</structfield>
  77. field to <constant>V4L2_MEMORY_MMAP</constant>. When
  78. <constant>VIDIOC_QBUF</constant> is called with a pointer to this
  79. structure the driver sets the
  80. <constant>V4L2_BUF_FLAG_MAPPED</constant> and
  81. <constant>V4L2_BUF_FLAG_QUEUED</constant> flags and clears the
  82. <constant>V4L2_BUF_FLAG_DONE</constant> flag in the
  83. <structfield>flags</structfield> field, or it returns an
  84. &EINVAL;.</para>
  85. <para>To enqueue a <link linkend="userp">user pointer</link>
  86. buffer applications set the <structfield>memory</structfield>
  87. field to <constant>V4L2_MEMORY_USERPTR</constant>, the
  88. <structfield>m.userptr</structfield> field to the address of the
  89. buffer and <structfield>length</structfield> to its size. When the multi-planar
  90. API is used, <structfield>m.userptr</structfield> and
  91. <structfield>length</structfield> members of the passed array of &v4l2-plane;
  92. have to be used instead. When <constant>VIDIOC_QBUF</constant> is called with
  93. a pointer to this structure the driver sets the
  94. <constant>V4L2_BUF_FLAG_QUEUED</constant> flag and clears the
  95. <constant>V4L2_BUF_FLAG_MAPPED</constant> and
  96. <constant>V4L2_BUF_FLAG_DONE</constant> flags in the
  97. <structfield>flags</structfield> field, or it returns an error code.
  98. This ioctl locks the memory pages of the buffer in physical memory,
  99. they cannot be swapped out to disk. Buffers remain locked until
  100. dequeued, until the &VIDIOC-STREAMOFF; or &VIDIOC-REQBUFS; ioctl is
  101. called, or until the device is closed.</para>
  102. <para>To enqueue a <link linkend="dmabuf">DMABUF</link> buffer applications
  103. set the <structfield>memory</structfield> field to
  104. <constant>V4L2_MEMORY_DMABUF</constant> and the <structfield>m.fd</structfield>
  105. field to a file descriptor associated with a DMABUF buffer. When the
  106. multi-planar API is used the <structfield>m.fd</structfield> fields of the
  107. passed array of &v4l2-plane; have to be used instead. When
  108. <constant>VIDIOC_QBUF</constant> is called with a pointer to this structure the
  109. driver sets the <constant>V4L2_BUF_FLAG_QUEUED</constant> flag and clears the
  110. <constant>V4L2_BUF_FLAG_MAPPED</constant> and
  111. <constant>V4L2_BUF_FLAG_DONE</constant> flags in the
  112. <structfield>flags</structfield> field, or it returns an error code. This
  113. ioctl locks the buffer. Locking a buffer means passing it to a driver for a
  114. hardware access (usually DMA). If an application accesses (reads/writes) a
  115. locked buffer then the result is undefined. Buffers remain locked until
  116. dequeued, until the &VIDIOC-STREAMOFF; or &VIDIOC-REQBUFS; ioctl is called, or
  117. until the device is closed.</para>
  118. <para>Applications call the <constant>VIDIOC_DQBUF</constant>
  119. ioctl to dequeue a filled (capturing) or displayed (output) buffer
  120. from the driver's outgoing queue. They just set the
  121. <structfield>type</structfield>, <structfield>memory</structfield>
  122. and <structfield>reserved</structfield>
  123. fields of a &v4l2-buffer; as above, when <constant>VIDIOC_DQBUF</constant>
  124. is called with a pointer to this structure the driver fills the
  125. remaining fields or returns an error code. The driver may also set
  126. <constant>V4L2_BUF_FLAG_ERROR</constant> in the <structfield>flags</structfield>
  127. field. It indicates a non-critical (recoverable) streaming error. In such case
  128. the application may continue as normal, but should be aware that data in the
  129. dequeued buffer might be corrupted. When using the multi-planar API, the
  130. planes array must be passed in as well.</para>
  131. <para>By default <constant>VIDIOC_DQBUF</constant> blocks when no
  132. buffer is in the outgoing queue. When the
  133. <constant>O_NONBLOCK</constant> flag was given to the &func-open;
  134. function, <constant>VIDIOC_DQBUF</constant> returns immediately
  135. with an &EAGAIN; when no buffer is available.</para>
  136. <para>The <structname>v4l2_buffer</structname> structure is
  137. specified in <xref linkend="buffer" />.</para>
  138. </refsect1>
  139. <refsect1>
  140. &return-value;
  141. <variablelist>
  142. <varlistentry>
  143. <term><errorcode>EAGAIN</errorcode></term>
  144. <listitem>
  145. <para>Non-blocking I/O has been selected using
  146. <constant>O_NONBLOCK</constant> and no buffer was in the outgoing
  147. queue.</para>
  148. </listitem>
  149. </varlistentry>
  150. <varlistentry>
  151. <term><errorcode>EINVAL</errorcode></term>
  152. <listitem>
  153. <para>The buffer <structfield>type</structfield> is not
  154. supported, or the <structfield>index</structfield> is out of bounds,
  155. or no buffers have been allocated yet, or the
  156. <structfield>userptr</structfield> or
  157. <structfield>length</structfield> are invalid.</para>
  158. </listitem>
  159. </varlistentry>
  160. <varlistentry>
  161. <term><errorcode>EIO</errorcode></term>
  162. <listitem>
  163. <para><constant>VIDIOC_DQBUF</constant> failed due to an
  164. internal error. Can also indicate temporary problems like signal
  165. loss. Note the driver might dequeue an (empty) buffer despite
  166. returning an error, or even stop capturing. Reusing such buffer may be unsafe
  167. though and its details (e.g. <structfield>index</structfield>) may not be
  168. returned either. It is recommended that drivers indicate recoverable errors
  169. by setting the <constant>V4L2_BUF_FLAG_ERROR</constant> and returning 0 instead.
  170. In that case the application should be able to safely reuse the buffer and
  171. continue streaming.
  172. </para>
  173. </listitem>
  174. </varlistentry>
  175. <varlistentry>
  176. <term><errorcode>EPIPE</errorcode></term>
  177. <listitem>
  178. <para><constant>VIDIOC_DQBUF</constant> returns this on an empty
  179. capture queue for mem2mem codecs if a buffer with the
  180. <constant>V4L2_BUF_FLAG_LAST</constant> was already dequeued and no new buffers
  181. are expected to become available.
  182. </para>
  183. </listitem>
  184. </varlistentry>
  185. </variablelist>
  186. </refsect1>
  187. </refentry>