[gst-devel] object destruction fix

Steve Baker stevebaker_org at yahoo.co.uk
Fri Sep 28 10:33:02 CEST 2001


Object destruction has been completely disabled in gstreamer since a
recent change in GObject API.  I have made some changes to make it work
again. I basically uncommented stuff and combined any shutdown or
real_destroy functions into a single dispose function.

The only issue so far is that pads seem to have a ref left over when
they are finalized but I don't think that is critical.

Now that I can actually destroy pipelines I think that I may have
exposed a bug with doing an elementfactory_create from a previously
loaded plugin but that needs some more research.

OK to commit?

Index: gstbin.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/gstbin.c,v
retrieving revision 1.91
diff -u -r1.91 gstbin.c
--- gstbin.c	2001/09/14 22:16:47	1.91
+++ gstbin.c	2001/09/28 17:24:55
@@ -37,7 +37,7 @@
 };
 

-static void			gst_bin_real_destroy		(GObject *object);
+static void			gst_bin_dispose		(GObject *object);
 
 static GstElementStateReturn	gst_bin_change_state		(GstElement *element);
 static GstElementStateReturn	gst_bin_change_state_norecurse	(GstBin *bin);
@@ -122,9 +122,7 @@
 #endif
 
   gstelement_class->change_state =	gst_bin_change_state;
-
-// FIXME
-//  gobject_class->destroy =		gst_bin_real_destroy;
+  gobject_class->dispose =		gst_bin_dispose;
 }
 
 static void
@@ -476,13 +474,13 @@
 }
 
 static void
