GstObject

GstObject — Base class for the GStreamer object hierarchy

Synopsis


#include <gst/gst.h>


            GstObject;
enum        GstObjectFlags;
#define     GST_FLAGS                       (obj)
#define     GST_FLAG_IS_SET                 (obj,flag)
#define     GST_FLAG_SET                    (obj,flag)
#define     GST_FLAG_UNSET                  (obj,flag)
#define     GST_OBJECT_NAME                 (obj)
#define     GST_OBJECT_PARENT               (obj)
#define     GST_LOCK                        (obj)
#define     GST_TRYLOCK                     (obj)
#define     GST_UNLOCK                      (obj)
#define     GST_GET_LOCK                    (obj)
#define     GST_OBJECT_IS_DESTROYED         (obj)
#define     GST_OBJECT_IS_DISPOSING         (obj)
#define     GST_OBJECT_IS_FLOATING          (obj)
#define     GST_OBJECT_REFCOUNT             (obj)
#define     GST_OBJECT_REFCOUNT_VALUE       (obj)
#define     GST_CLASS_GET_LOCK              (obj)
#define     GST_CLASS_LOCK                  (obj)
#define     GST_CLASS_TRYLOCK               (obj)
#define     GST_CLASS_UNLOCK                (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);
gchar*      gst_object_get_name_prefix      (GstObject *object);
void        gst_object_set_name_prefix      (GstObject *object,
                                             const gchar *name_prefix);
void        gst_object_default_deep_notify  (GObject *object,
                                             GstObject *orig,
                                             GParamSpec *pspec,
                                             gchar **excluded_props);
void        gst_object_default_error        (GstObject *source,
                                             GError *error,
                                             gchar *debug);
gboolean    gst_object_check_uniqueness     (GList *list,
                                             const gchar *name);
xmlNodePtr  gst_object_save_thyself         (GstObject *object,
                                             xmlNodePtr parent);
void        gst_object_restore_thyself      (GstObject *object,
                                             xmlNodePtr self);
gpointer    gst_object_ref                  (gpointer object);
void        gst_object_unref                (gpointer object);
void        gst_object_sink                 (gpointer object);
void        gst_object_replace              (GstObject **oldobj,
                                             GstObject *newobj);
gchar*      gst_object_get_path_string      (GstObject *object);
guint       gst_class_signal_connect        (GstObjectClass *klass,
                                             const gchar *name,
                                             gpointer func,
                                             gpointer func_data);
void        gst_class_signal_emit_by_name   (GstObject *object,
                                             const gchar *name,
                                             xmlNodePtr self);


Object Hierarchy


  GObject
   +----GstObject
         +----GstPad
         +----GstElement
         +----GstPadTemplate
         +----GstIndex
         +----GstBus
         +----GstClock
         +----GstTask
         +----GstXML
         +----GstCollectPads

Properties


  "name"                 gchararray            : Read / Write / Construct

Signal Prototypes


"deep-notify"
            void        user_function      (GstObject *gstobject,
                                            GObject *arg1,
                                            GParamSpec *arg2,
                                            gpointer user_data);
"object-saved"
            void        user_function      (GstObject *gstobject,
                                            gpointer arg1,
                                            gpointer user_data);
"parent-set"
            void        user_function      (GstObject *gstobject,
                                            GObject *arg1,
                                            gpointer user_data);
"parent-unset"
            void        user_function      (GstObject *gstobject,
                                            GObject *arg1,
                                            gpointer user_data);

Description

