PATCH: gspcav2-0.2.13-allow-unrequest-buffers.patch

Hans de Goede <[email protected]> Tue, 10 Jun 2008 23:41:09 +0200
Newsgroups gmane.linux.drivers.spca50x.devel
Message-ID <[email protected]>
Hi Jean (et all),

I've been testing my v4l1-compat wrapper, with gspcav2 with the helper disabled.

It works, but changing the capture size on the fly in camorama didn't work. 
This is caused by gspcav2 not supporting unrequesting of the buffers (aka 
requesting 0 buffers), as most (all?) other v4l2 drivers does.

This patch adds support for unrequesting the buffers to gspcav2. It also moves 
the buffersize check from try_fmt, to s_fmt. Try format is merely meant to 
query camera devices.

Last I've also sneeked in a small pac207 fix, I had the sof_marker declared as 
char (iow signed) and was comparing this in the sof_detect function with an 
unsigned char, this used to work, but gcc-4.3 correctly causes this to fail 
(both first get promoted to an int as they should).

Regards,

Hans

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php

_______________________________________________
Spca50x-devs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spca50x-devs
gspcav2-0.2.13-allow-unrequest-buffers.patch (text/plain, 2.6 KB)
--- gspcav2-0.2.13/gspca.c	2008-05-26 19:25:59.000000000 +0200
+++ gspcav2-0.2.13.new/gspca.c	2008-06-10 23:31:57.000000000 +0200
@@ -1266,9 +1268,6 @@
 	frsz = fmt->fmt.pix.bytesperline * fmt->fmt.pix.height;
 	if (gspca_is_compressed(fmt->fmt.pix.pixelformat))
 		frsz = (frsz * comp_fac) / 100;
-	if (gspca_dev->nframes != 0
-	    && frsz > gspca_dev->frsz)
-		return -EINVAL;
 	fmt->fmt.pix.sizeimage = frsz;
 	return mode;			/* used when s_fmt */
 }
@@ -1306,6 +1305,12 @@
 	if (ret < 0)
 		goto out;
 
+	if (gspca_dev->nframes != 0
+	    && fmt->fmt.pix.sizeimage > gspca_dev->frsz) {
+		ret = -EINVAL;
+		goto out;
+	}
+
 #ifndef GSPCA_HLP
 	if (ret == gspca_dev->curr_mode)
 		goto out;			/* same mode */
@@ -1345,6 +1350,8 @@
 		hlp->gspca_dev = 0;
 #endif /*GSPCA_HLP*/
 
+	ret = 0;
+
 out:
 	mutex_unlock(&gspca_dev->queue_lock);
 	return ret;
@@ -1566,7 +1573,7 @@
 			  struct v4l2_requestbuffers *rb)
 {
 	struct gspca_dev *gspca_dev = priv;
-	int ret;
+	int i, ret = 0;
 
 	PDEBUG(D_STREAM, "reqbufs %d", rb->count);
 	if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
@@ -1583,20 +1590,33 @@
 	default:
 		return -EINVAL;
 	}
-	if (rb->count == 0)
-		return -EINVAL;
 	if (mutex_lock_interruptible(&gspca_dev->queue_lock))
 		return -ERESTARTSYS;
-	if (gspca_dev->capt_file != 0	/* only one file may do capture */
-	    || gspca_dev->nframes != 0) {
+
+	for (i = 0; i < gspca_dev->nframes; i++) {
+		if (gspca_dev->frame[i].vma_use_count) {
+			ret = -EBUSY;
+			goto out;
+		}
+	}
+
+	/* only one file may do capture */
+	if ((gspca_dev->capt_file != 0 && gspca_dev->capt_file != file) ||
+	    gspca_dev->streaming) {
 		ret = -EBUSY;
 		goto out;
 	}
-	gspca_dev->memory = rb->memory;
-	ret = frame_alloc(gspca_dev, rb->count);
-	if (ret == 0) {
-		rb->count = gspca_dev->nframes;
-		gspca_dev->capt_file = file;
+
+	if (rb->count == 0) { /* unrequest? */
+		frame_free(gspca_dev);
+		gspca_dev->capt_file = 0;
+	} else {
+		gspca_dev->memory = rb->memory;
+		ret = frame_alloc(gspca_dev, rb->count);
+		if (ret == 0) {
+			rb->count = gspca_dev->nframes;
+			gspca_dev->capt_file = file;
+		}
 	}
 out:
 	mutex_unlock(&gspca_dev->queue_lock);
--- gspcav2-0.2.13/pac207.c	2008-05-24 11:32:51.000000000 +0200
+++ gspcav2-0.2.13.new/pac207.c	2008-06-09 23:19:45.000000000 +0200
@@ -188,7 +188,7 @@
 			/* 48 reg_72 Rate Control end BalSize_4a =0x36 */
 static const __u8 PacReg72[] = { 0x00, 0x00, 0x36, 0x00 };
 
-static const char pac207_sof_marker[5] = { 0xff, 0xff, 0x00, 0xff, 0x96 };
+static const unsigned char pac207_sof_marker[5] = { 0xff, 0xff, 0x00, 0xff, 0x96 };
 
 int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index,
 	const u8 *buffer, u16 length)