Re: [PATCH] Implement V4L2_CAP_STREAMING for zr364xx driver

2009-07-02 Thread Lamarque Vieira Souza
Hi all,

I have noticed the patch mentioned in the subject was not included in 
2.6.30. 
Do you plan to add it to 2.6.31?

Em Saturday 28 March 2009, Lamarque Vieira Souza escreveu:
> This patch implements V4L2_CAP_STREAMING for the zr364xx driver, by
> converting the driver to use videobuf.
>
> Tested with Creative PC-CAM 880.
>
> It basically:
> . implements V4L2_CAP_STREAMING using videobuf;
>
> . re-implements V4L2_CAP_READWRITE using videobuf;
>
> . copies cam->udev->product to the card field of the v4l2_capability
> struct. That gives more information to the users about the webcam;
>
> . moves the brightness setting code from before requesting a frame (in
> read_frame) to the vidioc_s_ctrl ioctl. This way the brightness code is
> executed only when the application requests a change in brightness and
> not before every frame read;
>
> . comments part of zr364xx_vidioc_try_fmt_vid_cap that says that Skype +
> libv4l do not work.
>
> This patch fixes zr364xx for applications such as mplayer,
> Kopete+libv4l and Skype+libv4l can make use of the webcam that comes
> with zr364xx chip.
>
> Signed-off-by: Lamarque V. Souza 
> ---
>
> --- v4l-dvb/linux/drivers/media/video/zr364xx.c   2009-03-27
> 15:18:54.050413997 -0300
> +++ v4l-dvb/linux-lvs/drivers/media/video/zr364xx.c   2009-03-27
> 15:22:47.914414277 -0300
... stripped off to not bloat the e-mail.

-- 
Lamarque V. Souza
http://www.geographicguide.com/brazil.htm
Linux User #57137 - http://counter.li.org/
--
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] Implement V4L2_CAP_STREAMING for zr364xx driver

2009-07-11 Thread Lamarque Vieira Souza
Hi guys. Any news about this patch? I really think is important to make 
zr364xx driver works with libv4l, mplayer, kopete and skype. Maintaining this 
patch out of tree is also troublesome for me, I would really appreciate if you 
could add it to the tree. If there is any problem with the patch let me know 
that will fix it.

Em Thursday 02 July 2009, Lamarque Vieira Souza escreveu:
>   Hi all,
>
>   I have noticed the patch mentioned in the subject was not included in
> 2.6.30. Do you plan to add it to 2.6.31?
>
> Em Saturday 28 March 2009, Lamarque Vieira Souza escreveu:
> > This patch implements V4L2_CAP_STREAMING for the zr364xx driver, by
> > converting the driver to use videobuf.
> >
> > Tested with Creative PC-CAM 880.
> >
> > It basically:
> > . implements V4L2_CAP_STREAMING using videobuf;
> >
> > . re-implements V4L2_CAP_READWRITE using videobuf;
> >
> > . copies cam->udev->product to the card field of the v4l2_capability
> > struct. That gives more information to the users about the webcam;
> >
> > . moves the brightness setting code from before requesting a frame (in
> > read_frame) to the vidioc_s_ctrl ioctl. This way the brightness code is
> > executed only when the application requests a change in brightness and
> > not before every frame read;
> >
> > . comments part of zr364xx_vidioc_try_fmt_vid_cap that says that Skype +
> > libv4l do not work.
> >
> > This patch fixes zr364xx for applications such as mplayer,
> > Kopete+libv4l and Skype+libv4l can make use of the webcam that comes
> > with zr364xx chip.
> >
> > Signed-off-by: Lamarque V. Souza 
> > ---
> >
> > --- v4l-dvb/linux/drivers/media/video/zr364xx.c 2009-03-27
> > 15:18:54.050413997 -0300
> > +++ v4l-dvb/linux-lvs/drivers/media/video/zr364xx.c 2009-03-27
> > 15:22:47.914414277 -0300
>
> ... stripped off to not bloat the e-mail.


-- 
Lamarque V. Souza
http://www.geographicguide.com/brazil.htm
Linux User #57137 - http://counter.li.org/
--
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] Implement V4L2_CAP_STREAMING for zr364xx driver

2009-07-15 Thread Lamarque Vieira Souza
This patch implements V4L2_CAP_STREAMING for the zr364xx driver, by
converting the driver to use videobuf. This version is synced with v4l-dvb as 
of 15/Jul/2009.

Tested with Creative PC-CAM 880.

It basically:
. implements V4L2_CAP_STREAMING using videobuf;

. re-implements V4L2_CAP_READWRITE using videobuf;

. copies cam->udev->product to the card field of the v4l2_capability struct.
That gives more information to the users about the webcam;

. moves the brightness setting code from before requesting a frame (in
read_frame) to the vidioc_s_ctrl ioctl. This way the brightness code is
executed only when the application requests a change in brightness and
not before every frame read;

. comments part of zr364xx_vidioc_try_fmt_vid_cap that says that Skype + 
libv4l do not work.

This patch fixes zr364xx for applications such as mplayer,
Kopete+libv4l and Skype+libv4l can make use of the webcam that comes
with zr364xx chip.

Signed-off-by: Lamarque V. Souza 
---

diff -r c300798213a9 linux/drivers/media/video/zr364xx.c
--- a/linux/drivers/media/video/zr364xx.c   Sun Jul 05 19:08:55 2009 -0300
+++ b/linux/drivers/media/video/zr364xx.c   Wed Jul 15 20:50:34 2009 -0300
@@ -1,5 +1,5 @@
 /*
- * Zoran 364xx based USB webcam module version 0.72
+ * Zoran 364xx based USB webcam module version 0.73
  *
  * Allows you to use your USB webcam with V4L2 applications
  * This is still in heavy developpement !
@@ -10,6 +10,8 @@
  * Heavily inspired by usb-skeleton.c, vicam.c, cpia.c and spca50x.c drivers
  * V4L2 version inspired by meye.c driver
  *
+ * Some video buffer code by Lamarque based on s2255drv.c and vivi.c drivers.
+ *
  * 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
@@ -35,25 +37,34 @@
 #include 
 #include 
 #include 
+#include 
 #include "compat.h"
 
 
 /* Version Information */
-#define DRIVER_VERSION "v0.72"
+#define DRIVER_VERSION "v0.73"
+#define ZR364_VERSION_CODE KERNEL_VERSION(0, 7, 3)
 #define DRIVER_AUTHOR "Antoine Jacquet, http://royale.zerezo.com/";
 #define DRIVER_DESC "Zoran 364xx"
 
 
 /* Camera */
-#define FRAMES 2
+#define FRAMES 1
 #define MAX_FRAME_SIZE 10
 #define BUFFER_SIZE 0x1000
 #define CTRL_TIMEOUT 500
 
+#define ZR364XX_DEF_BUFS   4
+#define ZR364XX_READ_IDLE  0
+#define ZR364XX_READ_FRAME 1
 
 /* Debug macro */
