Add gst_rtp_buffer_set_extension_data()

Original commit message from CVS:
Patch by: Thijs Vermeir <thijsvermeir at gmail dot com>
* gst-libs/gst/rtp/gstrtpbuffer.c:
(gst_rtp_buffer_set_extension_data):
* gst-libs/gst/rtp/gstrtpbuffer.h:
* tests/check/libs/rtp.c: (GST_START_TEST), (rtp_suite):
Add gst_rtp_buffer_set_extension_data()
Add a unit test for this addition. Fixes #511478.
API: GstRTPBuffer:gst_rtp_buffer_set_extension_data()
This commit is contained in:
Thijs Vermeir 2008-02-01 11:09:16 +00:00 committed by Wim Taymans
parent 88322ce012
commit b8d39bc200
4 changed files with 102 additions and 0 deletions

View file

@ -1,3 +1,15 @@
2008-02-01 Wim Taymans <wim.taymans@collabora.co.uk>
Patch by: Thijs Vermeir <thijsvermeir at gmail dot com>
* gst-libs/gst/rtp/gstrtpbuffer.c:
(gst_rtp_buffer_set_extension_data):
* gst-libs/gst/rtp/gstrtpbuffer.h:
* tests/check/libs/rtp.c: (GST_START_TEST), (rtp_suite):
Add gst_rtp_buffer_set_extension_data()
Add a unit test for this addition. Fixes #511478.
API: GstRTPBuffer:gst_rtp_buffer_set_extension_data()
2008-01-30 Jan Schmidt <jan.schmidt@sun.com>
* configure.ac:

View file

@ -630,6 +630,51 @@ gst_rtp_buffer_get_extension_data (GstBuffer * buffer, guint16 * bits,
return TRUE;
}
/**
* gst_rtp_buffer_set_extension_data:
* @buffer: the buffer
* @bits: the bits specific for the extension
* @length: the length that counts the number of 32-bit words in
* the extension, excluding the extension header ( therefore zero is a valid length)
*
* Set the extension bit of the rtp buffer and fill in the @bits and @length of the
* extension header. It will refuse to set the extension data if the buffer is not
* large enough.
*
* Returns: True if done.
*
* Since : 0.10.18
*/
gboolean
gst_rtp_buffer_set_extension_data (GstBuffer * buffer, guint16 bits,
guint16 length)
{
guint32 min_size = 0;
guint8 *data;
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, FALSE);
gst_rtp_buffer_set_extension (buffer, TRUE);
min_size =
GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (buffer) + 4 +
length * sizeof (guint32);
if (min_size > GST_BUFFER_SIZE (buffer)) {
GST_WARNING_OBJECT (buffer,
"rtp buffer too small: need more than %d bytes but only have %d bytes",
min_size, GST_BUFFER_SIZE (buffer));
return FALSE;
}
data =
GST_BUFFER_DATA (buffer) + GST_RTP_HEADER_LEN +
GST_RTP_HEADER_CSRC_SIZE (buffer);
GST_WRITE_UINT16_BE (data, bits);
GST_WRITE_UINT16_BE (data + 2, length);
return TRUE;
}
/**
* gst_rtp_buffer_get_ssrc:
* @buffer: the buffer

View file

@ -68,6 +68,7 @@ gboolean gst_rtp_buffer_get_extension (GstBuffer *buffer);
void gst_rtp_buffer_set_extension (GstBuffer *buffer, gboolean extension);
gboolean gst_rtp_buffer_get_extension_data (GstBuffer *buffer, guint16 *bits,
gpointer *data, guint *wordlen);
gboolean gst_rtp_buffer_set_extension_data (GstBuffer *buffer, guint16 bits, guint16 length);
guint32 gst_rtp_buffer_get_ssrc (GstBuffer *buffer);
void gst_rtp_buffer_set_ssrc (GstBuffer *buffer, guint32 ssrc);

View file

@ -106,6 +106,49 @@ GST_START_TEST (test_rtp_buffer)
GST_END_TEST;
GST_START_TEST (test_rtp_buffer_set_extension_data)
{
GstBuffer *buf;
guint8 *data;
guint16 bits;
guint size;
gpointer pointer;
/* check GstRTPHeader structure alignment and packing */
buf = gst_rtp_buffer_new_allocate (4, 0, 0);
data = GST_BUFFER_DATA (buf);
/* should be impossible to set the extension data */
fail_unless (gst_rtp_buffer_set_extension_data (buf, 0, 4) == FALSE);
fail_unless (gst_rtp_buffer_get_extension (buf) == TRUE);
/* should be possible to set the extension data */
fail_unless (gst_rtp_buffer_set_extension_data (buf, 270, 0) == TRUE);
fail_unless (gst_rtp_buffer_get_extension (buf) == TRUE);
gst_rtp_buffer_get_extension_data (buf, &bits, &pointer, &size);
fail_unless (bits == 270);
fail_unless (size == 0);
fail_unless (pointer == GST_BUFFER_DATA (buf) + 16);
pointer = gst_rtp_buffer_get_payload (buf);
fail_unless (pointer == GST_BUFFER_DATA (buf) + 16);
gst_buffer_unref (buf);
buf = gst_rtp_buffer_new_allocate (20, 0, 0);
data = GST_BUFFER_DATA (buf);
fail_unless (gst_rtp_buffer_get_extension (buf) == FALSE);
fail_unless (gst_rtp_buffer_set_extension_data (buf, 333, 2) == TRUE);
fail_unless (gst_rtp_buffer_get_extension (buf) == TRUE);
gst_rtp_buffer_get_extension_data (buf, &bits, &pointer, &size);
fail_unless (bits == 333);
fail_unless (size == 2);
fail_unless (pointer == GST_BUFFER_DATA (buf) + 16);
pointer = gst_rtp_buffer_get_payload (buf);
fail_unless (pointer == GST_BUFFER_DATA (buf) + 24);
gst_buffer_unref (buf);
}
GST_END_TEST;
static Suite *
rtp_suite (void)
{
@ -114,6 +157,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);
return s;
}