From 5948f8222706d63f603167bf1a17c20bdee0b321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 20 Apr 2010 07:38:52 +0000 Subject: [PATCH] Reset RTCP timestamps after seeking, add range start offset to the packets timestamps If these aren't reset, the timestamps make a huge jump when the next RTCP is received. Originally committed as revision 22918 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavformat/rtpdec.c | 2 +- libavformat/rtpdec.h | 1 + libavformat/rtsp.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index bd3566e9f8..0d2df59a75 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -437,7 +437,7 @@ static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestam delta_timestamp = timestamp - s->last_rtcp_timestamp; /* convert to the PTS timebase */ addend = av_rescale(s->last_rtcp_ntp_time - s->first_rtcp_ntp_time, s->st->time_base.den, (uint64_t)s->st->time_base.num << 32); - pkt->pts = addend + delta_timestamp; + pkt->pts = s->range_start_offset + addend + delta_timestamp; } } diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h index 599e13d2a2..477ab723f4 100644 --- a/libavformat/rtpdec.h +++ b/libavformat/rtpdec.h @@ -162,6 +162,7 @@ struct RTPDemuxContext { uint32_t timestamp; uint32_t base_timestamp; uint32_t cur_timestamp; + int64_t range_start_offset; int max_payload_size; struct MpegTSContext *ts; /* only used for MP2T payloads */ int read_buf_index; diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 0931201f81..06a6e9c55f 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -1314,6 +1314,7 @@ static int rtsp_read_play(AVFormatContext *s) { RTSPState *rt = s->priv_data; RTSPMessageHeader reply1, *reply = &reply1; + int i; char cmd[1024]; av_log(s, AV_LOG_DEBUG, "hello state=%d\n", rt->state); @@ -1330,6 +1331,22 @@ static int rtsp_read_play(AVFormatContext *s) if (reply->status_code != RTSP_STATUS_OK) { return -1; } + if (reply->range_start != AV_NOPTS_VALUE && + rt->transport == RTSP_TRANSPORT_RTP) { + for (i = 0; i < rt->nb_rtsp_streams; i++) { + RTSPStream *rtsp_st = rt->rtsp_streams[i]; + RTPDemuxContext *rtpctx = rtsp_st->transport_priv; + AVStream *st = NULL; + if (rtsp_st->stream_index >= 0) + st = s->streams[rtsp_st->stream_index]; + rtpctx->last_rtcp_ntp_time = AV_NOPTS_VALUE; + rtpctx->first_rtcp_ntp_time = AV_NOPTS_VALUE; + if (st) + rtpctx->range_start_offset = av_rescale_q(reply->range_start, + AV_TIME_BASE_Q, + st->time_base); + } + } } rt->state = RTSP_STATE_STREAMING; return 0;