From 33fd595e04e844bb05d21813a64a55c4780dd7fd Mon Sep 17 00:00:00 2001
From: Wim Taymans <wim.taymans@gmail.com>
Date: Fri, 31 Aug 2007 15:26:14 +0000
Subject: gst/rtpmanager/gstrtpjitterbuffer.c: Use extended timestamp to
 release buffers from the jitterbuffer so that we can h...

Original commit message from CVS:
* gst/rtpmanager/gstrtpjitterbuffer.c:
(gst_rtp_jitter_buffer_flush_stop),
(gst_rtp_jitter_buffer_change_state), (gst_rtp_jitter_buffer_loop):
Use extended timestamp to release buffers from the jitterbuffer so that
we can handle the rtp wraparound correctly.
---
 ChangeLog                           |  8 ++++++++
 gst/rtpmanager/gstrtpjitterbuffer.c | 36 +++++++++++++++++++++++-------------
 2 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e7fe82a7..6a12be9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-08-31  Wim Taymans  <wim.taymans@gmail.com>
+
+	* gst/rtpmanager/gstrtpjitterbuffer.c:
+	(gst_rtp_jitter_buffer_flush_stop),
+	(gst_rtp_jitter_buffer_change_state), (gst_rtp_jitter_buffer_loop):
+	Use extended timestamp to release buffers from the jitterbuffer so that
+	we can handle the rtp wraparound correctly.
+
 2007-08-29  Wim Taymans  <wim.taymans@gmail.com>
 
 	* gst/rtpmanager/gstrtpjitterbuffer.c:
diff --git a/gst/rtpmanager/gstrtpjitterbuffer.c b/gst/rtpmanager/gstrtpjitterbuffer.c
index f4d59bb6..bd1c07ea 100644
--- a/gst/rtpmanager/gstrtpjitterbuffer.c
+++ b/gst/rtpmanager/gstrtpjitterbuffer.c
@@ -149,6 +149,7 @@ struct _GstRtpJitterBufferPrivate
   /* clock rate and rtp timestamp offset */
   gint32 clock_rate;
   gint64 clock_base;
+  guint64 exttimestamp;
 
   /* when we are shutting down */
   GstFlowReturn srcresult;
@@ -531,6 +532,7 @@ gst_rtp_jitter_buffer_flush_stop (GstRtpJitterBuffer * jitterbuffer)
   priv->next_seqnum = -1;
   priv->clock_rate = -1;
   priv->eos = FALSE;
+  priv->exttimestamp = -1;
   JBUF_UNLOCK (priv);
 }
 
@@ -587,6 +589,7 @@ gst_rtp_jitter_buffer_change_state (GstElement * element,
       priv->peer_latency = 0;
       /* block until we go to PLAYING */
       priv->blocked = TRUE;
+      priv->exttimestamp = -1;
       JBUF_UNLOCK (priv);
       break;
     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
@@ -925,6 +928,7 @@ gst_rtp_jitter_buffer_loop (GstRtpJitterBuffer * jitterbuffer)
   guint32 rtp_time;
   GstClockTime timestamp;
   gint64 running_time;
+  guint64 exttimestamp;
 
   priv = jitterbuffer->priv;
 
@@ -951,8 +955,15 @@ again:
 
   seqnum = gst_rtp_buffer_get_seq (outbuf);
 
-  GST_DEBUG_OBJECT (jitterbuffer, "Popped buffer #%d, now %d left",
-      seqnum, rtp_jitter_buffer_num_packets (priv->jbuf));
+  /* get the max deadline to wait for the missing packets, this is the time
+   * of the currently popped packet */
+  rtp_time = gst_rtp_buffer_get_timestamp (outbuf);
+  exttimestamp = gst_rtp_buffer_ext_timestamp (&priv->exttimestamp, rtp_time);
+
+  GST_DEBUG_OBJECT (jitterbuffer,
+      "Popped buffer #%d, rtptime %u, exttime %" G_GUINT64_FORMAT
+      ",now %d left", seqnum, rtp_time, exttimestamp,
+      rtp_jitter_buffer_num_packets (priv->jbuf));
 
   /* If we don't know what the next seqnum should be (== -1) we have to wait
    * because it might be possible that we are not receiving this buffer in-order,
@@ -980,26 +991,25 @@ again:
       GST_DEBUG_OBJECT (jitterbuffer, "First buffer %d, do sync", seqnum);
     }
 
-    /* get the max deadline to wait for the missing packets, this is the time
-     * of the currently popped packet */
-    rtp_time = gst_rtp_buffer_get_timestamp (outbuf);
-
-    GST_DEBUG_OBJECT (jitterbuffer, "rtp_time %u, base %" G_GINT64_FORMAT,
-        rtp_time, priv->clock_base);
+    GST_DEBUG_OBJECT (jitterbuffer,
+        "exttimestamp %" G_GUINT64_FORMAT ", base %" G_GINT64_FORMAT,
+        exttimestamp, priv->clock_base);
 
     /* if no clock_base was given, take first ts as base */
     if (priv->clock_base == -1)
-      priv->clock_base = rtp_time;
+      priv->clock_base = exttimestamp;
 
     /* take rtp timestamp offset into account, this can wrap around */
-    rtp_time -= priv->clock_base;
+    exttimestamp -= priv->clock_base;
 
     /* bring timestamp to gst time */
-    timestamp = gst_util_uint64_scale (GST_SECOND, rtp_time, priv->clock_rate);
+    timestamp =
+        gst_util_uint64_scale_int (exttimestamp, GST_SECOND, priv->clock_rate);
 
     GST_DEBUG_OBJECT (jitterbuffer,
-        "rtptime %u, clock-rate %u, timestamp %" GST_TIME_FORMAT, rtp_time,
-        priv->clock_rate, GST_TIME_ARGS (timestamp));
+        "exttimestamp %" G_GUINT64_FORMAT ", clock-rate %u, timestamp %"
+        GST_TIME_FORMAT, exttimestamp, priv->clock_rate,
+        GST_TIME_ARGS (timestamp));
 
     /* bring to running time */
     running_time = gst_segment_to_running_time (&priv->segment, GST_FORMAT_TIME,
-- 
cgit v1.2.1