public class Clock extends GstObject
GStreamer uses a global clock to synchronize the plugins in a pipeline. Different clock implementations are possible by implementing this abstract base class.
The Clock
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 stream time. Usually all renderers synchronize to the global clock using the buffer timestamps, the newsegment 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 ClockID
for the periodic or single shot
notification using newSingleShotID(org.gstreamer.ClockTime)
or newPeriodicID(org.gstreamer.ClockTime, org.gstreamer.ClockTime)
.
To perform a blocking wait for the specific time of the ClockID
use the
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 it is 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 ClockID
that has been unscheduled cannot be used again for any wait
operation, a new ClockID should be created.
It is possible to perform a blocking wait on the same ClockID from multiple threads. However, registering the same ClockID for multiple async notifications is not possible, the callback will only be called for the thread registering the entry last.
These clock operations do not operate on the stream time, so the callbacks
will also occur when not in State.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 State.PLAYING
.
When a clock has the GST_CLOCK_FLAG_CAN_SET_MASTER flag set, it can be
slaved to another #GstClock with the 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 setCalibration(org.gstreamer.ClockTime, org.gstreamer.ClockTime, org.gstreamer.ClockTime, org.gstreamer.ClockTime)
. This feature is mostly useful for
plugins that have an internal clock but must operate with another clock
selected by the Pipeline
. 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 "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.
GObject.GCallback, GObject.NOTIFY
NativeObject.Initializer
Modifier and Type | Field and Description |
---|---|
static String |
GTYPE_NAME |
defaultInit, ownsHandle
Constructor and Description |
---|
Clock(NativeObject.Initializer init) |
Modifier and Type | Method and Description |
---|---|
void |
getCalibration(ClockTime internal,
ClockTime external,
ClockTime rateNumerator,
ClockTime rateDenominator)
Gets the internal rate and reference time of clock.
|
ClockTime |
getInternalTime()
Gets the current internal time of this clock.
|
Clock |
getMaster()
Gets the master clock that this clock is slaved to or null when the clock is
not slaved to any master clock.
|
ClockTime |
getResolution()
Gets the accuracy of the clock.
|
ClockTime |
getTime()
Gets the current time of the given clock.
|
ClockID |
newPeriodicID(ClockTime startTime,
ClockTime interval)
Gets an ID from this clock to trigger a periodic notification.
|
ClockID |
newSingleShotID(ClockTime time)
Gets a
ClockID from this clock to trigger a single shot
notification at the requested time. |
void |
setCalibration(ClockTime internal,
ClockTime external,
ClockTime rateNumerator,
ClockTime rateDenominator)
Adjusts the rate and time of this clock.
|
boolean |
setMaster(Clock master)
Set master as the master clock for this clock.
|
ClockTime |
setResolution(ClockTime resolution)
Sets the accuracy of the clock.
|
addListenerProxy, getName, getParent, initializer, initializer, ref, removeListenerProxy, setName, steal, toString, unref
addCallback, connect, connect, connect, connect, disconnect, disconnect, disconnect, disposeNativeHandle, emit, emit, g_signal_connect, get, getPointer, getPropertyDefaultValue, getPropertyMaximumValue, getPropertyMinimumValue, getType, getType, getTypeName, invalidate, listPropertyNames, removeCallback, set
classFor, disown, dispose, equals, finalize, getNativeAddress, handle, hashCode, initializer, instanceFor, isDisposed, nativeValue, objectFor, objectFor, objectFor, objectFor
public static final String GTYPE_NAME
public Clock(NativeObject.Initializer init)
public ClockTime setResolution(ClockTime resolution)
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.
resolution
- the new resolution of the clock.public ClockTime getResolution()
getTime()
.public ClockTime getTime()
ClockTime.NONE
when
given incorrect input.public ClockTime getInternalTime()
ClockTime.NONE
when given wrong input.public Clock getMaster()
public boolean setMaster(Clock master)
getTime()
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 getCalibration(org.gstreamer.ClockTime, org.gstreamer.ClockTime, org.gstreamer.ClockTime, org.gstreamer.ClockTime)
.
master can be null in which case clock will not be slaved anymore. It will
however keep reporting its time adjusted with the last configured rate
and time offsets.master
- a master Clockpublic void getCalibration(ClockTime internal, ClockTime external, ClockTime rateNumerator, ClockTime rateDenominator)
setCalibration(org.gstreamer.ClockTime, org.gstreamer.ClockTime, org.gstreamer.ClockTime, org.gstreamer.ClockTime)
for more information.
internal, external, rate_num, and rate_denom can be left NULL if the caller is not interested in the values. Thread safe.
internal
- a reference internal timeexternal
- a reference external timerateNumerator
- the numerator of the rate of the clock relative to its internal timerateDenominator
- the denominator of the rate of the clockpublic void setCalibration(ClockTime internal, ClockTime external, ClockTime rateNumerator, ClockTime rateDenominator)
internal and external are calibration parameters that arrange that
getTime()
should have been external at internal time internal.
This internal time should not be in the future; that is, it should be less
than the value of getInternalTime()
when this function is called.
Subsequent calls to gst_clock_get_time() will return clock times computed as follows:
time = (internal_time - internal) * rateNumerator/ rateDenominator + external
This formula is implemented in gst_clock_adjust_unlocked(). Of course, it tries to do the integer arithmetic as precisely as possible.
Note that getTime()
always returns increasing values so when you
move the clock backwards, getTime() will report the previous value
until the clock catches up.
Thread safe.
internal
- a reference internal timeexternal
- a reference external timerateNumerator
- the numerator of the rate of the clock relative to its internal timerateDenominator
- the denominator of the rate of the clockpublic ClockID newSingleShotID(ClockTime time)
ClockID
from this clock to trigger a single shot
notification at the requested time.
Thread safe.
time
- The requested timeClockID
that can be used to request the time notification.public ClockID newPeriodicID(ClockTime startTime, ClockTime interval)
Thread safe.
startTime
- The requested start time.interval
- The requested interval.ClockID
that can be used to request the time notification.Copyright © 2016. All rights reserved.