gstutils.h 27.6 KB
Newer Older
1
2
3
/* GStreamer
 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
 *                    2000 Wim Taymans <wtay@chello.be>
4
 *                    2002 Thomas Vander Stichele <thomas@apestaart.org>
5
6
 *
 * gstutils.h: Header for various utility functions
Erik Walthinsen's avatar
Erik Walthinsen committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


#ifndef __GST_UTILS_H__
#define __GST_UTILS_H__

28
#include <glib.h>
29
#include <gst/gstbin.h>
30
#include <gst/gstparse.h>
Erik Walthinsen's avatar
Erik Walthinsen committed
31

32
G_BEGIN_DECLS
33

34
void		gst_util_set_value_from_string	(GValue *value, const gchar *value_str);
35
36
void		gst_util_set_object_arg		(GObject *object, const gchar *name, const gchar *value);
void		gst_util_dump_mem		(const guchar *mem, guint size);
Erik Walthinsen's avatar
Erik Walthinsen committed
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
guint64         gst_util_gdouble_to_guint64     (gdouble value);
gdouble         gst_util_guint64_to_gdouble     (guint64 value);

/**
 * gst_guint64_to_gdouble:
 * @value: the #guint64 value to convert
 *
 * Convert @value to a gdouble.
 *
 * Returns: @value converted to a #gdouble.
 */

/**
 * gst_gdouble_to_guint64:
 * @value: the #gdouble value to convert
 *
 * Convert @value to a guint64.
 *
 * Returns: @value converted to a #guint64.
 */
58
#ifdef WIN32
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
59
60
#define         gst_gdouble_to_guint64(value)   gst_util_gdouble_to_guint64(value)
#define         gst_guint64_to_gdouble(value)   gst_util_guint64_to_gdouble(value)
61
#else
62
63
#define         gst_gdouble_to_guint64(value)   ((guint64) (value))
#define         gst_guint64_to_gdouble(value)   ((gdouble) (value))
64
65
#endif

66
67
guint64		gst_util_uint64_scale		(guint64 val, guint64 num, guint64 denom);

Jan Schmidt's avatar
Jan Schmidt committed
68
guint64         gst_util_uint64_scale_int       (guint64 val, gint num, gint denom);
69

70
71
void		gst_print_pad_caps		(GString *buf, gint indent, GstPad *pad);
void		gst_print_element_args		(GString *buf, gint indent, GstElement *element);
72

73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
GType gst_type_register_static_full (GType parent_type,
			                   const gchar       *type_name,
                               guint              class_size,
                               GBaseInitFunc      base_init,
                               GBaseFinalizeFunc  base_finalize,
                               GClassInitFunc     class_init,
                               GClassFinalizeFunc class_finalize,
                               gconstpointer      class_data,
                               guint              instance_size,
                               guint16            n_preallocs,
                               GInstanceInitFunc  instance_init,
                               const GTypeValueTable *value_table,
                               GTypeFlags	 flags);


Wim Taymans's avatar
Wim Taymans committed
89
/* Macros for defining classes.  Ideas taken from Bonobo, which took theirs
90
91
   from Nautilus and GOB. */

92
93
94
95
96
97
98
99
100
/* FIXME: Use g_once_init_* unconditionally once we depend on glib 2.14 */
#if GLIB_CHECK_VERSION (2, 14, 0)
#define __gst_once_init_enter(val) (g_once_init_enter (val))
#define __gst_once_init_leave(val,newval) (g_once_init_leave (val, newval))
#else
#define __gst_once_init_enter(val) (G_UNLIKELY (*(val) == 0))
#define __gst_once_init_leave(val,newval) (*(val) = newval)
#endif

101
102
103
104
105
106
/**
 * GST_BOILERPLATE_FULL:
 * @type: the name of the type struct
 * @type_as_function: the prefix for the functions
 * @parent_type: the parent type struct name
 * @parent_type_macro: the parent type macro
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
107
 * @additional_initializations: function pointer in the form of
108
109
110
111
112
113
114
115
116
117
118
119
 * void additional_initializations (GType type) that can be used for
 * initializing interfaces and the like
 *
 * Define the boilerplate type stuff to reduce typos and code size.  Defines
 * the get_type method and the parent_class static variable.
 *
 * <informalexample>
 * <programlisting>
 *   GST_BOILERPLATE_FULL (GstFdSink, gst_fdsink, GstElement, GST_TYPE_ELEMENT, _do_init);
 * </programlisting>
 * </informalexample>
 */
