Change Readme and Copying suffix from lib to libv4l
[platform/upstream/v4l-utils.git] / README.libv4l
1 Introduction
2 ------------
3
4 libv4l is a collection of libraries which adds a thin abstraction layer on
5 top of video4linux2 devices. The purpose of this (thin) layer is to make it
6 easy for application writers to support a wide variety of devices without
7 having to write separate code for different devices in the same class.
8
9 All libv4l components are licensed under the GNU Lesser General Public
10 License version 2 or (at your option) any later version.
11
12 libv4l consists of 3 different libraries:
13
14
15 libv4lconvert
16 -------------
17
18 libv4lconvert started as a library to convert from any (known) pixelformat to
19 V4l2_PIX_FMT_BGR24, RGB24, YUV420 or YVU420.
20
21 The list of know source formats is large and continually growing, so instead
22 of keeping an (almost always outdated) list here in the README, I refer you
23 to the source, see the list of defines at the top of
24 libv4lconvert/libv4lconvert.c for the full list.
25 For more details on the v4lconvert_ functions see libv4lconvert.h.
26
27 Later on libv4lconvert was expanded to also be able to do various video
28 processing functions to improve webcam video quality on a software basis. So
29 the name no longer 100% covers the functionality. The video processing is
30 split in to 2 parts, libv4lconvert/control and libv4lconvert/processing.
31
32 The control part is used to offer video controls which can be used to control
33 the video processing functions made available by libv4lconvert/processing.
34 These controls are stored application wide (until reboot) by using a
35 persistent shared memory object.
36
37 libv4lconvert/processing offers the actual video processing functionality.
38
39
40 libv4l1
41 -------
42
43 This offers functions like v4l1_open, v4l1_ioctl, etc. which can by used to
44 quickly make v4l1 applications work with v4l2 devices. These functions work
45 exactly like the normal open/close/etc, except that libv4l1 does full emulation
46 of the v4l1 api on top of v4l2 drivers, in case of v4l1 drivers it will just
47 pass calls through. For more details on the v4l1_ functions see libv4l1.h .
48
49
50 libv4l2
51 -------
52
53 This offers functions like v4l2_open, v4l2_ioctl, etc. which can by used to
54 quickly make v4l2 applications work with v4l2 devices with weird formats.
55 libv4l2 mostly passes calls directly through to the v4l2 driver. When the
56 app does a TRY_FMT / S_FMT with a not supported format libv4l2 will get in
57 the middle and emulate the format (if an app wants to know which formats the
58 hardware can _really_ do it should use ENUM_FMT, not randomly try a bunch of
59 S_FMT's). For more details on the v4l2_ functions see libv4l2.h .
60
61
62 wrappers
63 --------
64
65 The functionality provided by libv4l1 for v4l1 apps and libv4l2 for v4l2 apps
66 can also be used by existing apps without modifying them. For this purpose
67 2 wrapper libraries are provided which can be preloaded before starting the
68 application using the LD_PRELOAD environment variable. These wrappers will
69 then intercept calls to open/close/ioctl/etc. and if these calls directed
70 towards a video device the wrapper will redirect the call to the libv4lX
71 counterparts.
72
73 The preloadable libv4l1 wrapper which adds v4l2 device compatibility to v4l1
74 applications is called v4l1compat.so. The preloadable libv4l2 wrapper which
75 adds support for various pixelformats to v4l2 applications is called
76 v4l2convert.so.
77
78 Example usage (after install in default location):
79 $ export LD_PRELOAD=/usr/local/lib/libv4l/v4l1compat.so
80 $ camorama
81
82
83 Prerequisites
84 -------------
85
86 libv4l requires shmem file system support in the kernel (CONFIG_SHMEM).
87
88
89 FAQ
90 ---
91
92 Q: Why libv4l, whats wrong with directly accessing v4l2 devices ?
93 Q: Do we really need yet another library ?
94 A: Current webcam using applications like ekiga contain code to handle many
95 different specific pixelformats webcam's use, but that code only supports a
96 small subset of all native webcam (compressed) pixelformats. Other current
97 v4l2 applications do not support anything but rgb pixelformats (xawtv for
98 example) and this will not work with most webcams at all.
99
100 With gspca being ported to v4l2 and thus decoding to normal formats being
101 removed from the device driver as this really belongs in userspace, ekiga
102 would need to be extended with many more often chip dependent formats, like
103 the bayer compression used by the spca561 and the (different) compression used
104 by the pac207 and the (again different) compression used by the sn9c102. Adding
105 support for all these formats should not be done at the application level, as
106 then it needs to be written for each application separately. Licensing issues
107 with the decompressors will then also become a problem as just cut and pasting
108 from one application to another is bound to hit license incompatibilities.
109
110 So clearly this belongs in a library, and in a library with a license which
111 allows this code to be used from as many different applications as possible.
112 Hence libv4l was born.
113
114
115 Q: Under which license may I use and distribute libv4l?
116 A: The libv4l libraries are licensed under the GNU Library General Publishing
117 License version 2 or (at your option) any later version. See the included
118 COPYING.LIBV4L file. The decompression helpers are licensed under the GNU
119 Library Publishing License version 2 (as they are derived from kernel code)
120
121
122 Q: Okay so I get the use of having a libv4lconvert, but why libv4l1 ?
123 A: Many v4l2 drivers do not offer full v4l1 compatibility. They often do not
124 implemented the CGMBUF ioctl and v4l1 style mmap call. Adding support to all
125 these drivers for this is a lot of work and more importantly unnecessary
126 adds code to kernel space.
127
128 Also even if the CGMBUF ioctl and v4l1 style mmap are supported, then most
129 cams still deliver pixelformats which v4l1 applications do not understand.
130
131 This libv4l1 was born as an easy way to get v4l1 applications to work with
132 v4l2 devices without requiring full v4l1 emulation (including format
133 conversion) in the kernel, and without requiring major changes to the
134 applications.
135
136
137 Q: Why should I use libv4l2 in my app instead of direct device access
138    combined with libv4lconvert?
139 A: libv4l2 is mainly meant for quickly and easily adding support for more
140 pixelformats to existing v4l2 applications. So if you feel better directly
141 accessing the device in combination with libv4lconvert that's fine too.
142
143 Notice that libv4l2 also does emulation of the read() call on devices which
144 do not support it in the driver. In the background this uses mmap buffers
145 (even on devices which do support the read call). This mmap gives libv4lconvert
146 zero-copy access to the captured frame, and then it can write the converted
147 data directly to the buffer the application provided to v4l2_read(). Thus
148 another reason to use libv4l2 is to get the no memcpy advantage of the mmap
149 capture method combined with the simplicity of making a simple read() call.
150
151
152 Q: Where to send bugreports / questions?
153 A: Please send libv4l questions / bugreports to the:
154    Linux Media Mailing List <linux-media@vger.kernel.org>
155    Subscription is not necessary to send mail to this list. If you're not
156    subscribed please put yourself in the CC of your original mail so you
157    will receive replies.
158
159 Q: How do I port my application to libv4l1?
160 A: Just replace the open call for your device by v4l1_open and all
161    following calls concerning this device file descriptor by their
162    counterpart v4l1_xxx (for a list see libv4l1.h).
163
164 Q: How do I port my application to libv4l2?
165 A: Just replace the open call for your device by v4l2_open and all
166    following calls concerning this device file descriptor by their
167    counterpart v4l2_xxx (for a list see libv4l2.h).
168
169 Q: I still need an example how to convert my application!
170 A: Check out the patches for the VLC media player:
171    https://trac.videolan.org/vlc/attachment/ticket/1804/vlc-0.8.6-libv4l1.patch
172    https://trac.videolan.org/vlc/attachment/ticket/1804/vlc-0.8.6-libv4l2.patch