[REVIEW v4] v4l2 loopback

2009-05-17 Thread Vasily Levin
In this patch revision fixed complains from checkpatch.pl
spell check of comments done
---
This patch introduces v4l2 loopback module

From: Vasily Levin vas...@gmail.com

This is v4l2 loopback driver which can be used to make available any userspace
video as v4l2 device. Initially it was written to make videoeffects available
to Skype, but in fact it have many more uses.

Priority: normal

Signed-off-by: Vasily Levin vas...@gmail.com

diff -uprN v4l-dvb.orig/linux/drivers/media/video/Kconfig v4l-
dvb.my/linux/drivers/media/video/Kconfig
--- v4l-dvb.orig/linux/drivers/media/video/Kconfig  2009-05-17 
22:39:41.0 
+0300
+++ v4l-dvb.my/linux/drivers/media/video/Kconfig2009-05-17 
22:41:22.0 
+0300
@@ -497,6 +497,17 @@ config VIDEO_VIVI
  Say Y here if you want to test video apps or debug V4L devices.
  In doubt, say N.
 
+config VIDEO_V4L2_LOOPBACK
+   tristate v4l2 loopback driver
+   depends on VIDEO_V4L2  VIDEO_DEV
+   help
+ Say Y if you want to use v4l2 loopback driver.
+ Looback driver allows its user to present any userspace
+ video as a v4l2 device that can be handy for testing purpose,
+ or for fixing bugs like upside down image, or for adding
+ nice effects to video chats
+ This driver can be compiled as a module, called v4l2loopback.
+
 source drivers/media/video/bt8xx/Kconfig
 
 config VIDEO_PMS
diff -uprN v4l-dvb.orig/linux/drivers/media/video/Makefile v4l-
dvb.my/linux/drivers/media/video/Makefile
--- v4l-dvb.orig/linux/drivers/media/video/Makefile 2009-05-17 
22:39:41.0 
+0300
+++ v4l-dvb.my/linux/drivers/media/video/Makefile   2009-05-17 
22:41:22.0 
+0300
@@ -134,6 +134,7 @@ obj-$(CONFIG_VIDEO_IVTV) += ivtv/
 obj-$(CONFIG_VIDEO_CX18) += cx18/
 
 obj-$(CONFIG_VIDEO_VIVI) += vivi.o
+obj-$(CONFIG_VIDEO_V4L2_LOOPBACK) += v4l2loopback.o
 obj-$(CONFIG_VIDEO_CX23885) += cx23885/
 
 obj-$(CONFIG_VIDEO_OMAP2)  += omap2cam.o
diff -uprN v4l-dvb.orig/linux/drivers/media/video/v4l2loopback.c v4l-
dvb.my/linux/drivers/media/video/v4l2loopback.c
--- v4l-dvb.orig/linux/drivers/media/video/v4l2loopback.c   1970-01-01 
03:00:00.0 +0300
+++ v4l-dvb.my/linux/drivers/media/video/v4l2loopback.c 2009-05-17 
23:41:07.0 +0300
@@ -0,0 +1,774 @@
+/*
+ * v4l2loopback.c  --  video 4 linux loopback driver
+ *
+ * Copyright (C) 2005-2009
+ * Vasily Levin (vas...@gmail.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+#include linux/version.h
+#include linux/vmalloc.h
+#include linux/mm.h
+#include linux/time.h
+#include linux/module.h
+#include linux/videodev2.h
+#include media/v4l2-ioctl.h
+#include media/v4l2-common.h
+
+#define YAVLD_STREAMING
+
+MODULE_DESCRIPTION(V4L2 loopback video device);
+MODULE_VERSION(0.1.1);
+MODULE_AUTHOR(Vasily Levin);
+MODULE_LICENSE(GPL);
+
+/* module structures */
+/* TODO(vasaka) use typenames which are common to kernel, but first find out if
+ * it is needed */
+/* struct keeping state and settings of loopback device */
+struct v4l2_loopback_device {
+   struct video_device *vdev;
+   /* pixel and stream format */
+   struct v4l2_pix_format pix_format;
+   struct v4l2_captureparm capture_param;
+   /* buffers stuff */
+   u8 *image; /* pointer to actual buffers data */
+   int buffers_number;  /* should not be big, 4 is a good choice */
+   struct v4l2_buffer *buffers;/* inner driver buffers */
+   int write_position; /* number of last written frame + 1 */
+   long buffer_size;
+   /* sync stuff */
+   atomic_t open_count;
+   int ready_for_capture;/* set to true when at least one writer opened
+ * device and negotiated format */
+   wait_queue_head_t read_event;
+};
+
+/* types of opener shows what opener wants to do with loopback */
+enum opener_type {
+   UNNEGOTIATED = 0,
+   READER = 1,
+   WRITER = 2,
+};
+
+/* struct keeping state and type of opener */
+struct v4l2_loopback_opener {
+   enum opener_type type;
+   int buffers_number;
+   int position; /* number of last processed frame + 1 or
+  * write_position - 1 if reader went out of sync */
+   struct v4l2_buffer *buffers;
+};
+
+/* module parameters */
+static int debug = 1;
+module_param(debug, int, 0);
+MODULE_PARM_DESC(debug, if debug output is enabled, values are 0, 2 or 3);
+
+static int max_buffers_number = 4;
+module_param(max_buffers_number, int, 0);
+MODULE_PARM_DESC(max_buffers_number, how many buffers should be allocated);
+
+static int max_openers = 10;
+module_param(max_openers, int, 0);
+MODULE_PARM_DESC(max_openers, how many users can open loopback device);
+
+/* module constants */
+#define

