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