diff -r 127f67dea087 linux/drivers/media/video/vivi.c --- a/linux/drivers/media/video/vivi.c Tue Feb 26 20:43:56 2008 +0000 +++ b/linux/drivers/media/video/vivi.c Sun Mar 02 17:00:24 2008 -0600 @@ -48,6 +48,8 @@ #include #endif +#define MODULE_NAME "vivi" + /* Wake up at about 30 fps */ #define WAKE_NUMERATOR 30 #define WAKE_DENOMINATOR 1001 @@ -56,7 +58,7 @@ #include "font.h" #define VIVI_MAJOR_VERSION 0 -#define VIVI_MINOR_VERSION 4 +#define VIVI_MINOR_VERSION 5 #define VIVI_RELEASE 0 #define VIVI_VERSION \ KERNEL_VERSION(VIVI_MAJOR_VERSION, VIVI_MINOR_VERSION, VIVI_RELEASE) @@ -1220,10 +1222,14 @@ static int vivi_release(void) list_del(list); dev = list_entry(list, struct vivi_dev, vivi_devlist); - if (-1 != dev->vfd->minor) + if (-1 != dev->vfd->minor) { video_unregister_device(dev->vfd); - else + printk(KERN_INFO "%s: /dev/video%d unregistered.\n", MODULE_NAME, dev->vfd->minor); + } + else { video_device_release(dev->vfd); + printk(KERN_INFO "%s: /dev/video%d released.\n", MODULE_NAME, dev->vfd->minor); + } kfree(dev); } @@ -1338,6 +1344,7 @@ static int __init vivi_init(void) video_nr++; dev->vfd = vfd; + printk(KERN_INFO "%s: V4L2 device registered as /dev/video%d\n", MODULE_NAME, vfd->minor); } if (ret < 0) { @@ -1345,7 +1352,8 @@ static int __init vivi_init(void) printk(KERN_INFO "Error %d while loading vivi driver\n", ret); } else printk(KERN_INFO "Video Technology Magazine Virtual Video " - "Capture Board successfully loaded.\n"); + "Capture Board ver %u.%u.%u successfully loaded.\n", + (VIVI_VERSION >> 16) & 0xFF, (VIVI_VERSION >> 8) & 0xFF, VIVI_VERSION & 0xFF); return ret; } diff -r 127f67dea087 v4l2-apps/lib/v4l2_driver.h --- a/v4l2-apps/lib/v4l2_driver.h Tue Feb 26 20:43:56 2008 +0000 +++ b/v4l2-apps/lib/v4l2_driver.h Sun Mar 02 17:00:24 2008 -0600 @@ -12,6 +12,7 @@ Lesser General Public License for more details. */ +#include #include #include #include diff -r 127f67dea087 v4l2-apps/test/Makefile --- a/v4l2-apps/test/Makefile Tue Feb 26 20:43:56 2008 +0000 +++ b/v4l2-apps/test/Makefile Sun Mar 02 17:00:24 2008 -0600 @@ -25,6 +25,8 @@ install: driver-test: driver-test.o ../lib/libv4l2.a +ioctl-test: ioctl-test.o ../lib/libv4l2.a + pixfmt-test: pixfmt-test.o $(CC) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ -lX11 diff -r 127f67dea087 v4l2-apps/test/ioctl-test.c --- a/v4l2-apps/test/ioctl-test.c Tue Feb 26 20:43:56 2008 +0000 +++ b/v4l2-apps/test/ioctl-test.c Sun Mar 02 17:00:24 2008 -0600 @@ -29,14 +29,23 @@ */ //#define INTERNAL 1 /* meant for testing ioctl debug msgs */ +#include +#include #include #include +#include #include #include #include #include +#include + +#include /* getopt_long() */ + #include -#include "linux/videodev.h" +#include + +#include #ifdef INTERNAL typedef __u8 u8; @@ -47,6 +56,24 @@ typedef __u32 u32; #else typedef u_int32_t u32; #endif + +static const char * my_name; +#define VERSION "1.1" +static const char * dev_name = "/dev/video0"; + +#define CLEAR(var) memset (&(var), 0, sizeof (var)) + +typedef enum { + IO_METHOD_READ = 1, + IO_METHOD_MMAP, +} io_methods; + + +static int fd; +static v4l2_std_id std_id; +static io_methods io_method; +static struct v4l2_format fmt; +static unsigned int n_buffers; /* All possible parameters used on v4l ioctls */ union v4l_parms { @@ -209,26 +236,253 @@ int ioctls[] = { #define S_IOCTLS sizeof(ioctls)/sizeof(ioctls[0]) /********************************************************************/ +static int +xioctl (int fd, + int request, + void * arg) +{ + int r; -int main (void) + do r = ioctl (fd, request, arg); + while (-1 == r && EINTR == errno); + + return r; +} + +/********************************************************************/ +static void +error_exit (const char * templ, + ...) { - int fd=0, ret=0; + va_list ap; + + fprintf (stderr, "%s: ", my_name); + va_start (ap, templ); + vfprintf (stderr, templ, ap); + va_end (ap); + + exit (EXIT_FAILURE); +} + +/********************************************************************/ +static void +errno_exit (const char * s) +{ + error_exit ("%s error %d, %s\n", + s, errno, strerror (errno)); +} + + +/********************************************************************/ +static void +open_device (void) +{ + struct stat st; + + if (-1 == stat (dev_name, &st)) { + error_exit ("Cannot identify '%s'. %s.\n", + dev_name, strerror (errno)); + } + + if (!S_ISCHR (st.st_mode)) { + error_exit ("%s is not a device file.\n", dev_name); + } + + fd = open (dev_name, O_RDWR /* required */ | O_NONBLOCK, 0); + + if (-1 == fd) { + error_exit ("Cannot open %s. %s.\n", + dev_name, strerror (errno)); + } +} + +/********************************************************************/ +static void +printstat (struct v4l2_capability cap) +{ + printf ("driver=%s\n" "card=%s\n" "bus=%s\n" "version=%d.%d.%d\n" + "capabilities=%s\n", + cap.driver,cap.card,cap.bus_info, + (cap.version >> 16) & 0xff, + (cap.version >> 8) & 0xff, + cap.version & 0xff, + prt_caps(cap.capabilities)); +} + +/********************************************************************/ + +static void +init_device (void) +{ + struct v4l2_capability cap; + struct v4l2_cropcap cropcap; + struct v4l2_crop crop; + + if (-1 == xioctl (fd, VIDIOC_QUERYCAP, &cap)) { + if (EINVAL == errno) { + error_exit ("%s is not a V4L2 device.\n"); + } else { + errno_exit ("VIDIOC_QUERYCAP"); + } + } + + printstat(cap); + + switch (io_method) { + case 0: + if (cap.capabilities & V4L2_CAP_STREAMING) { + io_method = IO_METHOD_MMAP; + } else if (cap.capabilities & V4L2_CAP_READWRITE) { + io_method = IO_METHOD_READ; + } else { + error_exit ("%s does not support reading or " + "streaming.\n"); + } + + break; + + case IO_METHOD_READ: + if (0 == (cap.capabilities & V4L2_CAP_READWRITE)) { + error_exit ("%s does not support read i/o.\n"); + } + + break; + + case IO_METHOD_MMAP: + if (0 == (cap.capabilities & V4L2_CAP_STREAMING)) { + error_exit ("%s does not support streaming i/o.\n"); + } + + break; + + default: + assert (0); + break; + } + + CLEAR (cropcap); + + cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + + if (0 == xioctl (fd, VIDIOC_CROPCAP, &cropcap)) { + crop.type = cropcap.type; + crop.c = cropcap.defrect; /* reset to default */ + + /* Errors ignored. */ + xioctl (fd, VIDIOC_S_CROP, &crop); + } else { + /* Errors ignored. */ + } + + if (-1 == xioctl (fd, VIDIOC_G_STD, &std_id)) + errno_exit ("VIDIOC_G_STD"); +} + + +/********************************************************************/ +static void +mainloop (void) +{ + + int ret=0; unsigned i; - char *device="/dev/video0"; union v4l_parms p; - if ((fd = open(device, O_RDONLY)) < 0) { - perror("Couldn't open video0"); - return(-1); - } for (i=0;i