[media] docs-next: stop abusing on the cpp domain
[cascardo/linux.git] / Documentation / media / uapi / v4l / vidioc-g-fbuf.rst
1 .. -*- coding: utf-8; mode: rst -*-
2
3 .. _VIDIOC_G_FBUF:
4
5 **********************************
6 ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF
7 **********************************
8
9 Name
10 ====
11
12 VIDIOC_G_FBUF - VIDIOC_S_FBUF - Get or set frame buffer overlay parameters
13
14
15 Synopsis
16 ========
17
18 .. c:function:: int ioctl( int fd, int request, struct v4l2_framebuffer *argp )
19
20 .. c:function:: int ioctl( int fd, int request, const struct v4l2_framebuffer *argp )
21
22
23 Arguments
24 =========
25
26 ``fd``
27     File descriptor returned by :ref:`open() <func-open>`.
28
29 ``request``
30     VIDIOC_G_FBUF, VIDIOC_S_FBUF
31
32 ``argp``
33
34
35 Description
36 ===========
37
38 Applications can use the :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>` and :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>` ioctl
39 to get and set the framebuffer parameters for a
40 :ref:`Video Overlay <overlay>` or :ref:`Video Output Overlay <osd>`
41 (OSD). The type of overlay is implied by the device type (capture or
42 output device) and can be determined with the
43 :ref:`VIDIOC_QUERYCAP` ioctl. One ``/dev/videoN``
44 device must not support both kinds of overlay.
45
46 The V4L2 API distinguishes destructive and non-destructive overlays. A
47 destructive overlay copies captured video images into the video memory
48 of a graphics card. A non-destructive overlay blends video images into a
49 VGA signal or graphics into a video signal. *Video Output Overlays* are
50 always non-destructive.
51
52 To get the current parameters applications call the :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>`
53 ioctl with a pointer to a :ref:`struct v4l2_framebuffer <v4l2-framebuffer>`
54 structure. The driver fills all fields of the structure or returns an
55 EINVAL error code when overlays are not supported.
56
57 To set the parameters for a *Video Output Overlay*, applications must
58 initialize the ``flags`` field of a struct
59 :ref:`struct v4l2_framebuffer <v4l2-framebuffer>`. Since the framebuffer is
60 implemented on the TV card all other parameters are determined by the
61 driver. When an application calls :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>` with a pointer to
62 this structure, the driver prepares for the overlay and returns the
63 framebuffer parameters as :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>` does, or it returns an error
64 code.
65
66 To set the parameters for a *non-destructive Video Overlay*,
67 applications must initialize the ``flags`` field, the ``fmt``
68 substructure, and call :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>`. Again the driver prepares for
69 the overlay and returns the framebuffer parameters as :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>`
70 does, or it returns an error code.
71
72 For a *destructive Video Overlay* applications must additionally provide
73 a ``base`` address. Setting up a DMA to a random memory location can
74 jeopardize the system security, its stability or even damage the
75 hardware, therefore only the superuser can set the parameters for a
76 destructive video overlay.
77
78
79 .. tabularcolumns:: |p{3.5cm}|p{3.5cm}|p{3.5cm}|p{7.0cm}|
80
81 .. _v4l2-framebuffer:
82
83 .. cssclass:: longtable
84
85 .. flat-table:: struct v4l2_framebuffer
86     :header-rows:  0
87     :stub-columns: 0
88     :widths:       1 1 1 2
89
90
91     -  .. row 1
92
93        -  __u32
94
95        -  ``capability``
96
97        -
98        -  Overlay capability flags set by the driver, see
99           :ref:`framebuffer-cap`.
100
101     -  .. row 2
102
103        -  __u32
104
105        -  ``flags``
106
107        -
108        -  Overlay control flags set by application and driver, see
109           :ref:`framebuffer-flags`
110
111     -  .. row 3
112
113        -  void *
114
115        -  ``base``
116
117        -
118        -  Physical base address of the framebuffer, that is the address of
119           the pixel in the top left corner of the framebuffer. [#f1]_
120
121     -  .. row 4
122
123        -
124        -
125        -
126        -  This field is irrelevant to *non-destructive Video Overlays*. For
127           *destructive Video Overlays* applications must provide a base
128           address. The driver may accept only base addresses which are a
129           multiple of two, four or eight bytes. For *Video Output Overlays*
130           the driver must return a valid base address, so applications can
131           find the corresponding Linux framebuffer device (see
132           :ref:`osd`).
133
134     -  .. row 5
135
136        -  struct
137
138        -  ``fmt``
139
140        -
141        -  Layout of the frame buffer.
142
143     -  .. row 6
144
145        -
146        -  __u32
147
148        -  ``width``
149
150        -  Width of the frame buffer in pixels.
151
152     -  .. row 7
153
154        -
155        -  __u32
156
157        -  ``height``
158
159        -  Height of the frame buffer in pixels.
160
161     -  .. row 8
162
163        -
164        -  __u32
165
166        -  ``pixelformat``
167
168        -  The pixel format of the framebuffer.
169
170     -  .. row 9
171
172        -
173        -
174        -
175        -  For *non-destructive Video Overlays* this field only defines a
176           format for the struct :ref:`v4l2_window <v4l2-window>`
177           ``chromakey`` field.
178
179     -  .. row 10
180
181        -
182        -
183        -
184        -  For *destructive Video Overlays* applications must initialize this
185           field. For *Video Output Overlays* the driver must return a valid
186           format.
187
188     -  .. row 11
189
190        -
191        -
192        -
193        -  Usually this is an RGB format (for example
194           :ref:`V4L2_PIX_FMT_RGB565 <V4L2-PIX-FMT-RGB565>`) but YUV
195           formats (only packed YUV formats when chroma keying is used, not
196           including ``V4L2_PIX_FMT_YUYV`` and ``V4L2_PIX_FMT_UYVY``) and the
197           ``V4L2_PIX_FMT_PAL8`` format are also permitted. The behavior of
198           the driver when an application requests a compressed format is
199           undefined. See :ref:`pixfmt` for information on pixel formats.
200
201     -  .. row 12
202
203        -
204        -  enum :ref:`v4l2_field <v4l2-field>`
205
206        -  ``field``
207
208        -  Drivers and applications shall ignore this field. If applicable,
209           the field order is selected with the
210           :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, using the ``field``
211           field of struct :ref:`v4l2_window <v4l2-window>`.
212
213     -  .. row 13
214
215        -
216        -  __u32
217
218        -  ``bytesperline``
219
220        -  Distance in bytes between the leftmost pixels in two adjacent
221           lines.
222
223     -  .. row 14
224
225        -  :cspan:`3`
226
227           This field is irrelevant to *non-destructive Video Overlays*.
228
229           For *destructive Video Overlays* both applications and drivers can
230           set this field to request padding bytes at the end of each line.
231           Drivers however may ignore the requested value, returning
232           ``width`` times bytes-per-pixel or a larger value required by the
233           hardware. That implies applications can just set this field to
234           zero to get a reasonable default.
235
236           For *Video Output Overlays* the driver must return a valid value.
237
238           Video hardware may access padding bytes, therefore they must
239           reside in accessible memory. Consider for example the case where
240           padding bytes after the last line of an image cross a system page
241           boundary. Capture devices may write padding bytes, the value is
242           undefined. Output devices ignore the contents of padding bytes.
243
244           When the image format is planar the ``bytesperline`` value applies
245           to the first plane and is divided by the same factor as the
246           ``width`` field for the other planes. For example the Cb and Cr
247           planes of a YUV 4:2:0 image have half as many padding bytes
248           following each line as the Y plane. To avoid ambiguities drivers
249           must return a ``bytesperline`` value rounded up to a multiple of
250           the scale factor.
251
252     -  .. row 15
253
254        -
255        -  __u32
256
257        -  ``sizeimage``
258
259        -  This field is irrelevant to *non-destructive Video Overlays*. For
260           *destructive Video Overlays* applications must initialize this
261           field. For *Video Output Overlays* the driver must return a valid
262           format.
263
264           Together with ``base`` it defines the framebuffer memory
265           accessible by the driver.
266
267     -  .. row 16
268
269        -
270        -  enum :ref:`v4l2_colorspace <v4l2-colorspace>`
271
272        -  ``colorspace``
273
274        -  This information supplements the ``pixelformat`` and must be set
275           by the driver, see :ref:`colorspaces`.
276
277     -  .. row 17
278
279        -
280        -  __u32
281
282        -  ``priv``
283
284        -  Reserved. Drivers and applications must set this field to zero.
285
286
287 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
288
289 .. _framebuffer-cap:
290
291 .. flat-table:: Frame Buffer Capability Flags
292     :header-rows:  0
293     :stub-columns: 0
294     :widths:       3 1 4
295
296
297     -  .. row 1
298
299        -  ``V4L2_FBUF_CAP_EXTERNOVERLAY``
300
301        -  0x0001
302
303        -  The device is capable of non-destructive overlays. When the driver
304           clears this flag, only destructive overlays are supported. There
305           are no drivers yet which support both destructive and
306           non-destructive overlays. Video Output Overlays are in practice
307           always non-destructive.
308
309     -  .. row 2
310
311        -  ``V4L2_FBUF_CAP_CHROMAKEY``
312
313        -  0x0002
314
315        -  The device supports clipping by chroma-keying the images. That is,
316           image pixels replace pixels in the VGA or video signal only where
317           the latter assume a certain color. Chroma-keying makes no sense
318           for destructive overlays.
319
320     -  .. row 3
321
322        -  ``V4L2_FBUF_CAP_LIST_CLIPPING``
323
324        -  0x0004
325
326        -  The device supports clipping using a list of clip rectangles.
327
328     -  .. row 4
329
330        -  ``V4L2_FBUF_CAP_BITMAP_CLIPPING``
331
332        -  0x0008
333
334        -  The device supports clipping using a bit mask.
335
336     -  .. row 5
337
338        -  ``V4L2_FBUF_CAP_LOCAL_ALPHA``
339
340        -  0x0010
341
342        -  The device supports clipping/blending using the alpha channel of
343           the framebuffer or VGA signal. Alpha blending makes no sense for
344           destructive overlays.
345
346     -  .. row 6
347
348        -  ``V4L2_FBUF_CAP_GLOBAL_ALPHA``
349
350        -  0x0020
351
352        -  The device supports alpha blending using a global alpha value.
353           Alpha blending makes no sense for destructive overlays.
354
355     -  .. row 7
356
357        -  ``V4L2_FBUF_CAP_LOCAL_INV_ALPHA``
358
359        -  0x0040
360
361        -  The device supports clipping/blending using the inverted alpha
362           channel of the framebuffer or VGA signal. Alpha blending makes no
363           sense for destructive overlays.
364
365     -  .. row 8
366
367        -  ``V4L2_FBUF_CAP_SRC_CHROMAKEY``
368
369        -  0x0080
370
371        -  The device supports Source Chroma-keying. Video pixels with the
372           chroma-key colors are replaced by framebuffer pixels, which is
373           exactly opposite of ``V4L2_FBUF_CAP_CHROMAKEY``
374
375
376 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
377
378 .. _framebuffer-flags:
379
380 .. cssclass:: longtable
381
382 .. flat-table:: Frame Buffer Flags
383     :header-rows:  0
384     :stub-columns: 0
385     :widths:       3 1 4
386
387
388     -  .. row 1
389
390        -  ``V4L2_FBUF_FLAG_PRIMARY``
391
392        -  0x0001
393
394        -  The framebuffer is the primary graphics surface. In other words,
395           the overlay is destructive. This flag is typically set by any
396           driver that doesn't have the ``V4L2_FBUF_CAP_EXTERNOVERLAY``
397           capability and it is cleared otherwise.
398
399     -  .. row 2
400
401        -  ``V4L2_FBUF_FLAG_OVERLAY``
402
403        -  0x0002
404
405        -  If this flag is set for a video capture device, then the driver
406           will set the initial overlay size to cover the full framebuffer
407           size, otherwise the existing overlay size (as set by
408           :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`) will be used. Only one
409           video capture driver (bttv) supports this flag. The use of this
410           flag for capture devices is deprecated. There is no way to detect
411           which drivers support this flag, so the only reliable method of
412           setting the overlay size is through
413           :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`. If this flag is set for a
414           video output device, then the video output overlay window is
415           relative to the top-left corner of the framebuffer and restricted
416           to the size of the framebuffer. If it is cleared, then the video
417           output overlay window is relative to the video output display.
418
419     -  .. row 3
420
421        -  ``V4L2_FBUF_FLAG_CHROMAKEY``
422
423        -  0x0004
424
425        -  Use chroma-keying. The chroma-key color is determined by the
426           ``chromakey`` field of struct :ref:`v4l2_window <v4l2-window>`
427           and negotiated with the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
428           ioctl, see :ref:`overlay` and :ref:`osd`.
429
430     -  .. row 4
431
432        -  :cspan:`2` There are no flags to enable clipping using a list of
433           clip rectangles or a bitmap. These methods are negotiated with the
434           :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, see :ref:`overlay`
435           and :ref:`osd`.
436
437     -  .. row 5
438
439        -  ``V4L2_FBUF_FLAG_LOCAL_ALPHA``
440
441        -  0x0008
442
443        -  Use the alpha channel of the framebuffer to clip or blend
444           framebuffer pixels with video images. The blend function is:
445           output = framebuffer pixel * alpha + video pixel * (1 - alpha).
446           The actual alpha depth depends on the framebuffer pixel format.
447
448     -  .. row 6
449
450        -  ``V4L2_FBUF_FLAG_GLOBAL_ALPHA``
451
452        -  0x0010
453
454        -  Use a global alpha value to blend the framebuffer with video
455           images. The blend function is: output = (framebuffer pixel * alpha
456           + video pixel * (255 - alpha)) / 255. The alpha value is
457           determined by the ``global_alpha`` field of struct
458           :ref:`v4l2_window <v4l2-window>` and negotiated with the
459           :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, see :ref:`overlay`
460           and :ref:`osd`.
461
462     -  .. row 7
463
464        -  ``V4L2_FBUF_FLAG_LOCAL_INV_ALPHA``
465
466        -  0x0020
467
468        -  Like ``V4L2_FBUF_FLAG_LOCAL_ALPHA``, use the alpha channel of the
469           framebuffer to clip or blend framebuffer pixels with video images,
470           but with an inverted alpha value. The blend function is: output =
471           framebuffer pixel * (1 - alpha) + video pixel * alpha. The actual
472           alpha depth depends on the framebuffer pixel format.
473
474     -  .. row 8
475
476        -  ``V4L2_FBUF_FLAG_SRC_CHROMAKEY``
477
478        -  0x0040
479
480        -  Use source chroma-keying. The source chroma-key color is
481           determined by the ``chromakey`` field of struct
482           :ref:`v4l2_window <v4l2-window>` and negotiated with the
483           :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, see :ref:`overlay`
484           and :ref:`osd`. Both chroma-keying are mutual exclusive to each
485           other, so same ``chromakey`` field of struct
486           :ref:`v4l2_window <v4l2-window>` is being used.
487
488
489 Return Value
490 ============
491
492 On success 0 is returned, on error -1 and the ``errno`` variable is set
493 appropriately. The generic error codes are described at the
494 :ref:`Generic Error Codes <gen-errors>` chapter.
495
496 EPERM
497     :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>` can only be called by a privileged user to
498     negotiate the parameters for a destructive overlay.
499
500 EINVAL
501     The :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>` parameters are unsuitable.
502
503 .. [#f1]
504    A physical base address may not suit all platforms. GK notes in
505    theory we should pass something like PCI device + memory region +
506    offset instead. If you encounter problems please discuss on the
507    linux-media mailing list:
508    `https://linuxtv.org/lists.php <https://linuxtv.org/lists.php>`__.