From d06df554a9fa6ac574d184ee439a97b2fec439c1 Mon Sep 17 00:00:00 2001 From: Bernard B Date: Wed, 14 May 2008 13:43:12 +0000 Subject: [PATCH] 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 * 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. --- ChangeLog | 11 ++++++ gst-libs/gst/rtp/gstrtpbuffer.c | 12 ++---- tests/check/libs/rtp.c | 87 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea71240..71e28d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-05-14 Wim Taymans + + Patch by: Bernard B + + * 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 * gst/adder/gstadder.c: (gst_adder_setcaps), diff --git a/gst-libs/gst/rtp/gstrtpbuffer.c b/gst-libs/gst/rtp/gstrtpbuffer.c index 55193b7..aef6fc9 100644 --- a/gst-libs/gst/rtp/gstrtpbuffer.c +++ b/gst-libs/gst/rtp/gstrtpbuffer.c @@ -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); } /** diff --git a/tests/check/libs/rtp.c b/tests/check/libs/rtp.c index 04f9810..078778c 100644 --- a/tests/check/libs/rtp.c +++ b/tests/check/libs/rtp.c @@ -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; } -- 2.7.4