clean up clock lifecycle. fixes #109831

Original commit message from CVS:
clean up clock lifecycle.  fixes #109831
This commit is contained in:
Thomas Vander Stichele 2004-07-06 11:21:34 +00:00
parent cc70ab5b80
commit b3331d4771
4 changed files with 41 additions and 12 deletions

View file

@ -1,3 +1,10 @@
2004-07-06 Thomas Vander Stichele <thomas at apestaart dot org>
* 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 <thomas at apestaart dot org>
* po/LINGUAS:

View file

@ -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)

View file

@ -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 ();
}
}
GST_CAT_LOG_OBJECT (GST_CAT_CLOCK, sched, "scheduler selected clock %p (%s)",
/* 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)) : "-");
}
}
return clock;
}

View file

@ -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;
}