blob: 5a2e97bbc6bf38da54fc31724ab883f55838e845 [file] [log] [blame]
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001 <title>Input/Output</title>
2
3 <para>The V4L2 API defines several different methods to read from or
4write to a device. All drivers exchanging data with applications must
5support at least one of them.</para>
6
7 <para>The classic I/O method using the <function>read()</function>
8and <function>write()</function> function is automatically selected
9after opening a V4L2 device. When the driver does not support this
10method attempts to read or write will fail at any time.</para>
11
12 <para>Other methods must be negotiated. To select the streaming I/O
13method with memory mapped or user buffers applications call the
14&VIDIOC-REQBUFS; ioctl. The asynchronous I/O method is not defined
15yet.</para>
16
17 <para>Video overlay can be considered another I/O method, although
18the application does not directly receive the image data. It is
19selected by initiating video overlay with the &VIDIOC-S-FMT; ioctl.
20For more information see <xref linkend="overlay" />.</para>
21
22 <para>Generally exactly one I/O method, including overlay, is
23associated with each file descriptor. The only exceptions are
24applications not exchanging data with a driver ("panel applications",
25see <xref linkend="open" />) and drivers permitting simultaneous video capturing
26and overlay using the same file descriptor, for compatibility with V4L
27and earlier versions of V4L2.</para>
28
29 <para><constant>VIDIOC_S_FMT</constant> and
30<constant>VIDIOC_REQBUFS</constant> would permit this to some degree,
31but for simplicity drivers need not support switching the I/O method
32(after first switching away from read/write) other than by closing
33and reopening the device.</para>
34
35 <para>The following sections describe the various I/O methods in
36more detail.</para>
37
38 <section id="rw">
39 <title>Read/Write</title>
40
41 <para>Input and output devices support the
42<function>read()</function> and <function>write()</function> function,
43respectively, when the <constant>V4L2_CAP_READWRITE</constant> flag in
44the <structfield>capabilities</structfield> field of &v4l2-capability;
45returned by the &VIDIOC-QUERYCAP; ioctl is set.</para>
46
47 <para>Drivers may need the CPU to copy the data, but they may also
48support DMA to or from user memory, so this I/O method is not
49necessarily less efficient than other methods merely exchanging buffer
50pointers. It is considered inferior though because no meta-information
51like frame counters or timestamps are passed. This information is
52necessary to recognize frame dropping and to synchronize with other
53data streams. However this is also the simplest I/O method, requiring
54little or no setup to exchange data. It permits command line stunts
55like this (the <application>vidctrl</application> tool is
56fictitious):</para>
57
58 <informalexample>
59 <screen>
60&gt; vidctrl /dev/video --input=0 --format=YUYV --size=352x288
61&gt; dd if=/dev/video of=myimage.422 bs=202752 count=1
62</screen>
63 </informalexample>
64
65 <para>To read from the device applications use the
66&func-read; function, to write the &func-write; function.
67Drivers must implement one I/O method if they
68exchange data with applications, but it need not be this.<footnote>
69 <para>It would be desirable if applications could depend on
70drivers supporting all I/O interfaces, but as much as the complex
71memory mapping I/O can be inadequate for some devices we have no
72reason to require this interface, which is most useful for simple
73applications capturing still images.</para>
74 </footnote> When reading or writing is supported, the driver
75must also support the &func-select; and &func-poll;
76function.<footnote>
77 <para>At the driver level <function>select()</function> and
78<function>poll()</function> are the same, and
79<function>select()</function> is too important to be optional.</para>
80 </footnote></para>
81 </section>
82
83 <section id="mmap">
84 <title>Streaming I/O (Memory Mapping)</title>
85
86 <para>Input and output devices support this I/O method when the
87<constant>V4L2_CAP_STREAMING</constant> flag in the
88<structfield>capabilities</structfield> field of &v4l2-capability;
89returned by the &VIDIOC-QUERYCAP; ioctl is set. There are two
90streaming methods, to determine if the memory mapping flavor is
91supported applications must call the &VIDIOC-REQBUFS; ioctl.</para>
92
93 <para>Streaming is an I/O method where only pointers to buffers
94are exchanged between application and driver, the data itself is not
95copied. Memory mapping is primarily intended to map buffers in device
96memory into the application's address space. Device memory can be for
97example the video memory on a graphics card with a video capture
98add-on. However, being the most efficient I/O method available for a
99long time, many other drivers support streaming as well, allocating
100buffers in DMA-able main memory.</para>
101
102 <para>A driver can support many sets of buffers. Each set is
103identified by a unique buffer type value. The sets are independent and
104each set can hold a different type of data. To access different sets
105at the same time different file descriptors must be used.<footnote>
106 <para>One could use one file descriptor and set the buffer
107type field accordingly when calling &VIDIOC-QBUF; etc., but it makes
108the <function>select()</function> function ambiguous. We also like the
109clean approach of one file descriptor per logical stream. Video
110overlay for example is also a logical stream, although the CPU is not
111needed for continuous operation.</para>
112 </footnote></para>
113
114 <para>To allocate device buffers applications call the
115&VIDIOC-REQBUFS; ioctl with the desired number of buffers and buffer
116type, for example <constant>V4L2_BUF_TYPE_VIDEO_CAPTURE</constant>.
117This ioctl can also be used to change the number of buffers or to free
118the allocated memory, provided none of the buffers are still
119mapped.</para>
120
121 <para>Before applications can access the buffers they must map
122them into their address space with the &func-mmap; function. The
123location of the buffers in device memory can be determined with the
Pawel Osciak53b5d572011-01-07 01:41:33 -0300124&VIDIOC-QUERYBUF; ioctl. In the single-planar API case, the
125<structfield>m.offset</structfield> and <structfield>length</structfield>
126returned in a &v4l2-buffer; are passed as sixth and second parameter to the
127<function>mmap()</function> function. When using the multi-planar API,
128struct &v4l2-buffer; contains an array of &v4l2-plane; structures, each
129containing its own <structfield>m.offset</structfield> and
130<structfield>length</structfield>. When using the multi-planar API, every
131plane of every buffer has to be mapped separately, so the number of
132calls to &func-mmap; should be equal to number of buffers times number of
133planes in each buffer. The offset and length values must not be modified.
134Remember, the buffers are allocated in physical memory, as opposed to virtual
135memory, which can be swapped out to disk. Applications should free the buffers
136as soon as possible with the &func-munmap; function.</para>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300137
138 <example>
Pawel Osciak53b5d572011-01-07 01:41:33 -0300139 <title>Mapping buffers in the single-planar API</title>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300140 <programlisting>
141&v4l2-requestbuffers; reqbuf;
142struct {
143 void *start;
144 size_t length;
145} *buffers;
146unsigned int i;
147
Pawel Osciakc4c0a782011-01-12 05:57:26 -0300148memset(&amp;reqbuf, 0, sizeof(reqbuf));
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300149reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
150reqbuf.memory = V4L2_MEMORY_MMAP;
151reqbuf.count = 20;
152
153if (-1 == ioctl (fd, &VIDIOC-REQBUFS;, &amp;reqbuf)) {
154 if (errno == EINVAL)
Pawel Osciakc4c0a782011-01-12 05:57:26 -0300155 printf("Video capturing or mmap-streaming is not supported\n");
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300156 else
Pawel Osciakc4c0a782011-01-12 05:57:26 -0300157 perror("VIDIOC_REQBUFS");
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300158
Pawel Osciakc4c0a782011-01-12 05:57:26 -0300159 exit(EXIT_FAILURE);
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300160}
161
162/* We want at least five buffers. */
163
164if (reqbuf.count &lt; 5) {
165 /* You may need to free the buffers here. */
Pawel Osciakc4c0a782011-01-12 05:57:26 -0300166 printf("Not enough buffer memory\n");
167 exit(EXIT_FAILURE);
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300168}
169
Pawel Osciakc4c0a782011-01-12 05:57:26 -0300170buffers = calloc(reqbuf.count, sizeof(*buffers));
171assert(buffers != NULL);
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300172
173for (i = 0; i &lt; reqbuf.count; i++) {
174 &v4l2-buffer; buffer;
175
Pawel Osciakc4c0a782011-01-12 05:57:26 -0300176 memset(&amp;buffer, 0, sizeof(buffer));
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300177 buffer.type = reqbuf.type;
178 buffer.memory = V4L2_MEMORY_MMAP;
179 buffer.index = i;
180
181 if (-1 == ioctl (fd, &VIDIOC-QUERYBUF;, &amp;buffer)) {
Pawel Osciakc4c0a782011-01-12 05:57:26 -0300182 perror("VIDIOC_QUERYBUF");
183 exit(EXIT_FAILURE);
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300184 }
185
186 buffers[i].length = buffer.length; /* remember for munmap() */
187
Pawel Osciakc4c0a782011-01-12 05:57:26 -0300188 buffers[i].start = mmap(NULL, buffer.length,
189 PROT_READ | PROT_WRITE, /* recommended */
190 MAP_SHARED, /* recommended */
191 fd, buffer.m.offset);
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300192
193 if (MAP_FAILED == buffers[i].start) {
194 /* If you do not exit here you should unmap() and free()
195 the buffers mapped so far. */
Pawel Osciakc4c0a782011-01-12 05:57:26 -0300196 perror("mmap");
197 exit(EXIT_FAILURE);
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300198 }
199}
200
201/* Cleanup. */
202
203for (i = 0; i &lt; reqbuf.count; i++)
Pawel Osciakc4c0a782011-01-12 05:57:26 -0300204 munmap(buffers[i].start, buffers[i].length);
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300205 </programlisting>
206 </example>
207
Pawel Osciak53b5d572011-01-07 01:41:33 -0300208 <example>
209 <title>Mapping buffers in the multi-planar API</title>
210 <programlisting>
211&v4l2-requestbuffers; reqbuf;
212/* Our current format uses 3 planes per buffer */
Phil Carmody497888c2011-07-14 15:07:13 +0300213#define FMT_NUM_PLANES = 3
Pawel Osciak53b5d572011-01-07 01:41:33 -0300214
215struct {
216 void *start[FMT_NUM_PLANES];
217 size_t length[FMT_NUM_PLANES];
218} *buffers;
219unsigned int i, j;
220
221memset(&amp;reqbuf, 0, sizeof(reqbuf));
222reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
223reqbuf.memory = V4L2_MEMORY_MMAP;
224reqbuf.count = 20;
225
226if (ioctl(fd, &VIDIOC-REQBUFS;, &amp;reqbuf) &lt; 0) {
227 if (errno == EINVAL)
228 printf("Video capturing or mmap-streaming is not supported\n");
229 else
230 perror("VIDIOC_REQBUFS");
231
232 exit(EXIT_FAILURE);
233}
234
235/* We want at least five buffers. */
236
237if (reqbuf.count &lt; 5) {
238 /* You may need to free the buffers here. */
239 printf("Not enough buffer memory\n");
240 exit(EXIT_FAILURE);
241}
242
243buffers = calloc(reqbuf.count, sizeof(*buffers));
244assert(buffers != NULL);
245
246for (i = 0; i &lt; reqbuf.count; i++) {
247 &v4l2-buffer; buffer;
248 &v4l2-plane; planes[FMT_NUM_PLANES];
249
250 memset(&amp;buffer, 0, sizeof(buffer));
251 buffer.type = reqbuf.type;
252 buffer.memory = V4L2_MEMORY_MMAP;
253 buffer.index = i;
254 /* length in struct v4l2_buffer in multi-planar API stores the size
255 * of planes array. */
256 buffer.length = FMT_NUM_PLANES;
257 buffer.m.planes = planes;
258
259 if (ioctl(fd, &VIDIOC-QUERYBUF;, &amp;buffer) &lt; 0) {
260 perror("VIDIOC_QUERYBUF");
261 exit(EXIT_FAILURE);
262 }
263
264 /* Every plane has to be mapped separately */
265 for (j = 0; j &lt; FMT_NUM_PLANES; j++) {
266 buffers[i].length[j] = buffer.m.planes[j].length; /* remember for munmap() */
267
268 buffers[i].start[j] = mmap(NULL, buffer.m.planes[j].length,
269 PROT_READ | PROT_WRITE, /* recommended */
270 MAP_SHARED, /* recommended */
271 fd, buffer.m.planes[j].m.offset);
272
273 if (MAP_FAILED == buffers[i].start[j]) {
274 /* If you do not exit here you should unmap() and free()
275 the buffers and planes mapped so far. */
276 perror("mmap");
277 exit(EXIT_FAILURE);
278 }
279 }
280}
281
282/* Cleanup. */
283
284for (i = 0; i &lt; reqbuf.count; i++)
285 for (j = 0; j &lt; FMT_NUM_PLANES; j++)
286 munmap(buffers[i].start[j], buffers[i].length[j]);
287 </programlisting>
288 </example>
289
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300290 <para>Conceptually streaming drivers maintain two buffer queues, an incoming
291and an outgoing queue. They separate the synchronous capture or output
292operation locked to a video clock from the application which is
293subject to random disk or network delays and preemption by
294other processes, thereby reducing the probability of data loss.
295The queues are organized as FIFOs, buffers will be
296output in the order enqueued in the incoming FIFO, and were
297captured in the order dequeued from the outgoing FIFO.</para>
298
299 <para>The driver may require a minimum number of buffers enqueued
300at all times to function, apart of this no limit exists on the number
301of buffers applications can enqueue in advance, or dequeue and
302process. They can also enqueue in a different order than buffers have
303been dequeued, and the driver can <emphasis>fill</emphasis> enqueued
304<emphasis>empty</emphasis> buffers in any order. <footnote>
305 <para>Random enqueue order permits applications processing
306images out of order (such as video codecs) to return buffers earlier,
307reducing the probability of data loss. Random fill order allows
308drivers to reuse buffers on a LIFO-basis, taking advantage of caches
309holding scatter-gather lists and the like.</para>
310 </footnote> The index number of a buffer (&v4l2-buffer;
311<structfield>index</structfield>) plays no role here, it only
312identifies the buffer.</para>
313
314 <para>Initially all mapped buffers are in dequeued state,
315inaccessible by the driver. For capturing applications it is customary
316to first enqueue all mapped buffers, then to start capturing and enter
317the read loop. Here the application waits until a filled buffer can be
318dequeued, and re-enqueues the buffer when the data is no longer
319needed. Output applications fill and enqueue buffers, when enough
320buffers are stacked up the output is started with
321<constant>VIDIOC_STREAMON</constant>. In the write loop, when
322the application runs out of free buffers, it must wait until an empty
323buffer can be dequeued and reused.</para>
324
325 <para>To enqueue and dequeue a buffer applications use the
326&VIDIOC-QBUF; and &VIDIOC-DQBUF; ioctl. The status of a buffer being
327mapped, enqueued, full or empty can be determined at any time using the
328&VIDIOC-QUERYBUF; ioctl. Two methods exist to suspend execution of the
329application until one or more buffers can be dequeued. By default
330<constant>VIDIOC_DQBUF</constant> blocks when no buffer is in the
331outgoing queue. When the <constant>O_NONBLOCK</constant> flag was
332given to the &func-open; function, <constant>VIDIOC_DQBUF</constant>
333returns immediately with an &EAGAIN; when no buffer is available. The
Tomasz Stanislawski4b9c1cb2012-06-14 10:37:36 -0300334&func-select; or &func-poll; functions are always available.</para>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300335
336 <para>To start and stop capturing or output applications call the
337&VIDIOC-STREAMON; and &VIDIOC-STREAMOFF; ioctl. Note
338<constant>VIDIOC_STREAMOFF</constant> removes all buffers from both
339queues as a side effect. Since there is no notion of doing anything
340"now" on a multitasking system, if an application needs to synchronize
341with another event it should examine the &v4l2-buffer;
Sakari Ailusc6c09212013-01-25 15:00:07 -0300342<structfield>timestamp</structfield> of captured or outputted buffers.
343</para>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300344
345 <para>Drivers implementing memory mapping I/O must
346support the <constant>VIDIOC_REQBUFS</constant>,
347<constant>VIDIOC_QUERYBUF</constant>,
348<constant>VIDIOC_QBUF</constant>, <constant>VIDIOC_DQBUF</constant>,
349<constant>VIDIOC_STREAMON</constant> and
350<constant>VIDIOC_STREAMOFF</constant> ioctl, the
351<function>mmap()</function>, <function>munmap()</function>,
352<function>select()</function> and <function>poll()</function>
353function.<footnote>
354 <para>At the driver level <function>select()</function> and
355<function>poll()</function> are the same, and
356<function>select()</function> is too important to be optional. The
357rest should be evident.</para>
358 </footnote></para>
359
360 <para>[capture example]</para>
361
362 </section>
363
364 <section id="userp">
365 <title>Streaming I/O (User Pointers)</title>
366
367 <para>Input and output devices support this I/O method when the
368<constant>V4L2_CAP_STREAMING</constant> flag in the
369<structfield>capabilities</structfield> field of &v4l2-capability;
370returned by the &VIDIOC-QUERYCAP; ioctl is set. If the particular user
371pointer method (not only memory mapping) is supported must be
372determined by calling the &VIDIOC-REQBUFS; ioctl.</para>
373
374 <para>This I/O method combines advantages of the read/write and
Pawel Osciak53b5d572011-01-07 01:41:33 -0300375memory mapping methods. Buffers (planes) are allocated by the application
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300376itself, and can reside for example in virtual or shared memory. Only
377pointers to data are exchanged, these pointers and meta-information
Pawel Osciak53b5d572011-01-07 01:41:33 -0300378are passed in &v4l2-buffer; (or in &v4l2-plane; in the multi-planar API case).
379The driver must be switched into user pointer I/O mode by calling the
380&VIDIOC-REQBUFS; with the desired buffer type. No buffers (planes) are allocated
381beforehand, consequently they are not indexed and cannot be queried like mapped
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300382buffers with the <constant>VIDIOC_QUERYBUF</constant> ioctl.</para>
383
384 <example>
385 <title>Initiating streaming I/O with user pointers</title>
386
387 <programlisting>
388&v4l2-requestbuffers; reqbuf;
389
390memset (&amp;reqbuf, 0, sizeof (reqbuf));
391reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
392reqbuf.memory = V4L2_MEMORY_USERPTR;
393
394if (ioctl (fd, &VIDIOC-REQBUFS;, &amp;reqbuf) == -1) {
395 if (errno == EINVAL)
396 printf ("Video capturing or user pointer streaming is not supported\n");
397 else
398 perror ("VIDIOC_REQBUFS");
399
400 exit (EXIT_FAILURE);
401}
402 </programlisting>
403 </example>
404
Pawel Osciak53b5d572011-01-07 01:41:33 -0300405 <para>Buffer (plane) addresses and sizes are passed on the fly with the
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300406&VIDIOC-QBUF; ioctl. Although buffers are commonly cycled,
407applications can pass different addresses and sizes at each
408<constant>VIDIOC_QBUF</constant> call. If required by the hardware the
409driver swaps memory pages within physical memory to create a
410continuous area of memory. This happens transparently to the
411application in the virtual memory subsystem of the kernel. When buffer
412pages have been swapped out to disk they are brought back and finally
413locked in physical memory for DMA.<footnote>
414 <para>We expect that frequently used buffers are typically not
415swapped out. Anyway, the process of swapping, locking or generating
416scatter-gather lists may be time consuming. The delay can be masked by
417the depth of the incoming buffer queue, and perhaps by maintaining
418caches assuming a buffer will be soon enqueued again. On the other
419hand, to optimize memory usage drivers can limit the number of buffers
420locked in advance and recycle the most recently used buffers first. Of
421course, the pages of empty buffers in the incoming queue need not be
422saved to disk. Output buffers must be saved on the incoming and
423outgoing queue because an application may share them with other
424processes.</para>
425 </footnote></para>
426
427 <para>Filled or displayed buffers are dequeued with the
428&VIDIOC-DQBUF; ioctl. The driver can unlock the memory pages at any
429time between the completion of the DMA and this ioctl. The memory is
430also unlocked when &VIDIOC-STREAMOFF; is called, &VIDIOC-REQBUFS;, or
431when the device is closed. Applications must take care not to free
432buffers without dequeuing. For once, the buffers remain locked until
433further, wasting physical memory. Second the driver will not be
434notified when the memory is returned to the application's free list
435and subsequently reused for other purposes, possibly completing the
436requested DMA and overwriting valuable data.</para>
437
438 <para>For capturing applications it is customary to enqueue a
439number of empty buffers, to start capturing and enter the read loop.
440Here the application waits until a filled buffer can be dequeued, and
441re-enqueues the buffer when the data is no longer needed. Output
442applications fill and enqueue buffers, when enough buffers are stacked
443up output is started. In the write loop, when the application
444runs out of free buffers it must wait until an empty buffer can be
445dequeued and reused. Two methods exist to suspend execution of the
446application until one or more buffers can be dequeued. By default
447<constant>VIDIOC_DQBUF</constant> blocks when no buffer is in the
448outgoing queue. When the <constant>O_NONBLOCK</constant> flag was
449given to the &func-open; function, <constant>VIDIOC_DQBUF</constant>
450returns immediately with an &EAGAIN; when no buffer is available. The
451&func-select; or &func-poll; function are always available.</para>
452
453 <para>To start and stop capturing or output applications call the
454&VIDIOC-STREAMON; and &VIDIOC-STREAMOFF; ioctl. Note
455<constant>VIDIOC_STREAMOFF</constant> removes all buffers from both
456queues and unlocks all buffers as a side effect. Since there is no
457notion of doing anything "now" on a multitasking system, if an
458application needs to synchronize with another event it should examine
459the &v4l2-buffer; <structfield>timestamp</structfield> of captured
Sakari Ailusc6c09212013-01-25 15:00:07 -0300460or outputted buffers.</para>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300461
462 <para>Drivers implementing user pointer I/O must
463support the <constant>VIDIOC_REQBUFS</constant>,
464<constant>VIDIOC_QBUF</constant>, <constant>VIDIOC_DQBUF</constant>,
465<constant>VIDIOC_STREAMON</constant> and
466<constant>VIDIOC_STREAMOFF</constant> ioctl, the
467<function>select()</function> and <function>poll()</function> function.<footnote>
468 <para>At the driver level <function>select()</function> and
469<function>poll()</function> are the same, and
470<function>select()</function> is too important to be optional. The
471rest should be evident.</para>
472 </footnote></para>
473 </section>
474
Tomasz Stanislawski4b9c1cb2012-06-14 10:37:36 -0300475 <section id="dmabuf">
476 <title>Streaming I/O (DMA buffer importing)</title>
477
478 <note>
479 <title>Experimental</title>
Hans Verkuil07b64b82013-01-11 08:18:55 -0300480 <para>This is an <link linkend="experimental">experimental</link>
Tomasz Stanislawski4b9c1cb2012-06-14 10:37:36 -0300481 interface and may change in the future.</para>
482 </note>
483
484<para>The DMABUF framework provides a generic method for sharing buffers
485between multiple devices. Device drivers that support DMABUF can export a DMA
486buffer to userspace as a file descriptor (known as the exporter role), import a
487DMA buffer from userspace using a file descriptor previously exported for a
488different or the same device (known as the importer role), or both. This
489section describes the DMABUF importer role API in V4L2.</para>
490
Hans Verkuil07b64b82013-01-11 08:18:55 -0300491 <para>Refer to <link linkend="vidioc-expbuf">DMABUF exporting</link> for
Tomasz Stanislawski19b6ef52012-06-14 11:32:22 -0300492details about exporting V4L2 buffers as DMABUF file descriptors.</para>
493
Tomasz Stanislawski4b9c1cb2012-06-14 10:37:36 -0300494<para>Input and output devices support the streaming I/O method when the
495<constant>V4L2_CAP_STREAMING</constant> flag in the
496<structfield>capabilities</structfield> field of &v4l2-capability; returned by
497the &VIDIOC-QUERYCAP; ioctl is set. Whether importing DMA buffers through
498DMABUF file descriptors is supported is determined by calling the
499&VIDIOC-REQBUFS; ioctl with the memory type set to
500<constant>V4L2_MEMORY_DMABUF</constant>.</para>
501
502 <para>This I/O method is dedicated to sharing DMA buffers between different
503devices, which may be V4L devices or other video-related devices (e.g. DRM).
504Buffers (planes) are allocated by a driver on behalf of an application. Next,
505these buffers are exported to the application as file descriptors using an API
506which is specific for an allocator driver. Only such file descriptor are
507exchanged. The descriptors and meta-information are passed in &v4l2-buffer; (or
508in &v4l2-plane; in the multi-planar API case). The driver must be switched
509into DMABUF I/O mode by calling the &VIDIOC-REQBUFS; with the desired buffer
510type.</para>
511
512 <example>
513 <title>Initiating streaming I/O with DMABUF file descriptors</title>
514
515 <programlisting>
516&v4l2-requestbuffers; reqbuf;
517
518memset(&amp;reqbuf, 0, sizeof (reqbuf));
519reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
520reqbuf.memory = V4L2_MEMORY_DMABUF;
521reqbuf.count = 1;
522
523if (ioctl(fd, &VIDIOC-REQBUFS;, &amp;reqbuf) == -1) {
524 if (errno == EINVAL)
525 printf("Video capturing or DMABUF streaming is not supported\n");
526 else
527 perror("VIDIOC_REQBUFS");
528
529 exit(EXIT_FAILURE);
530}
531 </programlisting>
532 </example>
533
534 <para>The buffer (plane) file descriptor is passed on the fly with the
535&VIDIOC-QBUF; ioctl. In case of multiplanar buffers, every plane can be
536associated with a different DMABUF descriptor. Although buffers are commonly
537cycled, applications can pass a different DMABUF descriptor at each
538<constant>VIDIOC_QBUF</constant> call.</para>
539
540 <example>
541 <title>Queueing DMABUF using single plane API</title>
542
543 <programlisting>
544int buffer_queue(int v4lfd, int index, int dmafd)
545{
546 &v4l2-buffer; buf;
547
548 memset(&amp;buf, 0, sizeof buf);
549 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
550 buf.memory = V4L2_MEMORY_DMABUF;
551 buf.index = index;
552 buf.m.fd = dmafd;
553
554 if (ioctl(v4lfd, &VIDIOC-QBUF;, &amp;buf) == -1) {
555 perror("VIDIOC_QBUF");
556 return -1;
557 }
558
559 return 0;
560}
561 </programlisting>
562 </example>
563
564 <example>
565 <title>Queueing DMABUF using multi plane API</title>
566
567 <programlisting>
568int buffer_queue_mp(int v4lfd, int index, int dmafd[], int n_planes)
569{
570 &v4l2-buffer; buf;
571 &v4l2-plane; planes[VIDEO_MAX_PLANES];
572 int i;
573
574 memset(&amp;buf, 0, sizeof buf);
575 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
576 buf.memory = V4L2_MEMORY_DMABUF;
577 buf.index = index;
578 buf.m.planes = planes;
579 buf.length = n_planes;
580
581 memset(&amp;planes, 0, sizeof planes);
582
583 for (i = 0; i &lt; n_planes; ++i)
584 buf.m.planes[i].m.fd = dmafd[i];
585
586 if (ioctl(v4lfd, &VIDIOC-QBUF;, &amp;buf) == -1) {
587 perror("VIDIOC_QBUF");
588 return -1;
589 }
590
591 return 0;
592}
593 </programlisting>
594 </example>
595
596 <para>Captured or displayed buffers are dequeued with the
597&VIDIOC-DQBUF; ioctl. The driver can unlock the buffer at any
598time between the completion of the DMA and this ioctl. The memory is
599also unlocked when &VIDIOC-STREAMOFF; is called, &VIDIOC-REQBUFS;, or
600when the device is closed.</para>
601
602 <para>For capturing applications it is customary to enqueue a
603number of empty buffers, to start capturing and enter the read loop.
604Here the application waits until a filled buffer can be dequeued, and
605re-enqueues the buffer when the data is no longer needed. Output
606applications fill and enqueue buffers, when enough buffers are stacked
607up output is started. In the write loop, when the application
608runs out of free buffers it must wait until an empty buffer can be
609dequeued and reused. Two methods exist to suspend execution of the
610application until one or more buffers can be dequeued. By default
611<constant>VIDIOC_DQBUF</constant> blocks when no buffer is in the
612outgoing queue. When the <constant>O_NONBLOCK</constant> flag was
613given to the &func-open; function, <constant>VIDIOC_DQBUF</constant>
614returns immediately with an &EAGAIN; when no buffer is available. The
615&func-select; and &func-poll; functions are always available.</para>
616
617 <para>To start and stop capturing or displaying applications call the
618&VIDIOC-STREAMON; and &VIDIOC-STREAMOFF; ioctls. Note that
619<constant>VIDIOC_STREAMOFF</constant> removes all buffers from both queues and
620unlocks all buffers as a side effect. Since there is no notion of doing
621anything "now" on a multitasking system, if an application needs to synchronize
622with another event it should examine the &v4l2-buffer;
Sakari Ailusc6c09212013-01-25 15:00:07 -0300623<structfield>timestamp</structfield> of captured or outputted buffers.</para>
Tomasz Stanislawski4b9c1cb2012-06-14 10:37:36 -0300624
625 <para>Drivers implementing DMABUF importing I/O must support the
626<constant>VIDIOC_REQBUFS</constant>, <constant>VIDIOC_QBUF</constant>,
627<constant>VIDIOC_DQBUF</constant>, <constant>VIDIOC_STREAMON</constant> and
628<constant>VIDIOC_STREAMOFF</constant> ioctls, and the
629<function>select()</function> and <function>poll()</function> functions.</para>
630
631 </section>
632
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300633 <section id="async">
634 <title>Asynchronous I/O</title>
635
636 <para>This method is not defined yet.</para>
637 </section>
638
639 <section id="buffer">
640 <title>Buffers</title>
641
642 <para>A buffer contains data exchanged by application and
Pawel Osciak53b5d572011-01-07 01:41:33 -0300643driver using one of the Streaming I/O methods. In the multi-planar API, the
644data is held in planes, while the buffer structure acts as a container
645for the planes. Only pointers to buffers (planes) are exchanged, the data
646itself is not copied. These pointers, together with meta-information like
647timestamps or field parity, are stored in a struct
648<structname>v4l2_buffer</structname>, argument to
649the &VIDIOC-QUERYBUF;, &VIDIOC-QBUF; and &VIDIOC-DQBUF; ioctl.
650In the multi-planar API, some plane-specific members of struct
651<structname>v4l2_buffer</structname>, such as pointers and sizes for each
652plane, are stored in struct <structname>v4l2_plane</structname> instead.
653In that case, struct <structname>v4l2_buffer</structname> contains an array of
654plane structures.</para>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300655
Sakari Ailusc6c09212013-01-25 15:00:07 -0300656 <para>For timestamp types that are sampled from the system clock
657(V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC) it is guaranteed that the timestamp is
658taken after the complete frame has been received (or transmitted in
659case of video output devices). For other kinds of
660timestamps this may vary depending on the driver.</para>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300661
662 <table frame="none" pgwide="1" id="v4l2-buffer">
663 <title>struct <structname>v4l2_buffer</structname></title>
664 <tgroup cols="4">
665 &cs-ustr;
666 <tbody valign="top">
667 <row>
668 <entry>__u32</entry>
669 <entry><structfield>index</structfield></entry>
670 <entry></entry>
671 <entry>Number of the buffer, set by the application. This
672field is only used for <link linkend="mmap">memory mapping</link> I/O
673and can range from zero to the number of buffers allocated
674with the &VIDIOC-REQBUFS; ioctl (&v4l2-requestbuffers; <structfield>count</structfield>) minus one.</entry>
675 </row>
676 <row>
Sakari Ailus6016af82012-05-10 02:02:07 -0300677 <entry>__u32</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300678 <entry><structfield>type</structfield></entry>
679 <entry></entry>
680 <entry>Type of the buffer, same as &v4l2-format;
681<structfield>type</structfield> or &v4l2-requestbuffers;
Sakari Ailus6016af82012-05-10 02:02:07 -0300682<structfield>type</structfield>, set by the application. See <xref
683linkend="v4l2-buf-type" /></entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300684 </row>
685 <row>
686 <entry>__u32</entry>
687 <entry><structfield>bytesused</structfield></entry>
688 <entry></entry>
689 <entry>The number of bytes occupied by the data in the
690buffer. It depends on the negotiated data format and may change with
691each buffer for compressed variable size data like JPEG images.
692Drivers must set this field when <structfield>type</structfield>
693refers to an input stream, applications when an output stream.</entry>
694 </row>
695 <row>
696 <entry>__u32</entry>
697 <entry><structfield>flags</structfield></entry>
698 <entry></entry>
699 <entry>Flags set by the application or driver, see <xref
700linkend="buffer-flags" />.</entry>
701 </row>
702 <row>
Sakari Ailus6016af82012-05-10 02:02:07 -0300703 <entry>__u32</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300704 <entry><structfield>field</structfield></entry>
705 <entry></entry>
706 <entry>Indicates the field order of the image in the
707buffer, see <xref linkend="v4l2-field" />. This field is not used when
708the buffer contains VBI data. Drivers must set it when
709<structfield>type</structfield> refers to an input stream,
710applications when an output stream.</entry>
711 </row>
712 <row>
713 <entry>struct timeval</entry>
714 <entry><structfield>timestamp</structfield></entry>
715 <entry></entry>
Sakari Ailus1202ecd2012-10-21 16:02:47 -0300716 <entry><para>For input streams this is time when the first data
717 byte was captured, as returned by the
718 <function>clock_gettime()</function> function for the relevant
719 clock id; see <constant>V4L2_BUF_FLAG_TIMESTAMP_*</constant> in
Sakari Ailusc6c09212013-01-25 15:00:07 -0300720 <xref linkend="buffer-flags" />. For output streams the driver
721 stores the time at which the last data byte was actually sent out
722 in the <structfield>timestamp</structfield> field. This permits
Sakari Ailus1202ecd2012-10-21 16:02:47 -0300723 applications to monitor the drift between the video and system
724 clock.</para></entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300725 </row>
726 <row>
727 <entry>&v4l2-timecode;</entry>
728 <entry><structfield>timecode</structfield></entry>
729 <entry></entry>
730 <entry>When <structfield>type</structfield> is
731<constant>V4L2_BUF_TYPE_VIDEO_CAPTURE</constant> and the
732<constant>V4L2_BUF_FLAG_TIMECODE</constant> flag is set in
733<structfield>flags</structfield>, this structure contains a frame
734timecode. In <link linkend="v4l2-field">V4L2_FIELD_ALTERNATE</link>
735mode the top and bottom field contain the same timecode.
736Timecodes are intended to help video editing and are typically recorded on
737video tapes, but also embedded in compressed formats like MPEG. This
738field is independent of the <structfield>timestamp</structfield> and
739<structfield>sequence</structfield> fields.</entry>
740 </row>
741 <row>
742 <entry>__u32</entry>
743 <entry><structfield>sequence</structfield></entry>
744 <entry></entry>
Hans Verkuil0b1f8142012-09-04 07:07:54 -0300745 <entry>Set by the driver, counting the frames (not fields!) in
746sequence. This field is set for both input and output devices.</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300747 </row>
748 <row>
749 <entry spanname="hspan"><para>In <link
750linkend="v4l2-field">V4L2_FIELD_ALTERNATE</link> mode the top and
751bottom field have the same sequence number. The count starts at zero
752and includes dropped or repeated frames. A dropped frame was received
753by an input device but could not be stored due to lack of free buffer
754space. A repeated frame was displayed again by an output device
755because the application did not pass new data in
756time.</para><para>Note this may count the frames received
757e.g. over USB, without taking into account the frames dropped by the
758remote hardware due to limited compression throughput or bus
759bandwidth. These devices identify by not enumerating any video
760standards, see <xref linkend="standard" />.</para></entry>
761 </row>
762 <row>
Sakari Ailus6016af82012-05-10 02:02:07 -0300763 <entry>__u32</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300764 <entry><structfield>memory</structfield></entry>
765 <entry></entry>
766 <entry>This field must be set by applications and/or drivers
Sakari Ailus6016af82012-05-10 02:02:07 -0300767in accordance with the selected I/O method. See <xref linkend="v4l2-memory"
768 /></entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300769 </row>
770 <row>
771 <entry>union</entry>
772 <entry><structfield>m</structfield></entry>
773 </row>
774 <row>
775 <entry></entry>
776 <entry>__u32</entry>
777 <entry><structfield>offset</structfield></entry>
Pawel Osciak53b5d572011-01-07 01:41:33 -0300778 <entry>For the single-planar API and when
779<structfield>memory</structfield> is <constant>V4L2_MEMORY_MMAP</constant> this
780is the offset of the buffer from the start of the device memory. The value is
781returned by the driver and apart of serving as parameter to the &func-mmap;
782function not useful for applications. See <xref linkend="mmap" /> for details
783 </entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300784 </row>
785 <row>
786 <entry></entry>
787 <entry>unsigned long</entry>
788 <entry><structfield>userptr</structfield></entry>
Pawel Osciak53b5d572011-01-07 01:41:33 -0300789 <entry>For the single-planar API and when
790<structfield>memory</structfield> is <constant>V4L2_MEMORY_USERPTR</constant>
791this is a pointer to the buffer (casted to unsigned long type) in virtual
792memory, set by the application. See <xref linkend="userp" /> for details.
793 </entry>
794 </row>
795 <row>
796 <entry></entry>
797 <entry>struct v4l2_plane</entry>
798 <entry><structfield>*planes</structfield></entry>
799 <entry>When using the multi-planar API, contains a userspace pointer
800 to an array of &v4l2-plane;. The size of the array should be put
801 in the <structfield>length</structfield> field of this
802 <structname>v4l2_buffer</structname> structure.</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300803 </row>
804 <row>
Tomasz Stanislawski4b9c1cb2012-06-14 10:37:36 -0300805 <entry></entry>
806 <entry>int</entry>
807 <entry><structfield>fd</structfield></entry>
808 <entry>For the single-plane API and when
809<structfield>memory</structfield> is <constant>V4L2_MEMORY_DMABUF</constant> this
810is the file descriptor associated with a DMABUF buffer.</entry>
811 </row>
812 <row>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300813 <entry>__u32</entry>
814 <entry><structfield>length</structfield></entry>
815 <entry></entry>
Pawel Osciak53b5d572011-01-07 01:41:33 -0300816 <entry>Size of the buffer (not the payload) in bytes for the
Hans Verkuile3b1b4e2012-09-19 11:14:39 -0300817 single-planar API. For the multi-planar API the application sets
818 this to the number of elements in the <structfield>planes</structfield>
819 array. The driver will fill in the actual number of valid elements in
820 that array.
Pawel Osciak53b5d572011-01-07 01:41:33 -0300821 </entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300822 </row>
823 <row>
824 <entry>__u32</entry>
Sakari Ailus2b719d72012-05-02 09:40:03 -0300825 <entry><structfield>reserved2</structfield></entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300826 <entry></entry>
Hans Verkuil9495356f2012-09-03 10:09:23 -0300827 <entry>A place holder for future extensions. Applications
Sakari Ailus2b719d72012-05-02 09:40:03 -0300828should set this to 0.</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300829 </row>
830 <row>
831 <entry>__u32</entry>
832 <entry><structfield>reserved</structfield></entry>
833 <entry></entry>
Hans Verkuil9495356f2012-09-03 10:09:23 -0300834 <entry>A place holder for future extensions. Applications
Hans Verkuil995f5fe2010-02-20 09:41:03 -0300835should set this to 0.</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300836 </row>
837 </tbody>
838 </tgroup>
839 </table>
840
Pawel Osciak53b5d572011-01-07 01:41:33 -0300841 <table frame="none" pgwide="1" id="v4l2-plane">
842 <title>struct <structname>v4l2_plane</structname></title>
843 <tgroup cols="4">
844 &cs-ustr;
845 <tbody valign="top">
846 <row>
847 <entry>__u32</entry>
848 <entry><structfield>bytesused</structfield></entry>
849 <entry></entry>
850 <entry>The number of bytes occupied by data in the plane
851 (its payload).</entry>
852 </row>
853 <row>
854 <entry>__u32</entry>
855 <entry><structfield>length</structfield></entry>
856 <entry></entry>
857 <entry>Size in bytes of the plane (not its payload).</entry>
858 </row>
859 <row>
860 <entry>union</entry>
861 <entry><structfield>m</structfield></entry>
862 <entry></entry>
863 <entry></entry>
864 </row>
865 <row>
866 <entry></entry>
867 <entry>__u32</entry>
868 <entry><structfield>mem_offset</structfield></entry>
869 <entry>When the memory type in the containing &v4l2-buffer; is
870 <constant>V4L2_MEMORY_MMAP</constant>, this is the value that
871 should be passed to &func-mmap;, similar to the
872 <structfield>offset</structfield> field in &v4l2-buffer;.</entry>
873 </row>
874 <row>
875 <entry></entry>
Sakari Ailusfe4abb52012-11-16 17:42:12 -0300876 <entry>unsigned long</entry>
Pawel Osciak53b5d572011-01-07 01:41:33 -0300877 <entry><structfield>userptr</structfield></entry>
878 <entry>When the memory type in the containing &v4l2-buffer; is
879 <constant>V4L2_MEMORY_USERPTR</constant>, this is a userspace
880 pointer to the memory allocated for this plane by an application.
881 </entry>
882 </row>
883 <row>
Tomasz Stanislawski4b9c1cb2012-06-14 10:37:36 -0300884 <entry></entry>
885 <entry>int</entry>
886 <entry><structfield>fd</structfield></entry>
887 <entry>When the memory type in the containing &v4l2-buffer; is
888 <constant>V4L2_MEMORY_DMABUF</constant>, this is a file
889 descriptor associated with a DMABUF buffer, similar to the
890 <structfield>fd</structfield> field in &v4l2-buffer;.</entry>
891 </row>
892 <row>
Pawel Osciak53b5d572011-01-07 01:41:33 -0300893 <entry>__u32</entry>
894 <entry><structfield>data_offset</structfield></entry>
895 <entry></entry>
896 <entry>Offset in bytes to video data in the plane, if applicable.
897 </entry>
898 </row>
899 <row>
900 <entry>__u32</entry>
901 <entry><structfield>reserved[11]</structfield></entry>
902 <entry></entry>
903 <entry>Reserved for future use. Should be zeroed by an
904 application.</entry>
905 </row>
906 </tbody>
907 </tgroup>
908 </table>
909
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300910 <table frame="none" pgwide="1" id="v4l2-buf-type">
911 <title>enum v4l2_buf_type</title>
912 <tgroup cols="3">
913 &cs-def;
914 <tbody valign="top">
915 <row>
916 <entry><constant>V4L2_BUF_TYPE_VIDEO_CAPTURE</constant></entry>
917 <entry>1</entry>
Pawel Osciak53b5d572011-01-07 01:41:33 -0300918 <entry>Buffer of a single-planar video capture stream, see <xref
919 linkend="capture" />.</entry>
920 </row>
921 <row>
922 <entry><constant>V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE</constant>
923 </entry>
924 <entry>9</entry>
925 <entry>Buffer of a multi-planar video capture stream, see <xref
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300926 linkend="capture" />.</entry>
927 </row>
928 <row>
929 <entry><constant>V4L2_BUF_TYPE_VIDEO_OUTPUT</constant></entry>
930 <entry>2</entry>
Pawel Osciak53b5d572011-01-07 01:41:33 -0300931 <entry>Buffer of a single-planar video output stream, see <xref
932 linkend="output" />.</entry>
933 </row>
934 <row>
935 <entry><constant>V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE</constant>
936 </entry>
937 <entry>10</entry>
938 <entry>Buffer of a multi-planar video output stream, see <xref
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300939 linkend="output" />.</entry>
940 </row>
941 <row>
942 <entry><constant>V4L2_BUF_TYPE_VIDEO_OVERLAY</constant></entry>
943 <entry>3</entry>
944 <entry>Buffer for video overlay, see <xref linkend="overlay" />.</entry>
945 </row>
946 <row>
947 <entry><constant>V4L2_BUF_TYPE_VBI_CAPTURE</constant></entry>
948 <entry>4</entry>
949 <entry>Buffer of a raw VBI capture stream, see <xref
950 linkend="raw-vbi" />.</entry>
951 </row>
952 <row>
953 <entry><constant>V4L2_BUF_TYPE_VBI_OUTPUT</constant></entry>
954 <entry>5</entry>
955 <entry>Buffer of a raw VBI output stream, see <xref
956 linkend="raw-vbi" />.</entry>
957 </row>
958 <row>
959 <entry><constant>V4L2_BUF_TYPE_SLICED_VBI_CAPTURE</constant></entry>
960 <entry>6</entry>
961 <entry>Buffer of a sliced VBI capture stream, see <xref
962 linkend="sliced" />.</entry>
963 </row>
964 <row>
965 <entry><constant>V4L2_BUF_TYPE_SLICED_VBI_OUTPUT</constant></entry>
966 <entry>7</entry>
967 <entry>Buffer of a sliced VBI output stream, see <xref
968 linkend="sliced" />.</entry>
969 </row>
970 <row>
971 <entry><constant>V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY</constant></entry>
972 <entry>8</entry>
973 <entry>Buffer for video output overlay (OSD), see <xref
Sakari Ailus8fd207a2012-09-02 03:45:45 -0300974 linkend="osd" />.</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300975 </row>
Antti Palosaari559f40f2013-12-20 01:50:38 -0300976 <row>
977 <entry><constant>V4L2_BUF_TYPE_SDR_CAPTURE</constant></entry>
978 <entry>11</entry>
979 <entry>Buffer for Software Defined Radio (SDR), see <xref
980 linkend="sdr" />.</entry>
981 </row>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300982 </tbody>
983 </tgroup>
984 </table>
985
986 <table frame="none" pgwide="1" id="buffer-flags">
987 <title>Buffer Flags</title>
988 <tgroup cols="3">
989 &cs-def;
990 <tbody valign="top">
991 <row>
992 <entry><constant>V4L2_BUF_FLAG_MAPPED</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -0300993 <entry>0x00000001</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -0300994 <entry>The buffer resides in device memory and has been mapped
995into the application's address space, see <xref linkend="mmap" /> for details.
996Drivers set or clear this flag when the
997<link linkend="vidioc-querybuf">VIDIOC_QUERYBUF</link>, <link
998 linkend="vidioc-qbuf">VIDIOC_QBUF</link> or <link
999 linkend="vidioc-qbuf">VIDIOC_DQBUF</link> ioctl is called. Set by the driver.</entry>
1000 </row>
1001 <row>
1002 <entry><constant>V4L2_BUF_FLAG_QUEUED</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001003 <entry>0x00000002</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001004 <entry>Internally drivers maintain two buffer queues, an
1005incoming and outgoing queue. When this flag is set, the buffer is
1006currently on the incoming queue. It automatically moves to the
1007outgoing queue after the buffer has been filled (capture devices) or
1008displayed (output devices). Drivers set or clear this flag when the
1009<constant>VIDIOC_QUERYBUF</constant> ioctl is called. After
1010(successful) calling the <constant>VIDIOC_QBUF </constant>ioctl it is
1011always set and after <constant>VIDIOC_DQBUF</constant> always
1012cleared.</entry>
1013 </row>
1014 <row>
1015 <entry><constant>V4L2_BUF_FLAG_DONE</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001016 <entry>0x00000004</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001017 <entry>When this flag is set, the buffer is currently on
1018the outgoing queue, ready to be dequeued from the driver. Drivers set
1019or clear this flag when the <constant>VIDIOC_QUERYBUF</constant> ioctl
1020is called. After calling the <constant>VIDIOC_QBUF</constant> or
1021<constant>VIDIOC_DQBUF</constant> it is always cleared. Of course a
1022buffer cannot be on both queues at the same time, the
1023<constant>V4L2_BUF_FLAG_QUEUED</constant> and
1024<constant>V4L2_BUF_FLAG_DONE</constant> flag are mutually exclusive.
1025They can be both cleared however, then the buffer is in "dequeued"
1026state, in the application domain to say so.</entry>
1027 </row>
1028 <row>
Pawel Osciak21636362010-04-28 04:05:23 -03001029 <entry><constant>V4L2_BUF_FLAG_ERROR</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001030 <entry>0x00000040</entry>
Pawel Osciak21636362010-04-28 04:05:23 -03001031 <entry>When this flag is set, the buffer has been dequeued
1032 successfully, although the data might have been corrupted.
1033 This is recoverable, streaming may continue as normal and
1034 the buffer may be reused normally.
1035 Drivers set this flag when the <constant>VIDIOC_DQBUF</constant>
1036 ioctl is called.</entry>
1037 </row>
1038 <row>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001039 <entry><constant>V4L2_BUF_FLAG_KEYFRAME</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001040 <entry>0x00000008</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001041 <entry>Drivers set or clear this flag when calling the
1042<constant>VIDIOC_DQBUF</constant> ioctl. It may be set by video
1043capture devices when the buffer contains a compressed image which is a
1044key frame (or field), &ie; can be decompressed on its own.</entry>
1045 </row>
1046 <row>
1047 <entry><constant>V4L2_BUF_FLAG_PFRAME</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001048 <entry>0x00000010</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001049 <entry>Similar to <constant>V4L2_BUF_FLAG_KEYFRAME</constant>
1050this flags predicted frames or fields which contain only differences to a
1051previous key frame.</entry>
1052 </row>
1053 <row>
1054 <entry><constant>V4L2_BUF_FLAG_BFRAME</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001055 <entry>0x00000020</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001056 <entry>Similar to <constant>V4L2_BUF_FLAG_PFRAME</constant>
1057 this is a bidirectional predicted frame or field. [ooc tbd]</entry>
1058 </row>
1059 <row>
1060 <entry><constant>V4L2_BUF_FLAG_TIMECODE</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001061 <entry>0x00000100</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001062 <entry>The <structfield>timecode</structfield> field is valid.
1063Drivers set or clear this flag when the <constant>VIDIOC_DQBUF</constant>
1064ioctl is called.</entry>
1065 </row>
1066 <row>
Guennadi Liakhovetski55093282011-09-28 08:10:58 -03001067 <entry><constant>V4L2_BUF_FLAG_PREPARED</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001068 <entry>0x00000400</entry>
Guennadi Liakhovetski55093282011-09-28 08:10:58 -03001069 <entry>The buffer has been prepared for I/O and can be queued by the
1070application. Drivers set or clear this flag when the
1071<link linkend="vidioc-querybuf">VIDIOC_QUERYBUF</link>, <link
1072 linkend="vidioc-qbuf">VIDIOC_PREPARE_BUF</link>, <link
1073 linkend="vidioc-qbuf">VIDIOC_QBUF</link> or <link
1074 linkend="vidioc-qbuf">VIDIOC_DQBUF</link> ioctl is called.</entry>
1075 </row>
1076 <row>
1077 <entry><constant>V4L2_BUF_FLAG_NO_CACHE_INVALIDATE</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001078 <entry>0x00000800</entry>
Guennadi Liakhovetski55093282011-09-28 08:10:58 -03001079 <entry>Caches do not have to be invalidated for this buffer.
1080Typically applications shall use this flag if the data captured in the buffer
1081is not going to be touched by the CPU, instead the buffer will, probably, be
1082passed on to a DMA-capable hardware unit for further processing or output.
1083</entry>
1084 </row>
1085 <row>
1086 <entry><constant>V4L2_BUF_FLAG_NO_CACHE_CLEAN</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001087 <entry>0x00001000</entry>
Guennadi Liakhovetski55093282011-09-28 08:10:58 -03001088 <entry>Caches do not have to be cleaned for this buffer.
1089Typically applications shall use this flag for output buffers if the data
1090in this buffer has not been created by the CPU but by some DMA-capable unit,
1091in which case caches have not been used.</entry>
1092 </row>
Sakari Ailus1202ecd2012-10-21 16:02:47 -03001093 <row>
1094 <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_MASK</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001095 <entry>0x0000e000</entry>
Sakari Ailus1202ecd2012-10-21 16:02:47 -03001096 <entry>Mask for timestamp types below. To test the
1097 timestamp type, mask out bits not belonging to timestamp
1098 type by performing a logical and operation with buffer
1099 flags and timestamp mask.</entry>
1100 </row>
1101 <row>
1102 <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001103 <entry>0x00000000</entry>
Sakari Ailus1202ecd2012-10-21 16:02:47 -03001104 <entry>Unknown timestamp type. This type is used by
1105 drivers before Linux 3.9 and may be either monotonic (see
1106 below) or realtime (wall clock). Monotonic clock has been
1107 favoured in embedded systems whereas most of the drivers
1108 use the realtime clock. Either kinds of timestamps are
1109 available in user space via
1110 <function>clock_gettime(2)</function> using clock IDs
1111 <constant>CLOCK_MONOTONIC</constant> and
1112 <constant>CLOCK_REALTIME</constant>, respectively.</entry>
1113 </row>
1114 <row>
1115 <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001116 <entry>0x00002000</entry>
Sakari Ailus1202ecd2012-10-21 16:02:47 -03001117 <entry>The buffer timestamp has been taken from the
1118 <constant>CLOCK_MONOTONIC</constant> clock. To access the
1119 same clock outside V4L2, use
1120 <function>clock_gettime(2)</function> .</entry>
1121 </row>
Kamil Debski53bf0f42013-01-25 06:29:56 -03001122 <row>
1123 <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_COPY</constant></entry>
Sakari Ailus939f1372013-08-25 14:00:43 -03001124 <entry>0x00004000</entry>
Kamil Debski53bf0f42013-01-25 06:29:56 -03001125 <entry>The CAPTURE buffer timestamp has been taken from the
1126 corresponding OUTPUT buffer. This flag applies only to mem2mem devices.</entry>
1127 </row>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001128 </tbody>
1129 </tgroup>
1130 </table>
1131
1132 <table pgwide="1" frame="none" id="v4l2-memory">
1133 <title>enum v4l2_memory</title>
1134 <tgroup cols="3">
1135 &cs-def;
1136 <tbody valign="top">
1137 <row>
1138 <entry><constant>V4L2_MEMORY_MMAP</constant></entry>
1139 <entry>1</entry>
1140 <entry>The buffer is used for <link linkend="mmap">memory
1141mapping</link> I/O.</entry>
1142 </row>
1143 <row>
1144 <entry><constant>V4L2_MEMORY_USERPTR</constant></entry>
1145 <entry>2</entry>
1146 <entry>The buffer is used for <link linkend="userp">user
1147pointer</link> I/O.</entry>
1148 </row>
1149 <row>
1150 <entry><constant>V4L2_MEMORY_OVERLAY</constant></entry>
1151 <entry>3</entry>
1152 <entry>[to do]</entry>
1153 </row>
Tomasz Stanislawski4b9c1cb2012-06-14 10:37:36 -03001154 <row>
1155 <entry><constant>V4L2_MEMORY_DMABUF</constant></entry>
1156 <entry>4</entry>
1157 <entry>The buffer is used for <link linkend="dmabuf">DMA shared
1158buffer</link> I/O.</entry>
1159 </row>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001160 </tbody>
1161 </tgroup>
1162 </table>
1163
1164 <section>
1165 <title>Timecodes</title>
1166
1167 <para>The <structname>v4l2_timecode</structname> structure is
1168designed to hold a <xref linkend="smpte12m" /> or similar timecode.
1169(struct <structname>timeval</structname> timestamps are stored in
1170&v4l2-buffer; field <structfield>timestamp</structfield>.)</para>
1171
1172 <table frame="none" pgwide="1" id="v4l2-timecode">
1173 <title>struct <structname>v4l2_timecode</structname></title>
1174 <tgroup cols="3">
1175 &cs-str;
1176 <tbody valign="top">
1177 <row>
1178 <entry>__u32</entry>
1179 <entry><structfield>type</structfield></entry>
1180 <entry>Frame rate the timecodes are based on, see <xref
1181 linkend="timecode-type" />.</entry>
1182 </row>
1183 <row>
1184 <entry>__u32</entry>
1185 <entry><structfield>flags</structfield></entry>
1186 <entry>Timecode flags, see <xref linkend="timecode-flags" />.</entry>
1187 </row>
1188 <row>
1189 <entry>__u8</entry>
1190 <entry><structfield>frames</structfield></entry>
1191 <entry>Frame count, 0 ... 23/24/29/49/59, depending on the
1192 type of timecode.</entry>
1193 </row>
1194 <row>
1195 <entry>__u8</entry>
1196 <entry><structfield>seconds</structfield></entry>
1197 <entry>Seconds count, 0 ... 59. This is a binary, not BCD number.</entry>
1198 </row>
1199 <row>
1200 <entry>__u8</entry>
1201 <entry><structfield>minutes</structfield></entry>
1202 <entry>Minutes count, 0 ... 59. This is a binary, not BCD number.</entry>
1203 </row>
1204 <row>
1205 <entry>__u8</entry>
1206 <entry><structfield>hours</structfield></entry>
1207 <entry>Hours count, 0 ... 29. This is a binary, not BCD number.</entry>
1208 </row>
1209 <row>
1210 <entry>__u8</entry>
1211 <entry><structfield>userbits</structfield>[4]</entry>
1212 <entry>The "user group" bits from the timecode.</entry>
1213 </row>
1214 </tbody>
1215 </tgroup>
1216 </table>
1217
1218 <table frame="none" pgwide="1" id="timecode-type">
1219 <title>Timecode Types</title>
1220 <tgroup cols="3">
1221 &cs-def;
1222 <tbody valign="top">
1223 <row>
1224 <entry><constant>V4L2_TC_TYPE_24FPS</constant></entry>
1225 <entry>1</entry>
1226 <entry>24 frames per second, i.&nbsp;e. film.</entry>
1227 </row>
1228 <row>
1229 <entry><constant>V4L2_TC_TYPE_25FPS</constant></entry>
1230 <entry>2</entry>
1231 <entry>25 frames per second, &ie; PAL or SECAM video.</entry>
1232 </row>
1233 <row>
1234 <entry><constant>V4L2_TC_TYPE_30FPS</constant></entry>
1235 <entry>3</entry>
1236 <entry>30 frames per second, &ie; NTSC video.</entry>
1237 </row>
1238 <row>
1239 <entry><constant>V4L2_TC_TYPE_50FPS</constant></entry>
1240 <entry>4</entry>
1241 <entry></entry>
1242 </row>
1243 <row>
1244 <entry><constant>V4L2_TC_TYPE_60FPS</constant></entry>
1245 <entry>5</entry>
1246 <entry></entry>
1247 </row>
1248 </tbody>
1249 </tgroup>
1250 </table>
1251
1252 <table frame="none" pgwide="1" id="timecode-flags">
1253 <title>Timecode Flags</title>
1254 <tgroup cols="3">
1255 &cs-def;
1256 <tbody valign="top">
1257 <row>
1258 <entry><constant>V4L2_TC_FLAG_DROPFRAME</constant></entry>
1259 <entry>0x0001</entry>
1260 <entry>Indicates "drop frame" semantics for counting frames
1261in 29.97 fps material. When set, frame numbers 0 and 1 at the start of
1262each minute, except minutes 0, 10, 20, 30, 40, 50 are omitted from the
1263count.</entry>
1264 </row>
1265 <row>
1266 <entry><constant>V4L2_TC_FLAG_COLORFRAME</constant></entry>
1267 <entry>0x0002</entry>
1268 <entry>The "color frame" flag.</entry>
1269 </row>
1270 <row>
1271 <entry><constant>V4L2_TC_USERBITS_field</constant></entry>
1272 <entry>0x000C</entry>
1273 <entry>Field mask for the "binary group flags".</entry>
1274 </row>
1275 <row>
1276 <entry><constant>V4L2_TC_USERBITS_USERDEFINED</constant></entry>
1277 <entry>0x0000</entry>
1278 <entry>Unspecified format.</entry>
1279 </row>
1280 <row>
1281 <entry><constant>V4L2_TC_USERBITS_8BITCHARS</constant></entry>
1282 <entry>0x0008</entry>
1283 <entry>8-bit ISO characters.</entry>
1284 </row>
1285 </tbody>
1286 </tgroup>
1287 </table>
1288 </section>
1289 </section>
1290
1291 <section id="field-order">
1292 <title>Field Order</title>
1293
1294 <para>We have to distinguish between progressive and interlaced
1295video. Progressive video transmits all lines of a video image
1296sequentially. Interlaced video divides an image into two fields,
1297containing only the odd and even lines of the image, respectively.
1298Alternating the so called odd and even field are transmitted, and due
1299to a small delay between fields a cathode ray TV displays the lines
1300interleaved, yielding the original frame. This curious technique was
1301invented because at refresh rates similar to film the image would
1302fade out too quickly. Transmitting fields reduces the flicker without
1303the necessity of doubling the frame rate and with it the bandwidth
1304required for each channel.</para>
1305
1306 <para>It is important to understand a video camera does not expose
1307one frame at a time, merely transmitting the frames separated into
1308fields. The fields are in fact captured at two different instances in
1309time. An object on screen may well move between one field and the
1310next. For applications analysing motion it is of paramount importance
1311to recognize which field of a frame is older, the <emphasis>temporal
1312order</emphasis>.</para>
1313
1314 <para>When the driver provides or accepts images field by field
1315rather than interleaved, it is also important applications understand
Hans Verkuil37089362010-03-27 14:10:37 -03001316how the fields combine to frames. We distinguish between top (aka odd) and
1317bottom (aka even) fields, the <emphasis>spatial order</emphasis>: The first line
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001318of the top field is the first line of an interlaced frame, the first
1319line of the bottom field is the second line of that frame.</para>
1320
1321 <para>However because fields were captured one after the other,
1322arguing whether a frame commences with the top or bottom field is
1323pointless. Any two successive top and bottom, or bottom and top fields
1324yield a valid frame. Only when the source was progressive to begin
1325with, &eg; when transferring film to video, two fields may come from
1326the same frame, creating a natural order.</para>
1327
1328 <para>Counter to intuition the top field is not necessarily the
1329older field. Whether the older field contains the top or bottom lines
1330is a convention determined by the video standard. Hence the
1331distinction between temporal and spatial order of fields. The diagrams
1332below should make this clearer.</para>
1333
1334 <para>All video capture and output devices must report the current
1335field order. Some drivers may permit the selection of a different
1336order, to this end applications initialize the
1337<structfield>field</structfield> field of &v4l2-pix-format; before
1338calling the &VIDIOC-S-FMT; ioctl. If this is not desired it should
1339have the value <constant>V4L2_FIELD_ANY</constant> (0).</para>
1340
1341 <table frame="none" pgwide="1" id="v4l2-field">
1342 <title>enum v4l2_field</title>
1343 <tgroup cols="3">
1344 &cs-def;
1345 <tbody valign="top">
1346 <row>
1347 <entry><constant>V4L2_FIELD_ANY</constant></entry>
1348 <entry>0</entry>
1349 <entry>Applications request this field order when any
1350one of the <constant>V4L2_FIELD_NONE</constant>,
1351<constant>V4L2_FIELD_TOP</constant>,
1352<constant>V4L2_FIELD_BOTTOM</constant>, or
1353<constant>V4L2_FIELD_INTERLACED</constant> formats is acceptable.
1354Drivers choose depending on hardware capabilities or e.&nbsp;g. the
1355requested image size, and return the actual field order. &v4l2-buffer;
1356<structfield>field</structfield> can never be
1357<constant>V4L2_FIELD_ANY</constant>.</entry>
1358 </row>
1359 <row>
1360 <entry><constant>V4L2_FIELD_NONE</constant></entry>
1361 <entry>1</entry>
1362 <entry>Images are in progressive format, not interlaced.
1363The driver may also indicate this order when it cannot distinguish
1364between <constant>V4L2_FIELD_TOP</constant> and
1365<constant>V4L2_FIELD_BOTTOM</constant>.</entry>
1366 </row>
1367 <row>
1368 <entry><constant>V4L2_FIELD_TOP</constant></entry>
1369 <entry>2</entry>
Hans Verkuil37089362010-03-27 14:10:37 -03001370 <entry>Images consist of the top (aka odd) field only.</entry>
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001371 </row>
1372 <row>
1373 <entry><constant>V4L2_FIELD_BOTTOM</constant></entry>
1374 <entry>3</entry>
Hans Verkuil37089362010-03-27 14:10:37 -03001375 <entry>Images consist of the bottom (aka even) field only.
Mauro Carvalho Chehab8e080c22009-09-13 22:16:04 -03001376Applications may wish to prevent a device from capturing interlaced
1377images because they will have "comb" or "feathering" artefacts around
1378moving objects.</entry>
1379 </row>
1380 <row>
1381 <entry><constant>V4L2_FIELD_INTERLACED</constant></entry>
1382 <entry>4</entry>
1383 <entry>Images contain both fields, interleaved line by
1384line. The temporal order of the fields (whether the top or bottom
1385field is first transmitted) depends on the current video standard.
1386M/NTSC transmits the bottom field first, all other standards the top
1387field first.</entry>
1388 </row>
1389 <row>
1390 <entry><constant>V4L2_FIELD_SEQ_TB</constant></entry>
1391 <entry>5</entry>
1392 <entry>Images contain both fields, the top field lines
1393are stored first in memory, immediately followed by the bottom field
1394lines. Fields are always stored in temporal order, the older one first
1395in memory. Image sizes refer to the frame, not fields.</entry>
1396 </row>
1397 <row>
1398 <entry><constant>V4L2_FIELD_SEQ_BT</constant></entry>
1399 <entry>6</entry>
1400 <entry>Images contain both fields, the bottom field
1401lines are stored first in memory, immediately followed by the top
1402field lines. Fields are always stored in temporal order, the older one
1403first in memory. Image sizes refer to the frame, not fields.</entry>
1404 </row>
1405 <row>
1406 <entry><constant>V4L2_FIELD_ALTERNATE</constant></entry>
1407 <entry>7</entry>
1408 <entry>The two fields of a frame are passed in separate
1409buffers, in temporal order, &ie; the older one first. To indicate the field
1410parity (whether the current field is a top or bottom field) the driver
1411or application, depending on data direction, must set &v4l2-buffer;
1412<structfield>field</structfield> to
1413<constant>V4L2_FIELD_TOP</constant> or
1414<constant>V4L2_FIELD_BOTTOM</constant>. Any two successive fields pair
1415to build a frame. If fields are successive, without any dropped fields
1416between them (fields can drop individually), can be determined from
1417the &v4l2-buffer; <structfield>sequence</structfield> field. Image
1418sizes refer to the frame, not fields. This format cannot be selected
1419when using the read/write I/O method.<!-- Where it's indistinguishable
1420from V4L2_FIELD_SEQ_*. --></entry>
1421 </row>
1422 <row>
1423 <entry><constant>V4L2_FIELD_INTERLACED_TB</constant></entry>
1424 <entry>8</entry>
1425 <entry>Images contain both fields, interleaved line by
1426line, top field first. The top field is transmitted first.</entry>
1427 </row>
1428 <row>
1429 <entry><constant>V4L2_FIELD_INTERLACED_BT</constant></entry>
1430 <entry>9</entry>
1431 <entry>Images contain both fields, interleaved line by
1432line, top field first. The bottom field is transmitted first.</entry>
1433 </row>
1434 </tbody>
1435 </tgroup>
1436 </table>
1437
1438 <figure id="fieldseq-tb">
1439 <title>Field Order, Top Field First Transmitted</title>
1440 <mediaobject>
1441 <imageobject>
1442 <imagedata fileref="fieldseq_tb.pdf" format="PS" />
1443 </imageobject>
1444 <imageobject>
1445 <imagedata fileref="fieldseq_tb.gif" format="GIF" />
1446 </imageobject>
1447 </mediaobject>
1448 </figure>
1449
1450 <figure id="fieldseq-bt">
1451 <title>Field Order, Bottom Field First Transmitted</title>
1452 <mediaobject>
1453 <imageobject>
1454 <imagedata fileref="fieldseq_bt.pdf" format="PS" />
1455 </imageobject>
1456 <imageobject>
1457 <imagedata fileref="fieldseq_bt.gif" format="GIF" />
1458 </imageobject>
1459 </mediaobject>
1460 </figure>
1461 </section>