1*059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 254f38fcaSMauro Carvalho Chehab 354f38fcaSMauro Carvalho Chehab.. _osd: 454f38fcaSMauro Carvalho Chehab 554f38fcaSMauro Carvalho Chehab****************************** 654f38fcaSMauro Carvalho ChehabVideo Output Overlay Interface 754f38fcaSMauro Carvalho Chehab****************************** 854f38fcaSMauro Carvalho Chehab 954f38fcaSMauro Carvalho Chehab**Also known as On-Screen Display (OSD)** 1054f38fcaSMauro Carvalho Chehab 1154f38fcaSMauro Carvalho ChehabSome video output devices can overlay a framebuffer image onto the 1254f38fcaSMauro Carvalho Chehaboutgoing video signal. Applications can set up such an overlay using 1354f38fcaSMauro Carvalho Chehabthis interface, which borrows structures and ioctls of the 1454f38fcaSMauro Carvalho Chehab:ref:`Video Overlay <overlay>` interface. 1554f38fcaSMauro Carvalho Chehab 1654f38fcaSMauro Carvalho ChehabThe OSD function is accessible through the same character special file 1754f38fcaSMauro Carvalho Chehabas the :ref:`Video Output <capture>` function. 1854f38fcaSMauro Carvalho Chehab 1954f38fcaSMauro Carvalho Chehab.. note:: 2054f38fcaSMauro Carvalho Chehab 2154f38fcaSMauro Carvalho Chehab The default function of such a ``/dev/video`` device is video 2254f38fcaSMauro Carvalho Chehab capturing or output. The OSD function is only available after calling 2354f38fcaSMauro Carvalho Chehab the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. 2454f38fcaSMauro Carvalho Chehab 2554f38fcaSMauro Carvalho Chehab 2654f38fcaSMauro Carvalho ChehabQuerying Capabilities 2754f38fcaSMauro Carvalho Chehab===================== 2854f38fcaSMauro Carvalho Chehab 2954f38fcaSMauro Carvalho ChehabDevices supporting the *Video Output Overlay* interface set the 3054f38fcaSMauro Carvalho Chehab``V4L2_CAP_VIDEO_OUTPUT_OVERLAY`` flag in the ``capabilities`` field of 3154f38fcaSMauro Carvalho Chehabstruct :c:type:`v4l2_capability` returned by the 3254f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_QUERYCAP` ioctl. 3354f38fcaSMauro Carvalho Chehab 3454f38fcaSMauro Carvalho Chehab 3554f38fcaSMauro Carvalho ChehabFramebuffer 3654f38fcaSMauro Carvalho Chehab=========== 3754f38fcaSMauro Carvalho Chehab 3854f38fcaSMauro Carvalho ChehabContrary to the *Video Overlay* interface the framebuffer is normally 3954f38fcaSMauro Carvalho Chehabimplemented on the TV card and not the graphics card. On Linux it is 4054f38fcaSMauro Carvalho Chehabaccessible as a framebuffer device (``/dev/fbN``). Given a V4L2 device, 4154f38fcaSMauro Carvalho Chehabapplications can find the corresponding framebuffer device by calling 4254f38fcaSMauro Carvalho Chehabthe :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>` ioctl. It returns, amongst 4354f38fcaSMauro Carvalho Chehabother information, the physical address of the framebuffer in the 4454f38fcaSMauro Carvalho Chehab``base`` field of struct :c:type:`v4l2_framebuffer`. 4554f38fcaSMauro Carvalho ChehabThe framebuffer device ioctl ``FBIOGET_FSCREENINFO`` returns the same 4654f38fcaSMauro Carvalho Chehabaddress in the ``smem_start`` field of struct 47b4cc96f9SRandy Dunlap:c:type:`fb_fix_screeninfo`. The ``FBIOGET_FSCREENINFO`` 4854f38fcaSMauro Carvalho Chehabioctl and struct :c:type:`fb_fix_screeninfo` are defined in 4954f38fcaSMauro Carvalho Chehabthe ``linux/fb.h`` header file. 5054f38fcaSMauro Carvalho Chehab 5154f38fcaSMauro Carvalho ChehabThe width and height of the framebuffer depends on the current video 5254f38fcaSMauro Carvalho Chehabstandard. A V4L2 driver may reject attempts to change the video standard 5354f38fcaSMauro Carvalho Chehab(or any other ioctl which would imply a framebuffer size change) with an 5454f38fcaSMauro Carvalho Chehab``EBUSY`` error code until all applications closed the framebuffer device. 5554f38fcaSMauro Carvalho Chehab 5654f38fcaSMauro Carvalho ChehabExample: Finding a framebuffer device for OSD 5754f38fcaSMauro Carvalho Chehab--------------------------------------------- 5854f38fcaSMauro Carvalho Chehab 5954f38fcaSMauro Carvalho Chehab.. code-block:: c 6054f38fcaSMauro Carvalho Chehab 6154f38fcaSMauro Carvalho Chehab #include <linux/fb.h> 6254f38fcaSMauro Carvalho Chehab 6354f38fcaSMauro Carvalho Chehab struct v4l2_framebuffer fbuf; 6454f38fcaSMauro Carvalho Chehab unsigned int i; 6554f38fcaSMauro Carvalho Chehab int fb_fd; 6654f38fcaSMauro Carvalho Chehab 6754f38fcaSMauro Carvalho Chehab if (-1 == ioctl(fd, VIDIOC_G_FBUF, &fbuf)) { 6854f38fcaSMauro Carvalho Chehab perror("VIDIOC_G_FBUF"); 6954f38fcaSMauro Carvalho Chehab exit(EXIT_FAILURE); 7054f38fcaSMauro Carvalho Chehab } 7154f38fcaSMauro Carvalho Chehab 7254f38fcaSMauro Carvalho Chehab for (i = 0; i < 30; i++) { 7354f38fcaSMauro Carvalho Chehab char dev_name[16]; 7454f38fcaSMauro Carvalho Chehab struct fb_fix_screeninfo si; 7554f38fcaSMauro Carvalho Chehab 7654f38fcaSMauro Carvalho Chehab snprintf(dev_name, sizeof(dev_name), "/dev/fb%u", i); 7754f38fcaSMauro Carvalho Chehab 7854f38fcaSMauro Carvalho Chehab fb_fd = open(dev_name, O_RDWR); 7954f38fcaSMauro Carvalho Chehab if (-1 == fb_fd) { 8054f38fcaSMauro Carvalho Chehab switch (errno) { 8154f38fcaSMauro Carvalho Chehab case ENOENT: /* no such file */ 8254f38fcaSMauro Carvalho Chehab case ENXIO: /* no driver */ 8354f38fcaSMauro Carvalho Chehab continue; 8454f38fcaSMauro Carvalho Chehab 8554f38fcaSMauro Carvalho Chehab default: 8654f38fcaSMauro Carvalho Chehab perror("open"); 8754f38fcaSMauro Carvalho Chehab exit(EXIT_FAILURE); 8854f38fcaSMauro Carvalho Chehab } 8954f38fcaSMauro Carvalho Chehab } 9054f38fcaSMauro Carvalho Chehab 9154f38fcaSMauro Carvalho Chehab if (0 == ioctl(fb_fd, FBIOGET_FSCREENINFO, &si)) { 9254f38fcaSMauro Carvalho Chehab if (si.smem_start == (unsigned long)fbuf.base) 9354f38fcaSMauro Carvalho Chehab break; 9454f38fcaSMauro Carvalho Chehab } else { 9554f38fcaSMauro Carvalho Chehab /* Apparently not a framebuffer device. */ 9654f38fcaSMauro Carvalho Chehab } 9754f38fcaSMauro Carvalho Chehab 9854f38fcaSMauro Carvalho Chehab close(fb_fd); 9954f38fcaSMauro Carvalho Chehab fb_fd = -1; 10054f38fcaSMauro Carvalho Chehab } 10154f38fcaSMauro Carvalho Chehab 10254f38fcaSMauro Carvalho Chehab /* fb_fd is the file descriptor of the framebuffer device 10354f38fcaSMauro Carvalho Chehab for the video output overlay, or -1 if no device was found. */ 10454f38fcaSMauro Carvalho Chehab 10554f38fcaSMauro Carvalho Chehab 10654f38fcaSMauro Carvalho ChehabOverlay Window and Scaling 10754f38fcaSMauro Carvalho Chehab========================== 10854f38fcaSMauro Carvalho Chehab 10954f38fcaSMauro Carvalho ChehabThe overlay is controlled by source and target rectangles. The source 11054f38fcaSMauro Carvalho Chehabrectangle selects a subsection of the framebuffer image to be overlaid, 11154f38fcaSMauro Carvalho Chehabthe target rectangle an area in the outgoing video signal where the 11254f38fcaSMauro Carvalho Chehabimage will appear. Drivers may or may not support scaling, and arbitrary 11354f38fcaSMauro Carvalho Chehabsizes and positions of these rectangles. Further drivers may support any 11454f38fcaSMauro Carvalho Chehab(or none) of the clipping/blending methods defined for the 11554f38fcaSMauro Carvalho Chehab:ref:`Video Overlay <overlay>` interface. 11654f38fcaSMauro Carvalho Chehab 11754f38fcaSMauro Carvalho ChehabA struct :c:type:`v4l2_window` defines the size of the 11854f38fcaSMauro Carvalho Chehabsource rectangle, its position in the framebuffer and the 11954f38fcaSMauro Carvalho Chehabclipping/blending method to be used for the overlay. To get the current 12054f38fcaSMauro Carvalho Chehabparameters applications set the ``type`` field of a struct 12154f38fcaSMauro Carvalho Chehab:c:type:`v4l2_format` to 12254f38fcaSMauro Carvalho Chehab``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY`` and call the 12354f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl. The driver fills the 12454f38fcaSMauro Carvalho Chehabstruct :c:type:`v4l2_window` substructure named ``win``. It is not 12554f38fcaSMauro Carvalho Chehabpossible to retrieve a previously programmed clipping list or bitmap. 12654f38fcaSMauro Carvalho Chehab 12754f38fcaSMauro Carvalho ChehabTo program the source rectangle applications set the ``type`` field of a 12854f38fcaSMauro Carvalho Chehabstruct :c:type:`v4l2_format` to 12954f38fcaSMauro Carvalho Chehab``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY``, initialize the ``win`` 13054f38fcaSMauro Carvalho Chehabsubstructure and call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. 13154f38fcaSMauro Carvalho ChehabThe driver adjusts the parameters against hardware limits and returns 13254f38fcaSMauro Carvalho Chehabthe actual parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does. Like :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`, 13354f38fcaSMauro Carvalho Chehabthe :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl can be used to learn 13454f38fcaSMauro Carvalho Chehababout driver capabilities without actually changing driver state. Unlike 13554f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` this also works after the overlay has been enabled. 13654f38fcaSMauro Carvalho Chehab 13754f38fcaSMauro Carvalho ChehabA struct :c:type:`v4l2_crop` defines the size and position 13854f38fcaSMauro Carvalho Chehabof the target rectangle. The scaling factor of the overlay is implied by 13954f38fcaSMauro Carvalho Chehabthe width and height given in struct :c:type:`v4l2_window` 14054f38fcaSMauro Carvalho Chehaband struct :c:type:`v4l2_crop`. The cropping API applies to 14154f38fcaSMauro Carvalho Chehab*Video Output* and *Video Output Overlay* devices in the same way as to 14254f38fcaSMauro Carvalho Chehab*Video Capture* and *Video Overlay* devices, merely reversing the 14354f38fcaSMauro Carvalho Chehabdirection of the data flow. For more information see :ref:`crop`. 14454f38fcaSMauro Carvalho Chehab 14554f38fcaSMauro Carvalho Chehab 14654f38fcaSMauro Carvalho ChehabEnabling Overlay 14754f38fcaSMauro Carvalho Chehab================ 14854f38fcaSMauro Carvalho Chehab 14954f38fcaSMauro Carvalho ChehabThere is no V4L2 ioctl to enable or disable the overlay, however the 15054f38fcaSMauro Carvalho Chehabframebuffer interface of the driver may support the ``FBIOBLANK`` ioctl. 151