<?xml version="1.0" encoding="ANSI_X3.4-1968" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968" /><title>ioctl VIDIOC_REQBUFS</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><link rel="home" href="index.html" title="LINUX MEDIA INFRASTRUCTURE API" /><link rel="up" href="apa.html" title="Appendix A. Function Reference" /><link rel="prev" href="re58.html" title="ioctl VIDIOC_QUERYSTD" /><link rel="next" href="re60.html" title="ioctl VIDIOC_S_HW_FREQ_SEEK" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">ioctl VIDIOC_REQBUFS</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="re58.html">Prev</a> </td><th width="60%" align="center">Appendix A. Function Reference</th><td width="20%" align="right"> <a accesskey="n" href="re60.html">Next</a></td></tr></table><hr /></div><div class="refentry" title="ioctl VIDIOC_REQBUFS"><a id="vidioc-reqbufs"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>VIDIOC_REQBUFS — Initiate Memory Mapping or User Pointer I/O</p></div><div class="refsynopsisdiv" title="Synopsis"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table"><tr><td><code class="funcdef">int <b class="fsfunc">ioctl</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">request</var>, </td></tr><tr><td> </td><td>struct v4l2_requestbuffers *<var class="pdparam">argp</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1" title="Arguments"><a id="id2736292"></a><h2>Arguments</h2><div class="variablelist"><dl><dt><span class="term"><em class="parameter"><code>fd</code></em></span></dt><dd><p>File descriptor returned by <a class="link" href="re64.html" title="V4L2 open()"><code class="function">open()</code></a>.</p></dd><dt><span class="term"><em class="parameter"><code>request</code></em></span></dt><dd><p>VIDIOC_REQBUFS</p></dd><dt><span class="term"><em class="parameter"><code>argp</code></em></span></dt><dd><p></p></dd></dl></div></div><div class="refsect1" title="Description"><a id="id2736360"></a><h2>Description</h2><p>This ioctl is used to initiate <a class="link" href="ch03s02.html" title="Streaming I/O (Memory Mapping)">memory mapped</a> or <a class="link" href="ch03s03.html" title="Streaming I/O (User Pointers)">user pointer</a> I/O. Memory mapped buffers are located in device memory and must be allocated with this ioctl before they can be mapped into the application's address space. User buffers are allocated by applications themselves, and this ioctl is merely used to switch the driver into user pointer I/O mode.</p><p>To allocate device buffers applications initialize three fields of a <span class="structname">v4l2_requestbuffers</span> structure. They set the <em class="structfield"><code>type</code></em> field to the respective stream or buffer type, the <em class="structfield"><code>count</code></em> field to the desired number of buffers, and <em class="structfield"><code>memory</code></em> must be set to <code class="constant">V4L2_MEMORY_MMAP</code>. When the ioctl is called with a pointer to this structure the driver attempts to allocate the requested number of buffers and stores the actual number allocated in the <em class="structfield"><code>count</code></em> field. It can be smaller than the number requested, even zero, when the driver runs out of free memory. A larger number is possible when the driver requires more buffers to function correctly.<sup>[<a id="id2736422" href="#ftn.id2736422" class="footnote">26</a>]</sup> When memory mapping I/O is not supported the ioctl returns an <span class="errorcode">EINVAL</span> error code.</p><p>Applications can call <code class="constant">VIDIOC_REQBUFS</code> again to change the number of buffers, however this cannot succeed when any buffers are still mapped. A <em class="structfield"><code>count</code></em> value of zero frees all buffers, after aborting or finishing any DMA in progress, an implicit <a class="link" href="re61.html" title="ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF"><code class="constant">VIDIOC_STREAMOFF</code></a>. </p><p>To negotiate user pointer I/O, applications initialize only the <em class="structfield"><code>type</code></em> field and set <em class="structfield"><code>memory</code></em> to <code class="constant">V4L2_MEMORY_USERPTR</code>. When the ioctl is called with a pointer to this structure the driver prepares for user pointer I/O, when this I/O method is not supported the ioctl returns an <span class="errorcode">EINVAL</span> error code.</p><div class="table"><a id="v4l2-requestbuffers"></a><p class="title"><b>Table A.72. struct <span class="structname">v4l2_requestbuffers</span></b></p><div class="table-contents"><table summary="struct v4l2_requestbuffers" width="100%" border="0"><colgroup><col /><col /><col /></colgroup><tbody valign="top"><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>count</code></em></td><td valign="top">The number of buffers requested or granted. This field is only used when <em class="structfield"><code>memory</code></em> is set to <code class="constant">V4L2_MEMORY_MMAP</code>.</td></tr><tr><td valign="top">enum <a class="link" href="ch03s05.html#v4l2-buf-type" title="Table 3.2. enum v4l2_buf_type">v4l2_buf_type</a></td><td valign="top"><em class="structfield"><code>type</code></em></td><td valign="top">Type of the stream or buffers, this is the same as the struct <a class="link" href="re41.html#v4l2-format" title="Table A.46. struct v4l2_format">v4l2_format</a> <em class="structfield"><code>type</code></em> field. See <a class="xref" href="ch03s05.html#v4l2-buf-type" title="Table 3.2. enum v4l2_buf_type">Table 3.2, “enum v4l2_buf_type”</a> for valid values.</td></tr><tr><td valign="top">enum <a class="link" href="ch03s05.html#v4l2-memory" title="Table 3.4. enum v4l2_memory">v4l2_memory</a></td><td valign="top"><em class="structfield"><code>memory</code></em></td><td valign="top">Applications set this field to <code class="constant">V4L2_MEMORY_MMAP</code> or <code class="constant">V4L2_MEMORY_USERPTR</code>.</td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>reserved</code></em>[2]</td><td valign="top">A place holder for future extensions and custom (driver defined) buffer types <code class="constant">V4L2_BUF_TYPE_PRIVATE</code> and higher.</td></tr></tbody></table></div></div><br class="table-break" /></div><div class="refsect1" title="Return Value"><a id="id2736653"></a><h2>Return Value</h2><p>On success <span class="returnvalue">0</span> is returned, on error <span class="returnvalue">-1</span> and the <code class="varname">errno</code> variable is set appropriately:</p><div class="variablelist"><dl><dt><span class="term"><span class="errorcode">EBUSY</span></span></dt><dd><p>The driver supports multiple opens and I/O is already in progress, or reallocation of buffers was attempted although one or more are still mapped.</p></dd><dt><span class="term"><span class="errorcode">EINVAL</span></span></dt><dd><p>The buffer type (<em class="structfield"><code>type</code></em> field) or the requested I/O method (<em class="structfield"><code>memory</code></em>) is not supported.</p></dd></dl></div></div><div class="footnotes"><br /><hr width="100" align="left" /><div class="footnote"><p><sup>[<a id="ftn.id2736422" href="#id2736422" class="para">26</a>] </sup>For example video output requires at least two buffers, one displayed and one filled by the application.</p></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="re58.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="apa.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="re60.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ioctl VIDIOC_QUERYSTD </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> ioctl VIDIOC_S_HW_FREQ_SEEK</td></tr></table></div></body></html>