]> git.sesse.net Git - vlc/blobdiff - src/input/input_clock.c
* ./include/*, ./src/*: separated WIN32 #tests and UNDER_CE #tests, because
[vlc] / src / input / input_clock.c
index 9b24f651b447d335826cc9d99f38b0b819a4dd1d..1b9f7e2647f2d90efd0f760bcec21abb8d1b330e 100644 (file)
@@ -2,7 +2,7 @@
  * input_clock.c: Clock/System date convertions, stream management
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: input_clock.c,v 1.24 2001/11/28 15:08:06 massiot Exp $
+ * $Id: input_clock.c,v 1.34 2002/11/11 14:39:12 sam Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include "defs.h"
-
 #include <string.h>                                    /* memcpy(), memset() */
-#include <sys/types.h>                                              /* off_t */
 
-#include "config.h"
-#include "common.h"
-#include "intf_msg.h"
-#include "threads.h"
-#include "mtime.h"
+#include <vlc/vlc.h>
 
 #include "stream_control.h"
 #include "input_ext-intf.h"
@@ -161,10 +154,12 @@ int input_ClockManageControl( input_thread_t * p_input,
     if( p_input->stream.i_new_status == PAUSE_S )
     {
         int i_old_status;
+
         vlc_mutex_lock( &p_input->stream.control.control_lock );
         i_old_status = p_input->stream.control.i_status;
-
         p_input->stream.control.i_status = PAUSE_S;
+        vlc_mutex_unlock( &p_input->stream.control.control_lock );
+        
         vlc_cond_wait( &p_input->stream.stream_wait,
                        &p_input->stream.stream_lock );
         p_pgrm->last_syscr = 0;
@@ -173,13 +168,15 @@ int input_ClockManageControl( input_thread_t * p_input,
         if( p_input->stream.i_new_status == PAUSE_S )
         { 
             /* PAUSE_S undoes the pause state: Return to old state. */
+            vlc_mutex_lock( &p_input->stream.control.control_lock );
             p_input->stream.control.i_status = i_old_status;
+            vlc_mutex_unlock( &p_input->stream.control.control_lock );
+            
             p_input->stream.i_new_status = UNDEF_S;
             p_input->stream.i_new_rate = UNDEF_S;
         }
 
         /* We handle i_new_status != PAUSE_S below... */
-        vlc_mutex_unlock( &p_input->stream.control.control_lock );
 
         i_return_value = PAUSE_S;
     }
@@ -225,6 +222,12 @@ int input_ClockManageControl( input_thread_t * p_input,
 void input_ClockManageRef( input_thread_t * p_input,
                            pgrm_descriptor_t * p_pgrm, mtime_t i_clock )
 {
+    /* take selected program if none specified */
+    if( !p_pgrm )
+    {
+        p_pgrm = p_input->stream.p_selected_program;
+    }
+
     if( ( p_pgrm->i_synchro_state != SYNCHRO_OK ) || ( i_clock == 0 ) )
     {
         /* Feed synchro with a new reference point. */
@@ -232,7 +235,7 @@ void input_ClockManageRef( input_thread_t * p_input,
         p_pgrm->i_synchro_state = SYNCHRO_OK;
 
         if( p_input->stream.b_pace_control
-             && p_input->stream.pp_programs[0] == p_pgrm )
+             && p_input->stream.p_selected_program == p_pgrm )
         {
             p_pgrm->last_cr = i_clock;
             mwait( ClockToSysdate( p_input, p_pgrm, i_clock ) );
@@ -254,16 +257,16 @@ void input_ClockManageRef( input_thread_t * p_input,
             /* Stream discontinuity, for which we haven't received a
              * warning from the stream control facilities (dd-edited
              * stream ?). */
-            intf_WarnMsg( 1, "Clock gap, unexpected stream discontinuity" );
+            msg_Warn( p_input, "clock gap, unexpected stream discontinuity" );
             input_ClockInit( p_pgrm );
             p_pgrm->i_synchro_state = SYNCHRO_START;
-            input_EscapeDiscontinuity( p_input, p_pgrm );
+            input_EscapeDiscontinuity( p_input );
         }
 
         p_pgrm->last_cr = i_clock;
 
         if( p_input->stream.b_pace_control
-             && p_input->stream.pp_programs[0] == p_pgrm )
+             && p_input->stream.p_selected_program == p_pgrm )
         {
             /* We remember the last system date to be able to restart
              * the synchro we statistically better continuity, after 
@@ -309,10 +312,18 @@ void input_ClockManageRef( input_thread_t * p_input,
 mtime_t input_ClockGetTS( input_thread_t * p_input,
                           pgrm_descriptor_t * p_pgrm, mtime_t i_ts )
 {
+    /* take selected program if none specified */
+    if( !p_pgrm )
+    {
+        p_pgrm = p_input->stream.p_selected_program;
+    }
+
     if( p_pgrm->i_synchro_state == SYNCHRO_OK )
     {
         return( ClockToSysdate( p_input, p_pgrm, i_ts + p_pgrm->delta_cr )
-                 + DEFAULT_PTS_DELAY );
+                 + DEFAULT_PTS_DELAY
+                 + (p_input->p_vlc->i_desync > 0
+                       ? p_input->p_vlc->i_desync : 0) );
     }
     else
     {