All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [resend] usbvision: disable scaling for Nogatech MicroCam
@ 2011-07-22 20:00 Ondrej Zary
  2011-07-22 20:06 ` Devin Heitmueller
  0 siblings, 1 reply; 10+ messages in thread
From: Ondrej Zary @ 2011-07-22 20:00 UTC (permalink / raw)
  To: Joerg Heckenbach
  Cc: Dwaine Garden, linux-media, Kernel development list, Hans Verkuil

Scaling causes bad artifacts (horizontal lines) with compression at least
with Nogatech MicroCam so disable it (for this HW).

This also fixes messed up image with some programs (Cheese with 160x120,
Adobe Flash). HW seems to support only image widths that are multiple of 64
but the driver does not account that in vidioc_try_fmt_vid_cap(). Cheese
calls try_fmt with 160x120, succeeds and then assumes that it really gets
data in that resolution - but it gets 128x120 instead. Don't know if this
affects other usbvision devices, it would be great if someone could test it.

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>

diff -urp linux-2.6.39-rc2-/drivers/media/video/usbvision//usbvision-video.c linux-2.6.39-rc2/drivers/media/video/usbvision/usbvision-video.c
--- linux-2.6.39-rc2-/drivers/media/video/usbvision//usbvision-video.c	2011-07-16 16:42:35.000000000 +0200
+++ linux-2.6.39-rc2/drivers/media/video/usbvision/usbvision-video.c	2011-07-16 16:36:43.000000000 +0200
@@ -924,6 +924,11 @@ static int vidioc_try_fmt_vid_cap(struct
 	RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
 	RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
 
+	if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) {
+		vf->fmt.pix.width = MAX_FRAME_WIDTH;
+		vf->fmt.pix.height = MAX_FRAME_HEIGHT;
+	}
+
 	vf->fmt.pix.bytesperline = vf->fmt.pix.width*
 		usbvision->palette.bytes_per_pixel;
 	vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height;
@@ -952,6 +957,11 @@ static int vidioc_s_fmt_vid_cap(struct f
 
 	usbvision->cur_frame = NULL;
 
+	if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) {
+		vf->fmt.pix.width = MAX_FRAME_WIDTH;
+		vf->fmt.pix.height = MAX_FRAME_HEIGHT;
+	}
+
 	/* by now we are committed to the new data... */
 	usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height);
 

-- 
Ondrej Zary

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] [resend] usbvision: disable scaling for Nogatech MicroCam
  2011-07-22 20:00 [PATCH] [resend] usbvision: disable scaling for Nogatech MicroCam Ondrej Zary
@ 2011-07-22 20:06 ` Devin Heitmueller
  2011-07-22 21:22   ` Ondrej Zary
  0 siblings, 1 reply; 10+ messages in thread
From: Devin Heitmueller @ 2011-07-22 20:06 UTC (permalink / raw)
  To: Ondrej Zary
  Cc: Joerg Heckenbach, Dwaine Garden, linux-media,
	Kernel development list, Hans Verkuil

On Fri, Jul 22, 2011 at 4:00 PM, Ondrej Zary <linux@rainbow-software.org> wrote:
> Scaling causes bad artifacts (horizontal lines) with compression at least
> with Nogatech MicroCam so disable it (for this HW).
>
> This also fixes messed up image with some programs (Cheese with 160x120,
> Adobe Flash). HW seems to support only image widths that are multiple of 64
> but the driver does not account that in vidioc_try_fmt_vid_cap(). Cheese
> calls try_fmt with 160x120, succeeds and then assumes that it really gets
> data in that resolution - but it gets 128x120 instead. Don't know if this
> affects other usbvision devices, it would be great if someone could test it.
>
> Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
>
> diff -urp linux-2.6.39-rc2-/drivers/media/video/usbvision//usbvision-video.c linux-2.6.39-rc2/drivers/media/video/usbvision/usbvision-video.c
> --- linux-2.6.39-rc2-/drivers/media/video/usbvision//usbvision-video.c  2011-07-16 16:42:35.000000000 +0200
> +++ linux-2.6.39-rc2/drivers/media/video/usbvision/usbvision-video.c    2011-07-16 16:36:43.000000000 +0200
> @@ -924,6 +924,11 @@ static int vidioc_try_fmt_vid_cap(struct
>        RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
>        RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
>
> +       if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) {
> +               vf->fmt.pix.width = MAX_FRAME_WIDTH;
> +               vf->fmt.pix.height = MAX_FRAME_HEIGHT;
> +       }
> +
>        vf->fmt.pix.bytesperline = vf->fmt.pix.width*
>                usbvision->palette.bytes_per_pixel;
>        vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height;
> @@ -952,6 +957,11 @@ static int vidioc_s_fmt_vid_cap(struct f
>
>        usbvision->cur_frame = NULL;
>
> +       if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) {
> +               vf->fmt.pix.width = MAX_FRAME_WIDTH;
> +               vf->fmt.pix.height = MAX_FRAME_HEIGHT;
> +       }
> +
>        /* by now we are committed to the new data... */
>        usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height);
>
>
> --
> Ondrej Zary

Hello Ondrej,

Drivers are permitted to return a different resolution than what the
application provided in the S_FMT call.  It is the responsibility of
the application to look at the struct after the ioctl() call and if
the values are not what it expects to then accommodate the change.

In other words, this sounds like a bug in Cheese.

Devin

-- 
Devin J. Heitmueller - Kernel Labs
http://www.kernellabs.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] [resend] usbvision: disable scaling for Nogatech MicroCam
  2011-07-22 20:06 ` Devin Heitmueller
