/* the one instance of the systemclock */
static GstClock *_the_system_clock = NULL;
+static gboolean _external_default_clock = FALSE;
static void gst_system_clock_dispose (GObject * object);
static void gst_system_clock_set_property (GObject * object, guint prop_id,
}
/**
+ * gst_system_clock_set_default:
+ * @new_clock: a #GstClock
+ *
+ * Sets the default system clock that can be obtained with
+ * gst_system_clock_obtain.
+ *
+ * This is mostly used for testing and debugging purposes when you
+ * want to have control over the time reported by the default system
+ * clock.
+ *
+ * MT safe.
+ */
+void
+gst_system_clock_set_default (GstClock * new_clock)
+{
+ GstClock *clock;
+
+ g_mutex_lock (&_gst_sysclock_mutex);
+ clock = _the_system_clock;
+
+ if (clock != NULL)
+ g_object_unref (clock);
+
+ if (new_clock == NULL) {
+ GST_CAT_DEBUG (GST_CAT_CLOCK, "resetting default system clock");
+ _external_default_clock = FALSE;
+ } else {
+ GST_CAT_DEBUG (GST_CAT_CLOCK, "setting new default system clock to %p",
+ new_clock);
+ _external_default_clock = TRUE;
+ g_object_ref (new_clock);
+ }
+ _the_system_clock = new_clock;
+ g_mutex_unlock (&_gst_sysclock_mutex);
+}
+
+/**
* gst_system_clock_obtain:
*
* Get a handle to the default system clock. The refcount of the
if (clock == NULL) {
GST_CAT_DEBUG (GST_CAT_CLOCK, "creating new static system clock");
+ g_assert (_external_default_clock == FALSE);
clock = g_object_new (GST_TYPE_SYSTEM_CLOCK,
"name", "GstSystemClock", NULL);
return FALSE;
}
+GST_START_TEST (test_set_default)
+{
+ GstClock *clock, *static_clock;
+
+ /* obtain the default system clock, which keeps a static ref and bumps the
+ * refcount before returning */
+ static_clock = gst_system_clock_obtain ();
+ fail_unless (static_clock != NULL, "Could not create default system clock");
+ g_assert_cmpint (GST_OBJECT_REFCOUNT (static_clock), ==, 2);
+
+ /* set a new default clock to a different instance which should replace the
+ * static clock with this one, and unref the static clock */
+ clock = g_object_new (GST_TYPE_SYSTEM_CLOCK, "name", "TestClock", NULL);
+ gst_system_clock_set_default (clock);
+ g_assert_cmpint (GST_OBJECT_REFCOUNT (static_clock), ==, 1);
+ static_clock = gst_system_clock_obtain ();
+ fail_unless (static_clock == clock);
+ g_assert_cmpint (GST_OBJECT_REFCOUNT (clock), ==, 3);
+ g_object_unref (static_clock);
+
+ /* Reset the default clock to the static one */
+ gst_system_clock_set_default (NULL);
+ static_clock = gst_system_clock_obtain ();
+ fail_unless (static_clock != clock);
+ g_assert_cmpint (GST_OBJECT_REFCOUNT (clock), ==, 1);
+ g_assert_cmpint (GST_OBJECT_REFCOUNT (static_clock), ==, 2);
+ g_object_unref (clock);
+ g_object_unref (static_clock);
+}
+
+GST_END_TEST;
+
GST_START_TEST (test_single_shot)
{
GstClock *clock;
tcase_add_test (tc_chain, test_diff);
tcase_add_test (tc_chain, test_mixed);
tcase_add_test (tc_chain, test_async_full);
+ tcase_add_test (tc_chain, test_set_default);
return s;
}