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>
30 * @a: the first character
31 * @b: the second character
32 * @c: the third character
33 * @d: the fourth character
35 * Transform four characters into a #guint32 fourcc value with host
39 * guint32 fourcc = GST_MAKE_FOURCC ('M', 'J', 'P', 'G');
43 #define GST_MAKE_FOURCC(a,b,c,d) (guint32)((a)|(b)<<8|(c)<<16|(d)<<24)
47 * @f: a string with at least four characters
49 * Transform an input string into a #guint32 fourcc value with host
51 * Caller is responsible for ensuring the input string consists of at least
55 * guint32 fourcc = GST_STR_FOURCC ("MJPG");
59 #define GST_STR_FOURCC(f) (guint32)(((f)[0])|((f)[1]<<8)|((f)[2]<<16)|((f)[3]<<24))
64 * Can be used together with #GST_FOURCC_ARGS to properly output a
65 * #guint32 fourcc value in a printf()-style text message.
68 * printf ("fourcc: %" GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS (fcc));
72 #define GST_FOURCC_FORMAT "c%c%c%c"
76 * @fourcc: a #guint32 fourcc value to output
78 * Can be used together with #GST_FOURCC_FORMAT to properly output a
79 * #guint32 fourcc value in a printf()-style text message.
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))
88 * GST_VALUE_HOLDS_FOURCC:
89 * @x: the #GValue to check
91 * Checks if the given #GValue contains a #GST_TYPE_FOURCC value.
93 #define GST_VALUE_HOLDS_FOURCC(x) (G_VALUE_HOLDS(x, gst_fourcc_get_type ()))
96 * GST_VALUE_HOLDS_INT_RANGE:
97 * @x: the #GValue to check
99 * Checks if the given #GValue contains a #GST_TYPE_INT_RANGE value.
101 #define GST_VALUE_HOLDS_INT_RANGE(x) (G_VALUE_HOLDS(x, gst_int_range_get_type ()))
104 * GST_VALUE_HOLDS_DOUBLE_RANGE:
105 * @x: the #GValue to check
107 * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
109 #define GST_VALUE_HOLDS_DOUBLE_RANGE(x) (G_VALUE_HOLDS(x, gst_double_range_get_type ()))
112 * GST_VALUE_HOLDS_FRACTION_RANGE:
113 * @x: the #GValue to check
115 * Checks if the given #GValue contains a #GST_TYPE_FRACTION_RANGE value.
117 #define GST_VALUE_HOLDS_FRACTION_RANGE(x) (G_VALUE_HOLDS(x, gst_fraction_range_get_type ()))
120 * GST_VALUE_HOLDS_LIST:
121 * @x: the #GValue to check
123 * Checks if the given #GValue contains a #GST_TYPE_LIST value.
125 #define GST_VALUE_HOLDS_LIST(x) (G_VALUE_HOLDS(x, gst_value_list_get_type ()))
128 * GST_VALUE_HOLDS_ARRAY:
129 * @x: the #GValue to check
131 * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
133 #define GST_VALUE_HOLDS_ARRAY(x) (G_VALUE_HOLDS(x, gst_value_array_get_type ()))
136 * GST_VALUE_HOLDS_CAPS:
137 * @x: the #GValue to check
139 * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
141 #define GST_VALUE_HOLDS_CAPS(x) (G_VALUE_HOLDS(x, GST_TYPE_CAPS))
144 * GST_VALUE_HOLDS_BUFFER:
145 * @x: the #GValue to check
147 * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
149 #define GST_VALUE_HOLDS_BUFFER(x) (G_VALUE_HOLDS(x, GST_TYPE_BUFFER))
152 * GST_VALUE_HOLDS_FRACTION:
153 * @x: the #GValue to check
155 * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
157 #define GST_VALUE_HOLDS_FRACTION(x) (G_VALUE_HOLDS(x, gst_fraction_get_type ()))
160 * GST_VALUE_HOLDS_DATE:
161 * @x: the #GValue to check
163 * Checks if the given #GValue contains a #GST_TYPE_DATE value.
165 #define GST_VALUE_HOLDS_DATE(x) (G_VALUE_HOLDS(x, gst_date_get_type ()))
170 * a #GValue type that represents 4 byte identifier (e.g. used for codecs)
172 * Returns: the #GType of GstFourcc
174 #define GST_TYPE_FOURCC gst_fourcc_get_type ()
177 * GST_TYPE_INT_RANGE:
179 * a #GValue type that represents an integer range
181 * Returns: the #GType of GstIntRange
183 #define GST_TYPE_INT_RANGE gst_int_range_get_type ()
186 * GST_TYPE_DOUBLE_RANGE:
188 * a #GValue type that represents a floating point range with double precission
190 * Returns: the #GType of GstIntRange
192 #define GST_TYPE_DOUBLE_RANGE gst_double_range_get_type ()
195 * GST_TYPE_FRACTION_RANGE:
197 * a #GValue type that represents a GstFraction range
199 * Returns: the #GType of GstFractionRange
201 #define GST_TYPE_FRACTION_RANGE gst_fraction_range_get_type ()
206 * a #GValue type that represents an unordered list of #GValue values
208 * Returns: the #GType of GstValueList (which is not explicitly typed)
210 #define GST_TYPE_LIST gst_value_list_get_type ()
215 * a #GValue type that represents an ordered list of #GValue values
217 * Returns: the #GType of GstArrayList (which is not explicitly typed)
219 #define GST_TYPE_ARRAY gst_value_array_get_type ()
224 * a #GValue type that represents a fraction of an integer numerator over
225 * an integer denominator
227 * Returns: the #GType of GstFraction (which is not explicitly typed)
230 #define GST_TYPE_FRACTION gst_fraction_get_type ()
235 * a boxed #GValue type for #GDate that represents a date.
237 * Returns: the #GType of GstDate
240 #define GST_TYPE_DATE gst_date_get_type ()
243 * GST_VALUE_LESS_THAN:
245 * Indicates that the first value provided to a comparison function
246 * (gst_value_compare()) is lesser than the second one.
248 #define GST_VALUE_LESS_THAN (-1)
253 * Indicates that the first value provided to a comparison function
254 * (gst_value_compare()) is equal to the second one.
256 #define GST_VALUE_EQUAL 0
259 * GST_VALUE_GREATER_THAN:
261 * Indicates that the first value provided to a comparison function
262 * (gst_value_compare()) is greater than the second one.
264 #define GST_VALUE_GREATER_THAN 1
267 * GST_VALUE_UNORDERED:
269 * Indicates that the comparison function (gst_value_compare()) can not
270 * determine a order for the two provided values.
272 #define GST_VALUE_UNORDERED 2
275 * GstValueCompareFunc:
276 * @value1: first value for comparission
277 * @value2: second value for comparission
279 * Used together with gst_value_compare() to compare #GValues.
281 * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
282 * or GST_VALUE_UNORDERED
284 typedef gint (* GstValueCompareFunc) (const GValue *value1,
285 const GValue *value2);
288 * GstValueSerializeFunc:
291 * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
293 * Returns: the string representation of the value
295 typedef gchar * (* GstValueSerializeFunc) (const GValue *value1);
298 * GstValueDeserializeFunc:
302 * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
304 * Returns: %TRUE for success
306 typedef gboolean (* GstValueDeserializeFunc) (GValue *dest,
311 * @dest: a #GValue for the result
312 * @value1: a #GValue operand
313 * @value2: a #GValue operand
315 * Used by gst_value_union() to perform unification for a specific #GValue
316 * type. Register a new implementation with gst_value_register_union_func().
318 * Returns: %TRUE if a union was successful
320 typedef gboolean (* GstValueUnionFunc) (GValue *dest,
321 const GValue *value1,
322 const GValue *value2);
325 * GstValueIntersectFunc:
326 * @dest: a #GValue for the result
327 * @value1: a #GValue operand
328 * @value2: a #GValue operand
330 * Used by gst_value_intersect() to perform intersection for a specific #GValue
331 * type. If the intersection is non-empty, the result is
332 * placed in @dest and TRUE is returned. If the intersection is
333 * empty, @dest is unmodified and FALSE is returned.
334 * Register a new implementation with gst_value_register_intersection_func().
336 * Returns: %TRUE if the values can intersect
338 typedef gboolean (* GstValueIntersectFunc) (GValue *dest,
339 const GValue *value1,
340 const GValue *value2);
343 * GstValueSubtractFunc:
344 * @dest: a #GValue for the result
345 * @minuend: a #GValue operand
346 * @subtrahend: a #GValue operand
348 * Used by gst_value_subtract() to perform subtraction for a specific #GValue
349 * type. Register a new implementation with gst_value_register_subtract_func().
351 * Returns: %TRUE if the subtraction is not empty
353 typedef gboolean (* GstValueSubtractFunc) (GValue *dest,
354 const GValue *minuend,
355 const GValue *subtrahend);
357 typedef struct _GstValueTable GstValueTable;
361 * @compare: a #GstValueCompareFunc
362 * @serialize: a #GstValueSerializeFunc
363 * @deserialize: a #GstValueDeserializeFunc
365 * VTable for the #GValue @type.
367 struct _GstValueTable {
369 GstValueCompareFunc compare;
370 GstValueSerializeFunc serialize;
371 GstValueDeserializeFunc deserialize;
374 void *_gst_reserved [GST_PADDING];
377 GType gst_int_range_get_type (void);
378 GType gst_double_range_get_type (void);
379 GType gst_fraction_range_get_type (void);
380 GType gst_fourcc_get_type (void);
381 GType gst_fraction_get_type (void);
382 GType gst_value_list_get_type (void);
383 GType gst_value_array_get_type (void);
385 GType gst_date_get_type (void);
387 void gst_value_register (const GstValueTable *table);
388 void gst_value_init_and_copy (GValue *dest,
391 gchar * gst_value_serialize (const GValue *value);
392 gboolean gst_value_deserialize (GValue *dest,
396 void gst_value_list_append_value (GValue *value,
397 const GValue *append_value);
398 void gst_value_list_prepend_value (GValue *value,
399 const GValue *prepend_value);
400 void gst_value_list_concat (GValue *dest,
401 const GValue *value1,
402 const GValue *value2);
403 guint gst_value_list_get_size (const GValue *value);
404 G_CONST_RETURN GValue *
405 gst_value_list_get_value (const GValue *value,
409 void gst_value_array_append_value (GValue *value,
410 const GValue *append_value);
411 void gst_value_array_prepend_value (GValue *value,
412 const GValue *prepend_value);
413 guint gst_value_array_get_size (const GValue *value);
414 G_CONST_RETURN GValue *
415 gst_value_array_get_value (const GValue *value,
419 void gst_value_set_fourcc (GValue *value,
421 guint32 gst_value_get_fourcc (const GValue *value);
424 void gst_value_set_int_range (GValue *value,
427 gint gst_value_get_int_range_min (const GValue *value);
428 gint gst_value_get_int_range_max (const GValue *value);
431 void gst_value_set_double_range (GValue *value,
434 gdouble gst_value_get_double_range_min (const GValue *value);
435 gdouble gst_value_get_double_range_max (const GValue *value);
438 G_CONST_RETURN GstCaps *
439 gst_value_get_caps (const GValue *value);
440 void gst_value_set_caps (GValue *value,
441 const GstCaps *caps);
444 void gst_value_set_fraction (GValue *value,
447 gint gst_value_get_fraction_numerator (const GValue *value);
448 gint gst_value_get_fraction_denominator(const GValue *value);
449 gboolean gst_value_fraction_multiply (GValue *product,
450 const GValue *factor1,
451 const GValue *factor2);
452 gboolean gst_value_fraction_subtract (GValue * dest,
453 const GValue * minuend,
454 const GValue * subtrahend);
457 void gst_value_set_fraction_range (GValue *value,
460 void gst_value_set_fraction_range_full (GValue *value,
461 gint numerator_start,
462 gint denominator_start,
464 gint denominator_end);
465 const GValue *gst_value_get_fraction_range_min (const GValue *value);
466 const GValue *gst_value_get_fraction_range_max (const GValue *value);
469 G_CONST_RETURN GDate *
470 gst_value_get_date (const GValue *value);
471 void gst_value_set_date (GValue *value,
475 gint gst_value_compare (const GValue *value1,
476 const GValue *value2);
477 gboolean gst_value_can_compare (const GValue *value1,
478 const GValue *value2);
481 gboolean gst_value_union (GValue *dest,
482 const GValue *value1,
483 const GValue *value2);
484 gboolean gst_value_can_union (const GValue *value1,
485 const GValue *value2);
486 void gst_value_register_union_func (GType type1,
488 GstValueUnionFunc func);
491 gboolean gst_value_intersect (GValue *dest,
492 const GValue *value1,
493 const GValue *value2);
494 gboolean gst_value_can_intersect (const GValue *value1,
495 const GValue *value2);
496 void gst_value_register_intersect_func (GType type1,
498 GstValueIntersectFunc func);
501 gboolean gst_value_subtract (GValue *dest,
502 const GValue *minuend,
503 const GValue *subtrahend);
504 gboolean gst_value_can_subtract (const GValue *minuend,
505 const GValue *subtrahend);
506 void gst_value_register_subtract_func (GType minuend_type,
507 GType subtrahend_type,
508 GstValueSubtractFunc func);
511 gboolean gst_value_is_fixed (const GValue *value);
514 void _gst_value_initialize (void);