![]() |
![]() |
![]() |
GStreamer 0.11 Core Reference Manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Known Derived Interfaces | Properties | Signals |
#include <gst/gst.h> struct GstObject; struct GstObjectClass; enum GstObjectFlags; #define GST_OBJECT_FLAGS (obj) #define GST_OBJECT_FLAG_IS_SET (obj, flag) #define GST_OBJECT_FLAG_SET (obj, flag) #define GST_OBJECT_FLAG_UNSET (obj, flag) #define GST_OBJECT_NAME (obj) #define GST_OBJECT_PARENT (obj) #define GST_OBJECT_REFCOUNT (obj) #define GST_OBJECT_REFCOUNT_VALUE (obj) #define GST_OBJECT_LOCK (obj) #define GST_OBJECT_TRYLOCK (obj) #define GST_OBJECT_UNLOCK (obj) #define GST_OBJECT_GET_LOCK (obj) gboolean gst_object_set_name (GstObject *object
,const gchar *name
); gchar * gst_object_get_name (GstObject *object
); gboolean gst_object_set_parent (GstObject *object
,GstObject *parent
); GstObject * gst_object_get_parent (GstObject *object
); void gst_object_unparent (GstObject *object
); void gst_object_default_deep_notify (GObject *object
,GstObject *orig
,GParamSpec *pspec
,gchar **excluded_props
); void gst_object_default_error (GstObject *source
,const GError *error
,const gchar *debug
); gboolean gst_object_check_uniqueness (GList *list
,const gchar *name
); gboolean gst_object_has_ancestor (GstObject *object
,GstObject *ancestor
); gpointer gst_object_ref (gpointer object
); void gst_object_unref (gpointer object
); gpointer gst_object_ref_sink (gpointer object
); gboolean gst_object_replace (GstObject **oldobj
,GstObject *newobj
); gchar * gst_object_get_path_string (GstObject *object
);
GObject +----GInitiallyUnowned +----GstObject +----GstPad +----GstPadTemplate +----GstPluginFeature +----GstElement +----GstBus +----GstTask +----GstTaskPool +----GstClock +----GstPlugin +----GstRegistry +----GstIndex
GstObject provides a root for the object hierarchy tree filed in by the GStreamer library. It is currently a thin wrapper on top of GObject. It is an abstract class that is not very usable on its own.
GstObject gives us basic refcounting, parenting functionality and locking.
Most of the function are just extended for special GStreamer needs and can be
found under the same name in the base class of GstObject which is GObject
(e.g. g_object_ref()
becomes gst_object_ref()
).
The most interesting difference between GstObject and GObject is the
"floating" reference count. A GObject is created with a reference count of
1, owned by the creator of the GObject. (The owner of a reference is the
code section that has the right to call gst_object_unref()
in order to
remove that reference.) A GstObject is created with a reference count of 1
also, but it isn't owned by anyone; Instead, the initial reference count
of a GstObject is "floating". The floating reference can be removed by
anyone at any time, by calling gst_object_sink()
. gst_object_sink()
does
nothing if an object is already sunk (has no floating reference).
When you add a GstElement to its parent container, the parent container will do this:
gst_object_ref (GST_OBJECT (child_element)); gst_object_sink (GST_OBJECT (child_element));
This means that the container now owns a reference to the child element
(since it called gst_object_ref()
), and the child element has no floating
reference.
The purpose of the floating reference is to keep the child element alive until you add it to a parent container, which then manages the lifetime of the object itself:
element = gst_element_factory_make (factoryname, name); // element has one floating reference to keep it alive gst_bin_add (GST_BIN (bin), element); // element has one non-floating reference owned by the container
Another effect of this is, that calling gst_object_unref()
on a bin object,
will also destoy all the GstElement objects in it. The same is true for
calling gst_bin_remove()
.
Special care has to be taken for all methods that gst_object_sink()
an object
since if the caller of those functions had a floating reference to the object,
the object reference is now invalid.
In contrast to GObject instances, GstObject adds a name property. The functions
gst_object_set_name()
and gst_object_get_name()
are used to set/get the name
of the object.
Last reviewed on 2005-11-09 (0.9.4)
struct GstObject { GMutex *lock; /* object LOCK */ gchar *name; /* object name */ GstObject *parent; /* this object's parent, weak ref */ guint32 flags; };
GStreamer base object class.
struct GstObjectClass { GInitiallyUnownedClass parent_class; const gchar *path_string_separator; /* signals */ void (*deep_notify) (GstObject * object, GstObject * orig, GParamSpec * pspec); /* virtual methods for subclasses */ };
GStreamer base object class.
GInitiallyUnownedClass |
parent |
const gchar * |
separator used by gst_object_get_path_string()
|
default signal handler |
typedef enum { /* padding */ GST_OBJECT_FLAG_LAST = (1<<4) } GstObjectFlags;
The standard flags that an gstobject may have.
#define GST_OBJECT_FLAGS(obj) (GST_OBJECT_CAST (obj)->flags)
This macro returns the entire set of flags for the object.
|
a GstObject |
#define GST_OBJECT_FLAG_IS_SET(obj,flag) ((GST_OBJECT_FLAGS (obj) & (flag)) == (flag))
This macro checks to see if the given flag is set.
|
a GstObject |
|
Flag to check for |
#define GST_OBJECT_FLAG_SET(obj,flag) (GST_OBJECT_FLAGS (obj) |= (flag))
This macro sets the given bits.
|
a GstObject |
|
Flag to set |
#define GST_OBJECT_FLAG_UNSET(obj,flag) (GST_OBJECT_FLAGS (obj) &= ~(flag))
This macro usets the given bits.
|
a GstObject |
|
Flag to set |
#define GST_OBJECT_NAME(obj) (GST_OBJECT_CAST(obj)->name)
Get the name of this object
|
a GstObject |
#define GST_OBJECT_PARENT(obj) (GST_OBJECT_CAST(obj)->parent)
Get the parent of this object
|
a GstObject |
#define GST_OBJECT_REFCOUNT(obj) (((GObject*)(obj))->ref_count)
Get access to the reference count field of the object.
|
a GstObject |
#define GST_OBJECT_REFCOUNT_VALUE(obj) g_atomic_int_get ((gint *) &GST_OBJECT_REFCOUNT(obj))
Get the reference count value of the object.
|
a GstObject |
#define GST_OBJECT_LOCK(obj) g_mutex_lock(GST_OBJECT_GET_LOCK(obj))
This macro will obtain a lock on the object, making serialization possible. It blocks until the lock can be obtained.
|
a GstObject to lock |
#define GST_OBJECT_TRYLOCK(obj) g_mutex_trylock(GST_OBJECT_GET_LOCK(obj))
This macro will try to obtain a lock on the object, but will return with FALSE if it can't get it immediately.
|
a GstObject. |
#define GST_OBJECT_UNLOCK(obj) g_mutex_unlock(GST_OBJECT_GET_LOCK(obj))
This macro releases a lock on the object.
|
a GstObject to unlock. |
#define GST_OBJECT_GET_LOCK(obj) (GST_OBJECT_CAST(obj)->lock)
Acquire a reference to the mutex of this object.
|
a GstObject |
gboolean gst_object_set_name (GstObject *object
,const gchar *name
);
Sets the name of object
, or gives object
a guaranteed unique
name (if name
is NULL).
This function makes a copy of the provided name, so the caller
retains ownership of the name it sent.
|
a GstObject |
|
new name of object |
Returns : |
TRUE if the name could be set. Since Objects that have
a parent cannot be renamed, this function returns FALSE in those
cases.
MT safe. This function grabs and releases object 's LOCK. |
gchar * gst_object_get_name (GstObject *object
);
Returns a copy of the name of object
.
Caller should g_free()
the return value after usage.
For a nameless object, this returns NULL, which you can safely g_free()
as well.
Free-function: g_free
gboolean gst_object_set_parent (GstObject *object
,GstObject *parent
);
Sets the parent of object
to parent
. The object's reference count will
be incremented, and any floating reference will be removed (see gst_object_ref_sink()
).
|
a GstObject |
|
new parent of object |
Returns : |
TRUE if parent could be set or FALSE when object
already had a parent or object and parent are the same.
MT safe. Grabs and releases object 's LOCK. |
GstObject * gst_object_get_parent (GstObject *object
);
Returns the parent of object
. This function increases the refcount
of the parent object so you should gst_object_unref()
it after usage.
|
a GstObject |
Returns : |
parent of object , this can be NULL if object
has no parent. unref after usage.
MT safe. Grabs and releases object 's LOCK. [transfer full]
|
void gst_object_unparent (GstObject *object
);
Clear the parent of object
, removing the associated reference.
This function decreases the refcount of object
.
MT safe. Grabs and releases object
's lock.
|
a GstObject to unparent |
void gst_object_default_deep_notify (GObject *object
,GstObject *orig
,GParamSpec *pspec
,gchar **excluded_props
);
A default deep_notify signal callback for an object. The user data should contain a pointer to an array of strings that should be excluded from the notify. The default handler will print the new value of the property using g_print.
MT safe. This function grabs and releases object
's LOCK for getting its
path string.
|
the GObject that signalled the notify. |
|
a GstObject that initiated the notify. |
|
a GParamSpec of the property. |
|
(array zero-terminated=1) (element-type gchar*) (allow-none):a set of user-specified properties to exclude or NULL to show all changes. |
void gst_object_default_error (GstObject *source
,const GError *error
,const gchar *debug
);
A default error function that uses g_printerr()
to display the error message
and the optional debug sting..
The default handler will simply print the error string using g_print.
|
the GstObject that initiated the error. |
|
the GError. [in] |
|
an additional debug information string, or NULL. [in][allow-none] |
gboolean gst_object_check_uniqueness (GList *list
,const gchar *name
);
Checks to see if there is any object named name
in list
. This function
does not do any locking of any kind. You might want to protect the
provided list with the lock of the owner of the list. This function
will lock each GstObject in the list to compare the name, so be
carefull when passing a list with a locked object.
gboolean gst_object_has_ancestor (GstObject *object
,GstObject *ancestor
);
Check if object
has an ancestor ancestor
somewhere up in
the hierarchy. One can e.g. check if a GstElement is inside a GstPipeline.
gpointer gst_object_ref (gpointer object
);
Increments the reference count on object
. This function
does not take the lock on object
because it relies on
atomic refcounting.
This object returns the input parameter to ease writing constructs like : result = gst_object_ref (object->parent);
|
a GstObject to reference |
Returns : |
A pointer to object . [transfer full]
|
void gst_object_unref (gpointer object
);
Decrements the reference count on object
. If reference count hits
zero, destroy object
. This function does not take the lock
on object
as it relies on atomic refcounting.
The unref method should never be called with the LOCK held since this might deadlock the dispose function.
|
a GstObject to unreference |
gpointer gst_object_ref_sink (gpointer object
);
Increase the reference count of object
, and possibly remove the floating
reference, if object
has a floating reference.
In other words, if the object is floating, then this call "assumes ownership" of the floating reference, converting it to a normal reference by clearing the floating flag while leaving the reference count unchanged. If the object is not floating, then this call adds a new normal reference increasing the reference count by one.
|
a GstObject to sink |
gboolean gst_object_replace (GstObject **oldobj
,GstObject *newobj
);
Atomically modifies a pointer to point to a new object.
The reference count of oldobj
is decreased and the reference count of
newobj
is increased.
Either newobj
and the value pointed to by oldobj
may be NULL.
"name"
property"name" gchar* : Read / Write / Construct
The name of the object.
Default value: NULL
"deep-notify"
signalvoid user_function (GstObject *gstobject,
GstObject *prop_object,
GParamSpec *prop,
gpointer user_data) : No Hooks
The deep notify signal is used to be notified of property changes. It is typically attached to the toplevel bin to receive notifications from all the elements contained in that bin.
|
a GstObject |
|
the object that originated the signal |
|
the property that changed |
|
user data set when the signal handler was connected. |