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