Wim Taymans's avatar
Wim Taymans committed
120
121
122
123
#define GST_BOILERPLATE_FULL(type, type_as_function, parent_type, parent_type_macro, additional_initializations)	\
									\
static void type_as_function ## _base_init     (gpointer      g_class);	\
static void type_as_function ## _class_init    (type ## Class *g_class);\
124
125
static void type_as_function ## _init	       (type          *object,	\
                                                type ## Class *g_class);\
Wim Taymans's avatar
Wim Taymans committed
126
127
128
129
130
131
132
133
134
135
static parent_type ## Class *parent_class = NULL;			\
static void								\
type_as_function ## _class_init_trampoline (gpointer g_class,		\
					    gpointer data)		\
{									\
  parent_class = (parent_type ## Class *)				\
      g_type_class_peek_parent (g_class);				\
  type_as_function ## _class_init ((type ## Class *)g_class);		\
}									\
									\
136
137
GType type_as_function ## _get_type (void);				\
									\
Wim Taymans's avatar
Wim Taymans committed
138
139
140
GType									\
type_as_function ## _get_type (void)					\
{									\
141
142
143
144
145
  /* The typedef for GType may be gulong or gsize, depending on the	\
   * system and whether the compiler is c++ or not. The g_once_init_*	\
   * functions always take a gsize * though ... */			\
  static volatile gsize gonce_data;					\
  if (__gst_once_init_enter (&gonce_data)) {				\
146
    GType _type;							\
147
148
    _type = gst_type_register_static_full (parent_type_macro,           \
        g_intern_static_string (#type),					\
149
	sizeof (type ## Class),						\
150
151
152
153
154
155
156
157
158
159
        type_as_function ## _base_init,					\
        NULL,		  /* base_finalize */				\
        type_as_function ## _class_init_trampoline,			\
        NULL,		  /* class_finalize */				\
        NULL,               /* class_data */				\
        sizeof (type),							\
        0,                  /* n_preallocs */				\
        (GInstanceInitFunc) type_as_function ## _init,                  \
        NULL,                                                           \
        (GTypeFlags) 0);				                \
160
    additional_initializations (_type);				        \
161
    __gst_once_init_leave (&gonce_data, (gsize) _type);			\
Wim Taymans's avatar
Wim Taymans committed
162
  }									\
163
  return (GType) gonce_data;						\
164
165
166
}

#define __GST_DO_NOTHING(type)	/* NOP */
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

/**
 * GST_BOILERPLATE:
 * @type: the name of the type struct
 * @type_as_function: the prefix for the functions
 * @parent_type: the parent type struct name
 * @parent_type_macro: the parent type macro
 *
 * Define the boilerplate type stuff to reduce typos and code size.  Defines
 * the get_type method and the parent_class static variable.
 *
 * <informalexample>
 * <programlisting>
 *   GST_BOILERPLATE (GstFdSink, gst_fdsink, GstElement, GST_TYPE_ELEMENT);
 * </programlisting>
 * </informalexample>
 */
184
185
186
187
#define GST_BOILERPLATE(type,type_as_function,parent_type,parent_type_macro)	\
  GST_BOILERPLATE_FULL (type, type_as_function, parent_type, parent_type_macro,	\
      __GST_DO_NOTHING)

188
189
190
191
192
193
/* Like GST_BOILERPLATE, but makes the type 1) implement an interface, and 2)
 * implement GstImplementsInterface for that type
 *
 * After this you will need to implement interface_as_function ## _supported
 * and interface_as_function ## _interface_init
 */
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
 * GST_BOILERPLATE_WITH_INTERFACE:
 * @type: the name of the type struct
 * @type_as_function: the prefix for the functions
 * @parent_type: the parent type struct name
 * @parent_type_as_macro: the parent type macro
 * @interface_type: the name of the interface type struct
 * @interface_type_as_macro: the interface type macro
 * @interface_as_function: the interface function name prefix
 *
 * Like GST_BOILERPLATE, but makes the type 1) implement an interface, and 2)
 * implement GstImplementsInterface for that type.
 *
 * After this you will need to implement interface_as_function ## _supported
 * and interface_as_function ## _interface_init
 */
210
211
212
213
#define GST_BOILERPLATE_WITH_INTERFACE(type, type_as_function,		\
    parent_type, parent_type_as_macro, interface_type,			\
    interface_type_as_macro, interface_as_function)			\
                                                                        \
