gi-gst-1.0.20: GStreamer bindings

CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria (inaki@blueleaf.cc)
Safe HaskellNone
LanguageHaskell2010

GI.Gst.Objects.Clock

Contents

Description

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

The Clock returns a monotonically increasing time with the method clockGetTime. 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 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 clockNewSingleShotId or clockNewPeriodicId.

To perform a blocking wait for the specific time of the GstClockID use the clockIdWait. To receive a callback when the specific time is reached in the clock use clockIdWaitAsync. Both these calls can be interrupted with the clockIdUnschedule 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, clockIdWait 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 clockIdUnref.

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 Clock with the clockSetMaster. 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 clockSetCalibration. 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 clockGetCalibration function.

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

Synopsis

Exported types

newtype Clock Source #

Memory-managed wrapper type.

Constructors

Clock (ManagedPtr Clock) 
Instances
GObject Clock Source # 
Instance details

Defined in GI.Gst.Objects.Clock

Methods

gobjectType :: IO GType

HasParentTypes Clock Source # 
Instance details

Defined in GI.Gst.Objects.Clock

type ParentTypes Clock Source # 
Instance details

Defined in GI.Gst.Objects.Clock

type ParentTypes Clock = Object ': (Object ': ([] :: [Type]))

class (GObject o, IsDescendantOf Clock o) => IsClock o Source #

Type class for types which can be safely cast to Clock, for instance with toClock.

Instances
(GObject o, IsDescendantOf Clock o) => IsClock o Source # 
Instance details

Defined in GI.Gst.Objects.Clock

toClock :: (MonadIO m, IsClock o) => o -> m Clock Source #

Cast to Clock, for types for which this is known to be safe. For general casts, use castTo.

noClock :: Maybe Clock Source #

A convenience alias for Nothing :: Maybe Clock.

Methods

addObservation

clockAddObservation Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock

-> Word64

slave: a time on the slave

-> Word64

master: a time on the master

-> m (Bool, Double)

Returns: True if enough observations were added to run the regression algorithm.

MT safe.

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.

If this functions returns True, rSquared 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.

addObservationUnapplied

clockAddObservationUnapplied Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock

-> Word64

slave: a time on the slave

-> Word64

master: a time on the master

-> m (Bool, Double, Word64, Word64, Word64, Word64) 

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

The caller can then take the results and call clockSetCalibration with the values, or some modified version of them.

Since: 1.6

adjustUnlocked

clockAdjustUnlocked Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock to use

-> Word64

internal: a clock time

-> m Word64

Returns: the converted time of the clock.

Converts the given internal clock time to the external time, adjusting for the rate and reference time set with clockSetCalibration 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 clockUnadjustUnlocked.

adjustWithCalibration

clockAdjustWithCalibration Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock to use

-> Word64

internalTarget: a clock time

-> Word64

cinternal: a reference internal time

-> Word64

cexternal: a reference external time

-> Word64

cnum: the numerator of the rate of the clock relative to its internal time

-> Word64

cdenom: the denominator of the rate of the clock

-> m Word64

Returns: the converted time of the clock.

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

Note: The clock parameter is unused and can be NULL

Since: 1.6

getCalibration

clockGetCalibration Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock

-> m (Word64, Word64, Word64, Word64) 

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

internal, external, rateNum, and rateDenom can be left Nothing if the caller is not interested in the values.

MT safe.

getInternalTime

clockGetInternalTime Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock to query

-> m Word64

Returns: the internal time of the clock. Or GST_CLOCK_TIME_NONE when given invalid input.

MT safe.

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

getMaster

clockGetMaster Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock

-> m (Maybe Clock)

Returns: a master Clock or Nothing when this clock is not slaved to a master clock. Unref after usage.

MT safe.

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

getResolution

clockGetResolution Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock

-> m Word64

Returns: the resolution of the clock in units of GstClockTime.

MT safe.

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

getTime

clockGetTime Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock to query

-> m Word64

Returns: the time of the clock. Or GST_CLOCK_TIME_NONE when given invalid input.

MT safe.

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

getTimeout

clockGetTimeout Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock

-> m Word64

Returns: the interval between samples.

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

idCompareFunc

clockIdCompareFunc Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Ptr ()

id1: A GstClockID

-> Ptr ()

id2: A GstClockID to compare with

-> m Int32

Returns: negative value if a < b; zero if a = b; positive value if a > b

MT safe.

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

idGetClock

clockIdGetClock Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Ptr ()

id: a GstClockID

-> m (Maybe Clock)

Returns: a Clock or Nothing when the underlying clock has been freed. Unref after usage.

MT safe.

This function returns the underlying clock.

Since: 1.16

idGetTime

clockIdGetTime Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Ptr ()

