vaapipostproc: use sink resolution to calculate src colorimetry
authorU. Artie Eoff <ullysses.a.eoff@intel.com>
Tue, 4 Feb 2020 22:17:43 +0000 (14:17 -0800)
committerU. Artie Eoff <ullysses.a.eoff@intel.com>
Wed, 5 Feb 2020 18:33:23 +0000 (10:33 -0800)
The default output colorimetry is persuaded by the output
resolution, which is too naive when doing VPP cropping
and/or scaling.  For example, scaling 4K(sink)->1080P(src)
resolution (i.e. both YUV) results in bt2020(sink)->bt709(src)
colorimetry selection and some drivers don't support that
mode in vpp.

Thus, if output (i.e. downstream) does not specify a
colorimetry then we use the input resolution instead of the
output resolution to create the default colorimetry.  Also,
note that we still use the output format since it may be a
different color space than the input.  As in the example
above, this will result in bt2020(sink)->bt2020(src)
colorimetry selection and all drivers (afaik) should support
that in vpp.

gst/vaapi/gstvaapipostprocutil.c

index 51cf7d7..94ece02 100644 (file)
@@ -595,8 +595,8 @@ _set_multiview_mode (GstVaapiPostproc * postproc, GstVideoInfo * vinfo,
 }
 
 static gboolean
-_set_colorimetry (GstVaapiPostproc * postproc, GstVideoFormat format,
-    GstStructure * outs)
+_set_colorimetry (GstVaapiPostproc * postproc, GstVideoInfo * sinkinfo,
+    GstVideoFormat format, GstStructure * outs)
 {
   GstVideoInfo vinfo;
   GstVideoColorimetry colorimetry;
@@ -607,7 +607,10 @@ _set_colorimetry (GstVaapiPostproc * postproc, GstVideoFormat format,
       || !gst_structure_get_int (outs, "height", &height))
     return FALSE;
 
-  gst_video_info_set_format (&vinfo, format, width, height);
+  /* Use the sink resolution and the src format to correctly determine the
+   * default src colorimetry. */
+  gst_video_info_set_format (&vinfo, format, GST_VIDEO_INFO_WIDTH (sinkinfo),
+      GST_VIDEO_INFO_HEIGHT (sinkinfo));
 
   if (GST_VIDEO_INFO_CHROMA_SITE (&vinfo) != GST_VIDEO_CHROMA_SITE_UNKNOWN) {
     gst_structure_set (outs, "chroma-site", G_TYPE_STRING,
@@ -719,7 +722,7 @@ _get_preferred_caps (GstVaapiPostproc * postproc, GstVideoInfo * vinfo,
     goto fixate_failed;
   _set_multiview_mode (postproc, vinfo, structure);
 
-  if (!_set_colorimetry (postproc, format, structure))
+  if (!_set_colorimetry (postproc, vinfo, format, structure))
     goto fixate_failed;
 
   if (!_set_interlace_mode (postproc, vinfo, structure))