3 * Copyright (C) 2011 Stefan Sauer <ensonic@users.sf.net>
5 * gstcontrolbinding.c: Attachment for control sources
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 * SECTION:gstcontrolbinding
24 * @short_description: attachment for control source sources
26 * A value mapping object that attaches control sources to gobject properties.
29 #include "gst_private.h"
31 #include <glib-object.h>
34 #include "gstcontrolbinding.h"
38 #define GST_CAT_DEFAULT control_binding_debug
39 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
42 GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "gstcontrolbinding", 0, \
43 "dynamic parameter control source attachment");
45 static GObject *gst_control_binding_constructor (GType type,
46 guint n_construct_params, GObjectConstructParam * construct_params);
47 static void gst_control_binding_set_property (GObject * object, guint prop_id,
48 const GValue * value, GParamSpec * pspec);
49 static void gst_control_binding_get_property (GObject * object, guint prop_id,
50 GValue * value, GParamSpec * pspec);
51 static void gst_control_binding_dispose (GObject * object);
52 static void gst_control_binding_finalize (GObject * object);
54 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstControlBinding, gst_control_binding,
55 GST_TYPE_OBJECT, _do_init);
65 static GParamSpec *properties[PROP_LAST];
68 gst_control_binding_class_init (GstControlBindingClass * klass)
70 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
72 gobject_class->constructor = gst_control_binding_constructor;
73 gobject_class->set_property = gst_control_binding_set_property;
74 gobject_class->get_property = gst_control_binding_get_property;
75 gobject_class->dispose = gst_control_binding_dispose;
76 gobject_class->finalize = gst_control_binding_finalize;
78 properties[PROP_OBJECT] =
79 g_param_spec_object ("object", "Object",
80 "The object of the property", GST_TYPE_OBJECT,
81 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
83 properties[PROP_NAME] =
84 g_param_spec_string ("name", "Name", "The name of the property", NULL,
85 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
88 g_object_class_install_properties (gobject_class, PROP_LAST, properties);
92 gst_control_binding_init (GstControlBinding * self)
97 gst_control_binding_constructor (GType type, guint n_construct_params,
98 GObjectConstructParam * construct_params)
100 GstControlBinding *self;
103 self = GST_CONTROL_BINDING (G_OBJECT_CLASS (gst_control_binding_parent_class)
104 ->constructor (type, n_construct_params, construct_params));
106 GST_INFO_OBJECT (self->object, "trying to put property '%s' under control",
109 /* check if the object has a property of that name */
111 g_object_class_find_property (G_OBJECT_GET_CLASS (self->object),
113 GST_DEBUG_OBJECT (self->object, " psec->flags : 0x%08x", pspec->flags);
115 /* check if this param is witable && controlable && !construct-only */
116 if ((pspec->flags & (G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE |
117 G_PARAM_CONSTRUCT_ONLY)) ==
118 (G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE)) {
122 GST_WARNING_OBJECT (self->object, "class '%s' has no property '%s'",
123 G_OBJECT_TYPE_NAME (self->object), self->name);
125 return (GObject *) self;
129 gst_control_binding_dispose (GObject * object)
131 GstControlBinding *self = GST_CONTROL_BINDING (object);
134 gst_object_replace (&self->object, NULL);
138 gst_control_binding_finalize (GObject * object)
140 GstControlBinding *self = GST_CONTROL_BINDING (object);
146 gst_control_binding_set_property (GObject * object, guint prop_id,
147 const GValue * value, GParamSpec * pspec)
149 GstControlBinding *self = GST_CONTROL_BINDING (object);
153 self->object = g_value_dup_object (value);
156 self->name = g_value_dup_string (value);
159 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
165 gst_control_binding_get_property (GObject * object, guint prop_id,
166 GValue * value, GParamSpec * pspec)
168 GstControlBinding *self = GST_CONTROL_BINDING (object);
172 g_value_set_object (value, self->object);
175 g_value_set_string (value, self->name);
178 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
186 * gst_control_binding_sync_values:
187 * @self: the control binding
188 * @object: the object that has controlled properties
189 * @timestamp: the time that should be processed
190 * @last_sync: the last time this was called
192 * Sets the property of the @object, according to the #GstControlSources that
193 * handle them and for the given timestamp.
195 * If this function fails, it is most likely the application developers fault.
196 * Most probably the control sources are not setup correctly.
198 * Returns: %TRUE if the controller value could be applied to the object
199 * property, %FALSE otherwise
202 gst_control_binding_sync_values (GstControlBinding * self, GstObject * object,
203 GstClockTime timestamp, GstClockTime last_sync)
205 GstControlBindingClass *klass;
206 gboolean ret = FALSE;
208 g_return_val_if_fail (GST_IS_CONTROL_BINDING (self), FALSE);
213 klass = GST_CONTROL_BINDING_GET_CLASS (self);
215 if (G_LIKELY (klass->sync_values != NULL)) {
216 ret = klass->sync_values (self, object, timestamp, last_sync);
218 GST_WARNING_OBJECT (self, "missing sync_values implementation");
224 * gst_control_binding_get_value:
225 * @self: the control binding
226 * @timestamp: the time the control-change should be read from
228 * Gets the value for the given controlled property at the requested time.
230 * Returns: the GValue of the property at the given time, or %NULL if the
231 * property isn't controlled.
234 gst_control_binding_get_value (GstControlBinding * self, GstClockTime timestamp)
236 GstControlBindingClass *klass;
239 g_return_val_if_fail (GST_IS_CONTROL_BINDING (self), NULL);
240 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), NULL);
242 klass = GST_CONTROL_BINDING_GET_CLASS (self);
244 if (G_LIKELY (klass->get_value != NULL)) {
245 ret = klass->get_value (self, timestamp);
247 GST_WARNING_OBJECT (self, "missing get_value implementation");
253 * gst_control_binding_get_value_array:
254 * @self: the control binding
255 * @timestamp: the time that should be processed
256 * @interval: the time spacing between subsequent values
257 * @n_values: the number of values
258 * @values: array to put control-values in
260 * Gets a number of values for the given controllered property starting at the
261 * requested time. The array @values need to hold enough space for @n_values of
262 * the same type as the objects property's type.
264 * This function is useful if one wants to e.g. draw a graph of the control
265 * curve or apply a control curve sample by sample.
267 * Returns: %TRUE if the given array could be filled, %FALSE otherwise
270 gst_control_binding_get_value_array (GstControlBinding * self,
271 GstClockTime timestamp, GstClockTime interval, guint n_values,
274 GstControlBindingClass *klass;
275 gboolean ret = FALSE;
277 g_return_val_if_fail (GST_IS_CONTROL_BINDING (self), FALSE);
278 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
279 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (interval), FALSE);
280 g_return_val_if_fail (values, FALSE);
282 klass = GST_CONTROL_BINDING_GET_CLASS (self);
284 if (G_LIKELY (klass->get_value_array != NULL)) {
285 ret = klass->get_value_array (self, timestamp, interval, n_values, values);
287 GST_WARNING_OBJECT (self, "missing get_value_array implementation");
293 * gst_control_binding_set_disabled:
294 * @self: the control binding
295 * @disabled: boolean that specifies whether to disable the controller
298 * This function is used to disable a control binding for some time, i.e.
299 * gst_object_sync_values() will do nothing.
302 gst_control_binding_set_disabled (GstControlBinding * self, gboolean disabled)
304 g_return_if_fail (GST_IS_CONTROL_BINDING (self));
305 self->disabled = disabled;
309 * gst_control_binding_is_disabled:
310 * @self: the control binding
312 * Check if the control binding is disabled.
314 * Returns: %TRUE if the binding is inactive
317 gst_control_binding_is_disabled (GstControlBinding * self)
319 g_return_val_if_fail (GST_IS_CONTROL_BINDING (self), TRUE);
320 return (self->disabled == TRUE);