diff --git a/gst-libs/gst/vaapi/gstvaapiencoder.c b/gst-libs/gst/vaapi/gstvaapiencoder.c index bdb8d9ef49..d761bfa242 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder.c @@ -1511,6 +1511,49 @@ gst_vaapi_encoder_ensure_num_slices (GstVaapiEncoder * encoder, return TRUE; } +/** + * gst_vaapi_encoder_ensure_max_num_ref_frames: + * @encoder: a #GstVaapiEncoder + * @profile: a #GstVaapiProfile + * @entrypoint: a #GstVaapiEntrypoint + * + * This function will query VAConfigAttribEncMaxRefFrames to get the + * maximum number of reference frames in the driver, + * for both the reference picture list 0 (bottom 16 bits) and + * the reference picture list 1 (top 16 bits). + * + * We need to pass the @profile and the @entrypoint, because at the + * moment the encoder base class, still doesn't have them assigned, + * and this function is meant to be called by the derived classes + * while they are configured. + * + * Returns: %TRUE if the number of reference frames is different than zero. + **/ +gboolean +gst_vaapi_encoder_ensure_max_num_ref_frames (GstVaapiEncoder * encoder, + GstVaapiProfile profile, GstVaapiEntrypoint entrypoint) +{ + VAProfile va_profile; + VAEntrypoint va_entrypoint; + guint max_ref_frames; + + va_profile = gst_vaapi_profile_get_va_profile (profile); + va_entrypoint = gst_vaapi_entrypoint_get_va_entrypoint (entrypoint); + + if (!gst_vaapi_get_config_attribute (encoder->display, va_profile, + va_entrypoint, VAConfigAttribEncMaxRefFrames, &max_ref_frames)) { + /* Set the default the number of reference frames */ + encoder->max_num_ref_frames_0 = 1; + encoder->max_num_ref_frames_1 = 0; + return TRUE; + } + + encoder->max_num_ref_frames_0 = max_ref_frames & 0xffff; + encoder->max_num_ref_frames_1 = (max_ref_frames >> 16) & 0xffff; + + return TRUE; +} + /** * gst_vaapi_encoder_add_roi: * @encoder: a #GstVaapiEncoder diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_priv.h b/gst-libs/gst/vaapi/gstvaapiencoder_priv.h index 598aabf263..d73689e409 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_priv.h +++ b/gst-libs/gst/vaapi/gstvaapiencoder_priv.h @@ -261,6 +261,11 @@ struct _GstVaapiEncoder guint bitrate; /* kbps */ guint keyframe_period; + /* Maximum number of reference frames supported + * for the reference picture list 0 and list 2 */ + guint max_num_ref_frames_0; + guint max_num_ref_frames_1; + /* parameters */ VAEncMiscParameterBufferQualityLevel va_quality_level; @@ -411,6 +416,11 @@ gst_vaapi_encoder_ensure_num_slices (GstVaapiEncoder * encoder, GstVaapiProfile profile, GstVaapiEntrypoint entrypoint, guint media_max_slices, guint * num_slices); +G_GNUC_INTERNAL +gboolean +gst_vaapi_encoder_ensure_max_num_ref_frames (GstVaapiEncoder * encoder, + GstVaapiProfile profile, GstVaapiEntrypoint entrypoint); + G_END_DECLS #endif /* GST_VAAPI_ENCODER_PRIV_H */