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>
36 void gst_util_set_value_from_string (GValue *value, const gchar *value_str);
39 void gst_util_set_object_arg (GObject *object, const gchar *name, const gchar *value);
42 gboolean gst_util_set_object_array (GObject * object, const gchar * name,
43 const GValueArray * array);
45 gboolean gst_util_get_object_array (GObject * object, const gchar * name,
46 GValueArray ** array);
48 void gst_util_dump_mem (const guchar *mem, guint size);
51 void gst_util_dump_buffer (GstBuffer * buf);
54 guint64 gst_util_gdouble_to_guint64 (gdouble value) G_GNUC_CONST;
57 gdouble gst_util_guint64_to_gdouble (guint64 value) G_GNUC_CONST;
60 * gst_guint64_to_gdouble:
61 * @value: the #guint64 value to convert
63 * Convert @value to a gdouble.
65 * Returns: @value converted to a #gdouble.
69 * gst_gdouble_to_guint64:
70 * @value: the #gdouble value to convert
72 * Convert @value to a guint64.
74 * Returns: @value converted to a #guint64.
77 #define gst_gdouble_to_guint64(value) gst_util_gdouble_to_guint64(value)
78 #define gst_guint64_to_gdouble(value) gst_util_guint64_to_gdouble(value)
80 #define gst_gdouble_to_guint64(value) ((guint64) (value))
81 #define gst_guint64_to_gdouble(value) ((gdouble) (value))
85 guint64 gst_util_uint64_scale (guint64 val, guint64 num, guint64 denom);
88 guint64 gst_util_uint64_scale_round (guint64 val, guint64 num, guint64 denom);
91 guint64 gst_util_uint64_scale_ceil (guint64 val, guint64 num, guint64 denom);
94 guint64 gst_util_uint64_scale_int (guint64 val, gint num, gint denom);
97 guint64 gst_util_uint64_scale_int_round (guint64 val, gint num, gint denom);
100 guint64 gst_util_uint64_scale_int_ceil (guint64 val, gint num, gint denom);
102 #define GST_SEQNUM_INVALID (0)
105 guint32 gst_util_seqnum_next (void);
108 gint32 gst_util_seqnum_compare (guint32 s1, guint32 s2);
111 guint gst_util_group_id_next (void);
115 * @parent_class_cast: the name of the class cast macro for the parent type
116 * @name: name of the function to call
117 * @args: arguments enclosed in '( )'
119 * Just call the parent handler. This assumes that there is a variable
120 * named parent_class that points to the (duh!) parent class. Note that
121 * this macro is not to be used with things that return something, use
122 * the _WITH_DEFAULT version for that
124 #define GST_CALL_PARENT(parent_class_cast, name, args) \
125 ((parent_class_cast(parent_class)->name != NULL) ? \
126 parent_class_cast(parent_class)->name args : (void) 0)
129 * GST_CALL_PARENT_WITH_DEFAULT:
130 * @parent_class_cast: the name of the class cast macro for the parent type
131 * @name: name of the function to call
132 * @args: arguments enclosed in '( )'
133 * @def_return: default result
135 * Same as GST_CALL_PARENT(), but in case there is no implementation, it
136 * evaluates to @def_return.
138 #define GST_CALL_PARENT_WITH_DEFAULT(parent_class_cast, name, args, def_return)\
139 ((parent_class_cast(parent_class)->name != NULL) ? \
140 parent_class_cast(parent_class)->name args : def_return)
142 /* Define PUT and GET functions for unaligned memory */
143 #define _GST_GET(__data, __idx, __size, __shift) \
144 (((guint##__size) (((const guint8 *) (__data))[__idx])) << (__shift))
146 #define _GST_PUT(__data, __idx, __size, __shift, __num) \
147 (((guint8 *) (__data))[__idx] = (((guint##__size) (__num)) >> (__shift)) & 0xff)
149 #ifndef __GTK_DOC_IGNORE__
150 #if GST_HAVE_UNALIGNED_ACCESS
151 static inline guint16 __gst_fast_read16(const guint8 *v) {
152 return *(const guint16*)(const void*)(v);
154 static inline guint32 __gst_fast_read32(const guint8 *v) {
155 return *(const guint32*)(const void*)(v);
157 static inline guint64 __gst_fast_read64(const guint8 *v) {
158 return *(const guint64*)(const void*)(v);
160 static inline guint16 __gst_fast_read_swap16(const guint8 *v) {
161 return GUINT16_SWAP_LE_BE(*(const guint16*)(const void*)(v));
163 static inline guint32 __gst_fast_read_swap32(const guint8 *v) {
164 return GUINT32_SWAP_LE_BE(*(const guint32*)(const void*)(v));
166 static inline guint64 __gst_fast_read_swap64(const guint8 *v) {
167 return GUINT64_SWAP_LE_BE(*(const guint64*)(const void*)(v));
169 # define _GST_FAST_READ(s, d) __gst_fast_read##s((const guint8 *)(d))
170 # define _GST_FAST_READ_SWAP(s, d) __gst_fast_read_swap##s((const guint8 *)(d))
172 static inline void __gst_fast_write16 (guint8 *p, guint16 v) {
173 *(guint16*)(void*)(p) = v;
175 static inline void __gst_fast_write32 (guint8 *p, guint32 v) {
176 *(guint32*)(void*)(p) = v;
178 static inline void __gst_fast_write64 (guint8 *p, guint64 v) {
179 *(guint64*)(void*)(p) = v;
181 static inline void __gst_fast_write_swap16 (guint8 *p, guint16 v) {
182 *(guint16*)(void*)(p) = GUINT16_SWAP_LE_BE (v);
184 static inline void __gst_fast_write_swap32 (guint8 *p, guint32 v) {
185 *(guint32*)(void*)(p) = GUINT32_SWAP_LE_BE (v);
187 static inline void __gst_fast_write_swap64 (guint8 *p, guint64 v) {
188 *(guint64*)(void*)(p) = GUINT64_SWAP_LE_BE (v);
190 # define _GST_FAST_WRITE(s, d, v) __gst_fast_write##s((guint8 *)(d), (v))
191 # define _GST_FAST_WRITE_SWAP(s, d, v) __gst_fast_write_swap##s((guint8 *)(d), (v))
197 * GST_READ_UINT64_BE:
198 * @data: memory location
200 * Read a 64 bit unsigned integer value in big endian format from the memory buffer.
204 * GST_READ_UINT64_LE:
205 * @data: memory location
207 * Read a 64 bit unsigned integer value in little endian format from the memory buffer.
209 #if GST_HAVE_UNALIGNED_ACCESS
210 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
211 # define GST_READ_UINT64_BE(data) _GST_FAST_READ (64, data)
212 # define GST_READ_UINT64_LE(data) _GST_FAST_READ_SWAP (64, data)
214 # define GST_READ_UINT64_BE(data) _GST_FAST_READ_SWAP (64, data)
215 # define GST_READ_UINT64_LE(data) _GST_FAST_READ (64, data)
218 #define _GST_READ_UINT64_BE(data) (_GST_GET (data, 0, 64, 56) | \
219 _GST_GET (data, 1, 64, 48) | \
220 _GST_GET (data, 2, 64, 40) | \
221 _GST_GET (data, 3, 64, 32) | \
222 _GST_GET (data, 4, 64, 24) | \
223 _GST_GET (data, 5, 64, 16) | \
224 _GST_GET (data, 6, 64, 8) | \
225 _GST_GET (data, 7, 64, 0))
227 #define _GST_READ_UINT64_LE(data) (_GST_GET (data, 7, 64, 56) | \
228 _GST_GET (data, 6, 64, 48) | \
229 _GST_GET (data, 5, 64, 40) | \
230 _GST_GET (data, 4, 64, 32) | \
231 _GST_GET (data, 3, 64, 24) | \
232 _GST_GET (data, 2, 64, 16) | \
233 _GST_GET (data, 1, 64, 8) | \
234 _GST_GET (data, 0, 64, 0))
236 #define GST_READ_UINT64_BE(data) __gst_slow_read64_be((const guint8 *)(data))
237 static inline guint64 __gst_slow_read64_be (const guint8 * data) {
238 return _GST_READ_UINT64_BE (data);
240 #define GST_READ_UINT64_LE(data) __gst_slow_read64_le((const guint8 *)(data))
241 static inline guint64 __gst_slow_read64_le (const guint8 * data) {
242 return _GST_READ_UINT64_LE (data);
247 * GST_READ_UINT32_BE:
248 * @data: memory location
250 * Read a 32 bit unsigned integer value in big endian format from the memory buffer.
254 * GST_READ_UINT32_LE:
255 * @data: memory location
257 * Read a 32 bit unsigned integer value in little endian format from the memory buffer.
259 #if GST_HAVE_UNALIGNED_ACCESS
260 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
261 # define GST_READ_UINT32_BE(data) _GST_FAST_READ (32, data)
262 # define GST_READ_UINT32_LE(data) _GST_FAST_READ_SWAP (32, data)
264 # define GST_READ_UINT32_BE(data) _GST_FAST_READ_SWAP (32, data)
265 # define GST_READ_UINT32_LE(data) _GST_FAST_READ (32, data)
268 #define _GST_READ_UINT32_BE(data) (_GST_GET (data, 0, 32, 24) | \
269 _GST_GET (data, 1, 32, 16) | \
270 _GST_GET (data, 2, 32, 8) | \
271 _GST_GET (data, 3, 32, 0))
273 #define _GST_READ_UINT32_LE(data) (_GST_GET (data, 3, 32, 24) | \
274 _GST_GET (data, 2, 32, 16) | \
275 _GST_GET (data, 1, 32, 8) | \
276 _GST_GET (data, 0, 32, 0))
278 #define GST_READ_UINT32_BE(data) __gst_slow_read32_be((const guint8 *)(data))
279 static inline guint32 __gst_slow_read32_be (const guint8 * data) {
280 return _GST_READ_UINT32_BE (data);
282 #define GST_READ_UINT32_LE(data) __gst_slow_read32_le((const guint8 *)(data))
283 static inline guint32 __gst_slow_read32_le (const guint8 * data) {
284 return _GST_READ_UINT32_LE (data);
289 * GST_READ_UINT24_BE:
290 * @data: memory location
292 * Read a 24 bit unsigned integer value in big endian format from the memory buffer.
294 #define _GST_READ_UINT24_BE(data) (_GST_GET (data, 0, 32, 16) | \
295 _GST_GET (data, 1, 32, 8) | \
296 _GST_GET (data, 2, 32, 0))
298 #define GST_READ_UINT24_BE(data) __gst_slow_read24_be((const guint8 *)(data))
299 static inline guint32 __gst_slow_read24_be (const guint8 * data) {
300 return _GST_READ_UINT24_BE (data);
304 * GST_READ_UINT24_LE:
305 * @data: memory location
307 * Read a 24 bit unsigned integer value in little endian format from the memory buffer.
309 #define _GST_READ_UINT24_LE(data) (_GST_GET (data, 2, 32, 16) | \
310 _GST_GET (data, 1, 32, 8) | \
311 _GST_GET (data, 0, 32, 0))
313 #define GST_READ_UINT24_LE(data) __gst_slow_read24_le((const guint8 *)(data))
314 static inline guint32 __gst_slow_read24_le (const guint8 * data) {
315 return _GST_READ_UINT24_LE (data);
319 * GST_READ_UINT16_BE:
320 * @data: memory location
322 * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
325 * GST_READ_UINT16_LE:
326 * @data: memory location
328 * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
330 #if GST_HAVE_UNALIGNED_ACCESS
331 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
332 # define GST_READ_UINT16_BE(data) _GST_FAST_READ (16, data)
333 # define GST_READ_UINT16_LE(data) _GST_FAST_READ_SWAP (16, data)
335 # define GST_READ_UINT16_BE(data) _GST_FAST_READ_SWAP (16, data)
336 # define GST_READ_UINT16_LE(data) _GST_FAST_READ (16, data)
339 #define _GST_READ_UINT16_BE(data) (_GST_GET (data, 0, 16, 8) | \
340 _GST_GET (data, 1, 16, 0))
342 #define _GST_READ_UINT16_LE(data) (_GST_GET (data, 1, 16, 8) | \
343 _GST_GET (data, 0, 16, 0))
345 #define GST_READ_UINT16_BE(data) __gst_slow_read16_be((const guint8 *)(data))
346 static inline guint16 __gst_slow_read16_be (const guint8 * data) {
347 return _GST_READ_UINT16_BE (data);
349 #define GST_READ_UINT16_LE(data) __gst_slow_read16_le((const guint8 *)(data))
350 static inline guint16 __gst_slow_read16_le (const guint8 * data) {
351 return _GST_READ_UINT16_LE (data);
357 * @data: memory location
359 * Read an 8 bit unsigned integer value from the memory buffer.
361 #define GST_READ_UINT8(data) (_GST_GET (data, 0, 8, 0))
364 * GST_WRITE_UINT64_BE:
365 * @data: memory location
366 * @val: value to store
368 * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
371 * GST_WRITE_UINT64_LE:
372 * @data: memory location
373 * @val: value to store
375 * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
377 #if GST_HAVE_UNALIGNED_ACCESS
378 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
379 # define GST_WRITE_UINT64_BE(data,val) _GST_FAST_WRITE(64,data,val)
380 # define GST_WRITE_UINT64_LE(data,val) _GST_FAST_WRITE_SWAP(64,data,val)
382 # define GST_WRITE_UINT64_BE(data,val) _GST_FAST_WRITE_SWAP(64,data,val)
383 # define GST_WRITE_UINT64_LE(data,val) _GST_FAST_WRITE(64,data,val)
386 #define GST_WRITE_UINT64_BE(data,val) do { \
387 gpointer __put_data = data; \
388 guint64 __put_val = val; \
389 _GST_PUT (__put_data, 0, 64, 56, __put_val); \
390 _GST_PUT (__put_data, 1, 64, 48, __put_val); \
391 _GST_PUT (__put_data, 2, 64, 40, __put_val); \
392 _GST_PUT (__put_data, 3, 64, 32, __put_val); \
393 _GST_PUT (__put_data, 4, 64, 24, __put_val); \
394 _GST_PUT (__put_data, 5, 64, 16, __put_val); \
395 _GST_PUT (__put_data, 6, 64, 8, __put_val); \
396 _GST_PUT (__put_data, 7, 64, 0, __put_val); \
399 #define GST_WRITE_UINT64_LE(data,val) do { \
400 gpointer __put_data = data; \
401 guint64 __put_val = val; \
402 _GST_PUT (__put_data, 0, 64, 0, __put_val); \
403 _GST_PUT (__put_data, 1, 64, 8, __put_val); \
404 _GST_PUT (__put_data, 2, 64, 16, __put_val); \
405 _GST_PUT (__put_data, 3, 64, 24, __put_val); \
406 _GST_PUT (__put_data, 4, 64, 32, __put_val); \
407 _GST_PUT (__put_data, 5, 64, 40, __put_val); \
408 _GST_PUT (__put_data, 6, 64, 48, __put_val); \
409 _GST_PUT (__put_data, 7, 64, 56, __put_val); \
411 #endif /* !GST_HAVE_UNALIGNED_ACCESS */
414 * GST_WRITE_UINT32_BE:
415 * @data: memory location
416 * @val: value to store
418 * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
421 * GST_WRITE_UINT32_LE:
422 * @data: memory location
423 * @val: value to store
425 * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
427 #if GST_HAVE_UNALIGNED_ACCESS
428 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
429 # define GST_WRITE_UINT32_BE(data,val) _GST_FAST_WRITE(32,data,val)
430 # define GST_WRITE_UINT32_LE(data,val) _GST_FAST_WRITE_SWAP(32,data,val)
432 # define GST_WRITE_UINT32_BE(data,val) _GST_FAST_WRITE_SWAP(32,data,val)
433 # define GST_WRITE_UINT32_LE(data,val) _GST_FAST_WRITE(32,data,val)
436 #define GST_WRITE_UINT32_BE(data,val) do { \
437 gpointer __put_data = data; \
438 guint32 __put_val = val; \
439 _GST_PUT (__put_data, 0, 32, 24, __put_val); \
440 _GST_PUT (__put_data, 1, 32, 16, __put_val); \
441 _GST_PUT (__put_data, 2, 32, 8, __put_val); \
442 _GST_PUT (__put_data, 3, 32, 0, __put_val); \
445 #define GST_WRITE_UINT32_LE(data,val) do { \
446 gpointer __put_data = data; \
447 guint32 __put_val = val; \
448 _GST_PUT (__put_data, 0, 32, 0, __put_val); \
449 _GST_PUT (__put_data, 1, 32, 8, __put_val); \
450 _GST_PUT (__put_data, 2, 32, 16, __put_val); \
451 _GST_PUT (__put_data, 3, 32, 24, __put_val); \
453 #endif /* !GST_HAVE_UNALIGNED_ACCESS */
456 * GST_WRITE_UINT24_BE:
457 * @data: memory location
458 * @num: value to store
460 * Store a 24 bit unsigned integer value in big endian format into the memory buffer.
462 #define GST_WRITE_UINT24_BE(data, num) do { \
463 gpointer __put_data = data; \
464 guint32 __put_val = num; \
465 _GST_PUT (__put_data, 0, 32, 16, __put_val); \
466 _GST_PUT (__put_data, 1, 32, 8, __put_val); \
467 _GST_PUT (__put_data, 2, 32, 0, __put_val); \
471 * GST_WRITE_UINT24_LE:
472 * @data: memory location
473 * @num: value to store
475 * Store a 24 bit unsigned integer value in little endian format into the memory buffer.
477 #define GST_WRITE_UINT24_LE(data, num) do { \
478 gpointer __put_data = data; \
479 guint32 __put_val = num; \
480 _GST_PUT (__put_data, 0, 32, 0, __put_val); \
481 _GST_PUT (__put_data, 1, 32, 8, __put_val); \
482 _GST_PUT (__put_data, 2, 32, 16, __put_val); \
486 * GST_WRITE_UINT16_BE:
487 * @data: memory location
488 * @val: value to store
490 * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
493 * GST_WRITE_UINT16_LE:
494 * @data: memory location
495 * @val: value to store
497 * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
499 #if GST_HAVE_UNALIGNED_ACCESS
500 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
501 # define GST_WRITE_UINT16_BE(data,val) _GST_FAST_WRITE(16,data,val)
502 # define GST_WRITE_UINT16_LE(data,val) _GST_FAST_WRITE_SWAP(16,data,val)
504 # define GST_WRITE_UINT16_BE(data,val) _GST_FAST_WRITE_SWAP(16,data,val)
505 # define GST_WRITE_UINT16_LE(data,val) _GST_FAST_WRITE(16,data,val)
508 #define GST_WRITE_UINT16_BE(data,val) do { \
509 gpointer __put_data = data; \
510 guint16 __put_val = val; \
511 _GST_PUT (__put_data, 0, 16, 8, __put_val); \
512 _GST_PUT (__put_data, 1, 16, 0, __put_val); \
515 #define GST_WRITE_UINT16_LE(data,val) do { \
516 gpointer __put_data = data; \
517 guint16 __put_val = val; \
518 _GST_PUT (__put_data, 0, 16, 0, __put_val); \
519 _GST_PUT (__put_data, 1, 16, 8, __put_val); \
521 #endif /* !GST_HAVE_UNALIGNED_ACCESS */
525 * @data: memory location
526 * @num: value to store
528 * Store an 8 bit unsigned integer value into the memory buffer.
530 #define GST_WRITE_UINT8(data, num) do { \
531 _GST_PUT (data, 0, 8, 0, num); \
534 /* Float endianness conversion macros */
536 /* FIXME: Remove this once we depend on a GLib version with this */
537 #ifndef GFLOAT_FROM_LE
542 * Swap byte order of a 32-bit floating point value (float).
544 * Returns: @in byte-swapped.
547 GFLOAT_SWAP_LE_BE(gfloat in)
556 u.i = GUINT32_SWAP_LE_BE (u.i);
561 * GDOUBLE_SWAP_LE_BE:
564 * Swap byte order of a 64-bit floating point value (double).
566 * Returns: @in byte-swapped.
568 static inline gdouble
569 GDOUBLE_SWAP_LE_BE(gdouble in)
578 u.i = GUINT64_SWAP_LE_BE (u.i);
586 * Convert 64-bit floating point value (double) from native byte order into
587 * little endian byte order.
593 * Convert 64-bit floating point value (double) from native byte order into
594 * big endian byte order.
600 * Convert 64-bit floating point value (double) from little endian byte order
601 * into native byte order.
607 * Convert 64-bit floating point value (double) from big endian byte order
608 * into native byte order.
615 * Convert 32-bit floating point value (float) from native byte order into
616 * little endian byte order.
622 * Convert 32-bit floating point value (float) from native byte order into
623 * big endian byte order.
629 * Convert 32-bit floating point value (float) from little endian byte order
630 * into native byte order.
636 * Convert 32-bit floating point value (float) from big endian byte order
637 * into native byte order.
640 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
641 #define GFLOAT_TO_LE(val) ((gfloat) (val))
642 #define GFLOAT_TO_BE(val) (GFLOAT_SWAP_LE_BE (val))
643 #define GDOUBLE_TO_LE(val) ((gdouble) (val))
644 #define GDOUBLE_TO_BE(val) (GDOUBLE_SWAP_LE_BE (val))
646 #elif G_BYTE_ORDER == G_BIG_ENDIAN
647 #define GFLOAT_TO_LE(val) (GFLOAT_SWAP_LE_BE (val))
648 #define GFLOAT_TO_BE(val) ((gfloat) (val))
649 #define GDOUBLE_TO_LE(val) (GDOUBLE_SWAP_LE_BE (val))
650 #define GDOUBLE_TO_BE(val) ((gdouble) (val))
652 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
653 #error unknown ENDIAN type
654 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
656 #define GFLOAT_FROM_LE(val) (GFLOAT_TO_LE (val))
657 #define GFLOAT_FROM_BE(val) (GFLOAT_TO_BE (val))
658 #define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val))
659 #define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
661 #endif /* !defined(GFLOAT_FROM_LE) */
665 * @data: memory location
667 * Read a 32 bit float value in little endian format from the memory buffer.
669 * Returns: The floating point value read from @data
672 GST_READ_FLOAT_LE(const guint8 *data)
680 u.i = GST_READ_UINT32_LE (data);
686 * @data: memory location
688 * Read a 32 bit float value in big endian format from the memory buffer.
690 * Returns: The floating point value read from @data
693 GST_READ_FLOAT_BE(const guint8 *data)
701 u.i = GST_READ_UINT32_BE (data);
706 * GST_READ_DOUBLE_LE:
707 * @data: memory location
709 * Read a 64 bit double value in little endian format from the memory buffer.
711 * Returns: The double-precision floating point value read from @data
713 static inline gdouble
714 GST_READ_DOUBLE_LE(const guint8 *data)
722 u.i = GST_READ_UINT64_LE (data);
727 * GST_READ_DOUBLE_BE:
728 * @data: memory location
730 * Read a 64 bit double value in big endian format from the memory buffer.
732 * Returns: The double-precision floating point value read from @data
734 static inline gdouble
735 GST_READ_DOUBLE_BE(const guint8 *data)
743 u.i = GST_READ_UINT64_BE (data);
748 * GST_WRITE_FLOAT_LE:
749 * @data: memory location
750 * @num: value to store
752 * Store a 32 bit float value in little endian format into the memory buffer.
755 GST_WRITE_FLOAT_LE(guint8 *data, gfloat num)
764 GST_WRITE_UINT32_LE (data, u.i);
768 * GST_WRITE_FLOAT_BE:
769 * @data: memory location
770 * @num: value to store
772 * Store a 32 bit float value in big endian format into the memory buffer.
775 GST_WRITE_FLOAT_BE(guint8 *data, gfloat num)
784 GST_WRITE_UINT32_BE (data, u.i);
788 * GST_WRITE_DOUBLE_LE:
789 * @data: memory location
790 * @num: value to store
792 * Store a 64 bit double value in little endian format into the memory buffer.
795 GST_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
804 GST_WRITE_UINT64_LE (data, u.i);
808 * GST_WRITE_DOUBLE_BE:
809 * @data: memory location
810 * @num: value to store
812 * Store a 64 bit double value in big endian format into the memory buffer.
815 GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
824 GST_WRITE_UINT64_BE (data, u.i);
827 /* Miscellaneous utility macros */
831 * @num: integer value to round up
833 * Rounds an integer value up to the next multiple of 2.
835 #define GST_ROUND_UP_2(num) (((num)+1)&~1)
838 * @num: integer value to round up
840 * Rounds an integer value up to the next multiple of 4.
842 #define GST_ROUND_UP_4(num) (((num)+3)&~3)
845 * @num: integer value to round up
847 * Rounds an integer value up to the next multiple of 8.
849 #define GST_ROUND_UP_8(num) (((num)+7)&~7)
852 * @num: integer value to round up
854 * Rounds an integer value up to the next multiple of 16.
856 #define GST_ROUND_UP_16(num) (((num)+15)&~15)
859 * @num: integer value to round up
861 * Rounds an integer value up to the next multiple of 32.
863 #define GST_ROUND_UP_32(num) (((num)+31)&~31)
866 * @num: integer value to round up
868 * Rounds an integer value up to the next multiple of 64.
870 #define GST_ROUND_UP_64(num) (((num)+63)&~63)
873 * @num: integer value to round up
875 * Rounds an integer value up to the next multiple of 128.
878 #define GST_ROUND_UP_128(num) (((num)+127)&~127)
881 * @num: integrer value to round up
882 * @align: a power of two to round up to
884 * Rounds an integer value up to the next multiple of @align. @align MUST be a
887 #define GST_ROUND_UP_N(num,align) ((((num) + ((align) - 1)) & ~((align) - 1)))
892 * @num: integer value to round down
894 * Rounds an integer value down to the next multiple of 2.
896 #define GST_ROUND_DOWN_2(num) ((num)&(~1))
899 * @num: integer value to round down
901 * Rounds an integer value down to the next multiple of 4.
903 #define GST_ROUND_DOWN_4(num) ((num)&(~3))
906 * @num: integer value to round down
908 * Rounds an integer value down to the next multiple of 8.
910 #define GST_ROUND_DOWN_8(num) ((num)&(~7))
913 * @num: integer value to round down
915 * Rounds an integer value down to the next multiple of 16.
917 #define GST_ROUND_DOWN_16(num) ((num)&(~15))
920 * @num: integer value to round down
922 * Rounds an integer value down to the next multiple of 32.
924 #define GST_ROUND_DOWN_32(num) ((num)&(~31))
927 * @num: integer value to round down
929 * Rounds an integer value down to the next multiple of 64.
931 #define GST_ROUND_DOWN_64(num) ((num)&(~63))
933 * GST_ROUND_DOWN_128:
934 * @num: integer value to round down
936 * Rounds an integer value down to the next multiple of 128.
939 #define GST_ROUND_DOWN_128(num) ((num)&(~127))
942 * @num: integrer value to round down
943 * @align: a power of two to round down to
945 * Rounds an integer value down to the next multiple of @align. @align MUST be a
948 #define GST_ROUND_DOWN_N(num,align) (((num) & ~((align) - 1)))
952 void gst_object_default_error (GstObject * source,
953 const GError * error,
954 const gchar * debug);
956 /* element functions */
959 void gst_element_create_all_pads (GstElement *element);
962 GstPad* gst_element_get_compatible_pad (GstElement *element, GstPad *pad,
965 GstPadTemplate* gst_element_get_compatible_pad_template (GstElement *element, GstPadTemplate *compattempl);
968 const gchar* gst_element_state_get_name (GstState state);
971 const gchar * gst_element_state_change_return_get_name (GstStateChangeReturn state_ret);
974 const gchar * gst_state_change_get_name (GstStateChange transition);
977 gboolean gst_element_link (GstElement *src, GstElement *dest);
980 gboolean gst_element_link_many (GstElement *element_1,
981 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
983 gboolean gst_element_link_filtered (GstElement * src,
987 void gst_element_unlink (GstElement *src, GstElement *dest);
990 void gst_element_unlink_many (GstElement *element_1,
991 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
993 gboolean gst_element_link_pads (GstElement *src, const gchar *srcpadname,
994 GstElement *dest, const gchar *destpadname);
996 gboolean gst_element_link_pads_full (GstElement *src, const gchar *srcpadname,
997 GstElement *dest, const gchar *destpadname,
998 GstPadLinkCheck flags);
1000 void gst_element_unlink_pads (GstElement *src, const gchar *srcpadname,
1001 GstElement *dest, const gchar *destpadname);
1003 gboolean gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
1004 GstElement * dest, const gchar * destpadname,
1007 gboolean gst_element_seek_simple (GstElement *element,
1009 GstSeekFlags seek_flags,
1012 /* util elementfactory functions */
1015 gboolean gst_element_factory_can_sink_all_caps (GstElementFactory *factory, const GstCaps *caps);
1018 gboolean gst_element_factory_can_src_all_caps (GstElementFactory *factory, const GstCaps *caps);
1021 gboolean gst_element_factory_can_sink_any_caps (GstElementFactory *factory, const GstCaps *caps);
1024 gboolean gst_element_factory_can_src_any_caps (GstElementFactory *factory, const GstCaps *caps);
1026 /* util query functions */
1029 gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur);
1032 gboolean gst_element_query_duration (GstElement *element, GstFormat format, gint64 *duration);
1035 gboolean gst_element_query_convert (GstElement *element, GstFormat src_format, gint64 src_val,
1036 GstFormat dest_format, gint64 *dest_val);
1041 void gst_pad_use_fixed_caps (GstPad *pad);
1044 GstElement* gst_pad_get_parent_element (GstPad *pad);
1046 /* util query functions */
1049 gboolean gst_pad_proxy_query_accept_caps (GstPad *pad, GstQuery *query);
1052 gboolean gst_pad_proxy_query_caps (GstPad *pad, GstQuery *query);
1055 gboolean gst_pad_query_position (GstPad *pad, GstFormat format, gint64 *cur);
1058 gboolean gst_pad_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
1061 gboolean gst_pad_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
1062 GstFormat dest_format, gint64 *dest_val);
1064 GstCaps * gst_pad_query_caps (GstPad *pad, GstCaps *filter);
1067 gboolean gst_pad_query_accept_caps (GstPad *pad, GstCaps *caps);
1070 gboolean gst_pad_link_maybe_ghosting (GstPad *src,
1073 gboolean gst_pad_link_maybe_ghosting_full (GstPad *src,
1075 GstPadLinkCheck flags);
1077 gboolean gst_pad_peer_query_position (GstPad *pad, GstFormat format, gint64 *cur);
1080 gboolean gst_pad_peer_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
1083 gboolean gst_pad_peer_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
1084 GstFormat dest_format, gint64 *dest_val);
1086 GstCaps * gst_pad_peer_query_caps (GstPad * pad, GstCaps *filter);
1089 gboolean gst_pad_peer_query_accept_caps (GstPad * pad, GstCaps *caps);
1092 gchar * gst_pad_create_stream_id (GstPad * pad, GstElement * parent, const gchar *stream_id) G_GNUC_MALLOC;
1095 gchar * gst_pad_create_stream_id_printf (GstPad * pad, GstElement * parent, const gchar *stream_id, ...) G_GNUC_PRINTF (3, 4) G_GNUC_MALLOC;
1098 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;
1101 gchar * gst_pad_get_stream_id (GstPad * pad);
1104 GstStream * gst_pad_get_stream (GstPad * pad);
1109 void gst_bin_add_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
1112 void gst_bin_remove_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
1115 GstPad * gst_bin_find_unlinked_pad (GstBin *bin, GstPadDirection direction);
1118 gboolean gst_bin_sync_children_states (GstBin *bin);
1120 /* parse utility functions */
1123 GstElement * gst_parse_bin_from_description (const gchar * bin_description,
1124 gboolean ghost_unlinked_pads,
1127 GstElement * gst_parse_bin_from_description_full (const gchar * bin_description,
1128 gboolean ghost_unlinked_pads,
1129 GstParseContext * context,
1130 GstParseFlags flags,
1133 GstClockTime gst_util_get_timestamp (void);
1137 * @GST_SEARCH_MODE_EXACT : Only search for exact matches.
1138 * @GST_SEARCH_MODE_BEFORE: Search for an exact match or the element just before.
1139 * @GST_SEARCH_MODE_AFTER : Search for an exact match or the element just after.
1141 * The different search modes.
1144 GST_SEARCH_MODE_EXACT = 0,
1145 GST_SEARCH_MODE_BEFORE,
1146 GST_SEARCH_MODE_AFTER
1150 gpointer gst_util_array_binary_search (gpointer array, guint num_elements,
1151 gsize element_size, GCompareDataFunc search_func,
1152 GstSearchMode mode, gconstpointer search_data,
1153 gpointer user_data);
1155 /* fraction operations */
1158 gint gst_util_greatest_common_divisor (gint a, gint b);
1161 gint64 gst_util_greatest_common_divisor_int64 (gint64 a, gint64 b);
1164 void gst_util_fraction_to_double (gint src_n, gint src_d, gdouble *dest);
1167 void gst_util_double_to_fraction (gdouble src, gint *dest_n, gint *dest_d);
1170 gboolean gst_util_fraction_multiply (gint a_n, gint a_d, gint b_n, gint b_d,
1171 gint *res_n, gint *res_d);
1173 gboolean gst_util_fraction_add (gint a_n, gint a_d, gint b_n, gint b_d,
1174 gint *res_n, gint *res_d);
1176 gint gst_util_fraction_compare (gint a_n, gint a_d, gint b_n, gint b_d);
1179 gboolean gst_calculate_linear_regression (const GstClockTime * xy,
1180 GstClockTime * temp, guint n,
1181 GstClockTime * m_num, GstClockTime * m_denom,
1182 GstClockTime * b, GstClockTime * xbase,
1183 gdouble * r_squared);
1188 #endif /* __GST_UTILS_H__ */