From d7764275d819e6c419ef7eed1ea174ebd1aa041b Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Fri, 15 Jan 2021 08:47:10 -0300 Subject: [PATCH] formatter: Use the new `GstEncodingProfile:element-properties` property Cleaning up the code and making everything simpler. Part-of: --- ges/ges-base-xml-formatter.c | 33 ++------------------- ges/ges-xml-formatter.c | 56 ++++++++++++------------------------ 2 files changed, 22 insertions(+), 67 deletions(-) diff --git a/ges/ges-base-xml-formatter.c b/ges/ges-base-xml-formatter.c index 8cfa162968..a6d1a680eb 100644 --- a/ges/ges-base-xml-formatter.c +++ b/ges/ges-base-xml-formatter.c @@ -813,36 +813,9 @@ _create_profile (GESBaseXmlFormatter * self, gst_encoding_profile_set_description (profile, description); gst_encoding_profile_set_preset_name (profile, preset_name); } - - if (preset && preset_properties) { - GstElement *element; - - if (!g_strcmp0 (type, "container")) { - element = get_element_for_encoding_profile (profile, - GST_ELEMENT_FACTORY_TYPE_MUXER); - } else { - element = get_element_for_encoding_profile (profile, - GST_ELEMENT_FACTORY_TYPE_ENCODER); - } - - if (G_UNLIKELY (!element || !GST_IS_PRESET (element))) { - GST_WARNING_OBJECT (element, "Element is not a GstPreset"); - goto done; - } - - /* If the preset doesn't exist on the system, create it */ - if (!gst_preset_load_preset (GST_PRESET (element), preset)) { - gst_structure_foreach (preset_properties, - (GstStructureForeachFunc) set_property_foreach, element); - - if (!gst_preset_save_preset (GST_PRESET (element), preset)) { - GST_WARNING_OBJECT (element, "Could not save preset %s", preset); - } - } - - done: - if (element) - gst_object_unref (element); + if (preset_properties) { + gst_encoding_profile_set_element_properties (profile, + gst_structure_copy (preset_properties)); } return profile; diff --git a/ges/ges-xml-formatter.c b/ges/ges-xml-formatter.c index eafe253cac..e68da36f74 100644 --- a/ges/ges-xml-formatter.c +++ b/ges/ges-xml-formatter.c @@ -1867,6 +1867,7 @@ _save_stream_profiles (GESXmlFormatter * self, GString * str, { gchar *tmpc; GstCaps *tmpcaps; + GstStructure *properties; const gchar *preset, *preset_name, *name, *description; append_escaped (str, @@ -1901,25 +1902,18 @@ _save_stream_profiles (GESXmlFormatter * self, GString * str, preset = gst_encoding_profile_get_preset (sprof); if (preset) { - GstElement *encoder; - append_escaped (str, g_markup_printf_escaped ("preset='%s' ", preset), depth); + } - encoder = get_element_for_encoding_profile (sprof, - GST_ELEMENT_FACTORY_TYPE_ENCODER); - if (encoder) { - if (GST_IS_PRESET (encoder) && - gst_preset_load_preset (GST_PRESET (encoder), preset)) { + properties = gst_encoding_profile_get_element_properties (sprof); + if (properties) { + gchar *props_str = gst_structure_to_string (properties); - gchar *settings = - _serialize_properties (G_OBJECT (encoder), NULL, NULL); - append_escaped (str, g_markup_printf_escaped ("preset-properties='%s' ", - settings), depth); - g_free (settings); - } - gst_object_unref (encoder); - } + append_escaped (str, + g_markup_printf_escaped ("preset-properties='%s' ", props_str), depth); + g_free (props_str); + gst_structure_free (properties); } preset_name = gst_encoding_profile_get_preset_name (sprof); @@ -1953,6 +1947,7 @@ _save_encoding_profiles (GESXmlFormatter * self, GString * str, GESProject * project, guint depth) { GstCaps *profformat; + GstStructure *properties; const gchar *profname, *profdesc, *profpreset, *proftype, *profpresetname; const GList *tmp; @@ -1974,32 +1969,19 @@ _save_encoding_profiles (GESXmlFormatter * self, GString * str, profname, profdesc, proftype), depth); if (profpreset) { - GstElement *element; - append_escaped (str, g_markup_printf_escaped ("preset='%s' ", profpreset), depth); + } - if (GST_IS_ENCODING_CONTAINER_PROFILE (prof)) { - element = get_element_for_encoding_profile (prof, - GST_ELEMENT_FACTORY_TYPE_MUXER); - } else { - element = get_element_for_encoding_profile (prof, - GST_ELEMENT_FACTORY_TYPE_ENCODER); - } - - if (element) { - if (GST_IS_PRESET (element) && - gst_preset_load_preset (GST_PRESET (element), profpreset)) { - gchar *settings = - _serialize_properties (G_OBJECT (element), NULL, NULL); - append_escaped (str, - g_markup_printf_escaped ("preset-properties='%s' ", settings), - depth); - g_free (settings); - } - gst_object_unref (element); - } + properties = gst_encoding_profile_get_element_properties (prof); + if (properties) { + gchar *props_str = gst_structure_to_string (properties); + append_escaped (str, + g_markup_printf_escaped ("preset-properties='%s' ", props_str), + depth); + g_free (props_str); + gst_structure_free (properties); } if (profpresetname)