]> git.sesse.net Git - vlc/blobdiff - src/input/clock.c
macosx: Fix controller playlist toggling to use the contentRect and not the window...
[vlc] / src / input / clock.c
index 9043328827d261b0ffc5b1c69951bf8fe13108a0..27ab13ae76cbac1caa7d830edc87b1567279380b 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
 
 #include "input_internal.h"
 
@@ -72,7 +75,7 @@ static void ClockNewRef( input_clock_t * p_pgrm,
  *****************************************************************************/
 
 /* Maximum gap allowed between two CRs. */
-#define CR_MAX_GAP (I64C(2000000)*100/9)
+#define CR_MAX_GAP (INT64_C(2000000)*100/9)
 
 /* Latency introduced on DVDs with CR == 0 on chapter change - this is from
  * my dice --Meuuh */
@@ -115,8 +118,7 @@ static void ClockNewRef( input_clock_t *cl,
  * input_ClockInit: reinitializes the clock reference after a stream
  *                  discontinuity
  *****************************************************************************/
-void input_ClockInit( input_thread_t *p_input,
-                      input_clock_t *cl, vlc_bool_t b_master, int i_cr_average )
+void input_ClockInit( input_clock_t *cl, bool b_master, int i_cr_average, int i_rate )
 {
     cl->i_synchro_state = SYNCHRO_START;
 
@@ -127,7 +129,7 @@ void input_ClockInit( input_thread_t *p_input,
     cl->sysdate_ref = 0;
     cl->delta_cr = 0;
     cl->i_delta_cr_residue = 0;
-    cl->i_rate = p_input->p->i_rate;
+    cl->i_rate = i_rate;
 
     cl->i_cr_average = i_cr_average;
 
@@ -140,7 +142,7 @@ void input_ClockInit( input_thread_t *p_input,
 void input_ClockSetPCR( input_thread_t *p_input,
                         input_clock_t *cl, mtime_t i_clock )
 {
-    const vlc_bool_t b_synchronize = p_input->b_can_pace_control && cl->b_master;
+    const bool b_synchronize = p_input->b_can_pace_control && cl->b_master;
     const mtime_t i_mdate = mdate();
 
     if( ( cl->i_synchro_state != SYNCHRO_OK ) ||
@@ -153,10 +155,8 @@ void input_ClockSetPCR( input_thread_t *p_input,
 
         if( !b_synchronize )
         {
-            cl->last_cr = 0;
             cl->delta_cr = 0;
             cl->i_delta_cr_residue = 0;
-            cl->last_sysdate = 0;
             cl->last_update = 0;
         }
     }
@@ -168,7 +168,12 @@ void input_ClockSetPCR( input_thread_t *p_input,
          * warning from the stream control facilities (dd-edited
          * stream ?). */
         msg_Warn( p_input, "clock gap, unexpected stream discontinuity" );
-        input_ClockInit( p_input, cl, cl->b_master, cl->i_cr_average );
+        input_ClockInit( cl, cl->b_master, cl->i_cr_average, cl->i_rate );
+        /* Feed synchro with a new reference point. */
+        msg_Warn( p_input, "feeding synchro with a new reference point trying to recover from clock gap" );
+        ClockNewRef( cl, i_clock,
+                         __MAX( cl->last_pts + CR_MEAN_PTS_GAP, i_mdate ) );
+        cl->i_synchro_state = SYNCHRO_OK;
     }
 
     cl->last_cr = i_clock;
@@ -206,6 +211,15 @@ void input_ClockSetPCR( input_thread_t *p_input,
     }
 }
 
+/*****************************************************************************
+ * input_ClockResetPCR:
+ *****************************************************************************/
+void input_ClockResetPCR( input_clock_t *cl )
+{
+    cl->i_synchro_state =  SYNCHRO_REINIT;
+    cl->last_pts = 0;
+}
+
 /*****************************************************************************
  * input_ClockGetTS: manages a PTS or DTS
  *****************************************************************************/
@@ -222,14 +236,12 @@ mtime_t input_ClockGetTS( input_thread_t * p_input,
 /*****************************************************************************
  * input_ClockSetRate:
  *****************************************************************************/
-void input_ClockSetRate( input_thread_t *p_input, input_clock_t *cl )
+void input_ClockSetRate( input_clock_t *cl, int i_rate )
 {
+    /* Move the reference point */
     if( cl->i_synchro_state == SYNCHRO_OK )
-    {
-        /* Move the reference point */
-        cl->cr_ref = cl->last_cr;
-        cl->sysdate_ref = cl->last_sysdate;
-    }
-    cl->i_rate = p_input->p->i_rate;
+        ClockNewRef( cl, cl->last_cr, cl->last_sysdate );
+
+    cl->i_rate = i_rate;
 }