]> git.sesse.net Git - vlc/commitdiff
RTP: fix timestamp wrap - fix #1645
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 28 Mar 2010 17:56:14 +0000 (20:56 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 28 Mar 2010 17:57:52 +0000 (20:57 +0300)
modules/access/rtp/session.c

index c86aa08c49a32680767f48765e20bfb43292870e..5bf624cecbfe1c9d6fd5c27f61983e3983b9abdb 100644 (file)
@@ -141,6 +141,9 @@ struct rtp_source_t
     mtime_t  last_rx; /* last received packet local timestamp */
     uint32_t last_ts; /* last received packet RTP timestamp */
 
+    uint32_t ref_rtp; /* sender RTP timestamp reference */
+    mtime_t  ref_ntp; /* sender NTP timestamp reference */
+
     uint16_t bad_seq; /* tentatively next expected sequence for resync */
     uint16_t max_seq; /* next expected sequence */
 
@@ -164,6 +167,9 @@ rtp_source_create (demux_t *demux, const rtp_session_t *session,
 
     source->ssrc = ssrc;
     source->jitter = 0;
+    source->ref_rtp = 0;
+    /* TODO: use 0, but VLC does not like negative PTS at the moment */
+    source->ref_ntp = UINT64_C (1) << 62;
     source->max_seq = source->bad_seq = init_seq;
     source->last_seq = init_seq - 1;
     source->blocks = NULL;
@@ -408,10 +414,14 @@ rtp_decode (demux_t *demux, const rtp_session_t *session, rtp_source_t *src)
      * DTS is unknown. Also, while the clock frequency depends on the payload
      * format, a single source MUST only use payloads of a chosen frequency.
      * Otherwise it would be impossible to compute consistent timestamps. */
-    /* FIXME: handle timestamp wrap properly */
-    /* TODO: inter-medias/sessions sync (using RTCP-SR) */
     const uint32_t timestamp = rtp_timestamp (block);
-    block->i_pts = CLOCK_FREQ * timestamp / pt->frequency;
+    block->i_pts = src->ref_ntp
+       + CLOCK_FREQ * (int32_t)(timestamp - src->ref_rtp) / pt->frequency;
+    msg_Info (demux, "PTS = %lld, NTP = %lld, RTPd = %d",
+              block->i_pts, src->ref_ntp, timestamp - src->ref_rtp);
+    /* TODO: proper inter-medias/sessions sync (using RTCP-SR) */
+    src->ref_ntp = block->i_pts;
+    src->ref_rtp = timestamp;
 
     /* CSRC count */
     size_t skip = 12u + (block->p_buffer[0] & 0x0F) * 4;