[vlc-devel] [PATCH] input: clock: reset esout PCR on new clock synchro/gap

Francois Cartegnie fcvlcdev at free.fr
Fri Feb 17 15:48:27 CET 2017


Poor man's fix.
On unexpected clock gap (PCR diff > 60s), the synchro is fed with a new
point which is not propagated to program clocks or can match already
buffered data (hence the neverending 'cannot convert timestamp') in that
case.

refs #17541, #18026
---
 src/input/clock.c  | 18 +++++++-----------
 src/input/clock.h  |  2 +-
 src/input/es_out.c | 12 ++++++++----
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/input/clock.c b/src/input/clock.c
index e1cc0fc..cb58acd 100644
--- a/src/input/clock.c
+++ b/src/input/clock.c
@@ -237,22 +237,18 @@ void input_clock_Delete( input_clock_t *cl )
  *  i_ck_system: date in system clock
  *****************************************************************************/
 void input_clock_Update( input_clock_t *cl, vlc_object_t *p_log,
-                         bool *pb_late,
+                         bool *pb_late, bool *pb_reset_reference,
                          bool b_can_pace_control, bool b_buffering_allowed,
                          mtime_t i_ck_stream, mtime_t i_ck_system )
 {
-    bool b_reset_reference = false;
+    *pb_reset_reference = false;
 
     assert( i_ck_stream > VLC_TS_INVALID && i_ck_system > VLC_TS_INVALID );
 
     vlc_mutex_lock( &cl->lock );
 
-    if( !cl->b_has_reference )
-    {
-        /* */
-        b_reset_reference= true;
-    }
-    else if( cl->last.i_stream > VLC_TS_INVALID &&
+    if( cl->b_has_reference &&
+             cl->last.i_stream > VLC_TS_INVALID &&
              ( (cl->last.i_stream - i_ck_stream) > CR_MAX_GAP ||
                (cl->last.i_stream - i_ck_stream) < -CR_MAX_GAP ) )
     {
@@ -264,11 +260,11 @@ void input_clock_Update( input_clock_t *cl, vlc_object_t *p_log,
 
         /* */
         msg_Warn( p_log, "feeding synchro with a new reference point trying to recover from clock gap" );
-        b_reset_reference= true;
+        *pb_reset_reference = true;
     }
 
     /* */
-    if( b_reset_reference )
+    if( !cl->b_has_reference || *pb_reset_reference )
     {
         cl->i_next_drift_update = VLC_TS_INVALID;
         AvgReset( &cl->drift );
@@ -292,7 +288,7 @@ void input_clock_Update( input_clock_t *cl, vlc_object_t *p_log,
     }
 
     /* Update the extra buffering value */
-    if( !b_can_pace_control || b_reset_reference )
+    if( !b_can_pace_control || *pb_reset_reference )
     {
         cl->i_buffering_duration = 0;
     }
diff --git a/src/input/clock.h b/src/input/clock.h
index dc4c8bd..a454bf1 100644
--- a/src/input/clock.h
+++ b/src/input/clock.h
@@ -55,7 +55,7 @@ void           input_clock_Delete( input_clock_t * );
  * advanced (if possible).
  */
 void    input_clock_Update( input_clock_t *, vlc_object_t *p_log,
-                            bool *pb_late,
+                            bool *pb_late, bool *pb_reset,
                             bool b_can_pace_control, bool b_buffering_allowed,
                             mtime_t i_clock, mtime_t i_system );
 /**
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 490ee9c..126c957 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -2380,9 +2380,9 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
         }
 
         /* TODO do not use mdate() but proper stream acquisition date */
-        bool b_late;
+        bool b_late; bool b_clock_reset;
         input_clock_Update( p_pgrm->p_clock, VLC_OBJECT(p_sys->p_input),
-                            &b_late,
+                            &b_late, &b_clock_reset,
                             input_priv(p_sys->p_input)->b_can_pace_control || p_sys->b_buffering,
                             EsOutIsExtraBufferingAllowed( out ),
                             i_pcr, mdate() );
@@ -2397,8 +2397,12 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
         }
         else if( p_pgrm == p_sys->p_pgrm )
         {
-            if( b_late && ( !input_priv(p_sys->p_input)->p_sout ||
-                            !input_priv(p_sys->p_input)->b_out_pace_control ) )
+            if( b_clock_reset )
+            {
+                es_out_Control( out, ES_OUT_RESET_PCR );
+            }
+            else if( b_late && ( !input_priv(p_sys->p_input)->p_sout ||
+                     !input_priv(p_sys->p_input)->b_out_pace_control ) )
             {
                 const mtime_t i_pts_delay_base = p_sys->i_pts_delay - p_sys->i_pts_jitter;
                 mtime_t i_pts_delay = input_clock_GetJitter( p_pgrm->p_clock );
-- 
2.9.3



More information about the vlc-devel mailing list