From 0596871b98aed296b6fd89f001557f3c53f4b6aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 4 Apr 2024 13:21:44 +0300 Subject: [PATCH] rtpbin: Don't re-use a variable for a completely different purpose temporarily During RTP-Info synchronization, clock_base was temporarily switched from the actual clock-base to the base RTP time and then back some lines later. Instead directly work with the base RTP time. The comment about using a signed variable for convenience doesn't make any sense because all calculations done with the value are unsigned. Similarly, rtp_clock_base was overridden with the rtp_delta when calculating it, which was fine because it is not used anymore afterwards. Instead, introduce a new variable `rtp_delta` to make this calculation clearer. Part-of: --- .../gst/rtpmanager/gstrtpbin.c | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/subprojects/gst-plugins-good/gst/rtpmanager/gstrtpbin.c b/subprojects/gst-plugins-good/gst/rtpmanager/gstrtpbin.c index 92d72f2bb8..4389df56f4 100644 --- a/subprojects/gst-plugins-good/gst/rtpmanager/gstrtpbin.c +++ b/subprojects/gst-plugins-good/gst/rtpmanager/gstrtpbin.c @@ -1567,7 +1567,7 @@ gst_rtp_bin_associate (GstRtpBin * bin, GstRtpBinStream * stream, guint8 len, stream_set_ts_offset (bin, stream, stream->rt_delta, bin->max_ts_offset, bin->min_ts_offset, FALSE); } else { - gint64 min, rtp_min, clock_base = stream->clock_base; + gint64 min, rtp_min, clock_base; gboolean all_sync, use_rtp; gboolean rtcp_sync = g_atomic_int_get (&bin->rtcp_sync); @@ -1594,25 +1594,24 @@ gst_rtp_bin_associate (GstRtpBin * bin, GstRtpBinStream * stream, guint8 len, use_rtp = FALSE; if (rtcp_sync == GST_RTP_BIN_RTCP_SYNC_RTP) { guint64 ext_base = -1; + gint64 rtp_delta = 0; use_rtp = TRUE; - /* signed version for convenience */ - clock_base = base_rtptime; /* convert to extended RTP time */ rtp_clock_base = gst_rtp_buffer_ext_timestamp (&ext_base, rtp_clock_base); /* sanity check; base rtp and provided clock_base should be close */ - if (rtp_clock_base >= clock_base) { - if (rtp_clock_base - clock_base < 10 * clock_rate) { - rtp_clock_base = base_time + - gst_util_uint64_scale_int (rtp_clock_base - clock_base, + if (rtp_clock_base >= base_rtptime) { + if (rtp_clock_base - base_rtptime < 10 * clock_rate) { + rtp_delta = base_time + + gst_util_uint64_scale_int (rtp_clock_base - base_rtptime, GST_SECOND, clock_rate); } else { use_rtp = FALSE; } } else { - if (clock_base - rtp_clock_base < 10 * clock_rate) { - rtp_clock_base = base_time - - gst_util_uint64_scale_int (clock_base - rtp_clock_base, + if (base_rtptime - rtp_clock_base < 10 * clock_rate) { + rtp_delta = base_time - + gst_util_uint64_scale_int (base_rtptime - rtp_clock_base, GST_SECOND, clock_rate); } else { use_rtp = FALSE; @@ -1624,11 +1623,11 @@ gst_rtp_bin_associate (GstRtpBin * bin, GstRtpBinStream * stream, guint8 len, return; } /* store to track changes */ - clock_base = rtp_clock_base; + clock_base = rtp_delta; /* generate a fake as before, * now equating rtptime obtained from RTP-Info, * where the large time represent the otherwise irrelevant npt/ntp time */ - stream->rtp_delta = (GST_SECOND << 28) - rtp_clock_base; + stream->rtp_delta = (GST_SECOND << 28) - rtp_delta; } else { clock_base = rtp_clock_base; }