diff --git a/gst/vaapi/gstvaapiencode_vp9.c b/gst/vaapi/gstvaapiencode_vp9.c index c1cfb778bc..a7cf7c278c 100644 --- a/gst/vaapi/gstvaapiencode_vp9.c +++ b/gst/vaapi/gstvaapiencode_vp9.c @@ -99,6 +99,85 @@ gst_vaapiencode_vp9_alloc_encoder (GstVaapiEncode * base, return gst_vaapi_encoder_vp9_new (display); } +static gboolean +gst_vaapiencode_vp9_set_config (GstVaapiEncode * base_encode) +{ + GstVaapiEncoderVP9 *const encoder = + GST_VAAPI_ENCODER_VP9 (base_encode->encoder); + GstCaps *allowed_caps = NULL; + GstCaps *template_caps = NULL; + GArray *profiles = NULL; + GArray *profiles_hw = NULL; + GArray *profiles_allowed = NULL; + GstVaapiProfile profile; + gboolean ret = TRUE; + guint i, j; + + profiles_hw = gst_vaapi_display_get_encode_profiles_by_codec + (GST_VAAPI_PLUGIN_BASE_DISPLAY (base_encode), GST_VAAPI_CODEC_VP9); + if (!profiles_hw) { + ret = FALSE; + goto out; + } + + template_caps = + gst_pad_get_pad_template_caps (GST_VAAPI_PLUGIN_BASE_SRC_PAD + (base_encode)); + allowed_caps = + gst_pad_get_allowed_caps (GST_VAAPI_PLUGIN_BASE_SRC_PAD (base_encode)); + if (!allowed_caps || allowed_caps == template_caps) { + ret = gst_vaapi_encoder_vp9_set_allowed_profiles (encoder, profiles_hw); + goto out; + } else if (gst_caps_is_empty (allowed_caps)) { + ret = FALSE; + goto out; + } + + profiles = gst_vaapi_encoder_get_profiles_from_caps (allowed_caps, + gst_vaapi_utils_vp9_get_profile_from_string); + if (!profiles) { + ret = FALSE; + goto out; + } + + profiles_allowed = g_array_new (FALSE, FALSE, sizeof (GstVaapiProfile)); + if (!profiles_allowed) { + ret = FALSE; + goto out; + } + + for (i = 0; i < profiles->len; i++) { + profile = g_array_index (profiles, GstVaapiProfile, i); + for (j = 0; j < profiles_hw->len; j++) { + GstVaapiProfile p = g_array_index (profiles_hw, GstVaapiProfile, j); + if (p == profile) { + g_array_append_val (profiles_allowed, profile); + break; + } + } + } + if (profiles_allowed->len == 0) { + ret = FALSE; + goto out; + } + + ret = gst_vaapi_encoder_vp9_set_allowed_profiles (encoder, profiles_allowed); + +out: + if (allowed_caps) + gst_caps_unref (allowed_caps); + if (template_caps) + gst_caps_unref (template_caps); + if (profiles) + g_array_unref (profiles); + if (profiles_hw) + g_array_unref (profiles_hw); + if (profiles_allowed) + g_array_unref (profiles_allowed); + + return ret; +} + static void gst_vaapiencode_vp9_class_init (GstVaapiEncodeVP9Class * klass, gpointer data) { @@ -118,6 +197,7 @@ gst_vaapiencode_vp9_class_init (GstVaapiEncodeVP9Class * klass, gpointer data) encode_class->get_allowed_profiles = gst_vaapiencode_vp9_get_allowed_profiles; encode_class->get_caps = gst_vaapiencode_vp9_get_caps; encode_class->alloc_encoder = gst_vaapiencode_vp9_alloc_encoder; + encode_class->set_config = gst_vaapiencode_vp9_set_config; gst_element_class_set_static_metadata (element_class, "VA-API VP9 encoder",