Web lists-archives.com

[Spca50x-devs] gspcav2 patch: don't do frame conversion in the spca501 driver




Hi JF,

The attached patch removes frame conversion in the spca501 driver, libv4l can handle this.

Regards,

Hans
Only in gspcav2-2.0.4: Module.markers
Only in gspcav2-2.0.4: gspca_hlp
Only in gspcav2-2.0.4: modules.order
diff -ur gspcav2-2.0.4.orig/spca501.c gspcav2-2.0.4/spca501.c
--- gspcav2-2.0.4.orig/spca501.c	2008-06-27 10:27:14.000000000 +0200
+++ gspcav2-2.0.4/spca501.c	2008-06-30 20:41:27.000000000 +0200
@@ -34,11 +34,6 @@
 struct sd {
 	struct gspca_dev gspca_dev;	/* !! must be the first item */
 
-	int buflen;
-	__u8 tmpbuf[640 * 480 * 2];	/* YYUV per line */
-	__u8 tmpbuf2[640 * 480 * 2];	/* YUYV or YUV420 */
-	__u32 pixfmt;
-
 	unsigned short contrast;
 	__u8 brightness;
 	__u8 colors;
@@ -107,12 +102,9 @@
 };
 
 static struct cam_mode vga_mode[] = {
-	{V4L2_PIX_FMT_YUYV, 160, 120, 2},
-	{V4L2_PIX_FMT_YUV420, 160, 120, 2},
-	{V4L2_PIX_FMT_YUYV, 320, 240, 1},
-	{V4L2_PIX_FMT_YUV420, 320, 240, 1},
-	{V4L2_PIX_FMT_YUYV, 640, 480, 0},
-	{V4L2_PIX_FMT_YUV420, 640, 480, 0},
+	{V4L2_PIX_FMT_SPCA501, 160, 120, 2},
+	{V4L2_PIX_FMT_SPCA501, 320, 240, 1},
+	{V4L2_PIX_FMT_SPCA501, 640, 480, 0},
 };
 
 #define SPCA50X_REG_USB 0x2	/* spca505 501 */
@@ -2051,12 +2043,10 @@
 static void sd_start(struct gspca_dev *gspca_dev)
 {
 	struct usb_device *dev = gspca_dev->dev;
-	struct sd *sd = (struct sd *) gspca_dev;
 	int mode;
 
 	/* memorize the wanted pixel format */
 	mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].mode;
-	sd->pixfmt = gspca_dev->cam.cam_mode[mode].pixfmt;
 
 	/* Enable ISO packet machine CTRL reg=2,
 	 * index=1 bitmask=0x2 (bit ordinal 1) */
@@ -2076,7 +2066,7 @@
 	reg_write(dev, SPCA501_REG_CTLRL, 0x01, 0x2);
 
 	/* HDG atleast the Intel CreateAndShare needs to have one of its
-	 * brightness / contrast / color set otherwise it assumes wath seems
+	 * brightness / contrast / color set otherwise it assumes what seems
 	 * max contrast. Note that strange enough setting any of these is
 	 * enough to fix the max contrast problem, to be sure we set all 3 */
 	setbrightness(gspca_dev);
@@ -2101,109 +2091,25 @@
 	reg_write(gspca_dev->dev, SPCA501_REG_CTLRL, 0x05, 0x00);
 }
 
