diff --git a/gst/rtpmanager/gstrtpjitterbuffer.c b/gst/rtpmanager/gstrtpjitterbuffer.c index 7b72deb4c6..1fc313b0fe 100644 --- a/gst/rtpmanager/gstrtpjitterbuffer.c +++ b/gst/rtpmanager/gstrtpjitterbuffer.c @@ -1299,6 +1299,8 @@ gst_jitter_buffer_sink_parse_caps (GstRtpJitterBuffer * jitterbuffer, rtp_jitter_buffer_set_clock_rate (priv->jbuf, priv->clock_rate); + gst_rtp_packet_rate_ctx_reset (&priv->packet_rate_ctx, priv->clock_rate); + /* The clock base is the RTP timestamp corrsponding to the npt-start value. We * can use this to track the amount of time elapsed on the sender. */ if (gst_structure_get_uint (caps_struct, "clock-base", &val)) @@ -2632,6 +2634,8 @@ gst_rtp_jitter_buffer_chain (GstPad * pad, GstObject * parent, if (G_UNLIKELY (priv->clock_rate == -1)) goto no_clock_rate; + + gst_rtp_packet_rate_ctx_reset (&priv->packet_rate_ctx, priv->clock_rate); } /* don't accept more data on EOS */ diff --git a/gst/rtpmanager/rtpstats.c b/gst/rtpmanager/rtpstats.c index 984bc9f76a..cc25dbf64a 100644 --- a/gst/rtpmanager/rtpstats.c +++ b/gst/rtpmanager/rtpstats.c @@ -27,6 +27,7 @@ gst_rtp_packet_rate_ctx_reset (RTPPacketRateCtx * ctx, guint32 clock_rate) ctx->clock_rate = clock_rate; ctx->probed = FALSE; ctx->avg_packet_rate = -1; + ctx->last_ts = -1; } guint32 @@ -41,15 +42,16 @@ gst_rtp_packet_rate_ctx_update (RTPPacketRateCtx * ctx, guint16 seqnum, return ctx->avg_packet_rate; } + new_ts = ctx->last_ts; + gst_rtp_buffer_ext_timestamp (&new_ts, ts); + if (!ctx->probed) { ctx->last_seqnum = seqnum; - ctx->last_ts = ts; + ctx->last_ts = new_ts; ctx->probed = TRUE; return ctx->avg_packet_rate; } - new_ts = ctx->last_ts; - gst_rtp_buffer_ext_timestamp (&new_ts, ts); diff_seqnum = gst_rtp_buffer_compare_seqnum (ctx->last_seqnum, seqnum); if (diff_seqnum <= 0 || new_ts <= ctx->last_ts) { return ctx->avg_packet_rate; @@ -64,6 +66,7 @@ gst_rtp_packet_rate_ctx_update (RTPPacketRateCtx * ctx, guint16 seqnum, * but it will go down again slowly. * This is useful for bursty cases, where a lot of packets are close * to each other and should allow a higher reorder/dropout there. + * Round up the new average. */ if (ctx->avg_packet_rate > new_packet_rate) { ctx->avg_packet_rate = (7 * ctx->avg_packet_rate + new_packet_rate + 7) / 8;