From ec76a9a7e3eb1da58190799c15854897daa2898e Mon Sep 17 00:00:00 2001 From: Hyunjun Ko Date: Fri, 28 Jul 2017 15:27:20 +0900 Subject: libs: encoder: implements gst_vaapi_encoder_ensure_max_num_ref_frames This function will query VAConfigAttribEncMaxRefFrames to get the maximum number of reference frames supported in the driver. This will be used for h264/h265 encoding. https://bugzilla.gnome.org/show_bug.cgi?id=783803 --- gst-libs/gst/vaapi/gstvaapiencoder.c | 43 +++++++++++++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapiencoder_priv.h | 10 +++++++ 2 files changed, 53 insertions(+) diff --git a/gst-libs/gst/vaapi/gstvaapiencoder.c b/gst-libs/gst/vaapi/gstvaapiencoder.c index bdb8d9ef..d761bfa2 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 598aabf2..d73689e4 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 */ -- cgit v1.2.3