ioctl VIDIOC_EXPBUF
&manvol;

# VIDIOC_EXPBUF

Export a buffer as a DMABUF file descriptor.

    	int ioctl
    	int fd
    	int request
    	struct v4l2_exportbuffer *argp

## Arguments

`fd`

  &fd;

`request`

  VIDIOC_EXPBUF

`argp`

## Description

### Experimental

This is an experimental interface and may change in the future.

This ioctl is an extension to the memory mapping I/O method, therefore it is available only for `V4L2_MEMORY_MMAP` buffers. It can be used to export a buffer as a DMABUF file at any time after buffers have been allocated with the &VIDIOC-REQBUFS; ioctl.

To export a buffer, applications fill &v4l2-exportbuffer;. The type field is set to the same buffer type as was previously used with &v4l2-requestbuffers; type . Applications must also set the index field. Valid index numbers range from zero to the number of buffers allocated with &VIDIOC-REQBUFS; (&v4l2-requestbuffers; count ) minus one. For the multi-planar API, applications set the plane field to the index of the plane to be exported. Valid planes range from zero to the maximal number of valid planes for the currently active format. For the single-planar API, applications must set plane to zero. Additional flags may be posted in the flags field. Refer to a manual for open() for details. Currently only O_CLOEXEC is supported. All other fields must be set to zero. In the case of multi-planar API, every plane is exported separately using multiple `VIDIOC_EXPBUF` calls.

After calling `VIDIOC_EXPBUF` the fd field will be set by a driver. This is a DMABUF file descriptor. The application may pass it to other DMABUF-aware devices. Refer to DMABUF importing for details about importing DMABUF files into V4L2 nodes. It is recommended to close a DMABUF file when it is no longer used to allow the associated memory to be reclaimed.

## Examples

### Exporting a buffer.

    int buffer_export(int v4lfd, &v4l2-buf-type; bt, int index, int *dmafd)
    {
    	&v4l2-exportbuffer; expbuf;

    	memset(&expbuf, 0, sizeof(expbuf));
    	expbuf.type = bt;
    	expbuf.index = index;
    	if (ioctl(v4lfd, &VIDIOC-EXPBUF;, &expbuf) == -1) {
    		perror("VIDIOC_EXPBUF");
    		return -1;
    	}

    	*dmafd = expbuf.fd;

    	return 0;
    }

### Exporting a buffer using the multi-planar API.

    int buffer_export_mp(int v4lfd, &v4l2-buf-type; bt, int index,
    	int dmafd[], int n_planes)
    {
    	int i;

    	for (i = 0; i < n_planes; ++i) {
    		&v4l2-exportbuffer; expbuf;

    		memset(&expbuf, 0, sizeof(expbuf));
    		expbuf.type = bt;
    		expbuf.index = index;
    		expbuf.plane = i;
    		if (ioctl(v4lfd, &VIDIOC-EXPBUF;, &expbuf) == -1) {
    			perror("VIDIOC_EXPBUF");
    			while (i)
    				close(dmafd[--i]);
    			return -1;
    		}
    		dmafd[i] = expbuf.fd;
    	}

    	return 0;
    }

### struct v4l2_exportbuffer

&cs-str;
__u32 | type | Type of the buffer, same as &v4l2-format; type or &v4l2-requestbuffers; type, set by the application. See
__u32 | index | Number of the buffer, set by the application. This field is only used for memory mapping I/O and can range from zero to the number of buffers allocated with the &VIDIOC-REQBUFS; and/or &VIDIOC-CREATE-BUFS; ioctls.
__u32 | plane | Index of the plane to be exported when using the multi-planar API. Otherwise this value must be set to zero.
__u32 | flags | Flags for the newly created file, currently only `O_CLOEXEC` is supported, refer to the manual of open() for more details.
__s32 | fd | The DMABUF file descriptor associated with a buffer. Set by the driver.
__u32 | reserved[11] | Reserved field for future use. Must be set to zero.

&return-value;

EINVAL

  A queue is not in MMAP mode or DMABUF exporting is not supported or flags or type or index or plane fields are invalid.