-#define DBG(x...) if (debug) printk(KERN_INFO KBUILD_MODNAME x)
-
+#define DBG(fmt, args...) \
+   do { \
+   if (debug) { \
+   printk(KERN_INFO KBUILD_MODNAME " " fmt, ##args); \
+   } \
+   } while (0)
 
 /* Init methods, need to find nicer names for these
  * the exact names of the chipsets would be the best if someone finds it */
@@ -102,24 +113,93 @@
 
 MODULE_DEVICE_TABLE(usb, device_table);
 
+struct zr364xx_mode {
+   u32 color;  /* output video color format */
+   u32 brightness; /* brightness */
+};
+
+/* frame structure */
+struct zr364xx_framei {
+   unsigned long ulState;  /* ulState:ZR364XX_READ_IDLE,
+  ZR364XX_READ_FRAME */
+   void *lpvbits;  /* image data */
+   unsigned long cur_size; /* current data copied to it */
+};
+
+/* image buffer structure */
+struct zr364xx_bufferi {
+   unsigned long dwFrames; /* number of frames in buffer */
+   struct zr364xx_framei frame[FRAMES];/* array of FRAME structures */
+};
+
+struct zr364xx_dmaqueue {
+   struct list_headactive;
+   struct zr364xx_camera   *cam;
+};
+
+struct zr364xx_pipeinfo {
+   u32 transfer_size;
+   u8 *transfer_buffer;
+   u32 state;
+   void *stream_urb;
+   void *cam;  /* back pointer to zr364xx_camera struct */
+   u32 err_count;
+   u32 idx;
+};
+
+struct zr364xx_fmt {
+   char *name;
+   u32 fourcc;
+   int depth;
+};
+
+/* image formats.  */
+static const struct zr364xx_fmt formats[] = {
+   {
+   .name = "JPG",
+   .fourcc = V4L2_PIX_FMT_JPEG,
+   .depth = 24
+   }
+};
 
 /* Camera stuff */
 struct zr364xx_camera {
struct usb_device *udev;/* save off the usb device pointer */
struct usb_interface *interface;/* the interface for this device */
struct video_device *vdev;  /* v4l video device */
-   u8 *framebuf;
int nb;
-   unsigned char *buffer;
+   struct zr364xx_bufferi  buffer;
int skip;
-   int brightness;
int width;
int height;
int method;
struct mutex lock;
+   struct mutex open_lock;
int users;
+
+   spinlock_t  slock;
+   struct zr364xx_dmaqueue vidq;
+   int resources;
+   int last_frame;
+   int cur_frame;
+   unsigned long

Re: [PATCH] Implement V4L2_CAP_STREAMING for zr364xx driver

2009-07-16 Thread Lamarque Vieira Souza
Em Quinta-feira 16 Julho 2009, Antoine Jacquet escreveu:
> Thanks,
>
> I successfully applied your patch and tested it with mplayer.
> However I have the following trace each time I capture a frame:

No, I do not have this problem neither in 2.6.28 (vanilla), 2.6.29.3 
(vanilla 
source and v4l-dvb) and 2.6.30.1 (vanilla and v4l-dvb). My notebook is single 
core, maybe this problem is related to SMP. I will try to test the patch on a 
dual core processor.

> [  523.477064] BUG: scheduling while atomic: swapper/0/0x1001
> [  523.477390] Modules linked in: zr364xx videodev v4l1_compat
> v4l2_compat_ioctl32 videobuf_vmalloc videobuf_core binfmt_misc ipv6 fuse
> ntfs it87 hwmon_vid snd_intel8x0 snd_ac97_codec ac97_bus snd_pcm_oss
> snd_mixer_oss snd_pcm snd_seq_dummy snd_seq_oss snd_seq_midi_event
> snd_seq snd_timer snd_seq_device pcspkr snd snd_page_alloc
> [  523.477390] CPU 0:
> [  523.477390] Modules linked in: zr364xx videodev v4l1_compat
> v4l2_compat_ioctl32 videobuf_vmalloc videobuf_core binfmt_misc ipv6 fuse
> ntfs it87 hwmon_vid snd_intel8x0 snd_ac97_codec ac97_bus snd_pcm_oss
> snd_mixer_oss snd_pcm snd_seq_dummy snd_seq_oss snd_seq_midi_event
> snd_seq snd_timer snd_seq_device pcspkr snd snd_page_alloc
> [  523.477390] Pid: 0, comm: swapper Not tainted 2.6.30.1 #1 Aspire T160
> [  523.477390] RIP: 0010:[]  []
> default_idle+0x54/0x90
> [  523.477390] RSP: 0018:807e3f38  EFLAGS: 0246
> [  523.477390] RAX: 807e3fd8 RBX:  RCX:
> 
> [  523.477390] RDX:  RSI: 0001 RDI:
> 8078d010
> [  523.477390] RBP: 8020b60e R08:  R09:
> 
> [  523.477390] R10: 000f423d R11:  R12:
> 88003f87d180
> [  523.477390] R13:  R14: 88003e1e9940 R15:
> 88003f87d180
> [  523.477390] FS:  7f40f871e730() GS:80789000()
> knlGS:
> [  523.477390] CS:  0010 DS: 0018 ES: 0018 CR0: 8005003b
> [  523.477390] CR2: 7f099e8c2008 CR3: 3c16c000 CR4:
> 06e0
> [  523.477390] DR0:  DR1:  DR2:
> 
> [  523.477390] DR3:  DR6: 0ff0 DR7:
> 0400
> [  523.477390] Call Trace:
> [  523.477390]  [] ? notifier_call_chain+0x29/0x4c
> [  523.477390]  [] ? cpu_idle+0x23/0x5b
> [  523.477390]  [] ? start_kernel+0x2e8/0x2f4
> [  523.477390]  [] ? x86_64_start_kernel+0xe5/0xeb
>
> I can trigger it each time I read a frame, for example using dd on
> /dev/video0.
> Did you have the same behavior?
>
> Regards,
>
> Antoine
>
> Lamarque Vieira Souza wrote:
> > This patch implements V4L2_CAP_STREAMING for the zr364xx driver, by
> > converting the driver to use videobuf. This version is synced with
> > v4l-dvb as of 15/Jul/2009.
> >
> > Tested with Creative PC-CAM 880.
> >
> > It basically:
> > . implements V4L2_CAP_STREAMING using videobuf;
> >
> > . re-implements V4L2_CAP_READWRITE using videobuf;
> >
> > . copies cam->udev->product to the card field of the v4l2_capability
> > struct. That gives more information to the users about the webcam;
> >
> > . moves the brightness setting code from before requesting a frame (in
> > read_frame) to the vidioc_s_ctrl ioctl. This way the brightness code is
> > executed only when the application requests a change in brightness and
> > not before every frame read;
> >
> > . comments part of zr364xx_vidioc_try_fmt_vid_cap that says that Skype +
> > libv4l do not work.
> >
> > This patch fixes zr364xx for applications such as mplayer,
> > Kopete+libv4l and Skype+libv4l can make use of the webcam that comes
> > with zr364xx chip.
> >
> > Signed-off-by: Lamarque V. Souza 
> > ---


-- 
Lamarque V. Souza
http://www.geographicguide.com/brazil.htm
Linux User #57137 - http://counter.li.org/
--
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] Implement V4L2_CAP_STREAMING for zr364xx driver

2009-07-16 Thread Lamarque Vieira Souza
Em Quinta-feira 16 Julho 2009, Mauro Carvalho Chehab escreveu:
> Em Wed, 15 Jul 2009 20:54:55 -0300
>
> Lamarque Vieira Souza  escreveu:
> > This patch implements V4L2_CAP_STREAMING for the zr364xx driver, by
> > converting the driver to use videobuf. This version is synced with
> > v4l-dvb as of 15/Jul/2009.
> >
> > Tested with Creative PC-CAM 880.
> >
> > It basically:
> > . implements V4L2_CAP_STREAMING using videobuf;
> >
> > . re-implements V4L2_CAP_READWRITE using videobuf;
> >
> > . copies cam->udev->product to the card field of the v4l2_capability
> > struct. That gives more information to the users about the webcam;
> >
> > . moves the brightness setting code from before requesting a frame (in
> > read_frame) to the vidioc_s_ctrl ioctl. This way the brightness code is
> > executed only when the application requests a change in brightness and
> > not before every frame read;
> >
> > . comments part of zr364xx_vidioc_try_fmt_vid_cap that says that Skype +
> > libv4l do not work.
> >
> > This patch fixes zr364xx for applications such as mplayer,
> > Kopete+libv4l and Skype+libv4l can make use of the webcam that comes
> > with zr364xx chip.
> >
> > Signed-off-by: Lamarque V. Souza 
> > ---
> >
> > diff -r c300798213a9 linux/drivers/media/video/zr364xx.c
> > --- a/linux/drivers/media/video/zr364xx.c   Sun Jul 05 19:08:55 2009 -0300
> > +++ b/linux/drivers/media/video/zr364xx.c   Wed Jul 15 20:50:34 2009 -0300
> > @@ -1,5 +1,5 @@
> >  /*
> > - * Zoran 364xx based USB webcam module version 0.72
> > + * Zoran 364xx based USB webcam module version 0.73
> >   *
> >   * Allows you to use your USB webcam with V4L2 applications
> >   * This is still in heavy developpement !
> > @@ -10,6 +10,8 @@
> >   * Heavily inspired by usb-skeleton.c, vicam.c, cpia.c and spca50x.c
> > drivers * V4L2 version inspired by meye.c driver
> >   *
> > + * Some video buffer code by Lamarque based on s2255drv.c and vivi.c
> > drivers. + *
>
> Maybe the better example for it is em28xx-video, where we firstly used
> videobuf on usb devices.

I will take a look at em28xx-video. I used s2255drv.c and vivi.c 
because 
their code organization are similar to zr364xx.c, so it was easier to know 
what to do.

> > +static void free_buffer(struct videobuf_queue *vq, struct zr364xx_buffer
> > *buf)
> > +{
> > +   DBG("%s\n", __func__);
> > +
> > +   /*Lamarque: is this really needed? Sometimes this blocks rmmod forever
> > +* after running Skype on an AMD64 system. */
> > +   /*videobuf_waiton(&buf->vb, 0, 0);*/
>
> Answering to your note, take a look at em28xx-video implementation:
>
> /* We used to wait for the buffer to finish here, but this didn't
> work because, as we were keeping the state as VIDEOBUF_QUEUED,
> videobuf_queue_cancel marked it as finished for us.
>(Also, it could wedge forever if the hardware was
> misconfigured.)
>
>This should be safe; by the time we get here, the buffer isn't
>queued anymore. If we ever start marking the buffers as
>VIDEOBUF_ACTIVE, it won't be, though.
> */
> spin_lock_irqsave(&dev->slock, flags);
> if (dev->isoc_ctl.buf == buf)
> dev->isoc_ctl.buf = NULL;
> spin_unlock_irqrestore(&dev->slock, flags);

Yes, the comment answers my question. There is no similar code in 
zr364xx.c 
like the one above. zr364xx_camera does not have a member with zr364xxx_buffer 
type (the equivalent type of dev->isoc_ctl.buf).

> > +   if (pipe_info->state != 0) {
> > +   if (usb_submit_urb(pipe_info->stream_urb, GFP_KERNEL))
> > +   dev_err(&cam->udev->dev, "error submitting urb\n");
> > +   } else {
> > +   DBG("read pipe complete state 0\n");
> > +   }
>
> Hmm...  for the usb_submit_urb() call that happens during IRQ context
> (while you're receiving stream), you need to use:
> urb->status = usb_submit_urb(pipe_info->stream_urb, GFP_ATOMIC);
>
> otherwise, you may get the errors that Antoine is reporting

Ok, changed to GPF_ATOMIC. Could someone test this for me since I was 
not 
able to reproduce this problem? The new patch is here 
http://bach.metasys.com.br/~lamarque/zr364xx/zr364xx.c-streaming.patch-v4l-
dvb-20090716 . I upload it to avoid bloating the mailing-list with a 40k 
patch.

I have computer here with dual core processor but no display. I need to 
get a 
DVI <-> VGA adaptor to plug my DVI LCD on it, when I get one I am going to 
test the changes with SMP enabled.

-- 
Lamarque V. Souza
http://www.geographicguide.com/brazil.htm
Linux User #57137 - http://counter.li.org/
--
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] Implement changing resolution on the fly for zr364xx driver

2009-07-20 Thread Lamarque Vieira Souza
This patch implements changing resolution in 
zr364xx_vidioc_s_fmt_vid_cap for 
zr364xx driver. This version is synced with v4l-dvb as of 20/Jul/2009. Tested 
with Creative PC-CAM 880.

OBS: I had to increase MAX_FRAME_SIZE to prevent a hard crash in my notebook 
(caps lock blinking) when testing with mplayer, which automatically sets 
resolution to the maximum (640x480). Maybe we should add code to auto-detect 
frame size to prevent this kind of crash in the future.

Signed-off-by: Lamarque V. Souza 
---

diff -r 1cb6f19d2c9d linux/drivers/media/video/zr364xx.c
--- a/linux/drivers/media/video/zr364xx.c   Sun Jul 19 18:03:23 2009 -0300
+++ b/linux/drivers/media/video/zr364xx.c   Mon Jul 20 20:20:21 2009 -0300
@@ -43,14 +43,14 @@
 
 /* Version Information */
 #define DRIVER_VERSION "v0.73"
-#define ZR364_VERSION_CODE KERNEL_VERSION(0, 7, 3)
+#define ZR364XX_VERSION_CODE KERNEL_VERSION(0, 7, 3)
 #define DRIVER_AUTHOR "Antoine Jacquet, http://royale.zerezo.com/";
 #define DRIVER_DESC "Zoran 364xx"
 
 
 /* Camera */
 #define FRAMES 1
-#define MAX_FRAME_SIZE 10
+#define MAX_FRAME_SIZE 20
 #define BUFFER_SIZE 0x1000
 #define CTRL_TIMEOUT 500
 
@@ -734,7 +734,7 @@
strlcpy(cap->card, cam->udev->product, sizeof(cap->card));
strlcpy(cap->bus_info, dev_name(&cam->udev->dev),
sizeof(cap->bus_info));
-   cap->version = ZR364_VERSION_CODE;
+   cap->version = ZR364XX_VERSION_CODE;
cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
V4L2_CAP_READWRITE |
V4L2_CAP_STREAMING;
@@ -874,9 +874,14 @@
return -EINVAL;
}
 
