blob: 6a821a65a5aec9ce1e196261c5149b666f2e4c2e [file] [log] [blame]
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001<refentry id="vidioc-qbuf">
2 <refmeta>
3 <refentrytitle>ioctl VIDIOC_QBUF, VIDIOC_DQBUF</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>VIDIOC_QBUF</refname>
9 <refname>VIDIOC_DQBUF</refname>
10 <refpurpose>Exchange a buffer with the driver</refpurpose>
11 </refnamediv>
12
13 <refsynopsisdiv>
14 <funcsynopsis>
15 <funcprototype>
16 <funcdef>int <function>ioctl</function></funcdef>
17 <paramdef>int <parameter>fd</parameter></paramdef>
18 <paramdef>int <parameter>request</parameter></paramdef>
19 <paramdef>struct v4l2_buffer *<parameter>argp</parameter></paramdef>
20 </funcprototype>
21 </funcsynopsis>
22 </refsynopsisdiv>
23
24 <refsect1>
25 <title>Arguments</title>
26
27 <variablelist>
28 <varlistentry>
29 <term><parameter>fd</parameter></term>
30 <listitem>
31 <para>&fd;</para>
32 </listitem>
33 </varlistentry>
34 <varlistentry>
35 <term><parameter>request</parameter></term>
36 <listitem>
37 <para>VIDIOC_QBUF, VIDIOC_DQBUF</para>
38 </listitem>
39 </varlistentry>
40 <varlistentry>
41 <term><parameter>argp</parameter></term>
42 <listitem>
43 <para></para>
44 </listitem>
45 </varlistentry>
46 </variablelist>
47 </refsect1>
48
49 <refsect1>
50 <title>Description</title>
51
52 <para>Applications call the <constant>VIDIOC_QBUF</constant> ioctl
53to enqueue an empty (capturing) or filled (output) buffer in the
54driver's incoming queue. The semantics depend on the selected I/O
55method.</para>
56
Hans Verkuil995f5fe2010-02-20 09:41:03 -030057 <para>To enqueue a buffer applications set the <structfield>type</structfield>
58field of a &v4l2-buffer; to the same buffer type as was previously used
59with &v4l2-format; <structfield>type</structfield> and &v4l2-requestbuffers;
60<structfield>type</structfield>. Applications must also set the
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -030061<structfield>index</structfield> field. Valid index numbers range from
62zero to the number of buffers allocated with &VIDIOC-REQBUFS;
63(&v4l2-requestbuffers; <structfield>count</structfield>) minus one. The
64contents of the struct <structname>v4l2_buffer</structname> returned
65by a &VIDIOC-QUERYBUF; ioctl will do as well. When the buffer is
66intended for output (<structfield>type</structfield> is
Pawel Osciak53b5d572011-01-07 01:41:33 -030067<constant>V4L2_BUF_TYPE_VIDEO_OUTPUT</constant>,
68<constant>V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE</constant>, or
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -030069<constant>V4L2_BUF_TYPE_VBI_OUTPUT</constant>) applications must also
70initialize the <structfield>bytesused</structfield>,
71<structfield>field</structfield> and
Hans Verkuil995f5fe2010-02-20 09:41:03 -030072<structfield>timestamp</structfield> fields, see <xref
73linkend="buffer" /> for details.
Sakari Ailus2b719d72012-05-02 09:40:03 -030074Applications must also set <structfield>flags</structfield> to 0.
75The <structfield>reserved2</structfield> and
76<structfield>reserved</structfield> fields must be set to 0. When using
Pawel Osciak53b5d572011-01-07 01:41:33 -030077the <link linkend="planar-apis">multi-planar API</link>, the
78<structfield>m.planes</structfield> field must contain a userspace pointer
79to a filled-in array of &v4l2-plane; and the <structfield>length</structfield>
80field must be set to the number of elements in that array.
Hans Verkuil995f5fe2010-02-20 09:41:03 -030081</para>
82
83 <para>To enqueue a <link linkend="mmap">memory mapped</link>
84buffer applications set the <structfield>memory</structfield>
85field to <constant>V4L2_MEMORY_MMAP</constant>. When
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -030086<constant>VIDIOC_QBUF</constant> is called with a pointer to this
87structure the driver sets the
88<constant>V4L2_BUF_FLAG_MAPPED</constant> and
89<constant>V4L2_BUF_FLAG_QUEUED</constant> flags and clears the
90<constant>V4L2_BUF_FLAG_DONE</constant> flag in the
91<structfield>flags</structfield> field, or it returns an
92&EINVAL;.</para>
93
94 <para>To enqueue a <link linkend="userp">user pointer</link>
Hans Verkuil995f5fe2010-02-20 09:41:03 -030095buffer applications set the <structfield>memory</structfield>
96field to <constant>V4L2_MEMORY_USERPTR</constant>, the
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -030097<structfield>m.userptr</structfield> field to the address of the
Pawel Osciak53b5d572011-01-07 01:41:33 -030098buffer and <structfield>length</structfield> to its size. When the multi-planar
99API is used, <structfield>m.userptr</structfield> and
100<structfield>length</structfield> members of the passed array of &v4l2-plane;
101have to be used instead. When <constant>VIDIOC_QBUF</constant> is called with
102a pointer to this structure the driver sets the
103<constant>V4L2_BUF_FLAG_QUEUED</constant> flag and clears the
104<constant>V4L2_BUF_FLAG_MAPPED</constant> and
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300105<constant>V4L2_BUF_FLAG_DONE</constant> flags in the
106<structfield>flags</structfield> field, or it returns an error code.
107This ioctl locks the memory pages of the buffer in physical memory,
108they cannot be swapped out to disk. Buffers remain locked until
Hans Verkuil995f5fe2010-02-20 09:41:03 -0300109dequeued, until the &VIDIOC-STREAMOFF; or &VIDIOC-REQBUFS; ioctl is
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300110called, or until the device is closed.</para>
111
112 <para>Applications call the <constant>VIDIOC_DQBUF</constant>
113ioctl to dequeue a filled (capturing) or displayed (output) buffer
114from the driver's outgoing queue. They just set the
Hans Verkuil995f5fe2010-02-20 09:41:03 -0300115<structfield>type</structfield>, <structfield>memory</structfield>
116and <structfield>reserved</structfield>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300117fields of a &v4l2-buffer; as above, when <constant>VIDIOC_DQBUF</constant>
118is called with a pointer to this structure the driver fills the
Pawel Osciak21636362010-04-28 04:05:23 -0300119remaining fields or returns an error code. The driver may also set
120<constant>V4L2_BUF_FLAG_ERROR</constant> in the <structfield>flags</structfield>
121field. It indicates a non-critical (recoverable) streaming error. In such case
122the application may continue as normal, but should be aware that data in the
Pawel Osciak53b5d572011-01-07 01:41:33 -0300123dequeued buffer might be corrupted. When using the multi-planar API, the
124planes array does not have to be passed; the <structfield>m.planes</structfield>
125member must be set to NULL in that case.</para>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300126
127 <para>By default <constant>VIDIOC_DQBUF</constant> blocks when no
128buffer is in the outgoing queue. When the
129<constant>O_NONBLOCK</constant> flag was given to the &func-open;
130function, <constant>VIDIOC_DQBUF</constant> returns immediately
131with an &EAGAIN; when no buffer is available.</para>
132
133 <para>The <structname>v4l2_buffer</structname> structure is
134specified in <xref linkend="buffer" />.</para>
135 </refsect1>
136
137 <refsect1>
138 &return-value;
139
140 <variablelist>
141 <varlistentry>
142 <term><errorcode>EAGAIN</errorcode></term>
143 <listitem>
144 <para>Non-blocking I/O has been selected using
145<constant>O_NONBLOCK</constant> and no buffer was in the outgoing
146queue.</para>
147 </listitem>
148 </varlistentry>
149 <varlistentry>
150 <term><errorcode>EINVAL</errorcode></term>
151 <listitem>
152 <para>The buffer <structfield>type</structfield> is not
153supported, or the <structfield>index</structfield> is out of bounds,
154or no buffers have been allocated yet, or the
155<structfield>userptr</structfield> or
156<structfield>length</structfield> are invalid.</para>
157 </listitem>
Hans Verkuil071408b2012-08-14 06:10:01 -0300158 </varlistentry>
159 <varlistentry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300160 <term><errorcode>EIO</errorcode></term>
161 <listitem>
162 <para><constant>VIDIOC_DQBUF</constant> failed due to an
163internal error. Can also indicate temporary problems like signal
164loss. Note the driver might dequeue an (empty) buffer despite
Pawel Osciak21636362010-04-28 04:05:23 -0300165returning an error, or even stop capturing. Reusing such buffer may be unsafe
166though and its details (e.g. <structfield>index</structfield>) may not be
167returned either. It is recommended that drivers indicate recoverable errors
168by setting the <constant>V4L2_BUF_FLAG_ERROR</constant> and returning 0 instead.
169In that case the application should be able to safely reuse the buffer and
170continue streaming.
171 </para>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300172 </listitem>
173 </varlistentry>
174 </variablelist>
175 </refsect1>
176</refentry>