-gst_bin_real_destroy (GObject *object)
+gst_bin_dispose (GObject *object)
 {
   GstBin *bin = GST_BIN (object);
   GList *children, *orig;
   GstElement *child;
 
-  GST_DEBUG (GST_CAT_REFCOUNTING,"destroy()\n");
+  GST_DEBUG (GST_CAT_REFCOUNTING,"dispose\n");
 
   if (bin->children) {
     orig = children = g_list_copy (bin->children);
@@ -501,9 +499,7 @@
 
   g_cond_free (bin->eoscond);
 
-// FIXME!!!
-//  if (G_OBJECT_CLASS (parent_class)->destroy)
-//    G_OBJECT_CLASS (parent_class)->destroy (object);
+  G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 /**
Index: gstelement.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/gstelement.c,v
retrieving revision 1.76
diff -u -r1.76 gstelement.c
--- gstelement.c	2001/09/14 22:16:47	1.76
+++ gstelement.c	2001/09/28 17:24:58
@@ -56,8 +56,7 @@
 static void			gst_element_get_property	(GObject *object, guint prop_id, GValue *value, 
 								 GParamSpec *pspec);
 
-static void 			gst_element_shutdown 		(GObject *object);
-static void			gst_element_real_destroy	(GObject *object);
+static void 			gst_element_dispose 		(GObject *object);
 
 static GstElementStateReturn	gst_element_change_state	(GstElement *element);
 
@@ -140,9 +139,7 @@
 
   gobject_class->set_property =		GST_DEBUG_FUNCPTR(gst_element_set_property);
   gobject_class->get_property =		GST_DEBUG_FUNCPTR(gst_element_get_property);
-//  gobject_class->shutdown =		GST_DEBUG_FUNCPTR(gst_element_shutdown);
-// FIXME!
-//  gobject_class->destroy =		GST_DEBUG_FUNCPTR(gst_element_real_destroy);
+  gobject_class->dispose =		GST_DEBUG_FUNCPTR(gst_element_dispose);
 
 #ifndef GST_DISABLE_LOADSAVE
   gstobject_class->save_thyself =	GST_DEBUG_FUNCPTR(gst_element_save_thyself);
@@ -912,36 +909,23 @@
 }
 
 static void
-gst_element_shutdown (GObject *object)
+gst_element_dispose (GObject *object)
 {
   GstElement *element = GST_ELEMENT (object);
-
-  GST_DEBUG_ELEMENT (GST_CAT_REFCOUNTING, element, "shutdown\n");
+  GList *pads;
+  GstPad *pad;
+  
+  GST_DEBUG_ELEMENT (GST_CAT_REFCOUNTING, element, "dispose\n");
 
   if (GST_IS_BIN (GST_OBJECT_PARENT (element)))
     gst_bin_remove (GST_BIN (GST_OBJECT_PARENT (element)), element);
 
-//  if (G_OBJECT_CLASS (parent_class)->shutdown)
-//    G_OBJECT_CLASS (parent_class)->shutdown (G_OBJECT (object));
-}
-
-static void
-gst_element_real_destroy (GObject *object)
-{
-  GstElement *element = GST_ELEMENT (object);
-  GList *pads;
-  GstPad *pad;
-
-  GST_DEBUG_ELEMENT (GST_CAT_REFCOUNTING, element, "destroy\n");
 
   if (element->pads) {
     GList *orig;
     orig = pads = g_list_copy (element->pads);
     while (pads) {
       pad = GST_PAD (pads->data);
-      //gst_object_destroy (GST_OBJECT (pad));
-      gst_object_ref (GST_OBJECT (pad));
-      gst_element_remove_pad (element, pad);
       gst_object_unref (GST_OBJECT (pad));
       pads = g_list_next (pads);
     }
@@ -953,9 +937,7 @@
   element->numsrcpads = 0;
   element->numsinkpads = 0;
 
-// FIXME!
-//  if (G_OBJECT_CLASS (parent_class)->destroy)
-//    G_OBJECT_CLASS (parent_class)->destroy (object);
+  G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 /*
Index: gstelementfactory.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/gstelementfactory.c,v
retrieving revision 1.47
diff -u -r1.47 gstelementfactory.c
--- gstelementfactory.c	2001/09/23 08:26:10	1.47
+++ gstelementfactory.c	2001/09/28 17:24:58
@@ -226,8 +226,8 @@
   g_return_val_if_fail(factory != NULL, NULL);
   g_return_val_if_fail(name != NULL, NULL);
 
-  GST_DEBUG (GST_CAT_ELEMENTFACTORY,"creating element from factory \"%s\" with name \"%s\"\n", 
-             GST_OBJECT_NAME (factory), name);
+  GST_DEBUG (GST_CAT_ELEMENTFACTORY,"creating element from factory \"%s\" with name \"%s\" and type %d\n", 
+             GST_OBJECT_NAME (factory), name, factory->type);
 
   gst_plugin_feature_ensure_loaded (GST_PLUGIN_FEATURE (factory));
 
Index: gstobject.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/gstobject.c,v
retrieving revision 1.24
diff -u -r1.24 gstobject.c
--- gstobject.c	2001/09/14 22:16:47	1.24
+++ gstobject.c	2001/09/28 17:25:00
@@ -55,8 +55,7 @@
 static void		gst_object_class_init		(GstObjectClass *klass);
 static void		gst_object_init			(GstObject *object);
 
-static void 		gst_object_real_destroy 	(GObject *object);
-static void 		gst_object_shutdown 		(GObject *object);
+static void 		gst_object_dispose 		(GObject *object);
 static void 		gst_object_finalize 		(GObject *object);
 
 static GObjectClass *parent_class = NULL;
@@ -111,8 +110,7 @@
 // FIXME!!!
 //  klass->signal_object = g_object_new(gst_signal_object_get_type (,NULL));
 
-//  gobject_class->shutdown = gst_object_shutdown;
-//  gobject_class->destroy = gst_object_real_destroy;
+  gobject_class->dispose = gst_object_dispose;
   gobject_class->finalize = gst_object_finalize;
 }
 
@@ -143,6 +141,7 @@
              G_OBJECT(object)->ref_count,G_OBJECT(object)->ref_count+1);
 
   g_object_ref (G_OBJECT (object));
+  GST_DEBUG (GST_CAT_REFCOUNTING, "count now %d\n", G_OBJECT(object)->ref_count);
 
   return object;
 }
@@ -164,6 +163,7 @@
              G_OBJECT(object)->ref_count,G_OBJECT(object)->ref_count-1);
 
   g_object_unref (G_OBJECT (object));
+  GST_DEBUG (GST_CAT_REFCOUNTING, "count now %d\n", G_OBJECT(object)->ref_count);
 }
 #define gst_object_unref gst_object_unref
 
@@ -202,29 +202,19 @@
      * invocations.
      */
     gst_object_ref (object);
-//    G_OBJECT_GET_CLASS (object)->shutdown (G_OBJECT (object));
+    G_OBJECT_GET_CLASS (object)->dispose (G_OBJECT (object));
     gst_object_unref (object);
   }
 }
 
 static void
