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