From 7612c137bdb6d868213806a091e2df35854f3815 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Fri, 20 Aug 2010 15:30:08 -0400 Subject: [PATCH] tests: Add test for RTP header extension functions --- tests/check/libs/rtp.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/tests/check/libs/rtp.c b/tests/check/libs/rtp.c index e19c96c..a40262d 100644 --- a/tests/check/libs/rtp.c +++ b/tests/check/libs/rtp.c @@ -210,7 +210,9 @@ GST_START_TEST (test_rtp_buffer_set_extension_data) guint8 *data; guint16 bits; guint size; + guint8 misc_data[4] = { 1, 2, 3, 4 }; gpointer pointer; + guint8 appbits; /* check GstRTPHeader structure alignment and packing */ buf = gst_rtp_buffer_new_allocate (4, 0, 0); @@ -244,6 +246,122 @@ GST_START_TEST (test_rtp_buffer_set_extension_data) pointer = gst_rtp_buffer_get_payload (buf); fail_unless (pointer == GST_BUFFER_DATA (buf) + 24); gst_buffer_unref (buf); + + /* Test header extensions with a one byte header */ + buf = gst_rtp_buffer_new_allocate (20, 0, 0); + fail_unless (gst_rtp_buffer_get_extension (buf) == FALSE); + + fail_unless (gst_rtp_buffer_add_extension_onebyte_header (buf, 5, + misc_data, 2) == TRUE); + fail_unless (gst_rtp_buffer_get_extension_data (buf, &bits, &pointer, &size)); + fail_unless (bits == 0xBEDE); + fail_unless (size == 1); + data = (guint8 *) pointer; + fail_unless (data[0] == ((5 << 4) | 1)); + fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 2, + 1, &pointer, &size) == FALSE); + fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, + 2, &pointer, &size) == FALSE); + fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, + 1, &pointer, &size) == TRUE); + fail_unless (size == 2); + fail_unless (memcmp (pointer, misc_data, 2) == 0); + + fail_unless (gst_rtp_buffer_add_extension_onebyte_header (buf, 5, + misc_data, 4) == TRUE); + fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, + 1, &pointer, &size) == TRUE); + fail_unless (size == 2); + fail_unless (memcmp (pointer, misc_data, 2) == 0); + fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, + 2, &pointer, &size) == TRUE); + fail_unless (size == 4); + fail_unless (memcmp (pointer, misc_data, 4) == 0); + fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, + 3, &pointer, &size) == FALSE); + fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 2, + 1, &pointer, &size) == FALSE); + + fail_unless (gst_rtp_buffer_add_extension_onebyte_header (buf, 6, + misc_data, 2) == TRUE); + fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, + 1, &pointer, &size) == TRUE); + fail_unless (size == 2); + fail_unless (memcmp (pointer, misc_data, 2) == 0); + fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, + 2, &pointer, &size) == TRUE); + fail_unless (size == 4); + fail_unless (memcmp (pointer, misc_data, 4) == 0); + fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, + 3, &pointer, &size) == FALSE); + fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 2, + 1, &pointer, &size) == FALSE); + fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 6, + 2, &pointer, &size) == FALSE); + fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, + 1, &pointer, &size) == TRUE); + fail_unless (size == 2); + fail_unless (memcmp (pointer, misc_data, 2) == 0); + gst_buffer_unref (buf); + + /* Test header extensions with a two bytes header */ + buf = gst_rtp_buffer_new_allocate (20, 0, 0); + fail_unless (gst_rtp_buffer_get_extension (buf) == FALSE); + + fail_unless (gst_rtp_buffer_add_extension_twobytes_header (buf, 0, 5, + misc_data, 2) == TRUE); + fail_unless (gst_rtp_buffer_get_extension_data (buf, &bits, &pointer, &size)); + g_debug ("%X", appbits); + fail_unless (bits == 0x100 << 4); + fail_unless (size == 1); + data = (guint8 *) pointer; + fail_unless (data[0] == 5); + fail_unless (data[1] == 2); + fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 2, + 1, &pointer, &size) == FALSE); + fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, + 2, &pointer, &size) == FALSE); + fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, + 1, &pointer, &size) == TRUE); + fail_unless (size == 2); + fail_unless (memcmp (pointer, misc_data, 2) == 0); + + fail_unless (gst_rtp_buffer_add_extension_twobytes_header (buf, 0, 5, + misc_data, 4) == TRUE); + fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, + 1, &pointer, &size) == TRUE); + fail_unless (size == 2); + fail_unless (memcmp (pointer, misc_data, 2) == 0); + fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, + 2, &pointer, &size) == TRUE); + fail_unless (size == 4); + fail_unless (memcmp (pointer, misc_data, 4) == 0); + fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, + 3, &pointer, &size) == FALSE); + fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 2, + 1, &pointer, &size) == FALSE); + + fail_unless (gst_rtp_buffer_add_extension_twobytes_header (buf, 0, 6, + misc_data, 2) == TRUE); + fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, + 1, &pointer, &size) == TRUE); + fail_unless (size == 2); + fail_unless (memcmp (pointer, misc_data, 2) == 0); + fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, + 2, &pointer, &size) == TRUE); + fail_unless (size == 4); + fail_unless (memcmp (pointer, misc_data, 4) == 0); + fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, + 3, &pointer, &size) == FALSE); + fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 2, + 1, &pointer, &size) == FALSE); + fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 6, + 2, &pointer, &size) == FALSE); + fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, + 1, &pointer, &size) == TRUE); + fail_unless (size == 2); + fail_unless (memcmp (pointer, misc_data, 2) == 0); + gst_buffer_unref (buf); } GST_END_TEST; -- 2.7.4