From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id F33B14E14F for ; Fri, 6 Jun 2025 21:57:05 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 69C1D68C0DB; Sat, 7 Jun 2025 00:57:02 +0300 (EEST) Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 500F8687D46 for ; Sat, 7 Jun 2025 00:56:55 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id A847B43256 for ; Fri, 6 Jun 2025 21:56:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1749247014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5LBRhMN+O39Wg9LNuYIKX4VewmBYGhT5M/TzYd2rxpw=; b=h0odAaTx06wpCYQPhsxZHMpLiuhjrrNK3FSlbUjJs6zivC8qaIzUBCnnmDRfTsSW/ERip/ 6jmhlqgMI1tYP7Mr2NBcDGSRk0HE8MMzUg/RXS8QWp/ZSD+vQoi4JkogVzLKX7JlnJ4bvB bHiWUgjhT8hA5Uv7Unt6PJ6BqLAFT04BlAodF/KAzvxZ7PBKZOn4nsfmcWWiPRquAPqn0q nCpJuYL5V9ZyN8LKUxXsCe/tOc2zKfuvrKwM2tnqu1uU8d+IIBSqIiflPcFRg4NoVtcRxa e0ulTs4n5axb1NXbvwqlgvHOUr/kd1NFdb7WttQJlkXe4I1abKjkuUkj/dg1xQ== Date: Fri, 6 Jun 2025 23:56:54 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20250606215654.GA29660@pb2> References: <20250606085414.59143-1-peron.clem@gmail.com> MIME-Version: 1.0 In-Reply-To: <20250606085414.59143-1-peron.clem@gmail.com> X-GND-State: clean X-GND-Score: -70 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugdehieeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlhcuvffnffculdeftddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttdejnecuhfhrohhmpefoihgthhgrvghlucfpihgvuggvrhhmrgihvghruceomhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtqeenucggtffrrghtthgvrhhnpeelkeeggfffiedufeejueffjeduhedttdduledtheevveevtdeiueelhfdtuedtkeenucfkphepgedurdeiiedrieejrdduudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepgedurdeiiedrieejrdduudefpdhhvghloheplhhotggrlhhhohhsthdpmhgrihhlfhhrohhmpehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgdpnhgspghrtghpthhtohepuddprhgtphhtthhopehffhhmphgvghdquggvvhgvlhesfhhfmhhpvghgrdhorhhg X-GND-Sasl: michael@niedermayer.cc Subject: Re: [FFmpeg-devel] [PATCH] rtpdec: Fix RTP timestamp wraparound in Producer Reference Time X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: multipart/mixed; boundary="===============6286857913011923942==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============6286857913011923942== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="cQ4qDknrn5W0iqb2" Content-Disposition: inline --cQ4qDknrn5W0iqb2 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jun 06, 2025 at 10:54:14AM +0200, Cl=C3=A9ment P=C3=A9ron wrote: > The rtp_set_prft() function incorrectly calculates the timestamp delta > when RTP timestamps wrap around the 32-bit boundary. The current code: >=20 > delta_timestamp =3D (int64_t)timestamp - (int64_t)s->last_rtcp_timest= amp; >=20 > treats both timestamps as large positive values, causing wraparound to > produce a large negative delta instead of the correct small positive delt= a. >=20 > For example, with a 90kHz video clock: > - last_rtcp_timestamp =3D 0xFFFFFF00 (near wraparound) > - timestamp =3D 0x00000100 (after wraparound) > - Current result: delta =E2=89=88 -4.3 billion ticks =E2=89=88 -47,721 se= conds > - Expected result: delta =E2=89=88 +512 ticks =E2=89=88 +0.006 seconds >=20 > This causes prft->wallclock to jump backward by approximately: > - 90kHz video: ~47,721 seconds (~13.25 hours) > - 48kHz audio: ~89,478 seconds (~24.9 hours) > - 8kHz audio: ~536,871 seconds (~6.2 days) >=20 > Fix by casting the subtraction result to int32_t, which correctly > handles wraparound through modular arithmetic: >=20 > delta_timestamp =3D (int32_t)(timestamp - s->last_rtcp_timestamp); >=20 > This ensures the delta is always in the range [-2^31, 2^31-1], making > wraparound produce the correct small positive values. >=20 > Fixes timing jumps in applications that rely on Producer Reference Time > for media synchronization. > --- > libavformat/rtpdec.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c > index 729bf83685..7a658ad698 100644 > --- a/libavformat/rtpdec.c > +++ b/libavformat/rtpdec.c > @@ -642,7 +642,7 @@ static int rtp_set_prft(RTPDemuxContext *s, AVPacket = *pkt, uint32_t timestamp) { > return AVERROR(ENOMEM); > =20 > rtcp_time =3D ff_parse_ntp_time(s->last_rtcp_ntp_time) - NTP_OFFSET_= US; > - delta_timestamp =3D (int64_t)timestamp - (int64_t)s->last_rtcp_times= tamp; > + delta_timestamp =3D (int32_t)(timestamp - s->last_rtcp_timestamp); > delta_time =3D av_rescale_q(delta_timestamp, s->st->time_base, AV_TI= ME_BASE_Q); assuming the change is correct, the type of delta_timestamp can be changed to int32_t thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If you fake or manipulate statistics in a paper in physics you will never get a job again. If you fake or manipulate statistics in a paper in medicin you will get a job for life at the pharma industry. --cQ4qDknrn5W0iqb2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEKAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCaENkJQAKCRBhHseHBAsP q2ouAJ9bxJc5qk9DLpX7GmJSAprMCvBqlwCaA5GNJI6ep6NIFPbEBAqmscS/TUI= =oKZY -----END PGP SIGNATURE----- --cQ4qDknrn5W0iqb2-- --===============6286857913011923942== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============6286857913011923942==--