rtpstats: Don't save the ts & seqnum if the avg is not updated
authorolivier.crete@collabora.com <Olivier Crête>
Tue, 10 Sep 2019 17:59:02 +0000 (18:59 +0100)
committerOlivier Crête <olivier.crete@collabora.com>
Thu, 6 Feb 2020 19:00:48 +0000 (14:00 -0500)
This makes it update correctly when you have more than one packet per
frame.

gst/rtpmanager/rtpstats.c

index 27063ee..ed820a2 100644 (file)
@@ -47,13 +47,21 @@ gst_rtp_packet_rate_ctx_update (RTPPacketRateCtx * ctx, guint16 seqnum,
 
   if (!ctx->probed) {
     ctx->probed = TRUE;
-    goto done;
+    goto done_but_save;
   }
 
   diff_seqnum = gst_rtp_buffer_compare_seqnum (ctx->last_seqnum, seqnum);
-  if (diff_seqnum <= 0 || new_ts <= ctx->last_ts || diff_seqnum > 1) {
+  /* Ignore seqnums that are over 15,000 away from the latest one, it's close
+   * to 2^14 but far enough to avoid any risk of computing error.
+   */
+  if (diff_seqnum > 15000)
+    goto done_but_save;
+
+  /* Ignore any packet that is in the past, we're only interested in newer
+   * packets to compute the packet rate.
+   */
+  if (diff_seqnum <= 0 || new_ts <= ctx->last_ts)
     goto done;
-  }
 
   diff_ts = new_ts - ctx->last_ts;
   diff_ts = gst_util_uint64_scale_int (diff_ts, GST_SECOND, ctx->clock_rate);
@@ -72,9 +80,11 @@ gst_rtp_packet_rate_ctx_update (RTPPacketRateCtx * ctx, guint16 seqnum,
     ctx->avg_packet_rate = (ctx->avg_packet_rate + new_packet_rate + 1) / 2;
   }
 
-done:
+done_but_save:
+
   ctx->last_seqnum = seqnum;
   ctx->last_ts = new_ts;
+done:
 
   return ctx->avg_packet_rate;
 }