gstreamermm: Gst::Clock Class Reference

gstreamermm 0.10.11

- Main Page
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Related Functions
Gst::Clock Class Reference

An abstract class for global clocks. More...

Inheritance diagram for Gst::Clock:
[legend]
Collaboration diagram for Gst::Clock:
[legend]

List of all members.

## Public Member Functions
virtual | ~Clock ()
GstClock* | gobj ()
| Provides access to the underlying C GObject.
const GstClock* | gobj () const
| Provides access to the underlying C GObject.
GstClock* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
bool | add_observation (ClockTime slave_time, ClockTime master_time, gdouble* result)
| The time master of the master clock and the time slave of the slave clock are added to the list of observations.
bool | set_master (const Clock& master_clock)
| Set master as the master clock for clock.
Glib::RefPtr< Gst::Clock > | get_master ()
| Get the master clock that clock is slaved to or `0` when the clock is not slaved to any master clock.
Glib::RefPtr< const Gst::Clock > | get_master () const
| Get the master clock that clock is slaved to or `0` when the clock is not slaved to any master clock.
ClockTime | set_resolution (ClockTime resolution)
| Set the accuracy of the clock.
ClockTime | get_resolution () const
| Get the accuracy of the clock.
ClockTime | get_time () const
| Gets the current time of the given clock.
Glib::RefPtr< Gst::ClockID > | create_single_shot_id (ClockTime time)
| Get a Gst::ClockID from clock to trigger a single shot notification at the requested time.
Glib::RefPtr< Gst::ClockID > | create_periodic_id (ClockTime start_time, ClockTime intervals)
| Get an ID from clock to trigger a periodic notification.
ClockTime | get_internal_time () const
| Gets the current internal time of the given clock.
ClockTime | adjust_unlocked (ClockTime internal_time)
| Converts the given internal clock time to the external time, adjusting for the rate and reference time set with set_calibration() and making sure that the returned time is increasing.
ClockTime | unadjust_unlocked (ClockTime external_time)
| Converts the given external clock time to the internal time of clock, using the rate and reference time set with set_calibration().
void | get_calibration (ClockTime&internal, ClockTime& external, ClockTime& rate_num, ClockTime& rate_denom) const
| Gets the internal rate and reference time of clock.
void | set_calibration (ClockTime internal, ClockTime external, ClockTime rate_num, ClockTime rate_denom)
| Adjusts the rate and time of clock.
Glib::PropertyProxy< bool > | property_stats ()
| Enable clock stats (unimplemented).
Glib::PropertyProxy_ReadOnly < bool > | property_stats () const
| Enable clock stats (unimplemented).
Glib::PropertyProxy< guint64 > | property_timeout ()
| The amount of time, in nanoseconds, to sample master and slave clocks.
Glib::PropertyProxy_ReadOnly < guint64 > | property_timeout () const
| The amount of time, in nanoseconds, to sample master and slave clocks.
Glib::PropertyProxy< int > | property_window_size ()
| The size of the window used to calculate rate and offset.
Glib::PropertyProxy_ReadOnly< int > | property_window_size () const
| The size of the window used to calculate rate and offset.
Glib::PropertyProxy< int > | property_window_threshold ()
| The threshold to start calculating rate and offset.
Glib::PropertyProxy_ReadOnly< int > | property_window_threshold () const
| The threshold to start calculating rate and offset.
virtual ClockTime | change_resolution_vfunc (ClockTime old_resolution, ClockTime new_resolution)
| Change the resolution of the clock.
virtual ClockTime | get_resolution_vfunc () const
| Get the resolution of the clock.
virtual ClockTime | get_internal_time_vfunc () const
| Get the internal unadjusted time of the clock.
virtual ClockReturn | wait_vfunc (const Glib::RefPtr< Gst::ClockID >& id)
| Perform a blocking wait for the given Gst::ClockID.
virtual ClockReturn | wait_async_vfunc (const Glib::RefPtr< Gst::ClockID >& id)
| Perform an asynchronous wait for the given Gst::ClockID.
virtual void | unschedule_vfunc (const Glib::RefPtr< Gst::ClockID >& id)
| Unblock a blocking or async wait operation.
virtual ClockReturn | wait_jitter_vfunc (const Glib::RefPtr< Gst::ClockID >& id, ClockTimeDiff& jitter)
| Perform a blocking wait on the given Gst::ClockID and return the jitter.
## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system.
## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gst::Clock > | wrap (GstClock* object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Detailed Description

An abstract class for global clocks.

GStreamer uses a global clock to synchronize the plugins in a pipeline. Different clock implementations are possible by implementing this abstract base class.

The Gst::Clock returns a monotonically increasing time with the method 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 Gst::Pipeline.

A clock implementation can support periodic and single shot clock notifications both synchronous and asynchronous.

One first needs to create a Gst::ClockID for the periodic or single shot notification using create_single_shot_id() or create_periodic_id().

To perform a blocking wait for the specific time of the Gst::ClockID use the Gst::ClockID::wait() method. To receive a callback when the specific time is reached in the clock use Gst::ClockID::wait_async(). Both these calls can be interrupted with the Gst::ClockID::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 a sync periodic callback, Gst::ClockID::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 Gst::ClockID that has been unscheduled cannot be used again for any wait operation, a new Gst::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 slot will only be called for the thread registering the entry last.

None of the wait operations unref the Gst::ClockID, 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 Gst::ClockID has to keep a handle to the Gst::ClockID 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. (The RefPtr takes care of unreffing in this case)

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.

When a clock has the Gst::CLOCK_FLAG_CAN_SET_MASTER flag set, it can be slaved to another Gst::Clock with the set_master() method. The clock will then automatically be synchronized to this master clock by repeadedly sampling the master clock and the slave clock and recalibrating the slave clock with set_calibration(). This feature is mostly useful for plugins that have an internal clock but must operate with another clock selected by the Gst::Pipeline. They can track the offset and rate difference of their internal clock relative to the master clock by using the get_calibration() method.

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.

Last reviewed on 2006-08-11 (0.10.10)

## Constructor & Destructor Documentation

virtual Gst::Clock::~Clock | ( |  | ) | `[virtual]`

## Member Function Documentation

