3 * Copyright (C) <2005> Stefan Kost <ensonic at users dot sf dot net>
5 * gst-helper.c: GObject convinience 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 convinience methods for using dynamic properties
27 * These methods allow to use some #GstController functionallity directly from
32 #include "gst-controller.h"
34 #define GST_CAT_DEFAULT gst_controller_debug
35 GST_DEBUG_CATEGORY_EXTERN (GST_CAT_DEFAULT);
37 extern GQuark controller_key;
40 * gst_object_control_properties:
41 * @object: the object of which some properties should be controlled
42 * @...: %NULL terminated list of property names that should be controlled
44 * Convenience function for GObject
46 * Creates a GstController that allows you to dynamically control one, or more, GObject properties.
47 * If the given GObject already has a GstController, it adds the given properties to the existing
48 * controller and returns that controller.
50 * Returns: The GstController with which the user can control the given properties dynamically or NULL if
51 * one or more of the given properties aren't available, or cannot be controlled, for the given element.
54 gst_object_control_properties (GObject * object, ...)
58 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
62 va_start (var_args, object);
63 ctrl = gst_controller_new_valist (object, var_args);
69 * gst_object_uncontrol_properties:
70 * @object: the object of which some properties should not be controlled anymore
71 * @...: %NULL terminated list of property names that should be controlled
73 * Convenience function for GObject
75 * Removes the given element's properties from it's controller
77 * Returns: %FALSE if one of the given property names isn't handled by the
78 * controller, %TRUE otherwise
81 gst_object_uncontrol_properties (GObject * object, ...)
86 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
88 if ((ctrl = g_object_get_qdata (object, controller_key))) {
91 va_start (var_args, object);
92 res = gst_controller_remove_properties_valist (ctrl, var_args);
99 * gst_object_get_controller:
100 * @object: the object that has controlled properties
102 * Returns: the controller handling some of the given element's properties, %NULL if no controller
105 gst_object_get_controller (GObject * object)
107 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
109 return (g_object_get_qdata (object, controller_key));
113 * gst_object_set_controller:
114 * @object: the object that should get the controller
115 * @controller: the controller object to plug in
117 * Sets the controller on the given GObject
119 * Returns: %FALSE if the GObject already has an controller, %TRUE otherwise
122 gst_object_set_controller (GObject * object, GstController * controller)
126 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
127 g_return_val_if_fail (controller, FALSE);
129 ctrl = g_object_get_qdata (object, controller_key);
130 g_return_val_if_fail (!ctrl, FALSE);
131 g_object_set_qdata (object, controller_key, controller);
136 * gst_object_sink_values:
137 * @object: the object that has controlled properties
138 * @timestamp: the time that should be processed
140 * Convenience function for GObject
142 * Returns: same thing as gst_controller_sink_values()
145 gst_object_sink_values (GObject * object, GstClockTime timestamp)
147 GstController *ctrl = NULL;
149 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
150 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
152 ctrl = g_object_get_qdata (object, controller_key);
153 g_return_val_if_fail (ctrl, FALSE);
154 return gst_controller_sink_values (ctrl, timestamp);
158 * gst_object_get_value_arrays:
159 * @object: the object that has controlled properties
160 * @timestamp: the time that should be processed
161 * @value_arrays: list to return the control-values in
163 * Function to be able to get an array of values for one or more given element
166 * If the GstValueArray->values array in list nodes is NULL, it will be created
168 * The type of the values in the array are the same as the property's type.
170 * The g_object_* functions are just convenience functions for GObject
172 * Returns: %TRUE if the given array(s) could be filled, %FALSE otherwise
175 gst_object_get_value_arrays (GObject * object, GstClockTime timestamp,
176 GSList * value_arrays)
180 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
181 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
183 ctrl = g_object_get_qdata (object, controller_key);
184 g_return_val_if_fail (ctrl, FALSE);
185 return gst_controller_get_value_arrays (ctrl, timestamp, value_arrays);
189 * gst_object_get_value_array:
190 * @object: the object that has controlled properties
191 * @timestamp: the time that should be processed
192 * @value_array: array to put control-values in
194 * Function to be able to get an array of values for one element properties
196 * If the GstValueArray->values array is NULL, it will be created by the function.
197 * The type of the values in the array are the same as the property's type.
199 * The g_object_* functions are just convenience functions for GObject
201 * Returns: %TRUE if the given array(s) could be filled, %FALSE otherwise
204 gst_object_get_value_array (GObject * object, GstClockTime timestamp,
205 GstValueArray * value_array)
209 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
210 g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), FALSE);
212 ctrl = g_object_get_qdata (object, controller_key);
213 g_return_val_if_fail (ctrl, FALSE);
215 return gst_controller_get_value_array (ctrl, timestamp, value_array);