Path: blob/master/Documentation/DocBook/v4l/libv4l.xml
10821 views
<title>Libv4l Userspace Library</title>1<section id="libv4l-introduction">2<title>Introduction</title>34<para>libv4l is a collection of libraries which adds a thin abstraction5layer on top of video4linux2 devices. The purpose of this (thin) layer6is to make it easy for application writers to support a wide variety of7devices without having to write separate code for different devices in the8same class.</para>9<para>An example of using libv4l is provided by10<link linkend='v4l2grab-example'>v4l2grab</link>.11</para>1213<para>libv4l consists of 3 different libraries:</para>14<section>15<title>libv4lconvert</title>1617<para>libv4lconvert is a library that converts several18different pixelformats found in V4L2 drivers into a few common RGB and19YUY formats.</para>20<para>It currently accepts the following V4L2 driver formats:21<link linkend="V4L2-PIX-FMT-BGR24"><constant>V4L2_PIX_FMT_BGR24</constant></link>,22<link linkend="V4L2-PIX-FMT-HM12"><constant>V4L2_PIX_FMT_HM12</constant></link>,23<link linkend="V4L2-PIX-FMT-JPEG"><constant>V4L2_PIX_FMT_JPEG</constant></link>,24<link linkend="V4L2-PIX-FMT-MJPEG"><constant>V4L2_PIX_FMT_MJPEG</constant></link>,25<link linkend="V4L2-PIX-FMT-MR97310A"><constant>V4L2_PIX_FMT_MR97310A</constant></link>,26<link linkend="V4L2-PIX-FMT-OV511"><constant>V4L2_PIX_FMT_OV511</constant></link>,27<link linkend="V4L2-PIX-FMT-OV518"><constant>V4L2_PIX_FMT_OV518</constant></link>,28<link linkend="V4L2-PIX-FMT-PAC207"><constant>V4L2_PIX_FMT_PAC207</constant></link>,29<link linkend="V4L2-PIX-FMT-PJPG"><constant>V4L2_PIX_FMT_PJPG</constant></link>,30<link linkend="V4L2-PIX-FMT-RGB24"><constant>V4L2_PIX_FMT_RGB24</constant></link>,31<link linkend="V4L2-PIX-FMT-SBGGR8"><constant>V4L2_PIX_FMT_SBGGR8</constant></link>,32<link linkend="V4L2-PIX-FMT-SGBRG8"><constant>V4L2_PIX_FMT_SGBRG8</constant></link>,33<link linkend="V4L2-PIX-FMT-SGRBG8"><constant>V4L2_PIX_FMT_SGRBG8</constant></link>,34<link linkend="V4L2-PIX-FMT-SN9C10X"><constant>V4L2_PIX_FMT_SN9C10X</constant></link>,35<link linkend="V4L2-PIX-FMT-SN9C20X-I420"><constant>V4L2_PIX_FMT_SN9C20X_I420</constant></link>,36<link linkend="V4L2-PIX-FMT-SPCA501"><constant>V4L2_PIX_FMT_SPCA501</constant></link>,37<link linkend="V4L2-PIX-FMT-SPCA505"><constant>V4L2_PIX_FMT_SPCA505</constant></link>,38<link linkend="V4L2-PIX-FMT-SPCA508"><constant>V4L2_PIX_FMT_SPCA508</constant></link>,39<link linkend="V4L2-PIX-FMT-SPCA561"><constant>V4L2_PIX_FMT_SPCA561</constant></link>,40<link linkend="V4L2-PIX-FMT-SQ905C"><constant>V4L2_PIX_FMT_SQ905C</constant></link>,41<constant>V4L2_PIX_FMT_SRGGB8</constant>,42<link linkend="V4L2-PIX-FMT-UYVY"><constant>V4L2_PIX_FMT_UYVY</constant></link>,43<link linkend="V4L2-PIX-FMT-YUV420"><constant>V4L2_PIX_FMT_YUV420</constant></link>,44<link linkend="V4L2-PIX-FMT-YUYV"><constant>V4L2_PIX_FMT_YUYV</constant></link>,45<link linkend="V4L2-PIX-FMT-YVU420"><constant>V4L2_PIX_FMT_YVU420</constant></link>,46and <link linkend="V4L2-PIX-FMT-YVYU"><constant>V4L2_PIX_FMT_YVYU</constant></link>.47</para>48<para>Later on libv4lconvert was expanded to also be able to do49various video processing functions to improve webcam video quality.50The video processing is split in to 2 parts: libv4lconvert/control and51libv4lconvert/processing.</para>5253<para>The control part is used to offer video controls which can54be used to control the video processing functions made available by55libv4lconvert/processing. These controls are stored application wide56(until reboot) by using a persistent shared memory object.</para>5758<para>libv4lconvert/processing offers the actual video59processing functionality.</para>60</section>61<section>62<title>libv4l1</title>63<para>This library offers functions that can be used to quickly64make v4l1 applications work with v4l2 devices. These functions work exactly65like the normal open/close/etc, except that libv4l1 does full emulation of66the v4l1 api on top of v4l2 drivers, in case of v4l1 drivers it67will just pass calls through.</para>68<para>Since those functions are emulations of the old V4L1 API,69it shouldn't be used for new applications.</para>70</section>71<section>72<title>libv4l2</title>73<para>This library should be used for all modern V4L274applications.</para>75<para>It provides handles to call V4L2 open/ioctl/close/poll76methods. Instead of just providing the raw output of the device, it enhances77the calls in the sense that it will use libv4lconvert to provide more video78formats and to enhance the image quality.</para>79<para>In most cases, libv4l2 just passes the calls directly80through to the v4l2 driver, intercepting the calls to81<link linkend='vidioc-g-fmt'><constant>VIDIOC_TRY_FMT</constant></link>,82<link linkend='vidioc-g-fmt'><constant>VIDIOC_G_FMT</constant></link>83<link linkend='vidioc-g-fmt'><constant>VIDIOC_S_FMT</constant></link>84<link linkend='vidioc-enum-framesizes'><constant>VIDIOC_ENUM_FRAMESIZES</constant></link>85and <link linkend='vidioc-enum-frameintervals'><constant>VIDIOC_ENUM_FRAMEINTERVALS</constant></link>86in order to emulate the formats87<link linkend="V4L2-PIX-FMT-BGR24"><constant>V4L2_PIX_FMT_BGR24</constant></link>,88<link linkend="V4L2-PIX-FMT-RGB24"><constant>V4L2_PIX_FMT_RGB24</constant></link>,89<link linkend="V4L2-PIX-FMT-YUV420"><constant>V4L2_PIX_FMT_YUV420</constant></link>,90and <link linkend="V4L2-PIX-FMT-YVU420"><constant>V4L2_PIX_FMT_YVU420</constant></link>,91if they aren't available in the driver.92<link linkend='vidioc-enum-fmt'><constant>VIDIOC_ENUM_FMT</constant></link>93keeps enumerating the hardware supported formats, plus the emulated formats94offered by libv4l at the end.95</para>96<section id="libv4l-ops">97<title>Libv4l device control functions</title>98<para>The common file operation methods are provided by99libv4l.</para>100<para>Those functions operate just like glibc101open/close/dup/ioctl/read/mmap/munmap:</para>102<itemizedlist><listitem>103<para>int v4l2_open(const char *file, int oflag,104...) -105operates like the standard <link linkend='func-open'>open()</link> function.106</para></listitem><listitem>107<para>int v4l2_close(int fd) -108operates like the standard <link linkend='func-close'>close()</link> function.109</para></listitem><listitem>110<para>int v4l2_dup(int fd) -111operates like the standard dup() function, duplicating a file handler.112</para></listitem><listitem>113<para>int v4l2_ioctl (int fd, unsigned long int request, ...) -114operates like the standard <link linkend='func-ioctl'>ioctl()</link> function.115</para></listitem><listitem>116<para>int v4l2_read (int fd, void* buffer, size_t n) -117operates like the standard <link linkend='func-read'>read()</link> function.118</para></listitem><listitem>119<para>void v4l2_mmap(void *start, size_t length, int prot, int flags, int fd, int64_t offset); -120operates like the standard <link linkend='func-mmap'>mmap()</link> function.121</para></listitem><listitem>122<para>int v4l2_munmap(void *_start, size_t length); -123operates like the standard <link linkend='func-munmap'>munmap()</link> function.124</para></listitem>125</itemizedlist>126<para>Those functions provide additional control:</para>127<itemizedlist><listitem>128<para>int v4l2_fd_open(int fd, int v4l2_flags) -129opens an already opened fd for further use through v4l2lib and possibly130modify libv4l2's default behavior through the v4l2_flags argument.131Currently, v4l2_flags can be <constant>V4L2_DISABLE_CONVERSION</constant>,132to disable format conversion.133</para></listitem><listitem>134<para>int v4l2_set_control(int fd, int cid, int value) -135This function takes a value of 0 - 65535, and then scales that range to136the actual range of the given v4l control id, and then if the cid exists137and is not locked sets the cid to the scaled value.138</para></listitem><listitem>139<para>int v4l2_get_control(int fd, int cid) -140This function returns a value of 0 - 65535, scaled to from the actual range141of the given v4l control id. when the cid does not exist, could not be142accessed for some reason, or some error occurred 0 is returned.143</para></listitem>144</itemizedlist>145</section>146</section>147<section>148149<title>v4l1compat.so wrapper library</title>150151<para>This library intercepts calls to152open/close/ioctl/mmap/mmunmap operations and redirects them to the libv4l153counterparts, by using LD_PRELOAD=/usr/lib/v4l1compat.so. It also154emulates V4L1 calls via V4L2 API.</para>155<para>It allows usage of binary legacy applications that156still don't use libv4l.</para>157</section>158159</section>160<!--161Local Variables:162mode: sgml163sgml-parent-document: "v4l2.sgml"164indent-tabs-mode: nil165End:166-->167168169