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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6575>
This commit is contained in:
Sebastian Dröge 2024-04-04 13:21:44 +03:00 committed by GStreamer Marge Bot
parent 72c6cac8db
commit 17db91c7c1

View file

@ -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;
}