Web lists-archives.com

[Spca50x-devs] Patch: gspcav2-0.0.28 pac207 fixes + autogain support.




Hi,

Attached are 3 more patches to get pac207 support in gspcav2 in top notch condition.


gspcav2-0.0.28-pac207-cleanup.patch
-----------------------------------
Remove some unnecessary delays added during debugging earlier problems.

gspcav2-0.0.28-pac207-decompress-bugfix.patch
---------------------------------------------
Fix a nasty bug in the decoding

gspcav2-0.0.28-pac207-autogain.patch
------------------------------------
Add a callback which gets called whenever a frame gets dequeued, do autogain here (cannot be done under interrupt context), and some minor tweaks to the pac207 autogain code.

Regards,

Hans
--- gspcav2-0.0.28/gspca.c	2008-04-20 09:17:50.000000000 +0200
+++ gspcav2-0.0.28.new/gspca.c	2008-04-20 09:17:44.000000000 +0200
@@ -1366,6 +1366,10 @@
 		gspca_dev->fr_q,
 		gspca_dev->fr_i,
 		gspca_dev->fr_o);
+
+	if (gspca_dev->sd_desc->dq_callback)
+		gspca_dev->sd_desc->dq_callback(gspca_dev);
+
 	return j;
 }
 
--- gspcav2-0.0.28/gspca.h	2008-04-20 09:17:50.000000000 +0200
+++ gspcav2-0.0.28.new/gspca.h	2008-04-20 09:17:44.000000000 +0200
@@ -101,6 +101,7 @@
 	cam_v_op stopN;			/* called on stream off - main alt */
 	cam_v_op stop0;			/* called on stream off - alt 0 */
 	cam_v_op close;			/* called on close */
+	cam_v_op dq_callback;		/* called when a frame has been dequeued, may be NULL */
 	cam_pkt_op pkt_scan;
 	cam_jpg_op get_jcomp;
 	cam_jpg_op set_jcomp;
--- gspcav2-0.0.28/pac207.c	2008-04-20 10:55:25.000000000 +0200
+++ gspcav2-0.0.28.new/pac207.c	2008-04-20 11:41:27.000000000 +0200
@@ -33,14 +33,14 @@
 #define PAC207_EXPOSURE_MIN		4
 #define PAC207_EXPOSURE_MAX		26
 #define PAC207_EXPOSURE_DEFAULT		4 /* power on default: 3 ?? */
-#define PAC207_EXPOSURE_KNEE		15
+#define PAC207_EXPOSURE_KNEE		11 /* 4 = 30 fps, 11 = 8, 15 = 6 */
 
 #define PAC207_GAIN_MIN			0
 #define PAC207_GAIN_MAX			31
 #define PAC207_GAIN_DEFAULT         	9 /* power on default: 9 */
 #define PAC207_GAIN_KNEE		20
 