+   if (!(f->fmt.pix.width == 160 && f->fmt.pix.height == 120) &&
+   !(f->fmt.pix.width == 640 && f->fmt.pix.height == 480)) {
+   f->fmt.pix.width = 320;
+   f->fmt.pix.height = 240;
+   }
+
f->fmt.pix.field = V4L2_FIELD_NONE;
-   f->fmt.pix.width = cam->width;
-   f->fmt.pix.height = cam->height;
+   f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
f->fmt.pix.colorspace = 0;
@@ -907,7 +912,6 @@
return 0;
 }
 
-/* Lamarque TODO: implement changing resolution on the fly */
 static int zr364xx_vidioc_s_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f)
 {
@@ -915,6 +919,7 @@
struct videobuf_queue *q = &cam->vb_vidq;
char pixelformat_name[5];
int ret = zr364xx_vidioc_try_fmt_vid_cap(file, cam, f);
+   int i;
 
if (ret < 0)
return ret;
@@ -927,15 +932,55 @@
goto out;
}
 
-   f->fmt.pix.field = V4L2_FIELD_NONE;
-   f->fmt.pix.width = cam->width;
-   f->fmt.pix.height = cam->height;
+   if (res_check(cam)) {
+   DBG("%s can't change format after started\n", __func__);
+   ret = -EBUSY;
+   goto out;
+   }
+
+   cam->width = f->fmt.pix.width;
+   cam->height = f->fmt.pix.height;
+   dev_info(&cam->udev->dev, "%s: %dx%d mode selected\n", __func__,
+cam->width, cam->height);
f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
f->fmt.pix.colorspace = 0;
f->fmt.pix.priv = 0;
cam->vb_vidq.field = f->fmt.pix.field;
cam->mode.color = V4L2_PIX_FMT_JPEG;
+
+   if (f->fmt.pix.width == 160 && f->fmt.pix.height == 120)
+   mode = 1;
+   else if (f->fmt.pix.width == 640 && f->fmt.pix.height == 480)
+   mode = 2;
+   else
+   mode = 0;
+
+   m0d1[0] = mode;
+   m1[2].value = 0xf000 + mode;
+   m2[1].value = 0xf000 + mode;
+   header2[437] = cam->height / 256;
+   header2[438] = cam->height % 256;
+   header2[439] = cam->width / 256;
+   header2[440] = cam->width % 256;
+
+   for (i = 0; init[cam->method][i].size != -1; i++) {
+   ret =
+   send_control_msg(cam->udev, 1, init[cam->method][i].value,
+0, init[cam->method][i].bytes,
+init[cam->method][i].size);
+   if (ret < 0) {
+   dev_err(&cam->udev->dev,
+  "error during resolution change sequence: %d\n", i);
+   goto out;
+   }
+   }
+
+   /* Added some delay here, since opening/closing the camera quickly,
+* like Ekiga does during its startup, can crash the webcam
+*/
+   mdelay(100);
+   cam->skip = 2;
ret = 0;
 
 out:
