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