diff options
author | Stian Selnes <stian@pexip.com> | 2015-07-22 11:31:05 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2015-10-20 12:07:43 +0300 |
commit | 1cebfc8839c28f972aaeee22aa15dc52193a5c39 (patch) | |
tree | ee07fb508b82d7bd9aa7dc3bd2d00fa78190bd6a | |
parent | 7d11a78f06d76fb7d453cc62399514fbebc08f47 (diff) | |
download | gstreamer-plugins-base-1cebfc8839c28f972aaeee22aa15dc52193a5c39.tar.gz |
rtpbuffer: Add map flag to skip padding
Encrypted RTP buffers may contain encrypted padding, hence it's
necessary to have an option to relax the validation in order to
successfully map the buffer.
When the flag GST_RTP_BUFFER_MAP_FLAG_SKIP_PADDING is set
gst_rtp_buffer_map() will map the buffer like if padding is not
present.
https://bugzilla.gnome.org/show_bug.cgi?id=752705
-rw-r--r-- | gst-libs/gst/rtp/gstrtpbuffer.c | 5 | ||||
-rw-r--r-- | gst-libs/gst/rtp/gstrtpbuffer.h | 16 | ||||
-rw-r--r-- | tests/check/libs/rtp.c | 31 |
3 files changed, 50 insertions, 2 deletions
diff --git a/gst-libs/gst/rtp/gstrtpbuffer.c b/gst-libs/gst/rtp/gstrtpbuffer.c index a61051e81..d4c2edfe8 100644 --- a/gst-libs/gst/rtp/gstrtpbuffer.c +++ b/gst-libs/gst/rtp/gstrtpbuffer.c @@ -399,8 +399,9 @@ gst_rtp_buffer_map (GstBuffer * buffer, GstMapFlags flags, GstRTPBuffer * rtp) rtp->size[1] = 0; } - /* check for padding */ - if (data[0] & 0x20) { + /* check for padding unless flags says to skip */ + if ((data[0] & 0x20) != 0 && + (flags & GST_RTP_BUFFER_MAP_FLAG_SKIP_PADDING) == 0) { /* find memory for the padding bits */ if (!gst_buffer_find_memory (buffer, bufsize - 1, 1, &idx, &length, &skip)) goto wrong_length; diff --git a/gst-libs/gst/rtp/gstrtpbuffer.h b/gst-libs/gst/rtp/gstrtpbuffer.h index 8a4e5d872..b1ba33019 100644 --- a/gst-libs/gst/rtp/gstrtpbuffer.h +++ b/gst-libs/gst/rtp/gstrtpbuffer.h @@ -150,6 +150,22 @@ gboolean gst_rtp_buffer_add_extension_twobytes_header (GstRTPBuffer *rtp, gpointer data, guint size); +/** + * GstRTPBufferMapFlags: + * @GST_RTP_BUFFER_MAP_FLAG_SKIP_PADDING: Skip mapping and validation of RTP + * padding and RTP pad count when present. Useful for buffers where + * the padding may be encrypted. + * @GST_RTP_BUFFER_MAP_FLAG_LAST: Offset to define more flags + * + * Additional mapping flags for gst_rtp_buffer_map(). + * + * Since: 1.8 + */ +typedef enum { + GST_RTP_BUFFER_MAP_FLAG_SKIP_PADDING = (GST_MAP_FLAG_LAST << 0), + GST_RTP_BUFFER_MAP_FLAG_LAST = (GST_MAP_FLAG_LAST << 8) + /* 8 more flags possible afterwards */ +} GstRTPBufferMapFlags; G_END_DECLS diff --git a/tests/check/libs/rtp.c b/tests/check/libs/rtp.c index 77b3d194a..602a9a1ed 100644 --- a/tests/check/libs/rtp.c +++ b/tests/check/libs/rtp.c @@ -171,6 +171,36 @@ GST_START_TEST (test_rtp_buffer_validate_corrupt) GST_END_TEST; +GST_START_TEST (test_rtp_buffer_validate_padding) +{ + GstBuffer *buf; + guint8 packet_with_padding[] = { + 0xa0, 0x60, 0x6c, 0x49, 0x58, 0xab, 0xaa, 0x65, 0x65, 0x2e, 0xaf, 0xce, + 0x68, 0xce, 0x3c, 0x80, 0x00, 0x00, 0x00, 0x04 + }; + GstRTPBuffer rtp = GST_RTP_BUFFER_INIT; + + buf = gst_buffer_new_and_alloc (sizeof (packet_with_padding)); + gst_buffer_fill (buf, 0, packet_with_padding, sizeof (packet_with_padding)); + fail_unless (gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp)); + gst_rtp_buffer_unmap (&rtp); + gst_buffer_unref (buf); + + /* Set the padding to something invalid */ + buf = gst_buffer_new_and_alloc (sizeof (packet_with_padding)); + gst_buffer_fill (buf, 0, packet_with_padding, sizeof (packet_with_padding)); + gst_buffer_memset (buf, gst_buffer_get_size (buf) - 1, 0xff, 1); + fail_if (gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp)); + + memset (&rtp, 0, sizeof (rtp)); + fail_unless (gst_rtp_buffer_map (buf, GST_MAP_READ | + GST_RTP_BUFFER_MAP_FLAG_SKIP_PADDING, &rtp)); + gst_rtp_buffer_unmap (&rtp); + gst_buffer_unref (buf); +} + +GST_END_TEST; + #if 0 GST_START_TEST (test_rtp_buffer_list) { @@ -1179,6 +1209,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_validate_corrupt); + tcase_add_test (tc_chain, test_rtp_buffer_validate_padding); tcase_add_test (tc_chain, test_rtp_buffer_set_extension_data); //tcase_add_test (tc_chain, test_rtp_buffer_list_set_extension); tcase_add_test (tc_chain, test_rtp_seqnum_compare); |