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>
6 * gstutils.h: Header for various utility functions
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.
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.
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.
25 #ifndef __GST_UTILS_H__
26 #define __GST_UTILS_H__
29 #include <gst/gstbin.h>
30 #include <gst/gstparse.h>
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);
38 guint64 gst_util_gdouble_to_guint64 (gdouble value) G_GNUC_CONST;
39 gdouble gst_util_guint64_to_gdouble (guint64 value) G_GNUC_CONST;
42 * gst_guint64_to_gdouble:
43 * @value: the #guint64 value to convert
45 * Convert @value to a gdouble.
47 * Returns: @value converted to a #gdouble.
51 * gst_gdouble_to_guint64:
52 * @value: the #gdouble value to convert
54 * Convert @value to a guint64.
56 * Returns: @value converted to a #guint64.
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)
62 #define gst_gdouble_to_guint64(value) ((guint64) (value))
63 #define gst_guint64_to_gdouble(value) ((gdouble) (value))
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);
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);
74 guint32 gst_util_seqnum_next (void);
75 gint32 gst_util_seqnum_compare (guint32 s1, guint32 s2);
77 void gst_print_pad_caps (GString *buf, gint indent, GstPad *pad);
78 void gst_print_element_args (GString *buf, gint indent, GstElement *element);
81 GType gst_type_register_static_full (GType parent_type,
82 const gchar *type_name,
84 GBaseInitFunc base_init,
85 GBaseFinalizeFunc base_finalize,
86 GClassInitFunc class_init,
87 GClassFinalizeFunc class_finalize,
88 gconstpointer class_data,
91 GInstanceInitFunc instance_init,
92 const GTypeValueTable *value_table,
96 /* Macros for defining classes. Ideas taken from Bonobo, which took theirs
97 from Nautilus and GOB. */
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
109 * Define the boilerplate type stuff to reduce typos and code size. Defines
110 * the get_type method and the parent_class static variable.
114 * GST_BOILERPLATE_FULL (GstFdSink, gst_fdsink, GstElement, GST_TYPE_ELEMENT, _do_init);
118 #define GST_BOILERPLATE_FULL(type, type_as_function, parent_type, parent_type_macro, additional_initializations) \
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; \
126 type_as_function ## _class_init_trampoline (gpointer g_class, \
129 parent_class = (parent_type ## Class *) \
130 g_type_class_peek_parent (g_class); \
131 type_as_function ## _class_init ((type ## Class *)g_class); \
135 type_as_function ## _get_type (void) \
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)) { \
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 */ \
152 0, /* n_preallocs */ \
153 (GInstanceInitFunc) type_as_function ## _init, \
156 additional_initializations (_type); \
157 g_once_init_leave (&gonce_data, (gsize) _type); \
159 return (GType) gonce_data; \
162 #define __GST_DO_NOTHING(type) /* NOP */
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
171 * Define the boilerplate type stuff to reduce typos and code size. Defines
172 * the get_type method and the parent_class static variable.
176 * GST_BOILERPLATE (GstFdSink, gst_fdsink, GstElement, GST_TYPE_ELEMENT);
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, \
184 /* Like GST_BOILERPLATE, but makes the type 1) implement an interface, and 2)
185 * implement GstImplementsInterface for that type
187 * After this you will need to implement interface_as_function ## _supported
188 * and interface_as_function ## _interface_init
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
200 * Like GST_BOILERPLATE, but makes the type 1) implement an interface, and 2)
201 * implement GstImplementsInterface for that type.
203 * After this you will need to implement interface_as_function ## _supported
204 * and interface_as_function ## _interface_init
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) \
210 static void interface_as_function ## _interface_init (interface_type ## Class *klass); \
211 static gboolean interface_as_function ## _supported (type *object, GType iface_type); \
214 type_as_function ## _implements_interface_init (GstImplementsInterfaceClass *klass) \
216 klass->supported = (gboolean (*)(GstImplementsInterface*, GType))interface_as_function ## _supported; \
220 type_as_function ## _init_interfaces (GType type) \
222 static const GInterfaceInfo implements_iface_info = { \
223 (GInterfaceInitFunc) type_as_function ## _implements_interface_init,\
227 static const GInterfaceInfo iface_info = { \
228 (GInterfaceInitFunc) interface_as_function ## _interface_init, \
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, \
239 GST_BOILERPLATE_FULL (type, type_as_function, parent_type, \
240 parent_type_as_macro, type_as_function ## _init_interfaces)
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 '( )'
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
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)
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
264 * Same as GST_CALL_PARENT(), but in case there is no implementation, it
265 * evaluates to @def_return.
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)
271 /* Define PUT and GET functions for unaligned memory */
272 #define _GST_GET(__data, __idx, __size, __shift) \
273 (((guint##__size) (((guint8 *) (__data))[__idx])) << (__shift))
275 #define _GST_PUT(__data, __idx, __size, __shift, __num) \
276 (((guint8 *) (__data))[__idx] = (((guint##__size) (__num)) >> (__shift)) & 0xff)
279 * GST_READ_UINT64_BE:
280 * @data: memory location
282 * Read a 64 bit unsigned integer value in big endian format from the memory buffer.
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))
294 * GST_READ_UINT64_LE:
295 * @data: memory location
297 * Read a 64 bit unsigned integer value in little endian format from the memory buffer.
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))
309 * GST_READ_UINT32_BE:
310 * @data: memory location
312 * Read a 32 bit unsigned integer value in big endian format from the memory buffer.
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))
320 * GST_READ_UINT32_LE:
321 * @data: memory location
323 * Read a 32 bit unsigned integer value in little endian format from the memory buffer.
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))
331 * GST_READ_UINT24_BE:
332 * @data: memory location
334 * Read a 24 bit unsigned integer value in big endian format from the memory buffer.
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))
343 * GST_READ_UINT24_LE:
344 * @data: memory location
346 * Read a 24 bit unsigned integer value in little endian format from the memory buffer.
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))
355 * GST_READ_UINT16_BE:
356 * @data: memory location
358 * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
360 #define GST_READ_UINT16_BE(data) (_GST_GET (data, 0, 16, 8) | \
361 _GST_GET (data, 1, 16, 0))
364 * GST_READ_UINT16_LE:
365 * @data: memory location
367 * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
369 #define GST_READ_UINT16_LE(data) (_GST_GET (data, 1, 16, 8) | \
370 _GST_GET (data, 0, 16, 0))
374 * @data: memory location
376 * Read an 8 bit unsigned integer value from the memory buffer.
378 #define GST_READ_UINT8(data) (_GST_GET (data, 0, 8, 0))
381 * GST_WRITE_UINT64_BE:
382 * @data: memory location
383 * @num: value to store
385 * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
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); \
399 * GST_WRITE_UINT64_LE:
400 * @data: memory location
401 * @num: value to store
403 * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
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); \
417 * GST_WRITE_UINT32_BE:
418 * @data: memory location
419 * @num: value to store
421 * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
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); \
431 * GST_WRITE_UINT32_LE:
432 * @data: memory location
433 * @num: value to store
435 * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
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); \
445 * GST_WRITE_UINT24_BE:
446 * @data: memory location
447 * @num: value to store
449 * Store a 24 bit unsigned integer value in big endian format into the memory buffer.
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); \
460 * GST_WRITE_UINT24_LE:
461 * @data: memory location
462 * @num: value to store
464 * Store a 24 bit unsigned integer value in little endian format into the memory buffer.
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); \
475 * GST_WRITE_UINT16_BE:
476 * @data: memory location
477 * @num: value to store
479 * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
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); \
487 * GST_WRITE_UINT16_LE:
488 * @data: memory location
489 * @num: value to store
491 * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
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); \
500 * @data: memory location
501 * @num: value to store
503 * Store an 8 bit unsigned integer value into the memory buffer.
505 #define GST_WRITE_UINT8(data, num) do { \
506 _GST_PUT (data, 0, 8, 0, num); \
509 /* Float endianess conversion macros */
511 /* FIXME: Remove this once we depend on a GLib version with this */
512 #ifndef GFLOAT_FROM_LE
517 * Swap byte order of a 32-bit floating point value (float).
519 * Returns: @in byte-swapped.
524 #ifdef _FOOL_GTK_DOC_
525 G_INLINE_FUNC gfloat GFLOAT_SWAP_LE_BE (gfloat in);
529 GFLOAT_SWAP_LE_BE(gfloat in)
538 u.i = GUINT32_SWAP_LE_BE (u.i);
543 * GDOUBLE_SWAP_LE_BE:
546 * Swap byte order of a 64-bit floating point value (double).
548 * Returns: @in byte-swapped.
553 #ifdef _FOOL_GTK_DOC_
554 G_INLINE_FUNC gdouble GDOUBLE_SWAP_LE_BE (gdouble in);
557 inline static gdouble
558 GDOUBLE_SWAP_LE_BE(gdouble in)
567 u.i = GUINT64_SWAP_LE_BE (u.i);
575 * Convert 64-bit floating point value (double) from native byte order into
576 * little endian byte order.
585 * Convert 64-bit floating point value (double) from native byte order into
586 * big endian byte order.
595 * Convert 64-bit floating point value (double) from little endian byte order
596 * into native byte order.
605 * Convert 64-bit floating point value (double) from big endian byte order
606 * into native byte order.
616 * Convert 32-bit floating point value (float) from native byte order into
617 * little endian byte order.
626 * Convert 32-bit floating point value (float) from native byte order into
627 * big endian byte order.
636 * Convert 32-bit floating point value (float) from little endian byte order
637 * into native byte order.
646 * Convert 32-bit floating point value (float) from big endian byte order
647 * into native byte order.
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))
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))
665 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
666 #error unknown ENDIAN type
667 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
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))
674 #endif /* !defined(GFLOAT_FROM_LE) */
678 * @data: memory location
680 * Read a 32 bit float value in little endian format from the memory buffer.
682 * Returns: The floating point value read from @data
687 #ifdef _FOOL_GTK_DOC_
688 G_INLINE_FUNC gfloat GST_READ_FLOAT_LE (const guint8 *data);
692 GST_READ_FLOAT_LE(const guint8 *data)
700 u.i = GST_READ_UINT32_LE (data);
706 * @data: memory location
708 * Read a 32 bit float value in big endian format from the memory buffer.
710 * Returns: The floating point value read from @data
715 #ifdef _FOOL_GTK_DOC_
716 G_INLINE_FUNC gfloat GST_READ_FLOAT_BE (const guint8 *data);
720 GST_READ_FLOAT_BE(const guint8 *data)
728 u.i = GST_READ_UINT32_BE (data);
733 * GST_READ_DOUBLE_LE:
734 * @data: memory location
736 * Read a 64 bit double value in little endian format from the memory buffer.
738 * Returns: The double-precision floating point value read from @data
743 #ifdef _FOOL_GTK_DOC_
744 G_INLINE_FUNC gdouble GST_READ_DOUBLE_LE (const guint8 *data);
747 inline static gdouble
748 GST_READ_DOUBLE_LE(const guint8 *data)
756 u.i = GST_READ_UINT64_LE (data);
761 * GST_READ_DOUBLE_BE:
762 * @data: memory location
764 * Read a 64 bit double value in big endian format from the memory buffer.
766 * Returns: The double-precision floating point value read from @data
771 #ifdef _FOOL_GTK_DOC_
772 G_INLINE_FUNC gdouble GST_READ_DOUBLE_BE (const guint8 *data);
775 inline static gdouble
776 GST_READ_DOUBLE_BE(const guint8 *data)
784 u.i = GST_READ_UINT64_BE (data);
789 * GST_WRITE_FLOAT_LE:
790 * @data: memory location
791 * @num: value to store
793 * Store a 32 bit float value in little endian format into the memory buffer.
798 #ifdef _FOOL_GTK_DOC_
799 G_INLINE_FUNC void GST_WRITE_FLOAT_LE (guint8 *data, gfloat num);
803 GST_WRITE_FLOAT_LE(guint8 *data, gfloat num)
812 GST_WRITE_UINT32_LE (data, u.i);
816 * GST_WRITE_FLOAT_BE:
817 * @data: memory location
818 * @num: value to store
820 * Store a 32 bit float value in big endian format into the memory buffer.
825 #ifdef _FOOL_GTK_DOC_
826 G_INLINE_FUNC void GST_WRITE_FLOAT_BE (guint8 *data, gfloat num);
830 GST_WRITE_FLOAT_BE(guint8 *data, gfloat num)
839 GST_WRITE_UINT32_BE (data, u.i);
843 * GST_WRITE_DOUBLE_LE:
844 * @data: memory location
845 * @num: value to store
847 * Store a 64 bit double value in little endian format into the memory buffer.
852 #ifdef _FOOL_GTK_DOC_
853 G_INLINE_FUNC void GST_WRITE_DOUBLE_LE (guint8 *data, gdouble num);
857 GST_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
866 GST_WRITE_UINT64_LE (data, u.i);
870 * GST_WRITE_DOUBLE_BE:
871 * @data: memory location
872 * @num: value to store
874 * Store a 64 bit double value in big endian format into the memory buffer.
879 #ifdef _FOOL_GTK_DOC_
880 G_INLINE_FUNC void GST_WRITE_DOUBLE_BE (guint8 *data, gdouble num);
884 GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
893 GST_WRITE_UINT64_BE (data, u.i);
896 /* Miscellaneous utility macros */
900 * @num: integer value to round up
902 * Rounds an integer value up to the next multiple of 2.
904 #define GST_ROUND_UP_2(num) (((num)+1)&~1)
907 * @num: integer value to round up
909 * Rounds an integer value up to the next multiple of 4.
911 #define GST_ROUND_UP_4(num) (((num)+3)&~3)
914 * @num: integer value to round up
916 * Rounds an integer value up to the next multiple of 8.
918 #define GST_ROUND_UP_8(num) (((num)+7)&~7)
921 * @num: integer value to round up
923 * Rounds an integer value up to the next multiple of 16.
925 #define GST_ROUND_UP_16(num) (((num)+15)&~15)
928 * @num: integer value to round up
930 * Rounds an integer value up to the next multiple of 32.
932 #define GST_ROUND_UP_32(num) (((num)+31)&~31)
935 * @num: integer value to round up
937 * Rounds an integer value up to the next multiple of 64.
939 #define GST_ROUND_UP_64(num) (((num)+63)&~63)
943 * @num: integer value to round down
945 * Rounds an integer value down to the next multiple of 2.
949 #define GST_ROUND_DOWN_2(num) ((num)&(~1))
952 * @num: integer value to round down
954 * Rounds an integer value down to the next multiple of 4.
958 #define GST_ROUND_DOWN_4(num) ((num)&(~3))
961 * @num: integer value to round down
963 * Rounds an integer value down to the next multiple of 8.
967 #define GST_ROUND_DOWN_8(num) ((num)&(~7))
970 * @num: integer value to round down
972 * Rounds an integer value down to the next multiple of 16.
976 #define GST_ROUND_DOWN_16(num) ((num)&(~15))
979 * @num: integer value to round down
981 * Rounds an integer value down to the next multiple of 32.
985 #define GST_ROUND_DOWN_32(num) ((num)&(~31))
988 * @num: integer value to round down
990 * Rounds an integer value down to the next multiple of 64.
994 #define GST_ROUND_DOWN_64(num) ((num)&(~63))
996 void gst_object_default_error (GstObject * source,
997 GError * error, gchar * debug);
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);
1004 GstPadTemplate* gst_element_get_compatible_pad_template (GstElement *element, GstPadTemplate *compattempl);
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);
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,
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;
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);
1027 gboolean gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
1028 GstElement * dest, const gchar * destpadname,
1031 gboolean gst_element_seek_simple (GstElement *element,
1033 GstSeekFlags seek_flags,
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);
1040 /* util query functions */
1041 gboolean gst_element_query_position (GstElement *element, GstFormat *format,
1043 gboolean gst_element_query_duration (GstElement *element, GstFormat *format,
1045 gboolean gst_element_query_convert (GstElement *element, GstFormat src_format, gint64 src_val,
1046 GstFormat *dest_format, gint64 *dest_val);
1048 /* element class functions */
1049 void gst_element_class_install_std_props (GstElementClass * klass,
1050 const gchar * first_name, ...) G_GNUC_NULL_TERMINATED;
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);
1058 GstElement* gst_pad_get_parent_element (GstPad *pad);
1060 /* util query functions */
1061 gboolean gst_pad_query_position (GstPad *pad, GstFormat *format,
1063 gboolean gst_pad_query_duration (GstPad *pad, GstFormat *format,
1065 gboolean gst_pad_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
1066 GstFormat *dest_format, gint64 *dest_val);
1068 gboolean gst_pad_query_peer_position (GstPad *pad, GstFormat *format,
1070 gboolean gst_pad_query_peer_duration (GstPad *pad, GstFormat *format,
1072 gboolean gst_pad_query_peer_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
1073 GstFormat *dest_format, gint64 *dest_val);
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);
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 */
1090 /* atomic functions */
1091 #ifndef GST_DISABLE_DEPRECATED
1092 void gst_atomic_int_set (gint * atomic_int, gint value);
1096 gulong gst_pad_add_data_probe (GstPad * pad,
1100 gulong gst_pad_add_data_probe_full (GstPad * pad,
1103 GDestroyNotify notify);
1105 void gst_pad_remove_data_probe (GstPad * pad, guint handler_id);
1107 gulong gst_pad_add_event_probe (GstPad * pad,
1111 gulong gst_pad_add_event_probe_full (GstPad * pad,
1114 GDestroyNotify notify);
1116 void gst_pad_remove_event_probe (GstPad * pad, guint handler_id);
1118 gulong gst_pad_add_buffer_probe (GstPad * pad,
1122 gulong gst_pad_add_buffer_probe_full (GstPad * pad,
1125 GDestroyNotify notify);
1127 void gst_pad_remove_buffer_probe (GstPad * pad, guint handler_id);
1129 /* tag emission utility functions */
1130 void gst_element_found_tags_for_pad (GstElement * element,
1133 void gst_element_found_tags (GstElement * element,
1136 /* parse utility functions */
1137 GstElement * gst_parse_bin_from_description (const gchar * bin_description,
1138 gboolean ghost_unlinked_pads,
1141 GstElement * gst_parse_bin_from_description_full (const gchar * bin_description,
1142 gboolean ghost_unlinked_pads,
1143 GstParseContext * context,
1144 GstParseFlags flags,
1147 GstClockTime gst_util_get_timestamp (void);
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.
1155 * The different search modes.
1160 GST_SEARCH_MODE_EXACT = 0,
1161 GST_SEARCH_MODE_BEFORE,
1162 GST_SEARCH_MODE_AFTER
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);
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);
1177 /* sink message event
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.
1185 GstEvent* gst_event_new_sink_message (GstMessage *msg);
1186 void gst_event_parse_sink_message (GstEvent *event, GstMessage **msg);
1191 #endif /* __GST_UTILS_H__ */