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