gstvalue: Adds datetime functions
[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 #include <gst/gststructure.h>
26
27 G_BEGIN_DECLS
28
29 /**
30  * GST_MAKE_FOURCC:
31  * @a: the first character
32  * @b: the second character
33  * @c: the third character
34  * @d: the fourth character
35  *
36  * Transform four characters into a #guint32 fourcc value with host
37  * endianness.
38  * <informalexample>
39  * <programlisting>
40  * guint32 fourcc = GST_MAKE_FOURCC ('M', 'J', 'P', 'G');
41  * </programlisting>
42  * </informalexample>
43  */
44 #define GST_MAKE_FOURCC(a,b,c,d)        ((guint32)((a)|(b)<<8|(c)<<16|(d)<<24))
45
46 /**
47  * GST_STR_FOURCC:
48  * @f: a string with at least four characters
49  *
50  * Transform an input string into a #guint32 fourcc value with host
51  * endianness.
52  * Caller is responsible for ensuring the input string consists of at least
53  * four characters.
54  * <informalexample>
55  * <programlisting>
56  * guint32 fourcc = GST_STR_FOURCC ("MJPG");
57  * </programlisting>
58  * </informalexample>
59  */
60 #define GST_STR_FOURCC(f)               ((guint32)(((f)[0])|((f)[1]<<8)|((f)[2]<<16)|((f)[3]<<24)))
61
62 /**
63  * GST_FOURCC_FORMAT:
64  *
65  * Can be used together with #GST_FOURCC_ARGS to properly output a
66  * #guint32 fourcc value in a printf()-style text message.
67  * <informalexample>
68  * <programlisting>
69  * printf ("fourcc: %" GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS (fcc));
70  * </programlisting>
71  * </informalexample>
72  */
73 #define GST_FOURCC_FORMAT "c%c%c%c"
74
75 /**
76  * GST_FOURCC_ARGS:
77  * @fourcc: a #guint32 fourcc value to output
78  *
79  * Can be used together with #GST_FOURCC_FORMAT to properly output a
80  * #guint32 fourcc value in a printf()-style text message.
81  */
82 #define GST_FOURCC_ARGS(fourcc) \
83         ((gchar) ((fourcc)     &0xff)), \
84         ((gchar) (((fourcc)>>8 )&0xff)), \
85         ((gchar) (((fourcc)>>16)&0xff)), \
86         ((gchar) (((fourcc)>>24)&0xff))
87
88 /**
89  * GST_VALUE_HOLDS_FOURCC:
90  * @x: the #GValue to check
91  *
92  * Checks if the given #GValue contains a #GST_TYPE_FOURCC value.
93  */
94 #define GST_VALUE_HOLDS_FOURCC(x)       (G_VALUE_HOLDS((x), gst_fourcc_get_type ()))
95
96 /**
97  * GST_VALUE_HOLDS_INT_RANGE:
98  * @x: the #GValue to check
99  *
100  * Checks if the given #GValue contains a #GST_TYPE_INT_RANGE value.
101  */
102 #define GST_VALUE_HOLDS_INT_RANGE(x)    (G_VALUE_HOLDS((x), gst_int_range_get_type ()))
103
104 /**
105  * GST_VALUE_HOLDS_DOUBLE_RANGE:
106  * @x: the #GValue to check
107  *
108  * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
109  */
110 #define GST_VALUE_HOLDS_DOUBLE_RANGE(x) (G_VALUE_HOLDS((x), gst_double_range_get_type ()))
111
112 /**
113  * GST_VALUE_HOLDS_FRACTION_RANGE:
114  * @x: the #GValue to check
115  *
116  * Checks if the given #GValue contains a #GST_TYPE_FRACTION_RANGE value.
117  */
118 #define GST_VALUE_HOLDS_FRACTION_RANGE(x)    (G_VALUE_HOLDS((x), gst_fraction_range_get_type ()))
119
120 /**
121  * GST_VALUE_HOLDS_LIST:
122  * @x: the #GValue to check
123  *
124  * Checks if the given #GValue contains a #GST_TYPE_LIST value.
125  */
126 #define GST_VALUE_HOLDS_LIST(x)         (G_VALUE_HOLDS((x), gst_value_list_get_type ()))
127
128 /**
129  * GST_VALUE_HOLDS_ARRAY:
130  * @x: the #GValue to check
131  *
132  * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
133  */
134 #define GST_VALUE_HOLDS_ARRAY(x)        (G_VALUE_HOLDS((x), gst_value_array_get_type ()))
135
136 /**
137  * GST_VALUE_HOLDS_CAPS:
138  * @x: the #GValue to check
139  *
140  * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
141  */
142 #define GST_VALUE_HOLDS_CAPS(x)         (G_VALUE_HOLDS((x), GST_TYPE_CAPS))
143
144 /**
145  * GST_VALUE_HOLDS_STRUCTURE:
146  * @x: the #GValue to check
147  *
148  * Checks if the given #GValue contains a #GST_TYPE_STRUCTURE value.
149  *
150  * Since: 0.10.15
151  */
152 #define GST_VALUE_HOLDS_STRUCTURE(x)            (G_VALUE_HOLDS((x), GST_TYPE_STRUCTURE))
153
154 /**
155  * GST_VALUE_HOLDS_BUFFER:
156  * @x: the #GValue to check
157  *
158  * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
159  */
160 #define GST_VALUE_HOLDS_BUFFER(x)       (G_VALUE_HOLDS((x), GST_TYPE_BUFFER))
161
162 /**
163  * GST_VALUE_HOLDS_FRACTION:
164  * @x: the #GValue to check
165  *
166  * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
167  */
168 #define GST_VALUE_HOLDS_FRACTION(x)     (G_VALUE_HOLDS((x), gst_fraction_get_type ()))
169
170 /**
171  * GST_VALUE_HOLDS_DATE:
172  * @x: the #GValue to check
173  *
174  * Checks if the given #GValue contains a #GST_TYPE_DATE value.
175  */
176 #define GST_VALUE_HOLDS_DATE(x)         (G_VALUE_HOLDS((x), gst_date_get_type ()))
177
178 /**
179  * GST_VALUE_HOLDS_DATE_TIME:
180  * @x: the #GValue to check
181  *
182  * Checks if the given #GValue contains a #GST_TYPE_DATE_TIME value.
183  *
184  * Since: 0.10.31
185  */
186 #define GST_VALUE_HOLDS_DATE_TIME(x)    (G_VALUE_HOLDS((x), gst_date_time_get_type ()))
187
188 /**
189  * GST_TYPE_FOURCC:
190  *
191  * a #GValue type that represents 4 byte identifier (e.g. used for codecs)
192  *
193  * Returns: the #GType of GstFourcc
194  */
195 #define GST_TYPE_FOURCC                  gst_fourcc_get_type ()
196
197 /**
198  * GST_TYPE_INT_RANGE:
199  *
200  * a #GValue type that represents an integer range
201  *
202  * Returns: the #GType of GstIntRange
203  */
204 #define GST_TYPE_INT_RANGE               gst_int_range_get_type ()
205
206 /**
207  * GST_TYPE_DOUBLE_RANGE:
208  *
209  * a #GValue type that represents a floating point range with double precission
210  *
211  * Returns: the #GType of GstIntRange
212  */
213 #define GST_TYPE_DOUBLE_RANGE            gst_double_range_get_type ()
214
215 /**
216  * GST_TYPE_FRACTION_RANGE:
217  *
218  * a #GValue type that represents a GstFraction range
219  *
220  * Returns: the #GType of GstFractionRange
221  */
222 #define GST_TYPE_FRACTION_RANGE            gst_fraction_range_get_type ()
223
224 /**
225  * GST_TYPE_LIST:
226  *
227  * a #GValue type that represents an unordered list of #GValue values. This
228  * is used for example to express a list of possible values for a field in
229  * a caps structure, like a list of possible sample rates, of which only one
230  * will be chosen in the end. This means that all values in the list are
231  * meaningful on their own.
232  *
233  * Returns: the #GType of GstValueList (which is not explicitly typed)
234  */
235 #define GST_TYPE_LIST                    gst_value_list_get_type ()
236
237 /**
238  * GST_TYPE_ARRAY:
239  *
240  * a #GValue type that represents an ordered list of #GValue values. This is
241  * used to express a set of values that is meaningful only in their specific
242  * combination and order of values. Each value on its own is not particularly
243  * meaningful, only the ordered array in its entirety is meaningful. This is
244  * used for example to express channel layouts for multichannel audio where
245  * each channel needs to be mapped to a position in the room.
246  *
247  * Returns: the #GType of GstArrayList (which is not explicitly typed)
248  */
249 #define GST_TYPE_ARRAY                   gst_value_array_get_type ()
250
251 /**
252  * GST_TYPE_FRACTION:
253  *
254  * a #GValue type that represents a fraction of an integer numerator over
255  * an integer denominator
256  *
257  * Returns: the #GType of GstFraction (which is not explicitly typed)
258  */
259
260 #define GST_TYPE_FRACTION                gst_fraction_get_type ()
261
262 /**
263  * GST_TYPE_DATE:
264  *
265  * a boxed #GValue type for #GDate that represents a date.
266  *
267  * Returns: the #GType of GstDate
268  */
269
270 #define GST_TYPE_DATE                    gst_date_get_type ()
271
272 /**
273  * GST_TYPE_DATE_TIME:
274  *
275  * a boxed #GValue type for #GstDateTime that represents a date and time.
276  *
277  * Returns: the #GType of GstDateTime
278  * Since: 0.10.31
279  */
280
281 #define GST_TYPE_DATE_TIME               gst_date_time_get_type ()
282
283 /**
284  * GST_VALUE_LESS_THAN:
285  *
286  * Indicates that the first value provided to a comparison function
287  * (gst_value_compare()) is lesser than the second one.
288  */
289 #define GST_VALUE_LESS_THAN              (-1)
290
291 /**
292  * GST_VALUE_EQUAL:
293  *
294  * Indicates that the first value provided to a comparison function
295  * (gst_value_compare()) is equal to the second one.
296  */
297 #define GST_VALUE_EQUAL                   0
298
299 /**
300  * GST_VALUE_GREATER_THAN:
301  *
302  * Indicates that the first value provided to a comparison function
303  * (gst_value_compare()) is greater than the second one.
304  */
305 #define GST_VALUE_GREATER_THAN            1
306
307 /**
308  * GST_VALUE_UNORDERED:
309  *
310  * Indicates that the comparison function (gst_value_compare()) can not
311  * determine a order for the two provided values.
312  */
313 #define GST_VALUE_UNORDERED               2
314
315 /**
316  * GstValueCompareFunc:
317  * @value1: first value for comparison
318  * @value2: second value for comparison
319  *
320  * Used together with gst_value_compare() to compare #GValue items.
321  *
322  * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
323  * or GST_VALUE_UNORDERED
324  */
325 typedef gint     (* GstValueCompareFunc)     (const GValue *value1,
326                                               const GValue *value2);
327
328 /**
329  * GstValueSerializeFunc:
330  * @value1: a #GValue
331  *
332  * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
333  *
334  * Returns: the string representation of the value
335  */
336 typedef gchar *  (* GstValueSerializeFunc)   (const GValue *value1);
337
338 /**
339  * GstValueDeserializeFunc:
340  * @dest: a #GValue
341  * @s: a string
342  *
343  * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
344  *
345  * Returns: %TRUE for success
346  */
347 typedef gboolean (* GstValueDeserializeFunc) (GValue       *dest,
348                                               const gchar  *s);
349
350 /**
351  * GstValueUnionFunc:
352  * @dest: a #GValue for the result
353  * @value1: a #GValue operand
354  * @value2: a #GValue operand
355  *
356  * Used by gst_value_union() to perform unification for a specific #GValue
357  * type. Register a new implementation with gst_value_register_union_func().
358  *
359  * Returns: %TRUE if a union was successful
360  */
361 typedef gboolean (* GstValueUnionFunc)       (GValue       *dest,
362                                               const GValue *value1,
363                                               const GValue *value2);
364
365 /**
366  * GstValueIntersectFunc:
367  * @dest: a #GValue for the result
368  * @value1: a #GValue operand
369  * @value2: a #GValue operand
370  *
371  * Used by gst_value_intersect() to perform intersection for a specific #GValue
372  * type. If the intersection is non-empty, the result is
373  * placed in @dest and TRUE is returned.  If the intersection is
374  * empty, @dest is unmodified and FALSE is returned.
375  * Register a new implementation with gst_value_register_intersect_func().
376  *
377  * Returns: %TRUE if the values can intersect
378  */
379 typedef gboolean (* GstValueIntersectFunc)   (GValue       *dest,
380                                               const GValue *value1,
381                                               const GValue *value2);
382
383 /**
384  * GstValueSubtractFunc:
385  * @dest: a #GValue for the result
386  * @minuend: a #GValue operand
387  * @subtrahend: a #GValue operand
388  *
389  * Used by gst_value_subtract() to perform subtraction for a specific #GValue
390  * type. Register a new implementation with gst_value_register_subtract_func().
391  *
392  * Returns: %TRUE if the subtraction is not empty
393  */
394 typedef gboolean (* GstValueSubtractFunc)    (GValue       *dest,
395                                               const GValue *minuend,
396                                               const GValue *subtrahend);
397
398 typedef struct _GstValueTable GstValueTable;
399 /**
400  * GstValueTable:
401  * @type: a #GType
402  * @compare: a #GstValueCompareFunc
403  * @serialize: a #GstValueSerializeFunc
404  * @deserialize: a #GstValueDeserializeFunc
405  *
406  * VTable for the #GValue @type.
407  */
408 struct _GstValueTable {
409   GType type;
410   GstValueCompareFunc compare;
411   GstValueSerializeFunc serialize;
412   GstValueDeserializeFunc deserialize;
413
414   /*< private >*/
415   void *_gst_reserved [GST_PADDING];
416 };
417
418 GType gst_int_range_get_type (void);
419 GType gst_double_range_get_type (void);
420 GType gst_fraction_range_get_type (void);
421 GType gst_fourcc_get_type (void);
422 GType gst_fraction_get_type (void);
423 GType gst_value_list_get_type (void);
424 GType gst_value_array_get_type (void);
425
426 GType gst_date_get_type (void);
427 GType gst_date_time_get_type (void);
428
429 void            gst_value_register              (const GstValueTable   *table);
430 void            gst_value_init_and_copy         (GValue                *dest,
431                                                  const GValue          *src);
432
433 gchar *         gst_value_serialize             (const GValue          *value);
434 gboolean        gst_value_deserialize           (GValue                *dest,
435                                                  const gchar           *src);
436
437 /* list */
438 void            gst_value_list_append_value     (GValue         *value,
439                                                  const GValue   *append_value);
440 void            gst_value_list_prepend_value    (GValue         *value,
441                                                  const GValue   *prepend_value);
442 void            gst_value_list_concat           (GValue         *dest,
443                                                  const GValue   *value1,
444                                                  const GValue   *value2);
445 guint           gst_value_list_get_size         (const GValue   *value);
446 G_CONST_RETURN GValue *
447                 gst_value_list_get_value        (const GValue   *value,
448                                                  guint          index);
449
450 /* array */
451 void            gst_value_array_append_value    (GValue         *value,
452                                                  const GValue   *append_value);
453 void            gst_value_array_prepend_value   (GValue         *value,
454                                                  const GValue   *prepend_value);
455 guint           gst_value_array_get_size        (const GValue   *value);
456 G_CONST_RETURN GValue *
457                 gst_value_array_get_value       (const GValue   *value,
458                                                  guint          index);
459
460 /* fourcc */
461 void            gst_value_set_fourcc            (GValue         *value,
462                                                  guint32        fourcc);
463 guint32         gst_value_get_fourcc            (const GValue   *value);
464
465 /* int range */
466 void            gst_value_set_int_range         (GValue         *value,
467                                                  gint           start,
468                                                  gint           end);
469 gint            gst_value_get_int_range_min     (const GValue   *value);
470 gint            gst_value_get_int_range_max     (const GValue   *value);
471
472 /* double range */
473 void            gst_value_set_double_range      (GValue         *value,
474                                                  gdouble        start,
475                                                  gdouble        end);
476 gdouble         gst_value_get_double_range_min  (const GValue   *value);
477 gdouble         gst_value_get_double_range_max  (const GValue   *value);
478
479 /* caps */
480 G_CONST_RETURN GstCaps *
481                 gst_value_get_caps              (const GValue   *value);
482 void            gst_value_set_caps              (GValue         *value,
483                                                  const GstCaps  *caps);
484
485 /* structure */
486 G_CONST_RETURN GstStructure *
487                 gst_value_get_structure         (const GValue   *value);
488 void            gst_value_set_structure         (GValue         *value,
489                                                  const GstStructure  *structure);
490
491 /* fraction */
492 void            gst_value_set_fraction          (GValue         *value,
493                                                  gint           numerator,
494                                                  gint           denominator);
495 gint            gst_value_get_fraction_numerator (const GValue  *value);
496 gint            gst_value_get_fraction_denominator(const GValue *value);
497 gboolean        gst_value_fraction_multiply     (GValue         *product,
498                                                  const GValue   *factor1,
499                                                  const GValue   *factor2);
500 gboolean        gst_value_fraction_subtract (GValue * dest,
501                                              const GValue * minuend, 
502                                              const GValue * subtrahend);
503
504 /* fraction range */
505 void            gst_value_set_fraction_range    (GValue         *value,
506                                                  const GValue   *start,
507                                                  const GValue   *end);
508 void            gst_value_set_fraction_range_full (GValue       *value,
509                                                  gint numerator_start, 
510                                                  gint denominator_start,
511                                                  gint numerator_end, 
512                                                  gint denominator_end);
513 const GValue    *gst_value_get_fraction_range_min (const GValue *value);
514 const GValue    *gst_value_get_fraction_range_max (const GValue *value);
515
516 /* date */
517 G_CONST_RETURN GDate *
518                 gst_value_get_date              (const GValue   *value);
519 void            gst_value_set_date              (GValue         *value,
520                                                  const GDate    *date);
521
522 /* compare */
523 gint            gst_value_compare               (const GValue   *value1,
524                                                  const GValue   *value2);
525 gboolean        gst_value_can_compare           (const GValue   *value1,
526                                                  const GValue   *value2);
527 /* union */
528 gboolean        gst_value_union                 (GValue         *dest,
529                                                  const GValue   *value1,
530                                                  const GValue   *value2);
531 gboolean        gst_value_can_union             (const GValue   *value1,
532                                                  const GValue   *value2);
533 void            gst_value_register_union_func   (GType          type1,
534                                                  GType          type2,
535                                                  GstValueUnionFunc func);
536
537 /* intersection */
538 gboolean        gst_value_intersect             (GValue         *dest,
539                                                  const GValue   *value1,
540                                                  const GValue   *value2);
541 gboolean        gst_value_can_intersect         (const GValue   *value1,
542                                                  const GValue   *value2);
543 void            gst_value_register_intersect_func (GType        type1,
544                                                 GType           type2,
545                                                 GstValueIntersectFunc func);
546
547 /* subtraction */
548 gboolean        gst_value_subtract              (GValue         *dest,
549                                                  const GValue   *minuend,
550                                                  const GValue   *subtrahend);
551 gboolean        gst_value_can_subtract          (const GValue   *minuend,
552                                                  const GValue   *subtrahend);
553 void            gst_value_register_subtract_func (GType         minuend_type,
554                                                 GType           subtrahend_type,
555                                                 GstValueSubtractFunc func);
556
557 /* fixation */
558 gboolean        gst_value_is_fixed              (const GValue   *value);
559
560 G_END_DECLS
561
562 #endif
563
564