214
215
static void interface_as_function ## _interface_init (interface_type ## Class *klass);  \
static gboolean interface_as_function ## _supported (type *object, GType iface_type);   \
216
217
                                                                        \
static void                                                             \
218
type_as_function ## _implements_interface_init (GstImplementsInterfaceClass *klass)     \
219
{                                                                       \
220
  klass->supported = (gboolean (*)(GstImplementsInterface*, GType))interface_as_function ## _supported;     \
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
}                                                                       \
                                                                        \
static void                                                             \
type_as_function ## _init_interfaces (GType type)                       \
{                                                                       \
  static const GInterfaceInfo implements_iface_info = {                 \
    (GInterfaceInitFunc) type_as_function ## _implements_interface_init,\
    NULL,                                                               \
    NULL,                                                               \
  };                                                                    \
  static const GInterfaceInfo iface_info = {                            \
    (GInterfaceInitFunc) interface_as_function ## _interface_init,      \
    NULL,                                                               \
    NULL,                                                               \
  };                                                                    \
                                                                        \
  g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE,     \
      &implements_iface_info);                                          \
  g_type_add_interface_static (type, interface_type_as_macro,		\
      &iface_info);							\
}                                                                       \
                                                                        \
GST_BOILERPLATE_FULL (type, type_as_function, parent_type,              \
244
245
    parent_type_as_macro, type_as_function ## _init_interfaces)

Stefan Kost's avatar
Stefan Kost committed
246
247
248
249
250
251
252
/**
 * GST_CALL_PARENT:
 * @parent_class_cast: the name of the class cast macro for the parent type
 * @name: name of the function to call
 * @args: arguments enclosed in '( )'
 *
 * Just call the parent handler.  This assumes that there is a variable
253
254
 * named parent_class that points to the (duh!) parent class.  Note that
 * this macro is not to be used with things that return something, use
Stefan Kost's avatar
Stefan Kost committed
255
256
 * the _WITH_DEFAULT version for that
 */
257
258
#define GST_CALL_PARENT(parent_class_cast, name, args)			\
	((parent_class_cast(parent_class)->name != NULL) ?		\
259
260
	 parent_class_cast(parent_class)->name args : (void) 0)

Stefan Kost's avatar
Stefan Kost committed
261
262
263
264
265
266
267
268
269
270
271
/**
 * GST_CALL_PARENT_WITH_DEFAULT:
 * @parent_class_cast: the name of the class cast macro for the parent type
 * @name: name of the function to call
 * @args: arguments enclosed in '( )'
 * @def_return: default result
 *
 * Same as GST_CALL_PARENT(), but in case there is no implementation, it
 * evaluates to @def_return.
 */
#define GST_CALL_PARENT_WITH_DEFAULT(parent_class_cast, name, args, def_return)\
272
	((parent_class_cast(parent_class)->name != NULL) ?		\
273
274
	 parent_class_cast(parent_class)->name args : def_return)

275
276
277
278
279
280
281
/* Define possibly unaligned memory access method whether the type of
 * architecture. */
#if GST_HAVE_UNALIGNED_ACCESS

#define _GST_GET(__data, __size, __end) \
    (GUINT##__size##_FROM_##__end (* ((guint##__size *) (__data))))

Stefan Kost's avatar
Stefan Kost committed
282
283
284
285
286
287
/**
 * GST_READ_UINT64_BE:
 * @data: memory location
 *
 * Read a 64 bit unsigned integer value in big endian format from the memory buffer.
 */
288
#define GST_READ_UINT64_BE(data)	_GST_GET (data, 64, BE)
Stefan Kost's avatar
Stefan Kost committed
289
290
291
292
293
294
/**
 * GST_READ_UINT64_LE:
 * @data: memory location
 *
 * Read a 64 bit unsigned integer value in little endian format from the memory buffer.
 */
295
#define GST_READ_UINT64_LE(data)	_GST_GET (data, 64, LE)
Stefan Kost's avatar
Stefan Kost committed
296
297
298
299
300
301
/**
 * GST_READ_UINT32_BE:
 * @data: memory location
 *
 * Read a 32 bit unsigned integer value in big endian format from the memory buffer.
 */
302
#define GST_READ_UINT32_BE(data)	_GST_GET (data, 32, BE)
Stefan Kost's avatar
Stefan Kost committed
303
304
305
306
307
308
/**
 * GST_READ_UINT32_LE:
 * @data: memory location
 *
 * Read a 32 bit unsigned integer value in little endian format from the memory buffer.
 */
309
#define GST_READ_UINT32_LE(data)        _GST_GET (data, 32, LE)
Stefan Kost's avatar
Stefan Kost committed
310
311
312
313
314
315
/**
 * GST_READ_UINT16_BE:
 * @data: memory location
 *
 * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
 */
316
#define GST_READ_UINT16_BE(data)        _GST_GET (data, 16, BE)
Stefan Kost's avatar
Stefan Kost committed
317
318
319
320
321
322
/**
 * GST_READ_UINT16_LE:
 * @data: memory location
 *
 * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
 */
323
#define GST_READ_UINT16_LE(data)        _GST_GET (data, 16, LE)
Stefan Kost's avatar
Stefan Kost committed
324
325
326
327
328
329
/**
 * GST_READ_UINT8:
 * @data: memory location
 *
 * Read an 8 bit unsigned integer value from the memory buffer.
 */
330
#define GST_READ_UINT8(data)		(* ((guint8 *) (data)))
331
332
333
334

#define _GST_PUT(__data, __size, __end, __num) \
    ((* (guint##__size *) (__data)) = GUINT##__size##_TO_##__end (__num))

Stefan Kost's avatar
Stefan Kost committed
335
336
337
338
339
340
341
/**
 * GST_WRITE_UINT64_BE:
 * @data: memory location
 * @num: value to store
 *
 * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
 */
342
#define GST_WRITE_UINT64_BE(data, num)	_GST_PUT(data, 64, BE, num)
Stefan Kost's avatar
Stefan Kost committed
343
344
345
346
347
348
349
/**
 * GST_WRITE_UINT64_LE:
 * @data: memory location
 * @num: value to store
 *
 * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
 */
350
#define GST_WRITE_UINT64_LE(data, num)  _GST_PUT(data, 64, LE, num)
Stefan Kost's avatar
Stefan Kost committed
351
352
353
354
355
356
357
/**
 * GST_WRITE_UINT32_BE:
 * @data: memory location
 * @num: value to store
 *
 * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
 */
358
#define GST_WRITE_UINT32_BE(data, num)  _GST_PUT(data, 32, BE, num)
Stefan Kost's avatar
Stefan Kost committed
359
360
361
362
363
364
365
/**
 * GST_WRITE_UINT32_LE:
 * @data: memory location
 * @num: value to store
 *
 * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
 */
366
#define GST_WRITE_UINT32_LE(data, num)  _GST_PUT(data, 32, LE, num)
Stefan Kost's avatar
Stefan Kost committed
367
368
369
370
371
372
373
/**
 * GST_WRITE_UINT16_BE:
 * @data: memory location
 * @num: value to store
 *
 * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
 */
374
#define GST_WRITE_UINT16_BE(data, num)  _GST_PUT(data, 16, BE, num)
Stefan Kost's avatar
Stefan Kost committed
375
376
377
378
379
380
381
/**
 * GST_WRITE_UINT16_LE:
 * @data: memory location
 * @num: value to store
 *
 * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
 */
382
#define GST_WRITE_UINT16_LE(data, num)  _GST_PUT(data, 16, LE, num)
Stefan Kost's avatar
Stefan Kost committed
383
384
385
386
387
388
389
/**
 * GST_WRITE_UINT8:
 * @data: memory location
 * @num: value to store
 *
 * Store an 8 bit unsigned integer value into the memory buffer.
 */
390
#define GST_WRITE_UINT8(data, num)	((* (guint8 *) (data)) = (num))
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433

#else /* GST_HAVE_UNALIGNED_ACCESS */

#define _GST_GET(__data, __idx, __size, __shift) \
    (((guint##__size) (((guint8 *) (__data))[__idx])) << __shift)

#define GST_READ_UINT64_BE(data)	(_GST_GET (data, 0, 64, 56) | \
					 _GST_GET (data, 1, 64, 48) | \
					 _GST_GET (data, 2, 64, 40) | \
					 _GST_GET (data, 3, 64, 32) | \
					 _GST_GET (data, 4, 64, 24) | \
					 _GST_GET (data, 5, 64, 16) | \
					 _GST_GET (data, 6, 64,  8) | \
					 _GST_GET (data, 7, 64,  0))

#define GST_READ_UINT64_LE(data)	(_GST_GET (data, 7, 64, 56) | \
					 _GST_GET (data, 6, 64, 48) | \
					 _GST_GET (data, 5, 64, 40) | \
					 _GST_GET (data, 4, 64, 32) | \
					 _GST_GET (data, 3, 64, 24) | \
					 _GST_GET (data, 2, 64, 16) | \
					 _GST_GET (data, 1, 64,  8) | \
					 _GST_GET (data, 0, 64,  0))

#define GST_READ_UINT32_BE(data)	(_GST_GET (data, 0, 32, 24) | \
					 _GST_GET (data, 1, 32, 16) | \
					 _GST_GET (data, 2, 32,  8) | \
					 _GST_GET (data, 3, 32,  0))

#define GST_READ_UINT32_LE(data)	(_GST_GET (data, 3, 32, 24) | \
					 _GST_GET (data, 2, 32, 16) | \
					 _GST_GET (data, 1, 32,  8) | \
					 _GST_GET (data, 0, 32,  0))

#define GST_READ_UINT16_BE(data)	(_GST_GET (data, 0, 16,  8) | \
					 _GST_GET (data, 1, 16,  0))

#define GST_READ_UINT16_LE(data)	(_GST_GET (data, 1, 16,  8) | \
					 _GST_GET (data, 0, 16,  0))

#define GST_READ_UINT8(data)		(_GST_GET (data, 0,  8,  0))

#define _GST_PUT(__data, __idx, __size, __shift, __num) \
434
    (((guint8 *) (__data))[__idx] = (((guint##__size) __num) >> __shift) & 0xff)
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

#define GST_WRITE_UINT64_BE(data, num)	do { \
					  _GST_PUT (data, 0, 64, 56, num); \
					  _GST_PUT (data, 1, 64, 48, num); \
					  _GST_PUT (data, 2, 64, 40, num); \
					  _GST_PUT (data, 3, 64, 32, num); \
					  _GST_PUT (data, 4, 64, 24, num); \
					  _GST_PUT (data, 5, 64, 16, num); \
					  _GST_PUT (data, 6, 64,  8, num); \
					  _GST_PUT (data, 7, 64,  0, num); \
					} while (0)

#define GST_WRITE_UINT64_LE(data, num)	do { \
					  _GST_PUT (data, 0, 64,  0, num); \
					  _GST_PUT (data, 1, 64,  8, num); \
					  _GST_PUT (data, 2, 64, 16, num); \
					  _GST_PUT (data, 3, 64, 24, num); \
					  _GST_PUT (data, 4, 64, 32, num); \
					  _GST_PUT (data, 5, 64, 40, num); \
					  _GST_PUT (data, 6, 64, 48, num); \
					  _GST_PUT (data, 7, 64, 56, num); \
					} while (0)

#define GST_WRITE_UINT32_BE(data, num)	do { \
					  _GST_PUT (data, 0, 32, 24, num); \
					  _GST_PUT (data, 1, 32, 16, num); \
					  _GST_PUT (data, 2, 32,  8, num); \
					  _GST_PUT (data, 3, 32,  0, num); \
					} while (0)

#define GST_WRITE_UINT32_LE(data, num)	do { \
					  _GST_PUT (data, 0, 32,  0, num); \
					  _GST_PUT (data, 1, 32,  8, num); \
					  _GST_PUT (data, 2, 32, 16, num); \
					  _GST_PUT (data, 3, 32, 24, num); \
					} while (0)

#define GST_WRITE_UINT16_BE(data, num)	do { \
					  _GST_PUT (data, 0, 16,  8, num); \
					  _GST_PUT (data, 1, 16,  0, num); \
					} while (0)

#define GST_WRITE_UINT16_LE(data, num)	do { \
					  _GST_PUT (data, 0, 16,  0, num); \
					  _GST_PUT (data, 1, 16,  8, num); \
					} while (0)

