gst-libs/gst/rtp/gstrtcpbuffer.c: Use g_strndup which does exactly what we want.

Original commit message from CVS:
* gst-libs/gst/rtp/gstrtcpbuffer.c:
(gst_rtcp_packet_sdes_copy_entry):
Use g_strndup which does exactly what we want.
* gst-libs/gst/rtp/gstrtpbuffer.c: (gst_rtp_buffer_compare_seqnum),
(gst_rtp_buffer_ext_timestamp):
* gst-libs/gst/rtp/gstrtpbuffer.h:
Add helper function to compare seqnums.
Add helper function to calculate extended timestamps.
API: gst_rtp_buffer_compare_seqnum()
API: gst_rtp_buffer_ext_timestamp()
This commit is contained in:
Wim Taymans 2007-08-31 15:21:13 +00:00
parent fdc42d47b4
commit 27ea51ec37
4 changed files with 89 additions and 6 deletions

View file

@ -1,3 +1,17 @@
2007-08-31 Wim Taymans <wim.taymans@gmail.com>
* gst-libs/gst/rtp/gstrtcpbuffer.c:
(gst_rtcp_packet_sdes_copy_entry):
Use g_strndup which does exactly what we want.
* gst-libs/gst/rtp/gstrtpbuffer.c: (gst_rtp_buffer_compare_seqnum),
(gst_rtp_buffer_ext_timestamp):
* gst-libs/gst/rtp/gstrtpbuffer.h:
Add helper function to compare seqnums.
Add helper function to calculate extended timestamps.
API: gst_rtp_buffer_compare_seqnum()
API: gst_rtp_buffer_ext_timestamp()
2007-08-30 Wim Taymans <wim.taymans@gmail.com> 2007-08-30 Wim Taymans <wim.taymans@gmail.com>
* gst-libs/gst/rtp/gstrtcpbuffer.c: * gst-libs/gst/rtp/gstrtcpbuffer.c:

View file

@ -1177,12 +1177,8 @@ gst_rtcp_packet_sdes_copy_entry (GstRTCPPacket * packet,
if (len) if (len)
*len = tlen; *len = tlen;
if (data) { if (data)
/* alloc string with room for null-byte */ *data = (guint8 *) g_strndup ((gchar *) tdata, tlen);
*data = g_malloc (tlen + 1);
memcpy (*data, tdata, tlen);
(*data)[tlen] = '\0';
}
return TRUE; return TRUE;
} }

View file

@ -901,3 +901,74 @@ gst_rtp_buffer_default_clock_rate (guint8 payload_type)
return -1; return -1;
} }
} }
/**
* gst_rtp_buffer_compare_seqnum:
* @seqnum1: a sequence number
* @seqnum2: a sequence number
*
* Compare two sequence numbers, taking care of wraparounds.
*
* Returns: -1 if @seqnum1 is before @seqnum2, 0 if they are equal or 1 if
* @seqnum1 is bigger than @segnum2.
*
* Since: 0.10.15
*/
gint
gst_rtp_buffer_compare_seqnum (guint16 seqnum1, guint16 seqnum2)
{
/* check if diff more than half of the 16bit range */
if (abs (seqnum2 - seqnum1) > (1 << 15)) {
/* one of a/b has wrapped */
return seqnum1 - seqnum2;
} else {
return seqnum2 - seqnum1;
}
}
/**
* gst_rtp_buffer_ext_timestamp:
* @exttimestamp: a previous extended timestamp
* @timestamp: a new timestamp
*
* Update the @exttimestamp field with @timestamp. For the first call of the
* method, @exttimestamp should point to a location with a value of -1.
*
* This function makes sure that the returned value is a constantly increasing
* value even in the case where there is a timestamp wraparound.
*
* Returns: The extended timestamp of @timestamp.
*
* Since: 0.10.15
*/
guint64
gst_rtp_buffer_ext_timestamp (guint64 * exttimestamp, guint32 timestamp)
{
guint64 result, diff, ext;
g_return_val_if_fail (exttimestamp != NULL, -1);
ext = *exttimestamp;
if (ext == -1) {
result = timestamp;
} else {
/* pick wraparound counter from previous timestamp and add to new timestamp */
result = timestamp + (ext & ~(G_GINT64_CONSTANT (0xffffffff)));
/* check for timestamp wraparound */
if (result < ext)
diff = ext - result;
else
diff = result - ext;
if (diff > G_MAXINT32) {
/* timestamp went backwards more than allowed, we wrap around and get
* updated extended timestamp. */
result += (G_GINT64_CONSTANT (1) << 32);
}
}
*exttimestamp = result;
return result;
}

View file

@ -215,6 +215,8 @@ gpointer gst_rtp_buffer_get_payload (GstBuffer *buffer);
/* some helpers */ /* some helpers */
guint32 gst_rtp_buffer_default_clock_rate (guint8 payload_type); guint32 gst_rtp_buffer_default_clock_rate (guint8 payload_type);
gint gst_rtp_buffer_compare_seqnum (guint16 seqnum1, guint16 seqnum2);
guint64 gst_rtp_buffer_ext_timestamp (guint64 *exttimestamp, guint32 timestamp);
G_END_DECLS G_END_DECLS