summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Adam <jakub.adam@ktknet.cz>2021-05-24 19:02:42 +0200
committerJakub Adam <jakub.adam@collabora.com>2021-06-28 19:28:41 +0200
commitd294d7da36ac3625ffdb5983958c208d9610805e (patch)
treec9ca8e04a5225066eb415c0dbf84cfdc5a01c122
parente2e9e321f6ee4484abd4e28a33a9c8256eeac4b4 (diff)
downloadgstreamer-plugins-base-d294d7da36ac3625ffdb5983958c208d9610805e.tar.gz
rtpbuffer: Add gst_rtp_buffer_remove_extension_data()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1173>
-rw-r--r--gst-libs/gst/rtp/gstrtpbuffer.c31
-rw-r--r--gst-libs/gst/rtp/gstrtpbuffer.h3
-rw-r--r--tests/check/libs/rtp.c44
3 files changed, 78 insertions, 0 deletions
diff --git a/gst-libs/gst/rtp/gstrtpbuffer.c b/gst-libs/gst/rtp/gstrtpbuffer.c
index 7d72cd9c5..ce3949a6b 100644
--- a/gst-libs/gst/rtp/gstrtpbuffer.c
+++ b/gst-libs/gst/rtp/gstrtpbuffer.c
@@ -896,6 +896,37 @@ gst_rtp_buffer_set_extension_data (GstRTPBuffer * rtp, guint16 bits,
}
/**
+ * gst_rtp_buffer_remove_extension_data:
+ * @rtp: the RTP packet
+ *
+ * Unsets the extension bit of the RTP buffer and removes the extension header
+ * and data.
+ *
+ * If the RTP buffer has no header extension data, the action has no effect.
+ * The RTP buffer must be mapped READWRITE only once and the underlying
+ * GstBuffer must be writable.
+ *
+ * Since: 1.20
+ */
+void
+gst_rtp_buffer_remove_extension_data (GstRTPBuffer * rtp)
+{
+ g_return_if_fail (gst_buffer_is_writable (rtp->buffer));
+ g_return_if_fail (rtp->map[0].flags & GST_MAP_WRITE);
+
+ if (rtp->data[1] != NULL) {
+ GstBuffer *buf = rtp->buffer;
+
+ ensure_buffers (rtp);
+
+ GST_RTP_HEADER_EXTENSION (rtp->data[0]) = FALSE;
+ gst_rtp_buffer_unmap (rtp);
+ gst_buffer_remove_memory (buf, 1);
+ gst_rtp_buffer_map (buf, GST_MAP_READWRITE, rtp);
+ }
+}
+
+/**
* gst_rtp_buffer_get_ssrc:
* @rtp: the RTP packet
*
diff --git a/gst-libs/gst/rtp/gstrtpbuffer.h b/gst-libs/gst/rtp/gstrtpbuffer.h
index ae3af1438..cac8998c2 100644
--- a/gst-libs/gst/rtp/gstrtpbuffer.h
+++ b/gst-libs/gst/rtp/gstrtpbuffer.h
@@ -136,6 +136,9 @@ GST_RTP_API
gboolean gst_rtp_buffer_set_extension_data (GstRTPBuffer *rtp, guint16 bits, guint16 length);
GST_RTP_API
+void gst_rtp_buffer_remove_extension_data (GstRTPBuffer *rtp);
+
+GST_RTP_API
guint32 gst_rtp_buffer_get_ssrc (GstRTPBuffer *rtp);
GST_RTP_API
diff --git a/tests/check/libs/rtp.c b/tests/check/libs/rtp.c
index 39f1812af..d5879ca6b 100644
--- a/tests/check/libs/rtp.c
+++ b/tests/check/libs/rtp.c
@@ -2172,6 +2172,49 @@ GST_START_TEST (test_rtp_buffer_extlen_wraparound)
GST_END_TEST;
+GST_START_TEST (test_rtp_buffer_remove_extension_data)
+{
+ GstBuffer *buf;
+ GstMapInfo info;
+ guint8 rtp_test_buffer[] = {
+ 0x90, 0x7c, 0x18, 0xa6, /* |V=2|P|X|CC|M|PT|sequence number| */
+ 0x7a, 0x62, 0x17, 0x0f, /* |timestamp| */
+ 0x70, 0x23, 0x91, 0x38, /* |synchronization source (SSRC) identifier| */
+ 0xbe, 0xde, 0x00, 0x02, /* |0xBE|0xDE|length=2| */
+ 0x00, 0x00, 0x00, 0x00, /* |0 (pad)|0 (pad)|0 (pad)|0 (pad)| */
+ 0x00, 0x00, 0x00, 0x00, /* |0 (pad)|0 (pad)|0 (pad)|0 (pad)| */
+ 0xff, 0xff, 0xff, 0xff /* |dummy payload| */
+ };
+
+ guint8 expected_result[] = {
+ 0x80, 0x7c, 0x18, 0xa6, /* |V=2|P|X|CC|M|PT|sequence number| */
+ 0x7a, 0x62, 0x17, 0x0f, /* |timestamp| */
+ 0x70, 0x23, 0x91, 0x38, /* |synchronization source (SSRC) identifier| */
+ 0xff, 0xff, 0xff, 0xff /* |dummy payload| */
+ };
+
+ GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
+
+ buf = gst_buffer_new_and_alloc (sizeof (rtp_test_buffer));
+ gst_buffer_fill (buf, 0, rtp_test_buffer, sizeof (rtp_test_buffer));
+
+ fail_unless (gst_rtp_buffer_map (buf, GST_MAP_READWRITE, &rtp));
+
+ gst_rtp_buffer_remove_extension_data (&rtp);
+ gst_rtp_buffer_unmap (&rtp);
+
+ gst_buffer_map (buf, &info, GST_MAP_READ);
+
+ fail_unless_equals_int (info.size, sizeof (expected_result));
+ fail_unless_equals_int
+ (memcmp (info.data, expected_result, sizeof (expected_result)), 0);
+
+ gst_buffer_unmap (buf, &info);
+ gst_buffer_unref (buf);
+}
+
+GST_END_TEST;
+
static Suite *
rtp_suite (void)
{
@@ -2226,6 +2269,7 @@ rtp_suite (void)
tcase_add_test (tc_chain, test_rtcp_compound_padding);
tcase_add_test (tc_chain, test_rtp_buffer_extlen_wraparound);
+ tcase_add_test (tc_chain, test_rtp_buffer_remove_extension_data);
return s;
}