bin: Use the new group-id field of the stream-start message for stream-start message...
[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)    (G_VALUE_HOLDS((x), gst_int_range_get_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)    (G_VALUE_HOLDS((x), gst_int64_range_get_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) (G_VALUE_HOLDS((x), gst_double_range_get_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)    (G_VALUE_HOLDS((x), gst_fraction_range_get_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)         (G_VALUE_HOLDS((x), gst_value_list_get_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)        (G_VALUE_HOLDS((x), gst_value_array_get_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)         (G_VALUE_HOLDS((x), GST_TYPE_CAPS))
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_TYPE_STRUCTURE))
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_TYPE_CAPS_FEATURES))
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)       (G_VALUE_HOLDS((x), GST_TYPE_BUFFER))
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)       (G_VALUE_HOLDS((x), GST_TYPE_SAMPLE))
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)     (G_VALUE_HOLDS((x), gst_fraction_get_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)    (G_VALUE_HOLDS((x), gst_date_time_get_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)      (G_VALUE_HOLDS((x), gst_bitmask_get_type ()))
200
201 /**
202  * GST_TYPE_INT_RANGE:
203  *
204  * a #GValue type that represents an integer range
205  *
206  * Returns: the #GType of GstIntRange
207  */
208 #define GST_TYPE_INT_RANGE               gst_int_range_get_type ()
209
210 /**
211  * GST_TYPE_INT64_RANGE:
212  *
213  * a #GValue type that represents an #gint64 range
214  *
215  * Returns: the #GType of GstInt64Range
216  */
217 #define GST_TYPE_INT64_RANGE             gst_int64_range_get_type ()
218
219 /**
220  * GST_TYPE_DOUBLE_RANGE:
221  *
222  * a #GValue type that represents a floating point range with double precission
223  *
224  * Returns: the #GType of GstIntRange
225  */
226 #define GST_TYPE_DOUBLE_RANGE            gst_double_range_get_type ()
227
228 /**
229  * GST_TYPE_FRACTION_RANGE:
230  *
231  * a #GValue type that represents a GstFraction range
232  *
233  * Returns: the #GType of GstFractionRange
234  */
235 #define GST_TYPE_FRACTION_RANGE            gst_fraction_range_get_type ()
236
237 /**
238  * GST_TYPE_LIST:
239  *
240  * a #GValue type that represents an unordered list of #GValue values. This
241  * is used for example to express a list of possible values for a field in
242  * a caps structure, like a list of possible sample rates, of which only one
243  * will be chosen in the end. This means that all values in the list are
244  * meaningful on their own.
245  *
246  * Returns: the #GType of GstValueList (which is not explicitly typed)
247  */
248 #define GST_TYPE_LIST                    gst_value_list_get_type ()
249
250 /**
251  * GST_TYPE_ARRAY:
252  *
253  * a #GValue type that represents an ordered list of #GValue values. This is
254  * used to express a set of values that is meaningful only in their specific
255  * combination and order of values. Each value on its own is not particularly
256  * meaningful, only the ordered array in its entirety is meaningful. This is
257  * used for example to express channel layouts for multichannel audio where
258  * each channel needs to be mapped to a position in the room.
259  *
260  * Returns: the #GType of GstArrayList (which is not explicitly typed)
261  */
262 #define GST_TYPE_ARRAY                   gst_value_array_get_type ()
263
264 /**
265  * GST_TYPE_FRACTION:
266  *
267  * a #GValue type that represents a fraction of an integer numerator over
268  * an integer denominator
269  *
270  * Returns: the #GType of GstFraction (which is not explicitly typed)
271  */
272
273 #define GST_TYPE_FRACTION                gst_fraction_get_type ()
274
275 /**
276  * GST_TYPE_DATE_TIME:
277  *
278  * a boxed #GValue type for #GstDateTime that represents a date and time.
279  *
280  * Returns: the #GType of GstDateTime
281  */
282
283 #define GST_TYPE_DATE_TIME               gst_date_time_get_type ()
284
285 /**
286  * GST_TYPE_BITMASK:
287  *
288  * a #GValue type that represents a 64-bit bitmask.
289  *
290  * Returns: the #GType of GstBitmask (which is not explicitly typed)
291  */
292
293 #define GST_TYPE_BITMASK                 gst_bitmask_get_type ()
294
295 /**
296  * GST_TYPE_G_THREAD:
297  *
298  * a boxed #GValue type for #GThread that represents a thread.
299  *
300  * Returns: the #GType of GstGThread
301  */
302
303 #define GST_TYPE_G_THREAD                gst_g_thread_get_type ()
304
305 /**
306  * GST_VALUE_LESS_THAN:
307  *
308  * Indicates that the first value provided to a comparison function
309  * (gst_value_compare()) is lesser than the second one.
310  */
311 #define GST_VALUE_LESS_THAN              (-1)
312
313 /**
314  * GST_VALUE_EQUAL:
315  *
316  * Indicates that the first value provided to a comparison function
317  * (gst_value_compare()) is equal to the second one.
318  */
319 #define GST_VALUE_EQUAL                   0
320
321 /**
322  * GST_VALUE_GREATER_THAN:
323  *
324  * Indicates that the first value provided to a comparison function
325  * (gst_value_compare()) is greater than the second one.
326  */
327 #define GST_VALUE_GREATER_THAN            1
328
329 /**
330  * GST_VALUE_UNORDERED:
331  *
332  * Indicates that the comparison function (gst_value_compare()) can not
333  * determine a order for the two provided values.
334  */
335 #define GST_VALUE_UNORDERED               2
336
337 /**
338  * GstValueCompareFunc:
339  * @value1: first value for comparison
340  * @value2: second value for comparison
341  *
342  * Used together with gst_value_compare() to compare #GValue items.
343  *
344  * Returns: one of GST_VALUE_LESS_THAN, GST_VALUE_EQUAL, GST_VALUE_GREATER_THAN
345  * or GST_VALUE_UNORDERED
346  */
347 typedef gint     (* GstValueCompareFunc)     (const GValue *value1,
348                                               const GValue *value2);
349
350 /**
351  * GstValueSerializeFunc:
352  * @value1: a #GValue
353  *
354  * Used by gst_value_serialize() to obtain a non-binary form of the #GValue.
355  *
356  * Free-function: g_free
357  *
358  * Returns: (transfer full): the string representation of the value
359  */
360 typedef gchar *  (* GstValueSerializeFunc)   (const GValue *value1);
361
362 /**
363  * GstValueDeserializeFunc:
364  * @dest: a #GValue
365  * @s: a string
366  *
367  * Used by gst_value_deserialize() to parse a non-binary form into the #GValue.
368  *
369  * Returns: %TRUE for success
370  */
371 typedef gboolean (* GstValueDeserializeFunc) (GValue       *dest,
372                                               const gchar  *s);
373
374 typedef struct _GstValueTable GstValueTable;
375 /**
376  * GstValueTable:
377  * @type: a #GType
378  * @compare: a #GstValueCompareFunc
379  * @serialize: a #GstValueSerializeFunc
380  * @deserialize: a #GstValueDeserializeFunc
381  *
382  * VTable for the #GValue @type.
383  */
384 struct _GstValueTable {
385   GType type;
386   GstValueCompareFunc compare;
387   GstValueSerializeFunc serialize;
388   GstValueDeserializeFunc deserialize;
389
390   /*< private >*/
391   gpointer _gst_reserved [GST_PADDING];
392 };
393
394 GType gst_int_range_get_type (void);
395 GType gst_int64_range_get_type (void);
396 GType gst_double_range_get_type (void);
397 GType gst_fraction_range_get_type (void);
398 GType gst_fraction_get_type (void);
399 GType gst_value_list_get_type (void);
400 GType gst_value_array_get_type (void);
401 GType gst_bitmask_get_type (void);
402
403 /* Hide this compatibility type from introspection */
404 #ifndef __GI_SCANNER__
405 GType gst_g_thread_get_type (void);
406 #endif
407
408 GType gst_date_time_get_type (void);
409
410 void            gst_value_register              (const GstValueTable   *table);
411 void            gst_value_init_and_copy         (GValue                *dest,
412                                                  const GValue          *src);
413
414 gchar *         gst_value_serialize             (const GValue          *value) G_GNUC_MALLOC;
415 gboolean        gst_value_deserialize           (GValue                *dest,
416                                                  const gchar           *src);
417
418 /* list */
419 void            gst_value_list_append_value     (GValue         *value,
420                                                  const GValue   *append_value);
421 void            gst_value_list_append_and_take_value (GValue         *value,
422                                                  GValue   *append_value);
423 void            gst_value_list_prepend_value    (GValue         *value,
424                                                  const GValue   *prepend_value);
425 void            gst_value_list_concat           (GValue         *dest,
426                                                  const GValue   *value1,
427                                                  const GValue   *value2);
428 void            gst_value_list_merge            (GValue         *dest,
429                                                  const GValue   *value1,
430                                                  const GValue   *value2);
431 guint           gst_value_list_get_size         (const GValue   *value);
432 const GValue *  gst_value_list_get_value        (const GValue   *value,
433                                                  guint          index);
434
435 /* array */
436 void            gst_value_array_append_value    (GValue         *value,
437                                                  const GValue   *append_value);
438 void            gst_value_array_append_and_take_value    (GValue         *value,
439                                                  GValue   *append_value);
440 void            gst_value_array_prepend_value   (GValue         *value,
441                                                  const GValue   *prepend_value);
442 guint           gst_value_array_get_size        (const GValue   *value);
443 const GValue *  gst_value_array_get_value       (const GValue   *value,
444                                                  guint          index);
445
446 /* int range */
447 void            gst_value_set_int_range         (GValue         *value,
448                                                  gint           start,
449                                                  gint           end);
450 void            gst_value_set_int_range_step    (GValue         *value,
451                                                  gint           start,
452                                                  gint           end,
453                                                  gint           step);
454 gint            gst_value_get_int_range_min     (const GValue   *value);
455 gint            gst_value_get_int_range_max     (const GValue   *value);
456 gint            gst_value_get_int_range_step    (const GValue   *value);
457
458 /* int64 range */
459 void            gst_value_set_int64_range       (GValue         *value,
460                                                  gint64         start,
461                                                  gint64         end);
462 void            gst_value_set_int64_range_step  (GValue         *value,
463                                                  gint64         start,
464                                                  gint64         end,
465                                                  gint64         step);
466 gint64          gst_value_get_int64_range_min   (const GValue   *value);
467 gint64          gst_value_get_int64_range_max   (const GValue   *value);
468 gint64          gst_value_get_int64_range_step  (const GValue   *value);
469
470 /* double range */
471 void            gst_value_set_double_range      (GValue         *value,
472                                                  gdouble        start,
473                                                  gdouble        end);
474 gdouble         gst_value_get_double_range_min  (const GValue   *value);
475 gdouble         gst_value_get_double_range_max  (const GValue   *value);
476
477 /* caps */
478 const GstCaps * gst_value_get_caps              (const GValue   *value);
479 void            gst_value_set_caps              (GValue         *value,
480                                                  const GstCaps  *caps);
481
482 /* structure */
483 const GstStructure *
484                 gst_value_get_structure         (const GValue   *value);
485 void            gst_value_set_structure         (GValue         *value,
486                                                  const GstStructure  *structure);
487
488 /* caps features */
489 const GstCapsFeatures *
490                 gst_value_get_caps_features     (const GValue   *value);
491 void            gst_value_set_caps_features     (GValue         *value,
492                                                  const GstCapsFeatures  *features);
493
494 /* fraction */
495 void            gst_value_set_fraction          (GValue         *value,
496                                                  gint           numerator,
497                                                  gint           denominator);
498 gint            gst_value_get_fraction_numerator   (const GValue  *value);
499 gint            gst_value_get_fraction_denominator (const GValue *value);
500 gboolean        gst_value_fraction_multiply        (GValue         *product,
501                                                     const GValue   *factor1,
502                                                     const GValue   *factor2);
503 gboolean        gst_value_fraction_subtract     (GValue * dest,
504                                                  const GValue * minuend,
505                                                  const GValue * subtrahend);
506
507 /* fraction range */
508 void            gst_value_set_fraction_range    (GValue         *value,
509                                                  const GValue   *start,
510                                                  const GValue   *end);
511 void            gst_value_set_fraction_range_full (GValue       *value,
512                                                  gint numerator_start,
513                                                  gint denominator_start,
514                                                  gint numerator_end,
515                                                  gint denominator_end);
516 const GValue    *gst_value_get_fraction_range_min (const GValue *value);
517 const GValue    *gst_value_get_fraction_range_max (const GValue *value);
518
519 /* bitmask */
520 guint64         gst_value_get_bitmask           (const GValue   *value);
521 void            gst_value_set_bitmask           (GValue         *value,
522                                                  guint64         bitmask);
523
524 /* compare */
525 gint            gst_value_compare               (const GValue   *value1,
526                                                  const GValue   *value2);
527 gboolean        gst_value_can_compare           (const GValue   *value1,
528                                                  const GValue   *value2);
529 gboolean        gst_value_is_subset             (const GValue   *value1,
530                                                  const GValue   *value2);
531
532 /* union */
533 gboolean        gst_value_union                 (GValue         *dest,
534                                                  const GValue   *value1,
535                                                  const GValue   *value2);
536 gboolean        gst_value_can_union             (const GValue   *value1,
537                                                  const GValue   *value2);
538
539 /* intersection */
540 gboolean        gst_value_intersect             (GValue         *dest,
541                                                  const GValue   *value1,
542                                                  const GValue   *value2);
543 gboolean        gst_value_can_intersect         (const GValue   *value1,
544                                                  const GValue   *value2);
545
546 /* subtraction */
547 gboolean        gst_value_subtract              (GValue         *dest,
548                                                  const GValue   *minuend,
549                                                  const GValue   *subtrahend);
550 gboolean        gst_value_can_subtract          (const GValue   *minuend,
551                                                  const GValue   *subtrahend);
552
553 /* fixation */
554 gboolean        gst_value_is_fixed              (const GValue   *value);
555 gboolean        gst_value_fixate                (GValue         *dest,
556                                                  const GValue   *src);
557
558 G_END_DECLS
559
560 #endif
561
562