Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
0002 
0003 .. _overlay:
0004 
0005 ***********************
0006 Video Overlay Interface
0007 ***********************
0008 
0009 **Also known as Framebuffer Overlay or Previewing.**
0010 
0011 Video overlay devices have the ability to genlock (TV-)video into the
0012 (VGA-)video signal of a graphics card, or to store captured images
0013 directly in video memory of a graphics card, typically with clipping.
0014 This can be considerable more efficient than capturing images and
0015 displaying them by other means. In the old days when only nuclear power
0016 plants needed cooling towers this used to be the only way to put live
0017 video into a window.
0018 
0019 Video overlay devices are accessed through the same character special
0020 files as :ref:`video capture <capture>` devices.
0021 
0022 .. note::
0023 
0024    The default function of a ``/dev/video`` device is video
0025    capturing. The overlay function is only available after calling
0026    the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl.
0027 
0028 The driver may support simultaneous overlay and capturing using the
0029 read/write and streaming I/O methods. If so, operation at the nominal
0030 frame rate of the video standard is not guaranteed. Frames may be
0031 directed away from overlay to capture, or one field may be used for
0032 overlay and the other for capture if the capture parameters permit this.
0033 
0034 Applications should use different file descriptors for capturing and
0035 overlay. This must be supported by all drivers capable of simultaneous
0036 capturing and overlay. Optionally these drivers may also permit
0037 capturing and overlay with a single file descriptor for compatibility
0038 with V4L and earlier versions of V4L2. [#f1]_
0039 
0040 A common application of two file descriptors is the X11
0041 :ref:`Xv/V4L <xvideo>` interface driver and a V4L2 application.
0042 While the X server controls video overlay, the application can take
0043 advantage of memory mapping and DMA.
0044 
0045 Querying Capabilities
0046 =====================
0047 
0048 Devices supporting the video overlay interface set the
0049 ``V4L2_CAP_VIDEO_OVERLAY`` flag in the ``capabilities`` field of struct
0050 :c:type:`v4l2_capability` returned by the
0051 :ref:`VIDIOC_QUERYCAP` ioctl. The overlay I/O
0052 method specified below must be supported. Tuners and audio inputs are
0053 optional.
0054 
0055 
0056 Supplemental Functions
0057 ======================
0058 
0059 Video overlay devices shall support :ref:`audio input <audio>`,
0060 :ref:`tuner`, :ref:`controls <control>`,
0061 :ref:`cropping and scaling <crop>` and
0062 :ref:`streaming parameter <streaming-par>` ioctls as needed. The
0063 :ref:`video input <video>` and :ref:`video standard <standard>`
0064 ioctls must be supported by all video overlay devices.
0065 
0066 
0067 Setup
0068 =====
0069 
0070 Before overlay can commence applications must program the driver with
0071 frame buffer parameters, namely the address and size of the frame buffer
0072 and the image format, for example RGB 5:6:5. The
0073 :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>` and
0074 :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>` ioctls are available to get and
0075 set these parameters, respectively. The :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>` ioctl is
0076 privileged because it allows to set up DMA into physical memory,
0077 bypassing the memory protection mechanisms of the kernel. Only the
0078 superuser can change the frame buffer address and size. Users are not
0079 supposed to run TV applications as root or with SUID bit set. A small
0080 helper application with suitable privileges should query the graphics
0081 system and program the V4L2 driver at the appropriate time.
0082 
0083 Some devices add the video overlay to the output signal of the graphics
0084 card. In this case the frame buffer is not modified by the video device,
0085 and the frame buffer address and pixel format are not needed by the
0086 driver. The :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>` ioctl is not privileged. An application
0087 can check for this type of device by calling the :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>`
0088 ioctl.
0089 
0090 A driver may support any (or none) of five clipping/blending methods:
0091 
0092 1. Chroma-keying displays the overlaid image only where pixels in the
0093    primary graphics surface assume a certain color.
0094 
0095 2. A bitmap can be specified where each bit corresponds to a pixel in
0096    the overlaid image. When the bit is set, the corresponding video
0097    pixel is displayed, otherwise a pixel of the graphics surface.
0098 
0099 3. A list of clipping rectangles can be specified. In these regions *no*
0100    video is displayed, so the graphics surface can be seen here.
0101 
0102 4. The framebuffer has an alpha channel that can be used to clip or
0103    blend the framebuffer with the video.
0104 
0105 5. A global alpha value can be specified to blend the framebuffer
0106    contents with video images.
0107 
0108 When simultaneous capturing and overlay is supported and the hardware
0109 prohibits different image and frame buffer formats, the format requested
0110 first takes precedence. The attempt to capture
0111 (:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`) or overlay
0112 (:ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>`) may fail with an ``EBUSY`` error
0113 code or return accordingly modified parameters..
0114 
0115 
0116 Overlay Window
0117 ==============
0118 
0119 The overlaid image is determined by cropping and overlay window
0120 parameters. The former select an area of the video picture to capture,
0121 the latter how images are overlaid and clipped. Cropping initialization
0122 at minimum requires to reset the parameters to defaults. An example is
0123 given in :ref:`crop`.
0124 
0125 The overlay window is described by a struct
0126 :c:type:`v4l2_window`. It defines the size of the image,
0127 its position over the graphics surface and the clipping to be applied.
0128 To get the current parameters applications set the ``type`` field of a
0129 struct :c:type:`v4l2_format` to
0130 ``V4L2_BUF_TYPE_VIDEO_OVERLAY`` and call the
0131 :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl. The driver fills the
0132 struct :c:type:`v4l2_window` substructure named ``win``. It is not
0133 possible to retrieve a previously programmed clipping list or bitmap.
0134 
0135 To program the overlay window applications set the ``type`` field of a
0136 struct :c:type:`v4l2_format` to
0137 ``V4L2_BUF_TYPE_VIDEO_OVERLAY``, initialize the ``win`` substructure and
0138 call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. The driver
0139 adjusts the parameters against hardware limits and returns the actual
0140 parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does. Like :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`, the
0141 :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl can be used to learn
0142 about driver capabilities without actually changing driver state. Unlike
0143 :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` this also works after the overlay has been enabled.
0144 
0145 The scaling factor of the overlaid image is implied by the width and
0146 height given in struct :c:type:`v4l2_window` and the size
0147 of the cropping rectangle. For more information see :ref:`crop`.
0148 
0149 When simultaneous capturing and overlay is supported and the hardware
0150 prohibits different image and window sizes, the size requested first
0151 takes precedence. The attempt to capture or overlay as well
0152 (:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`) may fail with an ``EBUSY`` error
0153 code or return accordingly modified parameters.
0154 
0155 
0156 .. c:type:: v4l2_window
0157 
0158 struct v4l2_window
0159 ------------------
0160 
0161 ``struct v4l2_rect w``
0162     Size and position of the window relative to the top, left corner of
0163     the frame buffer defined with
0164     :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>`. The window can extend the
0165     frame buffer width and height, the ``x`` and ``y`` coordinates can
0166     be negative, and it can lie completely outside the frame buffer. The
0167     driver clips the window accordingly, or if that is not possible,
0168     modifies its size and/or position.
0169 
0170 ``enum v4l2_field field``
0171     Applications set this field to determine which video field shall be
0172     overlaid, typically one of ``V4L2_FIELD_ANY`` (0),
0173     ``V4L2_FIELD_TOP``, ``V4L2_FIELD_BOTTOM`` or
0174     ``V4L2_FIELD_INTERLACED``. Drivers may have to choose a different
0175     field order and return the actual setting here.
0176 
0177 ``__u32 chromakey``
0178     When chroma-keying has been negotiated with
0179     :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>` applications set this field
0180     to the desired pixel value for the chroma key. The format is the
0181     same as the pixel format of the framebuffer (struct
0182     :c:type:`v4l2_framebuffer` ``fmt.pixelformat``
0183     field), with bytes in host order. E. g. for
0184     :ref:`V4L2_PIX_FMT_BGR24 <V4L2-PIX-FMT-BGR32>` the value should
0185     be 0xRRGGBB on a little endian, 0xBBGGRR on a big endian host.
0186 
0187 ``struct v4l2_clip * clips``
0188     When chroma-keying has *not* been negotiated and
0189     :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>` indicated this capability,
0190     applications can set this field to point to an array of clipping
0191     rectangles.
0192 
0193     Like the window coordinates w, clipping rectangles are defined
0194     relative to the top, left corner of the frame buffer. However
0195     clipping rectangles must not extend the frame buffer width and
0196     height, and they must not overlap. If possible applications
0197     should merge adjacent rectangles. Whether this must create
0198     x-y or y-x bands, or the order of rectangles, is not defined. When
0199     clip lists are not supported the driver ignores this field. Its
0200     contents after calling :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`
0201     are undefined.
0202 
0203 ``__u32 clipcount``
0204     When the application set the ``clips`` field, this field must
0205     contain the number of clipping rectangles in the list. When clip
0206     lists are not supported the driver ignores this field, its contents
0207     after calling :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` are undefined. When clip lists are
0208     supported but no clipping is desired this field must be set to zero.
0209 
0210 ``void * bitmap``
0211     When chroma-keying has *not* been negotiated and
0212     :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>` indicated this capability,
0213     applications can set this field to point to a clipping bit mask.
0214 
0215 It must be of the same size as the window, ``w.width`` and ``w.height``.
0216 Each bit corresponds to a pixel in the overlaid image, which is
0217 displayed only when the bit is *set*. Pixel coordinates translate to
0218 bits like:
0219 
0220 
0221 .. code-block:: c
0222 
0223     ((__u8 *) bitmap)[w.width * y + x / 8] & (1 << (x & 7))
0224 
0225 where ``0`` ≤ x < ``w.width`` and ``0`` ≤ y <``w.height``. [#f2]_
0226 
0227 When a clipping bit mask is not supported the driver ignores this field,
0228 its contents after calling :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` are
0229 undefined. When a bit mask is supported but no clipping is desired this
0230 field must be set to ``NULL``.
0231 
0232 Applications need not create a clip list or bit mask. When they pass
0233 both, or despite negotiating chroma-keying, the results are undefined.
0234 Regardless of the chosen method, the clipping abilities of the hardware
0235 may be limited in quantity or quality. The results when these limits are
0236 exceeded are undefined. [#f3]_
0237 
0238 ``__u8 global_alpha``
0239     The global alpha value used to blend the framebuffer with video
0240     images, if global alpha blending has been negotiated
0241     (``V4L2_FBUF_FLAG_GLOBAL_ALPHA``, see
0242     :ref:`VIDIOC_S_FBUF <VIDIOC_G_FBUF>`,
0243     :ref:`framebuffer-flags`).
0244 
0245 .. note::
0246 
0247    This field was added in Linux 2.6.23, extending the
0248    structure. However the :ref:`VIDIOC_[G|S|TRY]_FMT <VIDIOC_G_FMT>`
0249    ioctls, which take a pointer to a :c:type:`v4l2_format`
0250    parent structure with padding bytes at the end, are not affected.
0251 
0252 
0253 .. c:type:: v4l2_clip
0254 
0255 struct v4l2_clip [#f4]_
0256 -----------------------
0257 
0258 ``struct v4l2_rect c``
0259     Coordinates of the clipping rectangle, relative to the top, left
0260     corner of the frame buffer. Only window pixels *outside* all
0261     clipping rectangles are displayed.
0262 
0263 ``struct v4l2_clip * next``
0264     Pointer to the next clipping rectangle, ``NULL`` when this is the last
0265     rectangle. Drivers ignore this field, it cannot be used to pass a
0266     linked list of clipping rectangles.
0267 
0268 
0269 .. c:type:: v4l2_rect
0270 
0271 struct v4l2_rect
0272 ----------------
0273 
0274 ``__s32 left``
0275     Horizontal offset of the top, left corner of the rectangle, in
0276     pixels.
0277 
0278 ``__s32 top``
0279     Vertical offset of the top, left corner of the rectangle, in pixels.
0280     Offsets increase to the right and down.
0281 
0282 ``__u32 width``
0283     Width of the rectangle, in pixels.
0284 
0285 ``__u32 height``
0286     Height of the rectangle, in pixels.
0287 
0288 
0289 Enabling Overlay
0290 ================
0291 
0292 To start or stop the frame buffer overlay applications call the
0293 :ref:`VIDIOC_OVERLAY` ioctl.
0294 
0295 .. [#f1]
0296    In the opinion of the designers of this API, no driver writer taking
0297    the efforts to support simultaneous capturing and overlay will
0298    restrict this ability by requiring a single file descriptor, as in
0299    V4L and earlier versions of V4L2. Making this optional means
0300    applications depending on two file descriptors need backup routines
0301    to be compatible with all drivers, which is considerable more work
0302    than using two fds in applications which do not. Also two fd's fit
0303    the general concept of one file descriptor for each logical stream.
0304    Hence as a complexity trade-off drivers *must* support two file
0305    descriptors and *may* support single fd operation.
0306 
0307 .. [#f2]
0308    Should we require ``w.width`` to be a multiple of eight?
0309 
0310 .. [#f3]
0311    When the image is written into frame buffer memory it will be
0312    undesirable if the driver clips out less pixels than expected,
0313    because the application and graphics system are not aware these
0314    regions need to be refreshed. The driver should clip out more pixels
0315    or not write the image at all.
0316 
0317 .. [#f4]
0318    The X Window system defines "regions" which are vectors of ``struct
0319    BoxRec { short x1, y1, x2, y2; }`` with ``width = x2 - x1`` and
0320    ``height = y2 - y1``, so one cannot pass X11 clip lists directly.