dev-osd.rst 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
  2. .. c:namespace:: V4L
  3. .. _osd:
  4. ******************************
  5. Video Output Overlay Interface
  6. ******************************
  7. **Also known as On-Screen Display (OSD)**
  8. Some video output devices can overlay a framebuffer image onto the
  9. outgoing video signal. Applications can set up such an overlay using
  10. this interface, which borrows structures and ioctls of the
  11. :ref:`Video Overlay <overlay>` interface.
  12. The OSD function is accessible through the same character special file
  13. as the :ref:`Video Output <capture>` function.
  14. .. note::
  15. The default function of such a ``/dev/video`` device is video
  16. capturing or output. The OSD function is only available after calling
  17. the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl.
  18. Querying Capabilities
  19. =====================
  20. Devices supporting the *Video Output Overlay* interface set the
  21. ``V4L2_CAP_VIDEO_OUTPUT_OVERLAY`` flag in the ``capabilities`` field of
  22. struct :c:type:`v4l2_capability` returned by the
  23. :ref:`VIDIOC_QUERYCAP` ioctl.
  24. Framebuffer
  25. ===========
  26. Contrary to the *Video Overlay* interface the framebuffer is normally
  27. implemented on the TV card and not the graphics card. On Linux it is
  28. accessible as a framebuffer device (``/dev/fbN``). Given a V4L2 device,
  29. applications can find the corresponding framebuffer device by calling
  30. the :ref:`VIDIOC_G_FBUF <VIDIOC_G_FBUF>` ioctl. It returns, amongst
  31. other information, the physical address of the framebuffer in the
  32. ``base`` field of struct :c:type:`v4l2_framebuffer`.
  33. The framebuffer device ioctl ``FBIOGET_FSCREENINFO`` returns the same
  34. address in the ``smem_start`` field of struct
  35. :c:type:`fb_fix_screeninfo`. The ``FBIOGET_FSCREENINFO``
  36. ioctl and struct :c:type:`fb_fix_screeninfo` are defined in
  37. the ``linux/fb.h`` header file.
  38. The width and height of the framebuffer depends on the current video
  39. standard. A V4L2 driver may reject attempts to change the video standard
  40. (or any other ioctl which would imply a framebuffer size change) with an
  41. ``EBUSY`` error code until all applications closed the framebuffer device.
  42. Example: Finding a framebuffer device for OSD
  43. ---------------------------------------------
  44. .. code-block:: c
  45. #include <linux/fb.h>
  46. struct v4l2_framebuffer fbuf;
  47. unsigned int i;
  48. int fb_fd;
  49. if (-1 == ioctl(fd, VIDIOC_G_FBUF, &fbuf)) {
  50. perror("VIDIOC_G_FBUF");
  51. exit(EXIT_FAILURE);
  52. }
  53. for (i = 0; i < 30; i++) {
  54. char dev_name[16];
  55. struct fb_fix_screeninfo si;
  56. snprintf(dev_name, sizeof(dev_name), "/dev/fb%u", i);
  57. fb_fd = open(dev_name, O_RDWR);
  58. if (-1 == fb_fd) {
  59. switch (errno) {
  60. case ENOENT: /* no such file */
  61. case ENXIO: /* no driver */
  62. continue;
  63. default:
  64. perror("open");
  65. exit(EXIT_FAILURE);
  66. }
  67. }
  68. if (0 == ioctl(fb_fd, FBIOGET_FSCREENINFO, &si)) {
  69. if (si.smem_start == (unsigned long)fbuf.base)
  70. break;
  71. } else {
  72. /* Apparently not a framebuffer device. */
  73. }
  74. close(fb_fd);
  75. fb_fd = -1;
  76. }
  77. /* fb_fd is the file descriptor of the framebuffer device
  78. for the video output overlay, or -1 if no device was found. */
  79. Overlay Window and Scaling
  80. ==========================
  81. The overlay is controlled by source and target rectangles. The source
  82. rectangle selects a subsection of the framebuffer image to be overlaid,
  83. the target rectangle an area in the outgoing video signal where the
  84. image will appear. Drivers may or may not support scaling, and arbitrary
  85. sizes and positions of these rectangles. Further drivers may support any
  86. (or none) of the clipping/blending methods defined for the
  87. :ref:`Video Overlay <overlay>` interface.
  88. A struct :c:type:`v4l2_window` defines the size of the
  89. source rectangle, its position in the framebuffer and the
  90. clipping/blending method to be used for the overlay. To get the current
  91. parameters applications set the ``type`` field of a struct
  92. :c:type:`v4l2_format` to
  93. ``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY`` and call the
  94. :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctl. The driver fills the
  95. struct :c:type:`v4l2_window` substructure named ``win``. It is not
  96. possible to retrieve a previously programmed clipping list or bitmap.
  97. To program the source rectangle applications set the ``type`` field of a
  98. struct :c:type:`v4l2_format` to
  99. ``V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY``, initialize the ``win``
  100. substructure and call the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl.
  101. The driver adjusts the parameters against hardware limits and returns
  102. the actual parameters as :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` does. Like :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`,
  103. the :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl can be used to learn
  104. about driver capabilities without actually changing driver state. Unlike
  105. :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` this also works after the overlay has been enabled.
  106. A struct :c:type:`v4l2_crop` defines the size and position
  107. of the target rectangle. The scaling factor of the overlay is implied by
  108. the width and height given in struct :c:type:`v4l2_window`
  109. and struct :c:type:`v4l2_crop`. The cropping API applies to
  110. *Video Output* and *Video Output Overlay* devices in the same way as to
  111. *Video Capture* and *Video Overlay* devices, merely reversing the
  112. direction of the data flow. For more information see :ref:`crop`.
  113. Enabling Overlay
  114. ================
  115. There is no V4L2 ioctl to enable or disable the overlay, however the
  116. framebuffer interface of the driver may support the ``FBIOBLANK`` ioctl.