@@ -1123,6 +1168,7 @@
cam->buffer.frame[j].ulState = ZR364XX_READ_IDLE;
cam->buffer.frame[j].cur_size = 0;
}
+   cam->b_acquire = 1;
return 0;
 }
 
@@ -1165

Re: [PATCH] Implement changing resolution on the fly for zr364xx driver

2009-07-21 Thread Lamarque Vieira Souza
Em Terça-feira 21 Julho 2009, Antoine Jacquet escreveu:
> Hi,

Hi,

> > This patch implements changing resolution in zr364xx_vidioc_s_fmt_vid_cap
> > for zr364xx driver. This version is synced with v4l-dvb as of
> > 20/Jul/2009. Tested with Creative PC-CAM 880.
>
> Nice, I successfully tested your patch with 2 compatible webcams.
>  From the users feedbacks I had before, it seems that some devices do
> not support the 640x480 resolution, but I was not able to verify this
> myself.
> This is the only concern I have, since some users may think the driver
> is not working if the application automatically switches to the maximum
> resolution with an incompatible device.

Maybe we should add a quirk list to prevent such cases or if 
send_control_msg 
returns error in such cases I can change the code to revert the change and 
keep the old resolution.

> > OBS: I had to increase MAX_FRAME_SIZE to prevent a hard crash in my
> > notebook (caps lock blinking) when testing with mplayer, which
> > automatically sets resolution to the maximum (640x480). Maybe we should
> > add code to auto-detect frame size to prevent this kind of crash in the
> > future.
>
> Yes, I also had this issue before. I don't know what is the good
> approach to determine the best size with JPEG compression.

The driver reads data from USB port in 4096-bytes chunks, so before 
adding 
the data to frm->lpvbits we could verify if frm->lpvbits has enough space to 
hold it. If there is no enough space we can dynamically increase frm->lpvbits. 
In user space that can be done using realloc, I just do not know if there is a 
similar function in kernel space. OBS: frm->lpvbits had be increased without 
loosing the old data and of course we should have a upper limit, maybe 640 x 
480 * 3 (3 bytes per pixel) = 921600 bytes.

> I will push your changes to my tree and send a pull request to Mauro later.

Ok, thanks.

-- 
Lamarque V. Souza
http://www.geographicguide.com/brazil.htm
Linux User #57137 - http://counter.li.org/
--
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] Implement changing resolution on the fly for zr364xx driver

2009-07-21 Thread Lamarque Vieira Souza
Hi,

I have made some changes to the patch:

. added code to print an error message when buffer is too small to hold frame 
data, that is better than just a hard crash. Tested using MAX_FRAME_SIZE = 
5, lots of error messages appeared in /var/log/messages but no crash.

. removed line "f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;" in 
zr364xx_vidioc_try_fmt_vid_cap, it should not be there.

. changes to improve performance (or at least not hurt it): removed some 
unneeded debug messages; added macro FULL_DEBUG to enable debug messages in 
performance critical places, this macro is disabled by default; removed "if 
(frm->lpvbits == NULL)..." in zr364xx_read_video_callback because after 
analisying the source code I concluded it will always results to false, so it 
is not needed.

. some small code reorganization.

There is an incremental version of the last patch I sent in 
http://bach.metasys.com.br/~lamarque/zr364xx/zr364xx.c-resolution.patch-
incremental-v4l-dvb-20090721

Signed-off-by: Lamarque V. Souza 
---

