3 * Copyright (C) <2005> Stefan Kost <ensonic at users dot sf dot net>
4 * Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org>
6 * gstcontroller.c: dynamic parameter control subsystem
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.
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.
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., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * SECTION:gstcontroller
26 * @short_description: dynamic parameter control subsystem
28 * The controller subsystem offers a lightweight way to adjust gobject
29 * properties over stream-time. It works by using time-stamped value pairs that
30 * are queued for element-properties. At run-time the elements continously pull
31 * values changes for the current stream-time.
33 * What needs to be changed in a #GstElement?
34 * Very little - it is just two steps to make a plugin controllable!
37 * mark gobject-properties paramspecs that make sense to be controlled,
38 * by GST_PARAM_CONTROLLABLE.
41 * when processing data (get, chain, loop function) at the beginning call
42 * gst_object_sync_values(element,timestamp).
43 * This will made the controller to update all gobject properties that are under
44 * control with the current values based on timestamp.
48 * What needs to be done in applications?
49 * Again its not a lot to change.
52 * first put some properties under control, by calling
53 * controller = gst_object_control_properties (object, "prop1", "prop2",...);
56 * Get a #GstControlSource for the property and set it up.
57 * csource = gst_interpolation_control_source_new ();
58 * gst_interpolation_control_source_set_interpolation_mode(csource, mode);
59 * gst_interpolation_control_source_set (csource,0 * GST_SECOND, value1);
60 * gst_interpolation_control_source_set (csource,1 * GST_SECOND, value2);
63 * Set the #GstControlSource in the controller.
64 * gst_controller_set_control_source (controller, "prop1", csource);
76 #include "gstcontroller.h"
77 #include "gstcontrollerprivate.h"
78 #include "gstcontrolsource.h"
79 #include "gstinterpolationcontrolsource.h"
81 #define GST_CAT_DEFAULT controller_debug
82 GST_DEBUG_CATEGORY_EXTERN (GST_CAT_DEFAULT);
84 static GObjectClass *parent_class = NULL;
85 GQuark priv_gst_controller_key;
93 struct _GstControllerPrivate
95 GstClockTime control_rate;
96 GstClockTime last_sync;
100 #ifndef GST_REMOVE_DEPRECATED
102 gst_controlled_property_add_interpolation_control_source (GstControlledProperty
105 GstControlSource *csource =
106 GST_CONTROL_SOURCE (gst_interpolation_control_source_new ());
109 ("Adding a GstInterpolationControlSource because of backward compatibility");
110 g_return_if_fail (!self->csource);
111 gst_control_source_bind (GST_CONTROL_SOURCE (csource), self->pspec);
112 self->csource = csource;
117 * gst_controlled_property_new:
118 * @object: for which object the controlled property should be set up
119 * @name: the name of the property to be controlled
121 * Private method which initializes the fields of a new controlled property
124 * Returns: a freshly allocated structure or %NULL
126 static GstControlledProperty *
127 gst_controlled_property_new (GObject * object, const gchar * name)
129 GstControlledProperty *prop = NULL;
132 GST_INFO ("trying to put property '%s' under control", name);
134 /* check if the object has a property of that name */
136 g_object_class_find_property (G_OBJECT_GET_CLASS (object), name))) {
137 GST_DEBUG (" psec->flags : 0x%08x", pspec->flags);
139 /* check if this param is witable && controlable && !construct-only */
140 g_return_val_if_fail ((pspec->flags & (G_PARAM_WRITABLE |
141 GST_PARAM_CONTROLLABLE | G_PARAM_CONSTRUCT_ONLY)) ==
142 (G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE), NULL);
144 if ((prop = g_slice_new (GstControlledProperty))) {
146 prop->name = pspec->name;
147 prop->csource = NULL;
148 prop->disabled = FALSE;
149 memset (&prop->last_value, 0, sizeof (GValue));
150 g_value_init (&prop->last_value, G_PARAM_SPEC_VALUE_TYPE (prop->pspec));
153 GST_WARNING ("class '%s' has no property '%s'", G_OBJECT_TYPE_NAME (object),
160 * gst_controlled_property_free:
161 * @prop: the object to free
163 * Private method which frees all data allocated by a #GstControlledProperty
167 gst_controlled_property_free (GstControlledProperty * prop)
170 g_object_unref (prop->csource);
171 g_value_unset (&prop->last_value);
172 g_slice_free (GstControlledProperty, prop);
176 * gst_controller_find_controlled_property:
177 * @self: the controller object to search for a property in
178 * @name: the gobject property name to look for
180 * Searches the list of properties under control.
182 * Returns: a #GstControlledProperty object of %NULL if the property is not
185 static GstControlledProperty *
186 gst_controller_find_controlled_property (GstController * self,
189 GstControlledProperty *prop;
192 for (node = self->properties; node; node = g_list_next (node)) {
194 /* FIXME: eventually use GQuark to speed it up */
195 if (!strcmp (prop->name, name)) {
199 GST_DEBUG ("controller does not (yet) manage property '%s'", name);
205 * gst_controller_add_property:
206 * @self: the controller object or %NULL if none yet exists
207 * @object: object to bind the property
208 * @name: name of projecty in @object
209 * @ref_existing: pointer to flag that tracks if we need to ref an existing
212 * Creates a new #GstControlledProperty if there is none for property @name yet.
213 * In case this is the first controlled propery, it creates the controller as
216 * Returns: a newly created controller object or reffed existing one with the
217 * given property bound.
219 static GstController *
220 gst_controller_add_property (GstController * self, GObject * object,
221 const gchar * name, gboolean * ref_existing)
223 /* test if this property isn't yet controlled */
224 if (!self || !gst_controller_find_controlled_property (self, name)) {
225 GstControlledProperty *prop;
227 /* create GstControlledProperty and add to self->propeties List */
228 if ((prop = gst_controlled_property_new (object, name))) {
229 /* if we don't have a controller object yet, now is the time to create one */
231 self = g_object_newv (GST_TYPE_CONTROLLER, 0, NULL);
232 self->object = g_object_ref (object);
233 /* store the controller */
234 g_object_set_qdata (object, priv_gst_controller_key, self);
235 *ref_existing = FALSE;
237 /* only want one single _ref(), even for multiple properties */
240 *ref_existing = FALSE;
241 GST_INFO ("returning existing controller");
244 self->properties = g_list_prepend (self->properties, prop);
247 GST_WARNING ("trying to control property %s again", name);
250 *ref_existing = FALSE;
259 * gst_controller_new_valist:
260 * @object: the object of which some properties should be controlled
261 * @var_args: %NULL terminated list of property names that should be controlled
263 * Creates a new GstController for the given object's properties
265 * Returns: the new controller.
268 gst_controller_new_valist (GObject * object, va_list var_args)
271 gboolean ref_existing = TRUE;
274 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
276 GST_INFO ("setting up a new controller");
278 self = g_object_get_qdata (object, priv_gst_controller_key);
279 /* create GstControlledProperty for each property */
280 while ((name = va_arg (var_args, gchar *))) {
281 self = gst_controller_add_property (self, object, name, &ref_existing);
286 GST_INFO ("controller->ref_count=%d", G_OBJECT (self)->ref_count);
291 * gst_controller_new_list:
292 * @object: the object of which some properties should be controlled
293 * @list: list of property names that should be controlled
295 * Creates a new GstController for the given object's properties
297 * Returns: the new controller.
300 gst_controller_new_list (GObject * object, GList * list)
303 gboolean ref_existing = TRUE;
307 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
309 GST_INFO ("setting up a new controller");
311 self = g_object_get_qdata (object, priv_gst_controller_key);
312 /* create GstControlledProperty for each property */
313 for (node = list; node; node = g_list_next (node)) {
314 name = (gchar *) node->data;
315 self = gst_controller_add_property (self, object, name, &ref_existing);
319 GST_INFO ("controller->ref_count=%d", G_OBJECT (self)->ref_count);
324 * gst_controller_new:
325 * @object: the object of which some properties should be controlled
326 * @...: %NULL terminated list of property names that should be controlled
328 * Creates a new GstController for the given object's properties
330 * Returns: the new controller.
333 gst_controller_new (GObject * object, ...)
338 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
340 va_start (var_args, object);
341 self = gst_controller_new_valist (object, var_args);
348 * gst_controller_remove_properties_valist:
349 * @self: the controller object from which some properties should be removed
350 * @var_args: %NULL terminated list of property names that should be removed
352 * Removes the given object properties from the controller
354 * Returns: %FALSE if one of the given property isn't handled by the controller, %TRUE otherwise
357 gst_controller_remove_properties_valist (GstController * self, va_list var_args)
360 GstControlledProperty *prop;
363 g_return_val_if_fail (GST_IS_CONTROLLER (self), FALSE);
365 while ((name = va_arg (var_args, gchar *))) {
366 /* find the property in the properties list of the controller, remove and free it */
367 g_mutex_lock (self->lock);
368 if ((prop = gst_controller_find_controlled_property (self, name))) {
369 self->properties = g_list_remove (self->properties, prop);
370 //g_signal_handler_disconnect (self->object, prop->notify_handler_id);
371 gst_controlled_property_free (prop);
375 g_mutex_unlock (self->lock);
382 * gst_controller_remove_properties_list:
383 * @self: the controller object from which some properties should be removed
384 * @list: #GList of property names that should be removed
386 * Removes the given object properties from the controller
388 * Returns: %FALSE if one of the given property isn't handled by the controller, %TRUE otherwise
391 gst_controller_remove_properties_list (GstController * self, GList * list)
394 GstControlledProperty *prop;
398 g_return_val_if_fail (GST_IS_CONTROLLER (self), FALSE);
400 for (tmp = list; tmp; tmp = g_list_next (tmp)) {
401 name = (gchar *) tmp->data;
403 /* find the property in the properties list of the controller, remove and free it */
404 g_mutex_lock (self->lock);
405 if ((prop = gst_controller_find_controlled_property (self, name))) {
406 self->properties = g_list_remove (self->properties, prop);
407 //g_signal_handler_disconnect (self->object, prop->notify_handler_id);
408 gst_controlled_property_free (prop);
412 g_mutex_unlock (self->lock);
419 * gst_controller_remove_properties:
420 * @self: the controller object from which some properties should be removed
421 * @...: %NULL terminated list of property names that should be removed
423 * Removes the given object properties from the controller
425 * Returns: %FALSE if one of the given property isn't handled by the controller, %TRUE otherwise
428 gst_controller_remove_properties (GstController * self, ...)
433 g_return_val_if_fail (GST_IS_CONTROLLER (self), FALSE);
435 va_start (var_args, self);
436 res = gst_controller_remove_properties_valist (self, var_args);
443 * gst_controller_set_property_disabled:
444 * @self: the #GstController which should be disabled
445 * @property_name: property to disable
446 * @disabled: boolean that specifies whether to disable the controller
449 * This function is used to disable the #GstController on a property for
450 * some time, i.e. gst_controller_sync_values() will do nothing for the
457 gst_controller_set_property_disabled (GstController * self,
458 const gchar * property_name, gboolean disabled)
460 GstControlledProperty *prop;
462 g_return_if_fail (GST_IS_CONTROLLER (self));
463 g_return_if_fail (property_name);
465 g_mutex_lock (self->lock);
466 if ((prop = gst_controller_find_controlled_property (self, property_name))) {
467 prop->disabled = disabled;
469 g_mutex_unlock (self->lock);
474 * gst_controller_set_disabled:
475 * @self: the #GstController which should be disabled
476 * @disabled: boolean that specifies whether to disable the controller
479 * This function is used to disable all properties of the #GstController
480 * for some time, i.e. gst_controller_sync_values() will do nothing.
486 gst_controller_set_disabled (GstController * self, gboolean disabled)
489 GstControlledProperty *prop;
491 g_return_if_fail (GST_IS_CONTROLLER (self));
493 g_mutex_lock (self->lock);
494 for (node = self->properties; node; node = node->next) {
496 prop->disabled = disabled;
498 g_mutex_unlock (self->lock);
502 * gst_controller_set_control_source:
503 * @self: the controller object
504 * @property_name: name of the property for which the #GstControlSource should be set
505 * @csource: the #GstControlSource that should be used for the property
507 * Sets the #GstControlSource for @property_name. If there already was a #GstControlSource
508 * for this property it will be unreferenced.
510 * Returns: %FALSE if the given property isn't handled by the controller or the new #GstControlSource
511 * couldn't be bound to the property, %TRUE if everything worked as expected.
516 gst_controller_set_control_source (GstController * self,
517 const gchar * property_name, GstControlSource * csource)
519 GstControlledProperty *prop;
520 gboolean ret = FALSE;
522 g_mutex_lock (self->lock);
523 if ((prop = gst_controller_find_controlled_property (self, property_name))) {
524 GstControlSource *old = prop->csource;
526 if (csource && (ret = gst_control_source_bind (csource, prop->pspec))) {
527 g_object_ref (csource);
528 prop->csource = csource;
529 } else if (!csource) {
531 prop->csource = NULL;
535 g_object_unref (old);
537 g_mutex_unlock (self->lock);
543 * gst_controller_get_control_source:
544 * @self: the controller object
545 * @property_name: name of the property for which the #GstControlSource should be get
547 * Gets the corresponding #GstControlSource for the property. This should be unreferenced
550 * Returns: the #GstControlSource for @property_name or NULL if the property is not
551 * controlled by this controller or no #GstControlSource was assigned yet.
556 gst_controller_get_control_source (GstController * self,
557 const gchar * property_name)
559 GstControlledProperty *prop;
560 GstControlSource *ret = NULL;
562 g_return_val_if_fail (GST_IS_CONTROLLER (self), NULL);
563 g_return_val_if_fail (property_name, NULL);
565 g_mutex_lock (self->lock);
566 if ((prop = gst_controller_find_controlled_property (self, property_name))) {
569 g_mutex_unlock (self->lock);
578 * gst_controller_get:
579 * @self: the controller object which handles the properties
580 * @property_name: the name of the property to get
581 * @timestamp: the time the control-change should be read from
583 * Gets the value for the given controller-handled property at the requested
586 * Returns: the GValue of the property at the given time, or %NULL if the
587 * property isn't handled by the controller
590 gst_controller_get (GstController * self, const gchar * property_name,
591 GstClockTime timestamp)
593 GstControlledProperty *prop;
596 g_return_val_if_fail (GST_IS_CONTROLLER (self), NULL);
597 g_return_val_if_fail (property_name, NULL);
598 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), NULL);
600 g_mutex_lock (self->lock);
601 if ((prop = gst_controller_find_controlled_property (self, property_name))) {
602 val = g_new0 (GValue, 1);
603 g_value_init (val, G_PARAM_SPEC_VALUE_TYPE (prop->pspec));
607 /* get current value via control source */
608 res = gst_control_source_get_value (prop->csource, timestamp, val);
614 g_object_get_property (self->object, prop->name, val);
617 g_mutex_unlock (self->lock);
623 * gst_controller_suggest_next_sync:
624 * @self: the controller that handles the values
626 * Returns a suggestion for timestamps where buffers should be split
627 * to get best controller results.
629 * Returns: Returns the suggested timestamp or %GST_CLOCK_TIME_NONE
630 * if no control-rate was set.
635 gst_controller_suggest_next_sync (GstController * self)
639 g_return_val_if_fail (GST_IS_CONTROLLER (self), GST_CLOCK_TIME_NONE);
640 g_return_val_if_fail (self->priv->control_rate != GST_CLOCK_TIME_NONE,
641 GST_CLOCK_TIME_NONE);
643 g_mutex_lock (self->lock);
645 /* TODO: Implement more logic, depending on interpolation mode
647 * FIXME: we need playback direction
649 ret = self->priv->last_sync + self->priv->control_rate;
651 g_mutex_unlock (self->lock);
657 * gst_controller_sync_values:
658 * @self: the controller that handles the values
659 * @timestamp: the time that should be processed
661 * Sets the properties of the element, according to the controller that (maybe)
662 * handles them and for the given timestamp.
664 * If this function fails, it is most likely the application developers fault.
665 * Most probably the control sources are not setup correctly.
667 * Returns: %TRUE if the controller values could be applied to the object
668 * properties, %FALSE otherwise
671 gst_controller_sync_values (GstController * self, GstClockTime timestamp)
673 GstControlledProperty *prop;
675 gboolean ret = TRUE, val_ret;
676 GValue value = { 0, };
678 g_return_val_if_fail (GST_IS_CONTROLLER (self), FALSE);
679 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
681 GST_LOG ("sync_values");
683 g_mutex_lock (self->lock);
684 g_object_freeze_notify (self->object);
685 /* go over the controlled properties of the controller */
686 for (node = self->properties; node; node = g_list_next (node)) {
689 if (!prop->csource || prop->disabled)
692 GST_LOG ("property '%s' at ts=%" G_GUINT64_FORMAT, prop->name, timestamp);
694 /* we can make this faster
695 * http://bugzilla.gnome.org/show_bug.cgi?id=536939
697 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (prop->pspec));
698 val_ret = gst_control_source_get_value (prop->csource, timestamp, &value);
699 if (G_LIKELY (val_ret)) {
700 /* always set the value for first time, but then only if it changed
701 * this should limit g_object_notify invocations.
702 * FIXME: can we detect negative playback rates?
704 if ((timestamp < self->priv->last_sync) ||
705 gst_value_compare (&value, &prop->last_value) != GST_VALUE_EQUAL) {
706 g_object_set_property (self->object, prop->name, &value);
707 g_value_copy (&value, &prop->last_value);
710 GST_DEBUG ("no control value for param %s", prop->name);
712 g_value_unset (&value);
715 self->priv->last_sync = timestamp;
716 g_object_thaw_notify (self->object);
718 g_mutex_unlock (self->lock);
724 * gst_controller_get_value_arrays:
725 * @self: the controller that handles the values
726 * @timestamp: the time that should be processed
727 * @value_arrays: list to return the control-values in
729 * Function to be able to get an array of values for one or more given element
732 * All fields of the %GstValueArray in the list must be filled correctly.
733 * Especially the GstValueArray->values arrays must be big enough to keep
734 * the requested amount of values.
736 * The types of the values in the array are the same as the property's type.
738 * <note><para>This doesn't modify the controlled GObject properties!</para></note>
740 * Returns: %TRUE if the given array(s) could be filled, %FALSE otherwise
743 gst_controller_get_value_arrays (GstController * self,
744 GstClockTime timestamp, GSList * value_arrays)
749 g_return_val_if_fail (GST_IS_CONTROLLER (self), FALSE);
750 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
751 g_return_val_if_fail (value_arrays, FALSE);
753 for (node = value_arrays; (res && node); node = g_slist_next (node)) {
754 res = gst_controller_get_value_array (self, timestamp, node->data);
761 * gst_controller_get_value_array:
762 * @self: the controller that handles the values
763 * @timestamp: the time that should be processed
764 * @value_array: array to put control-values in
766 * Function to be able to get an array of values for one element property.
768 * All fields of @value_array must be filled correctly. Especially the
769 * @value_array->values array must be big enough to keep the requested amount
770 * of values (as indicated by the nbsamples field).
772 * The type of the values in the array is the same as the property's type.
774 * <note><para>This doesn't modify the controlled GObject property!</para></note>
776 * Returns: %TRUE if the given array could be filled, %FALSE otherwise
779 gst_controller_get_value_array (GstController * self, GstClockTime timestamp,
780 GstValueArray * value_array)
782 gboolean res = FALSE;
783 GstControlledProperty *prop;
785 g_return_val_if_fail (GST_IS_CONTROLLER (self), FALSE);
786 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
787 g_return_val_if_fail (value_array, FALSE);
788 g_return_val_if_fail (value_array->property_name, FALSE);
789 g_return_val_if_fail (value_array->values, FALSE);
791 g_mutex_lock (self->lock);
794 gst_controller_find_controlled_property (self,
795 value_array->property_name))) {
796 /* get current value_array via control source */
802 gst_control_source_get_value_array (prop->csource, timestamp,
807 g_mutex_unlock (self->lock);
811 /* gobject handling */
814 _gst_controller_get_property (GObject * object, guint property_id,
815 GValue * value, GParamSpec * pspec)
817 GstController *self = GST_CONTROLLER (object);
819 switch (property_id) {
820 case PROP_CONTROL_RATE:{
821 /* FIXME: don't change if element is playing, controller works for GObject
824 GstState c_state, p_state;
825 GstStateChangeReturn ret;
827 ret = gst_element_get_state (self->object, &c_state, &p_state, 0);
828 if ((ret == GST_STATE_CHANGE_SUCCESS &&
829 (c_state == GST_STATE_NULL || c_state == GST_STATE_READY)) ||
830 (ret == GST_STATE_CHANGE_ASYNC &&
831 (p_state == GST_STATE_NULL || p_state == GST_STATE_READY))) {
833 g_value_set_uint64 (value, self->priv->control_rate);
837 GST_WARNING ("Changing the control rate is only allowed if the elemnt"
838 " is in NULL or READY");
844 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
850 /* sets the given properties for this object */
852 _gst_controller_set_property (GObject * object, guint property_id,
853 const GValue * value, GParamSpec * pspec)
855 GstController *self = GST_CONTROLLER (object);
857 switch (property_id) {
858 case PROP_CONTROL_RATE:{
859 self->priv->control_rate = g_value_get_uint64 (value);
863 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
870 _gst_controller_dispose (GObject * object)
872 GstController *self = GST_CONTROLLER (object);
874 if (self->object != NULL) {
875 g_mutex_lock (self->lock);
876 /* free list of properties */
877 if (self->properties) {
880 for (node = self->properties; node; node = g_list_next (node)) {
881 GstControlledProperty *prop = node->data;
883 gst_controlled_property_free (prop);
885 g_list_free (self->properties);
886 self->properties = NULL;
889 /* remove controller from object's qdata list */
890 g_object_set_qdata (self->object, priv_gst_controller_key, NULL);
891 g_object_unref (self->object);
893 g_mutex_unlock (self->lock);
896 if (G_OBJECT_CLASS (parent_class)->dispose)
897 (G_OBJECT_CLASS (parent_class)->dispose) (object);
901 _gst_controller_finalize (GObject * object)
903 GstController *self = GST_CONTROLLER (object);
905 g_mutex_free (self->lock);
907 if (G_OBJECT_CLASS (parent_class)->finalize)
908 (G_OBJECT_CLASS (parent_class)->finalize) (object);
912 _gst_controller_init (GTypeInstance * instance, gpointer g_class)
914 GstController *self = GST_CONTROLLER (instance);
916 self->lock = g_mutex_new ();
918 G_TYPE_INSTANCE_GET_PRIVATE (self, GST_TYPE_CONTROLLER,
919 GstControllerPrivate);
920 self->priv->last_sync = GST_CLOCK_TIME_NONE;
921 self->priv->control_rate = 100 * GST_MSECOND;
925 _gst_controller_class_init (GstControllerClass * klass)
927 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
929 parent_class = g_type_class_peek_parent (klass);
930 g_type_class_add_private (klass, sizeof (GstControllerPrivate));
932 gobject_class->set_property = _gst_controller_set_property;
933 gobject_class->get_property = _gst_controller_get_property;
934 gobject_class->dispose = _gst_controller_dispose;
935 gobject_class->finalize = _gst_controller_finalize;
937 priv_gst_controller_key = g_quark_from_static_string ("gst::controller");
939 /* register properties */
940 g_object_class_install_property (gobject_class, PROP_CONTROL_RATE,
941 g_param_spec_uint64 ("control-rate",
943 "Controlled properties will be updated at least every control-rate nanoseconds",
944 1, G_MAXUINT, 100 * GST_MSECOND,
945 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
947 /* register signals */
948 /* set defaults for overridable methods */
952 gst_controller_get_type (void)
954 static volatile gsize type = 0;
956 if (g_once_init_enter (&type)) {
958 static const GTypeInfo info = {
959 sizeof (GstControllerClass),
960 NULL, /* base_init */
961 NULL, /* base_finalize */
962 (GClassInitFunc) _gst_controller_class_init, /* class_init */
963 NULL, /* class_finalize */
964 NULL, /* class_data */
965 sizeof (GstController),
967 (GInstanceInitFunc) _gst_controller_init, /* instance_init */
968 NULL /* value_table */
970 _type = g_type_register_static (G_TYPE_OBJECT, "GstController", &info, 0);
971 g_once_init_leave (&type, _type);
976 /* FIXME: backward compatibility functions */
979 * gst_controlled_property_set_interpolation_mode:
980 * @self: the controlled property object to change
981 * @mode: the new interpolation mode
983 * Sets the given Interpolation mode for the controlled property and activates
984 * the respective interpolation hooks.
986 * Deprecated: Use #GstControlSource, for example #GstInterpolationControlSource
989 * Returns: %TRUE for success
991 #ifndef GST_REMOVE_DEPRECATED
993 gst_controlled_property_set_interpolation_mode (GstControlledProperty * self,
994 GstInterpolateMode mode)
996 GstInterpolationControlSource *icsource;
998 /* FIXME: backward compat, add GstInterpolationControlSource */
1000 gst_controlled_property_add_interpolation_control_source (self);
1002 g_return_val_if_fail (GST_IS_INTERPOLATION_CONTROL_SOURCE (self->csource),
1005 icsource = GST_INTERPOLATION_CONTROL_SOURCE (self->csource);
1007 return gst_interpolation_control_source_set_interpolation_mode (icsource,
1013 * gst_controller_set:
1014 * @self: the controller object which handles the properties
1015 * @property_name: the name of the property to set
1016 * @timestamp: the time the control-change is schedules for
1017 * @value: the control-value
1019 * Set the value of given controller-handled property at a certain time.
1021 * Deprecated: Use #GstControlSource, for example #GstInterpolationControlSource
1024 * Returns: FALSE if the values couldn't be set (ex : properties not handled by controller), TRUE otherwise
1026 #ifndef GST_REMOVE_DEPRECATED
1027 #ifdef GST_DISABLE_DEPRECATED
1029 gst_controller_set (GstController * self, const gchar * property_name,
1030 GstClockTime timestamp, GValue * value);
1033 gst_controller_set (GstController * self, const gchar * property_name,
1034 GstClockTime timestamp, GValue * value)
1036 gboolean res = FALSE;
1037 GstControlledProperty *prop;
1039 g_return_val_if_fail (GST_IS_CONTROLLER (self), FALSE);
1040 g_return_val_if_fail (property_name, FALSE);
1042 g_mutex_lock (self->lock);
1043 if ((prop = gst_controller_find_controlled_property (self, property_name))) {
1044 /* FIXME: backward compat, add GstInterpolationControlSource */
1046 gst_controlled_property_add_interpolation_control_source (prop);
1048 if (!GST_IS_INTERPOLATION_CONTROL_SOURCE (prop->csource))
1051 gst_interpolation_control_source_set (GST_INTERPOLATION_CONTROL_SOURCE
1052 (prop->csource), timestamp, value);
1056 g_mutex_unlock (self->lock);
1063 * gst_controller_set_from_list:
1064 * @self: the controller object which handles the properties
1065 * @property_name: the name of the property to set
1066 * @timedvalues: a list with #GstTimedValue items
1068 * Sets multiple timed values at once.
1070 * Deprecated: Use #GstControlSource, for example #GstInterpolationControlSource
1073 * Returns: %FALSE if the values couldn't be set (ex : properties not handled by controller), %TRUE otherwise
1075 #ifndef GST_REMOVE_DEPRECATED
1076 #ifdef GST_DISABLE_DEPRECATED
1078 gst_controller_set_from_list (GstController * self, const gchar * property_name,
1079 GSList * timedvalues);
1082 gst_controller_set_from_list (GstController * self, const gchar * property_name,
1083 GSList * timedvalues)
1085 gboolean res = FALSE;
1086 GstControlledProperty *prop;
1088 g_return_val_if_fail (GST_IS_CONTROLLER (self), FALSE);
1089 g_return_val_if_fail (property_name, FALSE);
1091 g_mutex_lock (self->lock);
1092 if ((prop = gst_controller_find_controlled_property (self, property_name))) {
1093 /* FIXME: backward compat, add GstInterpolationControlSource */
1095 gst_controlled_property_add_interpolation_control_source (prop);
1097 if (!GST_IS_INTERPOLATION_CONTROL_SOURCE (prop->csource))
1101 gst_interpolation_control_source_set_from_list
1102 (GST_INTERPOLATION_CONTROL_SOURCE (prop->csource), timedvalues);
1106 g_mutex_unlock (self->lock);
1113 * gst_controller_unset:
1114 * @self: the controller object which handles the properties
1115 * @property_name: the name of the property to unset
1116 * @timestamp: the time the control-change should be removed from
1118 * Used to remove the value of given controller-handled property at a certain
1121 * Deprecated: Use #GstControlSource, for example #GstInterpolationControlSource
1124 * Returns: %FALSE if the values couldn't be unset (ex : properties not handled by controller), %TRUE otherwise
1126 #ifndef GST_REMOVE_DEPRECATED
1127 #ifdef GST_DISABLE_DEPRECATED
1129 gst_controller_unset (GstController * self, const gchar * property_name,
1130 GstClockTime timestamp);
1133 gst_controller_unset (GstController * self, const gchar * property_name,
1134 GstClockTime timestamp)
1136 gboolean res = FALSE;
1137 GstControlledProperty *prop;
1139 g_return_val_if_fail (GST_IS_CONTROLLER (self), FALSE);
1140 g_return_val_if_fail (property_name, FALSE);
1141 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
1143 g_mutex_lock (self->lock);
1144 if ((prop = gst_controller_find_controlled_property (self, property_name))) {
1145 if (!prop->csource || !GST_IS_INTERPOLATION_CONTROL_SOURCE (prop->csource))
1149 gst_interpolation_control_source_unset (GST_INTERPOLATION_CONTROL_SOURCE
1150 (prop->csource), timestamp);
1154 g_mutex_unlock (self->lock);
1161 * gst_controller_unset_all:
1162 * @self: the controller object which handles the properties
1163 * @property_name: the name of the property to unset
1165 * Used to remove all time-stamped values of given controller-handled property
1167 * Deprecated: Use #GstControlSource, for example #GstInterpolationControlSource
1170 * Returns: %FALSE if the values couldn't be unset (ex : properties not handled
1171 * by controller), %TRUE otherwise
1174 #ifndef GST_REMOVE_DEPRECATED
1175 #ifdef GST_DISABLE_DEPRECATED
1176 gboolean gst_controller_unset_all (GstController * self,
1177 const gchar * property_name);
1180 gst_controller_unset_all (GstController * self, const gchar * property_name)
1182 GstControlledProperty *prop;
1184 g_return_val_if_fail (GST_IS_CONTROLLER (self), FALSE);
1185 g_return_val_if_fail (property_name, FALSE);
1187 g_mutex_lock (self->lock);
1188 if ((prop = gst_controller_find_controlled_property (self, property_name))) {
1189 if (!prop->csource || !GST_IS_INTERPOLATION_CONTROL_SOURCE (prop->csource))
1192 gst_interpolation_control_source_unset_all (GST_INTERPOLATION_CONTROL_SOURCE
1197 g_mutex_unlock (self->lock);
1204 * gst_controller_get_all:
1205 * @self: the controller to get the list from
1206 * @property_name: the name of the property to get the list for
1208 * Returns a read-only copy of the list of #GstTimedValue for the given property.
1209 * Free the list after done with it.
1211 * <note><para>This doesn't modify the controlled GObject property!</para></note>
1213 * Deprecated: Use #GstControlSource, for example #GstInterpolationControlSource
1216 * Returns: a copy of the list, or %NULL if the property isn't handled by the controller
1218 #ifndef GST_REMOVE_DEPRECATED
1219 #ifdef GST_DISABLE_DEPRECATED
1220 const GList *gst_controller_get_all (GstController * self,
1221 const gchar * property_name);
1224 gst_controller_get_all (GstController * self, const gchar * property_name)
1226 const GList *res = NULL;
1227 GstControlledProperty *prop;
1229 g_return_val_if_fail (GST_IS_CONTROLLER (self), NULL);
1230 g_return_val_if_fail (property_name, NULL);
1232 g_mutex_lock (self->lock);
1233 if ((prop = gst_controller_find_controlled_property (self, property_name))) {
1234 if (!prop->csource || !GST_IS_INTERPOLATION_CONTROL_SOURCE (prop->csource))
1238 gst_interpolation_control_source_get_all
1239 (GST_INTERPOLATION_CONTROL_SOURCE (prop->csource));
1243 g_mutex_unlock (self->lock);
1250 * gst_controller_set_interpolation_mode:
1251 * @self: the controller object
1252 * @property_name: the name of the property for which to change the interpolation
1253 * @mode: interpolation mode
1255 * Sets the given interpolation mode on the given property.
1257 * <note><para>User interpolation is not yet available and quadratic interpolation
1258 * is deprecated and maps to cubic interpolation.</para></note>
1260 * Deprecated: Use #GstControlSource, for example #GstInterpolationControlSource
1263 * Returns: %TRUE if the property is handled by the controller, %FALSE otherwise
1265 #ifndef GST_REMOVE_DEPRECATED
1266 #ifdef GST_DISABLE_DEPRECATED
1268 gst_controller_set_interpolation_mode (GstController * self,
1269 const gchar * property_name, GstInterpolateMode mode);
1272 gst_controller_set_interpolation_mode (GstController * self,
1273 const gchar * property_name, GstInterpolateMode mode)
1275 gboolean res = FALSE;
1276 GstControlledProperty *prop;
1278 g_return_val_if_fail (GST_IS_CONTROLLER (self), FALSE);
1279 g_return_val_if_fail (property_name, FALSE);
1281 g_mutex_lock (self->lock);
1282 if ((prop = gst_controller_find_controlled_property (self, property_name))) {
1283 res = gst_controlled_property_set_interpolation_mode (prop, mode);
1285 g_mutex_unlock (self->lock);