]> git.sesse.net Git - vlc/blobdiff - src/input/input_clock.c
A BIG kludge for the calculation of mux_rate, so that times displayed in
[vlc] / src / input / input_clock.c
index bb4970d992eb7fe16145aab730bd01f2a200ab31..1b93e45138b1be4e7f9848a4f0e4ae62dd744bd2 100644 (file)
@@ -2,7 +2,7 @@
  * input_clock.c: Clock/System date convertions, stream management
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_clock.c,v 1.13 2001/04/29 14:52:42 stef Exp $
+ * $Id: input_clock.c,v 1.20 2001/07/18 14:21:00 massiot Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -38,8 +38,7 @@
 #include "stream_control.h"
 #include "input_ext-intf.h"
 #include "input_ext-dec.h"
-
-#include "input.h"
+#include "input_ext-plugins.h"
 
 /*
  * DISCUSSION : SYNCHRONIZATION METHOD
@@ -123,7 +122,7 @@ static void ClockNewRef( input_thread_t * p_input, pgrm_descriptor_t * p_pgrm,
                          mtime_t i_clock, mtime_t i_sysdate )
 {
     p_pgrm->cr_ref = i_clock;
-    p_pgrm->sysdate_ref = i_sysdate;
+    p_pgrm->sysdate_ref = p_pgrm->last_syscr ? p_pgrm->last_syscr : i_sysdate;
 }
 
 /*****************************************************************************
@@ -133,19 +132,92 @@ static void ClockNewRef( input_thread_t * p_input, pgrm_descriptor_t * p_pgrm,
 void input_ClockInit( pgrm_descriptor_t * p_pgrm )
 {
     p_pgrm->last_cr = 0;
+    p_pgrm->last_syscr = 0;
     p_pgrm->cr_ref = 0;
     p_pgrm->sysdate_ref = 0;
     p_pgrm->delta_cr = 0;
     p_pgrm->c_average_count = 0;
 }
 
+/*****************************************************************************
+ * input_ClockManageControl: handles the messages from the interface
+ *****************************************************************************
+ * Returns UNDEF_S if nothing happened, PAUSE_S if the stream was paused
+ *****************************************************************************/
+int input_ClockManageControl( input_thread_t * p_input,
+                               pgrm_descriptor_t * p_pgrm, mtime_t i_clock )
+{
+    int i_return_value = UNDEF_S;
+
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+
+    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_cond_wait( &p_input->stream.stream_wait,
+                       &p_input->stream.stream_lock );
+        ClockNewRef( p_input, p_pgrm, i_clock, mdate() );
+
+        if( p_input->stream.i_new_status == PAUSE_S )
+        { 
+            /* PAUSE_S undoes the pause state: Return to old state. */
+            p_input->stream.control.i_status = i_old_status;
+            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;
+    }
+
+    if( p_input->stream.i_new_status != UNDEF_S )
+    {
+        vlc_mutex_lock( &p_input->stream.control.control_lock );
+
+        p_input->stream.control.i_status = p_input->stream.i_new_status;
+
+        ClockNewRef( p_input, p_pgrm, i_clock,
+                     ClockToSysdate( p_input, p_pgrm, i_clock ) );
+
+        if( p_input->stream.control.i_status == PLAYING_S )
+        {
+            p_input->stream.control.i_rate = DEFAULT_RATE;
+            p_input->stream.control.b_mute = 0;
+        }
+        else
+        {
+            p_input->stream.control.i_rate = p_input->stream.i_new_rate;
+            p_input->stream.control.b_mute = 1;
+
+            /* Feed the audio decoders with a NULL packet to avoid
+             * discontinuities. */
+            input_EscapeAudioDiscontinuity( p_input );
+        }
+
+        p_input->stream.i_new_status = UNDEF_S;
+        p_input->stream.i_new_rate = UNDEF_S;
+
+        vlc_mutex_unlock( &p_input->stream.control.control_lock );
+    }
+
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
+
+    return( i_return_value );
+}
+
 /*****************************************************************************
  * input_ClockManageRef: manages a clock reference
  *****************************************************************************/
 void input_ClockManageRef( input_thread_t * p_input,
                            pgrm_descriptor_t * p_pgrm, mtime_t i_clock )
 {
-    if( p_pgrm->i_synchro_state != SYNCHRO_OK )
+    if( ( p_pgrm->i_synchro_state != SYNCHRO_OK ) || ( i_clock == 0 ) )
     {
         /* Feed synchro with a new reference point. */
         ClockNewRef( p_input, p_pgrm, i_clock, mdate() );
@@ -157,6 +229,13 @@ void input_ClockManageRef( input_thread_t * p_input,
             p_pgrm->last_cr = i_clock;
             mwait( ClockToSysdate( p_input, p_pgrm, i_clock ) );
         }
+        else
+        {
+            p_pgrm->last_cr = 0;
+            p_pgrm->last_syscr = 0;
+            p_pgrm->delta_cr = 0;
+            p_pgrm->c_average_count = 0;
+        }
     }
     else
     {
@@ -167,7 +246,7 @@ 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( 3, "Clock gap, unexpected stream discontinuity" );
+            intf_WarnMsg( 1, "Clock gap, unexpected stream discontinuity" );
             input_ClockInit( p_pgrm );
             p_pgrm->i_synchro_state = SYNCHRO_START;
             input_EscapeDiscontinuity( p_input, p_pgrm );
@@ -181,65 +260,11 @@ void input_ClockManageRef( input_thread_t * p_input,
             /* Wait a while before delivering the packets to the decoder.
              * In case of multiple programs, we arbitrarily follow the
              * clock of the first program. */
-            mwait( ClockToSysdate( p_input, p_pgrm, i_clock ) );
+            p_pgrm->last_syscr = ClockToSysdate( p_input, p_pgrm, i_clock );
+            mwait( p_pgrm->last_syscr );
 
             /* Now take into account interface changes. */
-            vlc_mutex_lock( &p_input->stream.stream_lock );
-
-            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_cond_wait( &p_input->stream.stream_wait,
-                               &p_input->stream.stream_lock );
-                ClockNewRef( p_input, p_pgrm, i_clock, mdate() );
-
-                if( p_input->stream.i_new_status == PAUSE_S )
-                { 
-                    /* PAUSE_S undoes the pause state: Return to old state. */
-                    p_input->stream.control.i_status = i_old_status;
-                    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 );
-            }
-
-            if( p_input->stream.i_new_status != UNDEF_S )
-            {
-                vlc_mutex_lock( &p_input->stream.control.control_lock );
-
-                p_input->stream.control.i_status = p_input->stream.i_new_status;
-
-                ClockNewRef( p_input, p_pgrm, i_clock,
-                           ClockToSysdate( p_input, p_pgrm, i_clock ) );
-
-                if( p_input->stream.control.i_status == PLAYING_S )
-                {
-                    p_input->stream.control.i_rate = DEFAULT_RATE;
-                    p_input->stream.control.b_mute = 0;
-                }
-                else
-                {
-                    p_input->stream.control.i_rate = p_input->stream.i_new_rate;
-                    p_input->stream.control.b_mute = 1;
-
-                    /* Feed the audio decoders with a NULL packet to avoid
-                     * discontinuities. */
-                    input_EscapeAudioDiscontinuity( p_input, p_pgrm );
-                }
-
-                p_input->stream.i_new_status = UNDEF_S;
-                p_input->stream.i_new_rate = UNDEF_S;
-
-                vlc_mutex_unlock( &p_input->stream.control.control_lock );
-            }
-
-            vlc_mutex_unlock( &p_input->stream.stream_lock );
+            input_ClockManageControl( p_input, p_pgrm, i_clock );
         }
         else
         {