tests: Add test for RTP header extension functions

This commit is contained in:
Olivier Crête 2010-08-20 15:30:08 -04:00 committed by Wim Taymans
parent 484871b495
commit 7612c137bd

View file

@ -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;