Re: [PATCH v2 1/2] gspca: sn9c2028: Add support for Genius Videocam Live v2

2015-05-20 Thread Vasily Khoruzhick
Hi Mauro,

On Wed, May 20, 2015 at 3:12 PM, Mauro Carvalho Chehab
mche...@osg.samsung.com wrote:
 Em Fri, 24 Apr 2015 10:04:03 +0300
 Vasily Khoruzhick anars...@gmail.com escreveu:
 diff --git a/drivers/media/usb/gspca/sn9c2028.c 
 b/drivers/media/usb/gspca/sn9c2028.c
 index 39b6b2e..317b02c 100644
 --- a/drivers/media/usb/gspca/sn9c2028.c
 +++ b/drivers/media/usb/gspca/sn9c2028.c
 @@ -2,6 +2,7 @@
   * SN9C2028 library
   *
   * Copyright (C) 2009 Theodore Kilgore kilg...@auburn.edu
 + * Copyright (C) 2015 Vasily Khoruzhick anars...@gmail.com

 Hmm... adding a new copyright driver-wide only justifies if you changed 30%
 or more of the code. The copyright of your changes will be preserved at
 the git history.

OK, not a problem.

Regards,
Vasily
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/2] gspca: sn9c2028: Add support for Genius Videocam Live v2

2015-05-15 Thread Vasily Khoruzhick
Ping?

