From a637ec3da8d035b11cf6f11617ad942eb480e31d Mon Sep 17 00:00:00 2001 From: "olivier.crete@collabora.com" Date: Tue, 10 Sep 2019 18:59:02 +0100 Subject: [PATCH] rtpstats: Don't save the ts & seqnum if the avg is not updated This makes it update correctly when you have more than one packet per frame. --- gst/rtpmanager/rtpstats.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gst/rtpmanager/rtpstats.c b/gst/rtpmanager/rtpstats.c index 27063ee..ed820a2 100644 --- a/gst/rtpmanager/rtpstats.c +++ b/gst/rtpmanager/rtpstats.c @@ -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; } -- 2.7.4