diff --git a/docs/libs/gstreamer-libs-sections.txt b/docs/libs/gstreamer-libs-sections.txt index 36f3141559..48c65fca02 100644 --- a/docs/libs/gstreamer-libs-sections.txt +++ b/docs/libs/gstreamer-libs-sections.txt @@ -1345,6 +1345,7 @@ gst_test_clock_get_next_entry_time 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 GST_TEST_CLOCK GST_IS_TEST_CLOCK diff --git a/libs/gst/check/Makefile.am b/libs/gst/check/Makefile.am index aada08514a..5333963669 100644 --- a/libs/gst/check/Makefile.am +++ b/libs/gst/check/Makefile.am @@ -171,21 +171,22 @@ LIBGSTCHECK_EXPORTED_FUNCS = \ 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_next_clock_id \ - gst_test_clock_get_next_entry_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_process_next_clock_id \ + gst_test_clock_set_time \ + gst_test_clock_wait_for_multiple_pending_ids \ + 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 = \ diff --git a/libs/gst/check/gstharness.c b/libs/gst/check/gstharness.c index ccacd4d0ea..e9b033c5a7 100644 --- a/libs/gst/check/gstharness.c +++ b/libs/gst/check/gstharness.c @@ -1363,26 +1363,7 @@ gst_harness_wait_for_clock_id_waits (GstHarness * h, guint waits, guint timeout) 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); } /** diff --git a/libs/gst/check/gsttestclock.c b/libs/gst/check/gsttestclock.c index 2fb30bc225..c0961e32cc 100644 --- a/libs/gst/check/gsttestclock.c +++ b/libs/gst/check/gsttestclock.c @@ -1078,3 +1078,48 @@ gst_test_clock_id_list_get_latest_time (const GList * pending_list) 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; +} diff --git a/libs/gst/check/gsttestclock.h b/libs/gst/check/gsttestclock.h index cccbae30c2..17505c24af 100644 --- a/libs/gst/check/gsttestclock.h +++ b/libs/gst/check/gsttestclock.h @@ -114,6 +114,8 @@ guint gst_test_clock_process_id_list (GstTestClock * test_clock, 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 diff --git a/tests/check/libs/gsttestclock.c b/tests/check/libs/gsttestclock.c index b9d36b26df..7af1168c1f 100644 --- a/tests/check/libs/gsttestclock.c +++ b/tests/check/libs/gsttestclock.c @@ -1002,6 +1002,44 @@ GST_START_TEST (test_periodic_uniqueness) 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) { @@ -1033,6 +1071,7 @@ 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; }