From 02e62c139d5423ca9d8afe2e4136ce5780d92d07 Mon Sep 17 00:00:00 2001 From: Sebastian Dröge Date: Thu, 17 Apr 2014 17:26:36 +0200 Subject: rtpjitterbuffer: Fix hundreds of memory leaks in the test --- tests/check/elements/rtpjitterbuffer.c | 125 ++++++++++++++++++++++++++------- 1 file changed, 99 insertions(+), 26 deletions(-) (limited to 'tests') diff --git a/tests/check/elements/rtpjitterbuffer.c b/tests/check/elements/rtpjitterbuffer.c index 2169718c9..578c8e9a8 100644 --- a/tests/check/elements/rtpjitterbuffer.c +++ b/tests/check/elements/rtpjitterbuffer.c @@ -481,6 +481,7 @@ 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 (); @@ -518,7 +519,8 @@ setup_testharness (TestData * data) /* 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); - gst_pad_set_caps (data->test_sink_pad, generate_caps ()); + 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"); @@ -533,8 +535,9 @@ setup_testharness (TestData * data) gst_pad_push_event (data->test_src_pad, gst_event_new_stream_start ("stream0")); - gst_pad_set_caps (data->test_src_pad, generate_caps ()); + 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); @@ -601,6 +604,8 @@ verify_lost_event (GstEvent * event, guint32 expected_seqnum, g_assert_cmpint (timestamp, ==, expected_timestamp); g_assert_cmpint (duration, ==, expected_duration); g_assert (late == expected_late); + + gst_event_unref (event); } static void @@ -632,6 +637,8 @@ verify_rtx_event (GstEvent * event, guint32 expected_seqnum, g_assert_cmpint (timestamp, ==, expected_timestamp); g_assert_cmpint (delay, ==, expected_delay); g_assert_cmpint (spacing, ==, expected_spacing); + + gst_event_unref (event); } GST_START_TEST (test_only_one_lost_event_on_large_gaps) @@ -659,14 +666,17 @@ GST_START_TEST (test_only_one_lost_event_on_large_gaps) /* increase the time to timestamp + latency and release the wait */ gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), jb_latency_ms * GST_MSECOND); - g_assert (gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)) - == id); + test_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); + g_assert (test_id == id); + gst_clock_id_unref (test_id); + gst_clock_id_unref (id); /* check for the buffer coming out that was pushed in */ out_buf = g_async_queue_pop (data.buf_queue); g_assert (out_buf != NULL); g_assert_cmpint (GST_BUFFER_DTS (out_buf), ==, 0); g_assert_cmpint (GST_BUFFER_PTS (out_buf), ==, 0); + gst_buffer_unref (out_buf); /* move time ahead 10 seconds */ gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 10 * GST_SECOND); @@ -689,6 +699,8 @@ GST_START_TEST (test_only_one_lost_event_on_large_gaps) gst_test_clock_advance_time (GST_TEST_CLOCK (data.clock), GST_MSECOND * 20); test_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); g_assert (id == test_id); + gst_clock_id_unref (test_id); + gst_clock_id_unref (id); /* we should now receive a packet-lost-event for buffers 1 through 489 */ out_event = g_async_queue_pop (data.sink_event_queue); @@ -704,7 +716,10 @@ GST_START_TEST (test_only_one_lost_event_on_large_gaps) if (t > gst_clock_get_time (data.clock)) { gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), t); } - gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); + test_id = + gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); + gst_clock_id_unref (test_id); + gst_clock_id_unref (id); } } @@ -716,6 +731,7 @@ GST_START_TEST (test_only_one_lost_event_on_large_gaps) gst_rtp_buffer_unmap (&rtp); g_assert_cmpint (GST_BUFFER_DTS (out_buf), ==, (10 * GST_SECOND)); g_assert_cmpint (GST_BUFFER_PTS (out_buf), ==, (10 * GST_SECOND)); + gst_buffer_unref (out_buf); /* we get as many lost events as the the number of buffers the jitterbuffer * is able to wait for (+ the one we already got) */ @@ -729,7 +745,7 @@ GST_END_TEST; GST_START_TEST (test_two_lost_one_arrives_in_time) { TestData data; - GstClockID id; + GstClockID id, test_id; GstBuffer *in_buf, *out_buf; GstEvent *out_event; gint jb_latency_ms = 100; @@ -748,8 +764,10 @@ GST_START_TEST (test_two_lost_one_arrives_in_time) gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); now = jb_latency_ms * GST_MSECOND; gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), now); - g_assert (gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)) - == id); + test_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); + g_assert (test_id == id); + gst_clock_id_unref (test_id); + gst_clock_id_unref (id); out_buf = g_async_queue_pop (data.buf_queue); g_assert (out_buf != NULL); @@ -759,6 +777,7 @@ GST_START_TEST (test_two_lost_one_arrives_in_time) in_buf = generate_test_buffer (buffer_time, TRUE, b, b * 160); gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), now + buffer_time); g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + gst_buffer_unref (out_buf); /* check for the buffer coming out that was pushed in */ out_buf = g_async_queue_pop (data.buf_queue); @@ -766,6 +785,7 @@ GST_START_TEST (test_two_lost_one_arrives_in_time) g_assert_cmpint (GST_BUFFER_DTS (out_buf), ==, buffer_time); g_assert_cmpint (GST_BUFFER_PTS (out_buf), ==, buffer_time); } + gst_buffer_unref (out_buf); /* hop over 2 packets and make another one (gap of 2) */ b = 5; @@ -782,8 +802,10 @@ GST_START_TEST (test_two_lost_one_arrives_in_time) /* let the time expire... */ gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), gst_clock_id_get_time (id)); - g_assert (gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)) - == id); + test_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); + g_assert (test_id == id); + gst_clock_id_unref (test_id); + gst_clock_id_unref (id); /* we should now receive a packet-lost-event for buffer 3 */ out_event = g_async_queue_pop (data.sink_event_queue); @@ -805,6 +827,7 @@ GST_START_TEST (test_two_lost_one_arrives_in_time) gst_rtp_buffer_map (out_buf, GST_MAP_READ, &rtp); g_assert_cmpint (gst_rtp_buffer_get_seq (&rtp), ==, 4); gst_rtp_buffer_unmap (&rtp); + gst_buffer_unref (out_buf); /* and see that buffer 5 now arrives in a normal fashion */ out_buf = g_async_queue_pop (data.buf_queue); @@ -813,6 +836,7 @@ GST_START_TEST (test_two_lost_one_arrives_in_time) gst_rtp_buffer_map (out_buf, GST_MAP_READ, &rtp); g_assert_cmpint (gst_rtp_buffer_get_seq (&rtp), ==, 5); gst_rtp_buffer_unmap (&rtp); + gst_buffer_unref (out_buf); /* should still have only seen 1 packet lost event */ g_assert_cmpint (data.lost_event_count, ==, 1); @@ -825,7 +849,7 @@ GST_END_TEST; GST_START_TEST (test_late_packets_still_makes_lost_events) { TestData data; - GstClockID id; + GstClockID id, test_id; GstBuffer *in_buf, *out_buf; GstEvent *out_event; gint jb_latency_ms = 10; @@ -844,8 +868,10 @@ GST_START_TEST (test_late_packets_still_makes_lost_events) g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - g_assert (gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)) - == id); + 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); @@ -854,6 +880,7 @@ GST_START_TEST (test_late_packets_still_makes_lost_events) buffer_time = b * GST_MSECOND * 20; in_buf = generate_test_buffer (buffer_time, TRUE, b, b * 160); g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + gst_buffer_unref (out_buf); /* check for the buffer coming out that was pushed in */ out_buf = g_async_queue_pop (data.buf_queue); @@ -861,6 +888,7 @@ GST_START_TEST (test_late_packets_still_makes_lost_events) g_assert_cmpint (GST_BUFFER_DTS (out_buf), ==, buffer_time); g_assert_cmpint (GST_BUFFER_PTS (out_buf), ==, buffer_time); } + gst_buffer_unref (out_buf); /* hop over 2 packets and make another one (gap of 2) */ b = 5; @@ -882,6 +910,7 @@ GST_START_TEST (test_late_packets_still_makes_lost_events) gst_rtp_buffer_map (out_buf, GST_MAP_READ, &rtp); g_assert_cmpint (gst_rtp_buffer_get_seq (&rtp), ==, 5); gst_rtp_buffer_unmap (&rtp); + gst_buffer_unref (out_buf); /* should still have only seen 1 packet lost event */ g_assert_cmpint (data.lost_event_count, ==, 1); @@ -894,7 +923,7 @@ GST_END_TEST; GST_START_TEST (test_all_packets_are_timestamped_zero) { TestData data; - GstClockID id; + GstClockID id, test_id; GstBuffer *in_buf, *out_buf; GstEvent *out_event; gint jb_latency_ms = 10; @@ -912,8 +941,10 @@ GST_START_TEST (test_all_packets_are_timestamped_zero) g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - g_assert (gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)) - == id); + test_id = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); + g_assert (test_id == id); + gst_clock_id_unref (test_id); + gst_clock_id_unref (id); out_buf = g_async_queue_pop (data.buf_queue); g_assert (out_buf != NULL); @@ -921,6 +952,7 @@ GST_START_TEST (test_all_packets_are_timestamped_zero) for (b = 1; b < 3; b++) { in_buf = generate_test_buffer (0, TRUE, b, 0); g_assert_cmpint (gst_pad_push (data.test_src_pad, in_buf), ==, GST_FLOW_OK); + gst_buffer_unref (out_buf); /* check for the buffer coming out that was pushed in */ out_buf = g_async_queue_pop (data.buf_queue); @@ -928,6 +960,7 @@ GST_START_TEST (test_all_packets_are_timestamped_zero) g_assert_cmpint (GST_BUFFER_DTS (out_buf), ==, 0); g_assert_cmpint (GST_BUFFER_PTS (out_buf), ==, 0); } + gst_buffer_unref (out_buf); /* hop over 2 packets and make another one (gap of 2) */ b = 5; @@ -952,6 +985,7 @@ GST_START_TEST (test_all_packets_are_timestamped_zero) gst_rtp_buffer_map (out_buf, GST_MAP_READ, &rtp); g_assert_cmpint (gst_rtp_buffer_get_seq (&rtp), ==, 5); gst_rtp_buffer_unmap (&rtp); + gst_buffer_unref (out_buf); /* should still have only seen 2 packet lost events */ g_assert_cmpint (data.lost_event_count, ==, 2); @@ -983,6 +1017,7 @@ GST_START_TEST (test_rtx_expected_next) gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 20 * GST_MSECOND); gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); + gst_clock_id_unref (id); /* put second buffer, the jitterbuffer should now know that the packet spacing * is 20ms and should ask for retransmission of seqnum 2 in 20ms */ @@ -991,8 +1026,10 @@ GST_START_TEST (test_rtx_expected_next) 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); - g_assert (gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)) - == id); + 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); out_event = g_async_queue_pop (data.src_event_queue); g_assert (out_event != NULL); @@ -1003,6 +1040,8 @@ GST_START_TEST (test_rtx_expected_next) 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 (tid); + gst_clock_id_unref (id); out_event = g_async_queue_pop (data.src_event_queue); g_assert (out_event != NULL); @@ -1012,6 +1051,8 @@ GST_START_TEST (test_rtx_expected_next) gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 140 * 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); @@ -1021,15 +1062,20 @@ GST_START_TEST (test_rtx_expected_next) 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_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), 260 * GST_MSECOND); - g_assert (gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)) - == id); + 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); /* we should now receive a packet-lost-event for buffer 2 */ out_event = g_async_queue_pop (data.sink_event_queue); @@ -1080,8 +1126,10 @@ GST_START_TEST (test_rtx_two_missing) gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 60 * GST_MSECOND); do { gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); - } while (id != - gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock))); + tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); + gst_clock_id_unref (id); + gst_clock_id_unref (tid); + } while (id != tid); /* we should have 2 events now, one for 2 and another for 3 */ out_event = g_async_queue_pop (data.src_event_queue); @@ -1096,6 +1144,8 @@ GST_START_TEST (test_rtx_two_missing) 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); /* we should have 2 events now, one for 2 and another for 3 */ out_event = g_async_queue_pop (data.src_event_queue); @@ -1119,6 +1169,8 @@ GST_START_TEST (test_rtx_two_missing) gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 140 * 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); /* now we only get requests for 2 */ out_event = g_async_queue_pop (data.src_event_queue); @@ -1130,6 +1182,8 @@ GST_START_TEST (test_rtx_two_missing) 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); for (i = 0; i < 2; i++) { GST_DEBUG ("popping %d", i); @@ -1138,6 +1192,7 @@ GST_START_TEST (test_rtx_two_missing) 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); + gst_buffer_unref (out_buf); } /* this is when 2 is lost */ @@ -1145,6 +1200,8 @@ GST_START_TEST (test_rtx_two_missing) 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); /* we should now receive a packet-lost-event for buffer 2 */ out_event = g_async_queue_pop (data.sink_event_queue); @@ -1159,6 +1216,7 @@ GST_START_TEST (test_rtx_two_missing) 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); + gst_buffer_unref (out_buf); } /* should still have only seen 1 packet lost events */ g_assert_cmpint (data.lost_event_count, ==, 1); @@ -1173,6 +1231,7 @@ GST_START_TEST (test_rtx_two_missing) rtx_stat = gst_structure_get_value (rtx_stats, "rtx-rtt"); g_assert_cmpuint (g_value_get_uint64 (rtx_stat), ==, 0); + gst_structure_free (rtx_stats); destroy_testharness (&data); } @@ -1242,6 +1301,8 @@ GST_START_TEST (test_rtx_packet_delay) gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id); 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); for (i = 6; i < 8; i++) { GST_DEBUG ("popping %d", i); @@ -1254,12 +1315,16 @@ GST_START_TEST (test_rtx_packet_delay) 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) + 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); } - gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); + tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); + gst_clock_id_unref (id); + gst_clock_id_unref (tid); } } @@ -1272,18 +1337,23 @@ GST_START_TEST (test_rtx_packet_delay) 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); + 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) + 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); } - gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); + tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock)); + gst_clock_id_unref (id); + gst_clock_id_unref (tid); } } @@ -1304,6 +1374,7 @@ GST_START_TEST (test_rtx_packet_delay) 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); + gst_buffer_unref (out_buf); } GST_DEBUG ("waiting for 240ms"); @@ -1311,6 +1382,8 @@ GST_START_TEST (test_rtx_packet_delay) 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_DEBUG ("popping lost event 10"); out_event = g_async_queue_pop (data.sink_event_queue); -- cgit v1.2.3