]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - Documentation/linux_tv/media/v4l/vidioc-expbuf.rst
doc-rst: linux_tv: simplify references
[mirror_ubuntu-artful-kernel.git] / Documentation / linux_tv / media / v4l / vidioc-expbuf.rst
CommitLineData
5377d91f
MH
1.. -*- coding: utf-8; mode: rst -*-
2
af4a4d0d 3.. _VIDIOC_EXPBUF:
5377d91f
MH
4
5*******************
6ioctl VIDIOC_EXPBUF
7*******************
8
9*man VIDIOC_EXPBUF(2)*
10
11Export a buffer as a DMABUF file descriptor.
12
13
14Synopsis
15========
16
17.. c:function:: int ioctl( int fd, int request, struct v4l2_exportbuffer *argp )
18
19Arguments
20=========
21
22``fd``
23 File descriptor returned by :ref:`open() <func-open>`.
24
25``request``
26 VIDIOC_EXPBUF
27
28``argp``
29
30
31Description
32===========
33
34This ioctl is an extension to the :ref:`memory mapping <mmap>` I/O
35method, therefore it is available only for ``V4L2_MEMORY_MMAP`` buffers.
36It can be used to export a buffer as a DMABUF file at any time after
37buffers have been allocated with the
7347081e 38:ref:`VIDIOC_REQBUFS` ioctl.
5377d91f
MH
39
40To export a buffer, applications fill struct
41:ref:`v4l2_exportbuffer <v4l2-exportbuffer>`. The ``type`` field is
42set to the same buffer type as was previously used with struct
43:ref:`v4l2_requestbuffers <v4l2-requestbuffers>` ``type``.
44Applications must also set the ``index`` field. Valid index numbers
45range from zero to the number of buffers allocated with
7347081e 46:ref:`VIDIOC_REQBUFS` (struct
5377d91f
MH
47:ref:`v4l2_requestbuffers <v4l2-requestbuffers>` ``count``) minus
48one. For the multi-planar API, applications set the ``plane`` field to
49the index of the plane to be exported. Valid planes range from zero to
50the maximal number of valid planes for the currently active format. For
51the single-planar API, applications must set ``plane`` to zero.
52Additional flags may be posted in the ``flags`` field. Refer to a manual
53for open() for details. Currently only O_CLOEXEC, O_RDONLY, O_WRONLY,
54and O_RDWR are supported. All other fields must be set to zero. In the
55case of multi-planar API, every plane is exported separately using
56multiple ``VIDIOC_EXPBUF`` calls.
57
58After calling ``VIDIOC_EXPBUF`` the ``fd`` field will be set by a
59driver. This is a DMABUF file descriptor. The application may pass it to
60other DMABUF-aware devices. Refer to :ref:`DMABUF importing <dmabuf>`
61for details about importing DMABUF files into V4L2 nodes. It is
62recommended to close a DMABUF file when it is no longer used to allow
63the associated memory to be reclaimed.
64
65
66Examples
67========
68
69
70.. code-block:: c
71
72 int buffer_export(int v4lfd, enum v4l2_buf_type bt, int index, int *dmafd)
73 {
74 struct v4l2_exportbuffer expbuf;
75
76 memset(&expbuf, 0, sizeof(expbuf));
77 expbuf.type = bt;
78 expbuf.index = index;
79 if (ioctl(v4lfd, VIDIOC_EXPBUF, &expbuf) == -1) {
80 perror("VIDIOC_EXPBUF");
81 return -1;
82 }
83
84 *dmafd = expbuf.fd;
85
86 return 0;
87 }
88
89
90.. code-block:: c
91
92 int buffer_export_mp(int v4lfd, enum v4l2_buf_type bt, int index,
93 int dmafd[], int n_planes)
94 {
95 int i;
96
97 for (i = 0; i < n_planes; ++i) {
98 struct v4l2_exportbuffer expbuf;
99
100 memset(&expbuf, 0, sizeof(expbuf));
101 expbuf.type = bt;
102 expbuf.index = index;
103 expbuf.plane = i;
104 if (ioctl(v4lfd, VIDIOC_EXPBUF, &expbuf) == -1) {
105 perror("VIDIOC_EXPBUF");
106 while (i)
107 close(dmafd[--i]);
108 return -1;
109 }
110 dmafd[i] = expbuf.fd;
111 }
112
113 return 0;
114 }
115
116
117.. _v4l2-exportbuffer:
118
119.. flat-table:: struct v4l2_exportbuffer
120 :header-rows: 0
121 :stub-columns: 0
122 :widths: 1 1 2
123
124
125 - .. row 1
126
127 - __u32
128
129 - ``type``
130
131 - Type of the buffer, same as struct
132 :ref:`v4l2_format <v4l2-format>` ``type`` or struct
133 :ref:`v4l2_requestbuffers <v4l2-requestbuffers>` ``type``, set
134 by the application. See :ref:`v4l2-buf-type`
135
136 - .. row 2
137
138 - __u32
139
140 - ``index``
141
142 - Number of the buffer, set by the application. This field is only
143 used for :ref:`memory mapping <mmap>` I/O and can range from
144 zero to the number of buffers allocated with the
7347081e
MCC
145 :ref:`VIDIOC_REQBUFS` and/or
146 :ref:`VIDIOC_CREATE_BUFS` ioctls.
5377d91f
MH
147
148 - .. row 3
149
150 - __u32
151
152 - ``plane``
153
154 - Index of the plane to be exported when using the multi-planar API.
155 Otherwise this value must be set to zero.
156
157 - .. row 4
158
159 - __u32
160
161 - ``flags``
162
163 - Flags for the newly created file, currently only ``O_CLOEXEC``,
164 ``O_RDONLY``, ``O_WRONLY``, and ``O_RDWR`` are supported, refer to
165 the manual of open() for more details.
166
167 - .. row 5
168
169 - __s32
170
171 - ``fd``
172
173 - The DMABUF file descriptor associated with a buffer. Set by the
174 driver.
175
176 - .. row 6
177
178 - __u32
179
180 - ``reserved[11]``
181
182 - Reserved field for future use. Drivers and applications must set
183 the array to zero.
184
185
186
187Return Value
188============
189
190On success 0 is returned, on error -1 and the ``errno`` variable is set
191appropriately. The generic error codes are described at the
192:ref:`Generic Error Codes <gen-errors>` chapter.
193
194EINVAL
195 A queue is not in MMAP mode or DMABUF exporting is not supported or
196 ``flags`` or ``type`` or ``index`` or ``plane`` fields are invalid.
197
198
199.. ------------------------------------------------------------------------------
200.. This file was automatically converted from DocBook-XML with the dbxml
201.. library (https://github.com/return42/sphkerneldoc). The origin XML comes
202.. from the linux kernel, refer to:
203..
204.. * https://github.com/torvalds/linux/tree/master/Documentation/DocBook
205.. ------------------------------------------------------------------------------