vidioc-g-fbuf.rst 14.2 KB
Newer Older
1 2
.. -*- coding: utf-8; mode: rst -*-

3
.. _VIDIOC_G_FBUF:
4 5 6 7 8

**********************************
ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF
**********************************

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 27 28 29 30 31 32 33 34
=========

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

``request``
    VIDIOC_G_FBUF, VIDIOC_S_FBUF

``argp``


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 40 41 42
to get and set the framebuffer parameters for a
:ref:`Video Overlay <overlay>` or :ref:`Video Output Overlay <osd>`
(OSD). The type of overlay is implied by the device type (capture or
output device) and can be determined with the
43
:ref:`VIDIOC_QUERYCAP` ioctl. One ``/dev/videoN``
44 45 46 47 48 49 50 51
device must not support both kinds of overlay.

The V4L2 API distinguishes destructive and non-destructive overlays. A
destructive overlay copies captured video images into the video memory
of a graphics card. A non-destructive overlay blends video images into a
VGA signal or graphics into a video signal. *Video Output Overlays* are
always non-destructive.

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 55 56 57 58
structure. The driver fills all fields of the structure or returns an
EINVAL error code when overlays are not supported.

To set the parameters for a *Video Output Overlay*, applications must
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 65 66 67
code.

To set the parameters for a *non-destructive Video Overlay*,
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 71 72 73 74 75 76 77 78
does, or it returns an error code.

For a *destructive Video Overlay* applications must additionally provide
a ``base`` address. Setting up a DMA to a random memory location can
jeopardize the system security, its stability or even damage the
hardware, therefore only the superuser can set the parameters for a
destructive video overlay.


79 80
.. tabularcolumns:: |p{3.5cm}|p{3.5cm}|p{3.5cm}|p{7.0cm}|

81 82
.. _v4l2-framebuffer:

83 84
.. cssclass:: longtable

85 86 87 88 89 90 91 92 93 94 95 96
.. flat-table:: struct v4l2_framebuffer
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 1 2


    -  .. row 1

       -  __u32

       -  ``capability``

97
       -
98
       -  Overlay capability flags set by the driver, see
99
	  :ref:`framebuffer-cap`.
100 101 102 103 104 105 106

    -  .. row 2

       -  __u32

       -  ``flags``

107
       -
108
       -  Overlay control flags set by application and driver, see
109
	  :ref:`framebuffer-flags`
110 111 112 113 114 115 116

    -  .. row 3

       -  void *

       -  ``base``

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 122

    -  .. row 4

123 124 125
       -
       -
       -
126
       -  This field is irrelevant to *non-destructive Video Overlays*. For
127 128 129 130 131 132
	  *destructive Video Overlays* applications must provide a base
	  address. The driver may accept only base addresses which are a
	  multiple of two, four or eight bytes. For *Video Output Overlays*
	  the driver must return a valid base address, so applications can
	  find the corresponding Linux framebuffer device (see
	  :ref:`osd`).
133 134 135 136 137 138 139

    -  .. row 5

       -  struct

       -  ``fmt``

140
       -
141 142 143 144
       -  Layout of the frame buffer.

    -  .. row 6

145
       -
146 147 148 149 150 151 152 153
       -  __u32

       -  ``width``

       -  Width of the frame buffer in pixels.

    -  .. row 7

154
       -
155 156 157 158 159 160 161 162
       -  __u32

       -  ``height``

       -  Height of the frame buffer in pixels.

    -  .. row 8

163
       -
164 165 166 167 168 169 170 171
       -  __u32

       -  ``pixelformat``

       -  The pixel format of the framebuffer.

    -  .. row 9

172 173 174
       -
       -
       -
175
       -  For *non-destructive Video Overlays* this field only defines a
176 177
	  format for the struct :ref:`v4l2_window <v4l2-window>`
	  ``chromakey`` field.
178 179 180

    -  .. row 10

181 182 183
       -
       -
       -
184
       -  For *destructive Video Overlays* applications must initialize this
185 186
	  field. For *Video Output Overlays* the driver must return a valid
	  format.
187 188 189

    -  .. row 11

190 191 192
       -
       -
       -
193
       -  Usually this is an RGB format (for example
194 195 196 197 198 199
	  :ref:`V4L2_PIX_FMT_RGB565 <V4L2-PIX-FMT-RGB565>`) but YUV
	  formats (only packed YUV formats when chroma keying is used, not
	  including ``V4L2_PIX_FMT_YUYV`` and ``V4L2_PIX_FMT_UYVY``) and the
	  ``V4L2_PIX_FMT_PAL8`` format are also permitted. The behavior of
	  the driver when an application requests a compressed format is
	  undefined. See :ref:`pixfmt` for information on pixel formats.
200 201 202

    -  .. row 12

203
       -
204 205 206 207 208
       -  enum :ref:`v4l2_field <v4l2-field>`

       -  ``field``

       -  Drivers and applications shall ignore this field. If applicable,
