[FFmpeg-cvslog] r22917 - in trunk/libavformat: rtpdec.c rtpdec.h rtsp.c

mstorsjo subversion
Tue Apr 20 09:34:29 CEST 2010


Author: mstorsjo
Date: Tue Apr 20 09:34:28 2010
New Revision: 22917

Log:
Revert svn rev 21857, readd first_rtcp_ntp_time in RTPDemuxContext
    
In order to sync RTP streams that get their initial RTCP timestamp at
different times, propagate the NTP timestamp of the first RTCP packet
to all other streams.

This makes the timestamps of returned packets start at (near) zero instead
of at any random offset.

Modified:
   trunk/libavformat/rtpdec.c
   trunk/libavformat/rtpdec.h
   trunk/libavformat/rtsp.c

Modified: trunk/libavformat/rtpdec.c
==============================================================================
--- trunk/libavformat/rtpdec.c	Tue Apr 20 03:41:00 2010	(r22916)
+++ trunk/libavformat/rtpdec.c	Tue Apr 20 09:34:28 2010	(r22917)
@@ -80,6 +80,8 @@ static int rtcp_parse_packet(RTPDemuxCon
     if (buf[1] != 200)
         return -1;
     s->last_rtcp_ntp_time = AV_RB64(buf + 8);
+    if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE)
+        s->first_rtcp_ntp_time = s->last_rtcp_ntp_time;
     s->last_rtcp_timestamp = AV_RB32(buf + 16);
     return 0;
 }
@@ -326,6 +328,7 @@ RTPDemuxContext *rtp_parse_open(AVFormat
         return NULL;
     s->payload_type = payload_type;
     s->last_rtcp_ntp_time = AV_NOPTS_VALUE;
+    s->first_rtcp_ntp_time = AV_NOPTS_VALUE;
     s->ic = s1;
     s->st = st;
     s->rtp_payload_data = rtp_payload_data;
@@ -433,7 +436,7 @@ static void finalize_packet(RTPDemuxCont
         /* compute pts from timestamp with received ntp_time */
         delta_timestamp = timestamp - s->last_rtcp_timestamp;
         /* convert to the PTS timebase */
-        addend = av_rescale(s->last_rtcp_ntp_time, s->st->time_base.den, (uint64_t)s->st->time_base.num << 32);
+        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;
     }
 }

Modified: trunk/libavformat/rtpdec.h
==============================================================================
--- trunk/libavformat/rtpdec.h	Tue Apr 20 03:41:00 2010	(r22916)
+++ trunk/libavformat/rtpdec.h	Tue Apr 20 09:34:28 2010	(r22917)
@@ -174,6 +174,7 @@ struct RTPDemuxContext {
 
     /* rtcp sender statistics receive */
     int64_t last_rtcp_ntp_time;    // TODO: move into statistics
+    int64_t first_rtcp_ntp_time;   // TODO: move into statistics
     uint32_t last_rtcp_timestamp;  // TODO: move into statistics
 
     /* rtcp sender statistics */

Modified: trunk/libavformat/rtsp.c
==============================================================================
--- trunk/libavformat/rtsp.c	Tue Apr 20 03:41:00 2010	(r22916)
+++ trunk/libavformat/rtsp.c	Tue Apr 20 09:34:28 2010	(r22917)
@@ -1796,8 +1796,27 @@ static int rtsp_fetch_packet(AVFormatCon
         return AVERROR_EOF;
     if (rt->transport == RTSP_TRANSPORT_RDT) {
         ret = ff_rdt_parse_packet(rtsp_st->transport_priv, pkt, buf, len);
-    } else
+    } else {
         ret = rtp_parse_packet(rtsp_st->transport_priv, pkt, buf, len);
+        if (ret < 0) {
+            /* Either bad packet, or a RTCP packet. Check if the
+             * first_rtcp_ntp_time field was initialized. */
+            RTPDemuxContext *rtpctx = rtsp_st->transport_priv;
+            if (rtpctx->first_rtcp_ntp_time != AV_NOPTS_VALUE) {
+                /* first_rtcp_ntp_time has been initialized for this stream,
+                 * copy the same value to all other uninitialized streams,
+                 * in order to map their timestamp origin to the same ntp time
+                 * as this one. */
+                int i;
+                for (i = 0; i < rt->nb_rtsp_streams; i++) {
+                    RTPDemuxContext *rtpctx2 = rtsp_st->transport_priv;
+                    if (rtpctx2 &&
+                        rtpctx2->first_rtcp_ntp_time == AV_NOPTS_VALUE)
+                        rtpctx2->first_rtcp_ntp_time = rtpctx->first_rtcp_ntp_time;
+                }
+            }
+        }
+    }
     if (ret < 0)
         goto redo;
     if (ret == 1)



More information about the ffmpeg-cvslog mailing list