]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
Correctly display time and seek with high input caching.
[vlc] / src / input / input.c
index a31f7ee701db3b80c735f6dd587f8dead6bcfc72..ba75afac575b896e565f91ce9a9c7a0f5c769fce 100644 (file)
@@ -198,7 +198,6 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     p_input->p->input.b_rescale_ts = true;
     p_input->p->input.b_eof = false;
     p_input->p->input.i_cr_average = 0;
-    memset( &p_input->p->input_last_times, 0, sizeof(p_input->p->input_last_times) );
 
     vlc_mutex_lock( &p_item->lock );
 
@@ -645,52 +644,24 @@ static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, mtime_t *p
  */
 static void MainLoopInterface( input_thread_t *p_input )
 {
-    input_event_times_t ev;
-    mtime_t i_es_out_delay;
-
-    es_out_GetBuffering( p_input->p->p_es_out, &i_es_out_delay );
-
-    ev.f_position = 0.0;
-    ev.i_time = 0;
-    ev.i_length = 0;
+    double f_position = 0.0;
+    mtime_t i_time = 0;
+    mtime_t i_length = 0;
 
     /* update input status variables */
     if( demux_Control( p_input->p->input.p_demux,
-                       DEMUX_GET_POSITION, &ev.f_position ) )
-        ev.f_position = 0.0;
+                       DEMUX_GET_POSITION, &f_position ) )
+        f_position = 0.0;
 
     if( demux_Control( p_input->p->input.p_demux,
-                       DEMUX_GET_TIME, &ev.i_time ) )
-        ev.i_time = 0;
+                       DEMUX_GET_TIME, &i_time ) )
+        i_time = 0;
 
     if( demux_Control( p_input->p->input.p_demux,
-                       DEMUX_GET_LENGTH, &ev.i_length ) )
-        ev.i_length = 0;
-
-    if( ev.i_time > 0 )
-    {
-        ev.i_time -= i_es_out_delay;
-        if( ev.i_time < 0 )
-            ev.i_time = 0;
-    }
-    if( ev.i_length > 0 )
-    {
-        ev.f_position -= (double)i_es_out_delay / ev.i_length;
-    }
+                       DEMUX_GET_LENGTH, &i_length ) )
+        i_length = 0;
 
-    if( p_input->i_state == PAUSE_S )
-    {
-        input_event_times_t old = p_input->p->input_last_times;
-
-        /* XXX We have a jitter because of PCR frequency/get time precision.
-         * Hides it */
-        if( llabs(ev.i_time - old.i_time) < CLOCK_FREQ )
-            ev.i_time = old.i_time;
-    }
-
-    p_input->p->input_last_times = ev;
-
-    input_SendEventTimes( p_input, &ev );
+    es_out_SetTimes( p_input->p->p_es_out, f_position, i_time, i_length );
 }
 
 /**
@@ -739,7 +710,7 @@ static void MainLoop( input_thread_t *p_input )
          * is paused -> this may cause problem with some of them
          * The same problem can be seen when seeking while paused */
         b_paused = p_input->i_state == PAUSE_S &&
-                   !es_out_GetBuffering( p_input->p->p_es_out, NULL );
+                   !es_out_GetBuffering( p_input->p->p_es_out );
 
         if( !b_paused )
         {
@@ -1192,15 +1163,13 @@ static int Init( input_thread_t * p_input )
 
     /* Load master infos */
     /* Init length */
-    input_event_times_t ev_times;
-    ev_times.f_position = 0;
-    ev_times.i_time = 0;
+    mtime_t i_length;
     if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_LENGTH,
-                         &ev_times.i_length ) )
-        ev_times.i_length = 0;
-    if( ev_times.i_length <= 0 )
-        ev_times.i_length = input_item_GetDuration( p_input->p->input.p_item );
-    input_SendEventTimes( p_input, &ev_times );
+                         &i_length ) )
+        i_length = 0;
+    if( i_length <= 0 )
+        i_length = input_item_GetDuration( p_input->p->input.p_item );
+    input_SendEventTimes( p_input, 0.0, 0, i_length );
 
     StartTitle( p_input );
 
