diff --git a/gst-libs/gst/vaapi/gstvaapiencoder.c b/gst-libs/gst/vaapi/gstvaapiencoder.c index ef2675f17f..e56886fa12 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder.c @@ -307,18 +307,21 @@ static gboolean gst_vaapi_encoder_ensure_context (GstVaapiEncoder * encoder) { GstVaapiEncoderClass *const klass = GST_VAAPI_ENCODER_GET_CLASS (encoder); - GstVaapiContextInfo info; + GstVaapiContextInfo *const cip = &encoder->context_info; GstVaapiContext *context; if (GST_VAAPI_ENCODER_CONTEXT (encoder)) return TRUE; - memset (&info, 0, sizeof (info)); - if (!klass->get_context_info (encoder, &info)) - return FALSE; + cip->profile = GST_VAAPI_PROFILE_UNKNOWN; + cip->entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE; + cip->rc_mode = GST_VAAPI_ENCODER_RATE_CONTROL (encoder); + cip->width = GST_VAAPI_ENCODER_WIDTH (encoder); + cip->height = GST_VAAPI_ENCODER_HEIGHT (encoder); + cip->ref_frames = 0; + klass->set_context_info (encoder); - context = gst_vaapi_context_new_full (GST_VAAPI_ENCODER_DISPLAY (encoder), - &info); + context = gst_vaapi_context_new_full (encoder->display, cip); if (!context) return FALSE; @@ -406,7 +409,7 @@ gst_vaapi_encoder_init (GstVaapiEncoder * encoder, GstVaapiDisplay * display) CHECK_VTABLE_HOOK (encode); CHECK_VTABLE_HOOK (reordering); CHECK_VTABLE_HOOK (flush); - CHECK_VTABLE_HOOK (get_context_info); + CHECK_VTABLE_HOOK (set_context_info); CHECK_VTABLE_HOOK (set_format); #undef CHECK_VTABLE_HOOK diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c index 076273c870..d23646f216 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c @@ -1585,23 +1585,15 @@ end: return GST_VAAPI_ENCODER_STATUS_SUCCESS; } -static gboolean -gst_vaapi_encoder_h264_get_context_info (GstVaapiEncoder * base, - GstVaapiContextInfo * info) +static void +gst_vaapi_encoder_h264_set_context_info (GstVaapiEncoder * base_encoder) { - GstVaapiEncoderH264 *encoder = GST_VAAPI_ENCODER_H264 (base); - const static guint default_surface_num = 3; + GstVaapiEncoderH264 *const encoder = GST_VAAPI_ENCODER_H264 (base_encoder); + GstVaapiContextInfo *const cip = &base_encoder->context_info; + const guint DEFAULT_SURFACES_COUNT = 3; - g_return_val_if_fail (info, FALSE); - - info->profile = encoder->profile; - info->entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE; - info->width = GST_VAAPI_ENCODER_WIDTH (encoder); - info->height = GST_VAAPI_ENCODER_HEIGHT (encoder); - info->ref_frames = (encoder->b_frame_num ? 2 : 1) + default_surface_num; - info->rc_mode = GST_VAAPI_ENCODER_RATE_CONTROL (encoder); - - return TRUE; + cip->profile = encoder->profile; + cip->ref_frames = (encoder->b_frame_num ? 2 : 1) + DEFAULT_SURFACES_COUNT; } static GstCaps * diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c index 5bc01d55b2..876dc6d995 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c @@ -627,22 +627,14 @@ to_vaapi_profile (guint32 profile) return p; } -static gboolean -gst_vaapi_encoder_mpeg2_get_context_info (GstVaapiEncoder * base, - GstVaapiContextInfo * info) +static void +gst_vaapi_encoder_mpeg2_set_context_info (GstVaapiEncoder * base_encoder) { - GstVaapiEncoderMpeg2 *encoder = GST_VAAPI_ENCODER_MPEG2 (base); + GstVaapiEncoderMpeg2 *const encoder = GST_VAAPI_ENCODER_MPEG2 (base_encoder); + GstVaapiContextInfo *const cip = &base_encoder->context_info; - g_return_val_if_fail (info, FALSE); - - info->profile = to_vaapi_profile (encoder->profile); - info->entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE; - info->width = GST_VAAPI_ENCODER_WIDTH (encoder); - info->height = GST_VAAPI_ENCODER_HEIGHT (encoder); - info->ref_frames = 2; - info->rc_mode = GST_VAAPI_ENCODER_RATE_CONTROL (encoder); - - return TRUE; + cip->profile = to_vaapi_profile (encoder->profile); + cip->ref_frames = 2; } static gboolean diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_priv.h b/gst-libs/gst/vaapi/gstvaapiencoder_priv.h index 10b1ff9df9..e570602530 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_priv.h +++ b/gst-libs/gst/vaapi/gstvaapiencoder_priv.h @@ -80,6 +80,7 @@ struct _GstVaapiEncoder GstVaapiDisplay *display; GstVaapiContext *context; + GstVaapiContextInfo context_info; GstCaps *caps; VADisplay va_display; @@ -106,8 +107,7 @@ struct _GstVaapiEncoderClass GstVideoCodecState * in_state, GstCaps * ref_caps); - gboolean (*get_context_info) (GstVaapiEncoder * encoder, - GstVaapiContextInfo * info); + void (*set_context_info) (GstVaapiEncoder * encoder); GstVaapiEncoderStatus (*reordering) (GstVaapiEncoder * encoder, GstVideoCodecFrame * in, @@ -137,7 +137,7 @@ struct _GstVaapiEncoderClass GST_VAAPI_ENCODER_CLASS_HOOK (codec, init), \ GST_VAAPI_ENCODER_CLASS_HOOK (codec, finalize), \ GST_VAAPI_ENCODER_CLASS_HOOK (codec, set_format), \ - GST_VAAPI_ENCODER_CLASS_HOOK (codec, get_context_info), \ + GST_VAAPI_ENCODER_CLASS_HOOK (codec, set_context_info), \ GST_VAAPI_ENCODER_CLASS_HOOK (codec, reordering), \ GST_VAAPI_ENCODER_CLASS_HOOK (codec, encode), \ GST_VAAPI_ENCODER_CLASS_HOOK (codec, flush)