value: Properly set value and type for GST_FLAG_SET_MASK_EXACT in GI annotations
[platform/upstream/gstreamer.git] / gst / gstvalue.h
1 /* GStreamer
2  * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #ifndef __GST_VALUE_H__
21 #define __GST_VALUE_H__
22
23 #include <gst/gstconfig.h>
24 #include <gst/gstcaps.h>
25 #include <gst/gststructure.h>
26 #include <gst/gstcapsfeatures.h>
27
28 G_BEGIN_DECLS
29
30 /**
31  * GST_MAKE_FOURCC:
32  * @a: the first character
33  * @b: the second character
34  * @c: the third character
35  * @d: the fourth character
36  *
37  * Transform four characters into a #guint32 fourcc value with host
38  * endianness.
39  *
40  * |[
41  * guint32 fourcc = GST_MAKE_FOURCC ('M', 'J', 'P', 'G');
42  * ]|
43  *
44  */
45 #define GST_MAKE_FOURCC(a,b,c,d)        ((guint32)((a)|(b)<<8|(c)<<16|(d)<<24))
46
47 /**
48  * GST_STR_FOURCC:
49  * @f: a string with at least four characters
50  *
51  * Transform an input string into a #guint32 fourcc value with host
52  * endianness.
53  * Caller is responsible for ensuring the input string consists of at least
54  * four characters.
55  *
56  * |[
57  * guint32 fourcc = GST_STR_FOURCC ("MJPG");
58  * ]|
59  *
60  */
61 #define GST_STR_FOURCC(f)               ((guint32)(((f)[0])|((f)[1]<<8)|((f)[2]<<16)|((f)[3]<<24)))
62
63 /**
64  * GST_FOURCC_FORMAT:
65  *
66  * Can be used together with #GST_FOURCC_ARGS to properly output a
67  * #guint32 fourcc value in a printf()-style text message.
68  *
69  * |[
70  * printf ("fourcc: %" GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS (fcc));
71  * ]|
72  *
73  */
74 #define GST_FOURCC_FORMAT "c%c%c%c"
75
76 /**
77  * GST_FOURCC_ARGS:
78  * @fourcc: a #guint32 fourcc value to output
79  *
80  * Can be used together with #GST_FOURCC_FORMAT to properly output a
81  * #guint32 fourcc value in a printf()-style text message.
82  */
83
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)
91 /**
92  * GST_VALUE_HOLDS_INT_RANGE:
93  * @x: the #GValue to check
94  *
95  * Checks if the given #GValue contains a #GST_TYPE_INT_RANGE value.
96  */
97 #define GST_VALUE_HOLDS_INT_RANGE(x)      ((x) != NULL && G_VALUE_TYPE(x) == _gst_int_range_type)
98
99 /**
100  * GST_VALUE_HOLDS_INT64_RANGE:
101  * @x: the #GValue to check
102  *
103  * Checks if the given #GValue contains a #GST_TYPE_INT64_RANGE value.
104  */
105 #define GST_VALUE_HOLDS_INT64_RANGE(x)    ((x) != NULL && G_VALUE_TYPE(x) == _gst_int64_range_type)
106
107 /**
108  * GST_VALUE_HOLDS_DOUBLE_RANGE:
109  * @x: the #GValue to check
110  *
111  * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
112  */
113 #define GST_VALUE_HOLDS_DOUBLE_RANGE(x)   ((x) != NULL && G_VALUE_TYPE(x) == _gst_double_range_type)
114
115 /**
116  * GST_VALUE_HOLDS_FRACTION_RANGE:
117  * @x: the #GValue to check
118  *
119  * Checks if the given #GValue contains a #GST_TYPE_FRACTION_RANGE value.
120  */
121 #define GST_VALUE_HOLDS_FRACTION_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_range_type)
122
123 /**
124  * GST_VALUE_HOLDS_LIST:
125  * @x: the #GValue to check
126  *
127  * Checks if the given #GValue contains a #GST_TYPE_LIST value.
128  */
129 #define GST_VALUE_HOLDS_LIST(x)         ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_list_type)
130
131 /**
132  * GST_VALUE_HOLDS_ARRAY:
133  * @x: the #GValue to check
134  *
135  * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
136  */
137 #define GST_VALUE_HOLDS_ARRAY(x)        ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_array_type)
138
139 /**
140  * GST_VALUE_HOLDS_CAPS:
141  * @x: the #GValue to check
142  *
143  * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
144  */
145 #define GST_VALUE_HOLDS_CAPS(x)         ((x) != NULL && G_VALUE_TYPE(x) == _gst_caps_type)
146
147 /**
148  * GST_VALUE_HOLDS_STRUCTURE:
149  * @x: the #GValue to check
150  *
151  * Checks if the given #GValue contains a #GST_TYPE_STRUCTURE value.
152  */
153 #define GST_VALUE_HOLDS_STRUCTURE(x)            (G_VALUE_HOLDS((x), _gst_structure_type))
154
155 /**
156  * GST_VALUE_HOLDS_CAPS_FEATURES:
157  * @x: the #GValue to check
158  *
159  * Checks if the given #GValue contains a #GST_TYPE_CAPS_FEATURES value.
160  */
161 #define GST_VALUE_HOLDS_CAPS_FEATURES(x)        (G_VALUE_HOLDS((x), _gst_caps_features_type))
162
163 /**
164  * GST_VALUE_HOLDS_BUFFER:
165  * @x: the #GValue to check
166  *
167  * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
168  */
169 #define GST_VALUE_HOLDS_BUFFER(x)       ((x) != NULL && G_VALUE_TYPE(x) == _gst_buffer_type)
170
171 /**
172  * GST_VALUE_HOLDS_SAMPLE:
173  * @x: the #GValue to check
174  *
175  * Checks if the given #GValue contains a #GST_TYPE_SAMPLE value.
176  */
177 #define GST_VALUE_HOLDS_SAMPLE(x)       ((x) != NULL && G_VALUE_TYPE(x) == _gst_sample_type)
178
179 /**
180  * GST_VALUE_HOLDS_FRACTION:
181  * @x: the #GValue to check
182  *
183  * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
184  */
185 #define GST_VALUE_HOLDS_FRACTION(x)     ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_type)
186
187 /**
188  * GST_VALUE_HOLDS_DATE_TIME:
189  * @x: the #GValue to check
190  *
191  * Checks if the given #GValue contains a #GST_TYPE_DATE_TIME value.
192  */
193 #define GST_VALUE_HOLDS_DATE_TIME(x)    ((x) != NULL && G_VALUE_TYPE(x) == _gst_date_time_type)
194
195 /**
196  * GST_VALUE_HOLDS_BITMASK:
197  * @x: the #GValue to check
198  *
199  * Checks if the given #GValue contains a #GST_TYPE_BITMASK value.
200  */
201 #define GST_VALUE_HOLDS_BITMASK(x)      ((x) != NULL && G_VALUE_TYPE(x) == _gst_bitmask_type)
202
203 /**
204  * GST_VALUE_HOLDS_FLAG_SET:
205  * @x: the #GValue to check
206  *
207  * Checks if the given #GValue contains a #GST_TYPE_FLAG_SET value.
208  *
209  * Since: 1.6
210  */
211 #define GST_VALUE_HOLDS_FLAG_SET(x)     (G_TYPE_CHECK_VALUE_TYPE ((x), GST_TYPE_FLAG_SET))
212
213 /**
214  * GST_FLAG_SET_MASK_EXACT: (value 4294967295) (type guint)
215  *
216  * A mask value with all bits set, for use as a
217  * #GstFlagSet mask where all flag bits must match
218  * exactly
219  *
220  * Since: 1.6
221  */
222 #define GST_FLAG_SET_MASK_EXACT ((guint)(-1))
223
224 GST_EXPORT GType _gst_int_range_type;
225
226 /**
227  * GST_TYPE_INT_RANGE:
228  *
229  * a #GValue type that represents an integer range
230  *
231  * Returns: the #GType of GstIntRange
232  */
233 #define GST_TYPE_INT_RANGE               (_gst_int_range_type)
234
235 GST_EXPORT GType _gst_int64_range_type;
236
237 /**
238  * GST_TYPE_INT64_RANGE:
239  *
240  * a #GValue type that represents an #gint64 range
241  *
242  * Returns: the #GType of GstInt64Range
243  */
244 #define GST_TYPE_INT64_RANGE             (_gst_int64_range_type)
245
246 GST_EXPORT GType _gst_double_range_type;
247
248 /**
249  * GST_TYPE_DOUBLE_RANGE:
250  *
251  * a #GValue type that represents a floating point range with double precision
252  *
253  * Returns: the #GType of GstIntRange
254  */
255 #define GST_TYPE_DOUBLE_RANGE            (_gst_double_range_type)
256
257 GST_EXPORT GType _gst_fraction_range_type;
258
259 /**
260  * GST_TYPE_FRACTION_RANGE:
261  *
262  * a #GValue type that represents a GstFraction range
263  *
264  * Returns: the #GType of GstFractionRange
265  */
266 #define GST_TYPE_FRACTION_RANGE           (_gst_fraction_range_type)
267
268 GST_EXPORT GType _gst_value_list_type;
269
270 /**
271  * GST_TYPE_LIST:
272  *
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.
278  *
279  * Returns: the #GType of GstValueList (which is not explicitly typed)
280  */
281 #define GST_TYPE_LIST                    (_gst_value_list_type)
282
283 GST_EXPORT GType _gst_value_array_type;
284
285 /**
286  * GST_TYPE_ARRAY:
287  *
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.
294  *
295  * Returns: the #GType of GstArrayList (which is not explicitly typed)
296  */
297 #define GST_TYPE_ARRAY                   (_gst_value_array_type)
298
299 GST_EXPORT GType _gst_fraction_type;
300
301 /**
302  * GST_TYPE_FRACTION:
303  *
304  * a #GValue type that represents a fraction of an integer numerator over
305  * an integer denominator
306  *
307  * Returns: the #GType of GstFraction (which is not explicitly typed)
308  */
309
310 #define GST_TYPE_FRACTION                (_gst_fraction_type)
311
312 GST_EXPORT GType _gst_bitmask_type;
313
314 /**
315  * GST_TYPE_BITMASK:
316  *
317  * a #GValue type that represents a 64-bit bitmask.
318  *
319  * Returns: the #GType of GstBitmask (which is not explicitly typed)
320  */
321
322 #define GST_TYPE_BITMASK                 (_gst_bitmask_type)
323
324 GST_EXPORT GType _gst_flagset_type;
325
326 /**
327  * GST_TYPE_FLAG_SET:
328  *
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.
332  *
333  * Returns: the #GType of GstFlags (which is not explicitly typed)
334  *
335  * Since: 1.6
336  */
337 #define GST_TYPE_FLAG_SET                   (_gst_flagset_type)
338
339 /**
340  * GST_TYPE_G_THREAD:
341  *
342  * a boxed #GValue type for #GThread that represents a thread.
343  *
344  * Returns: the #GType of GstGThread
345  */
346
347 #define GST_TYPE_G_THREAD                gst_g_thread_get_type ()
348
349 /**
350  * GST_VALUE_LESS_THAN:
351  *
352  * Indicates that the first value provided to a comparison function
353  * (gst_value_compare()) is lesser than the second one.
354  */
355 #define GST_VALUE_LESS_THAN              (-1)
356
357 /**
358  * GST_VALUE_EQUAL:
359  *
360  * Indicates that the first value provided to a comparison function
361  * (gst_value_compare()) is equal to the second one.
362  */
363 #define GST_VALUE_EQUAL                   0
364
365 /**
366  * GST_VALUE_GREATER_THAN:
367  *
368  * Indicates that the first value provided to a comparison function
369  * (gst_value_compare()) is greater than the second one.
370  */
371 #define GST_VALUE_GREATER_THAN            1
372
373 /**
374  * GST_VALUE_UNORDERED:
375  *
376  * Indicates that the comparison function (gst_value_compare()) can not
377  * determine a order for the two provided values.
378  */
379 #define GST_VALUE_UNORDERED               2
380
381 /**
382  * GstValueCompareFunc:
383  * @value1: first value for comparison
384  * @value2: second value for comparison
385  *
386  * Used together with gst_value_compare() to compare #GValue items.
387  *
388  * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
389  * or GST_VALUE_UNORDERED
390  */
391 typedef gint     (* GstValueCompareFunc)     (const GValue *value1,
392                                               const GValue *value2);
393
394 /**
395  * GstValueSerializeFunc:
396  * @value1: a #GValue
397  *
398  * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
399  *
400  * Free-function: g_free
401  *
402  * Returns: (transfer full): the string representation of the value
403  */
404 typedef gchar *  (* GstValueSerializeFunc)   (const GValue *value1);
405
406 /**
407  * GstValueDeserializeFunc:
408  * @dest: a #GValue
409  * @s: a string
410  *
411  * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
412  *
413  * Returns: %TRUE for success
414  */
415 typedef gboolean (* GstValueDeserializeFunc) (GValue       *dest,
416                                               const gchar  *s);
417
418 typedef struct _GstValueTable GstValueTable;
419 /**
420  * GstValueTable:
421  * @type: a #GType
422  * @compare: a #GstValueCompareFunc
423  * @serialize: a #GstValueSerializeFunc
424  * @deserialize: a #GstValueDeserializeFunc
425  *
426  * VTable for the #GValue @type.
427  */
428 struct _GstValueTable {
429   GType type;
430   GstValueCompareFunc compare;
431   GstValueSerializeFunc serialize;
432   GstValueDeserializeFunc deserialize;
433
434   /*< private >*/
435   gpointer _gst_reserved [GST_PADDING];
436 };
437
438 GType gst_int_range_get_type (void);
439 GType gst_int64_range_get_type (void);
440 GType gst_double_range_get_type (void);
441 GType gst_fraction_range_get_type (void);
442 GType gst_fraction_get_type (void);
443 GType gst_value_list_get_type (void);
444 GType gst_value_array_get_type (void);
445 GType gst_bitmask_get_type (void);
446 GType gst_flagset_get_type (void);
447
448 /* Hide this compatibility type from introspection */
449 #ifndef __GI_SCANNER__
450 GType gst_g_thread_get_type (void);
451 #endif
452
453 void            gst_value_register              (const GstValueTable   *table);
454 void            gst_value_init_and_copy         (GValue                *dest,
455                                                  const GValue          *src);
456
457 gchar *         gst_value_serialize             (const GValue          *value) G_GNUC_MALLOC;
458 gboolean        gst_value_deserialize           (GValue                *dest,
459                                                  const gchar           *src);
460
461 /* list */
462 void            gst_value_list_append_value     (GValue         *value,
463                                                  const GValue   *append_value);
464 void            gst_value_list_append_and_take_value (GValue         *value,
465                                                  GValue   *append_value);
466 void            gst_value_list_prepend_value    (GValue         *value,
467                                                  const GValue   *prepend_value);
468 void            gst_value_list_concat           (GValue         *dest,
469                                                  const GValue   *value1,
470                                                  const GValue   *value2);
471 void            gst_value_list_merge            (GValue         *dest,
472                                                  const GValue   *value1,
473                                                  const GValue   *value2);
474 guint           gst_value_list_get_size         (const GValue   *value);
475 const GValue *  gst_value_list_get_value        (const GValue   *value,
476                                                  guint          index);
477
478 /* array */
479 void            gst_value_array_append_value    (GValue         *value,
480                                                  const GValue   *append_value);
481 void            gst_value_array_append_and_take_value    (GValue         *value,
482                                                  GValue   *append_value);
483 void            gst_value_array_prepend_value   (GValue         *value,
484                                                  const GValue   *prepend_value);
485 guint           gst_value_array_get_size        (const GValue   *value);
486 const GValue *  gst_value_array_get_value       (const GValue   *value,
487                                                  guint          index);
488
489 /* int range */
490 void            gst_value_set_int_range         (GValue         *value,
491                                                  gint           start,
492                                                  gint           end);
493 void            gst_value_set_int_range_step    (GValue         *value,
494                                                  gint           start,
495                                                  gint           end,
496                                                  gint           step);
497 gint            gst_value_get_int_range_min     (const GValue   *value);
498 gint            gst_value_get_int_range_max     (const GValue   *value);
499 gint            gst_value_get_int_range_step    (const GValue   *value);
500
501 /* int64 range */
502 void            gst_value_set_int64_range       (GValue         *value,
503                                                  gint64         start,
504                                                  gint64         end);
505 void            gst_value_set_int64_range_step  (GValue         *value,
506                                                  gint64         start,
507                                                  gint64         end,
508                                                  gint64         step);
509 gint64          gst_value_get_int64_range_min   (const GValue   *value);
510 gint64          gst_value_get_int64_range_max   (const GValue   *value);
511 gint64          gst_value_get_int64_range_step  (const GValue   *value);
512
513 /* double range */
514 void            gst_value_set_double_range      (GValue         *value,
515                                                  gdouble        start,
516                                                  gdouble        end);
517 gdouble         gst_value_get_double_range_min  (const GValue   *value);
518 gdouble         gst_value_get_double_range_max  (const GValue   *value);
519
520 /* caps */
521 const GstCaps * gst_value_get_caps              (const GValue   *value);
522 void            gst_value_set_caps              (GValue         *value,
523                                                  const GstCaps  *caps);
524
525 /* structure */
526 const GstStructure *
527                 gst_value_get_structure         (const GValue   *value);
528 void            gst_value_set_structure         (GValue         *value,
529                                                  const GstStructure  *structure);
530
531 /* caps features */
532 const GstCapsFeatures *
533                 gst_value_get_caps_features     (const GValue   *value);
534 void            gst_value_set_caps_features     (GValue         *value,
535                                                  const GstCapsFeatures  *features);
536
537 /* fraction */
538 void            gst_value_set_fraction          (GValue         *value,
539                                                  gint           numerator,
540                                                  gint           denominator);
541 gint            gst_value_get_fraction_numerator   (const GValue  *value);
542 gint            gst_value_get_fraction_denominator (const GValue *value);
543 gboolean        gst_value_fraction_multiply        (GValue         *product,
544                                                     const GValue   *factor1,
545                                                     const GValue   *factor2);
546 gboolean        gst_value_fraction_subtract     (GValue * dest,
547                                                  const GValue * minuend,
548                                                  const GValue * subtrahend);
549
550 /* fraction range */
551 void            gst_value_set_fraction_range    (GValue         *value,
552                                                  const GValue   *start,
553                                                  const GValue   *end);
554 void            gst_value_set_fraction_range_full (GValue       *value,
555                                                  gint numerator_start,
556                                                  gint denominator_start,
557                                                  gint numerator_end,
558                                                  gint denominator_end);
559 const GValue    *gst_value_get_fraction_range_min (const GValue *value);
560 const GValue    *gst_value_get_fraction_range_max (const GValue *value);
561
562 /* bitmask */
563 guint64         gst_value_get_bitmask           (const GValue   *value);
564 void            gst_value_set_bitmask           (GValue         *value,
565                                                  guint64         bitmask);
566 /* flagset */
567 void            gst_value_set_flagset (GValue * value, guint flags, guint mask);
568 guint           gst_value_get_flagset_flags (const GValue * value);
569 guint           gst_value_get_flagset_mask (const GValue * value);
570
571 /* compare */
572 gint            gst_value_compare               (const GValue   *value1,
573                                                  const GValue   *value2);
574 gboolean        gst_value_can_compare           (const GValue   *value1,
575                                                  const GValue   *value2);
576 gboolean        gst_value_is_subset             (const GValue   *value1,
577                                                  const GValue   *value2);
578
579 /* union */
580 gboolean        gst_value_union                 (GValue         *dest,
581                                                  const GValue   *value1,
582                                                  const GValue   *value2);
583 gboolean        gst_value_can_union             (const GValue   *value1,
584                                                  const GValue   *value2);
585
586 /* intersection */
587 gboolean        gst_value_intersect             (GValue         *dest,
588                                                  const GValue   *value1,
589                                                  const GValue   *value2);
590 gboolean        gst_value_can_intersect         (const GValue   *value1,
591                                                  const GValue   *value2);
592
593 /* subtraction */
594 gboolean        gst_value_subtract              (GValue         *dest,
595                                                  const GValue   *minuend,
596                                                  const GValue   *subtrahend);
597 gboolean        gst_value_can_subtract          (const GValue   *minuend,
598                                                  const GValue   *subtrahend);
599
600 /* fixation */
601 gboolean        gst_value_is_fixed              (const GValue   *value);
602 gboolean        gst_value_fixate                (GValue         *dest,
603                                                  const GValue   *src);
604
605 /* Flagset registration wrapper */
606 GType           gst_flagset_register (GType flags_type);
607
608 G_END_DECLS
609
610 #endif
611
612