1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>ioctl VIDIOC_EXPBUF</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="vidioc-enumstd.html" title="ioctl VIDIOC_ENUMSTD"><link rel="next" href="vidioc-g-audio.html" title="ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO"></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_EXPBUF</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="vidioc-enumstd.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-g-audio.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="vidioc-expbuf"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>VIDIOC_EXPBUF &#8212; Export a buffer as a DMABUF file descriptor.</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_exportbuffer *<var class="pdparam">argp</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">&#160;</div></div></div><div class="refsect1"><a name="idp1113547788"></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_EXPBUF</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="idp1113551836"></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>
2      interface and may change in the future.</p></div><p>This ioctl is an extension to the <a class="link" href="mmap.html" title="Streaming I/O (Memory Mapping)">memory
3mapping</a> I/O method, therefore it is available only for
4<code class="constant">V4L2_MEMORY_MMAP</code> buffers.  It can be used to export a
5buffer as a DMABUF file at any time after buffers have been allocated with the
6<a class="link" href="vidioc-reqbufs.html" title="ioctl VIDIOC_REQBUFS"><code class="constant">VIDIOC_REQBUFS</code></a> ioctl.</p><p> To export a buffer, applications fill struct&#160;<a class="link" href="vidioc-expbuf.html#v4l2-exportbuffer" title="Table&#160;A.50.&#160;struct v4l2_exportbuffer">v4l2_exportbuffer</a>.  The
7<em class="structfield"><code> type </code></em> field is set to the same buffer type as was
8previously used with  struct&#160;<a class="link" href="vidioc-reqbufs.html#v4l2-requestbuffers" title="Table&#160;A.100.&#160;struct v4l2_requestbuffers">v4l2_requestbuffers</a><em class="structfield"><code> type </code></em>.
9Applications must also set the <em class="structfield"><code> index </code></em> field. Valid
10index numbers range from zero to the number of buffers allocated with
11<a class="link" href="vidioc-reqbufs.html" title="ioctl VIDIOC_REQBUFS"><code class="constant">VIDIOC_REQBUFS</code></a> (struct&#160;<a class="link" href="vidioc-reqbufs.html#v4l2-requestbuffers" title="Table&#160;A.100.&#160;struct v4l2_requestbuffers">v4l2_requestbuffers</a><em class="structfield"><code> count </code></em>)
12minus one.  For the multi-planar API, applications set the <em class="structfield"><code> plane
13</code></em> field to the index of the plane to be exported. Valid planes
14range from zero to the maximal number of valid planes for the currently active
15format. For the single-planar API, applications must set <em class="structfield"><code> plane
16</code></em> to zero.  Additional flags may be posted in the <em class="structfield"><code>
17flags </code></em> field.  Refer to a manual for open() for details.
18Currently only O_CLOEXEC, O_RDONLY, O_WRONLY, and O_RDWR are supported.  All
19other fields must be set to zero.
20In the case of multi-planar API, every plane is exported separately using
21multiple <code class="constant"> VIDIOC_EXPBUF </code> calls. </p><p> After calling <code class="constant">VIDIOC_EXPBUF</code> the <em class="structfield"><code> fd
22</code></em> field will be set by a driver.  This is a DMABUF file
23descriptor. The application may pass it to other DMABUF-aware devices. Refer to
24<a class="link" href="dmabuf.html" title="Streaming I/O (DMA buffer importing)">DMABUF importing</a> for details about importing
25DMABUF files into V4L2 nodes. It is recommended to close a DMABUF file when it
26is no longer used to allow the associated memory to be reclaimed. </p></div><div class="refsect1"><a name="idp1113561100"></a><h2>Examples</h2><div class="example"><a name="idp1113561420"></a><p class="title"><b>Example&#160;A.1.&#160;Exporting a buffer.</b></p><div class="example-contents"><pre class="programlisting">
27int buffer_export(int v4lfd, enum&#160;<a class="link" href="buffer.html#v4l2-buf-type" title="Table&#160;3.3.&#160;enum v4l2_buf_type">v4l2_buf_type</a> bt, int index, int *dmafd)
28{
29	struct&#160;<a class="link" href="vidioc-expbuf.html#v4l2-exportbuffer" title="Table&#160;A.50.&#160;struct v4l2_exportbuffer">v4l2_exportbuffer</a> expbuf;
30
31	memset(&amp;expbuf, 0, sizeof(expbuf));
32	expbuf.type = bt;
33	expbuf.index = index;
34	if (ioctl(v4lfd, <a class="link" href="vidioc-expbuf.html" title="ioctl VIDIOC_EXPBUF"><code class="constant">VIDIOC_EXPBUF</code></a>, &amp;expbuf) == -1) {
35		perror("VIDIOC_EXPBUF");
36		return -1;
37	}
38
39	*dmafd = expbuf.fd;
40
41	return 0;
42}
43      </pre></div></div><br class="example-break"><div class="example"><a name="idp1113563748"></a><p class="title"><b>Example&#160;A.2.&#160;Exporting a buffer using the multi-planar API.</b></p><div class="example-contents"><pre class="programlisting">
44int buffer_export_mp(int v4lfd, enum&#160;<a class="link" href="buffer.html#v4l2-buf-type" title="Table&#160;3.3.&#160;enum v4l2_buf_type">v4l2_buf_type</a> bt, int index,
45	int dmafd[], int n_planes)
46{
47	int i;
48
49	for (i = 0; i &lt; n_planes; ++i) {
50		struct&#160;<a class="link" href="vidioc-expbuf.html#v4l2-exportbuffer" title="Table&#160;A.50.&#160;struct v4l2_exportbuffer">v4l2_exportbuffer</a> expbuf;
51
52		memset(&amp;expbuf, 0, sizeof(expbuf));
53		expbuf.type = bt;
54		expbuf.index = index;
55		expbuf.plane = i;
56		if (ioctl(v4lfd, <a class="link" href="vidioc-expbuf.html" title="ioctl VIDIOC_EXPBUF"><code class="constant">VIDIOC_EXPBUF</code></a>, &amp;expbuf) == -1) {
57			perror("VIDIOC_EXPBUF");
58			while (i)
59				close(dmafd[--i]);
60			return -1;
61		}
62		dmafd[i] = expbuf.fd;
63	}
64
65	return 0;
66}
67      </pre></div></div><br class="example-break"><div class="table"><a name="v4l2-exportbuffer"></a><p class="title"><b>Table&#160;A.50.&#160;struct <span class="structname">v4l2_exportbuffer</span></b></p><div class="table-contents"><table summary="struct v4l2_exportbuffer" 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>type</code></em></td><td valign="top">Type of the buffer, same as struct&#160;<a class="link" href="vidioc-g-fmt.html#v4l2-format" title="Table&#160;A.72.&#160;struct v4l2_format">v4l2_format</a>
68<em class="structfield"><code>type</code></em> or struct&#160;<a class="link" href="vidioc-reqbufs.html#v4l2-requestbuffers" title="Table&#160;A.100.&#160;struct v4l2_requestbuffers">v4l2_requestbuffers</a>
69<em class="structfield"><code>type</code></em>, set by the application. See <a class="xref" href="buffer.html#v4l2-buf-type" title="Table&#160;3.3.&#160;enum v4l2_buf_type">Table&#160;3.3, &#8220;enum v4l2_buf_type&#8221;</a></td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>index</code></em></td><td valign="top">Number of the buffer, set by the application. This field is
70only used for <a class="link" href="mmap.html" title="Streaming I/O (Memory Mapping)">memory mapping</a> I/O and can range from
71zero to the number of buffers allocated with the <a class="link" href="vidioc-reqbufs.html" title="ioctl VIDIOC_REQBUFS"><code class="constant">VIDIOC_REQBUFS</code></a> and/or
72<a class="link" href="vidioc-create-bufs.html" title="ioctl VIDIOC_CREATE_BUFS"><code class="constant">VIDIOC_CREATE_BUFS</code></a> ioctls. </td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>plane</code></em></td><td valign="top">Index of the plane to be exported when using the
73multi-planar API. Otherwise this value must be set to zero. </td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>flags</code></em></td><td valign="top">Flags for the newly created file, currently only <code class="constant">
74O_CLOEXEC </code>, <code class="constant">O_RDONLY</code>, <code class="constant">O_WRONLY
75</code>, and <code class="constant">O_RDWR</code> are supported, refer to the manual
76of open() for more details.</td></tr><tr><td valign="top">__s32</td><td valign="top"><em class="structfield"><code>fd</code></em></td><td valign="top">The DMABUF file descriptor associated with a buffer. Set by
77		the driver.</td></tr><tr><td valign="top">__u32</td><td valign="top"><em class="structfield"><code>reserved[11]</code></em></td><td valign="top">Reserved field for future use. Must be set to zero.</td></tr></tbody></table></div></div><br class="table-break"></div><div class="refsect1"><a name="idp1113579012"></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">EINVAL</span></span></dt><dd><p>A queue is not in MMAP mode or DMABUF exporting is not
78supported or <em class="structfield"><code> flags </code></em> or <em class="structfield"><code> type
79</code></em> or <em class="structfield"><code> index </code></em> or <em class="structfield"><code> plane
80</code></em> fields are invalid.</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="vidioc-enumstd.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-g-audio.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ioctl VIDIOC_ENUMSTD&#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_G_AUDIO, VIDIOC_S_AUDIO</td></tr></table></div></body></html>
81