Gst.Clock¶
- Subclasses:
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
|
|
|
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w |
The amount of time, in nanoseconds, to sample master and slave clocks |
||
r/w |
The size of the window used to calculate rate and offset |
||
r/w |
The threshold to start calculating rate and offset |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Signaled on clocks with |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
object |
r |
the parent structure |
Class Details¶
- class Gst.Clock(**kwargs)¶
- Bases:
- Abstract:
Yes
- Structure:
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 methodGst.Clock.get_time
(). Its accuracy and base time depend on the specific clock implementation but time is always expressed in nanoseconds.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.EventType.SEGMENT
events and the element’s base time, seeGst.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
Gst.Clock.new_single_shot_id
() orGst.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 useGst.Clock.id_wait_async
(). Both these calls can be interrupted with theGst.Clock.id_unschedule
() call. If the blocking wait is unscheduled a return value ofGst.ClockReturn.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.ClockFlags.CAN_SET_MASTER
flag set, it can be slaved to anotherGst.Clock
withGst.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 withGst.Clock.set_calibration
(). This feature is mostly useful for plugins that have an internal clock but must operate with another clock selected by theGst.Pipeline
. They can track the offset and rate difference of their internal clock relative to the master clock by using theGst.Clock.get_calibration
() function.The master/slave synchronisation can be tuned with the
Gst.Clock
:timeout
,Gst.Clock
:window-size
andGst.Clock
:window-threshold
properties. TheGst.Clock
:timeout
property defines the interval to sample the master clock and run the calibration functions.Gst.Clock
:window-size
defines the number of samples to use when calibrating andGst.Clock
:window-threshold
defines the minimum number of samples before the calibration is performed.New in version the.
- classmethod id_compare_func(id1, id2)[source]¶
- Parameters:
- Returns:
negative value if
a < b
; zero ifa = b
; positive value ifa > b
- Return type:
Compares the two #GstClockID instances. This function can be used as a
GLib.CompareFunc
when sorting ids.
- classmethod id_get_clock(id)[source]¶
- Parameters:
id (
object
) – a #GstClockID- Returns:
a
Gst.Clock
orNone
when the underlying clock has been freed.- Return type:
This function returns the underlying clock.
New in version 1.16.
- classmethod id_get_time(id)[source]¶
- Parameters:
id (
object
) – The #GstClockID to query- Returns:
the time of the given clock id.
- Return type:
Gets the time of the clock ID
- classmethod id_ref(id)[source]¶
- Parameters:
id (
object
) – The #GstClockID to ref- Returns:
The same #GstClockID with increased refcount.
- Return type:
Increases the refcount of given id.
- classmethod id_unref(id)[source]¶
- Parameters:
id (
object
) – The #GstClockID to unref
Unrefs given id. When the refcount reaches 0 the #GstClockID will be freed.
- classmethod id_unschedule(id)[source]¶
- Parameters:
id (
object
) – The id to unschedule
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 notifications, you need to create a new #GstClockID.
- classmethod id_uses_clock(id, clock)[source]¶
- Parameters:
- Returns:
whether the clock id uses the same underlying
Gst.Clock
clock.- Return type:
This function returns whether id uses clock as the underlying clock. clock can be
None
, 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.New in version 1.16.
- classmethod id_wait(id)[source]¶
- Parameters:
id (
object
) – The #GstClockID to wait on- Returns:
the result of the blocking wait.
Gst.ClockReturn.EARLY
will be returned if the current clock time is past the time of id,Gst.ClockReturn.OK
if id was scheduled in time.Gst.ClockReturn.UNSCHEDULED
if id was unscheduled withGst.Clock.id_unschedule
().- jitter:
a pointer that will contain the jitter, can be
None
.
- Return type:
(
Gst.ClockReturn
, jitter:int
)
Performs a blocking wait on id. id should have been created with
Gst.Clock.new_single_shot_id
() orGst.Clock.new_periodic_id
() and should not have been unscheduled with a call toGst.Clock.id_unschedule
().If the jitter argument is not
None
and this function returnsGst.ClockReturn.OK
orGst.ClockReturn.EARLY
, it will contain the difference against the clock and the time of id when this method was called. Positive values indicate how late id was relative to the clock (in which case this function will returnGst.ClockReturn.EARLY
). Negative values indicate how much time was spent waiting on the clock before this function returned.
- classmethod id_wait_async(id, func, *user_data)[source]¶
- Parameters:
id (
object
) – a #GstClockID to wait onfunc (
Gst.ClockCallback
) – The callback functionuser_data (
object
orNone
) – User data passed in the callback
- Returns:
the result of the non blocking wait.
- Return type:
Registers 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.The callback func can be invoked from any thread, either provided by the core or from a streaming thread. The application should be prepared for this.
- add_observation(slave, master)[source]¶
- Parameters:
- Returns:
True
if enough observations were added to run the regression algorithm.- r_squared:
a pointer to hold the result
- Return type:
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 self is recalibrated.
If this functions returns
True
, r_squared will 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.
- add_observation_unapplied(slave, master)[source]¶
- Parameters:
- Returns:
True
if enough observations were added to run the regression algorithm.- r_squared:
a pointer to hold the result
- internal:
a location to store the internal time
- external:
a location to store the external time
- rate_num:
a location to store the rate numerator
- rate_denom:
a location to store the rate denominator
- Return type:
(
bool
, r_squared:float
, internal:int
, external:int
, rate_num:int
, rate_denom:int
)
Add a clock observation to the internal slaving algorithm the same as
Gst.Clock.add_observation
(), and return the result of the 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.New in version 1.6.
- adjust_unlocked(internal)[source]¶
- Parameters:
internal (
int
) – a clock time- Returns:
the converted time of the clock.
- Return type:
Converts the given internal clock 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
().
- adjust_with_calibration(internal_target, cinternal, cexternal, cnum, cdenom)[source]¶
- Parameters:
- Returns:
the converted time of the clock.
- Return type:
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.adjust_unlocked
() when called using the current calibration parameters, but doesn’t ensure a monotonically increasing result asGst.Clock.adjust_unlocked
() does.Note: The self parameter is unused and can be
None
New in version 1.6.
- get_calibration()[source]¶
- Returns:
- internal:
a location to store the internal time
- external:
a location to store the external time
- rate_num:
a location to store the rate numerator
- rate_denom:
a location to store the rate denominator
- Return type:
(internal:
int
, external:int
, rate_num:int
, rate_denom:int
)
Gets the internal rate and reference time of self. See
Gst.Clock.set_calibration
() for more information.internal, external, rate_num, and rate_denom can be left
None
if the caller is not interested in the values.
- get_internal_time()[source]¶
- Returns:
the internal time of the clock. Or
Gst.CLOCK_TIME_NONE
when given invalid input.- Return type:
Gets the current internal time of the given clock. The time is returned unadjusted for the offset and the rate.
- get_master()[source]¶
-
Gets the master clock that self is slaved to or
None
when the clock is not slaved to any master clock.
- get_resolution()[source]¶
- Returns:
the resolution of the clock in units of #GstClockTime.
- Return type:
Gets the accuracy of the clock. The accuracy of the clock is the granularity of the values returned by
Gst.Clock.get_time
().
- get_time()[source]¶
- Returns:
the time of the clock. Or
Gst.CLOCK_TIME_NONE
when given invalid input.- Return type:
Gets the current time of the given clock. The time is always monotonically increasing and adjusted according to the current offset and rate.
- get_timeout()[source]¶
- Returns:
the interval between samples.
- Return type:
Gets the amount of time that master and slave clocks are sampled.
- is_synced()[source]¶
-
Checks if the clock is currently synced, by looking at whether
Gst.ClockFlags.NEEDS_STARTUP_SYNC
is set.New in version 1.6.
- new_periodic_id(start_time, interval)[source]¶
- Parameters:
- Returns:
a #GstClockID that can be used to request the time notification.
- Return type:
Gets an ID from self to trigger a periodic notification. The periodic notifications will start at time start_time and will then be fired with the given interval.
- new_single_shot_id(time)[source]¶
- Parameters:
time (
int
) – the requested time- Returns:
a #GstClockID that can be used to request the time notification.
- Return type:
Gets a #GstClockID from self to trigger a single shot notification at the requested time.
- periodic_id_reinit(id, start_time, interval)[source]¶
- Parameters:
- Returns:
True
if the GstClockID could be reinitialized to the provided time, elseFalse
.- Return type:
Reinitializes the provided periodic id to the provided start time and interval. Does not modify the reference count.
- set_calibration(internal, external, rate_num, rate_denom)[source]¶
- Parameters:
Adjusts the rate and time of self. A rate of 1/1 is the normal speed of the clock. Values bigger than 1/1 make the clock go faster.
internal and external are calibration parameters that arrange that
Gst.Clock.get_time
() 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 ofGst.Clock.get_internal_time
() when this function is called.Subsequent calls to
Gst.Clock.get_time
() will return clock times computed as follows:- `` C
time = (internal_time - internal) * rate_num / rate_denom + 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
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.
- set_master(master)[source]¶
- Parameters:
- Returns:
True
if the clock is capable of being slaved to a master clock. Trying to set a master on a clock without theGst.ClockFlags.CAN_SET_MASTER
flag will make this function returnFalse
.- Return type:
Sets master as the master clock for self. self 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
().master can be
None
in which case self will not be slaved anymore. It will however keep reporting its time adjusted with the last configured rate and time offsets.
- set_resolution(resolution)[source]¶
- Parameters:
resolution (
int
) – The resolution to set- Returns:
the new resolution of the clock.
- Return type:
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 the
Gst.ClockFlags.CAN_SET_RESOLUTION
flag set.
- set_synced(synced)[source]¶
- Parameters:
synced (
bool
) – if the clock is synced
Sets self to synced and emits the
Gst.Clock
::synced
signal, and wakes up any thread waiting inGst.Clock.wait_for_sync
().This function must only be called if
Gst.ClockFlags.NEEDS_STARTUP_SYNC
is set on the clock, and is intended to be called by subclasses only.New in version 1.6.
- set_timeout(timeout)[source]¶
- Parameters:
timeout (
int
) – a timeout
Sets the amount of time, in nanoseconds, to sample master and slave clocks
- single_shot_id_reinit(id, time)[source]¶
- Parameters:
- Returns:
True
if the GstClockID could be reinitialized to the provided time, elseFalse
.- Return type:
Reinitializes the provided single shot id to the provided time. Does not modify the reference count.
- unadjust_unlocked(external)[source]¶
- Parameters:
external (
int
) – an external clock time- Returns:
the internal time of the clock corresponding to external.
- Return type:
Converts the given external clock time to the internal time of self, 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
().
- unadjust_with_calibration(external_target, cinternal, cexternal, cnum, cdenom)[source]¶
- Parameters:
- Returns:
the converted time of the clock.
- Return type:
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.unadjust_unlocked
() when called using the current calibration parameters.Note: The self parameter is unused and can be
None
New in version 1.8.
- wait_for_sync(timeout)[source]¶
- Parameters:
timeout (
int
) – timeout for waiting orGst.CLOCK_TIME_NONE
- Returns:
- Return type:
Waits until self 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.For asynchronous waiting, the
Gst.Clock
::synced
signal can be used.This returns immediately with
True
ifGst.ClockFlags.NEEDS_STARTUP_SYNC
is not set on the clock, or if the clock is already synced.New in version 1.6.
- do_change_resolution(old_resolution, new_resolution) virtual¶
- Parameters:
- Returns:
the new resolution
- Return type:
Change the resolution of the clock. Not all values might be acceptable.
- do_get_internal_time() virtual¶
- Returns:
the internal time of the clock. Or
Gst.CLOCK_TIME_NONE
when given invalid input.- Return type:
Gets the current internal time of the given clock. The time is returned unadjusted for the offset and the rate.
- do_get_resolution() virtual¶
- Returns:
the resolution of the clock in units of #GstClockTime.
- Return type:
Gets the accuracy of the clock. The accuracy of the clock is the granularity of the values returned by
Gst.Clock.get_time
().
- do_unschedule(entry) virtual¶
- Parameters:
entry (
Gst.ClockEntry
) – the entry to unschedule
Unblock a blocking or async wait operation.
- do_wait(entry) virtual¶
- Parameters:
entry (
Gst.ClockEntry
) – the entry to wait on- Returns:
the result of the blocking wait.
Gst.ClockReturn.EARLY
will be returned if the current clock time is past the time of id,Gst.ClockReturn.OK
if id was scheduled in time.Gst.ClockReturn.UNSCHEDULED
if id was unscheduled withGst.Clock.id_unschedule
().- jitter:
a pointer that will contain the jitter
- Return type:
(
Gst.ClockReturn
, jitter:int
)
Perform a blocking wait on the given
Gst.ClockEntry
and return the jitter.
- do_wait_async(entry) virtual¶
- Parameters:
entry (
Gst.ClockEntry
) – the entry to wait on- Returns:
the result of the non blocking wait.
- Return type:
Perform an asynchronous wait on the given
Gst.ClockEntry
.
Signal Details¶
- Gst.Clock.signals.synced(clock, synced)¶
- Signal Name:
synced
- Flags:
- Parameters:
Signaled on clocks with
Gst.ClockFlags.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.This signal will be emitted from an arbitrary thread, most likely not the application’s main thread.
New in version 1.6.
Property Details¶
- Gst.Clock.props.timeout¶
-
The amount of time, in nanoseconds, to sample master and slave clocks
- Gst.Clock.props.window_size¶
-
The size of the window used to calculate rate and offset