gst_test_clock_wait_for_multiple_pending_ids
gst_test_clock_id_list_get_latest_time
gst_test_clock_process_id_list
+gst_test_clock_crank
<SUBSECTION Standard>
GST_TEST_CLOCK
GST_IS_TEST_CLOCK
gst_harness_use_systemclock \
gst_harness_use_testclock \
gst_harness_wait_for_clock_id_waits \
+ gst_test_clock_advance_time \
+ gst_test_clock_crank \
+ gst_test_clock_get_next_entry_time \
gst_test_clock_get_type \
+ gst_test_clock_has_id \
+ gst_test_clock_id_list_get_latest_time \
gst_test_clock_new \
gst_test_clock_new_with_start_time \
- gst_test_clock_set_time \
- gst_test_clock_advance_time \
gst_test_clock_peek_id_count \
- gst_test_clock_has_id \
gst_test_clock_peek_next_pending_id \
- gst_test_clock_wait_for_next_pending_id \
- gst_test_clock_wait_for_pending_id_count \
+ gst_test_clock_process_id_list \
gst_test_clock_process_next_clock_id \
- gst_test_clock_get_next_entry_time \
+ gst_test_clock_set_time \
gst_test_clock_wait_for_multiple_pending_ids \
- gst_test_clock_process_id_list \
- gst_test_clock_id_list_get_latest_time
+ gst_test_clock_wait_for_next_pending_id \
+ gst_test_clock_wait_for_pending_id_count
# For backwards compatibility with GStreamer < 1.5
LIBGSTCHECK_EXPORTED_COMPAT_FUNCS = \
gboolean
gst_harness_crank_single_clock_wait (GstHarness * h)
{
- GstTestClock *testclock = h->priv->testclock;
- GstClockID res, pending;
- gboolean ret = FALSE;
-
- gst_test_clock_wait_for_next_pending_id (testclock, &pending);
- gst_test_clock_set_time (testclock, gst_clock_id_get_time (pending));
- res = gst_test_clock_process_next_clock_id (testclock);
- if (res == pending) {
- GST_DEBUG ("cranked time %" GST_TIME_FORMAT,
- GST_TIME_ARGS (gst_clock_get_time (GST_CLOCK (testclock))));
- ret = TRUE;
- } else {
- GST_WARNING ("testclock next id != pending (%p != %p)", res, pending);
- }
-
- if (G_LIKELY (res != NULL))
- gst_clock_id_unref (res);
- gst_clock_id_unref (pending);
-
- return ret;
+ return gst_test_clock_crank (h->priv->testclock);
}
/**
return result;
}
+
+/**
+ * gst_test_clock_crank:
+ * @test_clock: #GstTestClock to crank
+ *
+ * A "crank" consists of three steps:
+ * 1: Wait for a #GstClockID to be registered with the #GstTestClock.
+ * 2: Advance the #GstTestClock to the time the #GstClockID is waiting for.
+ * 3: Release the #GstClockID wait.
+ * A "crank" can be though of as the notion of
+ * manually driving the clock forward to its next logical step.
+ *
+ * Return: %TRUE if the crank was successful, %FALSE otherwise.
+ *
+ * MT safe.
+ *
+ * Since: 1.8
+ */
+gboolean
+gst_test_clock_crank (GstTestClock * test_clock)
+{
+ GstClockID res, pending;
+ gboolean result;
+
+ gst_test_clock_wait_for_next_pending_id (test_clock, &pending);
+ gst_test_clock_set_time (test_clock, gst_clock_id_get_time (pending));
+ res = gst_test_clock_process_next_clock_id (test_clock);
+ if (G_LIKELY (res == pending)) {
+ GST_CAT_DEBUG_OBJECT (GST_CAT_TEST_CLOCK, test_clock,
+ "cranked to time %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (gst_clock_get_time (GST_CLOCK (test_clock))));
+ result = TRUE;
+ } else {
+ GST_CAT_WARNING_OBJECT (GST_CAT_TEST_CLOCK, test_clock,
+ "testclock next id != pending (%p != %p)", res, pending);
+ result = FALSE;
+ }
+
+ if (G_LIKELY (res != NULL))
+ gst_clock_id_unref (res);
+
+ gst_clock_id_unref (pending);
+
+ return result;
+}
GstClockTime gst_test_clock_id_list_get_latest_time (const GList * pending_list);
+gboolean gst_test_clock_crank (GstTestClock * test_clock);
+
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstTestClock, gst_object_unref)
#endif
GST_END_TEST;
+GST_START_TEST (test_crank)
+{
+ GstClock *clock;
+ GstTestClock *test_clock;
+ GstClockID clock_id;
+ SyncClockWaitContext context;
+ GThread *worker_thread;
+
+ clock = gst_test_clock_new_with_start_time (GST_SECOND);
+ test_clock = GST_TEST_CLOCK (clock);
+
+ /* register a wait for 5 seconds */
+ clock_id = gst_clock_new_single_shot_id (clock, 5 * GST_SECOND);
+ context.clock_id = gst_clock_id_ref (clock_id);
+ context.jitter = 0;
+ worker_thread =
+ g_thread_new ("worker_thread_a",
+ test_wait_pending_single_shot_id_sync_worker, &context);
+
+ /* crank */
+ gst_test_clock_crank (test_clock);
+
+ /* the clock should have advanced and the wait released */
+ g_thread_join (worker_thread);
+
+ /* 4 seconds was spent waiting for the clock */
+ fail_unless_equals_int64 (-4 * GST_SECOND, context.jitter);
+
+ /* and the clock is now at 5 seconds */
+ fail_unless_equals_int64 (5 * GST_SECOND, gst_clock_get_time (clock));
+
+ gst_clock_id_unref (context.clock_id);
+ gst_clock_id_unref (clock_id);
+ gst_object_unref (clock);
+}
+
+GST_END_TEST;
+
static Suite *
gst_test_clock_suite (void)
{
tcase_add_test (tc_chain, test_periodic_sync);
tcase_add_test (tc_chain, test_periodic_async);
tcase_add_test (tc_chain, test_periodic_uniqueness);
+ tcase_add_test (tc_chain, test_crank);
return s;
}