From 12348ca25e0bf44bf4530745753e938fc54e7ae3 Mon Sep 17 00:00:00 2001 From: John Brooks Date: Thu, 17 Nov 2011 08:50:12 -0700 Subject: rtpdec: unwrap RTP timestamps for PTS calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The timestamp field in RTPDemuxContext was unused before this. Signed-off-by: Martin Storsjö --- libavformat/rtpdec.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'libavformat/rtpdec.c') diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index a5ec1caf7a..94fa0f102b 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -439,7 +439,13 @@ static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestam if (!s->base_timestamp) s->base_timestamp = timestamp; - pkt->pts = s->range_start_offset + timestamp - s->base_timestamp; + /* assume that the difference is INT32_MIN < x < INT32_MAX, but allow the first timestamp to exceed INT32_MAX */ + if (!s->timestamp) + s->unwrapped_timestamp += timestamp; + else + s->unwrapped_timestamp += (int32_t)(timestamp - s->timestamp); + s->timestamp = timestamp; + pkt->pts = s->unwrapped_timestamp + s->range_start_offset - s->base_timestamp; } static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt, -- cgit v1.2.3