[vlc-devel] commit: Removed the ugly input clock.c sleep. (Laurent Aimar )

git version control git at videolan.org
Sun Sep 28 13:35:56 CEST 2008


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Tue Sep 23 22:13:17 2008 +0200| [987d3a8595102368d0098c5d0f817247a9b10ecf] | committer: Laurent Aimar 

Removed the ugly input clock.c sleep.

The input main loop will now handles space control at the right place.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=987d3a8595102368d0098c5d0f817247a9b10ecf
---

 src/input/clock.c          |   43 +++++++++++++++++++------------
 src/input/es_out.c         |    9 ++++++
 src/input/input.c          |   60 +++++++++++++++++++++++++-------------------
 src/input/input_internal.h |   12 ++------
 4 files changed, 72 insertions(+), 52 deletions(-)

diff --git a/src/input/clock.c b/src/input/clock.c
index 27ab13a..5aae7c7 100644
--- a/src/input/clock.c
+++ b/src/input/clock.c
@@ -66,6 +66,12 @@
  * new_average = (old_average * c_average + new_sample_value) / (c_average +1)
  */
 
+enum /* Synchro states */
+{
+    SYNCHRO_OK     = 0,
+    SYNCHRO_START  = 1,
+    SYNCHRO_REINIT = 2,
+};
 
 static void ClockNewRef( input_clock_t * p_pgrm,
                          mtime_t i_clock, mtime_t i_sysdate );
@@ -179,23 +185,7 @@ void input_ClockSetPCR( input_thread_t *p_input,
     cl->last_cr = i_clock;
     cl->last_sysdate = i_mdate;
 
-    if( b_synchronize )
-    {
-        /* Wait a while before delivering the packets to the decoder.
-         * In case of multiple programs, we arbitrarily follow the
-         * clock of the selected program. */
-        if( !p_input->p->b_out_pace_control )
-        {
-            mtime_t i_wakeup = ClockToSysdate( cl, i_clock );
-            while( (i_wakeup - mdate()) / CLOCK_FREQ > 1 )
-            {
-                msleep( CLOCK_FREQ );
-                if( p_input->b_die ) i_wakeup = mdate();
-            }
-            mwait( i_wakeup );
-        }
-    }
-    else if ( i_mdate - cl->last_update > 200000 )
+    if( !b_synchronize && i_mdate - cl->last_update > 200000 )
     {
         /* Smooth clock reference variations. */
         const mtime_t i_extrapoled_clock = ClockCurrent( cl );
@@ -245,3 +235,22 @@ void input_ClockSetRate( input_clock_t *cl, int i_rate )
     cl->i_rate = i_rate;
 }
 
+/*****************************************************************************
+ * input_ClockGetWakeup
+ *****************************************************************************/
+mtime_t input_ClockGetWakeup( input_thread_t *p_input, input_clock_t *cl )
+{
+    /* Not synchronized, we cannot wait */
+    if( cl->i_synchro_state != SYNCHRO_OK )
+        return 0;
+
+    /* We must not wait if not pace controled, or we are not the
+     * master clock */
+    if( !p_input->b_can_pace_control || !cl->b_master ||
+        p_input->p->b_out_pace_control )
+        return 0;
+
+    /* */
+    return ClockToSysdate( cl, cl->last_cr );
+}
+
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 9e4819a..2d25cb7 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -348,6 +348,15 @@ es_out_id_t *input_EsOutGetFromID( es_out_t *out, int i_id )
     return NULL;
 }
 
