18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci.. _osd: 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci****************************** 68c2ecf20Sopenharmony_ciVideo Output Overlay Interface 78c2ecf20Sopenharmony_ci****************************** 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci**Also known as On-Screen Display (OSD)** 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ciSome video output devices can overlay a framebuffer image onto the 128c2ecf20Sopenharmony_cioutgoing video signal. Applications can set up such an overlay using 138c2ecf20Sopenharmony_cithis interface, which borrows structures and ioctls of the 148c2ecf20Sopenharmony_ci:ref:`Video Overlay <overlay>` interface. 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ciThe OSD function is accessible through the same character special file 178c2ecf20Sopenharmony_cias the :ref:`Video Output <capture>` function. 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci.. note:: 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci The default function of such a ``/dev/video`` device is video 228c2ecf20Sopenharmony_ci capturing or output. The OSD function is only available after calling 238c2ecf20Sopenharmony_ci the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciQuerying Capabilities 278c2ecf20Sopenharmony_ci===================== 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ciDevices supporting the *Video Output Overlay* interface set the 308c2ecf20Sopenharmony_ci``V4L2_CAP_VIDEO_OUTPUT_OVERLAY`` flag in the ``capabilities`` field of 318c2ecf20Sopenharmony_cistruct :c:type:`v4l2_capability` returned by the 328c2ecf20Sopenharmony_ci:ref:`VIDIOC_QUERYCAP` ioctl. 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ciFramebuffer 368c2ecf20Sopenharmony_ci=========== 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ciContrary to the *Video Overlay* interface the framebuffer is normally 398c2ecf20Sopenharmony_ciimplemented on the TV card and not the graphics card. On Linux it is 408c2ecf20Sopenharmony_ciaccessible as a framebuffer device (``/dev/fbN``). Given a V4L2 device, 418c2ecf20Sopenharmony_ciapplications can find the corresponding framebuffer device by calling 428c2ecf20Sopenharmony_cithe :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>` ioctl. It returns, amongst 438c2ecf20Sopenharmony_ciother information, the physical address of the framebuffer in the 448c2ecf20Sopenharmony_ci``base`` field of struct :c:type:`v4l2_framebuffer`. 458c2ecf20Sopenharmony_ciThe framebuffer device ioctl ``FBIOGET_FSCREENINFO`` returns the same 468c2ecf20Sopenharmony_ciaddress in the ``smem_start`` field of struct 478c2ecf20Sopenharmony_ci:c:type:`fb_fix_screeninfo`. The ``FBIOGET_FSCREENINFO`` 488c2ecf20Sopenharmony_ciioctl and struct :c:type:`fb_fix_screeninfo` are defined in 498c2ecf20Sopenharmony_cithe ``linux/fb.h`` header file. 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ciThe width and height of the framebuffer depends on the current video 528c2ecf20Sopenharmony_cistandard. A V4L2 driver may reject attempts to change the video standard 538c2ecf20Sopenharmony_ci(or any other ioctl which would imply a framebuffer size change) with an 548c2ecf20Sopenharmony_ci``EBUSY`` error code until all applications closed the framebuffer device. 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ciExample: Finding a framebuffer device for OSD 578c2ecf20Sopenharmony_ci--------------------------------------------- 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci.. code-block:: c 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci #include <linux/fb.h> 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci struct v4l2_framebuffer fbuf; 648c2ecf20Sopenharmony_ci unsigned int i; 658c2ecf20Sopenharmony_ci int fb_fd; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci if (-1 == ioctl(fd, VIDIOC_G_FBUF, &fbuf)) { 688c2ecf20Sopenharmony_ci perror("VIDIOC_G_FBUF"); 698c2ecf20Sopenharmony_ci exit(EXIT_FAILURE); 708c2ecf20Sopenharmony_ci } 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci for (i = 0; i < 30; i++) { 738c2ecf20Sopenharmony_ci char dev_name[16]; 748c2ecf20Sopenharmony_ci struct fb_fix_screeninfo si; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci snprintf(dev_name, sizeof(dev_name), "/dev/fb%u", i); 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci fb_fd = open(dev_name, O_RDWR); 798c2ecf20Sopenharmony_ci if (-1 == fb_fd) { 808c2ecf20Sopenharmony_ci switch (errno) { 818c2ecf20Sopenharmony_ci case ENOENT: /* no such file */ 828c2ecf20Sopenharmony_ci case ENXIO: /* no driver */ 838c2ecf20Sopenharmony_ci continue; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci default: 868c2ecf20Sopenharmony_ci perror("open"); 878c2ecf20Sopenharmony_ci exit(EXIT_FAILURE); 888c2ecf20Sopenharmony_ci } 898c2ecf20Sopenharmony_ci } 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci if (0 == ioctl(fb_fd, FBIOGET_FSCREENINFO, &si)) { 928c2ecf20Sopenharmony_ci if (si.smem_start == (unsigned long)fbuf.base) 938c2ecf20Sopenharmony_ci break; 948c2ecf20Sopenharmony_ci } else { 958c2ecf20Sopenharmony_ci /* Apparently not a framebuffer device. */ 968c2ecf20Sopenharmony_ci } 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci close(fb_fd); 998c2ecf20Sopenharmony_ci fb_fd = -1; 1008c2ecf20Sopenharmony_ci } 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci /* fb_fd is the file descriptor of the framebuffer device 1038c2ecf20Sopenharmony_ci for the video output overlay, or -1 if no device was found. */ 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ciOverlay Window and Scaling 1078c2ecf20Sopenharmony_ci========================== 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ciThe overlay is controlled by source and target rectangles. The source 1108c2ecf20Sopenharmony_cirectangle selects a subsection of the framebuffer image to be overlaid, 1118c2ecf20Sopenharmony_cithe target rectangle an area in the outgoing video signal where the 1128c2ecf20Sopenharmony_ciimage will appear. Drivers may or may not support scaling, and arbitrary 1138c2ecf20Sopenharmony_cisizes and positions of these rectangles. Further drivers may support any 1148c2ecf20Sopenharmony_ci(or none) of the clipping/blending methods defined for the 1158c2ecf20Sopenharmony_ci:ref:`Video Overlay <overlay>` interface. 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ciA struct :c:type:`v4l2_window` defines the size of the 1188c2ecf20Sopenharmony_cisource rectangle, its position in the framebuffer and the 1198c2ecf20Sopenharmony_ciclipping/blending method to be used for the overlay. To get the current 1208c2ecf20Sopenharmony_ciparameters applications set the ``type`` field of a struct 1218c2ecf20Sopenharmony_ci:c:type:`v4l2_format` to 1228c2ecf20Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY`` and call the 1238c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl. The driver fills the 1248c2ecf20Sopenharmony_cistruct :c:type:`v4l2_window` substructure named ``win``. It is not 1258c2ecf20Sopenharmony_cipossible to retrieve a previously programmed clipping list or bitmap. 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ciTo program the source rectangle applications set the ``type`` field of a 1288c2ecf20Sopenharmony_cistruct :c:type:`v4l2_format` to 1298c2ecf20Sopenharmony_ci``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY``, initialize the ``win`` 1308c2ecf20Sopenharmony_cisubstructure and call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. 1318c2ecf20Sopenharmony_ciThe driver adjusts the parameters against hardware limits and returns 1328c2ecf20Sopenharmony_cithe actual parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does. Like :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`, 1338c2ecf20Sopenharmony_cithe :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl can be used to learn 1348c2ecf20Sopenharmony_ciabout driver capabilities without actually changing driver state. Unlike 1358c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` this also works after the overlay has been enabled. 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ciA struct :c:type:`v4l2_crop` defines the size and position 1388c2ecf20Sopenharmony_ciof the target rectangle. The scaling factor of the overlay is implied by 1398c2ecf20Sopenharmony_cithe width and height given in struct :c:type:`v4l2_window` 1408c2ecf20Sopenharmony_ciand struct :c:type:`v4l2_crop`. The cropping API applies to 1418c2ecf20Sopenharmony_ci*Video Output* and *Video Output Overlay* devices in the same way as to 1428c2ecf20Sopenharmony_ci*Video Capture* and *Video Overlay* devices, merely reversing the 1438c2ecf20Sopenharmony_cidirection of the data flow. For more information see :ref:`crop`. 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ciEnabling Overlay 1478c2ecf20Sopenharmony_ci================ 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ciThere is no V4L2 ioctl to enable or disable the overlay, however the 1508c2ecf20Sopenharmony_ciframebuffer interface of the driver may support the ``FBIOBLANK`` ioctl. 151