@@ -1328,6 +1297,10 @@ static void End( input_thread_t * p_input )
     /* Clean control variables */
     input_ControlVarStop( p_input );
 
+    /* Stop es out activity */
+    es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, false );
+    es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
+
     /* Clean up master */
     InputSourceClean( &p_input->p->input );
 
@@ -1607,19 +1580,13 @@ static bool Control( input_thread_t *p_input, int i_type,
                 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) ignored while recording" );
                 break;
             }
-            if( i_type == INPUT_CONTROL_SET_POSITION )
-            {
-                f_pos = val.f_float;
-            }
-            else
-            {
-                /* Should not fail */
-                demux_Control( p_input->p->input.p_demux,
-                                DEMUX_GET_POSITION, &f_pos );
-                f_pos += val.f_float;
-            }
-            if( f_pos < 0.0 ) f_pos = 0.0;
-            if( f_pos > 1.0 ) f_pos = 1.0;
+            f_pos = val.f_float;
+            if( i_type != INPUT_CONTROL_SET_POSITION )
+                f_pos += var_GetFloat( p_input, "position" );
+            if( f_pos < 0.0 )
+                f_pos = 0.0;
+            else if( f_pos > 1.0 )
+                f_pos = 1.0;
             /* Reset the decoders states and clock sync (before calling the demuxer */
             es_out_SetTime( p_input->p->p_es_out, -1 );
             if( demux_Control( p_input->p->input.p_demux, DEMUX_SET_POSITION,
@@ -1651,18 +1618,12 @@ static bool Control( input_thread_t *p_input, int i_type,
                 break;
             }
 
-            if( i_type == INPUT_CONTROL_SET_TIME )
-            {
-                i_time = val.i_time;
-            }
-            else
-            {
-                /* Should not fail */
-                demux_Control( p_input->p->input.p_demux,
-                                DEMUX_GET_TIME, &i_time );
-                i_time += val.i_time;
-            }
-            if( i_time < 0 ) i_time = 0;
+            i_time = val.i_time;
+            if( i_type != INPUT_CONTROL_SET_TIME )
+                i_time += var_GetTime( p_input, "time" );
+
+            if( i_time < 0 )
+                i_time = 0;
 
             /* Reset the decoders states and clock sync (before calling the demuxer */
             es_out_SetTime( p_input->p->p_es_out, -1 );
@@ -1961,9 +1922,8 @@ static bool Control( input_thread_t *p_input, int i_type,
                 {
                     i_seekpoint = p_demux->info.i_seekpoint;
                     i_seekpoint_time = p_input->p->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
-                    if( i_seekpoint_time >= 0 &&
-                         !demux_Control( p_demux,
-                                          DEMUX_GET_TIME, &i_input_time ) )
+                    i_input_time = var_GetTime( p_input, "time" );
+                    if( i_seekpoint_time >= 0 && i_input_time >= 0 )
                     {
                         if( i_input_time < i_seekpoint_time + 3000000 )
                             i_seekpoint--;
@@ -1997,9 +1957,8 @@ static bool Control( input_thread_t *p_input, int i_type,
                 {
                     i_seekpoint = p_access->info.i_seekpoint;
                     i_seekpoint_time = p_input->p->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
-                    if( i_seekpoint_time >= 0 &&
-                        demux_Control( p_demux,
-                                        DEMUX_GET_TIME, &i_input_time ) )
+                    i_input_time = var_GetTime( p_input, "time" );
+                    if( i_seekpoint_time >= 0 && i_input_time >= 0 )
                     {
                         if( i_input_time < i_seekpoint_time + 3000000 )
                             i_seekpoint--;