mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-12 11:26:39 +00:00
Work on refcounting and proper object destruction.
Original commit message from CVS: Work on refcounting and proper object destruction.
This commit is contained in:
parent
24a3b52549
commit
fa8e54e450
6 changed files with 156 additions and 43 deletions
|
@ -29,7 +29,7 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
/* we make too much noise for normal debugging... */
|
/* we make too much noise for normal debugging... */
|
||||||
#define GST_DEBUG_FORCE_DISABLE
|
//#define GST_DEBUG_FORCE_DISABLE
|
||||||
#include "gst_private.h"
|
#include "gst_private.h"
|
||||||
|
|
||||||
#include "cothreads.h"
|
#include "cothreads.h"
|
||||||
|
|
|
@ -510,6 +510,9 @@ gst_bin_real_destroy (GtkObject *object)
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free (bin->children);
|
g_list_free (bin->children);
|
||||||
|
|
||||||
|
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
||||||
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -915,7 +918,7 @@ static gboolean
|
||||||
gst_bin_iterate_func (GstBin *bin)
|
gst_bin_iterate_func (GstBin *bin)
|
||||||
{
|
{
|
||||||
// only iterate if this is the manager bin
|
// only iterate if this is the manager bin
|
||||||
if (GST_ELEMENT_SCHED(bin)->parent == (GstElement *)bin) {
|
if (GST_ELEMENT_SCHED(bin)->parent == GST_ELEMENT (bin)) {
|
||||||
return GST_SCHEDULE_ITERATE(GST_ELEMENT_SCHED(bin));
|
return GST_SCHEDULE_ITERATE(GST_ELEMENT_SCHED(bin));
|
||||||
} else {
|
} else {
|
||||||
GST_DEBUG (GST_CAT_SCHEDULING, "this bin can't be iterated on!\n");
|
GST_DEBUG (GST_CAT_SCHEDULING, "this bin can't be iterated on!\n");
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include "gstscheduler.h"
|
#include "gstscheduler.h"
|
||||||
#include "gstutils.h"
|
#include "gstutils.h"
|
||||||
|
|
||||||
|
|
||||||
/* Element signals and args */
|
/* Element signals and args */
|
||||||
enum {
|
enum {
|
||||||
STATE_CHANGE,
|
STATE_CHANGE,
|
||||||
|
@ -49,10 +48,10 @@ enum {
|
||||||
static void gst_element_class_init (GstElementClass *klass);
|
static void gst_element_class_init (GstElementClass *klass);
|
||||||
static void gst_element_init (GstElement *element);
|
static void gst_element_init (GstElement *element);
|
||||||
|
|
||||||
static void gst_element_set_arg (GtkObject *object, GtkArg *arg, guint id);
|
static void gst_element_set_arg (GtkObject *object, GtkArg *arg, guint id);
|
||||||
static void gst_element_get_arg (GtkObject *object, GtkArg *arg, guint id);
|
static void gst_element_get_arg (GtkObject *object, GtkArg *arg, guint id);
|
||||||
|
|
||||||
static void gst_element_real_destroy (GtkObject *object);
|
static void gst_element_finalize (GtkObject *object);
|
||||||
|
|
||||||
static GstElementStateReturn gst_element_change_state (GstElement *element);
|
static GstElementStateReturn gst_element_change_state (GstElement *element);
|
||||||
|
|
||||||
|
@ -121,7 +120,7 @@ gst_element_class_init (GstElementClass *klass)
|
||||||
|
|
||||||
gtkobject_class->set_arg = GST_DEBUG_FUNCPTR(gst_element_set_arg);
|
gtkobject_class->set_arg = GST_DEBUG_FUNCPTR(gst_element_set_arg);
|
||||||
gtkobject_class->get_arg = GST_DEBUG_FUNCPTR(gst_element_get_arg);
|
gtkobject_class->get_arg = GST_DEBUG_FUNCPTR(gst_element_get_arg);
|
||||||
gtkobject_class->destroy = GST_DEBUG_FUNCPTR(gst_element_real_destroy);
|
gtkobject_class->finalize = GST_DEBUG_FUNCPTR(gst_element_finalize);
|
||||||
|
|
||||||
gstobject_class->save_thyself = GST_DEBUG_FUNCPTR(gst_element_save_thyself);
|
gstobject_class->save_thyself = GST_DEBUG_FUNCPTR(gst_element_save_thyself);
|
||||||
gstobject_class->restore_thyself = GST_DEBUG_FUNCPTR(gst_element_restore_thyself);
|
gstobject_class->restore_thyself = GST_DEBUG_FUNCPTR(gst_element_restore_thyself);
|
||||||
|
@ -837,13 +836,13 @@ GST_ELEMENT_NAME(element),GST_ELEMENT_NAME(GST_ELEMENT_PARENT(element)),GST_ELEM
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_element_real_destroy (GtkObject *object)
|
gst_element_finalize (GtkObject *object)
|
||||||
{
|
{
|
||||||
GstElement *element = GST_ELEMENT (object);
|
GstElement *element = GST_ELEMENT (object);
|
||||||
GList *pads;
|
GList *pads;
|
||||||
GstPad *pad;
|
GstPad *pad;
|
||||||
|
|
||||||
// g_print("in gst_element_real_destroy()\n");
|
//g_print("element_finalize()\n");
|
||||||
|
|
||||||
pads = element->pads;
|
pads = element->pads;
|
||||||
while (pads) {
|
while (pads) {
|
||||||
|
@ -853,6 +852,8 @@ gst_element_real_destroy (GtkObject *object)
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free (element->pads);
|
g_list_free (element->pads);
|
||||||
|
|
||||||
|
GTK_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
142
gst/gstobject.c
142
gst/gstobject.c
|
@ -53,6 +53,10 @@ static guint gst_signal_object_signals[SO_LAST_SIGNAL] = { 0 };
|
||||||
static void gst_object_class_init (GstObjectClass *klass);
|
static void gst_object_class_init (GstObjectClass *klass);
|
||||||
static void gst_object_init (GstObject *object);
|
static void gst_object_init (GstObject *object);
|
||||||
|
|
||||||
|
static void gst_object_real_destroy (GtkObject *gtk_object);
|
||||||
|
static void gst_object_shutdown (GtkObject *gtk_object);
|
||||||
|
static void gst_object_finalize (GtkObject *gtk_object);
|
||||||
|
|
||||||
static GtkObjectClass *parent_class = NULL;
|
static GtkObjectClass *parent_class = NULL;
|
||||||
static guint gst_object_signals[LAST_SIGNAL] = { 0 };
|
static guint gst_object_signals[LAST_SIGNAL] = { 0 };
|
||||||
|
|
||||||
|
@ -105,6 +109,10 @@ gst_object_class_init (GstObjectClass *klass)
|
||||||
|
|
||||||
klass->path_string_separator = "/";
|
klass->path_string_separator = "/";
|
||||||
klass->signal_object = gtk_type_new (gst_signal_object_get_type ());
|
klass->signal_object = gtk_type_new (gst_signal_object_get_type ());
|
||||||
|
|
||||||
|
gtkobject_class->shutdown = gst_object_shutdown;
|
||||||
|
gtkobject_class->destroy = gst_object_real_destroy;
|
||||||
|
gtkobject_class->finalize = gst_object_finalize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -118,9 +126,12 @@ gst_object_init (GstObject *object)
|
||||||
#ifdef HAVE_ATOMIC_H
|
#ifdef HAVE_ATOMIC_H
|
||||||
atomic_set(&(object->refcount),1);
|
atomic_set(&(object->refcount),1);
|
||||||
#else
|
#else
|
||||||
object->refcount++;
|
object->refcount = 1;
|
||||||
#endif
|
#endif
|
||||||
object->parent = NULL;
|
object->parent = NULL;
|
||||||
|
|
||||||
|
object->flags = 0;
|
||||||
|
GST_FLAG_SET (object, GST_FLOATING);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,6 +147,113 @@ gst_object_new (void)
|
||||||
return GST_OBJECT (gtk_type_new (gst_object_get_type ()));
|
return GST_OBJECT (gtk_type_new (gst_object_get_type ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_object_ref:
|
||||||
|
* @object: GstObject to reference
|
||||||
|
*
|
||||||
|
* Increments the refence count on the object.
|
||||||
|
*/
|
||||||
|
GstObject*
|
||||||
|
gst_object_ref (GstObject *object)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
|
||||||
|
|
||||||
|
//g_print ("object_ref\n");
|
||||||
|
gtk_object_ref (GTK_OBJECT (object));
|
||||||
|
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
#define gst_object_ref gst_object_ref
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_object_unref:
|
||||||
|
* @object: GstObject to unreference
|
||||||
|
*
|
||||||
|
* Decrements the refence count on the object. If reference count hits
|
||||||
|
* zero, destroy the object.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gst_object_unref (GstObject *object)
|
||||||
|
{
|
||||||
|
g_return_if_fail (GST_IS_OBJECT (object));
|
||||||
|
|
||||||
|
//g_print ("object_unref\n");
|
||||||
|
gtk_object_unref (GTK_OBJECT (object));
|
||||||
|
}
|
||||||
|
#define gst_object_unref gst_object_unref
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_object_sink:
|
||||||
|
* @object: GstObject to sink
|
||||||
|
*
|
||||||
|
* Removes floating reference on an object. Any newly created object has
|
||||||
|
* a refcount of 1 and is FLOATING. This function should be used when
|
||||||
|
* creating a new object to symbolically 'take ownership of' the object.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gst_object_sink (GstObject *object)
|
||||||
|
{
|
||||||
|
g_return_if_fail (object != NULL);
|
||||||
|
g_return_if_fail (GST_IS_OBJECT (object));
|
||||||
|
|
||||||
|
//g_print ("object_sink\n");
|
||||||
|
if (GST_OBJECT_FLOATING (object))
|
||||||
|
{
|
||||||
|
GST_FLAG_UNSET (object, GST_FLOATING);
|
||||||
|
gst_object_unref (object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_object_destroy (GstObject *object)
|
||||||
|
{
|
||||||
|
g_return_if_fail (object != NULL);
|
||||||
|
g_return_if_fail (GST_IS_OBJECT (object));
|
||||||
|
|
||||||
|
//g_print ("object_destroy\n");
|
||||||
|
if (!GST_OBJECT_DESTROYED (object))
|
||||||
|
{
|
||||||
|
/* need to hold a reference count around all class method
|
||||||
|
* invocations.
|
||||||
|
*/
|
||||||
|
gst_object_ref (object);
|
||||||
|
GTK_OBJECT (object)->klass->shutdown (GTK_OBJECT (object));
|
||||||
|
gst_object_unref (object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_object_shutdown (GtkObject *object)
|
||||||
|
{
|
||||||
|
//g_print ("object_shutdown\n");
|
||||||
|
GST_FLAG_SET (GST_OBJECT (object), GST_DESTROYED);
|
||||||
|
parent_class->shutdown (GTK_OBJECT (object));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* finilize is called when the object has to free its resources */
|
||||||
|
static void
|
||||||
|
gst_object_real_destroy (GtkObject *gtk_object)
|
||||||
|
{
|
||||||
|
parent_class->destroy (gtk_object);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* finilize is called when the object has to free its resources */
|
||||||
|
static void
|
||||||
|
gst_object_finalize (GtkObject *gtk_object)
|
||||||
|
{
|
||||||
|
GstObject *object;
|
||||||
|
|
||||||
|
object = GST_OBJECT (gtk_object);
|
||||||
|
|
||||||
|
//g_print ("object_finalize\n");
|
||||||
|
if (object->name != NULL)
|
||||||
|
g_free (object->name);
|
||||||
|
|
||||||
|
g_mutex_free (object->lock);
|
||||||
|
|
||||||
|
parent_class->finalize (gtk_object);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_object_set_name:
|
* gst_object_set_name:
|
||||||
* @object: GstObject to set the name of
|
* @object: GstObject to set the name of
|
||||||
|
@ -314,28 +432,6 @@ gst_object_unref (GstObject *object)
|
||||||
}
|
}
|
||||||
#endif /* gst_object_unref */
|
#endif /* gst_object_unref */
|
||||||
|
|
||||||
/**
|
|
||||||
* gst_object_sink:
|
|
||||||
* @object: GstObject to sink
|
|
||||||
*
|
|
||||||
* Removes floating reference on an object. Any newly created object has
|
|
||||||
* a refcount of 1 and is FLOATING. This function should be used when
|
|
||||||
* creating a new object to symbolically 'take ownership of' the object.
|
|
||||||
*/
|
|
||||||
#ifndef gst_object_sink
|
|
||||||
void
|
|
||||||
gst_object_sink (GstObject *object)
|
|
||||||
{
|
|
||||||
g_return_if_fail (object != NULL);
|
|
||||||
g_return_if_fail (GST_IS_OBJECT (object));
|
|
||||||
|
|
||||||
if (GTK_OBJECT_FLOATING (object)) {
|
|
||||||
GTK_OBJECT_UNSET_FLAGS (object, GTK_FLOATING);
|
|
||||||
gst_object_unref (object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* gst_object_sink */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_object_check_uniqueness:
|
* gst_object_check_uniqueness:
|
||||||
* @list: a list of #GstObject to check through
|
* @list: a list of #GstObject to check through
|
||||||
|
|
|
@ -59,8 +59,14 @@ extern "C" {
|
||||||
|
|
||||||
//typedef struct _GstObject GstObject;
|
//typedef struct _GstObject GstObject;
|
||||||
//typedef struct _GstObjectClass GstObjectClass;
|
//typedef struct _GstObjectClass GstObjectClass;
|
||||||
|
//
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
GST_DESTROYED = 0,
|
||||||
|
GST_FLOATING,
|
||||||
|
|
||||||
#define GST_OBJECT_FLAG_LAST 4
|
GST_OBJECT_FLAG_LAST = 4,
|
||||||
|
} GstObjectFlags;
|
||||||
|
|
||||||
struct _GstObject {
|
struct _GstObject {
|
||||||
GtkObject object;
|
GtkObject object;
|
||||||
|
@ -78,6 +84,8 @@ struct _GstObject {
|
||||||
|
|
||||||
/* this objects parent */
|
/* this objects parent */
|
||||||
GstObject *parent;
|
GstObject *parent;
|
||||||
|
|
||||||
|
guint32 flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstObjectClass {
|
struct _GstObjectClass {
|
||||||
|
@ -91,19 +99,23 @@ struct _GstObjectClass {
|
||||||
void (*object_saved) (GstObject *object, xmlNodePtr parent);
|
void (*object_saved) (GstObject *object, xmlNodePtr parent);
|
||||||
|
|
||||||
/* functions go here */
|
/* functions go here */
|
||||||
|
void (*destroy) (GstObject *object);
|
||||||
|
|
||||||
xmlNodePtr (*save_thyself) (GstObject *object, xmlNodePtr parent);
|
xmlNodePtr (*save_thyself) (GstObject *object, xmlNodePtr parent);
|
||||||
void (*restore_thyself) (GstObject *object, xmlNodePtr self);
|
void (*restore_thyself) (GstObject *object, xmlNodePtr self);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define GST_OBJECT_NAME(obj) (const gchar*)(((GstObject *)(obj))->name)
|
#define GST_FLAGS(obj) (GST_OBJECT (obj)->flags)
|
||||||
#define GST_OBJECT_PARENT(obj) (((GstObject *)(obj))->parent)
|
|
||||||
|
|
||||||
|
|
||||||
#define GST_FLAGS(obj) GTK_OBJECT_FLAGS(obj)
|
|
||||||
#define GST_FLAG_IS_SET(obj,flag) (GST_FLAGS (obj) & (1<<(flag)))
|
#define GST_FLAG_IS_SET(obj,flag) (GST_FLAGS (obj) & (1<<(flag)))
|
||||||
#define GST_FLAG_SET(obj,flag) G_STMT_START{ (GST_FLAGS (obj) |= (1<<(flag))); }G_STMT_END
|
#define GST_FLAG_SET(obj,flag) G_STMT_START{ (GST_FLAGS (obj) |= (1<<(flag))); }G_STMT_END
|
||||||
#define GST_FLAG_UNSET(obj,flag) G_STMT_START{ (GST_FLAGS (obj) &= ~(1<<(flag))); }G_STMT_END
|
#define GST_FLAG_UNSET(obj,flag) G_STMT_START{ (GST_FLAGS (obj) &= ~(1<<(flag))); }G_STMT_END
|
||||||
|
|
||||||
|
#define GST_OBJECT_NAME(obj) (const gchar*)(((GstObject *)(obj))->name)
|
||||||
|
#define GST_OBJECT_PARENT(obj) (((GstObject *)(obj))->parent)
|
||||||
|
|
||||||
|
#define GST_OBJECT_DESTROYED(obj) (GST_FLAG_IS_SET (obj, GST_DESTROYED))
|
||||||
|
#define GST_OBJECT_FLOATING(obj) (GST_FLAG_IS_SET (obj, GST_FLOATING))
|
||||||
|
|
||||||
/* object locking */
|
/* object locking */
|
||||||
#define GST_LOCK(obj) (g_mutex_lock(GST_OBJECT(obj)->lock))
|
#define GST_LOCK(obj) (g_mutex_lock(GST_OBJECT(obj)->lock))
|
||||||
#define GST_TRYLOCK(obj) (g_mutex_trylock(GST_OBJECT(obj)->lock))
|
#define GST_TRYLOCK(obj) (g_mutex_trylock(GST_OBJECT(obj)->lock))
|
||||||
|
@ -129,12 +141,12 @@ gboolean gst_object_check_uniqueness (GList *list, const gchar *name);
|
||||||
xmlNodePtr gst_object_save_thyself (GstObject *object, xmlNodePtr parent);
|
xmlNodePtr gst_object_save_thyself (GstObject *object, xmlNodePtr parent);
|
||||||
|
|
||||||
/* refcounting */
|
/* refcounting */
|
||||||
#define gst_object_ref(object) gtk_object_ref(GTK_OBJECT(object));
|
GstObject * gst_object_ref (GstObject *object);
|
||||||
#define gst_object_unref(object) gtk_object_unref(GTK_OBJECT(object));
|
void gst_object_unref (GstObject *object);
|
||||||
#define gst_object_sink(object) gtk_object_sink(GTK_OBJECT(object));
|
void gst_object_sink (GstObject *object);
|
||||||
|
|
||||||
/* destroying an object */
|
/* destroying an object */
|
||||||
#define gst_object_destroy(object) gtk_object_destroy(GTK_OBJECT(object))
|
void gst_object_destroy (GstObject *object);
|
||||||
|
|
||||||
/* printing out the 'path' of the object */
|
/* printing out the 'path' of the object */
|
||||||
gchar * gst_object_get_path_string (GstObject *object);
|
gchar * gst_object_get_path_string (GstObject *object);
|
||||||
|
|
|
@ -180,7 +180,8 @@ gst_typefind_chain (GstPad *pad, GstBuffer *buf)
|
||||||
|
|
||||||
GST_DEBUG (0,"try type :%d \"%s\"\n", type->id, type->mime);
|
GST_DEBUG (0,"try type :%d \"%s\"\n", type->id, type->mime);
|
||||||
if (typefindfunc && (caps = typefindfunc (buf, type))) {
|
if (typefindfunc && (caps = typefindfunc (buf, type))) {
|
||||||
GST_DEBUG (0,"found type :%d \"%s\"\n", caps->id, type->mime);
|
GST_DEBUG (0,"found type :%d \"%s\" \"%s\"\n", caps->id, type->mime,
|
||||||
|
gst_caps_get_name (caps));
|
||||||
typefind->caps = caps;
|
typefind->caps = caps;
|
||||||
gtk_signal_emit (GTK_OBJECT (typefind), gst_typefind_signals[HAVE_TYPE],
|
gtk_signal_emit (GTK_OBJECT (typefind), gst_typefind_signals[HAVE_TYPE],
|
||||||
typefind->caps);
|
typefind->caps);
|
||||||
|
|
Loading…
Reference in a new issue