f48b630bdcaec11e05c612cad128058fcd9bf740
[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 /**
363  * GST_READ_FLOAT_LE:
364  * @data: memory location
365  *
366  * Read a 32 bit float value in little endian format from the memory buffer.
367  *
368  * Returns: The floating point value read from @data
369  *
370  * Since: 0.10.22
371  *
372  */
373 #ifdef _FOOL_GTK_DOC_
374 G_INLINE_FUNC gfloat GST_READ_FLOAT_LE (const guint8 *data);
375 #endif
376
377 inline static gfloat
378 GST_READ_FLOAT_LE(const guint8 *data)
379 {
380   union
381   {
382     guint32 i;
383     gfloat f;
384   } u;
385
386   u.i = GST_READ_UINT32_LE (data);
387   return u.f;
388 }
389
390 /**
391  * GST_READ_FLOAT_BE:
392  * @data: memory location
393  *
394  * Read a 32 bit float value in big endian format from the memory buffer.
395  *
396  * Returns: The floating point value read from @data
397  *
398  * Since: 0.10.22
399  *
400  */
401 #ifdef _FOOL_GTK_DOC_
402 G_INLINE_FUNC gfloat GST_READ_FLOAT_BE (const guint8 *data);
403 #endif
404
405 inline static gfloat
406 GST_READ_FLOAT_BE(const guint8 *data)
407 {
408   union
409   {
410     guint32 i;
411     gfloat f;
412   } u;
413
414   u.i = GST_READ_UINT32_BE (data);
415   return u.f;
416 }
417
418 /**
419  * GST_READ_DOUBLE_LE:
420  * @data: memory location
421  *
422  * Read a 64 bit double value in little endian format from the memory buffer.
423  *
424  * Returns: The double-precision floating point value read from @data
425  *
426  * Since: 0.10.22
427  *
428  */
429 #ifdef _FOOL_GTK_DOC_
430 G_INLINE_FUNC gdouble GST_READ_DOUBLE_LE (const guint8 *data);
431 #endif
432
433 inline static gdouble
434 GST_READ_DOUBLE_LE(const guint8 *data)
435 {
436   union
437   {
438     guint64 i;
439     gdouble d;
440   } u;
441
442   u.i = GST_READ_UINT64_LE (data);
443   return u.d;
444 }
445
446 /**
447  * GST_READ_DOUBLE_BE:
448  * @data: memory location
449  *
450  * Read a 64 bit double value in big endian format from the memory buffer.
451  *
452  * Returns: The double-precision floating point value read from @data
453  *
454  * Since: 0.10.22
455  *
456  */
457 #ifdef _FOOL_GTK_DOC_
458 G_INLINE_FUNC gdouble GST_READ_DOUBLE_BE (const guint8 *data);
459 #endif
460
461 inline static gdouble
462 GST_READ_DOUBLE_BE(const guint8 *data)
463 {
464   union
465   {
466     guint64 i;
467     gdouble d;
468   } u;
469
470   u.i = GST_READ_UINT64_BE (data);
471   return u.d;
472 }
473
474 /**
475  * GST_WRITE_FLOAT_LE:
476  * @data: memory location
477  * @num: value to store
478  *
479  * Store a 32 bit float value in little endian format into the memory buffer.
480  *
481  * Since: 0.10.22
482  *
483  */
484 #ifdef _FOOL_GTK_DOC_
485 G_INLINE_FUNC void GST_WRITE_FLOAT_LE (guint8 *data, gfloat num);
486 #endif
487
488 inline static void
489 GST_WRITE_FLOAT_LE(guint8 *data, gfloat num)
490 {
491   union
492   {
493     guint32 i;
494     gfloat f;
495   } u;
496
497   u.f = num;
498   GST_WRITE_UINT32_LE (data, u.i);
499 }
500
501 /**
502  * GST_WRITE_FLOAT_BE:
503  * @data: memory location
504  * @num: value to store
505  *
506  * Store a 32 bit float value in big endian format into the memory buffer.
507  *
508  * Since: 0.10.22
509  *
510  */
511 #ifdef _FOOL_GTK_DOC_
512 G_INLINE_FUNC void GST_WRITE_FLOAT_BE (guint8 *data, gfloat num);
513 #endif
514
515 inline static void
516 GST_WRITE_FLOAT_BE(guint8 *data, gfloat num)
517 {
518   union
519   {
520     guint32 i;
521     gfloat f;
522   } u;
523
524   u.f = num;
525   GST_WRITE_UINT32_BE (data, u.i);
526 }
527
528 /**
529  * GST_WRITE_DOUBLE_LE:
530  * @data: memory location
531  * @num: value to store
532  *
533  * Store a 64 bit double value in little endian format into the memory buffer.
534  *
535  * Since: 0.10.22
536  *
537  */
538 #ifdef _FOOL_GTK_DOC_
539 G_INLINE_FUNC void GST_WRITE_DOUBLE_LE (guint8 *data, gdouble num);
540 #endif
541
542 inline static void
543 GST_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
544 {
545   union
546   {
547     guint64 i;
548     gdouble d;
549   } u;
550
551   u.d = num;
552   GST_WRITE_UINT64_LE (data, u.i);
553 }
554
555 /**
556  * GST_WRITE_DOUBLE_BE:
557  * @data: memory location
558  * @num: value to store
559  *
560  * Store a 64 bit double value in big endian format into the memory buffer.
561  *
562  * Since: 0.10.22
563  *
564  */
565 #ifdef _FOOL_GTK_DOC_
566 G_INLINE_FUNC void GST_WRITE_DOUBLE_BE (guint8 *data, gdouble num);
567 #endif
568
569 inline static void
570 GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
571 {
572   union
573   {
574     guint64 i;
575     gdouble d;
576   } u;
577
578   u.d = num;
579   GST_WRITE_UINT64_BE (data, u.i);
580 }
581
582 /* Miscellaneous utility macros */
583
584 /**
585  * GST_ROUND_UP_2:
586  * @num: integer value to round up
587  *
588  * Rounds an integer value up to the next multiple of 2.
589  */
590 #define GST_ROUND_UP_2(num)  (((num)+1)&~1)
591 /**
592  * GST_ROUND_UP_4:
593  * @num: integer value to round up
594  *
595  * Rounds an integer value up to the next multiple of 4.
596  */
597 #define GST_ROUND_UP_4(num)  (((num)+3)&~3)
598 /**
599  * GST_ROUND_UP_8:
600  * @num: integer value to round up
601  *
602  * Rounds an integer value up to the next multiple of 8.
603  */
604 #define GST_ROUND_UP_8(num)  (((num)+7)&~7)
605 /**
606  * GST_ROUND_UP_16:
607  * @num: integer value to round up
608  *
609  * Rounds an integer value up to the next multiple of 16.
610  */
611 #define GST_ROUND_UP_16(num) (((num)+15)&~15)
612 /**
613  * GST_ROUND_UP_32:
614  * @num: integer value to round up
615  *
616  * Rounds an integer value up to the next multiple of 32.
617  */
618 #define GST_ROUND_UP_32(num) (((num)+31)&~31)
619 /**
620  * GST_ROUND_UP_64:
621  * @num: integer value to round up
622  *
623  * Rounds an integer value up to the next multiple of 64.
624  */
625 #define GST_ROUND_UP_64(num) (((num)+63)&~63)
626
627 /**
628  * GST_ROUND_DOWN_2:
629  * @num: integer value to round down
630  *
631  * Rounds an integer value down to the next multiple of 2.
632  *
633  * Since: 0.10.12
634  */
635 #define GST_ROUND_DOWN_2(num)  ((num)&(~1))
636 /**
637  * GST_ROUND_DOWN_4:
638  * @num: integer value to round down
639  *
640  * Rounds an integer value down to the next multiple of 4.
641  *
642  * Since: 0.10.12
643  */
644 #define GST_ROUND_DOWN_4(num)  ((num)&(~3))
645 /**
646  * GST_ROUND_DOWN_8:
647  * @num: integer value to round down
648  *
649  * Rounds an integer value down to the next multiple of 8.
650  *
651  * Since: 0.10.12
652  */
653 #define GST_ROUND_DOWN_8(num)  ((num)&(~7))
654 /**
655  * GST_ROUND_DOWN_16:
656  * @num: integer value to round down
657  *
658  * Rounds an integer value down to the next multiple of 16.
659  *
660  * Since: 0.10.12
661  */
662 #define GST_ROUND_DOWN_16(num) ((num)&(~15))
663 /**
664  * GST_ROUND_DOWN_32:
665  * @num: integer value to round down
666  *
667  * Rounds an integer value down to the next multiple of 32.
668  *
669  * Since: 0.10.12
670  */
671 #define GST_ROUND_DOWN_32(num) ((num)&(~31))
672 /**
673  * GST_ROUND_DOWN_64:
674  * @num: integer value to round down
675  *
676  * Rounds an integer value down to the next multiple of 64.
677  *
678  * Since: 0.10.12
679  */
680 #define GST_ROUND_DOWN_64(num) ((num)&(~63))
681
682 void                    gst_object_default_error        (GstObject    * source,
683                                                          const GError * error,
684                                                          const gchar  * debug);
685
686 /* element functions */
687 void                    gst_element_create_all_pads     (GstElement *element);
688 GstPad*                 gst_element_get_compatible_pad  (GstElement *element, GstPad *pad,
689                                                          const GstCaps *caps);
690
691 GstPadTemplate*         gst_element_get_compatible_pad_template (GstElement *element, GstPadTemplate *compattempl);
692
693 G_CONST_RETURN gchar*   gst_element_state_get_name      (GstState state);
694 G_CONST_RETURN gchar *  gst_element_state_change_return_get_name (GstStateChangeReturn state_ret);
695
696 gboolean                gst_element_link                (GstElement *src, GstElement *dest);
697 gboolean                gst_element_link_many           (GstElement *element_1,
698                                                          GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
699 gboolean                gst_element_link_filtered       (GstElement * src,
700                                                          GstElement * dest,
701                                                          GstCaps *filter);
702 void                    gst_element_unlink              (GstElement *src, GstElement *dest);
703 void                    gst_element_unlink_many         (GstElement *element_1,
704                                                          GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
705
706 gboolean                gst_element_link_pads           (GstElement *src, const gchar *srcpadname,
707                                                          GstElement *dest, const gchar *destpadname);
708 gboolean                gst_element_link_pads_full      (GstElement *src, const gchar *srcpadname,
709                                                          GstElement *dest, const gchar *destpadname,
710                                                          GstPadLinkCheck flags);
711 void                    gst_element_unlink_pads         (GstElement *src, const gchar *srcpadname,
712                                                          GstElement *dest, const gchar *destpadname);
713
714 gboolean                gst_element_link_pads_filtered  (GstElement * src, const gchar * srcpadname,
715                                                          GstElement * dest, const gchar * destpadname,
716                                                          GstCaps *filter);
717
718 gboolean                gst_element_seek_simple         (GstElement   *element,
719                                                          GstFormat     format,
720                                                          GstSeekFlags  seek_flags,
721                                                          gint64        seek_pos);
722
723 /* util elementfactory functions */
724 gboolean gst_element_factory_can_sink_all_caps (GstElementFactory *factory, const GstCaps *caps);
725 gboolean gst_element_factory_can_src_all_caps  (GstElementFactory *factory, const GstCaps *caps);
726 gboolean gst_element_factory_can_sink_any_caps (GstElementFactory *factory, const GstCaps *caps);
727 gboolean gst_element_factory_can_src_any_caps  (GstElementFactory *factory, const GstCaps *caps);
728
729 /* util query functions */
730 gboolean                gst_element_query_position      (GstElement *element, GstFormat *format,
731                                                          gint64 *cur);
732 gboolean                gst_element_query_duration      (GstElement *element, GstFormat *format,
733                                                          gint64 *duration);
734 gboolean                gst_element_query_convert       (GstElement *element, GstFormat src_format, gint64 src_val,
735                                                          GstFormat *dest_format, gint64 *dest_val);
736
737 /* element class functions */
738 void                    gst_element_class_install_std_props (GstElementClass * klass,
739                                                          const gchar * first_name, ...) G_GNUC_NULL_TERMINATED;
740
741 /* pad functions */
742 void                    gst_pad_use_fixed_caps          (GstPad *pad);
743 GstCaps*                gst_pad_proxy_getcaps           (GstPad * pad, GstCaps * filter);
744
745 GstElement*             gst_pad_get_parent_element      (GstPad *pad);
746
747 /* util query functions */
748 gboolean                gst_pad_query_position          (GstPad *pad, GstFormat *format,
749                                                          gint64 *cur);
750 gboolean                gst_pad_query_duration          (GstPad *pad, GstFormat *format,
751                                                          gint64 *duration);
752 gboolean                gst_pad_query_convert           (GstPad *pad, GstFormat src_format, gint64 src_val,
753                                                          GstFormat *dest_format, gint64 *dest_val);
754
755 gboolean                gst_pad_query_peer_position     (GstPad *pad, GstFormat *format,
756                                                          gint64 *cur);
757 gboolean                gst_pad_query_peer_duration     (GstPad *pad, GstFormat *format,
758                                                          gint64 *duration);
759 gboolean                gst_pad_query_peer_convert      (GstPad *pad, GstFormat src_format, gint64 src_val,
760                                                          GstFormat *dest_format, gint64 *dest_val);
761
762 /* bin functions */
763 void                    gst_bin_add_many                (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
764 void                    gst_bin_remove_many             (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
765 GstPad *                gst_bin_find_unlinked_pad       (GstBin *bin, GstPadDirection direction);
766
767 /* buffer functions */
768 GstBuffer *             gst_buffer_merge                (GstBuffer * buf1, GstBuffer * buf2);
769 GstBuffer *             gst_buffer_join                 (GstBuffer * buf1, GstBuffer * buf2);
770
771 /* tag emission utility functions */
772 void                    gst_element_found_tags_for_pad  (GstElement * element,
773                                                          GstPad * pad,
774                                                          GstTagList * list);
775 void                    gst_element_found_tags          (GstElement * element,
776                                                          GstTagList * list);
777
778 /* parse utility functions */
779 GstElement *            gst_parse_bin_from_description      (const gchar     * bin_description,
780                                                              gboolean          ghost_unlinked_pads,
781                                                              GError         ** err);
782
783 GstElement *            gst_parse_bin_from_description_full (const gchar     * bin_description,
784                                                              gboolean          ghost_unlinked_pads,
785                                                              GstParseContext * context,
786                                                              GstParseFlags     flags,
787                                                              GError         ** err);
788
789 GstClockTime            gst_util_get_timestamp          (void);
790
791 /**
792  * GstSearchMode:
793  * @GST_SEARCH_MODE_EXACT : Only search for exact matches.
794  * @GST_SEARCH_MODE_BEFORE: Search for an exact match or the element just before.
795  * @GST_SEARCH_MODE_AFTER : Search for an exact match or the element just after.
796  *
797  * The different search modes.
798  *
799  * Since: 0.10.23
800  */
801 typedef enum {
802   GST_SEARCH_MODE_EXACT = 0,
803   GST_SEARCH_MODE_BEFORE,
804   GST_SEARCH_MODE_AFTER
805 } GstSearchMode;
806
807 gpointer                gst_util_array_binary_search      (gpointer array, guint num_elements,
808                                                            gsize element_size, GCompareDataFunc search_func,
809                                                            GstSearchMode mode, gconstpointer search_data,
810                                                            gpointer user_data);
811
812 gint gst_util_greatest_common_divisor (gint a, gint b);
813 void gst_util_fraction_to_double (gint src_n, gint src_d, gdouble *dest);
814 void gst_util_double_to_fraction (gdouble src, gint *dest_n, gint *dest_d);
815 gboolean gst_util_fraction_multiply (gint a_n, gint a_d, gint b_n, gint b_d, gint *res_n, gint *res_d);
816 gboolean gst_util_fraction_add (gint a_n, gint a_d, gint b_n, gint b_d, gint *res_n, gint *res_d);
817 gint gst_util_fraction_compare (gint a_n, gint a_d, gint b_n, gint b_d);
818
819
820 /* sink message event
821  *
822  * FIXME: This should be in gstevent.h but can't because
823  * it needs GstMessage and this would introduce circular
824  * header includes. And forward declarations of typedefs
825  * are unfortunately not possible. The implementation of
826  * these functions is in gstevent.c.
827  */
828 GstEvent*       gst_event_new_sink_message      (GstMessage *msg);
829 void            gst_event_parse_sink_message    (GstEvent *event, GstMessage **msg);
830
831
832 G_END_DECLS
833
834 #endif /* __GST_UTILS_H__ */