Clock

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 gstreamer.SystemClock

The gstreamer.Clock returns a monotonically increasing time with the method 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 newsegment events and the element's base time, see gstreamer.Pipeline

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 Clock.newSingleShotId or Clock.newPeriodicId.

To perform a blocking wait for the specific time of the GstClockID use the Clock.idWait. To receive a callback when the specific time is reached in the clock use Clock.idWaitAsync. Both these calls can be interrupted with the 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 it is unscheduled. To schedule a sync periodic callback, 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 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 gstreamer.Clock with the 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 Clock.setCalibration. This feature is mostly useful for plugins that have an internal clock but must operate with another clock selected by the gstreamer.Pipeline They can track the offset and rate difference of their internal clock relative to the master clock by using the Clock.getCalibration function.

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

class Clock : ObjectGst {}

Constructors

this
this(GstClock* gstClock, bool ownedRef)

Sets our main struct and passes it to the parent class.

Members

Functions

addObservation
bool addObservation(GstClockTime slave, GstClockTime master, 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 observations and clock is recalibrated.

addObservationUnapplied
bool addObservationUnapplied(GstClockTime slave, GstClockTime master, double rSquared, GstClockTime internal, GstClockTime external, GstClockTime rateNum, GstClockTime rateDenom)

Add a clock observation to the internal slaving algorithm the same as Clock.addObservation, and return the result of the master clock estimation, without updating the internal calibration.

addOnSynced
gulong addOnSynced(void delegate(bool, Clock) dlg, ConnectFlags connectFlags)

Signaled on clocks with GST_CLOCK_FLAG_NEEDS_STARTUP_SYNC set once the clock is synchronized, or when it completely lost synchronization. This signal will not be emitted on clocks without the flag.

adjustUnlocked
GstClockTime adjustUnlocked(GstClockTime internal)

Converts the given internal clock time to the external time, adjusting for the rate and reference time set with Clock.setCalibration and making sure that the returned time is increasing. This function should be called with the clock's OBJECT_LOCK held and is mainly used by clock subclasses.

adjustWithCalibration
GstClockTime adjustWithCalibration(GstClockTime internalTarget, GstClockTime cinternal, GstClockTime cexternal, GstClockTime cnum, GstClockTime cdenom)

Converts the given internal_target clock time to the external time, using the passed calibration parameters. This function performs the same calculation as Clock.adjustUnlocked when called using the current calibration parameters, but doesn't ensure a monotonically increasing result as Clock.adjustUnlocked does.

getCalibration
void getCalibration(GstClockTime internal, GstClockTime external, GstClockTime rateNum, GstClockTime rateDenom)

Gets the internal rate and reference time of clock. See Clock.setCalibration for more information.

getClockStruct
GstClock* getClockStruct(bool transferOwnership)

Get the main Gtk struct

getInternalTime
GstClockTime getInternalTime()

Gets the current internal time of the given clock. The time is returned unadjusted for the offset and the rate.

getMaster
Clock getMaster()

Get the master clock that clock is slaved to or NULL when the clock is not slaved to any master clock.

getResolution
GstClockTime getResolution()

Get the accuracy of the clock. The accuracy of the clock is the granularity of the values returned by Clock.getTime.

getStruct
void* getStruct()

the main Gtk struct as a void*

getTime
GstClockTime getTime()

Gets the current time of the given clock. The time is always monotonically increasing and adjusted according to the current offset and rate.

getTimeout
GstClockTime getTimeout()

Get the amount of time that master and slave clocks are sampled.

isSynced
bool isSynced()

Checks if the clock is currently synced.

newPeriodicId
GstClockID newPeriodicId(GstClockTime startTime, GstClockTime interval)

Get 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. id should be unreffed after usage.

newSingleShotId
GstClockID newSingleShotId(GstClockTime time)

Get a GstClockID from clock to trigger a single shot notification at the requested time. The single shot id should be unreffed after usage.

periodicIdReinit
bool periodicIdReinit(GstClockID id, GstClockTime startTime, GstClockTime interval)

Reinitializes the provided periodic id to the provided start time and interval. Does not modify the reference count.

setCalibration
void setCalibration(GstClockTime internal, GstClockTime external, GstClockTime rateNum, GstClockTime 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.

setMaster
bool setMaster(Clock master)

Set master as the master clock for clock. clock will be automatically calibrated so that Clock.getTime reports the same time as the master clock.

setResolution
GstClockTime setResolution(GstClockTime resolution)

Set 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 of a clock. The resolution of a clock can only be changed if the clock has the GST_CLOCK_FLAG_CAN_SET_RESOLUTION flag set.

setSynced
void setSynced(bool synced)

Sets clock to synced and emits the GstClock::synced signal, and wakes up any thread waiting in Clock.waitForSync.

setTimeout
void setTimeout(GstClockTime timeout)

Set the amount of time, in nanoseconds, to sample master and slave clocks

singleShotIdReinit
bool singleShotIdReinit(GstClockID id, GstClockTime time)

Reinitializes the provided single shot id to the provided time. Does not modify the reference count.

unadjustUnlocked
GstClockTime unadjustUnlocked(GstClockTime external)

Converts the given external clock time to the internal time of clock, using the rate and reference time set with Clock.setCalibration. This function should be called with the clock's OBJECT_LOCK held and is mainly used by clock subclasses.

unadjustWithCalibration
GstClockTime unadjustWithCalibration(GstClockTime externalTarget, GstClockTime cinternal, GstClockTime cexternal, GstClockTime cnum, GstClockTime cdenom)

Converts the given external_target clock time to the internal time, using the passed calibration parameters. This function performs the same calculation as Clock.unadjustUnlocked when called using the current calibration parameters.

waitForSync
bool waitForSync(GstClockTime timeout)

Waits until clock is synced for reporting the current time. If timeout is GST_CLOCK_TIME_NONE it will wait forever, otherwise it will time out after timeout nanoseconds.

Static functions

getType
GType getType()
idCompareFunc
int idCompareFunc(void* id1, void* id2)

Compares the two GstClockID instances. This function can be used as a GCompareFunc when sorting ids.

idGetClock
Clock idGetClock(GstClockID id)

This function returns the underlying clock.

idGetTime
GstClockTime idGetTime(GstClockID id)

Get the time of the clock ID

idRef
GstClockID idRef(GstClockID id)

Increase the refcount of given id.

idUnref
void idUnref(GstClockID id)

Unref given id. When the refcount reaches 0 the GstClockID will be freed.

idUnschedule
void idUnschedule(GstClockID id)

Cancel 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 notifications, you need to create a new GstClockID

idUsesClock
bool idUsesClock(GstClockID id, 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, the id is no longer usable and should be freed.

idWait
GstClockReturn idWait(GstClockID id, GstClockTimeDiff jitter)

Perform a blocking wait on id. id should have been created with Clock.newSingleShotId or Clock.newPeriodicId and should not have been unscheduled with a call to Clock.idUnschedule.

idWaitAsync
GstClockReturn idWaitAsync(GstClockID id, GstClockCallback func, void* userData, GDestroyNotify destroyData)

Register a callback on the given GstClockID id with the given function and user_data. When passing a GstClockID with an invalid time to this function, the callback will be called immediately with a time set to GST_CLOCK_TIME_NONE. The callback will be called when the time of id has been reached.

Variables

gstClock
GstClock* gstClock;

the main Gtk struct

Inherited Members

From ObjectGst

gstObject
GstObject* gstObject;

the main Gtk struct

getObjectGstStruct
GstObject* getObjectGstStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

getType
GType getType()
checkUniqueness
bool checkUniqueness(ListG list, string name)

Checks to see if there is any object named name in list. This function does not do any locking of any kind. You might want to protect the provided list with the lock of the owner of the list. This function will lock each GstObject in the list to compare the name, so be careful when passing a list with a locked object.

defaultDeepNotify
void defaultDeepNotify(ObjectG object, ObjectGst orig, ParamSpec pspec, string[] excludedProps)

A default deep_notify signal callback for an object. The user data should contain a pointer to an array of strings that should be excluded from the notify. The default handler will print the new value of the property using g_print.

refSink
void* refSink(void* object)

Increase the reference count of object, and possibly remove the floating reference, if object has a floating reference.

replace
bool replace(ObjectGst oldobj, ObjectGst newobj)

Atomically modifies a pointer to point to a new object. The reference count of oldobj is decreased and the reference count of newobj is increased.

addControlBinding
bool addControlBinding(ControlBinding binding)

Attach the gstreamer.ControlBinding to the object. If there already was a gstreamer.ControlBinding for this property it will be replaced.

defaultError
void defaultError(ErrorG error, string debug_)

A default error function that uses g_printerr() to display the error message and the optional debug string..

getControlBinding
ControlBinding getControlBinding(string propertyName)

Gets the corresponding gstreamer.ControlBinding for the property. This should be unreferenced again after use.

getControlRate
GstClockTime getControlRate()

Obtain the control-rate for this object. Audio processing gstreamer.Element objects will use this rate to sub-divide their processing loop and call gst_object_sync_values() in between. The length of the processing segment should be up to control-rate nanoseconds.

getGValueArray
bool getGValueArray(string propertyName, GstClockTime timestamp, GstClockTime interval, Value[] values)

Gets a number of gobject.Values for the given controlled property starting at the requested time. The array values need to hold enough space for n_values of gobject.Value

getName
string getName()

Returns a copy of the name of object. Caller should g_free() the return value after usage. For a nameless object, this returns NULL, which you can safely g_free() as well.

getParent
ObjectGst getParent()

Returns the parent of object. This function increases the refcount of the parent object so you should gst_object_unref() it after usage.

getPathString
string getPathString()

Generates a string describing the path of object in the object hierarchy. Only useful (or used) for debugging.

getValue
Value getValue(string propertyName, GstClockTime timestamp)

Gets the value for the given controlled property at the requested time.

getValueArray
bool getValueArray(string propertyName, GstClockTime timestamp, GstClockTime interval, uint nValues, void* values)

Gets a number of values for the given controlled property starting at the requested time. The array values need to hold enough space for n_values of the same type as the objects property's type.

hasActiveControlBindings
bool hasActiveControlBindings()

Check if the object has active controlled properties.

hasAncestor
bool hasAncestor(ObjectGst ancestor)

Check if object has an ancestor ancestor somewhere up in the hierarchy. One can e.g. check if a gstreamer.Element is inside a gstreamer.Pipeline

hasAsAncestor
bool hasAsAncestor(ObjectGst ancestor)

Check if object has an ancestor ancestor somewhere up in the hierarchy. One can e.g. check if a gstreamer.Element is inside a gstreamer.Pipeline

hasAsParent
bool hasAsParent(ObjectGst parent)

Check if parent is the parent of object. E.g. a gstreamer.Element can check if it owns a given gstreamer.Pad

ref_
ObjectGst ref_()

Increments the reference count on object. This function does not take the lock on object because it relies on atomic refcounting.

removeControlBinding
bool removeControlBinding(ControlBinding binding)

Removes the corresponding gstreamer.ControlBinding If it was the last ref of the binding, it will be disposed.

setControlBindingDisabled
void setControlBindingDisabled(string propertyName, bool disabled)

This function is used to disable the control bindings on a property for some time, i.e. gst_object_sync_values() will do nothing for the property.

setControlBindingsDisabled
void setControlBindingsDisabled(bool disabled)

This function is used to disable all controlled properties of the object for some time, i.e. gst_object_sync_values() will do nothing.

setControlRate
void setControlRate(GstClockTime controlRate)

Change the control-rate for this object. Audio processing gstreamer.Element objects will use this rate to sub-divide their processing loop and call gst_object_sync_values() in between. The length of the processing segment should be up to control-rate nanoseconds.

setName
bool setName(string name)

Sets the name of object, or gives object a guaranteed unique name (if name is NULL). This function makes a copy of the provided name, so the caller retains ownership of the name it sent.

setParent
bool setParent(ObjectGst parent)

Sets the parent of object to parent. The object's reference count will be incremented, and any floating reference will be removed (see gst_object_ref_sink()).

suggestNextSync
GstClockTime suggestNextSync()

Returns a suggestion for timestamps where buffers should be split to get best controller results.

syncValues
bool syncValues(GstClockTime timestamp)

Sets the properties of the object, according to the gstreamer.ControlSources that (maybe) handle them and for the given timestamp.

unparent
void unparent()

Clear the parent of object, removing the associated reference. This function decreases the refcount of object.

unref
void unref()

Decrements the reference count on object. If reference count hits zero, destroy object. This function does not take the lock on object as it relies on atomic refcounting.

addOnDeepNotify
gulong addOnDeepNotify(void delegate(ObjectGst, ParamSpec, ObjectGst) dlg, ConnectFlags connectFlags)

The deep notify signal is used to be notified of property changes. It is typically attached to the toplevel bin to receive notifications from all the elements contained in that bin.