pad templates: Allow specifying GType

See https://bugzilla.gnome.org/show_bug.cgi?id=731301

https://bugzilla.gnome.org/show_bug.cgi?id=789986
This commit is contained in:
Mathieu Duponchelle 2017-11-06 21:10:54 +01:00
parent 02d678a2f8
commit c01949a99e
6 changed files with 107 additions and 2 deletions

View file

@ -865,6 +865,7 @@ GST_ELEMENT_METADATA_LONGNAME
<SUBSECTION element-construction>
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
<SUBSECTION Standard>

View file

@ -1426,6 +1426,28 @@ gst_element_class_add_static_pad_template (GstElementClass * klass,
gst_static_pad_template_get (static_templ));
}
/**
* 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

View file

@ -751,6 +751,11 @@ void gst_element_class_add_pad_template (GstElementClass
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);

View file

@ -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 = "*";
}
@ -309,6 +323,39 @@ gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
return new;
}
/**
* 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.
@ -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;

View file

@ -94,6 +94,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 {
@ -189,6 +204,11 @@ GstPadTemplate* gst_pad_template_new (const gchar *name_template,
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);

View file

@ -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