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:
215 * A mask value with all bits set, for use as a
216 * #GstFlagSet mask where all flag bits must match
221 #define GST_FLAG_SET_MASK_EXACT ((guint)(-1))
223 GST_EXPORT GType _gst_int_range_type;
226 * GST_TYPE_INT_RANGE:
228 * a #GValue type that represents an integer range
230 * Returns: the #GType of GstIntRange
232 #define GST_TYPE_INT_RANGE (_gst_int_range_type)
234 GST_EXPORT GType _gst_int64_range_type;
237 * GST_TYPE_INT64_RANGE:
239 * a #GValue type that represents an #gint64 range
241 * Returns: the #GType of GstInt64Range
243 #define GST_TYPE_INT64_RANGE (_gst_int64_range_type)
245 GST_EXPORT GType _gst_double_range_type;
248 * GST_TYPE_DOUBLE_RANGE:
250 * a #GValue type that represents a floating point range with double precision
252 * Returns: the #GType of GstIntRange
254 #define GST_TYPE_DOUBLE_RANGE (_gst_double_range_type)
256 GST_EXPORT GType _gst_fraction_range_type;
259 * GST_TYPE_FRACTION_RANGE:
261 * a #GValue type that represents a GstFraction range
263 * Returns: the #GType of GstFractionRange
265 #define GST_TYPE_FRACTION_RANGE (_gst_fraction_range_type)
267 GST_EXPORT GType _gst_value_list_type;
272 * a #GValue type that represents an unordered list of #GValue values. This
273 * is used for example to express a list of possible values for a field in
274 * a caps structure, like a list of possible sample rates, of which only one
275 * will be chosen in the end. This means that all values in the list are
276 * meaningful on their own.
278 * Returns: the #GType of GstValueList (which is not explicitly typed)
280 #define GST_TYPE_LIST (_gst_value_list_type)
282 GST_EXPORT GType _gst_value_array_type;
287 * a #GValue type that represents an ordered list of #GValue values. This is
288 * used to express a set of values that is meaningful only in their specific
289 * combination and order of values. Each value on its own is not particularly
290 * meaningful, only the ordered array in its entirety is meaningful. This is
291 * used for example to express channel layouts for multichannel audio where
292 * each channel needs to be mapped to a position in the room.
294 * Returns: the #GType of GstArrayList (which is not explicitly typed)
296 #define GST_TYPE_ARRAY (_gst_value_array_type)
298 GST_EXPORT GType _gst_fraction_type;
303 * a #GValue type that represents a fraction of an integer numerator over
304 * an integer denominator
306 * Returns: the #GType of GstFraction (which is not explicitly typed)
309 #define GST_TYPE_FRACTION (_gst_fraction_type)
311 GST_EXPORT GType _gst_bitmask_type;
316 * a #GValue type that represents a 64-bit bitmask.
318 * Returns: the #GType of GstBitmask (which is not explicitly typed)
321 #define GST_TYPE_BITMASK (_gst_bitmask_type)
323 GST_EXPORT GType _gst_flagset_type;
328 * a #GValue type that represents a 32-bit flag bitfield, with 32-bit
329 * mask indicating which of the bits in the field are explicitly set.
330 * Useful for negotiation.
332 * Returns: the #GType of GstFlags (which is not explicitly typed)
336 #define GST_TYPE_FLAG_SET (_gst_flagset_type)
341 * a boxed #GValue type for #GThread that represents a thread.
343 * Returns: the #GType of GstGThread
346 #define GST_TYPE_G_THREAD gst_g_thread_get_type ()
349 * GST_VALUE_LESS_THAN:
351 * Indicates that the first value provided to a comparison function
352 * (gst_value_compare()) is lesser than the second one.
354 #define GST_VALUE_LESS_THAN (-1)
359 * Indicates that the first value provided to a comparison function
360 * (gst_value_compare()) is equal to the second one.
362 #define GST_VALUE_EQUAL 0
365 * GST_VALUE_GREATER_THAN:
367 * Indicates that the first value provided to a comparison function
368 * (gst_value_compare()) is greater than the second one.
370 #define GST_VALUE_GREATER_THAN 1
373 * GST_VALUE_UNORDERED:
375 * Indicates that the comparison function (gst_value_compare()) can not
376 * determine a order for the two provided values.
378 #define GST_VALUE_UNORDERED 2
381 * GstValueCompareFunc:
382 * @value1: first value for comparison
383 * @value2: second value for comparison
385 * Used together with gst_value_compare() to compare #GValue items.
387 * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
388 * or GST_VALUE_UNORDERED
390 typedef gint (* GstValueCompareFunc) (const GValue *value1,
391 const GValue *value2);
394 * GstValueSerializeFunc:
397 * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
399 * Free-function: g_free
401 * Returns: (transfer full): the string representation of the value
403 typedef gchar * (* GstValueSerializeFunc) (const GValue *value1);
406 * GstValueDeserializeFunc:
410 * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
412 * Returns: %TRUE for success
414 typedef gboolean (* GstValueDeserializeFunc) (GValue *dest,
417 typedef struct _GstValueTable GstValueTable;
421 * @compare: a #GstValueCompareFunc
422 * @serialize: a #GstValueSerializeFunc
423 * @deserialize: a #GstValueDeserializeFunc
425 * VTable for the #GValue @type.
427 struct _GstValueTable {
429 GstValueCompareFunc compare;
430 GstValueSerializeFunc serialize;
431 GstValueDeserializeFunc deserialize;
434 gpointer _gst_reserved [GST_PADDING];
437 GType gst_int_range_get_type (void);
438 GType gst_int64_range_get_type (void);
439 GType gst_double_range_get_type (void);
440 GType gst_fraction_range_get_type (void);
441 GType gst_fraction_get_type (void);
442 GType gst_value_list_get_type (void);
443 GType gst_value_array_get_type (void);
444 GType gst_bitmask_get_type (void);
445 GType gst_flagset_get_type (void);
447 /* Hide this compatibility type from introspection */
448 #ifndef __GI_SCANNER__
449 GType gst_g_thread_get_type (void);
452 void gst_value_register (const GstValueTable *table);
453 void gst_value_init_and_copy (GValue *dest,
456 gchar * gst_value_serialize (const GValue *value) G_GNUC_MALLOC;
457 gboolean gst_value_deserialize (GValue *dest,
461 void gst_value_list_append_value (GValue *value,
462 const GValue *append_value);
463 void gst_value_list_append_and_take_value (GValue *value,
464 GValue *append_value);
465 void gst_value_list_prepend_value (GValue *value,
466 const GValue *prepend_value);
467 void gst_value_list_concat (GValue *dest,
468 const GValue *value1,
469 const GValue *value2);
470 void gst_value_list_merge (GValue *dest,
471 const GValue *value1,
472 const GValue *value2);
473 guint gst_value_list_get_size (const GValue *value);
474 const GValue * gst_value_list_get_value (const GValue *value,
478 void gst_value_array_append_value (GValue *value,
479 const GValue *append_value);
480 void gst_value_array_append_and_take_value (GValue *value,
481 GValue *append_value);
482 void gst_value_array_prepend_value (GValue *value,
483 const GValue *prepend_value);
484 guint gst_value_array_get_size (const GValue *value);
485 const GValue * gst_value_array_get_value (const GValue *value,
489 void gst_value_set_int_range (GValue *value,
492 void gst_value_set_int_range_step (GValue *value,
496 gint gst_value_get_int_range_min (const GValue *value);
497 gint gst_value_get_int_range_max (const GValue *value);
498 gint gst_value_get_int_range_step (const GValue *value);
501 void gst_value_set_int64_range (GValue *value,
504 void gst_value_set_int64_range_step (GValue *value,
508 gint64 gst_value_get_int64_range_min (const GValue *value);
509 gint64 gst_value_get_int64_range_max (const GValue *value);
510 gint64 gst_value_get_int64_range_step (const GValue *value);
513 void gst_value_set_double_range (GValue *value,
516 gdouble gst_value_get_double_range_min (const GValue *value);
517 gdouble gst_value_get_double_range_max (const GValue *value);
520 const GstCaps * gst_value_get_caps (const GValue *value);
521 void gst_value_set_caps (GValue *value,
522 const GstCaps *caps);
526 gst_value_get_structure (const GValue *value);
527 void gst_value_set_structure (GValue *value,
528 const GstStructure *structure);
531 const GstCapsFeatures *
532 gst_value_get_caps_features (const GValue *value);
533 void gst_value_set_caps_features (GValue *value,
534 const GstCapsFeatures *features);
537 void gst_value_set_fraction (GValue *value,
540 gint gst_value_get_fraction_numerator (const GValue *value);
541 gint gst_value_get_fraction_denominator (const GValue *value);
542 gboolean gst_value_fraction_multiply (GValue *product,
543 const GValue *factor1,
544 const GValue *factor2);
545 gboolean gst_value_fraction_subtract (GValue * dest,
546 const GValue * minuend,
547 const GValue * subtrahend);
550 void gst_value_set_fraction_range (GValue *value,
553 void gst_value_set_fraction_range_full (GValue *value,
554 gint numerator_start,
555 gint denominator_start,
557 gint denominator_end);
558 const GValue *gst_value_get_fraction_range_min (const GValue *value);
559 const GValue *gst_value_get_fraction_range_max (const GValue *value);
562 guint64 gst_value_get_bitmask (const GValue *value);
563 void gst_value_set_bitmask (GValue *value,
566 void gst_value_set_flagset (GValue * value, guint flags, guint mask);
567 guint gst_value_get_flagset_flags (const GValue * value);
568 guint gst_value_get_flagset_mask (const GValue * value);
571 gint gst_value_compare (const GValue *value1,
572 const GValue *value2);
573 gboolean gst_value_can_compare (const GValue *value1,
574 const GValue *value2);
575 gboolean gst_value_is_subset (const GValue *value1,
576 const GValue *value2);
579 gboolean gst_value_union (GValue *dest,
580 const GValue *value1,
581 const GValue *value2);
582 gboolean gst_value_can_union (const GValue *value1,
583 const GValue *value2);
586 gboolean gst_value_intersect (GValue *dest,
587 const GValue *value1,
588 const GValue *value2);
589 gboolean gst_value_can_intersect (const GValue *value1,
590 const GValue *value2);
593 gboolean gst_value_subtract (GValue *dest,
594 const GValue *minuend,
595 const GValue *subtrahend);
596 gboolean gst_value_can_subtract (const GValue *minuend,
597 const GValue *subtrahend);
600 gboolean gst_value_is_fixed (const GValue *value);
601 gboolean gst_value_fixate (GValue *dest,
604 /* Flagset registration wrapper */
605 GType gst_flagset_register (GType flags_type);