#define GST_WRITE_UINT8(data, num)	do { \
					  _GST_PUT (data, 0,  8,  0, num); \
					} while (0)

#endif /* GST_HAVE_UNALIGNED_ACCESS */
487

488
489

/* Miscellaneous utility macros */
Stefan Kost's avatar
Stefan Kost committed
490
491
492

/**
 * GST_ROUND_UP_2:
493
 * @num: integer value to round up
Stefan Kost's avatar
Stefan Kost committed
494
 *
495
 * Rounds an integer value up to the next multiple of 2.
Stefan Kost's avatar
Stefan Kost committed
496
 */
497
#define GST_ROUND_UP_2(num)  (((num)+1)&~1)
Stefan Kost's avatar
Stefan Kost committed
498
499
/**
 * GST_ROUND_UP_4:
500
 * @num: integer value to round up
Stefan Kost's avatar
Stefan Kost committed
501
 *
502
 * Rounds an integer value up to the next multiple of 4.
Stefan Kost's avatar
Stefan Kost committed
503
 */
504
#define GST_ROUND_UP_4(num)  (((num)+3)&~3)
Stefan Kost's avatar
Stefan Kost committed
505
506
/**
 * GST_ROUND_UP_8:
507
 * @num: integer value to round up
Stefan Kost's avatar
Stefan Kost committed
508
 *
509
 * Rounds an integer value up to the next multiple of 8.
Stefan Kost's avatar
Stefan Kost committed
510
 */
