Skip to contentSkip to conversation

usbvision: remove (broken) image format conversion

PATCH In review Ondrej Zary 4 participants 11 messages Apr 25, 2011 – Jun 16, 2011 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usbvision: remove (broken) image format conversion

The YVU420 and YUV422P formats are broken and cause kernel panic on use. (YVU420 does not work and sometimes causes "unable to handle paging request" panic, YUV422P always causes "NULL pointer dereference").

As V4L2 spec says that drivers shouldn't do any in-kernel image format conversion, remove it completely (except YUYV).

The removal also reveals an off-by-one bug in enum_fmt ioctl - it misses the last format, so this patch fixes it too.

This allows the driver to work with mplayer without need to manually specify a format and also to work with VLC without causing kernel panic.

drivers/media/video/usbvision/usbvision-core.c +28 -322
diff -up linux-2.6.39-rc2-/drivers/media/video/usbvision/usbvision-core.c linux-2.6.39-rc2/drivers/media/video/usbvision/usbvision-core.c
@@ -586,9 +586,8 @@ static enum parse_state usbvision_parse_
 	int len;
 	int i;
 	unsigned char yuyv[4] = { 180, 128, 10, 128 }; /* YUV components */
-	unsigned char rv, gv, bv;	/* RGB components */
-	int clipmask_index, bytes_per_pixel;
-	int stretch_bytes, clipmask_add;
+	int bytes_per_pixel;
+	int stretch_bytes;
 
 	frame  = usbvision->cur_frame;
 	f = frame->data + (frame->v4l2_linesize * frame->curline);
@@ -605,78 +604,16 @@ static enum parse_state usbvision_parse_
 
 	bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
 	stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel;
-	clipmask_index = frame->curline * MAX_FRAME_WIDTH;
-	clipmask_add = usbvision->stretch_width;
 
 	for (i = 0; i < frame->frmwidth; i += (2 * usbvision->stretch_width)) {
 		scratch_get(usbvision, &yuyv[0], 4);
 
-		if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-			*f++ = yuyv[0]; /* Y */
-			*f++ = yuyv[3]; /* U */
-		} else {
-			YUV_TO_RGB_BY_THE_BOOK(yuyv[0], yuyv[1], yuyv[3], rv, gv, bv);
-			switch (frame->v4l2_format.format) {
-			case V4L2_PIX_FMT_RGB565:
-				*f++ = (0x1F & rv) |
-					(0xE0 & (gv << 5));
-				*f++ = (0x07 & (gv >> 3)) |
-					(0xF8 &  bv);
-				break;
-			case V4L2_PIX_FMT_RGB24:
-				*f++ = rv;
-				*f++ = gv;
-				*f++ = bv;
-				break;
-			case V4L2_PIX_FMT_RGB32:
-				*f++ = rv;
-				*f++ = gv;
-				*f++ = bv;
-				f++;
-				break;
-			case V4L2_PIX_FMT_RGB555:
-				*f++ = (0x1F & rv) |
-					(0xE0 & (gv << 5));
-				*f++ = (0x03 & (gv >> 3)) |
-					(0x7C & (bv << 2));
-				break;
-			}
-		}
-		clipmask_index += clipmask_add;
+		*f++ = yuyv[0]; /* Y */
+		*f++ = yuyv[3]; /* U */
 		f += stretch_bytes;
 
-		if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-			*f++ = yuyv[2]; /* Y */
-			*f++ = yuyv[1]; /* V */
-		} else {
-			YUV_TO_RGB_BY_THE_BOOK(yuyv[2], yuyv[1], yuyv[3], rv, gv, bv);
-			switch (frame->v4l2_format.format) {
-			case V4L2_PIX_FMT_RGB565:
-				*f++ = (0x1F & rv) |
-					(0xE0 & (gv << 5));
-				*f++ = (0x07 & (gv >> 3)) |
-					(0xF8 &  bv);
-				break;
-			case V4L2_PIX_FMT_RGB24:
-				*f++ = rv;
-				*f++ = gv;
-				*f++ = bv;
-				break;
-			case V4L2_PIX_FMT_RGB32:
-				*f++ = rv;
-				*f++ = gv;
-				*f++ = bv;
-				f++;
-				break;
-			case V4L2_PIX_FMT_RGB555:
-				*f++ = (0x1F & rv) |
-					(0xE0 & (gv << 5));
-				*f++ = (0x03 & (gv >> 3)) |
-					(0x7C & (bv << 2));
-				break;
-			}
-		}
-		clipmask_index += clipmask_add;
+		*f++ = yuyv[2]; /* Y */
+		*f++ = yuyv[1]; /* V */
 		f += stretch_bytes;
 	}
 
@@ -794,30 +731,20 @@ static enum parse_state usbvision_parse_
 	unsigned char strip_data[USBVISION_STRIP_LEN_MAX];
 	unsigned char strip_header[USBVISION_STRIP_HEADER_LEN];
 	int idx, idx_end, strip_len, strip_ptr, startblock_pos, block_pos, block_type_pos;
-	int clipmask_index, bytes_per_pixel, rc;
+	int bytes_per_pixel, rc;
 	int image_size;
-	unsigned char rv, gv, bv;
 	static unsigned char *Y, *U, *V;
 
 	frame = usbvision->cur_frame;
 	image_size = frame->frmwidth * frame->frmheight;
-	if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
-	    (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420)) {       /* this is a planar format */
-		/* ... v4l2_linesize not used here. */
-		f = frame->data + (frame->width * frame->curline);
-	} else
-		f = frame->data + (frame->v4l2_linesize * frame->curline);
-
-	if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { /* initialise u and v pointers */
-		/* get base of u and b planes add halfoffset */
-		u = frame->data
-			+ image_size
-			+ (frame->frmwidth >> 1) * frame->curline;
-		v = u + (image_size >> 1);
-	} else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) {
-		v = frame->data + image_size + ((frame->curline * (frame->width)) >> 2);
-		u = v + (image_size >> 2);
-	}
+	f = frame->data + (frame->v4l2_linesize * frame->curline);
+
+	/* initialise u and v pointers */
+	/* get base of u and b planes add halfoffset */
+	u = frame->data
+		+ image_size
+		+ (frame->frmwidth >> 1) * frame->curline;
+	v = u + (image_size >> 1);
 
 	if (frame->curline == 0)
 		usbvision_adjust_compression(usbvision);
@@ -862,7 +789,6 @@ static enum parse_state usbvision_parse_
 	}
 
 	bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
-	clipmask_index = frame->curline * MAX_FRAME_WIDTH;
 
 	scratch_get(usbvision, strip_data, strip_len);
 
@@ -888,61 +814,10 @@ static enum parse_state usbvision_parse_
 		usbvision->strip_len_errors++;
 
 	for (idx = 0; idx < idx_end; idx++) {
-		if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-			*f++ = Y[idx];
-			*f++ = idx & 0x01 ? U[idx / 2] : V[idx / 2];
-		} else if (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) {
-			*f++ = Y[idx];
-			if (idx & 0x01)
-				*u++ = U[idx >> 1];
-			else
-				*v++ = V[idx >> 1];
-		} else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) {
-			*f++ = Y[idx];
-			if (!((idx & 0x01) | (frame->curline & 0x01))) {
-				/* only need do this for 1 in 4 pixels */
-				/* intraframe buffer is YUV420 format */
-				*u++ = U[idx >> 1];
-				*v++ = V[idx >> 1];
-			}
-		} else {
-			YUV_TO_RGB_BY_THE_BOOK(Y[idx], U[idx / 2], V[idx / 2], rv, gv, bv);
-			switch (frame->v4l2_format.format) {
-			case V4L2_PIX_FMT_GREY:
-				*f++ = Y[idx];
-				break;
-			case V4L2_PIX_FMT_RGB555:
-				*f++ = (0x1F & rv) |
-					(0xE0 & (gv << 5));
-				*f++ = (0x03 & (gv >> 3)) |
-					(0x7C & (bv << 2));
-				break;
-			case V4L2_PIX_FMT_RGB565:
-				*f++ = (0x1F & rv) |
-					(0xE0 & (gv << 5));
-				*f++ = (0x07 & (gv >> 3)) |
-					(0xF8 & bv);
-				break;
-			case V4L2_PIX_FMT_RGB24:
-				*f++ = rv;
-				*f++ = gv;
-				*f++ = bv;
-				break;
-			case V4L2_PIX_FMT_RGB32:
-				*f++ = rv;
-				*f++ = gv;
-				*f++ = bv;
-				f++;
-				break;
-			}
-		}
-		clipmask_index++;
+		*f++ = Y[idx];
+		*f++ = idx & 0x01 ? U[idx / 2] : V[idx / 2];
 	}
