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 gstreamerc.gstreamer;
31 public  import gstreamerc.gstreamertypes;
32 
33 
34 public struct Utils
35 {
36 	/**
37 	 */
38 
39 	/**
40 	 * Searches inside @array for @search_data by using the comparison function
41 	 * @search_func. @array must be sorted ascending.
42 	 *
43 	 * As @search_data is always passed as second argument to @search_func it's
44 	 * not required that @search_data has the same type as the array elements.
45 	 *
46 	 * The complexity of this search function is O(log (num_elements)).
47 	 *
48 	 * Params:
49 	 *     array = the sorted input array
50 	 *     numElements = number of elements in the array
51 	 *     elementSize = size of every element in bytes
52 	 *     searchFunc = function to compare two elements, @search_data will always be passed as second argument
53 	 *     mode = search mode that should be used
54 	 *     searchData = element that should be found
55 	 *     userData = data to pass to @search_func
56 	 *
57 	 * Return: The address of the found
58 	 *     element or %NULL if nothing was found
59 	 */
60 	public static void* arrayBinarySearch(void* array, uint numElements, size_t elementSize, GCompareDataFunc searchFunc, GstSearchMode mode, void* searchData, void* userData)
61 	{
62 		return gst_util_array_binary_search(array, numElements, elementSize, searchFunc, mode, searchData, userData);
63 	}
64 
65 	/**
66 	 * Transforms a #gdouble to a fraction and simplifies
67 	 * the result.
68 	 *
69 	 * Params:
70 	 *     src = #gdouble to transform
71 	 *     destN = pointer to a #gint to hold the result numerator
72 	 *     destD = pointer to a #gint to hold the result denominator
73 	 */
74 	public static void doubleToFraction(double src, out int destN, out int destD)
75 	{
76 		gst_util_double_to_fraction(src, &destN, &destD);
77 	}
78 
79 	/**
80 	 * Dumps the memory block into a hex representation. Useful for debugging.
81 	 *
82 	 * Params:
83 	 *     mem = a pointer to the memory to dump
84 	 *     size = the size of the memory block to dump
85 	 */
86 	public static void dumpMem(string mem, uint size)
87 	{
88 		gst_util_dump_mem(Str.toStringz(mem), size);
89 	}
90 
91 	/**
92 	 * Adds the fractions @a_n/@a_d and @b_n/@b_d and stores
93 	 * the result in @res_n and @res_d.
94 	 *
95 	 * Params:
96 	 *     aN = Numerator of first value
97 	 *     aD = Denominator of first value
98 	 *     bN = Numerator of second value
99 	 *     bD = Denominator of second value
100 	 *     resN = Pointer to #gint to hold the result numerator
101 	 *     resD = Pointer to #gint to hold the result denominator
102 	 *
103 	 * Return: %FALSE on overflow, %TRUE otherwise.
104 	 */
105 	public static bool fractionAdd(int aN, int aD, int bN, int bD, out int resN, out int resD)
106 	{
107 		return gst_util_fraction_add(aN, aD, bN, bD, &resN, &resD) != 0;
108 	}
109 
110 	/**
111 	 * Compares the fractions @a_n/@a_d and @b_n/@b_d and returns
112 	 * -1 if a < b, 0 if a = b and 1 if a > b.
113 	 *
114 	 * Params:
115 	 *     aN = Numerator of first value
116 	 *     aD = Denominator of first value
117 	 *     bN = Numerator of second value
118 	 *     bD = Denominator of second value
119 	 *
120 	 * Return: -1 if a < b; 0 if a = b; 1 if a > b.
121 	 */
122 	public static int fractionCompare(int aN, int aD, int bN, int bD)
123 	{
124 		return gst_util_fraction_compare(aN, aD, bN, bD);
125 	}
126 
127 	/**
128 	 * Multiplies the fractions @a_n/@a_d and @b_n/@b_d and stores
129 	 * the result in @res_n and @res_d.
130 	 *
131 	 * Params:
132 	 *     aN = Numerator of first value
133 	 *     aD = Denominator of first value
134 	 *     bN = Numerator of second value
135 	 *     bD = Denominator of second value
136 	 *     resN = Pointer to #gint to hold the result numerator
137 	 *     resD = Pointer to #gint to hold the result denominator
138 	 *
139 	 * Return: %FALSE on overflow, %TRUE otherwise.
140 	 */
141 	public static bool fractionMultiply(int aN, int aD, int bN, int bD, out int resN, out int resD)
142 	{
143 		return gst_util_fraction_multiply(aN, aD, bN, bD, &resN, &resD) != 0;
144 	}
145 
146 	/**
147 	 * Transforms a fraction to a #gdouble.
148 	 *
149 	 * Params:
150 	 *     srcN = Fraction numerator as #gint
151 	 *     srcD = Fraction denominator #gint
152 	 *     dest = pointer to a #gdouble for the result
153 	 */
154 	public static void fractionToDouble(int srcN, int srcD, out double dest)
155 	{
156 		gst_util_fraction_to_double(srcN, srcD, &dest);
157 	}
158 
159 	public static ulong gdoubleToGuint64(double value)
160 	{
161 		return gst_util_gdouble_to_guint64(value);
162 	}
163 
164 	/**
165 	 * Get a timestamp as GstClockTime to be used for interval measurements.
166 	 * The timestamp should not be interpreted in any other way.
167 	 *
168 	 * Return: the timestamp
169 	 */
170 	public static GstClockTime getTimestamp()
171 	{
172 		return gst_util_get_timestamp();
173 	}
174 
175 	/**
176 	 * Calculates the greatest common divisor of @a
177 	 * and @b.
178 	 *
179 	 * Params:
180 	 *     a = First value as #gint
181 	 *     b = Second value as #gint
182 	 *
183 	 * Return: Greatest common divisor of @a and @b
184 	 */
185 	public static int greatestCommonDivisor(int a, int b)
186 	{
187 		return gst_util_greatest_common_divisor(a, b);
188 	}
189 
190 	/**
191 	 * Calculates the greatest common divisor of @a
192 	 * and @b.
193 	 *
194 	 * Params:
195 	 *     a = First value as #gint64
196 	 *     b = Second value as #gint64
197 	 *
198 	 * Return: Greatest common divisor of @a and @b
199 	 */
200 	public static long greatestCommonDivisorInt64(long a, long b)
201 	{
202 		return gst_util_greatest_common_divisor_int64(a, b);
203 	}
204 
205 	/**
206 	 * Return a constantly incrementing group id.
207 	 *
208 	 * This function is used to generate a new group-id for the
209 	 * stream-start event.
210 	 *
211 	 * Return: A constantly incrementing unsigned integer, which might
212 	 *     overflow back to 0 at some point.
213 	 */
214 	public static uint groupIdNext()
215 	{
216 		return gst_util_group_id_next();
217 	}
218 
219 	public static double guint64ToGdouble(ulong value)
220 	{
221 		return gst_util_guint64_to_gdouble(value);
222 	}
223 
224 	/**
225 	 * Compare two sequence numbers, handling wraparound.
226 	 *
227 	 * The current implementation just returns (gint32)(@s1 - @s2).
228 	 *
229 	 * Params:
230 	 *     s1 = A sequence number.
231 	 *     s2 = Another sequence number.
232 	 *
233 	 * Return: A negative number if @s1 is before @s2, 0 if they are equal, or a
234 	 *     positive number if @s1 is after @s2.
235 	 */
236 	public static int seqnumCompare(uint s1, uint s2)
237 	{
238 		return gst_util_seqnum_compare(s1, s2);
239 	}
240 
241 	/**
242 	 * Return a constantly incrementing sequence number.
243 	 *
244 	 * This function is used internally to GStreamer to be able to determine which
245 	 * events and messages are "the same". For example, elements may set the seqnum
246 	 * on a segment-done message to be the same as that of the last seek event, to
247 	 * indicate that event and the message correspond to the same segment.
248 	 *
249 	 * Return: A constantly incrementing 32-bit unsigned integer, which might
250 	 *     overflow back to 0 at some point. Use gst_util_seqnum_compare() to make sure
251 	 *     you handle wraparound correctly.
252 	 */
253 	public static uint seqnumNext()
254 	{
255 		return gst_util_seqnum_next();
256 	}
257 
258 	/**
259 	 * Converts the string value to the type of the objects argument and
260 	 * sets the argument with it.
261 	 *
262 	 * Note that this function silently returns if @object has no property named
263 	 * @name or when @value cannot be converted to the type of the property.
264 	 *
265 	 * Params:
266 	 *     object = the object to set the argument of
267 	 *     name = the name of the argument to set
268 	 *     value = the string value to set
269 	 */
270 	public static void setObjectArg(ObjectG object, string name, string value)
271 	{
272 		gst_util_set_object_arg((object is null) ? null : object.getObjectGStruct(), Str.toStringz(name), Str.toStringz(value));
273 	}
274 
275 	/**
276 	 * Converts the string to the type of the value and
277 	 * sets the value with it.
278 	 *
279 	 * Note that this function is dangerous as it does not return any indication
280 	 * if the conversion worked or not.
281 	 *
282 	 * Params:
283 	 *     value = the value to set
284 	 *     valueStr = the string to get the value from
285 	 */
286 	public static void setValueFromString(out Value value, string valueStr)
287 	{
288 		GValue* outvalue = new GValue;
289 		
290 		gst_util_set_value_from_string(outvalue, Str.toStringz(valueStr));
291 		
292 		value = ObjectG.getDObject!(Value)(outvalue);
293 	}
294 
295 	/**
296 	 * Scale @val by the rational number @num / @denom, avoiding overflows and
297 	 * underflows and without loss of precision.
298 	 *
299 	 * This function can potentially be very slow if val and num are both
300 	 * greater than G_MAXUINT32.
301 	 *
302 	 * Params:
303 	 *     val = the number to scale
304 	 *     num = the numerator of the scale ratio
305 	 *     denom = the denominator of the scale ratio
306 	 *
307 	 * Return: @val * @num / @denom.  In the case of an overflow, this
308 	 *     function returns G_MAXUINT64.  If the result is not exactly
309 	 *     representable as an integer it is truncated.  See also
310 	 *     gst_util_uint64_scale_round(), gst_util_uint64_scale_ceil(),
311 	 *     gst_util_uint64_scale_int(), gst_util_uint64_scale_int_round(),
312 	 *     gst_util_uint64_scale_int_ceil().
313 	 */
314 	public static ulong uint64Scale(ulong val, ulong num, ulong denom)
315 	{
316 		return gst_util_uint64_scale(val, num, denom);
317 	}
318 
319 	/**
320 	 * Scale @val by the rational number @num / @denom, avoiding overflows and
321 	 * underflows and without loss of precision.
322 	 *
323 	 * This function can potentially be very slow if val and num are both
324 	 * greater than G_MAXUINT32.
325 	 *
326 	 * Params:
327 	 *     val = the number to scale
328 	 *     num = the numerator of the scale ratio
329 	 *     denom = the denominator of the scale ratio
330 	 *
331 	 * Return: @val * @num / @denom.  In the case of an overflow, this
332 	 *     function returns G_MAXUINT64.  If the result is not exactly
333 	 *     representable as an integer, it is rounded up.  See also
334 	 *     gst_util_uint64_scale(), gst_util_uint64_scale_round(),
335 	 *     gst_util_uint64_scale_int(), gst_util_uint64_scale_int_round(),
336 	 *     gst_util_uint64_scale_int_ceil().
337 	 */
338 	public static ulong uint64ScaleCeil(ulong val, ulong num, ulong denom)
339 	{
340 		return gst_util_uint64_scale_ceil(val, num, denom);
341 	}
342 
343 	/**
344 	 * Scale @val by the rational number @num / @denom, avoiding overflows and
345 	 * underflows and without loss of precision.  @num must be non-negative and
346 	 * @denom must be positive.
347 	 *
348 	 * Params:
349 	 *     val = guint64 (such as a #GstClockTime) to scale.
350 	 *     num = numerator of the scale factor.
351 	 *     denom = denominator of the scale factor.
352 	 *
353 	 * Return: @val * @num / @denom.  In the case of an overflow, this
354 	 *     function returns G_MAXUINT64.  If the result is not exactly
355 	 *     representable as an integer, it is truncated.  See also
356 	 *     gst_util_uint64_scale_int_round(), gst_util_uint64_scale_int_ceil(),
357 	 *     gst_util_uint64_scale(), gst_util_uint64_scale_round(),
358 	 *     gst_util_uint64_scale_ceil().
359 	 */
360 	public static ulong uint64ScaleInt(ulong val, int num, int denom)
361 	{
362 		return gst_util_uint64_scale_int(val, num, denom);
363 	}
364 
365 	/**
366 	 * Scale @val by the rational number @num / @denom, avoiding overflows and
367 	 * underflows and without loss of precision.  @num must be non-negative and
368 	 * @denom must be positive.
369 	 *
370 	 * Params:
371 	 *     val = guint64 (such as a #GstClockTime) to scale.
372 	 *     num = numerator of the scale factor.
373 	 *     denom = denominator of the scale factor.
374 	 *
375 	 * Return: @val * @num / @denom.  In the case of an overflow, this
376 	 *     function returns G_MAXUINT64.  If the result is not exactly
377 	 *     representable as an integer, it is rounded up.  See also
378 	 *     gst_util_uint64_scale_int(), gst_util_uint64_scale_int_round(),
379 	 *     gst_util_uint64_scale(), gst_util_uint64_scale_round(),
380 	 *     gst_util_uint64_scale_ceil().
381 	 */
382 	public static ulong uint64ScaleIntCeil(ulong val, int num, int denom)
383 	{
384 		return gst_util_uint64_scale_int_ceil(val, num, denom);
385 	}
386 
387 	/**
388 	 * Scale @val by the rational number @num / @denom, avoiding overflows and
389 	 * underflows and without loss of precision.  @num must be non-negative and
390 	 * @denom must be positive.
391 	 *
392 	 * Params:
393 	 *     val = guint64 (such as a #GstClockTime) to scale.
394 	 *     num = numerator of the scale factor.
395 	 *     denom = denominator of the scale factor.
396 	 *
397 	 * Return: @val * @num / @denom.  In the case of an overflow, this
398 	 *     function returns G_MAXUINT64.  If the result is not exactly
399 	 *     representable as an integer, it is rounded to the nearest integer
400 	 *     (half-way cases are rounded up).  See also gst_util_uint64_scale_int(),
401 	 *     gst_util_uint64_scale_int_ceil(), gst_util_uint64_scale(),
402 	 *     gst_util_uint64_scale_round(), gst_util_uint64_scale_ceil().
403 	 */
404 	public static ulong uint64ScaleIntRound(ulong val, int num, int denom)
405 	{
406 		return gst_util_uint64_scale_int_round(val, num, denom);
407 	}
408 
409 	/**
410 	 * Scale @val by the rational number @num / @denom, avoiding overflows and
411 	 * underflows and without loss of precision.
412 	 *
413 	 * This function can potentially be very slow if val and num are both
414 	 * greater than G_MAXUINT32.
415 	 *
416 	 * Params:
417 	 *     val = the number to scale
418 	 *     num = the numerator of the scale ratio
419 	 *     denom = the denominator of the scale ratio
420 	 *
421 	 * Return: @val * @num / @denom.  In the case of an overflow, this
422 	 *     function returns G_MAXUINT64.  If the result is not exactly
423 	 *     representable as an integer, it is rounded to the nearest integer
424 	 *     (half-way cases are rounded up).  See also gst_util_uint64_scale(),
425 	 *     gst_util_uint64_scale_ceil(), gst_util_uint64_scale_int(),
426 	 *     gst_util_uint64_scale_int_round(), gst_util_uint64_scale_int_ceil().
427 	 */
428 	public static ulong uint64ScaleRound(ulong val, ulong num, ulong denom)
429 	{
430 		return gst_util_uint64_scale_round(val, num, denom);
431 	}
432 }