511
#define GST_ROUND_UP_8(num)  (((num)+7)&~7)
Stefan Kost's avatar
Stefan Kost committed
512
513
/**
 * GST_ROUND_UP_16:
514
 * @num: integer value to round up
Stefan Kost's avatar
Stefan Kost committed
515
 *
516
 * Rounds an integer value up to the next multiple of 16.
Stefan Kost's avatar
Stefan Kost committed
517
 */
518
#define GST_ROUND_UP_16(num) (((num)+15)&~15)
Stefan Kost's avatar
Stefan Kost committed
519
520
/**
 * GST_ROUND_UP_32:
521
 * @num: integer value to round up
Stefan Kost's avatar
Stefan Kost committed
522
 *
523
 * Rounds an integer value up to the next multiple of 32.
Stefan Kost's avatar
Stefan Kost committed
524
 */
525
#define GST_ROUND_UP_32(num) (((num)+31)&~31)
Stefan Kost's avatar
Stefan Kost committed
526
527
/**
 * GST_ROUND_UP_64:
528
 * @num: integer value to round up
Stefan Kost's avatar
Stefan Kost committed
529
 *
530
 * Rounds an integer value up to the next multiple of 64.
Stefan Kost's avatar
Stefan Kost committed
531
 */
532
533
#define GST_ROUND_UP_64(num) (((num)+63)&~63)

