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.
Showing the changes to libavformat (1 of 1 file). Show all
Unified · Split
| @@ -597,6 +597,7 @@ static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp) { · 596 unmodified lines | |||
| 597 | return AVERROR(ENOMEM); | 597 | return AVERROR(ENOMEM); |
| 598 | 598 | ||
| 599 | rtcp_time = ff_parse_ntp_time(s->last_rtcp_ntp_time) - NTP_OFFSET_US; | 599 | rtcp_time = ff_parse_ntp_time(s->last_rtcp_ntp_time) - NTP_OFFSET_US; |
| 600 | /* Cast to int32_t to handle timestamp wraparound correctly */ | ||
| 600 | delta_timestamp = (int32_t)(timestamp - s->last_rtcp_timestamp); | 601 | delta_timestamp = (int32_t)(timestamp - s->last_rtcp_timestamp); |
| 601 | delta_time = av_rescale_q(delta_timestamp, s->st->time_base, AV_TIME_BASE_Q); | 602 | delta_time = av_rescale_q(delta_timestamp, s->st->time_base, AV_TIME_BASE_Q); |
| 602 | 603 | ||
| @@ -624,10 +625,11 @@ static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestam · 21 unmodified lines | |||
| 624 | 625 | ||
| 625 | if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE && s->ic->nb_streams > 1) { | 626 | if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE && s->ic->nb_streams > 1) { |
| 626 | int64_t addend; | 627 | int64_t addend; |
| 627 | int delta_timestamp; | 628 | int32_t delta_timestamp; |
| 628 | 629 | ||
| 629 | /* compute pts from timestamp with received ntp_time */ | 630 | /* compute pts from timestamp with received ntp_time */ |
| 630 | delta_timestamp = timestamp - s->last_rtcp_timestamp; | 631 | /* Cast to int32_t to handle timestamp wraparound correctly */ |
| 632 | delta_timestamp = (int32_t)(timestamp - s->last_rtcp_timestamp); | ||
| 631 | /* convert to the PTS timebase */ | 633 | /* convert to the PTS timebase */ |
| 632 | addend = av_rescale(s->last_rtcp_ntp_time - s->first_rtcp_ntp_time, | 634 | addend = av_rescale(s->last_rtcp_ntp_time - s->first_rtcp_ntp_time, |
| 633 | s->st->time_base.den, | 635 | s->st->time_base.den, |