dev-osd.xml 5.7 KB

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