From 5628955624ad682b7eace79729c5bb80b2ae6e77 Mon Sep 17 00:00:00 2001 From: Mengkejiergeli Ba Date: Wed, 15 Sep 2021 13:59:17 +0800 Subject: [PATCH] msdkenc: Pass color properties to MediaSDK for encoding Part-of: --- sys/msdk/gstmsdkenc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sys/msdk/gstmsdkenc.c b/sys/msdk/gstmsdkenc.c index db48f49..dd1ea3b 100644 --- a/sys/msdk/gstmsdkenc.c +++ b/sys/msdk/gstmsdkenc.c @@ -49,6 +49,7 @@ #include "gstmsdkvideomemory.h" #include "gstmsdksystemmemory.h" #include "gstmsdkcontextutil.h" +#include "mfxjpeg.h" #ifndef _WIN32 #include "gstmsdkallocator_libva.h" @@ -483,6 +484,7 @@ gst_msdkenc_init_encoder (GstMsdkEnc * thiz) guint i; gboolean need_vpp = TRUE; GstVideoFormat encoder_input_fmt; + mfxExtVideoSignalInfo ext_vsi; if (thiz->initialized) { GST_DEBUG_OBJECT (thiz, "Already initialized"); @@ -733,6 +735,25 @@ gst_msdkenc_init_encoder (GstMsdkEnc * thiz) goto failed; } + /* If color properties are available from upstream, set it and pass to MediaSDK here. + * MJPEG is excluded from color config below as it is different from other codecs in + * mfxInfoMFX struct. + */ + if (thiz->param.mfx.CodecId != MFX_CODEC_JPEG && (info->colorimetry.primaries + || info->colorimetry.transfer || info->colorimetry.matrix)) { + memset (&ext_vsi, 0, sizeof (ext_vsi)); + ext_vsi.Header.BufferId = MFX_EXTBUFF_VIDEO_SIGNAL_INFO; + ext_vsi.Header.BufferSz = sizeof (ext_vsi); + ext_vsi.ColourDescriptionPresent = 1; + ext_vsi.ColourPrimaries = + gst_video_color_primaries_to_iso (info->colorimetry.primaries); + ext_vsi.TransferCharacteristics = + gst_video_transfer_function_to_iso (info->colorimetry.transfer); + ext_vsi.MatrixCoefficients = + gst_video_color_matrix_to_iso (info->colorimetry.matrix); + gst_msdkenc_add_extra_param (thiz, (mfxExtBuffer *) & ext_vsi); + } + if (thiz->num_extra_params) { thiz->param.NumExtParam = thiz->num_extra_params; thiz->param.ExtParam = thiz->extra_params; -- 2.7.4