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