FreeBSD emulation of Linux V4L


The files here enable Linux ports that wish to access a FreeBSD webcam to do so. This is tested and works with the net/skype port and a camera that uses the pwc(4) or driver in the multimedia/pwcbsd port, or HPS's cuse4bsd(4) driver and associated webcamd etc.

It also allows browser-based Flash apps to access the camera. This is tested using www/firefox35 and www/linux-f10-flashplugin10 together with www/nspluginwrapper.

Contacting Me

By email here:


The files below have been tested and work on 7.2, 8.0 and 9-current.

On 9-current, where versions of these have been committed, you only need to update linux_ioctl.c; the other files are unchanged from the committed versions. Changes to the committed version include support for Video Clipping as well as some small bug fixes.

On 7.2 and 8.0, you will need to apply this diff:

In the directory /usr/src/sys/compat/linux:

Filename  Last Updated
linux_video.diff2010/04/24 22:30:01 UTC

On 8.0, you can just copy these four files if you prefer:
Filename  Last Updated
linux_ioctl.c2010/04/24 22:30:01 UTC
linux_ioctl.h2009/11/19 20:10:18 UTC
linux_videodev.h2009/11/19 20:11:04 UTC
linux_videodev_compat.h2009/12/02 19:44:48 UTC


Video Clipping

The version committed to 9-current works but does not support video clipping. The version here does include video clipping support but with the caveats below.

Video clipping allows the user to provide either a series of clip rectangles or a clip bitmap to the driver and have the driver mask the video according to the clipping specs provided.

Video clipping info is passed to the driver using the VIDIOCSWIN ioctl in two fields in the video_window structure: the integer clipcount and the pointer clips.

Adding support for clipping to the FreeBSD Linux emulator is problematic because it seems that this feature is not supported by many drivers and therefore it is ignored by many applications. Unfortunately, when not using it, rather than passing in a null clips list pointer and zero clipcount, some applications leave these fields uninitialized, casuing random values to be passed in. In the case where the driver does not use the clipping info, this is not a problem (although it is bad form). But the Linux emulator does not know which drivers will use this and which won't, so the Linux emulator must try to handle this clip list, and deal gracefully with cases where the values seem to be uninitialized.

The emulator code currently handles the clip data as follows:

Feedback from folk familiar with the use of the clipping list is requested, regarding whether the above handling seems appropriate.

Because some applications do not initialize the cliplist, even with the checks described here, it is still possible that VIDIOCSWIN might be executed with a non-zero clipcount but an invalid pointer. This will cause the ioctl to fail and return an error to the application (which will cause the application to fail) even though the application works OK on Linux. By removing the cliplist support, this does not happen allowing the application to work OK here too. By default, therefore, the cliplist code is not compiled in when compiling linux_ioctl.c.

So, if you need the cliplist support, you will need to compile the linux_ioctl.c file with COMPAT_LINUX_V4L_CLIPLIST defined. You can either define it in the file, or add it as an option in your kernel config file.


These are supported, but untested due to lack of FreeBSD driver support for them.