LWN.net Logo

LPC: What's happening with webcams

September 25, 2008

This article was contributed by Don Marti

Christmas is coming early for webcam users. Support for hundreds of popular webcams, available from Michel Xhaard's GSPCA project, is merged for inclusion in the upcoming 2.6.27 kernel. The amount of tweaking required from the user, the distribution, or both, has been cut, and it's likely that a random webcam will now just work out of the box.

Even with the much-wanted drivers becoming part of mainstream Linux, a small matter of plumbing remains. Webcams, Hans de Goede pointed out at the Linux Plumbers Conference, produce a variety of compressed video data. "They all came up with interesting proprietary compressed video formats," he says. The out-of-tree version of GSPCA did some decoding in kernel space, but the decoding of many camera-specific custom video formats had to be ripped out, as doing that kind of work in-kernel is a Linux faux pas. That's where Hans's libv4l comes in. Announced in June, the new library (actually a set of three) does the format conversion.

While not a Red Hat employee at the time (he is now) Hans posted a "BetterWebcamSupport" feature idea on the Fedora wiki, writing, "Currently many webcams do not work with Fedora out of the box even though a Linux driver exists for them." The problem was partly fixed with the GSPCA cleanup and inclusion upstream, and partly became the rationale for libv4l. Besides the core libv4lconvert library, the package includes libv4l2, to emulate a /dev/videoX device which, transparently to the application, will deliver "sane" video formats. There's also a libv4l1 to do the same thing but for the V4L1 API.

An audience member asked why the library is separate from gstreamer, which is already set up for video transcoding. V4L2 developer Hans Verkuil responded from the audience that "it's something that you do not want to have in the kernel, but it has to be small and fast." That leaves out gstreamer as a general solution, since some webcam applications don't need gstreamer or can't afford the space it takes. Therefore, a separate library. It needs one more feature, too: vendors install camera chips however they'll fit, which means the same camera module could be right side up on one product and upside down on another. Therefore, libv4l has software support for flipping images, but it still needs the data to know when to flip: a table identifying which hardware has the camera module in which orientation.

Brandon Philips at SUSE has another piece of the puzzle, a "frame server" that lets multiple applications share the webcam—doing for the webcam what PulseAudio does for the sound hardware. You can't shoot a photo with Cheese while another app has the webcam open, as he showed in a screenshot.

You can always rely on the computer hardware industry to figure out ways to save a little money on something if it's possible to solve the problem in software. Many new webcams have motorized focus but no hardware autofocus. Autofocus is up to the host system—which means a focusing daemon needs to see the video at the same time as an end-user application. So providing access for the autofocus daemon is another reason for the frame server. Someone on the mailing list has the autofocus math that will form the guts of the daemon figured out, but it's a fairly intensive calculation and will need to be done on an occasional frame of video, not each frame.

While the original frame server idea would have one shared memory segment per system, with access for multiple users, PulseAudio developer Lennart Poettering pointed out the potential security risks of that idea from the audience. "Memory mapping across privileges is a really bad idea," he said. He suggested putting the frame server in the user session to prevent users from, at least, killing each other's webcam applications.

The webcam market is one where Linux is an afterthought if it's a thought at all. The Linux conferences aren't teeming with employees of webcam manufacturers. The support Linux does have shows that the community can still support hardware on its own when it has to.


(Log in to post comments)

LPC: What's happening with webcams

