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 #ifndef __GTK_DOC_IGNORE__
117 #if GST_HAVE_UNALIGNED_ACCESS
118 static inline guint16 __gst_fast_read16(const guint8 *v) {
119 return *(const guint16*)(const void*)(v);
121 static inline guint32 __gst_fast_read32(const guint8 *v) {
122 return *(const guint32*)(const void*)(v);
124 static inline guint64 __gst_fast_read64(const guint8 *v) {
125 return *(const guint64*)(const void*)(v);
127 static inline guint16 __gst_fast_read_swap16(const guint8 *v) {
128 return GUINT16_SWAP_LE_BE(*(const guint16*)(const void*)(v));
130 static inline guint32 __gst_fast_read_swap32(const guint8 *v) {
131 return GUINT32_SWAP_LE_BE(*(const guint32*)(const void*)(v));
133 static inline guint64 __gst_fast_read_swap64(const guint8 *v) {
134 return GUINT64_SWAP_LE_BE(*(const guint64*)(const void*)(v));
136 # define _GST_FAST_READ(s, d) __gst_fast_read##s((const guint8 *)(d))
137 # define _GST_FAST_READ_SWAP(s, d) __gst_fast_read_swap##s((const guint8 *)(d))
143 * GST_READ_UINT64_BE:
144 * @data: memory location
146 * Read a 64 bit unsigned integer value in big endian format from the memory buffer.
150 * GST_READ_UINT64_LE:
151 * @data: memory location
153 * Read a 64 bit unsigned integer value in little endian format from the memory buffer.
155 #if GST_HAVE_UNALIGNED_ACCESS
156 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
157 # define GST_READ_UINT64_BE(data) _GST_FAST_READ (64, data)
158 # define GST_READ_UINT64_LE(data) _GST_FAST_READ_SWAP (64, data)
160 # define GST_READ_UINT64_BE(data) _GST_FAST_READ_SWAP (64, data)
161 # define GST_READ_UINT64_LE(data) _GST_FAST_READ (64, data)
164 #define _GST_READ_UINT64_BE(data) (_GST_GET (data, 0, 64, 56) | \
165 _GST_GET (data, 1, 64, 48) | \
166 _GST_GET (data, 2, 64, 40) | \
167 _GST_GET (data, 3, 64, 32) | \
168 _GST_GET (data, 4, 64, 24) | \
169 _GST_GET (data, 5, 64, 16) | \
170 _GST_GET (data, 6, 64, 8) | \
171 _GST_GET (data, 7, 64, 0))
173 #define _GST_READ_UINT64_LE(data) (_GST_GET (data, 7, 64, 56) | \
174 _GST_GET (data, 6, 64, 48) | \
175 _GST_GET (data, 5, 64, 40) | \
176 _GST_GET (data, 4, 64, 32) | \
177 _GST_GET (data, 3, 64, 24) | \
178 _GST_GET (data, 2, 64, 16) | \
179 _GST_GET (data, 1, 64, 8) | \
180 _GST_GET (data, 0, 64, 0))
182 #define GST_READ_UINT64_BE(data) __gst_slow_read64_be((const guint8 *)(data))
183 static inline guint64 __gst_slow_read64_be (const guint8 * data) {
184 return _GST_READ_UINT64_BE (data);
186 #define GST_READ_UINT64_LE(data) __gst_slow_read64_le((const guint8 *)(data))
187 static inline guint64 __gst_slow_read64_le (const guint8 * data) {
188 return _GST_READ_UINT64_LE (data);
193 * GST_READ_UINT32_BE:
194 * @data: memory location
196 * Read a 32 bit unsigned integer value in big endian format from the memory buffer.
200 * GST_READ_UINT32_LE:
201 * @data: memory location
203 * Read a 32 bit unsigned integer value in little endian format from the memory buffer.
205 #if GST_HAVE_UNALIGNED_ACCESS
206 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
207 # define GST_READ_UINT32_BE(data) _GST_FAST_READ (32, data)
208 # define GST_READ_UINT32_LE(data) _GST_FAST_READ_SWAP (32, data)
210 # define GST_READ_UINT32_BE(data) _GST_FAST_READ_SWAP (32, data)
211 # define GST_READ_UINT32_LE(data) _GST_FAST_READ (32, data)
214 #define _GST_READ_UINT32_BE(data) (_GST_GET (data, 0, 32, 24) | \
215 _GST_GET (data, 1, 32, 16) | \
216 _GST_GET (data, 2, 32, 8) | \
217 _GST_GET (data, 3, 32, 0))
219 #define _GST_READ_UINT32_LE(data) (_GST_GET (data, 3, 32, 24) | \
220 _GST_GET (data, 2, 32, 16) | \
221 _GST_GET (data, 1, 32, 8) | \
222 _GST_GET (data, 0, 32, 0))
224 #define GST_READ_UINT32_BE(data) __gst_slow_read32_be((const guint8 *)(data))
225 static inline guint32 __gst_slow_read32_be (const guint8 * data) {
226 return _GST_READ_UINT32_BE (data);
228 #define GST_READ_UINT32_LE(data) __gst_slow_read32_le((const guint8 *)(data))
229 static inline guint32 __gst_slow_read32_le (const guint8 * data) {
230 return _GST_READ_UINT32_LE (data);
235 * GST_READ_UINT24_BE:
236 * @data: memory location
238 * Read a 24 bit unsigned integer value in big endian format from the memory buffer.
240 #define _GST_READ_UINT24_BE(data) (_GST_GET (data, 0, 32, 16) | \
241 _GST_GET (data, 1, 32, 8) | \
242 _GST_GET (data, 2, 32, 0))
244 #define GST_READ_UINT24_BE(data) __gst_slow_read24_be((const guint8 *)(data))
245 static inline guint32 __gst_slow_read24_be (const guint8 * data) {
246 return _GST_READ_UINT24_BE (data);
250 * GST_READ_UINT24_LE:
251 * @data: memory location
253 * Read a 24 bit unsigned integer value in little endian format from the memory buffer.
255 #define _GST_READ_UINT24_LE(data) (_GST_GET (data, 2, 32, 16) | \
256 _GST_GET (data, 1, 32, 8) | \
257 _GST_GET (data, 0, 32, 0))
259 #define GST_READ_UINT24_LE(data) __gst_slow_read24_le((const guint8 *)(data))
260 static inline guint32 __gst_slow_read24_le (const guint8 * data) {
261 return _GST_READ_UINT24_LE (data);
265 * GST_READ_UINT16_BE:
266 * @data: memory location
268 * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
271 * GST_READ_UINT16_LE:
272 * @data: memory location
274 * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
276 #if GST_HAVE_UNALIGNED_ACCESS
277 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
278 # define GST_READ_UINT16_BE(data) _GST_FAST_READ (16, data)
279 # define GST_READ_UINT16_LE(data) _GST_FAST_READ_SWAP (16, data)
281 # define GST_READ_UINT16_BE(data) _GST_FAST_READ_SWAP (16, data)
282 # define GST_READ_UINT16_LE(data) _GST_FAST_READ (16, data)
285 #define _GST_READ_UINT16_BE(data) (_GST_GET (data, 0, 16, 8) | \
286 _GST_GET (data, 1, 16, 0))
288 #define _GST_READ_UINT16_LE(data) (_GST_GET (data, 1, 16, 8) | \
289 _GST_GET (data, 0, 16, 0))
291 #define GST_READ_UINT16_BE(data) __gst_slow_read16_be((const guint8 *)(data))
292 static inline guint16 __gst_slow_read16_be (const guint8 * data) {
293 return _GST_READ_UINT16_BE (data);
295 #define GST_READ_UINT16_LE(data) __gst_slow_read16_le((const guint8 *)(data))
296 static inline guint16 __gst_slow_read16_le (const guint8 * data) {
297 return _GST_READ_UINT16_LE (data);
303 * @data: memory location
305 * Read an 8 bit unsigned integer value from the memory buffer.
307 #define GST_READ_UINT8(data) (_GST_GET (data, 0, 8, 0))
310 * GST_WRITE_UINT64_BE:
311 * @data: memory location
312 * @num: value to store
314 * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
316 #define GST_WRITE_UINT64_BE(data, num) do { \
317 gpointer __put_data = data; \
318 _GST_PUT (__put_data, 0, 64, 56, num); \
319 _GST_PUT (__put_data, 1, 64, 48, num); \
320 _GST_PUT (__put_data, 2, 64, 40, num); \
321 _GST_PUT (__put_data, 3, 64, 32, num); \
322 _GST_PUT (__put_data, 4, 64, 24, num); \
323 _GST_PUT (__put_data, 5, 64, 16, num); \
324 _GST_PUT (__put_data, 6, 64, 8, num); \
325 _GST_PUT (__put_data, 7, 64, 0, num); \
329 * GST_WRITE_UINT64_LE:
330 * @data: memory location
331 * @num: value to store
333 * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
335 #define GST_WRITE_UINT64_LE(data, num) do { \
336 gpointer __put_data = data; \
337 _GST_PUT (__put_data, 0, 64, 0, num); \
338 _GST_PUT (__put_data, 1, 64, 8, num); \
339 _GST_PUT (__put_data, 2, 64, 16, num); \
340 _GST_PUT (__put_data, 3, 64, 24, num); \
341 _GST_PUT (__put_data, 4, 64, 32, num); \
342 _GST_PUT (__put_data, 5, 64, 40, num); \
343 _GST_PUT (__put_data, 6, 64, 48, num); \
344 _GST_PUT (__put_data, 7, 64, 56, num); \
348 * GST_WRITE_UINT32_BE:
349 * @data: memory location
350 * @num: value to store
352 * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
354 #define GST_WRITE_UINT32_BE(data, num) do { \
355 gpointer __put_data = data; \
356 _GST_PUT (__put_data, 0, 32, 24, num); \
357 _GST_PUT (__put_data, 1, 32, 16, num); \
358 _GST_PUT (__put_data, 2, 32, 8, num); \
359 _GST_PUT (__put_data, 3, 32, 0, num); \
363 * GST_WRITE_UINT32_LE:
364 * @data: memory location
365 * @num: value to store
367 * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
369 #define GST_WRITE_UINT32_LE(data, num) do { \
370 gpointer __put_data = data; \
371 _GST_PUT (__put_data, 0, 32, 0, num); \
372 _GST_PUT (__put_data, 1, 32, 8, num); \
373 _GST_PUT (__put_data, 2, 32, 16, num); \
374 _GST_PUT (__put_data, 3, 32, 24, num); \
378 * GST_WRITE_UINT24_BE:
379 * @data: memory location
380 * @num: value to store
382 * Store a 24 bit unsigned integer value in big endian format into the memory buffer.
384 #define GST_WRITE_UINT24_BE(data, num) do { \
385 gpointer __put_data = data; \
386 _GST_PUT (__put_data, 0, 32, 16, num); \
387 _GST_PUT (__put_data, 1, 32, 8, num); \
388 _GST_PUT (__put_data, 2, 32, 0, num); \
392 * GST_WRITE_UINT24_LE:
393 * @data: memory location
394 * @num: value to store
396 * Store a 24 bit unsigned integer value in little endian format into the memory buffer.
398 #define GST_WRITE_UINT24_LE(data, num) do { \
399 gpointer __put_data = data; \
400 _GST_PUT (__put_data, 0, 32, 0, num); \
401 _GST_PUT (__put_data, 1, 32, 8, num); \
402 _GST_PUT (__put_data, 2, 32, 16, num); \
406 * GST_WRITE_UINT16_BE:
407 * @data: memory location
408 * @num: value to store
410 * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
412 #define GST_WRITE_UINT16_BE(data, num) do { \
413 gpointer __put_data = data; \
414 _GST_PUT (__put_data, 0, 16, 8, num); \
415 _GST_PUT (__put_data, 1, 16, 0, num); \
419 * GST_WRITE_UINT16_LE:
420 * @data: memory location
421 * @num: value to store
423 * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
425 #define GST_WRITE_UINT16_LE(data, num) do { \
426 gpointer __put_data = data; \
427 _GST_PUT (__put_data, 0, 16, 0, num); \
428 _GST_PUT (__put_data, 1, 16, 8, num); \
433 * @data: memory location
434 * @num: value to store
436 * Store an 8 bit unsigned integer value into the memory buffer.
438 #define GST_WRITE_UINT8(data, num) do { \
439 _GST_PUT (data, 0, 8, 0, num); \
442 /* Float endianness conversion macros */
444 /* FIXME: Remove this once we depend on a GLib version with this */
445 #ifndef GFLOAT_FROM_LE
450 * Swap byte order of a 32-bit floating point value (float).
452 * Returns: @in byte-swapped.
455 GFLOAT_SWAP_LE_BE(gfloat in)
464 u.i = GUINT32_SWAP_LE_BE (u.i);
469 * GDOUBLE_SWAP_LE_BE:
472 * Swap byte order of a 64-bit floating point value (double).
474 * Returns: @in byte-swapped.
476 static inline gdouble
477 GDOUBLE_SWAP_LE_BE(gdouble in)
486 u.i = GUINT64_SWAP_LE_BE (u.i);
494 * Convert 64-bit floating point value (double) from native byte order into
495 * little endian byte order.
501 * Convert 64-bit floating point value (double) from native byte order into
502 * big endian byte order.
508 * Convert 64-bit floating point value (double) from little endian byte order
509 * into native byte order.
515 * Convert 64-bit floating point value (double) from big endian byte order
516 * into native byte order.
523 * Convert 32-bit floating point value (float) from native byte order into
524 * little endian byte order.
530 * Convert 32-bit floating point value (float) from native byte order into
531 * big endian byte order.
537 * Convert 32-bit floating point value (float) from little endian byte order
538 * into native byte order.
544 * Convert 32-bit floating point value (float) from big endian byte order
545 * into native byte order.
548 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
549 #define GFLOAT_TO_LE(val) ((gfloat) (val))
550 #define GFLOAT_TO_BE(val) (GFLOAT_SWAP_LE_BE (val))
551 #define GDOUBLE_TO_LE(val) ((gdouble) (val))
552 #define GDOUBLE_TO_BE(val) (GDOUBLE_SWAP_LE_BE (val))
554 #elif G_BYTE_ORDER == G_BIG_ENDIAN
555 #define GFLOAT_TO_LE(val) (GFLOAT_SWAP_LE_BE (val))
556 #define GFLOAT_TO_BE(val) ((gfloat) (val))
557 #define GDOUBLE_TO_LE(val) (GDOUBLE_SWAP_LE_BE (val))
558 #define GDOUBLE_TO_BE(val) ((gdouble) (val))
560 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
561 #error unknown ENDIAN type
562 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
564 #define GFLOAT_FROM_LE(val) (GFLOAT_TO_LE (val))
565 #define GFLOAT_FROM_BE(val) (GFLOAT_TO_BE (val))
566 #define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val))
567 #define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
569 #endif /* !defined(GFLOAT_FROM_LE) */
573 * @data: memory location
575 * Read a 32 bit float value in little endian format from the memory buffer.
577 * Returns: The floating point value read from @data
580 GST_READ_FLOAT_LE(const guint8 *data)
588 u.i = GST_READ_UINT32_LE (data);
594 * @data: memory location
596 * Read a 32 bit float value in big endian format from the memory buffer.
598 * Returns: The floating point value read from @data
601 GST_READ_FLOAT_BE(const guint8 *data)
609 u.i = GST_READ_UINT32_BE (data);
614 * GST_READ_DOUBLE_LE:
615 * @data: memory location
617 * Read a 64 bit double value in little endian format from the memory buffer.
619 * Returns: The double-precision floating point value read from @data
621 static inline gdouble
622 GST_READ_DOUBLE_LE(const guint8 *data)
630 u.i = GST_READ_UINT64_LE (data);
635 * GST_READ_DOUBLE_BE:
636 * @data: memory location
638 * Read a 64 bit double value in big endian format from the memory buffer.
640 * Returns: The double-precision floating point value read from @data
642 static inline gdouble
643 GST_READ_DOUBLE_BE(const guint8 *data)
651 u.i = GST_READ_UINT64_BE (data);
656 * GST_WRITE_FLOAT_LE:
657 * @data: memory location
658 * @num: value to store
660 * Store a 32 bit float value in little endian format into the memory buffer.
663 GST_WRITE_FLOAT_LE(guint8 *data, gfloat num)
672 GST_WRITE_UINT32_LE (data, u.i);
676 * GST_WRITE_FLOAT_BE:
677 * @data: memory location
678 * @num: value to store
680 * Store a 32 bit float value in big endian format into the memory buffer.
683 GST_WRITE_FLOAT_BE(guint8 *data, gfloat num)
692 GST_WRITE_UINT32_BE (data, u.i);
696 * GST_WRITE_DOUBLE_LE:
697 * @data: memory location
698 * @num: value to store
700 * Store a 64 bit double value in little endian format into the memory buffer.
703 GST_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
712 GST_WRITE_UINT64_LE (data, u.i);
716 * GST_WRITE_DOUBLE_BE:
717 * @data: memory location
718 * @num: value to store
720 * Store a 64 bit double value in big endian format into the memory buffer.
723 GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
732 GST_WRITE_UINT64_BE (data, u.i);
735 /* Miscellaneous utility macros */
739 * @num: integer value to round up
741 * Rounds an integer value up to the next multiple of 2.
743 #define GST_ROUND_UP_2(num) (((num)+1)&~1)
746 * @num: integer value to round up
748 * Rounds an integer value up to the next multiple of 4.
750 #define GST_ROUND_UP_4(num) (((num)+3)&~3)
753 * @num: integer value to round up
755 * Rounds an integer value up to the next multiple of 8.
757 #define GST_ROUND_UP_8(num) (((num)+7)&~7)
760 * @num: integer value to round up
762 * Rounds an integer value up to the next multiple of 16.
764 #define GST_ROUND_UP_16(num) (((num)+15)&~15)
767 * @num: integer value to round up
769 * Rounds an integer value up to the next multiple of 32.
771 #define GST_ROUND_UP_32(num) (((num)+31)&~31)
774 * @num: integer value to round up
776 * Rounds an integer value up to the next multiple of 64.
778 #define GST_ROUND_UP_64(num) (((num)+63)&~63)
781 * @num: integer value to round up
783 * Rounds an integer value up to the next multiple of 128.
786 #define GST_ROUND_UP_128(num) (((num)+127)&~127)
789 * @num: integrer value to round up
790 * @align: a power of two to round up to
792 * Rounds an integer value up to the next multiple of @align. @align MUST be a
795 #define GST_ROUND_UP_N(num,align) ((((num) + ((align) - 1)) & ~((align) - 1)))
800 * @num: integer value to round down
802 * Rounds an integer value down to the next multiple of 2.
804 #define GST_ROUND_DOWN_2(num) ((num)&(~1))
807 * @num: integer value to round down
809 * Rounds an integer value down to the next multiple of 4.
811 #define GST_ROUND_DOWN_4(num) ((num)&(~3))
814 * @num: integer value to round down
816 * Rounds an integer value down to the next multiple of 8.
818 #define GST_ROUND_DOWN_8(num) ((num)&(~7))
821 * @num: integer value to round down
823 * Rounds an integer value down to the next multiple of 16.
825 #define GST_ROUND_DOWN_16(num) ((num)&(~15))
828 * @num: integer value to round down
830 * Rounds an integer value down to the next multiple of 32.
832 #define GST_ROUND_DOWN_32(num) ((num)&(~31))
835 * @num: integer value to round down
837 * Rounds an integer value down to the next multiple of 64.
839 #define GST_ROUND_DOWN_64(num) ((num)&(~63))
841 * GST_ROUND_DOWN_128:
842 * @num: integer value to round down
844 * Rounds an integer value down to the next multiple of 128.
847 #define GST_ROUND_DOWN_128(num) ((num)&(~127))
850 * @num: integrer value to round down
851 * @align: a power of two to round down to
853 * Rounds an integer value down to the next multiple of @align. @align MUST be a
856 #define GST_ROUND_DOWN_N(num,align) (((num) & ~((align) - 1)))
859 void gst_object_default_error (GstObject * source,
860 const GError * error,
861 const gchar * debug);
863 /* element functions */
864 void gst_element_create_all_pads (GstElement *element);
865 GstPad* gst_element_get_compatible_pad (GstElement *element, GstPad *pad,
868 GstPadTemplate* gst_element_get_compatible_pad_template (GstElement *element, GstPadTemplate *compattempl);
870 const gchar* gst_element_state_get_name (GstState state);
871 const gchar * gst_element_state_change_return_get_name (GstStateChangeReturn state_ret);
873 gboolean gst_element_link (GstElement *src, GstElement *dest);
874 gboolean gst_element_link_many (GstElement *element_1,
875 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
876 gboolean gst_element_link_filtered (GstElement * src,
879 void gst_element_unlink (GstElement *src, GstElement *dest);
880 void gst_element_unlink_many (GstElement *element_1,
881 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
883 gboolean gst_element_link_pads (GstElement *src, const gchar *srcpadname,
884 GstElement *dest, const gchar *destpadname);
885 gboolean gst_element_link_pads_full (GstElement *src, const gchar *srcpadname,
886 GstElement *dest, const gchar *destpadname,
887 GstPadLinkCheck flags);
888 void gst_element_unlink_pads (GstElement *src, const gchar *srcpadname,
889 GstElement *dest, const gchar *destpadname);
891 gboolean gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
892 GstElement * dest, const gchar * destpadname,
895 gboolean gst_element_seek_simple (GstElement *element,
897 GstSeekFlags seek_flags,
900 /* util elementfactory functions */
901 gboolean gst_element_factory_can_sink_all_caps (GstElementFactory *factory, const GstCaps *caps);
902 gboolean gst_element_factory_can_src_all_caps (GstElementFactory *factory, const GstCaps *caps);
903 gboolean gst_element_factory_can_sink_any_caps (GstElementFactory *factory, const GstCaps *caps);
904 gboolean gst_element_factory_can_src_any_caps (GstElementFactory *factory, const GstCaps *caps);
906 /* util query functions */
907 gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur);
908 gboolean gst_element_query_duration (GstElement *element, GstFormat format, gint64 *duration);
909 gboolean gst_element_query_convert (GstElement *element, GstFormat src_format, gint64 src_val,
910 GstFormat dest_format, gint64 *dest_val);
913 void gst_pad_use_fixed_caps (GstPad *pad);
914 GstElement* gst_pad_get_parent_element (GstPad *pad);
916 /* util query functions */
917 gboolean gst_pad_proxy_query_accept_caps (GstPad *pad, GstQuery *query);
918 gboolean gst_pad_proxy_query_caps (GstPad *pad, GstQuery *query);
920 gboolean gst_pad_query_position (GstPad *pad, GstFormat format, gint64 *cur);
921 gboolean gst_pad_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
922 gboolean gst_pad_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
923 GstFormat dest_format, gint64 *dest_val);
924 GstCaps * gst_pad_query_caps (GstPad *pad, GstCaps *filter);
925 gboolean gst_pad_query_accept_caps (GstPad *pad, GstCaps *caps);
927 gboolean gst_pad_link_maybe_ghosting_full (GstPad *src,
929 GstPadLinkCheck flags);
931 gboolean gst_pad_peer_query_position (GstPad *pad, GstFormat format, gint64 *cur);
932 gboolean gst_pad_peer_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
933 gboolean gst_pad_peer_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
934 GstFormat dest_format, gint64 *dest_val);
935 GstCaps * gst_pad_peer_query_caps (GstPad * pad, GstCaps *filter);
936 gboolean gst_pad_peer_query_accept_caps (GstPad * pad, GstCaps *caps);
938 gchar * gst_pad_create_stream_id (GstPad * pad, GstElement * parent, const gchar *stream_id) G_GNUC_MALLOC;
939 gchar * gst_pad_create_stream_id_printf (GstPad * pad, GstElement * parent, const gchar *stream_id, ...) G_GNUC_PRINTF (3, 4) G_GNUC_MALLOC;
940 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;
942 gchar * gst_pad_get_stream_id (GstPad * pad);
945 void gst_bin_add_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
946 void gst_bin_remove_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
947 GstPad * gst_bin_find_unlinked_pad (GstBin *bin, GstPadDirection direction);
949 gboolean gst_bin_sync_children_states (GstBin *bin);
951 /* parse utility functions */
952 GstElement * gst_parse_bin_from_description (const gchar * bin_description,
953 gboolean ghost_unlinked_pads,
956 GstElement * gst_parse_bin_from_description_full (const gchar * bin_description,
957 gboolean ghost_unlinked_pads,
958 GstParseContext * context,
962 GstClockTime gst_util_get_timestamp (void);
966 * @GST_SEARCH_MODE_EXACT : Only search for exact matches.
967 * @GST_SEARCH_MODE_BEFORE: Search for an exact match or the element just before.
968 * @GST_SEARCH_MODE_AFTER : Search for an exact match or the element just after.
970 * The different search modes.
973 GST_SEARCH_MODE_EXACT = 0,
974 GST_SEARCH_MODE_BEFORE,
975 GST_SEARCH_MODE_AFTER
978 gpointer gst_util_array_binary_search (gpointer array, guint num_elements,
979 gsize element_size, GCompareDataFunc search_func,
980 GstSearchMode mode, gconstpointer search_data,
983 /* fraction operations */
984 gint gst_util_greatest_common_divisor (gint a, gint b);
985 gint64 gst_util_greatest_common_divisor_int64 (gint64 a, gint64 b);
987 void gst_util_fraction_to_double (gint src_n, gint src_d, gdouble *dest);
988 void gst_util_double_to_fraction (gdouble src, gint *dest_n, gint *dest_d);
990 gboolean gst_util_fraction_multiply (gint a_n, gint a_d, gint b_n, gint b_d,
991 gint *res_n, gint *res_d);
992 gboolean gst_util_fraction_add (gint a_n, gint a_d, gint b_n, gint b_d,
993 gint *res_n, gint *res_d);
994 gint gst_util_fraction_compare (gint a_n, gint a_d, gint b_n, gint b_d);
999 #endif /* __GST_UTILS_H__ */