From b3331d47718b06ca69d606cbce251d0f16e8c3df Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Tue, 6 Jul 2004 11:21:34 +0000 Subject: [PATCH] clean up clock lifecycle. fixes #109831 Original commit message from CVS: clean up clock lifecycle. fixes #109831 --- ChangeLog | 7 +++++++ gst/gstobject.c | 6 ++++-- gst/gstscheduler.c | 28 +++++++++++++++++++--------- gst/gstsystemclock.c | 12 +++++++++++- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0e1cdbca89..62217400fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-07-06 Thomas Vander Stichele + + * gst/gstobject.c: (gst_object_replace): + * gst/gstscheduler.c: (gst_scheduler_get_clock): + * gst/gstsystemclock.c: (gst_system_clock_obtain): + clean up clock lifecycle. Fixes #109831 + 2004-07-06 Thomas Vander Stichele * po/LINGUAS: diff --git a/gst/gstobject.c b/gst/gstobject.c index f8ab6216b4..27477e1587 100644 --- a/gst/gstobject.c +++ b/gst/gstobject.c @@ -286,9 +286,11 @@ gst_object_replace (GstObject ** oldobj, GstObject * newobj) g_return_if_fail (*oldobj == NULL || GST_IS_OBJECT (*oldobj)); g_return_if_fail (newobj == NULL || GST_IS_OBJECT (newobj)); - GST_CAT_LOG (GST_CAT_REFCOUNTING, "replace %s %s", + GST_CAT_LOG (GST_CAT_REFCOUNTING, "replace %s (%d) with %s (%d)", *oldobj ? GST_STR_NULL (GST_OBJECT_NAME (*oldobj)) : "(NONE)", - newobj ? GST_STR_NULL (GST_OBJECT_NAME (newobj)) : "(NONE)"); + *oldobj ? G_OBJECT (*oldobj)->ref_count : 0, + newobj ? GST_STR_NULL (GST_OBJECT_NAME (newobj)) : "(NONE)", + newobj ? G_OBJECT (newobj)->ref_count : 0); if (*oldobj != newobj) { if (newobj) diff --git a/gst/gstscheduler.c b/gst/gstscheduler.c index 0e2aeb423b..f86a5e3265 100644 --- a/gst/gstscheduler.c +++ b/gst/gstscheduler.c @@ -510,7 +510,7 @@ gst_scheduler_interrupt (GstScheduler * sched, GstElement * element) * gst_scheduler_get_clock: * @sched: the scheduler * - * Get the current clock used by the scheduler + * Gets the current clock used by the scheduler. * * Returns: a GstClock */ @@ -523,8 +523,8 @@ gst_scheduler_get_clock (GstScheduler * sched) if (GST_FLAG_IS_SET (sched, GST_SCHEDULER_FLAG_FIXED_CLOCK)) { clock = sched->clock; - GST_CAT_DEBUG (GST_CAT_CLOCK, "scheduler using fixed clock %p (%s)", clock, - (clock ? GST_OBJECT_NAME (clock) : "nil")); + GST_CAT_DEBUG (GST_CAT_CLOCK, "scheduler using fixed clock %p (%s)", + clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-"); } else { GList *schedulers = sched->schedulers; GList *providers = sched->clock_providers; @@ -534,24 +534,34 @@ gst_scheduler_get_clock (GstScheduler * sched) GstScheduler *scheduler = GST_SCHEDULER (schedulers->data); clock = gst_scheduler_get_clock (scheduler); - if (clock) + if (clock) { + GST_CAT_DEBUG (GST_CAT_CLOCK, + "scheduler found managed sched clock %p (%s)", + clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-"); break; + } schedulers = g_list_next (schedulers); } /* still no clock, try to find one in the providers */ while (!clock && providers) { clock = gst_element_get_clock (GST_ELEMENT (providers->data)); - + if (clock) + GST_CAT_DEBUG (GST_CAT_CLOCK, "scheduler found provider clock: %p (%s)", + clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-"); providers = g_list_next (providers); } /* still no clock, use a system clock */ if (!clock && sched->parent_sched == NULL) { clock = gst_system_clock_obtain (); + /* we unref since this function is not supposed to increase refcount + * of clock object returned; this is ok since the systemclock always + * has a refcount of at least one in the current code. */ + gst_object_unref (GST_OBJECT (clock)); + GST_CAT_DEBUG (GST_CAT_CLOCK, "scheduler obtained system clock: %p (%s)", + clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-"); } } - GST_CAT_LOG_OBJECT (GST_CAT_CLOCK, sched, "scheduler selected clock %p (%s)", - clock, clock ? GST_STR_NULL (GST_OBJECT_NAME (clock)) : "-"); return clock; } @@ -584,8 +594,8 @@ gst_scheduler_use_clock (GstScheduler * sched, GstClock * clock) * @sched: the scheduler * @clock: the clock to set * - * Set the clock for the scheduler. The clock will be distributed - * to all the elements managed by the scheduler. + * Set the clock for the scheduler. The clock will be distributed + * to all the elements managed by the scheduler. */ void gst_scheduler_set_clock (GstScheduler * sched, GstClock * clock) diff --git a/gst/gstsystemclock.c b/gst/gstsystemclock.c index e5dba1a881..83a0eeb706 100644 --- a/gst/gstsystemclock.c +++ b/gst/gstsystemclock.c @@ -119,7 +119,7 @@ gst_system_clock_dispose (GObject * object) } /** - * gst_system_clock_obtain + * gst_system_clock_obtain * * Get a handle to the default system clock. * @@ -135,21 +135,31 @@ gst_system_clock_obtain (void) if (_the_system_clock != NULL) { clock = _the_system_clock; g_static_mutex_unlock (&_gst_sysclock_mutex); + GST_CAT_DEBUG (GST_CAT_CLOCK, "returning static system clock"); goto have_clock; } + GST_CAT_DEBUG (GST_CAT_CLOCK, "creating new static system clock"); + /* FIXME: the only way to clean this up is to have a gst_exit() + * function; until then, the program will always end with the sysclock + * at refcount 1 */ clock = GST_CLOCK (g_object_new (GST_TYPE_SYSTEM_CLOCK, NULL)); gst_object_set_name (GST_OBJECT (clock), "GstSystemClock"); + /* we created the global clock; take ownership so + * we can hand out instances later */ gst_object_ref (GST_OBJECT (clock)); gst_object_sink (GST_OBJECT (clock)); _the_system_clock = clock; g_static_mutex_unlock (&_gst_sysclock_mutex); + } else { + GST_CAT_DEBUG (GST_CAT_CLOCK, "returning static system clock"); } have_clock: + /* we ref it since we are a clock factory. */ gst_object_ref (GST_OBJECT (clock)); return clock; }