video-info: check if alternate caps has the feature as well
authorGuillaume Desmottes <guillaume.desmottes@collabora.com>
Tue, 11 Dec 2018 10:37:36 +0000 (11:37 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.com>
Mon, 25 Mar 2019 14:36:57 +0000 (15:36 +0100)
It's invalid to have a 'interlace-mode=alternate' without the Interlaced caps
feature as well.
Modify gst_video_info_from_caps() to reject such case so we can easily
spot them in bugged elements.

gst-libs/gst/video/video-info.c
tests/check/libs/video.c

index 1acac24..cc98cfc 100644 (file)
@@ -455,6 +455,17 @@ gst_video_info_from_caps (GstVideoInfo * info, const GstCaps * caps)
   else
     info->interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
 
+  /* Interlaced feature is mandatory for raw alternate streams */
+  if (info->interlace_mode == GST_VIDEO_INTERLACE_MODE_ALTERNATE &&
+      format != GST_VIDEO_FORMAT_ENCODED) {
+    GstCapsFeatures *f;
+
+    f = gst_caps_get_features (caps, 0);
+    if (!f
+        || !gst_caps_features_contains (f, GST_CAPS_FEATURE_FORMAT_INTERLACED))
+      goto alternate_no_feature;
+  }
+
   if ((info->interlace_mode == GST_VIDEO_INTERLACE_MODE_INTERLEAVED ||
           info->interlace_mode == GST_VIDEO_INTERLACE_MODE_ALTERNATE) &&
       (s = gst_structure_get_string (structure, "field-order"))) {
@@ -541,6 +552,12 @@ no_height:
     GST_ERROR ("no height property given");
     return FALSE;
   }
+alternate_no_feature:
+  {
+    GST_ERROR
+        ("caps has 'interlace-mode=alternate' but doesn't have the Interlaced feature");
+    return FALSE;
+  }
 }
 
 /**
index 0959318..8afea68 100644 (file)
@@ -1309,6 +1309,25 @@ GST_START_TEST (test_interlace_mode)
       GST_VIDEO_FIELD_ORDER_TOP_FIELD_FIRST);
 
   gst_caps_unref (caps);
+
+  /* gst_video_info_from_caps() fails if an alternate stream doesn't contain
+   * the caps feature. */
+  caps =
+      gst_caps_from_string
+      ("video/x-raw, format=NV12, width=320, height=240, interlace-mode=alternate");
+  fail_unless (caps);
+
+  fail_if (gst_video_info_from_caps (&vinfo, caps));
+  gst_caps_unref (caps);
+
+  /* ... but it's ok for encoded video */
+  caps =
+      gst_caps_from_string
+      ("video/x-h265, width=320, height=240, interlace-mode=alternate");
+  fail_unless (caps);
+
+  fail_unless (gst_video_info_from_caps (&vinfo, caps));
+  gst_caps_unref (caps);
 }
 
 GST_END_TEST;