From b756b13ee2541e9899536c0594475dee6026488a Mon Sep 17 00:00:00 2001 From: "U. Artie Eoff" Date: Fri, 21 Jun 2019 18:18:44 -0700 Subject: [PATCH] msdkmjpegdec: support 422 output MSDK supports JPEG YUY2 (422 chroma) output color format. The color format of input bitstream is described by JPEGChromaFormat and JPEGColorFormat fields in the mfxInfoMFX structure which is filled in by the MFXVideoDECODE_DecodeHeader function. To obtain lossless decoded output from 422 encoded JPEGs, we must set the output color format in the FourCC and ChromaFormat fields in the mfxFrameInfo structure to the appropriate values at post_configure so that they are propagated through to the srcpad caps accordingly. --- sys/msdk/gstmsdkmjpegdec.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/sys/msdk/gstmsdkmjpegdec.c b/sys/msdk/gstmsdkmjpegdec.c index 69845016c6..75029da67f 100644 --- a/sys/msdk/gstmsdkmjpegdec.c +++ b/sys/msdk/gstmsdkmjpegdec.c @@ -37,6 +37,7 @@ #include #include "gstmsdkmjpegdec.h" +#include "gstmsdkvideomemory.h" #include @@ -50,6 +51,18 @@ static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], parsed = true ") ); +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/x-raw, " + "format = (string) { NV12, YUY2 }, " + "framerate = (fraction) [0, MAX], " + "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ]," + "interlace-mode = (string) progressive;" + GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF, + "{ NV12, YUY2 }") ";") + ); + #define gst_msdkmjpegdec_parent_class parent_class G_DEFINE_TYPE (GstMsdkMJPEGDec, gst_msdkmjpegdec, GST_TYPE_MSDKDEC); @@ -65,6 +78,24 @@ gst_msdkmjpegdec_configure (GstMsdkDec * decoder) the InterleaveDec to MFX_SCANTYPE_NONINTERLEAVED, msdk seems to be taking care of Interleaved samples, so let's hardcode it for now */ decoder->param.mfx.InterleavedDec = MFX_SCANTYPE_NONINTERLEAVED; + + return TRUE; +} + +static gboolean +gst_msdkmjpegdec_post_configure (GstMsdkDec * decoder) +{ + /* Set the output color format based on the input color format */ + switch (decoder->param.mfx.JPEGChromaFormat) { + case MFX_CHROMAFORMAT_YUV422: + decoder->param.mfx.FrameInfo.FourCC = MFX_FOURCC_YUY2; + decoder->param.mfx.FrameInfo.ChromaFormat = + decoder->param.mfx.JPEGChromaFormat; + break; + default: + break; + } + return TRUE; } @@ -78,6 +109,8 @@ gst_msdkmjpegdec_class_init (GstMsdkMJPEGDecClass * klass) decoder_class = GST_MSDKDEC_CLASS (klass); decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkmjpegdec_configure); + decoder_class->post_configure = + GST_DEBUG_FUNCPTR (gst_msdkmjpegdec_post_configure); gst_element_class_set_static_metadata (element_class, "Intel MSDK MJPEG decoder", @@ -86,6 +119,7 @@ gst_msdkmjpegdec_class_init (GstMsdkMJPEGDecClass * klass) "Scott D Phillips "); gst_element_class_add_static_pad_template (element_class, &sink_factory); + gst_element_class_add_static_pad_template (element_class, &src_factory); } static void