parse: Don't dist the bison and flex generated headers
[platform/upstream/gstreamer.git] / gst / gstobject.c
1 /* GStreamer
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>
5  *
6  * gstobject.c: Fundamental class used for all of GStreamer
7  *
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.
12  *
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.
17  *
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., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 /**
25  * SECTION:gstobject
26  * @short_description: Base class for the GStreamer object hierarchy
27  *
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  * #GInitiallyUnowned. It is an abstract class that is not very usable on its own.
31  *
32  * #GstObject gives us basic refcounting, parenting functionality and locking.
33  * Most of the functions 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()).
36  *
37  * Since #GstObject derives from #GInitiallyUnowned, it also inherits the
38  * floating reference. Be aware that functions such as gst_bin_add() and
39  * gst_element_add_pad() take ownership of the floating reference.
40  *
41  * In contrast to #GObject instances, #GstObject adds a name property. The functions
42  * gst_object_set_name() and gst_object_get_name() are used to set/get the name
43  * of the object.
44  *
45  * <refsect2>
46  * <title>controlled properties</title>
47  * <para>
48  * Controlled properties offers a lightweight way to adjust gobject properties
49  * over stream-time. It works by using time-stamped value pairs that are queued
50  * for element-properties. At run-time the elements continuously pull value
51  * changes for the current stream-time.
52  *
53  * What needs to be changed in a #GstElement?
54  * Very little - it is just two steps to make a plugin controllable!
55  * <orderedlist>
56  *   <listitem><para>
57  *     mark gobject-properties paramspecs that make sense to be controlled,
58  *     by GST_PARAM_CONTROLLABLE.
59  *   </para></listitem>
60  *   <listitem><para>
61  *     when processing data (get, chain, loop function) at the beginning call
62  *     gst_object_sync_values(element,timestamp).
63  *     This will make the controller to update all gobject properties that are under
64  *     control with the current values based on timestamp.
65  *   </para></listitem>
66  * </orderedlist>
67  *
68  * What needs to be done in applications?
69  * Again it's not a lot to change.
70  * <orderedlist>
71  *   <listitem><para>
72  *     create a #GstControlSource.
73  *     csource = gst_interpolation_control_source_new ();
74  *     g_object_set (csource, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
75  *   </para></listitem>
76  *   <listitem><para>
77  *     Attach the #GstControlSource on the controller to a property.
78  *     gst_object_add_control_binding (object, gst_direct_control_binding_new (object, "prop1", csource));
79  *   </para></listitem>
80  *   <listitem><para>
81  *     Set the control values
82  *     gst_timed_value_control_source_set ((GstTimedValueControlSource *)csource,0 * GST_SECOND, value1);
83  *     gst_timed_value_control_source_set ((GstTimedValueControlSource *)csource,1 * GST_SECOND, value2);
84  *   </para></listitem>
85  *   <listitem><para>
86  *     start your pipeline
87  *   </para></listitem>
88  * </orderedlist>
89  * </para>
90  * </refsect2>
91  *
92  * Last reviewed on 2012-03-29 (0.11.3)
93  */
94
95 #include "gst_private.h"
96 #include "glib-compat-private.h"
97
98 #include "gstobject.h"
99 #include "gstclock.h"
100 #include "gstcontrolbinding.h"
101 #include "gstcontrolsource.h"
102 #include "gstinfo.h"
103 #include "gstparamspecs.h"
104 #include "gstutils.h"
105
106 #ifndef GST_DISABLE_TRACE
107 #include "gsttrace.h"
108 static GstAllocTrace *_gst_object_trace;
109 #endif
110
111 #define DEBUG_REFCOUNT
112
113 /* Object signals and args */
114 enum
115 {
116   DEEP_NOTIFY,
117   LAST_SIGNAL
118 };
119
120 enum
121 {
122   PROP_0,
123   PROP_NAME,
124   PROP_PARENT,
125   PROP_LAST
126 };
127
128 enum
129 {
130   SO_OBJECT_LOADED,
131   SO_LAST_SIGNAL
132 };
133
134 /* maps type name quark => count */
135 static GData *object_name_counts = NULL;
136
137 G_LOCK_DEFINE_STATIC (object_name_mutex);
138
139 static void gst_object_set_property (GObject * object, guint prop_id,
140     const GValue * value, GParamSpec * pspec);
141 static void gst_object_get_property (GObject * object, guint prop_id,
142     GValue * value, GParamSpec * pspec);
143
144 static void gst_object_dispatch_properties_changed (GObject * object,
145     guint n_pspecs, GParamSpec ** pspecs);
146
147 static void gst_object_dispose (GObject * object);
148 static void gst_object_finalize (GObject * object);
149
150 static gboolean gst_object_set_name_default (GstObject * object);
151
152 static guint gst_object_signals[LAST_SIGNAL] = { 0 };
153
154 static GParamSpec *properties[PROP_LAST];
155
156 G_DEFINE_ABSTRACT_TYPE (GstObject, gst_object, G_TYPE_INITIALLY_UNOWNED);
157
158 static void
159 gst_object_class_init (GstObjectClass * klass)
160 {
161   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
162
163 #ifndef GST_DISABLE_TRACE
164   _gst_object_trace =
165       _gst_alloc_trace_register (g_type_name (GST_TYPE_OBJECT), -2);
166 #endif
167
168   gobject_class->set_property = gst_object_set_property;
169   gobject_class->get_property = gst_object_get_property;
170
171   properties[PROP_NAME] =
172       g_param_spec_string ("name", "Name", "The name of the object", NULL,
173       G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
174
175   /**
176    * GstObject:parent:
177    *
178    * The parent of the object. Please note, that when changing the 'parent'
179    * property, we don't emit #GObject::notify and #GstObject::deep-notify
180    * signals due to locking issues. In some cases one can use
181    * #GstBin::element-added or #GstBin::element-removed signals on the parent to
182    * achieve a similar effect.
183    */
184   properties[PROP_PARENT] =
185       g_param_spec_object ("parent", "Parent", "The parent of the object",
186       GST_TYPE_OBJECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
187
188   g_object_class_install_properties (gobject_class, PROP_LAST, properties);
189
190   /**
191    * GstObject::deep-notify:
192    * @gstobject: a #GstObject
193    * @prop_object: the object that originated the signal
194    * @prop: the property that changed
195    *
196    * The deep notify signal is used to be notified of property changes. It is
197    * typically attached to the toplevel bin to receive notifications from all
198    * the elements contained in that bin.
199    */
200   gst_object_signals[DEEP_NOTIFY] =
201       g_signal_new ("deep-notify", G_TYPE_FROM_CLASS (klass),
202       G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED |
203       G_SIGNAL_NO_HOOKS, G_STRUCT_OFFSET (GstObjectClass, deep_notify), NULL,
204       NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2, GST_TYPE_OBJECT,
205       G_TYPE_PARAM);
206
207   klass->path_string_separator = "/";
208
209   /* see the comments at gst_object_dispatch_properties_changed */
210   gobject_class->dispatch_properties_changed
211       = GST_DEBUG_FUNCPTR (gst_object_dispatch_properties_changed);
212
213   gobject_class->dispose = gst_object_dispose;
214   gobject_class->finalize = gst_object_finalize;
215 }
216
217 static void
218 gst_object_init (GstObject * object)
219 {
220   g_mutex_init (&object->lock);
221   object->parent = NULL;
222   object->name = NULL;
223   GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "%p new", object);
224
225 #ifndef GST_DISABLE_TRACE
226   _gst_alloc_trace_new (_gst_object_trace, object);
227 #endif
228
229   object->flags = 0;
230
231   object->control_rate = 100 * GST_MSECOND;
232   object->last_sync = GST_CLOCK_TIME_NONE;
233 }
234
235 /**
236  * gst_object_ref:
237  * @object: (type Gst.Object): a #GstObject to reference
238  *
239  * Increments the reference count on @object. This function
240  * does not take the lock on @object because it relies on
241  * atomic refcounting.
242  *
243  * This object returns the input parameter to ease writing
244  * constructs like :
245  *  result = gst_object_ref (object->parent);
246  *
247  * Returns: (transfer full) (type Gst.Object): A pointer to @object
248  */
249 gpointer
250 gst_object_ref (gpointer object)
251 {
252   g_return_val_if_fail (object != NULL, NULL);
253
254 #ifdef DEBUG_REFCOUNT
255   GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "%p ref %d->%d", object,
256       ((GObject *) object)->ref_count, ((GObject *) object)->ref_count + 1);
257 #endif
258   g_object_ref (object);
259
260   return object;
261 }
262
263 /**
264  * gst_object_unref:
265  * @object: (type Gst.Object): a #GstObject to unreference
266  *
267  * Decrements the reference count on @object.  If reference count hits
268  * zero, destroy @object. This function does not take the lock
269  * on @object as it relies on atomic refcounting.
270  *
271  * The unref method should never be called with the LOCK held since
272  * this might deadlock the dispose function.
273  */
274 void
275 gst_object_unref (gpointer object)
276 {
277   g_return_if_fail (object != NULL);
278   g_return_if_fail (((GObject *) object)->ref_count > 0);
279
280 #ifdef DEBUG_REFCOUNT
281   GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "%p unref %d->%d", object,
282       ((GObject *) object)->ref_count, ((GObject *) object)->ref_count - 1);
283 #endif
284   g_object_unref (object);
285 }
286
287 /**
288  * gst_object_ref_sink: (skip)
289  * @object: a #GstObject to sink
290  *
291  * Increase the reference count of @object, and possibly remove the floating
292  * reference, if @object has a floating reference.
293  *
294  * In other words, if the object is floating, then this call "assumes ownership"
295  * of the floating reference, converting it to a normal reference by clearing
296  * the floating flag while leaving the reference count unchanged. If the object
297  * is not floating, then this call adds a new normal reference increasing the
298  * reference count by one.
299  */
300 gpointer
301 gst_object_ref_sink (gpointer object)
302 {
303   g_return_val_if_fail (object != NULL, NULL);
304
305 #ifdef DEBUG_REFCOUNT
306   GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "%p ref_sink %d->%d",
307       object, ((GObject *) object)->ref_count,
308       ((GObject *) object)->ref_count + 1);
309 #endif
310   return g_object_ref_sink (object);
311 }
312
313 /**
314  * gst_object_replace:
315  * @oldobj: (inout) (transfer full): pointer to a place of a #GstObject to
316  *     replace
317  * @newobj: (transfer none): a new #GstObject
318  *
319  * Atomically modifies a pointer to point to a new object.
320  * The reference count of @oldobj is decreased and the reference count of
321  * @newobj is increased.
322  *
323  * Either @newobj and the value pointed to by @oldobj may be NULL.
324  *
325  * Returns: TRUE if @newobj was different from @oldobj
326  */
327 gboolean
328 gst_object_replace (GstObject ** oldobj, GstObject * newobj)
329 {
330   GstObject *oldptr;
331
332   g_return_val_if_fail (oldobj != NULL, FALSE);
333
334 #ifdef DEBUG_REFCOUNT
335   GST_CAT_TRACE (GST_CAT_REFCOUNTING, "replace %p %s (%d) with %p %s (%d)",
336       *oldobj, *oldobj ? GST_STR_NULL (GST_OBJECT_NAME (*oldobj)) : "(NONE)",
337       *oldobj ? G_OBJECT (*oldobj)->ref_count : 0,
338       newobj, newobj ? GST_STR_NULL (GST_OBJECT_NAME (newobj)) : "(NONE)",
339       newobj ? G_OBJECT (newobj)->ref_count : 0);
340 #endif
341
342   oldptr = g_atomic_pointer_get ((gpointer *) oldobj);
343
344   if (G_UNLIKELY (oldptr == newobj))
345     return FALSE;
346
347   if (newobj)
348     gst_object_ref (newobj);
349
350   while (G_UNLIKELY (!g_atomic_pointer_compare_and_exchange ((gpointer *)
351               oldobj, oldptr, newobj))) {
352     oldptr = g_atomic_pointer_get ((gpointer *) oldobj);
353     if (G_UNLIKELY (oldptr == newobj))
354       break;
355   }
356
357   if (oldptr)
358     gst_object_unref (oldptr);
359
360   return oldptr != newobj;
361 }
362
363 /* dispose is called when the object has to release all links
364  * to other objects */
365 static void
366 gst_object_dispose (GObject * object)
367 {
368   GstObject *self = (GstObject *) object;
369   GstObject *parent;
370
371   GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "dispose");
372
373   GST_OBJECT_LOCK (object);
374   if ((parent = GST_OBJECT_PARENT (object)))
375     goto have_parent;
376   GST_OBJECT_PARENT (object) = NULL;
377   GST_OBJECT_UNLOCK (object);
378
379   if (self->control_bindings) {
380     GList *node;
381
382     for (node = self->control_bindings; node; node = g_list_next (node)) {
383       gst_object_unparent (node->data);
384     }
385     g_list_free (self->control_bindings);
386     self->control_bindings = NULL;
387   }
388
389   ((GObjectClass *) gst_object_parent_class)->dispose (object);
390
391   return;
392
393   /* ERRORS */
394 have_parent:
395   {
396     g_critical ("\nTrying to dispose object \"%s\", but it still has a "
397         "parent \"%s\".\nYou need to let the parent manage the "
398         "object instead of unreffing the object directly.\n",
399         GST_OBJECT_NAME (object), GST_OBJECT_NAME (parent));
400     GST_OBJECT_UNLOCK (object);
401     /* ref the object again to revive it in this error case */
402     gst_object_ref (object);
403     return;
404   }
405 }
406
407 /* finalize is called when the object has to free its resources */
408 static void
409 gst_object_finalize (GObject * object)
410 {
411   GstObject *gstobject = GST_OBJECT_CAST (object);
412
413   GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "finalize");
414
415   g_signal_handlers_destroy (object);
416
417   g_free (gstobject->name);
418   g_mutex_clear (&gstobject->lock);
419
420 #ifndef GST_DISABLE_TRACE
421   _gst_alloc_trace_free (_gst_object_trace, object);
422 #endif
423
424   ((GObjectClass *) gst_object_parent_class)->finalize (object);
425 }
426
427 /* Changing a GObject property of a GstObject will result in "deep-notify"
428  * signals being emitted by the object itself, as well as in each parent
429  * object. This is so that an application can connect a listener to the
430  * top-level bin to catch property-change notifications for all contained
431  * elements.
432  *
433  * MT safe.
434  */
435 static void
436 gst_object_dispatch_properties_changed (GObject * object,
437     guint n_pspecs, GParamSpec ** pspecs)
438 {
439   GstObject *gst_object, *parent, *old_parent;
440   guint i;
441 #ifndef GST_DISABLE_GST_DEBUG
442   gchar *name = NULL;
443   const gchar *debug_name;
444 #endif
445
446   /* do the standard dispatching */
447   ((GObjectClass *)
448       gst_object_parent_class)->dispatch_properties_changed (object, n_pspecs,
449       pspecs);
450
451   gst_object = GST_OBJECT_CAST (object);
452 #ifndef GST_DISABLE_GST_DEBUG
453   if (G_UNLIKELY (_gst_debug_min >= GST_LEVEL_LOG)) {
454     name = gst_object_get_name (gst_object);
455     debug_name = GST_STR_NULL (name);
456   } else
457     debug_name = "";
458 #endif
459
460   /* now let the parent dispatch those, too */
461   parent = gst_object_get_parent (gst_object);
462   while (parent) {
463     for (i = 0; i < n_pspecs; i++) {
464       GST_CAT_LOG_OBJECT (GST_CAT_PROPERTIES, parent,
465           "deep notification from %s (%s)", debug_name, pspecs[i]->name);
466
467       g_signal_emit (parent, gst_object_signals[DEEP_NOTIFY],
468           g_quark_from_string (pspecs[i]->name), gst_object, pspecs[i]);
469     }
470
471     old_parent = parent;
472     parent = gst_object_get_parent (old_parent);
473     gst_object_unref (old_parent);
474   }
475 #ifndef GST_DISABLE_GST_DEBUG
476   g_free (name);
477 #endif
478 }
479
480 /**
481  * gst_object_default_deep_notify:
482  * @object: the #GObject that signalled the notify.
483  * @orig: a #GstObject that initiated the notify.
484  * @pspec: a #GParamSpec of the property.
485  * @excluded_props: (array zero-terminated=1) (element-type gchar*) (allow-none):
486  *     a set of user-specified properties to exclude or NULL to show
487  *     all changes.
488  *
489  * A default deep_notify signal callback for an object. The user data
490  * should contain a pointer to an array of strings that should be excluded
491  * from the notify. The default handler will print the new value of the property
492  * using g_print.
493  *
494  * MT safe. This function grabs and releases @object's LOCK for getting its
495  *          path string.
496  */
497 void
498 gst_object_default_deep_notify (GObject * object, GstObject * orig,
499     GParamSpec * pspec, gchar ** excluded_props)
500 {
501   GValue value = { 0, };        /* the important thing is that value.type = 0 */
502   gchar *str = NULL;
503   gchar *name = NULL;
504
505   if (pspec->flags & G_PARAM_READABLE) {
506     /* let's not print these out for excluded properties... */
507     while (excluded_props != NULL && *excluded_props != NULL) {
508       if (strcmp (pspec->name, *excluded_props) == 0)
509         return;
510       excluded_props++;
511     }
512     g_value_init (&value, pspec->value_type);
513     g_object_get_property (G_OBJECT (orig), pspec->name, &value);
514
515     if (G_VALUE_HOLDS_STRING (&value))
516       str = g_value_dup_string (&value);
517     else
518       str = gst_value_serialize (&value);
519     name = gst_object_get_path_string (orig);
520     g_print ("%s: %s = %s\n", name, pspec->name, str);
521     g_free (name);
522     g_free (str);
523     g_value_unset (&value);
524   } else {
525     name = gst_object_get_path_string (orig);
526     g_warning ("Parameter %s not readable in %s.", pspec->name, name);
527     g_free (name);
528   }
529 }
530
531 static gboolean
532 gst_object_set_name_default (GstObject * object)
533 {
534   const gchar *type_name;
535   gint count;
536   gchar *name;
537   GQuark q;
538   guint i, l;
539
540   /* to ensure guaranteed uniqueness across threads, only one thread
541    * may ever assign a name */
542   G_LOCK (object_name_mutex);
543
544   if (!object_name_counts) {
545     g_datalist_init (&object_name_counts);
546   }
547
548   q = g_type_qname (G_OBJECT_TYPE (object));
549   count = GPOINTER_TO_INT (g_datalist_id_get_data (&object_name_counts, q));
550   g_datalist_id_set_data (&object_name_counts, q, GINT_TO_POINTER (count + 1));
551
552   G_UNLOCK (object_name_mutex);
553
554   /* GstFooSink -> foosink<N> */
555   type_name = g_quark_to_string (q);
556   if (strncmp (type_name, "Gst", 3) == 0)
557     type_name += 3;
558   /* give the 20th "queue" element and the first "queue2" different names */
559   l = strlen (type_name);
560   if (l > 0 && g_ascii_isdigit (type_name[l - 1])) {
561     name = g_strdup_printf ("%s-%d", type_name, count);
562   } else {
563     name = g_strdup_printf ("%s%d", type_name, count);
564   }
565
566   l = strlen (name);
567   for (i = 0; i < l; i++)
568     name[i] = g_ascii_tolower (name[i]);
569
570   GST_OBJECT_LOCK (object);
571   if (G_UNLIKELY (object->parent != NULL))
572     goto had_parent;
573
574   g_free (object->name);
575   object->name = name;
576
577   GST_OBJECT_UNLOCK (object);
578
579   return TRUE;
580
581 had_parent:
582   {
583     g_free (name);
584     GST_WARNING ("parented objects can't be renamed");
585     GST_OBJECT_UNLOCK (object);
586     return FALSE;
587   }
588 }
589
590 /**
591  * gst_object_set_name:
592  * @object: a #GstObject
593  * @name:   new name of object
594  *
595  * Sets the name of @object, or gives @object a guaranteed unique
596  * name (if @name is NULL).
597  * This function makes a copy of the provided name, so the caller
598  * retains ownership of the name it sent.
599  *
600  * Returns: TRUE if the name could be set. Since Objects that have
601  * a parent cannot be renamed, this function returns FALSE in those
602  * cases.
603  *
604  * MT safe.  This function grabs and releases @object's LOCK.
605  */
606 gboolean
607 gst_object_set_name (GstObject * object, const gchar * name)
608 {
609   gboolean result;
610
611   g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
612
613   GST_OBJECT_LOCK (object);
614
615   /* parented objects cannot be renamed */
616   if (G_UNLIKELY (object->parent != NULL))
617     goto had_parent;
618
619   if (name != NULL) {
620     g_free (object->name);
621     object->name = g_strdup (name);
622     GST_OBJECT_UNLOCK (object);
623     result = TRUE;
624   } else {
625     GST_OBJECT_UNLOCK (object);
626     result = gst_object_set_name_default (object);
627   }
628   /* FIXME-0.11: this misses a g_object_notify (object, "name"); unless called
629    * from gst_object_set_property.
630    * Ideally remove such custom setters (or make it static).
631    */
632   return result;
633
634   /* error */
635 had_parent:
636   {
637     GST_WARNING ("parented objects can't be renamed");
638     GST_OBJECT_UNLOCK (object);
639     return FALSE;
640   }
641 }
642
643 /**
644  * gst_object_get_name:
645  * @object: a #GstObject
646  *
647  * Returns a copy of the name of @object.
648  * Caller should g_free() the return value after usage.
649  * For a nameless object, this returns NULL, which you can safely g_free()
650  * as well.
651  *
652  * Free-function: g_free
653  *
654  * Returns: (transfer full): the name of @object. g_free() after usage.
655  *
656  * MT safe. This function grabs and releases @object's LOCK.
657  */
658 gchar *
659 gst_object_get_name (GstObject * object)
660 {
661   gchar *result = NULL;
662
663   g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
664
665   GST_OBJECT_LOCK (object);
666   result = g_strdup (object->name);
667   GST_OBJECT_UNLOCK (object);
668
669   return result;
670 }
671
672 /**
673  * gst_object_set_parent:
674  * @object: a #GstObject
675  * @parent: new parent of object
676  *
677  * Sets the parent of @object to @parent. The object's reference count will
678  * be incremented, and any floating reference will be removed (see gst_object_ref_sink()).
679  *
680  * Returns: TRUE if @parent could be set or FALSE when @object
681  * already had a parent or @object and @parent are the same.
682  *
683  * MT safe. Grabs and releases @object's LOCK.
684  */
685 gboolean
686 gst_object_set_parent (GstObject * object, GstObject * parent)
687 {
688   g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
689   g_return_val_if_fail (GST_IS_OBJECT (parent), FALSE);
690   g_return_val_if_fail (object != parent, FALSE);
691
692   GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, object,
693       "set parent (ref and sink)");
694
695   GST_OBJECT_LOCK (object);
696   if (G_UNLIKELY (object->parent != NULL))
697     goto had_parent;
698
699   object->parent = parent;
700   gst_object_ref_sink (object);
701   GST_OBJECT_UNLOCK (object);
702
703   /* FIXME-2.0: this does not work, the deep notify takes the lock from the
704    * parent object and deadlocks when the parent holds its lock when calling
705    * this function (like _element_add_pad()), we need to use a GRecMutex
706    * for locking the parent instead.
707    */
708   /* g_object_notify_by_pspec ((GObject *)object, properties[PROP_PARENT]); */
709
710   return TRUE;
711
712   /* ERROR handling */
713 had_parent:
714   {
715     GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, object,
716         "set parent failed, object already had a parent");
717     GST_OBJECT_UNLOCK (object);
718     return FALSE;
719   }
720 }
721
722 /**
723  * gst_object_get_parent:
724  * @object: a #GstObject
725  *
726  * Returns the parent of @object. This function increases the refcount
727  * of the parent object so you should gst_object_unref() it after usage.
728  *
729  * Returns: (transfer full): parent of @object, this can be NULL if @object
730  *   has no parent. unref after usage.
731  *
732  * MT safe. Grabs and releases @object's LOCK.
733  */
734 GstObject *
735 gst_object_get_parent (GstObject * object)
736 {
737   GstObject *result = NULL;
738
739   g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
740
741   GST_OBJECT_LOCK (object);
742   result = object->parent;
743   if (G_LIKELY (result))
744     gst_object_ref (result);
745   GST_OBJECT_UNLOCK (object);
746
747   return result;
748 }
749
750 /**
751  * gst_object_unparent:
752  * @object: a #GstObject to unparent
753  *
754  * Clear the parent of @object, removing the associated reference.
755  * This function decreases the refcount of @object.
756  *
757  * MT safe. Grabs and releases @object's lock.
758  */
759 void
760 gst_object_unparent (GstObject * object)
761 {
762   GstObject *parent;
763
764   g_return_if_fail (GST_IS_OBJECT (object));
765
766   GST_OBJECT_LOCK (object);
767   parent = object->parent;
768
769   if (G_LIKELY (parent != NULL)) {
770     GST_CAT_TRACE_OBJECT (GST_CAT_REFCOUNTING, object, "unparent");
771     object->parent = NULL;
772     GST_OBJECT_UNLOCK (object);
773
774     /* g_object_notify_by_pspec ((GObject *)object, properties[PROP_PARENT]); */
775
776     gst_object_unref (object);
777   } else {
778     GST_OBJECT_UNLOCK (object);
779   }
780 }
781
782 /**
783  * gst_object_has_ancestor:
784  * @object: a #GstObject to check
785  * @ancestor: a #GstObject to check as ancestor
786  *
787  * Check if @object has an ancestor @ancestor somewhere up in
788  * the hierarchy. One can e.g. check if a #GstElement is inside a #GstPipeline.
789  *
790  * Returns: TRUE if @ancestor is an ancestor of @object.
791  *
792  * MT safe. Grabs and releases @object's locks.
793  */
794 gboolean
795 gst_object_has_ancestor (GstObject * object, GstObject * ancestor)
796 {
797   GstObject *parent, *tmp;
798
799   if (!ancestor || !object)
800     return FALSE;
801
802   parent = gst_object_ref (object);
803   do {
804     if (parent == ancestor) {
805       gst_object_unref (parent);
806       return TRUE;
807     }
808
809     tmp = gst_object_get_parent (parent);
810     gst_object_unref (parent);
811     parent = tmp;
812   } while (parent);
813
814   return FALSE;
815 }
816
817 /**
818  * gst_object_check_uniqueness:
819  * @list: (transfer none) (element-type Gst.Object): a list of #GstObject to
820  *      check through
821  * @name: the name to search for
822  *
823  * Checks to see if there is any object named @name in @list. This function
824  * does not do any locking of any kind. You might want to protect the
825  * provided list with the lock of the owner of the list. This function
826  * will lock each #GstObject in the list to compare the name, so be
827  * careful when passing a list with a locked object.
828  *
829  * Returns: TRUE if a #GstObject named @name does not appear in @list,
830  * FALSE if it does.
831  *
832  * MT safe. Grabs and releases the LOCK of each object in the list.
833  */
834 gboolean
835 gst_object_check_uniqueness (GList * list, const gchar * name)
836 {
837   gboolean result = TRUE;
838
839   g_return_val_if_fail (name != NULL, FALSE);
840
841   for (; list; list = g_list_next (list)) {
842     GstObject *child;
843     gboolean eq;
844
845     child = GST_OBJECT_CAST (list->data);
846
847     GST_OBJECT_LOCK (child);
848     eq = strcmp (GST_OBJECT_NAME (child), name) == 0;
849     GST_OBJECT_UNLOCK (child);
850
851     if (G_UNLIKELY (eq)) {
852       result = FALSE;
853       break;
854     }
855   }
856   return result;
857 }
858
859
860 static void
861 gst_object_set_property (GObject * object, guint prop_id,
862     const GValue * value, GParamSpec * pspec)
863 {
864   GstObject *gstobject;
865
866   gstobject = GST_OBJECT_CAST (object);
867
868   switch (prop_id) {
869     case PROP_NAME:
870       gst_object_set_name (gstobject, g_value_get_string (value));
871       break;
872     case PROP_PARENT:
873       gst_object_set_parent (gstobject, g_value_get_object (value));
874       break;
875     default:
876       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
877       break;
878   }
879 }
880
881 static void
882 gst_object_get_property (GObject * object, guint prop_id,
883     GValue * value, GParamSpec * pspec)
884 {
885   GstObject *gstobject;
886
887   gstobject = GST_OBJECT_CAST (object);
888
889   switch (prop_id) {
890     case PROP_NAME:
891       g_value_take_string (value, gst_object_get_name (gstobject));
892       break;
893     case PROP_PARENT:
894       g_value_take_object (value, gst_object_get_parent (gstobject));
895       break;
896     default:
897       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
898       break;
899   }
900 }
901
902 /**
903  * gst_object_get_path_string:
904  * @object: a #GstObject
905  *
906  * Generates a string describing the path of @object in
907  * the object hierarchy. Only useful (or used) for debugging.
908  *
909  * Free-function: g_free
910  *
911  * Returns: (transfer full): a string describing the path of @object. You must
912  *          g_free() the string after usage.
913  *
914  * MT safe. Grabs and releases the #GstObject's LOCK for all objects
915  *          in the hierarchy.
916  */
917 gchar *
918 gst_object_get_path_string (GstObject * object)
919 {
920   GSList *parentage;
921   GSList *parents;
922   void *parent;
923   gchar *prevpath, *path;
924   const gchar *typename;
925   gchar *component;
926   const gchar *separator;
927
928   /* ref object before adding to list */
929   gst_object_ref (object);
930   parentage = g_slist_prepend (NULL, object);
931
932   path = g_strdup ("");
933
934   /* first walk the object hierarchy to build a list of the parents,
935    * be careful here with refcounting. */
936   do {
937     if (GST_IS_OBJECT (object)) {
938       parent = gst_object_get_parent (object);
939       /* add parents to list, refcount remains increased while
940        * we handle the object */
941       if (parent)
942         parentage = g_slist_prepend (parentage, parent);
943     } else {
944       break;
945     }
946     object = parent;
947   } while (object != NULL);
948
949   /* then walk the parent list and print them out. we need to
950    * decrease the refcounting on each element after we handled
951    * it. */
952   for (parents = parentage; parents; parents = g_slist_next (parents)) {
953     if (G_IS_OBJECT (parents->data)) {
954       typename = G_OBJECT_TYPE_NAME (parents->data);
955     } else {
956       typename = NULL;
957     }
958     if (GST_IS_OBJECT (parents->data)) {
959       GstObject *item = GST_OBJECT_CAST (parents->data);
960       GstObjectClass *oclass = GST_OBJECT_GET_CLASS (item);
961       gchar *objname = gst_object_get_name (item);
962
963       component = g_strdup_printf ("%s:%s", typename, objname);
964       separator = oclass->path_string_separator;
965       /* and unref now */
966       gst_object_unref (item);
967       g_free (objname);
968     } else {
969       if (typename) {
970         component = g_strdup_printf ("%s:%p", typename, parents->data);
971       } else {
972         component = g_strdup_printf ("%p", parents->data);
973       }
974       separator = "/";
975     }
976
977     prevpath = path;
978     path = g_strjoin (separator, prevpath, component, NULL);
979     g_free (prevpath);
980     g_free (component);
981   }
982
983   g_slist_free (parentage);
984
985   return path;
986 }
987
988 /* controller helper functions */
989
990 /*
991  * gst_object_find_control_binding:
992  * @self: the gobject to search for a property in
993  * @name: the gobject property name to look for
994  *
995  * Searches the list of properties under control.
996  *
997  * Returns: a #GstControlBinding or %NULL if the property is not being
998  * controlled.
999  */
1000 static GstControlBinding *
1001 gst_object_find_control_binding (GstObject * self, const gchar * name)
1002 {
1003   GstControlBinding *binding;
1004   GList *node;
1005
1006   for (node = self->control_bindings; node; node = g_list_next (node)) {
1007     binding = node->data;
1008     /* FIXME: eventually use GQuark to speed it up */
1009     if (!strcmp (binding->name, name)) {
1010       GST_DEBUG_OBJECT (self, "found control binding for property '%s'", name);
1011       return binding;
1012     }
1013   }
1014   GST_DEBUG_OBJECT (self, "controller does not manage property '%s'", name);
1015
1016   return NULL;
1017 }
1018
1019 /* controller functions */
1020
1021 /**
1022  * gst_object_suggest_next_sync:
1023  * @object: the object that has controlled properties
1024  *
1025  * Returns a suggestion for timestamps where buffers should be split
1026  * to get best controller results.
1027  *
1028  * Returns: Returns the suggested timestamp or %GST_CLOCK_TIME_NONE
1029  * if no control-rate was set.
1030  */
1031 GstClockTime
1032 gst_object_suggest_next_sync (GstObject * object)
1033 {
1034   GstClockTime ret;
1035
1036   g_return_val_if_fail (GST_IS_OBJECT (object), GST_CLOCK_TIME_NONE);
1037   g_return_val_if_fail (object->control_rate != GST_CLOCK_TIME_NONE,
1038       GST_CLOCK_TIME_NONE);
1039
1040   GST_OBJECT_LOCK (object);
1041
1042   /* TODO: Implement more logic, depending on interpolation mode and control
1043    * points
1044    * FIXME: we need playback direction
1045    */
1046   ret = object->last_sync + object->control_rate;
1047
1048   GST_OBJECT_UNLOCK (object);
1049
1050   return ret;
1051 }
1052
1053 /**
1054  * gst_object_sync_values:
1055  * @object: the object that has controlled properties
1056  * @timestamp: the time that should be processed
1057  *
1058  * Sets the properties of the object, according to the #GstControlSources that
1059  * (maybe) handle them and for the given timestamp.
1060  *
1061  * If this function fails, it is most likely the application developers fault.
1062  * Most probably the control sources are not setup correctly.
1063  *
1064  * Returns: %TRUE if the controller values could be applied to the object
1065  * properties, %FALSE otherwise
1066  */
1067 gboolean
1068 gst_object_sync_values (GstObject * object, GstClockTime timestamp)
1069 {
1070   GList *node;
1071   gboolean ret = TRUE;
1072
1073   g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
1074   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
1075
1076   GST_LOG_OBJECT (object, "sync_values");
1077   if (!object->control_bindings)
1078     return TRUE;
1079
1080   /* FIXME: this deadlocks */
1081   /* GST_OBJECT_LOCK (object); */
1082   g_object_freeze_notify ((GObject *) object);
1083   for (node = object->control_bindings; node; node = g_list_next (node)) {
1084     ret &= gst_control_binding_sync_values ((GstControlBinding *) node->data,
1085         object, timestamp, object->last_sync);
1086   }
1087   object->last_sync = timestamp;
1088   g_object_thaw_notify ((GObject *) object);
1089   /* GST_OBJECT_UNLOCK (object); */
1090
1091   return ret;
1092 }
1093
1094
1095 /**
1096  * gst_object_has_active_control_bindings:
1097  * @object: the object that has controlled properties
1098  *
1099  * Check if the @object has an active controlled properties.
1100  *
1101  * Returns: %TRUE if the object has active controlled properties
1102  */
1103 gboolean
1104 gst_object_has_active_control_bindings (GstObject * object)
1105 {
1106   gboolean res = FALSE;
1107   GList *node;
1108
1109   g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
1110
1111   GST_OBJECT_LOCK (object);
1112   for (node = object->control_bindings; node; node = g_list_next (node)) {
1113     res |= !gst_control_binding_is_disabled ((GstControlBinding *) node->data);
1114   }
1115   GST_OBJECT_UNLOCK (object);
1116   return res;
1117 }
1118
1119 /**
1120  * gst_object_set_control_bindings_disabled:
1121  * @object: the object that has controlled properties
1122  * @disabled: boolean that specifies whether to disable the controller
1123  * or not.
1124  *
1125  * This function is used to disable all controlled properties of the @object for
1126  * some time, i.e. gst_object_sync_values() will do nothing.
1127  */
1128 void
1129 gst_object_set_control_bindings_disabled (GstObject * object, gboolean disabled)
1130 {
1131   GList *node;
1132
1133   g_return_if_fail (GST_IS_OBJECT (object));
1134
1135   GST_OBJECT_LOCK (object);
1136   for (node = object->control_bindings; node; node = g_list_next (node)) {
1137     gst_control_binding_set_disabled ((GstControlBinding *) node->data,
1138         disabled);
1139   }
1140   GST_OBJECT_UNLOCK (object);
1141 }
1142
1143 /**
1144  * gst_object_set_control_binding_disabled:
1145  * @object: the object that has controlled properties
1146  * @property_name: property to disable
1147  * @disabled: boolean that specifies whether to disable the controller
1148  * or not.
1149  *
1150  * This function is used to disable the control bindings on a property for
1151  * some time, i.e. gst_object_sync_values() will do nothing for the
1152  * property.
1153  */
1154 void
1155 gst_object_set_control_binding_disabled (GstObject * object,
1156     const gchar * property_name, gboolean disabled)
1157 {
1158   GstControlBinding *binding;
1159
1160   g_return_if_fail (GST_IS_OBJECT (object));
1161   g_return_if_fail (property_name);
1162
1163   GST_OBJECT_LOCK (object);
1164   if ((binding = gst_object_find_control_binding (object, property_name))) {
1165     gst_control_binding_set_disabled (binding, disabled);
1166   }
1167   GST_OBJECT_UNLOCK (object);
1168 }
1169
1170
1171 /**
1172  * gst_object_add_control_binding:
1173  * @object: the controller object
1174  * @binding: (transfer full): the #GstControlBinding that should be used
1175  *
1176  * Attach the #GstControlBinding to the object. If there already was a
1177  * #GstControlBinding for this property it will be replaced.
1178  *
1179  * The @object will take ownership of the @binding.
1180  *
1181  * Returns: %FALSE if the given @binding has not been setup for this object or
1182  * has been setup for a non suitable property, %TRUE otherwise.
1183  */
1184 gboolean
1185 gst_object_add_control_binding (GstObject * object, GstControlBinding * binding)
1186 {
1187   GstControlBinding *old;
1188
1189   g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
1190   g_return_val_if_fail (GST_IS_CONTROL_BINDING (binding), FALSE);
1191   g_return_val_if_fail (binding->pspec, FALSE);
1192
1193   GST_OBJECT_LOCK (object);
1194   if ((old = gst_object_find_control_binding (object, binding->name))) {
1195     GST_DEBUG_OBJECT (object, "controlled property %s removed", old->name);
1196     object->control_bindings = g_list_remove (object->control_bindings, old);
1197     gst_object_unparent (GST_OBJECT_CAST (old));
1198   }
1199   object->control_bindings = g_list_prepend (object->control_bindings, binding);
1200   gst_object_set_parent (GST_OBJECT_CAST (binding), object);
1201   GST_DEBUG_OBJECT (object, "controlled property %s added", binding->name);
1202   GST_OBJECT_UNLOCK (object);
1203
1204   return TRUE;
1205 }
1206
1207 /**
1208  * gst_object_get_control_binding:
1209  * @object: the object
1210  * @property_name: name of the property
1211  *
1212  * Gets the corresponding #GstControlBinding for the property. This should be
1213  * unreferenced again after use.
1214  *
1215  * Returns: (transfer full): the #GstControlBinding for @property_name or %NULL if
1216  * the property is not controlled.
1217  */
1218 GstControlBinding *
1219 gst_object_get_control_binding (GstObject * object, const gchar * property_name)
1220 {
1221   GstControlBinding *binding;
1222
1223   g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
1224   g_return_val_if_fail (property_name, NULL);
1225
1226   GST_OBJECT_LOCK (object);
1227   if ((binding = gst_object_find_control_binding (object, property_name))) {
1228     gst_object_ref (binding);
1229   }
1230   GST_OBJECT_UNLOCK (object);
1231
1232   return binding;
1233 }
1234
1235 /**
1236  * gst_object_remove_control_binding:
1237  * @object: the object
1238  * @binding: the binding
1239  *
1240  * Removes the corresponding #GstControlBinding. If it was the
1241  * last ref of the binding, it will be disposed.  
1242  *
1243  * Returns: %TRUE if the binding could be removed.
1244  */
1245 gboolean
1246 gst_object_remove_control_binding (GstObject * object,
1247     GstControlBinding * binding)
1248 {
1249   GList *node;
1250   gboolean ret = FALSE;
1251
1252   g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
1253   g_return_val_if_fail (GST_IS_CONTROL_BINDING (binding), FALSE);
1254
1255   GST_OBJECT_LOCK (object);
1256   if ((node = g_list_find (object->control_bindings, binding))) {
1257     GST_DEBUG_OBJECT (object, "controlled property %s removed", binding->name);
1258     object->control_bindings =
1259         g_list_delete_link (object->control_bindings, node);
1260     gst_object_unparent (GST_OBJECT_CAST (binding));
1261     ret = TRUE;
1262   }
1263   GST_OBJECT_UNLOCK (object);
1264
1265   return ret;
1266 }
1267
1268 /**
1269  * gst_object_get_value:
1270  * @object: the object that has controlled properties
1271  * @property_name: the name of the property to get
1272  * @timestamp: the time the control-change should be read from
1273  *
1274  * Gets the value for the given controlled property at the requested time.
1275  *
1276  * Returns: the GValue of the property at the given time, or %NULL if the
1277  * property isn't controlled.
1278  */
1279 GValue *
1280 gst_object_get_value (GstObject * object, const gchar * property_name,
1281     GstClockTime timestamp)
1282 {
1283   GstControlBinding *binding;
1284   GValue *val = NULL;
1285
1286   g_return_val_if_fail (GST_IS_OBJECT (object), NULL);
1287   g_return_val_if_fail (property_name, NULL);
1288   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), NULL);
1289
1290   GST_OBJECT_LOCK (object);
1291   if ((binding = gst_object_find_control_binding (object, property_name))) {
1292     val = gst_control_binding_get_value (binding, timestamp);
1293   }
1294   GST_OBJECT_UNLOCK (object);
1295
1296   return val;
1297 }
1298
1299 /**
1300  * gst_object_get_value_array:
1301  * @object: the object that has controlled properties
1302  * @property_name: the name of the property to get
1303  * @timestamp: the time that should be processed
1304  * @interval: the time spacing between subsequent values
1305  * @n_values: the number of values
1306  * @values: array to put control-values in
1307  *
1308  * Gets a number of values for the given controlled property starting at the
1309  * requested time. The array @values need to hold enough space for @n_values of
1310  * the same type as the objects property's type.
1311  *
1312  * This function is useful if one wants to e.g. draw a graph of the control
1313  * curve or apply a control curve sample by sample.
1314  *
1315  * The values are unboxed and ready to be used. The similar function 
1316  * gst_object_get_g_value_array() returns the array as #GValues and is
1317  * better suites for bindings.
1318  *
1319  * Returns: %TRUE if the given array could be filled, %FALSE otherwise
1320  */
1321 gboolean
1322 gst_object_get_value_array (GstObject * object, const gchar * property_name,
1323     GstClockTime timestamp, GstClockTime interval, guint n_values,
1324     gpointer values)
1325 {
1326   gboolean res = FALSE;
1327   GstControlBinding *binding;
1328
1329   g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
1330   g_return_val_if_fail (property_name, FALSE);
1331   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
1332   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (interval), FALSE);
1333   g_return_val_if_fail (values, FALSE);
1334
1335   GST_OBJECT_LOCK (object);
1336   if ((binding = gst_object_find_control_binding (object, property_name))) {
1337     res = gst_control_binding_get_value_array (binding, timestamp, interval,
1338         n_values, values);
1339   }
1340   GST_OBJECT_UNLOCK (object);
1341   return res;
1342 }
1343
1344 /**
1345  * gst_object_get_g_value_array:
1346  * @object: the object that has controlled properties
1347  * @property_name: the name of the property to get
1348  * @timestamp: the time that should be processed
1349  * @interval: the time spacing between subsequent values
1350  * @n_values: the number of values
1351  * @values: array to put control-values in
1352  *
1353  * Gets a number of #GValues for the given controlled property starting at the
1354  * requested time. The array @values need to hold enough space for @n_values of
1355  * #GValue.
1356  *
1357  * This function is useful if one wants to e.g. draw a graph of the control
1358  * curve or apply a control curve sample by sample.
1359  *
1360  * Returns: %TRUE if the given array could be filled, %FALSE otherwise
1361  */
1362 gboolean
1363 gst_object_get_g_value_array (GstObject * object, const gchar * property_name,
1364     GstClockTime timestamp, GstClockTime interval, guint n_values,
1365     GValue * values)
1366 {
1367   gboolean res = FALSE;
1368   GstControlBinding *binding;
1369
1370   g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
1371   g_return_val_if_fail (property_name, FALSE);
1372   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
1373   g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (interval), FALSE);
1374   g_return_val_if_fail (values, FALSE);
1375
1376   GST_OBJECT_LOCK (object);
1377   if ((binding = gst_object_find_control_binding (object, property_name))) {
1378     res = gst_control_binding_get_g_value_array (binding, timestamp, interval,
1379         n_values, values);
1380   }
1381   GST_OBJECT_UNLOCK (object);
1382   return res;
1383 }
1384
1385
1386 /**
1387  * gst_object_get_control_rate:
1388  * @object: the object that has controlled properties
1389  *
1390  * Obtain the control-rate for this @object. Audio processing #GstElement
1391  * objects will use this rate to sub-divide their processing loop and call
1392  * gst_object_sync_values() inbetween. The length of the processing segment
1393  * should be up to @control-rate nanoseconds.
1394  *
1395  * If the @object is not under property control, this will return
1396  * %GST_CLOCK_TIME_NONE. This allows the element to avoid the sub-dividing.
1397  *
1398  * The control-rate is not expected to change if the element is in
1399  * %GST_STATE_PAUSED or %GST_STATE_PLAYING.
1400  *
1401  * Returns: the control rate in nanoseconds
1402  */
1403 GstClockTime
1404 gst_object_get_control_rate (GstObject * object)
1405 {
1406   g_return_val_if_fail (GST_IS_OBJECT (object), FALSE);
1407
1408   return object->control_rate;
1409 }
1410
1411 /**
1412  * gst_object_set_control_rate:
1413  * @object: the object that has controlled properties
1414  * @control_rate: the new control-rate in nanoseconds.
1415  *
1416  * Change the control-rate for this @object. Audio processing #GstElement
1417  * objects will use this rate to sub-divide their processing loop and call
1418  * gst_object_sync_values() inbetween. The length of the processing segment
1419  * should be up to @control-rate nanoseconds.
1420  *
1421  * The control-rate should not change if the element is in %GST_STATE_PAUSED or
1422  * %GST_STATE_PLAYING.
1423  */
1424 void
1425 gst_object_set_control_rate (GstObject * object, GstClockTime control_rate)
1426 {
1427   g_return_if_fail (GST_IS_OBJECT (object));
1428
1429   object->control_rate = control_rate;
1430 }