+mtime_t input_EsOutGetWakeup( es_out_t *out )
+{
+    es_out_sys_t      *p_sys = out->p_sys;
+
+    if( !p_sys->p_pgrm )
+        return 0;
+    return input_ClockGetWakeup( p_sys->p_input, &p_sys->p_pgrm->clock );
+}
+
 static void EsOutDiscontinuity( es_out_t *out, bool b_flush, bool b_audio )
 {
     es_out_sys_t      *p_sys = out->p_sys;
diff --git a/src/input/input.c b/src/input/input.c
index ff9770a..5019dd4 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -727,40 +727,48 @@ static void MainLoop( input_thread_t *p_input )
         vlc_value_t val;
         mtime_t i_current;
         mtime_t i_deadline;
+        mtime_t i_wakeup;
 
         /* Demux data */
         b_force_update = false;
+        i_wakeup = 0;
         if( p_input->i_state != PAUSE_S )
+        {
             MainLoopDemux( p_input, &b_force_update, &i_start_mdate );
+            i_wakeup = input_EsOutGetWakeup( p_input->p->p_es_out );
+        }
 
         /* */
-        i_deadline = 0;
-        if( p_input->i_state == PAUSE_S )
-            i_deadline = __MIN( i_intf_update, i_statistic_update );
-
-        /* Handle control */
-        vlc_mutex_lock( &p_input->p->lock_control );
-        ControlReduce( p_input );
-        while( !ControlPopNoLock( p_input, &i_type, &val, i_deadline ) )
-        {
-            msg_Dbg( p_input, "control type=%d", i_type );
-            if( Control( p_input, i_type, val ) )
-                b_force_update = true;
-        }
-        vlc_mutex_unlock( &p_input->p->lock_control );
+        do {
+            i_deadline = i_wakeup;
+            if( p_input->i_state == PAUSE_S )
+                i_deadline = __MIN( i_intf_update, i_statistic_update );
+
+            /* Handle control */
+            vlc_mutex_lock( &p_input->p->lock_control );
+            ControlReduce( p_input );
+            while( !ControlPopNoLock( p_input, &i_type, &val, i_deadline ) )
+            {
+                msg_Dbg( p_input, "control type=%d", i_type );
+                if( Control( p_input, i_type, val ) )
+                    b_force_update = true;
+            }
+            vlc_mutex_unlock( &p_input->p->lock_control );
 
-        /* Update interface and statistics */
-        i_current = mdate();
-        if( i_intf_update < i_current || b_force_update )
-        {
-            MainLoopInterface( p_input );
-            i_intf_update = i_current + INT64_C(250000);
-        }
-        if( i_statistic_update < i_current )
-        {
-            MainLoopStatistic( p_input );
-            i_statistic_update = i_current + INT64_C(1000000);
-        }
+            /* Update interface and statistics */
+            i_current = mdate();
+            if( i_intf_update < i_current || b_force_update )
+            {
+                MainLoopInterface( p_input );
+                i_intf_update = i_current + INT64_C(250000);
+                b_force_update = false;
+            }
+            if( i_statistic_update < i_current )
+            {
+                MainLoopStatistic( p_input );
+                i_statistic_update = i_current + INT64_C(1000000);
+            }
+        } while( i_current < i_wakeup );
     }
 
     if( !p_input->b_eof && !p_input->b_error && p_input->p->input.b_eof )
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index cb6642b..fadc167 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -347,21 +347,14 @@ void       input_DecoderIsCcPresent( decoder_t *, bool pb_present[4] );
 es_out_t  *input_EsOutNew( input_thread_t *, int i_rate );
 void       input_EsOutDelete( es_out_t * );
 es_out_id_t *input_EsOutGetFromID( es_out_t *, int i_id );
+mtime_t    input_EsOutGetWakeup( es_out_t * );
 void       input_EsOutSetDelay( es_out_t *, int i_cat, int64_t );
-int        input_EsOutSetRecord(  es_out_t *, bool b_record );
+int        input_EsOutSetRecord( es_out_t *, bool b_record );
 void       input_EsOutChangeRate( es_out_t *, int );
 void       input_EsOutChangeState( es_out_t * );
 void       input_EsOutChangePosition( es_out_t * );
 bool input_EsOutDecodersEmpty( es_out_t * );
 
-/* clock.c */
-enum /* Synchro states */
-{
-    SYNCHRO_OK     = 0,
-    SYNCHRO_START  = 1,
-    SYNCHRO_REINIT = 2,
-};
-
 typedef struct
 {
     /* Synchronization information */
@@ -388,6 +381,7 @@ void    input_ClockSetPCR( input_thread_t *, input_clock_t *, mtime_t );
 void    input_ClockResetPCR( input_clock_t * );
 mtime_t input_ClockGetTS( input_thread_t *, input_clock_t *, mtime_t );
 void    input_ClockSetRate( input_clock_t *cl, int i_rate );
+mtime_t input_ClockGetWakeup( input_thread_t *, input_clock_t *cl );
 
 /* Subtitles */
 char **subtitles_Detect( input_thread_t *, char* path, const char *fname );




More information about the vlc-devel mailing list