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);
103 * GST_SEQNUM_INVALID:
105 * A value which is guaranteed to never be returned by
106 * gst_util_seqnum_next().
108 * Can be used as a default value in variables used to store seqnum.
112 #define GST_SEQNUM_INVALID (0)
115 guint32 gst_util_seqnum_next (void);
118 gint32 gst_util_seqnum_compare (guint32 s1, guint32 s2);
121 * GST_GROUP_ID_INVALID:
123 * A value which is guaranteed to never be returned by
124 * gst_util_group_id_next().
126 * Can be used as a default value in variables used to store group_id.
130 #define GST_GROUP_ID_INVALID (0)
133 guint gst_util_group_id_next (void);
137 * @parent_class_cast: the name of the class cast macro for the parent type
138 * @name: name of the function to call
139 * @args: arguments enclosed in '( )'
141 * Just call the parent handler. This assumes that there is a variable
142 * named parent_class that points to the (duh!) parent class. Note that
143 * this macro is not to be used with things that return something, use
144 * the _WITH_DEFAULT version for that
146 #define GST_CALL_PARENT(parent_class_cast, name, args) \
147 ((parent_class_cast(parent_class)->name != NULL) ? \
148 parent_class_cast(parent_class)->name args : (void) 0)
151 * GST_CALL_PARENT_WITH_DEFAULT:
152 * @parent_class_cast: the name of the class cast macro for the parent type
153 * @name: name of the function to call
154 * @args: arguments enclosed in '( )'
155 * @def_return: default result
157 * Same as GST_CALL_PARENT(), but in case there is no implementation, it
158 * evaluates to @def_return.
160 #define GST_CALL_PARENT_WITH_DEFAULT(parent_class_cast, name, args, def_return)\
161 ((parent_class_cast(parent_class)->name != NULL) ? \
162 parent_class_cast(parent_class)->name args : def_return)
164 /* Define PUT and GET functions for unaligned memory */
165 #define _GST_GET(__data, __idx, __size, __shift) \
166 (((guint##__size) (((const guint8 *) (__data))[__idx])) << (__shift))
168 #define _GST_PUT(__data, __idx, __size, __shift, __num) \
169 (((guint8 *) (__data))[__idx] = (((guint##__size) (__num)) >> (__shift)) & 0xff)
171 #ifndef __GTK_DOC_IGNORE__
172 #if GST_HAVE_UNALIGNED_ACCESS
173 static inline guint16 __gst_fast_read16(const guint8 *v) {
174 return *(const guint16*)(const void*)(v);
176 static inline guint32 __gst_fast_read32(const guint8 *v) {
177 return *(const guint32*)(const void*)(v);
179 static inline guint64 __gst_fast_read64(const guint8 *v) {
180 return *(const guint64*)(const void*)(v);
182 static inline guint16 __gst_fast_read_swap16(const guint8 *v) {
183 return GUINT16_SWAP_LE_BE(*(const guint16*)(const void*)(v));
185 static inline guint32 __gst_fast_read_swap32(const guint8 *v) {
186 return GUINT32_SWAP_LE_BE(*(const guint32*)(const void*)(v));
188 static inline guint64 __gst_fast_read_swap64(const guint8 *v) {
189 return GUINT64_SWAP_LE_BE(*(const guint64*)(const void*)(v));
191 # define _GST_FAST_READ(s, d) __gst_fast_read##s((const guint8 *)(d))
192 # define _GST_FAST_READ_SWAP(s, d) __gst_fast_read_swap##s((const guint8 *)(d))
194 static inline void __gst_fast_write16 (guint8 *p, guint16 v) {
195 *(guint16*)(void*)(p) = v;
197 static inline void __gst_fast_write32 (guint8 *p, guint32 v) {
198 *(guint32*)(void*)(p) = v;
200 static inline void __gst_fast_write64 (guint8 *p, guint64 v) {
201 *(guint64*)(void*)(p) = v;
203 static inline void __gst_fast_write_swap16 (guint8 *p, guint16 v) {
204 *(guint16*)(void*)(p) = GUINT16_SWAP_LE_BE (v);
206 static inline void __gst_fast_write_swap32 (guint8 *p, guint32 v) {
207 *(guint32*)(void*)(p) = GUINT32_SWAP_LE_BE (v);
209 static inline void __gst_fast_write_swap64 (guint8 *p, guint64 v) {
210 *(guint64*)(void*)(p) = GUINT64_SWAP_LE_BE (v);
212 # define _GST_FAST_WRITE(s, d, v) __gst_fast_write##s((guint8 *)(d), (v))
213 # define _GST_FAST_WRITE_SWAP(s, d, v) __gst_fast_write_swap##s((guint8 *)(d), (v))
219 * GST_READ_UINT64_BE:
220 * @data: memory location
222 * Read a 64 bit unsigned integer value in big endian format from the memory buffer.
226 * GST_READ_UINT64_LE:
227 * @data: memory location
229 * Read a 64 bit unsigned integer value in little endian format from the memory buffer.
231 #if GST_HAVE_UNALIGNED_ACCESS
232 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
233 # define GST_READ_UINT64_BE(data) _GST_FAST_READ (64, data)
234 # define GST_READ_UINT64_LE(data) _GST_FAST_READ_SWAP (64, data)
236 # define GST_READ_UINT64_BE(data) _GST_FAST_READ_SWAP (64, data)
237 # define GST_READ_UINT64_LE(data) _GST_FAST_READ (64, data)
240 #define _GST_READ_UINT64_BE(data) (_GST_GET (data, 0, 64, 56) | \
241 _GST_GET (data, 1, 64, 48) | \
242 _GST_GET (data, 2, 64, 40) | \
243 _GST_GET (data, 3, 64, 32) | \
244 _GST_GET (data, 4, 64, 24) | \
245 _GST_GET (data, 5, 64, 16) | \
246 _GST_GET (data, 6, 64, 8) | \
247 _GST_GET (data, 7, 64, 0))
249 #define _GST_READ_UINT64_LE(data) (_GST_GET (data, 7, 64, 56) | \
250 _GST_GET (data, 6, 64, 48) | \
251 _GST_GET (data, 5, 64, 40) | \
252 _GST_GET (data, 4, 64, 32) | \
253 _GST_GET (data, 3, 64, 24) | \
254 _GST_GET (data, 2, 64, 16) | \
255 _GST_GET (data, 1, 64, 8) | \
256 _GST_GET (data, 0, 64, 0))
258 #define GST_READ_UINT64_BE(data) __gst_slow_read64_be((const guint8 *)(data))
259 static inline guint64 __gst_slow_read64_be (const guint8 * data) {
260 return _GST_READ_UINT64_BE (data);
262 #define GST_READ_UINT64_LE(data) __gst_slow_read64_le((const guint8 *)(data))
263 static inline guint64 __gst_slow_read64_le (const guint8 * data) {
264 return _GST_READ_UINT64_LE (data);
269 * GST_READ_UINT32_BE:
270 * @data: memory location
272 * Read a 32 bit unsigned integer value in big endian format from the memory buffer.
276 * GST_READ_UINT32_LE:
277 * @data: memory location
279 * Read a 32 bit unsigned integer value in little endian format from the memory buffer.
281 #if GST_HAVE_UNALIGNED_ACCESS
282 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
283 # define GST_READ_UINT32_BE(data) _GST_FAST_READ (32, data)
284 # define GST_READ_UINT32_LE(data) _GST_FAST_READ_SWAP (32, data)
286 # define GST_READ_UINT32_BE(data) _GST_FAST_READ_SWAP (32, data)
287 # define GST_READ_UINT32_LE(data) _GST_FAST_READ (32, data)
290 #define _GST_READ_UINT32_BE(data) (_GST_GET (data, 0, 32, 24) | \
291 _GST_GET (data, 1, 32, 16) | \
292 _GST_GET (data, 2, 32, 8) | \
293 _GST_GET (data, 3, 32, 0))
295 #define _GST_READ_UINT32_LE(data) (_GST_GET (data, 3, 32, 24) | \
296 _GST_GET (data, 2, 32, 16) | \
297 _GST_GET (data, 1, 32, 8) | \
298 _GST_GET (data, 0, 32, 0))
300 #define GST_READ_UINT32_BE(data) __gst_slow_read32_be((const guint8 *)(data))
301 static inline guint32 __gst_slow_read32_be (const guint8 * data) {
302 return _GST_READ_UINT32_BE (data);
304 #define GST_READ_UINT32_LE(data) __gst_slow_read32_le((const guint8 *)(data))
305 static inline guint32 __gst_slow_read32_le (const guint8 * data) {
306 return _GST_READ_UINT32_LE (data);
311 * GST_READ_UINT24_BE:
312 * @data: memory location
314 * Read a 24 bit unsigned integer value in big endian format from the memory buffer.
316 #define _GST_READ_UINT24_BE(data) (_GST_GET (data, 0, 32, 16) | \
317 _GST_GET (data, 1, 32, 8) | \
318 _GST_GET (data, 2, 32, 0))
320 #define GST_READ_UINT24_BE(data) __gst_slow_read24_be((const guint8 *)(data))
321 static inline guint32 __gst_slow_read24_be (const guint8 * data) {
322 return _GST_READ_UINT24_BE (data);
326 * GST_READ_UINT24_LE:
327 * @data: memory location
329 * Read a 24 bit unsigned integer value in little endian format from the memory buffer.
331 #define _GST_READ_UINT24_LE(data) (_GST_GET (data, 2, 32, 16) | \
332 _GST_GET (data, 1, 32, 8) | \
333 _GST_GET (data, 0, 32, 0))
335 #define GST_READ_UINT24_LE(data) __gst_slow_read24_le((const guint8 *)(data))
336 static inline guint32 __gst_slow_read24_le (const guint8 * data) {
337 return _GST_READ_UINT24_LE (data);
341 * GST_READ_UINT16_BE:
342 * @data: memory location
344 * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
347 * GST_READ_UINT16_LE:
348 * @data: memory location
350 * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
352 #if GST_HAVE_UNALIGNED_ACCESS
353 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
354 # define GST_READ_UINT16_BE(data) _GST_FAST_READ (16, data)
355 # define GST_READ_UINT16_LE(data) _GST_FAST_READ_SWAP (16, data)
357 # define GST_READ_UINT16_BE(data) _GST_FAST_READ_SWAP (16, data)
358 # define GST_READ_UINT16_LE(data) _GST_FAST_READ (16, data)
361 #define _GST_READ_UINT16_BE(data) (_GST_GET (data, 0, 16, 8) | \
362 _GST_GET (data, 1, 16, 0))
364 #define _GST_READ_UINT16_LE(data) (_GST_GET (data, 1, 16, 8) | \
365 _GST_GET (data, 0, 16, 0))
367 #define GST_READ_UINT16_BE(data) __gst_slow_read16_be((const guint8 *)(data))
368 static inline guint16 __gst_slow_read16_be (const guint8 * data) {
369 return _GST_READ_UINT16_BE (data);
371 #define GST_READ_UINT16_LE(data) __gst_slow_read16_le((const guint8 *)(data))
372 static inline guint16 __gst_slow_read16_le (const guint8 * data) {
373 return _GST_READ_UINT16_LE (data);
379 * @data: memory location
381 * Read an 8 bit unsigned integer value from the memory buffer.
383 #define GST_READ_UINT8(data) (_GST_GET (data, 0, 8, 0))
386 * GST_WRITE_UINT64_BE:
387 * @data: memory location
388 * @val: value to store
390 * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
393 * GST_WRITE_UINT64_LE:
394 * @data: memory location
395 * @val: value to store
397 * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
399 #if GST_HAVE_UNALIGNED_ACCESS
400 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
401 # define GST_WRITE_UINT64_BE(data,val) _GST_FAST_WRITE(64,data,val)
402 # define GST_WRITE_UINT64_LE(data,val) _GST_FAST_WRITE_SWAP(64,data,val)
404 # define GST_WRITE_UINT64_BE(data,val) _GST_FAST_WRITE_SWAP(64,data,val)
405 # define GST_WRITE_UINT64_LE(data,val) _GST_FAST_WRITE(64,data,val)
408 #define GST_WRITE_UINT64_BE(data,val) do { \
409 gpointer __put_data = data; \
410 guint64 __put_val = val; \
411 _GST_PUT (__put_data, 0, 64, 56, __put_val); \
412 _GST_PUT (__put_data, 1, 64, 48, __put_val); \
413 _GST_PUT (__put_data, 2, 64, 40, __put_val); \
414 _GST_PUT (__put_data, 3, 64, 32, __put_val); \
415 _GST_PUT (__put_data, 4, 64, 24, __put_val); \
416 _GST_PUT (__put_data, 5, 64, 16, __put_val); \
417 _GST_PUT (__put_data, 6, 64, 8, __put_val); \
418 _GST_PUT (__put_data, 7, 64, 0, __put_val); \
421 #define GST_WRITE_UINT64_LE(data,val) do { \
422 gpointer __put_data = data; \
423 guint64 __put_val = val; \
424 _GST_PUT (__put_data, 0, 64, 0, __put_val); \
425 _GST_PUT (__put_data, 1, 64, 8, __put_val); \
426 _GST_PUT (__put_data, 2, 64, 16, __put_val); \
427 _GST_PUT (__put_data, 3, 64, 24, __put_val); \
428 _GST_PUT (__put_data, 4, 64, 32, __put_val); \
429 _GST_PUT (__put_data, 5, 64, 40, __put_val); \
430 _GST_PUT (__put_data, 6, 64, 48, __put_val); \
431 _GST_PUT (__put_data, 7, 64, 56, __put_val); \
433 #endif /* !GST_HAVE_UNALIGNED_ACCESS */
436 * GST_WRITE_UINT32_BE:
437 * @data: memory location
438 * @val: value to store
440 * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
443 * GST_WRITE_UINT32_LE:
444 * @data: memory location
445 * @val: value to store
447 * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
449 #if GST_HAVE_UNALIGNED_ACCESS
450 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
451 # define GST_WRITE_UINT32_BE(data,val) _GST_FAST_WRITE(32,data,val)
452 # define GST_WRITE_UINT32_LE(data,val) _GST_FAST_WRITE_SWAP(32,data,val)
454 # define GST_WRITE_UINT32_BE(data,val) _GST_FAST_WRITE_SWAP(32,data,val)
455 # define GST_WRITE_UINT32_LE(data,val) _GST_FAST_WRITE(32,data,val)
458 #define GST_WRITE_UINT32_BE(data,val) do { \
459 gpointer __put_data = data; \
460 guint32 __put_val = val; \
461 _GST_PUT (__put_data, 0, 32, 24, __put_val); \
462 _GST_PUT (__put_data, 1, 32, 16, __put_val); \
463 _GST_PUT (__put_data, 2, 32, 8, __put_val); \
464 _GST_PUT (__put_data, 3, 32, 0, __put_val); \
467 #define GST_WRITE_UINT32_LE(data,val) do { \
468 gpointer __put_data = data; \
469 guint32 __put_val = val; \
470 _GST_PUT (__put_data, 0, 32, 0, __put_val); \
471 _GST_PUT (__put_data, 1, 32, 8, __put_val); \
472 _GST_PUT (__put_data, 2, 32, 16, __put_val); \
473 _GST_PUT (__put_data, 3, 32, 24, __put_val); \
475 #endif /* !GST_HAVE_UNALIGNED_ACCESS */
478 * GST_WRITE_UINT24_BE:
479 * @data: memory location
480 * @num: value to store
482 * Store a 24 bit unsigned integer value in big endian format into the memory buffer.
484 #define GST_WRITE_UINT24_BE(data, num) do { \
485 gpointer __put_data = data; \
486 guint32 __put_val = num; \
487 _GST_PUT (__put_data, 0, 32, 16, __put_val); \
488 _GST_PUT (__put_data, 1, 32, 8, __put_val); \
489 _GST_PUT (__put_data, 2, 32, 0, __put_val); \
493 * GST_WRITE_UINT24_LE:
494 * @data: memory location
495 * @num: value to store
497 * Store a 24 bit unsigned integer value in little endian format into the memory buffer.
499 #define GST_WRITE_UINT24_LE(data, num) do { \
500 gpointer __put_data = data; \
501 guint32 __put_val = num; \
502 _GST_PUT (__put_data, 0, 32, 0, __put_val); \
503 _GST_PUT (__put_data, 1, 32, 8, __put_val); \
504 _GST_PUT (__put_data, 2, 32, 16, __put_val); \
508 * GST_WRITE_UINT16_BE:
509 * @data: memory location
510 * @val: value to store
512 * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
515 * GST_WRITE_UINT16_LE:
516 * @data: memory location
517 * @val: value to store
519 * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
521 #if GST_HAVE_UNALIGNED_ACCESS
522 # if (G_BYTE_ORDER == G_BIG_ENDIAN)
523 # define GST_WRITE_UINT16_BE(data,val) _GST_FAST_WRITE(16,data,val)
524 # define GST_WRITE_UINT16_LE(data,val) _GST_FAST_WRITE_SWAP(16,data,val)
526 # define GST_WRITE_UINT16_BE(data,val) _GST_FAST_WRITE_SWAP(16,data,val)
527 # define GST_WRITE_UINT16_LE(data,val) _GST_FAST_WRITE(16,data,val)
530 #define GST_WRITE_UINT16_BE(data,val) do { \
531 gpointer __put_data = data; \
532 guint16 __put_val = val; \
533 _GST_PUT (__put_data, 0, 16, 8, __put_val); \
534 _GST_PUT (__put_data, 1, 16, 0, __put_val); \
537 #define GST_WRITE_UINT16_LE(data,val) do { \
538 gpointer __put_data = data; \
539 guint16 __put_val = val; \
540 _GST_PUT (__put_data, 0, 16, 0, __put_val); \
541 _GST_PUT (__put_data, 1, 16, 8, __put_val); \
543 #endif /* !GST_HAVE_UNALIGNED_ACCESS */
547 * @data: memory location
548 * @num: value to store
550 * Store an 8 bit unsigned integer value into the memory buffer.
552 #define GST_WRITE_UINT8(data, num) do { \
553 _GST_PUT (data, 0, 8, 0, num); \
556 /* Float endianness conversion macros */
557 #ifndef __GI_SCANNER__
559 /* FIXME: Remove this once we depend on a GLib version with this */
560 #ifndef GFLOAT_FROM_LE
562 * GFLOAT_SWAP_LE_BE: (skip)
565 * Swap byte order of a 32-bit floating point value (float).
567 * Returns: @in byte-swapped.
570 GFLOAT_SWAP_LE_BE(gfloat in)
579 u.i = GUINT32_SWAP_LE_BE (u.i);
584 * GDOUBLE_SWAP_LE_BE: (skip)
587 * Swap byte order of a 64-bit floating point value (double).
589 * Returns: @in byte-swapped.
591 static inline gdouble
592 GDOUBLE_SWAP_LE_BE(gdouble in)
601 u.i = GUINT64_SWAP_LE_BE (u.i);
606 * GDOUBLE_TO_LE: (skip)
609 * Convert 64-bit floating point value (double) from native byte order into
610 * little endian byte order.
613 * GDOUBLE_TO_BE: (skip)
616 * Convert 64-bit floating point value (double) from native byte order into
617 * big endian byte order.
620 * GDOUBLE_FROM_LE: (skip)
623 * Convert 64-bit floating point value (double) from little endian byte order
624 * into native byte order.
627 * GDOUBLE_FROM_BE: (skip)
630 * Convert 64-bit floating point value (double) from big endian byte order
631 * into native byte order.
635 * GFLOAT_TO_LE: (skip)
638 * Convert 32-bit floating point value (float) from native byte order into
639 * little endian byte order.
642 * GFLOAT_TO_BE: (skip)
645 * Convert 32-bit floating point value (float) from native byte order into
646 * big endian byte order.
649 * GFLOAT_FROM_LE: (skip)
652 * Convert 32-bit floating point value (float) from little endian byte order
653 * into native byte order.
656 * GFLOAT_FROM_BE: (skip)
659 * Convert 32-bit floating point value (float) from big endian byte order
660 * into native byte order.
663 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
664 #define GFLOAT_TO_LE(val) ((gfloat) (val))
665 #define GFLOAT_TO_BE(val) (GFLOAT_SWAP_LE_BE (val))
666 #define GDOUBLE_TO_LE(val) ((gdouble) (val))
667 #define GDOUBLE_TO_BE(val) (GDOUBLE_SWAP_LE_BE (val))
669 #elif G_BYTE_ORDER == G_BIG_ENDIAN
670 #define GFLOAT_TO_LE(val) (GFLOAT_SWAP_LE_BE (val))
671 #define GFLOAT_TO_BE(val) ((gfloat) (val))
672 #define GDOUBLE_TO_LE(val) (GDOUBLE_SWAP_LE_BE (val))
673 #define GDOUBLE_TO_BE(val) ((gdouble) (val))
675 #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
676 #error unknown ENDIAN type
677 #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
679 #define GFLOAT_FROM_LE(val) (GFLOAT_TO_LE (val))
680 #define GFLOAT_FROM_BE(val) (GFLOAT_TO_BE (val))
681 #define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val))
682 #define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
684 #endif /* !defined(GFLOAT_FROM_LE) */
686 #endif /* !__GI_SCANNER__ */
690 * @data: memory location
692 * Read a 32 bit float value in little endian format from the memory buffer.
694 * Returns: The floating point value read from @data
697 GST_READ_FLOAT_LE(const guint8 *data)
705 u.i = GST_READ_UINT32_LE (data);
711 * @data: memory location
713 * Read a 32 bit float value in big endian format from the memory buffer.
715 * Returns: The floating point value read from @data
718 GST_READ_FLOAT_BE(const guint8 *data)
726 u.i = GST_READ_UINT32_BE (data);
731 * GST_READ_DOUBLE_LE:
732 * @data: memory location
734 * Read a 64 bit double value in little endian format from the memory buffer.
736 * Returns: The double-precision floating point value read from @data
738 static inline gdouble
739 GST_READ_DOUBLE_LE(const guint8 *data)
747 u.i = GST_READ_UINT64_LE (data);
752 * GST_READ_DOUBLE_BE:
753 * @data: memory location
755 * Read a 64 bit double value in big endian format from the memory buffer.
757 * Returns: The double-precision floating point value read from @data
759 static inline gdouble
760 GST_READ_DOUBLE_BE(const guint8 *data)
768 u.i = GST_READ_UINT64_BE (data);
773 * GST_WRITE_FLOAT_LE:
774 * @data: memory location
775 * @num: value to store
777 * Store a 32 bit float value in little endian format into the memory buffer.
780 GST_WRITE_FLOAT_LE(guint8 *data, gfloat num)
789 GST_WRITE_UINT32_LE (data, u.i);
793 * GST_WRITE_FLOAT_BE:
794 * @data: memory location
795 * @num: value to store
797 * Store a 32 bit float value in big endian format into the memory buffer.
800 GST_WRITE_FLOAT_BE(guint8 *data, gfloat num)
809 GST_WRITE_UINT32_BE (data, u.i);
813 * GST_WRITE_DOUBLE_LE:
814 * @data: memory location
815 * @num: value to store
817 * Store a 64 bit double value in little endian format into the memory buffer.
820 GST_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
829 GST_WRITE_UINT64_LE (data, u.i);
833 * GST_WRITE_DOUBLE_BE:
834 * @data: memory location
835 * @num: value to store
837 * Store a 64 bit double value in big endian format into the memory buffer.
840 GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
849 GST_WRITE_UINT64_BE (data, u.i);
852 /* Miscellaneous utility macros */
856 * @num: integer value to round up
858 * Rounds an integer value up to the next multiple of 2.
860 #define GST_ROUND_UP_2(num) (((num)+1)&~1)
863 * @num: integer value to round up
865 * Rounds an integer value up to the next multiple of 4.
867 #define GST_ROUND_UP_4(num) (((num)+3)&~3)
870 * @num: integer value to round up
872 * Rounds an integer value up to the next multiple of 8.
874 #define GST_ROUND_UP_8(num) (((num)+7)&~7)
877 * @num: integer value to round up
879 * Rounds an integer value up to the next multiple of 16.
881 #define GST_ROUND_UP_16(num) (((num)+15)&~15)
884 * @num: integer value to round up
886 * Rounds an integer value up to the next multiple of 32.
888 #define GST_ROUND_UP_32(num) (((num)+31)&~31)
891 * @num: integer value to round up
893 * Rounds an integer value up to the next multiple of 64.
895 #define GST_ROUND_UP_64(num) (((num)+63)&~63)
898 * @num: integer value to round up
900 * Rounds an integer value up to the next multiple of 128.
903 #define GST_ROUND_UP_128(num) (((num)+127)&~127)
906 * @num: integrer value to round up
907 * @align: a power of two to round up to
909 * Rounds an integer value up to the next multiple of @align. @align MUST be a
912 #define GST_ROUND_UP_N(num,align) ((((num) + ((align) - 1)) & ~((align) - 1)))
917 * @num: integer value to round down
919 * Rounds an integer value down to the next multiple of 2.
921 #define GST_ROUND_DOWN_2(num) ((num)&(~1))
924 * @num: integer value to round down
926 * Rounds an integer value down to the next multiple of 4.
928 #define GST_ROUND_DOWN_4(num) ((num)&(~3))
931 * @num: integer value to round down
933 * Rounds an integer value down to the next multiple of 8.
935 #define GST_ROUND_DOWN_8(num) ((num)&(~7))
938 * @num: integer value to round down
940 * Rounds an integer value down to the next multiple of 16.
942 #define GST_ROUND_DOWN_16(num) ((num)&(~15))
945 * @num: integer value to round down
947 * Rounds an integer value down to the next multiple of 32.
949 #define GST_ROUND_DOWN_32(num) ((num)&(~31))
952 * @num: integer value to round down
954 * Rounds an integer value down to the next multiple of 64.
956 #define GST_ROUND_DOWN_64(num) ((num)&(~63))
958 * GST_ROUND_DOWN_128:
959 * @num: integer value to round down
961 * Rounds an integer value down to the next multiple of 128.
964 #define GST_ROUND_DOWN_128(num) ((num)&(~127))
967 * @num: integrer value to round down
968 * @align: a power of two to round down to
970 * Rounds an integer value down to the next multiple of @align. @align MUST be a
973 #define GST_ROUND_DOWN_N(num,align) (((num) & ~((align) - 1)))
977 void gst_object_default_error (GstObject * source,
978 const GError * error,
979 const gchar * debug);
981 /* element functions */
984 void gst_element_create_all_pads (GstElement *element);
987 GstPad* gst_element_get_compatible_pad (GstElement *element, GstPad *pad,
990 GstPadTemplate* gst_element_get_compatible_pad_template (GstElement *element, GstPadTemplate *compattempl);
993 const gchar* gst_element_state_get_name (GstState state);
996 const gchar * gst_element_state_change_return_get_name (GstStateChangeReturn state_ret);
999 const gchar * gst_state_change_get_name (GstStateChange transition);
1002 gboolean gst_element_link (GstElement *src, GstElement *dest);
1005 gboolean gst_element_link_many (GstElement *element_1,
1006 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
1008 gboolean gst_element_link_filtered (GstElement * src,
1012 void gst_element_unlink (GstElement *src, GstElement *dest);
1015 void gst_element_unlink_many (GstElement *element_1,
1016 GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
1018 gboolean gst_element_link_pads (GstElement *src, const gchar *srcpadname,
1019 GstElement *dest, const gchar *destpadname);
1021 gboolean gst_element_link_pads_full (GstElement *src, const gchar *srcpadname,
1022 GstElement *dest, const gchar *destpadname,
1023 GstPadLinkCheck flags);
1025 void gst_element_unlink_pads (GstElement *src, const gchar *srcpadname,
1026 GstElement *dest, const gchar *destpadname);
1028 gboolean gst_element_link_pads_filtered (GstElement * src, const gchar * srcpadname,
1029 GstElement * dest, const gchar * destpadname,
1032 gboolean gst_element_seek_simple (GstElement *element,
1034 GstSeekFlags seek_flags,
1037 /* util elementfactory functions */
1040 gboolean gst_element_factory_can_sink_all_caps (GstElementFactory *factory, const GstCaps *caps);
1043 gboolean gst_element_factory_can_src_all_caps (GstElementFactory *factory, const GstCaps *caps);
1046 gboolean gst_element_factory_can_sink_any_caps (GstElementFactory *factory, const GstCaps *caps);
1049 gboolean gst_element_factory_can_src_any_caps (GstElementFactory *factory, const GstCaps *caps);
1051 /* util query functions */
1054 gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur);
1057 gboolean gst_element_query_duration (GstElement *element, GstFormat format, gint64 *duration);
1060 gboolean gst_element_query_convert (GstElement *element, GstFormat src_format, gint64 src_val,
1061 GstFormat dest_format, gint64 *dest_val);
1066 void gst_pad_use_fixed_caps (GstPad *pad);
1069 GstElement* gst_pad_get_parent_element (GstPad *pad);
1071 /* util query functions */
1074 gboolean gst_pad_proxy_query_accept_caps (GstPad *pad, GstQuery *query);
1077 gboolean gst_pad_proxy_query_caps (GstPad *pad, GstQuery *query);
1080 gboolean gst_pad_query_position (GstPad *pad, GstFormat format, gint64 *cur);
1083 gboolean gst_pad_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
1086 gboolean gst_pad_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
1087 GstFormat dest_format, gint64 *dest_val);
1089 GstCaps * gst_pad_query_caps (GstPad *pad, GstCaps *filter);
1092 gboolean gst_pad_query_accept_caps (GstPad *pad, GstCaps *caps);
1095 gboolean gst_pad_link_maybe_ghosting (GstPad *src,
1098 gboolean gst_pad_link_maybe_ghosting_full (GstPad *src,
1100 GstPadLinkCheck flags);
1102 gboolean gst_pad_peer_query_position (GstPad *pad, GstFormat format, gint64 *cur);
1105 gboolean gst_pad_peer_query_duration (GstPad *pad, GstFormat format, gint64 *duration);
1108 gboolean gst_pad_peer_query_convert (GstPad *pad, GstFormat src_format, gint64 src_val,
1109 GstFormat dest_format, gint64 *dest_val);
1111 GstCaps * gst_pad_peer_query_caps (GstPad * pad, GstCaps *filter);
1114 gboolean gst_pad_peer_query_accept_caps (GstPad * pad, GstCaps *caps);
1117 gchar * gst_pad_create_stream_id (GstPad * pad, GstElement * parent, const gchar *stream_id) G_GNUC_MALLOC;
1120 gchar * gst_pad_create_stream_id_printf (GstPad * pad, GstElement * parent, const gchar *stream_id, ...) G_GNUC_PRINTF (3, 4) G_GNUC_MALLOC;
1123 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;
1126 gchar * gst_pad_get_stream_id (GstPad * pad);
1129 GstStream * gst_pad_get_stream (GstPad * pad);
1134 void gst_bin_add_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
1137 void gst_bin_remove_many (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
1140 GstPad * gst_bin_find_unlinked_pad (GstBin *bin, GstPadDirection direction);
1143 gboolean gst_bin_sync_children_states (GstBin *bin);
1145 /* parse utility functions */
1148 GstElement * gst_parse_bin_from_description (const gchar * bin_description,
1149 gboolean ghost_unlinked_pads,
1152 GstElement * gst_parse_bin_from_description_full (const gchar * bin_description,
1153 gboolean ghost_unlinked_pads,
1154 GstParseContext * context,
1155 GstParseFlags flags,
1158 GstClockTime gst_util_get_timestamp (void);
1162 * @GST_SEARCH_MODE_EXACT : Only search for exact matches.
1163 * @GST_SEARCH_MODE_BEFORE: Search for an exact match or the element just before.
1164 * @GST_SEARCH_MODE_AFTER : Search for an exact match or the element just after.
1166 * The different search modes.
1169 GST_SEARCH_MODE_EXACT = 0,
1170 GST_SEARCH_MODE_BEFORE,
1171 GST_SEARCH_MODE_AFTER
1175 * GstPluginAPIFlags:
1176 * @GST_PLUGIN_API_FLAG_IGNORE_ENUM_MEMBERS: Ignore enum members when generating
1177 * the plugins cache. This is useful if the members of the enum are generated
1178 * dynamically, in order not to expose incorrect documentation to the end user.
1183 GST_PLUGIN_API_FLAG_IGNORE_ENUM_MEMBERS = (1 << 0),
1184 } GstPluginAPIFlags;
1187 gpointer gst_util_array_binary_search (gpointer array, guint num_elements,
1188 gsize element_size, GCompareDataFunc search_func,
1189 GstSearchMode mode, gconstpointer search_data,
1190 gpointer user_data);
1192 /* fraction operations */
1195 gint gst_util_greatest_common_divisor (gint a, gint b);
1198 gint64 gst_util_greatest_common_divisor_int64 (gint64 a, gint64 b);
1201 void gst_util_fraction_to_double (gint src_n, gint src_d, gdouble *dest);
1204 void gst_util_double_to_fraction (gdouble src, gint *dest_n, gint *dest_d);
1207 gboolean gst_util_fraction_multiply (gint a_n, gint a_d, gint b_n, gint b_d,
1208 gint *res_n, gint *res_d);
1210 gboolean gst_util_fraction_add (gint a_n, gint a_d, gint b_n, gint b_d,
1211 gint *res_n, gint *res_d);
1213 gint gst_util_fraction_compare (gint a_n, gint a_d, gint b_n, gint b_d);
1216 gboolean gst_calculate_linear_regression (const GstClockTime * xy,
1217 GstClockTime * temp, guint n,
1218 GstClockTime * m_num, GstClockTime * m_denom,
1219 GstClockTime * b, GstClockTime * xbase,
1220 gdouble * r_squared);
1223 void gst_type_mark_as_plugin_api (GType type, GstPluginAPIFlags flags);
1226 gboolean gst_type_is_plugin_api (GType type, GstPluginAPIFlags *flags);
1230 #endif /* __GST_UTILS_H__ */