Gst.Clock
const Gst = imports.gi.Gst; let clock = new Gst.Clock({ timeout: value, window_size: value, window_threshold: value, });
GStreamer uses a global clock to synchronize the plugins in a pipeline. Different clock implementations are possible by implementing this abstract base class or, more conveniently, by subclassing Gst.SystemClock.
The Gst.Clock returns a monotonically increasing time with the method Gst.get_time. Its accuracy and base time depend on the specific clock implementation but time is always expressed in nanoseconds. Since the baseline of the clock is undefined, the clock time returned is not meaningful in itself, what matters are the deltas between two clock times. The time returned by a clock is called the absolute time.
The pipeline uses the clock to calculate the running time. Usually all renderers synchronize to the global clock using the buffer timestamps, the newsegment events and the element's base time, see Gst.Pipeline.
A clock implementation can support periodic and single shot clock notifications both synchronous and asynchronous.
One first needs to create a Gst.ClockID for the periodic or single shot notification using Gst.new_single_shot_id or Gst.new_periodic_id.
To perform a blocking wait for the specific time of the Gst.ClockID use the Gst.id_wait. To receive a callback when the specific time is reached in the clock use Gst.id_wait_async. Both these calls can be interrupted with the Gst.id_unschedule call. If the blocking wait is unscheduled a return value of #GST_CLOCK_UNSCHEDULED is returned.
Periodic callbacks scheduled async will be repeatedly called automatically until it is unscheduled. To schedule a sync periodic callback, Gst.id_wait should be called repeatedly.
The async callbacks can happen from any thread, either provided by the core or from a streaming thread. The application should be prepared for this.
A Gst.ClockID that has been unscheduled cannot be used again for any wait operation, a new Gst.ClockID should be created and the old unscheduled one should be destroyed with Gst.id_unref.
It is possible to perform a blocking wait on the same Gst.ClockID from multiple threads. However, registering the same Gst.ClockID for multiple async notifications is not possible, the callback will only be called for the thread registering the entry last.
None of the wait operations unref the Gst.ClockID, the owner is responsible for unreffing the ids itself. This holds for both periodic and single shot notifications. The reason being that the owner of the Gst.ClockID has to keep a handle to the Gst.ClockID to unblock the wait on FLUSHING events or state changes and if the entry would be unreffed automatically, the handle might become invalid without any notification.
These clock operations do not operate on the running time, so the callbacks will also occur when not in PLAYING state as if the clock just keeps on running. Some clocks however do not progress when the element that provided the clock is not PLAYING.
When a clock has the #GST_CLOCK_FLAG_CAN_SET_MASTER flag set, it can be slaved to another Gst.Clock with the Gst.set_master. The clock will then automatically be synchronized to this master clock by repeatedly sampling the master clock and the slave clock and recalibrating the slave clock with Gst.set_calibration. This feature is mostly useful for plugins that have an internal clock but must operate with another clock selected by the Gst.Pipeline. They can track the offset and rate difference of their internal clock relative to the master clock by using the Gst.get_calibration function.
The master/slave synchronisation can be tuned with the Gst.timeout, Gst.window-size and Gst.window-threshold properties. The Gst.timeout property defines the interval to sample the master clock and run the calibration functions. Gst.window-size defines the number of samples to use when calibrating and Gst.window-threshold defines the minimum number of samples before the calibration is performed.
Last reviewed on 2012-03-28 (0.11.3)
Hierarchy
-
GObject.Object
-
GObject.InitiallyUnowned
-
Gst.Object
- Gst.Clock
-
-
Methods
- Gst.Clock.prototype.add_observation
- Gst.Clock.prototype.adjust_unlocked
- Gst.Clock.prototype.get_calibration
- Gst.Clock.prototype.get_internal_time
- Gst.Clock.prototype.get_master
- Gst.Clock.prototype.get_resolution
- Gst.Clock.prototype.get_time
- Gst.Clock.prototype.get_timeout
- Gst.Clock.prototype.new_periodic_id
- Gst.Clock.prototype.new_single_shot_id
- Gst.Clock.prototype.periodic_id_reinit
- Gst.Clock.prototype.set_calibration
- Gst.Clock.prototype.set_master
- Gst.Clock.prototype.set_resolution
- Gst.Clock.prototype.set_timeout
- Gst.Clock.prototype.single_shot_id_reinit
- Gst.Clock.prototype.unadjust_unlocked