diff -r 6477aa1782d5 linux/drivers/media/video/zr364xx.c
--- a/linux/drivers/media/videon/zr364xx.c  Tue Jul 21 09:17:24 2009 -0300
+++ b/linux/drivers/media/video/zr364xx.c   Tue Jul 21 19:00:52 2009 -0300
@@ -44,14 +44,14 @@
 
 /* Version Information */
 #define DRIVER_VERSION "v0.73"
-#define ZR364_VERSION_CODE KERNEL_VERSION(0, 7, 3)
+#define ZR364XX_VERSION_CODE KERNEL_VERSION(0, 7, 3)
 #define DRIVER_AUTHOR "Antoine Jacquet, http://royale.zerezo.com/";
 #define DRIVER_DESC "Zoran 364xx"
 
 
 /* Camera */
 #define FRAMES 1
-#define MAX_FRAME_SIZE 10
+#define MAX_FRAME_SIZE 20
 #define BUFFER_SIZE 0x1000
 #define CTRL_TIMEOUT 500
 
@@ -67,6 +67,13 @@
} \
} while (0)
 
+/*#define FULL_DEBUG 1*/
+#ifdef FULL_DEBUG
+#define _DBG DBG
+#else
+#define _DBG(fmt, args...)
+#endif
+
 /* Init methods, need to find nicer names for these
  * the exact names of the chipsets would be the best if someone finds it */
 #define METHOD0 0
@@ -376,7 +383,7 @@
 
 static void free_buffer(struct videobuf_queue *vq, struct zr364xx_buffer 
*buf)
 {
-   DBG("%s\n", __func__);
+   _DBG("%s\n", __func__);
 
if (in_interrupt())
BUG();
@@ -429,7 +436,7 @@
  vb);
struct zr364xx_camera *cam = vq->priv_data;
 
-   DBG("%s\n", __func__);
+   _DBG("%s\n", __func__);
 
buf->vb.state = VIDEOBUF_QUEUED;
list_add_tail(&buf->vb.queue, &cam->vidq.active);
@@ -441,7 +448,7 @@
struct zr364xx_buffer *buf = container_of(vb, struct zr364xx_buffer,
  vb);
 
-   DBG("%s\n", __func__);
+   _DBG("%s\n", __func__);
free_buffer(vq, buf);
 }
 
@@ -463,7 +470,7 @@
 {
struct zr364xx_camera *cam = video_drvdata(file);
 
-   DBG("%s\n", __func__);
+   _DBG("%s\n", __func__);
 
if (!buf)
return -EINVAL;
@@ -583,7 +590,7 @@
int i = 0;
unsigned char *ptr = NULL;
 
-   /*DBG("buffer to user\n");*/
+   _DBG("buffer to user\n");
idx = cam->cur_frame;
frm = &cam->buffer.frame[idx];
 
@@ -601,12 +608,6 @@
return -EINVAL;
}
 
-   if (frm->lpvbits == NULL) {
-   DBG("%s: frame buffer == NULL.%p %p %d\n", __func__,
-   frm, cam, idx);
-   return -ENOMEM;
-   }
-
psrc = (u8 *)pipe_info->transfer_buffer;
ptr = pdest = frm->lpvbits;
 
@@ -614,7 +615,7 @@
frm->ulState = ZR364XX_READ_FRAME;
frm->cur_size = 0;
 
-   DBG("jpeg header, ");
+   _DBG("jpeg header, ");
memcpy(ptr, header1, sizeof(header1));
ptr += sizeof(header1);
header3 = 0;
@@ -632,21 +633,28 @@
memcpy(ptr, psrc + 128,
   purb->actual_length - 128);
ptr += purb->actual_length - 128;
-   DBG("header : %d %d %d %d %d %d %d %d %d\n",
+   _DBG("header : %d %d %d %d %d %d %d %d %d\n",
psrc[0], psrc[1], psrc[2],
psrc[3], psrc[4], psrc[5],
psrc[6], psrc[7], psrc[8]);
frm->cur_size = ptr - pdest;
} else {
-   pdest += frm->cur_size;
-   memcpy(pdest, psrc, purb->actual_length);
-   frm->cur_size += purb->actual_length;
+   if (frm->cur_size + purb->actual_length > MAX_FRAME_SIZE) {
+   dev_info(&cam->udev->dev,
+"%s: buffer (%d bytes) too small to hold "
+"frame data\n",
+__func__, MAX_FRAME_SIZE);
+   } else {
+   pdest += frm->cur_size;
+   memcpy(pdest, psrc, purb->actual_length);
+   frm->cur_size += purb-

Re: [PATCH] Implement changing resolution on the fly for zr364xx driver

2009-07-22 Thread Lamarque Vieira Souza
Em Quarta-feira 22 Julho 2009, Antoine Jacquet escreveu:
> Hi,
>
> Lamarque Vieira Souza wrote:
> > I have made some changes to the patch:
>
> Since I already included your previous patch and sent a pull request to
> Mauro, could you send a patch against my current tree:
>   http://linuxtv.org/hg/~ajacquet/zr364xx/
>
> Thanks,
>
> Antoine

Here it is

Signed-off-by: Lamarque V. Souza 
---

diff -r ebb57057cf4d linux/drivers/media/video/zr364xx.c
--- a/linux/drivers/media/video/zr364xx.c   Mon Jul 20 20:46:42 2009 -0300
+++ b/linux/drivers/media/video/zr364xx.c   Wed Jul 22 16:52:30 2009 -0300
@@ -67,6 +67,13 @@
} \
} while (0)
 
+/*#define FULL_DEBUG 1*/
+#ifdef FULL_DEBUG
+#define _DBG DBG
+#else
+#define _DBG(fmt, args...)
+#endif
+
 /* Init methods, need to find nicer names for these
  * the exact names of the chipsets would be the best if someone finds it */
 #define METHOD0 0
@@ -376,7 +383,7 @@
 
 static void free_buffer(struct videobuf_queue *vq, struct zr364xx_buffer 
*buf)
 {
-   DBG("%s\n", __func__);
+   _DBG("%s\n", __func__);
 
if (in_interrupt())
BUG();
@@ -429,7 +436,7 @@
  vb);
struct zr364xx_camera *cam = vq->priv_data;
 
-   DBG("%s\n", __func__);
+   _DBG("%s\n", __func__);
 
buf->vb.state = VIDEOBUF_QUEUED;
list_add_tail(&buf->vb.queue, &cam->vidq.active);
@@ -441,7 +448,7 @@
struct zr364xx_buffer *buf = container_of(vb, struct zr364xx_buffer,
  vb);
 
-   DBG("%s\n", __func__);
+   _DBG("%s\n", __func__);
free_buffer(vq, buf);
 }
 
@@ -463,7 +470,7 @@
 {
struct zr364xx_camera *cam = video_drvdata(file);
 
-   DBG("%s\n", __func__);
+   _DBG("%s\n", __func__);
 
if (!buf)
return -EINVAL;
@@ -583,7 +590,7 @@
int i = 0;
unsigned char *ptr = NULL;
 
-   /*DBG("buffer to user\n");*/
+   _DBG("buffer to user\n");
idx = cam->cur_frame;
frm = &cam->buffer.frame[idx];
 
@@ -601,12 +608,6 @@
return -EINVAL;
}
 
