[MPlayer-dev-eng] [PATCH] tvi_v4l2.c `set format' fixes

Szabo Peter pts at inf.bme.hu
Tue Mar 15 14:09:18 CET 2005


Dear Developers,

The attached patch contains fix for an YV12 misdetection, and it also
supplies default values if the format specified in `-tv outfmt=' cannot be
enforced.

Best regards,

Péter

--- (vvv use GNU); pts at inf.bme.hu; http://www.inf.bme.hu/~pts
[/dlflg/=u]dZ[lflglblp*lqlg*+lpla*lqlf*+sfsgsbdsalblex]dscZ[lb%O]sdzzKsa
[nlaldx*lflg%O*sfdsalblex]dsuZ[.]zsqsssgsbnsfspselsn[lcxsslqdlp+spz+sqdx]dx
-------------- next part --------------
--- libmpdemux/tvi_v4l2.c.orig	2005-03-15 14:55:34.997965176 +0100
+++ libmpdemux/tvi_v4l2.c	2005-03-15 15:28:56.135745992 +0100
@@ -491,6 +491,22 @@
     return TVI_CONTROL_TRUE;
 }
 
+static int fallback_pixelformats[]={ /**** pts ****/
+  IMGFMT_UYVY, /* Dat: YUV with least loss */
+  IMGFMT_YUY2,
+  IMGFMT_422P,
+  IMGFMT_YV12,
+  IMGFMT_RGB24, /* Dat: might produce error stripes in 768x576 */
+  IMGFMT_BGR24,
+  IMGFMT_RGB32,
+  IMGFMT_BGR32,
+  IMGFMT_I420,
+  IMGFMT_RGB16,
+  IMGFMT_RGB15,
+  IMGFMT_Y800,
+  0
+};
+
 static int control(priv_t *priv, int cmd, void *arg)
 {
     struct v4l2_control control;
@@ -540,9 +556,23 @@
 	mp_msg(MSGT_TV, MSGL_V, "%s: set format: %s\n", info.short_name,
 	       pixfmt2name(priv->format.fmt.pix.pixelformat));
 	if (ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) {
-	    mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set format failed: %s\n",
-		   info.short_name, strerror(errno));
-	    return TVI_CONTROL_FALSE;
+	    int i; /**** pts ****/
+	    for (i=0; fallback_pixelformats[i]!=0; i++) {
+		priv->format.fmt.pix.pixelformat = fcc_mp2vl(fallback_pixelformats[i]);
+		priv->format.fmt.pix.field = V4L2_FIELD_ANY;
+		priv->mp_format = fallback_pixelformats[i];
+		mp_msg(MSGT_TV, MSGL_V, "%s: set fallback format: %s\n", info.short_name,
+		       pixfmt2name(priv->format.fmt.pix.pixelformat));
+		if (ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) >= 0) break;
+	    }
+	    if (fallback_pixelformats[i]==0) {
+		priv->format.fmt.pix.pixelformat=-1;
+		getfmt(priv);
+		priv->mp_format=fcc_vl2mp(priv->format.fmt.pix.pixelformat); /* Imp: special case for priv->mp_format == IMGFMT_YV12 && priv->format.fmt.pix.pixelformat == V4L2_PIX_FMT_YUV420 */
+		mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set format failed: %s\n",
+		       info.short_name, strerror(errno));
+		return TVI_CONTROL_FALSE;
+	    }
 	}
 	return TVI_CONTROL_TRUE;
     case TVI_CONTROL_VID_GET_WIDTH:
@@ -1301,13 +1331,12 @@
     int bytesperline = w*d/8;
 
     // YV12 uses VIDEO_PALETTE_YUV420P, but the planes are swapped
-    switch (priv->mp_format) {
-    case IMGFMT_YV12:
+    if (priv->mp_format == IMGFMT_YV12 && priv->format.fmt.pix.pixelformat == V4L2_PIX_FMT_YUV420) {
+        /**** pts ****/ /* ^^^ Dat: corrected condition above; Imp: same fix in tvi_v4l.c:copy_frame() */
 	memcpy(dest, source, w * h);
 	memcpy(dest+w * h*5/4, source+w * h, w * h/4);
 	memcpy(dest+w * h, source+w * h*5/4, w * h/4);
-	break;
-    default:
+    } else {
 	memcpy(dest, source, bytesperline * h);
     }
     


More information about the MPlayer-dev-eng mailing list