v4l2: Fix support for caps without width, height, framerate or format
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Sat, 29 Mar 2014 23:13:06 +0000 (19:13 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Tue, 1 Apr 2014 18:28:08 +0000 (14:28 -0400)
For format like mpegts, width and height is rarely in the negotiated caps. This
patch fixes failure when setting format, and prevent introducing width, height,
framerate and format to the caps when fixating.

https://bugzilla.gnome.org/show_bug.cgi?id=725860

sys/v4l2/gstv4l2object.c
sys/v4l2/gstv4l2src.c

index c7f2138..b8f66c0 100644 (file)
@@ -2334,17 +2334,6 @@ gst_v4l2_object_set_format (GstV4l2Object * v4l2object, GstCaps * caps)
       "%" GST_FOURCC_FORMAT " stride: %d", width, height,
       GST_FOURCC_ARGS (pixelformat), v4l2object->bytesperline[0]);
 
-  /* MPEG-TS source cameras don't get their format set for some reason.
-   * It looks wrong and we weren't able to track down the reason for that code
-   * so it is disabled until someone who has an mpeg-ts camera complains...
-   */
-#if 0
-  /* Only unconditionally accept mpegts for sources */
-  if ((v4l2object->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
-      (pixelformat == GST_MAKE_FOURCC ('M', 'P', 'E', 'G')))
-    goto done;
-#endif
-
   memset (&format, 0x00, sizeof (struct v4l2_format));
   format.type = v4l2object->type;
 
@@ -2360,6 +2349,12 @@ gst_v4l2_object_set_format (GstV4l2Object * v4l2object, GstCaps * caps)
         GST_FOURCC_ARGS (format.fmt.pix.pixelformat),
         format.fmt.pix_mp.colorspace, format.fmt.pix_mp.num_planes);
 
+    /* If no size in caps, use configured size */
+    if (width == 0 && height == 0) {
+      width = format.fmt.pix_mp.width;
+      height = format.fmt.pix_mp.height;
+    }
+
     if (format.type != v4l2object->type ||
         format.fmt.pix_mp.width != width ||
         format.fmt.pix_mp.height != height ||
@@ -2439,6 +2434,12 @@ gst_v4l2_object_set_format (GstV4l2Object * v4l2object, GstCaps * caps)
         GST_FOURCC_ARGS (format.fmt.pix.pixelformat),
         format.fmt.pix.bytesperline, format.fmt.pix.colorspace);
 
+    /* If no size in caps, use configured size */
+    if (width == 0 && height == 0) {
+      width = format.fmt.pix_mp.width;
+      height = format.fmt.pix_mp.height;
+    }
+
     if (format.type != v4l2object->type ||
         format.fmt.pix.width != width ||
         format.fmt.pix.height != height ||
index 2543b4e..e388a3f 100644 (file)
@@ -260,13 +260,20 @@ gst_v4l2src_fixate (GstBaseSrc * basesrc, GstCaps * caps)
   for (i = 0; i < gst_caps_get_size (caps); ++i) {
     structure = gst_caps_get_structure (caps, i);
 
-    /* We are fixating to a resonable 320x200 resolution
+    /* We are fixating to a reasonable 320x200 resolution
        and the maximum framerate resolution for that size */
-    gst_structure_fixate_field_nearest_int (structure, "width", 320);
-    gst_structure_fixate_field_nearest_int (structure, "height", 200);
-    gst_structure_fixate_field_nearest_fraction (structure, "framerate",
-        G_MAXINT, 1);
-    gst_structure_fixate_field (structure, "format");
+    if (gst_structure_has_field (structure, "width"))
+      gst_structure_fixate_field_nearest_int (structure, "width", 320);
+
+    if (gst_structure_has_field (structure, "height"))
+      gst_structure_fixate_field_nearest_int (structure, "height", 200);
+
+    if (gst_structure_has_field (structure, "framerate"))
+      gst_structure_fixate_field_nearest_fraction (structure, "framerate",
+          G_MAXINT, 1);
+
+    if (gst_structure_has_field (structure, "format"))
+      gst_structure_fixate_field (structure, "format");
   }
 
   GST_DEBUG_OBJECT (basesrc, "fixated caps %" GST_PTR_FORMAT, caps);