gst-libs/gst/rtp/gstrtpbuffer.c: Fix seqnum compare function for bordercase values and fix the docs again. Fixes #533...

Original commit message from CVS:
Patch by: Bernard B <b-gnome at largestprime dot net>
* gst-libs/gst/rtp/gstrtpbuffer.c: (gst_rtp_buffer_compare_seqnum):
Fix seqnum compare function for bordercase values and fix the docs
again. Fixes #533075.
* tests/check/libs/rtp.c: (GST_START_TEST), (rtp_suite):
Add a testcase for seqnum compare function.
This commit is contained in:
Bernard B 2008-05-14 13:43:12 +00:00 committed by Wim Taymans
parent 6720c5beb8
commit d06df554a9
3 changed files with 101 additions and 9 deletions

View file

@ -1,3 +1,14 @@
2008-05-14 Wim Taymans <wim.taymans@collabora.co.uk>
Patch by: Bernard B <b-gnome at largestprime dot net>
* gst-libs/gst/rtp/gstrtpbuffer.c: (gst_rtp_buffer_compare_seqnum):
Fix seqnum compare function for bordercase values and fix the docs
again. Fixes #533075.
* tests/check/libs/rtp.c: (GST_START_TEST), (rtp_suite):
Add a testcase for seqnum compare function.
2008-05-14 Sebastian Dröge <slomo@circular-chaos.org>
* gst/adder/gstadder.c: (gst_adder_setcaps),

View file

