tests: Add test for RTP header extension functions
authorOlivier CrĂȘte <olivier.crete@collabora.co.uk>
Fri, 20 Aug 2010 19:30:08 +0000 (15:30 -0400)
committerWim Taymans <wim.taymans@collabora.co.uk>
Tue, 5 Oct 2010 14:19:14 +0000 (16:19 +0200)
tests/check/libs/rtp.c

index e19c96c..a40262d 100644 (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;