@ 2011-07-22 21:22   ` Ondrej Zary
  2011-07-22 21:31     ` Devin Heitmueller
  0 siblings, 1 reply; 10+ messages in thread
From: Ondrej Zary @ 2011-07-22 21:22 UTC (permalink / raw)
  To: Devin Heitmueller
  Cc: Joerg Heckenbach, Dwaine Garden, linux-media,
	Kernel development list, Hans Verkuil

On Friday 22 July 2011 22:06:59 Devin Heitmueller wrote:
> On Fri, Jul 22, 2011 at 4:00 PM, Ondrej Zary <linux@rainbow-software.org> wrote:
> > Scaling causes bad artifacts (horizontal lines) with compression at least
> > with Nogatech MicroCam so disable it (for this HW).
> >
> > This also fixes messed up image with some programs (Cheese with 160x120,
> > Adobe Flash). HW seems to support only image widths that are multiple of 64
> > but the driver does not account that in vidioc_try_fmt_vid_cap(). Cheese
> > calls try_fmt with 160x120, succeeds and then assumes that it really gets
> > data in that resolution - but it gets 128x120 instead. Don't know if this
> > affects other usbvision devices, it would be great if someone could test it.
> >
> > Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
> >
> > diff -urp linux-2.6.39-rc2-/drivers/media/video/usbvision//usbvision-video.c linux-2.6.39-rc2/drivers/media/video/usbvision/usbvision-video.c
> > --- linux-2.6.39-rc2-/drivers/media/video/usbvision//usbvision-video.c  2011-07-16 16:42:35.000000000 +0200
> > +++ linux-2.6.39-rc2/drivers/media/video/usbvision/usbvision-video.c    2011-07-16 16:36:43.000000000 +0200
> > @@ -924,6 +924,11 @@ static int vidioc_try_fmt_vid_cap(struct
> >        RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
> >        RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
> >
> > +       if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) {
> > +               vf->fmt.pix.width = MAX_FRAME_WIDTH;
> > +               vf->fmt.pix.height = MAX_FRAME_HEIGHT;
> > +       }
> > +
> >        vf->fmt.pix.bytesperline = vf->fmt.pix.width*
> >                usbvision->palette.bytes_per_pixel;
> >        vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height;
> > @@ -952,6 +957,11 @@ static int vidioc_s_fmt_vid_cap(struct f
> >
> >        usbvision->cur_frame = NULL;
> >
> > +       if (usbvision_device_data[usbvision->dev_model].codec == CODEC_WEBCAM) {
> > +               vf->fmt.pix.width = MAX_FRAME_WIDTH;
> > +               vf->fmt.pix.height = MAX_FRAME_HEIGHT;
> > +       }
> > +
> >        /* by now we are committed to the new data... */
> >        usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height);
> >
> >
> > --
> > Ondrej Zary
> 
> Hello Ondrej,
> 
> Drivers are permitted to return a different resolution than what the
> application provided in the S_FMT call.  It is the responsibility of
> the application to look at the struct after the ioctl() call and if
> the values are not what it expects to then accommodate the change.
> 
> In other words, this sounds like a bug in Cheese.

