diff --git a/ChangeLog b/ChangeLog index d38269af04..aba58f9abe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2007-08-31 Wim Taymans + + * 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 * gst-libs/gst/rtp/gstrtcpbuffer.c: diff --git a/gst-libs/gst/rtp/gstrtcpbuffer.c b/gst-libs/gst/rtp/gstrtcpbuffer.c index cedf0b87bd..c1fca3c9b3 100644 --- a/gst-libs/gst/rtp/gstrtcpbuffer.c +++ b/gst-libs/gst/rtp/gstrtcpbuffer.c @@ -1177,12 +1177,8 @@ gst_rtcp_packet_sdes_copy_entry (GstRTCPPacket * packet, 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'; - } + if (data) + *data = (guint8 *) g_strndup ((gchar *) tdata, tlen); return TRUE; } diff --git a/gst-libs/gst/rtp/gstrtpbuffer.c b/gst-libs/gst/rtp/gstrtpbuffer.c index 9022445291..8caf494bea 100644 --- a/gst-libs/gst/rtp/gstrtpbuffer.c +++ b/gst-libs/gst/rtp/gstrtpbuffer.c @@ -901,3 +901,74 @@ gst_rtp_buffer_default_clock_rate (guint8 payload_type) 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; +} diff --git a/gst-libs/gst/rtp/gstrtpbuffer.h b/gst-libs/gst/rtp/gstrtpbuffer.h index 86f3db088e..205e90c072 100644 --- a/gst-libs/gst/rtp/gstrtpbuffer.h +++ b/gst-libs/gst/rtp/gstrtpbuffer.h @@ -215,6 +215,8 @@ gpointer gst_rtp_buffer_get_payload (GstBuffer *buffer); /* some helpers */ 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