209 210 211
	  the field order is selected with the
	  :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, using the ``field``
	  field of struct :ref:`v4l2_window <v4l2-window>`.
212 213 214

    -  .. row 13

215
       -
216 217 218 219 220
       -  __u32

       -  ``bytesperline``

       -  Distance in bytes between the leftmost pixels in two adjacent
221
	  lines.
222 223 224 225 226

    -  .. row 14

       -  :cspan:`3`

227
	  This field is irrelevant to *non-destructive Video Overlays*.
228

229 230 231 232 233 234
	  For *destructive Video Overlays* both applications and drivers can
	  set this field to request padding bytes at the end of each line.
	  Drivers however may ignore the requested value, returning
	  ``width`` times bytes-per-pixel or a larger value required by the
	  hardware. That implies applications can just set this field to
	  zero to get a reasonable default.
235

236
	  For *Video Output Overlays* the driver must return a valid value.
237

238 239 240 241 242
	  Video hardware may access padding bytes, therefore they must
	  reside in accessible memory. Consider for example the case where
	  padding bytes after the last line of an image cross a system page
	  boundary. Capture devices may write padding bytes, the value is
	  undefined. Output devices ignore the contents of padding bytes.
243

244 245 246 247 248 249 250
	  When the image format is planar the ``bytesperline`` value applies
	  to the first plane and is divided by the same factor as the
	  ``width`` field for the other planes. For example the Cb and Cr
	  planes of a YUV 4:2:0 image have half as many padding bytes
	  following each line as the Y plane. To avoid ambiguities drivers
	  must return a ``bytesperline`` value rounded up to a multiple of
	  the scale factor.
251 252 253

    -  .. row 15

254
       -
255 256 257 258 259
       -  __u32

       -  ``sizeimage``

       -  This field is irrelevant to *non-destructive Video Overlays*. For
260 261 262
	  *destructive Video Overlays* applications must initialize this
	  field. For *Video Output Overlays* the driver must return a valid
	  format.
263

264 265
	  Together with ``base`` it defines the framebuffer memory
	  accessible by the driver.
266 267 268

    -  .. row 16

269
       -
270 271 272 273 274
       -  enum :ref:`v4l2_colorspace <v4l2-colorspace>`

       -  ``colorspace``

       -  This information supplements the ``pixelformat`` and must be set
275
	  by the driver, see :ref:`colorspaces`.
276 277 278

    -  .. row 17

279
       -
280 281 282 283 284 285 286
       -  __u32

       -  ``priv``

       -  Reserved. Drivers and applications must set this field to zero.


287
.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303

.. _framebuffer-cap:

.. flat-table:: Frame Buffer Capability Flags
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4


    -  .. row 1

       -  ``V4L2_FBUF_CAP_EXTERNOVERLAY``

       -  0x0001

       -  The device is capable of non-destructive overlays. When the driver
304 305 306 307
	  clears this flag, only destructive overlays are supported. There
	  are no drivers yet which support both destructive and
	  non-destructive overlays. Video Output Overlays are in practice
	  always non-destructive.
308 309 310 311 312 313 314 315

    -  .. row 2

       -  ``V4L2_FBUF_CAP_CHROMAKEY``

       -  0x0002

       -  The device supports clipping by chroma-keying the images. That is,
316 317 318
	  image pixels replace pixels in the VGA or video signal only where
	  the latter assume a certain color. Chroma-keying makes no sense
	  for destructive overlays.
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342

    -  .. row 3

       -  ``V4L2_FBUF_CAP_LIST_CLIPPING``

       -  0x0004

       -  The device supports clipping using a list of clip rectangles.

    -  .. row 4

       -  ``V4L2_FBUF_CAP_BITMAP_CLIPPING``

       -  0x0008

       -  The device supports clipping using a bit mask.

    -  .. row 5

       -  ``V4L2_FBUF_CAP_LOCAL_ALPHA``

       -  0x0010

       -  The device supports clipping/blending using the alpha channel of
343 344
	  the framebuffer or VGA signal. Alpha blending makes no sense for
	  destructive overlays.
345 346 347 348 349 350 351 352

    -  .. row 6

       -  ``V4L2_FBUF_CAP_GLOBAL_ALPHA``

       -  0x0020

       -  The device supports alpha blending using a global alpha value.
353
	  Alpha blending makes no sense for destructive overlays.
354 355 356 357 358 359 360 361

    -  .. row 7

       -  ``V4L2_FBUF_CAP_LOCAL_INV_ALPHA``

       -  0x0040

       -  The device supports clipping/blending using the inverted alpha
362 363
	  channel of the framebuffer or VGA signal. Alpha blending makes no
	  sense for destructive overlays.
364 365 366 367 368 369 370 371

    -  .. row 8

       -  ``V4L2_FBUF_CAP_SRC_CHROMAKEY``

       -  0x0080

       -  The device supports Source Chroma-keying. Video pixels with the
372 373
	  chroma-key colors are replaced by framebuffer pixels, which is
	  exactly opposite of ``V4L2_FBUF_CAP_CHROMAKEY``
