From: Olivier Crete Date: Mon, 8 Dec 2008 12:08:32 +0000 (+0000) Subject: gst-libs/gst/rtp/gstrtcpbuffer.*: Implement gst_rtcp_packet_remove(). Fixes #563174. X-Git-Tag: 1.19.3~511^2~10150 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3c9df39c15c4ca0db15ab3e103f68d7b88c84e59;p=platform%2Fupstream%2Fgstreamer.git gst-libs/gst/rtp/gstrtcpbuffer.*: Implement gst_rtcp_packet_remove(). Fixes #563174. Original commit message from CVS: Patch by: Olivier Crete * gst-libs/gst/rtp/gstrtcpbuffer.c: (gst_rtcp_packet_remove): * gst-libs/gst/rtp/gstrtcpbuffer.h: Implement gst_rtcp_packet_remove(). Fixes #563174. * tests/check/libs/rtp.c: (GST_START_TEST), (rtp_suite): Add unit test for some RTCP functions. --- diff --git a/ChangeLog b/ChangeLog index 3f03b55..760ec54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-12-08 Wim Taymans + + Patch by: Olivier Crete + + * gst-libs/gst/rtp/gstrtcpbuffer.c: (gst_rtcp_packet_remove): + * gst-libs/gst/rtp/gstrtcpbuffer.h: + Implement gst_rtcp_packet_remove(). Fixes #563174. + + * tests/check/libs/rtp.c: (GST_START_TEST), (rtp_suite): + Add unit test for some RTCP functions. + 2008-12-04 Sebastian Dröge * configure.ac: diff --git a/gst-libs/gst/rtp/gstrtcpbuffer.c b/gst-libs/gst/rtp/gstrtcpbuffer.c index d5d49fa..b7172c6 100644 --- a/gst-libs/gst/rtp/gstrtcpbuffer.c +++ b/gst-libs/gst/rtp/gstrtcpbuffer.c @@ -486,17 +486,34 @@ no_space: * gst_rtcp_packet_remove: * @packet: a #GstRTCPPacket * - * Removes the packet pointed to by @packet. + * Removes the packet pointed to by @packet and moves pointer to the next one * - * Note: Not implemented. + * Returns: TRUE if @packet is pointing to a valid packet after calling this + * function. */ -void +gboolean gst_rtcp_packet_remove (GstRTCPPacket * packet) { - g_return_if_fail (packet != NULL); - g_return_if_fail (packet->type != GST_RTCP_TYPE_INVALID); + gboolean ret = FALSE; + guint offset = 0; - g_warning ("not implemented"); + g_return_val_if_fail (packet != NULL, FALSE); + g_return_val_if_fail (packet->type != GST_RTCP_TYPE_INVALID, FALSE); + + /* The next packet starts at offset + length + 4 (the header) */ + offset = packet->offset + (packet->length << 2) + 4; + + /* Overwrite this packet with the rest of the data */ + memmove (GST_BUFFER_DATA (packet->buffer) + packet->offset, + GST_BUFFER_DATA (packet->buffer) + offset, + GST_BUFFER_SIZE (packet->buffer) - offset); + + /* try to read next header */ + ret = read_packet_header (packet); + if (!ret) + packet->type = GST_RTCP_TYPE_INVALID; + + return ret; } /** diff --git a/gst-libs/gst/rtp/gstrtcpbuffer.h b/gst-libs/gst/rtp/gstrtcpbuffer.h index 57cd6c8..9c908a8 100644 --- a/gst-libs/gst/rtp/gstrtcpbuffer.h +++ b/gst-libs/gst/rtp/gstrtcpbuffer.h @@ -169,7 +169,7 @@ gboolean gst_rtcp_packet_move_to_next (GstRTCPPacket *packet); gboolean gst_rtcp_buffer_add_packet (GstBuffer *buffer, GstRTCPType type, GstRTCPPacket *packet); -void gst_rtcp_packet_remove (GstRTCPPacket *packet); +gboolean gst_rtcp_packet_remove (GstRTCPPacket *packet); /* working with packets */ gboolean gst_rtcp_packet_get_padding (GstRTCPPacket *packet); diff --git a/tests/check/libs/rtp.c b/tests/check/libs/rtp.c index 1ce3aae..3461800 100644 --- a/tests/check/libs/rtp.c +++ b/tests/check/libs/rtp.c @@ -25,6 +25,7 @@ #include #include +#include #include #define RTP_HEADER_LEN 12 @@ -261,6 +262,103 @@ GST_START_TEST (test_rtp_seqnum_compare) GST_END_TEST; +GST_START_TEST (test_rtcp_buffer) +{ + GstBuffer *buf; + GstRTCPPacket packet; + guint8 *data; + + buf = gst_rtcp_buffer_new (1400); + fail_unless (buf != NULL); + fail_unless_equals_int (GST_BUFFER_SIZE (buf), 1400); + data = GST_BUFFER_DATA (buf); + + fail_unless (gst_rtcp_buffer_get_first_packet (buf, &packet) == FALSE); + fail_unless (gst_rtcp_buffer_get_packet_count (buf) == 0); + fail_unless (gst_rtcp_buffer_validate (buf) == FALSE); + + /* add an SR packet */ + fail_unless (gst_rtcp_buffer_add_packet (buf, GST_RTCP_TYPE_SR, + &packet) == TRUE); + + fail_unless (gst_rtcp_packet_get_padding (&packet) == 0); + fail_unless (gst_rtcp_packet_get_count (&packet) == 0); + fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_SR); + fail_unless (gst_rtcp_packet_get_length (&packet) == 6); + + gst_rtcp_packet_sr_set_sender_info (&packet, 0x44556677, + G_GUINT64_CONSTANT (1), 0x11111111, 101, 123456); + { + guint32 ssrc; + guint64 ntptime; + guint32 rtptime; + guint32 packet_count; + guint32 octet_count; + + gst_rtcp_packet_sr_get_sender_info (&packet, &ssrc, &ntptime, &rtptime, + &packet_count, &octet_count); + + fail_unless (ssrc == 0x44556677); + fail_unless (ntptime == G_GUINT64_CONSTANT (1)); + fail_unless (rtptime == 0x11111111); + fail_unless (packet_count == 101); + fail_unless (octet_count == 123456); + } + + /* go to first packet, this should be the packet we just added */ + fail_unless (gst_rtcp_buffer_get_first_packet (buf, &packet) == TRUE); + + fail_unless (gst_rtcp_packet_get_padding (&packet) == 0); + fail_unless (gst_rtcp_packet_get_count (&packet) == 0); + fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_SR); + fail_unless (gst_rtcp_packet_get_length (&packet) == 6); + + fail_unless (gst_rtcp_packet_move_to_next (&packet) == FALSE); + + /* add some SDES */ + fail_unless (gst_rtcp_buffer_add_packet (buf, GST_RTCP_TYPE_SDES, + &packet) == TRUE); + fail_unless (gst_rtcp_packet_sdes_add_item (&packet, 0xff658743) == TRUE); + fail_unless (gst_rtcp_packet_sdes_add_entry (&packet, GST_RTCP_SDES_CNAME, + sizeof ("test@foo.bar"), (guint8 *) "test@foo.bar") == TRUE); + + /* add some BYE */ + fail_unless (gst_rtcp_buffer_add_packet (buf, GST_RTCP_TYPE_BYE, + &packet) == TRUE); + fail_unless (gst_rtcp_packet_bye_add_ssrc (&packet, 0x5613212f) == TRUE); + fail_unless (gst_rtcp_packet_bye_add_ssrc (&packet, 0x00112233) == TRUE); + fail_unless (gst_rtcp_packet_bye_get_ssrc_count (&packet) == 2); + + fail_unless (gst_rtcp_packet_get_padding (&packet) == 0); + fail_unless (gst_rtcp_packet_get_count (&packet) == 2); + fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_BYE); + fail_unless (gst_rtcp_packet_get_length (&packet) == 2); + + /* move to SDES */ + fail_unless (gst_rtcp_buffer_get_first_packet (buf, &packet) == TRUE); + fail_unless (gst_rtcp_packet_move_to_next (&packet) == TRUE); + + fail_unless (gst_rtcp_packet_get_padding (&packet) == 0); + fail_unless (gst_rtcp_packet_get_count (&packet) == 1); + fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_SDES); + fail_unless (gst_rtcp_packet_get_length (&packet) == 5); + + /* remove the SDES */ + fail_unless (gst_rtcp_packet_remove (&packet) == TRUE); + + /* we are now at the BYE packet */ + fail_unless (gst_rtcp_packet_get_padding (&packet) == 0); + fail_unless (gst_rtcp_packet_get_count (&packet) == 2); + fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_BYE); + fail_unless (gst_rtcp_packet_get_length (&packet) == 2); + + /* close and validate */ + gst_rtcp_buffer_end (buf); + fail_unless (gst_rtcp_buffer_validate (buf) == TRUE); +} + +GST_END_TEST; + static Suite * rtp_suite (void) { @@ -271,6 +369,9 @@ rtp_suite (void) 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); + + tcase_add_test (tc_chain, test_rtcp_buffer); + return s; }