diff options
author | He Junyan <junyan.he@intel.com> | 2020-07-11 23:37:29 +0800 |
---|---|---|
committer | Víctor Manuel Jáquez Leal <vjaquez@igalia.com> | 2020-11-30 16:45:54 +0000 |
commit | eb9be73299c9c3129b4141b60e71c9aefe0f6c07 (patch) | |
tree | 1dfe8695376159461166dc3bfdfbb05b6e52ff65 | |
parent | 33ef4ec817f5094381f8fb4fa2682e08e4583409 (diff) | |
download | gstreamer-vaapi-eb9be73299c9c3129b4141b60e71c9aefe0f6c07.tar.gz |
plugin: encode: vp9: Implement the set_config().
We store the allowed profiles list to encoder in set_config().
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi/-/merge_requests/380>
-rw-r--r-- | gst/vaapi/gstvaapiencode_vp9.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/gst/vaapi/gstvaapiencode_vp9.c b/gst/vaapi/gstvaapiencode_vp9.c index c1cfb778..a7cf7c27 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", |