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