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

Francois Cartegnie fcvlcdev at free.fr
Fri Aug 5 23:41:28 CEST 2016


---
 modules/access/live555.cpp | 61 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 44 insertions(+), 17 deletions(-)

diff --git a/modules/access/live555.cpp b/modules/access/live555.cpp
index bc5a9fa..019a48c 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_pcr;
     double          f_npt;
 
     bool            b_selected;
@@ -838,7 +840,9 @@ static int SessionsSetup( demux_t *p_demux )
             tk->p_out_muxed = NULL;
             tk->waiting     = 0;
             tk->b_rtcp_sync = false;
+            tk->b_discontinuity = false;
             tk->i_pts       = VLC_TS_INVALID;
+            tk->i_pcr       = VLC_TS_INVALID;
             tk->f_npt       = 0.;
             tk->b_selected  = true;
             tk->i_buffer    = i_frame_buffer;
@@ -1346,11 +1350,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;
@@ -1374,25 +1373,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 */
+    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_pts = 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 ) )
@@ -1526,6 +1541,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
                 {
                     p_sys->track[i]->b_rtcp_sync = false;
                     p_sys->track[i]->i_pts = VLC_TS_INVALID;
+                    p_sys->track[i]->i_pcr = VLC_TS_INVALID;
                 }
 
                 /* Retrieve the starttime if possible */
@@ -1668,7 +1684,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->b_discontinuity = false;
                     tk->i_pts = 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 );
@@ -2025,9 +2043,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 */
-- 
2.7.4



More information about the vlc-devel mailing list