From 8f5dca9611ad6174391b937798b6b73da7a9552e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 25 Oct 2024 16:37:15 +0300 Subject: [PATCH] rtmp2sink: Initialize base_ts / last_ts with the actual first observed timestamp Initializing it with zero can falsely trigger the overflow / underflow detection code if the first observed timestamp is a big integer. Part-of: --- .../gst-plugins-bad/gst/rtmp2/gstrtmp2sink.c | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst/rtmp2/gstrtmp2sink.c b/subprojects/gst-plugins-bad/gst/rtmp2/gstrtmp2sink.c index 904084c10f..cc40e3e1d1 100644 --- a/subprojects/gst-plugins-bad/gst/rtmp2/gstrtmp2sink.c +++ b/subprojects/gst-plugins-bad/gst/rtmp2/gstrtmp2sink.c @@ -567,8 +567,8 @@ gst_rtmp2_sink_start (GstBaseSink * sink) self->running = TRUE; self->cancellable = g_cancellable_new (); self->stream_id = 0; - self->last_ts = 0; - self->base_ts = 0; + self->last_ts = GST_CLOCK_TIME_NONE; + self->base_ts = GST_CLOCK_TIME_NONE; if (async) { gst_task_start (self->task); @@ -734,27 +734,31 @@ buffer_to_message (GstRtmp2Sink * self, GstBuffer * buffer, GstBuffer ** outbuf) /* flvmux timestamps roll over after about 49 days */ timestamp = header.timestamp; - if (timestamp + self->base_ts + G_MAXINT32 < self->last_ts) { - GST_WARNING_OBJECT (self, "Timestamp regression %" G_GUINT64_FORMAT - " -> %" G_GUINT64_FORMAT "; assuming overflow", self->last_ts, - timestamp + self->base_ts); - self->base_ts += G_MAXUINT32; - self->base_ts += 1; - } else if (timestamp + self->base_ts > self->last_ts + G_MAXINT32) { - GST_WARNING_OBJECT (self, "Timestamp jump %" G_GUINT64_FORMAT - " -> %" G_GUINT64_FORMAT "; assuming underflow", self->last_ts, - timestamp + self->base_ts); - if (self->base_ts > 0) { - self->base_ts -= G_MAXUINT32; - self->base_ts -= 1; - } else { - GST_WARNING_OBJECT (self, "Cannot regress further;" - " forcing timestamp to zero"); - timestamp = 0; + if (self->base_ts == GST_CLOCK_TIME_NONE) { + self->last_ts = self->base_ts = timestamp; + } else { + if (timestamp + self->base_ts + G_MAXINT32 < self->last_ts) { + GST_WARNING_OBJECT (self, "Timestamp regression %" G_GUINT64_FORMAT + " -> %" G_GUINT64_FORMAT "; assuming overflow", self->last_ts, + timestamp + self->base_ts); + self->base_ts += G_MAXUINT32; + self->base_ts += 1; + } else if (timestamp + self->base_ts > self->last_ts + G_MAXINT32) { + GST_WARNING_OBJECT (self, "Timestamp jump %" G_GUINT64_FORMAT + " -> %" G_GUINT64_FORMAT "; assuming underflow", self->last_ts, + timestamp + self->base_ts); + if (self->base_ts > 0) { + self->base_ts -= G_MAXUINT32; + self->base_ts -= 1; + } else { + GST_WARNING_OBJECT (self, "Cannot regress further;" + " forcing timestamp to zero"); + timestamp = 0; + } } + timestamp += self->base_ts; + self->last_ts = timestamp; } - timestamp += self->base_ts; - self->last_ts = timestamp; gst_buffer_unmap (buffer, &info); }