gst.clock

Module for [Clock] class

Types 3

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 #GstSystemClock.

The #GstClock returns a monotonically increasing time with the method [gst.clock.Clock.getTime]. 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 #GST_EVENT_SEGMENT events and the element's base time, see #GstPipeline.

A clock implementation can support periodic and single shot clock notifications both synchronous and asynchronous.

One first needs to create a #GstClockID for the periodic or single shot notification using [gst.clock.Clock.newSingleShotId] or [gst.clock.Clock.newPeriodicId].

To perform a blocking wait for the specific time of the #GstClockID use [gst.clock.Clock.idWait]. To receive a callback when the specific time is reached in the clock use [gst.clock.Clock.idWaitAsync]. Both these calls can be interrupted with the [gst.clock.Clock.idUnschedule] 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 they are unscheduled. To schedule a sync periodic callback, [gst.clock.Clock.idWait] 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 #GstClockID that has been unscheduled cannot be used again for any wait operation, a new #GstClockID should be created and the old unscheduled one should be destroyed with [gst.clock.Clock.idUnref].

It is possible to perform a blocking wait on the same #GstClockID from multiple threads. However, registering the same #GstClockID 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 #GstClockID, 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 #GstClockID has to keep a handle to the #GstClockID 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 #GstClock with [gst.clock.Clock.setMaster]. 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.clock.Clock.setCalibration]. This feature is mostly useful for plugins that have an internal clock but must operate with another clock selected by the #GstPipeline. They can track the offset and rate difference of their internal clock relative to the master clock by using the [gst.clock.Clock.getCalibration] function.

The master/slave synchronisation can be tuned with the #GstClock:timeout, #GstClock:window-size and #GstClock:window-threshold properties. The #GstClock:timeout property defines the interval to sample the master clock and run the calibration functions. #GstClock:window-size defines the number of samples to use when calibrating and #GstClock:window-threshold defines the minimum number of samples before the calibration is performed.

