Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Clément Péron" <peron.clem-at-gmail.com@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org, Kieran Kunhya <kieran618@googlemail.com>
Cc: "Clément Péron" <peron.clem@gmail.com>
Subject: [FFmpeg-devel] [PATCH] rtpdec: explicit timestamp wraparound handling
Date: Sun,  8 Jun 2025 17:07:37 +0200
Message-ID: <20250608150737.73929-1-peron.clem@gmail.com> (raw)

Change delta_timestamp to int32_t and add explicit cast to handle
RTP timestamp wraparound correctly. This fixes implementation-defined
behavior when computing negative timestamp differences due to 32-bit
wraparound.

Signed-off-by: Clément Péron <peron.clem@gmail.com>
---
 libavformat/rtpdec.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index 7664ab58bd..e302203db8 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -643,6 +643,7 @@ static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp) {
         return AVERROR(ENOMEM);
 
     rtcp_time = ff_parse_ntp_time(s->last_rtcp_ntp_time) - NTP_OFFSET_US;
+    /* Cast to int32_t to handle timestamp wraparound correctly */
     delta_timestamp = (int32_t)(timestamp - s->last_rtcp_timestamp);
     delta_time = av_rescale_q(delta_timestamp, s->st->time_base, AV_TIME_BASE_Q);
 
@@ -670,10 +671,11 @@ static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestam
 
     if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE && s->ic->nb_streams > 1) {
         int64_t addend;
-        int delta_timestamp;
+        int32_t delta_timestamp;
 
         /* compute pts from timestamp with received ntp_time */
-        delta_timestamp = timestamp - s->last_rtcp_timestamp;
+        /* Cast to int32_t to handle timestamp wraparound correctly */
+        delta_timestamp = (int32_t)(timestamp - s->last_rtcp_timestamp);
         /* convert to the PTS timebase */
         addend = av_rescale(s->last_rtcp_ntp_time - s->first_rtcp_ntp_time,
                             s->st->time_base.den,
-- 
2.48.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

             reply	other threads:[~2025-06-08 15:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-08 15:07 Clément Péron [this message]
2025-06-14 20:55 ` Michael Niedermayer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250608150737.73929-1-peron.clem@gmail.com \
    --to=peron.clem-at-gmail.com@ffmpeg.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=kieran618@googlemail.com \
    --cc=peron.clem@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git