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 * Conversion parameters: 26 * inFile = GstClock.html 27 * outPack = gstreamer 28 * outFile = Clock 29 * strct = GstClock 30 * realStrct= 31 * ctorStrct= 32 * clss = Clock 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gst_clock_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - glib.Str 47 * structWrap: 48 * - GstClock* -> Clock 49 * module aliases: 50 * local aliases: 51 * overrides: 52 */ 53 54 module gstreamer.Clock; 55 56 public import gstreamerc.gstreamertypes; 57 58 private import gstreamerc.gstreamer; 59 private import glib.ConstructionException; 60 private import gobject.ObjectG; 61 62 private import glib.Str; 63 64 65 private import gstreamer.ObjectGst; 66 67 /** 68 * GStreamer uses a global clock to synchronize the plugins in a pipeline. 69 * Different clock implementations are possible by implementing this abstract 70 * base class or, more conveniently, by subclassing GstSystemClock. 71 * 72 * The GstClock returns a monotonically increasing time with the method 73 * gst_clock_get_time(). Its accuracy and base time depend on the specific 74 * clock implementation but time is always expressed in nanoseconds. Since the 75 * baseline of the clock is undefined, the clock time returned is not 76 * meaningful in itself, what matters are the deltas between two clock times. 77 * The time returned by a clock is called the absolute time. 78 * 79 * The pipeline uses the clock to calculate the running time. Usually all 80 * renderers synchronize to the global clock using the buffer timestamps, the 81 * newsegment events and the element's base time, see GstPipeline. 82 * 83 * A clock implementation can support periodic and single shot clock 84 * notifications both synchronous and asynchronous. 85 * 86 * One first needs to create a GstClockID for the periodic or single shot 87 * notification using gst_clock_new_single_shot_id() or 88 * gst_clock_new_periodic_id(). 89 * 90 * To perform a blocking wait for the specific time of the GstClockID use the 91 * gst_clock_id_wait(). To receive a callback when the specific time is reached 92 * in the clock use gst_clock_id_wait_async(). Both these calls can be 93 * interrupted with the gst_clock_id_unschedule() call. If the blocking wait is 94 * unscheduled a return value of GST_CLOCK_UNSCHEDULED is returned. 95 * 96 * Periodic callbacks scheduled async will be repeatedly called automatically 97 * until it is unscheduled. To schedule a sync periodic callback, 98 * gst_clock_id_wait() should be called repeatedly. 99 * 100 * The async callbacks can happen from any thread, either provided by the core 101 * or from a streaming thread. The application should be prepared for this. 102 * 103 * A GstClockID that has been unscheduled cannot be used again for any wait 104 * operation, a new GstClockID should be created and the old unscheduled one 105 * should be destroyed with gst_clock_id_unref(). 106 * 107 * It is possible to perform a blocking wait on the same GstClockID from 108 * multiple threads. However, registering the same GstClockID for multiple 109 * async notifications is not possible, the callback will only be called for 110 * the thread registering the entry last. 111 * 112 * None of the wait operations unref the GstClockID, the owner is responsible 113 * for unreffing the ids itself. This holds for both periodic and single shot 114 * notifications. The reason being that the owner of the GstClockID has to 115 * keep a handle to the GstClockID to unblock the wait on FLUSHING events or 116 * state changes and if the entry would be unreffed automatically, the handle 117 * might become invalid without any notification. 118 * 119 * These clock operations do not operate on the running time, so the callbacks 120 * will also occur when not in PLAYING state as if the clock just keeps on 121 * running. Some clocks however do not progress when the element that provided 122 * the clock is not PLAYING. 123 * 124 * When a clock has the GST_CLOCK_FLAG_CAN_SET_MASTER flag set, it can be 125 * slaved to another GstClock with the gst_clock_set_master(). The clock will 126 * then automatically be synchronized to this master clock by repeatedly 127 * sampling the master clock and the slave clock and recalibrating the slave 128 * clock with gst_clock_set_calibration(). This feature is mostly useful for 129 * plugins that have an internal clock but must operate with another clock 130 * selected by the GstPipeline. They can track the offset and rate difference 131 * of their internal clock relative to the master clock by using the 132 * gst_clock_get_calibration() function. 133 * 134 * The master/slave synchronisation can be tuned with the "timeout", 135 * "window-size" and "window-threshold" properties. 136 * The "timeout" property defines the interval to sample the master 137 * clock and run the calibration functions. "window-size" defines the 138 * number of samples to use when calibrating and "window-threshold" 139 * defines the minimum number of samples before the calibration is performed. 140 * 141 * Last reviewed on 2012-03-28 (0.11.3) 142 */ 143 public class Clock : ObjectGst 144 { 145 146 /** the main Gtk struct */ 147 protected GstClock* gstClock; 148 149 150 /** Get the main Gtk struct */ 151 public GstClock* getClockStruct() 152 { 153 return gstClock; 154 } 155 156 157 /** the main Gtk struct as a void* */ 158 protected override void* getStruct() 159 { 160 return cast(void*)gstClock; 161 } 162 163 /** 164 * Sets our main struct and passes it to the parent class 165 */ 166 public this (GstClock* gstClock) 167 { 168 super(cast(GstObject*)gstClock); 169 this.gstClock = gstClock; 170 } 171 172 protected override void setStruct(GObject* obj) 173 { 174 super.setStruct(obj); 175 gstClock = cast(GstClock*)obj; 176 } 177 178 /** 179 */ 180 181 /** 182 * The time master of the master clock and the time slave of the slave 183 * clock are added to the list of observations. If enough observations 184 * are available, a linear regression algorithm is run on the 185 * observations and clock is recalibrated. 186 * If this functions returns TRUE, r_squared will contain the 187 * correlation coefficient of the interpolation. A value of 1.0 188 * means a perfect regression was performed. This value can 189 * be used to control the sampling frequency of the master and slave 190 * clocks. 191 * Params: 192 * slave = a time on the slave 193 * master = a time on the master 194 * rSquared = a pointer to hold the result. [out] 195 * Returns: TRUE if enough observations were added to run the regression algorithm. MT safe. 196 */ 197 public int addObservation(GstClockTime slave, GstClockTime master, out double rSquared) 198 { 199 // gboolean gst_clock_add_observation (GstClock *clock, GstClockTime slave, GstClockTime master, gdouble *r_squared); 200 return gst_clock_add_observation(gstClock, slave, master, &rSquared); 201 } 202 203 /** 204 * Set master as the master clock for clock. clock will be automatically 205 * calibrated so that gst_clock_get_time() reports the same time as the 206 * master clock. 207 * A clock provider that slaves its clock to a master can get the current 208 * calibration values with gst_clock_get_calibration(). 209 * master can be NULL in which case clock will not be slaved anymore. It will 210 * however keep reporting its time adjusted with the last configured rate 211 * and time offsets. 212 * Params: 213 * master = a master GstClock. [allow-none] 214 * Returns: TRUE if the clock is capable of being slaved to a master clock. Trying to set a master on a clock without the GST_CLOCK_FLAG_CAN_SET_MASTER flag will make this function return FALSE. MT safe. 215 */ 216 public int setMaster(Clock master) 217 { 218 // gboolean gst_clock_set_master (GstClock *clock, GstClock *master); 219 return gst_clock_set_master(gstClock, (master is null) ? null : master.getClockStruct()); 220 } 221 222 /** 223 * Get the master clock that clock is slaved to or NULL when the clock is 224 * not slaved to any master clock. 225 * Returns: a master GstClock or NULL when this clock is not slaved to a master clock. Unref after usage. MT safe. [transfer full] 226 */ 227 public Clock getMaster() 228 { 229 // GstClock * gst_clock_get_master (GstClock *clock); 230 auto p = gst_clock_get_master(gstClock); 231 232 if(p is null) 233 { 234 return null; 235 } 236 237 return ObjectG.getDObject!(Clock)(cast(GstClock*) p); 238 } 239 240 /** 241 * Set the accuracy of the clock. Some clocks have the possibility to operate 242 * with different accuracy at the expense of more resource usage. There is 243 * normally no need to change the default resolution of a clock. The resolution 244 * of a clock can only be changed if the clock has the 245 * GST_CLOCK_FLAG_CAN_SET_RESOLUTION flag set. 246 * Params: 247 * resolution = The resolution to set 248 * Returns: the new resolution of the clock. 249 */ 250 public GstClockTime setResolution(GstClockTime resolution) 251 { 252 // GstClockTime gst_clock_set_resolution (GstClock *clock, GstClockTime resolution); 253 return gst_clock_set_resolution(gstClock, resolution); 254 } 255 256 /** 257 * Get the accuracy of the clock. The accuracy of the clock is the granularity 258 * of the values returned by gst_clock_get_time(). 259 * Returns: the resolution of the clock in units of GstClockTime. MT safe. 260 */ 261 public GstClockTime getResolution() 262 { 263 // GstClockTime gst_clock_get_resolution (GstClock *clock); 264 return gst_clock_get_resolution(gstClock); 265 } 266 267 /** 268 * Gets the current time of the given clock. The time is always 269 * monotonically increasing and adjusted according to the current 270 * offset and rate. 271 * Returns: the time of the clock. Or GST_CLOCK_TIME_NONE when given invalid input. MT safe. 272 */ 273 public GstClockTime getTime() 274 { 275 // GstClockTime gst_clock_get_time (GstClock *clock); 276 return gst_clock_get_time(gstClock); 277 } 278 279 /** 280 * Get a GstClockID from clock to trigger a single shot 281 * notification at the requested time. The single shot id should be 282 * unreffed after usage. 283 * Free-function: gst_clock_id_unref 284 * Params: 285 * time = the requested time 286 * Returns: a GstClockID that can be used to request the time notification. MT safe. [transfer full] 287 */ 288 public GstClockID newSingleShotId(GstClockTime time) 289 { 290 // GstClockID gst_clock_new_single_shot_id (GstClock *clock, GstClockTime time); 291 return gst_clock_new_single_shot_id(gstClock, time); 292 } 293 294 /** 295 * Get an ID from clock to trigger a periodic notification. 296 * The periodic notifications will start at time start_time and 297 * will then be fired with the given interval. id should be unreffed 298 * after usage. 299 * Free-function: gst_clock_id_unref 300 * Params: 301 * startTime = the requested start time 302 * interval = the requested interval 303 * Returns: a GstClockID that can be used to request the time notification. MT safe. [transfer full] 304 */ 305 public GstClockID newPeriodicId(GstClockTime startTime, GstClockTime interval) 306 { 307 // GstClockID gst_clock_new_periodic_id (GstClock *clock, GstClockTime start_time, GstClockTime interval); 308 return gst_clock_new_periodic_id(gstClock, startTime, interval); 309 } 310 311 /** 312 * Reinitializes the provided single shot id to the provided time. Does not 313 * modify the reference count. 314 * Params: 315 * id = a GstClockID 316 * time = The requested time. 317 * Returns: TRUE if the GstClockID could be reinitialized to the provided time, else FALSE. 318 */ 319 public int singleShotIdReinit(GstClockID id, GstClockTime time) 320 { 321 // gboolean gst_clock_single_shot_id_reinit (GstClock *clock, GstClockID id, GstClockTime time); 322 return gst_clock_single_shot_id_reinit(gstClock, id, time); 323 } 324 325 /** 326 * Reinitializes the provided periodic id to the provided start time and 327 * interval. Does not modify the reference count. 328 * Params: 329 * id = a GstClockID 330 * startTime = the requested start time 331 * interval = the requested interval 332 * Returns: TRUE if the GstClockID could be reinitialized to the provided time, else FALSE. 333 */ 334 public int periodicIdReinit(GstClockID id, GstClockTime startTime, GstClockTime interval) 335 { 336 // gboolean gst_clock_periodic_id_reinit (GstClock *clock, GstClockID id, GstClockTime start_time, GstClockTime interval); 337 return gst_clock_periodic_id_reinit(gstClock, id, startTime, interval); 338 } 339 340 /** 341 * Gets the current internal time of the given clock. The time is returned 342 * unadjusted for the offset and the rate. 343 * Returns: the internal time of the clock. Or GST_CLOCK_TIME_NONE when given invalid input. MT safe. 344 */ 345 public GstClockTime getInternalTime() 346 { 347 // GstClockTime gst_clock_get_internal_time (GstClock *clock); 348 return gst_clock_get_internal_time(gstClock); 349 } 350 351 /** 352 * Converts the given internal clock time to the external time, adjusting for the 353 * rate and reference time set with gst_clock_set_calibration() and making sure 354 * that the returned time is increasing. This function should be called with the 355 * clock's OBJECT_LOCK held and is mainly used by clock subclasses. 356 * This function is the reverse of gst_clock_unadjust_unlocked(). 357 * Params: 358 * internal = a clock time 359 * Returns: the converted time of the clock. 360 */ 361 public GstClockTime adjustUnlocked(GstClockTime internal) 362 { 363 // GstClockTime gst_clock_adjust_unlocked (GstClock *clock, GstClockTime internal); 364 return gst_clock_adjust_unlocked(gstClock, internal); 365 } 366 367 /** 368 * Converts the given external clock time to the internal time of clock, 369 * using the rate and reference time set with gst_clock_set_calibration(). 370 * This function should be called with the clock's OBJECT_LOCK held and 371 * is mainly used by clock subclasses. 372 * This function is the reverse of gst_clock_adjust_unlocked(). 373 * Params: 374 * external = an external clock time 375 * Returns: the internal time of the clock corresponding to external. 376 */ 377 public GstClockTime unadjustUnlocked(GstClockTime external) 378 { 379 // GstClockTime gst_clock_unadjust_unlocked (GstClock *clock, GstClockTime external); 380 return gst_clock_unadjust_unlocked(gstClock, external); 381 } 382 383 /** 384 * Gets the internal rate and reference time of clock. See 385 * gst_clock_set_calibration() for more information. 386 * internal, external, rate_num, and rate_denom can be left NULL if the 387 * caller is not interested in the values. 388 * MT safe. 389 * Params: 390 * internal = a location to store the internal time. [out][allow-none] 391 * external = a location to store the external time. [out][allow-none] 392 * rateNum = a location to store the rate numerator. [out][allow-none] 393 * rateDenom = a location to store the rate denominator. [out][allow-none] 394 */ 395 public void getCalibration(out GstClockTime internal, out GstClockTime external, out GstClockTime rateNum, out GstClockTime rateDenom) 396 { 397 // void gst_clock_get_calibration (GstClock *clock, GstClockTime *internal, GstClockTime *external, GstClockTime *rate_num, GstClockTime *rate_denom); 398 gst_clock_get_calibration(gstClock, &internal, &external, &rateNum, &rateDenom); 399 } 400 401 /** 402 * Adjusts the rate and time of clock. A rate of 1/1 is the normal speed of 403 * the clock. Values bigger than 1/1 make the clock go faster. 404 * internal and external are calibration parameters that arrange that 405 * gst_clock_get_time() should have been external at internal time internal. 406 * This internal time should not be in the future; that is, it should be less 407 * than the value of gst_clock_get_internal_time() when this function is called. 408 * Subsequent calls to gst_clock_get_time() will return clock times computed as 409 * Params: 410 * internal = a reference internal time 411 * external = a reference external time 412 * rateNum = the numerator of the rate of the clock relative to its 413 * internal time 414 * rateDenom = the denominator of the rate of the clock 415 */ 416 public void setCalibration(GstClockTime internal, GstClockTime external, GstClockTime rateNum, GstClockTime rateDenom) 417 { 418 // void gst_clock_set_calibration (GstClock *clock, GstClockTime internal, GstClockTime external, GstClockTime rate_num, GstClockTime rate_denom); 419 gst_clock_set_calibration(gstClock, internal, external, rateNum, rateDenom); 420 } 421 422 /** 423 * Get the amount of time that master and slave clocks are sampled. 424 * Returns: the interval between samples. 425 */ 426 public GstClockTime getTimeout() 427 { 428 // GstClockTime gst_clock_get_timeout (GstClock *clock); 429 return gst_clock_get_timeout(gstClock); 430 } 431 432 /** 433 * Set the amount of time, in nanoseconds, to sample master and slave 434 * clocks 435 * Params: 436 * timeout = a timeout 437 */ 438 public void setTimeout(GstClockTime timeout) 439 { 440 // void gst_clock_set_timeout (GstClock *clock, GstClockTime timeout); 441 gst_clock_set_timeout(gstClock, timeout); 442 } 443 444 /** 445 * Get the time of the clock ID 446 * Params: 447 * id = The GstClockID to query 448 * Returns: the time of the given clock id. MT safe. 449 */ 450 public static GstClockTime idGetTime(GstClockID id) 451 { 452 // GstClockTime gst_clock_id_get_time (GstClockID id); 453 return gst_clock_id_get_time(id); 454 } 455 456 /** 457 * Perform a blocking wait on id. 458 * id should have been created with gst_clock_new_single_shot_id() 459 * or gst_clock_new_periodic_id() and should not have been unscheduled 460 * with a call to gst_clock_id_unschedule(). 461 * If the jitter argument is not NULL and this function returns GST_CLOCK_OK 462 * or GST_CLOCK_EARLY, it will contain the difference 463 * against the clock and the time of id when this method was 464 * called. 465 * Positive values indicate how late id was relative to the clock 466 * (in which case this function will return GST_CLOCK_EARLY). 467 * Negative values indicate how much time was spent waiting on the clock 468 * before this function returned. 469 * Params: 470 * id = The GstClockID to wait on 471 * jitter = a pointer that will contain the jitter, 472 * can be NULL. [out][allow-none] 473 * Returns: the result of the blocking wait. GST_CLOCK_EARLY will be returned if the current clock time is past the time of id, GST_CLOCK_OK if id was scheduled in time. GST_CLOCK_UNSCHEDULED if id was unscheduled with gst_clock_id_unschedule(). MT safe. 474 */ 475 public static GstClockReturn idWait(GstClockID id, ref GstClockTimeDiff jitter) 476 { 477 // GstClockReturn gst_clock_id_wait (GstClockID id, GstClockTimeDiff *jitter); 478 return gst_clock_id_wait(id, &jitter); 479 } 480 481 /** 482 * Register a callback on the given GstClockID id with the given 483 * function and user_data. When passing a GstClockID with an invalid 484 * time to this function, the callback will be called immediately 485 * with a time set to GST_CLOCK_TIME_NONE. The callback will 486 * be called when the time of id has been reached. 487 * The callback func can be invoked from any thread, either provided by the 488 * core or from a streaming thread. The application should be prepared for this. 489 * Params: 490 * id = a GstClockID to wait on 491 * func = The callback function 492 * userData = User data passed in the callback 493 * destroyData = GDestroyNotify for user_data 494 * Returns: the result of the non blocking wait. MT safe. 495 */ 496 public static GstClockReturn idWaitAsync(GstClockID id, GstClockCallback func, void* userData, GDestroyNotify destroyData) 497 { 498 // GstClockReturn gst_clock_id_wait_async (GstClockID id, GstClockCallback func, gpointer user_data, GDestroyNotify destroy_data); 499 return gst_clock_id_wait_async(id, func, userData, destroyData); 500 } 501 502 /** 503 * Cancel an outstanding request with id. This can either 504 * be an outstanding async notification or a pending sync notification. 505 * After this call, id cannot be used anymore to receive sync or 506 * async notifications, you need to create a new GstClockID. 507 * MT safe. 508 * Params: 509 * id = The id to unschedule 510 */ 511 public static void idUnschedule(GstClockID id) 512 { 513 // void gst_clock_id_unschedule (GstClockID id); 514 gst_clock_id_unschedule(id); 515 } 516 517 /** 518 * Compares the two GstClockID instances. This function can be used 519 * as a GCompareFunc when sorting ids. 520 * Params: 521 * id1 = A GstClockID 522 * id2 = A GstClockID to compare with 523 * Returns: negative value if a < b; zero if a = b; positive value if a > b MT safe. 524 */ 525 public static int idCompareFunc(void* id1, void* id2) 526 { 527 // gint gst_clock_id_compare_func (gconstpointer id1, gconstpointer id2); 528 return gst_clock_id_compare_func(id1, id2); 529 } 530 531 /** 532 * Increase the refcount of given id. 533 * Params: 534 * id = The GstClockID to ref 535 * Returns: The same GstClockID with increased refcount. MT safe. [transfer full] 536 */ 537 public static GstClockID idRef(GstClockID id) 538 { 539 // GstClockID gst_clock_id_ref (GstClockID id); 540 return gst_clock_id_ref(id); 541 } 542 543 /** 544 * Unref given id. When the refcount reaches 0 the 545 * GstClockID will be freed. 546 * MT safe. 547 * Params: 548 * id = The GstClockID to unref. [transfer full] 549 */ 550 public static void idUnref(GstClockID id) 551 { 552 // void gst_clock_id_unref (GstClockID id); 553 gst_clock_id_unref(id); 554 } 555 }