Class Clock
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
Clock.Clock$Impl,SystemClock
GstSystemClock.
The GstClock returns a monotonically increasing time with the method
gst_clock_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
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_new_single_shot_id() or
gst_clock_new_periodic_id().
To perform a blocking wait for the specific time of the GstClockID use
gst_clock_id_wait(). To receive a callback when the specific time is reached
in the clock use gst_clock_id_wait_async(). Both these calls can be
interrupted with the gst_clock_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 they are unscheduled. To schedule a sync periodic callback, gst_clock_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 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_id_unref().
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_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_clock_set_calibration(). 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_get_calibration() 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClock.Builder<B extends Clock.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classThe Clock$Impl type represents a native instance of the abstract Clock class.static classGStreamer clock class.static interfaceFunctional interface declaration of theSyncedCallbackcallback.Nested classes/interfaces inherited from class org.freedesktop.gstreamer.gst.GstObject
GstObject.DeepNotifyCallback, GstObject.Object$Impl, GstObject.ObjectClassNested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback -
Constructor Summary
ConstructorsConstructorDescriptionClock()Creates a new Clock.Clock(MemorySegment address) Create a Clock proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddObservation(ClockTime observationInternal, ClockTime observationExternal, Out<Double> rSquared) The timeobservationExternalof the external or master clock and the timeobservationInternalof the internal or slave clock are added to the list of observations.booleanaddObservationUnapplied(ClockTime observationInternal, ClockTime observationExternal, Out<Double> rSquared, @Nullable ClockTime internal, @Nullable ClockTime external, @Nullable ClockTime rateNum, @Nullable ClockTime rateDenom) Add a clock observation to the internal slaving algorithm the same as gst_clock_add_observation(), and return the result of the external or master clock estimation, without updating the internal calibration.adjustUnlocked(ClockTime internal) Converts the giveninternalclock time to the external time, adjusting for the rate and reference time set with gst_clock_set_calibration() and making sure that the returned time is increasing.adjustWithCalibration(ClockTime internalTarget, ClockTime cinternal, ClockTime cexternal, ClockTime cnum, ClockTime cdenom) Converts the giveninternalTargetclock time to the external time, using the passed calibration parameters.protected ClockasParent()Returns this instance as if it were its parent type.protected ClockTimechangeResolution(ClockTime oldResolution, ClockTime newResolution) Change the resolution of the clock.voidemitSynced(boolean synced) Emits the "synced" signal.voidgetCalibration(@Nullable ClockTime internal, @Nullable ClockTime external, @Nullable ClockTime rateNum, @Nullable ClockTime rateDenom) Gets the internal rate and reference time ofclock.See gst_clock_set_calibration() for more information.Gets the current internal time of the given clock.@Nullable ClockGets the master clock that this Clock is slaved to ornullwhen the clock is not slaved to any master clock.static MemoryLayoutThe memory layout of the native struct.Gets the accuracy of the clock.getTime()Gets the current time of the given clock.Gets the amount of time that master and slave clocks are sampled.static @Nullable TypegetType()Get the GType of the Clock classstatic intidCompareFunc(@Nullable MemorySegment id1, @Nullable MemorySegment id2) Compares the twoGstClockIDinstances.static @Nullable ClockidGetClock(@Nullable ClockID id) This function returns the underlying clock.static ClockTimeGets the time of the clock IDstatic @Nullable ClockIDIncreases the refcount of givenid.static voidUnrefs givenid.When the refcount reaches 0 theGstClockIDwill be freed.static voididUnschedule(@Nullable ClockID id) Cancels an outstanding request withid.This can either be an outstanding async notification or a pending sync notification.static booleanidUsesClock(@Nullable ClockID id, Clock clock) This function returns whetheridusesclockas the underlying clock.static ClockReturnidWait(@Nullable ClockID id, @Nullable ClockTimeDiff jitter) Performs a blocking wait onid.idshould have been created with gst_clock_new_single_shot_id() or gst_clock_new_periodic_id() and should not have been unscheduled with a call to gst_clock_id_unschedule().static ClockReturnidWaitAsync(@Nullable ClockID id, @Nullable ClockCallback func) Registers a callback on the givenGstClockIDidwith the given function and user_data.booleanisSynced()Checks if the clock is currently synced, by looking at whetherClockFlags.NEEDS_STARTUP_SYNCis set.@Nullable ClockIDnewPeriodicId(ClockTime startTime, ClockTime interval) Gets an ID from this Clock to trigger a periodic notification.@Nullable ClockIDnewSingleShotId(ClockTime time) Gets aGstClockIDfrom this Clock to trigger a single shot notification at the requested time.onSynced(Clock.SyncedCallback handler) Signaled on clocks withClockFlags.NEEDS_STARTUP_SYNCset once the clock is synchronized, or when it completely lost synchronization.booleanperiodicIdReinit(@Nullable ClockID id, ClockTime startTime, ClockTime interval) Reinitializes the provided periodicidto the provided start time and interval.voidsetCalibration(ClockTime internal, ClockTime external, ClockTime rateNum, ClockTime rateDenom) Adjusts the rate and time ofclock.A rate of 1/1 is the normal speed of the clock.booleanSetsmasteras the master clock forclock.this Clock will be automatically calibrated so that gst_clock_get_time() reports the same time as the master clock.setResolution(ClockTime resolution) Sets the accuracy of the clock.voidsetSynced(boolean synced) Sets this Clock to synced and emits theGstClock::synced signal, and wakes up any thread waiting in gst_clock_wait_for_sync().voidsetTimeout(ClockTime timeout) Sets the amount of time, in nanoseconds, to sample master and slave clocksbooleansingleShotIdReinit(@Nullable ClockID id, ClockTime time) Reinitializes the provided single shotidto the provided time.unadjustUnlocked(ClockTime external) Converts the givenexternalclock time to the internal time ofclock,using the rate and reference time set with gst_clock_set_calibration().unadjustWithCalibration(ClockTime externalTarget, ClockTime cinternal, ClockTime cexternal, ClockTime cnum, ClockTime cdenom) Converts the givenexternalTargetclock time to the internal time, using the passed calibration parameters.protected voidunschedule(ClockEntry entry) Unblock a blocking or async wait operation.protected ClockReturnwait_(ClockEntry entry, @Nullable ClockTimeDiff jitter) Perform a blocking wait on the givenGstClockEntryand return the jitter.protected ClockReturnwaitAsync(ClockEntry entry) Perform an asynchronous wait on the givenGstClockEntry.booleanwaitForSync(ClockTime timeout) Waits until this Clock is synced for reporting the current time.Methods inherited from class org.freedesktop.gstreamer.gst.GstObject
addControlBinding, checkUniqueness, deepNotify, defaultDeepNotify, defaultError, emitDeepNotify, getControlBinding, getControlRate, getGValueArray, getName, getParent, getPathString, getValue, getValueArray, hasActiveControlBindings, hasAncestor, hasAsAncestor, hasAsParent, onDeepNotify, ref, refSink, removeControlBinding, replace, setControlBindingDisabled, setControlBindingsDisabled, setControlRate, setName, setParent, suggestNextSync, syncValues, unparent, unrefMethods inherited from class org.gnome.gobject.InitiallyUnowned
builderMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Clock
Create a Clock proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Clock
public Clock()Creates a new Clock.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
idCompareFunc
Compares the twoGstClockIDinstances. This function can be used as a GCompareFunc when sorting ids.- Parameters:
id1- AGstClockIDid2- AGstClockIDto compare with- Returns:
- negative value if
a < b; zero ifa = b; positive value ifa > b
-
idGetClock
-
idGetTime
-
idRef
-
idUnref
Unrefs givenid.When the refcount reaches 0 theGstClockIDwill be freed.- Parameters:
id- TheGstClockIDto unref
-
idUnschedule
Cancels an outstanding request withid.This can either be an outstanding async notification or a pending sync notification. After this call,idcannot be used anymore to receive sync or async notifications, you need to create a newGstClockID.- Parameters:
id- The id to unschedule
-
idUsesClock
This function returns whetheridusesclockas the underlying clock.clockcan be NULL, in which case the return value indicates whether the underlying clock has been freed. If this is the case, theidis no longer usable and should be freed.- Parameters:
id- aGstClockIDto checkclock- aGstClockto compare against- Returns:
- whether the clock
iduses the same underlyingGstClockclock. - Since:
- 1.16
-
idWait
Performs a blocking wait onid.idshould have been created with gst_clock_new_single_shot_id() or gst_clock_new_periodic_id() and should not have been unscheduled with a call to gst_clock_id_unschedule().If the
jitterargument is notnulland this function returnsGST_CLOCK_OKorGST_CLOCK_EARLY, it will contain the difference against the clock and the time ofidwhen this method was called. Positive values indicate how lateidwas relative to the clock (in which case this function will returnGST_CLOCK_EARLY). Negative values indicate how much time was spent waiting on the clock before this function returned.- Parameters:
id- TheGstClockIDto wait onjitter- a pointer that will contain the jitter, can benull.- Returns:
- the result of the blocking wait.
GST_CLOCK_EARLYwill be returned if the current clock time is past the time ofid,GST_CLOCK_OKifidwas scheduled in time.GST_CLOCK_UNSCHEDULEDifidwas unscheduled with gst_clock_id_unschedule().
-
idWaitAsync
Registers a callback on the givenGstClockIDidwith the given function and user_data. When passing aGstClockIDwith an invalid time to this function, the callback will be called immediately with a time set toGST_CLOCK_TIME_NONE. The callback will be called when the time ofidhas been reached.The callback
funccan be invoked from any thread, either provided by the core or from a streaming thread. The application should be prepared for this.- Parameters:
id- aGstClockIDto wait onfunc- The callback function- Returns:
- the result of the non blocking wait.
-
addObservation
public boolean addObservation(ClockTime observationInternal, ClockTime observationExternal, Out<Double> rSquared) The timeobservationExternalof the external or master clock and the timeobservationInternalof the internal or slave clock are added to the list of observations. If enough observations are available, a linear regression algorithm is run on the observations and this Clock is recalibrated.If this functions returns
true,rSquaredwill contain the correlation coefficient of the interpolation. A value of 1.0 means a perfect regression was performed. This value can be used to control the sampling frequency of the master and slave clocks.- Parameters:
observationInternal- a time on the internal clockobservationExternal- a time on the external clockrSquared- a pointer to hold the result- Returns:
trueif enough observations were added to run the regression algorithm.
-
addObservationUnapplied
public boolean addObservationUnapplied(ClockTime observationInternal, ClockTime observationExternal, Out<Double> rSquared, @Nullable ClockTime internal, @Nullable ClockTime external, @Nullable ClockTime rateNum, @Nullable ClockTime rateDenom) Add a clock observation to the internal slaving algorithm the same as gst_clock_add_observation(), and return the result of the external or master clock estimation, without updating the internal calibration.The caller can then take the results and call gst_clock_set_calibration() with the values, or some modified version of them.
- Parameters:
observationInternal- a time on the internal clockobservationExternal- a time on the external clockrSquared- a pointer to hold the resultinternal- a location to store the internal timeexternal- a location to store the external timerateNum- a location to store the rate numeratorrateDenom- a location to store the rate denominator- Returns:
trueif enough observations were added to run the regression algorithm.- Since:
- 1.6
-
adjustUnlocked
Converts the giveninternalclock time to the external time, adjusting for the rate and reference time set with gst_clock_set_calibration() 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.This function is the reverse of gst_clock_unadjust_unlocked().
- Parameters:
internal- a clock time- Returns:
- the converted time of the clock.
-
adjustWithCalibration
public ClockTime adjustWithCalibration(ClockTime internalTarget, ClockTime cinternal, ClockTime cexternal, ClockTime cnum, ClockTime cdenom) Converts the giveninternalTargetclock time to the external time, using the passed calibration parameters. This function performs the same calculation as gst_clock_adjust_unlocked() when called using the current calibration parameters, but doesn't ensure a monotonically increasing result as gst_clock_adjust_unlocked() does.Note: The this Clock parameter is unused and can be NULL
- Parameters:
internalTarget- a clock timecinternal- a reference internal timecexternal- a reference external timecnum- the numerator of the rate of the clock relative to its internal timecdenom- the denominator of the rate of the clock- Returns:
- the converted time of the clock.
- Since:
- 1.6
-
getCalibration
public void getCalibration(@Nullable ClockTime internal, @Nullable ClockTime external, @Nullable ClockTime rateNum, @Nullable ClockTime rateDenom) Gets the internal rate and reference time ofclock.See gst_clock_set_calibration() for more information.internal,external,rateNum,andrateDenomcan be leftnullif the caller is not interested in the values.- Parameters:
internal- a location to store the internal timeexternal- a location to store the external timerateNum- a location to store the rate numeratorrateDenom- a location to store the rate denominator
-
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_CLOCK_TIME_NONEwhen given invalid input.
-
getMaster
Gets the master clock that this Clock is slaved to ornullwhen the clock is not slaved to any master clock.- Returns:
- a master
GstClockornullwhen this clock is not slaved to a master clock.
-
getResolution
Gets the accuracy of the clock. The accuracy of the clock is the granularity of the values returned by gst_clock_get_time().- Returns:
- the resolution of the clock in units of
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.- Returns:
- the time of the clock. Or
GST_CLOCK_TIME_NONEwhen given invalid input.
-
getTimeout
Gets the amount of time that master and slave clocks are sampled.- Returns:
- the interval between samples.
-
isSynced
public boolean isSynced()Checks if the clock is currently synced, by looking at whetherClockFlags.NEEDS_STARTUP_SYNCis set.- Returns:
trueif the clock is currently synced- Since:
- 1.6
-
newPeriodicId
Gets an ID from this Clock to trigger a periodic notification. The periodic notifications will start at timestartTimeand will then be fired with the giveninterval.- Parameters:
startTime- the requested start timeinterval- the requested interval- Returns:
- a
GstClockIDthat can be used to request the time notification.
-
newSingleShotId
-
periodicIdReinit
Reinitializes the provided periodicidto the provided start time and interval. Does not modify the reference count.- Parameters:
id- aGstClockIDstartTime- the requested start timeinterval- the requested interval- Returns:
trueif the GstClockID could be reinitialized to the providedtime,elsefalse.
-
setCalibration
public void setCalibration(ClockTime internal, ClockTime external, ClockTime rateNum, ClockTime rateDenom) Adjusts the rate and time ofclock.A rate of 1/1 is the normal speed of the clock. Values bigger than 1/1 make the clock go faster.internalandexternalare calibration parameters that arrange that gst_clock_get_time() should have beenexternalat internal timeinternal.This internal time should not be in the future; that is, it should be less than the value of gst_clock_get_internal_time() when this function is called.Subsequent calls to gst_clock_get_time() will return clock times computed as follows:
time = (internal_time - internal) * rate_num / rate_denom + externalThis formula is implemented in gst_clock_adjust_unlocked(). Of course, it tries to do the integer arithmetic as precisely as possible.
Note that gst_clock_get_time() always returns increasing values so when you move the clock backwards, gst_clock_get_time() will report the previous value until the clock catches up.
- Parameters:
internal- a reference internal timeexternal- a reference external timerateNum- the numerator of the rate of the clock relative to its internal timerateDenom- the denominator of the rate of the clock
-
setMaster
Setsmasteras the master clock forclock.this Clock will be automatically calibrated so that gst_clock_get_time() reports the same time as the master clock.A clock provider that slaves its clock to a master can get the current calibration values with gst_clock_get_calibration().
mastercan benullin which case this Clock will not be slaved anymore. It will however keep reporting its time adjusted with the last configured rate and time offsets.- Parameters:
master- a masterGstClock- Returns:
trueif the clock is capable of being slaved to a master clock. Trying to set a master on a clock without theGST_CLOCK_FLAG_CAN_SET_MASTERflag will make this function returnfalse.
-
setResolution
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 of a clock. The resolution of a clock can only be changed if the clock has theGST_CLOCK_FLAG_CAN_SET_RESOLUTIONflag set.- Parameters:
resolution- The resolution to set- Returns:
- the new resolution of the clock.
-
setSynced
public void setSynced(boolean synced) Sets this Clock to synced and emits theGstClock::synced signal, and wakes up any thread waiting in gst_clock_wait_for_sync().This function must only be called if
ClockFlags.NEEDS_STARTUP_SYNCis set on the clock, and is intended to be called by subclasses only.- Parameters:
synced- if the clock is synced- Since:
- 1.6
-
setTimeout
Sets the amount of time, in nanoseconds, to sample master and slave clocks- Parameters:
timeout- a timeout
-
singleShotIdReinit
Reinitializes the provided single shotidto the provided time. Does not modify the reference count.- Parameters:
id- aGstClockIDtime- The requested time.- Returns:
trueif the GstClockID could be reinitialized to the providedtime,elsefalse.
-
unadjustUnlocked
Converts the givenexternalclock time to the internal time ofclock,using the rate and reference time set with gst_clock_set_calibration(). This function should be called with the clock's OBJECT_LOCK held and is mainly used by clock subclasses.This function is the reverse of gst_clock_adjust_unlocked().
- Parameters:
external- an external clock time- Returns:
- the internal time of the clock corresponding to
external.
-
unadjustWithCalibration
public ClockTime unadjustWithCalibration(ClockTime externalTarget, ClockTime cinternal, ClockTime cexternal, ClockTime cnum, ClockTime cdenom) Converts the givenexternalTargetclock time to the internal time, using the passed calibration parameters. This function performs the same calculation as gst_clock_unadjust_unlocked() when called using the current calibration parameters.Note: The this Clock parameter is unused and can be NULL
- Parameters:
externalTarget- a clock timecinternal- a reference internal timecexternal- a reference external timecnum- the numerator of the rate of the clock relative to its internal timecdenom- the denominator of the rate of the clock- Returns:
- the converted time of the clock.
- Since:
- 1.8
-
waitForSync
Waits until this Clock is synced for reporting the current time. IftimeoutisGST_CLOCK_TIME_NONEit will wait forever, otherwise it will time out aftertimeoutnanoseconds.For asynchronous waiting, the
GstClock::synced signal can be used.This returns immediately with
trueifClockFlags.NEEDS_STARTUP_SYNCis not set on the clock, or if the clock is already synced.- Parameters:
timeout- timeout for waiting orGST_CLOCK_TIME_NONE- Returns:
trueif waiting was successful, orfalseon timeout- Since:
- 1.6
-
changeResolution
-
unschedule
Unblock a blocking or async wait operation.- Parameters:
entry- the entry to unschedule
-
wait_
Perform a blocking wait on the givenGstClockEntryand return the jitter.- Parameters:
entry- the entry to wait onjitter- a pointer that will contain the jitter- Returns:
- the result of the blocking wait.
GST_CLOCK_EARLYwill be returned if the current clock time is past the time ofid,GST_CLOCK_OKifidwas scheduled in time.GST_CLOCK_UNSCHEDULEDifidwas unscheduled with gst_clock_id_unschedule().
-
waitAsync
Perform an asynchronous wait on the givenGstClockEntry.- Parameters:
entry- the entry to wait on- Returns:
- the result of the non blocking wait.
-
onSynced
Signaled on clocks withClockFlags.NEEDS_STARTUP_SYNCset once the clock is synchronized, or when it completely lost synchronization. This signal will not be emitted on clocks without the flag.This signal will be emitted from an arbitrary thread, most likely not the application's main thread.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 1.6
- See Also:
-
emitSynced
public void emitSynced(boolean synced) Emits the "synced" signal. SeeonSynced(org.freedesktop.gstreamer.gst.Clock.SyncedCallback).
-