From fdc42d47b45a7788c9ffda3ecb666b3df05acf4f Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 30 Aug 2007 21:59:23 +0000 Subject: [PATCH] gst-libs/gst/rtp/gstrtcpbuffer.*: Fix and document SDES item data function. Original commit message from CVS: * gst-libs/gst/rtp/gstrtcpbuffer.c: (gst_rtcp_packet_sdes_get_entry), (gst_rtcp_packet_sdes_copy_entry): * gst-libs/gst/rtp/gstrtcpbuffer.h: Fix and document SDES item data function. Add new function that makes a proper copy of SDES item data. API: gst_rtcp_packet_sdes_copy_entry() --- ChangeLog | 10 +++++++ gst-libs/gst/rtp/gstrtcpbuffer.c | 48 ++++++++++++++++++++++++++++++-- gst-libs/gst/rtp/gstrtcpbuffer.h | 3 ++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b67245dc6a..d38269af04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-08-30 Wim Taymans + + * gst-libs/gst/rtp/gstrtcpbuffer.c: + (gst_rtcp_packet_sdes_get_entry), + (gst_rtcp_packet_sdes_copy_entry): + * gst-libs/gst/rtp/gstrtcpbuffer.h: + Fix and document SDES item data function. + Add new function that makes a proper copy of SDES item data. + API: gst_rtcp_packet_sdes_copy_entry() + 2007-08-30 Stefan Kost * configure.ac: diff --git a/gst-libs/gst/rtp/gstrtcpbuffer.c b/gst-libs/gst/rtp/gstrtcpbuffer.c index aec6bdc869..cedf0b87bd 100644 --- a/gst-libs/gst/rtp/gstrtcpbuffer.c +++ b/gst-libs/gst/rtp/gstrtcpbuffer.c @@ -1107,7 +1107,13 @@ gst_rtcp_packet_sdes_next_entry (GstRTCPPacket * packet) * @len: result length of the entry data * @data: result entry data * - * Get the data of the current SDES item entry. + * Get the data of the current SDES item entry. @type (when not NULL) will + * contain the type of the entry. @data (when not NULL) will point to @len + * bytes. + * + * When @type refers to a text item, @data will point to a UTF8 string. Note + * that this UTF8 string is NOT null-terminated. Use + * gst_rtcp_packet_sdes_copy_entry() to get a null-termined copy of the entry. * * Returns: %TRUE if there was valid data. */ @@ -1138,7 +1144,45 @@ gst_rtcp_packet_sdes_get_entry (GstRTCPPacket * packet, if (len) *len = bdata[offset + 1]; if (data) - *data = g_memdup (&bdata[offset + 2], bdata[offset + 1]); + *data = &bdata[offset + 2]; + + return TRUE; +} + +/** + * gst_rtcp_packet_sdes_copy_entry: + * @packet: a valid SDES #GstRTCPPacket + * @type: result of the entry type + * @len: result length of the entry data + * @data: result entry data + * + * This function is like gst_rtcp_packet_sdes_get_entry() but it returns a + * null-terminated copy of the data instead. use g_free() after usage. + * + * Returns: %TRUE if there was valid data. + */ +gboolean +gst_rtcp_packet_sdes_copy_entry (GstRTCPPacket * packet, + GstRTCPSDESType * type, guint8 * len, guint8 ** data) +{ + guint8 *tdata; + guint8 tlen; + + g_return_val_if_fail (packet != NULL, FALSE); + g_return_val_if_fail (packet->type == GST_RTCP_TYPE_SDES, FALSE); + g_return_val_if_fail (GST_IS_BUFFER (packet->buffer), FALSE); + + if (!gst_rtcp_packet_sdes_get_entry (packet, type, &tlen, &tdata)) + return FALSE; + + if (len) + *len = tlen; + if (data) { + /* alloc string with room for null-byte */ + *data = g_malloc (tlen + 1); + memcpy (*data, tdata, tlen); + (*data)[tlen] = '\0'; + } return TRUE; } diff --git a/gst-libs/gst/rtp/gstrtcpbuffer.h b/gst-libs/gst/rtp/gstrtcpbuffer.h index 74f944a10d..384862e3a8 100644 --- a/gst-libs/gst/rtp/gstrtcpbuffer.h +++ b/gst-libs/gst/rtp/gstrtcpbuffer.h @@ -215,6 +215,9 @@ gboolean gst_rtcp_packet_sdes_next_entry (GstRTCPPacket *packet); gboolean gst_rtcp_packet_sdes_get_entry (GstRTCPPacket *packet, GstRTCPSDESType *type, guint8 *len, guint8 **data); +gboolean gst_rtcp_packet_sdes_copy_entry (GstRTCPPacket *packet, + GstRTCPSDESType *type, guint8 *len, + guint8 **data); gboolean gst_rtcp_packet_sdes_add_item (GstRTCPPacket *packet, guint32 ssrc); gboolean gst_rtcp_packet_sdes_add_entry (GstRTCPPacket *packet, GstRTCPSDESType type,