GstObject provides a root for the object hierarchy tree filed in by the GST 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; calling gst_object_unref() on the newly-created GtkObject is incorrect. 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:

   element = gst_element_factory_make (factoryname, name);
   /* element has one floating reference to keep it alive */
   gtk_bin_add (GTK_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().

gst_object_set_name() and gst_object_get_name() are used to set/get the name of the object.

Details

GstObject

typedef struct {
  gint           refcount;

  GMutex        *lock;        /* object LOCK */
  gchar         *name;        /* object name */
  gchar         *name_prefix; /* used for debugging */
  GstObject     *parent;      /* this object's parent, weak ref */
  guint32        flags;
} GstObject;


enum GstObjectFlags

typedef enum
{
  GST_OBJECT_DISPOSING   = 0,
  GST_OBJECT_DESTROYED   = 1,
  GST_OBJECT_FLOATING,

  GST_OBJECT_FLAG_LAST   = 4
} GstObjectFlags;

Flags for an object

GST_OBJECT_DISPOSING
GST_OBJECT_DESTROYED
GST_OBJECT_FLOATING
GST_OBJECT_FLAG_LAST subclasses can add additional flags starting from this flag

GST_FLAGS()

#define GST_FLAGS(obj)                  (GST_OBJECT_CAST (obj)->flags)

This macro returns the entire set of flags for the object.

obj : Object to return flags for.

GST_FLAG_IS_SET()

#define GST_FLAG_IS_SET(obj,flag)       (!!(GST_FLAGS (obj) & (1<<(flag))))

This macro checks to see if the given flag is set.

obj : GstSrc to check for flag in.
flag : Flag to check for, must be a single bit in guint32.

GST_FLAG_SET()

#define GST_FLAG_SET(obj,flag)          G_STMT_START{ (GST_FLAGS (obj) |= (1<<(flag))); }G_STMT_END

This macro sets the given bits.

obj : Object to set flag in.
flag : Flag to set, can by any number of bits in guint32.

GST_FLAG_UNSET()

#define GST_FLAG_UNSET(obj,flag)        G_STMT_START{ (GST_FLAGS (obj) &= ~(1<<(flag))); }G_STMT_END

This macro usets the given bits.

obj : Object to unset flag in.
flag : Flag to set, must be a single bit in guint32.

GST_OBJECT_NAME()

#define GST_OBJECT_NAME(obj)            (GST_OBJECT_CAST(obj)->name)

Get the name of this object

obj : Object to get the name of.

GST_OBJECT_PARENT()

#define GST_OBJECT_PARENT(obj)          (GST_OBJECT_CAST(obj)->parent)

Get the parent of this object

obj : Object to get the parent of.

GST_LOCK()

#define GST_LOCK(obj)                   g_mutex_lock(GST_OBJECT_CAST(obj)->lock)

This macro will obtain a lock on the object, making serialization possible.

obj : Object to lock.

GST_TRYLOCK()

#define GST_TRYLOCK(obj)                g_mutex_trylock(GST_OBJECT_CAST(obj)->lock)

This macro will try to obtain a lock on the object, but will return with FALSE if it can't get it immediately.

obj : Object to try to get a lock on.

GST_UNLOCK()

#define GST_UNLOCK(obj)                 g_mutex_unlock(GST_OBJECT_CAST(obj)->lock)

This macro releases a lock on the object.

obj : Object to unlock.

GST_GET_LOCK()

#define GST_GET_LOCK(obj)               (GST_OBJECT_CAST(obj)->lock)

Acquire a reference to the mutex of this object.

obj : Object to get the mutex of.

GST_OBJECT_IS_DESTROYED()

#define GST_OBJECT_IS_DESTROYED(obj)    (GST_FLAG_IS_SET (obj, GST_OBJECT_DESTROYED))

obj :

GST_OBJECT_IS_DISPOSING()

#define GST_OBJECT_IS_DISPOSING(obj)    (GST_FLAG_IS_SET (obj, GST_OBJECT_DISPOSING))

obj :

GST_OBJECT_IS_FLOATING()

#define GST_OBJECT_IS_FLOATING(obj)     (GST_FLAG_IS_SET (obj, GST_OBJECT_FLOATING))

obj :

GST_OBJECT_REFCOUNT()

#define GST_OBJECT_REFCOUNT(obj)                ((GST_OBJECT_CAST(obj))->refcount)

obj :

GST_OBJECT_REFCOUNT_VALUE()

#define GST_OBJECT_REFCOUNT_VALUE(obj)          (g_atomic_int_get (&(GST_OBJECT_CAST(obj))->refcount))

obj :

GST_CLASS_GET_LOCK()

#define GST_CLASS_GET_LOCK(obj)         (GST_OBJECT_CLASS_CAST(obj)->lock)

obj :

GST_CLASS_LOCK()

#define GST_CLASS_LOCK(obj)             (g_static_rec_mutex_lock(GST_OBJECT_CLASS_CAST(obj)->lock))

obj :

GST_CLASS_TRYLOCK()

#define GST_CLASS_TRYLOCK(obj)          (g_static_rec_mutex_trylock(GST_OBJECT_CLASS_CAST(obj)->lock))

obj :

GST_CLASS_UNLOCK()

#define GST_CLASS_UNLOCK(obj)           (g_static_rec_mutex_unlock(GST_OBJECT_CLASS_CAST(obj)->lock))

obj :

gst_object_set_name ()

gboolean    gst_object_set_name             (GstObject *object,
                                             const gchar *name);

Sets the name of the object, or gives the 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.

object : a GstObject to set the name of
name : new name of object
Returns : TRUE if the name could be set. Objects that have a parent cannot be renamed. MT safe. This function grabs and releases the object's LOCK.

gst_object_get_name ()

gchar*      gst_object_get_name             (GstObject *object);

Returns a copy of the name of the 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.

object : a GstObject to get the name of
Returns : the name of the object. g_free() after usage. MT safe. This function grabs and releases the object's LOCK.

gst_object_set_parent ()

gboolean    gst_object_set_parent           (GstObject *object,
                                             GstObject *parent);

Sets the parent of object. The object's reference count will be incremented, and any floating reference will be removed (see gst_object_sink()).

Causes the parent-set signal to be emitted.

object : GstObject to set parent of
parent : new parent of object
Returns : TRUE if the parent could be set or FALSE when the object already had a parent, the object and parent are the same or wrong parameters were provided. MT safe. Grabs and releases the object's LOCK.

gst_object_get_parent ()

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.

object : GstObject to get parent of
Returns : parent of the object, this can be NULL if the object has no parent. unref after usage. MT safe. Grabs and releases the object's LOCK.

gst_object_unparent ()

void        gst_object_unparent             (GstObject *object);

Clear the parent of object, removing the associated reference. This function decreases the refcount of the object so the object might not point to valid memory anymore after calling this function.

MT safe. Grabs and releases the object's lock.

object : GstObject to unparent

gst_object_get_name_prefix ()

gchar*      gst_object_get_name_prefix      (GstObject *object);

Returns a copy of the name prefix of the object. Caller should g_free() the return value after usage. For a prefixless object, this returns NULL, which you can safely g_free() as well.

object : a GstObject to get the name prefix of
Returns : the name prefix of the object. g_free() after usage. MT safe. This function grabs and releases the object's LOCK.

gst_object_set_name_prefix ()

void        gst_object_set_name_prefix      (GstObject *object,
                                             const gchar *name_prefix);

Sets the name prefix of the object. This function makes a copy of the provided name prefix, so the caller retains ownership of the name prefix it sent.

MT safe. This function grabs and releases the object's LOCK.

object : a GstObject to set the name prefix of
name_prefix : new name prefix of object

gst_object_default_deep_notify ()

void        gst_object_default_deep_notify  (GObject *object,
                                             GstObject *orig,
                                             GParamSpec *pspec,
                                             gchar **excluded_props);

A default deep_notify signal callback for an element. 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 the object's LOCK or getting the path string of the object.

object : the GObject that signalled the notify.
orig : a GstObject that initiated the notify.
pspec : a GParamSpec of the property.
excluded_props : a set of user-specified properties to exclude or NULL to show all changes.

gst_object_default_error ()

void        gst_object_default_error        (GstObject *source,
                                             GError *error,
                                             gchar *debug);

A default error function.

The default handler will simply print the error string using g_print.

source : the GstObject that initiated the error.
error : the GError.
debug : an additional debug information string, or NULL.

gst_object_check_uniqueness ()

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.

list : a list of GstObject to check through
name : the name to search for
Returns : TRUE if the name does not appear in the list, FALSE if it does. MT safe. Grabs and releases the LOCK of each object in the list.

gst_object_save_thyself ()

xmlNodePtr  gst_object_save_thyself         (GstObject *object,
                                             xmlNodePtr parent);

Saves the given object into the parent XML node.

object : GstObject to save
parent : The parent XML node to save the object into
Returns : the new xmlNodePtr with the saved object

gst_object_restore_thyself ()

void        gst_object_restore_thyself      (GstObject *object,
                                             xmlNodePtr self);

Restores the given object with the data from the parent XML node.

object : GstObject to load into
self : The XML node to load the object from

gst_object_ref ()

gpointer    gst_object_ref                  (gpointer object);

Increments the refence count on the object. This function does not take the lock on the object because it relies on atomic refcounting.

This object returns the input parameter to ease writing constructs like : result = gst_object_ref (object->parent);

object : GstObject to reference
Returns : A pointer to the object

gst_object_unref ()

void        gst_object_unref                (gpointer object);

Decrements the refence count on the object. If reference count hits zero, destroy the object. This function does not take the lock on the 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.

object : GstObject to unreference

gst_object_sink ()

void        gst_object_sink                 (gpointer object);

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. Use gst_object_set_parent to have this done for you.

MT safe. This function grabs and releases the object lock.

object : GstObject to sink

gst_object_replace ()

void        gst_object_replace              (GstObject **oldobj,
                                             GstObject *newobj);

Unrefs the object pointer to by oldobj, refs the newobj and puts the newobj in *oldobj. Be carefull when calling this function, it does not take any locks. You might want to lock the object owning the oldobj pointer before calling this function.

Make sure not to LOCK the oldobj because it might be unreffed which could cause a deadlock when it is disposed.

oldobj : pointer to place of old GstObject
newobj : new GstObject

gst_object_get_path_string ()

gchar*      gst_object_get_path_string      (GstObject *object);

Generates a string describing the path of the object in the object hierarchy. Only useful (or used) for debugging.

object : GstObject to get the path from
Returns : a string describing the path of the object. You must g_free() the string after usage. MT safe. Grabs and releases the object's LOCK for all objects in the hierarchy.

gst_class_signal_connect ()

guint       gst_class_signal_connect        (GstObjectClass *klass,
                                             const gchar *name,
                                             gpointer func,
                                             gpointer func_data);

Connect to a class signal.

klass : the GstObjectClass to attach the signal to
name : the name of the signal to attach to
func : the signal function
func_data : a pointer to user data
Returns : the signal id.

gst_class_signal_emit_by_name ()

void        gst_class_signal_emit_by_name   (GstObject *object,
                                             const gchar *name,
                                             xmlNodePtr self);

emits the named class signal.

object : the object that sends the signal
name : the name of the signal to emit
self : data for the signal

Properties

The "name" property

  "name"                 gchararray            : Read / Write / Construct

The name of the object

Default value: NULL

Signals

The "deep-notify" signal

void        user_function                  (GstObject *gstobject,
                                            GObject *arg1,
                                            GParamSpec *arg2,
                                            gpointer user_data);

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.

gstobject : the object which received the signal.
arg1 : the object that originated the signal
arg2 : the property that changed
user_data : user data set when the signal handler was connected.

The "object-saved" signal

void        user_function                  (GstObject *gstobject,
                                            gpointer arg1,
                                            gpointer user_data);

Is trigered whenever a new object is saved to XML. You can connect to this signal to insert custom XML tags into the core XML.

gstobject : the object which received the signal.
arg1 : the xmlNodePtr of the parent node
user_data : user data set when the signal handler was connected.

The "parent-set" signal

void        user_function                  (GstObject *gstobject,
                                            GObject *arg1,
                                            gpointer user_data);

Is emitted when the parent of an object is set.

gstobject : the object which received the signal.
arg1 : the new parent
user_data : user data set when the signal handler was connected.

The "parent-unset" signal

void        user_function                  (GstObject *gstobject,
                                            GObject *arg1,
                                            gpointer user_data);

Is emitted when the parent of an object is unset.

gstobject : the object which received the signal.
arg1 : the old parent
user_data : user data set when the signal handler was connected.