libv4l.xml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <title>Libv4l Userspace Library</title>
  2. <section id="libv4l-introduction">
  3. <title>Introduction</title>
  4. <para>libv4l is a collection of libraries which adds a thin abstraction
  5. layer on top of video4linux2 devices. The purpose of this (thin) layer
  6. is to make it easy for application writers to support a wide variety of
  7. devices without having to write separate code for different devices in the
  8. same class.</para>
  9. <para>An example of using libv4l is provided by
  10. <link linkend='v4l2grab-example'>v4l2grab</link>.
  11. </para>
  12. <para>libv4l consists of 3 different libraries:</para>
  13. <section>
  14. <title>libv4lconvert</title>
  15. <para>libv4lconvert is a library that converts several
  16. different pixelformats found in V4L2 drivers into a few common RGB and
  17. YUY formats.</para>
  18. <para>It currently accepts the following V4L2 driver formats:
  19. <link linkend="V4L2-PIX-FMT-BGR24"><constant>V4L2_PIX_FMT_BGR24</constant></link>,
  20. <link linkend="V4L2-PIX-FMT-HM12"><constant>V4L2_PIX_FMT_HM12</constant></link>,
  21. <link linkend="V4L2-PIX-FMT-JPEG"><constant>V4L2_PIX_FMT_JPEG</constant></link>,
  22. <link linkend="V4L2-PIX-FMT-MJPEG"><constant>V4L2_PIX_FMT_MJPEG</constant></link>,
  23. <link linkend="V4L2-PIX-FMT-MR97310A"><constant>V4L2_PIX_FMT_MR97310A</constant></link>,
  24. <link linkend="V4L2-PIX-FMT-OV511"><constant>V4L2_PIX_FMT_OV511</constant></link>,
  25. <link linkend="V4L2-PIX-FMT-OV518"><constant>V4L2_PIX_FMT_OV518</constant></link>,
  26. <link linkend="V4L2-PIX-FMT-PAC207"><constant>V4L2_PIX_FMT_PAC207</constant></link>,
  27. <link linkend="V4L2-PIX-FMT-PJPG"><constant>V4L2_PIX_FMT_PJPG</constant></link>,
  28. <link linkend="V4L2-PIX-FMT-RGB24"><constant>V4L2_PIX_FMT_RGB24</constant></link>,
  29. <link linkend="V4L2-PIX-FMT-SBGGR8"><constant>V4L2_PIX_FMT_SBGGR8</constant></link>,
  30. <link linkend="V4L2-PIX-FMT-SGBRG8"><constant>V4L2_PIX_FMT_SGBRG8</constant></link>,
  31. <link linkend="V4L2-PIX-FMT-SGRBG8"><constant>V4L2_PIX_FMT_SGRBG8</constant></link>,
  32. <link linkend="V4L2-PIX-FMT-SN9C10X"><constant>V4L2_PIX_FMT_SN9C10X</constant></link>,
  33. <link linkend="V4L2-PIX-FMT-SN9C20X-I420"><constant>V4L2_PIX_FMT_SN9C20X_I420</constant></link>,
  34. <link linkend="V4L2-PIX-FMT-SPCA501"><constant>V4L2_PIX_FMT_SPCA501</constant></link>,
  35. <link linkend="V4L2-PIX-FMT-SPCA505"><constant>V4L2_PIX_FMT_SPCA505</constant></link>,
  36. <link linkend="V4L2-PIX-FMT-SPCA508"><constant>V4L2_PIX_FMT_SPCA508</constant></link>,
  37. <link linkend="V4L2-PIX-FMT-SPCA561"><constant>V4L2_PIX_FMT_SPCA561</constant></link>,
  38. <link linkend="V4L2-PIX-FMT-SQ905C"><constant>V4L2_PIX_FMT_SQ905C</constant></link>,
  39. <constant>V4L2_PIX_FMT_SRGGB8</constant>,
  40. <link linkend="V4L2-PIX-FMT-UYVY"><constant>V4L2_PIX_FMT_UYVY</constant></link>,
  41. <link linkend="V4L2-PIX-FMT-YUV420"><constant>V4L2_PIX_FMT_YUV420</constant></link>,
  42. <link linkend="V4L2-PIX-FMT-YUYV"><constant>V4L2_PIX_FMT_YUYV</constant></link>,
  43. <link linkend="V4L2-PIX-FMT-YVU420"><constant>V4L2_PIX_FMT_YVU420</constant></link>,
  44. and <link linkend="V4L2-PIX-FMT-YVYU"><constant>V4L2_PIX_FMT_YVYU</constant></link>.
  45. </para>
  46. <para>Later on libv4lconvert was expanded to also be able to do
  47. various video processing functions to improve webcam video quality.
  48. The video processing is split in to 2 parts: libv4lconvert/control and
  49. libv4lconvert/processing.</para>
  50. <para>The control part is used to offer video controls which can
  51. be used to control the video processing functions made available by
  52. libv4lconvert/processing. These controls are stored application wide
  53. (until reboot) by using a persistent shared memory object.</para>
  54. <para>libv4lconvert/processing offers the actual video
  55. processing functionality.</para>
  56. </section>
  57. <section>
  58. <title>libv4l1</title>
  59. <para>This library offers functions that can be used to quickly
  60. make v4l1 applications work with v4l2 devices. These functions work exactly
  61. like the normal open/close/etc, except that libv4l1 does full emulation of
  62. the v4l1 api on top of v4l2 drivers, in case of v4l1 drivers it
  63. will just pass calls through.</para>
  64. <para>Since those functions are emulations of the old V4L1 API,
  65. it shouldn't be used for new applications.</para>
  66. </section>
  67. <section>
  68. <title>libv4l2</title>
  69. <para>This library should be used for all modern V4L2
  70. applications.</para>
  71. <para>It provides handles to call V4L2 open/ioctl/close/poll
  72. methods. Instead of just providing the raw output of the device, it enhances
  73. the calls in the sense that it will use libv4lconvert to provide more video
  74. formats and to enhance the image quality.</para>
  75. <para>In most cases, libv4l2 just passes the calls directly
  76. through to the v4l2 driver, intercepting the calls to
  77. <link linkend='vidioc-g-fmt'><constant>VIDIOC_TRY_FMT</constant></link>,
  78. <link linkend='vidioc-g-fmt'><constant>VIDIOC_G_FMT</constant></link>
  79. <link linkend='vidioc-g-fmt'><constant>VIDIOC_S_FMT</constant></link>
  80. <link linkend='vidioc-enum-framesizes'><constant>VIDIOC_ENUM_FRAMESIZES</constant></link>
  81. and <link linkend='vidioc-enum-frameintervals'><constant>VIDIOC_ENUM_FRAMEINTERVALS</constant></link>
  82. in order to emulate the formats
  83. <link linkend="V4L2-PIX-FMT-BGR24"><constant>V4L2_PIX_FMT_BGR24</constant></link>,
  84. <link linkend="V4L2-PIX-FMT-RGB24"><constant>V4L2_PIX_FMT_RGB24</constant></link>,
  85. <link linkend="V4L2-PIX-FMT-YUV420"><constant>V4L2_PIX_FMT_YUV420</constant></link>,
  86. and <link linkend="V4L2-PIX-FMT-YVU420"><constant>V4L2_PIX_FMT_YVU420</constant></link>,
  87. if they aren't available in the driver.
  88. <link linkend='vidioc-enum-fmt'><constant>VIDIOC_ENUM_FMT</constant></link>
  89. keeps enumerating the hardware supported formats, plus the emulated formats
  90. offered by libv4l at the end.
  91. </para>
  92. <section id="libv4l-ops">
  93. <title>Libv4l device control functions</title>
  94. <para>The common file operation methods are provided by
  95. libv4l.</para>
  96. <para>Those functions operate just like glibc
  97. open/close/dup/ioctl/read/mmap/munmap:</para>
  98. <itemizedlist><listitem>
  99. <para>int v4l2_open(const char *file, int oflag,
  100. ...) -
  101. operates like the standard <link linkend='func-open'>open()</link> function.
  102. </para></listitem><listitem>
  103. <para>int v4l2_close(int fd) -
  104. operates like the standard <link linkend='func-close'>close()</link> function.
  105. </para></listitem><listitem>
  106. <para>int v4l2_dup(int fd) -
  107. operates like the standard dup() function, duplicating a file handler.
  108. </para></listitem><listitem>
  109. <para>int v4l2_ioctl (int fd, unsigned long int request, ...) -
  110. operates like the standard <link linkend='func-ioctl'>ioctl()</link> function.
  111. </para></listitem><listitem>
  112. <para>int v4l2_read (int fd, void* buffer, size_t n) -
  113. operates like the standard <link linkend='func-read'>read()</link> function.
  114. </para></listitem><listitem>
  115. <para>void v4l2_mmap(void *start, size_t length, int prot, int flags, int fd, int64_t offset); -
  116. operates like the standard <link linkend='func-mmap'>mmap()</link> function.
  117. </para></listitem><listitem>
  118. <para>int v4l2_munmap(void *_start, size_t length); -
  119. operates like the standard <link linkend='func-munmap'>munmap()</link> function.
  120. </para></listitem>
  121. </itemizedlist>
  122. <para>Those functions provide additional control:</para>
  123. <itemizedlist><listitem>
  124. <para>int v4l2_fd_open(int fd, int v4l2_flags) -
  125. opens an already opened fd for further use through v4l2lib and possibly
  126. modify libv4l2's default behavior through the v4l2_flags argument.
  127. Currently, v4l2_flags can be <constant>V4L2_DISABLE_CONVERSION</constant>,
  128. to disable format conversion.
  129. </para></listitem><listitem>
  130. <para>int v4l2_set_control(int fd, int cid, int value) -
  131. This function takes a value of 0 - 65535, and then scales that range to
  132. the actual range of the given v4l control id, and then if the cid exists
  133. and is not locked sets the cid to the scaled value.
  134. </para></listitem><listitem>
  135. <para>int v4l2_get_control(int fd, int cid) -
  136. This function returns a value of 0 - 65535, scaled to from the actual range
  137. of the given v4l control id. when the cid does not exist, could not be
  138. accessed for some reason, or some error occurred 0 is returned.
  139. </para></listitem>
  140. </itemizedlist>
  141. </section>
  142. </section>
  143. <section>
  144. <title>v4l1compat.so wrapper library</title>
  145. <para>This library intercepts calls to
  146. open/close/ioctl/mmap/mmunmap operations and redirects them to the libv4l
  147. counterparts, by using LD_PRELOAD=/usr/lib/v4l1compat.so. It also
  148. emulates V4L1 calls via V4L2 API.</para>
  149. <para>It allows usage of binary legacy applications that
  150. still don't use libv4l.</para>
  151. </section>
  152. </section>