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