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) ((guint32)((a)|(b)<<8|(c)<<16|(d)<<24))
49 * @f: a string with at least four characters
51 * Transform an input string into a #guint32 fourcc value with host
53 * Caller is responsible for ensuring the input string consists of at least
57 * guint32 fourcc = GST_STR_FOURCC ("MJPG");
61 #define GST_STR_FOURCC(f) ((guint32)(((f)[0])|((f)[1]<<8)|((f)[2]<<16)|((f)[3]<<24)))
66 * Can be used together with #GST_FOURCC_ARGS to properly output a
67 * #guint32 fourcc value in a printf()-style text message.
70 * printf ("fourcc: %" GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS (fcc));
74 #define GST_FOURCC_FORMAT "c%c%c%c"
78 * @fourcc: a #guint32 fourcc value to output
80 * Can be used together with #GST_FOURCC_FORMAT to properly output a
81 * #guint32 fourcc value in a printf()-style text message.
84 #define __GST_PRINT_CHAR(c) \
85 g_ascii_isprint(c) ? (c) : '.'
86 #define GST_FOURCC_ARGS(fourcc) \
87 __GST_PRINT_CHAR((fourcc) & 0xff), \
88 __GST_PRINT_CHAR(((fourcc) >> 8) & 0xff), \
89 __GST_PRINT_CHAR(((fourcc) >> 16) & 0xff), \
90 __GST_PRINT_CHAR(((fourcc) >> 24) & 0xff)
92 * GST_VALUE_HOLDS_INT_RANGE:
93 * @x: the #GValue to check
95 * Checks if the given #GValue contains a #GST_TYPE_INT_RANGE value.
97 #define GST_VALUE_HOLDS_INT_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_int_range_type)
100 * GST_VALUE_HOLDS_INT64_RANGE:
101 * @x: the #GValue to check
103 * Checks if the given #GValue contains a #GST_TYPE_INT64_RANGE value.
105 #define GST_VALUE_HOLDS_INT64_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_int64_range_type)
108 * GST_VALUE_HOLDS_DOUBLE_RANGE:
109 * @x: the #GValue to check
111 * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
113 #define GST_VALUE_HOLDS_DOUBLE_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_double_range_type)
116 * GST_VALUE_HOLDS_FRACTION_RANGE:
117 * @x: the #GValue to check
119 * Checks if the given #GValue contains a #GST_TYPE_FRACTION_RANGE value.
121 #define GST_VALUE_HOLDS_FRACTION_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_range_type)
124 * GST_VALUE_HOLDS_LIST:
125 * @x: the #GValue to check
127 * Checks if the given #GValue contains a #GST_TYPE_LIST value.
129 #define GST_VALUE_HOLDS_LIST(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_list_type)
132 * GST_VALUE_HOLDS_ARRAY:
133 * @x: the #GValue to check
135 * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
137 #define GST_VALUE_HOLDS_ARRAY(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_array_type)
140 * GST_VALUE_HOLDS_CAPS:
141 * @x: the #GValue to check
143 * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
145 #define GST_VALUE_HOLDS_CAPS(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_caps_type)
148 * GST_VALUE_HOLDS_STRUCTURE:
149 * @x: the #GValue to check
151 * Checks if the given #GValue contains a #GST_TYPE_STRUCTURE value.
153 #define GST_VALUE_HOLDS_STRUCTURE(x) (G_VALUE_HOLDS((x), _gst_structure_type))
156 * GST_VALUE_HOLDS_CAPS_FEATURES:
157 * @x: the #GValue to check
159 * Checks if the given #GValue contains a #GST_TYPE_CAPS_FEATURES value.
161 #define GST_VALUE_HOLDS_CAPS_FEATURES(x) (G_VALUE_HOLDS((x), _gst_caps_features_type))
164 * GST_VALUE_HOLDS_BUFFER:
165 * @x: the #GValue to check
167 * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
169 #define GST_VALUE_HOLDS_BUFFER(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_buffer_type)
172 * GST_VALUE_HOLDS_SAMPLE:
173 * @x: the #GValue to check
175 * Checks if the given #GValue contains a #GST_TYPE_SAMPLE value.
177 #define GST_VALUE_HOLDS_SAMPLE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_sample_type)
180 * GST_VALUE_HOLDS_FRACTION:
181 * @x: the #GValue to check
183 * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
185 #define GST_VALUE_HOLDS_FRACTION(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_type)
188 * GST_VALUE_HOLDS_DATE_TIME:
189 * @x: the #GValue to check
191 * Checks if the given #GValue contains a #GST_TYPE_DATE_TIME value.
193 #define GST_VALUE_HOLDS_DATE_TIME(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_date_time_type)
196 * GST_VALUE_HOLDS_BITMASK:
197 * @x: the #GValue to check
199 * Checks if the given #GValue contains a #GST_TYPE_BITMASK value.
201 #define GST_VALUE_HOLDS_BITMASK(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_bitmask_type)
204 * GST_VALUE_HOLDS_FLAG_SET:
205 * @x: the #GValue to check
207 * Checks if the given #GValue contains a #GST_TYPE_FLAG_SET value.
211 #define GST_VALUE_HOLDS_FLAG_SET(x) (G_TYPE_CHECK_VALUE_TYPE ((x), GST_TYPE_FLAG_SET))
214 * GST_FLAG_SET_MASK_EXACT: (value 4294967295) (type guint)
216 * A mask value with all bits set, for use as a
217 * #GstFlagSet mask where all flag bits must match
222 #define GST_FLAG_SET_MASK_EXACT ((guint)(-1))
224 GST_EXPORT GType _gst_int_range_type;
227 * GST_TYPE_INT_RANGE:
229 * a #GValue type that represents an integer range
231 * Returns: the #GType of GstIntRange
233 #define GST_TYPE_INT_RANGE (_gst_int_range_type)
235 GST_EXPORT GType _gst_int64_range_type;
238 * GST_TYPE_INT64_RANGE:
240 * a #GValue type that represents an #gint64 range
242 * Returns: the #GType of GstInt64Range
244 #define GST_TYPE_INT64_RANGE (_gst_int64_range_type)
246 GST_EXPORT GType _gst_double_range_type;
249 * GST_TYPE_DOUBLE_RANGE:
251 * a #GValue type that represents a floating point range with double precision
253 * Returns: the #GType of GstIntRange
255 #define GST_TYPE_DOUBLE_RANGE (_gst_double_range_type)
257 GST_EXPORT GType _gst_fraction_range_type;
260 * GST_TYPE_FRACTION_RANGE:
262 * a #GValue type that represents a GstFraction range
264 * Returns: the #GType of GstFractionRange
266 #define GST_TYPE_FRACTION_RANGE (_gst_fraction_range_type)
268 GST_EXPORT GType _gst_value_list_type;
273 * a #GValue type that represents an unordered list of #GValue values. This
274 * is used for example to express a list of possible values for a field in
275 * a caps structure, like a list of possible sample rates, of which only one
276 * will be chosen in the end. This means that all values in the list are
277 * meaningful on their own.
279 * Returns: the #GType of GstValueList (which is not explicitly typed)
281 #define GST_TYPE_LIST (_gst_value_list_type)
283 GST_EXPORT GType _gst_value_array_type;
288 * a #GValue type that represents an ordered list of #GValue values. This is
289 * used to express a set of values that is meaningful only in their specific
290 * combination and order of values. Each value on its own is not particularly
291 * meaningful, only the ordered array in its entirety is meaningful. This is
292 * used for example to express channel layouts for multichannel audio where
293 * each channel needs to be mapped to a position in the room.
295 * Returns: the #GType of GstArrayList (which is not explicitly typed)
297 #define GST_TYPE_ARRAY (_gst_value_array_type)
299 GST_EXPORT GType _gst_fraction_type;
304 * a #GValue type that represents a fraction of an integer numerator over
305 * an integer denominator
307 * Returns: the #GType of GstFraction (which is not explicitly typed)
310 #define GST_TYPE_FRACTION (_gst_fraction_type)
312 GST_EXPORT GType _gst_bitmask_type;
317 * a #GValue type that represents a 64-bit bitmask.
319 * Returns: the #GType of GstBitmask (which is not explicitly typed)
322 #define GST_TYPE_BITMASK (_gst_bitmask_type)
324 GST_EXPORT GType _gst_flagset_type;
329 * a #GValue type that represents a 32-bit flag bitfield, with 32-bit
330 * mask indicating which of the bits in the field are explicitly set.
331 * Useful for negotiation.
333 * Returns: the #GType of GstFlags (which is not explicitly typed)
337 #define GST_TYPE_FLAG_SET (_gst_flagset_type)
342 * a boxed #GValue type for #GThread that represents a thread.
344 * Returns: the #GType of GstGThread
347 #define GST_TYPE_G_THREAD gst_g_thread_get_type ()
350 * GST_VALUE_LESS_THAN:
352 * Indicates that the first value provided to a comparison function
353 * (gst_value_compare()) is lesser than the second one.
355 #define GST_VALUE_LESS_THAN (-1)
360 * Indicates that the first value provided to a comparison function
361 * (gst_value_compare()) is equal to the second one.
363 #define GST_VALUE_EQUAL 0
366 * GST_VALUE_GREATER_THAN:
368 * Indicates that the first value provided to a comparison function
369 * (gst_value_compare()) is greater than the second one.
371 #define GST_VALUE_GREATER_THAN 1
374 * GST_VALUE_UNORDERED:
376 * Indicates that the comparison function (gst_value_compare()) can not
377 * determine a order for the two provided values.
379 #define GST_VALUE_UNORDERED 2
382 * GstValueCompareFunc:
383 * @value1: first value for comparison
384 * @value2: second value for comparison
386 * Used together with gst_value_compare() to compare #GValue items.
388 * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
389 * or GST_VALUE_UNORDERED
391 typedef gint (* GstValueCompareFunc) (const GValue *value1,
392 const GValue *value2);
395 * GstValueSerializeFunc:
398 * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
400 * Free-function: g_free
402 * Returns: (transfer full): the string representation of the value
404 typedef gchar * (* GstValueSerializeFunc) (const GValue *value1);
407 * GstValueDeserializeFunc:
411 * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
413 * Returns: %TRUE for success
415 typedef gboolean (* GstValueDeserializeFunc) (GValue *dest,
418 typedef struct _GstValueTable GstValueTable;
422 * @compare: a #GstValueCompareFunc
423 * @serialize: a #GstValueSerializeFunc
424 * @deserialize: a #GstValueDeserializeFunc
426 * VTable for the #GValue @type.
428 struct _GstValueTable {
430 GstValueCompareFunc compare;
431 GstValueSerializeFunc serialize;
432 GstValueDeserializeFunc deserialize;
435 gpointer _gst_reserved [GST_PADDING];
439 GType gst_int_range_get_type (void);
442 GType gst_int64_range_get_type (void);
445 GType gst_double_range_get_type (void);
448 GType gst_fraction_range_get_type (void);
451 GType gst_fraction_get_type (void);
454 GType gst_value_list_get_type (void);
457 GType gst_value_array_get_type (void);
460 GType gst_bitmask_get_type (void);
463 GType gst_flagset_get_type (void);
465 /* Hide this compatibility type from introspection */
466 #ifndef __GI_SCANNER__
468 GType gst_g_thread_get_type (void);
472 void gst_value_register (const GstValueTable *table);
475 void gst_value_init_and_copy (GValue *dest,
478 gchar * gst_value_serialize (const GValue *value) G_GNUC_MALLOC;
481 gboolean gst_value_deserialize (GValue *dest,
487 void gst_value_list_append_value (GValue *value,
488 const GValue *append_value);
490 void gst_value_list_append_and_take_value (GValue *value,
491 GValue *append_value);
493 void gst_value_list_prepend_value (GValue *value,
494 const GValue *prepend_value);
496 void gst_value_list_concat (GValue *dest,
497 const GValue *value1,
498 const GValue *value2);
500 void gst_value_list_merge (GValue *dest,
501 const GValue *value1,
502 const GValue *value2);
504 guint gst_value_list_get_size (const GValue *value);
507 const GValue * gst_value_list_get_value (const GValue *value,
513 void gst_value_array_append_value (GValue *value,
514 const GValue *append_value);
516 void gst_value_array_append_and_take_value (GValue *value,
517 GValue *append_value);
519 void gst_value_array_prepend_value (GValue *value,
520 const GValue *prepend_value);
522 guint gst_value_array_get_size (const GValue *value);
525 const GValue * gst_value_array_get_value (const GValue *value,
531 void gst_value_set_int_range (GValue *value,
535 void gst_value_set_int_range_step (GValue *value,
540 gint gst_value_get_int_range_min (const GValue *value);
543 gint gst_value_get_int_range_max (const GValue *value);
546 gint gst_value_get_int_range_step (const GValue *value);
551 void gst_value_set_int64_range (GValue *value,
555 void gst_value_set_int64_range_step (GValue *value,
560 gint64 gst_value_get_int64_range_min (const GValue *value);
563 gint64 gst_value_get_int64_range_max (const GValue *value);
566 gint64 gst_value_get_int64_range_step (const GValue *value);
571 void gst_value_set_double_range (GValue *value,
575 gdouble gst_value_get_double_range_min (const GValue *value);
578 gdouble gst_value_get_double_range_max (const GValue *value);
583 const GstCaps * gst_value_get_caps (const GValue *value);
586 void gst_value_set_caps (GValue *value,
587 const GstCaps *caps);
593 gst_value_get_structure (const GValue *value);
596 void gst_value_set_structure (GValue *value,
597 const GstStructure *structure);
602 const GstCapsFeatures *
603 gst_value_get_caps_features (const GValue *value);
606 void gst_value_set_caps_features (GValue *value,
607 const GstCapsFeatures *features);
612 void gst_value_set_fraction (GValue *value,
616 gint gst_value_get_fraction_numerator (const GValue *value);
619 gint gst_value_get_fraction_denominator (const GValue *value);
622 gboolean gst_value_fraction_multiply (GValue *product,
623 const GValue *factor1,
624 const GValue *factor2);
626 gboolean gst_value_fraction_subtract (GValue * dest,
627 const GValue * minuend,
628 const GValue * subtrahend);
633 void gst_value_set_fraction_range (GValue *value,
637 void gst_value_set_fraction_range_full (GValue *value,
638 gint numerator_start,
639 gint denominator_start,
641 gint denominator_end);
643 const GValue *gst_value_get_fraction_range_min (const GValue *value);
646 const GValue *gst_value_get_fraction_range_max (const GValue *value);
651 guint64 gst_value_get_bitmask (const GValue *value);
654 void gst_value_set_bitmask (GValue *value,
659 void gst_value_set_flagset (GValue * value, guint flags, guint mask);
662 guint gst_value_get_flagset_flags (const GValue * value);
665 guint gst_value_get_flagset_mask (const GValue * value);
670 gint gst_value_compare (const GValue *value1,
671 const GValue *value2);
673 gboolean gst_value_can_compare (const GValue *value1,
674 const GValue *value2);
676 gboolean gst_value_is_subset (const GValue *value1,
677 const GValue *value2);
682 gboolean gst_value_union (GValue *dest,
683 const GValue *value1,
684 const GValue *value2);
686 gboolean gst_value_can_union (const GValue *value1,
687 const GValue *value2);
692 gboolean gst_value_intersect (GValue *dest,
693 const GValue *value1,
694 const GValue *value2);
696 gboolean gst_value_can_intersect (const GValue *value1,
697 const GValue *value2);
702 gboolean gst_value_subtract (GValue *dest,
703 const GValue *minuend,
704 const GValue *subtrahend);
706 gboolean gst_value_can_subtract (const GValue *minuend,
707 const GValue *subtrahend);
712 gboolean gst_value_is_fixed (const GValue *value);
715 gboolean gst_value_fixate (GValue *dest,
718 /* Flagset registration wrapper */
721 GType gst_flagset_register (GType flags_type);