-   if (frm->lpvbits == NULL) {
-   DBG("%s: frame buffer == NULL.%p %p %d\n", __func__,
-   frm, cam, idx);
-   return -ENOMEM;
-   }
-
psrc = (u8 *)pipe_info->transfer_buffer;
ptr = pdest = frm->lpvbits;
 
@@ -614,7 +615,7 @@
frm->ulState = ZR364XX_READ_FRAME;
frm->cur_size = 0;
 
-   DBG("jpeg header, ");
+   _DBG("jpeg header, ");
memcpy(ptr, header1, sizeof(header1));
ptr += sizeof(header1);
header3 = 0;
@@ -632,21 +633,28 @@
memcpy(ptr, psrc + 128,
   purb->actual_length - 128);
ptr += purb->actual_length - 128;
-   DBG("header : %d %d %d %d %d %d %d %d %d\n",
+   _DBG("header : %d %d %d %d %d %d %d %d %d\n",
psrc[0], psrc[1], psrc[2],
psrc[3], psrc[4], psrc[5],
psrc[6], psrc[7], psrc[8]);
frm->cur_size = ptr - pdest;
} else {
-   pdest += frm->cur_size;
-   memcpy(pdest, psrc, purb->actual_length);
-   frm->cur_size += purb->actual_length;
+   if (frm->cur_size + purb->actual_length > MAX_FRAME_SIZE) {
+   dev_info(&cam->udev->dev,
+"%s: buffer (%d bytes) too small to hold "
+"frame data. Discarding frame data.\n",
+__func__, MAX_FRAME_SIZE);
+   } else {
+   pdest += frm->cur_size;
+   memcpy(pdest, psrc, purb->actual_length);
+   frm->cur_size += purb->actual_length;
+   }
}
-   /*DBG("cur_size %lu urb size %d\n", frm->cur_size,
+   /*_DBG("cur_size %lu urb size %d\n", frm->cur_size,
purb->actual_length);*/
 