Posted Sep 25, 2008 21:21 UTC (Thu) by guinan (subscriber, #4644) [Link]

Any word on the ov51x drivers? The in-kernel drivers only support v4l (not v4l2). The out-of-tree driver supports v4l2, but appears to have stagnated (last update 2006), and doesn't compile on recent kernels without patching.

LPC: What's happening with webcams

Posted Sep 26, 2008 5:22 UTC (Fri) by shalem (subscriber, #4062) [Link]

GSPCA has support for ov519 cams already I'm looking into adding support for 0v518 and then 0v511, I have one of both laying on a shelf here.

The biggest issue is finding time to work on this. The article may give the impression I've been hired by RedHat to work on this, that is not the case, I've been hired to work on the installer (anaconda)

Hans de Goede

LPC: What's happening with webcams

Posted Sep 26, 2008 16:06 UTC (Fri) by jordip (guest, #47356) [Link]

BTW, I have a pixart imaging with BUS ID 0x093ax0262a
Right now I only can access a very old computer I dont dare to compile a kernel here (how many days can it take ...) but I am sure it works with the spca_pac7311 driver

LPC: What's happening with webcams

Posted Sep 25, 2008 23:40 UTC (Thu) by bronson (subscriber, #4806) [Link]

Frame server?? Why not just allow multiple applications to open a single video device simultaneously?

LPC: What's happening with webcams

Posted Sep 26, 2008 14:14 UTC (Fri) by mattdm (subscriber, #18) [Link]

Presumably because the devices don't support that.

LPC: What's happening with webcams

Posted Sep 26, 2008 15:35 UTC (Fri) by bronson (subscriber, #4806) [Link]

Sure, but that's the great thing about having the source code to your own kernel, you can fix things properly.

Did the V4L guys consider making this change and reject it because it would be too hard?

LPC: What's happening with webcams

Posted Sep 26, 2008 15:54 UTC (Fri) by JoeBuck (subscriber, #2330) [Link]

But then the code to arbitrate between the multiple devices that have the camera open has to be in the kernel, instead of in user space. It can be made to work, but is probably not the best design choice.

webcams and multiple users

Posted Sep 26, 2008 16:49 UTC (Fri) by sdalley (subscriber, #18550) [Link]

It's a question of practicalities. Think it through a little bit.

Remember, it's in userspace that the simultaneous reads have to take place.

libv4l has to provide a stream of decoded video frames by reading the encoded video device via the kernel interface, decoding the data and providing a proxy "device" in userspace. It makes sense for at most one thing to be doing that, and AIUI something which they call a "frame server" is to be the thing doing the proxying.

The userspace client programs can then talk simultaneously to the proxy to get the data that they themselves happen to be interested in. This is going to be different for different clients. That being the case, the "server" has to be the thing arbitrating the access to data by the different clients, reading and decoding new frames and updating the pool of decoded data which the clients are reading and quite possibly seeking around. Timed callbacks may also be required. This implies a separate thread or process of execution. Only in the very simplest and most restrictive use cases could you do without this.

Simultaneous use of a single device by multiple clients implies this sort of complexity, and you have to stuff it somewhere. In this case, it has to be in userspace.

LPC: What's happening with webcams

Posted Sep 26, 2008 7:04 UTC (Fri) by eru (subscriber, #2753) [Link]

Christmas is coming early for webcam users.

Early??? Very late, I would say. The GSPCA has existed for several years, but since it has been outside the official kernel and not included even in popular distro kernels, it is very cumbersome to take into use, and basically inaccessible for all nontechical users. I am very happy this is finally coming to the official kernel, so I can start playing with my dust-gathering webcams again (I used to run GSPCA but got tired of refitting it after each kernel upgrade). Thanks for everyone involved!

LPC: What's happening with webcams

Posted Sep 26, 2008 15:18 UTC (Fri) by wingo (guest, #26929) [Link]

The bits about a v4l daemon sound completely crazy. There is no sane use case that I know of that involves transparent access to the web cam from multiple applications.

We've seen this kind of user-space layering in innumerable sound servers, and it always proves to be a more difficult problem that the developers envision.

I say this as one who has worked a lot with v4l integration in gstreamer, both v1 and v2, and as a former hacker on Flumotion.

I might be wrong, but my instinct is that talk of v4l daemons indicates we have reached the point where entropy takes over from marginal returns.

LPC: What's happening with webcams

Posted Sep 26, 2008 18:01 UTC (Fri) by tmassey (guest, #52228) [Link]

They mentioned right in the article a case where this is necessary: Autofocus.

A userspace daemon is being used to focus the camera by analyzing the output from the webcam. I assume that you want some *other* application to have access to the stream *beside* the autofocus daemon?

They also mentioned another one: being able to use one program to take a snapshot of a video stream while another is displaying the feed. While you could expect every app that wants to have access to the video to make their own captures, why not just have a second application do it once and be done with it?

LPC: What's happening with webcams

Posted Oct 2, 2008 17:50 UTC (Thu) by smurf (subscriber, #17840) [Link]

Yes there are usecases for simultaneous access.

Program A archives periodic cam snapshots.

Program B does motion analysis.

Program C provides a high-quality stream for the internal LAN.

Program D provides a low-quality stream for Internet access.

Program E does the aforementioned autofocus, auto-brightness, and/or whatever.

Program F monitors that the stream exists, and raises bloody hell if somebody disconnects the camera.

Program G ... you get the idea.

Requiring that all of this be packaged in one single application which does all of it perfectly is (a) unrealistic and (b) not The Unix Way.

LPC: What's happening with webcams

Posted Sep 26, 2008 16:21 UTC (Fri) by guinan (subscriber, #4644) [Link]

I'd like to be able to record long periods of video from a webcam (birdfeeder cam, home security cam, etc.) and review/edit it later, but also be able to see the "live feed" from anywhere, maybe by tapping in and encoding to mjpeg and feeding through a web server.

So I think a "frame server" is a great idea.

  device--frameserver-+-mencoder
                      +-mjpeg encoder
                      +-preview app
                      +-...

LPC: What's happening with webcams

Posted Sep 26, 2008 17:38 UTC (Fri) by wingo (guest, #26929) [Link]

You can do this on the application level already, via e.g. Flumotion.

LPC: What's happening with webcams

Posted Sep 26, 2008 18:32 UTC (Fri) by elmarco (subscriber, #42897) [Link]

s/An audience member/Bastien Nocera

Corrections to the usual address

Posted Sep 27, 2008 4:11 UTC (Sat) by bignose (subscriber, #40) [Link]

You should, as always, direct article corrections to <lwn@lwn.net>. A correction posted in comments is less likely to be seen by the right people, and less likely to be fixed promptly.

Corrections to the usual address

Posted Sep 29, 2008 7:22 UTC (Mon) by ekj (subscriber, #1524) [Link]

We're spoilt. In principle you're right. In practice them folks at Lwn follow the site closely and seem to somehow magically ALWAYS notice suggestions and improvements posted in comments.

You should still use the email-thing though, if for no other reason than to keep signal/noise in the comments up.

Corrections to the usual address

Posted Sep 29, 2008 20:48 UTC (Mon) by nix (subscriber, #2304) [Link]

I think they just follow the comments RSS feed :)

LPC: What's happening with webcams

Posted Oct 13, 2008 12:53 UTC (Mon) by PinTail (guest, #41983) [Link]

I'm a bit new to all this. How this this square with the idea of embedding some kind of webcam control within an existing application. For example, aMSN (my kids insist upon it) has the ability to use a webcam, but for some reason it always opens a new window dedicated to the cam in question (and nothing else). SO what happens is that with several dirrent conversations going at one, they loose track of which webcam window is associated with which chat window. I must admit to taking some pleasure in hearing them whine about it, but it would be cool if this helped fix that problem.

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds