2 * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
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.
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.
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.
20 #ifndef __GST_VALUE_H__
21 #define __GST_VALUE_H__
23 #include <gst/gstconfig.h>
24 #include <gst/gstcaps.h>
25 #include <gst/gststructure.h>
31 * @a: the first character
32 * @b: the second character
33 * @c: the third character
34 * @d: the fourth character
36 * Transform four characters into a #guint32 fourcc value with host
40 * guint32 fourcc = GST_MAKE_FOURCC ('M', 'J', 'P', 'G');
44 #define GST_MAKE_FOURCC(a,b,c,d) (guint32)((a)|(b)<<8|(c)<<16|(d)<<24)
48 * @f: a string with at least four characters
50 * Transform an input string into a #guint32 fourcc value with host
52 * Caller is responsible for ensuring the input string consists of at least
56 * guint32 fourcc = GST_STR_FOURCC ("MJPG");
60 #define GST_STR_FOURCC(f) (guint32)(((f)[0])|((f)[1]<<8)|((f)[2]<<16)|((f)[3]<<24))
65 * Can be used together with #GST_FOURCC_ARGS to properly output a
66 * #guint32 fourcc value in a printf()-style text message.
69 * printf ("fourcc: %" GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS (fcc));
73 #define GST_FOURCC_FORMAT "c%c%c%c"
77 * @fourcc: a #guint32 fourcc value to output
79 * Can be used together with #GST_FOURCC_FORMAT to properly output a
80 * #guint32 fourcc value in a printf()-style text message.
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))
89 * GST_VALUE_HOLDS_FOURCC:
90 * @x: the #GValue to check
92 * Checks if the given #GValue contains a #GST_TYPE_FOURCC value.
94 #define GST_VALUE_HOLDS_FOURCC(x) (G_VALUE_HOLDS(x, gst_fourcc_get_type ()))
97 * GST_VALUE_HOLDS_INT_RANGE:
98 * @x: the #GValue to check
100 * Checks if the given #GValue contains a #GST_TYPE_INT_RANGE value.
102 #define GST_VALUE_HOLDS_INT_RANGE(x) (G_VALUE_HOLDS(x, gst_int_range_get_type ()))
105 * GST_VALUE_HOLDS_DOUBLE_RANGE:
106 * @x: the #GValue to check
108 * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
110 #define GST_VALUE_HOLDS_DOUBLE_RANGE(x) (G_VALUE_HOLDS(x, gst_double_range_get_type ()))
113 * GST_VALUE_HOLDS_FRACTION_RANGE:
114 * @x: the #GValue to check
116 * Checks if the given #GValue contains a #GST_TYPE_FRACTION_RANGE value.
118 #define GST_VALUE_HOLDS_FRACTION_RANGE(x) (G_VALUE_HOLDS(x, gst_fraction_range_get_type ()))
121 * GST_VALUE_HOLDS_LIST:
122 * @x: the #GValue to check
124 * Checks if the given #GValue contains a #GST_TYPE_LIST value.
126 #define GST_VALUE_HOLDS_LIST(x) (G_VALUE_HOLDS(x, gst_value_list_get_type ()))
129 * GST_VALUE_HOLDS_ARRAY:
130 * @x: the #GValue to check
132 * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
134 #define GST_VALUE_HOLDS_ARRAY(x) (G_VALUE_HOLDS(x, gst_value_array_get_type ()))
137 * GST_VALUE_HOLDS_CAPS:
138 * @x: the #GValue to check
140 * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
142 #define GST_VALUE_HOLDS_CAPS(x) (G_VALUE_HOLDS(x, GST_TYPE_CAPS))
145 * GST_VALUE_HOLDS_STRUCTURE:
146 * @x: the #GValue to check
148 * Checks if the given #GValue contains a #GST_TYPE_STRUCTURE value.
152 #define GST_VALUE_HOLDS_STRUCTURE(x) (G_VALUE_HOLDS(x, GST_TYPE_STRUCTURE))
155 * GST_VALUE_HOLDS_BUFFER:
156 * @x: the #GValue to check
158 * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
160 #define GST_VALUE_HOLDS_BUFFER(x) (G_VALUE_HOLDS(x, GST_TYPE_BUFFER))
163 * GST_VALUE_HOLDS_FRACTION:
164 * @x: the #GValue to check
166 * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
168 #define GST_VALUE_HOLDS_FRACTION(x) (G_VALUE_HOLDS(x, gst_fraction_get_type ()))
171 * GST_VALUE_HOLDS_DATE:
172 * @x: the #GValue to check
174 * Checks if the given #GValue contains a #GST_TYPE_DATE value.
176 #define GST_VALUE_HOLDS_DATE(x) (G_VALUE_HOLDS(x, gst_date_get_type ()))
181 * a #GValue type that represents 4 byte identifier (e.g. used for codecs)
183 * Returns: the #GType of GstFourcc
185 #define GST_TYPE_FOURCC gst_fourcc_get_type ()
188 * GST_TYPE_INT_RANGE:
190 * a #GValue type that represents an integer range
192 * Returns: the #GType of GstIntRange
194 #define GST_TYPE_INT_RANGE gst_int_range_get_type ()
197 * GST_TYPE_DOUBLE_RANGE:
199 * a #GValue type that represents a floating point range with double precission
201 * Returns: the #GType of GstIntRange
203 #define GST_TYPE_DOUBLE_RANGE gst_double_range_get_type ()
206 * GST_TYPE_FRACTION_RANGE:
208 * a #GValue type that represents a GstFraction range
210 * Returns: the #GType of GstFractionRange
212 #define GST_TYPE_FRACTION_RANGE gst_fraction_range_get_type ()
217 * a #GValue type that represents an unordered list of #GValue values. This
218 * is used for example to express a list of possible values for a field in
219 * a caps structure, like a list of possible sample rates, of which only one
220 * will be chosen in the end. This means that all values in the list are
221 * meaningful on their own.
223 * Returns: the #GType of GstValueList (which is not explicitly typed)
225 #define GST_TYPE_LIST gst_value_list_get_type ()
230 * a #GValue type that represents an ordered list of #GValue values. This is
231 * used to express a set of values that is meaningful only in their specific
232 * combination and order of values. Each value on its own is not particularly
233 * meaningful, only the ordered array in its entirety is meaningful. This is
234 * used for example to express channel layouts for multichannel audio where
235 * each channel needs to be mapped to a position in the room.
237 * Returns: the #GType of GstArrayList (which is not explicitly typed)
239 #define GST_TYPE_ARRAY gst_value_array_get_type ()
244 * a #GValue type that represents a fraction of an integer numerator over
245 * an integer denominator
247 * Returns: the #GType of GstFraction (which is not explicitly typed)
250 #define GST_TYPE_FRACTION gst_fraction_get_type ()
255 * a boxed #GValue type for #GDate that represents a date.
257 * Returns: the #GType of GstDate
260 #define GST_TYPE_DATE gst_date_get_type ()
263 * GST_VALUE_LESS_THAN:
265 * Indicates that the first value provided to a comparison function
266 * (gst_value_compare()) is lesser than the second one.
268 #define GST_VALUE_LESS_THAN (-1)
273 * Indicates that the first value provided to a comparison function
274 * (gst_value_compare()) is equal to the second one.
276 #define GST_VALUE_EQUAL 0
279 * GST_VALUE_GREATER_THAN:
281 * Indicates that the first value provided to a comparison function
282 * (gst_value_compare()) is greater than the second one.
284 #define GST_VALUE_GREATER_THAN 1
287 * GST_VALUE_UNORDERED:
289 * Indicates that the comparison function (gst_value_compare()) can not
290 * determine a order for the two provided values.
292 #define GST_VALUE_UNORDERED 2
295 * GstValueCompareFunc:
296 * @value1: first value for comparission
297 * @value2: second value for comparission
299 * Used together with gst_value_compare() to compare #GValues.
301 * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
302 * or GST_VALUE_UNORDERED
304 typedef gint (* GstValueCompareFunc) (const GValue *value1,
305 const GValue *value2);
308 * GstValueSerializeFunc:
311 * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
313 * Returns: the string representation of the value
315 typedef gchar * (* GstValueSerializeFunc) (const GValue *value1);
318 * GstValueDeserializeFunc:
322 * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
324 * Returns: %TRUE for success
326 typedef gboolean (* GstValueDeserializeFunc) (GValue *dest,
331 * @dest: a #GValue for the result
332 * @value1: a #GValue operand
333 * @value2: a #GValue operand
335 * Used by gst_value_union() to perform unification for a specific #GValue
336 * type. Register a new implementation with gst_value_register_union_func().
338 * Returns: %TRUE if a union was successful
340 typedef gboolean (* GstValueUnionFunc) (GValue *dest,
341 const GValue *value1,
342 const GValue *value2);
345 * GstValueIntersectFunc:
346 * @dest: a #GValue for the result
347 * @value1: a #GValue operand
348 * @value2: a #GValue operand
350 * Used by gst_value_intersect() to perform intersection for a specific #GValue
351 * type. If the intersection is non-empty, the result is
352 * placed in @dest and TRUE is returned. If the intersection is
353 * empty, @dest is unmodified and FALSE is returned.
354 * Register a new implementation with gst_value_register_intersection_func().
356 * Returns: %TRUE if the values can intersect
358 typedef gboolean (* GstValueIntersectFunc) (GValue *dest,
359 const GValue *value1,
360 const GValue *value2);
363 * GstValueSubtractFunc:
364 * @dest: a #GValue for the result
365 * @minuend: a #GValue operand
366 * @subtrahend: a #GValue operand
368 * Used by gst_value_subtract() to perform subtraction for a specific #GValue
369 * type. Register a new implementation with gst_value_register_subtract_func().
371 * Returns: %TRUE if the subtraction is not empty
373 typedef gboolean (* GstValueSubtractFunc) (GValue *dest,
374 const GValue *minuend,
375 const GValue *subtrahend);
377 typedef struct _GstValueTable GstValueTable;
381 * @compare: a #GstValueCompareFunc
382 * @serialize: a #GstValueSerializeFunc
383 * @deserialize: a #GstValueDeserializeFunc
385 * VTable for the #GValue @type.
387 struct _GstValueTable {
389 GstValueCompareFunc compare;
390 GstValueSerializeFunc serialize;
391 GstValueDeserializeFunc deserialize;
394 void *_gst_reserved [GST_PADDING];
397 GType gst_int_range_get_type (void);
398 GType gst_double_range_get_type (void);
399 GType gst_fraction_range_get_type (void);
400 GType gst_fourcc_get_type (void);
401 GType gst_fraction_get_type (void);
402 GType gst_value_list_get_type (void);
403 GType gst_value_array_get_type (void);
405 GType gst_date_get_type (void);
407 void gst_value_register (const GstValueTable *table);
408 void gst_value_init_and_copy (GValue *dest,
411 gchar * gst_value_serialize (const GValue *value);
412 gboolean gst_value_deserialize (GValue *dest,
416 void gst_value_list_append_value (GValue *value,
417 const GValue *append_value);
418 void gst_value_list_prepend_value (GValue *value,
419 const GValue *prepend_value);
420 void gst_value_list_concat (GValue *dest,
421 const GValue *value1,
422 const GValue *value2);
423 guint gst_value_list_get_size (const GValue *value);
424 G_CONST_RETURN GValue *
425 gst_value_list_get_value (const GValue *value,
429 void gst_value_array_append_value (GValue *value,
430 const GValue *append_value);
431 void gst_value_array_prepend_value (GValue *value,
432 const GValue *prepend_value);
433 guint gst_value_array_get_size (const GValue *value);
434 G_CONST_RETURN GValue *
435 gst_value_array_get_value (const GValue *value,
439 void gst_value_set_fourcc (GValue *value,
441 guint32 gst_value_get_fourcc (const GValue *value);
444 void gst_value_set_int_range (GValue *value,
447 gint gst_value_get_int_range_min (const GValue *value);
448 gint gst_value_get_int_range_max (const GValue *value);
451 void gst_value_set_double_range (GValue *value,
454 gdouble gst_value_get_double_range_min (const GValue *value);
455 gdouble gst_value_get_double_range_max (const GValue *value);
458 G_CONST_RETURN GstCaps *
459 gst_value_get_caps (const GValue *value);
460 void gst_value_set_caps (GValue *value,
461 const GstCaps *caps);
464 G_CONST_RETURN GstStructure *
465 gst_value_get_structure (const GValue *value);
466 void gst_value_set_structure (GValue *value,
467 const GstStructure *structure);
470 void gst_value_set_fraction (GValue *value,
473 gint gst_value_get_fraction_numerator (const GValue *value);
474 gint gst_value_get_fraction_denominator(const GValue *value);
475 gboolean gst_value_fraction_multiply (GValue *product,
476 const GValue *factor1,
477 const GValue *factor2);
478 gboolean gst_value_fraction_subtract (GValue * dest,
479 const GValue * minuend,
480 const GValue * subtrahend);
483 void gst_value_set_fraction_range (GValue *value,
486 void gst_value_set_fraction_range_full (GValue *value,
487 gint numerator_start,
488 gint denominator_start,
490 gint denominator_end);
491 const GValue *gst_value_get_fraction_range_min (const GValue *value);
492 const GValue *gst_value_get_fraction_range_max (const GValue *value);
495 G_CONST_RETURN GDate *
496 gst_value_get_date (const GValue *value);
497 void gst_value_set_date (GValue *value,
501 gint gst_value_compare (const GValue *value1,
502 const GValue *value2);
503 gboolean gst_value_can_compare (const GValue *value1,
504 const GValue *value2);
506 gboolean gst_value_union (GValue *dest,
507 const GValue *value1,
508 const GValue *value2);
509 gboolean gst_value_can_union (const GValue *value1,
510 const GValue *value2);
511 void gst_value_register_union_func (GType type1,
513 GstValueUnionFunc func);
516 gboolean gst_value_intersect (GValue *dest,
517 const GValue *value1,
518 const GValue *value2);
519 gboolean gst_value_can_intersect (const GValue *value1,
520 const GValue *value2);
521 void gst_value_register_intersect_func (GType type1,
523 GstValueIntersectFunc func);
526 gboolean gst_value_subtract (GValue *dest,
527 const GValue *minuend,
528 const GValue *subtrahend);
529 gboolean gst_value_can_subtract (const GValue *minuend,
530 const GValue *subtrahend);
531 void gst_value_register_subtract_func (GType minuend_type,
532 GType subtrahend_type,
533 GstValueSubtractFunc func);
536 gboolean gst_value_is_fixed (const GValue *value);