vidioc-qbuf.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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> or
  61. <constant>V4L2_BUF_TYPE_VBI_OUTPUT</constant>) applications must also
  62. initialize the <structfield>bytesused</structfield>,
  63. <structfield>field</structfield> and
  64. <structfield>timestamp</structfield> fields, see <xref
  65. linkend="buffer" /> for details.
  66. Applications must also set <structfield>flags</structfield> to 0. If a driver
  67. supports capturing from specific video inputs and you want to specify a video
  68. input, then <structfield>flags</structfield> should be set to
  69. <constant>V4L2_BUF_FLAG_INPUT</constant> and the field
  70. <structfield>input</structfield> must be initialized to the desired input.
  71. The <structfield>reserved</structfield> field must be set to 0.
  72. </para>
  73. <para>To enqueue a <link linkend="mmap">memory mapped</link>
  74. buffer applications set the <structfield>memory</structfield>
  75. field to <constant>V4L2_MEMORY_MMAP</constant>. When
  76. <constant>VIDIOC_QBUF</constant> is called with a pointer to this
  77. structure the driver sets the
  78. <constant>V4L2_BUF_FLAG_MAPPED</constant> and
  79. <constant>V4L2_BUF_FLAG_QUEUED</constant> flags and clears the
  80. <constant>V4L2_BUF_FLAG_DONE</constant> flag in the
  81. <structfield>flags</structfield> field, or it returns an
  82. &EINVAL;.</para>
  83. <para>To enqueue a <link linkend="userp">user pointer</link>
  84. buffer applications set the <structfield>memory</structfield>
  85. field to <constant>V4L2_MEMORY_USERPTR</constant>, the
  86. <structfield>m.userptr</structfield> field to the address of the
  87. buffer and <structfield>length</structfield> to its size.
  88. When <constant>VIDIOC_QBUF</constant> is called with a pointer to this
  89. structure the driver sets the <constant>V4L2_BUF_FLAG_QUEUED</constant>
  90. flag and clears the <constant>V4L2_BUF_FLAG_MAPPED</constant> and
  91. <constant>V4L2_BUF_FLAG_DONE</constant> flags in the
  92. <structfield>flags</structfield> field, or it returns an error code.
  93. This ioctl locks the memory pages of the buffer in physical memory,
  94. they cannot be swapped out to disk. Buffers remain locked until
  95. dequeued, until the &VIDIOC-STREAMOFF; or &VIDIOC-REQBUFS; ioctl is
  96. called, or until the device is closed.</para>
  97. <para>Applications call the <constant>VIDIOC_DQBUF</constant>
  98. ioctl to dequeue a filled (capturing) or displayed (output) buffer
  99. from the driver's outgoing queue. They just set the
  100. <structfield>type</structfield>, <structfield>memory</structfield>
  101. and <structfield>reserved</structfield>
  102. fields of a &v4l2-buffer; as above, when <constant>VIDIOC_DQBUF</constant>
  103. is called with a pointer to this structure the driver fills the
  104. remaining fields or returns an error code. The driver may also set
  105. <constant>V4L2_BUF_FLAG_ERROR</constant> in the <structfield>flags</structfield>
  106. field. It indicates a non-critical (recoverable) streaming error. In such case
  107. the application may continue as normal, but should be aware that data in the
  108. dequeued buffer might be corrupted.</para>
  109. <para>By default <constant>VIDIOC_DQBUF</constant> blocks when no
  110. buffer is in the outgoing queue. When the
  111. <constant>O_NONBLOCK</constant> flag was given to the &func-open;
  112. function, <constant>VIDIOC_DQBUF</constant> returns immediately
  113. with an &EAGAIN; when no buffer is available.</para>
  114. <para>The <structname>v4l2_buffer</structname> structure is
  115. specified in <xref linkend="buffer" />.</para>
  116. </refsect1>
  117. <refsect1>
  118. &return-value;
  119. <variablelist>
  120. <varlistentry>
  121. <term><errorcode>EAGAIN</errorcode></term>
  122. <listitem>
  123. <para>Non-blocking I/O has been selected using
  124. <constant>O_NONBLOCK</constant> and no buffer was in the outgoing
  125. queue.</para>
  126. </listitem>
  127. </varlistentry>
  128. <varlistentry>
  129. <term><errorcode>EINVAL</errorcode></term>
  130. <listitem>
  131. <para>The buffer <structfield>type</structfield> is not
  132. supported, or the <structfield>index</structfield> is out of bounds,
  133. or no buffers have been allocated yet, or the
  134. <structfield>userptr</structfield> or
  135. <structfield>length</structfield> are invalid.</para>
  136. </listitem>
  137. </varlistentry>
  138. <varlistentry>
  139. <term><errorcode>ENOMEM</errorcode></term>
  140. <listitem>
  141. <para>Not enough physical or virtual memory was available to
  142. enqueue a user pointer buffer.</para>
  143. </listitem>
  144. </varlistentry>
  145. <varlistentry>
  146. <term><errorcode>EIO</errorcode></term>
  147. <listitem>
  148. <para><constant>VIDIOC_DQBUF</constant> failed due to an
  149. internal error. Can also indicate temporary problems like signal
  150. loss. Note the driver might dequeue an (empty) buffer despite
  151. returning an error, or even stop capturing. Reusing such buffer may be unsafe
  152. though and its details (e.g. <structfield>index</structfield>) may not be
  153. returned either. It is recommended that drivers indicate recoverable errors
  154. by setting the <constant>V4L2_BUF_FLAG_ERROR</constant> and returning 0 instead.
  155. In that case the application should be able to safely reuse the buffer and
  156. continue streaming.
  157. </para>
  158. </listitem>
  159. </varlistentry>
  160. </variablelist>
  161. </refsect1>
  162. </refentry>
  163. <!--
  164. Local Variables:
  165. mode: sgml
  166. sgml-parent-document: "v4l2.sgml"
  167. indent-tabs-mode: nil
  168. End:
  169. -->