534
535
536
537
/**
 * GST_ROUND_DOWN_2:
 * @num: integer value to round down
 *
538
 * Rounds an integer value down to the next multiple of 2.
539
540
541
542
543
544
545
546
 *
 * Since: 0.10.12
 */
#define GST_ROUND_DOWN_2(num)  ((num)&(~1))
/**
 * GST_ROUND_DOWN_4:
 * @num: integer value to round down
 *
547
 * Rounds an integer value down to the next multiple of 4.
548
549
550
551
552
553
554
555
 *
 * Since: 0.10.12
 */
#define GST_ROUND_DOWN_4(num)  ((num)&(~3))
/**
 * GST_ROUND_DOWN_8:
 * @num: integer value to round down
 *
556
 * Rounds an integer value down to the next multiple of 8.
557
558
559
560
561
562
563
564
 *
 * Since: 0.10.12
 */
#define GST_ROUND_DOWN_8(num)  ((num)&(~7))
/**
 * GST_ROUND_DOWN_16:
 * @num: integer value to round down
 *
565
 * Rounds an integer value down to the next multiple of 16.
566
567
568
569
570
571
572
573
 *
 * Since: 0.10.12
 */
#define GST_ROUND_DOWN_16(num) ((num)&(~15))
/**
 * GST_ROUND_DOWN_32:
 * @num: integer value to round down
 *
574
 * Rounds an integer value down to the next multiple of 32.
575
576
577
578
579
580
581
582
 *
 * Since: 0.10.12
 */