-/* convert YUYV per line to YUV420 (YUV 4:2:0 planar) */
-static void yuv420_decode(__u8 *out,
-			__u8 *in,
-			int width,
-			int height)
-{
-	__u8 *Ui, *Vi, *yi, *yi1;
-	__u8 *Yout, *Yout1, *Uout, *Vout;
-	int i, j;
-
-	yi = in;
-	for (i = 0; i < height; i += 2) {
-		Yout = out + i * width;
-		Yout1 = out + (i + 1) * width;
-		Uout = out + width * height + i * width / 4;
-		Vout = out + width * height + width * height / 4
-			+ i * width / 4;
-		Ui = yi + width;
-		yi1 = Ui + width / 2;
-		Vi = yi1 + width;
-		for (j = width / 2; --j >= 0; ) {
-			*Yout++ = 128 + *yi++;
-			*Yout++ = 128 + *yi++;
-			*Yout1++ = 128 + *yi1++;
-			*Yout1++ = 128 + *yi1++;
-			*Uout++ = 128 + *Ui++;
-			*Vout++ = 128 + *Vi++;
-		}
-		yi += width * 2;
-	}
-}
-
-/* convert YUYV per line to YUYV (YUV 4:2:2) */
-static void yuyv_decode(__u8 *out,
-			__u8 *in,
-			int width,
-			int height)
-{
-	__u8 *Ui, *Vi, *yi, *yi1;
-	__u8 *out1;
-	int i, j;
-
-	yi = in;
-	for (i = height / 2; --i >= 0; ) {
-		out1 = out + width * 2;		/* next line */
-		Ui = yi + width;
-		yi1 = Ui + width / 2;
-		Vi = yi1 + width;
-		for (j = width / 2; --j >= 0; ) {
-			*out++ = 128 + *yi++;
-			*out++ = 128 + *Ui;
-			*out++ = 128 + *yi++;
-			*out++ = 128 + *Vi;
-
-			*out1++ = 128 + *yi1++;
-			*out1++ = 128 + *Ui++;
-			*out1++ = 128 + *yi1++;
-			*out1++ = 128 + *Vi++;
-		}
-		yi += width * 2;
-		out = out1;
-	}
-}
-
 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
 			struct gspca_frame *frame,	/* target */
 			__u8 *data,			/* isoc packet */
 			int len)			/* iso packet length */
 {
-	struct sd *sd = (struct sd *) gspca_dev;
-	int fr_len;
-
 	switch (data[0]) {
 	case 0:				/* start of frame */
-		if (gspca_dev->last_packet_type == FIRST_PACKET) {
-			if (sd->pixfmt == V4L2_PIX_FMT_YUYV) {
-				yuyv_decode(sd->tmpbuf2, sd->tmpbuf,
-						gspca_dev->width,
-						gspca_dev->height);
-				fr_len = gspca_dev->width * gspca_dev->height
-					* 2;
-			} else {
-				yuv420_decode(sd->tmpbuf2, sd->tmpbuf,
-						gspca_dev->width,
-						gspca_dev->height);
-				fr_len = gspca_dev->width * gspca_dev->height
-					* 3 / 2;
-			}
-			frame = gspca_frame_add(gspca_dev,
-						LAST_PACKET,
-						frame,
-						sd->tmpbuf2,
-						fr_len);
+		if (gspca_dev->last_packet_type == INTER_PACKET) {
+			frame = gspca_frame_add(gspca_dev, LAST_PACKET,
+						frame, NULL, 0);
 		}
-		gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
-				data, 0);
 		data += SPCA501_OFFSET_DATA;
 		len -= SPCA501_OFFSET_DATA;
 		if (len > 0)
-			memcpy(sd->tmpbuf, data, len);
+			gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
+					data, len);
 		else
-			len = 0;
-		sd->buflen = len;
+			gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
+					NULL, 0);
 		return;
 	case 0xff:			/* drop */
 /*		gspca_dev->last_packet_type = DISCARD_PACKET; */
@@ -2211,12 +2117,7 @@
 	}
 	data++;
 	len--;
-	if ((sd->buflen + len) > sizeof sd->tmpbuf) {
-		gspca_dev->last_packet_type = DISCARD_PACKET;
-		return;
-	}
-	memcpy(&sd->tmpbuf[sd->buflen], data, len);
-	sd->buflen += len;
+	gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
 }
 
 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
Only in gspcav2-2.0.4: spca501.c~
Only in gspcav2-2.0.4: test.sh
-------------------------------------------------------------------------
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
Spca50x-devs@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/spca50x-devs