3 * Copyright (C) <2005> Stefan Kost <ensonic at users dot sf dot net>
5 * gsthelper.c: GObject convenience methods for using dynamic properties
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.
24 * SECTION:gstcontrollergobject
25 * @short_description: #GObject convenience methods for using dynamic properties
26 * @see_also: #GstController
28 * These methods allow to use some #GstController functionality directly from
38 #include "gstcontrollerprivate.h"
39 #include "gstcontroller.h"
41 #define GST_CAT_DEFAULT controller_debug
42 GST_DEBUG_CATEGORY_EXTERN (GST_CAT_DEFAULT);
45 * gst_object_control_properties:
46 * @object: the object of which some properties should be controlled
47 * @...: %NULL terminated list of property names that should be controlled
49 * Convenience function for GObject
51 * Creates a GstController that allows you to dynamically control one, or more, GObject properties.
52 * If the given GObject already has a GstController, it adds the given properties to the existing
53 * controller and returns that controller.
55 * Returns: The GstController with which the user can control the given properties dynamically or NULL if
56 * one or more of the given properties aren't available, or cannot be controlled, for the given element.
60 gst_object_control_properties (GObject * object, ...)
65 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
67 va_start (var_args, object);
68 ctrl = gst_controller_new_valist (object, var_args);
74 * gst_object_uncontrol_properties:
75 * @object: the object of which some properties should not be controlled anymore
76 * @...: %NULL terminated list of property names that should be controlled
78 * Convenience function for GObject
80 * Removes the given element's properties from it's controller
82 * Returns: %FALSE if one of the given property names isn't handled by the
83 * controller, %TRUE otherwise
87 gst_object_uncontrol_properties (GObject * object, ...)
92 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
94 if ((ctrl = g_object_get_qdata (object, priv_gst_controller_key))) {
97 va_start (var_args, object);
98 res = gst_controller_remove_properties_valist (ctrl, var_args);
105 * gst_object_get_controller:
106 * @object: the object that has controlled properties
108 * Gets the controller for the given GObject
110 * Returns: the controller handling some of the given element's properties, %NULL if no controller
113 /* FIXME 0.11: This should return a new reference */
115 gst_object_get_controller (GObject * object)
117 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
119 return (g_object_get_qdata (object, priv_gst_controller_key));
123 * gst_object_set_controller:
124 * @object: the object that should get the controller
125 * @controller: the controller object to plug in
127 * Sets the controller on the given GObject
129 * Returns: %FALSE if the GObject already has an controller, %TRUE otherwise
132 /* FIXME 0.11: This should increase the refcount before storing */
134 gst_object_set_controller (GObject * object, GstController * controller)
136 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
137 g_return_val_if_fail (controller, FALSE);
139 if (!g_object_get_qdata (object, priv_gst_controller_key)) {
140 g_object_set_qdata (object, priv_gst_controller_key, controller);
147 * gst_object_suggest_next_sync:
148 * @object: the object that has controlled properties
150 * Convenience function for GObject
152 * Returns: same thing as gst_controller_suggest_next_sync()
156 gst_object_suggest_next_sync (GObject * object)
158 GstController *ctrl = NULL;
160 g_return_val_if_fail (G_IS_OBJECT (object), GST_CLOCK_TIME_NONE);
162 if ((ctrl = g_object_get_qdata (object, priv_gst_controller_key))) {
163 return gst_controller_suggest_next_sync (ctrl);
165 return (GST_CLOCK_TIME_NONE);
169 * gst_object_sync_values:
170 * @object: the object that has controlled properties
171 * @timestamp: the time that should be processed
173 * Convenience function for GObject
175 * Returns: same thing as gst_controller_sync_values()
179 gst_object_sync_values (GObject * object, GstClockTime timestamp)
181 GstController *ctrl = NULL;
183 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
185 if ((ctrl = g_object_get_qdata (object, priv_gst_controller_key))) {
186 return gst_controller_sync_values (ctrl, timestamp);
188 /* this is no failure, its called by elements regardless if there is a
189 * controller assigned or not
195 * gst_object_set_control_source:
196 * @object: the controller object
197 * @property_name: name of the property for which the #GstControlSource should be set
198 * @csource: the #GstControlSource that should be used for the property
200 * Sets the #GstControlSource for @property_name. If there already was a #GstControlSource
201 * for this property it will be unreferenced.
203 * Returns: %FALSE if the given property isn't handled by the controller or the new #GstControlSource
204 * couldn't be bound to the property, %TRUE if everything worked as expected.
209 gst_object_set_control_source (GObject * object, const gchar * property_name,
210 GstControlSource * csource)
212 GstController *ctrl = NULL;
214 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
215 g_return_val_if_fail (GST_IS_CONTROL_SOURCE (csource), FALSE);
217 if ((ctrl = g_object_get_qdata (object, priv_gst_controller_key))) {
218 return gst_controller_set_control_source (ctrl, property_name, csource);
224 * gst_object_get_control_source:
225 * @object: the object
226 * @property_name: name of the property for which the #GstControlSource should be get
228 * Gets the corresponding #GstControlSource for the property. This should be unreferenced
231 * Returns: the #GstControlSource for @property_name or NULL if the property is not
232 * controlled by this controller or no #GstControlSource was assigned yet.
237 gst_object_get_control_source (GObject * object, const gchar * property_name)
239 GstController *ctrl = NULL;
241 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
243 if ((ctrl = g_object_get_qdata (object, priv_gst_controller_key))) {
244 return gst_controller_get_control_source (ctrl, property_name);
250 * gst_object_get_value_arrays:
251 * @object: the object that has controlled properties
252 * @timestamp: the time that should be processed
253 * @value_arrays: list to return the control-values in
255 * Function to be able to get an array of values for one or more given element
258 * If the GstValueArray->values array in list nodes is NULL, it will be created
260 * The type of the values in the array are the same as the property's type.
262 * The g_object_* functions are just convenience functions for GObject
264 * Returns: %TRUE if the given array(s) could be filled, %FALSE otherwise
268 gst_object_get_value_arrays (GObject * object, GstClockTime timestamp,
269 GSList * value_arrays)
273 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
274 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
276 if ((ctrl = g_object_get_qdata (object, priv_gst_controller_key))) {
277 return gst_controller_get_value_arrays (ctrl, timestamp, value_arrays);
283 * gst_object_get_value_array:
284 * @object: the object that has controlled properties
285 * @timestamp: the time that should be processed
286 * @value_array: array to put control-values in
288 * Function to be able to get an array of values for one element properties
290 * If the GstValueArray->values array is NULL, it will be created by the function.
291 * The type of the values in the array are the same as the property's type.
293 * The g_object_* functions are just convenience functions for GObject
295 * Returns: %TRUE if the given array(s) could be filled, %FALSE otherwise
299 gst_object_get_value_array (GObject * object, GstClockTime timestamp,
300 GstValueArray * value_array)
304 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
305 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
307 if ((ctrl = g_object_get_qdata (object, priv_gst_controller_key))) {
308 return gst_controller_get_value_array (ctrl, timestamp, value_array);
314 * gst_object_get_control_rate:
315 * @object: the object that has controlled properties
317 * Obtain the control-rate for this @object. Audio processing #GstElement
318 * objects will use this rate to sub-divide their processing loop and call
319 * gst_object_sync_values() inbetween. The length of the processing segment
320 * should be up to @control-rate nanoseconds.
322 * If the @object is not under property control, this will return
323 * %GST_CLOCK_TIME_NONE. This allows the element to avoid the sub-dividing.
325 * The control-rate is not expected to change if the element is in
326 * %GST_STATE_PAUSED or %GST_STATE_PLAYING.
328 * Returns: the control rate in nanoseconds
332 gst_object_get_control_rate (GObject * object)
335 GstClockTime control_rate = GST_CLOCK_TIME_NONE;
337 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
339 if ((ctrl = g_object_get_qdata (object, priv_gst_controller_key))) {
340 g_object_get (ctrl, "control-rate", &control_rate, NULL);
342 return (control_rate);
346 * gst_object_set_control_rate:
347 * @object: the object that has controlled properties
348 * @control_rate: the new control-rate in nanoseconds.
350 * Change the control-rate for this @object. Audio processing #GstElement
351 * objects will use this rate to sub-divide their processing loop and call
352 * gst_object_sync_values() inbetween. The length of the processing segment
353 * should be up to @control-rate nanoseconds.
355 * The control-rate should not change if the element is in %GST_STATE_PAUSED or
356 * %GST_STATE_PLAYING.
361 gst_object_set_control_rate (GObject * object, GstClockTime control_rate)
365 g_return_if_fail (G_IS_OBJECT (object));
367 if ((ctrl = g_object_get_qdata (object, priv_gst_controller_key))) {
368 g_object_set (ctrl, "control-rate", control_rate, NULL);