1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2*4882a593Smuzhiyun.. c:namespace:: V4L 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun.. _VIDIOC_EXPBUF: 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun******************* 7*4882a593Smuzhiyunioctl VIDIOC_EXPBUF 8*4882a593Smuzhiyun******************* 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunName 11*4882a593Smuzhiyun==== 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunVIDIOC_EXPBUF - Export a buffer as a DMABUF file descriptor. 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunSynopsis 16*4882a593Smuzhiyun======== 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun.. c:macro:: VIDIOC_EXPBUF 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun``int ioctl(int fd, VIDIOC_EXPBUF, struct v4l2_exportbuffer *argp)`` 21*4882a593Smuzhiyun 22*4882a593SmuzhiyunArguments 23*4882a593Smuzhiyun========= 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun``fd`` 26*4882a593Smuzhiyun File descriptor returned by :c:func:`open()`. 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun``argp`` 29*4882a593Smuzhiyun Pointer to struct :c:type:`v4l2_exportbuffer`. 30*4882a593Smuzhiyun 31*4882a593SmuzhiyunDescription 32*4882a593Smuzhiyun=========== 33*4882a593Smuzhiyun 34*4882a593SmuzhiyunThis ioctl is an extension to the :ref:`memory mapping <mmap>` I/O 35*4882a593Smuzhiyunmethod, therefore it is available only for ``V4L2_MEMORY_MMAP`` buffers. 36*4882a593SmuzhiyunIt can be used to export a buffer as a DMABUF file at any time after 37*4882a593Smuzhiyunbuffers have been allocated with the 38*4882a593Smuzhiyun:ref:`VIDIOC_REQBUFS` ioctl. 39*4882a593Smuzhiyun 40*4882a593SmuzhiyunTo export a buffer, applications fill struct 41*4882a593Smuzhiyun:c:type:`v4l2_exportbuffer`. The ``type`` field is 42*4882a593Smuzhiyunset to the same buffer type as was previously used with struct 43*4882a593Smuzhiyun:c:type:`v4l2_requestbuffers` ``type``. 44*4882a593SmuzhiyunApplications must also set the ``index`` field. Valid index numbers 45*4882a593Smuzhiyunrange from zero to the number of buffers allocated with 46*4882a593Smuzhiyun:ref:`VIDIOC_REQBUFS` (struct 47*4882a593Smuzhiyun:c:type:`v4l2_requestbuffers` ``count``) minus 48*4882a593Smuzhiyunone. For the multi-planar API, applications set the ``plane`` field to 49*4882a593Smuzhiyunthe index of the plane to be exported. Valid planes range from zero to 50*4882a593Smuzhiyunthe maximal number of valid planes for the currently active format. For 51*4882a593Smuzhiyunthe single-planar API, applications must set ``plane`` to zero. 52*4882a593SmuzhiyunAdditional flags may be posted in the ``flags`` field. Refer to a manual 53*4882a593Smuzhiyunfor open() for details. Currently only O_CLOEXEC, O_RDONLY, O_WRONLY, 54*4882a593Smuzhiyunand O_RDWR are supported. All other fields must be set to zero. In the 55*4882a593Smuzhiyuncase of multi-planar API, every plane is exported separately using 56*4882a593Smuzhiyunmultiple :ref:`VIDIOC_EXPBUF` calls. 57*4882a593Smuzhiyun 58*4882a593SmuzhiyunAfter calling :ref:`VIDIOC_EXPBUF` the ``fd`` field will be set by a 59*4882a593Smuzhiyundriver. This is a DMABUF file descriptor. The application may pass it to 60*4882a593Smuzhiyunother DMABUF-aware devices. Refer to :ref:`DMABUF importing <dmabuf>` 61*4882a593Smuzhiyunfor details about importing DMABUF files into V4L2 nodes. It is 62*4882a593Smuzhiyunrecommended to close a DMABUF file when it is no longer used to allow 63*4882a593Smuzhiyunthe associated memory to be reclaimed. 64*4882a593Smuzhiyun 65*4882a593SmuzhiyunExamples 66*4882a593Smuzhiyun======== 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun.. code-block:: c 69*4882a593Smuzhiyun 70*4882a593Smuzhiyun int buffer_export(int v4lfd, enum v4l2_buf_type bt, int index, int *dmafd) 71*4882a593Smuzhiyun { 72*4882a593Smuzhiyun struct v4l2_exportbuffer expbuf; 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun memset(&expbuf, 0, sizeof(expbuf)); 75*4882a593Smuzhiyun expbuf.type = bt; 76*4882a593Smuzhiyun expbuf.index = index; 77*4882a593Smuzhiyun if (ioctl(v4lfd, VIDIOC_EXPBUF, &expbuf) == -1) { 78*4882a593Smuzhiyun perror("VIDIOC_EXPBUF"); 79*4882a593Smuzhiyun return -1; 80*4882a593Smuzhiyun } 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun *dmafd = expbuf.fd; 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun return 0; 85*4882a593Smuzhiyun } 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun.. code-block:: c 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun int buffer_export_mp(int v4lfd, enum v4l2_buf_type bt, int index, 90*4882a593Smuzhiyun int dmafd[], int n_planes) 91*4882a593Smuzhiyun { 92*4882a593Smuzhiyun int i; 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun for (i = 0; i < n_planes; ++i) { 95*4882a593Smuzhiyun struct v4l2_exportbuffer expbuf; 96*4882a593Smuzhiyun 97*4882a593Smuzhiyun memset(&expbuf, 0, sizeof(expbuf)); 98*4882a593Smuzhiyun expbuf.type = bt; 99*4882a593Smuzhiyun expbuf.index = index; 100*4882a593Smuzhiyun expbuf.plane = i; 101*4882a593Smuzhiyun if (ioctl(v4lfd, VIDIOC_EXPBUF, &expbuf) == -1) { 102*4882a593Smuzhiyun perror("VIDIOC_EXPBUF"); 103*4882a593Smuzhiyun while (i) 104*4882a593Smuzhiyun close(dmafd[--i]); 105*4882a593Smuzhiyun return -1; 106*4882a593Smuzhiyun } 107*4882a593Smuzhiyun dmafd[i] = expbuf.fd; 108*4882a593Smuzhiyun } 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun return 0; 111*4882a593Smuzhiyun } 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun.. c:type:: v4l2_exportbuffer 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}| 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun.. flat-table:: struct v4l2_exportbuffer 118*4882a593Smuzhiyun :header-rows: 0 119*4882a593Smuzhiyun :stub-columns: 0 120*4882a593Smuzhiyun :widths: 1 1 2 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun * - __u32 123*4882a593Smuzhiyun - ``type`` 124*4882a593Smuzhiyun - Type of the buffer, same as struct 125*4882a593Smuzhiyun :c:type:`v4l2_format` ``type`` or struct 126*4882a593Smuzhiyun :c:type:`v4l2_requestbuffers` ``type``, set 127*4882a593Smuzhiyun by the application. See :c:type:`v4l2_buf_type` 128*4882a593Smuzhiyun * - __u32 129*4882a593Smuzhiyun - ``index`` 130*4882a593Smuzhiyun - Number of the buffer, set by the application. This field is only 131*4882a593Smuzhiyun used for :ref:`memory mapping <mmap>` I/O and can range from 132*4882a593Smuzhiyun zero to the number of buffers allocated with the 133*4882a593Smuzhiyun :ref:`VIDIOC_REQBUFS` and/or 134*4882a593Smuzhiyun :ref:`VIDIOC_CREATE_BUFS` ioctls. 135*4882a593Smuzhiyun * - __u32 136*4882a593Smuzhiyun - ``plane`` 137*4882a593Smuzhiyun - Index of the plane to be exported when using the multi-planar API. 138*4882a593Smuzhiyun Otherwise this value must be set to zero. 139*4882a593Smuzhiyun * - __u32 140*4882a593Smuzhiyun - ``flags`` 141*4882a593Smuzhiyun - Flags for the newly created file, currently only ``O_CLOEXEC``, 142*4882a593Smuzhiyun ``O_RDONLY``, ``O_WRONLY``, and ``O_RDWR`` are supported, refer to 143*4882a593Smuzhiyun the manual of open() for more details. 144*4882a593Smuzhiyun * - __s32 145*4882a593Smuzhiyun - ``fd`` 146*4882a593Smuzhiyun - The DMABUF file descriptor associated with a buffer. Set by the 147*4882a593Smuzhiyun driver. 148*4882a593Smuzhiyun * - __u32 149*4882a593Smuzhiyun - ``reserved[11]`` 150*4882a593Smuzhiyun - Reserved field for future use. Drivers and applications must set 151*4882a593Smuzhiyun the array to zero. 152*4882a593Smuzhiyun 153*4882a593SmuzhiyunReturn Value 154*4882a593Smuzhiyun============ 155*4882a593Smuzhiyun 156*4882a593SmuzhiyunOn success 0 is returned, on error -1 and the ``errno`` variable is set 157*4882a593Smuzhiyunappropriately. The generic error codes are described at the 158*4882a593Smuzhiyun:ref:`Generic Error Codes <gen-errors>` chapter. 159*4882a593Smuzhiyun 160*4882a593SmuzhiyunEINVAL 161*4882a593Smuzhiyun A queue is not in MMAP mode or DMABUF exporting is not supported or 162*4882a593Smuzhiyun ``flags`` or ``type`` or ``index`` or ``plane`` fields are invalid. 163