1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = gstreamer-GstUtils.html
27  * outPack = gstreamer
28  * outFile = Utils
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = Utils
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gst_util_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gobject.ObjectG
48  * 	- gobject.Value
49  * structWrap:
50  * 	- GObject* -> ObjectG
51  * 	- GValue* -> Value
52  * module aliases:
53  * local aliases:
54  * overrides:
55  */
56 
57 module gstreamer.Utils;
58 
59 public  import gstreamerc.gstreamertypes;
60 
61 private import gstreamerc.gstreamer;
62 private import glib.ConstructionException;
63 private import gobject.ObjectG;
64 
65 private import glib.Str;
66 private import gobject.ObjectG;
67 private import gobject.Value;
68 
69 
70 
71 /**
72  */
73 public class Utils
74 {
75 	
76 	/**
77 	 */
78 	
79 	/**
80 	 * Read a 32 bit float value in little endian format from the memory buffer.
81 	 * Params:
82 	 * data = memory location
83 	 * Returns: The floating point value read from data
84 	 */
85 	public static float GST_READ_FLOAT_LE(ubyte* data)
86 	{
87 		// gfloat GST_READ_FLOAT_LE (const guint8 *data);
88 		return GST_READ_FLOAT_LE(data);
89 	}
90 	
91 	/**
92 	 * Read a 32 bit float value in big endian format from the memory buffer.
93 	 * Params:
94 	 * data = memory location
95 	 * Returns: The floating point value read from data
96 	 */
97 	public static float GST_READ_FLOAT_BE(ubyte* data)
98 	{
99 		// gfloat GST_READ_FLOAT_BE (const guint8 *data);
100 		return GST_READ_FLOAT_BE(data);
101 	}
102 	
103 	/**
104 	 * Read a 64 bit double value in little endian format from the memory buffer.
105 	 * Params:
106 	 * data = memory location
107 	 * Returns: The double-precision floating point value read from data
108 	 */
109 	public static double GST_READ_DOUBLE_LE(ubyte* data)
110 	{
111 		// gdouble GST_READ_DOUBLE_LE (const guint8 *data);
112 		return GST_READ_DOUBLE_LE(data);
113 	}
114 	
115 	/**
116 	 * Read a 64 bit double value in big endian format from the memory buffer.
117 	 * Params:
118 	 * data = memory location
119 	 * Returns: The double-precision floating point value read from data
120 	 */
121 	public static double GST_READ_DOUBLE_BE(ubyte* data)
122 	{
123 		// gdouble GST_READ_DOUBLE_BE (const guint8 *data);
124 		return GST_READ_DOUBLE_BE(data);
125 	}
126 	
127 	/**
128 	 * Store a 32 bit float value in little endian format into the memory buffer.
129 	 * Params:
130 	 * data = memory location
131 	 * num = value to store
132 	 */
133 	public static void GST_WRITE_FLOAT_LE(ubyte* data, float num)
134 	{
135 		// void GST_WRITE_FLOAT_LE (guint8 *data,  gfloat num);
136 		GST_WRITE_FLOAT_LE(data, num);
137 	}
138 	
139 	/**
140 	 * Store a 32 bit float value in big endian format into the memory buffer.
141 	 * Params:
142 	 * data = memory location
143 	 * num = value to store
144 	 */
145 	public static void GST_WRITE_FLOAT_BE(ubyte* data, float num)
146 	{
147 		// void GST_WRITE_FLOAT_BE (guint8 *data,  gfloat num);
148 		GST_WRITE_FLOAT_BE(data, num);
149 	}
150 	
151 	/**
152 	 * Store a 64 bit double value in little endian format into the memory buffer.
153 	 * Params:
154 	 * data = memory location
155 	 * num = value to store
156 	 */
157 	public static void GST_WRITE_DOUBLE_LE(ubyte* data, double num)
158 	{
159 		// void GST_WRITE_DOUBLE_LE (guint8 *data,  gdouble num);
160 		GST_WRITE_DOUBLE_LE(data, num);
161 	}
162 	
163 	/**
164 	 * Store a 64 bit double value in big endian format into the memory buffer.
165 	 * Params:
166 	 * data = memory location
167 	 * num = value to store
168 	 */
169 	public static void GST_WRITE_DOUBLE_BE(ubyte* data, double num)
170 	{
171 		// void GST_WRITE_DOUBLE_BE (guint8 *data,  gdouble num);
172 		GST_WRITE_DOUBLE_BE(data, num);
173 	}
174 	
175 	/**
176 	 * Swap byte order of a 64-bit floating point value (double).
177 	 * Params:
178 	 * in = input value
179 	 * Returns: in byte-swapped.
180 	 */
181 	public static double GDOUBLE_SWAP_LE_BE(double inn)
182 	{
183 		// gdouble GDOUBLE_SWAP_LE_BE (gdouble in);
184 		return GDOUBLE_SWAP_LE_BE(inn);
185 	}
186 	
187 	/**
188 	 * Swap byte order of a 32-bit floating point value (float).
189 	 * Params:
190 	 * in = input value
191 	 * Returns: in byte-swapped.
192 	 */
193 	public static float GFLOAT_SWAP_LE_BE(float inn)
194 	{
195 		// gfloat GFLOAT_SWAP_LE_BE (gfloat in);
196 		return GFLOAT_SWAP_LE_BE(inn);
197 	}
198 	
199 	/**
200 	 * Dumps the memory block into a hex representation. Useful for debugging.
201 	 * Params:
202 	 * mem = a pointer to the memory to dump
203 	 * size = the size of the memory block to dump
204 	 */
205 	public static void dumpMem(char* mem, uint size)
206 	{
207 		// void gst_util_dump_mem (const guchar *mem,  guint size);
208 		gst_util_dump_mem(mem, size);
209 	}
210 	
211 	/**
212 	 * Scale val by the rational number num / denom, avoiding overflows and
213 	 * underflows and without loss of precision.
214 	 * This function can potentially be very slow if val and num are both
215 	 * greater than G_MAXUINT32.
216 	 * Params:
217 	 * val = the number to scale
218 	 * num = the numerator of the scale ratio
219 	 * denom = the denominator of the scale ratio
220 	 * Returns: val * num / denom. In the case of an overflow, this function returns G_MAXUINT64. If the result is not exactly representable as an integer it is truncated. See also gst_util_uint64_scale_round(), gst_util_uint64_scale_ceil(), gst_util_uint64_scale_int(), gst_util_uint64_scale_int_round(), gst_util_uint64_scale_int_ceil().
221 	 */
222 	public static ulong uint64_Scale(ulong val, ulong num, ulong denom)
223 	{
224 		// guint64 gst_util_uint64_scale (guint64 val,  guint64 num,  guint64 denom);
225 		return gst_util_uint64_scale(val, num, denom);
226 	}
227 	
228 	/**
229 	 * Scale val by the rational number num / denom, avoiding overflows and
230 	 * underflows and without loss of precision.
231 	 * This function can potentially be very slow if val and num are both
232 	 * greater than G_MAXUINT32.
233 	 * Params:
234 	 * val = the number to scale
235 	 * num = the numerator of the scale ratio
236 	 * denom = the denominator of the scale ratio
237 	 * Returns: val * num / denom. In the case of an overflow, this function returns G_MAXUINT64. If the result is not exactly representable as an integer, it is rounded to the nearest integer (half-way cases are rounded up). See also gst_util_uint64_scale(), gst_util_uint64_scale_ceil(), gst_util_uint64_scale_int(), gst_util_uint64_scale_int_round(), gst_util_uint64_scale_int_ceil().
238 	 */
239 	public static ulong uint64_ScaleRound(ulong val, ulong num, ulong denom)
240 	{
241 		// guint64 gst_util_uint64_scale_round (guint64 val,  guint64 num,  guint64 denom);
242 		return gst_util_uint64_scale_round(val, num, denom);
243 	}
244 	
245 	/**
246 	 * Scale val by the rational number num / denom, avoiding overflows and
247 	 * underflows and without loss of precision.
248 	 * This function can potentially be very slow if val and num are both
249 	 * greater than G_MAXUINT32.
250 	 * Params:
251 	 * val = the number to scale
252 	 * num = the numerator of the scale ratio
253 	 * denom = the denominator of the scale ratio
254 	 * Returns: val * num / denom. In the case of an overflow, this function returns G_MAXUINT64. If the result is not exactly representable as an integer, it is rounded up. See also gst_util_uint64_scale(), gst_util_uint64_scale_round(), gst_util_uint64_scale_int(), gst_util_uint64_scale_int_round(), gst_util_uint64_scale_int_ceil().
255 	 */
256 	public static ulong uint64_ScaleCeil(ulong val, ulong num, ulong denom)
257 	{
258 		// guint64 gst_util_uint64_scale_ceil (guint64 val,  guint64 num,  guint64 denom);
259 		return gst_util_uint64_scale_ceil(val, num, denom);
260 	}
261 	
262 	/**
263 	 * Scale val by the rational number num / denom, avoiding overflows and
264 	 * underflows and without loss of precision. num must be non-negative and
265 	 * denom must be positive.
266 	 * Params:
267 	 * val = guint64 (such as a GstClockTime) to scale.
268 	 * num = numerator of the scale factor.
269 	 * denom = denominator of the scale factor.
270 	 * Returns: val * num / denom. In the case of an overflow, this function returns G_MAXUINT64. If the result is not exactly representable as an integer, it is truncated. See also gst_util_uint64_scale_int_round(), gst_util_uint64_scale_int_ceil(), gst_util_uint64_scale(), gst_util_uint64_scale_round(), gst_util_uint64_scale_ceil().
271 	 */
272 	public static ulong uint64_ScaleInt(ulong val, int num, int denom)
273 	{
274 		// guint64 gst_util_uint64_scale_int (guint64 val,  gint num,  gint denom);
275 		return gst_util_uint64_scale_int(val, num, denom);
276 	}
277 	
278 	/**
279 	 * Scale val by the rational number num / denom, avoiding overflows and
280 	 * underflows and without loss of precision. num must be non-negative and
281 	 * denom must be positive.
282 	 * Params:
283 	 * val = guint64 (such as a GstClockTime) to scale.
284 	 * num = numerator of the scale factor.
285 	 * denom = denominator of the scale factor.
286 	 * Returns: val * num / denom. In the case of an overflow, this function returns G_MAXUINT64. If the result is not exactly representable as an integer, it is rounded to the nearest integer (half-way cases are rounded up). See also gst_util_uint64_scale_int(), gst_util_uint64_scale_int_ceil(), gst_util_uint64_scale(), gst_util_uint64_scale_round(), gst_util_uint64_scale_ceil().
287 	 */
288 	public static ulong uint64_ScaleIntRound(ulong val, int num, int denom)
289 	{
290 		// guint64 gst_util_uint64_scale_int_round (guint64 val,  gint num,  gint denom);
291 		return gst_util_uint64_scale_int_round(val, num, denom);
292 	}
293 	
294 	/**
295 	 * Scale val by the rational number num / denom, avoiding overflows and
296 	 * underflows and without loss of precision. num must be non-negative and
297 	 * denom must be positive.
298 	 * Params:
299 	 * val = guint64 (such as a GstClockTime) to scale.
300 	 * num = numerator of the scale factor.
301 	 * denom = denominator of the scale factor.
302 	 * Returns: val * num / denom. In the case of an overflow, this function returns G_MAXUINT64. If the result is not exactly representable as an integer, it is rounded up. See also gst_util_uint64_scale_int(), gst_util_uint64_scale_int_round(), gst_util_uint64_scale(), gst_util_uint64_scale_round(), gst_util_uint64_scale_ceil().
303 	 */
304 	public static ulong uint64_ScaleIntCeil(ulong val, int num, int denom)
305 	{
306 		// guint64 gst_util_uint64_scale_int_ceil (guint64 val,  gint num,  gint denom);
307 		return gst_util_uint64_scale_int_ceil(val, num, denom);
308 	}
309 	
310 	/**
311 	 * Calculates the greatest common divisor of a
312 	 * and b.
313 	 * Params:
314 	 * a = First value as gint
315 	 * b = Second value as gint
316 	 * Returns: Greatest common divisor of a and b
317 	 */
318 	public static int greatestCommonDivisor(int a, int b)
319 	{
320 		// gint gst_util_greatest_common_divisor (gint a,  gint b);
321 		return gst_util_greatest_common_divisor(a, b);
322 	}
323 	
324 	/**
325 	 * Calculates the greatest common divisor of a
326 	 * and b.
327 	 * Params:
328 	 * a = First value as gint64
329 	 * b = Second value as gint64
330 	 * Returns: Greatest common divisor of a and b
331 	 */
332 	public static long greatestCommonDivisorInt64(long a, long b)
333 	{
334 		// gint64 gst_util_greatest_common_divisor_int64  (gint64 a,  gint64 b);
335 		return gst_util_greatest_common_divisor_int64(a, b);
336 	}
337 	
338 	/**
339 	 * Transforms a fraction to a gdouble.
340 	 * Params:
341 	 * srcN = Fraction numerator as gint
342 	 * srcD = Fraction denominator gint
343 	 * dest = pointer to a gdouble for the result. [out]
344 	 */
345 	public static void fractionToDouble(int srcN, int srcD, out double dest)
346 	{
347 		// void gst_util_fraction_to_double (gint src_n,  gint src_d,  gdouble *dest);
348 		gst_util_fraction_to_double(srcN, srcD, &dest);
349 	}
350 	
351 	/**
352 	 * Transforms a gdouble to a fraction and simplifies
353 	 * the result.
354 	 * Params:
355 	 * src = gdouble to transform
356 	 * destN = pointer to a gint to hold the result numerator. [out]
357 	 * destD = pointer to a gint to hold the result denominator. [out]
358 	 */
359 	public static void doubleToFraction(double src, out int destN, out int destD)
360 	{
361 		// void gst_util_double_to_fraction (gdouble src,  gint *dest_n,  gint *dest_d);
362 		gst_util_double_to_fraction(src, &destN, &destD);
363 	}
364 	
365 	/**
366 	 * Multiplies the fractions a_n/a_d and b_n/b_d and stores
367 	 * the result in res_n and res_d.
368 	 * Params:
369 	 * aN = Numerator of first value
370 	 * aD = Denominator of first value
371 	 * bN = Numerator of second value
372 	 * bD = Denominator of second value
373 	 * resN = Pointer to gint to hold the result numerator. [out]
374 	 * resD = Pointer to gint to hold the result denominator. [out]
375 	 * Returns: FALSE on overflow, TRUE otherwise.
376 	 */
377 	public static int fractionMultiply(int aN, int aD, int bN, int bD, out int resN, out int resD)
378 	{
379 		// gboolean gst_util_fraction_multiply (gint a_n,  gint a_d,  gint b_n,  gint b_d,  gint *res_n,  gint *res_d);
380 		return gst_util_fraction_multiply(aN, aD, bN, bD, &resN, &resD);
381 	}
382 	
383 	/**
384 	 * Adds the fractions a_n/a_d and b_n/b_d and stores
385 	 * the result in res_n and res_d.
386 	 * Params:
387 	 * aN = Numerator of first value
388 	 * aD = Denominator of first value
389 	 * bN = Numerator of second value
390 	 * bD = Denominator of second value
391 	 * resN = Pointer to gint to hold the result numerator. [out]
392 	 * resD = Pointer to gint to hold the result denominator. [out]
393 	 * Returns: FALSE on overflow, TRUE otherwise.
394 	 */
395 	public static int fractionAdd(int aN, int aD, int bN, int bD, out int resN, out int resD)
396 	{
397 		// gboolean gst_util_fraction_add (gint a_n,  gint a_d,  gint b_n,  gint b_d,  gint *res_n,  gint *res_d);
398 		return gst_util_fraction_add(aN, aD, bN, bD, &resN, &resD);
399 	}
400 	
401 	/**
402 	 * Compares the fractions a_n/a_d and b_n/b_d and returns
403 	 * -1 if a < b, 0 if a = b and 1 if a > b.
404 	 * Params:
405 	 * aN = Numerator of first value
406 	 * aD = Denominator of first value
407 	 * bN = Numerator of second value
408 	 * bD = Denominator of second value
409 	 * Returns: -1 if a < b; 0 if a = b; 1 if a > b.
410 	 */
411 	public static int fractionCompare(int aN, int aD, int bN, int bD)
412 	{
413 		// gint gst_util_fraction_compare (gint a_n,  gint a_d,  gint b_n,  gint b_d);
414 		return gst_util_fraction_compare(aN, aD, bN, bD);
415 	}
416 	
417 	/**
418 	 * Return a constantly incrementing sequence number.
419 	 * This function is used internally to GStreamer to be able to determine which
420 	 * events and messages are "the same". For example, elements may set the seqnum
421 	 * on a segment-done message to be the same as that of the last seek event, to
422 	 * indicate that event and the message correspond to the same segment.
423 	 * Returns: A constantly incrementing 32-bit unsigned integer, which might overflow back to 0 at some point. Use gst_util_seqnum_compare() to make sure you handle wraparound correctly.
424 	 */
425 	public static uint seqnumNext()
426 	{
427 		// guint32 gst_util_seqnum_next (void);
428 		return gst_util_seqnum_next();
429 	}
430 	
431 	/**
432 	 * Compare two sequence numbers, handling wraparound.
433 	 * The current implementation just returns (gint32)(s1 - s2).
434 	 * Params:
435 	 * s1 = A sequence number.
436 	 * s2 = Another sequence number.
437 	 * Returns: A negative number if s1 is before s2, 0 if they are equal, or a positive number if s1 is after s2.
438 	 */
439 	public static int seqnumCompare(uint s1, uint s2)
440 	{
441 		// gint32 gst_util_seqnum_compare (guint32 s1,  guint32 s2);
442 		return gst_util_seqnum_compare(s1, s2);
443 	}
444 	
445 	/**
446 	 * Return a constantly incrementing group id.
447 	 * This function is used to generate a new group-id for the
448 	 * stream-start event.
449 	 * Returns: A constantly incrementing unsigned integer, which might overflow back to 0 at some point.
450 	 */
451 	public static uint groupIdNext()
452 	{
453 		// guint gst_util_group_id_next (void);
454 		return gst_util_group_id_next();
455 	}
456 	
457 	/**
458 	 * Convertes the string value to the type of the objects argument and
459 	 * sets the argument with it.
460 	 * Note that this function silently returns if object has no property named
461 	 * name or when value cannot be converted to the type of the property.
462 	 * Params:
463 	 * object = the object to set the argument of
464 	 * name = the name of the argument to set
465 	 * value = the string value to set
466 	 */
467 	public static void setObjectArg(ObjectG object, string name, string value)
468 	{
469 		// void gst_util_set_object_arg (GObject *object,  const gchar *name,  const gchar *value);
470 		gst_util_set_object_arg((object is null) ? null : object.getObjectGStruct(), Str.toStringz(name), Str.toStringz(value));
471 	}
472 	
473 	/**
474 	 * Converts the string to the type of the value and
475 	 * sets the value with it.
476 	 * Note that this function is dangerous as it does not return any indication
477 	 * if the conversion worked or not.
478 	 * Params:
479 	 * value = the value to set. [out caller-allocates]
480 	 * valueStr = the string to get the value from
481 	 */
482 	public static void setValueFromString(Value value, string valueStr)
483 	{
484 		// void gst_util_set_value_from_string (GValue *value,  const gchar *value_str);
485 		gst_util_set_value_from_string((value is null) ? null : value.getValueStruct(), Str.toStringz(valueStr));
486 	}
487 	
488 	/**
489 	 * Get a timestamp as GstClockTime to be used for interval measurements.
490 	 * The timestamp should not be interpreted in any other way.
491 	 * Returns: the timestamp
492 	 */
493 	public static GstClockTime getTimestamp()
494 	{
495 		// GstClockTime gst_util_get_timestamp (void);
496 		return gst_util_get_timestamp();
497 	}
498 	
499 	/**
500 	 * Searches inside array for search_data by using the comparison function
501 	 * search_func. array must be sorted ascending.
502 	 * As search_data is always passed as second argument to search_func it's
503 	 * not required that search_data has the same type as the array elements.
504 	 * The complexity of this search function is O(log (num_elements)).
505 	 * Params:
506 	 * array = the sorted input array
507 	 * numElements = number of elements in the array
508 	 * elementSize = size of every element in bytes
509 	 * searchFunc = function to compare two elements, search_data will always be passed as second argument. [scope call]
510 	 * mode = search mode that should be used
511 	 * searchData = element that should be found
512 	 * userData = data to pass to search_func. [closure]
513 	 * Returns: The address of the found element or NULL if nothing was found. [transfer none]
514 	 */
515 	public static void* arrayBinarySearch(void* array, uint numElements, gsize elementSize, GCompareDataFunc searchFunc, GstSearchMode mode, void* searchData, void* userData)
516 	{
517 		// gpointer gst_util_array_binary_search (gpointer array,  guint num_elements,  gsize element_size,  GCompareDataFunc search_func,  GstSearchMode mode,  gconstpointer search_data,  gpointer user_data);
518 		return gst_util_array_binary_search(array, numElements, elementSize, searchFunc, mode, searchData, userData);
519 	}
520 }