From eaaaabf3aa3b3dfb3ed8dd2f8fac20308cffd2cc Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Wed, 11 Jul 2001 12:33:17 +0000 Subject: [PATCH] to element classes without using an elementfactory. Original commit message from CVS: Aplied the patch from Andy Wingo add padtemplates to element classes without using an elementfactory. The gst_element_add_padtemplate_to_class method was renamed to gst_element_class_add_padtemplate to better match glib/gtk conventions. --- gst/gstelement.c | 39 ++++++++++++++++++++++++++++++++------- gst/gstelement.h | 7 ++++++- gst/gstelementfactory.c | 6 +++++- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/gst/gstelement.c b/gst/gstelement.c index b84703e6da..1d837db6ba 100644 --- a/gst/gstelement.c +++ b/gst/gstelement.c @@ -148,6 +148,8 @@ gst_element_class_init (GstElementClass *klass) klass->change_state = GST_DEBUG_FUNCPTR(gst_element_change_state); klass->elementfactory = NULL; + klass->padtemplates = NULL; + klass->numpadtemplates = 0; } static void @@ -412,9 +414,14 @@ gst_element_remove_ghost_pad (GstElement *element, GstPad *pad) g_return_if_fail (element != NULL); g_return_if_fail (GST_IS_ELEMENT (element)); g_return_if_fail (pad != NULL); - g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (GST_IS_GHOST_PAD (pad)); // FIXME this is redundant? + // wingo 10-july-2001: I don't think so, you have to actually remove the pad + // from the element. gst_pad_remove_ghost_pad just removes the ghostpad from + // the real pad's ghost pad list + gst_pad_remove_ghost_pad (GST_PAD (GST_PAD_REALIZE (pad)), pad); + gst_element_remove_pad (element, pad); } @@ -473,6 +480,27 @@ gst_element_get_pad_list (GstElement *element) return element->pads; } +/** + * gst_element_class_add_padtemplate: + * @klass: element class to add padtemplate to + * @templ: padtemplate to add + * + * Add a padtemplate to an element class. This is useful if you have derived a custom + * bin and wish to provide an on-request pad at runtime. Plugin writers should use + * gst_elementfactory_add_padtemplate instead. + */ +void +gst_element_class_add_padtemplate (GstElementClass *klass, GstPadTemplate *templ) +{ + g_return_if_fail (klass != NULL); + g_return_if_fail (GST_IS_ELEMENT_CLASS (klass)); + g_return_if_fail (templ != NULL); + g_return_if_fail (GST_IS_PADTEMPLATE (templ)); + + klass->padtemplates = g_list_append (klass->padtemplates, templ); + klass->numpadtemplates++; +} + /** * gst_element_get_padtemplate_list: * @element: element to get padtemplates of @@ -491,10 +519,7 @@ gst_element_get_padtemplate_list (GstElement *element) oclass = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS(element)); - if (oclass->elementfactory == NULL) return NULL; - - /* return the list of pads */ - return oclass->elementfactory->padtemplates; + return oclass->padtemplates; } /** @@ -900,7 +925,7 @@ gst_element_shutdown (GObject *object) gst_bin_remove (GST_BIN (GST_OBJECT_PARENT (element)), element); if (G_OBJECT_CLASS (parent_class)->shutdown) - G_OBJECT_CLASS (parent_class)->shutdown ((GObject *)object); + G_OBJECT_CLASS (parent_class)->shutdown (G_OBJECT (object)); } static void @@ -1130,7 +1155,7 @@ gst_element_restore_thyself (xmlNodePtr self, GstObject *parent) } child = child->next; } - gst_util_set_object_arg (G_OBJECT (element), name, value); + gst_util_set_object_arg ((GObject *)G_OBJECT (element), name, value); } children = children->next; } diff --git a/gst/gstelement.h b/gst/gstelement.h index 2d84274ba3..0c4f711b5b 100644 --- a/gst/gstelement.h +++ b/gst/gstelement.h @@ -153,7 +153,10 @@ struct _GstElementClass { /* the elementfactory that created us */ GstElementFactory *elementfactory; - + /* templates for our pads */ + GList *padtemplates; + gint numpadtemplates; + /* signal callbacks */ void (*state_change) (GstElement *element,GstElementState state); void (*new_pad) (GstElement *element,GstPad *pad); @@ -192,6 +195,8 @@ struct _GstElementFactory { guint16 numpadtemplates; }; +void gst_element_class_add_padtemplate (GstElementClass *element, GstPadTemplate *templ); + GType gst_element_get_type (void); GstElement* gst_element_new (void); #define gst_element_destroy(element) gst_object_destroy (GST_OBJECT (element)) diff --git a/gst/gstelementfactory.c b/gst/gstelementfactory.c index 3f9d9162d7..da417f4c5b 100644 --- a/gst/gstelementfactory.c +++ b/gst/gstelementfactory.c @@ -168,7 +168,11 @@ gst_elementfactory_create (GstElementFactory *factory, GST_DEBUG (GST_CAT_ELEMENTFACTORY,"class %s\n", factory->name); oclass->elementfactory = factory; } - + + // copy pad template pointers to the element class + oclass->padtemplates = g_list_copy(factory->padtemplates); + oclass->numpadtemplates = factory->numpadtemplates; + gst_object_set_name (GST_OBJECT (element),name); return element;