Commit 31a84cf3 authored by Nicolas Dufresne's avatar Nicolas Dufresne

testclock: Allow calling crank with a past entry

At the moment, we can only use crank if the pending entry is in the
future. This patch leaves the clock time to the same point if the
pending entry was in the past. This still execute a single entry. This
will be needed for the jitterbuffer, since as soon as we stop waking up
the jitterbuffer when the timer is reschedule later, we may endup with
such case in the unit tests.

Related to #608
parent c34fe82b
Pipeline #44209 passed with stages
in 36 minutes and 35 seconds
......@@ -1153,7 +1153,8 @@ gst_test_clock_id_list_get_latest_time (const GList * pending_list)
*
* 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.
* 2: Advance the #GstTestClock to the time the #GstClockID is waiting, unless
* the clock time is already passed the clock id (Since 1.18).
* 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.
......@@ -1168,10 +1169,13 @@ gboolean
gst_test_clock_crank (GstTestClock * test_clock)
{
GstClockID res, pending;
GstClockTime now;
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));
now = gst_clock_get_time (GST_CLOCK (test_clock));
if (gst_clock_id_get_time (pending) > now)
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,
......
......@@ -1043,6 +1043,45 @@ GST_START_TEST (test_crank)
GST_END_TEST;
GST_START_TEST (test_late_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 the clock while the pending clock id is in the past */
gst_test_clock_set_time (test_clock, 6 * GST_SECOND);
gst_test_clock_crank (test_clock);
/* the clock should have advanced and the wait released */
g_thread_join (worker_thread);
/* the pending entry was schedule 1 second before waiting */
fail_unless_equals_int64 (1 * GST_SECOND, context.jitter);
/* and the clock is still 5 seconds as configured */
fail_unless_equals_int64 (6 * 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)
{
......@@ -1075,6 +1114,7 @@ gst_test_clock_suite (void)
tcase_add_test (tc_chain, test_periodic_async);
tcase_add_test (tc_chain, test_periodic_uniqueness);
tcase_add_test (tc_chain, test_crank);
tcase_add_test (tc_chain, test_late_crank);
return s;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment