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