-	/* Deal with non-integer no. of bytes for YUV420P */
-	if (frame->v4l2_format.format != V4L2_PIX_FMT_YVU420)
-		*pcopylen += frame->v4l2_linesize;
-	else
-		*pcopylen += frame->curline & 0x01 ? frame->v4l2_linesize : frame->v4l2_linesize << 1;
+	*pcopylen += frame->v4l2_linesize;
 
 	frame->curline += 1;
 
@@ -975,11 +850,8 @@ static enum parse_state usbvision_parse_
 	const int y_step[] = { 0, 0, 0, 2 }, y_step_size = 4;
 	const int uv_step[] = { 0, 0, 0, 4 }, uv_step_size = 4;
 	unsigned char y[2], u, v;	/* YUV components */
-	int y_, u_, v_, vb, uvg, ur;
-	int r_, g_, b_;			/* RGB components */
-	unsigned char g;
-	int clipmask_even_index, clipmask_odd_index, bytes_per_pixel;
-	int clipmask_add, stretch_bytes;
+	int bytes_per_pixel;
+	int stretch_bytes;
 
 	frame  = usbvision->cur_frame;
 	f_even = frame->data + (frame->v4l2_linesize * frame->curline);
@@ -990,9 +862,6 @@ static enum parse_state usbvision_parse_
 	/* I need two lines to decode the color */
 	bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
 	stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel;
