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 module gstreamer.Utils;
26 
27 private import glib.Str;
28 private import gobject.ObjectG;
29 private import gobject.Value;
30 private import gobject.ValueArray;
31 private import gstreamer.Plugin;
32 private import gstreamerc.gstreamer;
33 public  import gstreamerc.gstreamertypes;
34 
35 
36 /** */
37 public struct Utils
38 {
39 
40 	/**
41 	 * Searches inside @array for @search_data by using the comparison function
42 	 * @search_func. @array must be sorted ascending.
43 	 *
44 	 * As @search_data is always passed as second argument to @search_func it's
45 	 * not required that @search_data has the same type as the array elements.
46 	 *
47 	 * The complexity of this search function is O(log (num_elements)).
48 	 *
49 	 * Params:
50 	 *     array = the sorted input array
51 	 *     numElements = number of elements in the array
52 	 *     elementSize = size of every element in bytes
53 	 *     searchFunc = function to compare two elements, @search_data will always be passed as second argument
54 	 *     mode = search mode that should be used
55 	 *     searchData = element that should be found
56 	 *     userData = data to pass to @search_func
57 	 *
58 	 * Returns: The address of the found
59 	 *     element or %NULL if nothing was found
60 	 */
61 	public static void* arrayBinarySearch(void* array, uint numElements, size_t elementSize, GCompareDataFunc searchFunc, GstSearchMode mode, void* searchData, void* userData)
62 	{
63 		return gst_util_array_binary_search(array, numElements, elementSize, searchFunc, mode, searchData, userData);
64 	}
65 
66 	/**
67 	 * Transforms a #gdouble to a fraction and simplifies
68 	 * the result.
69 	 *
70 	 * Params:
71 	 *     src = #gdouble to transform
72 	 *     destN = pointer to a #gint to hold the result numerator
73 	 *     destD = pointer to a #gint to hold the result denominator
74 	 */
75 	public static void doubleToFraction(double src, out int destN, out int destD)
76 	{
77 		gst_util_double_to_fraction(src, &destN, &destD);
78 	}
79 
80 	/**
81 	 * Dumps the memory block into a hex representation. Useful for debugging.
82 	 *
83 	 * Params:
84 	 *     mem = a pointer to the memory to dump
85 	 *     size = the size of the memory block to dump
86 	 */
87 	public static void dumpMem(char* mem, uint size)
88 	{
89 		gst_util_dump_mem(mem, size);
90 	}
91 
92 	/**
93 	 * Adds the fractions @a_n/@a_d and @b_n/@b_d and stores
94 	 * the result in @res_n and @res_d.
95 	 *
96 	 * Params:
97 	 *     aN = Numerator of first value
98 	 *     aD = Denominator of first value
99 	 *     bN = Numerator of second value
100 	 *     bD = Denominator of second value
101 	 *     resN = Pointer to #gint to hold the result numerator
102 	 *     resD = Pointer to #gint to hold the result denominator
103 	 *
104 	 * Returns: %FALSE on overflow, %TRUE otherwise.
105 	 */
106 	public static bool fractionAdd(int aN, int aD, int bN, int bD, out int resN, out int resD)
107 	{
108 		return gst_util_fraction_add(aN, aD, bN, bD, &resN, &resD) != 0;
109 	}
110 
111 	/**
112 	 * Compares the fractions @a_n/@a_d and @b_n/@b_d and returns
113 	 * -1 if a < b, 0 if a = b and 1 if a > b.
114 	 *
115 	 * Params:
116 	 *     aN = Numerator of first value
117 	 *     aD = Denominator of first value
118 	 *     bN = Numerator of second value
119 	 *     bD = Denominator of second value
120 	 *
121 	 * Returns: -1 if a < b; 0 if a = b; 1 if a > b.
122 	 */
123 	public static int fractionCompare(int aN, int aD, int bN, int bD)
124 	{
125 		return gst_util_fraction_compare(aN, aD, bN, bD);
126 	}
127 
128 	/**
129 	 * Multiplies the fractions @a_n/@a_d and @b_n/@b_d and stores
130 	 * the result in @res_n and @res_d.
131 	 *
132 	 * Params:
133 	 *     aN = Numerator of first value
134 	 *     aD = Denominator of first value
135 	 *     bN = Numerator of second value
136 	 *     bD = Denominator of second value
137 	 *     resN = Pointer to #gint to hold the result numerator
138 	 *     resD = Pointer to #gint to hold the result denominator
139 	 *
140 	 * Returns: %FALSE on overflow, %TRUE otherwise.
141 	 */
142 	public static bool fractionMultiply(int aN, int aD, int bN, int bD, out int resN, out int resD)
143 	{
144 		return gst_util_fraction_multiply(aN, aD, bN, bD, &resN, &resD) != 0;
145 	}
146 
147 	/**
148 	 * Transforms a fraction to a #gdouble.
149 	 *
150 	 * Params:
151 	 *     srcN = Fraction numerator as #gint
152 	 *     srcD = Fraction denominator #gint
153 	 *     dest = pointer to a #gdouble for the result
154 	 */
155 	public static void fractionToDouble(int srcN, int srcD, out double dest)
156 	{
157 		gst_util_fraction_to_double(srcN, srcD, &dest);
158 	}
159 
160 	/** */
161 	public static ulong gdoubleToGuint64(double value)
162 	{
163 		return gst_util_gdouble_to_guint64(value);
164 	}
165 
166 	/**
167 	 * Get a timestamp as GstClockTime to be used for interval measurements.
168 	 * The timestamp should not be interpreted in any other way.
169 	 *
170 	 * Returns: the timestamp
171 	 */
172 	public static GstClockTime getTimestamp()
173 	{
174 		return gst_util_get_timestamp();
175 	}
176 
177 	/**
178 	 * Calculates the greatest common divisor of @a
179 	 * and @b.
180 	 *
181 	 * Params:
182 	 *     a = First value as #gint
183 	 *     b = Second value as #gint
184 	 *
185 	 * Returns: Greatest common divisor of @a and @b
186 	 */
187 	public static int greatestCommonDivisor(int a, int b)
188 	{
189 		return gst_util_greatest_common_divisor(a, b);
190 	}
191 
192 	/**
193 	 * Calculates the greatest common divisor of @a
194 	 * and @b.
195 	 *
196 	 * Params:
197 	 *     a = First value as #gint64
198 	 *     b = Second value as #gint64
199 	 *
200 	 * Returns: Greatest common divisor of @a and @b
201 	 */
202 	public static long greatestCommonDivisorInt64(long a, long b)
203 	{
204 		return gst_util_greatest_common_divisor_int64(a, b);
205 	}
206 
207 	/**
208 	 * Return a constantly incrementing group id.
209 	 *
210 	 * This function is used to generate a new group-id for the
211 	 * stream-start event.
212 	 *
213 	 * Returns: A constantly incrementing unsigned integer, which might
214 	 *     overflow back to 0 at some point.
215 	 */
216 	public static uint groupIdNext()
217 	{
218 		return gst_util_group_id_next();
219 	}
220 
221 	/** */
222 	public static double guint64ToGdouble(ulong value)
223 	{
224 		return gst_util_guint64_to_gdouble(value);
225 	}
226 
227 	/**
228 	 * Compare two sequence numbers, handling wraparound.
229 	 *
230 	 * The current implementation just returns (gint32)(@s1 - @s2).
231 	 *
232 	 * Params:
233 	 *     s1 = A sequence number.
234 	 *     s2 = Another sequence number.
235 	 *
236 	 * Returns: A negative number if @s1 is before @s2, 0 if they are equal, or a
237 	 *     positive number if @s1 is after @s2.
238 	 */
239 	public static int seqnumCompare(uint s1, uint s2)
240 	{
241 		return gst_util_seqnum_compare(s1, s2);
242 	}
243 
244 	/**
245 	 * Return a constantly incrementing sequence number.
246 	 *
247 	 * This function is used internally to GStreamer to be able to determine which
248 	 * events and messages are "the same". For example, elements may set the seqnum
249 	 * on a segment-done message to be the same as that of the last seek event, to
250 	 * indicate that event and the message correspond to the same segment.
251 	 *
252 	 * Returns: A constantly incrementing 32-bit unsigned integer, which might
253 	 *     overflow back to 0 at some point. Use gst_util_seqnum_compare() to make sure
254 	 *     you handle wraparound correctly.
255 	 */
256 	public static uint seqnumNext()
257 	{
258 		return gst_util_seqnum_next();
259 	}
260 
261 	/**
262 	 * Converts the string value to the type of the objects argument and
263 	 * sets the argument with it.
264 	 *
265 	 * Note that this function silently returns if @object has no property named
266 	 * @name or when @value cannot be converted to the type of the property.
267 	 *
268 	 * Params:
269 	 *     object = the object to set the argument of
270 	 *     name = the name of the argument to set
271 	 *     value = the string value to set
272 	 */
273 	public static void setObjectArg(ObjectG object, string name, string value)
274 	{
275 		gst_util_set_object_arg((object is null) ? null : object.getObjectGStruct(), Str.toStringz(name), Str.toStringz(value));
276 	}
277 
278 	/**
279 	 * Converts the string to the type of the value and
280 	 * sets the value with it.
281 	 *
282 	 * Note that this function is dangerous as it does not return any indication
283 	 * if the conversion worked or not.
284 	 *
285 	 * Params:
286 	 *     value = the value to set
287 	 *     valueStr = the string to get the value from
288 	 */
289 	public static void setValueFromString(out Value value, string valueStr)
290 	{
291 		GValue* outvalue = gMalloc!GValue();
292 		
293 		gst_util_set_value_from_string(outvalue, Str.toStringz(valueStr));
294 		
295 		value = ObjectG.getDObject!(Value)(outvalue, true);
296 	}
297 
298 	/**
299 	 * Scale @val by the rational number @num / @denom, avoiding overflows and
300 	 * underflows and without loss of precision.
301 	 *
302 	 * This function can potentially be very slow if val and num are both
303 	 * greater than G_MAXUINT32.
304 	 *
305 	 * Params:
306 	 *     val = the number to scale
307 	 *     num = the numerator of the scale ratio
308 	 *     denom = the denominator of the scale ratio
309 	 *
310 	 * Returns: @val * @num / @denom.  In the case of an overflow, this
311 	 *     function returns G_MAXUINT64.  If the result is not exactly
312 	 *     representable as an integer it is truncated.  See also
313 	 *     gst_util_uint64_scale_round(), gst_util_uint64_scale_ceil(),
314 	 *     gst_util_uint64_scale_int(), gst_util_uint64_scale_int_round(),
315 	 *     gst_util_uint64_scale_int_ceil().
316 	 */
317 	public static ulong uint64Scale(ulong val, ulong num, ulong denom)
318 	{
319 		return gst_util_uint64_scale(val, num, denom);
320 	}
321 
322 	/**
323 	 * Scale @val by the rational number @num / @denom, avoiding overflows and
324 	 * underflows and without loss of precision.
325 	 *
326 	 * This function can potentially be very slow if val and num are both
327 	 * greater than G_MAXUINT32.
328 	 *
329 	 * Params:
330 	 *     val = the number to scale
331 	 *     num = the numerator of the scale ratio
332 	 *     denom = the denominator of the scale ratio
333 	 *
334 	 * Returns: @val * @num / @denom.  In the case of an overflow, this
335 	 *     function returns G_MAXUINT64.  If the result is not exactly
336 	 *     representable as an integer, it is rounded up.  See also
337 	 *     gst_util_uint64_scale(), gst_util_uint64_scale_round(),
338 	 *     gst_util_uint64_scale_int(), gst_util_uint64_scale_int_round(),
339 	 *     gst_util_uint64_scale_int_ceil().
340 	 */
341 	public static ulong uint64ScaleCeil(ulong val, ulong num, ulong denom)
342 	{
343 		return gst_util_uint64_scale_ceil(val, num, denom);
344 	}
345 
346 	/**
347 	 * Scale @val by the rational number @num / @denom, avoiding overflows and
348 	 * underflows and without loss of precision.  @num must be non-negative and
349 	 * @denom must be positive.
350 	 *
351 	 * Params:
352 	 *     val = guint64 (such as a #GstClockTime) to scale.
353 	 *     num = numerator of the scale factor.
354 	 *     denom = denominator of the scale factor.
355 	 *
356 	 * Returns: @val * @num / @denom.  In the case of an overflow, this
357 	 *     function returns G_MAXUINT64.  If the result is not exactly
358 	 *     representable as an integer, it is truncated.  See also
359 	 *     gst_util_uint64_scale_int_round(), gst_util_uint64_scale_int_ceil(),
360 	 *     gst_util_uint64_scale(), gst_util_uint64_scale_round(),
361 	 *     gst_util_uint64_scale_ceil().
362 	 */
363 	public static ulong uint64ScaleInt(ulong val, int num, int denom)
364 	{
365 		return gst_util_uint64_scale_int(val, num, denom);
366 	}
367 
368 	/**
369 	 * Scale @val by the rational number @num / @denom, avoiding overflows and
370 	 * underflows and without loss of precision.  @num must be non-negative and
371 	 * @denom must be positive.
372 	 *
373 	 * Params:
374 	 *     val = guint64 (such as a #GstClockTime) to scale.
375 	 *     num = numerator of the scale factor.
376 	 *     denom = denominator of the scale factor.
377 	 *
378 	 * Returns: @val * @num / @denom.  In the case of an overflow, this
379 	 *     function returns G_MAXUINT64.  If the result is not exactly
380 	 *     representable as an integer, it is rounded up.  See also
381 	 *     gst_util_uint64_scale_int(), gst_util_uint64_scale_int_round(),
382 	 *     gst_util_uint64_scale(), gst_util_uint64_scale_round(),
383 	 *     gst_util_uint64_scale_ceil().
384 	 */
385 	public static ulong uint64ScaleIntCeil(ulong val, int num, int denom)
386 	{
387 		return gst_util_uint64_scale_int_ceil(val, num, denom);
388 	}
389 
390 	/**
391 	 * Scale @val by the rational number @num / @denom, avoiding overflows and
392 	 * underflows and without loss of precision.  @num must be non-negative and
393 	 * @denom must be positive.
394 	 *
395 	 * Params:
396 	 *     val = guint64 (such as a #GstClockTime) to scale.
397 	 *     num = numerator of the scale factor.
398 	 *     denom = denominator of the scale factor.
399 	 *
400 	 * Returns: @val * @num / @denom.  In the case of an overflow, this
401 	 *     function returns G_MAXUINT64.  If the result is not exactly
402 	 *     representable as an integer, it is rounded to the nearest integer
403 	 *     (half-way cases are rounded up).  See also gst_util_uint64_scale_int(),
404 	 *     gst_util_uint64_scale_int_ceil(), gst_util_uint64_scale(),
405 	 *     gst_util_uint64_scale_round(), gst_util_uint64_scale_ceil().
406 	 */
407 	public static ulong uint64ScaleIntRound(ulong val, int num, int denom)
408 	{
409 		return gst_util_uint64_scale_int_round(val, num, denom);
410 	}
411 
412 	/**
413 	 * Scale @val by the rational number @num / @denom, avoiding overflows and
414 	 * underflows and without loss of precision.
415 	 *
416 	 * This function can potentially be very slow if val and num are both
417 	 * greater than G_MAXUINT32.
418 	 *
419 	 * Params:
420 	 *     val = the number to scale
421 	 *     num = the numerator of the scale ratio
422 	 *     denom = the denominator of the scale ratio
423 	 *
424 	 * Returns: @val * @num / @denom.  In the case of an overflow, this
425 	 *     function returns G_MAXUINT64.  If the result is not exactly
426 	 *     representable as an integer, it is rounded to the nearest integer
427 	 *     (half-way cases are rounded up).  See also gst_util_uint64_scale(),
428 	 *     gst_util_uint64_scale_ceil(), gst_util_uint64_scale_int(),
429 	 *     gst_util_uint64_scale_int_round(), gst_util_uint64_scale_int_ceil().
430 	 */
431 	public static ulong uint64ScaleRound(ulong val, ulong num, ulong denom)
432 	{
433 		return gst_util_uint64_scale_round(val, num, denom);
434 	}
435 
436 	/**
437 	 * Calculates the linear regression of the values @xy and places the
438 	 * result in @m_num, @m_denom, @b and @xbase, representing the function
439 	 * y(x) = m_num/m_denom * (x - xbase) + b
440 	 * that has the least-square distance from all points @x and @y.
441 	 *
442 	 * @r_squared will contain the remaining error.
443 	 *
444 	 * If @temp is not %NULL, it will be used as temporary space for the function,
445 	 * in which case the function works without any allocation at all. If @temp is
446 	 * %NULL, an allocation will take place. @temp should have at least the same
447 	 * amount of memory allocated as @xy, i.e. 2*n*sizeof(GstClockTime).
448 	 *
449 	 * > This function assumes (x,y) values with reasonable large differences
450 	 * > between them. It will not calculate the exact results if the differences
451 	 * > between neighbouring values are too small due to not being able to
452 	 * > represent sub-integer values during the calculations.
453 	 *
454 	 * Params:
455 	 *     xy = Pairs of (x,y) values
456 	 *     temp = Temporary scratch space used by the function
457 	 *     n = number of (x,y) pairs
458 	 *     mNum = numerator of calculated slope
459 	 *     mDenom = denominator of calculated slope
460 	 *     b = Offset at Y-axis
461 	 *     xbase = Offset at X-axis
462 	 *     rSquared = R-squared
463 	 *
464 	 * Returns: %TRUE if the linear regression was successfully calculated
465 	 *
466 	 * Since: 1.12
467 	 */
468 	public static bool calculateLinearRegression(GstClockTime* xy, GstClockTime* temp, uint n, out GstClockTime mNum, out GstClockTime mDenom, out GstClockTime b, out GstClockTime xbase, out double rSquared)
469 	{
470 		return gst_calculate_linear_regression(xy, temp, n, &mNum, &mDenom, &b, &xbase, &rSquared) != 0;
471 	}
472 
473 	/** */
474 	public static bool dynamicTypeRegister(Plugin plugin, GType type)
475 	{
476 		return gst_dynamic_type_register((plugin is null) ? null : plugin.getPluginStruct(), type) != 0;
477 	}
478 
479 	/**
480 	 * Get a property of type %GST_TYPE_ARRAY and transform it into a
481 	 * #GValueArray. This allow language bindings to get GST_TYPE_ARRAY
482 	 * properties which are otherwise not an accessible type.
483 	 *
484 	 * Params:
485 	 *     object = the object to set the array to
486 	 *     name = the name of the property to set
487 	 *     array = a return #GValueArray
488 	 *
489 	 * Since: 1.12
490 	 */
491 	public static bool getObjectArray(ObjectG object, string name, out ValueArray array)
492 	{
493 		GValueArray* outarray = null;
494 		
495 		auto p = gst_util_get_object_array((object is null) ? null : object.getObjectGStruct(), Str.toStringz(name), &outarray) != 0;
496 		
497 		array = ObjectG.getDObject!(ValueArray)(outarray);
498 		
499 		return p;
500 	}
501 
502 	/**
503 	 * Transfer a #GValueArray to %GST_TYPE_ARRAY and set this value on the
504 	 * specified property name. This allow language bindings to set GST_TYPE_ARRAY
505 	 * properties which are otherwise not an accessible type.
506 	 *
507 	 * Params:
508 	 *     object = the object to set the array to
509 	 *     name = the name of the property to set
510 	 *     array = a #GValueArray containing the values
511 	 *
512 	 * Since: 1.12
513 	 */
514 	public static bool setObjectArray(ObjectG object, string name, ValueArray array)
515 	{
516 		return gst_util_set_object_array((object is null) ? null : object.getObjectGStruct(), Str.toStringz(name), (array is null) ? null : array.getValueArrayStruct()) != 0;
517 	}
518 }