1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>ioctl VIDIOC_CREATE_BUFS</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="LINUX MEDIA INFRASTRUCTURE API"><link rel="up" href="user-func.html" title="Appendix&#160;A.&#160;Function Reference"><link rel="prev" href="func-ioctl.html" title="V4L2 ioctl()"><link rel="next" href="vidioc-cropcap.html" title="ioctl VIDIOC_CROPCAP"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">ioctl VIDIOC_CREATE_BUFS</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="func-ioctl.html">Prev</a>&#160;</td><th width="60%" align="center">Appendix&#160;A.&#160;Function Reference</th><td width="20%" align="right">&#160;<a accesskey="n" href="vidioc-cropcap.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="vidioc-create-bufs"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>VIDIOC_CREATE_BUFS &#8212; Create buffers for Memory Mapped or User Pointer or DMA Buffer
2    I/O</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">ioctl</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td>&#160;</td><td>int <var class="pdparam">request</var>, </td></tr><tr><td>&#160;</td><td>struct v4l2_create_buffers *<var class="pdparam">argp</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">&#160;</div></div></div><div class="refsect1"><a name="idp1111828676"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>fd</code></em></span></dt><dd><p>File descriptor returned by <a class="link" href="func-open.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_CREATE_BUFS</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"><a name="idp1111832700"></a><h2>Description</h2><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Experimental</h3><p>This is an <a class="link" href="hist-v4l2.html#experimental" title="Experimental API Elements"> experimental </a>
3      interface and may change in the future.</p></div><p>This ioctl is used to create buffers for <a class="link" href="mmap.html" title="Streaming I/O (Memory Mapping)">memory
4mapped</a> or <a class="link" href="userp.html" title="Streaming I/O (User Pointers)">user pointer</a> or <a class="link" href="dmabuf.html" title="Streaming I/O (DMA buffer importing)">DMA buffer</a> I/O. It can be used as an alternative or in
5addition to the <code class="constant">VIDIOC_REQBUFS</code> ioctl, when a tighter
6control over buffers is required. This ioctl can be called multiple times to
7create buffers of different sizes.</p><p>To allocate the device buffers applications must initialize the
8relevant fields of the <span class="structname">v4l2_create_buffers</span> structure.
9The <em class="structfield"><code>count</code></em> field must be set to the number of
10requested buffers, the <em class="structfield"><code>memory</code></em> field specifies the
11requested I/O method and the <em class="structfield"><code>reserved</code></em> array must be
12zeroed.</p><p>The <em class="structfield"><code>format</code></em> field specifies the image format
13that the buffers must be able to handle. The application has to fill in this
14struct&#160;<a class="link" href="vidioc-g-fmt.html#v4l2-format" title="Table&#160;A.72.&#160;struct v4l2_format">v4l2_format</a>. Usually this will be done using the
15<code class="constant">VIDIOC_TRY_FMT</code> or <code class="constant">VIDIOC_G_FMT</code> ioctl()
16to ensure that the requested format is supported by the driver. Unsupported
17formats will result in an error.</p><p>The buffers created by this ioctl will have as minimum size the size
18defined by the <em class="structfield"><code>format.pix.sizeimage</code></em> field. If the
19<em class="structfield"><code>format.pix.sizeimage</code></em> field is less than the minimum
20required for the given format, then <em class="structfield"><code>sizeimage</code></em> will be
21increased by the driver to that minimum to allocate the buffers. If it is
22larger, then the value will be used as-is. The same applies to the
23<em class="structfield"><code>sizeimage</code></em> field of the
24<span class="structname">v4l2_plane_pix_format</span> structure in the case of
25multiplanar formats.</p><p>When the ioctl is called with a pointer to this structure the driver
26will attempt to allocate up to the requested number of buffers and store the
27actual number allocated and the starting index in the
28<em class="structfield"><code>count</code></em> and the <em class="structfield"><code>index</code></em> fields
29respectively. On return <em class="structfield"><code>count</code></em> can be smaller than
30the number requested. The driver may also increase buffer sizes if required,
31however, it will not update <em class="structfield"><code>sizeimage</code></em> field values.
32The user has to use <code class="constant">VIDIOC_QUERYBUF</code> to retrieve that
33information.</p><div class="table"><a name="v4l2-create-buffers"></a><p class="title"><b>Table&#160;A.1.&#160;struct <span class="structname">v4l2_create_buffers</span></b></p><div class="table-contents"><table summary="struct v4l2_create_buffers" width="100%" border="0"><colgroup><col class="c1"><col class="c2"><col class="c3"></colgroup><tbody valign="top"><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>index</code></em></td><td valign="top">The starting buffer index, returned by the driver.</td></tr><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. If count == 0, then
34	    <code class="constant">VIDIOC_CREATE_BUFS</code> will set <em class="structfield"><code>index</code></em>
35	    to the current number of created buffers, and it will check the validity of
36	    <em class="structfield"><code>memory</code></em> and <em class="structfield"><code>format.type</code></em>.
37	    If those are invalid -1 is returned and errno is set to <span class="errorcode">EINVAL</span> error code,
38	    otherwise <code class="constant">VIDIOC_CREATE_BUFS</code> returns 0. It will
39	    never set errno to <span class="errorcode">EBUSY</span> error code in this particular case.</td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>memory</code></em></td><td valign="top">Applications set this field to
40<code class="constant">V4L2_MEMORY_MMAP</code>,
41<code class="constant">V4L2_MEMORY_DMABUF</code> or
42<code class="constant">V4L2_MEMORY_USERPTR</code>. See <a class="xref" href="buffer.html#v4l2-memory" title="Table&#160;3.5.&#160;enum v4l2_memory">Table&#160;3.5, &#8220;enum v4l2_memory&#8221;</a></td></tr><tr><td valign="top">struct&#160;<a class="link" href="vidioc-g-fmt.html#v4l2-format" title="Table&#160;A.72.&#160;struct v4l2_format">v4l2_format</a></td><td valign="top"><em class="structfield"><code>format</code></em></td><td valign="top">Filled in by the application, preserved by the driver.</td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>reserved</code></em>[8]</td><td valign="top">A place holder for future extensions.</td></tr></tbody></table></div></div><br class="table-break"></div><div class="refsect1"><a name="idp1111944260"></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. The generic error codes are described at the <a class="link" href="gen_errors.html#gen-errors" title="Table&#160;19.1.&#160;Generic error codes">Generic Error Codes</a> chapter.</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorcode">ENOMEM</span></span></dt><dd><p>No memory to allocate buffers for <a class="link" href="mmap.html" title="Streaming I/O (Memory Mapping)">memory
43mapped</a> I/O.</p></dd><dt><span class="term"><span class="errorcode">EINVAL</span></span></dt><dd><p>The buffer type (<em class="structfield"><code>format.type</code></em> field),
44requested I/O method (<em class="structfield"><code>memory</code></em>) or format
45(<em class="structfield"><code>format</code></em> field) is not valid.</p></dd></dl></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="func-ioctl.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="user-func.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="vidioc-cropcap.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">V4L2 ioctl()&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;ioctl VIDIOC_CROPCAP</td></tr></table></div></body></html>
46