public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <j.w.r.degoede@hhs.nl>
To: Jean-Francois Moine <moinejf@free.fr>
Cc: video4linux-list@redhat.com
Subject: PATCH: gspca-uniform-pixfmt-report.patch
Date: Fri, 04 Jul 2008 09:35:08 +0200	[thread overview]
Message-ID: <486DD2AC.1020902@hhs.nl> (raw)

[-- Attachment #1: Type: text/plain, Size: 611 bytes --]

Hi all,

This patch fixes 3 inconsistencies between the pixfmt's returned by set_fmt
(through try_fmt / and try_fmt) and get_fmt.

* set_fmt (try_fmt) didn't set the pixformat field member
* get_fmt didn't take compression into account when setting sizeimage
* set_fmt (try_fmt) did take compression into account when setting sizeimage,
   but didn't add 600 to sizeimage for the jpeg header, as frame_alloc does

The later 2 are fixed by moving all buffer size calculations to
gspca_get_buff_size and using that everywhere for consistency.

Signed-off-by: Hans de Goede <j.w.r.degoede@hhs.nl>

Regards,

Hans


[-- Attachment #2: gspca-uniform-pixfmt-report.patch --]
[-- Type: text/plain, Size: 3302 bytes --]

This patch fixes 3 inconsistencies between the pixfmt's returned by set_fmt
(through try_fmt / and try_fmt) and get_fmt.

* set_fmt (try_fmt) didn't set the pixformat field member
* get_fmt didn't take compression into account when setting sizeimage
* set_fmt (try_fmt) did take compression into account when setting sizeimage,
  but didn't add 600 to sizeimage for the jpeg header, as frame_alloc does

The later 2 are fixed by moving all buffer size calculations to
gspca_get_buff_size and using that everywhere for consistency.

Signed-off-by: Hans de Goede <j.w.r.degoede@hhs.nl>

diff -r feeaaa9d3ed3 linux/drivers/media/video/gspca/gspca.c
--- a/linux/drivers/media/video/gspca/gspca.c	Thu Jul 03 13:20:58 2008 +0200
+++ b/linux/drivers/media/video/gspca/gspca.c	Fri Jul 04 09:28:31 2008 +0200
@@ -397,14 +397,20 @@
 	return 24;
 }
 
-static int gspca_get_buff_size(struct gspca_dev *gspca_dev)
+static int gspca_get_buff_size(struct gspca_dev *gspca_dev, int mode)
 {
 	unsigned int size;
 
-	size = gspca_dev->width * gspca_dev->height
-				* get_v4l2_depth(gspca_dev->pixfmt) / 8;
+	size =  gspca_dev->cam.cam_mode[mode].width * 
+		gspca_dev->cam.cam_mode[mode].height *
+		get_v4l2_depth(gspca_dev->cam.cam_mode[mode].pixfmt) / 8;
 	if (!size)
 		return -ENOMEM;
+
+	/* if compressed (JPEG), reduce the buffer size */
+	if (gspca_is_compressed(gspca_dev->cam.cam_mode[mode].pixfmt))
+		size = (size * comp_fac) / 100 + 600; /* (+ JPEG header sz) */
+
 	return size;
 }
 
@@ -415,15 +421,12 @@
 	unsigned int frsz;
 	int i;
 
-	frsz = gspca_get_buff_size(gspca_dev);
+	frsz = gspca_get_buff_size(gspca_dev, gspca_dev->curr_mode);
 	if (frsz < 0)
 		return frsz;
 	PDEBUG(D_STREAM, "frame alloc frsz: %d", frsz);
 	if (count > GSPCA_MAX_FRAMES)
 		count = GSPCA_MAX_FRAMES;
-	/* if compressed (JPEG), reduce the buffer size */
-	if (gspca_is_compressed(gspca_dev->pixfmt))
-		frsz = (frsz * comp_fac) / 100 + 600; /* (+ JPEG header sz) */
 	frsz = PAGE_ALIGN(frsz);
 	PDEBUG(D_STREAM, "new fr_sz: %d", frsz);
 	gspca_dev->frsz = frsz;
@@ -802,8 +805,8 @@
 	fmt->fmt.pix.field = V4L2_FIELD_NONE;
 	fmt->fmt.pix.bytesperline = get_v4l2_depth(fmt->fmt.pix.pixelformat)
 					* fmt->fmt.pix.width / 8;
-	fmt->fmt.pix.sizeimage = fmt->fmt.pix.bytesperline
-					* fmt->fmt.pix.height;
+	fmt->fmt.pix.sizeimage = gspca_get_buff_size(gspca_dev,
+							gspca_dev->curr_mode);
 /* (should be in the subdriver) */
 	fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
 	fmt->fmt.pix.priv = 0;
@@ -813,7 +816,7 @@
 static int try_fmt_vid_cap(struct gspca_dev *gspca_dev,
 			struct v4l2_format *fmt)
 {
-	int w, h, mode, mode2, frsz;
+	int w, h, mode, mode2;
 
 	if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
 		return -EINVAL;
@@ -855,12 +858,10 @@
 	}
 	fmt->fmt.pix.width = gspca_dev->cam.cam_mode[mode].width;
 	fmt->fmt.pix.height = gspca_dev->cam.cam_mode[mode].height;
+	fmt->fmt.pix.field = V4L2_FIELD_NONE;
 	fmt->fmt.pix.bytesperline = get_v4l2_depth(fmt->fmt.pix.pixelformat)
 					* fmt->fmt.pix.width / 8;
-	frsz = fmt->fmt.pix.bytesperline * fmt->fmt.pix.height;
-	if (gspca_is_compressed(fmt->fmt.pix.pixelformat))
-		frsz = (frsz * comp_fac) / 100;
-	fmt->fmt.pix.sizeimage = frsz;
+	fmt->fmt.pix.sizeimage = gspca_get_buff_size(gspca_dev, mode);
 	return mode;			/* used when s_fmt */
 }
 

[-- Attachment #3: Type: text/plain, Size: 164 bytes --]

--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

                 reply	other threads:[~2008-07-04  7:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=486DD2AC.1020902@hhs.nl \
    --to=j.w.r.degoede@hhs.nl \
    --cc=moinejf@free.fr \
    --cc=video4linux-list@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox