[FFmpeg-cvslog] rtpdec: unwrap RTP timestamps for PTS calculation
John Brooks
git at videolan.org
Sat Nov 19 02:09:41 CET 2011
ffmpeg | branch: master | John Brooks <john.brooks at bluecherry.net> | Thu Nov 17 08:50:12 2011 -0700| [12348ca25e0bf44bf4530745753e938fc54e7ae3] | committer: Martin Storsjö
rtpdec: unwrap RTP timestamps for PTS calculation
The timestamp field in RTPDemuxContext was unused before this.
Signed-off-by: Martin Storsjö <martin at martin.st>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=12348ca25e0bf44bf4530745753e938fc54e7ae3
---
libavformat/rtpdec.c | 8 +++++++-
libavformat/rtpdec.h | 1 +
libavformat/rtspdec.c | 2 ++
3 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index a5ec1ca..94fa0f1 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,
diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h
index d58eddd..eb1e62d 100644
--- a/libavformat/rtpdec.h
+++ b/libavformat/rtpdec.h
@@ -151,6 +151,7 @@ struct RTPDemuxContext {
uint32_t timestamp;
uint32_t base_timestamp;
uint32_t cur_timestamp;
+ int64_t unwrapped_timestamp;
int64_t range_start_offset;
int max_payload_size;
struct MpegTSContext *ts; /* only used for MP2T payloads */
diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
index c453b82..1b4982f 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -52,6 +52,8 @@ static int rtsp_read_play(AVFormatContext *s)
rtpctx->last_rtcp_ntp_time = AV_NOPTS_VALUE;
rtpctx->first_rtcp_ntp_time = AV_NOPTS_VALUE;
rtpctx->base_timestamp = 0;
+ rtpctx->timestamp = 0;
+ rtpctx->unwrapped_timestamp = 0;
rtpctx->rtcp_ts_offset = 0;
}
}
More information about the ffmpeg-cvslog
mailing list