-gst_object_shutdown (GObject *object)
+gst_object_dispose (GObject *object)
 {
-  GST_DEBUG (GST_CAT_REFCOUNTING, "shutdown '%s'\n",GST_OBJECT_NAME(object));
+  GST_DEBUG (GST_CAT_REFCOUNTING, "dispose '%s'\n",GST_OBJECT_NAME(object));
   GST_FLAG_SET (GST_OBJECT (object), GST_DESTROYED);
-//  parent_class->shutdown (object);
-}
-
-/* finilize is called when the object has to free its resources */
-static void
-gst_object_real_destroy (GObject *g_object)
-{
-  GST_DEBUG (GST_CAT_REFCOUNTING, "destroy '%s'\n",GST_OBJECT_NAME(g_object));
-
-  GST_OBJECT_PARENT (g_object) = NULL;
+  GST_OBJECT_PARENT (object) = NULL;
 
-// FIXME!!
-//  parent_class->destroy (g_object);
+  parent_class->dispose (object);
 }
 
 /* finilize is called when the object has to free its resources */
@@ -343,6 +333,8 @@
   if (object->parent == NULL)
     return;
 
+  GST_DEBUG (GST_CAT_REFCOUNTING, "unparent '%s'\n",GST_OBJECT_NAME(object));
+  
   object->parent = NULL;
   gst_object_unref (object);
 }
Index: gstpad.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/gstpad.c,v
retrieving revision 1.113
diff -u -r1.113 gstpad.c
--- gstpad.c	2001/09/23 08:26:10	1.113
+++ gstpad.c	2001/09/28 17:25:03
@@ -103,7 +103,7 @@
 static void	gst_real_pad_set_property	(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
 static void	gst_real_pad_get_property	(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
 
-static void	gst_real_pad_destroy		(GObject *object);
+static void	gst_real_pad_dispose		(GObject *object);
 
 static void	gst_pad_push_func		(GstPad *pad, GstBuffer *buf);
 
@@ -144,8 +144,7 @@
 
   real_pad_parent_class = g_type_class_ref(GST_TYPE_PAD);
 
-// FIXME!
-//  gobject_class->destroy  = GST_DEBUG_FUNCPTR(gst_real_pad_destroy);
+  gobject_class->dispose  = GST_DEBUG_FUNCPTR(gst_real_pad_dispose);
   gobject_class->set_property  = GST_DEBUG_FUNCPTR(gst_real_pad_set_property);
   gobject_class->get_property  = GST_DEBUG_FUNCPTR(gst_real_pad_get_property);
 
@@ -1023,21 +1022,27 @@
 }
 
 static void
-gst_real_pad_destroy (GObject *object)
+gst_real_pad_dispose (GObject *object)
 {
   GstPad *pad = GST_PAD (object);
-
-  GST_DEBUG (GST_CAT_REFCOUNTING, "destroy %s:%s\n", GST_DEBUG_PAD_NAME(pad));
+  
+  GST_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s\n", GST_DEBUG_PAD_NAME(pad));
 
-  if (GST_PAD (pad)->padtemplate)
+  if (GST_PAD (pad)->padtemplate){
+    GST_DEBUG (GST_CAT_REFCOUNTING, "unreffing padtemplate'%s'\n",GST_OBJECT_NAME(GST_OBJECT (GST_PAD (pad)->padtemplate)));
     gst_object_unref (GST_OBJECT (GST_PAD (pad)->padtemplate));
-
-  if (GST_PAD_PEER (pad))
+  }
+  
+  if (GST_PAD_PEER (pad)){
+    GST_DEBUG (GST_CAT_REFCOUNTING, "disconnecting pad '%s'\n",GST_OBJECT_NAME(GST_OBJECT (GST_PAD (GST_PAD_PEER (pad)))));
     gst_pad_disconnect (pad, GST_PAD (GST_PAD_PEER (pad)));
-
-  if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad)))
+  }
+  
+  if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))){
+    GST_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'\n",GST_OBJECT_NAME(GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
     gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
-
+  }
+  
   // FIXME we should destroy the ghostpads, because they are nothing without the real pad
   if (GST_REAL_PAD (pad)->ghostpads) {
     GList *orig, *ghostpads;
@@ -1047,18 +1052,17 @@
     while (ghostpads) {
       GstPad *ghostpad = GST_PAD (ghostpads->data);
 
-      if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad)))
+      if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))){
+        GST_DEBUG (GST_CAT_REFCOUNTING, "removing ghost pad from element '%s'\n", GST_OBJECT_NAME(GST_OBJECT_PARENT (ghostpad)));
         gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (ghostpad)), ghostpad);
