From 62ff9b8bcaaaf6deee32841ed20c8125f9946c09 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 9 Mar 2015 16:28:02 +0100 Subject: [PATCH] video-info: validate parsed colorimetry Validate the parsed colorimetry and reset to defaults when we get RGB with a matrix or YUV without a matrix. --- gst-libs/gst/video/video-info.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/gst-libs/gst/video/video-info.c b/gst-libs/gst/video/video-info.c index 9686e83391..98d87b0051 100644 --- a/gst-libs/gst/video/video-info.c +++ b/gst-libs/gst/video/video-info.c @@ -99,6 +99,22 @@ set_default_colorimetry (GstVideoInfo * info) } } +static gboolean +validate_colorimetry (GstVideoInfo * info) +{ + const GstVideoFormatInfo *finfo = info->finfo; + + if (!GST_VIDEO_FORMAT_INFO_IS_RGB (finfo) && + info->colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_RGB) + return FALSE; + + if (GST_VIDEO_FORMAT_INFO_IS_YUV (finfo) && + info->colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_UNKNOWN) + return FALSE; + + return TRUE; +} + /** * gst_video_info_set_format: * @info: a #GstVideoInfo @@ -244,10 +260,17 @@ gst_video_info_from_caps (GstVideoInfo * info, const GstCaps * caps) info->chroma_site = GST_VIDEO_CHROMA_SITE_UNKNOWN; if ((s = gst_structure_get_string (structure, "colorimetry"))) { - if (!gst_video_colorimetry_from_string (&info->colorimetry, s)) + if (!gst_video_colorimetry_from_string (&info->colorimetry, s)) { + GST_WARNING ("unparsable colorimetry, using default"); set_default_colorimetry (info); - } else + } else if (!validate_colorimetry (info)) { + GST_WARNING ("invalid colorimetry, using default"); + set_default_colorimetry (info); + } + } else { + GST_DEBUG ("no colorimetry, using default"); set_default_colorimetry (info); + } if (gst_structure_get_fraction (structure, "pixel-aspect-ratio", &par_n, &par_d)) {