]> git.sesse.net Git - vlc/blobdiff - src/input/es_out.c
Do not delay rate change after end of pause.
[vlc] / src / input / es_out.c
index a0b0b1cad56b171f7ff2d8ad6926b16ba1324281..3762e840e11f86169307bc050994a63a9096fe79 100644 (file)
@@ -573,9 +573,7 @@ static void EsOutChangeRate( es_out_t *out, int i_rate )
     es_out_sys_t      *p_sys = out->p_sys;
 
     p_sys->i_rate = i_rate;
-
-    if( !p_sys->b_paused )
-        EsOutProgramsChangeRate( out );
+    EsOutProgramsChangeRate( out );
 }
 
 static void EsOutChangePosition( es_out_t *out )
@@ -1030,9 +1028,10 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
         free( p_pgrm );
         return NULL;
     }
+    if( p_sys->b_paused )
+        input_clock_ChangePause( p_pgrm->p_clock, p_sys->b_paused, p_sys->i_pause_date );
     input_clock_SetJitter( p_pgrm->p_clock, p_sys->i_pts_delay, p_sys->i_cr_average );
 
-
     /* Append it */
     TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
 
@@ -1689,7 +1688,7 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
                 break;
             }
         }
-        var_Change( p_sys->p_input, "programs", VLC_VAR_FREELIST, &val, NULL );
+        var_FreeList( &val, NULL );
     }
     else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
     {
@@ -2211,6 +2210,7 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
             int            i_group = 0;
             int64_t        i_pcr;
 
+            /* Search program */
             if( i_query == ES_OUT_SET_PCR )
             {
                 p_pgrm = p_sys->p_pgrm;
@@ -2232,14 +2232,40 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
                 return VLC_EGENERIC;
             }
 
-            /* search program
-             * TODO do not use mdate() but proper stream acquisition date */
+            /* TODO do not use mdate() but proper stream acquisition date */
+            bool b_late;
             input_clock_Update( p_pgrm->p_clock, VLC_OBJECT(p_sys->p_input),
+                                &b_late,
                                 p_sys->p_input->p->b_can_pace_control || p_sys->b_buffering, i_pcr, mdate() );
-            /* Check buffering state on master clock update */
-            if( p_sys->b_buffering && p_pgrm == p_sys->p_pgrm )
-                EsOutDecodersStopBuffering( out, false );
 
+            if( p_pgrm == p_sys->p_pgrm )
+            {
+                if( p_sys->b_buffering )
+                {
+                    /* Check buffering state on master clock update */
+                    EsOutDecodersStopBuffering( out, false );
+                }
+                else if( b_late )
+                {
+                    mtime_t i_pts_delay = input_clock_GetJitter( p_pgrm->p_clock );
+
+                    /* Avoid dangerously high value */
+                    const mtime_t i_pts_delay_max = 30000000;
+                    if( i_pts_delay > i_pts_delay_max )
+                        i_pts_delay = __MAX( i_pts_delay_max, p_sys->i_pts_delay );
+
+                    /* Force a rebufferization when we are too late */
+                    msg_Err( p_sys->p_input,
+                             "ES_OUT_SET_(GROUP_)PCR  is called too late, increasing pts_delay to %d ms",
+                             (int)(i_pts_delay/1000) );
+
+                    /* It is not really good, as we throw away already buffered data
+                     * TODO have a mean to correctly reenter bufferization */
+                    es_out_Control( out, ES_OUT_RESET_PCR );
+
+                    es_out_Control( out, ES_OUT_SET_JITTER, i_pts_delay, p_sys->i_cr_average );
+                }
+            }
             return VLC_SUCCESS;
         }
 
@@ -2550,7 +2576,7 @@ static char *LanguageGetCode( const char *psz_lang )
     if( psz_lang == NULL || *psz_lang == '\0' )
         return strdup("??");
 
-    for( pl = p_languages; pl->psz_iso639_1 != NULL; pl++ )
+    for( pl = p_languages; pl->psz_eng_name != NULL; pl++ )
     {
         if( !strcasecmp( pl->psz_eng_name, psz_lang ) ||
             !strcasecmp( pl->psz_native_name, psz_lang ) ||
@@ -2560,7 +2586,7 @@ static char *LanguageGetCode( const char *psz_lang )
             break;
     }
 
-    if( pl->psz_iso639_1 != NULL )
+    if( pl->psz_eng_name != NULL )
         return strdup( pl->psz_iso639_1 );
 
     return strdup("??");