gst-libs/gst/rtp/gstrtcpbuffer.c: Use g_strndup which does exactly what we want.
authorWim Taymans <wim.taymans@gmail.com>
Fri, 31 Aug 2007 15:21:13 +0000 (15:21 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Fri, 31 Aug 2007 15:21:13 +0000 (15:21 +0000)
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()

ChangeLog
gst-libs/gst/rtp/gstrtcpbuffer.c
gst-libs/gst/rtp/gstrtpbuffer.c
gst-libs/gst/rtp/gstrtpbuffer.h

index d38269a..aba58f9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        * gst-libs/gst/rtp/gstrtcpbuffer.c:
index cedf0b8..c1fca3c 100644 (file)
@@ -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;
 }
index 9022445..8caf494 100644 (file)
@@ -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;
+}
index 86f3db0..205e90c 100644 (file)
@@ -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