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