vidioc-expbuf.xml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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
  62. </structfield> 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
  65. </structfield> to zero. Additional flags may be posted in the <structfield>
  66. flags </structfield> field. Refer to a manual for open() for details.
  67. Currently only O_CLOEXEC is supported. All other fields must be set to zero.
  68. In the case of multi-planar API, every plane is exported separately using
  69. multiple <constant> VIDIOC_EXPBUF </constant> calls. </para>
  70. <para> After calling <constant>VIDIOC_EXPBUF</constant> the <structfield> fd
  71. </structfield> field will be set by a driver. This is a DMABUF file
  72. descriptor. The application may pass it to other DMABUF-aware devices. Refer to
  73. <link linkend="dmabuf">DMABUF importing</link> for details about importing
  74. DMABUF files into V4L2 nodes. It is recommended to close a DMABUF file when it
  75. is no longer used to allow the associated memory to be reclaimed. </para>
  76. </refsect1>
  77. <refsect1>
  78. <title>Examples</title>
  79. <example>
  80. <title>Exporting a buffer.</title>
  81. <programlisting>
  82. int buffer_export(int v4lfd, &v4l2-buf-type; bt, int index, int *dmafd)
  83. {
  84. &v4l2-exportbuffer; expbuf;
  85. memset(&amp;expbuf, 0, sizeof(expbuf));
  86. expbuf.type = bt;
  87. expbuf.index = index;
  88. if (ioctl(v4lfd, &VIDIOC-EXPBUF;, &amp;expbuf) == -1) {
  89. perror("VIDIOC_EXPBUF");
  90. return -1;
  91. }
  92. *dmafd = expbuf.fd;
  93. return 0;
  94. }
  95. </programlisting>
  96. </example>
  97. <example>
  98. <title>Exporting a buffer using the multi-planar API.</title>
  99. <programlisting>
  100. int buffer_export_mp(int v4lfd, &v4l2-buf-type; bt, int index,
  101. int dmafd[], int n_planes)
  102. {
  103. int i;
  104. for (i = 0; i &lt; n_planes; ++i) {
  105. &v4l2-exportbuffer; expbuf;
  106. memset(&amp;expbuf, 0, sizeof(expbuf));
  107. expbuf.type = bt;
  108. expbuf.index = index;
  109. expbuf.plane = i;
  110. if (ioctl(v4lfd, &VIDIOC-EXPBUF;, &amp;expbuf) == -1) {
  111. perror("VIDIOC_EXPBUF");
  112. while (i)
  113. close(dmafd[--i]);
  114. return -1;
  115. }
  116. dmafd[i] = expbuf.fd;
  117. }
  118. return 0;
  119. }
  120. </programlisting>
  121. </example>
  122. <table pgwide="1" frame="none" id="v4l2-exportbuffer">
  123. <title>struct <structname>v4l2_exportbuffer</structname></title>
  124. <tgroup cols="3">
  125. &cs-str;
  126. <tbody valign="top">
  127. <row>
  128. <entry>__u32</entry>
  129. <entry><structfield>type</structfield></entry>
  130. <entry>Type of the buffer, same as &v4l2-format;
  131. <structfield>type</structfield> or &v4l2-requestbuffers;
  132. <structfield>type</structfield>, set by the application. See <xref
  133. linkend="v4l2-buf-type" /></entry>
  134. </row>
  135. <row>
  136. <entry>__u32</entry>
  137. <entry><structfield>index</structfield></entry>
  138. <entry>Number of the buffer, set by the application. This field is
  139. only used for <link linkend="mmap">memory mapping</link> I/O and can range from
  140. zero to the number of buffers allocated with the &VIDIOC-REQBUFS; and/or
  141. &VIDIOC-CREATE-BUFS; ioctls. </entry>
  142. </row>
  143. <row>
  144. <entry>__u32</entry>
  145. <entry><structfield>plane</structfield></entry>
  146. <entry>Index of the plane to be exported when using the
  147. multi-planar API. Otherwise this value must be set to zero. </entry>
  148. </row>
  149. <row>
  150. <entry>__u32</entry>
  151. <entry><structfield>flags</structfield></entry>
  152. <entry>Flags for the newly created file, currently only <constant>
  153. O_CLOEXEC </constant> is supported, refer to the manual of open() for more
  154. details.</entry>
  155. </row>
  156. <row>
  157. <entry>__s32</entry>
  158. <entry><structfield>fd</structfield></entry>
  159. <entry>The DMABUF file descriptor associated with a buffer. Set by
  160. the driver.</entry>
  161. </row>
  162. <row>
  163. <entry>__u32</entry>
  164. <entry><structfield>reserved[11]</structfield></entry>
  165. <entry>Reserved field for future use. Must be set to zero.</entry>
  166. </row>
  167. </tbody>
  168. </tgroup>
  169. </table>
  170. </refsect1>
  171. <refsect1>
  172. &return-value;
  173. <variablelist>
  174. <varlistentry>
  175. <term><errorcode>EINVAL</errorcode></term>
  176. <listitem>
  177. <para>A queue is not in MMAP mode or DMABUF exporting is not
  178. supported or <structfield> flags </structfield> or <structfield> type
  179. </structfield> or <structfield> index </structfield> or <structfield> plane
  180. </structfield> fields are invalid.</para>
  181. </listitem>
  182. </varlistentry>
  183. </variablelist>
  184. </refsect1>
  185. </refentry>