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))
139 static inline void __gst_fast_write16 (guint8 *p, guint16 v) {
140 *(guint16*)(void*)(p) = v;
142 static inline void __gst_fast_write32 (guint8 *p, guint32 v) {
143 *(guint32*)(void*)(p) = v;
145 static inline void __gst_fast_write64 (guint8 *p, guint64 v) {
146 *(guint64*)(void*)(p) = v;
148 static inline void __gst_fast_write_swap16 (guint8 *p, guint16 v) {
149 *(guint16*)(void*)(p) = GUINT16_SWAP_LE_BE (v);
151 static inline void __gst_fast_write_swap32 (guint8 *p, guint32 v) {
152 *(guint32*)(void*)(p) = GUINT32_SWAP_LE_BE (v);
154 static inline void __gst_fast_write_swap64 (guint8 *p, guint64 v) {
155 *(guint64*)(void*)(p) = GUINT64_SWAP_LE_BE (v);
157 # define _GST_FAST_WRITE(s, d, v) __gst_fast_write##s((guint8 *)(d), (v))
158 # define _GST_FAST_WRITE_SWAP(s, d, v) __gst_fast_write_swap##s((guint8 *)(d), (v))
164 * GST_READ_UINT64_BE:
165 * @data: memory location
167 * Read a 64 bit unsigned integer value in big endian format from the memory buffer.
171 * GST_READ_UINT64_LE:
172 * @data: memory location
174 * Read a 64 bit unsigned integer value in little endian format from the memory buffer.
176 #if GST_HAVE_UNALIGNED_ACCESS
177 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
178 # define GST_READ_UINT64_BE(data) _GST_FAST_READ (64, data)
179 # define GST_READ_UINT64_LE(data) _GST_FAST_READ_SWAP (64, data)
181 # define GST_READ_UINT64_BE(data) _GST_FAST_READ_SWAP (64, data)
182 # define GST_READ_UINT64_LE(data) _GST_FAST_READ (64, data)
185 #define _GST_READ_UINT64_BE(data) (_GST_GET (data, 0, 64, 56) | \
186 _GST_GET (data, 1, 64, 48) | \
187 _GST_GET (data, 2, 64, 40) | \
188 _GST_GET (data, 3, 64, 32) | \
189 _GST_GET (data, 4, 64, 24) | \
190 _GST_GET (data, 5, 64, 16) | \
191 _GST_GET (data, 6, 64, 8) | \
192 _GST_GET (data, 7, 64, 0))
194 #define _GST_READ_UINT64_LE(data) (_GST_GET (data, 7, 64, 56) | \
195 _GST_GET (data, 6, 64, 48) | \
196 _GST_GET (data, 5, 64, 40) | \
197 _GST_GET (data, 4, 64, 32) | \
198 _GST_GET (data, 3, 64, 24) | \
199 _GST_GET (data, 2, 64, 16) | \
200 _GST_GET (data, 1, 64, 8) | \
201 _GST_GET (data, 0, 64, 0))
203 #define GST_READ_UINT64_BE(data) __gst_slow_read64_be((const guint8 *)(data))
204 static inline guint64 __gst_slow_read64_be (const guint8 * data) {
205 return _GST_READ_UINT64_BE (data);
207 #define GST_READ_UINT64_LE(data) __gst_slow_read64_le((const guint8 *)(data))
208 static inline guint64 __gst_slow_read64_le (const guint8 * data) {
209 return _GST_READ_UINT64_LE (data);
214 * GST_READ_UINT32_BE:
215 * @data: memory location
217 * Read a 32 bit unsigned integer value in big endian format from the memory buffer.
221 * GST_READ_UINT32_LE:
222 * @data: memory location
224 * Read a 32 bit unsigned integer value in little endian format from the memory buffer.
226 #if GST_HAVE_UNALIGNED_ACCESS
227 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
228 # define GST_READ_UINT32_BE(data) _GST_FAST_READ (32, data)
229 # define GST_READ_UINT32_LE(data) _GST_FAST_READ_SWAP (32, data)
231 # define GST_READ_UINT32_BE(data) _GST_FAST_READ_SWAP (32, data)
232 # define GST_READ_UINT32_LE(data) _GST_FAST_READ (32, data)
235 #define _GST_READ_UINT32_BE(data) (_GST_GET (data, 0, 32, 24) | \
236 _GST_GET (data, 1, 32, 16) | \
237 _GST_GET (data, 2, 32, 8) | \
238 _GST_GET (data, 3, 32, 0))
240 #define _GST_READ_UINT32_LE(data) (_GST_GET (data, 3, 32, 24) | \
241 _GST_GET (data, 2, 32, 16) | \
242 _GST_GET (data, 1, 32, 8) | \
243 _GST_GET (data, 0, 32, 0))
245 #define GST_READ_UINT32_BE(data) __gst_slow_read32_be((const guint8 *)(data))
246 static inline guint32 __gst_slow_read32_be (const guint8 * data) {
247 return _GST_READ_UINT32_BE (data);
249 #define GST_READ_UINT32_LE(data) __gst_slow_read32_le((const guint8 *)(data))
250 static inline guint32 __gst_slow_read32_le (const guint8 * data) {
251 return _GST_READ_UINT32_LE (data);
256 * GST_READ_UINT24_BE:
257 * @data: memory location
259 * Read a 24 bit unsigned integer value in big endian format from the memory buffer.
261 #define _GST_READ_UINT24_BE(data) (_GST_GET (data, 0, 32, 16) | \
262 _GST_GET (data, 1, 32, 8) | \
263 _GST_GET (data, 2, 32, 0))
265 #define GST_READ_UINT24_BE(data) __gst_slow_read24_be((const guint8 *)(data))
266 static inline guint32 __gst_slow_read24_be (const guint8 * data) {
267 return _GST_READ_UINT24_BE (data);
271 * GST_READ_UINT24_LE:
272 * @data: memory location
274 * Read a 24 bit unsigned integer value in little endian format from the memory buffer.
276 #define _GST_READ_UINT24_LE(data) (_GST_GET (data, 2, 32, 16) | \
277 _GST_GET (data, 1, 32, 8) | \
278 _GST_GET (data, 0, 32, 0))
280 #define GST_READ_UINT24_LE(data) __gst_slow_read24_le((const guint8 *)(data))
281 static inline guint32 __gst_slow_read24_le (const guint8 * data) {
282 return _GST_READ_UINT24_LE (data);
286 * GST_READ_UINT16_BE:
287 * @data: memory location
289 * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
292 * GST_READ_UINT16_LE:
293 * @data: memory location
295 * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
297 #if GST_HAVE_UNALIGNED_ACCESS
298 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
299 # define GST_READ_UINT16_BE(data) _GST_FAST_READ (16, data)
300 # define GST_READ_UINT16_LE(data) _GST_FAST_READ_SWAP (16, data)
302 # define GST_READ_UINT16_BE(data) _GST_FAST_READ_SWAP (16, data)
303 # define GST_READ_UINT16_LE(data) _GST_FAST_READ (16, data)
306 #define _GST_READ_UINT16_BE(data) (_GST_GET (data, 0, 16, 8) | \
307 _GST_GET (data, 1, 16, 0))
309 #define _GST_READ_UINT16_LE(data) (_GST_GET (data, 1, 16, 8) | \
310 _GST_GET (data, 0, 16, 0))
312 #define GST_READ_UINT16_BE(data) __gst_slow_read16_be((const guint8 *)(data))
313 static inline guint16 __gst_slow_read16_be (const guint8 * data) {
314 return _GST_READ_UINT16_BE (data);
316 #define GST_READ_UINT16_LE(data) __gst_slow_read16_le((const guint8 *)(data))
317 static inline guint16 __gst_slow_read16_le (const guint8 * data) {
318 return _GST_READ_UINT16_LE (data);
324 * @data: memory location
326 * Read an 8 bit unsigned integer value from the memory buffer.
328 #define GST_READ_UINT8(data) (_GST_GET (data, 0, 8, 0))
331 * GST_WRITE_UINT64_BE:
332 * @data: memory location
333 * @val: value to store
335 * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
338 * GST_WRITE_UINT64_LE:
339 * @data: memory location
340 * @val: value to store
342 * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
344 #if GST_HAVE_UNALIGNED_ACCESS
345 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
346 # define GST_WRITE_UINT64_BE(data,val) _GST_FAST_WRITE(64,data,val)
347 # define GST_WRITE_UINT64_LE(data,val) _GST_FAST_WRITE_SWAP(64,data,val)
349 # define GST_WRITE_UINT64_BE(data,val) _GST_FAST_WRITE_SWAP(64,data,val)
350 # define GST_WRITE_UINT64_LE(data,val) _GST_FAST_WRITE(64,data,val)
353 #define GST_WRITE_UINT64_BE(data,val) do { \
354 gpointer __put_data = data; \
355 guint64 __put_val = val; \
356 _GST_PUT (__put_data, 0, 64, 56, __put_val); \
357 _GST_PUT (__put_data, 1, 64, 48, __put_val); \
358 _GST_PUT (__put_data, 2, 64, 40, __put_val); \
359 _GST_PUT (__put_data, 3, 64, 32, __put_val); \
360 _GST_PUT (__put_data, 4, 64, 24, __put_val); \
361 _GST_PUT (__put_data, 5, 64, 16, __put_val); \
362 _GST_PUT (__put_data, 6, 64, 8, __put_val); \
363 _GST_PUT (__put_data, 7, 64, 0, __put_val); \
366 #define GST_WRITE_UINT64_LE(data,val) do { \
367 gpointer __put_data = data; \
368 guint64 __put_val = val; \
369 _GST_PUT (__put_data, 0, 64, 0, __put_val); \
370 _GST_PUT (__put_data, 1, 64, 8, __put_val); \
371 _GST_PUT (__put_data, 2, 64, 16, __put_val); \
372 _GST_PUT (__put_data, 3, 64, 24, __put_val); \
373 _GST_PUT (__put_data, 4, 64, 32, __put_val); \
374 _GST_PUT (__put_data, 5, 64, 40, __put_val); \
375 _GST_PUT (__put_data, 6, 64, 48, __put_val); \
376 _GST_PUT (__put_data, 7, 64, 56, __put_val); \
378 #endif /* !GST_HAVE_UNALIGNED_ACCESS */
381 * GST_WRITE_UINT32_BE:
382 * @data: memory location
383 * @val: value to store
385 * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
388 * GST_WRITE_UINT32_LE:
389 * @data: memory location
390 * @val: value to store
392 * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
394 #if GST_HAVE_UNALIGNED_ACCESS
395 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
396 # define GST_WRITE_UINT32_BE(data,val) _GST_FAST_WRITE(32,data,val)
397 # define GST_WRITE_UINT32_LE(data,val) _GST_FAST_WRITE_SWAP(32,data,val)
399 # define GST_WRITE_UINT32_BE(data,val) _GST_FAST_WRITE_SWAP(32,data,val)
400 # define GST_WRITE_UINT32_LE(data,val) _GST_FAST_WRITE(32,data,val)
403 #define GST_WRITE_UINT32_BE(data,val) do { \
404 gpointer __put_data = data; \
405 guint32 __put_val = val; \
406 _GST_PUT (__put_data, 0, 32, 24, __put_val); \
407 _GST_PUT (__put_data, 1, 32, 16, __put_val); \
408 _GST_PUT (__put_data, 2, 32, 8, __put_val); \
409 _GST_PUT (__put_data, 3, 32, 0, __put_val); \
412 #define GST_WRITE_UINT32_LE(data,val) do { \
413 gpointer __put_data = data; \
414 guint32 __put_val = val; \
415 _GST_PUT (__put_data, 0, 32, 0, __put_val); \
416 _GST_PUT (__put_data, 1, 32, 8, __put_val); \
417 _GST_PUT (__put_data, 2, 32, 16, __put_val); \
418 _GST_PUT (__put_data, 3, 32, 24, __put_val); \
420 #endif /* !GST_HAVE_UNALIGNED_ACCESS */
423 * GST_WRITE_UINT24_BE:
424 * @data: memory location
425 * @num: value to store
427 * Store a 24 bit unsigned integer value in big endian format into the memory buffer.
429 #define GST_WRITE_UINT24_BE(data, num) do { \
430 gpointer __put_data = data; \
431 guint32 __put_val = num; \
432 _GST_PUT (__put_data, 0, 32, 16, __put_val); \
433 _GST_PUT (__put_data, 1, 32, 8, __put_val); \
434 _GST_PUT (__put_data, 2, 32, 0, __put_val); \
438 * GST_WRITE_UINT24_LE:
439 * @data: memory location
440 * @num: value to store
442 * Store a 24 bit unsigned integer value in little endian format into the memory buffer.
444 #define GST_WRITE_UINT24_LE(data, num) do { \
445 gpointer __put_data = data; \
446 guint32 __put_val = num; \
447 _GST_PUT (__put_data, 0, 32, 0, __put_val); \
448 _GST_PUT (__put_data, 1, 32, 8, __put_val); \
449 _GST_PUT (__put_data, 2, 32, 16, __put_val); \
453 * GST_WRITE_UINT16_BE:
454 * @data: memory location
455 * @val: value to store
457 * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
460 * GST_WRITE_UINT16_LE:
461 * @data: memory location
462 * @val: value to store
464 * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
466 #if GST_HAVE_UNALIGNED_ACCESS
467 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
468 # define GST_WRITE_UINT16_BE(data,val) _GST_FAST_WRITE(16,data,val)
469 # define GST_WRITE_UINT16_LE(data,val) _GST_FAST_WRITE_SWAP(16,data,val)
471 # define GST_WRITE_UINT16_BE(data,val) _GST_FAST_WRITE_SWAP(16,data,val)
472 # define GST_WRITE_UINT16_LE(data,val) _GST_FAST_WRITE(16,data,val)
475 #define GST_WRITE_UINT16_BE(data,val) do { \
476 gpointer __put_data = data; \
477 guint16 __put_val = val; \
478 _GST_PUT (__put_data, 0, 16, 8, __put_val); \
479 _GST_PUT (__put_data, 1, 16, 0, __put_val); \
482 #define GST_WRITE_UINT16_LE(data,val) do { \
483 gpointer __put_data = data; \
484 guint16 __put_val = val; \
485 _GST_PUT (__put_data, 0, 16, 0, __put_val); \
486 _GST_PUT (__put_data, 1, 16, 8, __put_val); \
488 #endif /* !GST_HAVE_UNALIGNED_ACCESS */
492 * @data: memory location
493 * @num: value to store
495 * Store an 8 bit unsigned integer value into the memory buffer.
497 #define GST_WRITE_UINT8(data, num) do { \
498 _GST_PUT (data, 0, 8, 0, num); \
501 /* Float endianness conversion macros */
503 /* FIXME: Remove this once we depend on a GLib version with this */
504 #ifndef GFLOAT_FROM_LE
509 * Swap byte order of a 32-bit floating point value (float).
511 * Returns: @in byte-swapped.
514 GFLOAT_SWAP_LE_BE(gfloat in)
523 u.i = GUINT32_SWAP_LE_BE (u.i);
528 * GDOUBLE_SWAP_LE_BE:
531 * Swap byte order of a 64-bit floating point value (double).
533 * Returns: @in byte-swapped.
535 static inline gdouble
536 GDOUBLE_SWAP_LE_BE(gdouble in)
545 u.i = GUINT64_SWAP_LE_BE (u.i);
553 * Convert 64-bit floating point value (double) from native byte order into
554 * little endian byte order.
560 * Convert 64-bit floating point value (double) from native byte order into
561 * big endian byte order.
567 * Convert 64-bit floating point value (double) from little endian byte order
568 * into native byte order.
574 * Convert 64-bit floating point value (double) from big endian byte order
575 * into native byte order.
582 * Convert 32-bit floating point value (float) from native byte order into
583 * little endian byte order.
589 * Convert 32-bit floating point value (float) from native byte order into
590 * big endian byte order.
596 * Convert 32-bit floating point value (float) from little endian byte order
597 * into native byte order.
603 * Convert 32-bit floating point value (float) from big endian byte order
604 * into native byte order.
607 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
608 #define GFLOAT_TO_LE(val) ((gfloat) (val))
609 #define GFLOAT_TO_BE(val) (GFLOAT_SWAP_LE_BE (val))
610 #define GDOUBLE_TO_LE(val) ((gdouble) (val))
611 #define GDOUBLE_TO_BE(val) (GDOUBLE_SWAP_LE_BE (val))
613 #elif G_BYTE_ORDER == G_BIG_ENDIAN
614 #define GFLOAT_TO_LE(val) (GFLOAT_SWAP_LE_BE (val))
615 #define GFLOAT_TO_BE(val) ((gfloat) (val))
616 #define GDOUBLE_TO_LE(val) (GDOUBLE_SWAP_LE_BE (val))
617 #define GDOUBLE_TO_BE(val) ((gdouble) (val))
619 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
620 #error unknown ENDIAN type
621 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
623 #define GFLOAT_FROM_LE(val) (GFLOAT_TO_LE (val))
624 #define GFLOAT_FROM_BE(val) (GFLOAT_TO_BE (val))
625 #define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val))
626 #define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
628 #endif /* !defined(GFLOAT_FROM_LE) */
632 * @data: memory location
634 * Read a 32 bit float value in little endian format from the memory buffer.
636 * Returns: The floating point value read from @data
639 GST_READ_FLOAT_LE(const guint8 *data)
647 u.i = GST_READ_UINT32_LE (data);
653 * @data: memory location
655 * Read a 32 bit float value in big endian format from the memory buffer.
657 * Returns: The floating point value read from @data
660 GST_READ_FLOAT_BE(const guint8 *data)
668 u.i = GST_READ_UINT32_BE (data);
673 * GST_READ_DOUBLE_LE:
674 * @data: memory location
676 * Read a 64 bit double value in little endian format from the memory buffer.
678 * Returns: The double-precision floating point value read from @data
680 static inline gdouble
681 GST_READ_DOUBLE_LE(const guint8 *data)
689 u.i = GST_READ_UINT64_LE (data);
694 * GST_READ_DOUBLE_BE:
695 * @data: memory location
697 * Read a 64 bit double value in big endian format from the memory buffer.
699 * Returns: The double-precision floating point value read from @data
701 static inline gdouble
702 GST_READ_DOUBLE_BE(const guint8 *data)
710 u.i = GST_READ_UINT64_BE (data);
715 * GST_WRITE_FLOAT_LE:
716 * @data: memory location
717 * @num: value to store
719 * Store a 32 bit float value in little endian format into the memory buffer.
722 GST_WRITE_FLOAT_LE(guint8 *data, gfloat num)
731 GST_WRITE_UINT32_LE (data, u.i);
735 * GST_WRITE_FLOAT_BE:
736 * @data: memory location
737 * @num: value to store
739 * Store a 32 bit float value in big endian format into the memory buffer.
742 GST_WRITE_FLOAT_BE(guint8 *data, gfloat num)
751 GST_WRITE_UINT32_BE (data, u.i);
755 * GST_WRITE_DOUBLE_LE:
756 * @data: memory location
757 * @num: value to store
759 * Store a 64 bit double value in little endian format into the memory buffer.
762 GST_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
771 GST_WRITE_UINT64_LE (data, u.i);
775 * GST_WRITE_DOUBLE_BE:
776 * @data: memory location
777 * @num: value to store
779 * Store a 64 bit double value in big endian format into the memory buffer.
782 GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
791 GST_WRITE_UINT64_BE (data, u.i);
794 /* Miscellaneous utility macros */
798 * @num: integer value to round up
800 * Rounds an integer value up to the next multiple of 2.
802 #define GST_ROUND_UP_2(num) (((num)+1)&~1)
805 * @num: integer value to round up
807 * Rounds an integer value up to the next multiple of 4.
809 #define GST_ROUND_UP_4(num) (((num)+3)&~3)
812 * @num: integer value to round up
814 * Rounds an integer value up to the next multiple of 8.
816 #define GST_ROUND_UP_8(num) (((num)+7)&~7)
819 * @num: integer value to round up
821 * Rounds an integer value up to the next multiple of 16.
823 #define GST_ROUND_UP_16(num) (((num)+15)&~15)
826 * @num: integer value to round up
828 * Rounds an integer value up to the next multiple of 32.
830 #define GST_ROUND_UP_32(num) (((num)+31)&~31)
833 * @num: integer value to round up
835 * Rounds an integer value up to the next multiple of 64.
837 #define GST_ROUND_UP_64(num) (((num)+63)&~63)
840 * @num: integer value to round up
842 * Rounds an integer value up to the next multiple of 128.
845 #define GST_ROUND_UP_128(num) (((num)+127)&~127)
848 * @num: integrer value to round up
849 * @align: a power of two to round up to
851 * Rounds an integer value up to the next multiple of @align. @align MUST be a
854 #define GST_ROUND_UP_N(num,align) ((((num) + ((align) - 1)) & ~((align) - 1)))
859 * @num: integer value to round down
861 * Rounds an integer value down to the next multiple of 2.
863 #define GST_ROUND_DOWN_2(num) ((num)&(~1))
866 * @num: integer value to round down
868 * Rounds an integer value down to the next multiple of 4.
870 #define GST_ROUND_DOWN_4(num) ((num)&(~3))
873 * @num: integer value to round down
875 * Rounds an integer value down to the next multiple of 8.
877 #define GST_ROUND_DOWN_8(num) ((num)&(~7))
880 * @num: integer value to round down
882 * Rounds an integer value down to the next multiple of 16.
884 #define GST_ROUND_DOWN_16(num) ((num)&(~15))
887 * @num: integer value to round down
889 * Rounds an integer value down to the next multiple of 32.
891 #define GST_ROUND_DOWN_32(num) ((num)&(~31))
894 * @num: integer value to round down
896 * Rounds an integer value down to the next multiple of 64.
898 #define GST_ROUND_DOWN_64(num) ((num)&(~63))
900 * GST_ROUND_DOWN_128:
901 * @num: integer value to round down
903 * Rounds an integer value down to the next multiple of 128.
906 #define GST_ROUND_DOWN_128(num) ((num)&(~127))
909 * @num: integrer value to round down
910 * @align: a power of two to round down to
912 * Rounds an integer value down to the next multiple of @align. @align MUST be a
915 #define GST_ROUND_DOWN_N(num,align) (((num) & ~((align) - 1)))
918 void gst_object_default_error (GstObject * source,
919 const GError * error,
920 const gchar * debug);
922 /* element functions */
923 void gst_element_create_all_pads (GstElement *element);
924 GstPad* gst_element_get_compatible_pad (GstElement *element, GstPad *pad,
927 GstPadTemplate* gst_element_get_compatible_pad_template (GstElement *element, GstPadTemplate *compattempl);
929 const gchar* gst_element_state_get_name (GstState state);
930 const gchar * gst_element_state_change_return_get_name (GstStateChangeReturn state_ret);
932 gboolean gst_element_link (GstElement *src, GstElement *dest);
933 gboolean gst_element_link_many (GstElement *element_1,
934 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
935 gboolean gst_element_link_filtered (GstElement * src,
938 void gst_element_unlink (GstElement *src, GstElement *dest);
939 void gst_element_unlink_many (GstElement *element_1,
940 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
942 gboolean gst_element_link_pads (GstElement *src, const gchar *srcpadname,
943 GstElement *dest, const gchar *destpadname);
944 gboolean gst_element_link_pads_full (GstElement *src, const gchar *srcpadname,
945 GstElement *dest, const gchar *destpadname,
946 GstPadLinkCheck flags);
947 void gst_element_unlink_pads (GstElement *src, const gchar *srcpadname,
948 GstElement *dest, const gchar *destpadname);
950 gboolean gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
951 GstElement * dest, const gchar * destpadname,
954 gboolean gst_element_seek_simple (GstElement *element,
956 GstSeekFlags seek_flags,
959 /* util elementfactory functions */
960 gboolean gst_element_factory_can_sink_all_caps (GstElementFactory *factory, const GstCaps *caps);
961 gboolean gst_element_factory_can_src_all_caps (GstElementFactory *factory, const GstCaps *caps);
962 gboolean gst_element_factory_can_sink_any_caps (GstElementFactory *factory, const GstCaps *caps);
963 gboolean gst_element_factory_can_src_any_caps (GstElementFactory *factory, const GstCaps *caps);
965 /* util query functions */
966 gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur);
967 gboolean gst_element_query_duration (GstElement *element, GstFormat format, gint64 *duration);
968 gboolean gst_element_query_convert (GstElement *element, GstFormat src_format, gint64 src_val,
969 GstFormat dest_format, gint64 *dest_val);
972 void gst_pad_use_fixed_caps (GstPad *pad);
973 GstElement* gst_pad_get_parent_element (GstPad *pad);
975 /* util query functions */
976 gboolean gst_pad_proxy_query_accept_caps (GstPad *pad, GstQuery *query);
977 gboolean gst_pad_proxy_query_caps (GstPad *pad, GstQuery *query);
979 gboolean gst_pad_query_position (GstPad *pad, GstFormat format, gint64 *cur);
980 gboolean gst_pad_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
981 gboolean gst_pad_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
982 GstFormat dest_format, gint64 *dest_val);
983 GstCaps * gst_pad_query_caps (GstPad *pad, GstCaps *filter);
984 gboolean gst_pad_query_accept_caps (GstPad *pad, GstCaps *caps);
986 gboolean gst_pad_link_maybe_ghosting (GstPad *src,
988 gboolean gst_pad_link_maybe_ghosting_full (GstPad *src,
990 GstPadLinkCheck flags);
992 gboolean gst_pad_peer_query_position (GstPad *pad, GstFormat format, gint64 *cur);
993 gboolean gst_pad_peer_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
994 gboolean gst_pad_peer_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
995 GstFormat dest_format, gint64 *dest_val);
996 GstCaps * gst_pad_peer_query_caps (GstPad * pad, GstCaps *filter);
997 gboolean gst_pad_peer_query_accept_caps (GstPad * pad, GstCaps *caps);
999 gchar * gst_pad_create_stream_id (GstPad * pad, GstElement * parent, const gchar *stream_id) G_GNUC_MALLOC;
1000 gchar * gst_pad_create_stream_id_printf (GstPad * pad, GstElement * parent, const gchar *stream_id, ...) G_GNUC_PRINTF (3, 4) G_GNUC_MALLOC;
1001 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;
1003 gchar * gst_pad_get_stream_id (GstPad * pad);
1004 GstStream * gst_pad_get_stream (GstPad * pad);
1007 void gst_bin_add_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
1008 void gst_bin_remove_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
1009 GstPad * gst_bin_find_unlinked_pad (GstBin *bin, GstPadDirection direction);
1011 gboolean gst_bin_sync_children_states (GstBin *bin);
1013 /* parse utility functions */
1014 GstElement * gst_parse_bin_from_description (const gchar * bin_description,
1015 gboolean ghost_unlinked_pads,
1018 GstElement * gst_parse_bin_from_description_full (const gchar * bin_description,
1019 gboolean ghost_unlinked_pads,
1020 GstParseContext * context,
1021 GstParseFlags flags,
1024 GstClockTime gst_util_get_timestamp (void);
1028 * @GST_SEARCH_MODE_EXACT : Only search for exact matches.
1029 * @GST_SEARCH_MODE_BEFORE: Search for an exact match or the element just before.
1030 * @GST_SEARCH_MODE_AFTER : Search for an exact match or the element just after.
1032 * The different search modes.
1035 GST_SEARCH_MODE_EXACT = 0,
1036 GST_SEARCH_MODE_BEFORE,
1037 GST_SEARCH_MODE_AFTER
1040 gpointer gst_util_array_binary_search (gpointer array, guint num_elements,
1041 gsize element_size, GCompareDataFunc search_func,
1042 GstSearchMode mode, gconstpointer search_data,
1043 gpointer user_data);
1045 /* fraction operations */
1046 gint gst_util_greatest_common_divisor (gint a, gint b);
1047 gint64 gst_util_greatest_common_divisor_int64 (gint64 a, gint64 b);
1049 void gst_util_fraction_to_double (gint src_n, gint src_d, gdouble *dest);
1050 void gst_util_double_to_fraction (gdouble src, gint *dest_n, gint *dest_d);
1052 gboolean gst_util_fraction_multiply (gint a_n, gint a_d, gint b_n, gint b_d,
1053 gint *res_n, gint *res_d);
1054 gboolean gst_util_fraction_add (gint a_n, gint a_d, gint b_n, gint b_d,
1055 gint *res_n, gint *res_d);
1056 gint gst_util_fraction_compare (gint a_n, gint a_d, gint b_n, gint b_d);
1058 gboolean gst_calculate_linear_regression (const GstClockTime * xy,
1059 GstClockTime * temp, guint n,
1060 GstClockTime * m_num, GstClockTime * m_denom,
1061 GstClockTime * b, GstClockTime * xbase,
1062 gdouble * r_squared);
1067 #endif /* __GST_UTILS_H__ */