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