io.xml 63 KB

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