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.
83 #define GST_FOURCC_ARGS(fourcc) \
84 ((gchar) ((fourcc) &0xff)), \
85 ((gchar) (((fourcc)>>8 )&0xff)), \
86 ((gchar) (((fourcc)>>16)&0xff)), \
87 ((gchar) (((fourcc)>>24)&0xff))
90 * GST_VALUE_HOLDS_INT_RANGE:
91 * @x: the #GValue to check
93 * Checks if the given #GValue contains a #GST_TYPE_INT_RANGE value.
95 #define GST_VALUE_HOLDS_INT_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_int_range_type)
98 * GST_VALUE_HOLDS_INT64_RANGE:
99 * @x: the #GValue to check
101 * Checks if the given #GValue contains a #GST_TYPE_INT64_RANGE value.
103 #define GST_VALUE_HOLDS_INT64_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_int64_range_type)
106 * GST_VALUE_HOLDS_DOUBLE_RANGE:
107 * @x: the #GValue to check
109 * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
111 #define GST_VALUE_HOLDS_DOUBLE_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_double_range_type)
114 * GST_VALUE_HOLDS_FRACTION_RANGE:
115 * @x: the #GValue to check
117 * Checks if the given #GValue contains a #GST_TYPE_FRACTION_RANGE value.
119 #define GST_VALUE_HOLDS_FRACTION_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_range_type)
122 * GST_VALUE_HOLDS_LIST:
123 * @x: the #GValue to check
125 * Checks if the given #GValue contains a #GST_TYPE_LIST value.
127 #define GST_VALUE_HOLDS_LIST(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_list_type)
130 * GST_VALUE_HOLDS_ARRAY:
131 * @x: the #GValue to check
133 * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
135 #define GST_VALUE_HOLDS_ARRAY(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_array_type)
138 * GST_VALUE_HOLDS_CAPS:
139 * @x: the #GValue to check
141 * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
143 #define GST_VALUE_HOLDS_CAPS(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_caps_type)
146 * GST_VALUE_HOLDS_STRUCTURE:
147 * @x: the #GValue to check
149 * Checks if the given #GValue contains a #GST_TYPE_STRUCTURE value.
151 #define GST_VALUE_HOLDS_STRUCTURE(x) (G_VALUE_HOLDS((x), _gst_structure_type))
154 * GST_VALUE_HOLDS_CAPS_FEATURES:
155 * @x: the #GValue to check
157 * Checks if the given #GValue contains a #GST_TYPE_CAPS_FEATURES value.
159 #define GST_VALUE_HOLDS_CAPS_FEATURES(x) (G_VALUE_HOLDS((x), _gst_caps_features_type))
162 * GST_VALUE_HOLDS_BUFFER:
163 * @x: the #GValue to check
165 * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
167 #define GST_VALUE_HOLDS_BUFFER(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_buffer_type)
170 * GST_VALUE_HOLDS_SAMPLE:
171 * @x: the #GValue to check
173 * Checks if the given #GValue contains a #GST_TYPE_SAMPLE value.
175 #define GST_VALUE_HOLDS_SAMPLE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_sample_type)
178 * GST_VALUE_HOLDS_FRACTION:
179 * @x: the #GValue to check
181 * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
183 #define GST_VALUE_HOLDS_FRACTION(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_type)
186 * GST_VALUE_HOLDS_DATE_TIME:
187 * @x: the #GValue to check
189 * Checks if the given #GValue contains a #GST_TYPE_DATE_TIME value.
191 #define GST_VALUE_HOLDS_DATE_TIME(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_date_time_type)
194 * GST_VALUE_HOLDS_BITMASK:
195 * @x: the #GValue to check
197 * Checks if the given #GValue contains a #GST_TYPE_BITMASK value.
199 #define GST_VALUE_HOLDS_BITMASK(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_bitmask_type)
201 GST_EXPORT GType _gst_int_range_type;
204 * GST_TYPE_INT_RANGE:
206 * a #GValue type that represents an integer range
208 * Returns: the #GType of GstIntRange
210 #define GST_TYPE_INT_RANGE (_gst_int_range_type)
212 GST_EXPORT GType _gst_int64_range_type;
215 * GST_TYPE_INT64_RANGE:
217 * a #GValue type that represents an #gint64 range
219 * Returns: the #GType of GstInt64Range
221 #define GST_TYPE_INT64_RANGE (_gst_int64_range_type)
223 GST_EXPORT GType _gst_double_range_type;
226 * GST_TYPE_DOUBLE_RANGE:
228 * a #GValue type that represents a floating point range with double precision
230 * Returns: the #GType of GstIntRange
232 #define GST_TYPE_DOUBLE_RANGE (_gst_double_range_type)
234 GST_EXPORT GType _gst_fraction_range_type;
237 * GST_TYPE_FRACTION_RANGE:
239 * a #GValue type that represents a GstFraction range
241 * Returns: the #GType of GstFractionRange
243 #define GST_TYPE_FRACTION_RANGE (_gst_fraction_range_type)
245 GST_EXPORT GType _gst_value_list_type;
250 * a #GValue type that represents an unordered list of #GValue values. This
251 * is used for example to express a list of possible values for a field in
252 * a caps structure, like a list of possible sample rates, of which only one
253 * will be chosen in the end. This means that all values in the list are
254 * meaningful on their own.
256 * Returns: the #GType of GstValueList (which is not explicitly typed)
258 #define GST_TYPE_LIST (_gst_value_list_type)
260 GST_EXPORT GType _gst_value_array_type;
265 * a #GValue type that represents an ordered list of #GValue values. This is
266 * used to express a set of values that is meaningful only in their specific
267 * combination and order of values. Each value on its own is not particularly
268 * meaningful, only the ordered array in its entirety is meaningful. This is
269 * used for example to express channel layouts for multichannel audio where
270 * each channel needs to be mapped to a position in the room.
272 * Returns: the #GType of GstArrayList (which is not explicitly typed)
274 #define GST_TYPE_ARRAY (_gst_value_array_type)
276 GST_EXPORT GType _gst_fraction_type;
281 * a #GValue type that represents a fraction of an integer numerator over
282 * an integer denominator
284 * Returns: the #GType of GstFraction (which is not explicitly typed)
287 #define GST_TYPE_FRACTION (_gst_fraction_type)
289 GST_EXPORT GType _gst_bitmask_type;
294 * a #GValue type that represents a 64-bit bitmask.
296 * Returns: the #GType of GstBitmask (which is not explicitly typed)
299 #define GST_TYPE_BITMASK (_gst_bitmask_type)
304 * a boxed #GValue type for #GThread that represents a thread.
306 * Returns: the #GType of GstGThread
309 #define GST_TYPE_G_THREAD gst_g_thread_get_type ()
312 * GST_VALUE_LESS_THAN:
314 * Indicates that the first value provided to a comparison function
315 * (gst_value_compare()) is lesser than the second one.
317 #define GST_VALUE_LESS_THAN (-1)
322 * Indicates that the first value provided to a comparison function
323 * (gst_value_compare()) is equal to the second one.
325 #define GST_VALUE_EQUAL 0
328 * GST_VALUE_GREATER_THAN:
330 * Indicates that the first value provided to a comparison function
331 * (gst_value_compare()) is greater than the second one.
333 #define GST_VALUE_GREATER_THAN 1
336 * GST_VALUE_UNORDERED:
338 * Indicates that the comparison function (gst_value_compare()) can not
339 * determine a order for the two provided values.
341 #define GST_VALUE_UNORDERED 2
344 * GstValueCompareFunc:
345 * @value1: first value for comparison
346 * @value2: second value for comparison
348 * Used together with gst_value_compare() to compare #GValue items.
350 * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
351 * or GST_VALUE_UNORDERED
353 typedef gint (* GstValueCompareFunc) (const GValue *value1,
354 const GValue *value2);
357 * GstValueSerializeFunc:
360 * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
362 * Free-function: g_free
364 * Returns: (transfer full): the string representation of the value
366 typedef gchar * (* GstValueSerializeFunc) (const GValue *value1);
369 * GstValueDeserializeFunc:
373 * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
375 * Returns: %TRUE for success
377 typedef gboolean (* GstValueDeserializeFunc) (GValue *dest,
380 typedef struct _GstValueTable GstValueTable;
384 * @compare: a #GstValueCompareFunc
385 * @serialize: a #GstValueSerializeFunc
386 * @deserialize: a #GstValueDeserializeFunc
388 * VTable for the #GValue @type.
390 struct _GstValueTable {
392 GstValueCompareFunc compare;
393 GstValueSerializeFunc serialize;
394 GstValueDeserializeFunc deserialize;
397 gpointer _gst_reserved [GST_PADDING];
400 GType gst_int_range_get_type (void);
401 GType gst_int64_range_get_type (void);
402 GType gst_double_range_get_type (void);
403 GType gst_fraction_range_get_type (void);
404 GType gst_fraction_get_type (void);
405 GType gst_value_list_get_type (void);
406 GType gst_value_array_get_type (void);
407 GType gst_bitmask_get_type (void);
409 /* Hide this compatibility type from introspection */
410 #ifndef __GI_SCANNER__
411 GType gst_g_thread_get_type (void);
414 void gst_value_register (const GstValueTable *table);
415 void gst_value_init_and_copy (GValue *dest,
418 gchar * gst_value_serialize (const GValue *value) G_GNUC_MALLOC;
419 gboolean gst_value_deserialize (GValue *dest,
423 void gst_value_list_append_value (GValue *value,
424 const GValue *append_value);
425 void gst_value_list_append_and_take_value (GValue *value,
426 GValue *append_value);
427 void gst_value_list_prepend_value (GValue *value,
428 const GValue *prepend_value);
429 void gst_value_list_concat (GValue *dest,
430 const GValue *value1,
431 const GValue *value2);
432 void gst_value_list_merge (GValue *dest,
433 const GValue *value1,
434 const GValue *value2);
435 guint gst_value_list_get_size (const GValue *value);
436 const GValue * gst_value_list_get_value (const GValue *value,
440 void gst_value_array_append_value (GValue *value,
441 const GValue *append_value);
442 void gst_value_array_append_and_take_value (GValue *value,
443 GValue *append_value);
444 void gst_value_array_prepend_value (GValue *value,
445 const GValue *prepend_value);
446 guint gst_value_array_get_size (const GValue *value);
447 const GValue * gst_value_array_get_value (const GValue *value,
451 void gst_value_set_int_range (GValue *value,
454 void gst_value_set_int_range_step (GValue *value,
458 gint gst_value_get_int_range_min (const GValue *value);
459 gint gst_value_get_int_range_max (const GValue *value);
460 gint gst_value_get_int_range_step (const GValue *value);
463 void gst_value_set_int64_range (GValue *value,
466 void gst_value_set_int64_range_step (GValue *value,
470 gint64 gst_value_get_int64_range_min (const GValue *value);
471 gint64 gst_value_get_int64_range_max (const GValue *value);
472 gint64 gst_value_get_int64_range_step (const GValue *value);
475 void gst_value_set_double_range (GValue *value,
478 gdouble gst_value_get_double_range_min (const GValue *value);
479 gdouble gst_value_get_double_range_max (const GValue *value);
482 const GstCaps * gst_value_get_caps (const GValue *value);
483 void gst_value_set_caps (GValue *value,
484 const GstCaps *caps);
488 gst_value_get_structure (const GValue *value);
489 void gst_value_set_structure (GValue *value,
490 const GstStructure *structure);
493 const GstCapsFeatures *
494 gst_value_get_caps_features (const GValue *value);
495 void gst_value_set_caps_features (GValue *value,
496 const GstCapsFeatures *features);
499 void gst_value_set_fraction (GValue *value,
502 gint gst_value_get_fraction_numerator (const GValue *value);
503 gint gst_value_get_fraction_denominator (const GValue *value);
504 gboolean gst_value_fraction_multiply (GValue *product,
505 const GValue *factor1,
506 const GValue *factor2);
507 gboolean gst_value_fraction_subtract (GValue * dest,
508 const GValue * minuend,
509 const GValue * subtrahend);
512 void gst_value_set_fraction_range (GValue *value,
515 void gst_value_set_fraction_range_full (GValue *value,
516 gint numerator_start,
517 gint denominator_start,
519 gint denominator_end);
520 const GValue *gst_value_get_fraction_range_min (const GValue *value);
521 const GValue *gst_value_get_fraction_range_max (const GValue *value);
524 guint64 gst_value_get_bitmask (const GValue *value);
525 void gst_value_set_bitmask (GValue *value,
529 gint gst_value_compare (const GValue *value1,
530 const GValue *value2);
531 gboolean gst_value_can_compare (const GValue *value1,
532 const GValue *value2);
533 gboolean gst_value_is_subset (const GValue *value1,
534 const GValue *value2);
537 gboolean gst_value_union (GValue *dest,
538 const GValue *value1,
539 const GValue *value2);
540 gboolean gst_value_can_union (const GValue *value1,
541 const GValue *value2);
544 gboolean gst_value_intersect (GValue *dest,
545 const GValue *value1,
546 const GValue *value2);
547 gboolean gst_value_can_intersect (const GValue *value1,
548 const GValue *value2);
551 gboolean gst_value_subtract (GValue *dest,
552 const GValue *minuend,
553 const GValue *subtrahend);
554 gboolean gst_value_can_subtract (const GValue *minuend,
555 const GValue *subtrahend);
558 gboolean gst_value_is_fixed (const GValue *value);
559 gboolean gst_value_fixate (GValue *dest,