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