id: The GstClockID to query

-> m Word64

Returns: the time of the given clock id.

MT safe.

Get the time of the clock ID

idRef

clockIdRef Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Ptr ()

id: The GstClockID to ref

-> m (Ptr ())

Returns: The same GstClockID with increased refcount.

MT safe.

Increase the refcount of given id.

idUnref

clockIdUnref Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Ptr ()

id: The GstClockID to unref

-> m () 

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

MT safe.

idUnschedule

clockIdUnschedule Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Ptr ()

id: The id to unschedule

-> m () 

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.

MT safe.

idUsesClock

clockIdUsesClock Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> Ptr ()

id: a GstClockID to check

-> a

clock: a Clock to compare against

-> m Bool

Returns: whether the clock id uses the same underlying Clock clock.

MT safe.

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.

Since: 1.16

idWait

clockIdWait Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Ptr ()

id: The GstClockID to wait on

-> m (ClockReturn, Int64)

Returns: the result of the blocking wait. GST_CLOCK_EARLY will be returned if the current clock time is past the time of id, GST_CLOCK_OK if id was scheduled in time. GST_CLOCK_UNSCHEDULED if id was unscheduled with clockIdUnschedule.

MT safe.

Perform a blocking wait on id. id should have been created with clockNewSingleShotId or clockNewPeriodicId and should not have been unscheduled with a call to clockIdUnschedule.

If the jitter argument is not Nothing and this function returns GST_CLOCK_OK or GST_CLOCK_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 return GST_CLOCK_EARLY). Negative values indicate how much time was spent waiting on the clock before this function returned.

idWaitAsync

clockIdWaitAsync Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Ptr ()

id: a GstClockID to wait on

-> ClockCallback

func: The callback function

-> m ClockReturn

Returns: the result of the non blocking wait.

MT safe.

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.

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.

isSynced

clockIsSynced Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a GstClock

-> m Bool

Returns: True if the clock is currently synced

Checks if the clock is currently synced.

This returns if GST_CLOCK_FLAG_NEEDS_STARTUP_SYNC is not set on the clock.

Since: 1.6

newPeriodicId

clockNewPeriodicId Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: The GstClockID to get a periodic notification id from

-> Word64

startTime: the requested start time

-> Word64

interval: the requested interval

-> m (Ptr ())

Returns: a GstClockID that can be used to request the time notification.

MT safe.

Get an ID from clock to trigger a periodic notification. The periodic notifications will start at time startTime and will then be fired with the given interval. id should be unreffed after usage.

Free-function: gst_clock_id_unref

newSingleShotId

clockNewSingleShotId Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: The GstClockID to get a single shot notification from

-> Word64

time: the requested time

-> m (Ptr ())

Returns: a GstClockID that can be used to request the time notification.

MT safe.

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

Free-function: gst_clock_id_unref

periodicIdReinit

clockPeriodicIdReinit Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock

-> Ptr ()

id: a GstClockID

-> Word64

startTime: the requested start time

-> Word64

interval: the requested interval

-> m Bool

Returns: True if the GstClockID could be reinitialized to the provided time, else False.

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

setCalibration

clockSetCalibration Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock to calibrate

-> Word64

internal: a reference internal time

-> Word64

external: a reference external time

-> Word64

rateNum: the numerator of the rate of the clock relative to its internal time

-> Word64

rateDenom: the denominator of the rate of the clock

-> m () 

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.

internal and external are calibration parameters that arrange that clockGetTime 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 clockGetInternalTime when this function is called.

Subsequent calls to clockGetTime will return clock times computed as follows:

 time = (internal_time - internal) * rate_num / rate_denom + external

This formula is implemented in clockAdjustUnlocked. Of course, it tries to do the integer arithmetic as precisely as possible.

Note that clockGetTime always returns increasing values so when you move the clock backwards, clockGetTime will report the previous value until the clock catches up.

MT safe.

setMaster

clockSetMaster Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a, IsClock b) 
=> a

clock: a Clock

-> Maybe b

master: a master Clock

-> m Bool

Returns: True if the clock is capable of being slaved to a master clock. Trying to set a master on a clock without the GST_CLOCK_FLAG_CAN_SET_MASTER flag will make this function return False.

MT safe.

Set master as the master clock for clock. clock will be automatically calibrated so that clockGetTime 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 clockGetCalibration.

master can be Nothing 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.

setResolution

clockSetResolution Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock

-> Word64

resolution: The resolution to set

-> m Word64

Returns: the new resolution of the clock.

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

clockSetSynced Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a GstClock

-> Bool

synced: if the clock is synced

-> m () 

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

This function must only be called if GST_CLOCK_FLAG_NEEDS_STARTUP_SYNC is set on the clock, and is intended to be called by subclasses only.

Since: 1.6

setTimeout

clockSetTimeout Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock

-> Word64

timeout: a timeout

-> m () 

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

singleShotIdReinit

clockSingleShotIdReinit Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock

-> Ptr ()

id: a GstClockID

-> Word64

time: The requested time.

-> m Bool

Returns: True if the GstClockID could be reinitialized to the provided time, else False.

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

unadjustUnlocked

clockUnadjustUnlocked Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock to use

-> Word64

external: an external clock time

-> m Word64

Returns: the internal time of the clock corresponding to external.

Converts the given external clock time to the internal time of clock, using the rate and reference time set with clockSetCalibration. 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 clockAdjustUnlocked.

unadjustWithCalibration

clockUnadjustWithCalibration Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a Clock to use

-> Word64

externalTarget: a clock time

-> Word64

cinternal: a reference internal time

-> Word64

cexternal: a reference external time

-> Word64

cnum: the numerator of the rate of the clock relative to its internal time

-> Word64

cdenom: the denominator of the rate of the clock

-> m Word64

Returns: the converted time of the clock.

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

Note: The clock parameter is unused and can be NULL

Since: 1.8

waitForSync

clockWaitForSync Source #

Arguments

:: (HasCallStack, MonadIO m, IsClock a) 
=> a

clock: a GstClock

-> Word64

timeout: timeout for waiting or CLOCK_TIME_NONE

-> m Bool

Returns: True if waiting was successful, or False on timeout

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

For asynchronous waiting, the GstClock::synced signal can be used.

This returns immediately with TRUE if GST_CLOCK_FLAG_NEEDS_STARTUP_SYNC is not set on the clock, or if the clock is already synced.

Since: 1.6

Properties

timeout

No description available in the introspection data.

constructClockTimeout :: IsClock o => Word64 -> IO (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “timeout” property. This is rarely needed directly, but it is used by new.

getClockTimeout :: (MonadIO m, IsClock o) => o -> m Word64 Source #

Get the value of the “timeout” property. When overloading is enabled, this is equivalent to

get clock #timeout

setClockTimeout :: (MonadIO m, IsClock o) => o -> Word64 -> m () Source #

Set the value of the “timeout” property. When overloading is enabled, this is equivalent to

set clock [ #timeout := value ]

windowSize

No description available in the introspection data.

constructClockWindowSize :: IsClock o => Int32 -> IO (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “window-size” property. This is rarely needed directly, but it is used by new.

getClockWindowSize :: (MonadIO m, IsClock o) => o -> m Int32 Source #

Get the value of the “window-size” property. When overloading is enabled, this is equivalent to

get clock #windowSize

setClockWindowSize :: (MonadIO m, IsClock o) => o -> Int32 -> m () Source #

Set the value of the “window-size” property. When overloading is enabled, this is equivalent to

set clock [ #windowSize := value ]

windowThreshold

No description available in the introspection data.

constructClockWindowThreshold :: IsClock o => Int32 -> IO (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “window-threshold” property. This is rarely needed directly, but it is used by new.

getClockWindowThreshold :: (MonadIO m, IsClock o) => o -> m Int32 Source #

Get the value of the “window-threshold” property. When overloading is enabled, this is equivalent to

get clock #windowThreshold

setClockWindowThreshold :: (MonadIO m, IsClock o) => o -> Int32 -> m () Source #

Set the value of the “window-threshold” property. When overloading is enabled, this is equivalent to

set clock [ #windowThreshold := value ]

Signals

synced

type C_ClockSyncedCallback = Ptr () -> CInt -> Ptr () -> IO () Source #

Type for the callback on the (unwrapped) C side.

type ClockSyncedCallback Source #

Arguments

 = Bool

synced: if the clock is synced now

-> IO () 

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.

This signal will be emitted from an arbitrary thread, most likely not the application's main thread.

Since: 1.6

afterClockSynced :: (IsClock a, MonadIO m) => a -> ClockSyncedCallback -> m SignalHandlerId Source #

Connect a signal handler for the “synced” signal, to be run after the default handler. When overloading is enabled, this is equivalent to

after clock #synced callback

genClosure_ClockSynced :: MonadIO m => ClockSyncedCallback -> m (GClosure C_ClockSyncedCallback) Source #

Wrap the callback into a GClosure.

mk_ClockSyncedCallback :: C_ClockSyncedCallback -> IO (FunPtr C_ClockSyncedCallback) Source #

Generate a function pointer callable from C code, from a C_ClockSyncedCallback.

onClockSynced :: (IsClock a, MonadIO m) => a -> ClockSyncedCallback -> m SignalHandlerId Source #

Connect a signal handler for the “synced” signal, to be run before the default handler. When overloading is enabled, this is equivalent to

on clock #synced callback