From 5c8527bb20787ba68759b44d196896c5fb370ab4 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sat, 28 Nov 2009 12:25:06 +0100 Subject: [PATCH] check: fix jitterbuffer check Make sure we set a base_time on the element. Fix the timeout to at least twice the jitterbuffer latency. Enable previously failing tests. Remove impossible checks. --- tests/check/elements/rtpjitterbuffer.c | 79 +++++++++++--------------- 1 file changed, 32 insertions(+), 47 deletions(-) diff --git a/tests/check/elements/rtpjitterbuffer.c b/tests/check/elements/rtpjitterbuffer.c index b79a5e3338..a8eaa61ec6 100644 --- a/tests/check/elements/rtpjitterbuffer.c +++ b/tests/check/elements/rtpjitterbuffer.c @@ -127,6 +127,23 @@ setup_jitterbuffer (gint num_buffers) return jitterbuffer; } +static GstStateChangeReturn +start_jitterbuffer (GstElement * jitterbuffer) +{ + GstStateChangeReturn ret; + GstClockTime now; + GstClock *clock; + + clock = gst_element_get_clock (jitterbuffer); + now = gst_clock_get_time (clock); + gst_object_unref (clock); + + gst_element_set_base_time (jitterbuffer, now); + ret = gst_element_set_state (jitterbuffer, GST_STATE_PLAYING); + + return ret; +} + static void cleanup_jitterbuffer (GstElement * jitterbuffer) { @@ -153,13 +170,12 @@ check_jitterbuffer_results (GstElement * jitterbuffer, gint num_buffers) GList *node; GstClockTime ts = G_GUINT64_CONSTANT (0); GstClockTime tso = gst_util_uint64_scale (RTP_FRAME_SIZE, GST_SECOND, 8000); - guint test_duration = GST_TIME_AS_USECONDS (num_buffers * tso); guint8 *data; guint16 prev_sn = 0, cur_sn; guint32 prev_ts = 0, cur_ts; - /* sleep for twice the duration of the tested buffers */ - g_usleep (2 * test_duration); + /* sleep for twice the latency */ + g_usleep (400 * 1000); GST_INFO ("of %d buffer %d/%d received/dropped", num_buffers, g_list_length (buffers), num_dropped); @@ -195,9 +211,8 @@ GST_START_TEST (test_push_forward_seq) GList *node; jitterbuffer = setup_jitterbuffer (num_buffers); - fail_unless (gst_element_set_state (jitterbuffer, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); + fail_unless (start_jitterbuffer (jitterbuffer) + == GST_STATE_CHANGE_SUCCESS, "could not set to playing"); /* push buffers: 0,1,2, */ for (node = inbuffers; node; node = g_list_next (node)) { @@ -222,9 +237,8 @@ GST_START_TEST (test_push_backward_seq) GList *node; jitterbuffer = setup_jitterbuffer (num_buffers); - fail_unless (gst_element_set_state (jitterbuffer, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); + fail_unless (start_jitterbuffer (jitterbuffer) + == GST_STATE_CHANGE_SUCCESS, "could not set to playing"); /* push buffers: 0,3,2,1 */ buffer = (GstBuffer *) inbuffers->data; @@ -251,9 +265,8 @@ GST_START_TEST (test_push_unordered) GstBuffer *buffer; jitterbuffer = setup_jitterbuffer (num_buffers); - fail_unless (gst_element_set_state (jitterbuffer, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); + fail_unless (start_jitterbuffer (jitterbuffer) + == GST_STATE_CHANGE_SUCCESS, "could not set to playing"); /* push buffers; 0,2,1,3 */ buffer = (GstBuffer *) inbuffers->data; @@ -281,12 +294,10 @@ GST_START_TEST (test_basetime) GstBuffer *buffer; GList *node; GstClockTime tso = gst_util_uint64_scale (RTP_FRAME_SIZE, GST_SECOND, 8000); - guint test_duration = GST_TIME_AS_USECONDS (num_buffers * tso); jitterbuffer = setup_jitterbuffer (num_buffers); - fail_unless (gst_element_set_state (jitterbuffer, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); + fail_unless (start_jitterbuffer (jitterbuffer) + == GST_STATE_CHANGE_SUCCESS, "could not set to playing"); /* push buffers: 2,1,0 */ for (node = g_list_last (inbuffers); node; node = g_list_previous (node)) { @@ -294,15 +305,12 @@ GST_START_TEST (test_basetime) fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); } - /* sleep for twice the duration of the tested buffers */ - g_usleep (2 * test_duration); + /* sleep for twice the latency */ + g_usleep (400 * 1000); /* if this fails, not all buffers have been processed */ fail_unless_equals_int ((g_list_length (buffers) + num_dropped), num_buffers); - /* check the buffer list */ - fail_unless_equals_int (g_list_length (buffers), 1); - buffer = (GstBuffer *) buffers->data; fail_unless (GST_BUFFER_TIMESTAMP (buffer) != (num_buffers * tso)); @@ -321,32 +329,9 @@ rtpjitterbuffer_suite (void) suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_push_forward_seq); - if (0) { - /* this one does not work yet (bug in test or jitter buffer?), sometimes I get - elements/rtpjitterbuffer.c:168:F:general:test_push_backward_seq:0: 'g_list_length (buffers)' (1) is not equal to 'num_buffers' (3) - 0:00:00.113317818 761 0x9a74008 WARN rtpjitterbuffer rtpjitterbuffer.c:249:calculate_skew: backward timestamps at server, taking new base time - 0:00:00.113547177 761 0x9a74008 WARN rtpjitterbuffer rtpjitterbuffer.c:249:calculate_skew: backward timestamps at server, taking new base time - and now we actually sent the first one always first to get a basetime set - */ - tcase_add_test (tc_chain, test_push_backward_seq); - } - if (0) { - /* this one does not work yet (bug in test or jitter buffer?), sometimes I get - elements/rtpjitterbuffer.c:168:F:general:test_push_unordered:0: 'g_list_length (buffers)' (2) is not equal to 'num_buffers' (3) - 0:00:00.090439642 1216 0x9096008 WARN gstrtpjitterbuffer gstrtpjitterbuffer.c:1309:gst_rtp_jitter_buffer_chain: Packet #7205 too late as #7206 was already popped, dropping - 0:00:00.090674798 1216 0x9096008 WARN gstrtpjitterbuffer gstrtpjitterbuffer.c:1309:gst_rtp_jitter_buffer_chain: Packet #7204 too late as #7206 was already popped, dropping - */ - tcase_add_test (tc_chain, test_push_unordered); - } - if (0) { - /* this shows that there is a bug in jitterbuffers, as the way this sometimes failes would mean that test_push_backward_seq() should work - https://bugzilla.gnome.org/show_bug.cgi?id=602940 - elements/rtpjitterbuffer.c:303:F:general:test_basetime:0: 'g_list_length (buffers)' (3) is not equal to '1' (1) - 0:00:00.104181601 23943 0x99f1008 WARN rtpjitterbuffer rtpjitterbuffer.c:249:calculate_skew: backward timestamps at server, taking new base time - 0:00:00.104412426 23943 0x99f1008 WARN rtpjitterbuffer rtpjitterbuffer.c:249:calculate_skew: backward timestamps at server, taking new base time - */ - tcase_add_test (tc_chain, test_basetime); - } + tcase_add_test (tc_chain, test_push_backward_seq); + tcase_add_test (tc_chain, test_push_unordered); + tcase_add_test (tc_chain, test_basetime); /* FIXME: test buffer lists */