2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2005 Wim Taymans <wim@fluendo.com>
6 * gstobject.c: Fundamental class used for all of GStreamer
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 * @short_description: Base class for the GStreamer object hierarchy
28 * #GstObject provides a root for the object hierarchy tree filed in by the
29 * GStreamer library. It is currently a thin wrapper on top of
30 * #GObject. It is an abstract class that is not very usable on its own.
32 * #GstObject gives us basic refcounting, parenting functionality and locking.
33 * Most of the function are just extended for special GStreamer needs and can be
34 * found under the same name in the base class of #GstObject which is #GObject
35 * (e.g. g_object_ref() becomes gst_object_ref()).
37 * The most interesting difference between #GstObject and #GObject is the
38 * "floating" reference count. A #GObject is created with a reference count of
39 * 1, owned by the creator of the #GObject. (The owner of a reference is the
40 * code section that has the right to call gst_object_unref() in order to
41 * remove that reference.) A #GstObject is created with a reference count of 1
42 * also, but it isn't owned by anyone; Instead, the initial reference count
43 * of a #GstObject is "floating". The floating reference can be removed by
44 * anyone at any time, by calling gst_object_sink(). gst_object_sink() does
45 * nothing if an object is already sunk (has no floating reference).
47 * When you add a #GstElement to its parent container, the parent container will
51 * gst_object_ref (GST_OBJECT (child_element));
52 * gst_object_sink (GST_OBJECT (child_element));
55 * This means that the container now owns a reference to the child element
56 * (since it called gst_object_ref()), and the child element has no floating
59 * The purpose of the floating reference is to keep the child element alive
60 * until you add it to a parent container, which then manages the lifetime of
64 * element = gst_element_factory_make (factoryname, name);
65 * // element has one floating reference to keep it alive
66 * gst_bin_add (GST_BIN (bin), element);
67 * // element has one non-floating reference owned by the container
71 * Another effect of this is, that calling gst_object_unref() on a bin object,
72 * will also destoy all the #GstElement objects in it. The same is true for
73 * calling gst_bin_remove().
75 * Special care has to be taken for all methods that gst_object_sink() an object
76 * since if the caller of those functions had a floating reference to the object,
77 * the object reference is now invalid.
79 * In contrast to #GObject instances, #GstObject adds a name property. The functions
80 * gst_object_set_name() and gst_object_get_name() are used to set/get the name
83 * Last reviewed on 2005-11-09 (0.9.4)
86 #include "gst_private.h"
87 #include "glib-compat-private.h"
89 #include "gstobject.h"
90 #include "gstmarshal.h"
91 #include "gstcontroller.h"
95 #ifndef GST_DISABLE_TRACE
97 static GstAllocTrace *_gst_object_trace;
100 #define DEBUG_REFCOUNT
102 /* Object signals and args */
123 /* maps type name quark => count */
124 static GData *object_name_counts = NULL;
126 G_LOCK_DEFINE_STATIC (object_name_mutex);
128 static void gst_object_set_property (GObject * object, guint prop_id,
129 const GValue * value, GParamSpec * pspec);
130 static void gst_object_get_property (GObject * object, guint prop_id,
131 GValue * value, GParamSpec * pspec);
133 static void gst_object_dispatch_properties_changed (GObject * object,
134 guint n_pspecs, GParamSpec ** pspecs);
136 static void gst_object_dispose (GObject * object);
137 static void gst_object_finalize (GObject * object);
139 static gboolean gst_object_set_name_default (GstObject * object);
141 static guint gst_object_signals[LAST_SIGNAL] = { 0 };
143 static GParamSpec *properties[PROP_LAST];
145 G_DEFINE_ABSTRACT_TYPE (GstObject, gst_object, G_TYPE_INITIALLY_UNOWNED);
148 gst_object_class_init (GstObjectClass * klass)
150 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
152 #ifndef GST_DISABLE_TRACE
153 _gst_object_trace = gst_alloc_trace_register (g_type_name (GST_TYPE_OBJECT));
156 gobject_class->set_property = gst_object_set_property;
157 gobject_class->get_property = gst_object_get_property;
159 properties[PROP_NAME] =
160 g_param_spec_string ("name", "Name", "The name of the object", NULL,
161 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
162 g_object_class_install_property (gobject_class, PROP_NAME,
163 properties[PROP_NAME]);
165 properties[PROP_PARENT] =
166 g_param_spec_object ("parent", "Parent", "The parent of the object",
167 GST_TYPE_OBJECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
168 g_object_class_install_property (gobject_class, PROP_PARENT,
169 properties[PROP_PARENT]);
172 * GstObject::deep-notify:
173 * @gstobject: a #GstObject
174 * @prop_object: the object that originated the signal
175 * @prop: the property that changed
177 * The deep notify signal is used to be notified of property changes. It is
178 * typically attached to the toplevel bin to receive notifications from all
179 * the elements contained in that bin.
181 gst_object_signals[DEEP_NOTIFY] =
182 g_signal_new ("deep-notify", G_TYPE_FROM_CLASS (klass),
183 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED |
184 G_SIGNAL_NO_HOOKS, G_STRUCT_OFFSET (GstObjectClass, deep_notify), NULL,
185 NULL, gst_marshal_VOID__OBJECT_PARAM, G_TYPE_NONE, 2, GST_TYPE_OBJECT,
188 klass->path_string_separator = "/";
190 /* see the comments at gst_object_dispatch_properties_changed */
191 gobject_class->dispatch_properties_changed
192 = GST_DEBUG_FUNCPTR (gst_object_dispatch_properties_changed);
194 gobject_class->dispose = gst_object_dispose;
195 gobject_class->finalize = gst_object_finalize;
199 gst_object_init (GstObject * object)
201 object->lock = g_mutex_new ();
202 object->parent = NULL;
204 GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "%p new", object);
206 #ifndef GST_DISABLE_TRACE
207 gst_alloc_trace_new (_gst_object_trace, object);
215 * @object: a #GstObject to reference
217 * Increments the reference count on @object. This function
218 * does not take the lock on @object because it relies on
219 * atomic refcounting.
221 * This object returns the input parameter to ease writing
223 * result = gst_object_ref (object->parent);
225 * Returns: (transfer full): A pointer to @object
228 gst_object_ref (gpointer object)
230 g_return_val_if_fail (object != NULL, NULL);
232 #ifdef DEBUG_REFCOUNT
233 GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "%p ref %d->%d", object,
234 ((GObject *) object)->ref_count, ((GObject *) object)->ref_count + 1);
236 g_object_ref (object);
243 * @object: a #GstObject to unreference
245 * Decrements the reference count on @object. If reference count hits
246 * zero, destroy @object. This function does not take the lock
247 * on @object as it relies on atomic refcounting.
249 * The unref method should never be called with the LOCK held since
250 * this might deadlock the dispose function.
253 gst_object_unref (gpointer object)
255 g_return_if_fail (object != NULL);
256 g_return_if_fail (((GObject *) object)->ref_count > 0);
258 #ifdef DEBUG_REFCOUNT
259 GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "%p unref %d->%d", object,
260 ((GObject *) object)->ref_count, ((GObject *) object)->ref_count - 1);
262 g_object_unref (object);
266 * gst_object_ref_sink: (skip)
267 * @object: a #GstObject to sink
269 * Increase the reference count of @object, and possibly remove the floating
270 * reference, if @object has a floating reference.
272 * In other words, if the object is floating, then this call "assumes ownership"
273 * of the floating reference, converting it to a normal reference by clearing
274 * the floating flag while leaving the reference count unchanged. If the object
275 * is not floating, then this call adds a new normal reference increasing the
276 * reference count by one.
279 gst_object_ref_sink (gpointer object)
281 g_return_val_if_fail (object != NULL, NULL);
283 #ifdef DEBUG_REFCOUNT
284 GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "%p ref_sink %d->%d",
285 object, ((GObject *) object)->ref_count,
286 ((GObject *) object)->ref_count + 1);
288 return g_object_ref_sink (object);
292 * gst_object_replace:
293 * @oldobj: (inout) (transfer full): pointer to a place of a #GstObject to
295 * @newobj: (transfer none): a new #GstObject
297 * Atomically modifies a pointer to point to a new object.
298 * The reference count of @oldobj is decreased and the reference count of
299 * @newobj is increased.
301 * Either @newobj and the value pointed to by @oldobj may be NULL.
303 * Returns: TRUE if @newobj was different from @oldobj
306 gst_object_replace (GstObject ** oldobj, GstObject * newobj)
310 g_return_val_if_fail (oldobj != NULL, FALSE);
312 #ifdef DEBUG_REFCOUNT
313 GST_CAT_TRACE (GST_CAT_REFCOUNTING, "replace %p %s (%d) with %p %s (%d)",
314 *oldobj, *oldobj ? GST_STR_NULL (GST_OBJECT_NAME (*oldobj)) : "(NONE)",
315 *oldobj ? G_OBJECT (*oldobj)->ref_count : 0,
316 newobj, newobj ? GST_STR_NULL (GST_OBJECT_NAME (newobj)) : "(NONE)",
317 newobj ? G_OBJECT (newobj)->ref_count : 0);
320 oldptr = g_atomic_pointer_get ((gpointer *) oldobj);
322 if (G_UNLIKELY (oldptr == newobj))
326 g_object_ref (newobj);
328 while (G_UNLIKELY (!g_atomic_pointer_compare_and_exchange ((gpointer *)
329 oldobj, oldptr, newobj))) {
330 oldptr = g_atomic_pointer_get ((gpointer *) oldobj);
331 if (G_UNLIKELY (oldptr == newobj))
336 g_object_unref (oldptr);
338 return oldptr != newobj;
341 /* dispose is called when the object has to release all links
342 * to other objects */
344 gst_object_dispose (GObject * object)
346 GstObject *self = (GstObject *) object;
349 GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "dispose");
351 GST_OBJECT_LOCK (object);
352 if ((parent = GST_OBJECT_PARENT (object)))
354 GST_OBJECT_PARENT (object) = NULL;
355 GST_OBJECT_UNLOCK (object);
358 g_object_unref (self->ctrl);
362 ((GObjectClass *) gst_object_parent_class)->dispose (object);
369 g_critical ("\nTrying to dispose object \"%s\", but it still has a "
370 "parent \"%s\".\nYou need to let the parent manage the "
371 "object instead of unreffing the object directly.\n",
372 GST_OBJECT_NAME (object), GST_OBJECT_NAME (parent));
373 GST_OBJECT_UNLOCK (object);
374 /* ref the object again to revive it in this error case */
375 gst_object_ref (object);
380 /* finalize is called when the object has to free its resources */
382 gst_object_finalize (GObject * object)
384 GstObject *gstobject = GST_OBJECT_CAST (object);
386 GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "finalize");
388 g_signal_handlers_destroy (object);
390 g_free (gstobject->name);
391 g_mutex_free (gstobject->lock);
393 #ifndef GST_DISABLE_TRACE
394 gst_alloc_trace_free (_gst_object_trace, object);
397 ((GObjectClass *) gst_object_parent_class)->finalize (object);
400 /* Changing a GObject property of a GstObject will result in "deep-notify"
401 * signals being emitted by the object itself, as well as in each parent
402 * object. This is so that an application can connect a listener to the
403 * top-level bin to catch property-change notifications for all contained
409 gst_object_dispatch_properties_changed (GObject * object,
410 guint n_pspecs, GParamSpec ** pspecs)
412 GstObject *gst_object, *parent, *old_parent;
414 #ifndef GST_DISABLE_GST_DEBUG
416 const gchar *debug_name;
419 /* do the standard dispatching */
421 gst_object_parent_class)->dispatch_properties_changed (object, n_pspecs,
424 gst_object = GST_OBJECT_CAST (object);
425 #ifndef GST_DISABLE_GST_DEBUG
426 if (G_UNLIKELY (_gst_debug_min >= GST_LEVEL_LOG)) {
427 name = gst_object_get_name (gst_object);
428 debug_name = GST_STR_NULL (name);
433 /* now let the parent dispatch those, too */
434 parent = gst_object_get_parent (gst_object);
436 for (i = 0; i < n_pspecs; i++) {
437 GST_CAT_LOG_OBJECT (GST_CAT_PROPERTIES, parent,
438 "deep notification from %s (%s)", debug_name, pspecs[i]->name);
440 g_signal_emit (parent, gst_object_signals[DEEP_NOTIFY],
441 g_quark_from_string (pspecs[i]->name), gst_object, pspecs[i]);
445 parent = gst_object_get_parent (old_parent);
446 gst_object_unref (old_parent);
448 #ifndef GST_DISABLE_GST_DEBUG
454 * gst_object_default_deep_notify:
455 * @object: the #GObject that signalled the notify.
456 * @orig: a #GstObject that initiated the notify.
457 * @pspec: a #GParamSpec of the property.
458 * @excluded_props: (array zero-terminated=1) (element-type gchar*)
459 * (allow-none):a set of user-specified properties to exclude or
460 * NULL to show all changes.
462 * A default deep_notify signal callback for an object. The user data
463 * should contain a pointer to an array of strings that should be excluded
464 * from the notify. The default handler will print the new value of the property
467 * MT safe. This function grabs and releases @object's LOCK for getting its
471 gst_object_default_deep_notify (GObject * object, GstObject * orig,
472 GParamSpec * pspec, gchar ** excluded_props)
474 GValue value = { 0, }; /* the important thing is that value.type = 0 */
478 if (pspec->flags & G_PARAM_READABLE) {
479 /* let's not print these out for excluded properties... */
480 while (excluded_props != NULL && *excluded_props != NULL) {
481 if (strcmp (pspec->name, *excluded_props) == 0)
485 g_value_init (&value, pspec->value_type);
486 g_object_get_property (G_OBJECT (orig), pspec->name, &value);
488 /* FIXME: handle flags */
489 if (G_IS_PARAM_SPEC_ENUM (pspec)) {
490 GEnumValue *enum_value;
491 GEnumClass *klass = G_ENUM_CLASS (g_type_class_ref (pspec->value_type));
493 enum_value = g_enum_get_value (klass, g_value_get_enum (&value));
495 str = g_strdup_printf ("%s (%d)", enum_value->value_nick,
497 g_type_class_unref (klass);
499 str = g_strdup_value_contents (&value);
501 name = gst_object_get_path_string (orig);
502 g_print ("%s: %s = %s\n", name, pspec->name, str);
505 g_value_unset (&value);
507 name = gst_object_get_path_string (orig);
508 g_warning ("Parameter %s not readable in %s.", pspec->name, name);
514 gst_object_set_name_default (GstObject * object)
516 const gchar *type_name;
522 /* to ensure guaranteed uniqueness across threads, only one thread
523 * may ever assign a name */
524 G_LOCK (object_name_mutex);
526 if (!object_name_counts) {
527 g_datalist_init (&object_name_counts);
530 q = g_type_qname (G_OBJECT_TYPE (object));
531 count = GPOINTER_TO_INT (g_datalist_id_get_data (&object_name_counts, q));
532 g_datalist_id_set_data (&object_name_counts, q, GINT_TO_POINTER (count + 1));
534 G_UNLOCK (object_name_mutex);
536 /* GstFooSink -> foosink<N> */
537 type_name = g_quark_to_string (q);
538 if (strncmp (type_name, "Gst", 3) == 0)
540 name = g_strdup_printf ("%s%d", type_name, count);
542 for (i = 0; i < l; i++)
543 name[i] = g_ascii_tolower (name[i]);
545 GST_OBJECT_LOCK (object);
546 if (G_UNLIKELY (object->parent != NULL))
549 g_free (object->name);
552 GST_OBJECT_UNLOCK (object);
559 GST_WARNING ("parented objects can't be renamed");
560 GST_OBJECT_UNLOCK (object);
566 * gst_object_set_name:
567 * @object: a #GstObject
568 * @name: new name of object
570 * Sets the name of @object, or gives @object a guaranteed unique
571 * name (if @name is NULL).
572 * This function makes a copy of the provided name, so the caller
573 * retains ownership of the name it sent.
575 * Returns: TRUE if the name could be set. Since Objects that have
576 * a parent cannot be renamed, this function returns FALSE in those
579 * MT safe. This function grabs and releases @object's LOCK.
582 gst_object_set_name (GstObject * object, const gchar * name)
586 g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
588 GST_OBJECT_LOCK (object);
590 /* parented objects cannot be renamed */
591 if (G_UNLIKELY (object->parent != NULL))
595 g_free (object->name);
596 object->name = g_strdup (name);
597 GST_OBJECT_UNLOCK (object);
600 GST_OBJECT_UNLOCK (object);
601 result = gst_object_set_name_default (object);
603 /* FIXME-0.11: this misses a g_object_notify (object, "name"); unless called
604 * from gst_object_set_property.
605 * Ideally remove such custom setters (or make it static).
612 GST_WARNING ("parented objects can't be renamed");
613 GST_OBJECT_UNLOCK (object);
619 * gst_object_get_name:
620 * @object: a #GstObject
622 * Returns a copy of the name of @object.
623 * Caller should g_free() the return value after usage.
624 * For a nameless object, this returns NULL, which you can safely g_free()
627 * Free-function: g_free
629 * Returns: (transfer full): the name of @object. g_free() after usage.
631 * MT safe. This function grabs and releases @object's LOCK.
634 gst_object_get_name (GstObject * object)
636 gchar *result = NULL;
638 g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
640 GST_OBJECT_LOCK (object);
641 result = g_strdup (object->name);
642 GST_OBJECT_UNLOCK (object);
648 * gst_object_set_parent:
649 * @object: a #GstObject
650 * @parent: new parent of object
652 * Sets the parent of @object to @parent. The object's reference count will
653 * be incremented, and any floating reference will be removed (see gst_object_ref_sink()).
655 * Returns: TRUE if @parent could be set or FALSE when @object
656 * already had a parent or @object and @parent are the same.
658 * MT safe. Grabs and releases @object's LOCK.
661 gst_object_set_parent (GstObject * object, GstObject * parent)
663 g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
664 g_return_val_if_fail (GST_IS_OBJECT (parent), FALSE);
665 g_return_val_if_fail (object != parent, FALSE);
667 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, object,
668 "set parent (ref and sink)");
670 GST_OBJECT_LOCK (object);
671 if (G_UNLIKELY (object->parent != NULL))
674 object->parent = parent;
675 g_object_ref_sink (object);
676 GST_OBJECT_UNLOCK (object);
678 /* FIXME, this does not work, the deep notify takes the lock from the parent
679 * object and deadlocks when the parent holds its lock when calling this
680 * function (like _element_add_pad()) */
681 /* g_object_notify_by_pspec ((GObject *)object, properties[PROP_PARENT]); */
688 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, object,
689 "set parent failed, object already had a parent");
690 GST_OBJECT_UNLOCK (object);
696 * gst_object_get_parent:
697 * @object: a #GstObject
699 * Returns the parent of @object. This function increases the refcount
700 * of the parent object so you should gst_object_unref() it after usage.
702 * Returns: (transfer full): parent of @object, this can be NULL if @object
703 * has no parent. unref after usage.
705 * MT safe. Grabs and releases @object's LOCK.
708 gst_object_get_parent (GstObject * object)
710 GstObject *result = NULL;
712 g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
714 GST_OBJECT_LOCK (object);
715 result = object->parent;
716 if (G_LIKELY (result))
717 gst_object_ref (result);
718 GST_OBJECT_UNLOCK (object);
724 * gst_object_unparent:
725 * @object: a #GstObject to unparent
727 * Clear the parent of @object, removing the associated reference.
728 * This function decreases the refcount of @object.
730 * MT safe. Grabs and releases @object's lock.
733 gst_object_unparent (GstObject * object)
737 g_return_if_fail (GST_IS_OBJECT (object));
739 GST_OBJECT_LOCK (object);
740 parent = object->parent;
742 if (G_LIKELY (parent != NULL)) {
743 GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "unparent");
744 object->parent = NULL;
745 GST_OBJECT_UNLOCK (object);
747 /* g_object_notify_by_pspec ((GObject *)object, properties[PROP_PARENT]); */
749 gst_object_unref (object);
751 GST_OBJECT_UNLOCK (object);
756 * gst_object_has_ancestor:
757 * @object: a #GstObject to check
758 * @ancestor: a #GstObject to check as ancestor
760 * Check if @object has an ancestor @ancestor somewhere up in
761 * the hierarchy. One can e.g. check if a #GstElement is inside a #GstPipeline.
763 * Returns: TRUE if @ancestor is an ancestor of @object.
765 * MT safe. Grabs and releases @object's locks.
768 gst_object_has_ancestor (GstObject * object, GstObject * ancestor)
770 GstObject *parent, *tmp;
772 if (!ancestor || !object)
775 parent = gst_object_ref (object);
777 if (parent == ancestor) {
778 gst_object_unref (parent);
782 tmp = gst_object_get_parent (parent);
783 gst_object_unref (parent);
791 * gst_object_check_uniqueness:
792 * @list: (transfer none) (element-type Gst.Object): a list of #GstObject to
794 * @name: the name to search for
796 * Checks to see if there is any object named @name in @list. This function
797 * does not do any locking of any kind. You might want to protect the
798 * provided list with the lock of the owner of the list. This function
799 * will lock each #GstObject in the list to compare the name, so be
800 * carefull when passing a list with a locked object.
802 * Returns: TRUE if a #GstObject named @name does not appear in @list,
805 * MT safe. Grabs and releases the LOCK of each object in the list.
808 gst_object_check_uniqueness (GList * list, const gchar * name)
810 gboolean result = TRUE;
812 g_return_val_if_fail (name != NULL, FALSE);
814 for (; list; list = g_list_next (list)) {
818 child = GST_OBJECT_CAST (list->data);
820 GST_OBJECT_LOCK (child);
821 eq = strcmp (GST_OBJECT_NAME (child), name) == 0;
822 GST_OBJECT_UNLOCK (child);
824 if (G_UNLIKELY (eq)) {
834 gst_object_set_property (GObject * object, guint prop_id,
835 const GValue * value, GParamSpec * pspec)
837 GstObject *gstobject;
839 gstobject = GST_OBJECT_CAST (object);
843 gst_object_set_name (gstobject, g_value_get_string (value));
846 gst_object_set_parent (gstobject, g_value_get_object (value));
849 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
855 gst_object_get_property (GObject * object, guint prop_id,
856 GValue * value, GParamSpec * pspec)
858 GstObject *gstobject;
860 gstobject = GST_OBJECT_CAST (object);
864 g_value_take_string (value, gst_object_get_name (gstobject));
867 g_value_take_object (value, gst_object_get_parent (gstobject));
870 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
876 * gst_object_get_path_string:
877 * @object: a #GstObject
879 * Generates a string describing the path of @object in
880 * the object hierarchy. Only useful (or used) for debugging.
882 * Free-function: g_free
884 * Returns: (transfer full): a string describing the path of @object. You must
885 * g_free() the string after usage.
887 * MT safe. Grabs and releases the #GstObject's LOCK for all objects
891 gst_object_get_path_string (GstObject * object)
896 gchar *prevpath, *path;
897 const gchar *typename;
899 const gchar *separator;
901 /* ref object before adding to list */
902 gst_object_ref (object);
903 parentage = g_slist_prepend (NULL, object);
905 path = g_strdup ("");
907 /* first walk the object hierarchy to build a list of the parents,
908 * be carefull here with refcounting. */
910 if (GST_IS_OBJECT (object)) {
911 parent = gst_object_get_parent (object);
912 /* add parents to list, refcount remains increased while
913 * we handle the object */
915 parentage = g_slist_prepend (parentage, parent);
920 } while (object != NULL);
922 /* then walk the parent list and print them out. we need to
923 * decrease the refcounting on each element after we handled
925 for (parents = parentage; parents; parents = g_slist_next (parents)) {
926 if (G_IS_OBJECT (parents->data)) {
927 typename = G_OBJECT_TYPE_NAME (parents->data);
931 if (GST_IS_OBJECT (parents->data)) {
932 GstObject *item = GST_OBJECT_CAST (parents->data);
933 GstObjectClass *oclass = GST_OBJECT_GET_CLASS (item);
934 gchar *objname = gst_object_get_name (item);
936 component = g_strdup_printf ("%s:%s", typename, objname);
937 separator = oclass->path_string_separator;
939 gst_object_unref (item);
943 component = g_strdup_printf ("%s:%p", typename, parents->data);
945 component = g_strdup_printf ("%p", parents->data);
951 path = g_strjoin (separator, prevpath, component, NULL);
956 g_slist_free (parentage);
961 /* controller functions */
964 * gst_object_control_properties:
965 * @object: the object of which some properties should be controlled
966 * @...: %NULL terminated list of property names that should be controlled
968 * Creates a GstController that allows you to dynamically control one, or more,
969 * GObject properties. If the given GstObject already has a GstController,
970 * it adds the given properties to the existing
971 * controller and returns that controller.
973 * Returns: %TRUE if the properties have been made controllable.
976 gst_object_control_properties (GstObject * object, ...)
978 gboolean res = FALSE;
981 g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
983 va_start (var_args, object);
985 object->ctrl = gst_controller_new_valist (object, var_args);
986 res = (object->ctrl != NULL);
988 res = gst_controller_add_properties_valist ((GstController *) object->ctrl,
996 * gst_object_uncontrol_properties:
997 * @object: the object of which some properties should not be controlled anymore
998 * @...: %NULL terminated list of property names that should be controlled
1000 * Removes the given element's properties from it's controller
1002 * Returns: %FALSE if one of the given property names isn't handled by the
1003 * controller, %TRUE otherwise
1006 gst_object_uncontrol_properties (GstObject * object, ...)
1008 gboolean res = FALSE;
1009 g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
1014 va_start (var_args, object);
1015 res = gst_controller_remove_properties_valist (
1016 (GstController *) object->ctrl, var_args);
1023 * gst_object_suggest_next_sync:
1024 * @object: the object that has controlled properties
1026 * Convenience function for GObject
1028 * Returns: same thing as gst_controller_suggest_next_sync()
1031 gst_object_suggest_next_sync (GstObject * object)
1033 g_return_val_if_fail (GST_IS_OBJECT (object), GST_CLOCK_TIME_NONE);
1036 return gst_controller_suggest_next_sync ((GstController *) object->ctrl);
1037 return (GST_CLOCK_TIME_NONE);
1041 * gst_object_sync_values:
1042 * @object: the object that has controlled properties
1043 * @timestamp: the time that should be processed
1045 * Convenience function for GObject
1047 * Returns: same thing as gst_controller_sync_values()
1050 gst_object_sync_values (GstObject * object, GstClockTime timestamp)
1052 g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
1055 return gst_controller_sync_values ((GstController *) object->ctrl,
1057 /* this is no failure, its called by elements regardless if there is a
1058 * controller assigned or not */
1063 * gst_object_has_active_automation:
1064 * @object: the object that has controlled properties
1066 * Check if the object has an active controller. It has one if it has at least
1067 * one controlled property that is not disabled.
1069 * Returns: %TRUE if the controller is active
1072 gst_object_has_active_automation (GstObject * object)
1074 gboolean res = FALSE;
1076 g_return_if_fail (GST_IS_OBJECT (object));
1079 res = gst_controller_is_active ((GstController *) object->ctrl);
1084 * gst_object_set_automation_disabled:
1085 * @object: the object that has controlled properties
1086 * @disabled: boolean that specifies whether to disable the controller
1089 * This function is used to disable all properties of the #GstController
1090 * for some time, i.e. gst_object_sync_values() will do nothing..
1093 gst_object_set_automation_disabled (GstObject * object, gboolean disabled)
1095 g_return_if_fail (GST_IS_OBJECT (object));
1098 gst_controller_set_disabled (object->ctrl, disabled);
1102 * gst_object_set_property_automation_disabled:
1103 * @object: the object that has controlled properties
1104 * @property_name: property to disable
1105 * @disabled: boolean that specifies whether to disable the controller
1108 * This function is used to disable the #GstController on a property for
1109 * some time, i.e. gst_controller_sync_values() will do nothing for the
1113 gst_object_set_property_automation_disabled (GstObject * object,
1114 const gchar * property_name, gboolean disabled)
1116 g_return_if_fail (GST_IS_OBJECT (object));
1117 g_return_if_fail (property_name);
1120 gst_controller_set_property_disabled ((GstController *) object->ctrl,
1121 property_name, disabled);
1125 * gst_object_set_control_source:
1126 * @object: the controller object
1127 * @property_name: name of the property for which the #GstControlSource should be set
1128 * @csource: the #GstControlSource that should be used for the property
1130 * Sets the #GstControlSource for @property_name. If there already was a #GstControlSource
1131 * for this property it will be unreferenced.
1133 * Returns: %FALSE if the given property isn't handled by the controller or the new #GstControlSource
1134 * couldn't be bound to the property, %TRUE if everything worked as expected.
1137 gst_object_set_control_source (GstObject * object, const gchar * property_name,
1138 GstControlSource * csource)
1140 g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
1141 g_return_val_if_fail (property_name, FALSE);
1142 g_return_val_if_fail (GST_IS_CONTROL_SOURCE (csource), FALSE);
1145 return gst_controller_set_control_source ((GstController *) object->ctrl,
1146 property_name, csource);
1151 * gst_object_get_control_source:
1152 * @object: the object
1153 * @property_name: name of the property for which the #GstControlSource should be get
1155 * Gets the corresponding #GstControlSource for the property. This should be unreferenced
1158 * Returns: (transfer full): the #GstControlSource for @property_name or NULL if
1159 * the property is not controlled by this controller or no #GstControlSource was
1163 gst_object_get_control_source (GstObject * object, const gchar * property_name)
1165 g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
1166 g_return_val_if_fail (property_name, NULL);
1169 return gst_controller_get_control_source ((GstController *) object->ctrl,
1176 gst_object_get_value (GstObject * object, const gchar * property_name,
1177 GstClockTime timestamp)
1179 g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
1180 g_return_val_if_fail (property_name, NULL);
1183 return gst_controller_get (object->ctrl, property_name, timestamp);
1188 * gst_object_get_value_arrays:
1189 * @object: the object that has controlled properties
1190 * @timestamp: the time that should be processed
1191 * @value_arrays: list to return the control-values in
1193 * Function to be able to get an array of values for one or more given element
1196 * If the GstValueArray->values array in list nodes is NULL, it will be created
1198 * The type of the values in the array are the same as the property's type.
1200 * The g_object_* functions are just convenience functions for GObject
1202 * Returns: %TRUE if the given array(s) could be filled, %FALSE otherwise
1205 gst_object_get_value_arrays (GstObject * object, GstClockTime timestamp,
1206 GSList * value_arrays)
1208 g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
1209 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
1212 return gst_controller_get_value_arrays ((GstController *) object->ctrl,
1213 timestamp, value_arrays);
1218 * gst_object_get_value_array:
1219 * @object: the object that has controlled properties
1220 * @timestamp: the time that should be processed
1221 * @value_array: array to put control-values in
1223 * Function to be able to get an array of values for one element properties
1225 * If the GstValueArray->values array is NULL, it will be created by the function.
1226 * The type of the values in the array are the same as the property's type.
1228 * The g_object_* functions are just convenience functions for GObject
1230 * Returns: %TRUE if the given array(s) could be filled, %FALSE otherwise
1233 gst_object_get_value_array (GstObject * object, GstClockTime timestamp,
1234 GstValueArray * value_array)
1236 g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
1237 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
1240 return gst_controller_get_value_array ((GstController *) object->ctrl,
1241 timestamp, value_array);
1246 * gst_object_get_control_rate:
1247 * @object: the object that has controlled properties
1249 * Obtain the control-rate for this @object. Audio processing #GstElement
1250 * objects will use this rate to sub-divide their processing loop and call
1251 * gst_object_sync_values() inbetween. The length of the processing segment
1252 * should be up to @control-rate nanoseconds.
1254 * If the @object is not under property control, this will return
1255 * %GST_CLOCK_TIME_NONE. This allows the element to avoid the sub-dividing.
1257 * The control-rate is not expected to change if the element is in
1258 * %GST_STATE_PAUSED or %GST_STATE_PLAYING.
1260 * Returns: the control rate in nanoseconds
1263 gst_object_get_control_rate (GstObject * object)
1265 GstClockTime control_rate = GST_CLOCK_TIME_NONE;
1267 g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
1270 g_object_get (object->ctrl, "control-rate", &control_rate, NULL);
1271 return (control_rate);
1275 * gst_object_set_control_rate:
1276 * @object: the object that has controlled properties
1277 * @control_rate: the new control-rate in nanoseconds.
1279 * Change the control-rate for this @object. Audio processing #GstElement
1280 * objects will use this rate to sub-divide their processing loop and call
1281 * gst_object_sync_values() inbetween. The length of the processing segment
1282 * should be up to @control-rate nanoseconds.
1284 * The control-rate should not change if the element is in %GST_STATE_PAUSED or
1285 * %GST_STATE_PLAYING.
1288 gst_object_set_control_rate (GstObject * object, GstClockTime control_rate)
1290 g_return_if_fail (GST_IS_OBJECT (object));
1293 g_object_set (object->ctrl, "control-rate", control_rate, NULL);