vidioc-expbuf.rst 5.5 KB
Newer Older
1 2
.. -*- coding: utf-8; mode: rst -*-

3
.. _VIDIOC_EXPBUF:
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

*******************
ioctl VIDIOC_EXPBUF
*******************

*man VIDIOC_EXPBUF(2)*

Export a buffer as a DMABUF file descriptor.


Synopsis
========

.. c:function:: int ioctl( int fd, int request, struct v4l2_exportbuffer *argp )

Arguments
=========

``fd``
    File descriptor returned by :ref:`open() <func-open>`.

``request``
    VIDIOC_EXPBUF

``argp``


Description
===========

This ioctl is an extension to the :ref:`memory mapping <mmap>` 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
38
:ref:`VIDIOC_REQBUFS <VIDIOC_REQBUFS>` ioctl.
39 40 41 42 43 44 45

To export a buffer, applications fill struct
:ref:`v4l2_exportbuffer <v4l2-exportbuffer>`. The ``type`` field is
set to the same buffer type as was previously used with struct
:ref:`v4l2_requestbuffers <v4l2-requestbuffers>` ``type``.
Applications must also set the ``index`` field. Valid index numbers
range from zero to the number of buffers allocated with
46
:ref:`VIDIOC_REQBUFS <VIDIOC_REQBUFS>` (struct
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
:ref:`v4l2_requestbuffers <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, O_RDONLY, O_WRONLY,
and O_RDWR are 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 :ref:`DMABUF importing <dmabuf>`
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
========


.. code-block:: c

    int buffer_export(int v4lfd, enum v4l2_buf_type bt, int index, int *dmafd)
    {
        struct 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;
    }


.. code-block:: c

    int buffer_export_mp(int v4lfd, enum v4l2_buf_type bt, int index,
        int dmafd[], int n_planes)
    {
        int i;

        for (i = 0; i < n_planes; ++i) {
            struct 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;
    }


.. _v4l2-exportbuffer:

.. flat-table:: struct v4l2_exportbuffer
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2


    -  .. row 1

       -  __u32

       -  ``type``

       -  Type of the buffer, same as struct
          :ref:`v4l2_format <v4l2-format>` ``type`` or struct
          :ref:`v4l2_requestbuffers <v4l2-requestbuffers>` ``type``, set
          by the application. See :ref:`v4l2-buf-type`

    -  .. row 2

       -  __u32

       -  ``index``

       -  Number of the buffer, set by the application. This field is only
          used for :ref:`memory mapping <mmap>` I/O and can range from
          zero to the number of buffers allocated with the
145 146
          :ref:`VIDIOC_REQBUFS <VIDIOC_REQBUFS>` and/or
          :ref:`VIDIOC_CREATE_BUFS <VIDIOC_CREATE_BUFS>` ioctls.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205

    -  .. row 3

       -  __u32

       -  ``plane``

       -  Index of the plane to be exported when using the multi-planar API.
          Otherwise this value must be set to zero.

    -  .. row 4

       -  __u32

       -  ``flags``

       -  Flags for the newly created file, currently only ``O_CLOEXEC``,
          ``O_RDONLY``, ``O_WRONLY``, and ``O_RDWR`` are supported, refer to
          the manual of open() for more details.

    -  .. row 5

       -  __s32

       -  ``fd``

       -  The DMABUF file descriptor associated with a buffer. Set by the
          driver.

    -  .. row 6

       -  __u32

       -  ``reserved[11]``

       -  Reserved field for future use. Drivers and applications must set
          the array to zero.



Return Value
============

On success 0 is returned, on error -1 and the ``errno`` variable is set
appropriately. The generic error codes are described at the
:ref:`Generic Error Codes <gen-errors>` chapter.

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.


.. ------------------------------------------------------------------------------
.. This file was automatically converted from DocBook-XML with the dbxml
.. library (https://github.com/return42/sphkerneldoc). The origin XML comes
.. from the linux kernel, refer to:
..
.. * https://github.com/torvalds/linux/tree/master/Documentation/DocBook
.. ------------------------------------------------------------------------------