rtpjitterbuffer: Fix calculation of reference timestamp metadata
authorMatt Crane <matt@standard.ai>
Mon, 12 Sep 2022 18:18:47 +0000 (14:18 -0400)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 12 Sep 2022 20:17:08 +0000 (20:17 +0000)
Add support for RTCP SRs that contain RTP timestamps later than the
current timestamps in the RTP stream packet buffers.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3019>

subprojects/gst-plugins-good/gst/rtpmanager/gstrtpjitterbuffer.c

index 0f0c4c9..600ec62 100644 (file)
@@ -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)