Seems that this bug is widespread - the same problem appears also in guvcview
and adobe flash. I think that the driver is broken too - it should return
corrected resolution in TRY_FMT.

> Devin
> 



-- 
Ondrej Zary

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] [resend] usbvision: disable scaling for Nogatech MicroCam
  2011-07-22 21:22   ` Ondrej Zary
@ 2011-07-22 21:31     ` Devin Heitmueller
  2011-07-22 21:44       ` Ondrej Zary
  0 siblings, 1 reply; 10+ messages in thread
From: Devin Heitmueller @ 2011-07-22 21:31 UTC (permalink / raw)
  To: Ondrej Zary
  Cc: Joerg Heckenbach, Dwaine Garden, linux-media,
	Kernel development list, Hans Verkuil

On Fri, Jul 22, 2011 at 5:22 PM, Ondrej Zary <linux@rainbow-software.org> wrote:
> Seems that this bug is widespread - the same problem appears also in guvcview
> and adobe flash. I think that the driver is broken too - it should return
> corrected resolution in TRY_FMT.

Well, if the driver does not return the resolution it is actually
capturing in, then that indeed is a driver bug.  That's a different
issue though than what your patch proposed.

You should make the TRY_FMT call specifying an invalid resolution and
see if it returns the real resolution the device will capture at.  If
it doesn't, then fix *that* bug.

The application needs to know the capturing resolution, so it's
possible that it does properly handle the driver passing back the real
resolution and the driver is at fault, in which case no change is
needed to the app at all.

Devin

-- 
Devin J. Heitmueller - Kernel Labs
http://www.kernellabs.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] [resend] usbvision: disable scaling for Nogatech MicroCam
  2011-07-22 21:31     ` Devin Heitmueller
@ 2011-07-22 21:44       ` Ondrej Zary
  2011-07-27 15:03         ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 10+ messages in thread
From: Ondrej Zary @ 2011-07-22 21:44 UTC (permalink / raw)
  To: Devin Heitmueller
  Cc: Joerg Heckenbach, Dwaine Garden, linux-media,
	Kernel development list, Hans Verkuil

On Friday 22 July 2011 23:31:46 Devin Heitmueller wrote:
> On Fri, Jul 22, 2011 at 5:22 PM, Ondrej Zary <linux@rainbow-software.org> wrote:
> > Seems that this bug is widespread - the same problem appears also in guvcview
> > and adobe flash. I think that the driver is broken too - it should return
> > corrected resolution in TRY_FMT.
> 
> Well, if the driver does not return the resolution it is actually
> capturing in, then that indeed is a driver bug.  That's a different
> issue though than what your patch proposed.
> 
> You should make the TRY_FMT call specifying an invalid resolution and
> see if it returns the real resolution the device will capture at.  If
> it doesn't, then fix *that* bug.

It does not, there's no code that would do that. I actually fixed that only
to find out that the scaling is unusable at least with the MicroCam because
of black horizontal lines that appear in the image (amount of the lines
depend on the scaling factor). So I just disabled the scaling completely for
MicroCam.

I also don't know if the multiple-of-64 width limit is valid for all
usbvision devices - that's why I haven't posted patch to fix this.

> The application needs to know the capturing resolution, so it's
> possible that it does properly handle the driver passing back the real
> resolution and the driver is at fault, in which case no change is
> needed to the app at all.
> 
> Devin
> 



-- 
Ondrej Zary

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] [resend] usbvision: disable scaling for Nogatech MicroCam
  2011-07-22 21:44       ` Ondrej Zary
