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., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 #ifndef __GST_UTILS_H__
26 #define __GST_UTILS_H__
29 #include <gst/gstconfig.h>
30 #include <gst/gstbin.h>
31 #include <gst/gstparse.h>
35 void gst_util_set_value_from_string (GValue *value, const gchar *value_str);
36 void gst_util_set_object_arg (GObject *object, const gchar *name, const gchar *value);
37 void gst_util_dump_mem (const guchar *mem, guint size);
39 guint64 gst_util_gdouble_to_guint64 (gdouble value) G_GNUC_CONST;
40 gdouble gst_util_guint64_to_gdouble (guint64 value) G_GNUC_CONST;
43 * gst_guint64_to_gdouble:
44 * @value: the #guint64 value to convert
46 * Convert @value to a gdouble.
48 * Returns: @value converted to a #gdouble.
52 * gst_gdouble_to_guint64:
53 * @value: the #gdouble value to convert
55 * Convert @value to a guint64.
57 * Returns: @value converted to a #guint64.
60 #define gst_gdouble_to_guint64(value) gst_util_gdouble_to_guint64(value)
61 #define gst_guint64_to_gdouble(value) gst_util_guint64_to_gdouble(value)
63 #define gst_gdouble_to_guint64(value) ((guint64) (value))
64 #define gst_guint64_to_gdouble(value) ((gdouble) (value))
67 guint64 gst_util_uint64_scale (guint64 val, guint64 num, guint64 denom);
68 guint64 gst_util_uint64_scale_round (guint64 val, guint64 num, guint64 denom);
69 guint64 gst_util_uint64_scale_ceil (guint64 val, guint64 num, guint64 denom);
71 guint64 gst_util_uint64_scale_int (guint64 val, gint num, gint denom);
72 guint64 gst_util_uint64_scale_int_round (guint64 val, gint num, gint denom);
73 guint64 gst_util_uint64_scale_int_ceil (guint64 val, gint num, gint denom);
75 guint32 gst_util_seqnum_next (void);
76 gint32 gst_util_seqnum_compare (guint32 s1, guint32 s2);
78 guint gst_util_group_id_next (void);
82 * @parent_class_cast: the name of the class cast macro for the parent type
83 * @name: name of the function to call
84 * @args: arguments enclosed in '( )'
86 * Just call the parent handler. This assumes that there is a variable
87 * named parent_class that points to the (duh!) parent class. Note that
88 * this macro is not to be used with things that return something, use
89 * the _WITH_DEFAULT version for that
91 #define GST_CALL_PARENT(parent_class_cast, name, args) \
92 ((parent_class_cast(parent_class)->name != NULL) ? \
93 parent_class_cast(parent_class)->name args : (void) 0)
96 * GST_CALL_PARENT_WITH_DEFAULT:
97 * @parent_class_cast: the name of the class cast macro for the parent type
98 * @name: name of the function to call
99 * @args: arguments enclosed in '( )'
100 * @def_return: default result
102 * Same as GST_CALL_PARENT(), but in case there is no implementation, it
103 * evaluates to @def_return.
105 #define GST_CALL_PARENT_WITH_DEFAULT(parent_class_cast, name, args, def_return)\
106 ((parent_class_cast(parent_class)->name != NULL) ? \
107 parent_class_cast(parent_class)->name args : def_return)
109 /* Define PUT and GET functions for unaligned memory */
110 #define _GST_GET(__data, __idx, __size, __shift) \
111 (((guint##__size) (((const guint8 *) (__data))[__idx])) << (__shift))
113 #define _GST_PUT(__data, __idx, __size, __shift, __num) \
114 (((guint8 *) (__data))[__idx] = (((guint##__size) (__num)) >> (__shift)) & 0xff)
116 #if GST_HAVE_UNALIGNED_ACCESS
117 static inline guint16 __gst_fast_read16(const guint8 *v) {
118 return *(const guint16*)(v);
120 static inline guint32 __gst_fast_read32(const guint8 *v) {
121 return *(const guint32*)(v);
123 static inline guint64 __gst_fast_read64(const guint8 *v) {
124 return *(const guint64*)(v);
126 static inline guint16 __gst_fast_read_swap16(const guint8 *v) {
127 return GUINT16_SWAP_LE_BE(*(const guint16*)(v));
129 static inline guint32 __gst_fast_read_swap32(const guint8 *v) {
130 return GUINT32_SWAP_LE_BE(*(const guint32*)(v));
132 static inline guint64 __gst_fast_read_swap64(const guint8 *v) {
133 return GUINT64_SWAP_LE_BE(*(const guint64*)(v));
135 # define _GST_FAST_READ(s, d) __gst_fast_read##s((const guint8 *)(d))
136 # define _GST_FAST_READ_SWAP(s, d) __gst_fast_read_swap##s((const guint8 *)(d))
141 * GST_READ_UINT64_BE:
142 * @data: memory location
144 * Read a 64 bit unsigned integer value in big endian format from the memory buffer.
148 * GST_READ_UINT64_LE:
149 * @data: memory location
151 * Read a 64 bit unsigned integer value in little endian format from the memory buffer.
153 #if GST_HAVE_UNALIGNED_ACCESS
154 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
155 # define GST_READ_UINT64_BE(data) _GST_FAST_READ (64, data)
156 # define GST_READ_UINT64_LE(data) _GST_FAST_READ_SWAP (64, data)
158 # define GST_READ_UINT64_BE(data) _GST_FAST_READ_SWAP (64, data)
159 # define GST_READ_UINT64_LE(data) _GST_FAST_READ (64, data)
162 #define _GST_READ_UINT64_BE(data) (_GST_GET (data, 0, 64, 56) | \
163 _GST_GET (data, 1, 64, 48) | \
164 _GST_GET (data, 2, 64, 40) | \
165 _GST_GET (data, 3, 64, 32) | \
166 _GST_GET (data, 4, 64, 24) | \
167 _GST_GET (data, 5, 64, 16) | \
168 _GST_GET (data, 6, 64, 8) | \
169 _GST_GET (data, 7, 64, 0))
171 #define _GST_READ_UINT64_LE(data) (_GST_GET (data, 7, 64, 56) | \
172 _GST_GET (data, 6, 64, 48) | \
173 _GST_GET (data, 5, 64, 40) | \
174 _GST_GET (data, 4, 64, 32) | \
175 _GST_GET (data, 3, 64, 24) | \
176 _GST_GET (data, 2, 64, 16) | \
177 _GST_GET (data, 1, 64, 8) | \
178 _GST_GET (data, 0, 64, 0))
180 #define GST_READ_UINT64_BE(data) __gst_slow_read64_be((const guint8 *)(data))
181 static inline guint64 __gst_slow_read64_be (const guint8 * data) {
182 return _GST_READ_UINT64_BE (data);
184 #define GST_READ_UINT64_LE(data) __gst_slow_read64_le((const guint8 *)(data))
185 static inline guint64 __gst_slow_read64_le (const guint8 * data) {
186 return _GST_READ_UINT64_LE (data);
191 * GST_READ_UINT32_BE:
192 * @data: memory location
194 * Read a 32 bit unsigned integer value in big endian format from the memory buffer.
198 * GST_READ_UINT32_LE:
199 * @data: memory location
201 * Read a 32 bit unsigned integer value in little endian format from the memory buffer.
203 #if GST_HAVE_UNALIGNED_ACCESS
204 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
205 # define GST_READ_UINT32_BE(data) _GST_FAST_READ (32, data)
206 # define GST_READ_UINT32_LE(data) _GST_FAST_READ_SWAP (32, data)
208 # define GST_READ_UINT32_BE(data) _GST_FAST_READ_SWAP (32, data)
209 # define GST_READ_UINT32_LE(data) _GST_FAST_READ (32, data)
212 #define _GST_READ_UINT32_BE(data) (_GST_GET (data, 0, 32, 24) | \
213 _GST_GET (data, 1, 32, 16) | \
214 _GST_GET (data, 2, 32, 8) | \
215 _GST_GET (data, 3, 32, 0))
217 #define _GST_READ_UINT32_LE(data) (_GST_GET (data, 3, 32, 24) | \
218 _GST_GET (data, 2, 32, 16) | \
219 _GST_GET (data, 1, 32, 8) | \
220 _GST_GET (data, 0, 32, 0))
222 #define GST_READ_UINT32_BE(data) __gst_slow_read32_be((const guint8 *)(data))
223 static inline guint32 __gst_slow_read32_be (const guint8 * data) {
224 return _GST_READ_UINT32_BE (data);
226 #define GST_READ_UINT32_LE(data) __gst_slow_read32_le((const guint8 *)(data))
227 static inline guint32 __gst_slow_read32_le (const guint8 * data) {
228 return _GST_READ_UINT32_LE (data);
233 * GST_READ_UINT24_BE:
234 * @data: memory location
236 * Read a 24 bit unsigned integer value in big endian format from the memory buffer.
238 #define _GST_READ_UINT24_BE(data) (_GST_GET (data, 0, 32, 16) | \
239 _GST_GET (data, 1, 32, 8) | \
240 _GST_GET (data, 2, 32, 0))
242 #define GST_READ_UINT24_BE(data) __gst_slow_read24_be((const guint8 *)(data))
243 static inline guint32 __gst_slow_read24_be (const guint8 * data) {
244 return _GST_READ_UINT24_BE (data);
248 * GST_READ_UINT24_LE:
249 * @data: memory location
251 * Read a 24 bit unsigned integer value in little endian format from the memory buffer.
253 #define _GST_READ_UINT24_LE(data) (_GST_GET (data, 2, 32, 16) | \
254 _GST_GET (data, 1, 32, 8) | \
255 _GST_GET (data, 0, 32, 0))
257 #define GST_READ_UINT24_LE(data) __gst_slow_read24_le((const guint8 *)(data))
258 static inline guint32 __gst_slow_read24_le (const guint8 * data) {
259 return _GST_READ_UINT24_LE (data);
263 * GST_READ_UINT16_BE:
264 * @data: memory location
266 * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
269 * GST_READ_UINT16_LE:
270 * @data: memory location
272 * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
274 #if GST_HAVE_UNALIGNED_ACCESS
275 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
276 # define GST_READ_UINT16_BE(data) _GST_FAST_READ (16, data)
277 # define GST_READ_UINT16_LE(data) _GST_FAST_READ_SWAP (16, data)
279 # define GST_READ_UINT16_BE(data) _GST_FAST_READ_SWAP (16, data)
280 # define GST_READ_UINT16_LE(data) _GST_FAST_READ (16, data)
283 #define _GST_READ_UINT16_BE(data) (_GST_GET (data, 0, 16, 8) | \
284 _GST_GET (data, 1, 16, 0))
286 #define _GST_READ_UINT16_LE(data) (_GST_GET (data, 1, 16, 8) | \
287 _GST_GET (data, 0, 16, 0))
289 #define GST_READ_UINT16_BE(data) __gst_slow_read16_be((const guint8 *)(data))
290 static inline guint16 __gst_slow_read16_be (const guint8 * data) {
291 return _GST_READ_UINT16_BE (data);
293 #define GST_READ_UINT16_LE(data) __gst_slow_read16_le((const guint8 *)(data))
294 static inline guint16 __gst_slow_read16_le (const guint8 * data) {
295 return _GST_READ_UINT16_LE (data);
301 * @data: memory location
303 * Read an 8 bit unsigned integer value from the memory buffer.
305 #define GST_READ_UINT8(data) (_GST_GET (data, 0, 8, 0))
308 * GST_WRITE_UINT64_BE:
309 * @data: memory location
310 * @num: value to store
312 * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
314 #define GST_WRITE_UINT64_BE(data, num) do { \
315 gpointer __put_data = data; \
316 _GST_PUT (__put_data, 0, 64, 56, num); \
317 _GST_PUT (__put_data, 1, 64, 48, num); \
318 _GST_PUT (__put_data, 2, 64, 40, num); \
319 _GST_PUT (__put_data, 3, 64, 32, num); \
320 _GST_PUT (__put_data, 4, 64, 24, num); \
321 _GST_PUT (__put_data, 5, 64, 16, num); \
322 _GST_PUT (__put_data, 6, 64, 8, num); \
323 _GST_PUT (__put_data, 7, 64, 0, num); \
327 * GST_WRITE_UINT64_LE:
328 * @data: memory location
329 * @num: value to store
331 * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
333 #define GST_WRITE_UINT64_LE(data, num) do { \
334 gpointer __put_data = data; \
335 _GST_PUT (__put_data, 0, 64, 0, num); \
336 _GST_PUT (__put_data, 1, 64, 8, num); \
337 _GST_PUT (__put_data, 2, 64, 16, num); \
338 _GST_PUT (__put_data, 3, 64, 24, num); \
339 _GST_PUT (__put_data, 4, 64, 32, num); \
340 _GST_PUT (__put_data, 5, 64, 40, num); \
341 _GST_PUT (__put_data, 6, 64, 48, num); \
342 _GST_PUT (__put_data, 7, 64, 56, num); \
346 * GST_WRITE_UINT32_BE:
347 * @data: memory location
348 * @num: value to store
350 * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
352 #define GST_WRITE_UINT32_BE(data, num) do { \
353 gpointer __put_data = data; \
354 _GST_PUT (__put_data, 0, 32, 24, num); \
355 _GST_PUT (__put_data, 1, 32, 16, num); \
356 _GST_PUT (__put_data, 2, 32, 8, num); \
357 _GST_PUT (__put_data, 3, 32, 0, num); \
361 * GST_WRITE_UINT32_LE:
362 * @data: memory location
363 * @num: value to store
365 * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
367 #define GST_WRITE_UINT32_LE(data, num) do { \
368 gpointer __put_data = data; \
369 _GST_PUT (__put_data, 0, 32, 0, num); \
370 _GST_PUT (__put_data, 1, 32, 8, num); \
371 _GST_PUT (__put_data, 2, 32, 16, num); \
372 _GST_PUT (__put_data, 3, 32, 24, num); \
376 * GST_WRITE_UINT24_BE:
377 * @data: memory location
378 * @num: value to store
380 * Store a 24 bit unsigned integer value in big endian format into the memory buffer.
382 #define GST_WRITE_UINT24_BE(data, num) do { \
383 gpointer __put_data = data; \
384 _GST_PUT (__put_data, 0, 32, 16, num); \
385 _GST_PUT (__put_data, 1, 32, 8, num); \
386 _GST_PUT (__put_data, 2, 32, 0, num); \
390 * GST_WRITE_UINT24_LE:
391 * @data: memory location
392 * @num: value to store
394 * Store a 24 bit unsigned integer value in little endian format into the memory buffer.
396 #define GST_WRITE_UINT24_LE(data, num) do { \
397 gpointer __put_data = data; \
398 _GST_PUT (__put_data, 0, 32, 0, num); \
399 _GST_PUT (__put_data, 1, 32, 8, num); \
400 _GST_PUT (__put_data, 2, 32, 16, num); \
404 * GST_WRITE_UINT16_BE:
405 * @data: memory location
406 * @num: value to store
408 * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
410 #define GST_WRITE_UINT16_BE(data, num) do { \
411 gpointer __put_data = data; \
412 _GST_PUT (__put_data, 0, 16, 8, num); \
413 _GST_PUT (__put_data, 1, 16, 0, num); \
417 * GST_WRITE_UINT16_LE:
418 * @data: memory location
419 * @num: value to store
421 * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
423 #define GST_WRITE_UINT16_LE(data, num) do { \
424 gpointer __put_data = data; \
425 _GST_PUT (__put_data, 0, 16, 0, num); \
426 _GST_PUT (__put_data, 1, 16, 8, num); \
431 * @data: memory location
432 * @num: value to store
434 * Store an 8 bit unsigned integer value into the memory buffer.
436 #define GST_WRITE_UINT8(data, num) do { \
437 _GST_PUT (data, 0, 8, 0, num); \
440 /* Float endianness conversion macros */
442 /* FIXME: Remove this once we depend on a GLib version with this */
443 #ifndef GFLOAT_FROM_LE
448 * Swap byte order of a 32-bit floating point value (float).
450 * Returns: @in byte-swapped.
452 #ifdef _FOOL_GTK_DOC_
453 G_INLINE_FUNC gfloat GFLOAT_SWAP_LE_BE (gfloat in);
457 GFLOAT_SWAP_LE_BE(gfloat in)
466 u.i = GUINT32_SWAP_LE_BE (u.i);
471 * GDOUBLE_SWAP_LE_BE:
474 * Swap byte order of a 64-bit floating point value (double).
476 * Returns: @in byte-swapped.
478 #ifdef _FOOL_GTK_DOC_
479 G_INLINE_FUNC gdouble GDOUBLE_SWAP_LE_BE (gdouble in);
482 inline static gdouble
483 GDOUBLE_SWAP_LE_BE(gdouble in)
492 u.i = GUINT64_SWAP_LE_BE (u.i);
500 * Convert 64-bit floating point value (double) from native byte order into
501 * little endian byte order.
507 * Convert 64-bit floating point value (double) from native byte order into
508 * big endian byte order.
514 * Convert 64-bit floating point value (double) from little endian byte order
515 * into native byte order.
521 * Convert 64-bit floating point value (double) from big endian byte order
522 * into native byte order.
529 * Convert 32-bit floating point value (float) from native byte order into
530 * little endian byte order.
536 * Convert 32-bit floating point value (float) from native byte order into
537 * big endian byte order.
543 * Convert 32-bit floating point value (float) from little endian byte order
544 * into native byte order.
550 * Convert 32-bit floating point value (float) from big endian byte order
551 * into native byte order.
554 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
555 #define GFLOAT_TO_LE(val) ((gfloat) (val))
556 #define GFLOAT_TO_BE(val) (GFLOAT_SWAP_LE_BE (val))
557 #define GDOUBLE_TO_LE(val) ((gdouble) (val))
558 #define GDOUBLE_TO_BE(val) (GDOUBLE_SWAP_LE_BE (val))
560 #elif G_BYTE_ORDER == G_BIG_ENDIAN
561 #define GFLOAT_TO_LE(val) (GFLOAT_SWAP_LE_BE (val))
562 #define GFLOAT_TO_BE(val) ((gfloat) (val))
563 #define GDOUBLE_TO_LE(val) (GDOUBLE_SWAP_LE_BE (val))
564 #define GDOUBLE_TO_BE(val) ((gdouble) (val))
566 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
567 #error unknown ENDIAN type
568 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
570 #define GFLOAT_FROM_LE(val) (GFLOAT_TO_LE (val))
571 #define GFLOAT_FROM_BE(val) (GFLOAT_TO_BE (val))
572 #define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val))
573 #define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
575 #endif /* !defined(GFLOAT_FROM_LE) */
579 * @data: memory location
581 * Read a 32 bit float value in little endian format from the memory buffer.
583 * Returns: The floating point value read from @data
585 #ifdef _FOOL_GTK_DOC_
586 G_INLINE_FUNC gfloat GST_READ_FLOAT_LE (const guint8 *data);
590 GST_READ_FLOAT_LE(const guint8 *data)
598 u.i = GST_READ_UINT32_LE (data);
604 * @data: memory location
606 * Read a 32 bit float value in big endian format from the memory buffer.
608 * Returns: The floating point value read from @data
610 #ifdef _FOOL_GTK_DOC_
611 G_INLINE_FUNC gfloat GST_READ_FLOAT_BE (const guint8 *data);
615 GST_READ_FLOAT_BE(const guint8 *data)
623 u.i = GST_READ_UINT32_BE (data);
628 * GST_READ_DOUBLE_LE:
629 * @data: memory location
631 * Read a 64 bit double value in little endian format from the memory buffer.
633 * Returns: The double-precision floating point value read from @data
635 #ifdef _FOOL_GTK_DOC_
636 G_INLINE_FUNC gdouble GST_READ_DOUBLE_LE (const guint8 *data);
639 inline static gdouble
640 GST_READ_DOUBLE_LE(const guint8 *data)
648 u.i = GST_READ_UINT64_LE (data);
653 * GST_READ_DOUBLE_BE:
654 * @data: memory location
656 * Read a 64 bit double value in big endian format from the memory buffer.
658 * Returns: The double-precision floating point value read from @data
660 #ifdef _FOOL_GTK_DOC_
661 G_INLINE_FUNC gdouble GST_READ_DOUBLE_BE (const guint8 *data);
664 inline static gdouble
665 GST_READ_DOUBLE_BE(const guint8 *data)
673 u.i = GST_READ_UINT64_BE (data);
678 * GST_WRITE_FLOAT_LE:
679 * @data: memory location
680 * @num: value to store
682 * Store a 32 bit float value in little endian format into the memory buffer.
684 #ifdef _FOOL_GTK_DOC_
685 G_INLINE_FUNC void GST_WRITE_FLOAT_LE (guint8 *data, gfloat num);
689 GST_WRITE_FLOAT_LE(guint8 *data, gfloat num)
698 GST_WRITE_UINT32_LE (data, u.i);
702 * GST_WRITE_FLOAT_BE:
703 * @data: memory location
704 * @num: value to store
706 * Store a 32 bit float value in big endian format into the memory buffer.
708 #ifdef _FOOL_GTK_DOC_
709 G_INLINE_FUNC void GST_WRITE_FLOAT_BE (guint8 *data, gfloat num);
713 GST_WRITE_FLOAT_BE(guint8 *data, gfloat num)
722 GST_WRITE_UINT32_BE (data, u.i);
726 * GST_WRITE_DOUBLE_LE:
727 * @data: memory location
728 * @num: value to store
730 * Store a 64 bit double value in little endian format into the memory buffer.
732 #ifdef _FOOL_GTK_DOC_
733 G_INLINE_FUNC void GST_WRITE_DOUBLE_LE (guint8 *data, gdouble num);
737 GST_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
746 GST_WRITE_UINT64_LE (data, u.i);
750 * GST_WRITE_DOUBLE_BE:
751 * @data: memory location
752 * @num: value to store
754 * Store a 64 bit double value in big endian format into the memory buffer.
756 #ifdef _FOOL_GTK_DOC_
757 G_INLINE_FUNC void GST_WRITE_DOUBLE_BE (guint8 *data, gdouble num);
761 GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
770 GST_WRITE_UINT64_BE (data, u.i);
773 /* Miscellaneous utility macros */
777 * @num: integer value to round up
779 * Rounds an integer value up to the next multiple of 2.
781 #define GST_ROUND_UP_2(num) (((num)+1)&~1)
784 * @num: integer value to round up
786 * Rounds an integer value up to the next multiple of 4.
788 #define GST_ROUND_UP_4(num) (((num)+3)&~3)
791 * @num: integer value to round up
793 * Rounds an integer value up to the next multiple of 8.
795 #define GST_ROUND_UP_8(num) (((num)+7)&~7)
798 * @num: integer value to round up
800 * Rounds an integer value up to the next multiple of 16.
802 #define GST_ROUND_UP_16(num) (((num)+15)&~15)
805 * @num: integer value to round up
807 * Rounds an integer value up to the next multiple of 32.
809 #define GST_ROUND_UP_32(num) (((num)+31)&~31)
812 * @num: integer value to round up
814 * Rounds an integer value up to the next multiple of 64.
816 #define GST_ROUND_UP_64(num) (((num)+63)&~63)
819 * @num: integer value to round up
821 * Rounds an integer value up to the next multiple of 128.
824 #define GST_ROUND_UP_128(num) (((num)+127)&~127)
827 * @num: integrer value to round up
828 * @align: a power of two to round up to
830 * Rounds an integer value up to the next multiple of @align. @align MUST be a
833 #define GST_ROUND_UP_N(num,align) ((((num) + ((align) - 1)) & ~((align) - 1)))
838 * @num: integer value to round down
840 * Rounds an integer value down to the next multiple of 2.
842 #define GST_ROUND_DOWN_2(num) ((num)&(~1))
845 * @num: integer value to round down
847 * Rounds an integer value down to the next multiple of 4.
849 #define GST_ROUND_DOWN_4(num) ((num)&(~3))
852 * @num: integer value to round down
854 * Rounds an integer value down to the next multiple of 8.
856 #define GST_ROUND_DOWN_8(num) ((num)&(~7))
859 * @num: integer value to round down
861 * Rounds an integer value down to the next multiple of 16.
863 #define GST_ROUND_DOWN_16(num) ((num)&(~15))
866 * @num: integer value to round down
868 * Rounds an integer value down to the next multiple of 32.
870 #define GST_ROUND_DOWN_32(num) ((num)&(~31))
873 * @num: integer value to round down
875 * Rounds an integer value down to the next multiple of 64.
877 #define GST_ROUND_DOWN_64(num) ((num)&(~63))
879 * GST_ROUND_DOWN_128:
880 * @num: integer value to round down
882 * Rounds an integer value down to the next multiple of 128.
885 #define GST_ROUND_DOWN_128(num) ((num)&(~127))
888 * @num: integrer value to round down
889 * @align: a power of two to round down to
891 * Rounds an integer value down to the next multiple of @align. @align MUST be a
894 #define GST_ROUND_DOWN_N(num,align) (((num) & ~((align) - 1)))
897 void gst_object_default_error (GstObject * source,
898 const GError * error,
899 const gchar * debug);
901 /* element functions */
902 void gst_element_create_all_pads (GstElement *element);
903 GstPad* gst_element_get_compatible_pad (GstElement *element, GstPad *pad,
906 GstPadTemplate* gst_element_get_compatible_pad_template (GstElement *element, GstPadTemplate *compattempl);
908 const gchar* gst_element_state_get_name (GstState state);
909 const gchar * gst_element_state_change_return_get_name (GstStateChangeReturn state_ret);
911 gboolean gst_element_link (GstElement *src, GstElement *dest);
912 gboolean gst_element_link_many (GstElement *element_1,
913 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
914 gboolean gst_element_link_filtered (GstElement * src,
917 void gst_element_unlink (GstElement *src, GstElement *dest);
918 void gst_element_unlink_many (GstElement *element_1,
919 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
921 gboolean gst_element_link_pads (GstElement *src, const gchar *srcpadname,
922 GstElement *dest, const gchar *destpadname);
923 gboolean gst_element_link_pads_full (GstElement *src, const gchar *srcpadname,
924 GstElement *dest, const gchar *destpadname,
925 GstPadLinkCheck flags);
926 void gst_element_unlink_pads (GstElement *src, const gchar *srcpadname,
927 GstElement *dest, const gchar *destpadname);
929 gboolean gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
930 GstElement * dest, const gchar * destpadname,
933 gboolean gst_element_seek_simple (GstElement *element,
935 GstSeekFlags seek_flags,
938 /* util elementfactory functions */
939 gboolean gst_element_factory_can_sink_all_caps (GstElementFactory *factory, const GstCaps *caps);
940 gboolean gst_element_factory_can_src_all_caps (GstElementFactory *factory, const GstCaps *caps);
941 gboolean gst_element_factory_can_sink_any_caps (GstElementFactory *factory, const GstCaps *caps);
942 gboolean gst_element_factory_can_src_any_caps (GstElementFactory *factory, const GstCaps *caps);
944 /* util query functions */
945 gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur);
946 gboolean gst_element_query_duration (GstElement *element, GstFormat format, gint64 *duration);
947 gboolean gst_element_query_convert (GstElement *element, GstFormat src_format, gint64 src_val,
948 GstFormat dest_format, gint64 *dest_val);
951 void gst_pad_use_fixed_caps (GstPad *pad);
952 GstElement* gst_pad_get_parent_element (GstPad *pad);
954 /* util query functions */
955 gboolean gst_pad_proxy_query_accept_caps (GstPad *pad, GstQuery *query);
956 gboolean gst_pad_proxy_query_caps (GstPad *pad, GstQuery *query);
958 gboolean gst_pad_query_position (GstPad *pad, GstFormat format, gint64 *cur);
959 gboolean gst_pad_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
960 gboolean gst_pad_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
961 GstFormat dest_format, gint64 *dest_val);
962 GstCaps * gst_pad_query_caps (GstPad *pad, GstCaps *filter);
963 gboolean gst_pad_query_accept_caps (GstPad *pad, GstCaps *caps);
966 gboolean gst_pad_peer_query_position (GstPad *pad, GstFormat format, gint64 *cur);
967 gboolean gst_pad_peer_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
968 gboolean gst_pad_peer_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
969 GstFormat dest_format, gint64 *dest_val);
970 GstCaps * gst_pad_peer_query_caps (GstPad * pad, GstCaps *filter);
971 gboolean gst_pad_peer_query_accept_caps (GstPad * pad, GstCaps *caps);
973 gchar * gst_pad_create_stream_id (GstPad * pad, GstElement * parent, const gchar *stream_id) G_GNUC_MALLOC;
974 gchar * gst_pad_create_stream_id_printf (GstPad * pad, GstElement * parent, const gchar *stream_id, ...) G_GNUC_PRINTF (3, 4) G_GNUC_MALLOC;
975 gchar * gst_pad_create_stream_id_printf_valist (GstPad * pad, GstElement * parent, const gchar *stream_id, va_list var_args) G_GNUC_PRINTF (3, 0) G_GNUC_MALLOC;
977 gchar * gst_pad_get_stream_id (GstPad * pad);
980 void gst_bin_add_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
981 void gst_bin_remove_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
982 GstPad * gst_bin_find_unlinked_pad (GstBin *bin, GstPadDirection direction);
984 /* parse utility functions */
985 GstElement * gst_parse_bin_from_description (const gchar * bin_description,
986 gboolean ghost_unlinked_pads,
989 GstElement * gst_parse_bin_from_description_full (const gchar * bin_description,
990 gboolean ghost_unlinked_pads,
991 GstParseContext * context,
995 GstClockTime gst_util_get_timestamp (void);
999 * @GST_SEARCH_MODE_EXACT : Only search for exact matches.
1000 * @GST_SEARCH_MODE_BEFORE: Search for an exact match or the element just before.
1001 * @GST_SEARCH_MODE_AFTER : Search for an exact match or the element just after.
1003 * The different search modes.
1006 GST_SEARCH_MODE_EXACT = 0,
1007 GST_SEARCH_MODE_BEFORE,
1008 GST_SEARCH_MODE_AFTER
1011 gpointer gst_util_array_binary_search (gpointer array, guint num_elements,
1012 gsize element_size, GCompareDataFunc search_func,
1013 GstSearchMode mode, gconstpointer search_data,
1014 gpointer user_data);
1016 /* fraction operations */
1017 gint gst_util_greatest_common_divisor (gint a, gint b);
1018 gint64 gst_util_greatest_common_divisor_int64 (gint64 a, gint64 b);
1020 void gst_util_fraction_to_double (gint src_n, gint src_d, gdouble *dest);
1021 void gst_util_double_to_fraction (gdouble src, gint *dest_n, gint *dest_d);
1023 gboolean gst_util_fraction_multiply (gint a_n, gint a_d, gint b_n, gint b_d,
1024 gint *res_n, gint *res_d);
1025 gboolean gst_util_fraction_add (gint a_n, gint a_d, gint b_n, gint b_d,
1026 gint *res_n, gint *res_d);
1027 gint gst_util_fraction_compare (gint a_n, gint a_d, gint b_n, gint b_d);
1032 #endif /* __GST_UTILS_H__ */