don't break docs build
[platform/upstream/gstreamer.git] / gst / gstvalue.h
1 /* GStreamer
2  * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __GST_VALUE_H__
21 #define __GST_VALUE_H__
22
23 #include <gst/gstconfig.h>
24 #include <gst/gstcaps.h>
25
26 G_BEGIN_DECLS
27
28 /**
29  * GST_MAKE_FOURCC:
30  * @a: the first character
31  * @b: the second character
32  * @c: the third character
33  * @d: the fourth character
34  *
35  * Transform four characters into a #guint32 fourcc value with host
36  * endianness.
37  * <informalexample>
38  * <programlisting>
39  * guint32 fourcc = GST_MAKE_FOURCC ('M', 'J', 'P', 'G');
40  * </programlisting>
41  * </informalexample>
42  */
43 #define GST_MAKE_FOURCC(a,b,c,d)        (guint32)((a)|(b)<<8|(c)<<16|(d)<<24)
44
45 /**
46  * GST_STR_FOURCC:
47  * @f: a string with at least four characters
48  *
49  * Transform an input string into a #guint32 fourcc value with host
50  * endianness.
51  * Caller is responsible for ensuring the input string consists of at least
52  * four characters.
53  * <informalexample>
54  * <programlisting>
55  * guint32 fourcc = GST_STR_FOURCC ("MJPG");
56  * </programlisting>
57  * </informalexample>
58  */
59 #define GST_STR_FOURCC(f)               (guint32)(((f)[0])|((f)[1]<<8)|((f)[2]<<16)|((f)[3]<<24))
60
61 /**
62  * GST_FOURCC_FORMAT:
63  *
64  * Can be used together with #GST_FOURCC_ARGS to properly output a
65  * #guint32 fourcc value in a printf()-style text message.
66  * <informalexample>
67  * <programlisting>
68  * printf ("fourcc: %" GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS (fcc));
69  * </programlisting>
70  * </informalexample>
71  */
72 #define GST_FOURCC_FORMAT "%c%c%c%c"
73
74 /**
75  * GST_FOURCC_ARGS:
76  * @fourcc: a #guint32 fourcc value to output
77  *
78  * Can be used together with #GST_FOURCC_FORMAT to properly output a
79  * #guint32 fourcc value in a printf()-style text message.
80  */
81 #define GST_FOURCC_ARGS(fourcc) \
82         ((gchar) ((fourcc)     &0xff)), \
83         ((gchar) (((fourcc)>>8 )&0xff)), \
84         ((gchar) (((fourcc)>>16)&0xff)), \
85         ((gchar) (((fourcc)>>24)&0xff))
86
87 /**
88  * GST_VALUE_HOLDS_FOURCC:
89  * @x: the #GValue to check
90  *
91  * Checks if the given #GValue contains a #GST_TYPE_FOURCC value.
92  */
93 #define GST_VALUE_HOLDS_FOURCC(x)       (G_VALUE_HOLDS(x, gst_type_fourcc))
94
95 /**
96  * GST_VALUE_HOLDS_INT_RANGE:
97  * @x: the #GValue to check
98  *
99  * Checks if the given #GValue contains a #GST_TYPE_INT_RANGE value.
100  */
101 #define GST_VALUE_HOLDS_INT_RANGE(x)    (G_VALUE_HOLDS(x, gst_type_int_range))
102
103 /**
104  * GST_VALUE_HOLDS_DOUBLE_RANGE:
105  * @x: the #GValue to check
106  *
107  * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
108  */
109 #define GST_VALUE_HOLDS_DOUBLE_RANGE(x) (G_VALUE_HOLDS(x, gst_type_double_range))
110
111 /**
112  * GST_VALUE_HOLDS_LIST:
113  * @x: the #GValue to check
114  *
115  * Checks if the given #GValue contains a #GST_TYPE_LIST value.
116  */
117 #define GST_VALUE_HOLDS_LIST(x)         (G_VALUE_HOLDS(x, gst_type_list))
118
119 /**
120  * GST_VALUE_HOLDS_ARRAY:
121  * @x: the #GValue to check
122  *
123  * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
124  */
125 #define GST_VALUE_HOLDS_ARRAY(x)        (G_VALUE_HOLDS(x, gst_type_array))
126
127 /**
128  * GST_VALUE_HOLDS_CAPS:
129  * @x: the #GValue to check
130  *
131  * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
132  */
133 #define GST_VALUE_HOLDS_CAPS(x)         (G_VALUE_HOLDS(x, GST_TYPE_CAPS))
134
135 /**
136  * GST_VALUE_HOLDS_BUFFER:
137  * @x: the #GValue to check
138  *
139  * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
140  */
141 #define GST_VALUE_HOLDS_BUFFER(x)       (G_VALUE_HOLDS(x, GST_TYPE_BUFFER))
142
143 /**
144  * GST_VALUE_HOLDS_FRACTION:
145  * @x: the #GValue to check
146  *
147  * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
148  */
149 #define GST_VALUE_HOLDS_FRACTION(x)     (G_VALUE_HOLDS(x, gst_type_fraction))
150
151 /**
152  * GST_VALUE_HOLDS_DATE:
153  * @x: the #GValue to check
154  *
155  * Checks if the given #GValue contains a #GST_TYPE_DATE value.
156  */
157 #define GST_VALUE_HOLDS_DATE(x)         (G_VALUE_HOLDS(x, gst_type_date))
158
159 /**
160  * GST_TYPE_FOURCC:
161  *
162  * a #GValue type that represents 4 byte identifier (e.g. used for codecs)
163  *
164  * Returns: the #GType of GstFourcc
165  */
166 #define GST_TYPE_FOURCC                  gst_type_fourcc
167
168 /**
169  * GST_TYPE_INT_RANGE:
170  *
171  * a #GValue type that represents an integer range
172  *
173  * Returns: the #GType of GstIntRange
174  */
175 #define GST_TYPE_INT_RANGE               gst_type_int_range
176
177 /**
178  * GST_TYPE_DOUBLE_RANGE:
179  *
180  * a #GValue type that represents a floating point range with double precission
181  *
182  * Returns: the #GType of GstIntRange
183  */
184 #define GST_TYPE_DOUBLE_RANGE            gst_type_double_range
185
186 /**
187  * GST_TYPE_LIST:
188  *
189  * a #GValue type that represents an unordered list of #GValue values
190  *
191  * Returns: the #GType of GstValueList (which is not explicitly typed)
192  */
193 #define GST_TYPE_LIST                    gst_type_list
194
195 /**
196  * GST_TYPE_ARRAY:
197  *
198  * a #GValue type that represents an ordered list of #GValue values
199  *
200  * Returns: the #GType of GstArrayList (which is not explicitly typed)
201  */
202 #define GST_TYPE_ARRAY                   gst_type_array
203
204 /**
205  * GST_TYPE_FRACTION:
206  *
207  * a #GValue type that represents a fraction of an integer numerator over
208  * an integer denominator
209  *
210  * Returns: the #GType of GstFraction (which is not explicitly typed)
211  */
212
213 #define GST_TYPE_FRACTION                gst_type_fraction
214
215 /**
216  * GST_TYPE_DATE:
217  *
218  * a boxed #GValue type for #GDate that represents a date.
219  *
220  * Returns: the #GType of GstDate
221  */
222
223 #define GST_TYPE_DATE                    gst_type_date
224
225 /**
226  * GST_VALUE_LESS_THAN:
227  *
228  * Indicates that the first value provided to a comparison function
229  * (gst_value_compare()) is lesser than the second one.
230  */
231 #define GST_VALUE_LESS_THAN              (-1)
232
233 /**
234  * GST_VALUE_EQUAL:
235  *
236  * Indicates that the first value provided to a comparison function
237  * (gst_value_compare()) is equal to the second one.
238  */
239 #define GST_VALUE_EQUAL                   0
240
241 /**
242  * GST_VALUE_GREATER_THAN:
243  *
244  * Indicates that the first value provided to a comparison function
245  * (gst_value_compare()) is greater than the second one.
246  */
247 #define GST_VALUE_GREATER_THAN            1
248
249 /**
250  * GST_VALUE_UNORDERED:
251  *
252  * Indicates that the comparison function (gst_value_compare()) can not
253  * determine a order for the two provided values.
254  */
255 #define GST_VALUE_UNORDERED               2
256
257 /**
258  * GstValueCompareFunc:
259  * @value1: first value for comparission
260  * @value2: second value for comparission 
261  *
262  * Used together with gst_value_compare() to compare #GValues.
263  *
264  * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
265  * or GST_VALUE_UNORDERED
266  */
267 typedef int      (* GstValueCompareFunc)     (const GValue *value1,
268                                               const GValue *value2);
269                                               
270 typedef char *   (* GstValueSerializeFunc)   (const GValue *value1);
271
272 typedef gboolean (* GstValueDeserializeFunc) (GValue       *dest,
273                                               const char   *s);
274                                               
275 typedef int      (* GstValueUnionFunc)       (GValue       *dest,
276                                               const GValue *value1,
277                                               const GValue *value2);
278                                               
279 typedef int      (* GstValueIntersectFunc)   (GValue       *dest,
280                                               const GValue *value1,
281                                               const GValue *value2);
282                                               
283 typedef int      (* GstValueSubtractFunc)    (GValue       *dest,
284                                               const GValue *minuend,
285                                               const GValue *subtrahend);
286
287 typedef struct _GstValueTable GstValueTable;
288 struct _GstValueTable {
289   GType type;
290   GstValueCompareFunc compare;
291   GstValueSerializeFunc serialize;
292   GstValueDeserializeFunc deserialize;
293
294   /*< private >*/
295   void *_gst_reserved [GST_PADDING];
296 };
297
298 GST_EXPORT GType gst_type_fourcc;
299 GST_EXPORT GType gst_type_int_range;
300 GST_EXPORT GType gst_type_double_range;
301 GST_EXPORT GType gst_type_list;
302 GST_EXPORT GType gst_type_array;
303 GST_EXPORT GType gst_type_fraction;
304 GST_EXPORT GType gst_type_date;
305
306 void            gst_value_register              (const GstValueTable   *table);
307 void            gst_value_init_and_copy         (GValue                *dest,
308                                                  const GValue          *src);
309
310 gchar *         gst_value_serialize             (const GValue          *value);
311 gboolean        gst_value_deserialize           (GValue                *dest,
312                                                  const gchar           *src);
313
314 /* list */
315 void            gst_value_list_append_value     (GValue         *value,
316                                                  const GValue   *append_value);
317 void            gst_value_list_prepend_value    (GValue         *value,
318                                                  const GValue   *prepend_value);
319 void            gst_value_list_concat           (GValue         *dest,
320                                                  const GValue   *value1,
321                                                  const GValue   *value2);
322 guint           gst_value_list_get_size         (const GValue   *value);
323 G_CONST_RETURN GValue *
324                 gst_value_list_get_value        (const GValue   *value,
325                                                  guint          index);
326
327 /* fourcc */
328 void            gst_value_set_fourcc            (GValue         *value,
329                                                  guint32        fourcc);
330 guint32         gst_value_get_fourcc            (const GValue   *value);
331
332 /* int range */
333 void            gst_value_set_int_range         (GValue         *value,
334                                                  int            start,
335                                                  int            end);
336 int             gst_value_get_int_range_min     (const GValue   *value);
337 int             gst_value_get_int_range_max     (const GValue   *value);
338
339 /* double range */
340 void            gst_value_set_double_range      (GValue         *value,
341                                                  double         start,
342                                                  double         end);
343 double          gst_value_get_double_range_min  (const GValue   *value);
344 double          gst_value_get_double_range_max  (const GValue   *value);
345
346 /* caps */
347 G_CONST_RETURN GstCaps *
348                 gst_value_get_caps              (const GValue   *value);
349 void            gst_value_set_caps              (GValue         *value,
350                                                  const GstCaps  *caps);
351
352 /* fraction */
353 void            gst_value_set_fraction          (GValue         *value,
354                                                  int            numerator,
355                                                  int            denominator);
356 int             gst_value_get_fraction_numerator (const GValue  *value);
357 int             gst_value_get_fraction_denominator(const GValue *value);
358 gboolean        gst_value_fraction_multiply     (GValue         *product,
359                                                  const GValue   *factor1,
360                                                  const GValue   *factor2);
361
362 /* date */
363 G_CONST_RETURN GDate *
364                 gst_value_get_date              (const GValue   *value);
365 void            gst_value_set_date              (GValue         *value,
366                                                  const GDate    *date);
367
368 /* compare */
369 int             gst_value_compare               (const GValue   *value1,
370                                                  const GValue   *value2);
371 gboolean        gst_value_can_compare           (const GValue   *value1,
372                                                  const GValue   *value2);
373
374 /* union */
375 gboolean        gst_value_union                 (GValue         *dest,
376                                                  const GValue   *value1,
377                                                  const GValue   *value2);
378 gboolean        gst_value_can_union             (const GValue   *value1,
379                                                  const GValue   *value2);
380 void            gst_value_register_union_func   (GType          type1,
381                                                  GType          type2,
382                                                  GstValueUnionFunc func);
383
384 /* intersection */
385 gboolean        gst_value_intersect             (GValue         *dest,
386                                                  const GValue   *value1,
387                                                  const GValue   *value2);
388 gboolean        gst_value_can_intersect         (const GValue   *value1,
389                                                  const GValue   *value2);
390 void            gst_value_register_intersect_func (GType        type1,
391                                                 GType           type2,
392                                                 GstValueIntersectFunc func);
393
394 /* subtraction */
395 gboolean        gst_value_subtract              (GValue         *dest,
396                                                  const GValue   *minuend,
397                                                  const GValue   *subtrahend);
398 gboolean        gst_value_can_subtract          (const GValue   *minuend,
399                                                  const GValue   *subtrahend);
400 void            gst_value_register_subtract_func (GType         minuend_type,
401                                                 GType           subtrahend_type,
402                                                 GstValueSubtractFunc func);
403
404 /* fixation */
405 gboolean        gst_value_is_fixed              (const GValue   *value);
406
407 /* private */
408 void            _gst_value_initialize           (void);
409
410 G_END_DECLS
411
412 #endif
413
414