@ 2011-07-27 15:03         ` Mauro Carvalho Chehab
  2011-07-27 17:15           ` Anca Emanuel
  2011-08-01 18:50           ` Ondrej Zary
  0 siblings, 2 replies; 10+ messages in thread
From: Mauro Carvalho Chehab @ 2011-07-27 15:03 UTC (permalink / raw)
  To: Ondrej Zary
  Cc: Devin Heitmueller, Joerg Heckenbach, Dwaine Garden, linux-media,
	Kernel development list, Hans Verkuil

Em 22-07-2011 18:44, Ondrej Zary escreveu:
> On Friday 22 July 2011 23:31:46 Devin Heitmueller wrote:
>> On Fri, Jul 22, 2011 at 5:22 PM, Ondrej Zary <linux@rainbow-software.org> wrote:
>>> Seems that this bug is widespread - the same problem appears also in guvcview
>>> and adobe flash. I think that the driver is broken too - it should return
>>> corrected resolution in TRY_FMT.
>>
>> Well, if the driver does not return the resolution it is actually
>> capturing in, then that indeed is a driver bug.  That's a different
>> issue though than what your patch proposed.
>>
>> You should make the TRY_FMT call specifying an invalid resolution and
>> see if it returns the real resolution the device will capture at.  If
>> it doesn't, then fix *that* bug.
> 
> It does not, there's no code that would do that. I actually fixed that only
> to find out that the scaling is unusable at least with the MicroCam because
> of black horizontal lines that appear in the image (amount of the lines
> depend on the scaling factor). So I just disabled the scaling completely for
> MicroCam.
> 
> I also don't know if the multiple-of-64 width limit is valid for all
> usbvision devices - that's why I haven't posted patch to fix this.
> 
>> The application needs to know the capturing resolution, so it's
>> possible that it does properly handle the driver passing back the real
>> resolution and the driver is at fault, in which case no change is
>> needed to the app at all.

Well, for sure you don't need to touch at s_fmt, as it calls try_fmt. Also,
if the problem is that the scaler requrires that the vertical resolution to be
multiple of some limit, a patch like the one bellow would do a better job:

diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index 5a74f5e..6907eff 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -922,6 +922,9 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
 	RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
 	RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
 
+	/* FIXME: please correct the minimum resolution here */
+	vf->fmt.pix.width &= ~0x01;
+
 	vf->fmt.pix.bytesperline = vf->fmt.pix.width*
 		usbvision->palette.bytes_per_pixel;
 	vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height;

Some scalers require an even vertical resolution. So, you'll need to adjust the
above, according with the restrictions you may have on the scaler your webcam
has.

Btw, V4L2 core defines a macro for such type of adjustments. For example,
em28xx uses it as:

		/* width must even because of the YUYV format
		   height must be even because of interlacing */
		v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh,
				      1, 0);

(

So, a better fix would be to remove the RESTRICT_TO_RANGE() calls, and use
the v4l_bound_align_image() macro instead, filled with the needed restrictions,
like:
	v4l_bound_align_image(&width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH, 1,
			      &height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT, 0);


-

[usbvision] Fix width/height scaling limits

It assumes that both just width is required to be even number.

NOT TESTED.

Signed-of-by: Mauro Carvalho Chehab <mchehab@redhat.com>

diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index 5a74f5e..41d3b47 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -919,8 +919,11 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
 	/* robustness */
 	if (format_idx == USBVISION_SUPPORTED_PALETTES)
 		return -EINVAL;
-	RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
-	RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
+
+	v4l_bound_align_image(&vf->fmt.pix.width,
+			      MIN_FRAME_WIDTH, MAX_FRAME_WIDTH, 1,
+			      &vf->fmt.pix.height,
+			      MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT, 0, 0);
 
 	vf->fmt.pix.bytesperline = vf->fmt.pix.width*
 		usbvision->palette.bytes_per_pixel;

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] [resend] usbvision: disable scaling for Nogatech MicroCam
  2011-07-27 15:03         ` Mauro Carvalho Chehab
