From e64a5b9a85e0a14f115d270e1c2189e01145a70a Mon Sep 17 00:00:00 2001 From: Matt Crane Date: Mon, 12 Sep 2022 14:18:47 -0400 Subject: [PATCH] rtpjitterbuffer: Fix calculation of reference timestamp metadata Add support for RTCP SRs that contain RTP timestamps later than the current timestamps in the RTP stream packet buffers. Part-of: --- .../gst/rtpmanager/gstrtpjitterbuffer.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/subprojects/gst-plugins-good/gst/rtpmanager/gstrtpjitterbuffer.c b/subprojects/gst-plugins-good/gst/rtpmanager/gstrtpjitterbuffer.c index 0f0c4c9b8e..600ec62345 100644 --- a/subprojects/gst-plugins-good/gst/rtpmanager/gstrtpjitterbuffer.c +++ b/subprojects/gst-plugins-good/gst/rtpmanager/gstrtpjitterbuffer.c @@ -3489,9 +3489,16 @@ gst_rtp_jitter_buffer_chain (GstPad * pad, GstObject * parent, ext_time = gst_rtp_buffer_ext_timestamp (&ext_time, rtptime); - ntp_time = - priv->last_known_ntpnstime + gst_util_uint64_scale (ext_time - - priv->last_known_ext_rtptime, GST_SECOND, priv->clock_rate); + if (ext_time >= priv->last_known_ext_rtptime) { + ntp_time = + priv->last_known_ntpnstime + gst_util_uint64_scale (ext_time - + priv->last_known_ext_rtptime, GST_SECOND, priv->clock_rate); + } else { + ntp_time = + priv->last_known_ntpnstime - + gst_util_uint64_scale (priv->last_known_ext_rtptime - ext_time, + GST_SECOND, priv->clock_rate); + } } if (priv->add_reference_timestamp_meta && GST_CLOCK_TIME_IS_VALID (ntp_time)