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)))
65 * GST_FOURCC_FORMAT: (skip):
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"
78 * GST_FOURCC_ARGS: (skip):
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 #GstIntRange value.
98 #define GST_VALUE_HOLDS_INT_RANGE(x) ((gpointer)(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 #GstInt64Range value.
106 #define GST_VALUE_HOLDS_INT64_RANGE(x) ((gpointer)(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 #GstDoubleRange value.
114 #define GST_VALUE_HOLDS_DOUBLE_RANGE(x) ((gpointer)(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 #GstFractionRange value.
122 #define GST_VALUE_HOLDS_FRACTION_RANGE(x) ((gpointer)(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 #GstValueList value.
130 #define GST_VALUE_HOLDS_LIST(x) ((gpointer)(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 #GstValueArray value.
138 #define GST_VALUE_HOLDS_ARRAY(x) ((gpointer)(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 #GstCaps value.
146 #define GST_VALUE_HOLDS_CAPS(x) ((gpointer)(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 #GstStructure value.
154 #define GST_VALUE_HOLDS_STRUCTURE(x) ((gpointer)(x) != NULL && G_VALUE_TYPE(x) == _gst_structure_type)
157 * GST_VALUE_HOLDS_CAPS_FEATURES:
158 * @x: the #GValue to check
160 * Checks if the given #GValue contains a #GstCapsFeatures value.
162 #define GST_VALUE_HOLDS_CAPS_FEATURES(x) ((gpointer)(x) != NULL && G_VALUE_TYPE(x) == _gst_caps_features_type)
165 * GST_VALUE_HOLDS_BUFFER:
166 * @x: the #GValue to check
168 * Checks if the given #GValue contains a #GstBuffer value.
170 #define GST_VALUE_HOLDS_BUFFER(x) ((gpointer)(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 #GstSample value.
178 #define GST_VALUE_HOLDS_SAMPLE(x) ((gpointer)(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 #GstFraction value.
186 #define GST_VALUE_HOLDS_FRACTION(x) ((gpointer)(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 #GstDateTime value.
194 #define GST_VALUE_HOLDS_DATE_TIME(x) ((gpointer)(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 #GstBitmask value.
202 #define GST_VALUE_HOLDS_BITMASK(x) ((gpointer)(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 #GstFlagSet value.
212 #define GST_VALUE_HOLDS_FLAG_SET(x) (G_TYPE_FUNDAMENTAL (G_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;
230 * A fundamental type that describes a #gint range
234 * GST_TYPE_INT_RANGE:
236 * a #GValue type that represents an integer range
238 * Returns: the #GType of GstIntRange
240 #define GST_TYPE_INT_RANGE (_gst_int_range_type)
242 GST_API GType _gst_int64_range_type;
247 * A fundamental type that describes a #gint64 range
251 * GST_TYPE_INT64_RANGE:
253 * a #GValue type that represents an #gint64 range
255 * Returns: the #GType of GstInt64Range
257 #define GST_TYPE_INT64_RANGE (_gst_int64_range_type)
259 GST_API GType _gst_double_range_type;
264 * A fundamental type that describes a #gdouble range
268 * GST_TYPE_DOUBLE_RANGE:
270 * a #GValue type that represents a floating point range with double precision
272 * Returns: the #GType of GstIntRange
274 #define GST_TYPE_DOUBLE_RANGE (_gst_double_range_type)
276 GST_API GType _gst_fraction_range_type;
281 * A fundamental type that describes a #GstFractionRange range
285 * GST_TYPE_FRACTION_RANGE:
287 * a #GValue type that represents a GstFraction range
289 * Returns: the #GType of GstFractionRange
291 #define GST_TYPE_FRACTION_RANGE (_gst_fraction_range_type)
293 GST_API GType _gst_value_list_type;
298 * A fundamental type that describes an unordered list of #GValue
304 * a #GValue type that represents an unordered list of #GValue values. This
305 * is used for example to express a list of possible values for a field in
306 * a caps structure, like a list of possible sample rates, of which only one
307 * will be chosen in the end. This means that all values in the list are
308 * meaningful on their own.
310 * Returns: the #GType of GstValueList (which is not explicitly typed)
312 #define GST_TYPE_LIST (_gst_value_list_type)
314 GST_API GType _gst_value_array_type;
319 * A fundamental type that describes an ordered list of #GValue
325 * a #GValue type that represents an ordered list of #GValue values. This is
326 * used to express a set of values that is meaningful only in their specific
327 * combination and order of values. Each value on its own is not particularly
328 * meaningful, only the ordered array in its entirety is meaningful. This is
329 * used for example to express channel layouts for multichannel audio where
330 * each channel needs to be mapped to a position in the room.
332 * Returns: the #GType of GstArrayList (which is not explicitly typed)
334 #define GST_TYPE_ARRAY (_gst_value_array_type)
336 GST_API GType _gst_fraction_type;
341 * A fundamental type that describes a fraction of an integer numerator
342 * over an integer denominator
348 * a #GValue type that represents a fraction of an integer numerator over
349 * an integer denominator
351 * Returns: the #GType of GstFraction (which is not explicitly typed)
354 #define GST_TYPE_FRACTION (_gst_fraction_type)
356 GST_API GType _gst_bitmask_type;
361 * A fundamental type that describes a 64-bit bitmask
367 * a #GValue type that represents a 64-bit bitmask.
369 * Returns: the #GType of GstBitmask (which is not explicitly typed)
372 #define GST_TYPE_BITMASK (_gst_bitmask_type)
374 GST_API GType _gst_flagset_type;
379 * A fundamental type that describes a 32-bit flag bitfield, with 32-bit
380 * mask indicating which of the bits in the field are explicitly set.
386 * a #GValue type that represents a 32-bit flag bitfield, with 32-bit
387 * mask indicating which of the bits in the field are explicitly set.
388 * Useful for negotiation.
390 * Returns: the #GType of GstFlags (which is not explicitly typed)
394 #define GST_TYPE_FLAG_SET (_gst_flagset_type)
399 * a boxed #GValue type for #GThread that represents a thread.
401 * Returns: the #GType of GstGThread
404 #define GST_TYPE_G_THREAD gst_g_thread_get_type ()
407 * GST_VALUE_LESS_THAN:
409 * Indicates that the first value provided to a comparison function
410 * (gst_value_compare()) is lesser than the second one.
412 #define GST_VALUE_LESS_THAN (-1)
417 * Indicates that the first value provided to a comparison function
418 * (gst_value_compare()) is equal to the second one.
420 #define GST_VALUE_EQUAL 0
423 * GST_VALUE_GREATER_THAN:
425 * Indicates that the first value provided to a comparison function
426 * (gst_value_compare()) is greater than the second one.
428 #define GST_VALUE_GREATER_THAN 1
431 * GST_VALUE_UNORDERED:
433 * Indicates that the comparison function (gst_value_compare()) can not
434 * determine a order for the two provided values.
436 #define GST_VALUE_UNORDERED 2
439 * GstValueCompareFunc:
440 * @value1: first value for comparison
441 * @value2: second value for comparison
443 * Used together with gst_value_compare() to compare #GValue items.
445 * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
446 * or GST_VALUE_UNORDERED
448 typedef gint (* GstValueCompareFunc) (const GValue *value1,
449 const GValue *value2);
452 * GstValueSerializeFunc:
455 * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
457 * Free-function: g_free
459 * Returns: (transfer full): the string representation of the value
461 typedef gchar * (* GstValueSerializeFunc) (const GValue *value1);
464 * GstValueDeserializeFunc:
468 * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
470 * Returns: %TRUE for success
472 typedef gboolean (* GstValueDeserializeFunc) (GValue *dest,
476 * GstValueDeserializeWithPSpecFunc:
479 * @pspec: a #GParamSpec describing the expected value
481 * Used by gst_value_deserialize_with_pspec() to parse a non-binary form into the #GValue.
483 * Returns: %TRUE for success
486 typedef gboolean (* GstValueDeserializeWithPSpecFunc) (GValue *dest,
491 typedef struct _GstValueTable GstValueTable;
495 * @compare: a #GstValueCompareFunc
496 * @serialize: a #GstValueSerializeFunc
497 * @deserialize: a #GstValueDeserializeFunc
498 * @deserialize_with_pspec: a #GstValueDeserializeWithPSpecFunc
500 * VTable for the #GValue @type.
502 struct _GstValueTable {
504 GstValueCompareFunc compare;
505 GstValueSerializeFunc serialize;
506 GstValueDeserializeFunc deserialize;
509 * GstValueTable.deserialize_with_pspec:
511 * a #GstValueDeserializeWithPSpecFunc
515 GstValueDeserializeWithPSpecFunc deserialize_with_pspec;
518 gpointer _gst_reserved [GST_PADDING - 1];
522 GType gst_int_range_get_type (void);
525 GType gst_int64_range_get_type (void);
528 GType gst_double_range_get_type (void);
531 GType gst_fraction_range_get_type (void);
534 GType gst_fraction_get_type (void);
537 GType gst_value_list_get_type (void);
540 GType gst_value_array_get_type (void);
543 GType gst_bitmask_get_type (void);
546 GType gst_flagset_get_type (void);
548 /* Hide this compatibility type from introspection */
549 #ifndef __GI_SCANNER__
551 GType gst_g_thread_get_type (void);
555 void gst_value_register (const GstValueTable *table);
558 void gst_value_init_and_copy (GValue *dest,
561 gchar * gst_value_serialize (const GValue *value) G_GNUC_MALLOC;
564 gboolean gst_value_deserialize (GValue *dest,
568 gboolean gst_value_deserialize_with_pspec (GValue *dest,
575 void gst_value_list_append_value (GValue *value,
576 const GValue *append_value);
578 void gst_value_list_append_and_take_value (GValue *value,
579 GValue *append_value);
581 void gst_value_list_prepend_value (GValue *value,
582 const GValue *prepend_value);
584 void gst_value_list_concat (GValue *dest,
585 const GValue *value1,
586 const GValue *value2);
588 void gst_value_list_merge (GValue *dest,
589 const GValue *value1,
590 const GValue *value2);
592 guint gst_value_list_get_size (const GValue *value);
595 const GValue * gst_value_list_get_value (const GValue *value,
599 GValue * gst_value_list_init (GValue *value,
604 void gst_value_array_append_value (GValue *value,
605 const GValue *append_value);
607 void gst_value_array_append_and_take_value (GValue *value,
608 GValue *append_value);
610 void gst_value_array_prepend_value (GValue *value,
611 const GValue *prepend_value);
613 guint gst_value_array_get_size (const GValue *value);
616 const GValue * gst_value_array_get_value (const GValue *value,
619 GValue * gst_value_array_init (GValue *value,
625 void gst_value_set_int_range (GValue *value,
629 void gst_value_set_int_range_step (GValue *value,
634 gint gst_value_get_int_range_min (const GValue *value);
637 gint gst_value_get_int_range_max (const GValue *value);
640 gint gst_value_get_int_range_step (const GValue *value);
645 void gst_value_set_int64_range (GValue *value,
649 void gst_value_set_int64_range_step (GValue *value,
654 gint64 gst_value_get_int64_range_min (const GValue *value);
657 gint64 gst_value_get_int64_range_max (const GValue *value);
660 gint64 gst_value_get_int64_range_step (const GValue *value);
665 void gst_value_set_double_range (GValue *value,
669 gdouble gst_value_get_double_range_min (const GValue *value);
672 gdouble gst_value_get_double_range_max (const GValue *value);
677 const GstCaps * gst_value_get_caps (const GValue *value);
680 void gst_value_set_caps (GValue *value,
681 const GstCaps *caps);
687 gst_value_get_structure (const GValue *value);
690 void gst_value_set_structure (GValue *value,
691 const GstStructure *structure);
696 const GstCapsFeatures *
697 gst_value_get_caps_features (const GValue *value);
700 void gst_value_set_caps_features (GValue *value,
701 const GstCapsFeatures *features);
706 void gst_value_set_fraction (GValue *value,
710 gint gst_value_get_fraction_numerator (const GValue *value);
713 gint gst_value_get_fraction_denominator (const GValue *value);
716 gboolean gst_value_fraction_multiply (GValue *product,
717 const GValue *factor1,
718 const GValue *factor2);
720 gboolean gst_value_fraction_subtract (GValue * dest,
721 const GValue * minuend,
722 const GValue * subtrahend);
727 void gst_value_set_fraction_range (GValue *value,
731 void gst_value_set_fraction_range_full (GValue *value,
732 gint numerator_start,
733 gint denominator_start,
735 gint denominator_end);
737 const GValue *gst_value_get_fraction_range_min (const GValue *value);
740 const GValue *gst_value_get_fraction_range_max (const GValue *value);
745 guint64 gst_value_get_bitmask (const GValue *value);
748 void gst_value_set_bitmask (GValue *value,
753 void gst_value_set_flagset (GValue * value, guint flags, guint mask);
756 guint gst_value_get_flagset_flags (const GValue * value);
759 guint gst_value_get_flagset_mask (const GValue * value);
764 gint gst_value_compare (const GValue *value1,
765 const GValue *value2);
767 gboolean gst_value_can_compare (const GValue *value1,
768 const GValue *value2);
770 gboolean gst_value_is_subset (const GValue *value1,
771 const GValue *value2);
776 gboolean gst_value_union (GValue *dest,
777 const GValue *value1,
778 const GValue *value2);
780 gboolean gst_value_can_union (const GValue *value1,
781 const GValue *value2);
786 gboolean gst_value_intersect (GValue *dest,
787 const GValue *value1,
788 const GValue *value2);
790 gboolean gst_value_can_intersect (const GValue *value1,
791 const GValue *value2);
796 gboolean gst_value_subtract (GValue *dest,
797 const GValue *minuend,
798 const GValue *subtrahend);
800 gboolean gst_value_can_subtract (const GValue *minuend,
801 const GValue *subtrahend);
806 gboolean gst_value_is_fixed (const GValue *value);
809 gboolean gst_value_fixate (GValue *dest,
812 /* Flagset registration wrapper */
815 GType gst_flagset_register (GType flags_type);