@ 2011-07-27 17:15           ` Anca Emanuel
  2011-07-27 18:33             ` Mauro Carvalho Chehab
  2011-08-01 18:50           ` Ondrej Zary
  1 sibling, 1 reply; 10+ messages in thread
From: Anca Emanuel @ 2011-07-27 17:15 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: linux-media

Offtopic. Mauro is your pull request ready ? the merge window is open.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] [resend] usbvision: disable scaling for Nogatech MicroCam
  2011-07-27 17:15           ` Anca Emanuel
@ 2011-07-27 18:33             ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 10+ messages in thread
From: Mauro Carvalho Chehab @ 2011-07-27 18:33 UTC (permalink / raw)
  To: Anca Emanuel; +Cc: linux-media

Em 27-07-2011 14:15, Anca Emanuel escreveu:
> Offtopic. Mauro is your pull request ready ? the merge window is open.

Working on it.

Cheers,
Mauro

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] [resend] usbvision: disable scaling for Nogatech MicroCam
  2011-07-27 15:03         ` Mauro Carvalho Chehab
  2011-07-27 17:15           ` Anca Emanuel
@ 2011-08-01 18:50           ` Ondrej Zary
  2011-08-01 20:19             ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 10+ messages in thread
From: Ondrej Zary @ 2011-08-01 18:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Devin Heitmueller, Joerg Heckenbach, Dwaine Garden, linux-media,
	Kernel development list, Hans Verkuil

On Wednesday 27 July 2011 17:03:06 Mauro Carvalho Chehab wrote:
> Em 22-07-2011 18:44, Ondrej Zary escreveu:
> > On Friday 22 July 2011 23:31:46 Devin Heitmueller wrote:
> >> On Fri, Jul 22, 2011 at 5:22 PM, Ondrej Zary <linux@rainbow-software.org> wrote:
> >>> Seems that this bug is widespread - the same problem appears also in guvcview
> >>> and adobe flash. I think that the driver is broken too - it should return
> >>> corrected resolution in TRY_FMT.
> >>
> >> Well, if the driver does not return the resolution it is actually
> >> capturing in, then that indeed is a driver bug.  That's a different
> >> issue though than what your patch proposed.
> >>
> >> You should make the TRY_FMT call specifying an invalid resolution and
> >> see if it returns the real resolution the device will capture at.  If
> >> it doesn't, then fix *that* bug.
> > 
> > It does not, there's no code that would do that. I actually fixed that only
> > to find out that the scaling is unusable at least with the MicroCam because
> > of black horizontal lines that appear in the image (amount of the lines
> > depend on the scaling factor). So I just disabled the scaling completely for
> > MicroCam.
> > 
> > I also don't know if the multiple-of-64 width limit is valid for all
> > usbvision devices - that's why I haven't posted patch to fix this.
> > 
> >> The application needs to know the capturing resolution, so it's
> >> possible that it does properly handle the driver passing back the real
> >> resolution and the driver is at fault, in which case no change is
> >> needed to the app at all.
> 
> Well, for sure you don't need to touch at s_fmt, as it calls try_fmt. Also,
> if the problem is that the scaler requrires that the vertical resolution to be
> multiple of some limit, a patch like the one bellow would do a better job:
> 
> diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
> index 5a74f5e..6907eff 100644
> --- a/drivers/media/video/usbvision/usbvision-video.c
> +++ b/drivers/media/video/usbvision/usbvision-video.c
> @@ -922,6 +922,9 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
>  	RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
>  	RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
>  
> +	/* FIXME: please correct the minimum resolution here */
> +	vf->fmt.pix.width &= ~0x01;
> +
>  	vf->fmt.pix.bytesperline = vf->fmt.pix.width*
>  		usbvision->palette.bytes_per_pixel;
>  	vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height;
> 
> Some scalers require an even vertical resolution. So, you'll need to adjust the
> above, according with the restrictions you may have on the scaler your webcam
> has.
> 
> Btw, V4L2 core defines a macro for such type of adjustments. For example,
> em28xx uses it as:
> 
> 		/* width must even because of the YUYV format
> 		   height must be even because of interlacing */
> 		v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh,
> 				      1, 0);
> 
> (
> 
> So, a better fix would be to remove the RESTRICT_TO_RANGE() calls, and use
> the v4l_bound_align_image() macro instead, filled with the needed restrictions,
> like:
> 	v4l_bound_align_image(&width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH, 1,
> 			      &height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT, 0);
> 
> 
> -
> 
> [usbvision] Fix width/height scaling limits
> 
> It assumes that both just width is required to be even number.

Width on the Nogatech MicroCam is limited to multiples of 64 (e.g. if you set
the width to 160, you get 128 instead). But the scaled output is useless
because of black horizontal lines that scaling produces with compression
(which is enabled by default). Probably nobody wants to disable the
compression as the framerate is very low without it.

I don't know about other usbvision devices. We shouldn't change the code for
all of them without testing.


> NOT TESTED.
> 
> Signed-of-by: Mauro Carvalho Chehab <mchehab@redhat.com>
> 
> diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
> index 5a74f5e..41d3b47 100644
> --- a/drivers/media/video/usbvision/usbvision-video.c
> +++ b/drivers/media/video/usbvision/usbvision-video.c
> @@ -919,8 +919,11 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
>  	/* robustness */
>  	if (format_idx == USBVISION_SUPPORTED_PALETTES)
>  		return -EINVAL;
> -	RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
> -	RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
> +
> +	v4l_bound_align_image(&vf->fmt.pix.width,
> +			      MIN_FRAME_WIDTH, MAX_FRAME_WIDTH, 1,
> +			      &vf->fmt.pix.height,
> +			      MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT, 0, 0);
>  
>  	vf->fmt.pix.bytesperline = vf->fmt.pix.width*
>  		usbvision->palette.bytes_per_pixel;
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 



-- 
Ondrej Zary

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] [resend] usbvision: disable scaling for Nogatech MicroCam
  2011-08-01 18:50           ` Ondrej Zary
