Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / gst / gstutils.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *                    2002 Thomas Vander Stichele <thomas@apestaart.org>
5  *
6  * gstutils.h: Header for various utility functions
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24
25 #ifndef __GST_UTILS_H__
26 #define __GST_UTILS_H__
27
28 #include <glib.h>
29 #include <gst/gstbin.h>
30 #include <gst/gstparse.h>
31
32 G_BEGIN_DECLS
33
34 void            gst_util_set_value_from_string  (GValue *value, const gchar *value_str);
35 void            gst_util_set_object_arg         (GObject *object, const gchar *name, const gchar *value);
36 void            gst_util_dump_mem               (const guchar *mem, guint size);
37
38 guint64         gst_util_gdouble_to_guint64     (gdouble value)  G_GNUC_CONST;
39 gdouble         gst_util_guint64_to_gdouble     (guint64 value)  G_GNUC_CONST;
40
41 /**
42  * gst_guint64_to_gdouble:
43  * @value: the #guint64 value to convert
44  *
45  * Convert @value to a gdouble.
46  *
47  * Returns: @value converted to a #gdouble.
48  */
49
50 /**
51  * gst_gdouble_to_guint64:
52  * @value: the #gdouble value to convert
53  *
54  * Convert @value to a guint64.
55  *
56  * Returns: @value converted to a #guint64.
57  */
58 #ifdef WIN32
59 #define         gst_gdouble_to_guint64(value)   gst_util_gdouble_to_guint64(value)
60 #define         gst_guint64_to_gdouble(value)   gst_util_guint64_to_gdouble(value)
61 #else
62 #define         gst_gdouble_to_guint64(value)   ((guint64) (value))
63 #define         gst_guint64_to_gdouble(value)   ((gdouble) (value))
64 #endif
65
66 guint64         gst_util_uint64_scale           (guint64 val, guint64 num, guint64 denom);
67 guint64         gst_util_uint64_scale_round     (guint64 val, guint64 num, guint64 denom);
68 guint64         gst_util_uint64_scale_ceil      (guint64 val, guint64 num, guint64 denom);
69
70 guint64         gst_util_uint64_scale_int       (guint64 val, gint num, gint denom);
71 guint64         gst_util_uint64_scale_int_round (guint64 val, gint num, gint denom);
72 guint64         gst_util_uint64_scale_int_ceil  (guint64 val, gint num, gint denom);
73
74 guint32         gst_util_seqnum_next            (void);
75 gint32          gst_util_seqnum_compare         (guint32 s1, guint32 s2);
76
77 void            gst_print_pad_caps              (GString *buf, gint indent, GstPad *pad);
78 void            gst_print_element_args          (GString *buf, gint indent, GstElement *element);
79
80
81 GType gst_type_register_static_full (GType parent_type,
82                                            const gchar       *type_name,
83                                guint              class_size,
84                                GBaseInitFunc      base_init,
85                                GBaseFinalizeFunc  base_finalize,
86                                GClassInitFunc     class_init,
87                                GClassFinalizeFunc class_finalize,
88                                gconstpointer      class_data,
89                                guint              instance_size,
90                                guint16            n_preallocs,
91                                GInstanceInitFunc  instance_init,
92                                const GTypeValueTable *value_table,
93                                GTypeFlags        flags);
94
95 /**
96  * GST_CALL_PARENT:
97  * @parent_class_cast: the name of the class cast macro for the parent type
98  * @name: name of the function to call
99  * @args: arguments enclosed in '( )'
100  *
101  * Just call the parent handler.  This assumes that there is a variable
102  * named parent_class that points to the (duh!) parent class.  Note that
103  * this macro is not to be used with things that return something, use
104  * the _WITH_DEFAULT version for that
105  */
106 #define GST_CALL_PARENT(parent_class_cast, name, args)                  \
107         ((parent_class_cast(parent_class)->name != NULL) ?              \
108          parent_class_cast(parent_class)->name args : (void) 0)
109
110 /**
111  * GST_CALL_PARENT_WITH_DEFAULT:
112  * @parent_class_cast: the name of the class cast macro for the parent type
113  * @name: name of the function to call
114  * @args: arguments enclosed in '( )'
115  * @def_return: default result
116  *
117  * Same as GST_CALL_PARENT(), but in case there is no implementation, it
118  * evaluates to @def_return.
119  */
120 #define GST_CALL_PARENT_WITH_DEFAULT(parent_class_cast, name, args, def_return)\
121         ((parent_class_cast(parent_class)->name != NULL) ?              \
122          parent_class_cast(parent_class)->name args : def_return)
123
124 /* Define PUT and GET functions for unaligned memory */
125 #define _GST_GET(__data, __idx, __size, __shift) \
126     (((guint##__size) (((const guint8 *) (__data))[__idx])) << (__shift))
127
128 #define _GST_PUT(__data, __idx, __size, __shift, __num) \
129     (((guint8 *) (__data))[__idx] = (((guint##__size) (__num)) >> (__shift)) & 0xff)
130
131 /**
132  * GST_READ_UINT64_BE:
133  * @data: memory location
134  *
135  * Read a 64 bit unsigned integer value in big endian format from the memory buffer.
136  */
137 #define GST_READ_UINT64_BE(data)        (_GST_GET (data, 0, 64, 56) | \
138                                          _GST_GET (data, 1, 64, 48) | \
139                                          _GST_GET (data, 2, 64, 40) | \
140                                          _GST_GET (data, 3, 64, 32) | \
141                                          _GST_GET (data, 4, 64, 24) | \
142                                          _GST_GET (data, 5, 64, 16) | \
143                                          _GST_GET (data, 6, 64,  8) | \
144                                          _GST_GET (data, 7, 64,  0))
145
146 /**
147  * GST_READ_UINT64_LE:
148  * @data: memory location
149  *
150  * Read a 64 bit unsigned integer value in little endian format from the memory buffer.
151  */
152 #define GST_READ_UINT64_LE(data)        (_GST_GET (data, 7, 64, 56) | \
153                                          _GST_GET (data, 6, 64, 48) | \
154                                          _GST_GET (data, 5, 64, 40) | \
155                                          _GST_GET (data, 4, 64, 32) | \
156                                          _GST_GET (data, 3, 64, 24) | \
157                                          _GST_GET (data, 2, 64, 16) | \
158                                          _GST_GET (data, 1, 64,  8) | \
159                                          _GST_GET (data, 0, 64,  0))
160
161 /**
162  * GST_READ_UINT32_BE:
163  * @data: memory location
164  *
165  * Read a 32 bit unsigned integer value in big endian format from the memory buffer.
166  */
167 #define GST_READ_UINT32_BE(data)        (_GST_GET (data, 0, 32, 24) | \
168                                          _GST_GET (data, 1, 32, 16) | \
169                                          _GST_GET (data, 2, 32,  8) | \
170                                          _GST_GET (data, 3, 32,  0))
171
172 /**
173  * GST_READ_UINT32_LE:
174  * @data: memory location
175  *
176  * Read a 32 bit unsigned integer value in little endian format from the memory buffer.
177  */
178 #define GST_READ_UINT32_LE(data)        (_GST_GET (data, 3, 32, 24) | \
179                                          _GST_GET (data, 2, 32, 16) | \
180                                          _GST_GET (data, 1, 32,  8) | \
181                                          _GST_GET (data, 0, 32,  0))
182
183 /**
184  * GST_READ_UINT24_BE:
185  * @data: memory location
186  *
187  * Read a 24 bit unsigned integer value in big endian format from the memory buffer.
188  *
189  * Since: 0.10.22
190  */
191 #define GST_READ_UINT24_BE(data)        (_GST_GET (data, 0, 32, 16) | \
192                                          _GST_GET (data, 1, 32,  8) | \
193                                          _GST_GET (data, 2, 32,  0))
194
195 /**
196  * GST_READ_UINT24_LE:
197  * @data: memory location
198  *
199  * Read a 24 bit unsigned integer value in little endian format from the memory buffer.
200  *
201  * Since: 0.10.22
202  */
203 #define GST_READ_UINT24_LE(data)        (_GST_GET (data, 2, 32, 16) | \
204                                          _GST_GET (data, 1, 32,  8) | \
205                                          _GST_GET (data, 0, 32,  0))
206
207 /**
208  * GST_READ_UINT16_BE:
209  * @data: memory location
210  *
211  * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
212  */
213 #define GST_READ_UINT16_BE(data)        (_GST_GET (data, 0, 16,  8) | \
214                                          _GST_GET (data, 1, 16,  0))
215
216 /**
217  * GST_READ_UINT16_LE:
218  * @data: memory location
219  *
220  * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
221  */
222 #define GST_READ_UINT16_LE(data)        (_GST_GET (data, 1, 16,  8) | \
223                                          _GST_GET (data, 0, 16,  0))
224
225 /**
226  * GST_READ_UINT8:
227  * @data: memory location
228  *
229  * Read an 8 bit unsigned integer value from the memory buffer.
230  */
231 #define GST_READ_UINT8(data)            (_GST_GET (data, 0,  8,  0))
232
233 /**
234  * GST_WRITE_UINT64_BE:
235  * @data: memory location
236  * @num: value to store
237  *
238  * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
239  */
240 #define GST_WRITE_UINT64_BE(data, num)  do { \
241                                           _GST_PUT (data, 0, 64, 56, num); \
242                                           _GST_PUT (data, 1, 64, 48, num); \
243                                           _GST_PUT (data, 2, 64, 40, num); \
244                                           _GST_PUT (data, 3, 64, 32, num); \
245                                           _GST_PUT (data, 4, 64, 24, num); \
246                                           _GST_PUT (data, 5, 64, 16, num); \
247                                           _GST_PUT (data, 6, 64,  8, num); \
248                                           _GST_PUT (data, 7, 64,  0, num); \
249                                         } while (0)
250
251 /**
252  * GST_WRITE_UINT64_LE:
253  * @data: memory location
254  * @num: value to store
255  *
256  * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
257  */
258 #define GST_WRITE_UINT64_LE(data, num)  do { \
259                                           _GST_PUT (data, 0, 64,  0, num); \
260                                           _GST_PUT (data, 1, 64,  8, num); \
261                                           _GST_PUT (data, 2, 64, 16, num); \
262                                           _GST_PUT (data, 3, 64, 24, num); \
263                                           _GST_PUT (data, 4, 64, 32, num); \
264                                           _GST_PUT (data, 5, 64, 40, num); \
265                                           _GST_PUT (data, 6, 64, 48, num); \
266                                           _GST_PUT (data, 7, 64, 56, num); \
267                                         } while (0)
268
269 /**
270  * GST_WRITE_UINT32_BE:
271  * @data: memory location
272  * @num: value to store
273  *
274  * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
275  */
276 #define GST_WRITE_UINT32_BE(data, num)  do { \
277                                           _GST_PUT (data, 0, 32, 24, num); \
278                                           _GST_PUT (data, 1, 32, 16, num); \
279                                           _GST_PUT (data, 2, 32,  8, num); \
280                                           _GST_PUT (data, 3, 32,  0, num); \
281                                         } while (0)
282
283 /**
284  * GST_WRITE_UINT32_LE:
285  * @data: memory location
286  * @num: value to store
287  *
288  * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
289  */
290 #define GST_WRITE_UINT32_LE(data, num)  do { \
291                                           _GST_PUT (data, 0, 32,  0, num); \
292                                           _GST_PUT (data, 1, 32,  8, num); \
293                                           _GST_PUT (data, 2, 32, 16, num); \
294                                           _GST_PUT (data, 3, 32, 24, num); \
295                                         } while (0)
296
297 /**
298  * GST_WRITE_UINT24_BE:
299  * @data: memory location
300  * @num: value to store
301  *
302  * Store a 24 bit unsigned integer value in big endian format into the memory buffer.
303  *
304  * Since: 0.10.22
305  */
306 #define GST_WRITE_UINT24_BE(data, num)  do { \
307                                           _GST_PUT (data, 0, 32,  16, num); \
308                                           _GST_PUT (data, 1, 32,  8, num); \
309                                           _GST_PUT (data, 2, 32,  0, num); \
310                                         } while (0)
311
312 /**
313  * GST_WRITE_UINT24_LE:
314  * @data: memory location
315  * @num: value to store
316  *
317  * Store a 24 bit unsigned integer value in little endian format into the memory buffer.
318  *
319  * Since: 0.10.22
320  */
321 #define GST_WRITE_UINT24_LE(data, num)  do { \
322                                           _GST_PUT (data, 0, 32,  0, num); \
323                                           _GST_PUT (data, 1, 32,  8, num); \
324                                           _GST_PUT (data, 2, 32,  16, num); \
325                                         } while (0)
326
327 /**
328  * GST_WRITE_UINT16_BE:
329  * @data: memory location
330  * @num: value to store
331  *
332  * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
333  */
334 #define GST_WRITE_UINT16_BE(data, num)  do { \
335                                           _GST_PUT (data, 0, 16,  8, num); \
336                                           _GST_PUT (data, 1, 16,  0, num); \
337                                         } while (0)
338
339 /**
340  * GST_WRITE_UINT16_LE:
341  * @data: memory location
342  * @num: value to store
343  *
344  * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
345  */
346 #define GST_WRITE_UINT16_LE(data, num)  do { \
347                                           _GST_PUT (data, 0, 16,  0, num); \
348                                           _GST_PUT (data, 1, 16,  8, num); \
349                                         } while (0)
350
351 /**
352  * GST_WRITE_UINT8:
353  * @data: memory location
354  * @num: value to store
355  *
356  * Store an 8 bit unsigned integer value into the memory buffer.
357  */
358 #define GST_WRITE_UINT8(data, num)      do { \
359                                           _GST_PUT (data, 0,  8,  0, num); \
360                                         } while (0)
361
362 /* Float endianess conversion macros */
363
364 /* FIXME: Remove this once we depend on a GLib version with this */
365 #ifndef GFLOAT_FROM_LE
366 /**
367  * GFLOAT_SWAP_LE_BE:
368  * @in: input value
369  *
370  * Swap byte order of a 32-bit floating point value (float).
371  *
372  * Returns: @in byte-swapped.
373  *
374  * Since: 0.10.22
375  *
376  */
377 #ifdef _FOOL_GTK_DOC_
378 G_INLINE_FUNC gfloat GFLOAT_SWAP_LE_BE (gfloat in);
379 #endif
380
381 inline static gfloat
382 GFLOAT_SWAP_LE_BE(gfloat in)
383 {
384   union
385   {
386     guint32 i;
387     gfloat f;
388   } u;
389
390   u.f = in;
391   u.i = GUINT32_SWAP_LE_BE (u.i);
392   return u.f;
393 }
394
395 /**
396  * GDOUBLE_SWAP_LE_BE:
397  * @in: input value
398  *
399  * Swap byte order of a 64-bit floating point value (double).
400  *
401  * Returns: @in byte-swapped.
402  *
403  * Since: 0.10.22
404  *
405  */
406 #ifdef _FOOL_GTK_DOC_
407 G_INLINE_FUNC gdouble GDOUBLE_SWAP_LE_BE (gdouble in);
408 #endif
409
410 inline static gdouble
411 GDOUBLE_SWAP_LE_BE(gdouble in)
412 {
413   union
414   {
415     guint64 i;
416     gdouble d;
417   } u;
418
419   u.d = in;
420   u.i = GUINT64_SWAP_LE_BE (u.i);
421   return u.d;
422 }
423
424 /**
425  * GDOUBLE_TO_LE:
426  * @val: value
427  *
428  * Convert 64-bit floating point value (double) from native byte order into
429  * little endian byte order.
430  *
431  * Since: 0.10.22
432  *
433  */
434 /**
435  * GDOUBLE_TO_BE:
436  * @val: value
437  *
438  * Convert 64-bit floating point value (double) from native byte order into
439  * big endian byte order.
440  *
441  * Since: 0.10.22
442  *
443  */
444 /**
445  * GDOUBLE_FROM_LE:
446  * @val: value
447  *
448  * Convert 64-bit floating point value (double) from little endian byte order
449  * into native byte order.
450  *
451  * Since: 0.10.22
452  *
453  */
454 /**
455  * GDOUBLE_FROM_BE:
456  * @val: value
457  *
458  * Convert 64-bit floating point value (double) from big endian byte order
459  * into native byte order.
460  *
461  * Since: 0.10.22
462  *
463  */
464
465 /**
466  * GFLOAT_TO_LE:
467  * @val: value
468  *
469  * Convert 32-bit floating point value (float) from native byte order into
470  * little endian byte order.
471  *
472  * Since: 0.10.22
473  *
474  */
475 /**
476  * GFLOAT_TO_BE:
477  * @val: value
478  *
479  * Convert 32-bit floating point value (float) from native byte order into
480  * big endian byte order.
481  *
482  * Since: 0.10.22
483  *
484  */
485 /**
486  * GFLOAT_FROM_LE:
487  * @val: value
488  *
489  * Convert 32-bit floating point value (float) from little endian byte order
490  * into native byte order.
491  *
492  * Since: 0.10.22
493  *
494  */
495 /**
496  * GFLOAT_FROM_BE:
497  * @val: value
498  *
499  * Convert 32-bit floating point value (float) from big endian byte order
500  * into native byte order.
501  *
502  * Since: 0.10.22
503  *
504  */
505
506 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
507 #define GFLOAT_TO_LE(val)    ((gfloat) (val))
508 #define GFLOAT_TO_BE(val)    (GFLOAT_SWAP_LE_BE (val))
509 #define GDOUBLE_TO_LE(val)   ((gdouble) (val))
510 #define GDOUBLE_TO_BE(val)   (GDOUBLE_SWAP_LE_BE (val))
511
512 #elif G_BYTE_ORDER == G_BIG_ENDIAN
513 #define GFLOAT_TO_LE(val)    (GFLOAT_SWAP_LE_BE (val))
514 #define GFLOAT_TO_BE(val)    ((gfloat) (val))
515 #define GDOUBLE_TO_LE(val)   (GDOUBLE_SWAP_LE_BE (val))
516 #define GDOUBLE_TO_BE(val)   ((gdouble) (val))
517
518 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
519 #error unknown ENDIAN type
520 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
521
522 #define GFLOAT_FROM_LE(val)  (GFLOAT_TO_LE (val))
523 #define GFLOAT_FROM_BE(val)  (GFLOAT_TO_BE (val))
524 #define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val))
525 #define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
526
527 #endif /* !defined(GFLOAT_FROM_LE) */
528
529 /**
530  * GST_READ_FLOAT_LE:
531  * @data: memory location
532  *
533  * Read a 32 bit float value in little endian format from the memory buffer.
534  *
535  * Returns: The floating point value read from @data
536  *
537  * Since: 0.10.22
538  *
539  */
540 #ifdef _FOOL_GTK_DOC_
541 G_INLINE_FUNC gfloat GST_READ_FLOAT_LE (const guint8 *data);
542 #endif
543
544 inline static gfloat
545 GST_READ_FLOAT_LE(const guint8 *data)
546 {
547   union
548   {
549     guint32 i;
550     gfloat f;
551   } u;
552
553   u.i = GST_READ_UINT32_LE (data);
554   return u.f;
555 }
556
557 /**
558  * GST_READ_FLOAT_BE:
559  * @data: memory location
560  *
561  * Read a 32 bit float value in big endian format from the memory buffer.
562  *
563  * Returns: The floating point value read from @data
564  *
565  * Since: 0.10.22
566  *
567  */
568 #ifdef _FOOL_GTK_DOC_
569 G_INLINE_FUNC gfloat GST_READ_FLOAT_BE (const guint8 *data);
570 #endif
571
572 inline static gfloat
573 GST_READ_FLOAT_BE(const guint8 *data)
574 {
575   union
576   {
577     guint32 i;
578     gfloat f;
579   } u;
580
581   u.i = GST_READ_UINT32_BE (data);
582   return u.f;
583 }
584
585 /**
586  * GST_READ_DOUBLE_LE:
587  * @data: memory location
588  *
589  * Read a 64 bit double value in little endian format from the memory buffer.
590  *
591  * Returns: The double-precision floating point value read from @data
592  *
593  * Since: 0.10.22
594  *
595  */
596 #ifdef _FOOL_GTK_DOC_
597 G_INLINE_FUNC gdouble GST_READ_DOUBLE_LE (const guint8 *data);
598 #endif
599
600 inline static gdouble
601 GST_READ_DOUBLE_LE(const guint8 *data)
602 {
603   union
604   {
605     guint64 i;
606     gdouble d;
607   } u;
608
609   u.i = GST_READ_UINT64_LE (data);
610   return u.d;
611 }
612
613 /**
614  * GST_READ_DOUBLE_BE:
615  * @data: memory location
616  *
617  * Read a 64 bit double value in big endian format from the memory buffer.
618  *
619  * Returns: The double-precision floating point value read from @data
620  *
621  * Since: 0.10.22
622  *
623  */
624 #ifdef _FOOL_GTK_DOC_
625 G_INLINE_FUNC gdouble GST_READ_DOUBLE_BE (const guint8 *data);
626 #endif
627
628 inline static gdouble
629 GST_READ_DOUBLE_BE(const guint8 *data)
630 {
631   union
632   {
633     guint64 i;
634     gdouble d;
635   } u;
636
637   u.i = GST_READ_UINT64_BE (data);
638   return u.d;
639 }
640
641 /**
642  * GST_WRITE_FLOAT_LE:
643  * @data: memory location
644  * @num: value to store
645  *
646  * Store a 32 bit float value in little endian format into the memory buffer.
647  *
648  * Since: 0.10.22
649  *
650  */
651 #ifdef _FOOL_GTK_DOC_
652 G_INLINE_FUNC void GST_WRITE_FLOAT_LE (guint8 *data, gfloat num);
653 #endif
654
655 inline static void
656 GST_WRITE_FLOAT_LE(guint8 *data, gfloat num)
657 {
658   union
659   {
660     guint32 i;
661     gfloat f;
662   } u;
663
664   u.f = num;
665   GST_WRITE_UINT32_LE (data, u.i);
666 }
667
668 /**
669  * GST_WRITE_FLOAT_BE:
670  * @data: memory location
671  * @num: value to store
672  *
673  * Store a 32 bit float value in big endian format into the memory buffer.
674  *
675  * Since: 0.10.22
676  *
677  */
678 #ifdef _FOOL_GTK_DOC_
679 G_INLINE_FUNC void GST_WRITE_FLOAT_BE (guint8 *data, gfloat num);
680 #endif
681
682 inline static void
683 GST_WRITE_FLOAT_BE(guint8 *data, gfloat num)
684 {
685   union
686   {
687     guint32 i;
688     gfloat f;
689   } u;
690
691   u.f = num;
692   GST_WRITE_UINT32_BE (data, u.i);
693 }
694
695 /**
696  * GST_WRITE_DOUBLE_LE:
697  * @data: memory location
698  * @num: value to store
699  *
700  * Store a 64 bit double value in little endian format into the memory buffer.
701  *
702  * Since: 0.10.22
703  *
704  */
705 #ifdef _FOOL_GTK_DOC_
706 G_INLINE_FUNC void GST_WRITE_DOUBLE_LE (guint8 *data, gdouble num);
707 #endif
708
709 inline static void
710 GST_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
711 {
712   union
713   {
714     guint64 i;
715     gdouble d;
716   } u;
717
718   u.d = num;
719   GST_WRITE_UINT64_LE (data, u.i);
720 }
721
722 /**
723  * GST_WRITE_DOUBLE_BE:
724  * @data: memory location
725  * @num: value to store
726  *
727  * Store a 64 bit double value in big endian format into the memory buffer.
728  *
729  * Since: 0.10.22
730  *
731  */
732 #ifdef _FOOL_GTK_DOC_
733 G_INLINE_FUNC void GST_WRITE_DOUBLE_BE (guint8 *data, gdouble num);
734 #endif
735
736 inline static void
737 GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
738 {
739   union
740   {
741     guint64 i;
742     gdouble d;
743   } u;
744
745   u.d = num;
746   GST_WRITE_UINT64_BE (data, u.i);
747 }
748
749 /* Miscellaneous utility macros */
750
751 /**
752  * GST_ROUND_UP_2:
753  * @num: integer value to round up
754  *
755  * Rounds an integer value up to the next multiple of 2.
756  */
757 #define GST_ROUND_UP_2(num)  (((num)+1)&~1)
758 /**
759  * GST_ROUND_UP_4:
760  * @num: integer value to round up
761  *
762  * Rounds an integer value up to the next multiple of 4.
763  */
764 #define GST_ROUND_UP_4(num)  (((num)+3)&~3)
765 /**
766  * GST_ROUND_UP_8:
767  * @num: integer value to round up
768  *
769  * Rounds an integer value up to the next multiple of 8.
770  */
771 #define GST_ROUND_UP_8(num)  (((num)+7)&~7)
772 /**
773  * GST_ROUND_UP_16:
774  * @num: integer value to round up
775  *
776  * Rounds an integer value up to the next multiple of 16.
777  */
778 #define GST_ROUND_UP_16(num) (((num)+15)&~15)
779 /**
780  * GST_ROUND_UP_32:
781  * @num: integer value to round up
782  *
783  * Rounds an integer value up to the next multiple of 32.
784  */
785 #define GST_ROUND_UP_32(num) (((num)+31)&~31)
786 /**
787  * GST_ROUND_UP_64:
788  * @num: integer value to round up
789  *
790  * Rounds an integer value up to the next multiple of 64.
791  */
792 #define GST_ROUND_UP_64(num) (((num)+63)&~63)
793
794 /**
795  * GST_ROUND_DOWN_2:
796  * @num: integer value to round down
797  *
798  * Rounds an integer value down to the next multiple of 2.
799  *
800  * Since: 0.10.12
801  */
802 #define GST_ROUND_DOWN_2(num)  ((num)&(~1))
803 /**
804  * GST_ROUND_DOWN_4:
805  * @num: integer value to round down
806  *
807  * Rounds an integer value down to the next multiple of 4.
808  *
809  * Since: 0.10.12
810  */
811 #define GST_ROUND_DOWN_4(num)  ((num)&(~3))
812 /**
813  * GST_ROUND_DOWN_8:
814  * @num: integer value to round down
815  *
816  * Rounds an integer value down to the next multiple of 8.
817  *
818  * Since: 0.10.12
819  */
820 #define GST_ROUND_DOWN_8(num)  ((num)&(~7))
821 /**
822  * GST_ROUND_DOWN_16:
823  * @num: integer value to round down
824  *
825  * Rounds an integer value down to the next multiple of 16.
826  *
827  * Since: 0.10.12
828  */
829 #define GST_ROUND_DOWN_16(num) ((num)&(~15))
830 /**
831  * GST_ROUND_DOWN_32:
832  * @num: integer value to round down
833  *
834  * Rounds an integer value down to the next multiple of 32.
835  *
836  * Since: 0.10.12
837  */
838 #define GST_ROUND_DOWN_32(num) ((num)&(~31))
839 /**
840  * GST_ROUND_DOWN_64:
841  * @num: integer value to round down
842  *
843  * Rounds an integer value down to the next multiple of 64.
844  *
845  * Since: 0.10.12
846  */
847 #define GST_ROUND_DOWN_64(num) ((num)&(~63))
848
849 void                    gst_object_default_error        (GstObject    * source,
850                                                          const GError * error,
851                                                          const gchar  * debug);
852
853 /* element functions */
854 void                    gst_element_create_all_pads     (GstElement *element);
855 GstPad*                 gst_element_get_compatible_pad  (GstElement *element, GstPad *pad,
856                                                          const GstCaps *caps);
857
858 GstPadTemplate*         gst_element_get_compatible_pad_template (GstElement *element, GstPadTemplate *compattempl);
859
860 G_CONST_RETURN gchar*   gst_element_state_get_name      (GstState state);
861 G_CONST_RETURN gchar *  gst_element_state_change_return_get_name (GstStateChangeReturn state_ret);
862
863 gboolean                gst_element_link                (GstElement *src, GstElement *dest);
864 gboolean                gst_element_link_many           (GstElement *element_1,
865                                                          GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
866 gboolean                gst_element_link_filtered       (GstElement * src,
867                                                          GstElement * dest,
868                                                          GstCaps *filter);
869 void                    gst_element_unlink              (GstElement *src, GstElement *dest);
870 void                    gst_element_unlink_many         (GstElement *element_1,
871                                                          GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
872
873 gboolean                gst_element_link_pads           (GstElement *src, const gchar *srcpadname,
874                                                          GstElement *dest, const gchar *destpadname);
875 gboolean                gst_element_link_pads_full      (GstElement *src, const gchar *srcpadname,
876                                                          GstElement *dest, const gchar *destpadname,
877                                                          GstPadLinkCheck flags);
878 void                    gst_element_unlink_pads         (GstElement *src, const gchar *srcpadname,
879                                                          GstElement *dest, const gchar *destpadname);
880
881 gboolean                gst_element_link_pads_filtered  (GstElement * src, const gchar * srcpadname,
882                                                          GstElement * dest, const gchar * destpadname,
883                                                          GstCaps *filter);
884
885 gboolean                gst_element_seek_simple         (GstElement   *element,
886                                                          GstFormat     format,
887                                                          GstSeekFlags  seek_flags,
888                                                          gint64        seek_pos);
889
890 /* util elementfactory functions */
891 gboolean gst_element_factory_can_sink_all_caps (GstElementFactory *factory, const GstCaps *caps);
892 gboolean gst_element_factory_can_src_all_caps  (GstElementFactory *factory, const GstCaps *caps);
893 gboolean gst_element_factory_can_sink_any_caps (GstElementFactory *factory, const GstCaps *caps);
894 gboolean gst_element_factory_can_src_any_caps  (GstElementFactory *factory, const GstCaps *caps);
895
896 /* util query functions */
897 gboolean                gst_element_query_position      (GstElement *element, GstFormat *format,
898                                                          gint64 *cur);
899 gboolean                gst_element_query_duration      (GstElement *element, GstFormat *format,
900                                                          gint64 *duration);
901 gboolean                gst_element_query_convert       (GstElement *element, GstFormat src_format, gint64 src_val,
902                                                          GstFormat *dest_format, gint64 *dest_val);
903
904 /* element class functions */
905 void                    gst_element_class_install_std_props (GstElementClass * klass,
906                                                          const gchar * first_name, ...) G_GNUC_NULL_TERMINATED;
907
908 /* pad functions */
909 void                    gst_pad_use_fixed_caps          (GstPad *pad);
910 GstCaps*                gst_pad_proxy_getcaps           (GstPad * pad, GstCaps * filter);
911 gboolean                gst_pad_proxy_setcaps           (GstPad * pad, GstCaps * caps);
912
913 GstElement*             gst_pad_get_parent_element      (GstPad *pad);
914
915 /* util query functions */
916 gboolean                gst_pad_query_position          (GstPad *pad, GstFormat *format,
917                                                          gint64 *cur);
918 gboolean                gst_pad_query_duration          (GstPad *pad, GstFormat *format,
919                                                          gint64 *duration);
920 gboolean                gst_pad_query_convert           (GstPad *pad, GstFormat src_format, gint64 src_val,
921                                                          GstFormat *dest_format, gint64 *dest_val);
922
923 gboolean                gst_pad_query_peer_position     (GstPad *pad, GstFormat *format,
924                                                          gint64 *cur);
925 gboolean                gst_pad_query_peer_duration     (GstPad *pad, GstFormat *format,
926                                                          gint64 *duration);
927 gboolean                gst_pad_query_peer_convert      (GstPad *pad, GstFormat src_format, gint64 src_val,
928                                                          GstFormat *dest_format, gint64 *dest_val);
929
930 /* bin functions */
931 void                    gst_bin_add_many                (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
932 void                    gst_bin_remove_many             (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
933 GstPad *                gst_bin_find_unlinked_pad       (GstBin *bin, GstPadDirection direction);
934
935 /* buffer functions */
936 GstBuffer *             gst_buffer_merge                (GstBuffer * buf1, GstBuffer * buf2);
937 GstBuffer *             gst_buffer_join                 (GstBuffer * buf1, GstBuffer * buf2);
938
939 /* probes */
940 gulong                  gst_pad_add_data_probe          (GstPad   * pad,
941                                                          GCallback  handler,
942                                                          gpointer   data);
943
944 gulong                  gst_pad_add_data_probe_full     (GstPad       * pad,
945                                                          GCallback      handler,
946                                                          gpointer       data,
947                                                          GDestroyNotify notify);
948
949 void                    gst_pad_remove_data_probe       (GstPad * pad, guint handler_id);
950
951 gulong                  gst_pad_add_event_probe         (GstPad   * pad,
952                                                          GCallback  handler,
953                                                          gpointer   data);
954
955 gulong                  gst_pad_add_event_probe_full    (GstPad       * pad,
956                                                          GCallback      handler,
957                                                          gpointer       data,
958                                                          GDestroyNotify notify);
959
960 void                    gst_pad_remove_event_probe      (GstPad * pad, guint handler_id);
961
962 gulong                  gst_pad_add_buffer_probe        (GstPad   * pad,
963                                                          GCallback  handler,
964                                                          gpointer   data);
965
966 gulong                  gst_pad_add_buffer_probe_full   (GstPad       * pad,
967                                                          GCallback      handler,
968                                                          gpointer       data,
969                                                          GDestroyNotify notify);
970
971 void                    gst_pad_remove_buffer_probe     (GstPad * pad, guint handler_id);
972
973 /* tag emission utility functions */
974 void                    gst_element_found_tags_for_pad  (GstElement * element,
975                                                          GstPad * pad,
976                                                          GstTagList * list);
977 void                    gst_element_found_tags          (GstElement * element,
978                                                          GstTagList * list);
979
980 /* parse utility functions */
981 GstElement *            gst_parse_bin_from_description      (const gchar     * bin_description,
982                                                              gboolean          ghost_unlinked_pads,
983                                                              GError         ** err);
984
985 GstElement *            gst_parse_bin_from_description_full (const gchar     * bin_description,
986                                                              gboolean          ghost_unlinked_pads,
987                                                              GstParseContext * context,
988                                                              GstParseFlags     flags,
989                                                              GError         ** err);
990
991 GstClockTime            gst_util_get_timestamp          (void);
992
993 /**
994  * GstSearchMode:
995  * @GST_SEARCH_MODE_EXACT : Only search for exact matches.
996  * @GST_SEARCH_MODE_BEFORE: Search for an exact match or the element just before.
997  * @GST_SEARCH_MODE_AFTER : Search for an exact match or the element just after.
998  *
999  * The different search modes.
1000  *
1001  * Since: 0.10.23
1002  */
1003 typedef enum {
1004   GST_SEARCH_MODE_EXACT = 0,
1005   GST_SEARCH_MODE_BEFORE,
1006   GST_SEARCH_MODE_AFTER
1007 } GstSearchMode;
1008
1009 gpointer                gst_util_array_binary_search      (gpointer array, guint num_elements,
1010                                                            gsize element_size, GCompareDataFunc search_func,
1011                                                            GstSearchMode mode, gconstpointer search_data,
1012                                                            gpointer user_data);
1013
1014 gint gst_util_greatest_common_divisor (gint a, gint b);
1015 void gst_util_fraction_to_double (gint src_n, gint src_d, gdouble *dest);
1016 void gst_util_double_to_fraction (gdouble src, gint *dest_n, gint *dest_d);
1017 gboolean gst_util_fraction_multiply (gint a_n, gint a_d, gint b_n, gint b_d, gint *res_n, gint *res_d);
1018 gboolean gst_util_fraction_add (gint a_n, gint a_d, gint b_n, gint b_d, gint *res_n, gint *res_d);
1019 gint gst_util_fraction_compare (gint a_n, gint a_d, gint b_n, gint b_d);
1020
1021
1022 /* sink message event
1023  *
1024  * FIXME: This should be in gstevent.h but can't because
1025  * it needs GstMessage and this would introduce circular
1026  * header includes. And forward declarations of typedefs
1027  * are unfortunately not possible. The implementation of
1028  * these functions is in gstevent.c.
1029  */
1030 GstEvent*       gst_event_new_sink_message      (GstMessage *msg);
1031 void            gst_event_parse_sink_message    (GstEvent *event, GstMessage **msg);
1032
1033
1034 G_END_DECLS
1035
1036 #endif /* __GST_UTILS_H__ */