diff --git a/gst-libs/gst/video/video-info.c b/gst-libs/gst/video/video-info.c index 1acac24e16..cc98cfc658 100644 --- a/gst-libs/gst/video/video-info.c +++ b/gst-libs/gst/video/video-info.c @@ -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; + } } /** diff --git a/tests/check/libs/video.c b/tests/check/libs/video.c index 0959318127..8afea6804b 100644 --- a/tests/check/libs/video.c +++ b/tests/check/libs/video.c @@ -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;