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