From 0e2fc39f24cb8b7ba554ffee5a9e2fe5de531709 Mon Sep 17 00:00:00 2001 From: Haihao Xiang Date: Thu, 28 Nov 2019 14:54:30 +0800 Subject: [PATCH] msdkenc: add need_reconfig virtual method need_reconfig is added to allow sub class requires a reconfig when the input frame or the MetaData (e.g. GstVideoRegionOfInterestMeta) attached to the input frame is changed. --- sys/msdk/gstmsdkenc.c | 16 +++++++++------- sys/msdk/gstmsdkenc.h | 3 +++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sys/msdk/gstmsdkenc.c b/sys/msdk/gstmsdkenc.c index fad4357..74b7ecc 100644 --- a/sys/msdk/gstmsdkenc.c +++ b/sys/msdk/gstmsdkenc.c @@ -1374,22 +1374,17 @@ static GstFlowReturn gst_msdkenc_handle_frame (GstVideoEncoder * encoder, GstVideoCodecFrame * frame) { GstMsdkEnc *thiz = GST_MSDKENC (encoder); + GstMsdkEncClass *klass = GST_MSDKENC_GET_CLASS (thiz); GstVideoInfo *info = &thiz->input_state->info; FrameData *fdata; MsdkSurface *surface; - if (thiz->reconfig) { - mfxInfoMFX *mfx = NULL; - - GST_INFO_OBJECT (encoder, "Adjust encoder bitrate before current frame"); + if (thiz->reconfig || klass->need_reconfig (thiz, frame)) { gst_msdkenc_flush_frames (thiz, FALSE); gst_msdkenc_close_encoder (thiz); // This will reinitialized the encoder but keep same input format. gst_msdkenc_set_format (encoder, NULL); - - mfx = &thiz->param.mfx; - GST_INFO_OBJECT (encoder, "New target bitrate: %u", mfx->TargetKbps); } if (G_UNLIKELY (thiz->context == NULL)) @@ -1682,6 +1677,12 @@ gst_msdkenc_need_conversion (GstMsdkEnc * encoder, GstVideoInfo * info, } } +static gboolean +gst_msdkenc_need_reconfig (GstMsdkEnc * encoder, GstVideoCodecFrame * frame) +{ + return FALSE; +} + static void gst_msdkenc_class_init (GstMsdkEncClass * klass) { @@ -1694,6 +1695,7 @@ gst_msdkenc_class_init (GstMsdkEncClass * klass) gstencoder_class = GST_VIDEO_ENCODER_CLASS (klass); klass->need_conversion = gst_msdkenc_need_conversion; + klass->need_reconfig = gst_msdkenc_need_reconfig; gobject_class->finalize = gst_msdkenc_finalize; diff --git a/sys/msdk/gstmsdkenc.h b/sys/msdk/gstmsdkenc.h index 6ee84b0..e209720 100644 --- a/sys/msdk/gstmsdkenc.h +++ b/sys/msdk/gstmsdkenc.h @@ -174,6 +174,9 @@ struct _GstMsdkEncClass */ gboolean (*need_conversion) (GstMsdkEnc * encoder, GstVideoInfo * info, GstVideoFormat * out_format); + + /* Return TRUE if sub class requires a recofnig */ + gboolean (*need_reconfig) (GstMsdkEnc * encoder, GstVideoCodecFrame * frame); }; struct _MsdkEncTask -- 2.7.4