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);
136 ((GObjectClass *) gst_control_binding_parent_class)->dispose (object);
140 gst_control_binding_finalize (GObject * object)
142 GstControlBinding *self = GST_CONTROL_BINDING (object);
146 ((GObjectClass *) gst_control_binding_parent_class)->finalize (object);
150 gst_control_binding_set_property (GObject * object, guint prop_id,
151 const GValue * value, GParamSpec * pspec)
153 GstControlBinding *self = GST_CONTROL_BINDING (object);
157 self->object = g_value_dup_object (value);
160 self->name = g_value_dup_string (value);
163 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
169 gst_control_binding_get_property (GObject * object, guint prop_id,
170 GValue * value, GParamSpec * pspec)
172 GstControlBinding *self = GST_CONTROL_BINDING (object);
176 g_value_set_object (value, self->object);
179 g_value_set_string (value, self->name);
182 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
190 * gst_control_binding_sync_values:
191 * @self: the control binding
192 * @object: the object that has controlled properties
193 * @timestamp: the time that should be processed
194 * @last_sync: the last time this was called
196 * Sets the property of the @object, according to the #GstControlSources that
197 * handle them and for the given timestamp.
199 * If this function fails, it is most likely the application developers fault.
200 * Most probably the control sources are not setup correctly.
202 * Returns: %TRUE if the controller value could be applied to the object
203 * property, %FALSE otherwise
206 gst_control_binding_sync_values (GstControlBinding * self, GstObject * object,
207 GstClockTime timestamp, GstClockTime last_sync)
209 GstControlBindingClass *klass;
210 gboolean ret = FALSE;
212 g_return_val_if_fail (GST_IS_CONTROL_BINDING (self), FALSE);
217 klass = GST_CONTROL_BINDING_GET_CLASS (self);
219 if (G_LIKELY (klass->sync_values != NULL)) {
220 ret = klass->sync_values (self, object, timestamp, last_sync);
222 GST_WARNING_OBJECT (self, "missing sync_values implementation");
228 * gst_control_binding_get_value:
229 * @self: the control binding
230 * @timestamp: the time the control-change should be read from
232 * Gets the value for the given controlled property at the requested time.
234 * Returns: the GValue of the property at the given time, or %NULL if the
235 * property isn't controlled.
238 gst_control_binding_get_value (GstControlBinding * self, GstClockTime timestamp)
240 GstControlBindingClass *klass;
243 g_return_val_if_fail (GST_IS_CONTROL_BINDING (self), NULL);
244 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), NULL);
246 klass = GST_CONTROL_BINDING_GET_CLASS (self);
248 if (G_LIKELY (klass->get_value != NULL)) {
249 ret = klass->get_value (self, timestamp);
251 GST_WARNING_OBJECT (self, "missing get_value implementation");
257 * gst_control_binding_get_value_array:
258 * @self: the control binding
259 * @timestamp: the time that should be processed
260 * @interval: the time spacing between subsequent values
261 * @n_values: the number of values
262 * @values: array to put control-values in
264 * Gets a number of values for the given controllered property starting at the
265 * requested time. The array @values need to hold enough space for @n_values of
266 * the same type as the objects property's type.
268 * This function is useful if one wants to e.g. draw a graph of the control
269 * curve or apply a control curve sample by sample.
271 * Returns: %TRUE if the given array could be filled, %FALSE otherwise
274 gst_control_binding_get_value_array (GstControlBinding * self,
275 GstClockTime timestamp, GstClockTime interval, guint n_values,
278 GstControlBindingClass *klass;
279 gboolean ret = FALSE;
281 g_return_val_if_fail (GST_IS_CONTROL_BINDING (self), FALSE);
282 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
283 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (interval), FALSE);
284 g_return_val_if_fail (values, FALSE);
286 klass = GST_CONTROL_BINDING_GET_CLASS (self);
288 if (G_LIKELY (klass->get_value_array != NULL)) {
289 ret = klass->get_value_array (self, timestamp, interval, n_values, values);
291 GST_WARNING_OBJECT (self, "missing get_value_array implementation");
297 * gst_control_binding_set_disabled:
298 * @self: the control binding
299 * @disabled: boolean that specifies whether to disable the controller
302 * This function is used to disable a control binding for some time, i.e.
303 * gst_object_sync_values() will do nothing.
306 gst_control_binding_set_disabled (GstControlBinding * self, gboolean disabled)
308 g_return_if_fail (GST_IS_CONTROL_BINDING (self));
309 self->disabled = disabled;
313 * gst_control_binding_is_disabled:
314 * @self: the control binding
316 * Check if the control binding is disabled.
318 * Returns: %TRUE if the binding is inactive
321 gst_control_binding_is_disabled (GstControlBinding * self)
323 g_return_val_if_fail (GST_IS_CONTROL_BINDING (self), TRUE);
324 return (self->disabled == TRUE);