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*)(v);
121 static inline guint32 __gst_fast_read32(const guint8 *v) {
122 return *(const guint32*)(v);
124 static inline guint64 __gst_fast_read64(const guint8 *v) {
125 return *(const guint64*)(v);
127 static inline guint16 __gst_fast_read_swap16(const guint8 *v) {
128 return GUINT16_SWAP_LE_BE(*(const guint16*)(v));
130 static inline guint32 __gst_fast_read_swap32(const guint8 *v) {
131 return GUINT32_SWAP_LE_BE(*(const guint32*)(v));
133 static inline guint64 __gst_fast_read_swap64(const guint8 *v) {
134 return GUINT64_SWAP_LE_BE(*(const guint64*)(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.
454 #ifdef _FOOL_GTK_DOC_
455 G_INLINE_FUNC gfloat GFLOAT_SWAP_LE_BE (gfloat in);
459 GFLOAT_SWAP_LE_BE(gfloat in)
468 u.i = GUINT32_SWAP_LE_BE (u.i);
473 * GDOUBLE_SWAP_LE_BE:
476 * Swap byte order of a 64-bit floating point value (double).
478 * Returns: @in byte-swapped.
480 #ifdef _FOOL_GTK_DOC_
481 G_INLINE_FUNC gdouble GDOUBLE_SWAP_LE_BE (gdouble in);
484 inline static gdouble
485 GDOUBLE_SWAP_LE_BE(gdouble in)
494 u.i = GUINT64_SWAP_LE_BE (u.i);
502 * Convert 64-bit floating point value (double) from native byte order into
503 * little endian byte order.
509 * Convert 64-bit floating point value (double) from native byte order into
510 * big endian byte order.
516 * Convert 64-bit floating point value (double) from little endian byte order
517 * into native byte order.
523 * Convert 64-bit floating point value (double) from big endian byte order
524 * into native byte order.
531 * Convert 32-bit floating point value (float) from native byte order into
532 * little endian byte order.
538 * Convert 32-bit floating point value (float) from native byte order into
539 * big endian byte order.
545 * Convert 32-bit floating point value (float) from little endian byte order
546 * into native byte order.
552 * Convert 32-bit floating point value (float) from big endian byte order
553 * into native byte order.
556 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
557 #define GFLOAT_TO_LE(val) ((gfloat) (val))
558 #define GFLOAT_TO_BE(val) (GFLOAT_SWAP_LE_BE (val))
559 #define GDOUBLE_TO_LE(val) ((gdouble) (val))
560 #define GDOUBLE_TO_BE(val) (GDOUBLE_SWAP_LE_BE (val))
562 #elif G_BYTE_ORDER == G_BIG_ENDIAN
563 #define GFLOAT_TO_LE(val) (GFLOAT_SWAP_LE_BE (val))
564 #define GFLOAT_TO_BE(val) ((gfloat) (val))
565 #define GDOUBLE_TO_LE(val) (GDOUBLE_SWAP_LE_BE (val))
566 #define GDOUBLE_TO_BE(val) ((gdouble) (val))
568 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
569 #error unknown ENDIAN type
570 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
572 #define GFLOAT_FROM_LE(val) (GFLOAT_TO_LE (val))
573 #define GFLOAT_FROM_BE(val) (GFLOAT_TO_BE (val))
574 #define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val))
575 #define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
577 #endif /* !defined(GFLOAT_FROM_LE) */
581 * @data: memory location
583 * Read a 32 bit float value in little endian format from the memory buffer.
585 * Returns: The floating point value read from @data
587 #ifdef _FOOL_GTK_DOC_
588 G_INLINE_FUNC gfloat GST_READ_FLOAT_LE (const guint8 *data);
592 GST_READ_FLOAT_LE(const guint8 *data)
600 u.i = GST_READ_UINT32_LE (data);
606 * @data: memory location
608 * Read a 32 bit float value in big endian format from the memory buffer.
610 * Returns: The floating point value read from @data
612 #ifdef _FOOL_GTK_DOC_
613 G_INLINE_FUNC gfloat GST_READ_FLOAT_BE (const guint8 *data);
617 GST_READ_FLOAT_BE(const guint8 *data)
625 u.i = GST_READ_UINT32_BE (data);
630 * GST_READ_DOUBLE_LE:
631 * @data: memory location
633 * Read a 64 bit double value in little endian format from the memory buffer.
635 * Returns: The double-precision floating point value read from @data
637 #ifdef _FOOL_GTK_DOC_
638 G_INLINE_FUNC gdouble GST_READ_DOUBLE_LE (const guint8 *data);
641 inline static gdouble
642 GST_READ_DOUBLE_LE(const guint8 *data)
650 u.i = GST_READ_UINT64_LE (data);
655 * GST_READ_DOUBLE_BE:
656 * @data: memory location
658 * Read a 64 bit double value in big endian format from the memory buffer.
660 * Returns: The double-precision floating point value read from @data
662 #ifdef _FOOL_GTK_DOC_
663 G_INLINE_FUNC gdouble GST_READ_DOUBLE_BE (const guint8 *data);
666 inline static gdouble
667 GST_READ_DOUBLE_BE(const guint8 *data)
675 u.i = GST_READ_UINT64_BE (data);
680 * GST_WRITE_FLOAT_LE:
681 * @data: memory location
682 * @num: value to store
684 * Store a 32 bit float value in little endian format into the memory buffer.
686 #ifdef _FOOL_GTK_DOC_
687 G_INLINE_FUNC void GST_WRITE_FLOAT_LE (guint8 *data, gfloat num);
691 GST_WRITE_FLOAT_LE(guint8 *data, gfloat num)
700 GST_WRITE_UINT32_LE (data, u.i);
704 * GST_WRITE_FLOAT_BE:
705 * @data: memory location
706 * @num: value to store
708 * Store a 32 bit float value in big endian format into the memory buffer.
710 #ifdef _FOOL_GTK_DOC_
711 G_INLINE_FUNC void GST_WRITE_FLOAT_BE (guint8 *data, gfloat num);
715 GST_WRITE_FLOAT_BE(guint8 *data, gfloat num)
724 GST_WRITE_UINT32_BE (data, u.i);
728 * GST_WRITE_DOUBLE_LE:
729 * @data: memory location
730 * @num: value to store
732 * Store a 64 bit double value in little endian format into the memory buffer.
734 #ifdef _FOOL_GTK_DOC_
735 G_INLINE_FUNC void GST_WRITE_DOUBLE_LE (guint8 *data, gdouble num);
739 GST_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
748 GST_WRITE_UINT64_LE (data, u.i);
752 * GST_WRITE_DOUBLE_BE:
753 * @data: memory location
754 * @num: value to store
756 * Store a 64 bit double value in big endian format into the memory buffer.
758 #ifdef _FOOL_GTK_DOC_
759 G_INLINE_FUNC void GST_WRITE_DOUBLE_BE (guint8 *data, gdouble num);
763 GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
772 GST_WRITE_UINT64_BE (data, u.i);
775 /* Miscellaneous utility macros */
779 * @num: integer value to round up
781 * Rounds an integer value up to the next multiple of 2.
783 #define GST_ROUND_UP_2(num) (((num)+1)&~1)
786 * @num: integer value to round up
788 * Rounds an integer value up to the next multiple of 4.
790 #define GST_ROUND_UP_4(num) (((num)+3)&~3)
793 * @num: integer value to round up
795 * Rounds an integer value up to the next multiple of 8.
797 #define GST_ROUND_UP_8(num) (((num)+7)&~7)
800 * @num: integer value to round up
802 * Rounds an integer value up to the next multiple of 16.
804 #define GST_ROUND_UP_16(num) (((num)+15)&~15)
807 * @num: integer value to round up
809 * Rounds an integer value up to the next multiple of 32.
811 #define GST_ROUND_UP_32(num) (((num)+31)&~31)
814 * @num: integer value to round up
816 * Rounds an integer value up to the next multiple of 64.
818 #define GST_ROUND_UP_64(num) (((num)+63)&~63)
821 * @num: integer value to round up
823 * Rounds an integer value up to the next multiple of 128.
826 #define GST_ROUND_UP_128(num) (((num)+127)&~127)
829 * @num: integrer value to round up
830 * @align: a power of two to round up to
832 * Rounds an integer value up to the next multiple of @align. @align MUST be a
835 #define GST_ROUND_UP_N(num,align) ((((num) + ((align) - 1)) & ~((align) - 1)))
840 * @num: integer value to round down
842 * Rounds an integer value down to the next multiple of 2.
844 #define GST_ROUND_DOWN_2(num) ((num)&(~1))
847 * @num: integer value to round down
849 * Rounds an integer value down to the next multiple of 4.
851 #define GST_ROUND_DOWN_4(num) ((num)&(~3))
854 * @num: integer value to round down
856 * Rounds an integer value down to the next multiple of 8.
858 #define GST_ROUND_DOWN_8(num) ((num)&(~7))
861 * @num: integer value to round down
863 * Rounds an integer value down to the next multiple of 16.
865 #define GST_ROUND_DOWN_16(num) ((num)&(~15))
868 * @num: integer value to round down
870 * Rounds an integer value down to the next multiple of 32.
872 #define GST_ROUND_DOWN_32(num) ((num)&(~31))
875 * @num: integer value to round down
877 * Rounds an integer value down to the next multiple of 64.
879 #define GST_ROUND_DOWN_64(num) ((num)&(~63))
881 * GST_ROUND_DOWN_128:
882 * @num: integer value to round down
884 * Rounds an integer value down to the next multiple of 128.
887 #define GST_ROUND_DOWN_128(num) ((num)&(~127))
890 * @num: integrer value to round down
891 * @align: a power of two to round down to
893 * Rounds an integer value down to the next multiple of @align. @align MUST be a
896 #define GST_ROUND_DOWN_N(num,align) (((num) & ~((align) - 1)))
899 void gst_object_default_error (GstObject * source,
900 const GError * error,
901 const gchar * debug);
903 /* element functions */
904 void gst_element_create_all_pads (GstElement *element);
905 GstPad* gst_element_get_compatible_pad (GstElement *element, GstPad *pad,
908 GstPadTemplate* gst_element_get_compatible_pad_template (GstElement *element, GstPadTemplate *compattempl);
910 const gchar* gst_element_state_get_name (GstState state);
911 const gchar * gst_element_state_change_return_get_name (GstStateChangeReturn state_ret);
913 gboolean gst_element_link (GstElement *src, GstElement *dest);
914 gboolean gst_element_link_many (GstElement *element_1,
915 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
916 gboolean gst_element_link_filtered (GstElement * src,
919 void gst_element_unlink (GstElement *src, GstElement *dest);
920 void gst_element_unlink_many (GstElement *element_1,
921 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
923 gboolean gst_element_link_pads (GstElement *src, const gchar *srcpadname,
924 GstElement *dest, const gchar *destpadname);
925 gboolean gst_element_link_pads_full (GstElement *src, const gchar *srcpadname,
926 GstElement *dest, const gchar *destpadname,
927 GstPadLinkCheck flags);
928 void gst_element_unlink_pads (GstElement *src, const gchar *srcpadname,
929 GstElement *dest, const gchar *destpadname);
931 gboolean gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
932 GstElement * dest, const gchar * destpadname,
935 gboolean gst_element_seek_simple (GstElement *element,
937 GstSeekFlags seek_flags,
940 /* util elementfactory functions */
941 gboolean gst_element_factory_can_sink_all_caps (GstElementFactory *factory, const GstCaps *caps);
942 gboolean gst_element_factory_can_src_all_caps (GstElementFactory *factory, const GstCaps *caps);
943 gboolean gst_element_factory_can_sink_any_caps (GstElementFactory *factory, const GstCaps *caps);
944 gboolean gst_element_factory_can_src_any_caps (GstElementFactory *factory, const GstCaps *caps);
946 /* util query functions */
947 gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur);
948 gboolean gst_element_query_duration (GstElement *element, GstFormat format, gint64 *duration);
949 gboolean gst_element_query_convert (GstElement *element, GstFormat src_format, gint64 src_val,
950 GstFormat dest_format, gint64 *dest_val);
951 #ifdef TIZEN_PROFILE_TV
952 gboolean gst_element_query_resource (GstElement *element, GList **resource_list);
957 void gst_pad_use_fixed_caps (GstPad *pad);
958 GstElement* gst_pad_get_parent_element (GstPad *pad);
960 /* util query functions */
961 gboolean gst_pad_proxy_query_accept_caps (GstPad *pad, GstQuery *query);
962 gboolean gst_pad_proxy_query_caps (GstPad *pad, GstQuery *query);
964 gboolean gst_pad_query_position (GstPad *pad, GstFormat format, gint64 *cur);
965 gboolean gst_pad_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
966 gboolean gst_pad_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
967 GstFormat dest_format, gint64 *dest_val);
968 GstCaps * gst_pad_query_caps (GstPad *pad, GstCaps *filter);
969 gboolean gst_pad_query_accept_caps (GstPad *pad, GstCaps *caps);
972 gboolean gst_pad_peer_query_position (GstPad *pad, GstFormat format, gint64 *cur);
973 gboolean gst_pad_peer_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
974 gboolean gst_pad_peer_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
975 GstFormat dest_format, gint64 *dest_val);
976 GstCaps * gst_pad_peer_query_caps (GstPad * pad, GstCaps *filter);
977 gboolean gst_pad_peer_query_accept_caps (GstPad * pad, GstCaps *caps);
979 gchar * gst_pad_create_stream_id (GstPad * pad, GstElement * parent, const gchar *stream_id) G_GNUC_MALLOC;
980 gchar * gst_pad_create_stream_id_printf (GstPad * pad, GstElement * parent, const gchar *stream_id, ...) G_GNUC_PRINTF (3, 4) G_GNUC_MALLOC;
981 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;
983 gchar * gst_pad_get_stream_id (GstPad * pad);
986 void gst_bin_add_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
987 void gst_bin_remove_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
988 GstPad * gst_bin_find_unlinked_pad (GstBin *bin, GstPadDirection direction);
990 gboolean gst_bin_sync_children_states (GstBin *bin);
992 /* parse utility functions */
993 GstElement * gst_parse_bin_from_description (const gchar * bin_description,
994 gboolean ghost_unlinked_pads,
997 GstElement * gst_parse_bin_from_description_full (const gchar * bin_description,
998 gboolean ghost_unlinked_pads,
999 GstParseContext * context,
1000 GstParseFlags flags,
1003 GstClockTime gst_util_get_timestamp (void);
1007 * @GST_SEARCH_MODE_EXACT : Only search for exact matches.
1008 * @GST_SEARCH_MODE_BEFORE: Search for an exact match or the element just before.
1009 * @GST_SEARCH_MODE_AFTER : Search for an exact match or the element just after.
1011 * The different search modes.
1014 GST_SEARCH_MODE_EXACT = 0,
1015 GST_SEARCH_MODE_BEFORE,
1016 GST_SEARCH_MODE_AFTER
1019 gpointer gst_util_array_binary_search (gpointer array, guint num_elements,
1020 gsize element_size, GCompareDataFunc search_func,
1021 GstSearchMode mode, gconstpointer search_data,
1022 gpointer user_data);
1024 /* fraction operations */
1025 gint gst_util_greatest_common_divisor (gint a, gint b);
1026 gint64 gst_util_greatest_common_divisor_int64 (gint64 a, gint64 b);
1028 void gst_util_fraction_to_double (gint src_n, gint src_d, gdouble *dest);
1029 void gst_util_double_to_fraction (gdouble src, gint *dest_n, gint *dest_d);
1031 gboolean gst_util_fraction_multiply (gint a_n, gint a_d, gint b_n, gint b_d,
1032 gint *res_n, gint *res_d);
1033 gboolean gst_util_fraction_add (gint a_n, gint a_d, gint b_n, gint b_d,
1034 gint *res_n, gint *res_d);
1035 gint gst_util_fraction_compare (gint a_n, gint a_d, gint b_n, gint b_d);
1037 #ifdef TIZEN_PROFILE_TV
1038 void gst_set_family_id_to_child (GstElement* child, int id);
1042 #endif /* __GST_UTILS_H__ */