From c01949a99eef3619723297e38bea591e7968eda2 Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Mon, 6 Nov 2017 21:10:54 +0100 Subject: [PATCH] pad templates: Allow specifying GType See https://bugzilla.gnome.org/show_bug.cgi?id=731301 https://bugzilla.gnome.org/show_bug.cgi?id=789986 --- docs/gst/gstreamer-sections.txt | 3 +++ gst/gstelement.c | 22 +++++++++++++++++ gst/gstelement.h | 5 ++++ gst/gstpadtemplate.c | 55 ++++++++++++++++++++++++++++++++++++++++- gst/gstpadtemplate.h | 22 ++++++++++++++++- win32/common/libgstreamer.def | 2 ++ 6 files changed, 107 insertions(+), 2 deletions(-) diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index e105444..0c60dbc 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -865,6 +865,7 @@ GST_ELEMENT_METADATA_LONGNAME gst_element_class_add_pad_template gst_element_class_add_static_pad_template +gst_element_class_add_static_pad_template_with_gtype gst_element_class_get_pad_template gst_element_class_get_pad_template_list gst_element_class_set_metadata @@ -2198,7 +2199,9 @@ GST_PAD_TEMPLATE_DIRECTION GST_PAD_TEMPLATE_PRESENCE GST_PAD_TEMPLATE_CAPS GST_PAD_TEMPLATE_IS_FIXED +GST_PAD_TEMPLATE_GTYPE gst_pad_template_new +gst_pad_template_new_from_static_pad_template_with_gtype gst_pad_template_get_caps diff --git a/gst/gstelement.c b/gst/gstelement.c index 80ecf44..97f327d 100644 --- a/gst/gstelement.c +++ b/gst/gstelement.c @@ -1427,6 +1427,28 @@ gst_element_class_add_static_pad_template (GstElementClass * klass, } /** + * gst_element_class_add_static_pad_template_with_gtype: + * @klass: the #GstElementClass to add the pad template to. + * @static_templ: #GstStaticPadTemplate to add as pad template to the element class. + * @pad_type: The #GType of the pad to create + * + * Adds a pad template to an element class based on the static pad template + * @templ. This is mainly used in the _class_init functions of element + * implementations. If a pad template with the same name already exists, + * the old one is replaced by the new one. + * + * Since: 1.14 + */ +void +gst_element_class_add_static_pad_template_with_gtype (GstElementClass * klass, + GstStaticPadTemplate * static_templ, GType pad_type) +{ + gst_element_class_add_pad_template (klass, + gst_pad_template_new_from_static_pad_template_with_gtype (static_templ, + pad_type)); +} + +/** * gst_element_class_add_metadata: * @klass: class to set metadata for * @key: the key to set diff --git a/gst/gstelement.h b/gst/gstelement.h index fab64a0..a8a0a4b 100644 --- a/gst/gstelement.h +++ b/gst/gstelement.h @@ -752,6 +752,11 @@ GST_EXPORT void gst_element_class_add_static_pad_template (GstElementClass *klass, GstStaticPadTemplate *static_templ); GST_EXPORT +void gst_element_class_add_static_pad_template_with_gtype (GstElementClass *klass, + GstStaticPadTemplate *static_templ, + GType pad_type); + +GST_EXPORT GstPadTemplate* gst_element_class_get_pad_template (GstElementClass *element_class, const gchar *name); GST_EXPORT diff --git a/gst/gstpadtemplate.c b/gst/gstpadtemplate.c index 8666ed1..c177219 100644 --- a/gst/gstpadtemplate.c +++ b/gst/gstpadtemplate.c @@ -105,7 +105,8 @@ enum PROP_NAME_TEMPLATE = 1, PROP_DIRECTION, PROP_PRESENCE, - PROP_CAPS + PROP_CAPS, + PROP_GTYPE, }; enum @@ -195,6 +196,19 @@ gst_pad_template_class_init (GstPadTemplateClass * klass) GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + /** + * GstPadTemplate:gtype: + * + * The type of the pad described by the pad template. + * + * Since: 1.14 + */ + g_object_class_install_property (gobject_class, PROP_GTYPE, + g_param_spec_gtype ("gtype", "GType", + "The GType of the pad described by the pad template", + G_TYPE_NONE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + gstobject_class->path_string_separator = "*"; } @@ -310,6 +324,39 @@ gst_static_pad_template_get (GstStaticPadTemplate * pad_template) } /** + * gst_pad_template_new_from_static_pad_template_with_gtype: + * @pad_template: the static pad template + * @pad_type: The #GType of the pad to create + * + * Converts a #GstStaticPadTemplate into a #GstPadTemplate with a type. + * + * Returns: (transfer floating): a new #GstPadTemplate. + */ +GstPadTemplate * +gst_pad_template_new_from_static_pad_template_with_gtype (GstStaticPadTemplate * + pad_template, GType pad_type) +{ + GstPadTemplate *new; + GstCaps *caps; + + if (!name_is_valid (pad_template->name_template, pad_template->presence)) + return NULL; + + caps = gst_static_caps_get (&pad_template->static_caps); + + new = g_object_new (gst_pad_template_get_type (), + "name", pad_template->name_template, + "name-template", pad_template->name_template, + "direction", pad_template->direction, + "presence", pad_template->presence, "caps", caps, "gtype", pad_type, + NULL); + + gst_caps_unref (caps); + + return new; +} + +/** * gst_pad_template_new: * @name_template: the name template. * @direction: the #GstPadDirection of the template. @@ -422,6 +469,9 @@ gst_pad_template_set_property (GObject * object, guint prop_id, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED); } break; + case PROP_GTYPE: + GST_PAD_TEMPLATE_GTYPE (object) = g_value_get_gtype (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -446,6 +496,9 @@ gst_pad_template_get_property (GObject * object, guint prop_id, GValue * value, case PROP_CAPS: g_value_set_boxed (value, GST_PAD_TEMPLATE_CAPS (object)); break; + case PROP_GTYPE: + g_value_set_gtype (value, GST_PAD_TEMPLATE_GTYPE (object)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; diff --git a/gst/gstpadtemplate.h b/gst/gstpadtemplate.h index f07dbd8..77dc8a1 100644 --- a/gst/gstpadtemplate.h +++ b/gst/gstpadtemplate.h @@ -95,6 +95,16 @@ typedef enum { #define GST_PAD_TEMPLATE_CAPS(templ) (((GstPadTemplate *)(templ))->caps) /** + * GST_PAD_TEMPLATE_GTYPE: + * @templ: the template to query + * + * Get the #GType of the padtemplate + * + * Since: 1.14 + */ +#define GST_PAD_TEMPLATE_GTYPE(templ) (((GstPadTemplate *)(templ))->ABI.abi.gtype) + +/** * GstPadTemplateFlags: * @GST_PAD_TEMPLATE_FLAG_LAST: first flag that can be used by subclasses. * @@ -127,7 +137,12 @@ struct _GstPadTemplate { GstCaps *caps; /*< private >*/ - gpointer _gst_reserved[GST_PADDING]; + union { + gpointer _gst_reserved[GST_PADDING]; + struct { + GType gtype; + } abi; + } ABI; }; struct _GstPadTemplateClass { @@ -190,6 +205,11 @@ GST_EXPORT GstPadTemplate * gst_static_pad_template_get (GstStaticPadTemplate *pad_template); GST_EXPORT +GstPadTemplate * gst_pad_template_new_from_static_pad_template_with_gtype ( + GstStaticPadTemplate * pad_template, + GType pad_type); + +GST_EXPORT GstCaps* gst_static_pad_template_get_caps (GstStaticPadTemplate *templ); GST_EXPORT diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index b4b918a..b063dcb 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -504,6 +504,7 @@ EXPORTS gst_element_class_add_pad_template gst_element_class_add_static_metadata gst_element_class_add_static_pad_template + gst_element_class_add_static_pad_template_with_gtype gst_element_class_get_metadata gst_element_class_get_pad_template gst_element_class_get_pad_template_list @@ -980,6 +981,7 @@ EXPORTS gst_pad_template_get_caps gst_pad_template_get_type gst_pad_template_new + gst_pad_template_new_from_static_pad_template_with_gtype gst_pad_template_pad_created gst_pad_unlink gst_pad_use_fixed_caps -- 2.7.4