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