[vlc-commits] access: live555: fix spurious PCR_RESET on RTCP clock synchronization

Francois Cartegnie git at videolan.org
Thu Aug 11 10:54:16 CEST 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Aug  5 22:29:45 2016 +0200| [087960fd46de8f292a0742fe00777073e103a3cc] | committer: Francois Cartegnie

access: live555: fix spurious PCR_RESET on RTCP clock synchronization

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=087960fd46de8f292a0742fe00777073e103a3cc
---

 modules/access/live555.cpp | 75 +++++++++++++++++++++++++++++++---------------
 1 file changed, 51 insertions(+), 24 deletions(-)

diff --git a/modules/access/live555.cpp b/modules/access/live555.cpp
index f01afd6..9a14c12 100644
--- a/modules/access/live555.cpp
+++ b/modules/access/live555.cpp
@@ -165,8 +165,10 @@ typedef struct
     unsigned int    i_buffer;
 
     bool            b_rtcp_sync;
+    bool            b_discontinuity;
     char            waiting;
-    int64_t         i_pts;
+    int64_t         i_lastpts;
+    int64_t         i_pcr;
     double          f_npt;
 
     bool            b_selected;
@@ -819,7 +821,9 @@ static int SessionsSetup( demux_t *p_demux )
             tk->p_out_muxed = NULL;
             tk->waiting     = 0;
             tk->b_rtcp_sync = false;
-            tk->i_pts       = VLC_TS_INVALID;
+            tk->b_discontinuity = false;
+            tk->i_lastpts   = VLC_TS_INVALID;
+            tk->i_pcr       = VLC_TS_INVALID;
             tk->f_npt       = 0.;
             tk->b_selected  = true;
             tk->i_buffer    = i_frame_buffer;
@@ -1293,11 +1297,6 @@ static int Demux( demux_t *p_demux )
         if( tk->b_asf || tk->b_muxed )
             b_send_pcr = false;
     }
-    if( p_sys->i_pcr > VLC_TS_INVALID )
-    {
-        if( b_send_pcr )
-            es_out_Control( p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_pcr );
-    }
 
     /* First warn we want to read data */
     p_sys->event_data = 0;
@@ -1321,25 +1320,41 @@ static int Demux( demux_t *p_demux )
     /* remove the task */
     p_sys->scheduler->unscheduleDelayedTask( task );
 
+    mtime_t i_minpcr = VLC_TS_INVALID;
+    bool b_discontinuity = false;
+
     /* Check for gap in pts value */
     for( i = 0; i < p_sys->i_track; i++ )
     {
-        live_track_t *tk = p_sys->track[i];
+        const live_track_t *tk = p_sys->track[i];
 
-        if( !tk->b_muxed && !tk->b_rtcp_sync &&
-            tk->sub->rtpSource() && tk->sub->rtpSource()->hasBeenSynchronizedUsingRTCP() )
-        {
-            msg_Dbg( p_demux, "tk->rtpSource->hasBeenSynchronizedUsingRTCP()" );
+        /* Check for gap in pts value */
+        b_discontinuity |= (tk->b_muxed && tk->b_discontinuity);
+
+        if( i_minpcr == VLC_TS_INVALID || i_minpcr > tk->i_pcr )
+            i_minpcr = tk->i_pcr;
+    }
 
-            es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
-            tk->b_rtcp_sync = true;
-            /* reset PCR */
-            tk->i_pts = VLC_TS_INVALID;
+    if( p_sys->i_pcr > VLC_TS_INVALID && b_discontinuity )
+    {
+        es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
+        p_sys->i_pcr = 0;
+        p_sys->f_npt = 0.;
+
+        for( i = 0; i < p_sys->i_track; i++ )
+        {
+            live_track_t *tk = p_sys->track[i];
+            tk->i_lastpts = VLC_TS_INVALID;
+            tk->i_pcr = VLC_TS_INVALID;
             tk->f_npt = 0.;
-            p_sys->i_pcr = 0;
-            p_sys->f_npt = 0.;
+            tk->b_discontinuity = false;
         }
     }
+    else if( b_send_pcr && i_minpcr > VLC_TS_INVALID && i_minpcr > p_sys->i_pcr + CLOCK_FREQ / 4 )
+    {
+        p_sys->i_pcr = i_minpcr;
+        es_out_Control( p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_pcr );
+    }
 
     if( p_sys->b_multicast && p_sys->b_no_data &&
         ( p_sys->i_no_data_ti > 120 ) )
@@ -1472,7 +1487,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
                 for( i = 0; i < p_sys->i_track; i++ )
                 {
                     p_sys->track[i]->b_rtcp_sync = false;
-                    p_sys->track[i]->i_pts = VLC_TS_INVALID;
+                    p_sys->track[i]->i_lastpts = VLC_TS_INVALID;
+                    p_sys->track[i]->i_pcr = VLC_TS_INVALID;
                 }
 
                 /* Retrieve the starttime if possible */
@@ -1602,7 +1618,9 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
                 {
                     live_track_t *tk = p_sys->track[i];
                     tk->b_rtcp_sync = false;
-                    tk->i_pts = VLC_TS_INVALID;
+                    tk->b_discontinuity = false;
+                    tk->i_lastpts = VLC_TS_INVALID;
+                    tk->i_pcr = VLC_TS_INVALID;
                 }
                 p_sys->i_pcr = VLC_TS_INVALID;
                 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
@@ -1960,9 +1978,18 @@ static void StreamRead( void *p_private, unsigned int i_size,
         memcpy( p_block->p_buffer, tk->p_buffer, i_size );
     }
 
-    if( p_sys->i_pcr < i_pts )
+    /* No data sent. Always in sync then */
+    if( !tk->b_rtcp_sync && tk->sub->rtpSource() &&
+         tk->sub->rtpSource()->hasBeenSynchronizedUsingRTCP() )
+    {
+        msg_Dbg( p_demux, "tk->rtpSource->hasBeenSynchronizedUsingRTCP()" );
+        tk->b_rtcp_sync = true;
+        tk->b_discontinuity = ( tk->i_pcr > VLC_TS_INVALID );
+    }
+
+    if( tk->i_pcr < i_pts )
     {
-        p_sys->i_pcr = i_pts;
+        tk->i_pcr = i_pts;
     }
 
     /* Update our global npt value */
@@ -1974,7 +2001,7 @@ static void StreamRead( void *p_private, unsigned int i_size,
     {
         if( !tk->b_muxed && !tk->b_asf )
         {
-            if( i_pts != tk->i_pts )
+            if( i_pts != tk->i_lastpts )
                 p_block->i_pts = VLC_TS_0 + i_pts;
             /*FIXME: for h264 you should check that packetization-mode=1 in sdp-file */
             p_block->i_dts = ( tk->fmt.i_codec == VLC_CODEC_MPGV ) ? VLC_TS_INVALID : (VLC_TS_0 + i_pts);
@@ -1998,7 +2025,7 @@ static void StreamRead( void *p_private, unsigned int i_size,
 
     if( i_pts > 0 && !tk->b_muxed )
     {
-        tk->i_pts = i_pts;
+        tk->i_lastpts = i_pts;
     }
 }
 



More information about the vlc-commits mailing list