rtpjitterbuffer: Calculate receive time if we don't have any
authorSebastian Dröge <sebastian@centricular.com>
Wed, 8 Jul 2015 14:02:05 +0000 (17:02 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 8 Jul 2015 14:02:05 +0000 (17:02 +0300)
This is required to properly schedule packet loss timers and make
sure all our calculations work properly.

https://bugzilla.gnome.org/show_bug.cgi?id=749536

gst/rtpmanager/gstrtpjitterbuffer.c

index 079cac3..6a5a59f 100644 (file)
@@ -2106,9 +2106,10 @@ calculate_expected (GstRtpJitterBuffer * jitterbuffer, guint32 expected,
       "dts %" GST_TIME_FORMAT ", last %" GST_TIME_FORMAT,
       GST_TIME_ARGS (dts), GST_TIME_ARGS (priv->last_in_dts));
 
-  /* Nothing to be done here if we don't get packet receive times */
-  if (dts == GST_CLOCK_TIME_NONE)
+  if (dts == GST_CLOCK_TIME_NONE) {
+    GST_WARNING_OBJECT (jitterbuffer, "Have no DTS");
     return;
+  }
 
   /* the total duration spanned by the missing packets */
   if (dts >= priv->last_in_dts)
@@ -2446,6 +2447,34 @@ gst_rtp_jitter_buffer_chain (GstPad * pad, GstObject * parent,
     GST_DEBUG_OBJECT (jitterbuffer, "expected #%d, got #%d, gap of %d",
         expected, seqnum, gap);
 
+    /* Try to calculate a DTS if we have none, based on
+     * whatever the jitterbuffer currently knows */
+    if (dts == GST_CLOCK_TIME_NONE) {
+      guint64 base_rtptime, base_time;
+      guint32 clock_rate;
+      guint64 last_rtptime;
+      guint64 ext_rtptime;
+      GstClockTime gst_send_diff;
+      guint64 send_diff;
+
+      rtp_jitter_buffer_get_sync (jitterbuffer->priv->jbuf, &base_rtptime,
+          &base_time, &clock_rate, &last_rtptime);
+
+      if (base_rtptime != -1 && clock_rate != -1 && base_time != -1) {
+        ext_rtptime = gst_rtp_buffer_ext_timestamp (&last_rtptime, rtptime);
+        if (ext_rtptime > base_rtptime)
+          send_diff = ext_rtptime - base_rtptime;
+        else
+          send_diff = 0;
+
+        gst_send_diff =
+            gst_util_uint64_scale_int (send_diff, GST_SECOND, clock_rate);
+
+        dts = base_time + gst_send_diff;
+        pts = dts;
+      }
+    }
+
     if (G_LIKELY (gap == 0)) {
       /* packet is expected */
       calculate_packet_spacing (jitterbuffer, rtptime, dts);