mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 14:26:43 +00:00
tests: rtpsession: refactor tests to use GstHarness
This patch simplifies the tests (44% less code) and makes them much more readable. The provided SessionHarness also makes it much easier to write new tests for rtpsession. https://bugzilla.gnome.org/show_bug.cgi?id=791070
This commit is contained in:
parent
b02350bd62
commit
96d837b301
1 changed files with 285 additions and 412 deletions
|
@ -25,53 +25,49 @@
|
||||||
#include <gst/check/gstharness.h>
|
#include <gst/check/gstharness.h>
|
||||||
#include <gst/check/gstcheck.h>
|
#include <gst/check/gstcheck.h>
|
||||||
#include <gst/check/gsttestclock.h>
|
#include <gst/check/gsttestclock.h>
|
||||||
|
#include <gst/check/gstharness.h>
|
||||||
|
|
||||||
#include <gst/rtp/gstrtpbuffer.h>
|
#include <gst/rtp/gstrtpbuffer.h>
|
||||||
#include <gst/rtp/gstrtcpbuffer.h>
|
#include <gst/rtp/gstrtcpbuffer.h>
|
||||||
#include <gst/net/gstnetaddressmeta.h>
|
#include <gst/net/gstnetaddressmeta.h>
|
||||||
|
|
||||||
static const guint payload_size = 160;
|
#define TEST_BUF_CLOCK_RATE 8000
|
||||||
static const guint clock_rate = 8000;
|
#define TEST_BUF_PT 0
|
||||||
static const guint payload_type = 0;
|
#define TEST_BUF_SSRC 0x01BADBAD
|
||||||
|
#define TEST_BUF_MS 20
|
||||||
typedef struct
|
#define TEST_BUF_DURATION (TEST_BUF_MS * GST_MSECOND)
|
||||||
{
|
#define TEST_BUF_SIZE (64000 * TEST_BUF_MS / 1000)
|
||||||
GstElement *session;
|
#define TEST_RTP_TS_DURATION (TEST_BUF_CLOCK_RATE * TEST_BUF_MS / 1000)
|
||||||
GstPad *src, *rtcp_sink, *rtpsrc;
|
|
||||||
GstClock *clock;
|
|
||||||
GAsyncQueue *rtcp_queue;
|
|
||||||
} TestData;
|
|
||||||
|
|
||||||
static GstCaps *
|
static GstCaps *
|
||||||
generate_caps (void)
|
generate_caps (void)
|
||||||
{
|
{
|
||||||
return gst_caps_new_simple ("application/x-rtp",
|
return gst_caps_new_simple ("application/x-rtp",
|
||||||
"clock-rate", G_TYPE_INT, clock_rate,
|
"clock-rate", G_TYPE_INT, TEST_BUF_CLOCK_RATE,
|
||||||
"payload-type", G_TYPE_INT, payload_type, NULL);
|
"payload", G_TYPE_INT, TEST_BUF_PT,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstBuffer *
|
static GstBuffer *
|
||||||
generate_test_buffer (GstClockTime gst_ts,
|
generate_test_buffer_full (GstClockTime dts,
|
||||||
gboolean marker_bit, guint seq_num, guint32 rtp_ts, guint ssrc)
|
guint seq_num, guint32 rtp_ts, guint ssrc)
|
||||||
{
|
{
|
||||||
GstBuffer *buf;
|
GstBuffer *buf;
|
||||||
guint8 *payload;
|
guint8 *payload;
|
||||||
guint i;
|
guint i;
|
||||||
GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
|
GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
|
||||||
|
|
||||||
buf = gst_rtp_buffer_new_allocate (payload_size, 0, 0);
|
buf = gst_rtp_buffer_new_allocate (TEST_BUF_SIZE, 0, 0);
|
||||||
GST_BUFFER_DTS (buf) = gst_ts;
|
GST_BUFFER_DTS (buf) = dts;
|
||||||
GST_BUFFER_PTS (buf) = gst_ts;
|
|
||||||
|
|
||||||
gst_rtp_buffer_map (buf, GST_MAP_READWRITE, &rtp);
|
gst_rtp_buffer_map (buf, GST_MAP_READWRITE, &rtp);
|
||||||
gst_rtp_buffer_set_payload_type (&rtp, payload_type);
|
gst_rtp_buffer_set_payload_type (&rtp, TEST_BUF_PT);
|
||||||
gst_rtp_buffer_set_marker (&rtp, marker_bit);
|
|
||||||
gst_rtp_buffer_set_seq (&rtp, seq_num);
|
gst_rtp_buffer_set_seq (&rtp, seq_num);
|
||||||
gst_rtp_buffer_set_timestamp (&rtp, rtp_ts);
|
gst_rtp_buffer_set_timestamp (&rtp, rtp_ts);
|
||||||
gst_rtp_buffer_set_ssrc (&rtp, ssrc);
|
gst_rtp_buffer_set_ssrc (&rtp, ssrc);
|
||||||
|
|
||||||
payload = gst_rtp_buffer_get_payload (&rtp);
|
payload = gst_rtp_buffer_get_payload (&rtp);
|
||||||
for (i = 0; i < payload_size; i++)
|
for (i = 0; i < TEST_BUF_SIZE; i++)
|
||||||
payload[i] = 0xff;
|
payload[i] = 0xff;
|
||||||
|
|
||||||
gst_rtp_buffer_unmap (&rtp);
|
gst_rtp_buffer_unmap (&rtp);
|
||||||
|
@ -79,295 +75,245 @@ generate_test_buffer (GstClockTime gst_ts,
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstBuffer *
|
||||||
test_sink_pad_chain_cb (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
generate_test_buffer (guint seq_num, guint ssrc)
|
||||||
{
|
{
|
||||||
TestData *data = gst_pad_get_element_private (pad);
|
return generate_test_buffer_full (seq_num * TEST_BUF_DURATION,
|
||||||
g_async_queue_push (data->rtcp_queue, buffer);
|
seq_num, seq_num * TEST_RTP_TS_DURATION, ssrc);
|
||||||
GST_DEBUG ("chained");
|
|
||||||
return GST_FLOW_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
GstHarness *send_rtp_h;
|
||||||
|
GstHarness *recv_rtp_h;
|
||||||
|
GstHarness *rtcp_h;
|
||||||
|
|
||||||
|
GstElement *session;
|
||||||
|
GObject *internal_session;
|
||||||
|
GstTestClock *testclock;
|
||||||
|
GstCaps *caps;
|
||||||
|
} SessionHarness;
|
||||||
|
|
||||||
static GstCaps *
|
static GstCaps *
|
||||||
pt_map_requested (GstElement * elemen, guint pt, gpointer data)
|
_pt_map_requested (GstElement * element, guint pt, gpointer data)
|
||||||
{
|
{
|
||||||
return generate_caps ();
|
SessionHarness *h = data;
|
||||||
|
return gst_caps_copy (h->caps);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SessionHarness *
|
||||||
|
session_harness_new (void)
|
||||||
|
{
|
||||||
|
SessionHarness *h = g_new0 (SessionHarness, 1);
|
||||||
|
h->caps = generate_caps ();
|
||||||
|
|
||||||
|
h->testclock = GST_TEST_CLOCK_CAST (gst_test_clock_new ());
|
||||||
|
gst_system_clock_set_default (GST_CLOCK_CAST (h->testclock));
|
||||||
|
|
||||||
|
h->session = gst_element_factory_make ("rtpsession", NULL);
|
||||||
|
gst_element_set_clock (h->session, GST_CLOCK_CAST (h->testclock));
|
||||||
|
|
||||||
|
h->send_rtp_h = gst_harness_new_with_element (h->session,
|
||||||
|
"send_rtp_sink", "send_rtp_src");
|
||||||
|
gst_harness_set_src_caps (h->send_rtp_h, gst_caps_copy (h->caps));
|
||||||
|
|
||||||
|
h->recv_rtp_h = gst_harness_new_with_element (h->session,
|
||||||
|
"recv_rtp_sink", "recv_rtp_src");
|
||||||
|
gst_harness_set_src_caps (h->recv_rtp_h, gst_caps_copy (h->caps));
|
||||||
|
|
||||||
|
h->rtcp_h = gst_harness_new_with_element (h->session,
|
||||||
|
"recv_rtcp_sink", "send_rtcp_src");
|
||||||
|
gst_harness_set_src_caps_str (h->rtcp_h, "application/x-rtcp");
|
||||||
|
|
||||||
|
g_signal_connect (h->session, "request-pt-map",
|
||||||
|
(GCallback) _pt_map_requested, h);
|
||||||
|
|
||||||
|
g_object_get (h->session, "internal-session", &h->internal_session, NULL);
|
||||||
|
|
||||||
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_testharness (TestData * data)
|
session_harness_free (SessionHarness * h)
|
||||||
{
|
{
|
||||||
g_assert_cmpint (gst_element_set_state (data->session, GST_STATE_NULL),
|
gst_system_clock_set_default (NULL);
|
||||||
==, GST_STATE_CHANGE_SUCCESS);
|
|
||||||
gst_object_unref (data->session);
|
|
||||||
data->session = NULL;
|
|
||||||
|
|
||||||
gst_object_unref (data->src);
|
gst_caps_unref (h->caps);
|
||||||
data->src = NULL;
|
gst_object_unref (h->testclock);
|
||||||
|
|
||||||
gst_object_unref (data->rtcp_sink);
|
gst_harness_teardown (h->rtcp_h);
|
||||||
data->rtcp_sink = NULL;
|
gst_harness_teardown (h->recv_rtp_h);
|
||||||
|
gst_harness_teardown (h->send_rtp_h);
|
||||||
|
|
||||||
gst_object_unref (data->rtpsrc);
|
g_object_unref (h->internal_session);
|
||||||
data->rtpsrc = NULL;
|
gst_object_unref (h->session);
|
||||||
|
g_free (h);
|
||||||
|
}
|
||||||
|
|
||||||
gst_object_unref (data->clock);
|
static GstFlowReturn
|
||||||
data->clock = NULL;
|
session_harness_send_rtp (SessionHarness * h, GstBuffer * buf)
|
||||||
|
{
|
||||||
|
return gst_harness_push (h->send_rtp_h, buf);
|
||||||
|
}
|
||||||
|
|
||||||
g_async_queue_unref (data->rtcp_queue);
|
static GstFlowReturn
|
||||||
data->rtcp_queue = NULL;
|
session_harness_recv_rtp (SessionHarness * h, GstBuffer * buf)
|
||||||
|
{
|
||||||
|
return gst_harness_push (h->recv_rtp_h, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstFlowReturn
|
||||||
|
session_harness_recv_rtcp (SessionHarness * h, GstBuffer * buf)
|
||||||
|
{
|
||||||
|
return gst_harness_push (h->rtcp_h, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstBuffer *
|
||||||
|
session_harness_pull_rtcp (SessionHarness * h)
|
||||||
|
{
|
||||||
|
return gst_harness_pull (h->rtcp_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setup_testharness (TestData * data, gboolean session_as_sender)
|
session_harness_crank_clock (SessionHarness * h)
|
||||||
{
|
{
|
||||||
GstPad *rtp_sink_pad, *rtcp_src_pad, *rtp_src_pad;
|
gst_test_clock_crank (h->testclock);
|
||||||
GstSegment seg;
|
}
|
||||||
GstMiniObject *obj;
|
|
||||||
GstCaps *caps;
|
|
||||||
|
|
||||||
data->clock = gst_test_clock_new ();
|
static gboolean
|
||||||
GST_DEBUG ("Setting default system clock to test clock");
|
session_harness_advance_and_crank (SessionHarness * h,
|
||||||
gst_system_clock_set_default (data->clock);
|
GstClockTime delta)
|
||||||
g_assert (data->clock);
|
{
|
||||||
gst_test_clock_set_time (GST_TEST_CLOCK (data->clock), 0);
|
GstClockID res, pending;
|
||||||
|
gboolean result;
|
||||||
|
gst_test_clock_wait_for_next_pending_id (h->testclock, &pending);
|
||||||
|
gst_test_clock_advance_time (h->testclock, delta);
|
||||||
|
res = gst_test_clock_process_next_clock_id (h->testclock);
|
||||||
|
if (res == pending)
|
||||||
|
result = TRUE;
|
||||||
|
else
|
||||||
|
result = FALSE;
|
||||||
|
if (res)
|
||||||
|
gst_clock_id_unref (res);
|
||||||
|
gst_clock_id_unref (pending);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
data->session = gst_element_factory_make ("rtpsession", NULL);
|
static void
|
||||||
g_signal_connect (data->session, "request-pt-map",
|
session_harness_produce_rtcp (SessionHarness * h, gint num_rtcp_packets)
|
||||||
(GCallback) pt_map_requested, data);
|
{
|
||||||
g_assert (data->session);
|
/* due to randomness in rescheduling of RTCP timeout, we need to
|
||||||
gst_element_set_clock (data->session, data->clock);
|
keep cranking until we have the desired amount of packets */
|
||||||
g_assert_cmpint (gst_element_set_state (data->session,
|
while (gst_harness_buffers_in_queue (h->rtcp_h) < num_rtcp_packets)
|
||||||
GST_STATE_PLAYING), !=, GST_STATE_CHANGE_FAILURE);
|
session_harness_crank_clock (h);
|
||||||
|
|
||||||
data->rtcp_queue =
|
|
||||||
g_async_queue_new_full ((GDestroyNotify) gst_mini_object_unref);
|
|
||||||
|
|
||||||
/* link in the test source-pad */
|
|
||||||
data->src = gst_pad_new ("src", GST_PAD_SRC);
|
|
||||||
g_assert (data->src);
|
|
||||||
rtp_sink_pad = gst_element_get_request_pad (data->session,
|
|
||||||
session_as_sender ? "send_rtp_sink" : "recv_rtp_sink");
|
|
||||||
g_assert (rtp_sink_pad);
|
|
||||||
g_assert_cmpint (gst_pad_link (data->src, rtp_sink_pad), ==, GST_PAD_LINK_OK);
|
|
||||||
gst_object_unref (rtp_sink_pad);
|
|
||||||
|
|
||||||
data->rtpsrc = gst_pad_new ("sink", GST_PAD_SINK);
|
|
||||||
g_assert (data->rtpsrc);
|
|
||||||
rtp_src_pad = gst_element_get_static_pad (data->session,
|
|
||||||
session_as_sender ? "send_rtp_src" : "recv_rtp_src");
|
|
||||||
g_assert (rtp_src_pad);
|
|
||||||
g_assert_cmpint (gst_pad_link (rtp_src_pad, data->rtpsrc), ==,
|
|
||||||
GST_PAD_LINK_OK);
|
|
||||||
gst_object_unref (rtp_src_pad);
|
|
||||||
|
|
||||||
/* link in the test sink-pad */
|
|
||||||
data->rtcp_sink = gst_pad_new ("sink", GST_PAD_SINK);
|
|
||||||
g_assert (data->rtcp_sink);
|
|
||||||
gst_pad_set_element_private (data->rtcp_sink, data);
|
|
||||||
caps = generate_caps ();
|
|
||||||
gst_pad_set_caps (data->rtcp_sink, caps);
|
|
||||||
gst_pad_set_chain_function (data->rtcp_sink, test_sink_pad_chain_cb);
|
|
||||||
rtcp_src_pad = gst_element_get_request_pad (data->session, "send_rtcp_src");
|
|
||||||
g_assert (rtcp_src_pad);
|
|
||||||
g_assert_cmpint (gst_pad_link (rtcp_src_pad, data->rtcp_sink), ==,
|
|
||||||
GST_PAD_LINK_OK);
|
|
||||||
gst_object_unref (rtcp_src_pad);
|
|
||||||
|
|
||||||
g_assert (gst_pad_set_active (data->src, TRUE));
|
|
||||||
g_assert (gst_pad_set_active (data->rtcp_sink, TRUE));
|
|
||||||
|
|
||||||
gst_segment_init (&seg, GST_FORMAT_TIME);
|
|
||||||
gst_pad_push_event (data->src, gst_event_new_stream_start ("stream0"));
|
|
||||||
gst_pad_set_caps (data->src, caps);
|
|
||||||
gst_pad_push_event (data->src, gst_event_new_segment (&seg));
|
|
||||||
gst_caps_unref (caps);
|
|
||||||
|
|
||||||
while ((obj = g_async_queue_try_pop (data->rtcp_queue)))
|
|
||||||
gst_mini_object_unref (obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_START_TEST (test_multiple_ssrc_rr)
|
GST_START_TEST (test_multiple_ssrc_rr)
|
||||||
{
|
{
|
||||||
TestData data;
|
SessionHarness *h = session_harness_new ();
|
||||||
GstFlowReturn res;
|
GstFlowReturn res;
|
||||||
GstClockID id, tid;
|
|
||||||
GstBuffer *in_buf, *out_buf;
|
GstBuffer *in_buf, *out_buf;
|
||||||
GstRTCPBuffer rtcp = GST_RTCP_BUFFER_INIT;
|
GstRTCPBuffer rtcp = GST_RTCP_BUFFER_INIT;
|
||||||
GstRTCPPacket rtcp_packet;
|
GstRTCPPacket rtcp_packet;
|
||||||
int i;
|
gint i, j;
|
||||||
guint32 ssrc, exthighestseq, jitter, lsr, dlsr;
|
|
||||||
gint32 packetslost;
|
|
||||||
guint8 fractionlost;
|
|
||||||
|
|
||||||
setup_testharness (&data, FALSE);
|
guint ssrcs[] = {
|
||||||
|
0x01BADBAD,
|
||||||
|
0xDEADBEEF,
|
||||||
|
};
|
||||||
|
|
||||||
gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), 10 * GST_MSECOND);
|
/* receive buffers with multiple ssrcs */
|
||||||
|
for (i = 0; i < 2; i++) {
|
||||||
for (i = 0; i < 5; i++) {
|
for (j = 0; j < G_N_ELEMENTS (ssrcs); j++) {
|
||||||
GST_DEBUG ("Push %i", i);
|
in_buf = generate_test_buffer (i, ssrcs[j]);
|
||||||
in_buf =
|
res = session_harness_recv_rtp (h, in_buf);
|
||||||
generate_test_buffer (i * 20 * GST_MSECOND, FALSE, i, i * 20,
|
fail_unless_equals_int (GST_FLOW_OK, res);
|
||||||
0x01BADBAD);
|
}
|
||||||
res = gst_pad_push (data.src, in_buf);
|
|
||||||
fail_unless (res == GST_FLOW_OK || res == GST_FLOW_FLUSHING);
|
|
||||||
|
|
||||||
|
|
||||||
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));
|
|
||||||
gst_clock_id_unref (id);
|
|
||||||
if (tid)
|
|
||||||
gst_clock_id_unref (tid);
|
|
||||||
|
|
||||||
in_buf =
|
|
||||||
generate_test_buffer (i * 20 * GST_MSECOND, FALSE, i, i * 20,
|
|
||||||
0xDEADBEEF);
|
|
||||||
res = gst_pad_push (data.src, in_buf);
|
|
||||||
fail_unless (res == GST_FLOW_OK || res == GST_FLOW_FLUSHING);
|
|
||||||
|
|
||||||
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));
|
|
||||||
GST_DEBUG ("pushed %i", i);
|
|
||||||
gst_test_clock_set_time (GST_TEST_CLOCK (data.clock),
|
|
||||||
gst_clock_id_get_time (id));
|
|
||||||
gst_clock_id_unref (id);
|
|
||||||
if (tid)
|
|
||||||
gst_clock_id_unref (tid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out_buf = g_async_queue_try_pop (data.rtcp_queue);
|
/* crank the rtcp-thread and pull out the rtcp-packet we have generated */
|
||||||
if (out_buf)
|
session_harness_crank_clock (h);
|
||||||
gst_buffer_unref (out_buf);
|
out_buf = session_harness_pull_rtcp (h);
|
||||||
|
|
||||||
gst_test_clock_set_time (GST_TEST_CLOCK (data.clock),
|
/* verify we have report blocks for both ssrcs */
|
||||||
gst_clock_id_get_time (id) + (5 * GST_SECOND));
|
|
||||||
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));
|
|
||||||
gst_clock_id_unref (id);
|
|
||||||
gst_clock_id_unref (tid);
|
|
||||||
|
|
||||||
out_buf = g_async_queue_pop (data.rtcp_queue);
|
|
||||||
g_assert (out_buf != NULL);
|
g_assert (out_buf != NULL);
|
||||||
g_assert (gst_rtcp_buffer_validate (out_buf));
|
fail_unless (gst_rtcp_buffer_validate (out_buf));
|
||||||
gst_rtcp_buffer_map (out_buf, GST_MAP_READ, &rtcp);
|
gst_rtcp_buffer_map (out_buf, GST_MAP_READ, &rtcp);
|
||||||
g_assert (gst_rtcp_buffer_get_first_packet (&rtcp, &rtcp_packet));
|
g_assert (gst_rtcp_buffer_get_first_packet (&rtcp, &rtcp_packet));
|
||||||
g_assert (gst_rtcp_packet_get_type (&rtcp_packet) == GST_RTCP_TYPE_RR);
|
fail_unless_equals_int (GST_RTCP_TYPE_RR,
|
||||||
g_assert_cmpint (gst_rtcp_packet_get_rb_count (&rtcp_packet), ==, 2);
|
gst_rtcp_packet_get_type (&rtcp_packet));
|
||||||
|
|
||||||
gst_rtcp_packet_get_rb (&rtcp_packet, 0, &ssrc, &fractionlost, &packetslost,
|
fail_unless_equals_int (G_N_ELEMENTS (ssrcs),
|
||||||
&exthighestseq, &jitter, &lsr, &dlsr);
|
gst_rtcp_packet_get_rb_count (&rtcp_packet));
|
||||||
|
|
||||||
g_assert_cmpint (ssrc, ==, 0x01BADBAD);
|
for (j = 0; j < G_N_ELEMENTS (ssrcs); j++) {
|
||||||
|
guint32 ssrc;
|
||||||
|
gst_rtcp_packet_get_rb (&rtcp_packet, j, &ssrc,
|
||||||
|
NULL, NULL, NULL, NULL, NULL, NULL);
|
||||||
|
fail_unless_equals_int (ssrcs[j], ssrc);
|
||||||
|
}
|
||||||
|
|
||||||
gst_rtcp_packet_get_rb (&rtcp_packet, 1, &ssrc, &fractionlost, &packetslost,
|
|
||||||
&exthighestseq, &jitter, &lsr, &dlsr);
|
|
||||||
g_assert_cmpint (ssrc, ==, 0xDEADBEEF);
|
|
||||||
gst_rtcp_buffer_unmap (&rtcp);
|
gst_rtcp_buffer_unmap (&rtcp);
|
||||||
gst_buffer_unref (out_buf);
|
gst_buffer_unref (out_buf);
|
||||||
|
|
||||||
destroy_testharness (&data);
|
session_harness_free (h);
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
|
||||||
/* This verifies that rtpsession will correctly place RBs round-robin
|
/* This verifies that rtpsession will correctly place RBs round-robin
|
||||||
* across multiple SRs when there are too many senders that their RBs
|
* across multiple RRs when there are too many senders that their RBs
|
||||||
* do not fit in one SR */
|
* do not fit in one RR */
|
||||||
GST_START_TEST (test_multiple_senders_roundrobin_rbs)
|
GST_START_TEST (test_multiple_senders_roundrobin_rbs)
|
||||||
{
|
{
|
||||||
TestData data;
|
SessionHarness *h = session_harness_new ();
|
||||||
GstFlowReturn res;
|
GstFlowReturn res;
|
||||||
GstClockID id, tid;
|
|
||||||
GstBuffer *buf;
|
GstBuffer *buf;
|
||||||
GstRTCPBuffer rtcp = GST_RTCP_BUFFER_INIT;
|
GstRTCPBuffer rtcp = GST_RTCP_BUFFER_INIT;
|
||||||
GstRTCPPacket rtcp_packet;
|
GstRTCPPacket rtcp_packet;
|
||||||
GstClockTime time;
|
|
||||||
gint queue_length;
|
|
||||||
gint i, j, k;
|
gint i, j, k;
|
||||||
guint32 ssrc;
|
guint32 ssrc;
|
||||||
GHashTable *sr_ssrcs, *rb_ssrcs, *tmp_set;
|
GHashTable *rb_ssrcs, *tmp_set;
|
||||||
|
|
||||||
setup_testharness (&data, TRUE);
|
g_object_set (h->internal_session, "internal-ssrc", 0xDEADBEEF, NULL);
|
||||||
|
|
||||||
/* only the RTCP thread waits on the clock */
|
for (i = 0; i < 2; i++) { /* cycles between RR reports */
|
||||||
gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id);
|
|
||||||
|
|
||||||
for (i = 0; i < 2; i++) { /* cycles between SR reports */
|
|
||||||
for (j = 0; j < 5; j++) { /* packets per ssrc */
|
for (j = 0; j < 5; j++) { /* packets per ssrc */
|
||||||
gint seq = (i * 5) + j;
|
gint seq = (i * 5) + j;
|
||||||
GST_DEBUG ("Push %i", seq);
|
|
||||||
|
|
||||||
gst_test_clock_advance_time (GST_TEST_CLOCK (data.clock),
|
|
||||||
200 * GST_MSECOND);
|
|
||||||
|
|
||||||
for (k = 0; k < 35; k++) { /* number of ssrcs */
|
for (k = 0; k < 35; k++) { /* number of ssrcs */
|
||||||
buf =
|
buf = generate_test_buffer (seq, 10000 + k);
|
||||||
generate_test_buffer (seq * 200 * GST_MSECOND, FALSE, seq,
|
res = session_harness_recv_rtp (h, buf);
|
||||||
seq * 200, 10000 + k);
|
fail_unless_equals_int (GST_FLOW_OK, res);
|
||||||
res = gst_pad_push (data.src, buf);
|
|
||||||
fail_unless (res == GST_FLOW_OK || res == GST_FLOW_FLUSHING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_DEBUG ("pushed %i", seq);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
queue_length = g_async_queue_length (data.rtcp_queue);
|
|
||||||
|
|
||||||
do {
|
|
||||||
/* crank the RTCP pad thread */
|
|
||||||
time = gst_clock_id_get_time (id);
|
|
||||||
GST_DEBUG ("Advancing time to %" GST_TIME_FORMAT, GST_TIME_ARGS (time));
|
|
||||||
gst_test_clock_set_time (GST_TEST_CLOCK (data.clock), time);
|
|
||||||
tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data.clock));
|
|
||||||
fail_unless_equals_pointer (tid, id);
|
|
||||||
gst_clock_id_unref (id);
|
|
||||||
gst_clock_id_unref (tid);
|
|
||||||
|
|
||||||
/* wait for the RTCP pad thread to output its data
|
|
||||||
* and start waiting on the next timeout */
|
|
||||||
gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock),
|
|
||||||
&id);
|
|
||||||
|
|
||||||
/* and retry as long as there are no new RTCP packets out,
|
|
||||||
* because the RTCP thread may randomly decide to reschedule
|
|
||||||
* the RTCP timeout for later */
|
|
||||||
} while (g_async_queue_length (data.rtcp_queue) == queue_length);
|
|
||||||
|
|
||||||
GST_DEBUG ("RTCP timeout processed");
|
|
||||||
}
|
}
|
||||||
gst_clock_id_unref (id);
|
|
||||||
|
|
||||||
sr_ssrcs = g_hash_table_new (g_direct_hash, g_direct_equal);
|
|
||||||
rb_ssrcs = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
|
rb_ssrcs = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
|
||||||
(GDestroyNotify) g_hash_table_unref);
|
(GDestroyNotify) g_hash_table_unref);
|
||||||
|
|
||||||
/* verify the rtcp packets */
|
/* verify the rtcp packets */
|
||||||
for (i = 0; i < 2 * 35; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
guint expected_rb_count = (i < 35) ? GST_RTCP_MAX_RB_COUNT :
|
guint expected_rb_count = (i < 1) ? GST_RTCP_MAX_RB_COUNT :
|
||||||
(35 - GST_RTCP_MAX_RB_COUNT - 1);
|
(35 - GST_RTCP_MAX_RB_COUNT);
|
||||||
|
|
||||||
GST_DEBUG ("pop %d", i);
|
session_harness_produce_rtcp (h, 1);
|
||||||
|
buf = session_harness_pull_rtcp (h);
|
||||||
buf = g_async_queue_pop (data.rtcp_queue);
|
|
||||||
g_assert (buf != NULL);
|
g_assert (buf != NULL);
|
||||||
g_assert (gst_rtcp_buffer_validate (buf));
|
fail_unless (gst_rtcp_buffer_validate (buf));
|
||||||
|
|
||||||
gst_rtcp_buffer_map (buf, GST_MAP_READ, &rtcp);
|
gst_rtcp_buffer_map (buf, GST_MAP_READ, &rtcp);
|
||||||
g_assert (gst_rtcp_buffer_get_first_packet (&rtcp, &rtcp_packet));
|
fail_unless (gst_rtcp_buffer_get_first_packet (&rtcp, &rtcp_packet));
|
||||||
g_assert_cmpint (gst_rtcp_packet_get_type (&rtcp_packet), ==,
|
fail_unless_equals_int (GST_RTCP_TYPE_RR,
|
||||||
GST_RTCP_TYPE_SR);
|
gst_rtcp_packet_get_type (&rtcp_packet));
|
||||||
|
|
||||||
gst_rtcp_packet_sr_get_sender_info (&rtcp_packet, &ssrc, NULL, NULL, NULL,
|
ssrc = gst_rtcp_packet_rr_get_ssrc (&rtcp_packet);
|
||||||
NULL);
|
fail_unless_equals_int (0xDEADBEEF, ssrc);
|
||||||
g_assert_cmpint (ssrc, >=, 10000);
|
|
||||||
g_assert_cmpint (ssrc, <=, 10035);
|
|
||||||
g_hash_table_add (sr_ssrcs, GUINT_TO_POINTER (ssrc));
|
|
||||||
|
|
||||||
/* inspect the RBs */
|
/* inspect the RBs */
|
||||||
g_assert_cmpint (gst_rtcp_packet_get_rb_count (&rtcp_packet), ==,
|
fail_unless_equals_int (expected_rb_count,
|
||||||
expected_rb_count);
|
gst_rtcp_packet_get_rb_count (&rtcp_packet));
|
||||||
|
|
||||||
if (i < 35) {
|
if (i == 0) {
|
||||||
tmp_set = g_hash_table_new (g_direct_hash, g_direct_equal);
|
tmp_set = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||||
g_hash_table_insert (rb_ssrcs, GUINT_TO_POINTER (ssrc), tmp_set);
|
g_hash_table_insert (rb_ssrcs, GUINT_TO_POINTER (ssrc), tmp_set);
|
||||||
} else {
|
} else {
|
||||||
|
@ -385,196 +331,146 @@ GST_START_TEST (test_multiple_senders_roundrobin_rbs)
|
||||||
|
|
||||||
gst_rtcp_buffer_unmap (&rtcp);
|
gst_rtcp_buffer_unmap (&rtcp);
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
|
|
||||||
/* cycle done, verify all ssrcs have issued SR reports */
|
|
||||||
if ((i + 1) == 35 || (i + 1) == (2 * 35)) {
|
|
||||||
g_assert_cmpint (g_hash_table_size (sr_ssrcs), ==, 35);
|
|
||||||
g_hash_table_remove_all (sr_ssrcs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now verify all other ssrcs have been reported on each ssrc's SR */
|
/* now verify all received ssrcs have been reported */
|
||||||
g_assert_cmpint (g_hash_table_size (rb_ssrcs), ==, 35);
|
fail_unless_equals_int (1, g_hash_table_size (rb_ssrcs));
|
||||||
for (i = 10000; i < 10035; i++) {
|
tmp_set = g_hash_table_lookup (rb_ssrcs, GUINT_TO_POINTER (0xDEADBEEF));
|
||||||
tmp_set = g_hash_table_lookup (rb_ssrcs, GUINT_TO_POINTER (i));
|
g_assert (tmp_set);
|
||||||
g_assert (tmp_set);
|
fail_unless_equals_int (35, g_hash_table_size (tmp_set));
|
||||||
/* SR contains RBs for each other ssrc except the ssrc of the SR */
|
|
||||||
g_assert_cmpint (g_hash_table_size (tmp_set), ==, 34);
|
|
||||||
g_assert (!g_hash_table_contains (tmp_set, GUINT_TO_POINTER (i)));
|
|
||||||
}
|
|
||||||
|
|
||||||
g_hash_table_unref (sr_ssrcs);
|
|
||||||
g_hash_table_unref (rb_ssrcs);
|
g_hash_table_unref (rb_ssrcs);
|
||||||
|
session_harness_free (h);
|
||||||
destroy_testharness (&data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
|
||||||
static void
|
|
||||||
crank_rtcp_thread (TestData * data, GstClockTime * time, GstClockID * id)
|
|
||||||
{
|
|
||||||
gint queue_length;
|
|
||||||
GstClockID *tid;
|
|
||||||
|
|
||||||
queue_length = g_async_queue_length (data->rtcp_queue);
|
|
||||||
do {
|
|
||||||
*time = gst_clock_id_get_time (*id);
|
|
||||||
GST_DEBUG ("Advancing time to %" GST_TIME_FORMAT, GST_TIME_ARGS (*time));
|
|
||||||
if (*time > gst_clock_get_time (data->clock))
|
|
||||||
gst_test_clock_set_time (GST_TEST_CLOCK (data->clock), *time);
|
|
||||||
tid = gst_test_clock_process_next_clock_id (GST_TEST_CLOCK (data->clock));
|
|
||||||
fail_unless_equals_pointer (tid, *id);
|
|
||||||
|
|
||||||
gst_clock_id_unref (tid);
|
|
||||||
gst_clock_id_unref (*id);
|
|
||||||
*id = NULL;
|
|
||||||
|
|
||||||
/* wait for the RTCP pad thread to output its data
|
|
||||||
* and start waiting on the next timeout */
|
|
||||||
gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data->clock), id);
|
|
||||||
|
|
||||||
/* and retry as long as there are no new RTCP packets out,
|
|
||||||
* because the RTCP thread may randomly decide to reschedule
|
|
||||||
* the RTCP timeout for later */
|
|
||||||
} while (g_async_queue_length (data->rtcp_queue) == queue_length);
|
|
||||||
}
|
|
||||||
|
|
||||||
GST_START_TEST (test_internal_sources_timeout)
|
GST_START_TEST (test_internal_sources_timeout)
|
||||||
{
|
{
|
||||||
TestData data;
|
SessionHarness *h = session_harness_new ();
|
||||||
GstClockID id;
|
|
||||||
GstClockTime time;
|
|
||||||
GObject *internal_session;
|
|
||||||
guint internal_ssrc;
|
guint internal_ssrc;
|
||||||
guint32 ssrc;
|
guint32 ssrc;
|
||||||
GstBuffer *buf;
|
GstBuffer *buf;
|
||||||
GstRTCPBuffer rtcp = GST_RTCP_BUFFER_INIT;
|
GstRTCPBuffer rtcp = GST_RTCP_BUFFER_INIT;
|
||||||
GstRTCPPacket rtcp_packet;
|
GstRTCPPacket rtcp_packet;
|
||||||
|
GstRTCPType rtcp_type;
|
||||||
GstFlowReturn res;
|
GstFlowReturn res;
|
||||||
gint i, j;
|
gint i, j;
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
|
gboolean seen_bye;
|
||||||
|
|
||||||
setup_testharness (&data, TRUE);
|
g_object_set (h->internal_session, "internal-ssrc", 0xDEADBEEF, NULL);
|
||||||
g_object_get (data.session, "internal-session", &internal_session, NULL);
|
g_object_get (h->internal_session, "internal-ssrc", &internal_ssrc, NULL);
|
||||||
g_object_set (internal_session, "internal-ssrc", 0xDEADBEEF, NULL);
|
fail_unless_equals_int (0xDEADBEEF, internal_ssrc);
|
||||||
|
|
||||||
/* only the RTCP thread waits on the clock */
|
for (i = 1; i < 4; i++) {
|
||||||
gst_test_clock_wait_for_next_pending_id (GST_TEST_CLOCK (data.clock), &id);
|
buf = generate_test_buffer (i, 0xBEEFDEAD);
|
||||||
|
res = session_harness_recv_rtp (h, buf);
|
||||||
/* crank the RTCP pad thread until it creates a RR for its internal-ssrc
|
fail_unless_equals_int (GST_FLOW_OK, res);
|
||||||
* source, since we have not pushed any RTP packets and it doesn't have
|
}
|
||||||
* any other source available */
|
|
||||||
crank_rtcp_thread (&data, &time, &id);
|
|
||||||
|
|
||||||
g_object_get (internal_session, "internal-ssrc", &internal_ssrc, NULL);
|
|
||||||
g_assert_cmpint (internal_ssrc, ==, 0xDEADBEEF);
|
|
||||||
|
|
||||||
/* verify that rtpsession has sent RR for an internally-created
|
/* verify that rtpsession has sent RR for an internally-created
|
||||||
* RTPSource that is using the internal-ssrc */
|
* RTPSource that is using the internal-ssrc */
|
||||||
buf = g_async_queue_pop (data.rtcp_queue);
|
session_harness_produce_rtcp (h, 1);
|
||||||
g_assert (buf != NULL);
|
buf = session_harness_pull_rtcp (h);
|
||||||
g_assert (gst_rtcp_buffer_validate (buf));
|
|
||||||
|
fail_unless (buf != NULL);
|
||||||
|
fail_unless (gst_rtcp_buffer_validate (buf));
|
||||||
gst_rtcp_buffer_map (buf, GST_MAP_READ, &rtcp);
|
gst_rtcp_buffer_map (buf, GST_MAP_READ, &rtcp);
|
||||||
g_assert (gst_rtcp_buffer_get_first_packet (&rtcp, &rtcp_packet));
|
fail_unless (gst_rtcp_buffer_get_first_packet (&rtcp, &rtcp_packet));
|
||||||
g_assert_cmpint (gst_rtcp_packet_get_type (&rtcp_packet), ==,
|
fail_unless_equals_int (GST_RTCP_TYPE_RR,
|
||||||
GST_RTCP_TYPE_RR);
|
gst_rtcp_packet_get_type (&rtcp_packet));
|
||||||
ssrc = gst_rtcp_packet_rr_get_ssrc (&rtcp_packet);
|
ssrc = gst_rtcp_packet_rr_get_ssrc (&rtcp_packet);
|
||||||
g_assert_cmpint (ssrc, ==, internal_ssrc);
|
fail_unless_equals_int (ssrc, internal_ssrc);
|
||||||
gst_rtcp_buffer_unmap (&rtcp);
|
gst_rtcp_buffer_unmap (&rtcp);
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
|
|
||||||
/* ok, now let's push some RTP packets */
|
/* ok, now let's push some RTP packets */
|
||||||
caps =
|
caps = gst_caps_new_simple ("application/x-rtp",
|
||||||
gst_caps_new_simple ("application/x-rtp", "ssrc", G_TYPE_UINT, 0x01BADBAD,
|
"ssrc", G_TYPE_UINT, 0x01BADBAD, NULL);
|
||||||
NULL);
|
gst_harness_set_src_caps (h->send_rtp_h, caps);
|
||||||
gst_pad_set_caps (data.src, caps);
|
|
||||||
gst_caps_unref (caps);
|
|
||||||
|
|
||||||
for (i = 1; i < 4; i++) {
|
for (i = 1; i < 4; i++) {
|
||||||
gst_test_clock_advance_time (GST_TEST_CLOCK (data.clock),
|
buf = generate_test_buffer (i, 0x01BADBAD);
|
||||||
200 * GST_MSECOND);
|
res = session_harness_send_rtp (h, buf);
|
||||||
buf =
|
fail_unless_equals_int (GST_FLOW_OK, res);
|
||||||
generate_test_buffer (time + i * 200 * GST_MSECOND, FALSE, i, i * 200,
|
|
||||||
0x01BADBAD);
|
|
||||||
res = gst_pad_push (data.src, buf);
|
|
||||||
fail_unless (res == GST_FLOW_OK || res == GST_FLOW_FLUSHING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* internal ssrc must have changed already */
|
/* internal ssrc must have changed already */
|
||||||
g_object_get (internal_session, "internal-ssrc", &internal_ssrc, NULL);
|
g_object_get (h->internal_session, "internal-ssrc", &internal_ssrc, NULL);
|
||||||
g_assert_cmpint (ssrc, !=, internal_ssrc);
|
fail_unless (internal_ssrc != ssrc);
|
||||||
g_assert_cmpint (internal_ssrc, ==, 0x01BADBAD);
|
fail_unless_equals_int (0x01BADBAD, internal_ssrc);
|
||||||
|
|
||||||
/* wait for SR */
|
|
||||||
crank_rtcp_thread (&data, &time, &id);
|
|
||||||
|
|
||||||
/* verify SR and RR */
|
/* verify SR and RR */
|
||||||
j = 0;
|
j = 0;
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
buf = g_async_queue_pop (data.rtcp_queue);
|
session_harness_produce_rtcp (h, 1);
|
||||||
|
buf = session_harness_pull_rtcp (h);
|
||||||
g_assert (buf != NULL);
|
g_assert (buf != NULL);
|
||||||
g_assert (gst_rtcp_buffer_validate (buf));
|
fail_unless (gst_rtcp_buffer_validate (buf));
|
||||||
gst_rtcp_buffer_map (buf, GST_MAP_READ, &rtcp);
|
gst_rtcp_buffer_map (buf, GST_MAP_READ, &rtcp);
|
||||||
g_assert (gst_rtcp_buffer_get_first_packet (&rtcp, &rtcp_packet));
|
fail_unless (gst_rtcp_buffer_get_first_packet (&rtcp, &rtcp_packet));
|
||||||
if (gst_rtcp_packet_get_type (&rtcp_packet) == GST_RTCP_TYPE_SR) {
|
rtcp_type = gst_rtcp_packet_get_type (&rtcp_packet);
|
||||||
|
|
||||||
|
if (rtcp_type == GST_RTCP_TYPE_SR) {
|
||||||
gst_rtcp_packet_sr_get_sender_info (&rtcp_packet, &ssrc, NULL, NULL, NULL,
|
gst_rtcp_packet_sr_get_sender_info (&rtcp_packet, &ssrc, NULL, NULL, NULL,
|
||||||
NULL);
|
NULL);
|
||||||
g_assert_cmpint (ssrc, ==, internal_ssrc);
|
fail_unless_equals_int (internal_ssrc, ssrc);
|
||||||
g_assert_cmpint (ssrc, ==, 0x01BADBAD);
|
fail_unless_equals_int (0x01BADBAD, ssrc);
|
||||||
j |= 0x1;
|
j |= 0x1;
|
||||||
} else if (gst_rtcp_packet_get_type (&rtcp_packet) == GST_RTCP_TYPE_RR) {
|
} else if (rtcp_type == GST_RTCP_TYPE_RR) {
|
||||||
ssrc = gst_rtcp_packet_rr_get_ssrc (&rtcp_packet);
|
ssrc = gst_rtcp_packet_rr_get_ssrc (&rtcp_packet);
|
||||||
g_assert_cmpint (ssrc, !=, internal_ssrc);
|
fail_unless (internal_ssrc != ssrc);
|
||||||
g_assert_cmpint (ssrc, ==, 0xDEADBEEF);
|
fail_unless_equals_int (0xDEADBEEF, ssrc);
|
||||||
j |= 0x2;
|
j |= 0x2;
|
||||||
}
|
}
|
||||||
gst_rtcp_buffer_unmap (&rtcp);
|
gst_rtcp_buffer_unmap (&rtcp);
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
}
|
}
|
||||||
g_assert_cmpint (j, ==, 0x3); /* verify we got both SR and RR */
|
fail_unless_equals_int (0x3, j); /* verify we got both SR and RR */
|
||||||
|
|
||||||
/* go 30 seconds in the future and observe both sources timing out:
|
/* go 30 seconds in the future and observe both sources timing out:
|
||||||
* 0xDEADBEEF -> BYE, 0x01BADBAD -> becomes receiver only */
|
* 0xDEADBEEF -> BYE, 0x01BADBAD -> becomes receiver only */
|
||||||
gst_test_clock_advance_time (GST_TEST_CLOCK (data.clock), 30 * GST_SECOND);
|
fail_unless (session_harness_advance_and_crank (h, 30 * GST_SECOND));
|
||||||
crank_rtcp_thread (&data, &time, &id);
|
|
||||||
|
|
||||||
/* verify BYE and RR */
|
/* verify BYE and RR */
|
||||||
j = 0;
|
j = 0;
|
||||||
for (i = 0; i < 2; i++) {
|
seen_bye = FALSE;
|
||||||
buf = g_async_queue_pop (data.rtcp_queue);
|
while (!seen_bye) {
|
||||||
g_assert (buf != NULL);
|
session_harness_produce_rtcp (h, 1);
|
||||||
g_assert (gst_rtcp_buffer_validate (buf));
|
buf = session_harness_pull_rtcp (h);
|
||||||
|
fail_unless (buf != NULL);
|
||||||
|
fail_unless (gst_rtcp_buffer_validate (buf));
|
||||||
gst_rtcp_buffer_map (buf, GST_MAP_READ, &rtcp);
|
gst_rtcp_buffer_map (buf, GST_MAP_READ, &rtcp);
|
||||||
|
fail_unless (gst_rtcp_buffer_get_first_packet (&rtcp, &rtcp_packet));
|
||||||
|
rtcp_type = gst_rtcp_packet_get_type (&rtcp_packet);
|
||||||
|
|
||||||
g_assert (gst_rtcp_buffer_get_first_packet (&rtcp, &rtcp_packet));
|
if (rtcp_type == GST_RTCP_TYPE_RR) {
|
||||||
g_assert_cmpint (gst_rtcp_packet_get_type (&rtcp_packet), ==,
|
ssrc = gst_rtcp_packet_rr_get_ssrc (&rtcp_packet);
|
||||||
GST_RTCP_TYPE_RR);
|
if (ssrc == 0x01BADBAD) {
|
||||||
ssrc = gst_rtcp_packet_rr_get_ssrc (&rtcp_packet);
|
j |= 0x1;
|
||||||
if (ssrc == 0x01BADBAD) {
|
fail_unless_equals_int (internal_ssrc, ssrc);
|
||||||
j |= 0x1;
|
/* 2 => RR, SDES. There is no BYE here */
|
||||||
g_assert_cmpint (ssrc, ==, internal_ssrc);
|
fail_unless_equals_int (2, gst_rtcp_buffer_get_packet_count (&rtcp));
|
||||||
/* 2 => RR, SDES. There is no BYE here */
|
} else if (ssrc == 0xDEADBEEF) {
|
||||||
g_assert_cmpint (gst_rtcp_buffer_get_packet_count (&rtcp), ==, 2);
|
j |= 0x2;
|
||||||
} else if (ssrc == 0xDEADBEEF) {
|
g_assert_cmpint (ssrc, !=, internal_ssrc);
|
||||||
j |= 0x2;
|
/* 3 => RR, SDES, BYE */
|
||||||
g_assert_cmpint (ssrc, !=, internal_ssrc);
|
if (gst_rtcp_buffer_get_packet_count (&rtcp) == 3) {
|
||||||
/* 3 => RR, SDES, BYE */
|
fail_unless (gst_rtcp_packet_move_to_next (&rtcp_packet));
|
||||||
g_assert_cmpint (gst_rtcp_buffer_get_packet_count (&rtcp), ==, 3);
|
fail_unless (gst_rtcp_packet_move_to_next (&rtcp_packet));
|
||||||
g_assert (gst_rtcp_packet_move_to_next (&rtcp_packet));
|
fail_unless_equals_int (GST_RTCP_TYPE_BYE,
|
||||||
g_assert (gst_rtcp_packet_move_to_next (&rtcp_packet));
|
gst_rtcp_packet_get_type (&rtcp_packet));
|
||||||
g_assert_cmpint (gst_rtcp_packet_get_type (&rtcp_packet), ==,
|
seen_bye = TRUE;
|
||||||
GST_RTCP_TYPE_BYE);
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_rtcp_buffer_unmap (&rtcp);
|
gst_rtcp_buffer_unmap (&rtcp);
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
}
|
}
|
||||||
g_assert_cmpint (j, ==, 0x3); /* verify we got both BYE and RR */
|
fail_unless_equals_int (0x3, j); /* verify we got both BYE and RR */
|
||||||
gst_clock_id_unref (id);
|
|
||||||
|
|
||||||
g_object_unref (internal_session);
|
session_harness_free (h);
|
||||||
destroy_testharness (&data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
@ -599,43 +495,38 @@ on_app_rtcp_cb (GObject * session, guint subtype, guint ssrc,
|
||||||
|
|
||||||
GST_START_TEST (test_receive_rtcp_app_packet)
|
GST_START_TEST (test_receive_rtcp_app_packet)
|
||||||
{
|
{
|
||||||
GstHarness *h;
|
SessionHarness *h = session_harness_new ();
|
||||||
GstBuffer *buffer;
|
GstBuffer *buf;
|
||||||
GstRTCPBuffer rtcp = GST_RTCP_BUFFER_INIT;
|
GstRTCPBuffer rtcp = GST_RTCP_BUFFER_INIT;
|
||||||
GstRTCPPacket packet;
|
GstRTCPPacket packet;
|
||||||
RTCPAppResult result = { 0 };
|
RTCPAppResult result = { 0 };
|
||||||
GstElement *internal_session;
|
|
||||||
guint8 data[] = { 0x11, 0x22, 0x33, 0x44 };
|
guint8 data[] = { 0x11, 0x22, 0x33, 0x44 };
|
||||||
|
|
||||||
h = gst_harness_new_with_padnames ("rtpsession", "recv_rtcp_sink", NULL);
|
g_signal_connect (h->internal_session, "on-app-rtcp",
|
||||||
g_object_get (h->element, "internal-session", &internal_session, NULL);
|
|
||||||
|
|
||||||
g_signal_connect (internal_session, "on-app-rtcp",
|
|
||||||
G_CALLBACK (on_app_rtcp_cb), &result);
|
G_CALLBACK (on_app_rtcp_cb), &result);
|
||||||
|
|
||||||
/* Push APP buffer with no data */
|
/* Push APP buffer with no data */
|
||||||
buffer = gst_rtcp_buffer_new (1000);
|
buf = gst_rtcp_buffer_new (1000);
|
||||||
fail_unless (gst_rtcp_buffer_map (buffer, GST_MAP_READWRITE, &rtcp));
|
fail_unless (gst_rtcp_buffer_map (buf, GST_MAP_READWRITE, &rtcp));
|
||||||
fail_unless (gst_rtcp_buffer_add_packet (&rtcp, GST_RTCP_TYPE_APP, &packet));
|
fail_unless (gst_rtcp_buffer_add_packet (&rtcp, GST_RTCP_TYPE_APP, &packet));
|
||||||
gst_rtcp_packet_app_set_subtype (&packet, 21);
|
gst_rtcp_packet_app_set_subtype (&packet, 21);
|
||||||
gst_rtcp_packet_app_set_ssrc (&packet, 0x11111111);
|
gst_rtcp_packet_app_set_ssrc (&packet, 0x11111111);
|
||||||
gst_rtcp_packet_app_set_name (&packet, "Test");
|
gst_rtcp_packet_app_set_name (&packet, "Test");
|
||||||
gst_rtcp_buffer_unmap (&rtcp);
|
gst_rtcp_buffer_unmap (&rtcp);
|
||||||
|
|
||||||
gst_harness_set_src_caps_str (h, "application/x-rtcp");
|
fail_unless_equals_int (GST_FLOW_OK, session_harness_recv_rtcp (h, buf));
|
||||||
fail_unless_equals_int (gst_harness_push (h, buffer), GST_FLOW_OK);
|
|
||||||
|
|
||||||
fail_unless_equals_int (result.subtype, 21);
|
fail_unless_equals_int (21, result.subtype);
|
||||||
fail_unless_equals_int (result.ssrc, 0x11111111);
|
fail_unless_equals_int (0x11111111, result.ssrc);
|
||||||
fail_unless_equals_string (result.name, "Test");
|
fail_unless_equals_string ("Test", result.name);
|
||||||
fail_unless_equals_pointer (result.data, NULL);
|
fail_unless_equals_pointer (NULL, result.data);
|
||||||
|
|
||||||
g_free (result.name);
|
g_free (result.name);
|
||||||
|
|
||||||
/* Push APP buffer with data */
|
/* Push APP buffer with data */
|
||||||
memset (&result, 0, sizeof (result));
|
memset (&result, 0, sizeof (result));
|
||||||
buffer = gst_rtcp_buffer_new (1000);
|
buf = gst_rtcp_buffer_new (1000);
|
||||||
fail_unless (gst_rtcp_buffer_map (buffer, GST_MAP_READWRITE, &rtcp));
|
fail_unless (gst_rtcp_buffer_map (buf, GST_MAP_READWRITE, &rtcp));
|
||||||
fail_unless (gst_rtcp_buffer_add_packet (&rtcp, GST_RTCP_TYPE_APP, &packet));
|
fail_unless (gst_rtcp_buffer_add_packet (&rtcp, GST_RTCP_TYPE_APP, &packet));
|
||||||
gst_rtcp_packet_app_set_subtype (&packet, 22);
|
gst_rtcp_packet_app_set_subtype (&packet, 22);
|
||||||
gst_rtcp_packet_app_set_ssrc (&packet, 0x22222222);
|
gst_rtcp_packet_app_set_ssrc (&packet, 0x22222222);
|
||||||
|
@ -644,18 +535,17 @@ GST_START_TEST (test_receive_rtcp_app_packet)
|
||||||
memcpy (gst_rtcp_packet_app_get_data (&packet), data, sizeof (data));
|
memcpy (gst_rtcp_packet_app_get_data (&packet), data, sizeof (data));
|
||||||
gst_rtcp_buffer_unmap (&rtcp);
|
gst_rtcp_buffer_unmap (&rtcp);
|
||||||
|
|
||||||
fail_unless_equals_int (gst_harness_push (h, buffer), GST_FLOW_OK);
|
fail_unless_equals_int (GST_FLOW_OK, session_harness_recv_rtcp (h, buf));
|
||||||
|
|
||||||
fail_unless_equals_int (result.subtype, 22);
|
fail_unless_equals_int (22, result.subtype);
|
||||||
fail_unless_equals_int (result.ssrc, 0x22222222);
|
fail_unless_equals_int (0x22222222, result.ssrc);
|
||||||
fail_unless_equals_string (result.name, "Test");
|
fail_unless_equals_string ("Test", result.name);
|
||||||
fail_unless (gst_buffer_memcmp (result.data, 0, data, sizeof (data)) == 0);
|
fail_unless (gst_buffer_memcmp (result.data, 0, data, sizeof (data)) == 0);
|
||||||
|
|
||||||
g_free (result.name);
|
g_free (result.name);
|
||||||
gst_buffer_unref (result.data);
|
gst_buffer_unref (result.data);
|
||||||
|
|
||||||
gst_object_unref (internal_session);
|
session_harness_free (h);
|
||||||
gst_harness_teardown (h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
@ -768,44 +658,27 @@ create_bye_rtcp (guint32 ssrc)
|
||||||
|
|
||||||
GST_START_TEST (test_ignore_suspicious_bye)
|
GST_START_TEST (test_ignore_suspicious_bye)
|
||||||
{
|
{
|
||||||
GstHarness *h_rtcp = NULL;
|
SessionHarness *h = session_harness_new ();
|
||||||
GstHarness *h_send = NULL;
|
|
||||||
gboolean cb_called = FALSE;
|
gboolean cb_called = FALSE;
|
||||||
GstTestClock *testclock = GST_TEST_CLOCK (gst_test_clock_new ());
|
|
||||||
|
|
||||||
/* use testclock as the systemclock to capture the rtcp thread waits */
|
|
||||||
gst_system_clock_set_default (GST_CLOCK (testclock));
|
|
||||||
|
|
||||||
h_rtcp =
|
|
||||||
gst_harness_new_with_padnames ("rtpsession", "recv_rtcp_sink",
|
|
||||||
"send_rtcp_src");
|
|
||||||
h_send =
|
|
||||||
gst_harness_new_with_element (h_rtcp->element, "send_rtp_sink",
|
|
||||||
"send_rtp_src");
|
|
||||||
|
|
||||||
/* connect to the stats-reporting */
|
/* connect to the stats-reporting */
|
||||||
g_signal_connect (h_rtcp->element, "notify::stats",
|
g_signal_connect (h->session, "notify::stats",
|
||||||
G_CALLBACK (suspicious_bye_cb), &cb_called);
|
G_CALLBACK (suspicious_bye_cb), &cb_called);
|
||||||
|
|
||||||
/* Push RTP buffer making our internal SSRC=0xDEADBEEF */
|
/* Push RTP buffer making our internal SSRC=0xDEADBEEF */
|
||||||
gst_harness_set_src_caps_str (h_send,
|
fail_unless_equals_int (GST_FLOW_OK,
|
||||||
"application/x-rtp,ssrc=(uint)0xDEADBEEF,"
|
session_harness_send_rtp (h, generate_test_buffer (0, 0xDEADBEEF)));
|
||||||
"clock-rate=90000,seqnum-offset=(uint)12345");
|
|
||||||
gst_harness_push (h_send,
|
|
||||||
generate_test_buffer (0, FALSE, 12345, 0, 0xDEADBEEF));
|
|
||||||
|
|
||||||
/* Push BYE RTCP with internal SSRC (0xDEADBEEF) */
|
/* Receive BYE RTCP referencing our internal SSRC(!?!) (0xDEADBEEF) */
|
||||||
gst_harness_set_src_caps_str (h_rtcp, "application/x-rtcp");
|
fail_unless_equals_int (GST_FLOW_OK,
|
||||||
gst_harness_push (h_rtcp, create_bye_rtcp (0xDEADBEEF));
|
session_harness_recv_rtcp (h, create_bye_rtcp (0xDEADBEEF)));
|
||||||
|
|
||||||
/* "crank" and check the stats */
|
/* "crank" and check the stats */
|
||||||
g_assert (gst_test_clock_crank (testclock));
|
session_harness_crank_clock (h);
|
||||||
gst_buffer_unref (gst_harness_pull (h_rtcp));
|
gst_buffer_unref (session_harness_pull_rtcp (h));
|
||||||
fail_unless (cb_called);
|
fail_unless (cb_called);
|
||||||
|
|
||||||
gst_harness_teardown (h_send);
|
session_harness_free (h);
|
||||||
gst_harness_teardown (h_rtcp);
|
|
||||||
gst_object_unref (testclock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
|
Loading…
Reference in a new issue