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