1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
13 VIDIOC_EXPBUF - Export a buffer as a DMABUF file descriptor.
18 .. c:macro:: VIDIOC_EXPBUF
20 ``int ioctl(int fd, VIDIOC_EXPBUF, struct v4l2_exportbuffer *argp)``
26 File descriptor returned by :c:func:`open()`.
29 Pointer to struct :c:type:`v4l2_exportbuffer`.
34 This ioctl is an extension to the :ref:`memory mapping <mmap>` I/O
35 method, therefore it is available only for ``V4L2_MEMORY_MMAP`` buffers.
36 It can be used to export a buffer as a DMABUF file at any time after
37 buffers have been allocated with the
38 :ref:`VIDIOC_REQBUFS` ioctl.
40 To export a buffer, applications fill struct
41 :c:type:`v4l2_exportbuffer`. The ``type`` field is
42 set to the same buffer type as was previously used with struct
43 :c:type:`v4l2_requestbuffers` ``type``.
44 Applications must also set the ``index`` field. Valid index numbers
45 range from zero to the number of buffers allocated with
46 :ref:`VIDIOC_REQBUFS` (struct
47 :c:type:`v4l2_requestbuffers` ``count``) minus
48 one. For the multi-planar API, applications set the ``plane`` field to
49 the index of the plane to be exported. Valid planes range from zero to
50 the maximal number of valid planes for the currently active format. For
51 the single-planar API, applications must set ``plane`` to zero.
52 Additional flags may be posted in the ``flags`` field. Refer to a manual
53 for open() for details. Currently only O_CLOEXEC, O_RDONLY, O_WRONLY,
54 and O_RDWR are supported. All other fields must be set to zero. In the
55 case of multi-planar API, every plane is exported separately using
56 multiple :ref:`VIDIOC_EXPBUF` calls.
58 After calling :ref:`VIDIOC_EXPBUF` the ``fd`` field will be set by a
59 driver. This is a DMABUF file descriptor. The application may pass it to
60 other DMABUF-aware devices. Refer to :ref:`DMABUF importing <dmabuf>`
61 for details about importing DMABUF files into V4L2 nodes. It is
62 recommended to close a DMABUF file when it is no longer used to allow
63 the associated memory to be reclaimed.
70 int buffer_export(int v4lfd, enum v4l2_buf_type bt, int index, int *dmafd)
72 struct v4l2_exportbuffer expbuf;
74 memset(&expbuf, 0, sizeof(expbuf));
77 if (ioctl(v4lfd, VIDIOC_EXPBUF, &expbuf) == -1) {
78 perror("VIDIOC_EXPBUF");
89 int buffer_export_mp(int v4lfd, enum v4l2_buf_type bt, int index,
90 int dmafd[], int n_planes)
94 for (i = 0; i < n_planes; ++i) {
95 struct v4l2_exportbuffer expbuf;
97 memset(&expbuf, 0, sizeof(expbuf));
101 if (ioctl(v4lfd, VIDIOC_EXPBUF, &expbuf) == -1) {
102 perror("VIDIOC_EXPBUF");
107 dmafd[i] = expbuf.fd;
113 .. c:type:: v4l2_exportbuffer
115 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
117 .. flat-table:: struct v4l2_exportbuffer
124 - Type of the buffer, same as struct
125 :c:type:`v4l2_format` ``type`` or struct
126 :c:type:`v4l2_requestbuffers` ``type``, set
127 by the application. See :c:type:`v4l2_buf_type`
130 - Number of the buffer, set by the application. This field is only
131 used for :ref:`memory mapping <mmap>` I/O and can range from
132 zero to the number of buffers allocated with the
133 :ref:`VIDIOC_REQBUFS` and/or
134 :ref:`VIDIOC_CREATE_BUFS` ioctls.
137 - Index of the plane to be exported when using the multi-planar API.
138 Otherwise this value must be set to zero.
141 - Flags for the newly created file, currently only ``O_CLOEXEC``,
142 ``O_RDONLY``, ``O_WRONLY``, and ``O_RDWR`` are supported, refer to
143 the manual of open() for more details.
146 - The DMABUF file descriptor associated with a buffer. Set by the
150 - Reserved field for future use. Drivers and applications must set
156 On success 0 is returned, on error -1 and the ``errno`` variable is set
157 appropriately. The generic error codes are described at the
158 :ref:`Generic Error Codes <gen-errors>` chapter.
161 A queue is not in MMAP mode or DMABUF exporting is not supported or
162 ``flags`` or ``type`` or ``index`` or ``plane`` fields are invalid.