Skip to content

Commit

Permalink
rtpbuffer: Add gst_rtp_buffer_remove_extension_data()
Browse files Browse the repository at this point in the history
  • Loading branch information
xhaakon committed Jun 28, 2021
1 parent e2e9e32 commit d294d7d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
31 changes: 31 additions & 0 deletions gst-libs/gst/rtp/gstrtpbuffer.c
Expand Up @@ -895,6 +895,37 @@ gst_rtp_buffer_set_extension_data (GstRTPBuffer * rtp, guint16 bits,
return TRUE;
}

/**
* 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
Expand Down
3 changes: 3 additions & 0 deletions gst-libs/gst/rtp/gstrtpbuffer.h
Expand Up @@ -135,6 +135,9 @@ GBytes* gst_rtp_buffer_get_extension_bytes (GstRTPBuffer *rtp, guint16
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);

Expand Down
44 changes: 44 additions & 0 deletions tests/check/libs/rtp.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit d294d7d

Please sign in to comment.