[REVIEW v4.1] v4l2 loopback

2009-05-17 Thread Vasily Levin
In this patch revision fixed complains from checkpatch.pl
spell check of comments done

v4 was wrong one
---
This patch introduces v4l2 loopback module

From: Vasily Levin vas...@gmail.com

This is v4l2 loopback driver which can be used to make available any userspace
video as v4l2 device. Initially it was written to make videoeffects available
to Skype, but in fact it have many more uses.

Priority: normal

Signed-off-by: Vasily Levin vas...@gmail.com

diff -uprN v4l-dvb.orig/linux/drivers/media/video/Kconfig 
v4l-dvb.my/linux/drivers/media/video/Kconfig
--- v4l-dvb.orig/linux/drivers/media/video/Kconfig  2009-05-17 
22:39:41.0 +0300
+++ v4l-dvb.my/linux/drivers/media/video/Kconfig2009-05-17 
22:41:22.0 +0300
@@ -497,6 +497,17 @@ config VIDEO_VIVI
  Say Y here if you want to test video apps or debug V4L devices.
  In doubt, say N.
 
+config VIDEO_V4L2_LOOPBACK
+   tristate v4l2 loopback driver
+   depends on VIDEO_V4L2  VIDEO_DEV
+   help
+ Say Y if you want to use v4l2 loopback driver.
+ Looback driver allows its user to present any userspace
+ video as a v4l2 device that can be handy for testing purpose,
+ or for fixing bugs like upside down image, or for adding
+ nice effects to video chats
+ This driver can be compiled as a module, called v4l2loopback.
+
 source drivers/media/video/bt8xx/Kconfig
 
 config VIDEO_PMS
diff -uprN v4l-dvb.orig/linux/drivers/media/video/Makefile 
v4l-dvb.my/linux/drivers/media/video/Makefile
--- v4l-dvb.orig/linux/drivers/media/video/Makefile 2009-05-17 
22:39:41.0 +0300
+++ v4l-dvb.my/linux/drivers/media/video/Makefile   2009-05-17 
22:41:22.0 +0300
@@ -134,6 +134,7 @@ obj-$(CONFIG_VIDEO_IVTV) += ivtv/
 obj-$(CONFIG_VIDEO_CX18) += cx18/
 
 obj-$(CONFIG_VIDEO_VIVI) += vivi.o
+obj-$(CONFIG_VIDEO_V4L2_LOOPBACK) += v4l2loopback.o
 obj-$(CONFIG_VIDEO_CX23885) += cx23885/
 
 obj-$(CONFIG_VIDEO_OMAP2)  += omap2cam.o
diff -uprN v4l-dvb.orig/linux/drivers/media/video/v4l2loopback.c 
v4l-dvb.my/linux/drivers/media/video/v4l2loopback.c
--- v4l-dvb.orig/linux/drivers/media/video/v4l2loopback.c   1970-01-01 
03:00:00.0 +0300
+++ v4l-dvb.my/linux/drivers/media/video/v4l2loopback.c 2009-05-17 
23:41:07.0 +0300
@@ -0,0 +1,774 @@
+/*
+ * v4l2loopback.c  --  video 4 linux loopback driver
+ *
+ * Copyright (C) 2005-2009
+ * Vasily Levin (vas...@gmail.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+#include linux/version.h
+#include linux/vmalloc.h
+#include linux/mm.h
+#include linux/time.h
+#include linux/module.h
+#include linux/videodev2.h
+#include media/v4l2-ioctl.h
+#include media/v4l2-common.h
+
+#define YAVLD_STREAMING
+
+MODULE_DESCRIPTION(V4L2 loopback video device);
+MODULE_VERSION(0.1.1);
+MODULE_AUTHOR(Vasily Levin);
+MODULE_LICENSE(GPL);
+
+/* module structures */
+/* TODO(vasaka) use typenames which are common to kernel, but first find out if
+ * it is needed */
+/* struct keeping state and settings of loopback device */
+struct v4l2_loopback_device {
+   struct video_device *vdev;
+   /* pixel and stream format */
+   struct v4l2_pix_format pix_format;
+   struct v4l2_captureparm capture_param;
+   /* buffers stuff */
+   u8 *image; /* pointer to actual buffers data */
+   int buffers_number;  /* should not be big, 4 is a good choice */
+   struct v4l2_buffer *buffers;/* inner driver buffers */
+   int write_position; /* number of last written frame + 1 */
+   long buffer_size;
+   /* sync stuff */
+   atomic_t open_count;
+   int ready_for_capture;/* set to true when at least one writer opened
+ * device and negotiated format */
+   wait_queue_head_t read_event;
+};
+
+/* types of opener shows what opener wants to do with loopback */
+enum opener_type {
+   UNNEGOTIATED = 0,
+   READER = 1,
+   WRITER = 2,
+};
+
+/* struct keeping state and type of opener */
+struct v4l2_loopback_opener {
+   enum opener_type type;
+   int buffers_number;
+   int position; /* number of last processed frame + 1 or
+  * write_position - 1 if reader went out of sync */
+   struct v4l2_buffer *buffers;
+};
+
+/* module parameters */
+static int debug = 1;
+module_param(debug, int, 0);
+MODULE_PARM_DESC(debug, if debug output is enabled, values are 0, 2 or 3);
+
+static int max_buffers_number = 4;
+module_param(max_buffers_number, int, 0);
+MODULE_PARM_DESC(max_buffers_number, how many buffers should be allocated);
+
+static int max_openers = 10;
+module_param(max_openers, int, 0);
+MODULE_PARM_DESC(max_openers, how many users can open loopback device);
+
+/* module