162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 262306a36Sopenharmony_ci.. c:namespace:: V4L 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci.. _VIDIOC_EXPBUF: 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci******************* 762306a36Sopenharmony_ciioctl VIDIOC_EXPBUF 862306a36Sopenharmony_ci******************* 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciName 1162306a36Sopenharmony_ci==== 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciVIDIOC_EXPBUF - Export a buffer as a DMABUF file descriptor. 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciSynopsis 1662306a36Sopenharmony_ci======== 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci.. c:macro:: VIDIOC_EXPBUF 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_EXPBUF, struct v4l2_exportbuffer *argp)`` 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciArguments 2362306a36Sopenharmony_ci========= 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci``fd`` 2662306a36Sopenharmony_ci File descriptor returned by :c:func:`open()`. 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci``argp`` 2962306a36Sopenharmony_ci Pointer to struct :c:type:`v4l2_exportbuffer`. 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ciDescription 3262306a36Sopenharmony_ci=========== 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ciThis ioctl is an extension to the :ref:`memory mapping <mmap>` I/O 3562306a36Sopenharmony_cimethod, therefore it is available only for ``V4L2_MEMORY_MMAP`` buffers. 3662306a36Sopenharmony_ciIt can be used to export a buffer as a DMABUF file at any time after 3762306a36Sopenharmony_cibuffers have been allocated with the 3862306a36Sopenharmony_ci:ref:`VIDIOC_REQBUFS` ioctl. 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ciTo export a buffer, applications fill struct 4162306a36Sopenharmony_ci:c:type:`v4l2_exportbuffer`. The ``type`` field is 4262306a36Sopenharmony_ciset to the same buffer type as was previously used with struct 4362306a36Sopenharmony_ci:c:type:`v4l2_requestbuffers` ``type``. 4462306a36Sopenharmony_ciApplications must also set the ``index`` field. Valid index numbers 4562306a36Sopenharmony_cirange from zero to the number of buffers allocated with 4662306a36Sopenharmony_ci:ref:`VIDIOC_REQBUFS` (struct 4762306a36Sopenharmony_ci:c:type:`v4l2_requestbuffers` ``count``) minus 4862306a36Sopenharmony_cione. For the multi-planar API, applications set the ``plane`` field to 4962306a36Sopenharmony_cithe index of the plane to be exported. Valid planes range from zero to 5062306a36Sopenharmony_cithe maximal number of valid planes for the currently active format. For 5162306a36Sopenharmony_cithe single-planar API, applications must set ``plane`` to zero. 5262306a36Sopenharmony_ciAdditional flags may be posted in the ``flags`` field. Refer to a manual 5362306a36Sopenharmony_cifor open() for details. Currently only O_CLOEXEC, O_RDONLY, O_WRONLY, 5462306a36Sopenharmony_ciand O_RDWR are supported. All other fields must be set to zero. In the 5562306a36Sopenharmony_cicase of multi-planar API, every plane is exported separately using 5662306a36Sopenharmony_cimultiple :ref:`VIDIOC_EXPBUF` calls. 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ciAfter calling :ref:`VIDIOC_EXPBUF` the ``fd`` field will be set by a 5962306a36Sopenharmony_cidriver. This is a DMABUF file descriptor. The application may pass it to 6062306a36Sopenharmony_ciother DMABUF-aware devices. Refer to :ref:`DMABUF importing <dmabuf>` 6162306a36Sopenharmony_cifor details about importing DMABUF files into V4L2 nodes. It is 6262306a36Sopenharmony_cirecommended to close a DMABUF file when it is no longer used to allow 6362306a36Sopenharmony_cithe associated memory to be reclaimed. 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ciExamples 6662306a36Sopenharmony_ci======== 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci.. code-block:: c 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci int buffer_export(int v4lfd, enum v4l2_buf_type bt, int index, int *dmafd) 7162306a36Sopenharmony_ci { 7262306a36Sopenharmony_ci struct v4l2_exportbuffer expbuf; 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci memset(&expbuf, 0, sizeof(expbuf)); 7562306a36Sopenharmony_ci expbuf.type = bt; 7662306a36Sopenharmony_ci expbuf.index = index; 7762306a36Sopenharmony_ci if (ioctl(v4lfd, VIDIOC_EXPBUF, &expbuf) == -1) { 7862306a36Sopenharmony_ci perror("VIDIOC_EXPBUF"); 7962306a36Sopenharmony_ci return -1; 8062306a36Sopenharmony_ci } 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci *dmafd = expbuf.fd; 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci return 0; 8562306a36Sopenharmony_ci } 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci.. code-block:: c 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci int buffer_export_mp(int v4lfd, enum v4l2_buf_type bt, int index, 9062306a36Sopenharmony_ci int dmafd[], int n_planes) 9162306a36Sopenharmony_ci { 9262306a36Sopenharmony_ci int i; 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci for (i = 0; i < n_planes; ++i) { 9562306a36Sopenharmony_ci struct v4l2_exportbuffer expbuf; 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci memset(&expbuf, 0, sizeof(expbuf)); 9862306a36Sopenharmony_ci expbuf.type = bt; 9962306a36Sopenharmony_ci expbuf.index = index; 10062306a36Sopenharmony_ci expbuf.plane = i; 10162306a36Sopenharmony_ci if (ioctl(v4lfd, VIDIOC_EXPBUF, &expbuf) == -1) { 10262306a36Sopenharmony_ci perror("VIDIOC_EXPBUF"); 10362306a36Sopenharmony_ci while (i) 10462306a36Sopenharmony_ci close(dmafd[--i]); 10562306a36Sopenharmony_ci return -1; 10662306a36Sopenharmony_ci } 10762306a36Sopenharmony_ci dmafd[i] = expbuf.fd; 10862306a36Sopenharmony_ci } 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci return 0; 11162306a36Sopenharmony_ci } 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci.. c:type:: v4l2_exportbuffer 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}| 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci.. flat-table:: struct v4l2_exportbuffer 11862306a36Sopenharmony_ci :header-rows: 0 11962306a36Sopenharmony_ci :stub-columns: 0 12062306a36Sopenharmony_ci :widths: 1 1 2 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci * - __u32 12362306a36Sopenharmony_ci - ``type`` 12462306a36Sopenharmony_ci - Type of the buffer, same as struct 12562306a36Sopenharmony_ci :c:type:`v4l2_format` ``type`` or struct 12662306a36Sopenharmony_ci :c:type:`v4l2_requestbuffers` ``type``, set 12762306a36Sopenharmony_ci by the application. See :c:type:`v4l2_buf_type` 12862306a36Sopenharmony_ci * - __u32 12962306a36Sopenharmony_ci - ``index`` 13062306a36Sopenharmony_ci - Number of the buffer, set by the application. This field is only 13162306a36Sopenharmony_ci used for :ref:`memory mapping <mmap>` I/O and can range from 13262306a36Sopenharmony_ci zero to the number of buffers allocated with the 13362306a36Sopenharmony_ci :ref:`VIDIOC_REQBUFS` and/or 13462306a36Sopenharmony_ci :ref:`VIDIOC_CREATE_BUFS` ioctls. 13562306a36Sopenharmony_ci * - __u32 13662306a36Sopenharmony_ci - ``plane`` 13762306a36Sopenharmony_ci - Index of the plane to be exported when using the multi-planar API. 13862306a36Sopenharmony_ci Otherwise this value must be set to zero. 13962306a36Sopenharmony_ci * - __u32 14062306a36Sopenharmony_ci - ``flags`` 14162306a36Sopenharmony_ci - Flags for the newly created file, currently only ``O_CLOEXEC``, 14262306a36Sopenharmony_ci ``O_RDONLY``, ``O_WRONLY``, and ``O_RDWR`` are supported, refer to 14362306a36Sopenharmony_ci the manual of open() for more details. 14462306a36Sopenharmony_ci * - __s32 14562306a36Sopenharmony_ci - ``fd`` 14662306a36Sopenharmony_ci - The DMABUF file descriptor associated with a buffer. Set by the 14762306a36Sopenharmony_ci driver. 14862306a36Sopenharmony_ci * - __u32 14962306a36Sopenharmony_ci - ``reserved[11]`` 15062306a36Sopenharmony_ci - Reserved field for future use. Drivers and applications must set 15162306a36Sopenharmony_ci the array to zero. 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ciReturn Value 15462306a36Sopenharmony_ci============ 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set 15762306a36Sopenharmony_ciappropriately. The generic error codes are described at the 15862306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter. 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ciEINVAL 16162306a36Sopenharmony_ci A queue is not in MMAP mode or DMABUF exporting is not supported or 16262306a36Sopenharmony_ci ``flags`` or ``type`` or ``index`` or ``plane`` fields are invalid. 163