diff options
author | Havard Graff <havard.graff@gmail.com> | 2016-02-18 16:09:29 +0100 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2016-02-19 14:44:02 +0000 |
commit | 69436d5a61f46cea892ef9acb32f51404ccc1ab3 (patch) | |
tree | 9461af33165ada906d096fe571faeb030f9b0280 /tests/check | |
parent | d52765fabbd1b86bf29ab9f4e2d541363d9649a6 (diff) |
tests: rtpjitterbuffer: port testharness to GstHarness and cleanup/improve
Probably found a bug as well, in that there are some timestamps in
there that are looking very wrong. (marked with FIXME)
https://bugzilla.gnome.org/show_bug.cgi?id=762267
Diffstat (limited to 'tests/check')
-rw-r--r-- | tests/check/elements/rtpjitterbuffer.c | 855 |
1 files changed, 276 insertions, 579 deletions
diff --git a/tests/check/elements/rtpjitterbuffer.c b/tests/check/elements/rtpjitterbuffer.c index d68b1a3ad..f3d6a1193 100644 --- a/tests/check/elements/rtpjitterbuffer.c +++ b/tests/check/elements/rtpjitterbuffer.c @@ -458,151 +458,6 @@ get_rtp_seq_num (GstBuffer * buf) return seq; } -static GstFlowReturn -test_sink_pad_chain_cb (GstPad * pad, GstObject * parent, GstBuffer * buffer) -{ - TestData *data = gst_pad_get_element_private (pad); - g_async_queue_push (data->buf_queue, buffer); - return GST_FLOW_OK; -} - -static gboolean -test_sink_pad_event_cb (GstPad * pad, GstObject * parent, GstEvent * event) -{ - TestData *data = gst_pad_get_element_private (pad); - const GstStructure *structure = gst_event_get_structure (event); - - GST_DEBUG ("got event %" GST_PTR_FORMAT, event); - - if (strcmp (gst_structure_get_name (structure), "GstRTPPacketLost") == 0) { - data->lost_event_count++; - GST_DEBUG ("lost event count %d", data->lost_event_count); - } - - g_async_queue_push (data->sink_event_queue, event); - return TRUE; -} - -static gboolean -test_src_pad_event_cb (GstPad * pad, GstObject * parent, GstEvent * event) -{ - TestData *data = gst_pad_get_element_private (pad); - const GstStructure *structure = gst_event_get_structure (event); - - GST_DEBUG ("got event %" GST_PTR_FORMAT, event); - - if (structure - && strcmp (gst_structure_get_name (structure), - "GstRTPRetransmissionRequest") == 0) { - data->rtx_event_count++; - GST_DEBUG ("rtx event count %d", data->rtx_event_count); - } - - g_async_queue_push (data->src_event_queue, event); - return TRUE; -} - -static void -setup_testharness (TestData * data) -{ - GstPad *jb_sink_pad, *jb_src_pad; - GstSegment seg; - GstMiniObject *obj; - GstCaps *caps; - - /* create the testclock */ - data->clock = gst_test_clock_new (); - g_assert (data->clock); - gst_test_clock_set_time (GST_TEST_CLOCK (data->clock), 0); - - /* rig up the jitter buffer */ - data->jitter_buffer = gst_element_factory_make ("rtpjitterbuffer", NULL); - g_assert (data->jitter_buffer); - gst_element_set_clock (data->jitter_buffer, data->clock); - g_object_set (data->jitter_buffer, "do-lost", TRUE, NULL); - g_assert_cmpint (gst_element_set_state (data->jitter_buffer, - GST_STATE_PLAYING), !=, GST_STATE_CHANGE_FAILURE); - - /* set up the buf and event queues */ - data->buf_queue = - g_async_queue_new_full ((GDestroyNotify) gst_mini_object_unref); - data->sink_event_queue = - g_async_queue_new_full ((GDestroyNotify) gst_mini_object_unref); - data->src_event_queue = - g_async_queue_new_full ((GDestroyNotify) gst_mini_object_unref); - - data->lost_event_count = 0; - data->rtx_event_count = 0; - - /* link in the test source-pad */ - data->test_src_pad = gst_pad_new ("src", GST_PAD_SRC); - gst_pad_set_element_private (data->test_src_pad, data); - gst_pad_set_event_function (data->test_src_pad, test_src_pad_event_cb); - jb_sink_pad = gst_element_get_static_pad (data->jitter_buffer, "sink"); - g_assert_cmpint (gst_pad_link (data->test_src_pad, jb_sink_pad), ==, - GST_PAD_LINK_OK); - gst_object_unref (jb_sink_pad); - - /* link in the test sink-pad */ - data->test_sink_pad = gst_pad_new ("sink", GST_PAD_SINK); - gst_pad_set_element_private (data->test_sink_pad, data); - caps = generate_caps (); - gst_pad_set_caps (data->test_sink_pad, caps); - gst_pad_set_chain_function (data->test_sink_pad, test_sink_pad_chain_cb); - gst_pad_set_event_function (data->test_sink_pad, test_sink_pad_event_cb); - jb_src_pad = gst_element_get_static_pad (data->jitter_buffer, "src"); - g_assert_cmpint (gst_pad_link (jb_src_pad, data->test_sink_pad), ==, - GST_PAD_LINK_OK); - gst_object_unref (jb_src_pad); - - g_assert (gst_pad_set_active (data->test_src_pad, TRUE)); - g_assert (gst_pad_set_active (data->test_sink_pad, TRUE)); - - gst_segment_init (&seg, GST_FORMAT_TIME); - - gst_pad_push_event (data->test_src_pad, - gst_event_new_stream_start ("stream0")); - gst_pad_set_caps (data->test_src_pad, caps); - gst_pad_push_event (data->test_src_pad, gst_event_new_segment (&seg)); - gst_caps_unref (caps); - - obj = g_async_queue_pop (data->sink_event_queue); - gst_mini_object_unref (obj); - obj = g_async_queue_pop (data->sink_event_queue); - gst_mini_object_unref (obj); - obj = g_async_queue_pop (data->sink_event_queue); - gst_mini_object_unref (obj); -} - -static void -destroy_testharness (TestData * data) -{ - /* clean up */ - g_assert_cmpint (gst_element_set_state (data->jitter_buffer, GST_STATE_NULL), - ==, GST_STATE_CHANGE_SUCCESS); - gst_object_unref (data->jitter_buffer); - data->jitter_buffer = NULL; - - gst_object_unref (data->test_src_pad); - data->test_src_pad = NULL; - - gst_object_unref (data->test_sink_pad); - data->test_sink_pad = NULL; - - gst_object_unref (data->clock); - data->clock = NULL; - - g_async_queue_unref (data->buf_queue); - data->buf_queue = NULL; - - g_async_queue_unref (data->sink_event_queue); - data->sink_event_queue = NULL; - g_async_queue_unref (data->src_event_queue); - data->src_event_queue = NULL; - - data->lost_event_count = 0; -} - static void verify_lost_event (GstEvent * event, guint32 expected_seqnum, GstClockTime expected_timestamp, GstClockTime expected_duration) @@ -955,670 +810,512 @@ GST_START_TEST (test_all_packets_are_timestamped_zero) GST_END_TEST; -GST_START_TEST (test_rtx_expected_next) +static void +gst_test_clock_set_time_and_process (GstTestClock * testclock, + GstClockTime time) { - TestData data; GstClockID id, tid; - GstBuffer *in_buf, *out_buf; + gst_test_clock_wait_for_next_pending_id (testclock, &id); + gst_test_clock_set_time (testclock, time); + tid = gst_test_clock_process_next_clock_id (testclock); + g_assert (tid == id); + gst_clock_id_unref (tid); + gst_clock_id_unref (id); +} + +GST_START_TEST (test_rtx_expected_next) +{ + GstHarness *h = gst_harness_new ("rtpjitterbuffer"); + GstTestClock *testclock; + GstBuffer *out_buf; GstEvent *out_event; gint jb_latency_ms = 200; + const GstClockTime rtx_retry_timeout = 40 * GST_MSECOND; - setup_testharness (&data); - g_object_set (data.jitter_buffer, "do-retransmission", TRUE, NULL); - g_object_set (data.jitter_buffer, "latency", jb_latency_ms, NULL); - g_object_set (data.jitter_buffer, "rtx-retry-period", 120, NULL); + gst_harness_set_src_caps (h, generate_caps ()); + testclock = gst_harness_get_testclock (h); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 0); + g_object_set (h->element, "do-lost", TRUE, NULL); + g_object_set (h->element, "do-retransmission", TRUE, NULL); + g_object_set (h->element, "latency", jb_latency_ms, NULL); + g_object_set (h->element, "rtx-retry-period", 120, NULL); /* push the first buffer in */ - in_buf = generate_test_buffer (0); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); - - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 20 * GST_MSECOND); + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer (0))); - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_clock_id_unref (id); + gst_harness_set_time (h, 20 * GST_MSECOND); + gst_harness_wait_for_clock_id_waits (h, 1, 60); /* put second buffer, the jitterbuffer should now know that the packet * spacing is 20ms and should ask for retransmission of seqnum 2 in * 20ms+10ms because 2*jitter==0 and 0.5*packet_spacing==10ms */ - in_buf = generate_test_buffer (1); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer (1))); - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 50 * GST_MSECOND); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (tid == id); - gst_clock_id_unref (tid); - gst_clock_id_unref (id); + gst_test_clock_set_time_and_process (testclock, 50 * GST_MSECOND); + + /* drop reconfigure event */ + gst_event_unref (gst_harness_pull_upstream_event (h)); + /* drop GstEventStreamStart & GstEventCaps & GstEventSegment */ + for (int i = 0; i < 3; i++) + gst_event_unref (gst_harness_pull_event (h)); - out_event = g_async_queue_pop (data.src_event_queue); - g_assert (out_event != NULL); - verify_rtx_event (out_event, 2, 40 * GST_MSECOND, 10, PCMU_BUF_DURATION); + out_event = gst_harness_pull_upstream_event (h); + verify_rtx_event (out_event, 2, rtx_retry_timeout, 10, PCMU_BUF_DURATION); /* now we wait for the next timeout, all following timeouts 40ms in the * future because this is rtx-retry-timeout */ - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 90 * GST_MSECOND); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (id == tid); - gst_clock_id_unref (tid); - gst_clock_id_unref (id); - - out_event = g_async_queue_pop (data.src_event_queue); - g_assert (out_event != NULL); - verify_rtx_event (out_event, 2, 40 * GST_MSECOND, 50, PCMU_BUF_DURATION); - - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 130 * GST_MSECOND); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (id == tid); - gst_clock_id_unref (tid); - gst_clock_id_unref (id); + gst_test_clock_set_time_and_process (testclock, 90 * GST_MSECOND); + out_event = gst_harness_pull_upstream_event (h); + verify_rtx_event (out_event, 2, rtx_retry_timeout, 50, PCMU_BUF_DURATION); - out_event = g_async_queue_pop (data.src_event_queue); - g_assert (out_event != NULL); - verify_rtx_event (out_event, 2, 40 * GST_MSECOND, 90, PCMU_BUF_DURATION); + gst_test_clock_set_time_and_process (testclock, 130 * GST_MSECOND); + out_event = gst_harness_pull_upstream_event (h); + verify_rtx_event (out_event, 2, rtx_retry_timeout, 90, PCMU_BUF_DURATION); - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 200 * GST_MSECOND); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (id == tid); - gst_clock_id_unref (tid); - gst_clock_id_unref (id); - - out_buf = g_async_queue_pop (data.buf_queue); - g_assert (out_buf != NULL); + gst_test_clock_set_time_and_process (testclock, 200 * GST_MSECOND); + out_buf = gst_harness_pull (h); + fail_unless_equals_int (0, get_rtp_seq_num (out_buf)); gst_buffer_unref (out_buf); - - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 240 * GST_MSECOND); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (tid == id); - gst_clock_id_unref (tid); - gst_clock_id_unref (id); - + gst_test_clock_set_time_and_process (testclock, 240 * GST_MSECOND); /* we should now receive a packet-lost-event for buffer 2 */ - out_event = g_async_queue_pop (data.sink_event_queue); - g_assert (out_event != NULL); + out_event = gst_harness_pull_event (h); verify_lost_event (out_event, 2, 40 * GST_MSECOND, PCMU_BUF_DURATION); - destroy_testharness (&data); + gst_object_unref (testclock); + gst_harness_teardown (h); } GST_END_TEST; GST_START_TEST (test_rtx_two_missing) { - TestData data; - GstClockID id, tid; - GstBuffer *in_buf, *out_buf; + GstHarness *h = gst_harness_new ("rtpjitterbuffer"); + GstTestClock *testclock; + GstBuffer *out_buf; GstEvent *out_event; gint jb_latency_ms = 200; - gint i; + const GstClockTime rtx_retry_timeout = 40 * GST_MSECOND; GstStructure *rtx_stats; const GValue *rtx_stat; - GstRTPBuffer rtp = GST_RTP_BUFFER_INIT; + gint i; - setup_testharness (&data); - g_object_set (data.jitter_buffer, "do-retransmission", TRUE, NULL); - g_object_set (data.jitter_buffer, "latency", jb_latency_ms, NULL); - g_object_set (data.jitter_buffer, "rtx-retry-period", 120, NULL); + gst_harness_set_src_caps (h, generate_caps ()); + testclock = gst_harness_get_testclock (h); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 0); + g_object_set (h->element, "do-lost", TRUE, NULL); + g_object_set (h->element, "do-retransmission", TRUE, NULL); + g_object_set (h->element, "latency", jb_latency_ms, NULL); + g_object_set (h->element, "rtx-retry-period", 120, NULL); /* push the first buffer in */ - in_buf = generate_test_buffer (0); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer (0))); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 20 * GST_MSECOND); + gst_harness_set_time (h, 20 * GST_MSECOND); /* put second buffer, the jitterbuffer should now know that the packet * spacing is 20ms and should ask for retransmission of seqnum 2 in * 20ms+10ms because 2*jitter==0 and 0.5*packet_spacing==10ms */ - in_buf = generate_test_buffer (1); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer (1))); /* push buffer 4, 2 and 3 are missing now, we should get * retransmission events for 3 at 100ms*/ - in_buf = generate_test_buffer (4); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer (4))); /* wait for first retransmission request */ - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 50 * GST_MSECOND); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (id == tid); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); + gst_test_clock_set_time_and_process (testclock, 50 * GST_MSECOND); + + /* drop reconfigure event */ + gst_event_unref (gst_harness_pull_upstream_event (h)); + /* drop GstEventStreamStart & GstEventCaps & GstEventSegment */ + for (int i = 0; i < 3; i++) + gst_event_unref (gst_harness_pull_event (h)); /* First event for 2 */ - out_event = g_async_queue_pop (data.src_event_queue); - g_assert (out_event != NULL); - verify_rtx_event (out_event, 2, 40 * GST_MSECOND, 10, PCMU_BUF_DURATION); + out_event = gst_harness_pull_upstream_event (h); + verify_rtx_event (out_event, 2, rtx_retry_timeout, 10, PCMU_BUF_DURATION); /* wait for second retransmission request */ - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 60 * GST_MSECOND); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (id == tid); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); + gst_test_clock_set_time_and_process (testclock, 60 * GST_MSECOND); /* Second event for 3 */ - out_event = g_async_queue_pop (data.src_event_queue); - g_assert (out_event != NULL); + out_event = gst_harness_pull_upstream_event (h); verify_rtx_event (out_event, 3, 60 * GST_MSECOND, 0, PCMU_BUF_DURATION); /* now we wait for the next timeout for 2 */ - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 90 * GST_MSECOND); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (id == tid); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); + gst_test_clock_set_time_and_process (testclock, 90 * GST_MSECOND); /* First event for 2 */ - out_event = g_async_queue_pop (data.src_event_queue); - g_assert (out_event != NULL); - verify_rtx_event (out_event, 2, 40 * GST_MSECOND, 50, PCMU_BUF_DURATION); + out_event = gst_harness_pull_upstream_event (h); + verify_rtx_event (out_event, 2, rtx_retry_timeout, 50, PCMU_BUF_DURATION); /* now we wait for the next timeout for 3 */ - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 100 * GST_MSECOND); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (id == tid); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); + gst_test_clock_set_time_and_process (testclock, 100 * GST_MSECOND); /* Second event for 3 */ - out_event = g_async_queue_pop (data.src_event_queue); - g_assert (out_event != NULL); + out_event = gst_harness_pull_upstream_event (h); verify_rtx_event (out_event, 3, 60 * GST_MSECOND, 40, PCMU_BUF_DURATION); /* make buffer 3 */ - in_buf = generate_test_buffer (3); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer (3))); /* make more buffers */ for (i = 5; i < 15; i++) { - in_buf = generate_test_buffer (i); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer (i))); } - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 130 * GST_MSECOND); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (id == tid); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); + gst_test_clock_set_time_and_process (testclock, 130 * GST_MSECOND); /* now we only get requests for 2 */ - out_event = g_async_queue_pop (data.src_event_queue); - g_assert (out_event != NULL); - verify_rtx_event (out_event, 2, 40 * GST_MSECOND, 90, PCMU_BUF_DURATION); + out_event = gst_harness_pull_upstream_event (h); + verify_rtx_event (out_event, 2, rtx_retry_timeout, 90, PCMU_BUF_DURATION); /* this is when buffer 0 deadline expires */ - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 200 * GST_MSECOND); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (id == tid); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); + gst_test_clock_set_time_and_process (testclock, 200 * GST_MSECOND); for (i = 0; i < 2; i++) { GST_DEBUG ("popping %d", i); - out_buf = g_async_queue_pop (data.buf_queue); - g_assert (out_buf != NULL); - gst_rtp_buffer_map (out_buf, GST_MAP_READ, &rtp); - g_assert_cmpint (gst_rtp_buffer_get_seq (&rtp), ==, i); - gst_rtp_buffer_unmap (&rtp); + out_buf = gst_harness_pull (h); + fail_unless_equals_int (i, get_rtp_seq_num (out_buf)); gst_buffer_unref (out_buf); } /* this is when 2 is lost */ - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 240 * GST_MSECOND); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (id == tid); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); + gst_test_clock_set_time_and_process (testclock, 240 * GST_MSECOND); /* we should now receive a packet-lost-event for buffer 2 */ - out_event = g_async_queue_pop (data.sink_event_queue); - g_assert (out_event != NULL); + out_event = gst_harness_pull_event (h); verify_lost_event (out_event, 2, 40 * GST_MSECOND, PCMU_BUF_DURATION); /* verify that buffers made it through! */ for (i = 3; i < 15; i++) { GST_DEBUG ("popping %d", i); - out_buf = g_async_queue_pop (data.buf_queue); - g_assert (out_buf != NULL); - gst_rtp_buffer_map (out_buf, GST_MAP_READ, &rtp); - g_assert_cmpint (gst_rtp_buffer_get_seq (&rtp), ==, i); - gst_rtp_buffer_unmap (&rtp); + out_buf = gst_harness_pull (h); + fail_unless_equals_int (i, get_rtp_seq_num (out_buf)); gst_buffer_unref (out_buf); } - /* should still have only seen 1 packet lost events */ - g_assert_cmpint (data.lost_event_count, ==, 1); + /* should still have only seen 1 packet lost events, + so no events in the queue */ + fail_unless_equals_int (0, gst_harness_events_in_queue (h)); - g_object_get (data.jitter_buffer, "stats", &rtx_stats, NULL); + g_object_get (h->element, "stats", &rtx_stats, NULL); rtx_stat = gst_structure_get_value (rtx_stats, "rtx-count"); - g_assert_cmpuint (g_value_get_uint64 (rtx_stat), ==, 5); + fail_unless_equals_uint64 (5, g_value_get_uint64 (rtx_stat)); rtx_stat = gst_structure_get_value (rtx_stats, "rtx-success-count"); - g_assert_cmpuint (g_value_get_uint64 (rtx_stat), ==, 1); + fail_unless_equals_uint64 (1, g_value_get_uint64 (rtx_stat)); rtx_stat = gst_structure_get_value (rtx_stats, "rtx-rtt"); - g_assert_cmpuint (g_value_get_uint64 (rtx_stat), ==, 0); + fail_unless_equals_uint64 (0, g_value_get_uint64 (rtx_stat)); gst_structure_free (rtx_stats); - destroy_testharness (&data); + gst_object_unref (testclock); + gst_harness_teardown (h); } GST_END_TEST; GST_START_TEST (test_rtx_packet_delay) { - TestData data; - GstClockID id, tid; + GstHarness *h = gst_harness_new ("rtpjitterbuffer"); + GstTestClock *testclock; GstBuffer *in_buf, *out_buf; GstEvent *out_event; gint jb_latency_ms = 200; gint i; - GstRTPBuffer rtp = GST_RTP_BUFFER_INIT; - setup_testharness (&data); - g_object_set (data.jitter_buffer, "do-retransmission", TRUE, NULL); - g_object_set (data.jitter_buffer, "latency", jb_latency_ms, NULL); - g_object_set (data.jitter_buffer, "rtx-retry-period", 120, NULL); + gst_harness_set_src_caps (h, generate_caps ()); + testclock = gst_harness_get_testclock (h); + + g_object_set (h->element, "do-lost", TRUE, NULL); + g_object_set (h->element, "do-retransmission", TRUE, NULL); + g_object_set (h->element, "latency", jb_latency_ms, NULL); + g_object_set (h->element, "rtx-retry-period", 120, NULL); /* push the first buffer in */ in_buf = generate_test_buffer (0); GST_BUFFER_FLAG_SET (in_buf, GST_BUFFER_FLAG_DISCONT); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + gst_harness_push (h, in_buf); /* put second buffer, the jitterbuffer should now know that the packet * spacing is 20ms and should ask for retransmission of seqnum 2 in * 20ms+10ms because 2*jitter==0 and 0.5*packet_spacing==10ms */ - in_buf = generate_test_buffer (1); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer (1))); /* push buffer 8, 2 -> 7 are missing now. note that the rtp time is the same * as packet 1 because it was part of a fragmented payload. This means that * the estimate for 2 could be refined now to 20ms. also packet 2, 3 and 4 * are exceeding the max allowed reorder distance and should request a * retransmission right away */ - in_buf = - generate_test_buffer_full (20 * GST_MSECOND, TRUE, 8, - 8 * PCMU_RTP_TS_DURATION); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer_full ( + 20 * GST_MSECOND, TRUE, 8, 8 * PCMU_RTP_TS_DURATION))); + + /* drop reconfigure event */ + gst_event_unref (gst_harness_pull_upstream_event (h)); + /* drop GstEventStreamStart & GstEventCaps & GstEventSegment */ + for (int i = 0; i < 3; i++) + gst_event_unref (gst_harness_pull_event (h)); /* we should now receive retransmission requests for 2 -> 5 */ - out_event = g_async_queue_pop (data.src_event_queue); - g_assert (out_event != NULL); + out_event = gst_harness_pull_upstream_event (h); verify_rtx_event (out_event, 2, 20 * GST_MSECOND, 30, PCMU_BUF_DURATION); for (i = 3; i < 5; i++) { GST_DEBUG ("popping %d", i); - out_event = g_async_queue_pop (data.src_event_queue); - g_assert (out_event != NULL); + out_event = gst_harness_pull_upstream_event (h); verify_rtx_event (out_event, i, 20 * GST_MSECOND, 0, PCMU_BUF_DURATION); } - g_assert_cmpint (data.rtx_event_count, ==, 3); + fail_unless_equals_int (0, gst_harness_upstream_events_in_queue (h)); /* push 9, this should immediately request retransmission of 5 */ - in_buf = - generate_test_buffer_full (20 * GST_MSECOND, TRUE, 9, - 9 * PCMU_RTP_TS_DURATION); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer_full ( + 20 * GST_MSECOND, TRUE, 9, 9 * PCMU_RTP_TS_DURATION))); /* we should now receive retransmission requests for 5 */ - out_event = g_async_queue_pop (data.src_event_queue); - g_assert (out_event != NULL); + out_event = gst_harness_pull_upstream_event (h); verify_rtx_event (out_event, 5, 20 * GST_MSECOND, 0, PCMU_BUF_DURATION); /* wait for timeout for rtx 6 -> 7 */ - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_advance_time (GST_TEST_CLOCK (data.clock), GST_MSECOND * 60); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (id == tid); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); + gst_test_clock_set_time_and_process (testclock, 60 * GST_MSECOND); for (i = 6; i < 8; i++) { GST_DEBUG ("popping %d", i); - out_event = g_async_queue_pop (data.src_event_queue); - g_assert (out_event != NULL); + out_event = gst_harness_pull_upstream_event (h); verify_rtx_event (out_event, i, 20 * GST_MSECOND, 0, PCMU_BUF_DURATION); } - /* churn through sync_times until the new buffer gets pushed out */ - while (g_async_queue_length (data.buf_queue) < 1) { - if (gst_test_clock_peek_next_pending_id (GST_TEST_CLOCK (data.clock), &id)) { - GstClockTime t = gst_clock_id_get_time (id); - if (t >= 240 * GST_MSECOND) { - gst_clock_id_unref (id); - break; - } - if (t > gst_clock_get_time (data.clock)) { - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), t); - } - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); - } - } + /* churn through 7 sync_times until the new buffer gets pushed out */ + for (i = 0; i < 7; i++) + gst_harness_crank_single_clock_wait (h); /* verify that buffer 0 and 1 made it through! */ for (i = 0; i < 2; i++) { - out_buf = g_async_queue_pop (data.buf_queue); - g_assert (out_buf != NULL); + out_buf = gst_harness_pull (h); if (i == 0) - g_assert (GST_BUFFER_FLAG_IS_SET (out_buf, GST_BUFFER_FLAG_DISCONT)); - gst_rtp_buffer_map (out_buf, GST_MAP_READ, &rtp); - g_assert_cmpint (gst_rtp_buffer_get_seq (&rtp), ==, i); - gst_rtp_buffer_unmap (&rtp); + fail_unless (GST_BUFFER_FLAG_IS_SET (out_buf, GST_BUFFER_FLAG_DISCONT)); + fail_unless_equals_int (i, get_rtp_seq_num (out_buf)); gst_buffer_unref (out_buf); } - /* churn through sync_times until the next buffer gets pushed out */ - while (g_async_queue_length (data.buf_queue) < 1) { - if (gst_test_clock_peek_next_pending_id (GST_TEST_CLOCK (data.clock), &id)) { - GstClockTime t = gst_clock_id_get_time (id); - if (t >= 240 * GST_MSECOND) { - gst_clock_id_unref (id); - break; - } - if (t > gst_clock_get_time (data.clock)) { - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), t); - } - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); - } - } + /* churn through 1 sync_time until the next buffer gets pushed out */ + gst_harness_crank_single_clock_wait (h); for (i = 2; i < 8; i++) { GST_DEBUG ("popping lost event %d", i); - out_event = g_async_queue_pop (data.sink_event_queue); - g_assert (out_event != NULL); + out_event = gst_harness_pull_event (h); verify_lost_event (out_event, i, 20 * GST_MSECOND, 0); } /* verify that buffer 8 made it through! */ for (i = 8; i < 10; i++) { GST_DEBUG ("popping buffer %d", i); - out_buf = g_async_queue_pop (data.buf_queue); - g_assert (out_buf != NULL); + out_buf = gst_harness_pull (h); if (i == 8) g_assert (GST_BUFFER_FLAG_IS_SET (out_buf, GST_BUFFER_FLAG_DISCONT)); - gst_rtp_buffer_map (out_buf, GST_MAP_READ, &rtp); - g_assert_cmpint (gst_rtp_buffer_get_seq (&rtp), ==, i); - gst_rtp_buffer_unmap (&rtp); + fail_unless_equals_int (i, get_rtp_seq_num (out_buf)); gst_buffer_unref (out_buf); } GST_DEBUG ("waiting for 240ms"); - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 240 * GST_MSECOND); - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (id == tid); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); + gst_test_clock_set_time_and_process (testclock, 240 * GST_MSECOND); GST_DEBUG ("popping lost event 10"); - out_event = g_async_queue_pop (data.sink_event_queue); - g_assert (out_event != NULL); + out_event = gst_harness_pull_event (h); verify_lost_event (out_event, 10, 40 * GST_MSECOND, PCMU_BUF_DURATION); - /* should have seen 6 packet lost events */ - g_assert_cmpint (data.lost_event_count, ==, 7); - g_assert_cmpint (data.rtx_event_count, ==, 26); + fail_unless_equals_int (0, gst_harness_events_in_queue (h)); + fail_unless_equals_int (20, gst_harness_upstream_events_in_queue (h)); - destroy_testharness (&data); + gst_object_unref (testclock); + gst_harness_teardown (h); } GST_END_TEST; GST_START_TEST (test_gap_exceeds_latency) { - TestData data; - GstBuffer *in_buf, *out_buf; - GstClockID id, tid; - GstEvent *out_event; + GstHarness *h = gst_harness_new ("rtpjitterbuffer"); + GstTestClock *testclock; + const gint jb_latency_ms = 200; + guint32 timestamp_ms = 0; - guint32 last_ts = 0; - gint jb_latency_ms = 200; guint32 rtp_ts = 0; - guint32 last_rtp = 0; - const GstStructure *s = NULL; - guint32 seqnum = 0; gint i; + GstEvent *out_event; + GstBuffer *out_buf; + + gst_harness_set_src_caps (h, generate_caps ()); + testclock = gst_harness_get_testclock (h); - setup_testharness (&data); - g_object_set (data.jitter_buffer, "do-retransmission", TRUE, NULL); - g_object_set (data.jitter_buffer, "latency", jb_latency_ms, NULL); - g_object_set (data.jitter_buffer, "rtx-retry-period", 120, NULL); + g_object_set (h->element, "do-lost", TRUE, NULL); + g_object_set (h->element, "do-retransmission", TRUE, NULL); + g_object_set (h->element, "latency", jb_latency_ms, NULL); + g_object_set (h->element, "rtx-retry-period", 120, NULL); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 0); - in_buf = - generate_test_buffer_full (timestamp_ms * GST_MSECOND, TRUE, 0, rtp_ts); - GST_BUFFER_FLAG_SET (in_buf, GST_BUFFER_FLAG_DISCONT); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + /* push the first buffer in */ + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer (0))); timestamp_ms += 20; rtp_ts += PCMU_RTP_TS_DURATION; - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), - timestamp_ms * GST_MSECOND); + gst_harness_set_time (h, timestamp_ms * GST_MSECOND); + + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer (1))); - in_buf = - generate_test_buffer_full (timestamp_ms * GST_MSECOND, TRUE, 1, rtp_ts); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); - last_rtp = rtp_ts; - last_ts = timestamp_ms; + /* drop reconfigure event */ + gst_event_unref (gst_harness_pull_upstream_event (h)); + /* drop GstEventStreamStart & GstEventCaps & GstEventSegment */ + for (i = 0; i < 3; i++) + gst_event_unref (gst_harness_pull_event (h)); /* Allow seqnum 2 to be declared lost */ - do { - out_event = g_async_queue_try_pop (data.sink_event_queue); - if (!out_event) { - if (gst_test_clock_peek_next_pending_id (GST_TEST_CLOCK (data.clock), - &id)) { - - GstClockTime t = gst_clock_id_get_time (id); - if (t > gst_clock_get_time (data.clock)) { - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), t); - } - tid = - gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); - } - } - } while (!out_event); - - out_buf = g_async_queue_pop (data.buf_queue); - gst_buffer_unref (out_buf); + for (i = 0; i < 3; i++) { + gst_harness_crank_single_clock_wait (h); + out_event = gst_harness_pull_upstream_event (h); + verify_rtx_event (out_event, + 2, 2 * PCMU_BUF_DURATION, 10 + 40 * i, PCMU_BUF_DURATION); + } - out_buf = g_async_queue_pop (data.buf_queue); - gst_buffer_unref (out_buf); + /* buffer 0 & 1 */ + gst_harness_crank_single_clock_wait (h); + for (i = 0; i < 2; i++) { + out_buf = gst_harness_pull (h); + fail_unless_equals_int (i, get_rtp_seq_num (out_buf)); + gst_buffer_unref (out_buf); + } - timestamp_ms += (20 * 15); - s = gst_event_get_structure (out_event); - g_assert (gst_structure_get_uint (s, "seqnum", &seqnum)); - g_assert_cmpint (seqnum, ==, 2); - gst_event_unref (out_event); + /* lost event */ + gst_harness_crank_single_clock_wait (h); + out_event = gst_harness_pull_event (h); + verify_lost_event (out_event, 2, 2 * PCMU_BUF_DURATION, PCMU_BUF_DURATION); /* Now data comes in again, a "bulk" lost packet is created for 3 -> 5 */ - rtp_ts += (PCMU_RTP_TS_DURATION * 15); - in_buf = - generate_test_buffer_full (timestamp_ms * GST_MSECOND, TRUE, 16, rtp_ts); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); - - last_ts += 60; - last_rtp += 480; - in_buf = generate_test_buffer_full (last_ts * GST_MSECOND, TRUE, 8, last_rtp); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); - - last_ts += PCMU_BUF_MS; - last_rtp += PCMU_RTP_TS_DURATION; - in_buf = generate_test_buffer_full (last_ts * GST_MSECOND, TRUE, 9, last_rtp); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); - - last_ts += PCMU_BUF_MS; - last_rtp += PCMU_RTP_TS_DURATION; - in_buf = - generate_test_buffer_full (last_ts * GST_MSECOND, TRUE, 10, last_rtp); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); - - last_ts += PCMU_BUF_MS; - last_rtp += PCMU_RTP_TS_DURATION; - in_buf = - generate_test_buffer_full (last_ts * GST_MSECOND, TRUE, 11, last_rtp); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); - - last_ts += PCMU_BUF_MS; - last_rtp += PCMU_RTP_TS_DURATION; - in_buf = - generate_test_buffer_full (last_ts * GST_MSECOND, TRUE, 12, last_rtp); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); - - last_ts += PCMU_BUF_MS; - last_rtp += PCMU_RTP_TS_DURATION; - in_buf = - generate_test_buffer_full (last_ts * GST_MSECOND, TRUE, 13, last_rtp); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); - - last_ts += PCMU_BUF_MS; - last_rtp += PCMU_RTP_TS_DURATION; - in_buf = - generate_test_buffer_full (last_ts * GST_MSECOND, TRUE, 14, last_rtp); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); - - last_ts += PCMU_BUF_MS; - last_rtp += PCMU_RTP_TS_DURATION; - in_buf = - generate_test_buffer_full (last_ts * GST_MSECOND, TRUE, 15, last_rtp); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); - - /* Wait for data to be pushed. */ - while (g_async_queue_length (data.buf_queue) < 1) { - if (gst_test_clock_peek_next_pending_id (GST_TEST_CLOCK (data.clock), &id)) { - GstClockTime t = gst_clock_id_get_time (id); - if (t > gst_clock_get_time (data.clock)) { - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), t); - } - tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); - } + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer (16))); + + /* FIXME: something is up with the timestamp here!!?! */ + out_event = gst_harness_pull_upstream_event (h); + verify_rtx_event (out_event, 6, 119999994, 0, PCMU_BUF_DURATION); + /* lost more rtx with weird timestamps... */ + for (i = 0; i < 13; i++) { + gst_event_unref (gst_harness_pull_upstream_event (h)); } - out_event = g_async_queue_pop (data.sink_event_queue); - s = gst_event_get_structure (out_event); - g_assert (gst_structure_get_uint (s, "seqnum", &seqnum)); - g_assert_cmpint (seqnum, ==, 3); - gst_event_unref (out_event); + fail_unless_equals_int (0, gst_harness_upstream_events_in_queue (h)); + fail_unless_equals_int (0, gst_harness_events_in_queue (h)); + fail_unless_equals_int (0, gst_harness_buffers_in_queue (h)); + + for (i = 8; i < 16; i++) { + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer (i))); + } + + /* FIXME: wtf is going on with timestamps and durations here??!? */ + gst_harness_crank_single_clock_wait (h); + out_event = gst_harness_pull_event (h); + verify_lost_event (out_event, 3, 41428571, 78571423); + + /* FIXME: and these rtx... */ + gst_harness_crank_single_clock_wait (h); + out_event = gst_harness_pull_upstream_event (h); + verify_rtx_event (out_event, 7, 141428565, 120, PCMU_BUF_DURATION); - out_event = g_async_queue_pop (data.sink_event_queue); - s = gst_event_get_structure (out_event); - g_assert (gst_structure_get_uint (s, "seqnum", &seqnum)); - g_assert_cmpint (seqnum, ==, 6); - gst_event_unref (out_event); + gst_harness_crank_single_clock_wait (h); + out_event = gst_harness_pull_event (h); + verify_lost_event (out_event, 6, 119999994, 21428571); - out_event = g_async_queue_pop (data.sink_event_queue); - s = gst_event_get_structure (out_event); - g_assert (gst_structure_get_uint (s, "seqnum", &seqnum)); - g_assert_cmpint (seqnum, ==, 7); - gst_event_unref (out_event); + gst_harness_crank_single_clock_wait (h); + out_event = gst_harness_pull_event (h); + verify_lost_event (out_event, 7, 141428565, 21428571); /* 8 */ for (i = 8; i <= 16; i++) { - out_buf = g_async_queue_pop (data.buf_queue); + GstBuffer * out_buf = gst_harness_pull (h); GST_DEBUG ("pop %d", i); + fail_unless_equals_int (i, get_rtp_seq_num (out_buf)); gst_buffer_unref (out_buf); } - do { - out_event = g_async_queue_try_pop (data.sink_event_queue); - if (!out_event) { - if (gst_test_clock_peek_next_pending_id (GST_TEST_CLOCK (data.clock), - &id)) { - - GstClockTime t = gst_clock_id_get_time (id); - if (t > gst_clock_get_time (data.clock)) { - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), t); - } - tid = - gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - gst_clock_id_unref (id); - gst_clock_id_unref (tid); - } - } - } while (!out_event); + fail_unless_equals_int (0, gst_harness_upstream_events_in_queue (h)); + fail_unless_equals_int (0, gst_harness_events_in_queue (h)); + fail_unless_equals_int (0, gst_harness_buffers_in_queue (h)); + + /* rtx x 3 */ + for (i = 0; i < 3; i++) { + gst_harness_crank_single_clock_wait (h); + out_event = gst_harness_pull_upstream_event (h); + verify_rtx_event (out_event, + 17, 17 * PCMU_BUF_DURATION, 10 + 40 * i, PCMU_BUF_DURATION); + } + + /* lost event for 17 */ + gst_harness_crank_single_clock_wait (h); + out_event = gst_harness_pull_event (h); + verify_lost_event (out_event, 17, 17 * PCMU_BUF_DURATION, PCMU_BUF_DURATION); - /* and lost of 17 */ - s = gst_event_get_structure (out_event); - g_assert (gst_structure_get_uint (s, "seqnum", &seqnum)); - g_assert_cmpint (seqnum, ==, 17); - gst_event_unref (out_event); + fail_unless_equals_int (0, gst_harness_upstream_events_in_queue (h)); + fail_unless_equals_int (0, gst_harness_events_in_queue (h)); + fail_unless_equals_int (0, gst_harness_buffers_in_queue (h)); - destroy_testharness (&data); + gst_object_unref (testclock); + gst_harness_teardown (h); } GST_END_TEST; GST_START_TEST (test_deadline_ts_offset) { - TestData data; - GstClockID id, test_id; - GstBuffer *in_buf, *out_buf; - gint jb_latency_ms = 10; - - setup_testharness (&data); + GstHarness *h = gst_harness_new ("rtpjitterbuffer"); + GstTestClock *testclock; + GstClockID id; + const gint jb_latency_ms = 10; - g_object_set (data.jitter_buffer, "latency", jb_latency_ms, NULL); + gst_harness_set_src_caps (h, generate_caps ()); + testclock = gst_harness_get_testclock (h); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 0); + g_object_set (h->element, "latency", jb_latency_ms, NULL); /* push the first buffer in */ - in_buf = generate_test_buffer (0); - g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, generate_test_buffer (0))); /* wait_next_timeout() syncs on the deadline timer */ - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - g_assert_cmpint (gst_clock_id_get_time (id), ==, jb_latency_ms * GST_MSECOND); + gst_test_clock_wait_for_next_pending_id (testclock, &id); + fail_unless_equals_uint64 (jb_latency_ms * GST_MSECOND, + gst_clock_id_get_time (id)); + gst_clock_id_unref (id); /* add ts-offset while waiting */ - g_object_set (data.jitter_buffer, "ts-offset", 20 * GST_MSECOND, NULL); + g_object_set (h->element, "ts-offset", 20 * GST_MSECOND, NULL); - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), - jb_latency_ms * GST_MSECOND); - test_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (test_id == id); - gst_clock_id_unref (id); - gst_clock_id_unref (test_id); + gst_test_clock_set_time_and_process (testclock, jb_latency_ms * GST_MSECOND); /* wait_next_timeout() syncs on the new deadline timer */ - gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - g_assert_cmpint (gst_clock_id_get_time (id), ==, - (20 + jb_latency_ms) * GST_MSECOND); + gst_test_clock_wait_for_next_pending_id (testclock, &id); + fail_unless_equals_uint64 ((20 + jb_latency_ms) * GST_MSECOND, + gst_clock_id_get_time (id)); + gst_clock_id_unref (id); /* now make deadline timer timeout */ - gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), + gst_test_clock_set_time_and_process (testclock, (20 + jb_latency_ms) * GST_MSECOND); - test_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); - g_assert (test_id == id); - gst_clock_id_unref (id); - gst_clock_id_unref (test_id); - out_buf = g_async_queue_pop (data.buf_queue); - g_assert (out_buf != NULL); - gst_buffer_unref (out_buf); + gst_buffer_unref (gst_harness_pull (h)); - destroy_testharness (&data); + gst_object_unref (testclock); + gst_harness_teardown (h); } GST_END_TEST; |