2005-11-21 Wim Taymans <wim@fluendo.com>
+ * gst/gstclock.c: (gst_clock_init), (gst_clock_set_master),
+ (gst_clock_get_master):
+ * gst/gstclock.h:
+ * gst/gstsystemclock.c: (gst_system_clock_init):
+ Convert Clock flags to object flags.
+ Added methods to manage master/slave clocks.
+
+2005-11-21 Wim Taymans <wim@fluendo.com>
+
* check/gst/gstsegment.c: (GST_START_TEST):
* docs/design/part-TODO.txt:
* gst/base/gstbasesink.c: (gst_base_sink_handle_object),
clock->last_time = 0;
clock->entries = NULL;
clock->entries_changed = g_cond_new ();
- clock->flags = 0;
clock->stats = FALSE;
clock->internal_calibration = 0;
GST_OBJECT_UNLOCK (clock);
}
+/**
+ * gst_clock_set_master
+ * @clock: a #GstClock
+ * @master: a master #GstClock
+ *
+ * Set @master as the master clock for @clock. @clock 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().
+ *
+ * MT safe.
+ */
+void
+gst_clock_set_master (GstClock * clock, GstClock * master)
+{
+ GST_OBJECT_LOCK (clock);
+ gst_object_replace ((GstObject **) & clock->master, (GstObject *) master);
+ GST_OBJECT_UNLOCK (clock);
+}
+
+/**
+ * gst_clock_get_master
+ * @clock: a #GstClock
+ *
+ * Get the master clock that @clock is slaved to or NULL when the clock is
+ * not slaved to any master clock.
+ *
+ * Returns: a master #GstClock or NULL when this clock is not slaved to a master
+ * clock. Unref after usage.
+ *
+ * MT safe.
+ */
+GstClock *
+gst_clock_get_master (GstClock * clock)
+{
+ GstClock *result = NULL;
+
+ GST_OBJECT_LOCK (clock);
+ if (clock->master)
+ result = gst_object_ref (clock->master);
+ GST_OBJECT_UNLOCK (clock);
+
+ return result;
+}
+
static void
gst_clock_update_stats (GstClock * clock)
{
* @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
+ * @GST_CLOCK_FLAG_LAST: subclasses can add additional flags starting from this flag
*
* The capabilities of this clock
*/
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),
+ GST_CLOCK_FLAG_CAN_DO_SINGLE_SYNC = (GST_OBJECT_FLAG_LAST << 0),
+ GST_CLOCK_FLAG_CAN_DO_SINGLE_ASYNC = (GST_OBJECT_FLAG_LAST << 1),
+ GST_CLOCK_FLAG_CAN_DO_PERIODIC_SYNC = (GST_OBJECT_FLAG_LAST << 2),
+ GST_CLOCK_FLAG_CAN_DO_PERIODIC_ASYNC = (GST_OBJECT_FLAG_LAST << 3),
+ GST_CLOCK_FLAG_CAN_SET_RESOLUTION = (GST_OBJECT_FLAG_LAST << 4),
+ /* padding */
+ GST_CLOCK_FLAG_LAST = (GST_OBJECT_FLAG_LAST << 8),
} GstClockFlags;
/**
struct _GstClock {
GstObject object;
- /*< public >*/
- GstClockFlags flags;
-
/*< protected >*/ /* with LOCK */
GstClockTime internal_calibration;
GstClockTime external_calibration;
GstClockTime resolution;
gboolean stats;
+ GstClock *master;
+
GstClockTime _gst_reserved[GST_PADDING];
};
GstClockTime external, gdouble rate);
void gst_clock_get_calibration (GstClock *clock, GstClockTime *internal,
GstClockTime *external, gdouble *rate);
+/* master/slave clocks */
+void gst_clock_set_master (GstClock *clock, GstClock *master);
+GstClock* gst_clock_get_master (GstClock *clock);
GstClockTime gst_clock_get_internal_time (GstClock *clock);
GstClockTime gst_clock_adjust_unlocked (GstClock *clock, GstClockTime internal);
{
GError *error = NULL;
- GST_CLOCK_FLAGS (clock) =
+ GST_OBJECT_FLAG_SET (clock,
GST_CLOCK_FLAG_CAN_DO_SINGLE_SYNC |
GST_CLOCK_FLAG_CAN_DO_SINGLE_ASYNC |
GST_CLOCK_FLAG_CAN_DO_PERIODIC_SYNC |
- GST_CLOCK_FLAG_CAN_DO_PERIODIC_ASYNC;
+ GST_CLOCK_FLAG_CAN_DO_PERIODIC_ASYNC);
GST_OBJECT_LOCK (clock);
clock->thread = g_thread_create ((GThreadFunc) gst_system_clock_async_thread,