On Fri, Apr 24, 2015 at 10:04 AM, Vasily Khoruzhick anars...@gmail.com wrote:
 This cam seems to return different values on long commands, so make status 
 check
 in sn9c2028_long_command() more tolerant. Anyway, read value isn't used 
 anywhere
 later.

 Signed-off-by: Vasily Khoruzhick anars...@gmail.com
 ---
 v2: update commit message to explain change in sn9c2028_long_command()

  drivers/media/usb/gspca/sn9c2028.c | 120 
 -
  1 file changed, 119 insertions(+), 1 deletion(-)

 diff --git a/drivers/media/usb/gspca/sn9c2028.c 
 b/drivers/media/usb/gspca/sn9c2028.c
 index 39b6b2e..317b02c 100644
 --- a/drivers/media/usb/gspca/sn9c2028.c
 +++ b/drivers/media/usb/gspca/sn9c2028.c
 @@ -2,6 +2,7 @@
   * SN9C2028 library
   *
   * Copyright (C) 2009 Theodore Kilgore kilg...@auburn.edu
 + * Copyright (C) 2015 Vasily Khoruzhick anars...@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
 @@ -128,7 +129,7 @@ static int sn9c2028_long_command(struct gspca_dev 
 *gspca_dev, u8 *command)
 status = -1;
 for (i = 0; i  256  status  2; i++)
 status = sn9c2028_read1(gspca_dev);
 -   if (status != 2) {
 +   if (status  0) {
 pr_err(long command status read error %d\n, status);
 return (status  0) ? status : -EIO;
 }
 @@ -178,6 +179,9 @@ static int sd_config(struct gspca_dev *gspca_dev,
 case 0x7005:
 PDEBUG(D_PROBE, Genius Smart 300 camera);
 break;
 +   case 0x7003:
 +   PDEBUG(D_PROBE, Genius Videocam Live v2);
 +   break;
 case 0x8000:
 PDEBUG(D_PROBE, DC31VC);
 break;
 @@ -530,6 +534,116 @@ static int start_genius_cam(struct gspca_dev *gspca_dev)
   ARRAY_SIZE(genius_start_commands));
  }

 +static int start_genius_videocam_live(struct gspca_dev *gspca_dev)
 +{
 +   int r;
 +   struct sd *sd = (struct sd *) gspca_dev;
 +   struct init_command genius_vcam_live_start_commands[] = {
 +   {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 0},
 +   {{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
 +   {{0x10, 0x00, 0x00, 0x00, 0x00, 0x00}, 4},
 +   {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
 +   {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
 +
 +   {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
 +   {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
 +   {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
 +   {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
 +   {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
 +   {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
 +   {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
 +   {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4},
 +   {{0x1c, 0x20, 0x00, 0x2d, 0x00, 0x00}, 4},
 +   {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
 +   {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
 +   {{0x13, 0x22, 0x01, 0x00, 0x00, 0x00}, 4},
 +   {{0x13, 0x23, 0x01, 0x01, 0x00, 0x00}, 4},
 +   {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
 +   {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
 +   {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
 +   {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
 +   {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
 +   {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
 +   {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
 +   {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
 +   {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
 +   {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
 +   {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
 +   {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
 +   {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
 +   {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
 +   {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x01, 0x04, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x02, 0x92, 0x00, 0x00, 0x00}, 4},
 +   {{0x11, 0x10, 0x00, 0x00, 0x00

Re: [PATCH v2 1/2] gspca: sn9c2028: Add support for Genius Videocam Live v2

2015-05-15 Thread Vasily Khoruzhick
Hi Hans,

On Fri, May 15, 2015 at 8:51 PM, Hans de Goede hdego...@redhat.com wrote:
 Sorry for being a bit slow on this one, v2 looks good. I'll queue it up for
 merging into 4.2 as soon as I find some time to work on this,

Thanks!

Regards,
Vasily
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/2] gspca: sn9c2028: Add support for Genius Videocam Live v2

2015-04-24 Thread Vasily Khoruzhick
This cam seems to return different values on long commands, so make status check
in sn9c2028_long_command() more tolerant. Anyway, read value isn't used anywhere
later.

Signed-off-by: Vasily Khoruzhick anars...@gmail.com
---
v2: update commit message to explain change in sn9c2028_long_command()

 drivers/media/usb/gspca/sn9c2028.c | 120 -
 1 file changed, 119 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/gspca/sn9c2028.c 
b/drivers/media/usb/gspca/sn9c2028.c
index 39b6b2e..317b02c 100644
--- a/drivers/media/usb/gspca/sn9c2028.c
+++ b/drivers/media/usb/gspca/sn9c2028.c
@@ -2,6 +2,7 @@
  * SN9C2028 library
  *
  * Copyright (C) 2009 Theodore Kilgore kilg...@auburn.edu
+ * Copyright (C) 2015 Vasily Khoruzhick anars...@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
@@ -128,7 +129,7 @@ static int sn9c2028_long_command(struct gspca_dev 
*gspca_dev, u8 *command)
status = -1;
for (i = 0; i  256  status  2; i++)
status = sn9c2028_read1(gspca_dev);
-   if (status != 2) {
+   if (status  0) {
pr_err(long command status read error %d\n, status);
return (status  0) ? status : -EIO;
}
@@ -178,6 +179,9 @@ static int sd_config(struct gspca_dev *gspca_dev,
case 0x7005:
PDEBUG(D_PROBE, Genius Smart 300 camera);
break;
+   case 0x7003:
+   PDEBUG(D_PROBE, Genius Videocam Live v2);
+   break;
case 0x8000:
PDEBUG(D_PROBE, DC31VC);
break;
@@ -530,6 +534,116 @@ static int start_genius_cam(struct gspca_dev *gspca_dev)
  ARRAY_SIZE(genius_start_commands));
 }
 
+static int start_genius_videocam_live(struct gspca_dev *gspca_dev)
+{
+   int r;
+   struct sd *sd = (struct sd *) gspca_dev;
+   struct init_command genius_vcam_live_start_commands[] = {
+   {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 0},
+   {{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x10, 0x00, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
+   {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
+
+   {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
+   {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
+   {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
+   {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
+   {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
+   {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
+   {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
+   {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4},
+   {{0x1c, 0x20, 0x00, 0x2d, 0x00, 0x00}, 4},
+   {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x22, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x23, 0x01, 0x01, 0x00, 0x00}, 4},
+   {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
+   {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
+   {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
+   {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
+   {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
+   {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
+   {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
+   {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
+   {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
+   {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
+   {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x01, 0x04, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x02, 0x92, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4

Re: [PATCH 2/2] gspca: sn9c2028: Add gain and autogain controls Genius Videocam Live v2

2015-04-21 Thread Vasily Khoruzhick
Hi Hans,

On Tue, Apr 21, 2015 at 5:32 PM, Hans de Goede hdego...@redhat.com wrote:

 diff --git a/drivers/media/usb/gspca/sn9c2028.h
 b/drivers/media/usb/gspca/sn9c2028.h
 index 8fd1d3e..6f20c0f 100644
 --- a/drivers/media/usb/gspca/sn9c2028.h
 +++ b/drivers/media/usb/gspca/sn9c2028.h
 @@ -21,8 +21,17 @@
*
*/

 -static const unsigned char sn9c2028_sof_marker[5] =
 -   { 0xff, 0xff, 0x00, 0xc4, 0xc4 };
 +static const unsigned char sn9c2028_sof_marker[] = {
 +   0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96,
 +   0x00,
 +   0x00, /* seq */
 +   0x00,
 +   0x00,
 +   0x00, /* avg luminance lower 8 bit */
 +   0x00, /* avg luminance higher 8 bit */
 +   0x00,
 +   0x00,
 +};


 This seems wrong, the header is only 12 bytes the extra 2 0x00 bytes you add
 are
 actually part of the compressed data and are parsed by the userspace code,
 please drop them.

OK, I've found average lumimance value in header heuristically,
based on info that it's present in header of sn9c1xx and sn9c201 cams,
and I didn't check actual header length - my fault.

Regards,
Vasily
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] gspca: sn9c2028: Add support for Genius Videocam Live v2

2015-04-21 Thread Vasily Khoruzhick
Hi Hans,

On Tue, Apr 21, 2015 at 5:21 PM, Hans de Goede hdego...@redhat.com wrote:
 @@ -128,7 +129,7 @@ static int sn9c2028_long_command(struct gspca_dev
 *gspca_dev, u8 *command)
 status = -1;
 for (i = 0; i  256  status  2; i++)
 status = sn9c2028_read1(gspca_dev);
 -   if (status != 2) {
 +   if (status  0) {
 pr_err(long command status read error %d\n, status);
 return (status  0) ? status : -EIO;
 }


 Do you really need this change ? sn9c2028_read1 returns either a negative
 error code, or the byte read from the sn9c2028 chip. This functions wait for
 the sn9c2028 to return a read value of 2. I admit that the check in the for
 vs the check in the error reporting is not chosen well, both should probably
 be != 2. But checking for status  0 is not good as this does not catch
 a successful read from the chip not returning 2.

For this cam it returns 1 on some commands. Anyway, this value is not
used anywhere later, so I just extended condition.

Regards,
Vasily
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] gspca: sn9c2028: Add support for Genius Videocam Live v2

2015-04-19 Thread Vasily Khoruzhick
Signed-off-by: Vasily Khoruzhick anars...@gmail.com
---
 drivers/media/usb/gspca/sn9c2028.c | 120 -
 1 file changed, 119 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/gspca/sn9c2028.c 
b/drivers/media/usb/gspca/sn9c2028.c
index 39b6b2e..317b02c 100644
--- a/drivers/media/usb/gspca/sn9c2028.c
+++ b/drivers/media/usb/gspca/sn9c2028.c
@@ -2,6 +2,7 @@
  * SN9C2028 library
  *
  * Copyright (C) 2009 Theodore Kilgore kilg...@auburn.edu
+ * Copyright (C) 2015 Vasily Khoruzhick anars...@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
@@ -128,7 +129,7 @@ static int sn9c2028_long_command(struct gspca_dev 
*gspca_dev, u8 *command)
status = -1;
for (i = 0; i  256  status  2; i++)
status = sn9c2028_read1(gspca_dev);
-   if (status != 2) {
+   if (status  0) {
pr_err(long command status read error %d\n, status);
return (status  0) ? status : -EIO;
}
@@ -178,6 +179,9 @@ static int sd_config(struct gspca_dev *gspca_dev,
case 0x7005:
PDEBUG(D_PROBE, Genius Smart 300 camera);
break;
+   case 0x7003:
+   PDEBUG(D_PROBE, Genius Videocam Live v2);
+   break;
case 0x8000:
PDEBUG(D_PROBE, DC31VC);
break;
@@ -530,6 +534,116 @@ static int start_genius_cam(struct gspca_dev *gspca_dev)
  ARRAY_SIZE(genius_start_commands));
 }
 
+static int start_genius_videocam_live(struct gspca_dev *gspca_dev)
+{
+   int r;
+   struct sd *sd = (struct sd *) gspca_dev;
+   struct init_command genius_vcam_live_start_commands[] = {
+   {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 0},
+   {{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x10, 0x00, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
+   {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
+
+   {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
+   {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
+   {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
+   {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
+   {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
+   {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
+   {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
+   {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4},
+   {{0x1c, 0x20, 0x00, 0x2d, 0x00, 0x00}, 4},
+   {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x22, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x23, 0x01, 0x01, 0x00, 0x00}, 4},
+   {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
+   {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
+   {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
+   {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
+   {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
+   {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
+   {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
+   {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
+   {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
+   {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
+   {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x01, 0x04, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x02, 0x92, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
+   {{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4

[PATCH 2/2] gspca: sn9c2028: Add gain and autogain controls Genius Videocam Live v2

2015-04-19 Thread Vasily Khoruzhick
Autogain algorithm is very simple, if average luminance is low - increase gain,
if it's high - decrease gain. Gain granularity is low enough for this algo to
stabilize quickly.

Signed-off-by: Vasily Khoruzhick anars...@gmail.com
---
 drivers/media/usb/gspca/sn9c2028.c | 121 +
 drivers/media/usb/gspca/sn9c2028.h |  20 +-
 2 files changed, 138 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/gspca/sn9c2028.c 
b/drivers/media/usb/gspca/sn9c2028.c
index 317b02c..0ff390f 100644
--- a/drivers/media/usb/gspca/sn9c2028.c
+++ b/drivers/media/usb/gspca/sn9c2028.c
@@ -34,6 +34,16 @@ struct sd {
struct gspca_dev gspca_dev;  /* !! must be the first item */
u8 sof_read;
u16 model;
+
+#define MIN_AVG_LUM 8500
+#define MAX_AVG_LUM 1
+   int avg_lum;
+   u8 avg_lum_l;
+
+   struct { /* autogain and gain control cluster */
+   struct v4l2_ctrl *autogain;
+   struct v4l2_ctrl *gain;
+   };
 };
 
 struct init_command {
@@ -252,6 +262,77 @@ static int run_start_commands(struct gspca_dev *gspca_dev,
return 0;
 }
 
+static void set_gain(struct gspca_dev *gspca_dev, s32 g)
+{
+   struct sd *sd = (struct sd *) gspca_dev;
+
+   struct init_command genius_vcam_live_gain_cmds[] = {
+   {{0x1d, 0x25, 0x10, 0x20, 0xab, 0x00}, 0},
+   };
+   if (!gspca_dev-streaming)
+   return;
+
+   switch (sd-model) {
+   case 0x7003:
+   genius_vcam_live_gain_cmds[0].instruction[2] = g;
+   run_start_commands(gspca_dev, genius_vcam_live_gain_cmds,
+  ARRAY_SIZE(genius_vcam_live_gain_cmds));
+   break;
+   default:
+   break;
+   }
+}
+
+static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct gspca_dev *gspca_dev =
+   container_of(ctrl-handler, struct gspca_dev, ctrl_handler);
+   struct sd *sd = (struct sd *)gspca_dev;
+
+   gspca_dev-usb_err = 0;
+
+   if (!gspca_dev-streaming)
+   return 0;
+
+   switch (ctrl-id) {
+   /* standalone gain control */
+   case V4L2_CID_GAIN:
+   set_gain(gspca_dev, ctrl-val);
+   break;
+   /* autogain */
+   case V4L2_CID_AUTOGAIN:
+   set_gain(gspca_dev, sd-gain-val);
+   break;
+   }
+   return gspca_dev-usb_err;
+}
+
+static const struct v4l2_ctrl_ops sd_ctrl_ops = {
+   .s_ctrl = sd_s_ctrl,
+};
+
+
+static int sd_init_controls(struct gspca_dev *gspca_dev)
+{
+   struct v4l2_ctrl_handler *hdl = gspca_dev-ctrl_handler;
+   struct sd *sd = (struct sd *)gspca_dev;
+
+   gspca_dev-vdev.ctrl_handler = hdl;
+   v4l2_ctrl_handler_init(hdl, 2);
+
+   switch (sd-model) {
+   case 0x7003:
+   sd-gain = v4l2_ctrl_new_std(hdl, sd_ctrl_ops,
+   V4L2_CID_GAIN, 0, 20, 1, 0);
+   sd-autogain = v4l2_ctrl_new_std(hdl, sd_ctrl_ops,
+   V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
+   break;
+   default:
+   break;
+   }
+
+   return 0;
+}
 static int start_spy_cam(struct gspca_dev *gspca_dev)
 {
struct init_command spy_start_commands[] = {
@@ -641,6 +722,9 @@ static int start_genius_videocam_live(struct gspca_dev 
*gspca_dev)
if (r  0)
return r;
 
+   if (sd-gain)
+   set_gain(gspca_dev, v4l2_ctrl_g_ctrl(sd-gain));
+
return r;
 }
 
@@ -757,6 +841,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
return -ENXIO;
}
 
+   sd-avg_lum = -1;
+
return err_code;
 }
 
@@ -776,6 +862,39 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
PERR(Camera Stop command failed);
 }
 
+static void do_autogain(struct gspca_dev *gspca_dev, int avg_lum)
+{
+   struct sd *sd = (struct sd *) gspca_dev;
+   s32 cur_gain = v4l2_ctrl_g_ctrl(sd-gain);
+
+   if (avg_lum == -1)
+   return;
+
+   if (avg_lum  MIN_AVG_LUM) {
+   if (cur_gain == sd-gain-maximum)
+   return;
+   cur_gain++;
+   v4l2_ctrl_s_ctrl(sd-gain, cur_gain);
+   }
+   if (avg_lum  MAX_AVG_LUM) {
+   if (cur_gain == sd-gain-minimum)
+   return;
+   cur_gain--;
+   v4l2_ctrl_s_ctrl(sd-gain, cur_gain);
+   }
+
+}
+
+static void sd_dqcallback(struct gspca_dev *gspca_dev)
+{
+   struct sd *sd = (struct sd *) gspca_dev;
+
+   if (sd-autogain == NULL || !v4l2_ctrl_g_ctrl(sd-autogain))
+   return;
+
+   do_autogain(gspca_dev, sd-avg_lum);
+}
+
 /* Include sn9c2028 sof detection functions */
 #include sn9c2028.h
 
@@ -810,8 +929,10 @@ static const struct sd_desc sd_desc = {
.name = MODULE_NAME,
.config = sd_config,
.init = sd_init,
+   .init_controls = sd_init_controls,
.start = sd_start

Re: [PATCH] libv4l: add hflip quirk for dealextreme cam sku #44507

2012-01-03 Thread Vasily
2012/1/3 Hans de Goede hdego...@redhat.com:
 Hi,


 Thanks for the patch.

 I'm sorry, but a quick google shows that your cam has a usb id used by
 various generic
 cameras, including some microscopes, see:
 http://blog.littleimpact.de/index.php/2011/10/16/using-biolux-nv-on-ubuntu-linux/

 Enabling flipping on all these models because one has the sensor mounted
 upside down
 is the wrong thing to do.

 Instead you could add the following to your /etc/profile
 export LIBV4LCONTROL_FLAGS=3

 Note this will flip the image from all cameras you plug into your computer,
 or you
 can keep a patched libv4l around for yourself.

Thanks, I'm OK with it :)

 Regards,

 Hans
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] libv4l: add hflip quirk for dealextreme cam sku #44507

2012-01-02 Thread Vasily Khoruzhick
Signed-off-by: Vasily Khoruzhick anars...@gmail.com
---
 lib/libv4lconvert/control/libv4lcontrol.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lib/libv4lconvert/control/libv4lcontrol.c 
b/lib/libv4lconvert/control/libv4lcontrol.c
index 12fa874..a9908ac 100644
--- a/lib/libv4lconvert/control/libv4lcontrol.c
+++ b/lib/libv4lconvert/control/libv4lcontrol.c
@@ -51,6 +51,8 @@ static const struct v4lcontrol_flags_info v4lcontrol_flags[] 
= {
/* Genius E-M 112 (also want whitebalance by default) */
{ 0x093a, 0x2476, 0, NULL, NULL,
V4LCONTROL_HFLIPPED|V4LCONTROL_VFLIPPED | V4LCONTROL_WANTS_WB, 
1500 },
+   /* uvc-compatible cam from dealextreme (sku #44507) */
+   { 0x18ec, 0x3366, 0, NULL, NULL, V4LCONTROL_HFLIPPED },
 
/* Laptops (and all in one PC's) */
{ 0x0402, 0x5606, 0,
-- 
1.7.8.1

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[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

Re: [REVIEW] v4l2 loopback

2009-05-06 Thread Vasily
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. Initialy 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-04-25 
04:41:20.0 +0300
+++ v4l-dvb.my/linux/drivers/media/video/Kconfig2009-05-07 
01:49:38.0 +0300
@@ -479,6 +479,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 it's user to present any userspace
+ video as a v4l2 device that can be handy for tesring purpose,
+ or for fixing bugs like upside down image, or for adding
+ nice effects to videochats
+ 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-07 
01:31:32.0 +0300
+++ v4l-dvb.my/linux/drivers/media/video/Makefile   2009-05-07 
01:50:11.0 +0300
@@ -132,6 +132,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-07 
02:30:08.0 +0300
@@ -0,0 +1,775 @@
+/*
+ * 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 media/v4l2-ioctl.h
+#include linux/videodev2.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 = 0;
+module_param(debug, int, 0);
+MODULE_PARM_DESC(debug,if debug output is enabled, values are 0, 1 or 2);
+
+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 MAX_MMAP_BUFFERS 100 /* max buffers that can be mmaped, actuale

[REVIEW] v4l2 loopback

2009-03-26 Thread Vasily
Hello, please review the new version of v4l2 loopback driver.
I fixed up comments to the previous submission, waiting for the new ones :-),
reposting for patchwork tool

---
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. Initialy 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-03-21 
07:08:06.0 +0200
+++ v4l-dvb.my/linux/drivers/media/video/Kconfig2009-03-25 
23:36:13.0 +0200
@@ -465,6 +465,13 @@ 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.
+ This driver can be compiled as a module, called v4l2loopback.
+
 source drivers/media/video/bt8xx/Kconfig
 
 config VIDEO_SAA6588
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-03-21 
07:08:06.0 +0200
+++ v4l-dvb.my/linux/drivers/media/video/Makefile   2009-03-24 
12:54:59.0 +0200
@@ -132,6 +132,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_MX3)+= mx3_camera.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-03-25 
23:01:35.0 +0200
@@ -0,0 +1,725 @@
+/*
+ *  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 media/v4l2-ioctl.h
+#include v4l2loopback.h
+
+/* #define DEBUG 
+#define DEBUG_RW */
+#define YAVLD_STREAMING
+
+#ifdef DEBUG
+#define dprintk(fmt, args...)\
+   do {\
+   printk(KERN_INFO v4l2-loopback:  fmt, ##args);\
+   } while (0)
+#else
+#define dprintk(fmt, args...)
+#endif
+
+#ifdef DEBUG_RW
+#define dprintkrw(fmt, args...)\
+   do {\
+   printk(KERN_INFO v4l2-loopback:  fmt, ##args);\
+   } while (0)
+#else
+#define dprintkrw(fmt, args...)
+#endif
+
+/* global module data */
+struct v4l2_loopback_device *dev;
+/* forward declarations */
+static void init_buffers(int buffer_size);
+static const struct v4l2_file_operations v4l2_loopback_fops;
+static const struct v4l2_ioctl_ops v4l2_loopback_ioctl_ops;
+/
+ my queue helpers ***
+/
+/* next functions sets buffer flags and adjusts counters accordingly */
+static void set_done(struct v4l2_buffer *buffer)
+{
+   buffer-flags |= V4L2_BUF_FLAG_DONE;
+   buffer-flags = ~V4L2_BUF_FLAG_QUEUED;
+}
+
+static void set_queued(struct v4l2_buffer *buffer)
+{
+   buffer-flags |= V4L2_BUF_FLAG_QUEUED;
+   buffer-flags = ~V4L2_BUF_FLAG_DONE;
+}
+
+static void unset_all(struct v4l2_buffer *buffer)
+{
+   buffer-flags = ~V4L2_BUF_FLAG_QUEUED;
+   buffer-flags = ~V4L2_BUF_FLAG_DONE;
+}
+/
+ V4L2 ioctl caps and params calls ***
+/
+/**/
+/* returns device capabilities, called on VIDIOC_QUERYCAP ioctl*/
+static int vidioc_querycap(struct file *file,
+  void *priv, struct v4l2_capability *cap)
+{
+   strcpy(cap-driver, v4l2 loopback);
+   strcpy(cap-card, Dummy video device);
+   cap-version = 1;
+   cap-capabilities =
+   V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT |
+   V4L2_CAP_READWRITE
+#ifdef YAVLD_STREAMING
+   | V4L2_CAP_STREAMING
+#endif