rtpjitterbuffer: Take a running average of the packet spacings instead of just the...
authorSebastian Dröge <sebastian@centricular.com>
Wed, 22 Apr 2015 17:41:07 +0000 (19:41 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 22 Apr 2015 18:25:43 +0000 (20:25 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=748041

gst/rtpmanager/gstrtpjitterbuffer.c

index 340a936..673713e 100644 (file)
@@ -2027,9 +2027,28 @@ calculate_packet_spacing (GstRtpJitterBuffer * jitterbuffer, guint32 rtptime,
   if (priv->ips_rtptime != rtptime) {
     /* rtptime changed, check dts diff */
     if (priv->ips_dts != -1 && dts != -1 && dts > priv->ips_dts) {
-      priv->packet_spacing = dts - priv->ips_dts;
+      GstClockTime new_packet_spacing = dts - priv->ips_dts;
+      GstClockTime old_packet_spacing = priv->packet_spacing;
+
+      /* Biased towards bigger packet spacings to prevent
+       * too many unneeded retransmission requests for next
+       * packets that just arrive a little later than we would
+       * expect */
+      if (old_packet_spacing > new_packet_spacing)
+        priv->packet_spacing =
+            (new_packet_spacing + 3 * old_packet_spacing) / 4;
+      else if (old_packet_spacing > 0)
+        priv->packet_spacing =
+            (3 * new_packet_spacing + old_packet_spacing) / 4;
+      else
+        priv->packet_spacing = new_packet_spacing;
+
       GST_DEBUG_OBJECT (jitterbuffer,
-          "new packet spacing %" GST_TIME_FORMAT,
+          "new packet spacing %" GST_TIME_FORMAT
+          " old packet spacing %" GST_TIME_FORMAT
+          " combined to %" GST_TIME_FORMAT,
+          GST_TIME_ARGS (new_packet_spacing),
+          GST_TIME_ARGS (old_packet_spacing),
           GST_TIME_ARGS (priv->packet_spacing));
     }
     priv->ips_rtptime = rtptime;