2.0 beta init
[framework/multimedia/gstreamer0.10.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_INT64_RANGE:
106  * @x: the #GValue to check
107  *
108  * Checks if the given #GValue contains a #GST_TYPE_INT64_RANGE value.
109  *
110  * Since: 0.10.31
111  */
112 #define GST_VALUE_HOLDS_INT64_RANGE(x)    (G_VALUE_HOLDS((x), gst_int64_range_get_type ()))
113
114 /**
115  * GST_VALUE_HOLDS_DOUBLE_RANGE:
116  * @x: the #GValue to check
117  *
118  * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
119  */
120 #define GST_VALUE_HOLDS_DOUBLE_RANGE(x) (G_VALUE_HOLDS((x), gst_double_range_get_type ()))
121
122 /**
123  * GST_VALUE_HOLDS_FRACTION_RANGE:
124  * @x: the #GValue to check
125  *
126  * Checks if the given #GValue contains a #GST_TYPE_FRACTION_RANGE value.
127  */
128 #define GST_VALUE_HOLDS_FRACTION_RANGE(x)    (G_VALUE_HOLDS((x), gst_fraction_range_get_type ()))
129
130 /**
131  * GST_VALUE_HOLDS_LIST:
132  * @x: the #GValue to check
133  *
134  * Checks if the given #GValue contains a #GST_TYPE_LIST value.
135  */
136 #define GST_VALUE_HOLDS_LIST(x)         (G_VALUE_HOLDS((x), gst_value_list_get_type ()))
137
138 /**
139  * GST_VALUE_HOLDS_ARRAY:
140  * @x: the #GValue to check
141  *
142  * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
143  */
144 #define GST_VALUE_HOLDS_ARRAY(x)        (G_VALUE_HOLDS((x), gst_value_array_get_type ()))
145
146 /**
147  * GST_VALUE_HOLDS_CAPS:
148  * @x: the #GValue to check
149  *
150  * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
151  */
152 #define GST_VALUE_HOLDS_CAPS(x)         (G_VALUE_HOLDS((x), GST_TYPE_CAPS))
153
154 /**
155  * GST_VALUE_HOLDS_STRUCTURE:
156  * @x: the #GValue to check
157  *
158  * Checks if the given #GValue contains a #GST_TYPE_STRUCTURE value.
159  *
160  * Since: 0.10.15
161  */
162 #define GST_VALUE_HOLDS_STRUCTURE(x)            (G_VALUE_HOLDS((x), GST_TYPE_STRUCTURE))
163
164 /**
165  * GST_VALUE_HOLDS_BUFFER:
166  * @x: the #GValue to check
167  *
168  * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
169  */
170 #define GST_VALUE_HOLDS_BUFFER(x)       (G_VALUE_HOLDS((x), GST_TYPE_BUFFER))
171
172 /**
173  * GST_VALUE_HOLDS_FRACTION:
174  * @x: the #GValue to check
175  *
176  * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
177  */
178 #define GST_VALUE_HOLDS_FRACTION(x)     (G_VALUE_HOLDS((x), gst_fraction_get_type ()))
179
180 /**
181  * GST_VALUE_HOLDS_DATE:
182  * @x: the #GValue to check
183  *
184  * Checks if the given #GValue contains a #GST_TYPE_DATE value.
185  */
186 #define GST_VALUE_HOLDS_DATE(x)         (G_VALUE_HOLDS((x), gst_date_get_type ()))
187
188 /**
189  * GST_VALUE_HOLDS_DATE_TIME:
190  * @x: the #GValue to check
191  *
192  * Checks if the given #GValue contains a #GST_TYPE_DATE_TIME value.
193  *
194  * Since: 0.10.31
195  */
196 #define GST_VALUE_HOLDS_DATE_TIME(x)    (G_VALUE_HOLDS((x), gst_date_time_get_type ()))
197
198 /**
199  * GST_TYPE_FOURCC:
200  *
201  * a #GValue type that represents 4 byte identifier (e.g. used for codecs)
202  *
203  * Returns: the #GType of GstFourcc
204  */
205 #define GST_TYPE_FOURCC                  gst_fourcc_get_type ()
206
207 /**
208  * GST_TYPE_INT_RANGE:
209  *
210  * a #GValue type that represents an integer range
211  *
212  * Returns: the #GType of GstIntRange
213  */
214 #define GST_TYPE_INT_RANGE               gst_int_range_get_type ()
215
216 /**
217  * GST_TYPE_INT64_RANGE:
218  *
219  * a #GValue type that represents an #gint64 range
220  *
221  * Returns: the #GType of GstInt64Range
222  *
223  * Since: 0.10.31
224  */
225 #define GST_TYPE_INT64_RANGE             gst_int64_range_get_type ()
226
227 /**
228  * GST_TYPE_DOUBLE_RANGE:
229  *
230  * a #GValue type that represents a floating point range with double precission
231  *
232  * Returns: the #GType of GstIntRange
233  */
234 #define GST_TYPE_DOUBLE_RANGE            gst_double_range_get_type ()
235
236 /**
237  * GST_TYPE_FRACTION_RANGE:
238  *
239  * a #GValue type that represents a GstFraction range
240  *
241  * Returns: the #GType of GstFractionRange
242  */
243 #define GST_TYPE_FRACTION_RANGE            gst_fraction_range_get_type ()
244
245 /**
246  * GST_TYPE_LIST:
247  *
248  * a #GValue type that represents an unordered list of #GValue values. This
249  * is used for example to express a list of possible values for a field in
250  * a caps structure, like a list of possible sample rates, of which only one
251  * will be chosen in the end. This means that all values in the list are
252  * meaningful on their own.
253  *
254  * Returns: the #GType of GstValueList (which is not explicitly typed)
255  */
256 #define GST_TYPE_LIST                    gst_value_list_get_type ()
257
258 /**
259  * GST_TYPE_ARRAY:
260  *
261  * a #GValue type that represents an ordered list of #GValue values. This is
262  * used to express a set of values that is meaningful only in their specific
263  * combination and order of values. Each value on its own is not particularly
264  * meaningful, only the ordered array in its entirety is meaningful. This is
265  * used for example to express channel layouts for multichannel audio where
266  * each channel needs to be mapped to a position in the room.
267  *
268  * Returns: the #GType of GstArrayList (which is not explicitly typed)
269  */
270 #define GST_TYPE_ARRAY                   gst_value_array_get_type ()
271
272 /**
273  * GST_TYPE_FRACTION:
274  *
275  * a #GValue type that represents a fraction of an integer numerator over
276  * an integer denominator
277  *
278  * Returns: the #GType of GstFraction (which is not explicitly typed)
279  */
280
281 #define GST_TYPE_FRACTION                gst_fraction_get_type ()
282
283 /**
284  * GST_TYPE_DATE:
285  *
286  * a boxed #GValue type for #GDate that represents a date.
287  *
288  * Returns: the #GType of GstDate
289  */
290
291 #define GST_TYPE_DATE                    gst_date_get_type ()
292
293 /**
294  * GST_TYPE_DATE_TIME:
295  *
296  * a boxed #GValue type for #GstDateTime that represents a date and time.
297  *
298  * Returns: the #GType of GstDateTime
299  * Since: 0.10.31
300  */
301
302 #define GST_TYPE_DATE_TIME               gst_date_time_get_type ()
303
304 /**
305  * GST_VALUE_LESS_THAN:
306  *
307  * Indicates that the first value provided to a comparison function
308  * (gst_value_compare()) is lesser than the second one.
309  */
310 #define GST_VALUE_LESS_THAN              (-1)
311
312 /**
313  * GST_VALUE_EQUAL:
314  *
315  * Indicates that the first value provided to a comparison function
316  * (gst_value_compare()) is equal to the second one.
317  */
318 #define GST_VALUE_EQUAL                   0
319
320 /**
321  * GST_VALUE_GREATER_THAN:
322  *
323  * Indicates that the first value provided to a comparison function
324  * (gst_value_compare()) is greater than the second one.
325  */
326 #define GST_VALUE_GREATER_THAN            1
327
328 /**
329  * GST_VALUE_UNORDERED:
330  *
331  * Indicates that the comparison function (gst_value_compare()) can not
332  * determine a order for the two provided values.
333  */
334 #define GST_VALUE_UNORDERED               2
335
336 /**
337  * GstValueCompareFunc:
338  * @value1: first value for comparison
339  * @value2: second value for comparison
340  *
341  * Used together with gst_value_compare() to compare #GValue items.
342  *
343  * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
344  * or GST_VALUE_UNORDERED
345  */
346 typedef gint     (* GstValueCompareFunc)     (const GValue *value1,
347                                               const GValue *value2);
348
349 /**
350  * GstValueSerializeFunc:
351  * @value1: a #GValue
352  *
353  * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
354  *
355  * Free-function: g_free
356  *
357  * Returns: (transfer full): the string representation of the value
358  */
359 typedef gchar *  (* GstValueSerializeFunc)   (const GValue *value1);
360
361 /**
362  * GstValueDeserializeFunc:
363  * @dest: a #GValue
364  * @s: a string
365  *
366  * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
367  *
368  * Returns: %TRUE for success
369  */
370 typedef gboolean (* GstValueDeserializeFunc) (GValue       *dest,
371                                               const gchar  *s);
372
373 /**
374  * GstValueUnionFunc:
375  * @dest: a #GValue for the result
376  * @value1: a #GValue operand
377  * @value2: a #GValue operand
378  *
379  * Used by gst_value_union() to perform unification for a specific #GValue
380  * type. Register a new implementation with gst_value_register_union_func().
381  *
382  * Returns: %TRUE if a union was successful
383  */
384 typedef gboolean (* GstValueUnionFunc)       (GValue       *dest,
385                                               const GValue *value1,
386                                               const GValue *value2);
387
388 /**
389  * GstValueIntersectFunc:
390  * @dest: (out caller-allocates): a #GValue for the result
391  * @value1: a #GValue operand
392  * @value2: a #GValue operand
393  *
394  * Used by gst_value_intersect() to perform intersection for a specific #GValue
395  * type. If the intersection is non-empty, the result is
396  * placed in @dest and TRUE is returned.  If the intersection is
397  * empty, @dest is unmodified and FALSE is returned.
398  * Register a new implementation with gst_value_register_intersect_func().
399  *
400  * Returns: %TRUE if the values can intersect
401  */
402 typedef gboolean (* GstValueIntersectFunc)   (GValue       *dest,
403                                               const GValue *value1,
404                                               const GValue *value2);
405
406 /**
407  * GstValueSubtractFunc:
408  * @dest: (out caller-allocates): a #GValue for the result
409  * @minuend: a #GValue operand
410  * @subtrahend: a #GValue operand
411  *
412  * Used by gst_value_subtract() to perform subtraction for a specific #GValue
413  * type. Register a new implementation with gst_value_register_subtract_func().
414  *
415  * Returns: %TRUE if the subtraction is not empty
416  */
417 typedef gboolean (* GstValueSubtractFunc)    (GValue       *dest,
418                                               const GValue *minuend,
419                                               const GValue *subtrahend);
420
421 typedef struct _GstValueTable GstValueTable;
422 /**
423  * GstValueTable:
424  * @type: a #GType
425  * @compare: a #GstValueCompareFunc
426  * @serialize: a #GstValueSerializeFunc
427  * @deserialize: a #GstValueDeserializeFunc
428  *
429  * VTable for the #GValue @type.
430  */
431 struct _GstValueTable {
432   GType type;
433   GstValueCompareFunc compare;
434   GstValueSerializeFunc serialize;
435   GstValueDeserializeFunc deserialize;
436
437   /*< private >*/
438   void *_gst_reserved [GST_PADDING];
439 };
440
441 GType gst_int_range_get_type (void);
442 GType gst_int64_range_get_type (void);
443 GType gst_double_range_get_type (void);
444 GType gst_fraction_range_get_type (void);
445 GType gst_fourcc_get_type (void);
446 GType gst_fraction_get_type (void);
447 GType gst_value_list_get_type (void);
448 GType gst_value_array_get_type (void);
449
450 GType gst_date_get_type (void);
451 GType gst_date_time_get_type (void);
452
453 void            gst_value_register              (const GstValueTable   *table);
454 void            gst_value_init_and_copy         (GValue                *dest,
455                                                  const GValue          *src);
456
457 gchar *         gst_value_serialize             (const GValue          *value) G_GNUC_MALLOC;
458 gboolean        gst_value_deserialize           (GValue                *dest,
459                                                  const gchar           *src);
460
461 /* list */
462 void            gst_value_list_append_value     (GValue         *value,
463                                                  const GValue   *append_value);
464 void            gst_value_list_prepend_value    (GValue         *value,
465                                                  const GValue   *prepend_value);
466 void            gst_value_list_concat           (GValue         *dest,
467                                                  const GValue   *value1,
468                                                  const GValue   *value2);
469 void            gst_value_list_merge            (GValue         *dest,
470                                                  const GValue   *value1,
471                                                  const GValue   *value2);
472 guint           gst_value_list_get_size         (const GValue   *value);
473 const GValue *  gst_value_list_get_value        (const GValue   *value,
474                                                  guint          index);
475
476 /* array */
477 void            gst_value_array_append_value    (GValue         *value,
478                                                  const GValue   *append_value);
479 void            gst_value_array_prepend_value   (GValue         *value,
480                                                  const GValue   *prepend_value);
481 guint           gst_value_array_get_size        (const GValue   *value);
482 const GValue *  gst_value_array_get_value       (const GValue   *value,
483                                                  guint          index);
484
485 /* fourcc */
486 void            gst_value_set_fourcc            (GValue         *value,
487                                                  guint32        fourcc);
488 guint32         gst_value_get_fourcc            (const GValue   *value);
489
490 /* int range */
491 void            gst_value_set_int_range         (GValue         *value,
492                                                  gint           start,
493                                                  gint           end);
494 gint            gst_value_get_int_range_min     (const GValue   *value);
495 gint            gst_value_get_int_range_max     (const GValue   *value);
496
497 /* int64 range */
498 void            gst_value_set_int64_range       (GValue         *value,
499                                                  gint64         start,
500                                                  gint64         end);
501 gint64          gst_value_get_int64_range_min   (const GValue   *value);
502 gint64          gst_value_get_int64_range_max   (const GValue   *value);
503
504 /* double range */
505 void            gst_value_set_double_range      (GValue         *value,
506                                                  gdouble        start,
507                                                  gdouble        end);
508 gdouble         gst_value_get_double_range_min  (const GValue   *value);
509 gdouble         gst_value_get_double_range_max  (const GValue   *value);
510
511 /* caps */
512 const GstCaps * gst_value_get_caps              (const GValue   *value);
513 void            gst_value_set_caps              (GValue         *value,
514                                                  const GstCaps  *caps);
515
516 /* structure */
517 const GstStructure *
518                 gst_value_get_structure         (const GValue   *value);
519 void            gst_value_set_structure         (GValue         *value,
520                                                  const GstStructure  *structure);
521
522 /* fraction */
523 void            gst_value_set_fraction          (GValue         *value,
524                                                  gint           numerator,
525                                                  gint           denominator);
526 gint            gst_value_get_fraction_numerator (const GValue  *value);
527 gint            gst_value_get_fraction_denominator(const GValue *value);
528 gboolean        gst_value_fraction_multiply     (GValue         *product,
529                                                  const GValue   *factor1,
530                                                  const GValue   *factor2);
531 gboolean        gst_value_fraction_subtract (GValue * dest,
532                                              const GValue * minuend, 
533                                              const GValue * subtrahend);
534
535 /* fraction range */
536 void            gst_value_set_fraction_range    (GValue         *value,
537                                                  const GValue   *start,
538                                                  const GValue   *end);
539 void            gst_value_set_fraction_range_full (GValue       *value,
540                                                  gint numerator_start, 
541                                                  gint denominator_start,
542                                                  gint numerator_end, 
543                                                  gint denominator_end);
544 const GValue    *gst_value_get_fraction_range_min (const GValue *value);
545 const GValue    *gst_value_get_fraction_range_max (const GValue *value);
546
547 /* date */
548 const GDate *   gst_value_get_date              (const GValue   *value);
549 void            gst_value_set_date              (GValue         *value,
550                                                  const GDate    *date);
551
552 /* compare */
553 gint            gst_value_compare               (const GValue   *value1,
554                                                  const GValue   *value2);
555 gboolean        gst_value_can_compare           (const GValue   *value1,
556                                                  const GValue   *value2);
557 /* union */
558 gboolean        gst_value_union                 (GValue         *dest,
559                                                  const GValue   *value1,
560                                                  const GValue   *value2);
561 gboolean        gst_value_can_union             (const GValue   *value1,
562                                                  const GValue   *value2);
563 void            gst_value_register_union_func   (GType          type1,
564                                                  GType          type2,
565                                                  GstValueUnionFunc func);
566
567 /* intersection */
568 gboolean        gst_value_intersect             (GValue         *dest,
569                                                  const GValue   *value1,
570                                                  const GValue   *value2);
571 gboolean        gst_value_can_intersect         (const GValue   *value1,
572                                                  const GValue   *value2);
573 void            gst_value_register_intersect_func (GType        type1,
574                                                 GType           type2,
575                                                 GstValueIntersectFunc func);
576
577 /* subtraction */
578 gboolean        gst_value_subtract              (GValue         *dest,
579                                                  const GValue   *minuend,
580                                                  const GValue   *subtrahend);
581 gboolean        gst_value_can_subtract          (const GValue   *minuend,
582                                                  const GValue   *subtrahend);
583 void            gst_value_register_subtract_func (GType         minuend_type,
584                                                 GType           subtrahend_type,
585                                                 GstValueSubtractFunc func);
586
587 /* fixation */
588 gboolean        gst_value_is_fixed              (const GValue   *value);
589
590 G_END_DECLS
591
592 #endif
593
594