@ 2011-08-01 20:19             ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 10+ messages in thread
From: Mauro Carvalho Chehab @ 2011-08-01 20:19 UTC (permalink / raw)
  To: Ondrej Zary
  Cc: Devin Heitmueller, Joerg Heckenbach, Dwaine Garden, linux-media,
	Kernel development list, Hans Verkuil

Em 01-08-2011 15:50, Ondrej Zary escreveu:
> On Wednesday 27 July 2011 17:03:06 Mauro Carvalho Chehab wrote:
>> Em 22-07-2011 18:44, Ondrej Zary escreveu:
>>> On Friday 22 July 2011 23:31:46 Devin Heitmueller wrote:
>>>> On Fri, Jul 22, 2011 at 5:22 PM, Ondrej Zary <linux@rainbow-software.org> wrote:
>>>>> Seems that this bug is widespread - the same problem appears also in guvcview
>>>>> and adobe flash. I think that the driver is broken too - it should return
>>>>> corrected resolution in TRY_FMT.
>>>>
>>>> Well, if the driver does not return the resolution it is actually
>>>> capturing in, then that indeed is a driver bug.  That's a different
>>>> issue though than what your patch proposed.
>>>>
>>>> You should make the TRY_FMT call specifying an invalid resolution and
>>>> see if it returns the real resolution the device will capture at.  If
>>>> it doesn't, then fix *that* bug.
>>>
>>> It does not, there's no code that would do that. I actually fixed that only
>>> to find out that the scaling is unusable at least with the MicroCam because
>>> of black horizontal lines that appear in the image (amount of the lines
>>> depend on the scaling factor). So I just disabled the scaling completely for
>>> MicroCam.
>>>
>>> I also don't know if the multiple-of-64 width limit is valid for all
>>> usbvision devices - that's why I haven't posted patch to fix this.
>>>
>>>> The application needs to know the capturing resolution, so it's
>>>> possible that it does properly handle the driver passing back the real
>>>> resolution and the driver is at fault, in which case no change is
>>>> needed to the app at all.
>>
>> Well, for sure you don't need to touch at s_fmt, as it calls try_fmt. Also,
>> if the problem is that the scaler requrires that the vertical resolution to be
>> multiple of some limit, a patch like the one bellow would do a better job:
>>
>> diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
>> index 5a74f5e..6907eff 100644
>> --- a/drivers/media/video/usbvision/usbvision-video.c
>> +++ b/drivers/media/video/usbvision/usbvision-video.c
>> @@ -922,6 +922,9 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
>>  	RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
>>  	RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
>>  
>> +	/* FIXME: please correct the minimum resolution here */
>> +	vf->fmt.pix.width &= ~0x01;
>> +
>>  	vf->fmt.pix.bytesperline = vf->fmt.pix.width*
>>  		usbvision->palette.bytes_per_pixel;
>>  	vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height;
>>
>> Some scalers require an even vertical resolution. So, you'll need to adjust the
>> above, according with the restrictions you may have on the scaler your webcam
>> has.
>>
>> Btw, V4L2 core defines a macro for such type of adjustments. For example,
>> em28xx uses it as:
>>
>> 		/* width must even because of the YUYV format
>> 		   height must be even because of interlacing */
>> 		v4l_bound_align_image(&width, 48, maxw, 1, &height, 32, maxh,
>> 				      1, 0);
>>
>> (
>>
>> So, a better fix would be to remove the RESTRICT_TO_RANGE() calls, and use
>> the v4l_bound_align_image() macro instead, filled with the needed restrictions,
>> like:
>> 	v4l_bound_align_image(&width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH, 1,
>> 			      &height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT, 0);
>>
>>
>> -
>>
>> [usbvision] Fix width/height scaling limits
>>
>> It assumes that both just width is required to be even number.
> 
> Width on the Nogatech MicroCam is limited to multiples of 64 (e.g. if you set
> the width to 160, you get 128 instead). But the scaled output is useless
> because of black horizontal lines that scaling produces with compression
> (which is enabled by default).

Ok. This seems to be either a sensor or a bridge problem. So, it is not specific
to Nogatech.

> Probably nobody wants to disable the
> compression as the framerate is very low without it.

Yet, it may make sense for some applications, like surveillance cameras or
telescopes. If the driver already supports compression to be disabled, maybe
the right thing to do would be to allow scaling only if compression is disabled,
for the devices that have the same bridge and sensor.
> 
> I don't know about other usbvision devices. We shouldn't change the code for
> all of them without testing.
> 
> 
>> NOT TESTED.
>>
>> Signed-of-by: Mauro Carvalho Chehab <mchehab@redhat.com>
>>
>> diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
>> index 5a74f5e..41d3b47 100644
>> --- a/drivers/media/video/usbvision/usbvision-video.c
>> +++ b/drivers/media/video/usbvision/usbvision-video.c
>> @@ -919,8 +919,11 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
>>  	/* robustness */
>>  	if (format_idx == USBVISION_SUPPORTED_PALETTES)
>>  		return -EINVAL;
>> -	RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
>> -	RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
>> +
>> +	v4l_bound_align_image(&vf->fmt.pix.width,
>> +			      MIN_FRAME_WIDTH, MAX_FRAME_WIDTH, 1,
>> +			      &vf->fmt.pix.height,
>> +			      MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT, 0, 0);
>>  
>>  	vf->fmt.pix.bytesperline = vf->fmt.pix.width*
>>  		usbvision->palette.bytes_per_pixel;
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/
>>
> 
> 
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-08-01 20:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-22 20:00 [PATCH] [resend] usbvision: disable scaling for Nogatech MicroCam Ondrej Zary
2011-07-22 20:06 ` Devin Heitmueller
2011-07-22 21:22   ` Ondrej Zary
2011-07-22 21:31     ` Devin Heitmueller
2011-07-22 21:44       ` Ondrej Zary
2011-07-27 15:03         ` Mauro Carvalho Chehab
2011-07-27 17:15           ` Anca Emanuel
2011-07-27 18:33             ` Mauro Carvalho Chehab
2011-08-01 18:50           ` Ondrej Zary
2011-08-01 20:19             ` Mauro Carvalho Chehab

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.