Commit 0e2fc39f authored by Haihao Xiang's avatar Haihao Xiang

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.
parent 6e73e762
......@@ -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;
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment