![]() |
![]() |
![]() |
GStreamer 0.9 Core Reference Manual | ![]() |
---|
GstClockGstClock — Abstract class for global clocks |
#include <gst/gst.h> GstClock; typedef GstClockTime; typedef GstClockTimeDiff; typedef GstClockID; #define GST_CLOCK_TIME_NONE #define GST_CLOCK_TIME_IS_VALID (time) #define GST_SECOND #define GST_MSECOND #define GST_USECOND #define GST_NSECOND #define GST_CLOCK_DIFF (s, e) #define GST_TIMEVAL_TO_TIME (tv) #define GST_TIME_TO_TIMEVAL (t,tv) #define GST_TIMESPEC_TO_TIME (ts) #define GST_TIME_TO_TIMESPEC (t,ts) #define GST_CLOCK_ENTRY_TRACE_NAME GstClockEntry; gboolean (*GstClockCallback) (GstClock *clock, GstClockTime time, GstClockID id, gpointer user_data); enum GstClockEntryType; #define GST_CLOCK_ENTRY (entry) #define GST_CLOCK_ENTRY_CLOCK (entry) #define GST_CLOCK_ENTRY_TYPE (entry) #define GST_CLOCK_ENTRY_TIME (entry) #define GST_CLOCK_ENTRY_INTERVAL (entry) #define GST_CLOCK_ENTRY_STATUS (entry) enum GstClockReturn; enum GstClockFlags; #define GST_CLOCK_FLAGS (clock) #define GST_CLOCK_BROADCAST (clock) #define GST_CLOCK_COND (clock) #define GST_CLOCK_TIMED_WAIT (clock,tv) #define GST_CLOCK_WAIT (clock) guint64 gst_clock_set_resolution (GstClock *clock, guint64 resolution); guint64 gst_clock_get_resolution (GstClock *clock); GstClockTime gst_clock_get_time (GstClock *clock); GstClockID gst_clock_new_single_shot_id (GstClock *clock, GstClockTime time); GstClockID gst_clock_new_periodic_id (GstClock *clock, GstClockTime start_time, GstClockTime interval); GstClockTime gst_clock_adjust_unlocked (GstClock *clock, GstClockTime internal); void gst_clock_set_time_adjust (GstClock *clock, GstClockTime adjust); GstClockTime gst_clock_id_get_time (GstClockID id); GstClockReturn gst_clock_id_wait (GstClockID id, GstClockTimeDiff *jitter); GstClockReturn gst_clock_id_wait_async (GstClockID id, GstClockCallback func, gpointer user_data); void gst_clock_id_unschedule (GstClockID id); gint gst_clock_id_compare_func (gconstpointer id1, gconstpointer id2); GstClockID gst_clock_id_ref (GstClockID id); void gst_clock_id_unref (GstClockID id); #define GST_TYPE_CLOCK_TIME
GStreamer uses a global clock to synchronize the plugins in a pipeline. Different clock implementations are possible by implementing this abstract base class.
The GstClock returns a monotonically increasing time with the method
gst_clock_get_time()
. Its accuracy and base time depends on the specific clock
implementation but time is always expessed in nanoseconds. Since the
baseline of the clock is undefined, the clock time returned is not
meaningfull in itself, what matters are the deltas between two clock
times.
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.
The time of the clock in itself is not very useful for an application.
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 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 repeadedly called automatically until
it is unscheduled. To schedule an async periodic callback, gst_clock_id_wait()
should be called repeadedly.
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.
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 once.
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 we unref it automatically, the handle might be invalid.
These clock operations do not operate on the stream 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.
Last reviewed on 2005-10-28 (0.9.4)
typedef struct { GstClockFlags flags; } GstClock;
GstClock base structure. The values of this structure are protected for subclasses, use the methods to use the GstClock.
GstClockFlags flags ; |
The flags specifying the capabilities of the clock. |
typedef gint64 GstClockTimeDiff;
A datatype to hold a timedifference, measured in nanoseconds.
typedef gpointer GstClockID;
A datatype to hold the handle to an outstanding async clock callback.
#define GST_CLOCK_TIME_NONE ((GstClockTime) -1)
Constant to define an undefined clock time.
#define GST_CLOCK_TIME_IS_VALID(time) ((time) != GST_CLOCK_TIME_NONE)
Tests if a given GstClockTime represents a valid defined time.
time : |
clock time to validate |
#define GST_SECOND (G_USEC_PER_SEC * G_GINT64_CONSTANT (1000))
Constant that defines one GStreamer second.
#define GST_MSECOND (GST_SECOND / G_GINT64_CONSTANT (1000))
Constant that defines one GStreamer millisecond.
#define GST_USECOND (GST_SECOND / G_GINT64_CONSTANT (1000000))
Constant that defines one GStreamer microsecond.
#define GST_NSECOND (GST_SECOND / G_GINT64_CONSTANT (1000000000))
Constant that defines one GStreamer nanosecond
#define GST_CLOCK_DIFF(s, e) (GstClockTimeDiff)((e) - (s))
Calculate a difference between two clock times as a GstClockTimeDiff.
s : |
the first time |
e : |
the second time |
#define GST_TIMEVAL_TO_TIME(tv) ((tv).tv_sec * GST_SECOND + (tv).tv_usec * GST_USECOND)
Convert a GTimeVal to a GstClockTime.
tv : |
the timeval to convert |
#define GST_TIME_TO_TIMEVAL(t,tv)
Note: on 32-bit systems, a timeval has a range of only 2^32 - 1 seconds, which is about 68 years. Expect trouble if you want to schedule stuff in your pipeline for 2038.
Convert a GstClockTime to a GTimeVal
t : |
The GstClockTime to convert |
tv : |
The target timeval |
#define GST_TIMESPEC_TO_TIME(ts) ((ts).tv_sec * GST_SECOND + (ts).tv_nsec * GST_NSECOND)
Convert a struct timespec (see man pselect) to a GstClockTime.
ts : |
the timespec to convert |
#define GST_TIME_TO_TIMESPEC(t,ts)
Convert a GstClockTime to a struct timespec (see man pselect)
t : |
The GstClockTime to convert |
ts : |
The target timespec |
#define GST_CLOCK_ENTRY_TRACE_NAME "GstClockEntry"
The name used for tracing clock entry allocations.
typedef struct { gint refcount; } GstClockEntry;
All pending timeouts or periodic notifies are converted into an entry.
gint refcount ; |
reference counter (read-only) |
gboolean (*GstClockCallback) (GstClock *clock, GstClockTime time, GstClockID id, gpointer user_data);
The function prototype of the callback.
clock : |
The clock that triggered the callback |
time : |
The time it was triggered |
id : |
The GstClockID that expired |
user_data : |
user data passed in the async_wait call |
Returns : | TRUE or FALSE (currently unused)
|
typedef enum { GST_CLOCK_ENTRY_SINGLE, GST_CLOCK_ENTRY_PERIODIC } GstClockEntryType;
The type of the clock entry
GST_CLOCK_ENTRY_SINGLE |
a single shot timeout |
GST_CLOCK_ENTRY_PERIODIC |
a periodic timeout request |
#define GST_CLOCK_ENTRY(entry) ((GstClockEntry *)(entry))
Cast to a clock entry
entry : |
the entry to cast |
#define GST_CLOCK_ENTRY_CLOCK(entry) ((entry)->clock)
Get the owner clock of the entry
entry : |
the entry to query |
#define GST_CLOCK_ENTRY_TYPE(entry) ((entry)->type)
Get the type of the clock entry
entry : |
the entry to query |
#define GST_CLOCK_ENTRY_TIME(entry) ((entry)->time)
Get the requested time of this entry
entry : |
the entry to query |
#define GST_CLOCK_ENTRY_INTERVAL(entry) ((entry)->interval)
Get the interval of this periodic entry
entry : |
the entry to query |
#define GST_CLOCK_ENTRY_STATUS(entry) ((entry)->status)
The status of the entry
entry : |
the entry to query |
typedef enum { GST_CLOCK_OK = 0, GST_CLOCK_EARLY = 1, GST_CLOCK_UNSCHEDULED = 2, GST_CLOCK_BUSY = 3, GST_CLOCK_BADTIME = 4, GST_CLOCK_ERROR = 5, GST_CLOCK_UNSUPPORTED = 6, } GstClockReturn;
The return value of a clock operation.
GST_CLOCK_OK |
The operation succeded. |
GST_CLOCK_EARLY |
The operation was scheduled too late. |
GST_CLOCK_UNSCHEDULED |
The clockID was unscheduled |
GST_CLOCK_BUSY |
The ClockID is busy |
GST_CLOCK_BADTIME |
A bad time was provided to a function. |
GST_CLOCK_ERROR |
An error occured |
GST_CLOCK_UNSUPPORTED |
Operation is not supported |
typedef enum { GST_CLOCK_FLAG_CAN_DO_SINGLE_SYNC = (1 << 1), GST_CLOCK_FLAG_CAN_DO_SINGLE_ASYNC = (1 << 2), GST_CLOCK_FLAG_CAN_DO_PERIODIC_SYNC = (1 << 3), GST_CLOCK_FLAG_CAN_DO_PERIODIC_ASYNC = (1 << 4), GST_CLOCK_FLAG_CAN_SET_RESOLUTION = (1 << 5), } GstClockFlags;
The capabilities of this clock
GST_CLOCK_FLAG_CAN_DO_SINGLE_SYNC |
clock can do a single sync timeout request |
GST_CLOCK_FLAG_CAN_DO_SINGLE_ASYNC |
clock can do a single async timeout request |
GST_CLOCK_FLAG_CAN_DO_PERIODIC_SYNC |
clock can do sync periodic timeout requests |
GST_CLOCK_FLAG_CAN_DO_PERIODIC_ASYNC |
clock can do async periodic timeout callbacks |
GST_CLOCK_FLAG_CAN_SET_RESOLUTION |
clock's resolution can be changed |
#define GST_CLOCK_FLAGS(clock) (GST_CLOCK(clock)->flags)
Gets the GstClockFlags clock flags.
clock : |
the clock to query |
#define GST_CLOCK_BROADCAST(clock) g_cond_broadcast(GST_CLOCK_COND(clock))
Signal that the entries in the clock have changed.
clock : |
the clock to broadcast |
#define GST_CLOCK_COND(clock) (GST_CLOCK_CAST(clock)->entries_changed)
Gets the GCond that gets signaled when the entries of the clock changed.
clock : |
the clock to query |
#define GST_CLOCK_TIMED_WAIT(clock,tv) g_cond_timed_wait(GST_CLOCK_COND(clock),GST_GET_LOCK(clock),tv)
Wait on the clock until the entries changed or the specified timeout occured.
clock : |
the clock to wait on |
tv : |
a GTimeVal to wait. |
#define GST_CLOCK_WAIT(clock) g_cond_wait(GST_CLOCK_COND(clock),GST_GET_LOCK(clock))
Wait on the clock until the entries changed.
clock : |
the clock to wait on |
guint64 gst_clock_set_resolution (GstClock *clock, guint64 resolution);
Set the accuracy of the clock.
clock : |
The clock set the resolution on |
resolution : |
The resolution to set |
Returns : | the new resolution of the clock. |
guint64 gst_clock_get_resolution (GstClock *clock);
Get the accuracy of the clock.
clock : |
The clock get the resolution of |
Returns : | the resolution of the clock in microseconds. MT safe. |
GstClockTime gst_clock_get_time (GstClock *clock);
Gets the current time of the given clock. The time is always monotonically increasing.
clock : |
a GstClock to query |
Returns : | the time of the clock. Or GST_CLOCK_TIME_NONE when giving wrong input. MT safe. |
GstClockID gst_clock_new_single_shot_id (GstClock *clock, GstClockTime time);
Get an ID from the given clock to trigger a single shot notification at the requested time. The single shot id should be unreffed after usage.
clock : |
The clockid to get a single shot notification from |
time : |
the requested time |
Returns : | An id that can be used to request the time notification. MT safe. |
GstClockID gst_clock_new_periodic_id (GstClock *clock, GstClockTime start_time, GstClockTime interval);
Get an ID from the given clock to trigger a periodic notification. The periodeic notifications will be start at time start_time and will then be fired with the given interval. The id should be unreffed after usage.
clock : |
The clockid to get a periodic notification id from |
start_time : |
the requested start time |
interval : |
the requested interval |
Returns : | An id that can be used to request the time notification. MT safe. |
GstClockTime gst_clock_adjust_unlocked (GstClock *clock, GstClockTime internal);
Converts the given internal
clock time to the real time, adjusting
and making sure that the returned time is increasing.
This function should be called with the clock LOCK held and is
mainly used by clock subclasses.
clock : |
a GstClock to use |
internal : |
a clock time |
Returns : | the converted time of the clock. MT safe. |
void gst_clock_set_time_adjust (GstClock *clock, GstClockTime adjust);
Adjusts the current time of the clock with the adjust value.
A positive value moves the clock forwards and a backwards value
moves it backwards. Note that _get_time()
always returns
increasing values so when you move the clock backwards, _get_time()
will report the previous value until the clock catches up.
MT safe.
clock : |
a GstClock to adjust |
adjust : |
the adjust value |
GstClockTime gst_clock_id_get_time (GstClockID id);
Get the time of the clock ID
id : |
The clockid to query |
Returns : | the time of the given clock id. MT safe. |
GstClockReturn gst_clock_id_wait (GstClockID id, GstClockTimeDiff *jitter);
Perform a blocking wait on the given ID. The jitter arg can be NULL.
id : |
The clockid to wait on |
jitter : |
A pointer that will contain the jitter |
Returns : | the result of the blocking wait. MT safe. |
GstClockReturn gst_clock_id_wait_async (GstClockID id, GstClockCallback func, gpointer user_data);
Register a callback on the given clockid with the given function and user_data. When passing an id with an invalid time to this function, the callback will be called immediatly with a time set to GST_CLOCK_TIME_NONE. The callback will be called when the time of the id has been reached.
id : |
a GstClockID to wait on |
func : |
The callback function |
user_data : |
User data passed in the calback |
Returns : | the result of the non blocking wait. MT safe. |
void gst_clock_id_unschedule (GstClockID id);
Cancel an outstanding request with the given ID. This can either
be an outstanding async notification or a pending sync notification.
After this call, the id
cannot be used anymore to receive sync or
async notifications, you need to create a new GstClockID.
MT safe.
id : |
The id to unschedule |
gint gst_clock_id_compare_func (gconstpointer id1, gconstpointer id2);
Compares the two GstClockID instances. This function can be used as a GCompareFunc when sorting ids.
id1 : |
A clockid |
id2 : |
A clockid to compare with |
Returns : | negative value if a < b; zero if a = b; positive value if a > b MT safe. |
GstClockID gst_clock_id_ref (GstClockID id);
Increase the refcount of the given clockid.
id : |
The clockid to ref |
Returns : | The same GstClockID with increased refcount. MT safe. |
void gst_clock_id_unref (GstClockID id);
Unref the given clockid. When the refcount reaches 0 the GstClockID will be freed.
MT safe.
id : |
The clockid to unref |
<< GstChildProxy | gstconfig >> |