bool Gst::Clock::add_observation | ( | ClockTime | slave_time,
|  | ClockTime | master_time,
|  | gdouble * | result
| ) |  |

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`, 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.

Parameters:

  slave | A time on the slave.
  master | A time on the master.
  r_squared | A pointer to hold the result.

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

MT safe.

ClockTime Gst::Clock::adjust_unlocked | ( | ClockTime | internal_time | ) |

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

Parameters:

  internal | A clock time.

Returns:
  The converted time of the clock.

virtual ClockTime Gst::Clock::change_resolution_vfunc | ( | ClockTime | old_resolution,
|  | ClockTime | new_resolution
| ) |  | `[virtual]`

Change the resolution of the clock.

Not all values might be acceptable. The new resolution should be returned.

Glib::RefPtr<Gst::ClockID> Gst::Clock::create_periodic_id | ( | ClockTime | start_time,
|  | ClockTime | intervals
| ) |  |

Get an ID from clock to trigger a periodic notification.

The periodic notifications will start at time start_time and will then be fired with the given interval. id should be unreffed after usage.

Free-function: gst_clock_id_unref

Parameters:

  start_time | The requested start time.
  interval | The requested interval.

Returns:
  A Gst::ClockID that can be used to request the time notification.

MT safe.

Glib::RefPtr<Gst::ClockID> Gst::Clock::create_single_shot_id | ( | ClockTime | time | ) |

Get a Gst::ClockID 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

Parameters:

  time | The requested time.

Returns:
  A Gst::ClockID that can be used to request the time notification.

MT safe.

void Gst::Clock::get_calibration | ( | ClockTime& | internal,
|  | ClockTime& | external,
|  | ClockTime& | rate_num,
|  | ClockTime& | rate_denom
| ) |  | const

Gets the internal rate and reference time of clock.

See set_calibration() for more information.

internal, external, rate_num, and rate_denom can be left `0` if the caller is not interested in the values.

MT safe.

Parameters:

  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.

ClockTime Gst::Clock::get_internal_time | ( |  | ) | const

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_NONE when given invalid input.

MT safe.

virtual ClockTime Gst::Clock::get_internal_time_vfunc | ( |  | ) | const`[virtual]`

Get the internal unadjusted time of the clock.

Glib::RefPtr<Gst::Clock> Gst::Clock::get_master | ( |  | ) |

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

Returns:
  A master Gst::Clock or `0` when this clock is not slaved to a master clock. Unref after usage.

MT safe.

Glib::RefPtr<const Gst::Clock> Gst::Clock::get_master | ( |  | ) | const

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

Returns:
  A master Gst::Clock or `0` when this clock is not slaved to a master clock. Unref after usage.

MT safe.

ClockTime Gst::Clock::get_resolution | ( |  | ) | const

Get the accuracy of the clock.

The accuracy of the clock is the granularity of the values returned by get_time().

Returns:
  The resolution of the clock in units of Gst::ClockTime.

MT safe.

virtual ClockTime Gst::Clock::get_resolution_vfunc | ( |  | ) | const`[virtual]`

Get the resolution of the clock.

ClockTime Gst::Clock::get_time | ( |  | ) | const

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_NONE when given invalid input.

MT safe.

static GType Gst::Clock::get_type | ( |  | ) | `[static]`

Get the GType for this class, for use with the underlying GObject type system.

Reimplemented from Gst::Object.

Reimplemented in Gst::SystemClock, and Gst::AudioClock.

GstClock* Gst::Clock::gobj | ( |  | ) | `[inline]`

Provides access to the underlying C GObject.

Reimplemented from Gst::Object.

Reimplemented in Gst::SystemClock, and Gst::AudioClock.

const GstClock* Gst::Clock::gobj | ( |  | ) | const`[inline]`

Provides access to the underlying C GObject.

Reimplemented from Gst::Object.

Reimplemented in Gst::SystemClock, and Gst::AudioClock.

GstClock* Gst::Clock::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

Reimplemented from Gst::Object.

Reimplemented in Gst::SystemClock, and Gst::AudioClock.

Glib::PropertyProxy< bool > Gst::Clock::property_stats | ( |  | ) |

Enable clock stats (unimplemented).

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly< bool > Gst::Clock::property_stats | ( |  | ) | const

Enable clock stats (unimplemented).

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy< guint64 > Gst::Clock::property_timeout | ( |  | ) |

The amount of time, in nanoseconds, to sample master and slave clocks.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly< guint64 > Gst::Clock::property_timeout | ( |  | ) | const

The amount of time, in nanoseconds, to sample master and slave clocks.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy< int > Gst::Clock::property_window_size | ( |  | ) |

The size of the window used to calculate rate and offset.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly< int > Gst::Clock::property_window_size | ( |  | ) | const

The size of the window used to calculate rate and offset.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy< int > Gst::Clock::property_window_threshold | ( |  | ) |

The threshold to start calculating rate and offset.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

Glib::PropertyProxy_ReadOnly< int > Gst::Clock::property_window_threshold | ( |  | ) | const

The threshold to start calculating rate and offset.

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

void Gst::Clock::set_calibration | ( | ClockTime | internal,
|  | ClockTime | external,
|  | ClockTime | rate_num,
|  | ClockTime | rate_denom
| ) |  |

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 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 of get_internal_time() when this function is called.

Subsequent calls to get_time() will return clock times computed as follows:

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

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

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.

Parameters:

  internal | A reference internal time.
  external | A reference external time.
  rate_num | The numerator of the rate of the clock relative to its internal time.
  rate_denom | The denominator of the rate of the clock.

bool Gst::Clock::set_master | ( | const Clock& | master_clock | ) |

Set master as the master clock for clock.

clock will be automatically calibrated so that 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 get_calibration().

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

Parameters:

  master | A master Gst::Clock.

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.

ClockTime Gst::Clock::set_resolution | ( | ClockTime | resolution | ) |

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.

Parameters:

  resolution | The resolution to set.

Returns:
  The new resolution of the clock.

ClockTime Gst::Clock::unadjust_unlocked | ( | ClockTime | external_time | ) |

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

Parameters:

  external | An external clock time.

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

virtual void Gst::Clock::unschedule_vfunc | ( | const Glib::RefPtr< Gst::ClockID >& | id | ) | `[virtual]`

Unblock a blocking or async wait operation.

virtual ClockReturn Gst::Clock::wait_async_vfunc | ( | const Glib::RefPtr< Gst::ClockID >& | id | ) | `[virtual]`

Perform an asynchronous wait for the given Gst::ClockID.

virtual ClockReturn Gst::Clock::wait_jitter_vfunc | ( | const Glib::RefPtr< Gst::ClockID >& | id,
|  | ClockTimeDiff& | jitter
| ) |  | `[virtual]`

Perform a blocking wait on the given Gst::ClockID and return the jitter.

(Since: 0.10.10)

virtual ClockReturn Gst::Clock::wait_vfunc | ( | const Glib::RefPtr< Gst::ClockID >& | id | ) | `[virtual]`

Perform a blocking wait for the given Gst::ClockID.

Deprecated, implement wait_jitter_vfunc() instead.

## Friends And Related Function Documentation

Glib::RefPtr< Gst::Clock > wrap | ( | GstClock * | object,
|  | bool | take_copy = `false`
| ) |  | `[related]`

A Glib::wrap() method for this object.

Parameters:

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns:
  A C++ instance that wraps this C instance.

The documentation for this class was generated from the following file:

- gstreamermm/clock.h