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_PURE;
39 gdouble gst_util_guint64_to_gdouble (guint64 value) G_GNUC_PURE;
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) G_GNUC_PURE;
67 guint64 gst_util_uint64_scale_round (guint64 val, guint64 num, guint64 denom) G_GNUC_PURE;
68 guint64 gst_util_uint64_scale_ceil (guint64 val, guint64 num, guint64 denom) G_GNUC_PURE;
70 guint64 gst_util_uint64_scale_int (guint64 val, gint num, gint denom) G_GNUC_PURE;
71 guint64 gst_util_uint64_scale_int_round (guint64 val, gint num, gint denom) G_GNUC_PURE;
72 guint64 gst_util_uint64_scale_int_ceil (guint64 val, gint num, gint denom) G_GNUC_PURE;
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); \
134 GType type_as_function ## _get_type (void); \
137 type_as_function ## _get_type (void) \
139 /* The typedef for GType may be gulong or gsize, depending on the \
140 * system and whether the compiler is c++ or not. The g_once_init_* \
141 * functions always take a gsize * though ... */ \
142 static volatile gsize gonce_data = 0; \
143 if (g_once_init_enter (&gonce_data)) { \
145 _type = gst_type_register_static_full (parent_type_macro, \
146 g_intern_static_string (#type), \
147 sizeof (type ## Class), \
148 type_as_function ## _base_init, \
149 NULL, /* base_finalize */ \
150 type_as_function ## _class_init_trampoline, \
151 NULL, /* class_finalize */ \
152 NULL, /* class_data */ \
154 0, /* n_preallocs */ \
155 (GInstanceInitFunc) type_as_function ## _init, \
158 additional_initializations (_type); \
159 g_once_init_leave (&gonce_data, (gsize) _type); \
161 return (GType) gonce_data; \
164 #define __GST_DO_NOTHING(type) /* NOP */
168 * @type: the name of the type struct
169 * @type_as_function: the prefix for the functions
170 * @parent_type: the parent type struct name
171 * @parent_type_macro: the parent type macro
173 * Define the boilerplate type stuff to reduce typos and code size. Defines
174 * the get_type method and the parent_class static variable.
178 * GST_BOILERPLATE (GstFdSink, gst_fdsink, GstElement, GST_TYPE_ELEMENT);
182 #define GST_BOILERPLATE(type,type_as_function,parent_type,parent_type_macro) \
183 GST_BOILERPLATE_FULL (type, type_as_function, parent_type, parent_type_macro, \
186 /* Like GST_BOILERPLATE, but makes the type 1) implement an interface, and 2)
187 * implement GstImplementsInterface for that type
189 * After this you will need to implement interface_as_function ## _supported
190 * and interface_as_function ## _interface_init
193 * GST_BOILERPLATE_WITH_INTERFACE:
194 * @type: the name of the type struct
195 * @type_as_function: the prefix for the functions
196 * @parent_type: the parent type struct name
197 * @parent_type_as_macro: the parent type macro
198 * @interface_type: the name of the interface type struct
199 * @interface_type_as_macro: the interface type macro
200 * @interface_as_function: the interface function name prefix
202 * Like GST_BOILERPLATE, but makes the type 1) implement an interface, and 2)
203 * implement GstImplementsInterface for that type.
205 * After this you will need to implement interface_as_function ## _supported
206 * and interface_as_function ## _interface_init
208 #define GST_BOILERPLATE_WITH_INTERFACE(type, type_as_function, \
209 parent_type, parent_type_as_macro, interface_type, \
210 interface_type_as_macro, interface_as_function) \
212 static void interface_as_function ## _interface_init (interface_type ## Class *klass); \
213 static gboolean interface_as_function ## _supported (type *object, GType iface_type); \
216 type_as_function ## _implements_interface_init (GstImplementsInterfaceClass *klass) \
218 klass->supported = (gboolean (*)(GstImplementsInterface*, GType))interface_as_function ## _supported; \
222 type_as_function ## _init_interfaces (GType type) \
224 static const GInterfaceInfo implements_iface_info = { \
225 (GInterfaceInitFunc) type_as_function ## _implements_interface_init,\
229 static const GInterfaceInfo iface_info = { \
230 (GInterfaceInitFunc) interface_as_function ## _interface_init, \
235 g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE, \
236 &implements_iface_info); \
237 g_type_add_interface_static (type, interface_type_as_macro, \
241 GST_BOILERPLATE_FULL (type, type_as_function, parent_type, \
242 parent_type_as_macro, type_as_function ## _init_interfaces)
246 * @parent_class_cast: the name of the class cast macro for the parent type
247 * @name: name of the function to call
248 * @args: arguments enclosed in '( )'
250 * Just call the parent handler. This assumes that there is a variable
251 * named parent_class that points to the (duh!) parent class. Note that
252 * this macro is not to be used with things that return something, use
253 * the _WITH_DEFAULT version for that
255 #define GST_CALL_PARENT(parent_class_cast, name, args) \
256 ((parent_class_cast(parent_class)->name != NULL) ? \
257 parent_class_cast(parent_class)->name args : (void) 0)
260 * GST_CALL_PARENT_WITH_DEFAULT:
261 * @parent_class_cast: the name of the class cast macro for the parent type
262 * @name: name of the function to call
263 * @args: arguments enclosed in '( )'
264 * @def_return: default result
266 * Same as GST_CALL_PARENT(), but in case there is no implementation, it
267 * evaluates to @def_return.
269 #define GST_CALL_PARENT_WITH_DEFAULT(parent_class_cast, name, args, def_return)\
270 ((parent_class_cast(parent_class)->name != NULL) ? \
271 parent_class_cast(parent_class)->name args : def_return)
273 /* Define PUT and GET functions for unaligned memory */
274 #define _GST_GET(__data, __idx, __size, __shift) \
275 (((guint##__size) (((guint8 *) (__data))[__idx])) << (__shift))
277 #define _GST_PUT(__data, __idx, __size, __shift, __num) \
278 (((guint8 *) (__data))[__idx] = (((guint##__size) (__num)) >> (__shift)) & 0xff)
281 * GST_READ_UINT64_BE:
282 * @data: memory location
284 * Read a 64 bit unsigned integer value in big endian format from the memory buffer.
286 #define GST_READ_UINT64_BE(data) (_GST_GET (data, 0, 64, 56) | \
287 _GST_GET (data, 1, 64, 48) | \
288 _GST_GET (data, 2, 64, 40) | \
289 _GST_GET (data, 3, 64, 32) | \
290 _GST_GET (data, 4, 64, 24) | \
291 _GST_GET (data, 5, 64, 16) | \
292 _GST_GET (data, 6, 64, 8) | \
293 _GST_GET (data, 7, 64, 0))
296 * GST_READ_UINT64_LE:
297 * @data: memory location
299 * Read a 64 bit unsigned integer value in little endian format from the memory buffer.
301 #define GST_READ_UINT64_LE(data) (_GST_GET (data, 7, 64, 56) | \
302 _GST_GET (data, 6, 64, 48) | \
303 _GST_GET (data, 5, 64, 40) | \
304 _GST_GET (data, 4, 64, 32) | \
305 _GST_GET (data, 3, 64, 24) | \
306 _GST_GET (data, 2, 64, 16) | \
307 _GST_GET (data, 1, 64, 8) | \
308 _GST_GET (data, 0, 64, 0))
311 * GST_READ_UINT32_BE:
312 * @data: memory location
314 * Read a 32 bit unsigned integer value in big endian format from the memory buffer.
316 #define GST_READ_UINT32_BE(data) (_GST_GET (data, 0, 32, 24) | \
317 _GST_GET (data, 1, 32, 16) | \
318 _GST_GET (data, 2, 32, 8) | \
319 _GST_GET (data, 3, 32, 0))
322 * GST_READ_UINT32_LE:
323 * @data: memory location
325 * Read a 32 bit unsigned integer value in little endian format from the memory buffer.
327 #define GST_READ_UINT32_LE(data) (_GST_GET (data, 3, 32, 24) | \
328 _GST_GET (data, 2, 32, 16) | \
329 _GST_GET (data, 1, 32, 8) | \
330 _GST_GET (data, 0, 32, 0))
333 * GST_READ_UINT24_BE:
334 * @data: memory location
336 * Read a 24 bit unsigned integer value in big endian format from the memory buffer.
340 #define GST_READ_UINT24_BE(data) (_GST_GET (data, 0, 32, 16) | \
341 _GST_GET (data, 1, 32, 8) | \
342 _GST_GET (data, 2, 32, 0))
345 * GST_READ_UINT24_LE:
346 * @data: memory location
348 * Read a 24 bit unsigned integer value in little endian format from the memory buffer.
352 #define GST_READ_UINT24_LE(data) (_GST_GET (data, 2, 32, 16) | \
353 _GST_GET (data, 1, 32, 8) | \
354 _GST_GET (data, 0, 32, 0))
357 * GST_READ_UINT16_BE:
358 * @data: memory location
360 * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
362 #define GST_READ_UINT16_BE(data) (_GST_GET (data, 0, 16, 8) | \
363 _GST_GET (data, 1, 16, 0))
366 * GST_READ_UINT16_LE:
367 * @data: memory location
369 * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
371 #define GST_READ_UINT16_LE(data) (_GST_GET (data, 1, 16, 8) | \
372 _GST_GET (data, 0, 16, 0))
376 * @data: memory location
378 * Read an 8 bit unsigned integer value from the memory buffer.
380 #define GST_READ_UINT8(data) (_GST_GET (data, 0, 8, 0))
383 * GST_WRITE_UINT64_BE:
384 * @data: memory location
385 * @num: value to store
387 * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
389 #define GST_WRITE_UINT64_BE(data, num) do { \
390 _GST_PUT (data, 0, 64, 56, num); \
391 _GST_PUT (data, 1, 64, 48, num); \
392 _GST_PUT (data, 2, 64, 40, num); \
393 _GST_PUT (data, 3, 64, 32, num); \
394 _GST_PUT (data, 4, 64, 24, num); \
395 _GST_PUT (data, 5, 64, 16, num); \
396 _GST_PUT (data, 6, 64, 8, num); \
397 _GST_PUT (data, 7, 64, 0, num); \
401 * GST_WRITE_UINT64_LE:
402 * @data: memory location
403 * @num: value to store
405 * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
407 #define GST_WRITE_UINT64_LE(data, num) do { \
408 _GST_PUT (data, 0, 64, 0, num); \
409 _GST_PUT (data, 1, 64, 8, num); \
410 _GST_PUT (data, 2, 64, 16, num); \
411 _GST_PUT (data, 3, 64, 24, num); \
412 _GST_PUT (data, 4, 64, 32, num); \
413 _GST_PUT (data, 5, 64, 40, num); \
414 _GST_PUT (data, 6, 64, 48, num); \
415 _GST_PUT (data, 7, 64, 56, num); \
419 * GST_WRITE_UINT32_BE:
420 * @data: memory location
421 * @num: value to store
423 * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
425 #define GST_WRITE_UINT32_BE(data, num) do { \
426 _GST_PUT (data, 0, 32, 24, num); \
427 _GST_PUT (data, 1, 32, 16, num); \
428 _GST_PUT (data, 2, 32, 8, num); \
429 _GST_PUT (data, 3, 32, 0, num); \
433 * GST_WRITE_UINT32_LE:
434 * @data: memory location
435 * @num: value to store
437 * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
439 #define GST_WRITE_UINT32_LE(data, num) do { \
440 _GST_PUT (data, 0, 32, 0, num); \
441 _GST_PUT (data, 1, 32, 8, num); \
442 _GST_PUT (data, 2, 32, 16, num); \
443 _GST_PUT (data, 3, 32, 24, num); \
447 * GST_WRITE_UINT24_BE:
448 * @data: memory location
449 * @num: value to store
451 * Store a 24 bit unsigned integer value in big endian format into the memory buffer.
455 #define GST_WRITE_UINT24_BE(data, num) do { \
456 _GST_PUT (data, 0, 32, 16, num); \
457 _GST_PUT (data, 1, 32, 8, num); \
458 _GST_PUT (data, 2, 32, 0, num); \
462 * GST_WRITE_UINT24_LE:
463 * @data: memory location
464 * @num: value to store
466 * Store a 24 bit unsigned integer value in little endian format into the memory buffer.
470 #define GST_WRITE_UINT24_LE(data, num) do { \
471 _GST_PUT (data, 0, 32, 0, num); \
472 _GST_PUT (data, 1, 32, 8, num); \
473 _GST_PUT (data, 2, 32, 16, num); \
477 * GST_WRITE_UINT16_BE:
478 * @data: memory location
479 * @num: value to store
481 * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
483 #define GST_WRITE_UINT16_BE(data, num) do { \
484 _GST_PUT (data, 0, 16, 8, num); \
485 _GST_PUT (data, 1, 16, 0, num); \
489 * GST_WRITE_UINT16_LE:
490 * @data: memory location
491 * @num: value to store
493 * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
495 #define GST_WRITE_UINT16_LE(data, num) do { \
496 _GST_PUT (data, 0, 16, 0, num); \
497 _GST_PUT (data, 1, 16, 8, num); \
502 * @data: memory location
503 * @num: value to store
505 * Store an 8 bit unsigned integer value into the memory buffer.
507 #define GST_WRITE_UINT8(data, num) do { \
508 _GST_PUT (data, 0, 8, 0, num); \
511 /* Float endianess conversion macros */
513 /* FIXME: Remove this once we depend on a GLib version with this */
514 #ifndef GFLOAT_FROM_LE
519 * Swap byte order of a 32-bit floating point value (float).
521 * Returns: @in byte-swapped.
526 #ifdef _FOOL_GTK_DOC_
527 G_INLINE_FUNC gfloat GFLOAT_SWAP_LE_BE (gfloat in);
531 GFLOAT_SWAP_LE_BE(gfloat in)
540 u.i = GUINT32_SWAP_LE_BE (u.i);
545 * GDOUBLE_SWAP_LE_BE:
548 * Swap byte order of a 64-bit floating point value (double).
550 * Returns: @in byte-swapped.
555 #ifdef _FOOL_GTK_DOC_
556 G_INLINE_FUNC gdouble GDOUBLE_SWAP_LE_BE (gdouble in);
559 inline static gdouble
560 GDOUBLE_SWAP_LE_BE(gdouble in)
569 u.i = GUINT64_SWAP_LE_BE (u.i);
577 * Convert 64-bit floating point value (double) from native byte order into
578 * little endian byte order.
587 * Convert 64-bit floating point value (double) from native byte order into
588 * big endian byte order.
597 * Convert 64-bit floating point value (double) from little endian byte order
598 * into native byte order.
607 * Convert 64-bit floating point value (double) from big endian byte order
608 * into native byte order.
618 * Convert 32-bit floating point value (float) from native byte order into
619 * little endian byte order.
628 * Convert 32-bit floating point value (float) from native byte order into
629 * big endian byte order.
638 * Convert 32-bit floating point value (float) from little endian byte order
639 * into native byte order.
648 * Convert 32-bit floating point value (float) from big endian byte order
649 * into native byte order.
655 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
656 #define GFLOAT_TO_LE(val) ((gfloat) (val))
657 #define GFLOAT_TO_BE(val) (GFLOAT_SWAP_LE_BE (val))
658 #define GDOUBLE_TO_LE(val) ((gdouble) (val))
659 #define GDOUBLE_TO_BE(val) (GDOUBLE_SWAP_LE_BE (val))
661 #elif G_BYTE_ORDER == G_BIG_ENDIAN
662 #define GFLOAT_TO_LE(val) (GFLOAT_SWAP_LE_BE (val))
663 #define GFLOAT_TO_BE(val) ((gfloat) (val))
664 #define GDOUBLE_TO_LE(val) (GDOUBLE_SWAP_LE_BE (val))
665 #define GDOUBLE_TO_BE(val) ((gdouble) (val))
667 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
668 #error unknown ENDIAN type
669 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
671 #define GFLOAT_FROM_LE(val) (GFLOAT_TO_LE (val))
672 #define GFLOAT_FROM_BE(val) (GFLOAT_TO_BE (val))
673 #define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val))
674 #define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
676 #endif /* !defined(GFLOAT_FROM_LE) */
680 * @data: memory location
682 * Read a 32 bit float value in little endian format from the memory buffer.
684 * Returns: The floating point value read from @data
689 #ifdef _FOOL_GTK_DOC_
690 G_INLINE_FUNC gfloat GST_READ_FLOAT_LE (const guint8 *data);
694 GST_READ_FLOAT_LE(const guint8 *data)
702 u.i = GST_READ_UINT32_LE (data);
708 * @data: memory location
710 * Read a 32 bit float value in big endian format from the memory buffer.
712 * Returns: The floating point value read from @data
717 #ifdef _FOOL_GTK_DOC_
718 G_INLINE_FUNC gfloat GST_READ_FLOAT_BE (const guint8 *data);
722 GST_READ_FLOAT_BE(const guint8 *data)
730 u.i = GST_READ_UINT32_BE (data);
735 * GST_READ_DOUBLE_LE:
736 * @data: memory location
738 * Read a 64 bit double value in little endian format from the memory buffer.
740 * Returns: The double-precision floating point value read from @data
745 #ifdef _FOOL_GTK_DOC_
746 G_INLINE_FUNC gdouble GST_READ_DOUBLE_LE (const guint8 *data);
749 inline static gdouble
750 GST_READ_DOUBLE_LE(const guint8 *data)
758 u.i = GST_READ_UINT64_LE (data);
763 * GST_READ_DOUBLE_BE:
764 * @data: memory location
766 * Read a 64 bit double value in big endian format from the memory buffer.
768 * Returns: The double-precision floating point value read from @data
773 #ifdef _FOOL_GTK_DOC_
774 G_INLINE_FUNC gdouble GST_READ_DOUBLE_BE (const guint8 *data);
777 inline static gdouble
778 GST_READ_DOUBLE_BE(const guint8 *data)
786 u.i = GST_READ_UINT64_BE (data);
791 * GST_WRITE_FLOAT_LE:
792 * @data: memory location
793 * @num: value to store
795 * Store a 32 bit float value in little endian format into the memory buffer.
800 #ifdef _FOOL_GTK_DOC_
801 G_INLINE_FUNC void GST_WRITE_FLOAT_LE (guint8 *data, gfloat num);
805 GST_WRITE_FLOAT_LE(guint8 *data, gfloat num)
814 GST_WRITE_UINT32_LE (data, u.i);
818 * GST_WRITE_FLOAT_BE:
819 * @data: memory location
820 * @num: value to store
822 * Store a 32 bit float value in big endian format into the memory buffer.
827 #ifdef _FOOL_GTK_DOC_
828 G_INLINE_FUNC void GST_WRITE_FLOAT_BE (guint8 *data, gfloat num);
832 GST_WRITE_FLOAT_BE(guint8 *data, gfloat num)
841 GST_WRITE_UINT32_BE (data, u.i);
845 * GST_WRITE_DOUBLE_LE:
846 * @data: memory location
847 * @num: value to store
849 * Store a 64 bit double value in little endian format into the memory buffer.
854 #ifdef _FOOL_GTK_DOC_
855 G_INLINE_FUNC void GST_WRITE_DOUBLE_LE (guint8 *data, gdouble num);
859 GST_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
868 GST_WRITE_UINT64_LE (data, u.i);
872 * GST_WRITE_DOUBLE_BE:
873 * @data: memory location
874 * @num: value to store
876 * Store a 64 bit double value in big endian format into the memory buffer.
881 #ifdef _FOOL_GTK_DOC_
882 G_INLINE_FUNC void GST_WRITE_DOUBLE_BE (guint8 *data, gdouble num);
886 GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
895 GST_WRITE_UINT64_BE (data, u.i);
898 /* Miscellaneous utility macros */
902 * @num: integer value to round up
904 * Rounds an integer value up to the next multiple of 2.
906 #define GST_ROUND_UP_2(num) (((num)+1)&~1)
909 * @num: integer value to round up
911 * Rounds an integer value up to the next multiple of 4.
913 #define GST_ROUND_UP_4(num) (((num)+3)&~3)
916 * @num: integer value to round up
918 * Rounds an integer value up to the next multiple of 8.
920 #define GST_ROUND_UP_8(num) (((num)+7)&~7)
923 * @num: integer value to round up
925 * Rounds an integer value up to the next multiple of 16.
927 #define GST_ROUND_UP_16(num) (((num)+15)&~15)
930 * @num: integer value to round up
932 * Rounds an integer value up to the next multiple of 32.
934 #define GST_ROUND_UP_32(num) (((num)+31)&~31)
937 * @num: integer value to round up
939 * Rounds an integer value up to the next multiple of 64.
941 #define GST_ROUND_UP_64(num) (((num)+63)&~63)
945 * @num: integer value to round down
947 * Rounds an integer value down to the next multiple of 2.
951 #define GST_ROUND_DOWN_2(num) ((num)&(~1))
954 * @num: integer value to round down
956 * Rounds an integer value down to the next multiple of 4.
960 #define GST_ROUND_DOWN_4(num) ((num)&(~3))
963 * @num: integer value to round down
965 * Rounds an integer value down to the next multiple of 8.
969 #define GST_ROUND_DOWN_8(num) ((num)&(~7))
972 * @num: integer value to round down
974 * Rounds an integer value down to the next multiple of 16.
978 #define GST_ROUND_DOWN_16(num) ((num)&(~15))
981 * @num: integer value to round down
983 * Rounds an integer value down to the next multiple of 32.
987 #define GST_ROUND_DOWN_32(num) ((num)&(~31))
990 * @num: integer value to round down
992 * Rounds an integer value down to the next multiple of 64.
996 #define GST_ROUND_DOWN_64(num) ((num)&(~63))
998 void gst_object_default_error (GstObject * source,
999 GError * error, gchar * debug);
1001 /* element functions */
1002 void gst_element_create_all_pads (GstElement *element);
1003 GstPad* gst_element_get_compatible_pad (GstElement *element, GstPad *pad,
1004 const GstCaps *caps);
1006 GstPadTemplate* gst_element_get_compatible_pad_template (GstElement *element, GstPadTemplate *compattempl);
1008 G_CONST_RETURN gchar* gst_element_state_get_name (GstState state);
1009 G_CONST_RETURN gchar * gst_element_state_change_return_get_name (GstStateChangeReturn state_ret);
1011 gboolean gst_element_link (GstElement *src, GstElement *dest);
1012 gboolean gst_element_link_many (GstElement *element_1,
1013 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
1014 gboolean gst_element_link_filtered (GstElement * src,
1017 void gst_element_unlink (GstElement *src, GstElement *dest);
1018 void gst_element_unlink_many (GstElement *element_1,
1019 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
1021 gboolean gst_element_link_pads (GstElement *src, const gchar *srcpadname,
1022 GstElement *dest, const gchar *destpadname);
1023 void gst_element_unlink_pads (GstElement *src, const gchar *srcpadname,
1024 GstElement *dest, const gchar *destpadname);
1026 gboolean gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
1027 GstElement * dest, const gchar * destpadname,
1030 gboolean gst_element_seek_simple (GstElement *element,
1032 GstSeekFlags seek_flags,
1035 /* util elementfactory functions */
1036 gboolean gst_element_factory_can_src_caps(GstElementFactory *factory, const GstCaps *caps);
1037 gboolean gst_element_factory_can_sink_caps(GstElementFactory *factory, const GstCaps *caps);
1039 /* util query functions */
1040 gboolean gst_element_query_position (GstElement *element, GstFormat *format,
1042 gboolean gst_element_query_duration (GstElement *element, GstFormat *format,
1044 gboolean gst_element_query_convert (GstElement *element, GstFormat src_format, gint64 src_val,
1045 GstFormat *dest_format, gint64 *dest_val);
1047 /* element class functions */
1048 void gst_element_class_install_std_props (GstElementClass * klass,
1049 const gchar * first_name, ...) G_GNUC_NULL_TERMINATED;
1052 void gst_pad_use_fixed_caps (GstPad *pad);
1053 GstCaps* gst_pad_get_fixed_caps_func (GstPad *pad);
1054 GstCaps* gst_pad_proxy_getcaps (GstPad * pad);
1055 gboolean gst_pad_proxy_setcaps (GstPad * pad, GstCaps * caps);
1057 GstElement* gst_pad_get_parent_element (GstPad *pad);
1059 /* util query functions */
1060 gboolean gst_pad_query_position (GstPad *pad, GstFormat *format,
1062 gboolean gst_pad_query_duration (GstPad *pad, GstFormat *format,
1064 gboolean gst_pad_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
1065 GstFormat *dest_format, gint64 *dest_val);
1067 gboolean gst_pad_query_peer_position (GstPad *pad, GstFormat *format,
1069 gboolean gst_pad_query_peer_duration (GstPad *pad, GstFormat *format,
1071 gboolean gst_pad_query_peer_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
1072 GstFormat *dest_format, gint64 *dest_val);
1075 void gst_bin_add_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
1076 void gst_bin_remove_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
1077 GstPad * gst_bin_find_unlinked_pad (GstBin *bin, GstPadDirection direction);
1078 #ifndef GST_DISABLE_DEPRECATED
1079 GstPad * gst_bin_find_unconnected_pad (GstBin *bin, GstPadDirection direction);
1082 /* buffer functions */
1083 GstBuffer * gst_buffer_merge (GstBuffer * buf1, GstBuffer * buf2);
1084 GstBuffer * gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2);
1085 #ifndef GST_DISABLE_DEPRECATED
1086 void gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src);
1087 #endif /* GST_DISABLE_DEPRECATED */
1089 /* atomic functions */
1090 #ifndef GST_DISABLE_DEPRECATED
1091 void gst_atomic_int_set (gint * atomic_int, gint value);
1095 gulong gst_pad_add_data_probe (GstPad * pad,
1099 gulong gst_pad_add_data_probe_full (GstPad * pad,
1102 GDestroyNotify notify);
1104 void gst_pad_remove_data_probe (GstPad * pad, guint handler_id);
1106 gulong gst_pad_add_event_probe (GstPad * pad,
1110 gulong gst_pad_add_event_probe_full (GstPad * pad,
1113 GDestroyNotify notify);
1115 void gst_pad_remove_event_probe (GstPad * pad, guint handler_id);
1117 gulong gst_pad_add_buffer_probe (GstPad * pad,
1121 gulong gst_pad_add_buffer_probe_full (GstPad * pad,
1124 GDestroyNotify notify);
1126 void gst_pad_remove_buffer_probe (GstPad * pad, guint handler_id);
1128 /* tag emission utility functions */
1129 void gst_element_found_tags_for_pad (GstElement * element,
1132 void gst_element_found_tags (GstElement * element,
1135 /* parse utility functions */
1136 GstElement * gst_parse_bin_from_description (const gchar * bin_description,
1137 gboolean ghost_unlinked_pads,
1140 GstElement * gst_parse_bin_from_description_full (const gchar * bin_description,
1141 gboolean ghost_unlinked_pads,
1142 GstParseContext * context,
1143 GstParseFlags flags,
1146 GstClockTime gst_util_get_timestamp (void);
1150 * @GST_SEARCH_MODE_EXACT : Only search for exact matches.
1151 * @GST_SEARCH_MODE_BEFORE: Search for an exact match or the element just before.
1152 * @GST_SEARCH_MODE_AFTER : Search for an exact match or the element just after.
1154 * The different search modes.
1159 GST_SEARCH_MODE_EXACT = 0,
1160 GST_SEARCH_MODE_BEFORE,
1161 GST_SEARCH_MODE_AFTER
1164 gpointer gst_util_array_binary_search (gpointer array, guint num_elements,
1165 gsize element_size, GCompareDataFunc search_func,
1166 GstSearchMode mode, gconstpointer search_data,
1167 gpointer user_data);
1169 gint gst_util_greatest_common_divisor (gint a, gint b);
1170 void gst_util_fraction_to_double (gint src_n, gint src_d, gdouble *dest);
1171 void gst_util_double_to_fraction (gdouble src, gint *dest_n, gint *dest_d);
1175 #endif /* __GST_UTILS_H__ */