From e6bbe0ddb2f34503e932e7950be1344832655e84 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 21 Nov 2005 17:12:50 +0000 Subject: [PATCH] gst/: Convert Clock flags to object flags. Original commit message from CVS: * 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. --- ChangeLog | 9 +++++++++ gst/gstclock.c | 48 +++++++++++++++++++++++++++++++++++++++++++- gst/gstclock.h | 21 +++++++++++-------- gst/gstsystemclock.c | 4 ++-- 4 files changed, 71 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index b21421d161..0efc45c7b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-11-21 Wim Taymans + + * 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 * check/gst/gstsegment.c: (GST_START_TEST): diff --git a/gst/gstclock.c b/gst/gstclock.c index 36c7201efe..e83672e7c8 100644 --- a/gst/gstclock.c +++ b/gst/gstclock.c @@ -529,7 +529,6 @@ gst_clock_init (GstClock * clock) clock->last_time = 0; clock->entries = NULL; clock->entries_changed = g_cond_new (); - clock->flags = 0; clock->stats = FALSE; clock->internal_calibration = 0; @@ -767,6 +766,53 @@ gst_clock_get_calibration (GstClock * clock, GstClockTime * internal, 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) { diff --git a/gst/gstclock.h b/gst/gstclock.h index f5f5f70b54..5f975ca169 100644 --- a/gst/gstclock.h +++ b/gst/gstclock.h @@ -308,15 +308,18 @@ struct _GstClockEntry { * @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; /** @@ -369,9 +372,6 @@ typedef enum { struct _GstClock { GstObject object; - /*< public >*/ - GstClockFlags flags; - /*< protected >*/ /* with LOCK */ GstClockTime internal_calibration; GstClockTime external_calibration; @@ -384,6 +384,8 @@ struct _GstClock { GstClockTime resolution; gboolean stats; + GstClock *master; + GstClockTime _gst_reserved[GST_PADDING]; }; @@ -419,6 +421,9 @@ void gst_clock_set_calibration (GstClock *clock, GstClockTime internal, 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); diff --git a/gst/gstsystemclock.c b/gst/gstsystemclock.c index b635d12643..3f2de44ccf 100644 --- a/gst/gstsystemclock.c +++ b/gst/gstsystemclock.c @@ -120,11 +120,11 @@ gst_system_clock_init (GstSystemClock * clock) { 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,