#define GST_ROUND_DOWN_32(num) ((num)&(~31))
/**
 * GST_ROUND_DOWN_64:
 * @num: integer value to round down
 *
583
 * Rounds an integer value down to the next multiple of 64.
584
585
586
587
588
 *
 * Since: 0.10.12
 */
#define GST_ROUND_DOWN_64(num) ((num)&(~63))

589
void			gst_object_default_error	(GstObject * source,
590
591
592
							 GError * error, gchar * debug);

/* element functions */
593
void                    gst_element_create_all_pads     (GstElement *element);
594
595
GstPad*                 gst_element_get_compatible_pad  (GstElement *element, GstPad *pad,
		                                         const GstCaps *caps);
596
597
598

GstPadTemplate*         gst_element_get_compatible_pad_template (GstElement *element, GstPadTemplate *compattempl);

599
G_CONST_RETURN gchar*   gst_element_state_get_name      (GstState state);
600
G_CONST_RETURN gchar *  gst_element_state_change_return_get_name (GstStateChangeReturn state_ret);
601
602
603

gboolean		gst_element_link                (GstElement *src, GstElement *dest);
gboolean		gst_element_link_many           (GstElement *element_1,
604
		                                         GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
605
606
607
gboolean		gst_element_link_filtered	(GstElement * src,
                                                         GstElement * dest,
                                                         GstCaps *filter);
608
609
void                    gst_element_unlink              (GstElement *src, GstElement *dest);
void                    gst_element_unlink_many         (GstElement *element_1,
610
		                                         GstElement *element_2, ...) G_GNUC_NULL_TERMINATED;
611
612
613
614
615

gboolean		gst_element_link_pads           (GstElement *src, const gchar *srcpadname,
		                                         GstElement *dest, const gchar *destpadname);
void                    gst_element_unlink_pads         (GstElement *src, const gchar *srcpadname,
		                                         GstElement *dest, const gchar *destpadname);
616

617
618
619
gboolean		gst_element_link_pads_filtered	(GstElement * src, const gchar * srcpadname,
                                                         GstElement * dest, const gchar * destpadname,
                                                         GstCaps *filter);
620
621
622
623
624
625

gboolean        gst_element_seek_simple (GstElement   *element,
                                         GstFormat     format,
                                         GstSeekFlags  seek_flags,
                                         gint64        seek_pos);

626
627
628
629
/* util elementfactory functions */
gboolean		gst_element_factory_can_src_caps(GstElementFactory *factory, const GstCaps *caps);
gboolean		gst_element_factory_can_sink_caps(GstElementFactory *factory, const GstCaps *caps);

630
631
/* util query functions */
gboolean                gst_element_query_position      (GstElement *element, GstFormat *format,
Wim Taymans's avatar
Wim Taymans committed
632
633
634
		                                         gint64 *cur);
gboolean                gst_element_query_duration      (GstElement *element, GstFormat *format,
		                                         gint64 *duration);
635
gboolean                gst_element_query_convert       (GstElement *element, GstFormat src_format, gint64 src_val,
636
		                                         GstFormat *dest_format, gint64 *dest_val);
637
638

/* element class functions */
639
void			gst_element_class_install_std_props (GstElementClass * klass,
640
							 const gchar * first_name, ...) G_GNUC_NULL_TERMINATED;
641
642
643
644
645
646
647
648
649

/* pad functions */
gboolean                gst_pad_can_link                (GstPad *srcpad, GstPad *sinkpad);

void			gst_pad_use_fixed_caps		(GstPad *pad);
GstCaps*		gst_pad_get_fixed_caps_func	(GstPad *pad);
GstCaps*		gst_pad_proxy_getcaps		(GstPad * pad);
gboolean		gst_pad_proxy_setcaps		(GstPad * pad, GstCaps * caps);

650
651
GstElement*		gst_pad_get_parent_element	(GstPad *pad);

652
653
/* util query functions */
gboolean                gst_pad_query_position          (GstPad *pad, GstFormat *format,
Wim Taymans's avatar
Wim Taymans committed
654
655
656
		                                         gint64 *cur);
gboolean                gst_pad_query_duration          (GstPad *pad, GstFormat *format,
		                                         gint64 *duration);
657
gboolean                gst_pad_query_convert           (GstPad *pad, GstFormat src_format, gint64 src_val,
658
659
660
661
662
663
664
		                                         GstFormat *dest_format, gint64 *dest_val);

gboolean                gst_pad_query_peer_position     (GstPad *pad, GstFormat *format,
		                                         gint64 *cur);
gboolean                gst_pad_query_peer_duration     (GstPad *pad, GstFormat *format,
		                                         gint64 *duration);
gboolean                gst_pad_query_peer_convert      (GstPad *pad, GstFormat src_format, gint64 src_val,
665
		                                         GstFormat *dest_format, gint64 *dest_val);
666

667
/* bin functions */
668
669
670
void                    gst_bin_add_many                (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
void                    gst_bin_remove_many             (GstBin *bin, GstElement *element_1, ...) G_GNUC_NULL_TERMINATED;
GstPad *                gst_bin_find_unconnected_pad    (GstBin *bin, GstPadDirection direction);
671
672
673

/* buffer functions */
GstBuffer *		gst_buffer_merge		(GstBuffer * buf1, GstBuffer * buf2);
674
GstBuffer *		gst_buffer_join			(GstBuffer * buf1, GstBuffer * buf2);
675
#ifndef GST_DISABLE_DEPRECATED
676
void			gst_buffer_stamp		(GstBuffer * dest, const GstBuffer * src);
677
#endif /* GST_DISABLE_DEPRECATED */
678

679
/* atomic functions */
680
#ifndef GST_DISABLE_DEPRECATED
681
void                    gst_atomic_int_set              (gint * atomic_int, gint value);
682
#endif
683

684
/* probes */
685
686
687
688
689
690
691
692
693
gulong			gst_pad_add_data_probe		(GstPad   * pad,
							 GCallback  handler,
							 gpointer   data);

gulong			gst_pad_add_data_probe_full	(GstPad       * pad,
							 GCallback      handler,
							 gpointer       data,
							 GDestroyNotify notify);

694
void			gst_pad_remove_data_probe	(GstPad * pad, guint handler_id);
695
696
697
698
699
700
701
702
703
704

gulong			gst_pad_add_event_probe		(GstPad   * pad,
							 GCallback  handler,
							 gpointer   data);

gulong			gst_pad_add_event_probe_full	(GstPad       * pad,
							 GCallback      handler,
							 gpointer       data,
							 GDestroyNotify notify);

705
void			gst_pad_remove_event_probe	(GstPad * pad, guint handler_id);
706
707
708
709
710
711
712
713
714
715

gulong			gst_pad_add_buffer_probe	(GstPad   * pad,
							 GCallback  handler,
							 gpointer   data);

gulong			gst_pad_add_buffer_probe_full	(GstPad       * pad,
							 GCallback      handler,
							 gpointer       data,
							 GDestroyNotify notify);

716
void			gst_pad_remove_buffer_probe	(GstPad * pad, guint handler_id);
717

718
719
720
721
722
723
724
/* tag emission utility functions */
void			gst_element_found_tags_for_pad	(GstElement * element,
							 GstPad * pad,
							 GstTagList * list);
void			gst_element_found_tags		(GstElement * element,
							 GstTagList * list);

725
/* parse utility functions */
726
727
728
729
730
731
732
733
734
GstElement *            gst_parse_bin_from_description      (const gchar     * bin_description,
                                                             gboolean          ghost_unconnected_pads,
                                                             GError         ** err);

GstElement *            gst_parse_bin_from_description_full (const gchar     * bin_description,
                                                             gboolean          ghost_unconnected_pads,
                                                             GstParseContext * context,
                                                             GstParseFlags     flags,
                                                             GError         ** err);
735

736
GstClockTime gst_util_get_timestamp (void);
737

738
G_END_DECLS
739

Erik Walthinsen's avatar
Erik Walthinsen committed
740
#endif /* __GST_UTILS_H__ */