Methods
GType _gType() @property
Clock self()Returns `this`, for use in `with` statements.
ClockGidBuilder builder()Get builder for [gst.clock.Clock] Returns: New builder object
ulong timeout() @property
void timeout(ulong propval) @property
int windowSize() @property
void windowSize(int propval) @property
int windowThreshold() @property
void windowThreshold(int propval) @property
int idCompareFunc(const(void) * id1 = null, const(void) * id2 = null)Compares the two #GstClockID instances. This function can be used as a GCompareFunc when sorting ids.
gst.clock.Clock idGetClock(gst.types.ClockID id)This function returns the underlying clock.
gst.types.ClockTime idGetTime(gst.types.ClockID id)Gets the time of the clock ID
gst.types.ClockID idRef(gst.types.ClockID id)Increases the refcount of given id.
void idUnref(gst.types.ClockID id)Unrefs given id. When the refcount reaches 0 the #GstClockID will be freed.
void idUnschedule(gst.types.ClockID id)Cancels an outstanding request with id. This can either be an outstanding async notification or a pending sync notification. After this call, id cannot be used anymore to receive sync or async noti...
bool idUsesClock(gst.types.ClockID id, gst.clock.Clock clock)This function returns whether id uses clock as the underlying clock. clock can be NULL, in which case the return value indicates whether the underlying clock has been freed. If this is the case, t...
gst.types.ClockReturn idWait(gst.types.ClockID id, out gst.types.ClockTimeDiff jitter)Performs a blocking wait on id. id should have been created with [gst.clock.Clock.newSingleShotId] or [gst.clock.Clock.newPeriodicId] and should not have been unscheduled with a call to [gst.clock....
gst.types.ClockReturn idWaitAsync(gst.types.ClockID id, gst.types.ClockCallback func)Registers a callback on the given #GstClockID id with the given function and userdata. When passing a #GstClockID with an invalid time to this function, the callback will be called immediately with...
bool addObservation(gst.types.ClockTime slave, gst.types.ClockTime master, out double rSquared)The time master of the master clock and the time slave of the slave clock are added to the list of observations. If enough observations are available, a linear regression algorithm is run on the ob...
bool addObservationUnapplied(gst.types.ClockTime slave, gst.types.ClockTime master, out double rSquared, out gst.types.ClockTime internal, out gst.types.ClockTime external, out gst.types.ClockTime rateNum, out gst.types.ClockTime rateDenom)Add a clock observation to the internal slaving algorithm the same as [gst.clock.Clock.addObservation], and return the result of the master clock estimation, without updating the internal calibration.
gst.types.ClockTime adjustUnlocked(gst.types.ClockTime internal)Converts the given internal clock time to the external time, adjusting for the rate and reference time set with [gst.clock.Clock.setCalibration] and making sure that the returned time is increasing...
gst.types.ClockTime adjustWithCalibration(gst.types.ClockTime internalTarget, gst.types.ClockTime cinternal, gst.types.ClockTime cexternal, gst.types.ClockTime cnum, gst.types.ClockTime cdenom)Converts the given internal_target clock time to the external time, using the passed calibration parameters. This function performs the same calculation as [gst.clock.Clock.adjustUnlocked] when cal...
void getCalibration(out gst.types.ClockTime internal, out gst.types.ClockTime external, out gst.types.ClockTime rateNum, out gst.types.ClockTime rateDenom)Gets the internal rate and reference time of clock. See [gst.clock.Clock.setCalibration] for more information.
gst.types.ClockTime getInternalTime()Gets the current internal time of the given clock. The time is returned unadjusted for the offset and the rate. Returns: the internal time of the clock. Or [gst.types.CLOCKTIMENONE] when given inva...
gst.clock.Clock getMaster()Gets the master clock that clock is slaved to or null when the clock is not slaved to any master clock. Returns: a master #GstClock or null when this clock is not slaved to a master clock.
gst.types.ClockTime getResolution()Gets the accuracy of the clock. The accuracy of the clock is the granularity of the values returned by [gst.clock.Clock.getTime]. Returns: the resolution of the clock in units of #GstClockTime.
gst.types.ClockTime getTime()Gets the current time of the given clock. The time is always monotonically increasing and adjusted according to the current offset and rate. Returns: the time of the clock. Or [gst.types.CLOCKTIMEN...
gst.types.ClockTime getTimeout()Gets the amount of time that master and slave clocks are sampled. Returns: the interval between samples.
bool isSynced()Checks if the clock is currently synced, by looking at whether [gst.types.ClockFlags.NeedsStartupSync] is set. Returns: true if the clock is currently synced
gst.types.ClockID newPeriodicId(gst.types.ClockTime startTime, gst.types.ClockTime interval)Gets an ID from clock to trigger a periodic notification. The periodic notifications will start at time start_time and will then be fired with the given interval.
gst.types.ClockID newSingleShotId(gst.types.ClockTime time)Gets a #GstClockID from clock to trigger a single shot notification at the requested time.
bool periodicIdReinit(gst.types.ClockID id, gst.types.ClockTime startTime, gst.types.ClockTime interval)Reinitializes the provided periodic id to the provided start time and interval. Does not modify the reference count.
void setCalibration(gst.types.ClockTime internal, gst.types.ClockTime external, gst.types.ClockTime rateNum, gst.types.ClockTime rateDenom)Adjusts the rate and time of clock. A rate of 1/1 is the normal speed of the clock. Values bigger than 1/1 make the clock go faster.
bool setMaster(gst.clock.Clock master = null)Sets master as the master clock for clock. clock will be automatically calibrated so that [gst.clock.Clock.getTime] reports the same time as the master clock.
gst.types.ClockTime setResolution(gst.types.ClockTime resolution)Sets the accuracy of the clock. Some clocks have the possibility to operate with different accuracy at the expense of more resource usage. There is normally no need to change the default resolution...
void setSynced(bool synced)Sets clock to synced and emits the #GstClock::synced signal, and wakes up any thread waiting in [gst.clock.Clock.waitForSync].
void setTimeout(gst.types.ClockTime timeout)Sets the amount of time, in nanoseconds, to sample master and slave clocks
bool singleShotIdReinit(gst.types.ClockID id, gst.types.ClockTime time)Reinitializes the provided single shot id to the provided time. Does not modify the reference count.
gst.types.ClockTime unadjustUnlocked(gst.types.ClockTime external)Converts the given external clock time to the internal time of clock, using the rate and reference time set with [gst.clock.Clock.setCalibration]. This function should be called with the clock's OB...
gst.types.ClockTime unadjustWithCalibration(gst.types.ClockTime externalTarget, gst.types.ClockTime cinternal, gst.types.ClockTime cexternal, gst.types.ClockTime cnum, gst.types.ClockTime cdenom)Converts the given external_target clock time to the internal time, using the passed calibration parameters. This function performs the same calculation as [gst.clock.Clock.unadjustUnlocked] when c...
bool waitForSync(gst.types.ClockTime timeout)Waits until clock is synced for reporting the current time. If timeout is [gst.types.CLOCKTIMENONE] it will wait forever, otherwise it will time out after timeout nanoseconds.
gulong connectSynced(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == bool))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gst.clock.Clock))) && Parameters!T.length < 3)Connect to `Synced` signal.
Constructors
this(void * ptr, Flag!"Take" take)
Methods
T timeout(ulong propval)
T windowSize(int propval)
T windowThreshold(int propval)

Fluent builder for [gst.clock.Clock]

Methods
Clock build()