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