162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci.. _osd: 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci****************************** 662306a36Sopenharmony_ciVideo Output Overlay Interface 762306a36Sopenharmony_ci****************************** 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci**Also known as On-Screen Display (OSD)** 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciSome video output devices can overlay a framebuffer image onto the 1262306a36Sopenharmony_cioutgoing video signal. Applications can set up such an overlay using 1362306a36Sopenharmony_cithis interface, which borrows structures and ioctls of the 1462306a36Sopenharmony_ci:ref:`Video Overlay <overlay>` interface. 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ciThe OSD function is accessible through the same character special file 1762306a36Sopenharmony_cias the :ref:`Video Output <capture>` function. 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci.. note:: 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci The default function of such a ``/dev/video`` device is video 2262306a36Sopenharmony_ci capturing or output. The OSD function is only available after calling 2362306a36Sopenharmony_ci the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciQuerying Capabilities 2762306a36Sopenharmony_ci===================== 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ciDevices supporting the *Video Output Overlay* interface set the 3062306a36Sopenharmony_ci``V4L2_CAP_VIDEO_OUTPUT_OVERLAY`` flag in the ``capabilities`` field of 3162306a36Sopenharmony_cistruct :c:type:`v4l2_capability` returned by the 3262306a36Sopenharmony_ci:ref:`VIDIOC_QUERYCAP` ioctl. 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ciFramebuffer 3662306a36Sopenharmony_ci=========== 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciContrary to the *Video Overlay* interface the framebuffer is normally 3962306a36Sopenharmony_ciimplemented on the TV card and not the graphics card. On Linux it is 4062306a36Sopenharmony_ciaccessible as a framebuffer device (``/dev/fbN``). Given a V4L2 device, 4162306a36Sopenharmony_ciapplications can find the corresponding framebuffer device by calling 4262306a36Sopenharmony_cithe :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>` ioctl. It returns, amongst 4362306a36Sopenharmony_ciother information, the physical address of the framebuffer in the 4462306a36Sopenharmony_ci``base`` field of struct :c:type:`v4l2_framebuffer`. 4562306a36Sopenharmony_ciThe framebuffer device ioctl ``FBIOGET_FSCREENINFO`` returns the same 4662306a36Sopenharmony_ciaddress in the ``smem_start`` field of struct 4762306a36Sopenharmony_ci:c:type:`fb_fix_screeninfo`. The ``FBIOGET_FSCREENINFO`` 4862306a36Sopenharmony_ciioctl and struct :c:type:`fb_fix_screeninfo` are defined in 4962306a36Sopenharmony_cithe ``linux/fb.h`` header file. 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ciThe width and height of the framebuffer depends on the current video 5262306a36Sopenharmony_cistandard. A V4L2 driver may reject attempts to change the video standard 5362306a36Sopenharmony_ci(or any other ioctl which would imply a framebuffer size change) with an 5462306a36Sopenharmony_ci``EBUSY`` error code until all applications closed the framebuffer device. 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ciExample: Finding a framebuffer device for OSD 5762306a36Sopenharmony_ci--------------------------------------------- 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci.. code-block:: c 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci #include <linux/fb.h> 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci struct v4l2_framebuffer fbuf; 6462306a36Sopenharmony_ci unsigned int i; 6562306a36Sopenharmony_ci int fb_fd; 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci if (-1 == ioctl(fd, VIDIOC_G_FBUF, &fbuf)) { 6862306a36Sopenharmony_ci perror("VIDIOC_G_FBUF"); 6962306a36Sopenharmony_ci exit(EXIT_FAILURE); 7062306a36Sopenharmony_ci } 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci for (i = 0; i < 30; i++) { 7362306a36Sopenharmony_ci char dev_name[16]; 7462306a36Sopenharmony_ci struct fb_fix_screeninfo si; 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci snprintf(dev_name, sizeof(dev_name), "/dev/fb%u", i); 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci fb_fd = open(dev_name, O_RDWR); 7962306a36Sopenharmony_ci if (-1 == fb_fd) { 8062306a36Sopenharmony_ci switch (errno) { 8162306a36Sopenharmony_ci case ENOENT: /* no such file */ 8262306a36Sopenharmony_ci case ENXIO: /* no driver */ 8362306a36Sopenharmony_ci continue; 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci default: 8662306a36Sopenharmony_ci perror("open"); 8762306a36Sopenharmony_ci exit(EXIT_FAILURE); 8862306a36Sopenharmony_ci } 8962306a36Sopenharmony_ci } 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci if (0 == ioctl(fb_fd, FBIOGET_FSCREENINFO, &si)) { 9262306a36Sopenharmony_ci if (si.smem_start == (unsigned long)fbuf.base) 9362306a36Sopenharmony_ci break; 9462306a36Sopenharmony_ci } else { 9562306a36Sopenharmony_ci /* Apparently not a framebuffer device. */ 9662306a36Sopenharmony_ci } 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci close(fb_fd); 9962306a36Sopenharmony_ci fb_fd = -1; 10062306a36Sopenharmony_ci } 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci /* fb_fd is the file descriptor of the framebuffer device 10362306a36Sopenharmony_ci for the video output overlay, or -1 if no device was found. */ 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ciOverlay Window and Scaling 10762306a36Sopenharmony_ci========================== 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ciThe overlay is controlled by source and target rectangles. The source 11062306a36Sopenharmony_cirectangle selects a subsection of the framebuffer image to be overlaid, 11162306a36Sopenharmony_cithe target rectangle an area in the outgoing video signal where the 11262306a36Sopenharmony_ciimage will appear. Drivers may or may not support scaling, and arbitrary 11362306a36Sopenharmony_cisizes and positions of these rectangles. Further drivers may support any 11462306a36Sopenharmony_ci(or none) of the clipping/blending methods defined for the 11562306a36Sopenharmony_ci:ref:`Video Overlay <overlay>` interface. 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ciA struct :c:type:`v4l2_window` defines the size of the 11862306a36Sopenharmony_cisource rectangle, its position in the framebuffer and the 11962306a36Sopenharmony_ciclipping/blending method to be used for the overlay. To get the current 12062306a36Sopenharmony_ciparameters applications set the ``type`` field of a struct 12162306a36Sopenharmony_ci:c:type:`v4l2_format` to 12262306a36Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY`` and call the 12362306a36Sopenharmony_ci:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl. The driver fills the 12462306a36Sopenharmony_cistruct :c:type:`v4l2_window` substructure named ``win``. It is not 12562306a36Sopenharmony_cipossible to retrieve a previously programmed clipping list or bitmap. 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ciTo program the source rectangle applications set the ``type`` field of a 12862306a36Sopenharmony_cistruct :c:type:`v4l2_format` to 12962306a36Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY``, initialize the ``win`` 13062306a36Sopenharmony_cisubstructure and call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. 13162306a36Sopenharmony_ciThe driver adjusts the parameters against hardware limits and returns 13262306a36Sopenharmony_cithe actual parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does. Like :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`, 13362306a36Sopenharmony_cithe :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl can be used to learn 13462306a36Sopenharmony_ciabout driver capabilities without actually changing driver state. Unlike 13562306a36Sopenharmony_ci:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` this also works after the overlay has been enabled. 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ciA struct :c:type:`v4l2_crop` defines the size and position 13862306a36Sopenharmony_ciof the target rectangle. The scaling factor of the overlay is implied by 13962306a36Sopenharmony_cithe width and height given in struct :c:type:`v4l2_window` 14062306a36Sopenharmony_ciand struct :c:type:`v4l2_crop`. The cropping API applies to 14162306a36Sopenharmony_ci*Video Output* and *Video Output Overlay* devices in the same way as to 14262306a36Sopenharmony_ci*Video Capture* and *Video Overlay* devices, merely reversing the 14362306a36Sopenharmony_cidirection of the data flow. For more information see :ref:`crop`. 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ciEnabling Overlay 14762306a36Sopenharmony_ci================ 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ciThere is no V4L2 ioctl to enable or disable the overlay, however the 15062306a36Sopenharmony_ciframebuffer interface of the driver may support the ``FBIOBLANK`` ioctl. 151