]> git.sesse.net Git - vlc/blobdiff - src/input/es_out.c
Change ES_OUT_SET_NEXT_DISPLAY_TIME parameters.
[vlc] / src / input / es_out.c
index 4c6573ba227f45bfd5080416b90ffe4c2eac872d..8940e046c60640e2673099d2953b3a7c07583862 100644 (file)
@@ -77,9 +77,6 @@ struct es_out_id_t
     int       i_id;
     es_out_pgrm_t *p_pgrm;
 
-    /* Misc. */
-    int64_t i_preroll_end;
-
     /* Channel in the track type */
     int         i_channel;
     es_format_t fmt;
@@ -140,6 +137,9 @@ struct es_out_sys_t
     /* Rate used for clock */
     int         i_rate;
 
+    /* Current preroll */
+    int64_t     i_preroll_end;
+
     /* Used for buffering */
     bool        b_buffering;
 
@@ -282,6 +282,7 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
     p_sys->i_rate = i_rate;
 
     p_sys->b_buffering = true;
+    p_sys->i_preroll_end = -1;
 
     p_sys->p_sout_record = NULL;
 
@@ -470,7 +471,7 @@ void input_EsOutSetDelay( es_out_t *out, int i_cat, int64_t i_delay )
 
     if( i_cat == AUDIO_ES )
         p_sys->i_audio_delay = i_delay;
-    else if( i_cat == AUDIO_ES )
+    else if( i_cat == SPU_ES )
         p_sys->i_spu_delay = i_delay;
 
     for( int i = 0; i < p_sys->i_es; i++ )
@@ -511,9 +512,10 @@ void input_EsOutChangePosition( es_out_t *out )
         input_clock_Reset( p_sys->pgrm[i]->p_clock );
 
     p_sys->b_buffering = true;
+    p_sys->i_preroll_end = -1;
 }
 
-bool input_EsOutDecodersEmpty( es_out_t *out )
+bool input_EsOutDecodersIsEmpty( es_out_t *out )
 {
     es_out_sys_t      *p_sys = out->p_sys;
     int i;
@@ -537,6 +539,11 @@ bool input_EsOutDecodersEmpty( es_out_t *out )
     return true;
 }
 
+bool input_EsOutIsBuffering( es_out_t *out )
+{
+    return out->p_sys->b_buffering;
+}
+
 /*****************************************************************************
  *
  *****************************************************************************/
@@ -556,15 +563,20 @@ static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced )
     if( i_ret )
         return;
 
-    if( i_stream_duration <= p_sys->p_input->i_pts_delay && !b_forced )
+    mtime_t i_preroll_duration = 0;
+    if( p_sys->i_preroll_end >= 0 )
+        i_preroll_duration = __MAX( p_sys->i_preroll_end - i_stream_start, 0 );
+
+    if( i_stream_duration <= p_sys->p_input->i_pts_delay + i_preroll_duration && !b_forced )
     {
-        msg_Dbg( p_sys->p_input, "Buffering %d%%", (int)(100 * i_stream_duration / p_sys->p_input->i_pts_delay) );
+        msg_Dbg( p_sys->p_input, "Buffering %d%%", (int)(100 * i_stream_duration / ( p_sys->p_input->i_pts_delay + i_preroll_duration )) );
         return;
     }
 
     msg_Dbg( p_sys->p_input, "Stream buffering done (%d ms in %d ms)",
               (int)(i_stream_duration/1000), (int)(i_system_duration/1000) );
     p_sys->b_buffering = false;
+    p_sys->i_preroll_end = -1;
 
     const mtime_t i_decoder_buffering_start = mdate();
     for( int i = 0; i < p_sys->i_es; i++ )
@@ -584,7 +596,7 @@ static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced )
     const mtime_t i_ts_delay = 10*1000 + /* FIXME CLEANUP thread wake up time*/
                                mdate();
     //msg_Dbg( p_sys->p_input, "==> %lld", i_ts_delay - p_sys->p_input->i_pts_delay );
-    input_clock_ChangeSystemOrigin( p_sys->p_pgrm->p_clock, i_ts_delay - p_sys->p_input->i_pts_delay );
+    input_clock_ChangeSystemOrigin( p_sys->p_pgrm->p_clock, i_ts_delay - p_sys->p_input->i_pts_delay - i_preroll_duration );
 
     for( int i = 0; i < p_sys->i_es; i++ )
     {
@@ -640,7 +652,7 @@ static void EsOutDecoderChangeDelay( es_out_t *out, es_out_id_t *p_es )
         if( p_es->p_dec )
             input_DecoderChangeDelay( p_es->p_dec, i_delay );
         if( p_es->p_dec_record )
-            input_DecoderChangeDelay( p_es->p_dec, i_delay );
+            input_DecoderChangeDelay( p_es->p_dec_record, i_delay );
     }
 }
 
@@ -1177,7 +1189,6 @@ static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
     es->i_id = fmt->i_id;
     es->p_pgrm = p_pgrm;
     es_format_Copy( &es->fmt, fmt );
-    es->i_preroll_end = -1;
 
     switch( fmt->i_cat )
     {
@@ -1371,7 +1382,6 @@ static void EsSelect( es_out_t *out, es_out_id_t *es )
             }
         }
 
-        es->i_preroll_end = -1;
         EsCreateDecoder( out, es );
 
         if( es->p_dec == NULL || es->p_pgrm != p_sys->p_pgrm )
@@ -1658,16 +1668,14 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
     }
 
     /* Mark preroll blocks */
-    if( es->i_preroll_end >= 0 )
+    if( p_sys->i_preroll_end >= 0 )
     {
         int64_t i_date = p_block->i_pts;
         if( i_date <= 0 )
             i_date = p_block->i_dts;
 
-        if( i_date < es->i_preroll_end )
+        if( i_date < p_sys->i_preroll_end )
             p_block->i_flags |= BLOCK_FLAG_PREROLL;
-        else
-            es->i_preroll_end = -1;
     }
 
     p_block->i_rate = 0;
@@ -1737,7 +1745,7 @@ static void EsOutDel( es_out_t *out, es_out_id_t *es )
     /* We don't try to reselect */
     if( es->p_dec )
     {
-        while( !out->p_sys->p_input->b_die && es->p_dec )
+        while( !p_sys->p_input->b_die && !p_sys->b_buffering && es->p_dec )
         {
             if( input_DecoderIsEmpty( es->p_dec ) &&
                 ( !es->p_dec_record || input_DecoderIsEmpty( es->p_dec_record ) ))
@@ -2089,15 +2097,12 @@ static int EsOutControl( es_out_t *out, int i_query, va_list args )
 
         case ES_OUT_SET_NEXT_DISPLAY_TIME:
         {
-            int64_t i_date;
-
-            es = (es_out_id_t*) va_arg( args, es_out_id_t * );
-            i_date = (int64_t)va_arg( args, int64_t );
+            const int64_t i_date = (int64_t)va_arg( args, int64_t );
 
-            if( !es || !es->p_dec )
+            if( i_date < 0 )
                 return VLC_EGENERIC;
 
-            es->i_preroll_end = i_date;
+            p_sys->i_preroll_end = i_date;
 
             return VLC_SUCCESS;
         }