From bca1ae8fb04c8ab0d6f21d6df3d2b41d99d63402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Mon, 9 Apr 2012 12:47:58 +0100 Subject: [PATCH] element: add gst_element_class_{set,add}_static_metadata() Add gst_element_class_{add,set}_metadata() variants for static strings, so we can avoid unnecessary g_strdup()s. API: gst_element_class_add_static_metadata() API: gst_element_class_set_static_metadata() --- docs/gst/gstreamer-sections.txt | 2 + gst/gstelement.c | 73 +++++++++++++++++++++++++++++++++ gst/gstelement.h | 7 ++++ win32/common/libgstreamer.def | 3 +- 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index e4f78cfd69..c66ccc1eb4 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -697,7 +697,9 @@ gst_element_class_add_pad_template gst_element_class_get_pad_template gst_element_class_get_pad_template_list gst_element_class_set_metadata +gst_element_class_set_static_metadata gst_element_class_add_metadata +gst_element_class_add_static_metadata gst_element_add_pad diff --git a/gst/gstelement.c b/gst/gstelement.c index da8e9f6809..0555a1e04f 100644 --- a/gst/gstelement.c +++ b/gst/gstelement.c @@ -1229,6 +1229,34 @@ gst_element_class_add_metadata (GstElementClass * klass, key, G_TYPE_STRING, value, NULL); } +/** + * gst_element_class_add_static_metadata: + * @klass: class to set metadata for + * @key: the key to set + * @value: the value to set + * + * Set @key with @value as metadata in @klass. + * + * Same as gst_element_class_add_metadata(), but @value must be a static string + * or an inlined string, as it will not be copied. (GStreamer plugins will + * be made resident once loaded, so this function can be used even from + * dynamically loaded plugins.) + */ +void +gst_element_class_add_static_metadata (GstElementClass * klass, + const gchar * key, const gchar * value) +{ + GValue val = G_VALUE_INIT; + + g_return_if_fail (GST_IS_ELEMENT_CLASS (klass)); + g_return_if_fail (key != NULL); + g_return_if_fail (value != NULL); + + g_value_init (&val, G_TYPE_STRING); + g_value_set_static_string (&val, value); + gst_structure_take_value ((GstStructure *) klass->metadata, key, &val); +} + /** * gst_element_class_set_metadata: * @klass: class to set metadata for @@ -1258,6 +1286,51 @@ gst_element_class_set_metadata (GstElementClass * klass, GST_ELEMENT_METADATA_AUTHOR, G_TYPE_STRING, author, NULL); } +/** + * gst_element_class_set_static_metadata: + * @klass: class to set metadata for + * @longname: The long English name of the element. E.g. "File Sink" + * @classification: String describing the type of element, as an unordered list + * separated with slashes ('/'). See draft-klass.txt of the design docs + * for more details and common types. E.g: "Sink/File" + * @description: Sentence describing the purpose of the element. + * E.g: "Write stream to a file" + * @author: Name and contact details of the author(s). Use \n to separate + * multiple author metadata. E.g: "Joe Bloggs <joe.blogs at foo.com>" + * + * Sets the detailed information for a #GstElementClass. + * This function is for use in _class_init functions only. + * + * Same as gst_element_class_set_metadata(), but @longname, @classification, + * @description, and @author must be static strings or inlined strings, as + * they will not be copied. (GStreamer plugins will be made resident once + * loaded, so this function can be used even from dynamically loaded plugins.) + */ +void +gst_element_class_set_static_metadata (GstElementClass * klass, + const gchar * longname, const gchar * classification, + const gchar * description, const gchar * author) +{ + GstStructure *s = (GstStructure *) klass->metadata; + GValue val = G_VALUE_INIT; + + g_return_if_fail (GST_IS_ELEMENT_CLASS (klass)); + + g_value_init (&val, G_TYPE_STRING); + + g_value_set_static_string (&val, longname); + gst_structure_set_value (s, GST_ELEMENT_METADATA_LONGNAME, &val); + + g_value_set_static_string (&val, classification); + gst_structure_set_value (s, GST_ELEMENT_METADATA_KLASS, &val); + + g_value_set_static_string (&val, description); + gst_structure_set_value (s, GST_ELEMENT_METADATA_DESCRIPTION, &val); + + g_value_set_static_string (&val, author); + gst_structure_take_value (s, GST_ELEMENT_METADATA_AUTHOR, &val); +} + /** * gst_element_class_get_metadata: * @klass: class to get metadata for diff --git a/gst/gstelement.h b/gst/gstelement.h index 5269b685d3..263c57310e 100644 --- a/gst/gstelement.h +++ b/gst/gstelement.h @@ -669,8 +669,15 @@ void gst_element_class_set_metadata (GstElementClass const gchar *classification, const gchar *description, const gchar *author); +void gst_element_class_set_static_metadata (GstElementClass *klass, + const gchar *longname, + const gchar *classification, + const gchar *description, + const gchar *author); void gst_element_class_add_metadata (GstElementClass * klass, const gchar * key, const gchar * value); +void gst_element_class_add_static_metadata (GstElementClass * klass, + const gchar * key, const gchar * value); const gchar * gst_element_class_get_metadata (GstElementClass * klass, const gchar * key); diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index 50dae4827c..f7fba34285 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -321,10 +321,12 @@ EXPORTS gst_element_change_state gst_element_class_add_metadata gst_element_class_add_pad_template + gst_element_class_add_static_metadata gst_element_class_get_metadata gst_element_class_get_pad_template gst_element_class_get_pad_template_list gst_element_class_set_metadata + gst_element_class_set_static_metadata gst_element_continue_state gst_element_create_all_pads gst_element_factory_can_sink_all_caps @@ -1112,7 +1114,6 @@ EXPORTS gst_task_pool_push gst_task_set_lock gst_task_set_pool - gst_task_set_priority gst_task_set_state gst_task_set_thread_callbacks gst_task_start