README File for V4L2 Sample Drivers

1999-August-5


The sample drivers will compile and work like functioning device drivers,
but require no actual hardware. I have tried to make them implement as much
of the API as possible for a pseudo device. You can use a sample driver 
to test applications if you have no hardware or no V4L2 driver for your 
hardware. It sends debug information to /proc/kmsg or /var/log/messages if
any application mistake is detected. The sample driver source code can 
also be used as a starting point for a new driver, even a closed-source 
driver. The sample drivers are in the public domain, and have no copy 
restrictions of any kind. 

Two sample drivers have been written so far:
v4l2cap.c      Video capture driver
v4l2out.c      Video output driver such as for a DVD decoder or analog 
               video playback
A codec driver is in progress.

Building a Driver

First, make sure you have the videodev.h and videodev.c files installed, 
and that you have video4linux enabled in the kernel as a module.

A basic compile command line:
# gcc -c -O2 -Wall v4l2cap.c

Add the driver you want to the Makefile in drivers/char to the
"M_OBJS :=" line, for example "M_OBJS := v4l2cap.o". Then make
modules.

# cd /usr/src/linux
# make modules; make modules_install
# depmod -a


Assigning Device Minor Numbers

All V4L2 drivers require the device minor numbers to be assigned on the
module command line. The parameter depends on the type of device. The
only requirements for the minor numbers is they must be between 0 and 255,
and they must all be unique. The sample drivers create two devices each,
so two minor numbers should be given. Examples:

# insmod v4l2cap.o unit_video=0,1
# insmod v4l2out.o unit_vout=16,17

Make sure videodev.o is installed first. If you are using kernel module
loading, the lines you should add to the /etc/conf.modules file for the
above example would be:

options v4l2cap unit_video=0,1
options v4l2out unit_vout=16,17
alias char-major-81 videodev
alias char-major-81-0 v4l2cap
alias char-major-81-1 v4l2cap
alias char-major-81-16 v4l2cap
alias char-major-81-17 v4l2cap

You can get a list of installed V4L2 devices with the command:

# cat /proc/videodev


Making Device Nodes

You need to create entries in the /dev tree to make the devices accessible
to applications. The major device number is 81. The device node name is
up to you, but the conventions are:
Capture devices:    /dev/video%d
Output devices:     /dev/vout%d
Here are some example command lines to create the device nodes:

# mknod /dev/video0 c 81 0
# mknod /dev/video1 c 81 1
# mknod /dev/vout0 c 81 16
# mknod /dev/vout1 c 81 17


Bill.
