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 9E4204E26C for ; Sat, 7 Jun 2025 23:33:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 2985B68BF86; Sun, 8 Jun 2025 02:33:13 +0300 (EEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id D92AD6882FB for ; Sun, 8 Jun 2025 02:33:06 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 359F2432F6 for ; Sat, 7 Jun 2025 23:33:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1749339186; 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=7Yb4npaGdTFk7YVmqibqPbxDysuLthPZ7xKbi6QYec4=; b=O6xRo2EnPW+5SH/TJQ615XbhL6pafqcG7q1poQ4UWbySc89TpFbJUgaMHudANnL+q2fEte HGqYraaUE/MgHpb5AG5MxjxVYPKTIc3kj9UVXjOYjtZvp3P61FWQw4P46BA3/EHNk7YXsq BOOkSx21xxZAOjmvzDLcsEhXWAZCUfAsr0ZenC/z8DjpS1565LF56KMEF9QCctjaCVz63s HbeiZhrEISjMTUad9AhJVM+nyYONDwhLHJrCsVwJAavIw5fn21Yp9ALJ2pyhl+CJ4pZV7m hxrFB9hW5WkCgVh/iPux1tfy50Tt4hLm5TlH1q004ovulzuCoHLhkxFuxXebLw== Date: Sun, 8 Jun 2025 01:33:05 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20250607233305.GL29660@pb2> References: <20250607080619.87769-1-peron.clem@gmail.com> MIME-Version: 1.0 In-Reply-To: <20250607080619.87769-1-peron.clem@gmail.com> X-GND-State: clean X-GND-Score: -85 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugdejudelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlhcuvffnffculdduhedmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttdejnecuhfhrohhmpefoihgthhgrvghlucfpihgvuggvrhhmrgihvghruceomhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtqeenucggtffrrghtthgvrhhnpeelkeeggfffiedufeejueffjeduhedttdduledtheevveevtdeiueelhfdtuedtkeenucfkphepgedurdeiiedrieejrdduudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepgedurdeiiedrieejrdduudefpdhhvghloheplhhotggrlhhhohhsthdpmhgrihhlfhhrohhmpehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgdpnhgspghrtghpthhtohepuddprhgtphhtthhopehffhhmphgvghdquggvvhgvlhesfhhfmhhpvghgrdhorhhg X-GND-Sasl: michael@niedermayer.cc Subject: Re: [FFmpeg-devel] [PATCH v2] 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="===============2647320875715927692==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============2647320875715927692== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="0/YXx5lWW8rTFVUO" Content-Disposition: inline --0/YXx5lWW8rTFVUO Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi On Sat, Jun 07, 2025 at 10:06:19AM +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. >=20 > Signed-off-by: Cl=C3=A9ment P=C3=A9ron > --- > libavformat/rtpdec.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) >=20 > diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c > index 729bf83685..7664ab58bd 100644 > --- a/libavformat/rtpdec.c > +++ b/libavformat/rtpdec.c > @@ -633,7 +633,8 @@ void ff_rtp_parse_set_crypto(RTPDemuxContext *s, cons= t char *suite, > } > =20 > static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t time= stamp) { > - int64_t rtcp_time, delta_timestamp, delta_time; > + int64_t rtcp_time, delta_time; > + int32_t delta_timestamp; > =20 > AVProducerReferenceTime *prft =3D > (AVProducerReferenceTime *) av_packet_new_side_data( > @@ -642,7 +643,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); > =20 > prft->wallclock =3D rtcp_time + delta_time; will apply thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Asymptotically faster algorithms should always be preferred if you have asymptotical amounts of data --0/YXx5lWW8rTFVUO Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEKAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCaETMMQAKCRBhHseHBAsP q1poAJ0erO3tY2vNOtik4CayXbHTTy0E7QCfchVSx+IYRSKjeHi8vJEAUDmmVQY= =t4Vq -----END PGP SIGNATURE----- --0/YXx5lWW8rTFVUO-- --===============2647320875715927692== 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". --===============2647320875715927692==--