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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, 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>
26 #include <gst/gstcapsfeatures.h>
32 * @a: the first character
33 * @b: the second character
34 * @c: the third character
35 * @d: the fourth character
37 * Transform four characters into a #guint32 fourcc value with host
41 * guint32 fourcc = GST_MAKE_FOURCC ('M', 'J', 'P', 'G');
45 #define GST_MAKE_FOURCC(a,b,c,d) \
46 ( (guint32)(a) | ((guint32) (b)) << 8 | ((guint32) (c)) << 16 | ((guint32) (d)) << 24 )
50 * @f: a string with at least four characters
52 * Transform an input string into a #guint32 fourcc value with host
54 * Caller is responsible for ensuring the input string consists of at least
58 * guint32 fourcc = GST_STR_FOURCC ("MJPG");
62 #define GST_STR_FOURCC(f) ((guint32)(((f)[0])|((f)[1]<<8)|((f)[2]<<16)|((f)[3]<<24)))
67 * Can be used together with #GST_FOURCC_ARGS to properly output a
68 * #guint32 fourcc value in a printf()-style text message.
71 * printf ("fourcc: %" GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS (fcc));
75 #define GST_FOURCC_FORMAT "c%c%c%c"
79 * @fourcc: a #guint32 fourcc value to output
81 * Can be used together with #GST_FOURCC_FORMAT to properly output a
82 * #guint32 fourcc value in a printf()-style text message.
85 #define __GST_PRINT_CHAR(c) \
86 g_ascii_isprint(c) ? (c) : '.'
87 #define GST_FOURCC_ARGS(fourcc) \
88 __GST_PRINT_CHAR((fourcc) & 0xff), \
89 __GST_PRINT_CHAR(((fourcc) >> 8) & 0xff), \
90 __GST_PRINT_CHAR(((fourcc) >> 16) & 0xff), \
91 __GST_PRINT_CHAR(((fourcc) >> 24) & 0xff)
93 * GST_VALUE_HOLDS_INT_RANGE:
94 * @x: the #GValue to check
96 * Checks if the given #GValue contains a #GST_TYPE_INT_RANGE value.
98 #define GST_VALUE_HOLDS_INT_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_int_range_type)
101 * GST_VALUE_HOLDS_INT64_RANGE:
102 * @x: the #GValue to check
104 * Checks if the given #GValue contains a #GST_TYPE_INT64_RANGE value.
106 #define GST_VALUE_HOLDS_INT64_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_int64_range_type)
109 * GST_VALUE_HOLDS_DOUBLE_RANGE:
110 * @x: the #GValue to check
112 * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
114 #define GST_VALUE_HOLDS_DOUBLE_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_double_range_type)
117 * GST_VALUE_HOLDS_FRACTION_RANGE:
118 * @x: the #GValue to check
120 * Checks if the given #GValue contains a #GST_TYPE_FRACTION_RANGE value.
122 #define GST_VALUE_HOLDS_FRACTION_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_range_type)
125 * GST_VALUE_HOLDS_LIST:
126 * @x: the #GValue to check
128 * Checks if the given #GValue contains a #GST_TYPE_LIST value.
130 #define GST_VALUE_HOLDS_LIST(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_list_type)
133 * GST_VALUE_HOLDS_ARRAY:
134 * @x: the #GValue to check
136 * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
138 #define GST_VALUE_HOLDS_ARRAY(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_array_type)
141 * GST_VALUE_HOLDS_CAPS:
142 * @x: the #GValue to check
144 * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
146 #define GST_VALUE_HOLDS_CAPS(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_caps_type)
149 * GST_VALUE_HOLDS_STRUCTURE:
150 * @x: the #GValue to check
152 * Checks if the given #GValue contains a #GST_TYPE_STRUCTURE value.
154 #define GST_VALUE_HOLDS_STRUCTURE(x) (G_VALUE_HOLDS((x), _gst_structure_type))
157 * GST_VALUE_HOLDS_CAPS_FEATURES:
158 * @x: the #GValue to check
160 * Checks if the given #GValue contains a #GST_TYPE_CAPS_FEATURES value.
162 #define GST_VALUE_HOLDS_CAPS_FEATURES(x) (G_VALUE_HOLDS((x), _gst_caps_features_type))
165 * GST_VALUE_HOLDS_BUFFER:
166 * @x: the #GValue to check
168 * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
170 #define GST_VALUE_HOLDS_BUFFER(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_buffer_type)
173 * GST_VALUE_HOLDS_SAMPLE:
174 * @x: the #GValue to check
176 * Checks if the given #GValue contains a #GST_TYPE_SAMPLE value.
178 #define GST_VALUE_HOLDS_SAMPLE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_sample_type)
181 * GST_VALUE_HOLDS_FRACTION:
182 * @x: the #GValue to check
184 * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
186 #define GST_VALUE_HOLDS_FRACTION(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_type)
189 * GST_VALUE_HOLDS_DATE_TIME:
190 * @x: the #GValue to check
192 * Checks if the given #GValue contains a #GST_TYPE_DATE_TIME value.
194 #define GST_VALUE_HOLDS_DATE_TIME(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_date_time_type)
197 * GST_VALUE_HOLDS_BITMASK:
198 * @x: the #GValue to check
200 * Checks if the given #GValue contains a #GST_TYPE_BITMASK value.
202 #define GST_VALUE_HOLDS_BITMASK(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_bitmask_type)
205 * GST_VALUE_HOLDS_FLAG_SET:
206 * @x: the #GValue to check
208 * Checks if the given #GValue contains a #GST_TYPE_FLAG_SET value.
212 #define GST_VALUE_HOLDS_FLAG_SET(x) (G_TYPE_CHECK_VALUE_TYPE ((x), GST_TYPE_FLAG_SET))
215 * GST_FLAG_SET_MASK_EXACT: (value 4294967295) (type guint)
217 * A mask value with all bits set, for use as a
218 * GstFlagSet mask where all flag bits must match
223 #define GST_FLAG_SET_MASK_EXACT ((guint)(-1))
225 GST_API GType _gst_int_range_type;
228 * GST_TYPE_INT_RANGE:
230 * a #GValue type that represents an integer range
232 * Returns: the #GType of GstIntRange
234 #define GST_TYPE_INT_RANGE (_gst_int_range_type)
236 GST_API GType _gst_int64_range_type;
239 * GST_TYPE_INT64_RANGE:
241 * a #GValue type that represents an #gint64 range
243 * Returns: the #GType of GstInt64Range
245 #define GST_TYPE_INT64_RANGE (_gst_int64_range_type)
247 GST_API GType _gst_double_range_type;
250 * GST_TYPE_DOUBLE_RANGE:
252 * a #GValue type that represents a floating point range with double precision
254 * Returns: the #GType of GstIntRange
256 #define GST_TYPE_DOUBLE_RANGE (_gst_double_range_type)
258 GST_API GType _gst_fraction_range_type;
261 * GST_TYPE_FRACTION_RANGE:
263 * a #GValue type that represents a GstFraction range
265 * Returns: the #GType of GstFractionRange
267 #define GST_TYPE_FRACTION_RANGE (_gst_fraction_range_type)
269 GST_API GType _gst_value_list_type;
274 * a #GValue type that represents an unordered list of #GValue values. This
275 * is used for example to express a list of possible values for a field in
276 * a caps structure, like a list of possible sample rates, of which only one
277 * will be chosen in the end. This means that all values in the list are
278 * meaningful on their own.
280 * Returns: the #GType of GstValueList (which is not explicitly typed)
282 #define GST_TYPE_LIST (_gst_value_list_type)
284 GST_API GType _gst_value_array_type;
289 * a #GValue type that represents an ordered list of #GValue values. This is
290 * used to express a set of values that is meaningful only in their specific
291 * combination and order of values. Each value on its own is not particularly
292 * meaningful, only the ordered array in its entirety is meaningful. This is
293 * used for example to express channel layouts for multichannel audio where
294 * each channel needs to be mapped to a position in the room.
296 * Returns: the #GType of GstArrayList (which is not explicitly typed)
298 #define GST_TYPE_ARRAY (_gst_value_array_type)
300 GST_API GType _gst_fraction_type;
305 * a #GValue type that represents a fraction of an integer numerator over
306 * an integer denominator
308 * Returns: the #GType of GstFraction (which is not explicitly typed)
311 #define GST_TYPE_FRACTION (_gst_fraction_type)
313 GST_API GType _gst_bitmask_type;
318 * a #GValue type that represents a 64-bit bitmask.
320 * Returns: the #GType of GstBitmask (which is not explicitly typed)
323 #define GST_TYPE_BITMASK (_gst_bitmask_type)
325 GST_API GType _gst_flagset_type;
330 * a #GValue type that represents a 32-bit flag bitfield, with 32-bit
331 * mask indicating which of the bits in the field are explicitly set.
332 * Useful for negotiation.
334 * Returns: the #GType of GstFlags (which is not explicitly typed)
338 #define GST_TYPE_FLAG_SET (_gst_flagset_type)
343 * a boxed #GValue type for #GThread that represents a thread.
345 * Returns: the #GType of GstGThread
348 #define GST_TYPE_G_THREAD gst_g_thread_get_type ()
351 * GST_VALUE_LESS_THAN:
353 * Indicates that the first value provided to a comparison function
354 * (gst_value_compare()) is lesser than the second one.
356 #define GST_VALUE_LESS_THAN (-1)
361 * Indicates that the first value provided to a comparison function
362 * (gst_value_compare()) is equal to the second one.
364 #define GST_VALUE_EQUAL 0
367 * GST_VALUE_GREATER_THAN:
369 * Indicates that the first value provided to a comparison function
370 * (gst_value_compare()) is greater than the second one.
372 #define GST_VALUE_GREATER_THAN 1
375 * GST_VALUE_UNORDERED:
377 * Indicates that the comparison function (gst_value_compare()) can not
378 * determine a order for the two provided values.
380 #define GST_VALUE_UNORDERED 2
383 * GstValueCompareFunc:
384 * @value1: first value for comparison
385 * @value2: second value for comparison
387 * Used together with gst_value_compare() to compare #GValue items.
389 * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
390 * or GST_VALUE_UNORDERED
392 typedef gint (* GstValueCompareFunc) (const GValue *value1,
393 const GValue *value2);
396 * GstValueSerializeFunc:
399 * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
401 * Free-function: g_free
403 * Returns: (transfer full): the string representation of the value
405 typedef gchar * (* GstValueSerializeFunc) (const GValue *value1);
408 * GstValueDeserializeFunc:
412 * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
414 * Returns: %TRUE for success
416 typedef gboolean (* GstValueDeserializeFunc) (GValue *dest,
419 typedef struct _GstValueTable GstValueTable;
423 * @compare: a #GstValueCompareFunc
424 * @serialize: a #GstValueSerializeFunc
425 * @deserialize: a #GstValueDeserializeFunc
427 * VTable for the #GValue @type.
429 struct _GstValueTable {
431 GstValueCompareFunc compare;
432 GstValueSerializeFunc serialize;
433 GstValueDeserializeFunc deserialize;
436 gpointer _gst_reserved [GST_PADDING];
440 GType gst_int_range_get_type (void);
443 GType gst_int64_range_get_type (void);
446 GType gst_double_range_get_type (void);
449 GType gst_fraction_range_get_type (void);
452 GType gst_fraction_get_type (void);
455 GType gst_value_list_get_type (void);
458 GType gst_value_array_get_type (void);
461 GType gst_bitmask_get_type (void);
464 GType gst_flagset_get_type (void);
466 /* Hide this compatibility type from introspection */
467 #ifndef __GI_SCANNER__
469 GType gst_g_thread_get_type (void);
473 void gst_value_register (const GstValueTable *table);
476 void gst_value_init_and_copy (GValue *dest,
479 gchar * gst_value_serialize (const GValue *value) G_GNUC_MALLOC;
482 gboolean gst_value_deserialize (GValue *dest,
488 void gst_value_list_append_value (GValue *value,
489 const GValue *append_value);
491 void gst_value_list_append_and_take_value (GValue *value,
492 GValue *append_value);
494 void gst_value_list_prepend_value (GValue *value,
495 const GValue *prepend_value);
497 void gst_value_list_concat (GValue *dest,
498 const GValue *value1,
499 const GValue *value2);
501 void gst_value_list_merge (GValue *dest,
502 const GValue *value1,
503 const GValue *value2);
505 guint gst_value_list_get_size (const GValue *value);
508 const GValue * gst_value_list_get_value (const GValue *value,
514 void gst_value_array_append_value (GValue *value,
515 const GValue *append_value);
517 void gst_value_array_append_and_take_value (GValue *value,
518 GValue *append_value);
520 void gst_value_array_prepend_value (GValue *value,
521 const GValue *prepend_value);
523 guint gst_value_array_get_size (const GValue *value);
526 const GValue * gst_value_array_get_value (const GValue *value,
532 void gst_value_set_int_range (GValue *value,
536 void gst_value_set_int_range_step (GValue *value,
541 gint gst_value_get_int_range_min (const GValue *value);
544 gint gst_value_get_int_range_max (const GValue *value);
547 gint gst_value_get_int_range_step (const GValue *value);
552 void gst_value_set_int64_range (GValue *value,
556 void gst_value_set_int64_range_step (GValue *value,
561 gint64 gst_value_get_int64_range_min (const GValue *value);
564 gint64 gst_value_get_int64_range_max (const GValue *value);
567 gint64 gst_value_get_int64_range_step (const GValue *value);
572 void gst_value_set_double_range (GValue *value,
576 gdouble gst_value_get_double_range_min (const GValue *value);
579 gdouble gst_value_get_double_range_max (const GValue *value);
584 const GstCaps * gst_value_get_caps (const GValue *value);
587 void gst_value_set_caps (GValue *value,
588 const GstCaps *caps);
594 gst_value_get_structure (const GValue *value);
597 void gst_value_set_structure (GValue *value,
598 const GstStructure *structure);
603 const GstCapsFeatures *
604 gst_value_get_caps_features (const GValue *value);
607 void gst_value_set_caps_features (GValue *value,
608 const GstCapsFeatures *features);
613 void gst_value_set_fraction (GValue *value,
617 gint gst_value_get_fraction_numerator (const GValue *value);
620 gint gst_value_get_fraction_denominator (const GValue *value);
623 gboolean gst_value_fraction_multiply (GValue *product,
624 const GValue *factor1,
625 const GValue *factor2);
627 gboolean gst_value_fraction_subtract (GValue * dest,
628 const GValue * minuend,
629 const GValue * subtrahend);
634 void gst_value_set_fraction_range (GValue *value,
638 void gst_value_set_fraction_range_full (GValue *value,
639 gint numerator_start,
640 gint denominator_start,
642 gint denominator_end);
644 const GValue *gst_value_get_fraction_range_min (const GValue *value);
647 const GValue *gst_value_get_fraction_range_max (const GValue *value);
652 guint64 gst_value_get_bitmask (const GValue *value);
655 void gst_value_set_bitmask (GValue *value,
660 void gst_value_set_flagset (GValue * value, guint flags, guint mask);
663 guint gst_value_get_flagset_flags (const GValue * value);
666 guint gst_value_get_flagset_mask (const GValue * value);
671 gint gst_value_compare (const GValue *value1,
672 const GValue *value2);
674 gboolean gst_value_can_compare (const GValue *value1,
675 const GValue *value2);
677 gboolean gst_value_is_subset (const GValue *value1,
678 const GValue *value2);
683 gboolean gst_value_union (GValue *dest,
684 const GValue *value1,
685 const GValue *value2);
687 gboolean gst_value_can_union (const GValue *value1,
688 const GValue *value2);
693 gboolean gst_value_intersect (GValue *dest,
694 const GValue *value1,
695 const GValue *value2);
697 gboolean gst_value_can_intersect (const GValue *value1,
698 const GValue *value2);
703 gboolean gst_value_subtract (GValue *dest,
704 const GValue *minuend,
705 const GValue *subtrahend);
707 gboolean gst_value_can_subtract (const GValue *minuend,
708 const GValue *subtrahend);
713 gboolean gst_value_is_fixed (const GValue *value);
716 gboolean gst_value_fixate (GValue *dest,
719 /* Flagset registration wrapper */
722 GType gst_flagset_register (GType flags_type);