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)
203 GST_EXPORT GType _gst_int_range_type;
206 * GST_TYPE_INT_RANGE:
208 * a #GValue type that represents an integer range
210 * Returns: the #GType of GstIntRange
212 #define GST_TYPE_INT_RANGE (_gst_int_range_type)
214 GST_EXPORT GType _gst_int64_range_type;
217 * GST_TYPE_INT64_RANGE:
219 * a #GValue type that represents an #gint64 range
221 * Returns: the #GType of GstInt64Range
223 #define GST_TYPE_INT64_RANGE (_gst_int64_range_type)
225 GST_EXPORT GType _gst_double_range_type;
228 * GST_TYPE_DOUBLE_RANGE:
230 * a #GValue type that represents a floating point range with double precision
232 * Returns: the #GType of GstIntRange
234 #define GST_TYPE_DOUBLE_RANGE (_gst_double_range_type)
236 GST_EXPORT GType _gst_fraction_range_type;
239 * GST_TYPE_FRACTION_RANGE:
241 * a #GValue type that represents a GstFraction range
243 * Returns: the #GType of GstFractionRange
245 #define GST_TYPE_FRACTION_RANGE (_gst_fraction_range_type)
247 GST_EXPORT GType _gst_value_list_type;
252 * a #GValue type that represents an unordered list of #GValue values. This
253 * is used for example to express a list of possible values for a field in
254 * a caps structure, like a list of possible sample rates, of which only one
255 * will be chosen in the end. This means that all values in the list are
256 * meaningful on their own.
258 * Returns: the #GType of GstValueList (which is not explicitly typed)
260 #define GST_TYPE_LIST (_gst_value_list_type)
262 GST_EXPORT GType _gst_value_array_type;
267 * a #GValue type that represents an ordered list of #GValue values. This is
268 * used to express a set of values that is meaningful only in their specific
269 * combination and order of values. Each value on its own is not particularly
270 * meaningful, only the ordered array in its entirety is meaningful. This is
271 * used for example to express channel layouts for multichannel audio where
272 * each channel needs to be mapped to a position in the room.
274 * Returns: the #GType of GstArrayList (which is not explicitly typed)
276 #define GST_TYPE_ARRAY (_gst_value_array_type)
278 GST_EXPORT GType _gst_fraction_type;
283 * a #GValue type that represents a fraction of an integer numerator over
284 * an integer denominator
286 * Returns: the #GType of GstFraction (which is not explicitly typed)
289 #define GST_TYPE_FRACTION (_gst_fraction_type)
291 GST_EXPORT GType _gst_bitmask_type;
296 * a #GValue type that represents a 64-bit bitmask.
298 * Returns: the #GType of GstBitmask (which is not explicitly typed)
301 #define GST_TYPE_BITMASK (_gst_bitmask_type)
306 * a boxed #GValue type for #GThread that represents a thread.
308 * Returns: the #GType of GstGThread
311 #define GST_TYPE_G_THREAD gst_g_thread_get_type ()
314 * GST_VALUE_LESS_THAN:
316 * Indicates that the first value provided to a comparison function
317 * (gst_value_compare()) is lesser than the second one.
319 #define GST_VALUE_LESS_THAN (-1)
324 * Indicates that the first value provided to a comparison function
325 * (gst_value_compare()) is equal to the second one.
327 #define GST_VALUE_EQUAL 0
330 * GST_VALUE_GREATER_THAN:
332 * Indicates that the first value provided to a comparison function
333 * (gst_value_compare()) is greater than the second one.
335 #define GST_VALUE_GREATER_THAN 1
338 * GST_VALUE_UNORDERED:
340 * Indicates that the comparison function (gst_value_compare()) can not
341 * determine a order for the two provided values.
343 #define GST_VALUE_UNORDERED 2
346 * GstValueCompareFunc:
347 * @value1: first value for comparison
348 * @value2: second value for comparison
350 * Used together with gst_value_compare() to compare #GValue items.
352 * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
353 * or GST_VALUE_UNORDERED
355 typedef gint (* GstValueCompareFunc) (const GValue *value1,
356 const GValue *value2);
359 * GstValueSerializeFunc:
362 * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
364 * Free-function: g_free
366 * Returns: (transfer full): the string representation of the value
368 typedef gchar * (* GstValueSerializeFunc) (const GValue *value1);
371 * GstValueDeserializeFunc:
375 * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
377 * Returns: %TRUE for success
379 typedef gboolean (* GstValueDeserializeFunc) (GValue *dest,
382 typedef struct _GstValueTable GstValueTable;
386 * @compare: a #GstValueCompareFunc
387 * @serialize: a #GstValueSerializeFunc
388 * @deserialize: a #GstValueDeserializeFunc
390 * VTable for the #GValue @type.
392 struct _GstValueTable {
394 GstValueCompareFunc compare;
395 GstValueSerializeFunc serialize;
396 GstValueDeserializeFunc deserialize;
399 gpointer _gst_reserved [GST_PADDING];
402 GType gst_int_range_get_type (void);
403 GType gst_int64_range_get_type (void);
404 GType gst_double_range_get_type (void);
405 GType gst_fraction_range_get_type (void);
406 GType gst_fraction_get_type (void);
407 GType gst_value_list_get_type (void);
408 GType gst_value_array_get_type (void);
409 GType gst_bitmask_get_type (void);
411 /* Hide this compatibility type from introspection */
412 #ifndef __GI_SCANNER__
413 GType gst_g_thread_get_type (void);
416 void gst_value_register (const GstValueTable *table);
417 void gst_value_init_and_copy (GValue *dest,
420 gchar * gst_value_serialize (const GValue *value) G_GNUC_MALLOC;
421 gboolean gst_value_deserialize (GValue *dest,
425 void gst_value_list_append_value (GValue *value,
426 const GValue *append_value);
427 void gst_value_list_append_and_take_value (GValue *value,
428 GValue *append_value);
429 void gst_value_list_prepend_value (GValue *value,
430 const GValue *prepend_value);
431 void gst_value_list_concat (GValue *dest,
432 const GValue *value1,
433 const GValue *value2);
434 void gst_value_list_merge (GValue *dest,
435 const GValue *value1,
436 const GValue *value2);
437 guint gst_value_list_get_size (const GValue *value);
438 const GValue * gst_value_list_get_value (const GValue *value,
442 void gst_value_array_append_value (GValue *value,
443 const GValue *append_value);
444 void gst_value_array_append_and_take_value (GValue *value,
445 GValue *append_value);
446 void gst_value_array_prepend_value (GValue *value,
447 const GValue *prepend_value);
448 guint gst_value_array_get_size (const GValue *value);
449 const GValue * gst_value_array_get_value (const GValue *value,
453 void gst_value_set_int_range (GValue *value,
456 void gst_value_set_int_range_step (GValue *value,
460 gint gst_value_get_int_range_min (const GValue *value);
461 gint gst_value_get_int_range_max (const GValue *value);
462 gint gst_value_get_int_range_step (const GValue *value);
465 void gst_value_set_int64_range (GValue *value,
468 void gst_value_set_int64_range_step (GValue *value,
472 gint64 gst_value_get_int64_range_min (const GValue *value);
473 gint64 gst_value_get_int64_range_max (const GValue *value);
474 gint64 gst_value_get_int64_range_step (const GValue *value);
477 void gst_value_set_double_range (GValue *value,
480 gdouble gst_value_get_double_range_min (const GValue *value);
481 gdouble gst_value_get_double_range_max (const GValue *value);
484 const GstCaps * gst_value_get_caps (const GValue *value);
485 void gst_value_set_caps (GValue *value,
486 const GstCaps *caps);
490 gst_value_get_structure (const GValue *value);
491 void gst_value_set_structure (GValue *value,
492 const GstStructure *structure);
495 const GstCapsFeatures *
496 gst_value_get_caps_features (const GValue *value);
497 void gst_value_set_caps_features (GValue *value,
498 const GstCapsFeatures *features);
501 void gst_value_set_fraction (GValue *value,
504 gint gst_value_get_fraction_numerator (const GValue *value);
505 gint gst_value_get_fraction_denominator (const GValue *value);
506 gboolean gst_value_fraction_multiply (GValue *product,
507 const GValue *factor1,
508 const GValue *factor2);
509 gboolean gst_value_fraction_subtract (GValue * dest,
510 const GValue * minuend,
511 const GValue * subtrahend);
514 void gst_value_set_fraction_range (GValue *value,
517 void gst_value_set_fraction_range_full (GValue *value,
518 gint numerator_start,
519 gint denominator_start,
521 gint denominator_end);
522 const GValue *gst_value_get_fraction_range_min (const GValue *value);
523 const GValue *gst_value_get_fraction_range_max (const GValue *value);
526 guint64 gst_value_get_bitmask (const GValue *value);
527 void gst_value_set_bitmask (GValue *value,
531 gint gst_value_compare (const GValue *value1,
532 const GValue *value2);
533 gboolean gst_value_can_compare (const GValue *value1,
534 const GValue *value2);
535 gboolean gst_value_is_subset (const GValue *value1,
536 const GValue *value2);
539 gboolean gst_value_union (GValue *dest,
540 const GValue *value1,
541 const GValue *value2);
542 gboolean gst_value_can_union (const GValue *value1,
543 const GValue *value2);
546 gboolean gst_value_intersect (GValue *dest,
547 const GValue *value1,
548 const GValue *value2);
549 gboolean gst_value_can_intersect (const GValue *value1,
550 const GValue *value2);
553 gboolean gst_value_subtract (GValue *dest,
554 const GValue *minuend,
555 const GValue *subtrahend);
556 gboolean gst_value_can_subtract (const GValue *minuend,
557 const GValue *subtrahend);
560 gboolean gst_value_is_fixed (const GValue *value);
561 gboolean gst_value_fixate (GValue *dest,