d672f2d88214a8c84aba05dbea6a25fcc3443016
[platform/upstream/gstreamer.git] / libs / gst / controller / gst-controller.h
1 /* GStreamer
2  *
3  * Copyright (C) <2005> Stefan Kost <ensonic at users dot sf dot net>
4  *
5  * gst-controller.h: dynamic parameter control subsystem
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #ifndef __GST_CONTROLLER_H__
24 #define __GST_CONTROLLER_H__
25
26 #include <string.h>
27
28 #include <glib.h>
29 #include <glib-object.h>
30 #include <glib/gprintf.h>
31 #include <gst/gst.h>
32
33 G_BEGIN_DECLS
34
35 /**
36  * GST_PARAM_CONTROLLABLE:
37  *
38  * Use this flag on GstElement properties you wish to be (eventually) handled
39  * by a GstController.
40  * TODO: needs to go to gstelemnt.h (to avoid clashes on G_PARAM_USER_SHIFT)
41  */
42 #define GST_PARAM_CONTROLLABLE  (1 << (G_PARAM_USER_SHIFT + 1))
43
44
45 /**
46  * GstTimedValue:
47  *
48  * a structure for value+time
49  */
50 typedef struct _GstTimedValue
51 {
52   GstClockTime timestamp;       // timestamp of the value change
53   GValue value;                 // the new value
54   /* TODO what about storing the difference to next timestamp and value here
55      + make calculations slightly easier and faster
56      - determining the GType for the value_dif is not simple
57      e.g. if value is G_TYPE_UCHAR value_diff needs to be G_TYPE_INT
58    */
59 } GstTimedValue;
60
61
62 /**
63  * GstValueArray:
64  *
65  * Structure to receive multiple values at once
66  */
67 typedef struct _GstValueArray
68 {
69   gchar *property_name;
70   gint nbsamples;               // Number of samples requested
71   GstClockTime sample_interval; // Interval between each sample
72   gpointer *values;             // pointer to the array (so it can be filled if NULL)
73 } GstValueArray;
74
75
76 /**
77  * GstInterpolateMode:
78  * @GST_INTERPOLATE_NONE: steps-like interpolation, default
79  * @GST_INTERPOLATE_TRIGGER: returns the default value of the property, 
80  * except for times with specific values
81  * @GST_INTERPOLATE_LINEAR: linear interpolation
82  * @GST_INTERPOLATE_QUADRATIC: square interpolation
83  * @GST_INTERPOLATE_CUBIC: cubic interpolation
84  * @GST_INTERPOLATE_USER: user-provided interpolation
85  *
86  * The various interpolation modes available.
87  */
88 typedef enum
89 {
90   GST_INTERPOLATE_NONE,
91   GST_INTERPOLATE_TRIGGER,
92   GST_INTERPOLATE_LINEAR,
93   GST_INTERPOLATE_QUADRATIC,
94   GST_INTERPOLATE_CUBIC,
95   GST_INTERPOLATE_USER
96 } GstInterpolateMode;
97
98
99 struct _GstControlledProperty;
100
101 typedef GValue *(*InterpolateGet) (struct _GstControlledProperty * prop,
102         GstClockTime timestamp);
103 typedef gboolean (*InterpolateGetValueArray) (struct _GstControlledProperty * prop,
104         GstClockTime timestamp, GstValueArray * value_array);
105
106 /**
107  * GstInterpolateMethod:
108  *
109  * Function pointer structure to do user-defined interpolation methods
110  */
111 typedef struct _GstInterpolateMethod
112 {
113   InterpolateGet get_int;
114   InterpolateGetValueArray get_int_value_array;
115   InterpolateGet get_long;
116   InterpolateGetValueArray get_long_value_array;
117   InterpolateGet get_float;
118   InterpolateGetValueArray get_float_value_array;
119   InterpolateGet get_double;
120   InterpolateGetValueArray get_double_value_array;
121 } GstInterpolateMethod;
122
123 /**
124  * GstControlledProperty:
125  */
126 typedef struct _GstControlledProperty
127 {
128   gchar *name;                  // name of the property
129   GType type;                   // type of the handled property
130   GValue default_value;         // default value for the handled property
131   GValue result_value;          // result value location for the interpolation method
132   GstTimedValue last_value;     // the last value a _sink call wrote
133   GstTimedValue live_value;     // temporary value override for live input
134   gulong notify_handler_id;     // id of the notify::<name> signal handler
135   GstInterpolateMode interpolation;     // Interpolation mode
136   /* TODO instead of *method, have pointers to get() and get_value_array() here
137      gst_controller_set_interpolation_mode() will pick the right ones for the
138      properties value type
139      GstInterpolateMethod *method; // User-implemented handler (if interpolation == GST_INTERPOLATE_USER)
140   */
141   InterpolateGet get;
142   InterpolateGetValueArray get_value_array;
143
144   GList *values;                // List of GstTimedValue
145   /* TODO keep the last search result to be able to continue
146      GList      *last_value;                    // last search result, can be used for incremental searches
147    */
148 } GstControlledProperty;
149
150 #define GST_CONTROLLED_PROPERTY(obj)    ((GstControlledProperty *)(obj))
151
152 /* type macros */
153
154 #define GST_TYPE_CONTROLLER            (gst_controller_get_type ())
155 #define GST_CONTROLLER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_CONTROLLER, GstController))
156 #define GST_CONTROLLER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_CONTROLLER, GstControllerClass))
157 #define GST_IS_CONTROLLER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_CONTROLLER))
158 #define GST_IS_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_CONTROLLERE))
159 #define GST_CONTROLLER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_CONTROLLER, GstControllerClass))
160
161 typedef struct _GstController GstController;
162 typedef struct _GstControllerClass GstControllerClass;
163
164 //typedef struct _GstControllerPrivate GstControllerPrivate;
165
166 /**
167  * GstController:
168  *
169  * The instance structure of GstController
170  */
171
172 struct _GstController
173 {
174   GObject parent;
175
176   GList *properties;  // List of GstControlledProperty
177   GMutex *lock;       // Secure property access, elements will access from threads
178   GObject *object;    // the object we control
179 };
180
181 struct _GstControllerClass
182 {
183   GObjectClass parent_class;
184 };
185
186 GType gst_controller_get_type (void);
187
188 /* GstController functions */
189
190 GstController *gst_controller_new_valist (GObject * object, va_list var_args);
191 GstController *gst_controller_new (GObject * object, ...);
192
193 gboolean gst_controller_remove_properties_valist (GstController * self,
194     va_list var_args);
195 gboolean gst_controller_remove_properties (GstController * self, ...);
196
197 gboolean gst_controller_set (GstController * self, gchar * property_name,
198     GstClockTime timestamp, GValue * value);
199 gboolean gst_controller_set_from_list (GstController * self,
200     gchar * property_name, GSList * timedvalues);
201
202 gboolean gst_controller_unset (GstController * self, gchar * property_name,
203     GstClockTime timestamp);
204
205
206 GValue *gst_controller_get (GstController * self, gchar * property_name,
207     GstClockTime timestamp);
208 const GList *gst_controller_get_all (GstController * self,
209     gchar * property_name);
210
211
212 gboolean gst_controller_sink_values (GstController * self,
213     GstClockTime timestamp);
214     
215 gboolean gst_controller_get_value_arrays (GstController * self,
216     GstClockTime timestamp, GSList * value_arrays);
217 gboolean gst_controller_get_value_array (GstController * self,
218     GstClockTime timestamp, GstValueArray * value_array);
219
220 gboolean gst_controller_set_interpolation_mode (GstController * self,
221     gchar * property_name, GstInterpolateMode mode);
222
223
224 /* GObject convenience functions */
225
226 GstController *gst_object_control_properties (GObject * object, ...);
227 gboolean gst_object_uncontrol_properties (GObject * object, ...);
228
229 GstController *gst_object_get_controller (GObject * object);
230 gboolean gst_object_set_controller (GObject * object, GstController * controller);
231
232 gboolean gst_object_sink_values (GObject * object, GstClockTime timestamp);
233
234 gboolean gst_object_get_value_arrays (GObject * object,
235     GstClockTime timestamp, GSList * value_arrays);
236 gboolean gst_object_get_value_array (GObject * object,
237     GstClockTime timestamp, GstValueArray * value_array);
238
239 /* lib init/done */
240
241 gboolean gst_controller_init (int * argc, char ***argv);
242
243 G_END_DECLS
244 #endif /* __GST_CONTROLLER_H__ */