374 375


376
.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
377 378 379

.. _framebuffer-flags:

380 381
.. cssclass:: longtable

382 383 384 385 386 387 388 389 390 391 392 393 394
.. flat-table:: Frame Buffer Flags
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4


    -  .. row 1

       -  ``V4L2_FBUF_FLAG_PRIMARY``

       -  0x0001

       -  The framebuffer is the primary graphics surface. In other words,
395 396 397
	  the overlay is destructive. This flag is typically set by any
	  driver that doesn't have the ``V4L2_FBUF_CAP_EXTERNOVERLAY``
	  capability and it is cleared otherwise.
398 399 400 401 402 403 404 405

    -  .. row 2

       -  ``V4L2_FBUF_FLAG_OVERLAY``

       -  0x0002

       -  If this flag is set for a video capture device, then the driver
406 407 408 409 410 411 412 413 414 415 416 417
	  will set the initial overlay size to cover the full framebuffer
	  size, otherwise the existing overlay size (as set by
	  :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`) will be used. Only one
	  video capture driver (bttv) supports this flag. The use of this
	  flag for capture devices is deprecated. There is no way to detect
	  which drivers support this flag, so the only reliable method of
	  setting the overlay size is through
	  :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`. If this flag is set for a
	  video output device, then the video output overlay window is
	  relative to the top-left corner of the framebuffer and restricted
	  to the size of the framebuffer. If it is cleared, then the video
	  output overlay window is relative to the video output display.
418 419 420 421 422 423 424 425

    -  .. row 3

       -  ``V4L2_FBUF_FLAG_CHROMAKEY``

       -  0x0004

       -  Use chroma-keying. The chroma-key color is determined by the
426 427 428
	  ``chromakey`` field of struct :ref:`v4l2_window <v4l2-window>`
	  and negotiated with the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
	  ioctl, see :ref:`overlay` and :ref:`osd`.
429 430 431 432

    -  .. row 4

       -  :cspan:`2` There are no flags to enable clipping using a list of
433 434 435
	  clip rectangles or a bitmap. These methods are negotiated with the
	  :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, see :ref:`overlay`
	  and :ref:`osd`.
436 437 438 439 440 441 442 443

    -  .. row 5

       -  ``V4L2_FBUF_FLAG_LOCAL_ALPHA``

       -  0x0008

       -  Use the alpha channel of the framebuffer to clip or blend
444 445 446
	  framebuffer pixels with video images. The blend function is:
	  output = framebuffer pixel * alpha + video pixel * (1 - alpha).
	  The actual alpha depth depends on the framebuffer pixel format.
447 448 449 450 451 452 453 454

    -  .. row 6

       -  ``V4L2_FBUF_FLAG_GLOBAL_ALPHA``

       -  0x0010

       -  Use a global alpha value to blend the framebuffer with video
455 456 457 458 459 460
	  images. The blend function is: output = (framebuffer pixel * alpha
	  + video pixel * (255 - alpha)) / 255. The alpha value is
	  determined by the ``global_alpha`` field of struct
	  :ref:`v4l2_window <v4l2-window>` and negotiated with the
	  :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, see :ref:`overlay`
	  and :ref:`osd`.
461 462 463 464 465 466 467 468

    -  .. row 7

       -  ``V4L2_FBUF_FLAG_LOCAL_INV_ALPHA``

       -  0x0020

       -  Like ``V4L2_FBUF_FLAG_LOCAL_ALPHA``, use the alpha channel of the
469 470 471 472
	  framebuffer to clip or blend framebuffer pixels with video images,
	  but with an inverted alpha value. The blend function is: output =
	  framebuffer pixel * (1 - alpha) + video pixel * alpha. The actual
	  alpha depth depends on the framebuffer pixel format.
473 474 475 476 477 478 479 480

    -  .. row 8

       -  ``V4L2_FBUF_FLAG_SRC_CHROMAKEY``

       -  0x0040

       -  Use source chroma-keying. The source chroma-key color is
481 482 483 484 485 486
	  determined by the ``chromakey`` field of struct
	  :ref:`v4l2_window <v4l2-window>` and negotiated with the
	  :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl, see :ref:`overlay`
	  and :ref:`osd`. Both chroma-keying are mutual exclusive to each
	  other, so same ``chromakey`` field of struct
	  :ref:`v4l2_window <v4l2-window>` is being used.
487 488


489
Return Value
490 491 492 493 494 495 496
============

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.

EPERM
497
    :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>` can only be called by a privileged user to
498 499 500
    negotiate the parameters for a destructive overlay.

EINVAL
501
    The :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>` parameters are unsuitable.
502

503
.. [#f1]
504 505 506 507 508
   A physical base address may not suit all platforms. GK notes in
   theory we should pass something like PCI device + memory region +
   offset instead. If you encounter problems please discuss on the
   linux-media mailing list:
   `https://linuxtv.org/lists.php <https://linuxtv.org/lists.php>`__.