vidioc-expbuf.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <refentry id="vidioc-expbuf">
  2. <refmeta>
  3. <refentrytitle>ioctl VIDIOC_EXPBUF</refentrytitle>
  4. &manvol;
  5. </refmeta>
  6. <refnamediv>
  7. <refname>VIDIOC_EXPBUF</refname>
  8. <refpurpose>Export a buffer as a DMABUF file descriptor.</refpurpose>
  9. </refnamediv>
  10. <refsynopsisdiv>
  11. <funcsynopsis>
  12. <funcprototype>
  13. <funcdef>int <function>ioctl</function></funcdef>
  14. <paramdef>int <parameter>fd</parameter></paramdef>
  15. <paramdef>int <parameter>request</parameter></paramdef>
  16. <paramdef>struct v4l2_exportbuffer *<parameter>argp</parameter></paramdef>
  17. </funcprototype>
  18. </funcsynopsis>
  19. </refsynopsisdiv>
  20. <refsect1>
  21. <title>Arguments</title>
  22. <variablelist>
  23. <varlistentry>
  24. <term><parameter>fd</parameter></term>
  25. <listitem>
  26. <para>&fd;</para>
  27. </listitem>
  28. </varlistentry>
  29. <varlistentry>
  30. <term><parameter>request</parameter></term>
  31. <listitem>
  32. <para>VIDIOC_EXPBUF</para>
  33. </listitem>
  34. </varlistentry>
  35. <varlistentry>
  36. <term><parameter>argp</parameter></term>
  37. <listitem>
  38. <para></para>
  39. </listitem>
  40. </varlistentry>
  41. </variablelist>
  42. </refsect1>
  43. <refsect1>
  44. <title>Description</title>
  45. <note>
  46. <title>Experimental</title>
  47. <para>This is an <link linkend="experimental"> experimental </link>
  48. interface and may change in the future.</para>
  49. </note>
  50. <para>This ioctl is an extension to the <link linkend="mmap">memory
  51. mapping</link> I/O method, therefore it is available only for
  52. <constant>V4L2_MEMORY_MMAP</constant> buffers. It can be used to export a
  53. buffer as a DMABUF file at any time after buffers have been allocated with the
  54. &VIDIOC-REQBUFS; ioctl.</para>
  55. <para> To export a buffer, applications fill &v4l2-exportbuffer;. The
  56. <structfield>type</structfield> field is set to the same buffer type as was
  57. previously used with &v4l2-requestbuffers; <structfield>type</structfield>.
  58. Applications must also set the <structfield>index</structfield> field. Valid
  59. index numbers range from zero to the number of buffers allocated with
  60. &VIDIOC-REQBUFS; (&v4l2-requestbuffers; <structfield>count</structfield>)
  61. minus one. For the multi-planar API, applications set the <structfield>plane</structfield>
  62. field to the index of the plane to be exported. Valid planes
  63. range from zero to the maximal number of valid planes for the currently active
  64. format. For the single-planar API, applications must set <structfield>plane</structfield>
  65. to zero. Additional flags may be posted in the <structfield>flags</structfield>
  66. field. Refer to a manual for open() for details.
  67. Currently only O_CLOEXEC, O_RDONLY, O_WRONLY, and O_RDWR are supported. All
  68. other fields must be set to zero.
  69. In the case of multi-planar API, every plane is exported separately using
  70. multiple <constant>VIDIOC_EXPBUF</constant> calls.</para>
  71. <para>After calling <constant>VIDIOC_EXPBUF</constant> the <structfield>fd</structfield>
  72. field will be set by a driver. This is a DMABUF file
  73. descriptor. The application may pass it to other DMABUF-aware devices. Refer to
  74. <link linkend="dmabuf">DMABUF importing</link> for details about importing
  75. DMABUF files into V4L2 nodes. It is recommended to close a DMABUF file when it
  76. is no longer used to allow the associated memory to be reclaimed.</para>
  77. </refsect1>
  78. <refsect1>
  79. <title>Examples</title>
  80. <example>
  81. <title>Exporting a buffer.</title>
  82. <programlisting>
  83. int buffer_export(int v4lfd, &v4l2-buf-type; bt, int index, int *dmafd)
  84. {
  85. &v4l2-exportbuffer; expbuf;
  86. memset(&amp;expbuf, 0, sizeof(expbuf));
  87. expbuf.type = bt;
  88. expbuf.index = index;
  89. if (ioctl(v4lfd, &VIDIOC-EXPBUF;, &amp;expbuf) == -1) {
  90. perror("VIDIOC_EXPBUF");
  91. return -1;
  92. }
  93. *dmafd = expbuf.fd;
  94. return 0;
  95. }
  96. </programlisting>
  97. </example>
  98. <example>
  99. <title>Exporting a buffer using the multi-planar API.</title>
  100. <programlisting>
  101. int buffer_export_mp(int v4lfd, &v4l2-buf-type; bt, int index,
  102. int dmafd[], int n_planes)
  103. {
  104. int i;
  105. for (i = 0; i &lt; n_planes; ++i) {
  106. &v4l2-exportbuffer; expbuf;
  107. memset(&amp;expbuf, 0, sizeof(expbuf));
  108. expbuf.type = bt;
  109. expbuf.index = index;
  110. expbuf.plane = i;
  111. if (ioctl(v4lfd, &VIDIOC-EXPBUF;, &amp;expbuf) == -1) {
  112. perror("VIDIOC_EXPBUF");
  113. while (i)
  114. close(dmafd[--i]);
  115. return -1;
  116. }
  117. dmafd[i] = expbuf.fd;
  118. }
  119. return 0;
  120. }
  121. </programlisting>
  122. </example>
  123. <table pgwide="1" frame="none" id="v4l2-exportbuffer">
  124. <title>struct <structname>v4l2_exportbuffer</structname></title>
  125. <tgroup cols="3">
  126. &cs-str;
  127. <tbody valign="top">
  128. <row>
  129. <entry>__u32</entry>
  130. <entry><structfield>type</structfield></entry>
  131. <entry>Type of the buffer, same as &v4l2-format;
  132. <structfield>type</structfield> or &v4l2-requestbuffers;
  133. <structfield>type</structfield>, set by the application. See <xref
  134. linkend="v4l2-buf-type" /></entry>
  135. </row>
  136. <row>
  137. <entry>__u32</entry>
  138. <entry><structfield>index</structfield></entry>
  139. <entry>Number of the buffer, set by the application. This field is
  140. only used for <link linkend="mmap">memory mapping</link> I/O and can range from
  141. zero to the number of buffers allocated with the &VIDIOC-REQBUFS; and/or
  142. &VIDIOC-CREATE-BUFS; ioctls. </entry>
  143. </row>
  144. <row>
  145. <entry>__u32</entry>
  146. <entry><structfield>plane</structfield></entry>
  147. <entry>Index of the plane to be exported when using the
  148. multi-planar API. Otherwise this value must be set to zero. </entry>
  149. </row>
  150. <row>
  151. <entry>__u32</entry>
  152. <entry><structfield>flags</structfield></entry>
  153. <entry>Flags for the newly created file, currently only
  154. <constant>O_CLOEXEC</constant>, <constant>O_RDONLY</constant>, <constant>O_WRONLY</constant>,
  155. and <constant>O_RDWR</constant> are supported, refer to the manual
  156. of open() for more details.</entry>
  157. </row>
  158. <row>
  159. <entry>__s32</entry>
  160. <entry><structfield>fd</structfield></entry>
  161. <entry>The DMABUF file descriptor associated with a buffer. Set by
  162. the driver.</entry>
  163. </row>
  164. <row>
  165. <entry>__u32</entry>
  166. <entry><structfield>reserved[11]</structfield></entry>
  167. <entry>Reserved field for future use. Drivers and applications must
  168. set the array to zero.</entry>
  169. </row>
  170. </tbody>
  171. </tgroup>
  172. </table>
  173. </refsect1>
  174. <refsect1>
  175. &return-value;
  176. <variablelist>
  177. <varlistentry>
  178. <term><errorcode>EINVAL</errorcode></term>
  179. <listitem>
  180. <para>A queue is not in MMAP mode or DMABUF exporting is not
  181. supported or <structfield>flags</structfield> or <structfield>type</structfield>
  182. or <structfield>index</structfield> or <structfield>plane</structfield> fields
  183. are invalid.</para>
  184. </listitem>
  185. </varlistentry>
  186. </variablelist>
  187. </refsect1>
  188. </refentry>