if (purb->actual_length < pipe_info->transfer_size) {
-   DBG("Buffer[%d]full*\n", idx);
+   _DBG("Buffer[%d]full*\n", idx);
cam->last_frame = cam->cur_frame;
cam->cur_frame++;
/* end of system frame ring buffer, start at zero */
@@ -681,7 +689,7 @@
if (cam->skip)
cam->skip--;
 

Patch implementing V4L2_CAP_STREAMING for zr364xx driver

2009-03-25 Thread Lamarque Vieira Souza
Hi,

I have implemented V4L2_CAP_STREAMING for the zr364xx driver (see the 
attached file). Could you review the code for me? My 
Creative PC-CAM 880 works, but I do not have any other webcam to test the 
code. Besides the streaming implementation the patch also does:

. re-implement V4L2_CAP_READWRITE using videobuf.

. copy cam->udev->product to the card field of the v4l2_capability struct. 
That gives more information to the users about the webcam.

. move the brightness setting code from before requesting a frame (in 
read_frame) to the vidioc_s_ctrl ioctl. This way the brightness code is 
executed only when the application request a change in brightness and not 
before every frame read. Is there any reason to set the brightness before 
every frame read?

. comment part of zr364xx_vidioc_try_fmt_vid_cap. Skype + libv4l do not work 
if it is there and libv4's maintainer told me it is a driver bug, so I fix it.

This patch is needed for applications such as mplayer, Kopete+libv4l 
and 
Skype+libv4l can make use of the webcam that comes with zr364xx chip. The 
patch is big, if you need it splitted into small patches I can do it.

Best regards,

-- 
Lamarque V. Souza
http://www.geographicguide.com/brazil.htm
Linux User #57137 - http://counter.li.org/

--- linux-2.6.29/drivers/media/video/zr364xx.c	2009-03-25 19:06:37.241552912 -0300
+++ linux-2.6.29-lvs/drivers/media/video/zr364xx.c	2009-03-25 19:25:58.981551627 -0300
@@ -1,5 +1,5 @@
 /*
- * Zoran 364xx based USB webcam module version 0.72
+ * Zoran 364xx based USB webcam module version 0.73
  *
  * Allows you to use your USB webcam with V4L2 applications
  * This is still in heavy developpement !
@@ -10,6 +10,8 @@
  * Heavily inspired by usb-skeleton.c, vicam.c, cpia.c and spca50x.c drivers
  * V4L2 version inspired by meye.c driver
  *
+ * Some video buffer code by Lamarque based on s2255drv driver.
+ *
  * 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
@@ -25,7 +27,6 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-
 #include 
 #include 
 #include 
@@ -36,23 +37,33 @@
 #include 
 #include 
 #include 
+#include 
 
 
 /* Version Information */
-#define DRIVER_VERSION "v0.72"
+#define ZR364_VERSION_CODE KERNEL_VERSION(0, 7, 3)
+#define DRIVER_VERSION "v0.73"
 #define DRIVER_AUTHOR "Antoine Jacquet, http://royale.zerezo.com/";
 #define DRIVER_DESC "Zoran 364xx"
 
 
 /* Camera */
-#define FRAMES 2
+#define FRAMES 1
 #define MAX_FRAME_SIZE 10
 #define BUFFER_SIZE 0x1000
 #define CTRL_TIMEOUT 500
 
+#define ZR364XX_DEF_BUFS	4
+#define ZR364XX_READ_IDLE	0
+#define ZR364XX_READ_FRAME	1
 
 /* Debug macro */
-#define DBG(x...) if (debug) printk(KERN_INFO KBUILD_MODNAME x)
+#define DBG(fmt, args...) \
+	do { \
+		if (debug) { \
+			printk(KERN_INFO KBUILD_MODNAME " " fmt, ##args); \
+		} \
+	} while (0)
 
 
 /* Init methods, need to find nicer names for these
@@ -101,24 +112,96 @@ static struct usb_device_id device_table
 
 MODULE_DEVICE_TABLE(usb, device_table);
 
+struct zr364xx_mode {
+	u32 color;	/* output video color format */
+	u32 brightness;	/* brightness */
+};
+
+/* frame structure */
+struct zr364xx_framei {
+	unsigned long ulState;	/* ulState:ZR364XX_READ_IDLE, ZR364XX_READ_FRAME*/
+	void *lpvbits;		/* image data */
+	unsigned long cur_size;	/* current data copied to it */
+};
+
+/* image buffer structure */
+struct zr364xx_bufferi {
+	unsigned long dwFrames;			/* number of frames in buffer */
+	struct zr364xx_framei frame[FRAMES];	/* array of FRAME structures */
+};
+
+struct zr364xx_dmaqueue {
+	struct list_head	active;
+	struct zr364xx_camera	*cam;
+};
+
+struct zr364xx_pipeinfo {
+	u32 transfer_size;
+	u8 *transfer_buffer;
+	u32 transfer_flags;;
+	u32 state;
+	u32 prev_state;
+	u32 urb_size;
+	void *stream_urb;
+	void *cam;	/* back pointer to zr364xx_camera struct */
+	u32 err_count;
+	u32 idx;
+	u32 priority_set;
+};
+
+struct zr364xx_fmt {
+	char *name;
+	u32 fourcc;
+	int depth;
+};
+
+/* image formats.  */
+static const struct zr364xx_fmt formats[] = {
+	{
+		.name = "JPG",
+		.fourcc = V4L2_PIX_FMT_JPEG,
+		.depth = 24
+	}
+};
 
 /* Camera stuff */
 struct zr364xx_camera {
 	struct usb_device *udev;	/* save off the usb device pointer */
 	struct usb_interface *interface;/* the interface for this device */
 	struct video_device *vdev;	/* v4l video device */
-	u8 *framebuf;
 	int nb;
-	unsigned char *buffer;
+	struct zr364xx_bufferi		buffer;
 	int skip;
-	int brightness;
 	int width;
 	int height;
 	int method;
 	struct mutex lock;
+	struct mutex open_lock;
 	int users;
+
+	spinlock_t		slock;
+	struct zr364xx_dmaqueue	vidq;
+	int 			resources;
+	int			last_frame;
+	int			cur_frame;
+	unsigned long		frame_count;
+	int			b_acquire;
+	struct zr364xx_pipeinfo	pipe[1];
+
+	u8			read_endpoint;
+
+	const struct zr364

Re: Patch implementing V4L2_CAP_STREAMING for zr364xx driver

2009-03-27 Thread Lamarque Vieira Souza
Here is the patch with the modifications you asked.

Em Friday 27 March 2009, Mauro Carvalho Chehab escreveu:
> On Wed, 25 Mar 2009 20:25:10 -0300
>
> Lamarque Vieira Souza  wrote:
> > Hi,
> >
> > I have implemented V4L2_CAP_STREAMING for the zr364xx driver (see
> > the attached file). Could you review the code for me? My
> > Creative PC-CAM 880 works, but I do not have any other webcam to test the
> > code. Besides the streaming implementation the patch also does:
> >
> > . re-implement V4L2_CAP_READWRITE using videobuf.
> >
> > . copy cam->udev->product to the card field of the v4l2_capability
> > struct. That gives more information to the users about the webcam.
> >
> > . move the brightness setting code from before requesting a frame (in
> > read_frame) to the vidioc_s_ctrl ioctl. This way the brightness code is
> > executed only when the application request a change in brightness and not
> > before every frame read. Is there any reason to set the brightness before
> > every frame read?
> >
> > . comment part of zr364xx_vidioc_try_fmt_vid_cap. Skype + libv4l do not
> > work if it is there and libv4's maintainer told me it is a driver bug, so
> > I fix it.
> >
> > This patch is needed for applications such as mplayer, Kopete+libv4l and
> > Skype+libv4l can make use of the webcam that comes with zr364xx chip. The
> > patch is big, if you need it splitted into small patches I can do it.
>
> Your patch didn't apply:
>
> patching file drivers/media/video/zr364xx.c
> Hunk #4 FAILED at 37.
> Hunk #5 succeeded at 114 (offset 2 lines).
> Hunk #7 succeeded at 474 (offset 2 lines).
> Hunk #9 succeeded at 782 (offset 2 lines).
> Hunk #11 succeeded at 848 (offset 2 lines).
> Hunk #13 succeeded at 918 (offset 2 lines).
> Hunk #15 succeeded at 1198 (offset 2 lines).
> Hunk #17 succeeded at 1242 (offset 2 lines).
> Hunk #19 succeeded at 1373 (offset 2 lines).
> Hunk #21 succeeded at 1409 (offset 2 lines).
> Hunk #23 succeeded at 1532 (offset 2 lines).
> 1 out of 24 hunks FAILED -- saving rejects to file
> drivers/media/video/zr364xx.c.rej Patch doesn't apply
>
> Probably because you didn't generate it against the development tree. Could
> you please re-generate it against: http://linuxtv.org/hg/v4l-dvbg/v4l-dvb
>
> The better is to clone it using:
>   hg clone http://linuxtv.org/hg/v4l-dvb
>
>
> Also, please test it against checkpatch tool, since there are a few coding
> style issues like:
>
>   }
>   else {
>
> and
>   if (foo)
>   {
>
> Violating Linux codingstyle. For more info, please read the README.patches
> file at the tree.
>
> > Lamarque V. Souza
> > http://www.geographicguide.com/brazil.htm
> > Linux User #57137 - http://counter.li.org/
>
> Legal! outro brasileiro na lista! Bem vindo ao time.

Hehe, obrigado.

-- 
Lamarque V. Souza
http://www.geographicguide.com/brazil.htm
Linux User #57137 - http://counter.li.org/
--- v4l-dvb/linux/drivers/media/video/zr364xx.c	2009-03-27 15:18:54.050413997 -0300
+++ v4l-dvb/linux-lvs/drivers/media/video/zr364xx.c	2009-03-27 15:22:47.914414277 -0300
@@ -1,5 +1,5 @@
 /*
- * Zoran 364xx based USB webcam module version 0.72
+ * Zoran 364xx based USB webcam module version 0.73
  *
  * Allows you to use your USB webcam with V4L2 applications
  * This is still in heavy developpement !
@@ -10,6 +10,8 @@
  * Heavily inspired by usb-skeleton.c, vicam.c, cpia.c and spca50x.c drivers
  * V4L2 version inspired by meye.c driver
  *
+ * Some video buffer code by Lamarque based on s2255drv.c and vivi.c drivers.
+ *
  * 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
@@ -25,7 +27,6 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-
 #include 
 #include 
 #include 
@@ -36,25 +37,34 @@
 #include 
 #include 
 #include 
+#include 
 #include "compat.h"
 
 
 /* Version Information */
-#define DRIVER_VERSION "v0.72"
+#define DRIVER_VERSION "v0.73"
+#define ZR364_VERSION_CODE KERNEL_VERSION(0, 7, 3)
 #define DRIVER_AUTHOR "Antoine Jacquet, http://royale.zerezo.com/";
 #define DRIVER_DESC "Zoran 364xx"
 
 
 /* Camera */
-#define FRAMES 2
+#define FRAMES 1
 #define MAX_FRAME_SIZE 10
 #define BUFFER_SIZE 0x1000
 #define CTRL_TIMEOUT 500
 
+#define ZR364XX_DEF_BUFS	4
+#define ZR364XX_READ_IDLE	0
+#define ZR364XX_READ_FRAME	1
 
 /* Debug macro */
-#define DBG(x...) if (debug) printk(KERN_INFO KBUILD_MODNAME x)
-
+#define DBG(fmt, args...) \
+	do { \
+		if (debug) { \
+			prin

[PATCH] Implement V4L2_CAP_STREAMING for zr364xx driver

2009-03-28 Thread Lamarque Vieira Souza
This patch implements V4L2_CAP_STREAMING for the zr364xx driver, by
converting the driver to use videobuf.

Tested with Creative PC-CAM 880.

It basically:
. implements V4L2_CAP_STREAMING using videobuf;

. re-implements V4L2_CAP_READWRITE using videobuf;

. copies cam->udev->product to the card field of the v4l2_capability struct.
That gives more information to the users about the webcam;

. moves the brightness setting code from before requesting a frame (in
read_frame) to the vidioc_s_ctrl ioctl. This way the brightness code is
executed only when the application requests a change in brightness and
not before every frame read;

. comments part of zr364xx_vidioc_try_fmt_vid_cap that says that Skype + 
libv4l do not work.

This patch fixes zr364xx for applications such as mplayer,
Kopete+libv4l and Skype+libv4l can make use of the webcam that comes
with zr364xx chip.

Signed-off-by: Lamarque V. Souza 
---

--- v4l-dvb/linux/drivers/media/video/zr364xx.c 2009-03-27 15:18:54.050413997 
-0300
+++ v4l-dvb/linux-lvs/drivers/media/video/zr364xx.c 2009-03-27 
15:22:47.914414277 -0300
@@ -1,5 +1,5 @@
 /*
- * Zoran 364xx based USB webcam module version 0.72
+ * Zoran 364xx based USB webcam module version 0.73
  *
  * Allows you to use your USB webcam with V4L2 applications
  * This is still in heavy developpement !
@@ -10,6 +10,8 @@
  * Heavily inspired by usb-skeleton.c, vicam.c, cpia.c and spca50x.c drivers
  * V4L2 version inspired by meye.c driver
  *
+ * Some video buffer code by Lamarque based on s2255drv.c and vivi.c drivers.
+ *
  * 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
@@ -25,7 +27,6 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-
 #include 
 #include 
 #include 
@@ -36,25 +37,34 @@
 #include 
 #include 
 #include 
+#include 
 #include "compat.h"
 
 
 /* Version Information */
-#define DRIVER_VERSION "v0.72"
+#define DRIVER_VERSION "v0.73"
+#define ZR364_VERSION_CODE KERNEL_VERSION(0, 7, 3)
 #define DRIVER_AUTHOR "Antoine Jacquet, http://royale.zerezo.com/";
 #define DRIVER_DESC "Zoran 364xx"
 
 
 /* Camera */
-#define FRAMES 2
+#define FRAMES 1
 #define MAX_FRAME_SIZE 10
 #define BUFFER_SIZE 0x1000
 #define CTRL_TIMEOUT 500
 
+#define ZR364XX_DEF_BUFS   4
+#define ZR364XX_READ_IDLE  0
+#define ZR364XX_READ_FRAME 1
 
 /* Debug macro */
-#define DBG(x...) if (debug) printk(KERN_INFO KBUILD_MODNAME x)
-
+#define DBG(fmt, args...) \
+   do { \
+   if (debug) { \
+   printk(KERN_INFO KBUILD_MODNAME " " fmt, ##args); \
+   } \
+   } while (0)
 
 /* Init methods, need to find nicer names for these
  * the exact names of the chipsets would be the best if someone finds it */
@@ -103,24 +113,97 @@ static struct usb_device_id device_table
 
 MODULE_DEVICE_TABLE(usb, device_table);
 
+struct zr364xx_mode {
+   u32 color;  /* output video color format */
+   u32 brightness; /* brightness */
+};
+
+/* frame structure */
+struct zr364xx_framei {
+   unsigned long ulState;  /* ulState:ZR364XX_READ_IDLE,
+  ZR364XX_READ_FRAME */
+   void *lpvbits;  /* image data */
+   unsigned long cur_size; /* current data copied to it */
+};
+
+/* image buffer structure */
+struct zr364xx_bufferi {
+   unsigned long dwFrames; /* number of frames in buffer */
+   struct zr364xx_framei frame[FRAMES];/* array of FRAME structures */
+};
+
+struct zr364xx_dmaqueue {
+   struct list_headactive;
+   struct zr364xx_camera   *cam;
+};
+
+struct zr364xx_pipeinfo {
+   u32 transfer_size;
+   u8 *transfer_buffer;
+   u32 transfer_flags;;
+   u32 state;
+   u32 prev_state;
+   u32 urb_size;
+   void *stream_urb;
+   void *cam;  /* back pointer to zr364xx_camera struct */
+   u32 err_count;
+   u32 idx;
+   u32 priority_set;
+};
+
+struct zr364xx_fmt {
+   char *name;
+   u32 fourcc;
+   int depth;
+};
+
+/* image formats.  */
+static const struct zr364xx_fmt formats[] = {
+   {
+   .name = "JPG",
+   .fourcc = V4L2_PIX_FMT_JPEG,
+   .depth = 24
+   }
+};
 
 /* Camera stuff */
 struct zr364xx_camera {
struct usb_device *udev;/* save off the usb device pointer */
struct usb_interface *interface;/* the interface for this device */
struct video_device *vdev;  /* v4l video device */
-   u8 *framebuf;
int nb;
-   unsigned char *buffer;
+   struct zr364xx_bufferi  buffer;
int skip;
-   int brightness;
int width;
int height;
int method;
struct mutex lock;
+   struct mutex open_lock;
int users;
+
+   spinlock_t  slock;
+ 

Re: [PATCH] Implement V4L2_CAP_STREAMING for zr364xx driver

2009-03-28 Thread Lamarque Vieira Souza
Em Saturday 28 March 2009, Hans de Goede escreveu:
> On 03/28/2009 11:11 AM, Lamarque Vieira Souza wrote:
> > This patch implements V4L2_CAP_STREAMING for the zr364xx driver, by
> > converting the driver to use videobuf.
> >
> > Tested with Creative PC-CAM 880.
> >
> > It basically:
> > . implements V4L2_CAP_STREAMING using videobuf;
> >
> > . re-implements V4L2_CAP_READWRITE using videobuf;
> >
> > . copies cam->udev->product to the card field of the v4l2_capability
> > struct. That gives more information to the users about the webcam;
> >
> > . moves the brightness setting code from before requesting a frame (in
> > read_frame) to the vidioc_s_ctrl ioctl. This way the brightness code is
> > executed only when the application requests a change in brightness and
> > not before every frame read;
> >
> > . comments part of zr364xx_vidioc_try_fmt_vid_cap that says that Skype +
> > libv4l do not work.
>
> Note that this may make things work, but is not correct, applications
> which properly honor the field value may get bitten by this. The correct
> fix is to unconditionally set the field value to V4L2_FIELD_NONE.

The part of zr364xx_vidioc_try_fmt_vid_cap which was commented was the 
"if" 
that checks the field value, now the driver does not do the check, it always 
set the field value to V4L2_FIELD_NONE, since that is the only value that the 
card accepts.

> > This patch fixes zr364xx for applications such as mplayer,
> > Kopete+libv4l and Skype+libv4l can make use of the webcam that comes
> > with zr364xx chip.
> >
> > Signed-off-by: Lamarque V. Souza
>
> 
>
> Regards,
>
> Hans


-- 
Lamarque V. Souza
http://www.geographicguide.com/brazil.htm
Linux User #57137 - http://counter.li.org/
--
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