bufferpool: Don't check size in config validation
[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  * <informalexample>
40  * <programlisting>
41  * guint32 fourcc = GST_MAKE_FOURCC ('M', 'J', 'P', 'G');
42  * </programlisting>
43  * </informalexample>
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  * <informalexample>
56  * <programlisting>
57  * guint32 fourcc = GST_STR_FOURCC ("MJPG");
58  * </programlisting>
59  * </informalexample>
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  * <informalexample>
69  * <programlisting>
70  * printf ("fourcc: %" GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS (fcc));
71  * </programlisting>
72  * </informalexample>
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 #define GST_FOURCC_ARGS(fourcc) \
84         ((gchar) ((fourcc)     &0xff)), \
85         ((gchar) (((fourcc)>>8 )&0xff)), \
86         ((gchar) (((fourcc)>>16)&0xff)), \
87         ((gchar) (((fourcc)>>24)&0xff))
88
89 /**
90  * GST_VALUE_HOLDS_INT_RANGE:
91  * @x: the #GValue to check
92  *
93  * Checks if the given #GValue contains a #GST_TYPE_INT_RANGE value.
94  */
95 #define GST_VALUE_HOLDS_INT_RANGE(x)      ((x) != NULL && G_VALUE_TYPE(x) == _gst_int_range_type)
96
97 /**
98  * GST_VALUE_HOLDS_INT64_RANGE:
99  * @x: the #GValue to check
100  *
101  * Checks if the given #GValue contains a #GST_TYPE_INT64_RANGE value.
102  */
103 #define GST_VALUE_HOLDS_INT64_RANGE(x)    ((x) != NULL && G_VALUE_TYPE(x) == _gst_int64_range_type)
104
105 /**
106  * GST_VALUE_HOLDS_DOUBLE_RANGE:
107  * @x: the #GValue to check
108  *
109  * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
110  */
111 #define GST_VALUE_HOLDS_DOUBLE_RANGE(x)   ((x) != NULL && G_VALUE_TYPE(x) == _gst_double_range_type)
112
113 /**
114  * GST_VALUE_HOLDS_FRACTION_RANGE:
115  * @x: the #GValue to check
116  *
117  * Checks if the given #GValue contains a #GST_TYPE_FRACTION_RANGE value.
118  */
119 #define GST_VALUE_HOLDS_FRACTION_RANGE(x) ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_range_type)
120
121 /**
122  * GST_VALUE_HOLDS_LIST:
123  * @x: the #GValue to check
124  *
125  * Checks if the given #GValue contains a #GST_TYPE_LIST value.
126  */
127 #define GST_VALUE_HOLDS_LIST(x)         ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_list_type)
128
129 /**
130  * GST_VALUE_HOLDS_ARRAY:
131  * @x: the #GValue to check
132  *
133  * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
134  */
135 #define GST_VALUE_HOLDS_ARRAY(x)        ((x) != NULL && G_VALUE_TYPE(x) == _gst_value_array_type)
136
137 /**
138  * GST_VALUE_HOLDS_CAPS:
139  * @x: the #GValue to check
140  *
141  * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
142  */
143 #define GST_VALUE_HOLDS_CAPS(x)         ((x) != NULL && G_VALUE_TYPE(x) == _gst_caps_type)
144
145 /**
146  * GST_VALUE_HOLDS_STRUCTURE:
147  * @x: the #GValue to check
148  *
149  * Checks if the given #GValue contains a #GST_TYPE_STRUCTURE value.
150  */
151 #define GST_VALUE_HOLDS_STRUCTURE(x)            (G_VALUE_HOLDS((x), _gst_structure_type))
152
153 /**
154  * GST_VALUE_HOLDS_CAPS_FEATURES:
155  * @x: the #GValue to check
156  *
157  * Checks if the given #GValue contains a #GST_TYPE_CAPS_FEATURES value.
158  */
159 #define GST_VALUE_HOLDS_CAPS_FEATURES(x)        (G_VALUE_HOLDS((x), _gst_caps_features_type))
160
161 /**
162  * GST_VALUE_HOLDS_BUFFER:
163  * @x: the #GValue to check
164  *
165  * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
166  */
167 #define GST_VALUE_HOLDS_BUFFER(x)       ((x) != NULL && G_VALUE_TYPE(x) == _gst_buffer_type)
168
169 /**
170  * GST_VALUE_HOLDS_SAMPLE:
171  * @x: the #GValue to check
172  *
173  * Checks if the given #GValue contains a #GST_TYPE_SAMPLE value.
174  */
175 #define GST_VALUE_HOLDS_SAMPLE(x)       ((x) != NULL && G_VALUE_TYPE(x) == _gst_sample_type)
176
177 /**
178  * GST_VALUE_HOLDS_FRACTION:
179  * @x: the #GValue to check
180  *
181  * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
182  */
183 #define GST_VALUE_HOLDS_FRACTION(x)     ((x) != NULL && G_VALUE_TYPE(x) == _gst_fraction_type)
184
185 /**
186  * GST_VALUE_HOLDS_DATE_TIME:
187  * @x: the #GValue to check
188  *
189  * Checks if the given #GValue contains a #GST_TYPE_DATE_TIME value.
190  */
191 #define GST_VALUE_HOLDS_DATE_TIME(x)    ((x) != NULL && G_VALUE_TYPE(x) == _gst_date_time_type)
192
193 /**
194  * GST_VALUE_HOLDS_BITMASK:
195  * @x: the #GValue to check
196  *
197  * Checks if the given #GValue contains a #GST_TYPE_BITMASK value.
198  */
199 #define GST_VALUE_HOLDS_BITMASK(x)      ((x) != NULL && G_VALUE_TYPE(x) == _gst_bitmask_type)
200
201 GST_EXPORT GType _gst_int_range_type;
202
203 /**
204  * GST_TYPE_INT_RANGE:
205  *
206  * a #GValue type that represents an integer range
207  *
208  * Returns: the #GType of GstIntRange
209  */
210 #define GST_TYPE_INT_RANGE               (_gst_int_range_type)
211
212 GST_EXPORT GType _gst_int64_range_type;
213
214 /**
215  * GST_TYPE_INT64_RANGE:
216  *
217  * a #GValue type that represents an #gint64 range
218  *
219  * Returns: the #GType of GstInt64Range
220  */
221 #define GST_TYPE_INT64_RANGE             (_gst_int64_range_type)
222
223 GST_EXPORT GType _gst_double_range_type;
224
225 /**
226  * GST_TYPE_DOUBLE_RANGE:
227  *
228  * a #GValue type that represents a floating point range with double precision
229  *
230  * Returns: the #GType of GstIntRange
231  */
232 #define GST_TYPE_DOUBLE_RANGE            (_gst_double_range_type)
233
234 GST_EXPORT GType _gst_fraction_range_type;
235
236 /**
237  * GST_TYPE_FRACTION_RANGE:
238  *
239  * a #GValue type that represents a GstFraction range
240  *
241  * Returns: the #GType of GstFractionRange
242  */
243 #define GST_TYPE_FRACTION_RANGE           (_gst_fraction_range_type)
244
245 GST_EXPORT GType _gst_value_list_type;
246
247 /**
248  * GST_TYPE_LIST:
249  *
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.
255  *
256  * Returns: the #GType of GstValueList (which is not explicitly typed)
257  */
258 #define GST_TYPE_LIST                    (_gst_value_list_type)
259
260 GST_EXPORT GType _gst_value_array_type;
261
262 /**
263  * GST_TYPE_ARRAY:
264  *
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.
271  *
272  * Returns: the #GType of GstArrayList (which is not explicitly typed)
273  */
274 #define GST_TYPE_ARRAY                   (_gst_value_array_type)
275
276 GST_EXPORT GType _gst_fraction_type;
277
278 /**
279  * GST_TYPE_FRACTION:
280  *
281  * a #GValue type that represents a fraction of an integer numerator over
282  * an integer denominator
283  *
284  * Returns: the #GType of GstFraction (which is not explicitly typed)
285  */
286
287 #define GST_TYPE_FRACTION                (_gst_fraction_type)
288
289 GST_EXPORT GType _gst_bitmask_type;
290
291 /**
292  * GST_TYPE_BITMASK:
293  *
294  * a #GValue type that represents a 64-bit bitmask.
295  *
296  * Returns: the #GType of GstBitmask (which is not explicitly typed)
297  */
298
299 #define GST_TYPE_BITMASK                 (_gst_bitmask_type)
300
301 /**
302  * GST_TYPE_G_THREAD:
303  *
304  * a boxed #GValue type for #GThread that represents a thread.
305  *
306  * Returns: the #GType of GstGThread
307  */
308
309 #define GST_TYPE_G_THREAD                gst_g_thread_get_type ()
310
311 /**
312  * GST_VALUE_LESS_THAN:
313  *
314  * Indicates that the first value provided to a comparison function
315  * (gst_value_compare()) is lesser than the second one.
316  */
317 #define GST_VALUE_LESS_THAN              (-1)
318
319 /**
320  * GST_VALUE_EQUAL:
321  *
322  * Indicates that the first value provided to a comparison function
323  * (gst_value_compare()) is equal to the second one.
324  */
325 #define GST_VALUE_EQUAL                   0
326
327 /**
328  * GST_VALUE_GREATER_THAN:
329  *
330  * Indicates that the first value provided to a comparison function
331  * (gst_value_compare()) is greater than the second one.
332  */
333 #define GST_VALUE_GREATER_THAN            1
334
335 /**
336  * GST_VALUE_UNORDERED:
337  *
338  * Indicates that the comparison function (gst_value_compare()) can not
339  * determine a order for the two provided values.
340  */
341 #define GST_VALUE_UNORDERED               2
342
343 /**
344  * GstValueCompareFunc:
345  * @value1: first value for comparison
346  * @value2: second value for comparison
347  *
348  * Used together with gst_value_compare() to compare #GValue items.
349  *
350  * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
351  * or GST_VALUE_UNORDERED
352  */
353 typedef gint     (* GstValueCompareFunc)     (const GValue *value1,
354                                               const GValue *value2);
355
356 /**
357  * GstValueSerializeFunc:
358  * @value1: a #GValue
359  *
360  * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
361  *
362  * Free-function: g_free
363  *
364  * Returns: (transfer full): the string representation of the value
365  */
366 typedef gchar *  (* GstValueSerializeFunc)   (const GValue *value1);
367
368 /**
369  * GstValueDeserializeFunc:
370  * @dest: a #GValue
371  * @s: a string
372  *
373  * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
374  *
375  * Returns: %TRUE for success
376  */
377 typedef gboolean (* GstValueDeserializeFunc) (GValue       *dest,
378                                               const gchar  *s);
379
380 typedef struct _GstValueTable GstValueTable;
381 /**
382  * GstValueTable:
383  * @type: a #GType
384  * @compare: a #GstValueCompareFunc
385  * @serialize: a #GstValueSerializeFunc
386  * @deserialize: a #GstValueDeserializeFunc
387  *
388  * VTable for the #GValue @type.
389  */
390 struct _GstValueTable {
391   GType type;
392   GstValueCompareFunc compare;
393   GstValueSerializeFunc serialize;
394   GstValueDeserializeFunc deserialize;
395
396   /*< private >*/
397   gpointer _gst_reserved [GST_PADDING];
398 };
399
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);
408
409 /* Hide this compatibility type from introspection */
410 #ifndef __GI_SCANNER__
411 GType gst_g_thread_get_type (void);
412 #endif
413
414 void            gst_value_register              (const GstValueTable   *table);
415 void            gst_value_init_and_copy         (GValue                *dest,
416                                                  const GValue          *src);
417
418 gchar *         gst_value_serialize             (const GValue          *value) G_GNUC_MALLOC;
419 gboolean        gst_value_deserialize           (GValue                *dest,
420                                                  const gchar           *src);
421
422 /* list */
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,
437                                                  guint          index);
438
439 /* array */
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,
448                                                  guint          index);
449
450 /* int range */
451 void            gst_value_set_int_range         (GValue         *value,
452                                                  gint           start,
453                                                  gint           end);
454 void            gst_value_set_int_range_step    (GValue         *value,
455                                                  gint           start,
456                                                  gint           end,
457                                                  gint           step);
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);
461
462 /* int64 range */
463 void            gst_value_set_int64_range       (GValue         *value,
464                                                  gint64         start,
465                                                  gint64         end);
466 void            gst_value_set_int64_range_step  (GValue         *value,
467                                                  gint64         start,
468                                                  gint64         end,
469                                                  gint64         step);
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);
473
474 /* double range */
475 void            gst_value_set_double_range      (GValue         *value,
476                                                  gdouble        start,
477                                                  gdouble        end);
478 gdouble         gst_value_get_double_range_min  (const GValue   *value);
479 gdouble         gst_value_get_double_range_max  (const GValue   *value);
480
481 /* caps */
482 const GstCaps * gst_value_get_caps              (const GValue   *value);
483 void            gst_value_set_caps              (GValue         *value,
484                                                  const GstCaps  *caps);
485
486 /* structure */
487 const GstStructure *
488                 gst_value_get_structure         (const GValue   *value);
489 void            gst_value_set_structure         (GValue         *value,
490                                                  const GstStructure  *structure);
491
492 /* caps features */
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);
497
498 /* fraction */
499 void            gst_value_set_fraction          (GValue         *value,
500                                                  gint           numerator,
501                                                  gint           denominator);
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);
510
511 /* fraction range */
512 void            gst_value_set_fraction_range    (GValue         *value,
513                                                  const GValue   *start,
514                                                  const GValue   *end);
515 void            gst_value_set_fraction_range_full (GValue       *value,
516                                                  gint numerator_start,
517                                                  gint denominator_start,
518                                                  gint numerator_end,
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);
522
523 /* bitmask */
524 guint64         gst_value_get_bitmask           (const GValue   *value);
525 void            gst_value_set_bitmask           (GValue         *value,
526                                                  guint64         bitmask);
527
528 /* compare */
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);
535
536 /* union */
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);
542
543 /* intersection */
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);
549
550 /* subtraction */
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);
556
557 /* fixation */
558 gboolean        gst_value_is_fixed              (const GValue   *value);
559 gboolean        gst_value_fixate                (GValue         *dest,
560                                                  const GValue   *src);
561
562 G_END_DECLS
563
564 #endif
565
566