-	clipmask_even_index = frame->curline * MAX_FRAME_WIDTH;
-	clipmask_odd_index  = clipmask_even_index + MAX_FRAME_WIDTH;
-	clipmask_add = usbvision->stretch_width;
 	pixel_per_line = frame->isoc_header.frame_width;
 
 	if (scratch_len(usbvision) < (int)pixel_per_line * 3) {
@@ -1019,185 +888,22 @@ static enum parse_state usbvision_parse_
 			scratch_get_extra(usbvision, &u, &u_ptr, 1);
 			scratch_get_extra(usbvision, &v, &v_ptr, 1);
 
-			/* I don't use the YUV_TO_RGB macro for better performance */
-			v_ = v - 128;
-			u_ = u - 128;
-			vb = 132252 * v_;
-			uvg = -53281 * u_ - 25625 * v_;
-			ur = 104595 * u_;
-
-			if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-				*f_even++ = y[0];
-				*f_even++ = v;
-			} else {
-				y_ = 76284 * (y[0] - 16);
-
-				b_ = (y_ + vb) >> 16;
-				g_ = (y_ + uvg) >> 16;
-				r_ = (y_ + ur) >> 16;
-
-				switch (frame->v4l2_format.format) {
-				case V4L2_PIX_FMT_RGB565:
-					g = LIMIT_RGB(g_);
-					*f_even++ =
-						(0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_even++ =
-						(0x07 & (g >> 3)) |
-						(0xF8 &  LIMIT_RGB(b_));
-					break;
-				case V4L2_PIX_FMT_RGB24:
-					*f_even++ = LIMIT_RGB(r_);
-					*f_even++ = LIMIT_RGB(g_);
-					*f_even++ = LIMIT_RGB(b_);
-					break;
-				case V4L2_PIX_FMT_RGB32:
-					*f_even++ = LIMIT_RGB(r_);
-					*f_even++ = LIMIT_RGB(g_);
-					*f_even++ = LIMIT_RGB(b_);
-					f_even++;
-					break;
-				case V4L2_PIX_FMT_RGB555:
-					g = LIMIT_RGB(g_);
-					*f_even++ = (0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_even++ = (0x03 & (g >> 3)) |
-						(0x7C & (LIMIT_RGB(b_) << 2));
-					break;
-				}
-			}
-			clipmask_even_index += clipmask_add;
+			*f_even++ = y[0];
+			*f_even++ = v;
 			f_even += stretch_bytes;
 
-			if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-				*f_even++ = y[1];
-				*f_even++ = u;
-			} else {
-				y_ = 76284 * (y[1] - 16);
-
-				b_ = (y_ + vb) >> 16;
-				g_ = (y_ + uvg) >> 16;
-				r_ = (y_ + ur) >> 16;
-
-				switch (frame->v4l2_format.format) {
-				case V4L2_PIX_FMT_RGB565:
-					g = LIMIT_RGB(g_);
-					*f_even++ =
-						(0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_even++ =
-						(0x07 & (g >> 3)) |
-						(0xF8 &  LIMIT_RGB(b_));
-					break;
-				case V4L2_PIX_FMT_RGB24:
-					*f_even++ = LIMIT_RGB(r_);
-					*f_even++ = LIMIT_RGB(g_);
-					*f_even++ = LIMIT_RGB(b_);
-					break;
-				case V4L2_PIX_FMT_RGB32:
-					*f_even++ = LIMIT_RGB(r_);
-					*f_even++ = LIMIT_RGB(g_);
-					*f_even++ = LIMIT_RGB(b_);
-					f_even++;
-					break;
-				case V4L2_PIX_FMT_RGB555:
-					g = LIMIT_RGB(g_);
-					*f_even++ = (0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_even++ = (0x03 & (g >> 3)) |
-						(0x7C & (LIMIT_RGB(b_) << 2));
-					break;
-				}
-			}
-			clipmask_even_index += clipmask_add;
+			*f_even++ = y[1];
+			*f_even++ = u;
 			f_even += stretch_bytes;
 
 			scratch_get_extra(usbvision, &y[0], &y_ptr, 2);
 
-			if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-				*f_odd++ = y[0];
-				*f_odd++ = v;
-			} else {
-				y_ = 76284 * (y[0] - 16);
-
-				b_ = (y_ + vb) >> 16;
-				g_ = (y_ + uvg) >> 16;
-				r_ = (y_ + ur) >> 16;
-
-				switch (frame->v4l2_format.format) {
-				case V4L2_PIX_FMT_RGB565:
-					g = LIMIT_RGB(g_);
-					*f_odd++ =
-						(0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_odd++ =
-						(0x07 & (g >> 3)) |
-						(0xF8 &  LIMIT_RGB(b_));
-					break;
-				case V4L2_PIX_FMT_RGB24:
-					*f_odd++ = LIMIT_RGB(r_);
-					*f_odd++ = LIMIT_RGB(g_);
-					*f_odd++ = LIMIT_RGB(b_);
-					break;
-				case V4L2_PIX_FMT_RGB32:
-					*f_odd++ = LIMIT_RGB(r_);
-					*f_odd++ = LIMIT_RGB(g_);
-					*f_odd++ = LIMIT_RGB(b_);
-					f_odd++;
-					break;
-				case V4L2_PIX_FMT_RGB555:
-					g = LIMIT_RGB(g_);
-					*f_odd++ = (0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_odd++ = (0x03 & (g >> 3)) |
-						(0x7C & (LIMIT_RGB(b_) << 2));
-					break;
-				}
-			}
-			clipmask_odd_index += clipmask_add;
+			*f_odd++ = y[0];
+			*f_odd++ = v;
 			f_odd += stretch_bytes;
 
-			if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-				*f_odd++ = y[1];
-				*f_odd++ = u;
-			} else {
-				y_ = 76284 * (y[1] - 16);
-
-				b_ = (y_ + vb) >> 16;
-				g_ = (y_ + uvg) >> 16;
-				r_ = (y_ + ur) >> 16;
-
-				switch (frame->v4l2_format.format) {
-				case V4L2_PIX_FMT_RGB565:
-					g = LIMIT_RGB(g_);
-					*f_odd++ =
-						(0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_odd++ =
-						(0x07 & (g >> 3)) |
-						(0xF8 &  LIMIT_RGB(b_));
-					break;
-				case V4L2_PIX_FMT_RGB24:
-					*f_odd++ = LIMIT_RGB(r_);
-					*f_odd++ = LIMIT_RGB(g_);
-					*f_odd++ = LIMIT_RGB(b_);
-					break;
-				case V4L2_PIX_FMT_RGB32:
-					*f_odd++ = LIMIT_RGB(r_);
-					*f_odd++ = LIMIT_RGB(g_);
-					*f_odd++ = LIMIT_RGB(b_);
-					f_odd++;
-					break;
-				case V4L2_PIX_FMT_RGB555:
-					g = LIMIT_RGB(g_);
-					*f_odd++ = (0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_odd++ = (0x03 & (g >> 3)) |
-						(0x7C & (LIMIT_RGB(b_) << 2));
-					break;
-				}
-			}
-			clipmask_odd_index += clipmask_add;
+			*f_odd++ = y[1];
+			*f_odd++ = u;
 			f_odd += stretch_bytes;
 		}
 
drivers/media/video/usbvision/usbvision.h +0 -42

48 lines not on this page · raw message

drivers/media/video/usbvision/usbvision-video.c +2 -16
diff -up linux-2.6.39-rc2-/drivers/media/video/usbvision/usbvision-video.c linux-2.6.39-rc2/drivers/media/video/usbvision/usbvision-video.c
@@ -112,14 +112,7 @@ USBVISION_DRIVER_VERSION_PATCHLEVEL)
 static int usbvision_nr;
 
 static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = {
-	{ 1, 1,  8, V4L2_PIX_FMT_GREY    , "GREY" },
-	{ 1, 2, 16, V4L2_PIX_FMT_RGB565  , "RGB565" },
-	{ 1, 3, 24, V4L2_PIX_FMT_RGB24   , "RGB24" },
-	{ 1, 4, 32, V4L2_PIX_FMT_RGB32   , "RGB32" },
-	{ 1, 2, 16, V4L2_PIX_FMT_RGB555  , "RGB555" },
 	{ 1, 2, 16, V4L2_PIX_FMT_YUYV    , "YUV422" },
-	{ 1, 2, 12, V4L2_PIX_FMT_YVU420  , "YUV420P" }, /* 1.5 ! */
-	{ 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" }
 };
 
 /* Function prototypes */
@@ -888,7 +881,7 @@ static int vidioc_streamoff(struct file
 static int vidioc_enum_fmt_vid_cap(struct file *file, void  *priv,
 					struct v4l2_fmtdesc *vfd)
 {
-	if (vfd->index >= USBVISION_SUPPORTED_PALETTES - 1)
+	if (vfd->index > USBVISION_SUPPORTED_PALETTES - 1)
 		return -EINVAL;
 	strcpy(vfd->description, usbvision_v4l2_format[vfd->index].desc);
 	vfd->pixelformat = usbvision_v4l2_format[vfd->index].format;
@@ -1454,7 +1447,7 @@ static void usbvision_configure_video(st
 		return;
 
 	model = usbvision->dev_model;
-	usbvision->palette = usbvision_v4l2_format[2]; /* V4L2_PIX_FMT_RGB24; */
+	usbvision->palette = usbvision_v4l2_format[0];
 
 	if (usbvision_device_data[usbvision->dev_model].vin_reg2_override) {
 		usbvision->vin_reg2_preset =
@@ -1659,13 +1652,6 @@ static int __init usbvision_init(void)
 	PDEBUG(DBG_PROBE, "PROBE   debugging is enabled [video]");
 	PDEBUG(DBG_MMAP, "MMAP    debugging is enabled [video]");
 
-	/* disable planar mode support unless compression enabled */
-	if (isoc_mode != ISOC_MODE_COMPRESS) {
-		/* FIXME : not the right way to set supported flag */
-		usbvision_v4l2_format[6].supported = 0; /* V4L2_PIX_FMT_YVU420 */
-		usbvision_v4l2_format[7].supported = 0; /* V4L2_PIX_FMT_YUV422P */
-	}
-
 	err_code = usb_register(&usbvision_driver);
 
 	if (err_code == 0) {
Signature · 1 line
Ondrej Zary
#1 lore raw
Quoted 6 lines · On Monday, April 25, 2011 23:23:17 Ondrej Zary wrote:

The YVU420 and YUV422P formats are broken and cause kernel panic on use. (YVU420 does not work and sometimes causes "unable to handle paging request" panic, YUV422P always causes "NULL pointer dereference").

As V4L2 spec says that drivers shouldn't do any in-kernel image format conversion, remove it completely (except YUYV).

What really should happen is that the conversion is moved to libv4lconvert. I've never had the time to tackle that, but it would improve this driver a lot.

Would you perhaps be interested in doing that work?

Quoted 2 lines

The removal also reveals an off-by-one bug in enum_fmt ioctl - it misses the last format, so this patch fixes it too.

Good. But why are the GREY/RGB formats also removed? Are those broken as well?

Regards,

Hans

Quoted 540 lines

This allows the driver to work with mplayer without need to manually specify a format and also to work with VLC without causing kernel panic.

diff -up linux-2.6.39-rc2-/drivers/media/video/usbvision/usbvision-core.c linux-2.6.39-rc2/drivers/media/video/usbvision/usbvision-core.c

drivers/media/video/usbvision/usbvision-core.c +28 -322
@@ -586,9 +586,8 @@ static enum parse_state usbvision_parse_
 	int len;
 	int i;
 	unsigned char yuyv[4] = { 180, 128, 10, 128 }; /* YUV components */
-	unsigned char rv, gv, bv;	/* RGB components */
-	int clipmask_index, bytes_per_pixel;
-	int stretch_bytes, clipmask_add;
+	int bytes_per_pixel;
+	int stretch_bytes;
 
 	frame  = usbvision->cur_frame;
 	f = frame->data + (frame->v4l2_linesize * frame->curline);
@@ -605,78 +604,16 @@ static enum parse_state usbvision_parse_
 
 	bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
 	stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel;
-	clipmask_index = frame->curline * MAX_FRAME_WIDTH;
-	clipmask_add = usbvision->stretch_width;
 
 	for (i = 0; i < frame->frmwidth; i += (2 * usbvision->stretch_width)) {
 		scratch_get(usbvision, &yuyv[0], 4);
 
-		if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-			*f++ = yuyv[0]; /* Y */
-			*f++ = yuyv[3]; /* U */
-		} else {
-			YUV_TO_RGB_BY_THE_BOOK(yuyv[0], yuyv[1], yuyv[3], rv, gv, bv);
-			switch (frame->v4l2_format.format) {
-			case V4L2_PIX_FMT_RGB565:
-				*f++ = (0x1F & rv) |
-					(0xE0 & (gv << 5));
-				*f++ = (0x07 & (gv >> 3)) |
-					(0xF8 &  bv);
-				break;
-			case V4L2_PIX_FMT_RGB24:
-				*f++ = rv;
-				*f++ = gv;
-				*f++ = bv;
-				break;
-			case V4L2_PIX_FMT_RGB32:
-				*f++ = rv;
-				*f++ = gv;
-				*f++ = bv;
-				f++;
-				break;
-			case V4L2_PIX_FMT_RGB555:
-				*f++ = (0x1F & rv) |
-					(0xE0 & (gv << 5));
-				*f++ = (0x03 & (gv >> 3)) |
-					(0x7C & (bv << 2));
-				break;
-			}
-		}
-		clipmask_index += clipmask_add;
+		*f++ = yuyv[0]; /* Y */
+		*f++ = yuyv[3]; /* U */
 		f += stretch_bytes;
 
-		if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-			*f++ = yuyv[2]; /* Y */
-			*f++ = yuyv[1]; /* V */
-		} else {
-			YUV_TO_RGB_BY_THE_BOOK(yuyv[2], yuyv[1], yuyv[3], rv, gv, bv);
-			switch (frame->v4l2_format.format) {
-			case V4L2_PIX_FMT_RGB565:
-				*f++ = (0x1F & rv) |
-					(0xE0 & (gv << 5));
-				*f++ = (0x07 & (gv >> 3)) |
-					(0xF8 &  bv);
-				break;
-			case V4L2_PIX_FMT_RGB24:
-				*f++ = rv;
-				*f++ = gv;
-				*f++ = bv;
-				break;
-			case V4L2_PIX_FMT_RGB32:
-				*f++ = rv;
-				*f++ = gv;
-				*f++ = bv;
-				f++;
-				break;
-			case V4L2_PIX_FMT_RGB555:
-				*f++ = (0x1F & rv) |
-					(0xE0 & (gv << 5));
-				*f++ = (0x03 & (gv >> 3)) |
-					(0x7C & (bv << 2));
-				break;
-			}
-		}
-		clipmask_index += clipmask_add;
+		*f++ = yuyv[2]; /* Y */
+		*f++ = yuyv[1]; /* V */
 		f += stretch_bytes;
 	}
 
@@ -794,30 +731,20 @@ static enum parse_state usbvision_parse_
 	unsigned char strip_data[USBVISION_STRIP_LEN_MAX];
 	unsigned char strip_header[USBVISION_STRIP_HEADER_LEN];
 	int idx, idx_end, strip_len, strip_ptr, startblock_pos, block_pos, block_type_pos;
-	int clipmask_index, bytes_per_pixel, rc;
+	int bytes_per_pixel, rc;
 	int image_size;
-	unsigned char rv, gv, bv;
 	static unsigned char *Y, *U, *V;
 
 	frame = usbvision->cur_frame;
 	image_size = frame->frmwidth * frame->frmheight;
-	if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
-	    (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420)) {       /* this is a planar format */
-		/* ... v4l2_linesize not used here. */
-		f = frame->data + (frame->width * frame->curline);
-	} else
-		f = frame->data + (frame->v4l2_linesize * frame->curline);
-
-	if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { /* initialise u and v pointers */
-		/* get base of u and b planes add halfoffset */
-		u = frame->data
-			+ image_size
-			+ (frame->frmwidth >> 1) * frame->curline;
-		v = u + (image_size >> 1);
-	} else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) {
-		v = frame->data + image_size + ((frame->curline * (frame->width)) >> 2);
-		u = v + (image_size >> 2);
-	}
+	f = frame->data + (frame->v4l2_linesize * frame->curline);
+
+	/* initialise u and v pointers */
+	/* get base of u and b planes add halfoffset */
+	u = frame->data
+		+ image_size
+		+ (frame->frmwidth >> 1) * frame->curline;
+	v = u + (image_size >> 1);
 
 	if (frame->curline == 0)
 		usbvision_adjust_compression(usbvision);
@@ -862,7 +789,6 @@ static enum parse_state usbvision_parse_
 	}
 
 	bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
-	clipmask_index = frame->curline * MAX_FRAME_WIDTH;
 
 	scratch_get(usbvision, strip_data, strip_len);
 
@@ -888,61 +814,10 @@ static enum parse_state usbvision_parse_
 		usbvision->strip_len_errors++;
 
 	for (idx = 0; idx < idx_end; idx++) {
-		if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-			*f++ = Y[idx];
-			*f++ = idx & 0x01 ? U[idx / 2] : V[idx / 2];
-		} else if (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) {
-			*f++ = Y[idx];
-			if (idx & 0x01)
-				*u++ = U[idx >> 1];
-			else
-				*v++ = V[idx >> 1];
-		} else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) {
-			*f++ = Y[idx];
-			if (!((idx & 0x01) | (frame->curline & 0x01))) {
-				/* only need do this for 1 in 4 pixels */
-				/* intraframe buffer is YUV420 format */
-				*u++ = U[idx >> 1];
-				*v++ = V[idx >> 1];
-			}
-		} else {
-			YUV_TO_RGB_BY_THE_BOOK(Y[idx], U[idx / 2], V[idx / 2], rv, gv, bv);
-			switch (frame->v4l2_format.format) {
-			case V4L2_PIX_FMT_GREY:
-				*f++ = Y[idx];
-				break;
-			case V4L2_PIX_FMT_RGB555:
-				*f++ = (0x1F & rv) |
-					(0xE0 & (gv << 5));
-				*f++ = (0x03 & (gv >> 3)) |
-					(0x7C & (bv << 2));
-				break;
-			case V4L2_PIX_FMT_RGB565:
-				*f++ = (0x1F & rv) |
-					(0xE0 & (gv << 5));
-				*f++ = (0x07 & (gv >> 3)) |
-					(0xF8 & bv);
-				break;
-			case V4L2_PIX_FMT_RGB24:
-				*f++ = rv;
-				*f++ = gv;
-				*f++ = bv;
-				break;
-			case V4L2_PIX_FMT_RGB32:
-				*f++ = rv;
-				*f++ = gv;
-				*f++ = bv;
-				f++;
-				break;
-			}
-		}
-		clipmask_index++;
+		*f++ = Y[idx];
+		*f++ = idx & 0x01 ? U[idx / 2] : V[idx / 2];
 	}
-	/* Deal with non-integer no. of bytes for YUV420P */
-	if (frame->v4l2_format.format != V4L2_PIX_FMT_YVU420)
-		*pcopylen += frame->v4l2_linesize;
-	else
-		*pcopylen += frame->curline & 0x01 ? frame->v4l2_linesize : frame->v4l2_linesize << 1;
+	*pcopylen += frame->v4l2_linesize;
 
 	frame->curline += 1;
 
@@ -975,11 +850,8 @@ static enum parse_state usbvision_parse_
 	const int y_step[] = { 0, 0, 0, 2 }, y_step_size = 4;
 	const int uv_step[] = { 0, 0, 0, 4 }, uv_step_size = 4;
 	unsigned char y[2], u, v;	/* YUV components */
-	int y_, u_, v_, vb, uvg, ur;
-	int r_, g_, b_;			/* RGB components */
-	unsigned char g;
-	int clipmask_even_index, clipmask_odd_index, bytes_per_pixel;
-	int clipmask_add, stretch_bytes;
+	int bytes_per_pixel;
+	int stretch_bytes;
 
 	frame  = usbvision->cur_frame;
 	f_even = frame->data + (frame->v4l2_linesize * frame->curline);
@@ -990,9 +862,6 @@ static enum parse_state usbvision_parse_
 	/* I need two lines to decode the color */
 	bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
 	stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel;
-	clipmask_even_index = frame->curline * MAX_FRAME_WIDTH;
-	clipmask_odd_index  = clipmask_even_index + MAX_FRAME_WIDTH;
-	clipmask_add = usbvision->stretch_width;
 	pixel_per_line = frame->isoc_header.frame_width;
 
 	if (scratch_len(usbvision) < (int)pixel_per_line * 3) {
@@ -1019,185 +888,22 @@ static enum parse_state usbvision_parse_
 			scratch_get_extra(usbvision, &u, &u_ptr, 1);
 			scratch_get_extra(usbvision, &v, &v_ptr, 1);
 
-			/* I don't use the YUV_TO_RGB macro for better performance */
-			v_ = v - 128;
-			u_ = u - 128;
-			vb = 132252 * v_;
-			uvg = -53281 * u_ - 25625 * v_;
-			ur = 104595 * u_;
-
-			if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-				*f_even++ = y[0];
-				*f_even++ = v;
-			} else {
-				y_ = 76284 * (y[0] - 16);
-
-				b_ = (y_ + vb) >> 16;
-				g_ = (y_ + uvg) >> 16;
-				r_ = (y_ + ur) >> 16;
-
-				switch (frame->v4l2_format.format) {
-				case V4L2_PIX_FMT_RGB565:
-					g = LIMIT_RGB(g_);
-					*f_even++ =
-						(0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_even++ =
-						(0x07 & (g >> 3)) |
-						(0xF8 &  LIMIT_RGB(b_));
-					break;
-				case V4L2_PIX_FMT_RGB24:
-					*f_even++ = LIMIT_RGB(r_);
-					*f_even++ = LIMIT_RGB(g_);
-					*f_even++ = LIMIT_RGB(b_);
-					break;
-				case V4L2_PIX_FMT_RGB32:
-					*f_even++ = LIMIT_RGB(r_);
-					*f_even++ = LIMIT_RGB(g_);
-					*f_even++ = LIMIT_RGB(b_);
-					f_even++;
-					break;
-				case V4L2_PIX_FMT_RGB555:
-					g = LIMIT_RGB(g_);
-					*f_even++ = (0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_even++ = (0x03 & (g >> 3)) |
-						(0x7C & (LIMIT_RGB(b_) << 2));
-					break;
-				}
-			}
-			clipmask_even_index += clipmask_add;
+			*f_even++ = y[0];
+			*f_even++ = v;
 			f_even += stretch_bytes;
 
-			if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-				*f_even++ = y[1];
-				*f_even++ = u;
-			} else {
-				y_ = 76284 * (y[1] - 16);
-
-				b_ = (y_ + vb) >> 16;
-				g_ = (y_ + uvg) >> 16;
-				r_ = (y_ + ur) >> 16;
-
-				switch (frame->v4l2_format.format) {
-				case V4L2_PIX_FMT_RGB565:
-					g = LIMIT_RGB(g_);
-					*f_even++ =
-						(0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_even++ =
-						(0x07 & (g >> 3)) |
-						(0xF8 &  LIMIT_RGB(b_));
-					break;
-				case V4L2_PIX_FMT_RGB24:
-					*f_even++ = LIMIT_RGB(r_);
-					*f_even++ = LIMIT_RGB(g_);
-					*f_even++ = LIMIT_RGB(b_);
-					break;
-				case V4L2_PIX_FMT_RGB32:
-					*f_even++ = LIMIT_RGB(r_);
-					*f_even++ = LIMIT_RGB(g_);
-					*f_even++ = LIMIT_RGB(b_);
-					f_even++;
-					break;
-				case V4L2_PIX_FMT_RGB555:
-					g = LIMIT_RGB(g_);
-					*f_even++ = (0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_even++ = (0x03 & (g >> 3)) |
-						(0x7C & (LIMIT_RGB(b_) << 2));
-					break;
-				}
-			}
-			clipmask_even_index += clipmask_add;
+			*f_even++ = y[1];
+			*f_even++ = u;
 			f_even += stretch_bytes;
 
 			scratch_get_extra(usbvision, &y[0], &y_ptr, 2);
 
-			if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-				*f_odd++ = y[0];
-				*f_odd++ = v;
-			} else {
-				y_ = 76284 * (y[0] - 16);
-
-				b_ = (y_ + vb) >> 16;
-				g_ = (y_ + uvg) >> 16;
-				r_ = (y_ + ur) >> 16;
-
-				switch (frame->v4l2_format.format) {
-				case V4L2_PIX_FMT_RGB565:
-					g = LIMIT_RGB(g_);
-					*f_odd++ =
-						(0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_odd++ =
-						(0x07 & (g >> 3)) |
-						(0xF8 &  LIMIT_RGB(b_));
-					break;
-				case V4L2_PIX_FMT_RGB24:
-					*f_odd++ = LIMIT_RGB(r_);
-					*f_odd++ = LIMIT_RGB(g_);
-					*f_odd++ = LIMIT_RGB(b_);
-					break;
-				case V4L2_PIX_FMT_RGB32:
-					*f_odd++ = LIMIT_RGB(r_);
-					*f_odd++ = LIMIT_RGB(g_);
-					*f_odd++ = LIMIT_RGB(b_);
-					f_odd++;
-					break;
-				case V4L2_PIX_FMT_RGB555:
-					g = LIMIT_RGB(g_);
-					*f_odd++ = (0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_odd++ = (0x03 & (g >> 3)) |
-						(0x7C & (LIMIT_RGB(b_) << 2));
-					break;
-				}
-			}
-			clipmask_odd_index += clipmask_add;
+			*f_odd++ = y[0];
+			*f_odd++ = v;
 			f_odd += stretch_bytes;
 
-			if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
-				*f_odd++ = y[1];
-				*f_odd++ = u;
-			} else {
-				y_ = 76284 * (y[1] - 16);
-
-				b_ = (y_ + vb) >> 16;
-				g_ = (y_ + uvg) >> 16;
-				r_ = (y_ + ur) >> 16;
-
-				switch (frame->v4l2_format.format) {
-				case V4L2_PIX_FMT_RGB565:
-					g = LIMIT_RGB(g_);
-					*f_odd++ =
-						(0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_odd++ =
-						(0x07 & (g >> 3)) |
-						(0xF8 &  LIMIT_RGB(b_));
-					break;
-				case V4L2_PIX_FMT_RGB24:
-					*f_odd++ = LIMIT_RGB(r_);
-					*f_odd++ = LIMIT_RGB(g_);
-					*f_odd++ = LIMIT_RGB(b_);
-					break;
-				case V4L2_PIX_FMT_RGB32:
-					*f_odd++ = LIMIT_RGB(r_);
-					*f_odd++ = LIMIT_RGB(g_);
-					*f_odd++ = LIMIT_RGB(b_);
-					f_odd++;
-					break;
-				case V4L2_PIX_FMT_RGB555:
-					g = LIMIT_RGB(g_);
-					*f_odd++ = (0x1F & LIMIT_RGB(r_)) |
-						(0xE0 & (g << 5));
-					*f_odd++ = (0x03 & (g >> 3)) |
-						(0x7C & (LIMIT_RGB(b_) << 2));
-					break;
-				}
-			}
-			clipmask_odd_index += clipmask_add;
+			*f_odd++ = y[1];
+			*f_odd++ = u;
 			f_odd += stretch_bytes;
 		}
 

diff -up linux-2.6.39-rc2-/drivers/media/video/usbvision/usbvision.h linux-2.6.39-rc2/drivers/media/video/usbvision/usbvision.h

drivers/media/video/usbvision/usbvision.h +0 -42
@@ -165,48 +165,6 @@ enum {
 	{ if ((v) < (mi)) (v) = (mi); else if ((v) > (ma)) (v) = (ma); }
 
 /*
- * We use macros to do YUV -> RGB conversion because this is
- * very important for speed and totally unimportant for size.
- *
- * YUV -> RGB Conversion
- * ---------------------
- *
- * B = 1.164*(Y-16)		    + 2.018*(V-128)
- * G = 1.164*(Y-16) - 0.813*(U-128) - 0.391*(V-128)
- * R = 1.164*(Y-16) + 1.596*(U-128)
- *
- * If you fancy integer arithmetics (as you should), hear this:
- *
- * 65536*B = 76284*(Y-16)		  + 132252*(V-128)
- * 65536*G = 76284*(Y-16) -  53281*(U-128) -  25625*(V-128)
- * 65536*R = 76284*(Y-16) + 104595*(U-128)
- *
- * Make sure the output values are within [0..255] range.
- */
-#define LIMIT_RGB(x) (((x) < 0) ? 0 : (((x) > 255) ? 255 : (x)))
-#define YUV_TO_RGB_BY_THE_BOOK(my, mu, mv, mr, mg, mb) { \
-	int mm_y, mm_yc, mm_u, mm_v, mm_r, mm_g, mm_b; \
-	mm_y = (my) - 16; \
-	mm_u = (mu) - 128; \
-	mm_v = (mv) - 128; \
-	mm_yc = mm_y * 76284; \
-	mm_b = (mm_yc + 132252 * mm_v) >> 16; \
-	mm_g = (mm_yc - 53281 * mm_u - 25625 * mm_v) >> 16; \
-	mm_r = (mm_yc + 104595 * mm_u) >> 16; \
-	mb = LIMIT_RGB(mm_b); \
-	mg = LIMIT_RGB(mm_g); \
-	mr = LIMIT_RGB(mm_r); \
-}
-
-/* Debugging aid */
-#define USBVISION_SAY_AND_WAIT(what) { \
-	wait_queue_head_t wq; \
-	init_waitqueue_head(&wq); \
-	printk(KERN_INFO "Say: %s\n", what); \
-	interruptible_sleep_on_timeout(&wq, HZ * 3); \
-}
-
-/*
  * This macro checks if usbvision is still operational. The 'usbvision'
  * pointer must be valid, usbvision->dev must be valid, we are not
  * removing the device and the device has not erred on us.

diff -up linux-2.6.39-rc2-/drivers/media/video/usbvision/usbvision-video.c linux-2.6.39-rc2/drivers/media/video/usbvision/usbvision-video.c

drivers/media/video/usbvision/usbvision-video.c +2 -16
@@ -112,14 +112,7 @@ USBVISION_DRIVER_VERSION_PATCHLEVEL)
 static int usbvision_nr;
 
 static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = {
-	{ 1, 1,  8, V4L2_PIX_FMT_GREY    , "GREY" },
-	{ 1, 2, 16, V4L2_PIX_FMT_RGB565  , "RGB565" },
-	{ 1, 3, 24, V4L2_PIX_FMT_RGB24   , "RGB24" },
-	{ 1, 4, 32, V4L2_PIX_FMT_RGB32   , "RGB32" },
-	{ 1, 2, 16, V4L2_PIX_FMT_RGB555  , "RGB555" },
 	{ 1, 2, 16, V4L2_PIX_FMT_YUYV    , "YUV422" },
-	{ 1, 2, 12, V4L2_PIX_FMT_YVU420  , "YUV420P" }, /* 1.5 ! */
-	{ 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" }
 };
 
 /* Function prototypes */
@@ -888,7 +881,7 @@ static int vidioc_streamoff(struct file
 static int vidioc_enum_fmt_vid_cap(struct file *file, void  *priv,
 					struct v4l2_fmtdesc *vfd)
 {
-	if (vfd->index >= USBVISION_SUPPORTED_PALETTES - 1)
+	if (vfd->index > USBVISION_SUPPORTED_PALETTES - 1)
 		return -EINVAL;
 	strcpy(vfd->description, usbvision_v4l2_format[vfd->index].desc);
 	vfd->pixelformat = usbvision_v4l2_format[vfd->index].format;
@@ -1454,7 +1447,7 @@ static void usbvision_configure_video(st
 		return;
 
 	model = usbvision->dev_model;
-	usbvision->palette = usbvision_v4l2_format[2]; /* V4L2_PIX_FMT_RGB24; */
+	usbvision->palette = usbvision_v4l2_format[0];
 
 	if (usbvision_device_data[usbvision->dev_model].vin_reg2_override) {
 		usbvision->vin_reg2_preset =
@@ -1659,13 +1652,6 @@ static int __init usbvision_init(void)
 	PDEBUG(DBG_PROBE, "PROBE   debugging is enabled [video]");
 	PDEBUG(DBG_MMAP, "MMAP    debugging is enabled [video]");
 
-	/* disable planar mode support unless compression enabled */
-	if (isoc_mode != ISOC_MODE_COMPRESS) {
-		/* FIXME : not the right way to set supported flag */
-		usbvision_v4l2_format[6].supported = 0; /* V4L2_PIX_FMT_YVU420 */
-		usbvision_v4l2_format[7].supported = 0; /* V4L2_PIX_FMT_YUV422P */
-	}
-
 	err_code = usb_register(&usbvision_driver);
 
 	if (err_code == 0) {
#2 lore raw
Quoted 11 lines · you
Quoted 6 lines · On Monday, April 25, 2011 23:23:17 Ondrej Zary wrote:

The YVU420 and YUV422P formats are broken and cause kernel panic on use. (YVU420 does not work and sometimes causes "unable to handle paging request" panic, YUV422P always causes "NULL pointer dereference").

As V4L2 spec says that drivers shouldn't do any in-kernel image format conversion, remove it completely (except YUYV).

What really should happen is that the conversion is moved to libv4lconvert. I've never had the time to tackle that, but it would improve this driver a lot.

Depending on isoc_mode module parameter, the device uses different image
formats: YUV 4:2:2 interleaved, YUV 4:2:0 planar or compressed format.

Maybe the parameter should go away and these three formats exposed to userspace? Hopefully the non-compressed formats could be used directly without any conversion. But the compressed format (with new V4L2_PIX_FMT_ assigned?) should be preferred (as it provides much higher frame rates). The code moved into libv4lconvert would decompress the format and convert into something standard (YUV420?).

Quoted 1 line

Would you perhaps be interested in doing that work?

I can try it. But the hardware isn't mine so my time is limited.

Quoted 5 lines
Quoted 2 lines

The removal also reveals an off-by-one bug in enum_fmt ioctl - it misses the last format, so this patch fixes it too.

Good. But why are the GREY/RGB formats also removed? Are those broken as well?

GREY, RGB24 and RGB32 seem to work (at least with mplayer). RGB565 and RGB555 have wrong colors. GREY is implemented only in compressed mode but can be selected in other modes too. Can't userspace do the conversion better?

Quoted 3 lines

Regards,

Hans

Signature · 1 line
Ondrej Zary
#3 lore raw

Hi,

Quoted 13 lines · Ondrej Zary
Quoted 11 lines · you
Quoted 6 lines · On Monday, April 25, 2011 23:23:17 Ondrej Zary wrote:

The YVU420 and YUV422P formats are broken and cause kernel panic on use. (YVU420 does not work and sometimes causes "unable to handle paging request" panic, YUV422P always causes "NULL pointer dereference").

As V4L2 spec says that drivers shouldn't do any in-kernel image format conversion, remove it completely (except YUYV).

What really should happen is that the conversion is moved to libv4lconvert. I've never had the time to tackle that, but it would improve this driver a lot.

Quoted 5 lines

Depending on isoc_mode module parameter, the device uses different image
formats: YUV 4:2:2 interleaved, YUV 4:2:0 planar or compressed format.

Maybe the parameter should go away and these three formats exposed to userspace?

That sounds right,

Quoted 5 lines

Hopefully the non-compressed formats could be used directly without any conversion. But the compressed format (with new V4L2_PIX_FMT_ assigned?) should be preferred (as it provides much higher frame rates). The code moved into libv4lconvert would decompress the format and convert into something standard (YUV420?).

Correct.

Quoted 5 lines
Quoted 2 lines

Would you perhaps be interested in doing that work?

I can try it. But the hardware isn't mine so my time is limited.

If you could give it a shot that would be great. I've some hardware to test this with (although I've never actually tested that hardware), so I can hopefully pick things up if you cannot finish things before you need to return the hardware.

Thanks & Regards,

Hans

#4 lore raw
Quoted 41 lines

Hi,

Quoted 16 lines · Ondrej Zary
Quoted 6 lines · you
Quoted 5 lines · On Monday, April 25, 2011 23:23:17 Ondrej Zary wrote:

The YVU420 and YUV422P formats are broken and cause kernel panic on use.
(YVU420 does not work and sometimes causes "unable to handle paging request" panic, YUV422P always causes "NULL pointer dereference").

Quoted 8 lines
Quoted 2 lines

As V4L2 spec says that drivers shouldn't do any in-kernel image format conversion, remove it completely (except YUYV).

What really should happen is that the conversion is moved to libv4lconvert.
I've never had the time to tackle that, but it would improve this driver a
lot.

Quoted 5 lines

Depending on isoc_mode module parameter, the device uses different image
formats: YUV 4:2:2 interleaved, YUV 4:2:0 planar or compressed format.

Maybe the parameter should go away and these three formats exposed to userspace?

That sounds right,

Quoted 8 lines

Hopefully the non-compressed formats could be used directly without any conversion. But the compressed format (with new V4L2_PIX_FMT_
assigned?) should be preferred (as it provides much higher frame rates). The
code moved into libv4lconvert would decompress the format and convert into
something standard (YUV420?).

Correct.

Quoted 3 lines
Quoted 2 lines

Would you perhaps be interested in doing that work?

Quoted 7 lines
Quoted 2 lines

I can try it. But the hardware isn't mine so my time is limited.

If you could give it a shot that would be great. I've some hardware to test this with (although I've never actually tested that hardware), so I can hopefully pick things up if you cannot finish things before you need to return the hardware.

I can also test this.

Regards,

Hans

Quoted 5 lines

Thanks & Regards,

Hans

#5 lore raw
Quoted 40 lines · On Tuesday 26 April 2011 14:33:20 Hans Verkuil wrote:
Quoted 40 lines

Hi,

Quoted 16 lines · Ondrej Zary
Quoted 6 lines · you
Quoted 5 lines · On Monday, April 25, 2011 23:23:17 Ondrej Zary wrote:

The YVU420 and YUV422P formats are broken and cause kernel panic on use.
(YVU420 does not work and sometimes causes "unable to handle paging request" panic, YUV422P always causes "NULL pointer dereference").

Quoted 8 lines
Quoted 2 lines

As V4L2 spec says that drivers shouldn't do any in-kernel image format conversion, remove it completely (except YUYV).

What really should happen is that the conversion is moved to libv4lconvert.
I've never had the time to tackle that, but it would improve this driver a
lot.

Quoted 5 lines

Depending on isoc_mode module parameter, the device uses different image
formats: YUV 4:2:2 interleaved, YUV 4:2:0 planar or compressed format.

Maybe the parameter should go away and these three formats exposed to userspace?

That sounds right,

Quoted 8 lines

Hopefully the non-compressed formats could be used directly without any conversion. But the compressed format (with new V4L2_PIX_FMT_
assigned?) should be preferred (as it provides much higher frame rates). The
code moved into libv4lconvert would decompress the format and convert into
something standard (YUV420?).

Correct.

Quoted 2 lines
Quoted 1 line

Would you perhaps be interested in doing that work?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

I can try it. But the hardware isn't mine so my time is limited.

If you could give it a shot that would be great. I've some hardware to test this with (although I've never actually tested that hardware), so I can hopefully pick things up if you cannot finish things before you need to return the hardware.

I can also test this.

After digging in the code for hours, I'm giving this up. It's not worth it.

The ISOC_MODE_YUV422 mode works as V4L2_PIX_FMT_YVYU with VLC and mplayer+libv4lconvert, reducing the loop (and dropping strech_*) in usbvision_parse_lines_422() to:
scratch_get(usbvision, frame->data + (frame->v4l2_linesize * frame->curline), 2 * frame->frmwidth);

The ISOC_MODE_YUV420 is some weird custom format with 64-byte lines of YYUV. usbvision_parse_lines_420() is real mess with that scratch_* crap everywhere.

ISOC_MODE_COMPRESS: There are callbacks to usbvision_request_intra() and also usbvision_adjust_compression(). This is not going to work outside the kernel.

So I can redo the conversion removal patch to keep the RGB formats and also provide another one to remove the testpattern (it oopses too). But I'm not going to do any major changes in the driver.

Signature · 1 line
Ondrej Zary
#6 lore raw

Em 26-04-2011 17:40, Ondrej Zary escreveu:

Quoted 13 lines · On Tuesday 26 April 2011 14:33:20 Hans Verkuil wrote:

After digging in the code for hours, I'm giving this up. It's not worth it.

The ISOC_MODE_YUV422 mode works as V4L2_PIX_FMT_YVYU with VLC and mplayer+libv4lconvert, reducing the loop (and dropping strech_*) in usbvision_parse_lines_422() to:
scratch_get(usbvision, frame->data + (frame->v4l2_linesize * frame->curline), 2 * frame->frmwidth);

The ISOC_MODE_YUV420 is some weird custom format with 64-byte lines of YYUV. usbvision_parse_lines_420() is real mess with that scratch_* crap everywhere.

Quoted 7 lines

ISOC_MODE_COMPRESS: There are callbacks to usbvision_request_intra() and also usbvision_adjust_compression(). This is not going to work outside the kernel.

So I can redo the conversion removal patch to keep the RGB formats and also provide another one to remove the testpattern (it oopses too). But I'm not going to do any major changes in the driver.

While in a perfect world, this should be moved to userspace, I'm ok on keeping it there, but the OOPS/Panic conditions should be fixed.

Could you please work on a patch fixing the broken stuff, without removing the conversions?

Thanks,
Mauro

#7 lore raw
Quoted 25 lines · On Tuesday 03 May 2011 12:29:45 Mauro Carvalho Chehab wrote:

Em 26-04-2011 17:40, Ondrej Zary escreveu:

Quoted 15 lines · On Tuesday 26 April 2011 14:33:20 Hans Verkuil wrote:

After digging in the code for hours, I'm giving this up. It's not worth it.

The ISOC_MODE_YUV422 mode works as V4L2_PIX_FMT_YVYU with VLC and mplayer+libv4lconvert, reducing the loop (and dropping strech_*) in usbvision_parse_lines_422() to:
scratch_get(usbvision, frame->data + (frame->v4l2_linesize *
frame->curline), 2 * frame->frmwidth);

The ISOC_MODE_YUV420 is some weird custom format with 64-byte lines of YYUV. usbvision_parse_lines_420() is real mess with that scratch_* crap everywhere.

Quoted 8 lines

ISOC_MODE_COMPRESS: There are callbacks to usbvision_request_intra() and also usbvision_adjust_compression(). This is not going to work outside the kernel.

So I can redo the conversion removal patch to keep the RGB formats and also provide another one to remove the testpattern (it oopses too). But I'm not going to do any major changes in the driver.

Quoted 5 lines

While in a perfect world, this should be moved to userspace, I'm ok on keeping it there, but the OOPS/Panic conditions should be fixed.

Could you please work on a patch fixing the broken stuff, without removing the conversions?

I've already returned the hardware so I can't test the driver anymore.

Did the YUV422P conversion ever work? The initialization of u and v pointers is missing in usbvision_parse_compress() function for YUV422P case.

The following oops was captured when trying to fix YVU420. Seems to be related to the u pointer too...

[  181.169233] usbvision_parse_compress before conversion
[  181.169233] usbvision_parse_compress idx=0, format=842094169
[  181.169233] usbvision_parse_compress YVU420 f=e088d000, Y=e0a3e000
[  181.169233] usbvision_parse_compress YVU420 frame=df016b68
[  181.169233] usbvision_parse_compress YVU420 frame->curline=0
[  181.169233] usbvision_parse_compress YVU420 u=e08a4700, U=e0a50c00, v=e089fc00, V=e0a55700
[  181.169233] BUG: unable to handle kernel paging request at e08a4700
[  181.169233] IP: [<e097fd57>] usbvision_parse_compress+0x599/0x76e [usbvision]
[  181.169233] *pde = 1f0c2067 *pte = 00000000
[  181.169233] Oops: 0002 [#1] SMP
[  181.169233] last sysfs file: /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/i2c-0/uevent
[  181.169233] Modules linked in: savage drm loop usbvision v4l2_common snd_fm801 snd_tea575x_tuner videodev snd_intel8x0 e
[  181.169233]
[  181.169233] Pid: 0, comm: swapper Not tainted 2.6.39-rc2 #2    /848P-ICH5
[  181.169233] EIP: 0060:[<e097fd57>] EFLAGS: 00010046 CPU: 0
[  181.169233] EIP is at usbvision_parse_compress+0x599/0x76e [usbvision]
[  181.169233] EAX: 00000000 EBX: df016b68 ECX: e08a4700 EDX: e0a50c81
[  181.169233] ESI: 00000000 EDI: e088d001 EBP: 000000a0 ESP: df021cb4
[  181.169233]  DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068
[  181.169233] Process swapper (pid: 0, ti=df020000 task=c12dde60 task.ti=c12b0000)
[  181.169233] Stack:
[  181.169233]  e0986ed3 e09861a4 e08a4700 e0a50c00 e089fc00 e0a55700 00000003 e089fc00
[  181.169233]  e08a4700 000000c0 00000140 df021f14 df021d52 05060000 00060027 00000009
[  181.169233]  000000c0 00003293 00605a25 ff00605a fff0ffff 55d501fc 82995568 a0060124
[  181.169233] Call Trace:
[  181.169233]  [<e0c9c69d>] ? uhci_urb_enqueue+0x712/0x725 [uhci_hcd]
[  181.169233]  [<e08f4155>] ? usb_hcd_submit_urb+0x4be/0x53d [usbcore]
[  181.169233]  [<c11e9840>] ? printk+0xe/0x16
[  181.169233]  [<e0980486>] ? usbvision_isoc_irq+0x55a/0x17a0 [usbvision]
[  181.169233]  [<e097f5f9>] ? usbvision_write_reg_irq+0xd5/0x10f [usbvision]
[  181.169233]  [<e0981505>] ? usbvision_isoc_irq+0x15d9/0x17a0 [usbvision]
[  181.169233]  [<c1026eb2>] ? try_to_wake_up+0x13b/0x13b
[  181.169233]  [<c117057c>] ? ata_scsi_qc_complete+0x2b4/0x2c2
[  181.169233]  [<c101e899>] ? __wake_up+0x2c/0x3b
[  181.169233]  [<e08f33e5>] ? usb_hcd_giveback_urb+0x46/0x71 [usbcore]
[  181.169233]  [<e0c9a98d>] ? uhci_giveback_urb+0xea/0x15d [uhci_hcd]
[  181.169233]  [<e0c9aff7>] ? uhci_scan_schedule+0x526/0x777 [uhci_hcd]
[  181.169233]  [<c117951b>] ? __ata_sff_port_intr+0x97/0xa2
[  181.169233]  [<e0c9c9f8>] ? uhci_irq+0xbf/0xcd [uhci_hcd]
[  181.169233]  [<e08f2d2e>] ? usb_hcd_irq+0x1e/0x5f [usbcore]
[  181.169233]  [<c1058581>] ? handle_irq_event_percpu+0x1e/0x106
[  181.169233]  [<c1059edc>] ? handle_edge_irq+0xa0/0xa0
[  181.169233]  [<c105868a>] ? handle_irq_event+0x21/0x37
[  181.169233]  [<c1059edc>] ? handle_edge_irq+0xa0/0xa0
[  181.169233]  [<c1059f42>] ? handle_fasteoi_irq+0x66/0x7e
[  181.169233]  <IRQ>
[  181.169233]  [<c10035c7>] ? do_IRQ+0x2e/0x84
[  181.169233]  [<c11ec370>] ? common_interrupt+0x30/0x38
[  181.169233]  [<c1007699>] ? mwait_idle+0x4f/0x54
[  181.169233]  [<c1001a86>] ? cpu_idle+0x91/0xab
[  181.169233]  [<c12f96d4>] ? start_kernel+0x2a3/0x2a8
[  181.169233] Code: 08 ff 35 8c a1 98 e0 ff 74 24 14 68 a4 61 98 e0 68 d3 6e 98 e0 e8 ec 9a 86 e0 8b 15 8c a1 98 e0 89 f0
[  181.169233]  11 8b 15 88 a1 98 e0 41 89 4c 24 20 8a 04 02 8b 54 24 1c 88
[  181.169233] EIP: [<e097fd57>] usbvision_parse_compress+0x599/0x76e [usbvision] SS:ESP 0068:df021cb4
[  181.169233] CR2: 00000000e08a4700
[  181.169233] ---[ end trace aeedba237da329c1 ]---
Signature · 1 line
Ondrej Zary
#8 lore raw

Hi Hans de G.,

Em 26-04-2011 08:54, Hans de Goede escreveu:

Quoted 4 lines

If you could give it a shot that would be great. I've some hardware to test this with (although I've never actually tested that hardware), so I can hopefully pick things up if you cannot finish things before you need to return the hardware.

As Ondrej couldn't work on that while he was with the hardware, could you please try to address this issue?

Thanks,
Mauro

Em 03-05-2011 13:37, Ondrej Zary escreveu:

Quoted 98 lines · On Tuesday 03 May 2011 12:29:45 Mauro Carvalho Chehab wrote:
Quoted 25 lines

Em 26-04-2011 17:40, Ondrej Zary escreveu:

Quoted 15 lines · On Tuesday 26 April 2011 14:33:20 Hans Verkuil wrote:

After digging in the code for hours, I'm giving this up. It's not worth it.

The ISOC_MODE_YUV422 mode works as V4L2_PIX_FMT_YVYU with VLC and mplayer+libv4lconvert, reducing the loop (and dropping strech_*) in usbvision_parse_lines_422() to:
scratch_get(usbvision, frame->data + (frame->v4l2_linesize *
frame->curline), 2 * frame->frmwidth);

The ISOC_MODE_YUV420 is some weird custom format with 64-byte lines of YYUV. usbvision_parse_lines_420() is real mess with that scratch_* crap everywhere.

Quoted 8 lines

ISOC_MODE_COMPRESS: There are callbacks to usbvision_request_intra() and also usbvision_adjust_compression(). This is not going to work outside the kernel.

So I can redo the conversion removal patch to keep the RGB formats and also provide another one to remove the testpattern (it oopses too). But I'm not going to do any major changes in the driver.

Quoted 5 lines

While in a perfect world, this should be moved to userspace, I'm ok on keeping it there, but the OOPS/Panic conditions should be fixed.

Could you please work on a patch fixing the broken stuff, without removing the conversions?

I've already returned the hardware so I can't test the driver anymore.

Did the YUV422P conversion ever work? The initialization of u and v pointers is missing in usbvision_parse_compress() function for YUV422P case.

The following oops was captured when trying to fix YVU420. Seems to be related to the u pointer too...

[  181.169233] usbvision_parse_compress before conversion
[  181.169233] usbvision_parse_compress idx=0, format=842094169
[  181.169233] usbvision_parse_compress YVU420 f=e088d000, Y=e0a3e000
[  181.169233] usbvision_parse_compress YVU420 frame=df016b68
[  181.169233] usbvision_parse_compress YVU420 frame->curline=0
[  181.169233] usbvision_parse_compress YVU420 u=e08a4700, U=e0a50c00, v=e089fc00, V=e0a55700
[  181.169233] BUG: unable to handle kernel paging request at e08a4700
[  181.169233] IP: [<e097fd57>] usbvision_parse_compress+0x599/0x76e [usbvision]
[  181.169233] *pde = 1f0c2067 *pte = 00000000
[  181.169233] Oops: 0002 [#1] SMP
[  181.169233] last sysfs file: /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/i2c-0/uevent
[  181.169233] Modules linked in: savage drm loop usbvision v4l2_common snd_fm801 snd_tea575x_tuner videodev snd_intel8x0 e
[  181.169233]
[  181.169233] Pid: 0, comm: swapper Not tainted 2.6.39-rc2 #2    /848P-ICH5
[  181.169233] EIP: 0060:[<e097fd57>] EFLAGS: 00010046 CPU: 0
[  181.169233] EIP is at usbvision_parse_compress+0x599/0x76e [usbvision]
[  181.169233] EAX: 00000000 EBX: df016b68 ECX: e08a4700 EDX: e0a50c81
[  181.169233] ESI: 00000000 EDI: e088d001 EBP: 000000a0 ESP: df021cb4
[  181.169233]  DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068
[  181.169233] Process swapper (pid: 0, ti=df020000 task=c12dde60 task.ti=c12b0000)
[  181.169233] Stack:
[  181.169233]  e0986ed3 e09861a4 e08a4700 e0a50c00 e089fc00 e0a55700 00000003 e089fc00
[  181.169233]  e08a4700 000000c0 00000140 df021f14 df021d52 05060000 00060027 00000009
[  181.169233]  000000c0 00003293 00605a25 ff00605a fff0ffff 55d501fc 82995568 a0060124
[  181.169233] Call Trace:
[  181.169233]  [<e0c9c69d>] ? uhci_urb_enqueue+0x712/0x725 [uhci_hcd]
[  181.169233]  [<e08f4155>] ? usb_hcd_submit_urb+0x4be/0x53d [usbcore]
[  181.169233]  [<c11e9840>] ? printk+0xe/0x16
[  181.169233]  [<e0980486>] ? usbvision_isoc_irq+0x55a/0x17a0 [usbvision]
[  181.169233]  [<e097f5f9>] ? usbvision_write_reg_irq+0xd5/0x10f [usbvision]
[  181.169233]  [<e0981505>] ? usbvision_isoc_irq+0x15d9/0x17a0 [usbvision]
[  181.169233]  [<c1026eb2>] ? try_to_wake_up+0x13b/0x13b
[  181.169233]  [<c117057c>] ? ata_scsi_qc_complete+0x2b4/0x2c2
[  181.169233]  [<c101e899>] ? __wake_up+0x2c/0x3b
[  181.169233]  [<e08f33e5>] ? usb_hcd_giveback_urb+0x46/0x71 [usbcore]
[  181.169233]  [<e0c9a98d>] ? uhci_giveback_urb+0xea/0x15d [uhci_hcd]
[  181.169233]  [<e0c9aff7>] ? uhci_scan_schedule+0x526/0x777 [uhci_hcd]
[  181.169233]  [<c117951b>] ? __ata_sff_port_intr+0x97/0xa2
[  181.169233]  [<e0c9c9f8>] ? uhci_irq+0xbf/0xcd [uhci_hcd]
[  181.169233]  [<e08f2d2e>] ? usb_hcd_irq+0x1e/0x5f [usbcore]
[  181.169233]  [<c1058581>] ? handle_irq_event_percpu+0x1e/0x106
[  181.169233]  [<c1059edc>] ? handle_edge_irq+0xa0/0xa0
[  181.169233]  [<c105868a>] ? handle_irq_event+0x21/0x37
[  181.169233]  [<c1059edc>] ? handle_edge_irq+0xa0/0xa0
[  181.169233]  [<c1059f42>] ? handle_fasteoi_irq+0x66/0x7e
[  181.169233]  <IRQ>
[  181.169233]  [<c10035c7>] ? do_IRQ+0x2e/0x84
[  181.169233]  [<c11ec370>] ? common_interrupt+0x30/0x38
[  181.169233]  [<c1007699>] ? mwait_idle+0x4f/0x54
[  181.169233]  [<c1001a86>] ? cpu_idle+0x91/0xab
[  181.169233]  [<c12f96d4>] ? start_kernel+0x2a3/0x2a8
[  181.169233] Code: 08 ff 35 8c a1 98 e0 ff 74 24 14 68 a4 61 98 e0 68 d3 6e 98 e0 e8 ec 9a 86 e0 8b 15 8c a1 98 e0 89 f0
[  181.169233]  11 8b 15 88 a1 98 e0 41 89 4c 24 20 8a 04 02 8b 54 24 1c 88
[  181.169233] EIP: [<e097fd57>] usbvision_parse_compress+0x599/0x76e [usbvision] SS:ESP 0068:df021cb4
[  181.169233] CR2: 00000000e08a4700
[  181.169233] ---[ end trace aeedba237da329c1 ]---
#9 lore raw

Hi,

Quoted 10 lines · Mauro Carvalho Chehab

Hi Hans de G.,

Em 26-04-2011 08:54, Hans de Goede escreveu:

Quoted 4 lines

If you could give it a shot that would be great. I've some hardware to test this with (although I've never actually tested that hardware), so I can hopefully pick things up if you cannot finish things before you need to return the hardware.

As Ondrej couldn't work on that while he was with the hardware, could you please try to address this issue?

I've put it on my to do list, not sure when I'll get around to it though.

Regards,

Hans

#10 lore raw
In reply to Hans Verkuil

Hi,

Quoted 5 lines · Hans Verkuil
Quoted 4 lines · On Monday, April 25, 2011 23:23:17 Ondrej Zary wrote:

The YVU420 and YUV422P formats are broken and cause kernel panic on use. (YVU420 does not work and sometimes causes "unable to handle paging request" panic, YUV422P always causes "NULL pointer dereference").

Quoted 9 lines
Quoted 2 lines

As V4L2 spec says that drivers shouldn't do any in-kernel image format conversion, remove it completely (except YUYV).

What really should happen is that the conversion is moved to libv4lconvert. I've never had the time to tackle that, but it would improve this driver a lot.

Would you perhaps be interested in doing that work?

Seconded! I would be more then happy to help with the libv4l part (in the form of review + merging + advice).

Regards,

Hans