-
+      }
       ghostpads = g_list_next (ghostpads);
     }
     g_list_free (orig);
     g_list_free (GST_REAL_PAD(pad)->ghostpads);
   }
-
-// FIXME !!
-//  if (G_OBJECT_CLASS (real_pad_parent_class)->destroy)
-//    G_OBJECT_CLASS (real_pad_parent_class)->destroy (object);
+  
+  G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
 }
 

Index: gstthread.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/gstthread.c,v
retrieving revision 1.54
diff -u -r1.54 gstthread.c
--- gstthread.c	2001/09/14 22:16:47	1.54
+++ gstthread.c	2001/09/28 17:25:05
@@ -61,7 +61,7 @@
 static void			gst_thread_class_init		(GstThreadClass *klass);
 static void			gst_thread_init			(GstThread *thread);
 
-static void 			gst_thread_real_destroy 	(GObject *object);
+static void 			gst_thread_dispose 	(GObject *object);
 
 static void			gst_thread_set_property		(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
 static void			gst_thread_get_property		(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
@@ -121,8 +121,7 @@
     g_param_spec_boolean("create_thread", "Create Thread", "Whether to create a thread.",
                          TRUE,G_PARAM_READWRITE));
 
-// FIXME!
-//  gobject_class->destroy =		gst_thread_real_destroy;
+  gobject_class->dispose =		gst_thread_dispose;
 
 #ifndef GST_DISABLE_LOADSAVE
   gstobject_class->save_thyself =	gst_thread_save_thyself;
@@ -162,21 +161,20 @@
 }
 
 static void
-gst_thread_real_destroy (GObject *object)
+gst_thread_dispose (GObject *object)
 {
   GstThread *thread = GST_THREAD (object);
 
-  GST_DEBUG (GST_CAT_REFCOUNTING,"destroy()\n");
+  GST_DEBUG (GST_CAT_REFCOUNTING,"dispose\n");
 
   g_mutex_free (thread->lock);
   g_cond_free (thread->cond);
 
-// FIXME!
-//  if (G_OBJECT_CLASS (parent_class)->destroy)
-//    G_OBJECT_CLASS (parent_class)->destroy (object);
+  G_OBJECT_CLASS (parent_class)->dispose (object);
 
   gst_object_destroy (GST_OBJECT (GST_ELEMENT_SCHED (thread)));
   gst_object_unref (GST_OBJECT (GST_ELEMENT_SCHED (thread)));
+
 }
 
 static void


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com





More information about the gstreamer-devel mailing list