@ -1033,21 +1033,15 @@ gst_rtp_buffer_default_clock_rate (guint8 payload_type)
* Compare two sequence numbers, taking care of wraparounds. This function
* returns the difference between @seqnum1 and @seqnum2.
*
* Returns: a negative value if @seqnum1 is before @seqnum2, 0 if they are equal
* or a positive value if @seqnum1 is bigger than @segnum2.
* Returns: a negative value if @seqnum1 is bigger than @seqnum2, 0 if they
* are equal or a positive value if @seqnum1 is smaller than @segnum2.
*
* Since: 0.10.15
*/
gint
gst_rtp_buffer_compare_seqnum (guint16 seqnum1, guint16 seqnum2)
{
/* check if diff more than half of the 16bit range */
if (abs (seqnum2 - seqnum1) > (1 << 15)) {
/* one of a/b has wrapped */
return seqnum1 - seqnum2;
} else {
return seqnum2 - seqnum1;
}
return (gint16) (seqnum2 - seqnum1);
}
/**

View file

@ -174,6 +174,92 @@ GST_START_TEST (test_rtp_buffer_set_extension_data)
GST_END_TEST;
GST_START_TEST (test_rtp_seqnum_compare)
{
#define ASSERT_COMP(a,b,c) fail_unless (gst_rtp_buffer_compare_seqnum ((guint16)a,(guint16)b) == c);
ASSERT_COMP (0xfffe, 0xfffd, -1);
ASSERT_COMP (0xffff, 0xfffe, -1);
ASSERT_COMP (0x0000, 0xffff, -1);
ASSERT_COMP (0x0001, 0x0000, -1);
ASSERT_COMP (0x0002, 0x0001, -1);
ASSERT_COMP (0xffff, 0xfffd, -2);
ASSERT_COMP (0x0000, 0xfffd, -3);
ASSERT_COMP (0x0001, 0xfffd, -4);
ASSERT_COMP (0x0002, 0xfffd, -5);
ASSERT_COMP (0x7ffe, 0x7ffd, -1);
ASSERT_COMP (0x7fff, 0x7ffe, -1);
ASSERT_COMP (0x8000, 0x7fff, -1);
ASSERT_COMP (0x8001, 0x8000, -1);
ASSERT_COMP (0x8002, 0x8001, -1);
ASSERT_COMP (0x7fff, 0x7ffd, -2);
ASSERT_COMP (0x8000, 0x7ffd, -3);
ASSERT_COMP (0x8001, 0x7ffd, -4);
ASSERT_COMP (0x8002, 0x7ffd, -5);
ASSERT_COMP (0x7ffd, 0xffff, -0x7ffe);
ASSERT_COMP (0x7ffe, 0x0000, -0x7ffe);
ASSERT_COMP (0x7fff, 0x0001, -0x7ffe);
ASSERT_COMP (0x7fff, 0x0000, -0x7fff);
ASSERT_COMP (0x8000, 0x0001, -0x7fff);
ASSERT_COMP (0x8001, 0x0002, -0x7fff);
ASSERT_COMP (0xfffd, 0x7ffe, -0x7fff);
ASSERT_COMP (0xfffe, 0x7fff, -0x7fff);
ASSERT_COMP (0xffff, 0x8000, -0x7fff);
ASSERT_COMP (0x0000, 0x8001, -0x7fff);
ASSERT_COMP (0x0001, 0x8002, -0x7fff);
ASSERT_COMP (0xfffe, 0x7ffe, -0x8000);
ASSERT_COMP (0xffff, 0x7fff, -0x8000);
ASSERT_COMP (0x0000, 0x8000, -0x8000);
ASSERT_COMP (0x0001, 0x8001, -0x8000);
ASSERT_COMP (0x7ffe, 0xfffe, -0x8000);
ASSERT_COMP (0x7fff, 0xffff, -0x8000);
ASSERT_COMP (0x8000, 0x0000, -0x8000);
ASSERT_COMP (0x8001, 0x0001, -0x8000);
ASSERT_COMP (0x0001, 0x0002, 1);
ASSERT_COMP (0x0000, 0x0001, 1);
ASSERT_COMP (0xffff, 0x0000, 1);
ASSERT_COMP (0xfffe, 0xffff, 1);
ASSERT_COMP (0xfffd, 0xfffe, 1);
ASSERT_COMP (0x0000, 0x0002, 2);
ASSERT_COMP (0xffff, 0x0002, 3);
ASSERT_COMP (0xfffe, 0x0002, 4);
ASSERT_COMP (0xfffd, 0x0002, 5);
ASSERT_COMP (0x8001, 0x8002, 1);
ASSERT_COMP (0x8000, 0x8001, 1);
ASSERT_COMP (0x7fff, 0x8000, 1);
ASSERT_COMP (0x7ffe, 0x7fff, 1);
ASSERT_COMP (0x7ffd, 0x7ffe, 1);
ASSERT_COMP (0x8000, 0x8002, 2);
ASSERT_COMP (0x7fff, 0x8002, 3);
ASSERT_COMP (0x7ffe, 0x8002, 4);
ASSERT_COMP (0x7ffd, 0x8002, 5);
ASSERT_COMP (0xfffe, 0x7ffd, 0x7fff);
ASSERT_COMP (0xffff, 0x7ffe, 0x7fff);
ASSERT_COMP (0x0000, 0x7fff, 0x7fff);
ASSERT_COMP (0x0001, 0x8000, 0x7fff);
ASSERT_COMP (0x0002, 0x8001, 0x7fff);
ASSERT_COMP (0x7ffe, 0xfffd, 0x7fff);
ASSERT_COMP (0x7fff, 0xfffe, 0x7fff);
ASSERT_COMP (0x8000, 0xffff, 0x7fff);
ASSERT_COMP (0x8001, 0x0000, 0x7fff);
ASSERT_COMP (0x8002, 0x0001, 0x7fff);
#undef ASSERT_COMP
}
GST_END_TEST;
static Suite *
rtp_suite (void)
{
@ -183,6 +269,7 @@ rtp_suite (void)
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_rtp_buffer);
tcase_add_test (tc_chain, test_rtp_buffer_set_extension_data);
tcase_add_test (tc_chain, test_rtp_seqnum_compare);
return s;
}