utils: Don't use G_GNUC_CONST for the uint64 scaling 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/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 /* Macros for defining classes.  Ideas taken from Bonobo, which took theirs
97    from Nautilus and GOB. */
98
99 /**
100  * GST_BOILERPLATE_FULL:
101  * @type: the name of the type struct
102  * @type_as_function: the prefix for the functions
103  * @parent_type: the parent type struct name
104  * @parent_type_macro: the parent type macro
105  * @additional_initializations: function pointer in the form of
106  * void additional_initializations (GType type) that can be used for
107  * initializing interfaces and the like
108  *
109  * Define the boilerplate type stuff to reduce typos and code size.  Defines
110  * the get_type method and the parent_class static variable.
111  *
112  * <informalexample>
113  * <programlisting>
114  *   GST_BOILERPLATE_FULL (GstFdSink, gst_fdsink, GstElement, GST_TYPE_ELEMENT, _do_init);
115  * </programlisting>
116  * </informalexample>
117  */
118 #define GST_BOILERPLATE_FULL(type, type_as_function, parent_type, parent_type_macro, additional_initializations)        \
119                                                                         \
120 static void type_as_function ## _base_init     (gpointer      g_class); \
121 static void type_as_function ## _class_init    (type ## Class *g_class);\
122 static void type_as_function ## _init          (type          *object,  \
123                                                 type ## Class *g_class);\
124 static parent_type ## Class *parent_class = NULL;                       \
125 static void                                                             \
126 type_as_function ## _class_init_trampoline (gpointer g_class,           \
127                                             gpointer data)              \
128 {                                                                       \
129   parent_class = (parent_type ## Class *)                               \
130       g_type_class_peek_parent (g_class);                               \
131   type_as_function ## _class_init ((type ## Class *)g_class);           \
132 }                                                                       \
133                                                                         \
134 GType                                                                   \
135 type_as_function ## _get_type (void)                                    \
136 {                                                                       \
137   /* The typedef for GType may be gulong or gsize, depending on the     \
138    * system and whether the compiler is c++ or not. The g_once_init_*   \
139    * functions always take a gsize * though ... */                      \
140   static volatile gsize gonce_data = 0;                                 \
141   if (g_once_init_enter (&gonce_data)) {                                \
142     GType _type;                                                        \
143     _type = gst_type_register_static_full (parent_type_macro,           \
144         g_intern_static_string (#type),                                 \
145         sizeof (type ## Class),                                         \
146         type_as_function ## _base_init,                                 \
147         NULL,             /* base_finalize */                           \
148         type_as_function ## _class_init_trampoline,                     \
149         NULL,             /* class_finalize */                          \
150         NULL,               /* class_data */                            \
151         sizeof (type),                                                  \
152         0,                  /* n_preallocs */                           \
153         (GInstanceInitFunc) type_as_function ## _init,                  \
154         NULL,                                                           \
155         (GTypeFlags) 0);                                                \
156     additional_initializations (_type);                                 \
157     g_once_init_leave (&gonce_data, (gsize) _type);                     \
158   }                                                                     \
159   return (GType) gonce_data;                                            \
160 }
161
162 #define __GST_DO_NOTHING(type)  /* NOP */
163
164 /**
165  * GST_BOILERPLATE:
166  * @type: the name of the type struct
167  * @type_as_function: the prefix for the functions
168  * @parent_type: the parent type struct name
169  * @parent_type_macro: the parent type macro
170  *
171  * Define the boilerplate type stuff to reduce typos and code size.  Defines
172  * the get_type method and the parent_class static variable.
173  *
174  * <informalexample>
175  * <programlisting>
176  *   GST_BOILERPLATE (GstFdSink, gst_fdsink, GstElement, GST_TYPE_ELEMENT);
177  * </programlisting>
178  * </informalexample>
179  */
180 #define GST_BOILERPLATE(type,type_as_function,parent_type,parent_type_macro)    \
181   GST_BOILERPLATE_FULL (type, type_as_function, parent_type, parent_type_macro, \
182       __GST_DO_NOTHING)
183
184 /* Like GST_BOILERPLATE, but makes the type 1) implement an interface, and 2)
185  * implement GstImplementsInterface for that type
186  *
187  * After this you will need to implement interface_as_function ## _supported
188  * and interface_as_function ## _interface_init
189  */
190 /**
191  * GST_BOILERPLATE_WITH_INTERFACE:
192  * @type: the name of the type struct
193  * @type_as_function: the prefix for the functions
194  * @parent_type: the parent type struct name
195  * @parent_type_as_macro: the parent type macro
196  * @interface_type: the name of the interface type struct
197  * @interface_type_as_macro: the interface type macro
198  * @interface_as_function: the interface function name prefix
199  *
200  * Like GST_BOILERPLATE, but makes the type 1) implement an interface, and 2)
201  * implement GstImplementsInterface for that type.
202  *
203  * After this you will need to implement interface_as_function ## _supported
204  * and interface_as_function ## _interface_init
205  */
206 #define GST_BOILERPLATE_WITH_INTERFACE(type, type_as_function,          \
207     parent_type, parent_type_as_macro, interface_type,                  \
208     interface_type_as_macro, interface_as_function)                     \
209                                                                         \
210 static void interface_as_function ## _interface_init (interface_type ## Class *klass);  \
211 static gboolean interface_as_function ## _supported (type *object, GType iface_type);   \
212                                                                         \
213 static void                                                             \
214 type_as_function ## _implements_interface_init (GstImplementsInterfaceClass *klass)     \
215 {                                                                       \
216   klass->supported = (gboolean (*)(GstImplementsInterface*, GType))interface_as_function ## _supported;     \
217 }                                                                       \
218                                                                         \
219 static void                                                             \
220 type_as_function ## _init_interfaces (GType type)                       \
221 {                                                                       \
222   static const GInterfaceInfo implements_iface_info = {                 \
223     (GInterfaceInitFunc) type_as_function ## _implements_interface_init,\
224     NULL,                                                               \
225     NULL,                                                               \
226   };                                                                    \
227   static const GInterfaceInfo iface_info = {                            \
228     (GInterfaceInitFunc) interface_as_function ## _interface_init,      \
229     NULL,                                                               \
230     NULL,                                                               \
231   };                                                                    \
232                                                                         \
233   g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE,     \
234       &implements_iface_info);                                          \
235   g_type_add_interface_static (type, interface_type_as_macro,           \
236       &iface_info);                                                     \
237 }                                                                       \
238                                                                         \
239 GST_BOILERPLATE_FULL (type, type_as_function, parent_type,              \
240     parent_type_as_macro, type_as_function ## _init_interfaces)
241
242 /**
243  * GST_CALL_PARENT:
244  * @parent_class_cast: the name of the class cast macro for the parent type
245  * @name: name of the function to call
246  * @args: arguments enclosed in '( )'
247  *
248  * Just call the parent handler.  This assumes that there is a variable
249  * named parent_class that points to the (duh!) parent class.  Note that
250  * this macro is not to be used with things that return something, use
251  * the _WITH_DEFAULT version for that
252  */
253 #define GST_CALL_PARENT(parent_class_cast, name, args)                  \
254         ((parent_class_cast(parent_class)->name != NULL) ?              \
255          parent_class_cast(parent_class)->name args : (void) 0)
256
257 /**
258  * GST_CALL_PARENT_WITH_DEFAULT:
259  * @parent_class_cast: the name of the class cast macro for the parent type
260  * @name: name of the function to call
261  * @args: arguments enclosed in '( )'
262  * @def_return: default result
263  *
264  * Same as GST_CALL_PARENT(), but in case there is no implementation, it
265  * evaluates to @def_return.
266  */
267 #define GST_CALL_PARENT_WITH_DEFAULT(parent_class_cast, name, args, def_return)\
268         ((parent_class_cast(parent_class)->name != NULL) ?              \
269          parent_class_cast(parent_class)->name args : def_return)
270
271 /* Define PUT and GET functions for unaligned memory */
272 #define _GST_GET(__data, __idx, __size, __shift) \
273     (((guint##__size) (((guint8 *) (__data))[__idx])) << (__shift))
274
275 #define _GST_PUT(__data, __idx, __size, __shift, __num) \
276     (((guint8 *) (__data))[__idx] = (((guint##__size) (__num)) >> (__shift)) & 0xff)
277
278 /**
279  * GST_READ_UINT64_BE:
280  * @data: memory location
281  *
282  * Read a 64 bit unsigned integer value in big endian format from the memory buffer.
283  */
284 #define GST_READ_UINT64_BE(data)        (_GST_GET (data, 0, 64, 56) | \
285                                          _GST_GET (data, 1, 64, 48) | \
286                                          _GST_GET (data, 2, 64, 40) | \
287                                          _GST_GET (data, 3, 64, 32) | \
288                                          _GST_GET (data, 4, 64, 24) | \
289                                          _GST_GET (data, 5, 64, 16) | \
290                                          _GST_GET (data, 6, 64,  8) | \
291                                          _GST_GET (data, 7, 64,  0))
292
293 /**
294  * GST_READ_UINT64_LE:
295  * @data: memory location
296  *
297  * Read a 64 bit unsigned integer value in little endian format from the memory buffer.
298  */
299 #define GST_READ_UINT64_LE(data)        (_GST_GET (data, 7, 64, 56) | \
300                                          _GST_GET (data, 6, 64, 48) | \
301                                          _GST_GET (data, 5, 64, 40) | \
302                                          _GST_GET (data, 4, 64, 32) | \
303                                          _GST_GET (data, 3, 64, 24) | \
304                                          _GST_GET (data, 2, 64, 16) | \
305                                          _GST_GET (data, 1, 64,  8) | \
306                                          _GST_GET (data, 0, 64,  0))
307
308 /**
309  * GST_READ_UINT32_BE:
310  * @data: memory location
311  *
312  * Read a 32 bit unsigned integer value in big endian format from the memory buffer.
313  */
314 #define GST_READ_UINT32_BE(data)        (_GST_GET (data, 0, 32, 24) | \
315                                          _GST_GET (data, 1, 32, 16) | \
316                                          _GST_GET (data, 2, 32,  8) | \
317                                          _GST_GET (data, 3, 32,  0))
318
319 /**
320  * GST_READ_UINT32_LE:
321  * @data: memory location
322  *
323  * Read a 32 bit unsigned integer value in little endian format from the memory buffer.
324  */
325 #define GST_READ_UINT32_LE(data)        (_GST_GET (data, 3, 32, 24) | \
326                                          _GST_GET (data, 2, 32, 16) | \
327                                          _GST_GET (data, 1, 32,  8) | \
328                                          _GST_GET (data, 0, 32,  0))
329
330 /**
331  * GST_READ_UINT24_BE:
332  * @data: memory location
333  *
334  * Read a 24 bit unsigned integer value in big endian format from the memory buffer.
335  *
336  * Since: 0.10.22
337  */
338 #define GST_READ_UINT24_BE(data)        (_GST_GET (data, 0, 32, 16) | \
339                                          _GST_GET (data, 1, 32,  8) | \
340                                          _GST_GET (data, 2, 32,  0))
341
342 /**
343  * GST_READ_UINT24_LE:
344  * @data: memory location
345  *
346  * Read a 24 bit unsigned integer value in little endian format from the memory buffer.
347  *
348  * Since: 0.10.22
349  */
350 #define GST_READ_UINT24_LE(data)        (_GST_GET (data, 2, 32, 16) | \
351                                          _GST_GET (data, 1, 32,  8) | \
352                                          _GST_GET (data, 0, 32,  0))
353
354 /**
355  * GST_READ_UINT16_BE:
356  * @data: memory location
357  *
358  * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
359  */
360 #define GST_READ_UINT16_BE(data)        (_GST_GET (data, 0, 16,  8) | \
361                                          _GST_GET (data, 1, 16,  0))
362
363 /**
364  * GST_READ_UINT16_LE:
365  * @data: memory location
366  *
367  * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
368  */
369 #define GST_READ_UINT16_LE(data)        (_GST_GET (data, 1, 16,  8) | \
370                                          _GST_GET (data, 0, 16,  0))
371
372 /**
373  * GST_READ_UINT8:
374  * @data: memory location
375  *
376  * Read an 8 bit unsigned integer value from the memory buffer.
377  */
378 #define GST_READ_UINT8(data)            (_GST_GET (data, 0,  8,  0))
379
380 /**
381  * GST_WRITE_UINT64_BE:
382  * @data: memory location
383  * @num: value to store
384  *
385  * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
386  */
387 #define GST_WRITE_UINT64_BE(data, num)  do { \
388                                           _GST_PUT (data, 0, 64, 56, num); \
389                                           _GST_PUT (data, 1, 64, 48, num); \
390                                           _GST_PUT (data, 2, 64, 40, num); \
391                                           _GST_PUT (data, 3, 64, 32, num); \
392                                           _GST_PUT (data, 4, 64, 24, num); \
393                                           _GST_PUT (data, 5, 64, 16, num); \
394                                           _GST_PUT (data, 6, 64,  8, num); \
395                                           _GST_PUT (data, 7, 64,  0, num); \
396                                         } while (0)
397
398 /**
399  * GST_WRITE_UINT64_LE:
400  * @data: memory location
401  * @num: value to store
402  *
403  * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
404  */
405 #define GST_WRITE_UINT64_LE(data, num)  do { \
406                                           _GST_PUT (data, 0, 64,  0, num); \
407                                           _GST_PUT (data, 1, 64,  8, num); \
408                                           _GST_PUT (data, 2, 64, 16, num); \
409                                           _GST_PUT (data, 3, 64, 24, num); \
410                                           _GST_PUT (data, 4, 64, 32, num); \
411                                           _GST_PUT (data, 5, 64, 40, num); \
412                                           _GST_PUT (data, 6, 64, 48, num); \
413                                           _GST_PUT (data, 7, 64, 56, num); \
414                                         } while (0)
415
416 /**
417  * GST_WRITE_UINT32_BE:
418  * @data: memory location
419  * @num: value to store
420  *
421  * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
422  */
423 #define GST_WRITE_UINT32_BE(data, num)  do { \
424                                           _GST_PUT (data, 0, 32, 24, num); \
425                                           _GST_PUT (data, 1, 32, 16, num); \
426                                           _GST_PUT (data, 2, 32,  8, num); \
427                                           _GST_PUT (data, 3, 32,  0, num); \
428                                         } while (0)
429
430 /**
431  * GST_WRITE_UINT32_LE:
432  * @data: memory location
433  * @num: value to store
434  *
435  * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
436  */
437 #define GST_WRITE_UINT32_LE(data, num)  do { \
438                                           _GST_PUT (data, 0, 32,  0, num); \
439                                           _GST_PUT (data, 1, 32,  8, num); \
440                                           _GST_PUT (data, 2, 32, 16, num); \
441                                           _GST_PUT (data, 3, 32, 24, num); \
442                                         } while (0)
443
444 /**
445  * GST_WRITE_UINT24_BE:
446  * @data: memory location
447  * @num: value to store
448  *
449  * Store a 24 bit unsigned integer value in big endian format into the memory buffer.
450  *
451  * Since: 0.10.22
452  */
453 #define GST_WRITE_UINT24_BE(data, num)  do { \
454                                           _GST_PUT (data, 0, 32,  16, num); \
455                                           _GST_PUT (data, 1, 32,  8, num); \
456                                           _GST_PUT (data, 2, 32,  0, num); \
457                                         } while (0)
458
459 /**
460  * GST_WRITE_UINT24_LE:
461  * @data: memory location
462  * @num: value to store
463  *
464  * Store a 24 bit unsigned integer value in little endian format into the memory buffer.
465  *
466  * Since: 0.10.22
467  */
468 #define GST_WRITE_UINT24_LE(data, num)  do { \
469                                           _GST_PUT (data, 0, 32,  0, num); \
470                                           _GST_PUT (data, 1, 32,  8, num); \
471                                           _GST_PUT (data, 2, 32,  16, num); \
472                                         } while (0)
473
474 /**
475  * GST_WRITE_UINT16_BE:
476  * @data: memory location
477  * @num: value to store
478  *
479  * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
480  */
481 #define GST_WRITE_UINT16_BE(data, num)  do { \
482                                           _GST_PUT (data, 0, 16,  8, num); \
483                                           _GST_PUT (data, 1, 16,  0, num); \
484                                         } while (0)
485
486 /**
487  * GST_WRITE_UINT16_LE:
488  * @data: memory location
489  * @num: value to store
490  *
491  * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
492  */
493 #define GST_WRITE_UINT16_LE(data, num)  do { \
494                                           _GST_PUT (data, 0, 16,  0, num); \
495                                           _GST_PUT (data, 1, 16,  8, num); \
496                                         } while (0)
497
498 /**
499  * GST_WRITE_UINT8:
500  * @data: memory location
501  * @num: value to store
502  *
503  * Store an 8 bit unsigned integer value into the memory buffer.
504  */
505 #define GST_WRITE_UINT8(data, num)      do { \
506                                           _GST_PUT (data, 0,  8,  0, num); \
507                                         } while (0)
508
509 /* Float endianess conversion macros */
510
511 /* FIXME: Remove this once we depend on a GLib version with this */
512 #ifndef GFLOAT_FROM_LE
513 /**
514  * GFLOAT_SWAP_LE_BE:
515  * @in: input value
516  *
517  * Swap byte order of a 32-bit floating point value (float).
518  *
519  * Returns: @in byte-swapped.
520  *
521  * Since: 0.10.22
522  *
523  */
524 #ifdef _FOOL_GTK_DOC_
525 G_INLINE_FUNC gfloat GFLOAT_SWAP_LE_BE (gfloat in);
526 #endif
527
528 inline static gfloat
529 GFLOAT_SWAP_LE_BE(gfloat in)
530 {
531   union
532   {
533     guint32 i;
534     gfloat f;
535   } u;
536
537   u.f = in;
538   u.i = GUINT32_SWAP_LE_BE (u.i);
539   return u.f;
540 }
541
542 /**
543  * GDOUBLE_SWAP_LE_BE:
544  * @in: input value
545  *
546  * Swap byte order of a 64-bit floating point value (double).
547  *
548  * Returns: @in byte-swapped.
549  *
550  * Since: 0.10.22
551  *
552  */
553 #ifdef _FOOL_GTK_DOC_
554 G_INLINE_FUNC gdouble GDOUBLE_SWAP_LE_BE (gdouble in);
555 #endif
556
557 inline static gdouble
558 GDOUBLE_SWAP_LE_BE(gdouble in)
559 {
560   union
561   {
562     guint64 i;
563     gdouble d;
564   } u;
565
566   u.d = in;
567   u.i = GUINT64_SWAP_LE_BE (u.i);
568   return u.d;
569 }
570
571 /**
572  * GDOUBLE_TO_LE:
573  * @val: value
574  *
575  * Convert 64-bit floating point value (double) from native byte order into
576  * little endian byte order.
577  *
578  * Since: 0.10.22
579  *
580  */
581 /**
582  * GDOUBLE_TO_BE:
583  * @val: value
584  *
585  * Convert 64-bit floating point value (double) from native byte order into
586  * big endian byte order.
587  *
588  * Since: 0.10.22
589  *
590  */
591 /**
592  * GDOUBLE_FROM_LE:
593  * @val: value
594  *
595  * Convert 64-bit floating point value (double) from little endian byte order
596  * into native byte order.
597  *
598  * Since: 0.10.22
599  *
600  */
601 /**
602  * GDOUBLE_FROM_BE:
603  * @val: value
604  *
605  * Convert 64-bit floating point value (double) from big endian byte order
606  * into native byte order.
607  *
608  * Since: 0.10.22
609  *
610  */
611
612 /**
613  * GFLOAT_TO_LE:
614  * @val: value
615  *
616  * Convert 32-bit floating point value (float) from native byte order into
617  * little endian byte order.
618  *
619  * Since: 0.10.22
620  *
621  */
622 /**
623  * GFLOAT_TO_BE:
624  * @val: value
625  *
626  * Convert 32-bit floating point value (float) from native byte order into
627  * big endian byte order.
628  *
629  * Since: 0.10.22
630  *
631  */
632 /**
633  * GFLOAT_FROM_LE:
634  * @val: value
635  *
636  * Convert 32-bit floating point value (float) from little endian byte order
637  * into native byte order.
638  *
639  * Since: 0.10.22
640  *
641  */
642 /**
643  * GFLOAT_FROM_BE:
644  * @val: value
645  *
646  * Convert 32-bit floating point value (float) from big endian byte order
647  * into native byte order.
648  *
649  * Since: 0.10.22
650  *
651  */
652
653 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
654 #define GFLOAT_TO_LE(val)    ((gfloat) (val))
655 #define GFLOAT_TO_BE(val)    (GFLOAT_SWAP_LE_BE (val))
656 #define GDOUBLE_TO_LE(val)   ((gdouble) (val))
657 #define GDOUBLE_TO_BE(val)   (GDOUBLE_SWAP_LE_BE (val))
658
659 #elif G_BYTE_ORDER == G_BIG_ENDIAN
660 #define GFLOAT_TO_LE(val)    (GFLOAT_SWAP_LE_BE (val))
661 #define GFLOAT_TO_BE(val)    ((gfloat) (val))
662 #define GDOUBLE_TO_LE(val)   (GDOUBLE_SWAP_LE_BE (val))
663 #define GDOUBLE_TO_BE(val)   ((gdouble) (val))
664
665 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
666 #error unknown ENDIAN type
667 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
668
669 #define GFLOAT_FROM_LE(val)  (GFLOAT_TO_LE (val))
670 #define GFLOAT_FROM_BE(val)  (GFLOAT_TO_BE (val))
671 #define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val))
672 #define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
673
674 #endif /* !defined(GFLOAT_FROM_LE) */
675
676 /**
677  * GST_READ_FLOAT_LE:
678  * @data: memory location
679  *
680  * Read a 32 bit float value in little endian format from the memory buffer.
681  *
682  * Returns: The floating point value read from @data
683  *
684  * Since: 0.10.22
685  *
686  */
687 #ifdef _FOOL_GTK_DOC_
688 G_INLINE_FUNC gfloat GST_READ_FLOAT_LE (const guint8 *data);
689 #endif
690
691 inline static gfloat
692 GST_READ_FLOAT_LE(const guint8 *data)
693 {
694   union
695   {
696     guint32 i;
697     gfloat f;
698   } u;
699
700   u.i = GST_READ_UINT32_LE (data);
701   return u.f;
702 }
703
704 /**
705  * GST_READ_FLOAT_BE:
706  * @data: memory location
707  *
708  * Read a 32 bit float value in big endian format from the memory buffer.
709  *
710  * Returns: The floating point value read from @data
711  *
712  * Since: 0.10.22
713  *
714  */
715 #ifdef _FOOL_GTK_DOC_
716 G_INLINE_FUNC gfloat GST_READ_FLOAT_BE (const guint8 *data);
717 #endif
718
719 inline static gfloat
720 GST_READ_FLOAT_BE(const guint8 *data)
721 {
722   union
723   {
724     guint32 i;
725     gfloat f;
726   } u;
727
728   u.i = GST_READ_UINT32_BE (data);
729   return u.f;
730 }
731
732 /**
733  * GST_READ_DOUBLE_LE:
734  * @data: memory location
735  *
736  * Read a 64 bit double value in little endian format from the memory buffer.
737  *
738  * Returns: The double-precision floating point value read from @data
739  *
740  * Since: 0.10.22
741  *
742  */
743 #ifdef _FOOL_GTK_DOC_
744 G_INLINE_FUNC gdouble GST_READ_DOUBLE_LE (const guint8 *data);
745 #endif
746
747 inline static gdouble
748 GST_READ_DOUBLE_LE(const guint8 *data)
749 {
750   union
751   {
752     guint64 i;
753     gdouble d;
754   } u;
755
756   u.i = GST_READ_UINT64_LE (data);
757   return u.d;
758 }
759
760 /**
761  * GST_READ_DOUBLE_BE:
762  * @data: memory location
763  *
764  * Read a 64 bit double value in big endian format from the memory buffer.
765  *
766  * Returns: The double-precision floating point value read from @data
767  *
768  * Since: 0.10.22
769  *
770  */
771 #ifdef _FOOL_GTK_DOC_
772 G_INLINE_FUNC gdouble GST_READ_DOUBLE_BE (const guint8 *data);
773 #endif
774
775 inline static gdouble
776 GST_READ_DOUBLE_BE(const guint8 *data)
777 {
778   union
779   {
780     guint64 i;
781     gdouble d;
782   } u;
783
784   u.i = GST_READ_UINT64_BE (data);
785   return u.d;
786 }
787
788 /**
789  * GST_WRITE_FLOAT_LE:
790  * @data: memory location
791  * @num: value to store
792  *
793  * Store a 32 bit float value in little endian format into the memory buffer.
794  *
795  * Since: 0.10.22
796  *
797  */
798 #ifdef _FOOL_GTK_DOC_
799 G_INLINE_FUNC void GST_WRITE_FLOAT_LE (guint8 *data, gfloat num);
800 #endif
801
802 inline static void
803 GST_WRITE_FLOAT_LE(guint8 *data, gfloat num)
804 {
805   union
806   {
807     guint32 i;
808     gfloat f;
809   } u;
810
811   u.f = num;
812   GST_WRITE_UINT32_LE (data, u.i);
813 }
814
815 /**
816  * GST_WRITE_FLOAT_BE:
817  * @data: memory location
818  * @num: value to store
819  *
820  * Store a 32 bit float value in big endian format into the memory buffer.
821  *
822  * Since: 0.10.22
823  *
824  */
825 #ifdef _FOOL_GTK_DOC_
826 G_INLINE_FUNC void GST_WRITE_FLOAT_BE (guint8 *data, gfloat num);
827 #endif
828
829 inline static void
830 GST_WRITE_FLOAT_BE(guint8 *data, gfloat num)
831 {
832   union
833   {
834     guint32 i;
835     gfloat f;
836   } u;
837
838   u.f = num;
839   GST_WRITE_UINT32_BE (data, u.i);
840 }
841
842 /**
843  * GST_WRITE_DOUBLE_LE:
844  * @data: memory location
845  * @num: value to store
846  *
847  * Store a 64 bit double value in little endian format into the memory buffer.
848  *
849  * Since: 0.10.22
850  *
851  */
852 #ifdef _FOOL_GTK_DOC_
853 G_INLINE_FUNC void GST_WRITE_DOUBLE_LE (guint8 *data, gdouble num);
854 #endif
855
856 inline static void
857 GST_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
858 {
859   union
860   {
861     guint64 i;
862     gdouble d;
863   } u;
864
865   u.d = num;
866   GST_WRITE_UINT64_LE (data, u.i);
867 }
868
869 /**
870  * GST_WRITE_DOUBLE_BE:
871  * @data: memory location
872  * @num: value to store
873  *
874  * Store a 64 bit double value in big endian format into the memory buffer.
875  *
876  * Since: 0.10.22
877  *
878  */
879 #ifdef _FOOL_GTK_DOC_
880 G_INLINE_FUNC void GST_WRITE_DOUBLE_BE (guint8 *data, gdouble num);
881 #endif
882
883 inline static void
884 GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
885 {
886   union
887   {
888     guint64 i;
889     gdouble d;
890   } u;
891
892   u.d = num;
893   GST_WRITE_UINT64_BE (data, u.i);
894 }
895
896 /* Miscellaneous utility macros */
897
898 /**
899  * GST_ROUND_UP_2:
900  * @num: integer value to round up
901  *
902  * Rounds an integer value up to the next multiple of 2.
903  */
904 #define GST_ROUND_UP_2(num)  (((num)+1)&~1)
905 /**
906  * GST_ROUND_UP_4:
907  * @num: integer value to round up
908  *
909  * Rounds an integer value up to the next multiple of 4.
910  */
911 #define GST_ROUND_UP_4(num)  (((num)+3)&~3)
912 /**
913  * GST_ROUND_UP_8:
914  * @num: integer value to round up
915  *
916  * Rounds an integer value up to the next multiple of 8.
917  */
918 #define GST_ROUND_UP_8(num)  (((num)+7)&~7)
919 /**
920  * GST_ROUND_UP_16:
921  * @num: integer value to round up
922  *
923  * Rounds an integer value up to the next multiple of 16.
924  */
925 #define GST_ROUND_UP_16(num) (((num)+15)&~15)
926 /**
927  * GST_ROUND_UP_32:
928  * @num: integer value to round up
929  *
930  * Rounds an integer value up to the next multiple of 32.
931  */
932 #define GST_ROUND_UP_32(num) (((num)+31)&~31)
933 /**
934  * GST_ROUND_UP_64:
935  * @num: integer value to round up
936  *
937  * Rounds an integer value up to the next multiple of 64.
938  */
939 #define GST_ROUND_UP_64(num) (((num)+63)&~63)
940
941 /**
942  * GST_ROUND_DOWN_2:
943  * @num: integer value to round down
944  *
945  * Rounds an integer value down to the next multiple of 2.
946  *
947  * Since: 0.10.12
948  */
949 #define GST_ROUND_DOWN_2(num)  ((num)&(~1))
950 /**
951  * GST_ROUND_DOWN_4:
952  * @num: integer value to round down
953  *
954  * Rounds an integer value down to the next multiple of 4.
955  *
956  * Since: 0.10.12
957  */
958 #define GST_ROUND_DOWN_4(num)  ((num)&(~3))
959 /**
960  * GST_ROUND_DOWN_8:
961  * @num: integer value to round down
962  *
963  * Rounds an integer value down to the next multiple of 8.
964  *
965  * Since: 0.10.12
966  */
967 #define GST_ROUND_DOWN_8(num)  ((num)&(~7))
968 /**
969  * GST_ROUND_DOWN_16:
970  * @num: integer value to round down
971  *
972  * Rounds an integer value down to the next multiple of 16.
973  *
974  * Since: 0.10.12
975  */
976 #define GST_ROUND_DOWN_16(num) ((num)&(~15))
977 /**
978  * GST_ROUND_DOWN_32:
979  * @num: integer value to round down
980  *
981  * Rounds an integer value down to the next multiple of 32.
982  *
983  * Since: 0.10.12
984  */
985 #define GST_ROUND_DOWN_32(num) ((num)&(~31))
986 /**
987  * GST_ROUND_DOWN_64:
988  * @num: integer value to round down
989  *
990  * Rounds an integer value down to the next multiple of 64.
991  *
992  * Since: 0.10.12
993  */
994 #define GST_ROUND_DOWN_64(num) ((num)&(~63))
995
996 void                    gst_object_default_error        (GstObject * source,
997                                                          GError * error, gchar * debug);
998
999 /* element functions */
1000 void                    gst_element_create_all_pads     (GstElement *element);
1001 GstPad*                 gst_element_get_compatible_pad  (GstElement *element, GstPad *pad,
1002                                                          const GstCaps *caps);
1003
1004 GstPadTemplate*         gst_element_get_compatible_pad_template (GstElement *element, GstPadTemplate *compattempl);
1005
1006 G_CONST_RETURN gchar*   gst_element_state_get_name      (GstState state);
1007 G_CONST_RETURN gchar *  gst_element_state_change_return_get_name (GstStateChangeReturn state_ret);
1008
1009 gboolean                gst_element_link                (GstElement *src, GstElement *dest);
1010 gboolean                gst_element_link_many           (GstElement *element_1,
1011                                                          GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
1012 gboolean                gst_element_link_filtered       (GstElement * src,
1013                                                          GstElement * dest,
1014                                                          GstCaps *filter);
1015 void                    gst_element_unlink              (GstElement *src, GstElement *dest);
1016 void                    gst_element_unlink_many         (GstElement *element_1,
1017                                                          GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
1018
1019 gboolean                gst_element_link_pads           (GstElement *src, const gchar *srcpadname,
1020                                                          GstElement *dest, const gchar *destpadname);
1021 gboolean                gst_element_link_pads_full      (GstElement *src, const gchar *srcpadname,
1022                                                          GstElement *dest, const gchar *destpadname,
1023                                                          GstPadLinkCheck flags);
1024 void                    gst_element_unlink_pads         (GstElement *src, const gchar *srcpadname,
1025                                                          GstElement *dest, const gchar *destpadname);
1026
1027 gboolean                gst_element_link_pads_filtered  (GstElement * src, const gchar * srcpadname,
1028                                                          GstElement * dest, const gchar * destpadname,
1029                                                          GstCaps *filter);
1030
1031 gboolean                gst_element_seek_simple         (GstElement   *element,
1032                                                          GstFormat     format,
1033                                                          GstSeekFlags  seek_flags,
1034                                                          gint64        seek_pos);
1035
1036 /* util elementfactory functions */
1037 gboolean                gst_element_factory_can_src_caps(GstElementFactory *factory, const GstCaps *caps);
1038 gboolean                gst_element_factory_can_sink_caps(GstElementFactory *factory, const GstCaps *caps);
1039
1040 /* util query functions */
1041 gboolean                gst_element_query_position      (GstElement *element, GstFormat *format,
1042                                                          gint64 *cur);
1043 gboolean                gst_element_query_duration      (GstElement *element, GstFormat *format,
1044                                                          gint64 *duration);
1045 gboolean                gst_element_query_convert       (GstElement *element, GstFormat src_format, gint64 src_val,
1046                                                          GstFormat *dest_format, gint64 *dest_val);
1047
1048 /* element class functions */
1049 void                    gst_element_class_install_std_props (GstElementClass * klass,
1050                                                          const gchar * first_name, ...) G_GNUC_NULL_TERMINATED;
1051
1052 /* pad functions */
1053 void                    gst_pad_use_fixed_caps          (GstPad *pad);
1054 GstCaps*                gst_pad_get_fixed_caps_func     (GstPad *pad);
1055 GstCaps*                gst_pad_proxy_getcaps           (GstPad * pad);
1056 gboolean                gst_pad_proxy_setcaps           (GstPad * pad, GstCaps * caps);
1057
1058 GstElement*             gst_pad_get_parent_element      (GstPad *pad);
1059
1060 /* util query functions */
1061 gboolean                gst_pad_query_position          (GstPad *pad, GstFormat *format,
1062                                                          gint64 *cur);
1063 gboolean                gst_pad_query_duration          (GstPad *pad, GstFormat *format,
1064                                                          gint64 *duration);
1065 gboolean                gst_pad_query_convert           (GstPad *pad, GstFormat src_format, gint64 src_val,
1066                                                          GstFormat *dest_format, gint64 *dest_val);
1067
1068 gboolean                gst_pad_query_peer_position     (GstPad *pad, GstFormat *format,
1069                                                          gint64 *cur);
1070 gboolean                gst_pad_query_peer_duration     (GstPad *pad, GstFormat *format,
1071                                                          gint64 *duration);
1072 gboolean                gst_pad_query_peer_convert      (GstPad *pad, GstFormat src_format, gint64 src_val,
1073                                                          GstFormat *dest_format, gint64 *dest_val);
1074
1075 /* bin functions */
1076 void                    gst_bin_add_many                (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
1077 void                    gst_bin_remove_many             (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
1078 GstPad *                gst_bin_find_unlinked_pad       (GstBin *bin, GstPadDirection direction);
1079 #ifndef GST_DISABLE_DEPRECATED
1080 GstPad *                gst_bin_find_unconnected_pad    (GstBin *bin, GstPadDirection direction);
1081 #endif
1082
1083 /* buffer functions */
1084 GstBuffer *             gst_buffer_merge                (GstBuffer * buf1, GstBuffer * buf2);
1085 GstBuffer *             gst_buffer_join                 (GstBuffer * buf1, GstBuffer * buf2);
1086 #ifndef GST_DISABLE_DEPRECATED
1087 void                    gst_buffer_stamp                (GstBuffer * dest, const GstBuffer * src);
1088 #endif /* GST_DISABLE_DEPRECATED */
1089
1090 /* atomic functions */
1091 #ifndef GST_DISABLE_DEPRECATED
1092 void                    gst_atomic_int_set              (gint * atomic_int, gint value);
1093 #endif
1094
1095 /* probes */
1096 gulong                  gst_pad_add_data_probe          (GstPad   * pad,
1097                                                          GCallback  handler,
1098                                                          gpointer   data);
1099
1100 gulong                  gst_pad_add_data_probe_full     (GstPad       * pad,
1101                                                          GCallback      handler,
1102                                                          gpointer       data,
1103                                                          GDestroyNotify notify);
1104
1105 void                    gst_pad_remove_data_probe       (GstPad * pad, guint handler_id);
1106
1107 gulong                  gst_pad_add_event_probe         (GstPad   * pad,
1108                                                          GCallback  handler,
1109                                                          gpointer   data);
1110
1111 gulong                  gst_pad_add_event_probe_full    (GstPad       * pad,
1112                                                          GCallback      handler,
1113                                                          gpointer       data,
1114                                                          GDestroyNotify notify);
1115
1116 void                    gst_pad_remove_event_probe      (GstPad * pad, guint handler_id);
1117
1118 gulong                  gst_pad_add_buffer_probe        (GstPad   * pad,
1119                                                          GCallback  handler,
1120                                                          gpointer   data);
1121
1122 gulong                  gst_pad_add_buffer_probe_full   (GstPad       * pad,
1123                                                          GCallback      handler,
1124                                                          gpointer       data,
1125                                                          GDestroyNotify notify);
1126
1127 void                    gst_pad_remove_buffer_probe     (GstPad * pad, guint handler_id);
1128
1129 /* tag emission utility functions */
1130 void                    gst_element_found_tags_for_pad  (GstElement * element,
1131                                                          GstPad * pad,
1132                                                          GstTagList * list);
1133 void                    gst_element_found_tags          (GstElement * element,
1134                                                          GstTagList * list);
1135
1136 /* parse utility functions */
1137 GstElement *            gst_parse_bin_from_description      (const gchar     * bin_description,
1138                                                              gboolean          ghost_unlinked_pads,
1139                                                              GError         ** err);
1140
1141 GstElement *            gst_parse_bin_from_description_full (const gchar     * bin_description,
1142                                                              gboolean          ghost_unlinked_pads,
1143                                                              GstParseContext * context,
1144                                                              GstParseFlags     flags,
1145                                                              GError         ** err);
1146
1147 GstClockTime            gst_util_get_timestamp          (void);
1148
1149 /**
1150  * GstSearchMode:
1151  * @GST_SEARCH_MODE_EXACT : Only search for exact matches.
1152  * @GST_SEARCH_MODE_BEFORE: Search for an exact match or the element just before.
1153  * @GST_SEARCH_MODE_AFTER : Search for an exact match or the element just after.
1154  *
1155  * The different search modes.
1156  *
1157  * Since: 0.10.23
1158  */
1159 typedef enum {
1160   GST_SEARCH_MODE_EXACT = 0,
1161   GST_SEARCH_MODE_BEFORE,
1162   GST_SEARCH_MODE_AFTER
1163 } GstSearchMode;
1164
1165 gpointer                gst_util_array_binary_search      (gpointer array, guint num_elements,
1166                                                            gsize element_size, GCompareDataFunc search_func,
1167                                                            GstSearchMode mode, gconstpointer search_data,
1168                                                            gpointer user_data);
1169
1170 gint gst_util_greatest_common_divisor (gint a, gint b);
1171 void gst_util_fraction_to_double (gint src_n, gint src_d, gdouble *dest);
1172 void gst_util_double_to_fraction (gdouble src, gint *dest_n, gint *dest_d);
1173 gboolean gst_util_fraction_multiply (gint a_n, gint a_d, gint b_n, gint b_d, gint *res_n, gint *res_d);
1174 gboolean gst_util_fraction_add (gint a_n, gint a_d, gint b_n, gint b_d, gint *res_n, gint *res_d);
1175
1176
1177 /* sink message event
1178  *
1179  * FIXME: This should be in gstevent.h but can't because
1180  * it needs GstMessage and this would introduce circular
1181  * header includes. And forward declarations of typedefs
1182  * are unfortunately not possible. The implementation of
1183  * these functions is in gstevent.c.
1184  */
1185 GstEvent*       gst_event_new_sink_message      (GstMessage *msg);
1186 void            gst_event_parse_sink_message    (GstEvent *event, GstMessage **msg);
1187
1188
1189 G_END_DECLS
1190
1191 #endif /* __GST_UTILS_H__ */