-#define PAC207_AUTOGAIN_DEADZONE	10
+#define PAC207_AUTOGAIN_DEADZONE	30
 /* We calculating the autogain at the end of the transfer of a frame, at this
    moment a frame with the old settings is being transmitted, and a frame is
    being captured with the old settings. So if we adjust the autogain we must
@@ -442,7 +437,7 @@
 	desired_avg_lum = 100 + sd->brightness / 2;
 
 	/* If we are of a multiple of deadzone, do multiple step to reach the
-	   desired lumination fast (with the risc of a slight overshoot */
+	   desired lumination fast (with the risc of a slight overshoot) */
 	steps = abs(desired_avg_lum - avg_lum) / PAC207_AUTOGAIN_DEADZONE;
 
 	for (i = 0; i < steps; i++) {
@@ -482,7 +482,7 @@
 	if (sd->exposure != orig_exposure || sd->gain != orig_gain) {
 		if (sd->exposure != orig_exposure)
 			pac207_write_reg(gspca_dev, 0x0002, sd->exposure);
-		else
+		if (sd->gain != orig_gain)
 			pac207_write_reg(gspca_dev, 0x000e, sd->gain);
 		pac207_write_reg(gspca_dev, 0x13, 0x01); /* load registers to sen. */
 		pac207_write_reg(gspca_dev, 0x1c, 0x01); /* not documented */
@@ -871,6 +874,7 @@
 	.stopN = sd_stopN,
 	.stop0 = sd_stop0,
 	.close = sd_close,
+	.dq_callback = pac207_do_auto_gain,
 	.pkt_scan = sd_pkt_scan,
 };
 
--- gspcav2-0.0.28/pac207.c	2008-04-20 10:55:25.000000000 +0200
+++ gspcav2-0.0.28.new/pac207.c	2008-04-20 11:41:27.000000000 +0200
@@ -24,7 +24,7 @@
 
 #define MODULE_NAME "pac207"
 
-#define PAC207_CTRL_TIMEOUT		500  /* ms */
+#define PAC207_CTRL_TIMEOUT		100  /* ms */
 
 #define PAC207_BRIGHTNESS_MIN		0
 #define PAC207_BRIGHTNESS_MAX		255
@@ -296,20 +299,12 @@
 	__u8 mode;
 
 	pac207_write_reg(gspca_dev, 0x0f, 0x10); /* Power control (Bit 6-0) */
-	udelay(1000); /* taken from gspca */
-	
 	pac207_write_regs(gspca_dev, 0x0002, pac207_sensor_init[0], 8);
-	udelay(1000); /* taken from gspca */
 	pac207_write_regs(gspca_dev, 0x000a, pac207_sensor_init[1], 8);
-	udelay(1000); /* taken from gspca */
 	pac207_write_regs(gspca_dev, 0x0012, pac207_sensor_init[2], 8);
-	udelay(1000); /* taken from gspca */
 	pac207_write_regs(gspca_dev, 0x0040, pac207_sensor_init[3], 8);
-	udelay(1000); /* taken from gspca */
 	pac207_write_regs(gspca_dev, 0x0042, pac207_sensor_init[4], 8);
-	udelay(1000); /* taken from gspca */
 	pac207_write_regs(gspca_dev, 0x0048, PacReg72, 4);
-	udelay(1000); /* taken from gspca */
 
 	if (gspca_dev->width == 176)
 		pac207_write_reg(gspca_dev, 0x4a, 0xff); /* Compression Balance */
--- gspcav2-0.0.28/pac207.c	2008-04-20 10:55:25.000000000 +0200
+++ gspcav2-0.0.28.new/pac207.c	2008-04-20 11:41:27.000000000 +0200
@@ -65,10 +65,13 @@
 };
 
 struct pac207_decoder_state {
+	/* generic state */
 	u16 line_read;
 	u16 line_marker;
 	u8 line_state;
 	u8 header_read;
+	/* compression state */
+	u16 processed_bytes;
 	u8 remaining_bits;
 	s8 no_remaining_bits;
 	u8 get_abs;
@@ -525,7 +523,7 @@
 		decoder_state->line_read++;
 		len--;
 		if (len == 0)
-			goto decompress_exit;
+			return 0;
 	}
 
 	while (decoder_state->line_read < gspca_dev->width) {
@@ -564,24 +562,28 @@
 	}
 
 	if (decoder_state->line_read == gspca_dev->width) {
+		int compressed_line_len;
+
 		gspca_frame_add(gspca_dev, INTER_PACKET, f,
 				decoder_state->line_decode_buf,
 				gspca_dev->width);
+
 		/* completely decompressed line, round pos to nearest word */
-		len -= 2 * ((bitpos + 15) / 16);
+		compressed_line_len = ((decoder_state->processed_bytes * 8 +
+			bitpos + 15) / 16) * 2;
+
+		len -= compressed_line_len - decoder_state->processed_bytes;
 		if (len < 0) {
 			decoder_state->discard_byte = 1;
 			len = 0;
 		}
 	} else {
+		decoder_state->processed_bytes += len;
 		decoder_state->remaining_bits = cdata[bitpos/8];
 		decoder_state->no_remaining_bits = (8 - bitpos) & 7;
 		len = 0;
 	}
 
-decompress_exit:
-	f->data_end = outp;
-	
 	return len;
 }
 
@@ -592,6 +594,7 @@
 
 	decoder_state->line_read = 0;
 	decoder_state->line_state = LINE_HEADER1;
+	decoder_state->processed_bytes = 0;
 	decoder_state->no_remaining_bits = 0;
 	decoder_state->get_abs = 0; 
 }
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Spca50x-devs mailing list
Spca50x-devs@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/spca50x-devs