Remove 0.10-related documentation and "Since" markers
[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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, 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
27 G_BEGIN_DECLS
28
29 /**
30  * GST_MAKE_FOURCC:
31  * @a: the first character
32  * @b: the second character
33  * @c: the third character
34  * @d: the fourth character
35  *
36  * Transform four characters into a #guint32 fourcc value with host
37  * endianness.
38  * <informalexample>
39  * <programlisting>
40  * guint32 fourcc = GST_MAKE_FOURCC ('M', 'J', 'P', 'G');
41  * </programlisting>
42  * </informalexample>
43  */
44 #define GST_MAKE_FOURCC(a,b,c,d)        ((guint32)((a)|(b)<<8|(c)<<16|(d)<<24))
45
46 /**
47  * GST_STR_FOURCC:
48  * @f: a string with at least four characters
49  *
50  * Transform an input string into a #guint32 fourcc value with host
51  * endianness.
52  * Caller is responsible for ensuring the input string consists of at least
53  * four characters.
54  * <informalexample>
55  * <programlisting>
56  * guint32 fourcc = GST_STR_FOURCC ("MJPG");
57  * </programlisting>
58  * </informalexample>
59  */
60 #define GST_STR_FOURCC(f)               ((guint32)(((f)[0])|((f)[1]<<8)|((f)[2]<<16)|((f)[3]<<24)))
61
62 /**
63  * GST_FOURCC_FORMAT:
64  *
65  * Can be used together with #GST_FOURCC_ARGS to properly output a
66  * #guint32 fourcc value in a printf()-style text message.
67  * <informalexample>
68  * <programlisting>
69  * printf ("fourcc: %" GST_FOURCC_FORMAT "\n", GST_FOURCC_ARGS (fcc));
70  * </programlisting>
71  * </informalexample>
72  */
73 #define GST_FOURCC_FORMAT "c%c%c%c"
74
75 /**
76  * GST_FOURCC_ARGS:
77  * @fourcc: a #guint32 fourcc value to output
78  *
79  * Can be used together with #GST_FOURCC_FORMAT to properly output a
80  * #guint32 fourcc value in a printf()-style text message.
81  */
82 #define GST_FOURCC_ARGS(fourcc) \
83         ((gchar) ((fourcc)     &0xff)), \
84         ((gchar) (((fourcc)>>8 )&0xff)), \
85         ((gchar) (((fourcc)>>16)&0xff)), \
86         ((gchar) (((fourcc)>>24)&0xff))
87
88 /**
89  * GST_VALUE_HOLDS_INT_RANGE:
90  * @x: the #GValue to check
91  *
92  * Checks if the given #GValue contains a #GST_TYPE_INT_RANGE value.
93  */
94 #define GST_VALUE_HOLDS_INT_RANGE(x)    (G_VALUE_HOLDS((x), gst_int_range_get_type ()))
95
96 /**
97  * GST_VALUE_HOLDS_INT64_RANGE:
98  * @x: the #GValue to check
99  *
100  * Checks if the given #GValue contains a #GST_TYPE_INT64_RANGE value.
101  */
102 #define GST_VALUE_HOLDS_INT64_RANGE(x)    (G_VALUE_HOLDS((x), gst_int64_range_get_type ()))
103
104 /**
105  * GST_VALUE_HOLDS_DOUBLE_RANGE:
106  * @x: the #GValue to check
107  *
108  * Checks if the given #GValue contains a #GST_TYPE_DOUBLE_RANGE value.
109  */
110 #define GST_VALUE_HOLDS_DOUBLE_RANGE(x) (G_VALUE_HOLDS((x), gst_double_range_get_type ()))
111
112 /**
113  * GST_VALUE_HOLDS_FRACTION_RANGE:
114  * @x: the #GValue to check
115  *
116  * Checks if the given #GValue contains a #GST_TYPE_FRACTION_RANGE value.
117  */
118 #define GST_VALUE_HOLDS_FRACTION_RANGE(x)    (G_VALUE_HOLDS((x), gst_fraction_range_get_type ()))
119
120 /**
121  * GST_VALUE_HOLDS_LIST:
122  * @x: the #GValue to check
123  *
124  * Checks if the given #GValue contains a #GST_TYPE_LIST value.
125  */
126 #define GST_VALUE_HOLDS_LIST(x)         (G_VALUE_HOLDS((x), gst_value_list_get_type ()))
127
128 /**
129  * GST_VALUE_HOLDS_ARRAY:
130  * @x: the #GValue to check
131  *
132  * Checks if the given #GValue contains a #GST_TYPE_ARRAY value.
133  */
134 #define GST_VALUE_HOLDS_ARRAY(x)        (G_VALUE_HOLDS((x), gst_value_array_get_type ()))
135
136 /**
137  * GST_VALUE_HOLDS_CAPS:
138  * @x: the #GValue to check
139  *
140  * Checks if the given #GValue contains a #GST_TYPE_CAPS value.
141  */
142 #define GST_VALUE_HOLDS_CAPS(x)         (G_VALUE_HOLDS((x), GST_TYPE_CAPS))
143
144 /**
145  * GST_VALUE_HOLDS_STRUCTURE:
146  * @x: the #GValue to check
147  *
148  * Checks if the given #GValue contains a #GST_TYPE_STRUCTURE value.
149  */
150 #define GST_VALUE_HOLDS_STRUCTURE(x)            (G_VALUE_HOLDS((x), GST_TYPE_STRUCTURE))
151
152 /**
153  * GST_VALUE_HOLDS_BUFFER:
154  * @x: the #GValue to check
155  *
156  * Checks if the given #GValue contains a #GST_TYPE_BUFFER value.
157  */
158 #define GST_VALUE_HOLDS_BUFFER(x)       (G_VALUE_HOLDS((x), GST_TYPE_BUFFER))
159
160 /**
161  * GST_VALUE_HOLDS_SAMPLE:
162  * @x: the #GValue to check
163  *
164  * Checks if the given #GValue contains a #GST_TYPE_SAMPLE value.
165  */
166 #define GST_VALUE_HOLDS_SAMPLE(x)       (G_VALUE_HOLDS((x), GST_TYPE_SAMPLE))
167
168 /**
169  * GST_VALUE_HOLDS_FRACTION:
170  * @x: the #GValue to check
171  *
172  * Checks if the given #GValue contains a #GST_TYPE_FRACTION value.
173  */
174 #define GST_VALUE_HOLDS_FRACTION(x)     (G_VALUE_HOLDS((x), gst_fraction_get_type ()))
175
176 /**
177  * GST_VALUE_HOLDS_DATE_TIME:
178  * @x: the #GValue to check
179  *
180  * Checks if the given #GValue contains a #GST_TYPE_DATE_TIME value.
181  */
182 #define GST_VALUE_HOLDS_DATE_TIME(x)    (G_VALUE_HOLDS((x), gst_date_time_get_type ()))
183
184 /**
185  * GST_VALUE_HOLDS_BITMASK:
186  * @x: the #GValue to check
187  *
188  * Checks if the given #GValue contains a #GST_TYPE_BITMASK value.
189  */
190 #define GST_VALUE_HOLDS_BITMASK(x)      (G_VALUE_HOLDS((x), gst_bitmask_get_type ()))
191
192 /**
193  * GST_TYPE_INT_RANGE:
194  *
195  * a #GValue type that represents an integer range
196  *
197  * Returns: the #GType of GstIntRange
198  */
199 #define GST_TYPE_INT_RANGE               gst_int_range_get_type ()
200
201 /**
202  * GST_TYPE_INT64_RANGE:
203  *
204  * a #GValue type that represents an #gint64 range
205  *
206  * Returns: the #GType of GstInt64Range
207  */
208 #define GST_TYPE_INT64_RANGE             gst_int64_range_get_type ()
209
210 /**
211  * GST_TYPE_DOUBLE_RANGE:
212  *
213  * a #GValue type that represents a floating point range with double precission
214  *
215  * Returns: the #GType of GstIntRange
216  */
217 #define GST_TYPE_DOUBLE_RANGE            gst_double_range_get_type ()
218
219 /**
220  * GST_TYPE_FRACTION_RANGE:
221  *
222  * a #GValue type that represents a GstFraction range
223  *
224  * Returns: the #GType of GstFractionRange
225  */
226 #define GST_TYPE_FRACTION_RANGE            gst_fraction_range_get_type ()
227
228 /**
229  * GST_TYPE_LIST:
230  *
231  * a #GValue type that represents an unordered list of #GValue values. This
232  * is used for example to express a list of possible values for a field in
233  * a caps structure, like a list of possible sample rates, of which only one
234  * will be chosen in the end. This means that all values in the list are
235  * meaningful on their own.
236  *
237  * Returns: the #GType of GstValueList (which is not explicitly typed)
238  */
239 #define GST_TYPE_LIST                    gst_value_list_get_type ()
240
241 /**
242  * GST_TYPE_ARRAY:
243  *
244  * a #GValue type that represents an ordered list of #GValue values. This is
245  * used to express a set of values that is meaningful only in their specific
246  * combination and order of values. Each value on its own is not particularly
247  * meaningful, only the ordered array in its entirety is meaningful. This is
248  * used for example to express channel layouts for multichannel audio where
249  * each channel needs to be mapped to a position in the room.
250  *
251  * Returns: the #GType of GstArrayList (which is not explicitly typed)
252  */
253 #define GST_TYPE_ARRAY                   gst_value_array_get_type ()
254
255 /**
256  * GST_TYPE_FRACTION:
257  *
258  * a #GValue type that represents a fraction of an integer numerator over
259  * an integer denominator
260  *
261  * Returns: the #GType of GstFraction (which is not explicitly typed)
262  */
263
264 #define GST_TYPE_FRACTION                gst_fraction_get_type ()
265
266 /**
267  * GST_TYPE_DATE_TIME:
268  *
269  * a boxed #GValue type for #GstDateTime that represents a date and time.
270  *
271  * Returns: the #GType of GstDateTime
272  */
273
274 #define GST_TYPE_DATE_TIME               gst_date_time_get_type ()
275
276 /**
277  * GST_TYPE_BITMASK:
278  *
279  * a #GValue type that represents a 64-bit bitmask.
280  *
281  * Returns: the #GType of GstBitmask (which is not explicitly typed)
282  */
283
284 #define GST_TYPE_BITMASK                 gst_bitmask_get_type ()
285
286 /**
287  * GST_VALUE_LESS_THAN:
288  *
289  * Indicates that the first value provided to a comparison function
290  * (gst_value_compare()) is lesser than the second one.
291  */
292 #define GST_VALUE_LESS_THAN              (-1)
293
294 /**
295  * GST_VALUE_EQUAL:
296  *
297  * Indicates that the first value provided to a comparison function
298  * (gst_value_compare()) is equal to the second one.
299  */
300 #define GST_VALUE_EQUAL                   0
301
302 /**
303  * GST_VALUE_GREATER_THAN:
304  *
305  * Indicates that the first value provided to a comparison function
306  * (gst_value_compare()) is greater than the second one.
307  */
308 #define GST_VALUE_GREATER_THAN            1
309
310 /**
311  * GST_VALUE_UNORDERED:
312  *
313  * Indicates that the comparison function (gst_value_compare()) can not
314  * determine a order for the two provided values.
315  */
316 #define GST_VALUE_UNORDERED               2
317
318 /**
319  * GstValueCompareFunc:
320  * @value1: first value for comparison
321  * @value2: second value for comparison
322  *
323  * Used together with gst_value_compare() to compare #GValue items.
324  *
325  * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
326  * or GST_VALUE_UNORDERED
327  */
328 typedef gint     (* GstValueCompareFunc)     (const GValue *value1,
329                                               const GValue *value2);
330
331 /**
332  * GstValueSerializeFunc:
333  * @value1: a #GValue
334  *
335  * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
336  *
337  * Free-function: g_free
338  *
339  * Returns: (transfer full): the string representation of the value
340  */
341 typedef gchar *  (* GstValueSerializeFunc)   (const GValue *value1);
342
343 /**
344  * GstValueDeserializeFunc:
345  * @dest: a #GValue
346  * @s: a string
347  *
348  * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
349  *
350  * Returns: %TRUE for success
351  */
352 typedef gboolean (* GstValueDeserializeFunc) (GValue       *dest,
353                                               const gchar  *s);
354
355 typedef struct _GstValueTable GstValueTable;
356 /**
357  * GstValueTable:
358  * @type: a #GType
359  * @compare: a #GstValueCompareFunc
360  * @serialize: a #GstValueSerializeFunc
361  * @deserialize: a #GstValueDeserializeFunc
362  *
363  * VTable for the #GValue @type.
364  */
365 struct _GstValueTable {
366   GType type;
367   GstValueCompareFunc compare;
368   GstValueSerializeFunc serialize;
369   GstValueDeserializeFunc deserialize;
370
371   /*< private >*/
372   gpointer _gst_reserved [GST_PADDING];
373 };
374
375 GType gst_int_range_get_type (void);
376 GType gst_int64_range_get_type (void);
377 GType gst_double_range_get_type (void);
378 GType gst_fraction_range_get_type (void);
379 GType gst_fraction_get_type (void);
380 GType gst_value_list_get_type (void);
381 GType gst_value_array_get_type (void);
382 GType gst_bitmask_get_type (void);
383
384 GType gst_date_time_get_type (void);
385
386 void            gst_value_register              (const GstValueTable   *table);
387 void            gst_value_init_and_copy         (GValue                *dest,
388                                                  const GValue          *src);
389
390 gchar *         gst_value_serialize             (const GValue          *value) G_GNUC_MALLOC;
391 gboolean        gst_value_deserialize           (GValue                *dest,
392                                                  const gchar           *src);
393
394 /* list */
395 void            gst_value_list_append_value     (GValue         *value,
396                                                  const GValue   *append_value);
397 void            gst_value_list_prepend_value    (GValue         *value,
398                                                  const GValue   *prepend_value);
399 void            gst_value_list_concat           (GValue         *dest,
400                                                  const GValue   *value1,
401                                                  const GValue   *value2);
402 void            gst_value_list_merge            (GValue         *dest,
403                                                  const GValue   *value1,
404                                                  const GValue   *value2);
405 guint           gst_value_list_get_size         (const GValue   *value);
406 const GValue *  gst_value_list_get_value        (const GValue   *value,
407                                                  guint          index);
408
409 /* array */
410 void            gst_value_array_append_value    (GValue         *value,
411                                                  const GValue   *append_value);
412 void            gst_value_array_prepend_value   (GValue         *value,
413                                                  const GValue   *prepend_value);
414 guint           gst_value_array_get_size        (const GValue   *value);
415 const GValue *  gst_value_array_get_value       (const GValue   *value,
416                                                  guint          index);
417
418 /* int range */
419 void            gst_value_set_int_range         (GValue         *value,
420                                                  gint           start,
421                                                  gint           end);
422 void            gst_value_set_int_range_step    (GValue         *value,
423                                                  gint           start,
424                                                  gint           end,
425                                                  gint           step);
426 gint            gst_value_get_int_range_min     (const GValue   *value);
427 gint            gst_value_get_int_range_max     (const GValue   *value);
428 gint            gst_value_get_int_range_step    (const GValue   *value);
429
430 /* int64 range */
431 void            gst_value_set_int64_range       (GValue         *value,
432                                                  gint64         start,
433                                                  gint64         end);
434 void            gst_value_set_int64_range_step  (GValue         *value,
435                                                  gint64         start,
436                                                  gint64         end,
437                                                  gint64         step);
438 gint64          gst_value_get_int64_range_min   (const GValue   *value);
439 gint64          gst_value_get_int64_range_max   (const GValue   *value);
440 gint64          gst_value_get_int64_range_step  (const GValue   *value);
441
442 /* double range */
443 void            gst_value_set_double_range      (GValue         *value,
444                                                  gdouble        start,
445                                                  gdouble        end);
446 gdouble         gst_value_get_double_range_min  (const GValue   *value);
447 gdouble         gst_value_get_double_range_max  (const GValue   *value);
448
449 /* caps */
450 const GstCaps * gst_value_get_caps              (const GValue   *value);
451 void            gst_value_set_caps              (GValue         *value,
452                                                  const GstCaps  *caps);
453
454 /* structure */
455 const GstStructure *
456                 gst_value_get_structure         (const GValue   *value);
457 void            gst_value_set_structure         (GValue         *value,
458                                                  const GstStructure  *structure);
459
460 /* fraction */
461 void            gst_value_set_fraction          (GValue         *value,
462                                                  gint           numerator,
463                                                  gint           denominator);
464 gint            gst_value_get_fraction_numerator   (const GValue  *value);
465 gint            gst_value_get_fraction_denominator (const GValue *value);
466 gboolean        gst_value_fraction_multiply        (GValue         *product,
467                                                     const GValue   *factor1,
468                                                     const GValue   *factor2);
469 gboolean        gst_value_fraction_subtract     (GValue * dest,
470                                                  const GValue * minuend,
471                                                  const GValue * subtrahend);
472
473 /* fraction range */
474 void            gst_value_set_fraction_range    (GValue         *value,
475                                                  const GValue   *start,
476                                                  const GValue   *end);
477 void            gst_value_set_fraction_range_full (GValue       *value,
478                                                  gint numerator_start,
479                                                  gint denominator_start,
480                                                  gint numerator_end,
481                                                  gint denominator_end);
482 const GValue    *gst_value_get_fraction_range_min (const GValue *value);
483 const GValue    *gst_value_get_fraction_range_max (const GValue *value);
484
485 /* bitmask */
486 guint64         gst_value_get_bitmask           (const GValue   *value);
487 void            gst_value_set_bitmask           (GValue         *value,
488                                                  guint64         bitmask);
489
490 /* compare */
491 gint            gst_value_compare               (const GValue   *value1,
492                                                  const GValue   *value2);
493 gboolean        gst_value_can_compare           (const GValue   *value1,
494                                                  const GValue   *value2);
495 gboolean        gst_value_is_subset             (const GValue   *value1,
496                                                  const GValue   *value2);
497
498 /* union */
499 gboolean        gst_value_union                 (GValue         *dest,
500                                                  const GValue   *value1,
501                                                  const GValue   *value2);
502 gboolean        gst_value_can_union             (const GValue   *value1,
503                                                  const GValue   *value2);
504
505 /* intersection */
506 gboolean        gst_value_intersect             (GValue         *dest,
507                                                  const GValue   *value1,
508                                                  const GValue   *value2);
509 gboolean        gst_value_can_intersect         (const GValue   *value1,
510                                                  const GValue   *value2);
511
512 /* subtraction */
513 gboolean        gst_value_subtract              (GValue         *dest,
514                                                  const GValue   *minuend,
515                                                  const GValue   *subtrahend);
516 gboolean        gst_value_can_subtract          (const GValue   *minuend,
517                                                  const GValue   *subtrahend);
518
519 /* fixation */
520 gboolean        gst_value_is_fixed              (const GValue   *value);
521 gboolean        gst_value_fixate                (GValue         *dest,
522                                                  const GValue   *src);
523
524 G_END_DECLS
525
526 #endif
527
528