mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-02 08:42:32 +00:00
testclock: add crank method
And use it inside GstHarness API: gst_test_clock_crank() https://bugzilla.gnome.org/show_bug.cgi?id=761906
This commit is contained in:
parent
cc4e4ae029
commit
668b3215b8
6 changed files with 98 additions and 29 deletions
|
@ -1345,6 +1345,7 @@ gst_test_clock_get_next_entry_time
|
||||||
gst_test_clock_wait_for_multiple_pending_ids
|
gst_test_clock_wait_for_multiple_pending_ids
|
||||||
gst_test_clock_id_list_get_latest_time
|
gst_test_clock_id_list_get_latest_time
|
||||||
gst_test_clock_process_id_list
|
gst_test_clock_process_id_list
|
||||||
|
gst_test_clock_crank
|
||||||
<SUBSECTION Standard>
|
<SUBSECTION Standard>
|
||||||
GST_TEST_CLOCK
|
GST_TEST_CLOCK
|
||||||
GST_IS_TEST_CLOCK
|
GST_IS_TEST_CLOCK
|
||||||
|
|
|
@ -171,21 +171,22 @@ LIBGSTCHECK_EXPORTED_FUNCS = \
|
||||||
gst_harness_use_systemclock \
|
gst_harness_use_systemclock \
|
||||||
gst_harness_use_testclock \
|
gst_harness_use_testclock \
|
||||||
gst_harness_wait_for_clock_id_waits \
|
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_get_type \
|
||||||
|
gst_test_clock_has_id \
|
||||||
|
gst_test_clock_id_list_get_latest_time \
|
||||||
gst_test_clock_new \
|
gst_test_clock_new \
|
||||||
gst_test_clock_new_with_start_time \
|
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_peek_id_count \
|
||||||
gst_test_clock_has_id \
|
|
||||||
gst_test_clock_peek_next_pending_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_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
|
# For backwards compatibility with GStreamer < 1.5
|
||||||
LIBGSTCHECK_EXPORTED_COMPAT_FUNCS = \
|
LIBGSTCHECK_EXPORTED_COMPAT_FUNCS = \
|
||||||
|
|
|
@ -1363,26 +1363,7 @@ gst_harness_wait_for_clock_id_waits (GstHarness * h, guint waits, guint timeout)
|
||||||
gboolean
|
gboolean
|
||||||
gst_harness_crank_single_clock_wait (GstHarness * h)
|
gst_harness_crank_single_clock_wait (GstHarness * h)
|
||||||
{
|
{
|
||||||
GstTestClock *testclock = h->priv->testclock;
|
return gst_test_clock_crank (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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1078,3 +1078,48 @@ gst_test_clock_id_list_get_latest_time (const GList * pending_list)
|
||||||
|
|
||||||
return result;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
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
|
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstTestClock, gst_object_unref)
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstTestClock, gst_object_unref)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1002,6 +1002,44 @@ GST_START_TEST (test_periodic_uniqueness)
|
||||||
|
|
||||||
GST_END_TEST;
|
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 *
|
static Suite *
|
||||||
gst_test_clock_suite (void)
|
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_sync);
|
||||||
tcase_add_test (tc_chain, test_periodic_async);
|
tcase_add_test (tc_chain, test_periodic_async);
|
||||||
tcase_add_test (tc_chain, test_periodic_uniqueness);
|
tcase_add_test (tc_chain, test_periodic_uniqueness);
|
||||||
|
tcase_add_test (tc_chain, test_crank);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue