]> git.sesse.net Git - vlc/blobdiff - src/input/es_out.c
es_out: use input_DecoderDrain()
[vlc] / src / input / es_out.c
index a7c7c23a06c838637b0275c9db3df42b22a99f6d..ec7d6556ccd2ae830aeaf7f58969bcc79c3a8721 100644 (file)
@@ -1,25 +1,25 @@
 /*****************************************************************************
  * es_out.c: Es Out handler for input.
  *****************************************************************************
- * Copyright (C) 2003-2004 the VideoLAN team
+ * Copyright (C) 2003-2004 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
 #include <vlc_aout.h>
 #include <vlc_fourcc.h>
 
-#include <vlc_memory.h>
-
 #include "input_internal.h"
 #include "clock.h"
 #include "decoder.h"
 #include "es_out.h"
 #include "event.h"
+#include "info.h"
+#include "item.h"
 
 #include "../stream_output/stream_output.h"
 
@@ -114,7 +114,6 @@ struct es_out_sys_t
     /* all programs */
     int           i_pgrm;
     es_out_pgrm_t **pgrm;
-    es_out_pgrm_t **pp_selected_pgrm; /* --programs */
     es_out_pgrm_t *p_pgrm;  /* Master program */
 
     /* all es */
@@ -131,7 +130,8 @@ struct es_out_sys_t
     int         i_video;
     int         i_sub;
 
-    /* es to select */
+    /* es/group to select */
+    int         i_group_id;
     int         i_audio_last, i_audio_id;
     int         i_sub_last, i_sub_id;
     int         i_default_sub_id;   /* As specified in container; if applicable */
@@ -149,6 +149,7 @@ struct es_out_sys_t
 
     /* Clock configuration */
     mtime_t     i_pts_delay;
+    mtime_t     i_pts_jitter;
     int         i_cr_average;
     int         i_rate;
 
@@ -175,6 +176,7 @@ static void         EsOutDel    ( es_out_t *, es_out_id_t * );
 static int          EsOutControl( es_out_t *, int i_query, va_list );
 static void         EsOutDelete ( es_out_t * );
 
+static void         EsOutTerminate( es_out_t * );
 static void         EsOutSelect( es_out_t *, es_out_id_t *es, bool b_force );
 static void         EsOutUpdateInfo( es_out_t *, es_out_id_t *es, const es_format_t *, const vlc_meta_t * );
 static int          EsOutSetRecord(  es_out_t *, bool b_record );
@@ -190,8 +192,8 @@ static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced );
 
 static char *LanguageGetName( const char *psz_code );
 static char *LanguageGetCode( const char *psz_lang );
-static char **LanguageSplit( const char *psz_langs );
-static int LanguageArrayIndex( char **ppsz_langs, char *psz_lang );
+static char **LanguageSplit( const char *psz_langs, bool b_default_any );
+static int LanguageArrayIndex( char **ppsz_langs, const char *psz_lang );
 
 static char *EsOutProgramGetMetaName( es_out_pgrm_t *p_pgrm );
 
@@ -225,7 +227,7 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
     if( !out )
         return NULL;
 
-    es_out_sys_t *p_sys = malloc( sizeof( *p_sys ) );
+    es_out_sys_t *p_sys = calloc( 1, sizeof( *p_sys ) );
     if( !p_sys )
     {
         free( out );
@@ -238,30 +240,21 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
     out->pf_control = EsOutControl;
     out->pf_destroy = EsOutDelete;
     out->p_sys      = p_sys;
-    out->b_sout     = p_input->p->p_sout != NULL;
-
 
     vlc_mutex_init_recursive( &p_sys->lock );
     p_sys->p_input = p_input;
 
     p_sys->b_active = false;
-    p_sys->i_mode   = ES_OUT_MODE_AUTO;
+    p_sys->i_mode   = ES_OUT_MODE_NONE;
 
 
     TAB_INIT( p_sys->i_pgrm, p_sys->pgrm );
-    p_sys->p_pgrm   = NULL;
-
-    p_sys->i_id    = 0;
 
     TAB_INIT( p_sys->i_es, p_sys->es );
 
-    p_sys->i_audio = 0;
-    p_sys->i_video = 0;
-    p_sys->i_sub   = 0;
-
     /* */
+    p_sys->i_group_id = var_GetInteger( p_input, "program" );
     p_sys->i_audio_last = var_GetInteger( p_input, "audio-track" );
-
     p_sys->i_sub_last = var_GetInteger( p_input, "sub-track" );
 
     p_sys->i_default_sub_id   = -1;
@@ -271,7 +264,7 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
         char *psz_string;
 
         psz_string = var_GetString( p_input, "audio-language" );
-        p_sys->ppsz_audio_language = LanguageSplit( psz_string );
+        p_sys->ppsz_audio_language = LanguageSplit( psz_string, true );
         if( p_sys->ppsz_audio_language )
         {
             for( int i = 0; p_sys->ppsz_audio_language[i]; i++ )
@@ -281,7 +274,7 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
         free( psz_string );
 
         psz_string = var_GetString( p_input, "sub-language" );
-        p_sys->ppsz_sub_language = LanguageSplit( psz_string );
+        p_sys->ppsz_sub_language = LanguageSplit( psz_string, false );
         if( p_sys->ppsz_sub_language )
         {
             for( int i = 0; p_sys->ppsz_sub_language[i]; i++ )
@@ -290,38 +283,18 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
         }
         free( psz_string );
     }
-    else
-    {
-        p_sys->ppsz_sub_language = NULL;
-        p_sys->ppsz_audio_language = NULL;
-    }
 
     p_sys->i_audio_id = var_GetInteger( p_input, "audio-track-id" );
 
     p_sys->i_sub_id = var_GetInteger( p_input, "sub-track-id" );
 
-    p_sys->p_es_audio = NULL;
-    p_sys->p_es_video = NULL;
-    p_sys->p_es_sub   = NULL;
-
-    p_sys->i_audio_delay= 0;
-    p_sys->i_spu_delay  = 0;
-
-    p_sys->b_paused = false;
     p_sys->i_pause_date = -1;
 
     p_sys->i_rate = i_rate;
-    p_sys->i_pts_delay = 0;
-    p_sys->i_cr_average = 0;
 
     p_sys->b_buffering = true;
-    p_sys->i_buffering_extra_initial = 0;
-    p_sys->i_buffering_extra_stream = 0;
-    p_sys->i_buffering_extra_system = 0;
     p_sys->i_preroll_end = -1;
 
-    p_sys->p_sout_record = NULL;
-
     return out;
 }
 
@@ -331,12 +304,35 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, int i_rate )
 static void EsOutDelete( es_out_t *out )
 {
     es_out_sys_t *p_sys = out->p_sys;
-    int i;
+
+    assert( !p_sys->i_es && !p_sys->i_pgrm && !p_sys->p_pgrm );
+    if( p_sys->ppsz_audio_language )
+    {
+        for( int i = 0; p_sys->ppsz_audio_language[i]; i++ )
+            free( p_sys->ppsz_audio_language[i] );
+        free( p_sys->ppsz_audio_language );
+    }
+    if( p_sys->ppsz_sub_language )
+    {
+        for( int i = 0; p_sys->ppsz_sub_language[i]; i++ )
+            free( p_sys->ppsz_sub_language[i] );
+        free( p_sys->ppsz_sub_language );
+    }
+
+    vlc_mutex_destroy( &p_sys->lock );
+
+    free( p_sys );
+    free( out );
+}
+
+static void EsOutTerminate( es_out_t *out )
+{
+    es_out_sys_t *p_sys = out->p_sys;
 
     if( p_sys->p_sout_record )
         EsOutSetRecord( out, false );
 
-    for( i = 0; i < p_sys->i_es; i++ )
+    for( int i = 0; i < p_sys->i_es; i++ )
     {
         if( p_sys->es[i]->p_dec )
             input_DecoderDelete( p_sys->es[i]->p_dec );
@@ -347,22 +343,10 @@ static void EsOutDelete( es_out_t *out )
 
         free( p_sys->es[i] );
     }
-    if( p_sys->ppsz_audio_language )
-    {
-        for( i = 0; p_sys->ppsz_audio_language[i]; i++ )
-            free( p_sys->ppsz_audio_language[i] );
-        free( p_sys->ppsz_audio_language );
-    }
-    if( p_sys->ppsz_sub_language )
-    {
-        for( i = 0; p_sys->ppsz_sub_language[i]; i++ )
-            free( p_sys->ppsz_sub_language[i] );
-        free( p_sys->ppsz_sub_language );
-    }
-    free( p_sys->es );
+    TAB_CLEAN( p_sys->i_es, p_sys->es );
 
     /* FIXME duplicate work EsOutProgramDel (but we cannot use it) add a EsOutProgramClean ? */
-    for( i = 0; i < p_sys->i_pgrm; i++ )
+    for( int i = 0; i < p_sys->i_pgrm; i++ )
     {
         es_out_pgrm_t *p_pgrm = p_sys->pgrm[i];
         input_clock_Delete( p_pgrm->p_clock );
@@ -374,12 +358,10 @@ static void EsOutDelete( es_out_t *out )
     }
     TAB_CLEAN( p_sys->i_pgrm, p_sys->pgrm );
 
-    input_item_SetEpgOffline( p_sys->p_input->p->p_item );
-
-    vlc_mutex_destroy( &p_sys->lock );
+    p_sys->p_pgrm = NULL;
 
-    free( p_sys );
-    free( out );
+    input_item_SetEpgOffline( p_sys->p_input->p->p_item );
+    input_SendEventMetaEpg( p_sys->p_input );
 }
 
 static mtime_t EsOutGetWakeup( es_out_t *out )
@@ -393,7 +375,8 @@ static mtime_t EsOutGetWakeup( es_out_t *out )
     /* We do not have a wake up date if the input cannot have its speed
      * controlled or sout is imposing its own or while buffering
      *
-     * FIXME for !p_input->p->b_can_pace_control a wkeup time is still needed to avoid too strong buffering */
+     * FIXME for !p_input->p->b_can_pace_control a wake-up time is still needed
+     * to avoid too heavy buffering */
     if( !p_input->p->b_can_pace_control ||
         p_input->p->b_out_pace_control ||
         p_sys->b_buffering )
@@ -404,14 +387,13 @@ static mtime_t EsOutGetWakeup( es_out_t *out )
 
 static es_out_id_t *EsOutGetFromID( es_out_t *out, int i_id )
 {
-    int i;
     if( i_id < 0 )
     {
         /* Special HACK, -i_id is the cat of the stream */
         return (es_out_id_t*)((uint8_t*)NULL-i_id);
     }
 
-    for( i = 0; i < out->p_sys->i_es; i++ )
+    for( int i = 0; i < out->p_sys->i_es; i++ )
     {
         if( out->p_sys->es[i]->i_id == i_id )
             return out->p_sys->es[i];
@@ -422,7 +404,6 @@ static es_out_id_t *EsOutGetFromID( es_out_t *out, int i_id )
 static bool EsOutDecodersIsEmpty( es_out_t *out )
 {
     es_out_sys_t      *p_sys = out->p_sys;
-    int i;
 
     if( p_sys->b_buffering && p_sys->p_pgrm )
     {
@@ -431,7 +412,7 @@ static bool EsOutDecodersIsEmpty( es_out_t *out )
             return true;
     }
 
-    for( i = 0; i < p_sys->i_es; i++ )
+    for( int i = 0; i < p_sys->i_es; i++ )
     {
         es_out_id_t *es = p_sys->es[i];
 
@@ -480,7 +461,7 @@ static int EsOutSetRecord(  es_out_t *out, bool b_record )
 
         if( !psz_sout && psz_path )
         {
-            char *psz_file = input_CreateFilename( VLC_OBJECT(p_input), psz_path, INPUT_RECORD_PREFIX, NULL );
+            char *psz_file = input_CreateFilename( p_input, psz_path, INPUT_RECORD_PREFIX, NULL );
             if( psz_file )
             {
                 if( asprintf( &psz_sout, "#record{dst-prefix='%s'}", psz_file ) < 0 )
@@ -510,7 +491,7 @@ static int EsOutSetRecord(  es_out_t *out, bool b_record )
 
             p_es->p_dec_record = input_DecoderNew( p_input, &p_es->fmt, p_es->p_pgrm->p_clock, p_sys->p_sout_record );
             if( p_es->p_dec_record && p_sys->b_buffering )
-                input_DecoderStartBuffering( p_es->p_dec_record );
+                input_DecoderStartWait( p_es->p_dec_record );
         }
     }
     else
@@ -592,13 +573,16 @@ static void EsOutChangePosition( es_out_t *out )
     {
         es_out_id_t *p_es = p_sys->es[i];
 
-        if( !p_es->p_dec )
-            continue;
-
-        input_DecoderStartBuffering( p_es->p_dec );
-
-        if( p_es->p_dec_record )
-            input_DecoderStartBuffering( p_es->p_dec_record );
+        if( p_es->p_dec != NULL )
+        {
+            input_DecoderFlush( p_es->p_dec );
+            if( !p_sys->b_buffering )
+            {
+                input_DecoderStartWait( p_es->p_dec );
+                if( p_es->p_dec_record != NULL )
+                    input_DecoderStartWait( p_es->p_dec_record );
+            }
+        }
     }
 
     for( int i = 0; i < p_sys->i_pgrm; i++ )
@@ -616,17 +600,14 @@ static void EsOutChangePosition( es_out_t *out )
 static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced )
 {
     es_out_sys_t *p_sys = out->p_sys;
-    int i_ret;
 
     mtime_t i_stream_start;
     mtime_t i_system_start;
     mtime_t i_stream_duration;
     mtime_t i_system_duration;
-    i_ret = input_clock_GetState( p_sys->p_pgrm->p_clock,
+    if (input_clock_GetState( p_sys->p_pgrm->p_clock,
                                   &i_stream_start, &i_system_start,
-                                  &i_stream_duration, &i_system_duration );
-    assert( !i_ret || b_forced );
-    if( i_ret )
+                                  &i_stream_duration, &i_system_duration ))
         return;
 
     mtime_t i_preroll_duration = 0;
@@ -639,7 +620,11 @@ static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced )
 
     if( i_stream_duration <= i_buffering_duration && !b_forced )
     {
-        const double f_level = (double)i_stream_duration / i_buffering_duration;
+        double f_level;
+        if (i_buffering_duration == 0)
+            f_level = 0;
+        else
+            f_level = __MAX( (double)i_stream_duration / i_buffering_duration, 0 );
         input_SendEventCache( p_sys->p_input, f_level );
 
         msg_Dbg( p_sys->p_input, "Buffering %d%%", (int)(100 * f_level) );
@@ -665,12 +650,12 @@ static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced )
 
         if( !p_es->p_dec || p_es->fmt.i_cat == SPU_ES )
             continue;
-        input_DecoderWaitBuffering( p_es->p_dec );
+        input_DecoderWait( p_es->p_dec );
         if( p_es->p_dec_record )
-            input_DecoderWaitBuffering( p_es->p_dec_record );
+            input_DecoderWait( p_es->p_dec_record );
     }
 
-    msg_Dbg( p_sys->p_input, "Decoder buffering done in %d ms",
+    msg_Dbg( p_sys->p_input, "Decoder wait done in %d ms",
               (int)(mdate() - i_decoder_buffering_start)/1000 );
 
     /* Here is a good place to destroy unused vout with every demuxer */
@@ -680,7 +665,8 @@ static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced )
     const mtime_t i_wakeup_delay = 10*1000; /* FIXME CLEANUP thread wake up time*/
     const mtime_t i_current_date = p_sys->b_paused ? p_sys->i_pause_date : mdate();
 
-    input_clock_ChangeSystemOrigin( p_sys->p_pgrm->p_clock, i_current_date + i_wakeup_delay - i_buffering_duration );
+    input_clock_ChangeSystemOrigin( p_sys->p_pgrm->p_clock, true,
+                                    i_current_date + i_wakeup_delay - i_buffering_duration );
 
     for( int i = 0; i < p_sys->i_es; i++ )
     {
@@ -689,9 +675,9 @@ static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced )
         if( !p_es->p_dec )
             continue;
 
-        input_DecoderStopBuffering( p_es->p_dec );
+        input_DecoderStopWait( p_es->p_dec );
         if( p_es->p_dec_record )
-            input_DecoderStopBuffering( p_es->p_dec_record );
+            input_DecoderStopWait( p_es->p_dec_record );
     }
 }
 static void EsOutDecodersChangePause( es_out_t *out, bool b_paused, mtime_t i_date )
@@ -726,13 +712,13 @@ static bool EsOutIsExtraBufferingAllowed( es_out_t *out )
         if( p_es->p_dec_record )
             i_size += input_DecoderGetFifoSize( p_es->p_dec_record );
     }
-    //fprintf( stderr, "----- EsOutIsExtraBufferingAllowed =% 5d kbytes -- ", i_size / 1024 );
+    //msg_Info( out, "----- EsOutIsExtraBufferingAllowed =% 5d KiB -- ", i_size / 1024 );
 
     /* TODO maybe we want to be able to tune it ? */
 #if defined(OPTIMIZE_MEMORY)
-    const size_t i_level_high = 500000;  /* 0.5 Mbytes */
+    const size_t i_level_high = 512*1024;  /* 0.5 MiB */
 #else
-    const size_t i_level_high = 10000000; /* 10 Mbytes */
+    const size_t i_level_high = 10*1024*1024; /* 10 MiB */
 #endif
     return i_size < i_level_high;
 }
@@ -754,14 +740,13 @@ static void EsOutDecoderChangeDelay( es_out_t *out, es_out_id_t *p_es )
         i_delay = p_sys->i_audio_delay;
     else if( p_es->fmt.i_cat == SPU_ES )
         i_delay = p_sys->i_spu_delay;
+    else
+        return;
 
-    if( i_delay != 0 )
-    {
-        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_record, i_delay );
-    }
+    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_record, i_delay );
 }
 static void EsOutProgramsChangeRate( es_out_t *out )
 {
@@ -842,21 +827,19 @@ static void EsOutFrameNext( es_out_t *out )
 static mtime_t EsOutGetBuffering( es_out_t *out )
 {
     es_out_sys_t *p_sys = out->p_sys;
+    mtime_t i_stream_duration, i_system_start;
 
     if( !p_sys->p_pgrm )
         return 0;
+    else
+    {
+        mtime_t i_stream_start, i_system_duration;
 
-    int i_ret;
-    mtime_t i_stream_start;
-    mtime_t i_system_start;
-    mtime_t i_stream_duration;
-    mtime_t i_system_duration;
-    i_ret = input_clock_GetState( p_sys->p_pgrm->p_clock,
+        if( input_clock_GetState( p_sys->p_pgrm->p_clock,
                                   &i_stream_start, &i_system_start,
-                                  &i_stream_duration, &i_system_duration );
-
-    if( i_ret )
-        return 0;
+                                  &i_stream_duration, &i_system_duration ) )
+            return 0;
+    }
 
     mtime_t i_delay;
 
@@ -867,6 +850,7 @@ static mtime_t EsOutGetBuffering( es_out_t *out )
     else
     {
         mtime_t i_system_duration;
+
         if( p_sys->b_paused )
         {
             i_system_duration = p_sys->i_pause_date  - i_system_start;
@@ -928,10 +912,9 @@ static void EsOutESVarUpdateGeneric( es_out_t *out, int i_id,
     {
         if( psz_language && *psz_language )
         {
-            text.psz_string = malloc( strlen( fmt->psz_description) +
-                                      strlen( psz_language ) + 10 );
-            sprintf( text.psz_string, "%s - [%s]", fmt->psz_description,
-                                                   psz_language );
+            if( asprintf( &text.psz_string, "%s - [%s]", fmt->psz_description,
+                          psz_language ) == -1 )
+                text.psz_string = NULL;
         }
         else text.psz_string = strdup( fmt->psz_description );
     }
@@ -939,12 +922,12 @@ static void EsOutESVarUpdateGeneric( es_out_t *out, int i_id,
     {
         if( psz_language && *psz_language )
         {
-            if( asprintf( &text.psz_string, "%s %i - [%s]", _( "Track" ), val.i_int, psz_language ) == -1 )
+            if( asprintf( &text.psz_string, "%s %"PRId64" - [%s]", _( "Track" ), val.i_int, psz_language ) == -1 )
                 text.psz_string = NULL;
         }
         else
         {
-            if( asprintf( &text.psz_string, "%s %i", _( "Track" ), val.i_int ) == -1 )
+            if( asprintf( &text.psz_string, "%s %"PRId64, _( "Track" ), val.i_int ) == -1 )
                 text.psz_string = NULL;
         }
     }
@@ -969,6 +952,11 @@ static void EsOutESVarUpdate( es_out_t *out, es_out_id_t *es,
     EsOutESVarUpdateGeneric( out, es->i_id, &es->fmt, es->psz_language, b_delete );
 }
 
+static bool EsOutIsProgramVisible( es_out_t *out, int i_group )
+{
+    return out->p_sys->i_group_id == 0 || out->p_sys->i_group_id == i_group;
+}
+
 /* EsOutProgramSelect:
  *  Select a program and update the object variable
  */
@@ -1027,7 +1015,7 @@ static void EsOutProgramSelect( es_out_t *out, es_out_pgrm_t *p_pgrm )
     }
 
     /* Update now playing */
-    input_item_SetNowPlaying( p_input->p->p_item, p_pgrm->psz_now_playing );
+    input_item_SetESNowPlaying( p_input->p->p_item, p_pgrm->psz_now_playing );
     input_item_SetPublisher( p_input->p->p_item, p_pgrm->psz_publisher );
 
     input_SendEventMeta( p_input );
@@ -1067,9 +1055,10 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out, int i_group )
     TAB_APPEND( p_sys->i_pgrm, p_sys->pgrm, p_pgrm );
 
     /* Update "program" variable */
-    input_SendEventProgramAdd( p_input, i_group, NULL );
+    if( EsOutIsProgramVisible( out, i_group ) )
+        input_SendEventProgramAdd( p_input, i_group, NULL );
 
-    if( i_group == var_GetInteger( p_input, "program" ) )
+    if( i_group == p_sys->i_group_id || ( !p_sys->p_pgrm && p_sys->i_group_id == 0 ) )
         EsOutProgramSelect( out, p_pgrm );
 
     return p_pgrm;
@@ -1160,7 +1149,6 @@ static void EsOutProgramMeta( es_out_t *out, int i_group, const vlc_meta_t *p_me
     es_out_sys_t      *p_sys = out->p_sys;
     es_out_pgrm_t     *p_pgrm;
     input_thread_t    *p_input = p_sys->p_input;
-    char              *psz_cat;
     const char        *psz_title = NULL;
     const char        *psz_provider = NULL;
     int i;
@@ -1169,13 +1157,15 @@ static void EsOutProgramMeta( es_out_t *out, int i_group, const vlc_meta_t *p_me
 
     /* Check against empty meta data (empty for what we handle) */
     if( !vlc_meta_Get( p_meta, vlc_meta_Title) &&
-        !vlc_meta_Get( p_meta, vlc_meta_NowPlaying) &&
+        !vlc_meta_Get( p_meta, vlc_meta_ESNowPlaying) &&
         !vlc_meta_Get( p_meta, vlc_meta_Publisher) &&
-        vlc_dictionary_keys_count( &p_meta->extra_tags ) <= 0 )
+        vlc_meta_GetExtraCount( p_meta ) <= 0 )
     {
         return;
     }
     /* Find program */
+    if( !EsOutIsProgramVisible( out, i_group ) )
+        return;
     p_pgrm = EsOutProgramFind( out, i_group );
     if( !p_pgrm )
         return;
@@ -1216,33 +1206,46 @@ static void EsOutProgramMeta( es_out_t *out, int i_group, const vlc_meta_t *p_me
         {
             input_SendEventProgramDel( p_input, i_group );
             input_SendEventProgramAdd( p_input, i_group, psz_text );
-
+            if( p_sys->p_pgrm == p_pgrm )
+                input_SendEventProgramSelect( p_input, i_group );
             free( psz_text );
         }
     }
 
-    psz_cat = EsOutProgramGetMetaName( p_pgrm );
-    if( psz_provider )
+    /* */
+    char **ppsz_all_keys = vlc_meta_CopyExtraNames(p_meta );
+
+    info_category_t *p_cat = NULL;
+    if( psz_provider || ( ppsz_all_keys[0] && *ppsz_all_keys[0] ) )
     {
-        if( p_sys->p_pgrm == p_pgrm )
-        {
-            input_item_SetPublisher( p_input->p->p_item, psz_provider );
-            input_SendEventMeta( p_input );
-        }
-        input_Control( p_input, INPUT_ADD_INFO, psz_cat, input_MetaTypeToLocalizedString(vlc_meta_Publisher), psz_provider );
+        char *psz_cat = EsOutProgramGetMetaName( p_pgrm );
+        if( psz_cat )
+            p_cat = info_category_New( psz_cat );
+        free( psz_cat );
     }
-    char ** ppsz_all_keys = vlc_dictionary_all_keys( &p_meta->extra_tags );
+
     for( i = 0; ppsz_all_keys[i]; i++ )
     {
-        input_Control( p_input, INPUT_ADD_INFO, psz_cat,
-                       vlc_gettext(ppsz_all_keys[i]),
-                       vlc_dictionary_value_for_key( &p_meta->extra_tags,
-                       ppsz_all_keys[i] ) );
+        if( p_cat )
+            info_category_AddInfo( p_cat, vlc_gettext(ppsz_all_keys[i]), "%s",
+                                   vlc_meta_GetExtra( p_meta, ppsz_all_keys[i] ) );
         free( ppsz_all_keys[i] );
     }
     free( ppsz_all_keys );
 
-    free( psz_cat );
+    if( psz_provider )
+    {
+        if( p_sys->p_pgrm == p_pgrm )
+        {
+            input_item_SetPublisher( p_input->p->p_item, psz_provider );
+            input_SendEventMeta( p_input );
+        }
+        if( p_cat )
+            info_category_AddInfo( p_cat, vlc_meta_TypeToLocalizedString(vlc_meta_Publisher),
+                                   "%s",psz_provider );
+    }
+    if( p_cat )
+        input_Control( p_input, INPUT_MERGE_INFOS, p_cat );
 }
 
 static void EsOutProgramEpg( es_out_t *out, int i_group, const vlc_epg_t *p_epg )
@@ -1254,6 +1257,8 @@ static void EsOutProgramEpg( es_out_t *out, int i_group, const vlc_epg_t *p_epg
     char *psz_cat;
 
     /* Find program */
+    if( !EsOutIsProgramVisible( out, i_group ) )
+        return;
     p_pgrm = EsOutProgramFind( out, i_group );
     if( !p_pgrm )
         return;
@@ -1269,6 +1274,7 @@ static void EsOutProgramEpg( es_out_t *out, int i_group, const vlc_epg_t *p_epg
     epg.psz_name = psz_cat;
 
     input_item_SetEpg( p_item, &epg );
+    input_SendEventMetaEpg( p_sys->p_input );
 
     /* Update now playing */
     free( p_pgrm->psz_now_playing );
@@ -1290,20 +1296,20 @@ static void EsOutProgramEpg( es_out_t *out, int i_group, const vlc_epg_t *p_epg
 
     if( p_pgrm == p_sys->p_pgrm )
     {
-        input_item_SetNowPlaying( p_input->p->p_item, p_pgrm->psz_now_playing );
+        input_item_SetESNowPlaying( p_input->p->p_item, p_pgrm->psz_now_playing );
         input_SendEventMeta( p_input );
     }
 
     if( p_pgrm->psz_now_playing )
     {
         input_Control( p_input, INPUT_ADD_INFO, psz_cat,
-            input_MetaTypeToLocalizedString(vlc_meta_NowPlaying),
+            vlc_meta_TypeToLocalizedString(vlc_meta_ESNowPlaying), "%s",
             p_pgrm->psz_now_playing );
     }
     else
     {
         input_Control( p_input, INPUT_DEL_INFO, psz_cat,
-            input_MetaTypeToLocalizedString(vlc_meta_NowPlaying) );
+            vlc_meta_TypeToLocalizedString(vlc_meta_ESNowPlaying) );
     }
 
     free( psz_cat );
@@ -1341,48 +1347,34 @@ static void EsOutMeta( es_out_t *p_out, const vlc_meta_t *p_meta )
 {
     es_out_sys_t    *p_sys = p_out->p_sys;
     input_thread_t  *p_input = p_sys->p_input;
-
     input_item_t *p_item = input_GetItem( p_input );
 
-    char *psz_title = NULL;
-    char *psz_arturl = input_item_GetArtURL( p_item );
-
-    vlc_mutex_lock( &p_item->lock );
+    if( vlc_meta_Get( p_meta, vlc_meta_Title ) != NULL )
+        input_item_SetName( p_item, vlc_meta_Get( p_meta, vlc_meta_Title ) );
 
-    if( vlc_meta_Get( p_meta, vlc_meta_Title ) && !p_item->b_fixed_name )
-        psz_title = strdup( vlc_meta_Get( p_meta, vlc_meta_Title ) );
+    char *psz_arturl = NULL;
+    if( vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL ) != NULL )
+        psz_arturl = input_item_GetArtURL( p_item ); /* save value */
 
+    vlc_mutex_lock( &p_item->lock );
     vlc_meta_Merge( p_item->p_meta, p_meta );
-
-    if( !psz_arturl || *psz_arturl == '\0' )
-    {
-        const char *psz_tmp = vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL );
-        if( psz_tmp )
-            psz_arturl = strdup( psz_tmp );
-    }
     vlc_mutex_unlock( &p_item->lock );
 
-    if( psz_arturl && *psz_arturl )
-    {
+    if( psz_arturl != NULL ) /* restore/favor previously set item art URL */
         input_item_SetArtURL( p_item, psz_arturl );
+    else
+        psz_arturl = input_item_GetArtURL( p_item );
 
-        if( !strncmp( psz_arturl, "attachment://", strlen("attachment") ) )
-        {
-            /* Don't look for art cover if sout
-             * XXX It can change when sout has meta data support */
-            if( p_out->b_sout && !p_input->b_preparsing )
-                input_item_SetArtURL( p_item, "" );
-            else
-                input_ExtractAttachmentAndCacheArt( p_input );
-        }
+    if( psz_arturl != NULL && !strncmp( psz_arturl, "attachment://", 13 ) )
+    {   /* Clear art cover if streaming out.
+         * FIXME: Why? Remove this when sout gets meta data support. */
+        if( p_input->p->p_sout && !p_input->b_preparsing )
+            input_item_SetArtURL( p_item, NULL );
+        else
+            input_ExtractAttachmentAndCacheArt( p_input, psz_arturl + 13 );
     }
     free( psz_arturl );
 
-    if( psz_title )
-    {
-        input_item_SetName( p_item, psz_title );
-        free( psz_title );
-    }
     input_item_SetPreparsed( p_item, true );
 
     input_SendEventMeta( p_input );
@@ -1431,7 +1423,12 @@ static es_out_id_t *EsOutAdd( es_out_t *out, const es_format_t *fmt )
         es->fmt.i_id = out->p_sys->i_id;
     if( !es->fmt.i_original_fourcc )
         es->fmt.i_original_fourcc = es->fmt.i_codec;
-    es->fmt.i_codec = vlc_fourcc_GetCodec( es->fmt.i_cat, es->fmt.i_codec );
+    if( es->fmt.i_cat == AUDIO_ES )
+        es->fmt.i_codec = vlc_fourcc_GetCodecAudio( es->fmt.i_codec,
+                                                    es->fmt.audio.i_bitspersample );
+    else
+        es->fmt.i_codec = vlc_fourcc_GetCodec( es->fmt.i_cat,
+                                               es->fmt.i_codec );
 
     es->i_id = es->fmt.i_id;
     es->i_meta_id = out->p_sys->i_id;
@@ -1550,13 +1547,13 @@ static void EsCreateDecoder( es_out_t *out, es_out_id_t *p_es )
     if( p_es->p_dec )
     {
         if( p_sys->b_buffering )
-            input_DecoderStartBuffering( p_es->p_dec );
+            input_DecoderStartWait( p_es->p_dec );
 
         if( !p_es->p_master && p_sys->p_sout_record )
         {
             p_es->p_dec_record = input_DecoderNew( p_input, &p_es->fmt, p_es->p_pgrm->p_clock, p_sys->p_sout_record );
             if( p_es->p_dec_record && p_sys->b_buffering )
-                input_DecoderStartBuffering( p_es->p_dec_record );
+                input_DecoderStartWait( p_es->p_dec_record );
         }
     }
 
@@ -1602,9 +1599,10 @@ static void EsSelect( es_out_t *out, es_out_id_t *es )
     }
     else
     {
+        const bool b_sout = p_input->p->p_sout != NULL;
         if( es->fmt.i_cat == VIDEO_ES || es->fmt.i_cat == SPU_ES )
         {
-            if( !var_GetBool( p_input, out->b_sout ? "sout-video" : "video" ) )
+            if( !var_GetBool( p_input, b_sout ? "sout-video" : "video" ) )
             {
                 msg_Dbg( p_input, "video is disabled, not selecting ES 0x%x",
                          es->i_id );
@@ -1613,7 +1611,7 @@ static void EsSelect( es_out_t *out, es_out_id_t *es )
         }
         else if( es->fmt.i_cat == AUDIO_ES )
         {
-            if( !var_GetBool( p_input, out->b_sout ? "sout-audio" : "audio" ) )
+            if( !var_GetBool( p_input, b_sout ? "sout-audio" : "audio" ) )
             {
                 msg_Dbg( p_input, "audio is disabled, not selecting ES 0x%x",
                          es->i_id );
@@ -1622,7 +1620,7 @@ static void EsSelect( es_out_t *out, es_out_id_t *es )
         }
         if( es->fmt.i_cat == SPU_ES )
         {
-            if( !var_GetBool( p_input, out->b_sout ? "sout-spu" : "spu" ) )
+            if( !var_GetBool( p_input, b_sout ? "sout-spu" : "spu" ) )
             {
                 msg_Dbg( p_input, "spu is disabled, not selecting ES 0x%x",
                          es->i_id );
@@ -1707,7 +1705,7 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
     int i_cat = es->fmt.i_cat;
 
     if( !p_sys->b_active ||
-        ( !b_force && es->fmt.i_priority < 0 ) )
+        ( !b_force && es->fmt.i_priority < ES_PRIORITY_SELECTABLE_MIN ) )
     {
         return;
     }
@@ -1719,19 +1717,24 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
     }
     else if( p_sys->i_mode == ES_OUT_MODE_PARTIAL )
     {
-        vlc_value_t val;
-        int i;
-        var_Get( p_sys->p_input, "programs", &val );
-        for ( i = 0; i < val.p_list->i_count; i++ )
+        char *prgms = var_GetNonEmptyString( p_sys->p_input, "programs" );
+        if( prgms != NULL )
         {
-            if ( val.p_list->p_values[i].i_int == es->p_pgrm->i_id || b_force )
+            char *buf;
+
+            for ( const char *prgm = strtok_r( prgms, ",", &buf );
+                  prgm != NULL;
+                  prgm = strtok_r( NULL, ",", &buf ) )
             {
-                if( !EsIsSelected( es ) )
-                    EsSelect( out, es );
-                break;
+                if( atoi( prgm ) == es->p_pgrm->i_id || b_force )
+                {
+                    if( !EsIsSelected( es ) )
+                        EsSelect( out, es );
+                    break;
+                }
             }
+            free( prgms );
         }
-        var_FreeList( &val, NULL );
     }
     else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
     {
@@ -1742,28 +1745,34 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
 
         if( i_cat == AUDIO_ES )
         {
-            int idx1 = LanguageArrayIndex( p_sys->ppsz_audio_language,
-                                     es->psz_language_code );
-
-            if( p_sys->p_es_audio &&
-                p_sys->p_es_audio->fmt.i_priority >= es->fmt.i_priority )
+            if( p_sys->ppsz_audio_language )
             {
-                int idx2 = LanguageArrayIndex( p_sys->ppsz_audio_language,
-                                         p_sys->p_es_audio->psz_language_code );
-
-                if( idx1 < 0 || ( idx2 >= 0 && idx2 <= idx1 ) )
-                    return;
-                i_wanted = es->i_channel;
+                int es_idx = LanguageArrayIndex( p_sys->ppsz_audio_language,
+                                                 es->psz_language_code );
+                if( !p_sys->p_es_audio )
+                {
+                    /* Only select the language if it's in the list */
+                    if( es_idx >= 0 )
+                        i_wanted = es->i_channel;
+                }
+                else
+                {
+                    int selected_es_idx =
+                        LanguageArrayIndex( p_sys->ppsz_audio_language,
+                                            p_sys->p_es_audio->psz_language_code );
+                    if( es_idx >= 0 &&
+                        ( selected_es_idx < 0 || es_idx < selected_es_idx ||
+                          ( es_idx == selected_es_idx &&
+                            p_sys->p_es_audio->fmt.i_priority < es->fmt.i_priority ) ) )
+                        i_wanted = es->i_channel;
+                }
             }
             else
             {
-                /* Select audio if (no audio selected yet)
-                 * - no audio-language
-                 * - no audio code for the ES
-                 * - audio code in the requested list */
-                if( idx1 >= 0 ||
-                    !strcmp( es->psz_language_code, "??" ) ||
-                    !p_sys->ppsz_audio_language )
+                /* Select the first one if there is no selected audio yet 
+                 * then choose by ES priority */
+                if( !p_sys->p_es_audio ||
+                    p_sys->p_es_audio->fmt.i_priority < es->fmt.i_priority )
                     i_wanted = es->i_channel;
             }
 
@@ -1780,35 +1789,58 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
         }
         else if( i_cat == SPU_ES )
         {
-            int idx1 = LanguageArrayIndex( p_sys->ppsz_sub_language,
-                                     es->psz_language_code );
-
-            if( p_sys->p_es_sub &&
-                p_sys->p_es_sub->fmt.i_priority >= es->fmt.i_priority )
+            if( p_sys->ppsz_sub_language )
             {
-                int idx2 = LanguageArrayIndex( p_sys->ppsz_sub_language,
-                                         p_sys->p_es_sub->psz_language_code );
-
-                msg_Dbg( p_sys->p_input, "idx1=%d(%s) idx2=%d(%s)",
-                        idx1, es->psz_language_code, idx2,
-                        p_sys->p_es_sub->psz_language_code );
-
-                if( idx1 < 0 || ( idx2 >= 0 && idx2 <= idx1 ) )
-                    return;
-                /* We found a SPU that matches our language request */
-                i_wanted  = es->i_channel;
+                int es_idx = LanguageArrayIndex( p_sys->ppsz_sub_language,
+                                     es->psz_language_code );
+                if( !p_sys->p_es_sub )
+                {
+                    /* Select the language if it's in the list */
+                    if( es_idx >= 0 ||
+                        /*FIXME: Should default subtitle not in the list be 
+                         * displayed if not forbidden by none? */
+                        ( p_sys->i_default_sub_id >= 0 &&
+                          /* check if the subtitle isn't forbidden by none */
+                          LanguageArrayIndex( p_sys->ppsz_sub_language, "none" ) < 0 &&
+                          es->i_id == p_sys->i_default_sub_id ) )
+                        i_wanted = es->i_channel;
+                }
+                else
+                {
+                    int selected_es_idx =
+                        LanguageArrayIndex( p_sys->ppsz_sub_language,
+                                            p_sys->p_es_sub->psz_language_code );
+
+                    if( es_idx >= 0 &&
+                        ( selected_es_idx < 0 || es_idx < selected_es_idx ||
+                          ( es_idx == selected_es_idx &&
+                            p_sys->p_es_sub->fmt.i_priority < es->fmt.i_priority ) ) )
+                        i_wanted = es->i_channel;
+                }
             }
-            else if( idx1 >= 0 )
+            else if ( es->fmt.i_codec == EsOutFourccClosedCaptions[0] ||
+                      es->fmt.i_codec == EsOutFourccClosedCaptions[1] ||
+                      es->fmt.i_codec == EsOutFourccClosedCaptions[2] ||
+                      es->fmt.i_codec == EsOutFourccClosedCaptions[3])
             {
-                msg_Dbg( p_sys->p_input, "idx1=%d(%s)",
-                        idx1, es->psz_language_code );
-
-                i_wanted  = es->i_channel;
+                    /* We don't want to enable on initial create since p_master
+                       isn't set yet (otherwise we will think it's a standard
+                       ES_SUB stream and cause a resource leak) */
+                    return;
             }
-            else if( p_sys->i_default_sub_id >= 0 )
+            else
             {
-                if( es->i_id == p_sys->i_default_sub_id )
+                /* If there is no user preference, select the default subtitle 
+                 * or adapt by ES priority */
+                if( ( !p_sys->p_es_sub &&
+                      ( p_sys->i_default_sub_id >= 0 &&
+                        es->i_id == p_sys->i_default_sub_id ) ) ||
+                    ( p_sys->p_es_sub && 
+                      p_sys->p_es_sub->fmt.i_priority < es->fmt.i_priority ) )
                     i_wanted = es->i_channel;
+                else if( p_sys->p_es_sub &&
+                         p_sys->p_es_sub->fmt.i_priority >= es->fmt.i_priority )
+                    i_wanted = p_sys->p_es_sub->i_channel;
             }
 
             if( p_sys->i_sub_last >= 0 )
@@ -1874,27 +1906,25 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
 {
     es_out_sys_t   *p_sys = out->p_sys;
     input_thread_t *p_input = p_sys->p_input;
-    int i_total = 0;
 
     if( libvlc_stats( p_input ) )
     {
+        uint64_t i_total;
+
         vlc_mutex_lock( &p_input->p->counters.counters_lock );
-        stats_UpdateInteger( p_input, p_input->p->counters.p_demux_read,
-                             p_block->i_buffer, &i_total );
-        stats_UpdateFloat( p_input , p_input->p->counters.p_demux_bitrate,
-                           (float)i_total, NULL );
+        stats_Update( p_input->p->counters.p_demux_read,
+                      p_block->i_buffer, &i_total );
+        stats_Update( p_input->p->counters.p_demux_bitrate, i_total, NULL );
 
         /* Update number of corrupted data packats */
         if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
         {
-            stats_UpdateInteger( p_input, p_input->p->counters.p_demux_corrupted,
-                                 1, NULL );
+            stats_Update( p_input->p->counters.p_demux_corrupted, 1, NULL );
         }
         /* Update number of discontinuities */
         if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
         {
-            stats_UpdateInteger( p_input, p_input->p->counters.p_demux_discontinuity,
-                                 1, NULL );
+            stats_Update( p_input->p->counters.p_demux_discontinuity, 1, NULL );
         }
         vlc_mutex_unlock( &p_input->p->counters.counters_lock );
     }
@@ -1905,15 +1935,13 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
     if( p_sys->i_preroll_end >= 0 )
     {
         int64_t i_date = p_block->i_pts;
-        if( i_date <= 0 )
+        if( p_block->i_pts <= VLC_TS_INVALID )
             i_date = p_block->i_dts;
 
         if( i_date < p_sys->i_preroll_end )
             p_block->i_flags |= BLOCK_FLAG_PREROLL;
     }
 
-    p_block->i_rate = 0;
-
     if( !es->p_dec )
     {
         block_Release( p_block );
@@ -1922,7 +1950,7 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
     }
 
     /* Check for sout mode */
-    if( out->b_sout )
+    if( p_input->p->p_sout )
     {
         /* FIXME review this, proper lock may be missing */
         if( p_input->p->p_sout->i_out_pace_nocontrol > 0 &&
@@ -1984,6 +2012,10 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
 
         /* */
         es->pb_cc_present[i] = true;
+
+        /* Enable if user specified on command line */
+        if (p_sys->i_sub_last == i)
+            EsOutSelect(out, es->pp_cc_es[i], true);
     }
 
     vlc_mutex_unlock( &p_sys->lock );
@@ -2005,7 +2037,7 @@ static void EsOutDel( es_out_t *out, es_out_id_t *es )
     /* We don't try to reselect */
     if( es->p_dec )
     {
-        while( !p_sys->p_input->b_die && !p_sys->b_buffering && es->p_dec )
+        while( vlc_object_alive(p_sys->p_input) && !p_sys->b_buffering )
         {
             if( input_DecoderIsEmpty( es->p_dec ) &&
                 ( !es->p_dec_record || input_DecoderIsEmpty( es->p_dec_record ) ))
@@ -2082,491 +2114,585 @@ static void EsOutDel( es_out_t *out, es_out_id_t *es )
 static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
 {
     es_out_sys_t *p_sys = out->p_sys;
-    bool  b, *pb;
-    int         i;
-
-    es_out_id_t *es;
 
     switch( i_query )
     {
-        case ES_OUT_SET_ES_STATE:
-            es = (es_out_id_t*) va_arg( args, es_out_id_t * );
-            b = (bool) va_arg( args, int );
-            if( b && !EsIsSelected( es ) )
-            {
-                EsSelect( out, es );
-                return EsIsSelected( es ) ? VLC_SUCCESS : VLC_EGENERIC;
-            }
-            else if( !b && EsIsSelected( es ) )
-            {
-                EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
-                return VLC_SUCCESS;
-            }
+    case ES_OUT_SET_ES_STATE:
+    {
+        es_out_id_t *es = va_arg( args, es_out_id_t * );
+        bool b = va_arg( args, int );
+        if( b && !EsIsSelected( es ) )
+        {
+            EsSelect( out, es );
+            return EsIsSelected( es ) ? VLC_SUCCESS : VLC_EGENERIC;
+        }
+        else if( !b && EsIsSelected( es ) )
+        {
+            EsUnselect( out, es, es->p_pgrm == p_sys->p_pgrm );
             return VLC_SUCCESS;
+        }
+        return VLC_SUCCESS;
+    }
 
-        case ES_OUT_GET_ES_STATE:
-            es = (es_out_id_t*) va_arg( args, es_out_id_t * );
-            pb = (bool*) va_arg( args, bool * );
+    case ES_OUT_GET_ES_STATE:
+    {
+        es_out_id_t *es = va_arg( args, es_out_id_t * );
+        bool *pb = va_arg( args, bool * );
 
-            *pb = EsIsSelected( es );
-            return VLC_SUCCESS;
+        *pb = EsIsSelected( es );
+        return VLC_SUCCESS;
+    }
+
+    case ES_OUT_GET_GROUP_FORCED:
+    {
+        int *pi_group = va_arg( args, int * );
+        *pi_group = p_sys->i_group_id;
+        return VLC_SUCCESS;
+    }
+
+    case ES_OUT_SET_MODE:
+    {
+        const int i_mode = va_arg( args, int );
+        assert( i_mode == ES_OUT_MODE_NONE || i_mode == ES_OUT_MODE_ALL ||
+                i_mode == ES_OUT_MODE_AUTO || i_mode == ES_OUT_MODE_PARTIAL ||
+                i_mode == ES_OUT_MODE_END );
 
-        case ES_OUT_SET_ACTIVE:
+        if( i_mode != ES_OUT_MODE_NONE && !p_sys->b_active && p_sys->i_es > 0 )
         {
-            b = (bool) va_arg( args, int );
-            if( b && !p_sys->b_active && p_sys->i_es > 0 )
+            /* XXX Terminate vout if there are tracks but no video one.
+             * This one is not mandatory but is he earliest place where it
+             * can be done */
+            int i;
+            for( i = 0; i < p_sys->i_es; i++ )
             {
-                /* XXX Terminate vout if there are tracks but no video one.
-                 * This one is not mandatory but is he earliest place where it
-                 * can be done */
-                for( i = 0; i < p_sys->i_es; i++ )
-                {
-                    es_out_id_t *p_es = p_sys->es[i];
-                    if( p_es->fmt.i_cat == VIDEO_ES )
-                        break;
-                }
-                if( i >= p_sys->i_es )
-                    input_resource_TerminateVout( p_sys->p_input->p->p_resource );
+                es_out_id_t *p_es = p_sys->es[i];
+                if( p_es->fmt.i_cat == VIDEO_ES )
+                    break;
             }
-            p_sys->b_active = b;
-            return VLC_SUCCESS;
+            if( i >= p_sys->i_es )
+                input_resource_TerminateVout( p_sys->p_input->p->p_resource );
         }
+        p_sys->b_active = i_mode != ES_OUT_MODE_NONE;
+        p_sys->i_mode = i_mode;
 
-        case ES_OUT_SET_MODE:
-            i = (int) va_arg( args, int );
-            if( i == ES_OUT_MODE_NONE || i == ES_OUT_MODE_ALL ||
-                i == ES_OUT_MODE_AUTO || i == ES_OUT_MODE_PARTIAL )
-            {
-                p_sys->i_mode = i;
-
-                /* Reapply policy mode */
-                for( i = 0; i < p_sys->i_es; i++ )
-                {
-                    if( EsIsSelected( p_sys->es[i] ) )
-                    {
-                        EsUnselect( out, p_sys->es[i],
-                                    p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
-                    }
-                }
-                for( i = 0; i < p_sys->i_es; i++ )
-                {
-                    EsOutSelect( out, p_sys->es[i], false );
-                }
-                return VLC_SUCCESS;
-            }
-            return VLC_EGENERIC;
-
-        case ES_OUT_SET_ES:
-        case ES_OUT_RESTART_ES:
+        /* Reapply policy mode */
+        for( int i = 0; i < p_sys->i_es; i++ )
         {
-            int i_cat;
+            if( EsIsSelected( p_sys->es[i] ) )
+                EsUnselect( out, p_sys->es[i],
+                            p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
+        }
+        for( int i = 0; i < p_sys->i_es; i++ )
+            EsOutSelect( out, p_sys->es[i], false );
+        if( i_mode == ES_OUT_MODE_END )
+            EsOutTerminate( out );
+        return VLC_SUCCESS;
+    }
 
-            es = (es_out_id_t*) va_arg( args, es_out_id_t * );
+    case ES_OUT_SET_ES:
+    case ES_OUT_RESTART_ES:
+    {
+        es_out_id_t *es = va_arg( args, es_out_id_t * );
 
-            if( es == NULL )
-                i_cat = UNKNOWN_ES;
-            else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
-                i_cat = AUDIO_ES;
-            else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
-                i_cat = VIDEO_ES;
-            else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
-                i_cat = SPU_ES;
-            else
-                i_cat = -1;
+        int i_cat;
+        if( es == NULL )
+            i_cat = UNKNOWN_ES;
+        else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
+            i_cat = AUDIO_ES;
+        else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
+            i_cat = VIDEO_ES;
+        else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
+            i_cat = SPU_ES;
+        else
+            i_cat = -1;
 
-            for( i = 0; i < p_sys->i_es; i++ )
+        for( int i = 0; i < p_sys->i_es; i++ )
+        {
+            if( i_cat == -1 )
             {
-                if( i_cat == -1 )
+                if( es == p_sys->es[i] )
                 {
-                    if( es == p_sys->es[i] )
-                    {
-                        EsOutSelect( out, es, true );
-                        break;
-                    }
+                    EsOutSelect( out, es, true );
+                    break;
                 }
-                else
+            }
+            else
+            {
+                if( i_cat == UNKNOWN_ES || p_sys->es[i]->fmt.i_cat == i_cat )
                 {
-                    if( i_cat == UNKNOWN_ES || p_sys->es[i]->fmt.i_cat == i_cat )
+                    if( EsIsSelected( p_sys->es[i] ) )
                     {
-                        if( EsIsSelected( p_sys->es[i] ) )
+                        if( i_query == ES_OUT_RESTART_ES )
                         {
-                            if( i_query == ES_OUT_RESTART_ES )
+                            if( p_sys->es[i]->p_dec )
                             {
-                                if( p_sys->es[i]->p_dec )
-                                {
-                                    EsDestroyDecoder( out, p_sys->es[i] );
-                                    EsCreateDecoder( out, p_sys->es[i] );
-                                }
-                            }
-                            else
-                            {
-                                EsUnselect( out, p_sys->es[i],
-                                            p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
+                                EsDestroyDecoder( out, p_sys->es[i] );
+                                EsCreateDecoder( out, p_sys->es[i] );
                             }
                         }
+                        else
+                        {
+                            EsUnselect( out, p_sys->es[i],
+                                        p_sys->es[i]->p_pgrm == p_sys->p_pgrm );
+                        }
                     }
                 }
             }
-            return VLC_SUCCESS;
         }
-        case ES_OUT_SET_ES_DEFAULT:
-        {
-            es = (es_out_id_t*) va_arg( args, es_out_id_t * );
+        return VLC_SUCCESS;
+    }
 
-            if( es == NULL )
-            {
-                /*p_sys->i_default_video_id = -1;*/
-                /*p_sys->i_default_audio_id = -1;*/
-                p_sys->i_default_sub_id = -1;
-            }
-            else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
-            {
-                /*p_sys->i_default_video_id = -1;*/
-            }
-            else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
-            {
-                /*p_sys->i_default_audio_id = -1;*/
-            }
-            else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
-            {
-                p_sys->i_default_sub_id = -1;
-            }
+    case ES_OUT_SET_ES_DEFAULT:
+    {
+        es_out_id_t *es = va_arg( args, es_out_id_t * );
+
+        if( es == NULL )
+        {
+            /*p_sys->i_default_video_id = -1;*/
+            /*p_sys->i_default_audio_id = -1;*/
+            p_sys->i_default_sub_id = -1;
+        }
+        else if( es == (es_out_id_t*)((uint8_t*)NULL+AUDIO_ES) )
+        {
+            /*p_sys->i_default_video_id = -1;*/
+        }
+        else if( es == (es_out_id_t*)((uint8_t*)NULL+VIDEO_ES) )
+        {
+            /*p_sys->i_default_audio_id = -1;*/
+        }
+        else if( es == (es_out_id_t*)((uint8_t*)NULL+SPU_ES) )
+        {
+            p_sys->i_default_sub_id = -1;
+        }
+        else
+        {
+            /*if( es->fmt.i_cat == VIDEO_ES )
+                p_sys->i_default_video_id = es->i_id;
             else
-            {
-                /*if( es->fmt.i_cat == VIDEO_ES )
-                    p_sys->i_default_video_id = es->i_id;
-                else
-                if( es->fmt.i_cat == AUDIO_ES )
-                    p_sys->i_default_audio_id = es->i_id;
-                else*/
-                if( es->fmt.i_cat == SPU_ES )
-                    p_sys->i_default_sub_id = es->i_id;
-            }
-            return VLC_SUCCESS;
+            if( es->fmt.i_cat == AUDIO_ES )
+                p_sys->i_default_audio_id = es->i_id;
+            else*/
+            if( es->fmt.i_cat == SPU_ES )
+                p_sys->i_default_sub_id = es->i_id;
         }
+        return VLC_SUCCESS;
+    }
 
-        case ES_OUT_SET_PCR:
-        case ES_OUT_SET_GROUP_PCR:
-        {
-            es_out_pgrm_t *p_pgrm = NULL;
-            int            i_group = 0;
-            int64_t        i_pcr;
+    case ES_OUT_SET_PCR:
+    case ES_OUT_SET_GROUP_PCR:
+    {
+        es_out_pgrm_t *p_pgrm = NULL;
+        int            i_group = 0;
+        int64_t        i_pcr;
 
-            /* Search program */
-            if( i_query == ES_OUT_SET_PCR )
-            {
-                p_pgrm = p_sys->p_pgrm;
-                if( !p_pgrm )
-                    p_pgrm = EsOutProgramAdd( out, i_group );   /* Create it */
-            }
-            else
-            {
-                i_group = (int)va_arg( args, int );
-                p_pgrm = EsOutProgramFind( out, i_group );
-            }
+        /* Search program */
+        if( i_query == ES_OUT_SET_PCR )
+        {
+            p_pgrm = p_sys->p_pgrm;
             if( !p_pgrm )
-                return VLC_EGENERIC;
+                p_pgrm = EsOutProgramAdd( out, i_group );   /* Create it */
+        }
+        else
+        {
+            i_group = (int)va_arg( args, int );
+            p_pgrm = EsOutProgramFind( out, i_group );
+        }
+        if( !p_pgrm )
+            return VLC_EGENERIC;
 
-            i_pcr = (int64_t)va_arg( args, int64_t );
-            if( i_pcr <= VLC_TS_INVALID )
-            {
-                msg_Err( p_sys->p_input, "Invalid PCR value in ES_OUT_SET_(GROUP_)PCR !" );
-                return VLC_EGENERIC;
-            }
+        i_pcr = (int64_t)va_arg( args, int64_t );
+        if( i_pcr <= VLC_TS_INVALID )
+        {
+            msg_Err( p_sys->p_input, "Invalid PCR value in ES_OUT_SET_(GROUP_)PCR !" );
+            return VLC_EGENERIC;
+        }
 
-            /* 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,
-                                EsOutIsExtraBufferingAllowed( out ),
-                                i_pcr, mdate() );
+        /* 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,
+                            EsOutIsExtraBufferingAllowed( out ),
+                            i_pcr, mdate() );
 
-            if( p_pgrm == p_sys->p_pgrm )
+        if( !p_sys->p_pgrm )
+            return VLC_SUCCESS;
+
+        if( p_sys->b_buffering )
+        {
+            /* Check buffering state on master clock update */
+            EsOutDecodersStopBuffering( out, false );
+        }
+        else if( p_pgrm == p_sys->p_pgrm )
+        {
+            if( b_late && ( !p_sys->p_input->p->p_sout ||
+                                 !p_sys->p_input->p->b_out_pace_control ) )
             {
-                if( p_sys->b_buffering )
+                const mtime_t i_pts_delay_base = p_sys->i_pts_delay - p_sys->i_pts_jitter;
+                mtime_t i_pts_delay = input_clock_GetJitter( p_pgrm->p_clock );
+
+                /* Avoid dangerously high value */
+                const mtime_t i_jitter_max = INT64_C(1000) * var_InheritInteger( p_sys->p_input, "clock-jitter" );
+                if( i_pts_delay > __MIN( i_pts_delay_base + i_jitter_max, INPUT_PTS_DELAY_MAX ) )
                 {
-                    /* Check buffering state on master clock update */
-                    EsOutDecodersStopBuffering( out, false );
+                    msg_Err( p_sys->p_input,
+                             "ES_OUT_SET_(GROUP_)PCR  is called too late (jitter of %d ms ignored)",
+                             (int)(i_pts_delay - i_pts_delay_base) / 1000 );
+                    i_pts_delay = p_sys->i_pts_delay;
+
+                    /* reset clock */
+                    for( int i = 0; i < p_sys->i_pgrm; i++ )
+                      input_clock_Reset( p_sys->pgrm[i]->p_clock );
                 }
-                else if( b_late )
+                else
                 {
-                    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",
+                             "ES_OUT_SET_(GROUP_)PCR  is called too late (pts_delay increased to %d ms)",
                              (int)(i_pts_delay/1000) );
 
+                    /* Force a rebufferization when we are too late */
+
                     /* 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 );
                 }
+
+                es_out_SetJitter( out, i_pts_delay_base, i_pts_delay - i_pts_delay_base, p_sys->i_cr_average );
             }
-            return VLC_SUCCESS;
         }
+        return VLC_SUCCESS;
+    }
 
-        case ES_OUT_RESET_PCR:
-            msg_Err( p_sys->p_input, "ES_OUT_RESET_PCR called" );
-            EsOutChangePosition( out );
-            return VLC_SUCCESS;
+    case ES_OUT_RESET_PCR:
+        msg_Err( p_sys->p_input, "ES_OUT_RESET_PCR called" );
+        EsOutChangePosition( out );
+        return VLC_SUCCESS;
 
-        case ES_OUT_SET_GROUP:
+    case ES_OUT_SET_GROUP:
+    {
+        int i = va_arg( args, int );
+        for( int j = 0; j < p_sys->i_pgrm; j++ )
         {
-            int j;
-            i = (int) va_arg( args, int );
-            for( j = 0; j < p_sys->i_pgrm; j++ )
+            es_out_pgrm_t *p_pgrm = p_sys->pgrm[j];
+            if( p_pgrm->i_id == i )
             {
-                es_out_pgrm_t *p_pgrm = p_sys->pgrm[j];
-                if( p_pgrm->i_id == i )
-                {
-                    EsOutProgramSelect( out, p_pgrm );
-                    return VLC_SUCCESS;
-                }
+                EsOutProgramSelect( out, p_pgrm );
+                return VLC_SUCCESS;
             }
-            return VLC_EGENERIC;
         }
+        return VLC_EGENERIC;
+    }
 
-        case ES_OUT_SET_ES_FMT:
+    case ES_OUT_SET_ES_FMT:
+    {
+        /* This ain't pretty but is need by some demuxers (eg. Ogg )
+         * to update the p_extra data */
+        es_out_id_t *es = va_arg( args, es_out_id_t * );
+        es_format_t *p_fmt = va_arg( args, es_format_t * );
+        if( es == NULL )
+            return VLC_EGENERIC;
+
+        if( p_fmt->i_extra )
         {
-            /* This ain't pretty but is need by some demuxers (eg. Ogg )
-             * to update the p_extra data */
-            es_format_t *p_fmt;
-            es = (es_out_id_t*) va_arg( args, es_out_id_t * );
-            p_fmt = (es_format_t*) va_arg( args, es_format_t * );
-            if( es == NULL )
-                return VLC_EGENERIC;
+            es->fmt.i_extra = p_fmt->i_extra;
+            es->fmt.p_extra = xrealloc( es->fmt.p_extra, p_fmt->i_extra );
+            memcpy( es->fmt.p_extra, p_fmt->p_extra, p_fmt->i_extra );
 
-            if( p_fmt->i_extra )
-            {
-                es->fmt.i_extra = p_fmt->i_extra;
-                es->fmt.p_extra = realloc_or_free( es->fmt.p_extra,
-                                                             p_fmt->i_extra );
-                assert( es->fmt.p_extra );
-                memcpy( es->fmt.p_extra, p_fmt->p_extra, p_fmt->i_extra );
-
-                if( !es->p_dec )
-                    return VLC_SUCCESS;
+            if( !es->p_dec )
+                return VLC_SUCCESS;
 #if 1
-                EsDestroyDecoder( out, es );
+            EsDestroyDecoder( out, es );
 
-                EsCreateDecoder( out, es );
+            EsCreateDecoder( out, es );
 #else
-                es->p_dec->fmt_in.i_extra = p_fmt->i_extra;
-                es->p_dec->fmt_in.p_extra =
-                  realloc_or_free( es->p_dec->fmt_in.p_extra, p_fmt->i_extra );
-                assert( es->p_dec->fmt_in.p_extra );
-                memcpy( es->p_dec->fmt_in.p_extra,
-                        p_fmt->p_extra, p_fmt->i_extra );
+            es->p_dec->fmt_in.i_extra = p_fmt->i_extra;
+            es->p_dec->fmt_in.p_extra =
+              xrealloc( es->p_dec->fmt_in.p_extra, p_fmt->i_extra );
+            memcpy( es->p_dec->fmt_in.p_extra,
+                    p_fmt->p_extra, p_fmt->i_extra );
 #endif
-            }
-
-            return VLC_SUCCESS;
         }
 
-        case ES_OUT_SET_ES_SCRAMBLED_STATE:
-        {
-            es = (es_out_id_t*) va_arg( args, es_out_id_t * );
-            bool b_scrambled = (bool)va_arg( args, int );
+        return VLC_SUCCESS;
+    }
 
-            if( !es->b_scrambled != !b_scrambled )
-            {
-                es->b_scrambled = b_scrambled;
-                EsOutProgramUpdateScrambled( out, es->p_pgrm );
-            }
-            return VLC_SUCCESS;
-        }
+    case ES_OUT_SET_ES_SCRAMBLED_STATE:
+    {
+        es_out_id_t *es = va_arg( args, es_out_id_t * );
+        bool b_scrambled = (bool)va_arg( args, int );
 
-        case ES_OUT_SET_NEXT_DISPLAY_TIME:
+        if( !es->b_scrambled != !b_scrambled )
         {
-            const int64_t i_date = (int64_t)va_arg( args, int64_t );
+            es->b_scrambled = b_scrambled;
+            EsOutProgramUpdateScrambled( out, es->p_pgrm );
+        }
+        return VLC_SUCCESS;
+    }
 
-            if( i_date < 0 )
-                return VLC_EGENERIC;
+    case ES_OUT_SET_NEXT_DISPLAY_TIME:
+    {
+        const int64_t i_date = (int64_t)va_arg( args, int64_t );
 
-            p_sys->i_preroll_end = i_date;
+        if( i_date < 0 )
+            return VLC_EGENERIC;
 
-            return VLC_SUCCESS;
-        }
-        case ES_OUT_SET_GROUP_META:
-        {
-            int i_group = (int)va_arg( args, int );
-            const vlc_meta_t *p_meta = va_arg( args, const vlc_meta_t * );
+        p_sys->i_preroll_end = i_date;
 
-            EsOutProgramMeta( out, i_group, p_meta );
-            return VLC_SUCCESS;
-        }
-        case ES_OUT_SET_GROUP_EPG:
-        {
-            int i_group = (int)va_arg( args, int );
-            const vlc_epg_t *p_epg = va_arg( args, const vlc_epg_t * );
+        return VLC_SUCCESS;
+    }
+    case ES_OUT_SET_GROUP_META:
+    {
+        int i_group = (int)va_arg( args, int );
+        const vlc_meta_t *p_meta = va_arg( args, const vlc_meta_t * );
 
-            EsOutProgramEpg( out, i_group, p_epg );
-            return VLC_SUCCESS;
-        }
+        EsOutProgramMeta( out, i_group, p_meta );
+        return VLC_SUCCESS;
+    }
+    case ES_OUT_SET_GROUP_EPG:
+    {
+        int i_group = (int)va_arg( args, int );
+        const vlc_epg_t *p_epg = va_arg( args, const vlc_epg_t * );
 
-        case ES_OUT_DEL_GROUP:
-        {
-            int i_group = (int)va_arg( args, int );
+        EsOutProgramEpg( out, i_group, p_epg );
+        return VLC_SUCCESS;
+    }
 
-            return EsOutProgramDel( out, i_group );
-        }
+    case ES_OUT_DEL_GROUP:
+    {
+        int i_group = (int)va_arg( args, int );
 
-        case ES_OUT_SET_META:
-        {
-            const vlc_meta_t *p_meta = va_arg( args, const vlc_meta_t * );
+        return EsOutProgramDel( out, i_group );
+    }
 
-            EsOutMeta( out, p_meta );
-            return VLC_SUCCESS;
-        }
+    case ES_OUT_SET_META:
+    {
+        const vlc_meta_t *p_meta = va_arg( args, const vlc_meta_t * );
 
-        case ES_OUT_GET_WAKE_UP:
-        {
-            mtime_t *pi_wakeup = (mtime_t*)va_arg( args, mtime_t* );
-            *pi_wakeup = EsOutGetWakeup( out );
-            return VLC_SUCCESS;
-        }
+        EsOutMeta( out, p_meta );
+        return VLC_SUCCESS;
+    }
 
-        case ES_OUT_SET_ES_BY_ID:
-        case ES_OUT_RESTART_ES_BY_ID:
-        case ES_OUT_SET_ES_DEFAULT_BY_ID:
-        {
-            const int i_id = (int)va_arg( args, int );
-            es_out_id_t *p_es = EsOutGetFromID( out, i_id );
-            int i_new_query;
+    case ES_OUT_GET_WAKE_UP:
+    {
+        mtime_t *pi_wakeup = (mtime_t*)va_arg( args, mtime_t* );
+        *pi_wakeup = EsOutGetWakeup( out );
+        return VLC_SUCCESS;
+    }
 
-            switch( i_query )
-            {
-            case ES_OUT_SET_ES_BY_ID:         i_new_query = ES_OUT_SET_ES; break;
-            case ES_OUT_RESTART_ES_BY_ID:     i_new_query = ES_OUT_RESTART_ES; break;
-            case ES_OUT_SET_ES_DEFAULT_BY_ID: i_new_query = ES_OUT_SET_ES_DEFAULT; break;
-            default:
-              assert(0);
-            }
-            /* TODO if the lock is made non recursive it should be changed */
-            int i_ret = es_out_Control( out, i_new_query, p_es );
+    case ES_OUT_SET_ES_BY_ID:
+    case ES_OUT_RESTART_ES_BY_ID:
+    case ES_OUT_SET_ES_DEFAULT_BY_ID:
+    {
+        const int i_id = (int)va_arg( args, int );
+        es_out_id_t *p_es = EsOutGetFromID( out, i_id );
+        int i_new_query = 0;
 
-            /* Clean up vout after user action (in active mode only).
-             * FIXME it does not work well with multiple video windows */
-            if( p_sys->b_active )
-                input_resource_TerminateVout( p_sys->p_input->p->p_resource );
-            return i_ret;
+        switch( i_query )
+        {
+        case ES_OUT_SET_ES_BY_ID:         i_new_query = ES_OUT_SET_ES; break;
+        case ES_OUT_RESTART_ES_BY_ID:     i_new_query = ES_OUT_RESTART_ES; break;
+        case ES_OUT_SET_ES_DEFAULT_BY_ID: i_new_query = ES_OUT_SET_ES_DEFAULT; break;
+        default:
+          vlc_assert_unreachable();
         }
+        /* TODO if the lock is made non recursive it should be changed */
+        int i_ret = es_out_Control( out, i_new_query, p_es );
 
-        case ES_OUT_GET_BUFFERING:
-            pb = (bool *)va_arg( args, bool* );
-            *pb = p_sys->b_buffering;
-            return VLC_SUCCESS;
+        /* Clean up vout after user action (in active mode only).
+         * FIXME it does not work well with multiple video windows */
+        if( p_sys->b_active )
+            input_resource_TerminateVout( p_sys->p_input->p->p_resource );
+        return i_ret;
+    }
 
-        case ES_OUT_GET_EMPTY:
-            pb = (bool *)va_arg( args, bool* );
-            *pb = EsOutDecodersIsEmpty( out );
-            return VLC_SUCCESS;
+    case ES_OUT_GET_ES_OBJECTS_BY_ID:
+    {
+        const int i_id = va_arg( args, int );
+        es_out_id_t *p_es = EsOutGetFromID( out, i_id );
+        if( !p_es )
+            return VLC_EGENERIC;
 
-        case ES_OUT_SET_DELAY:
+        vlc_object_t    **pp_decoder = va_arg( args, vlc_object_t ** );
+        vout_thread_t   **pp_vout    = va_arg( args, vout_thread_t ** );
+        audio_output_t **pp_aout    = va_arg( args, audio_output_t ** );
+        if( p_es->p_dec )
         {
-            const int i_cat = (int)va_arg( args, int );
-            const mtime_t i_delay = (mtime_t)va_arg( args, mtime_t );
-            EsOutSetDelay( out, i_cat, i_delay );
-            return VLC_SUCCESS;
+            if( pp_decoder )
+                *pp_decoder = vlc_object_hold( p_es->p_dec );
+            input_DecoderGetObjects( p_es->p_dec, pp_vout, pp_aout );
+        }
+        else
+        {
+            if( pp_decoder )
+                *pp_decoder = NULL;
+            if( pp_vout )
+                *pp_vout = NULL;
+            if( pp_aout )
+                *pp_aout = NULL;
         }
+        return VLC_SUCCESS;
+    }
 
-        case ES_OUT_SET_RECORD_STATE:
-            b = (bool) va_arg( args, int );
-            return EsOutSetRecord( out, b );
+    case ES_OUT_GET_BUFFERING:
+    {
+        bool *pb = va_arg( args, bool* );
+        *pb = p_sys->b_buffering;
+        return VLC_SUCCESS;
+    }
 
-        case ES_OUT_SET_PAUSE_STATE:
-        {
-            const bool b_source_paused = (bool)va_arg( args, int );
-            const bool b_paused = (bool)va_arg( args, int );
-            const mtime_t i_date = (mtime_t) va_arg( args, mtime_t );
+    case ES_OUT_GET_EMPTY:
+    {
+        bool *pb = va_arg( args, bool* );
+        *pb = EsOutDecodersIsEmpty( out );
+        return VLC_SUCCESS;
+    }
 
-            assert( !b_source_paused == !b_paused );
-            EsOutChangePause( out, b_paused, i_date );
+    case ES_OUT_SET_DELAY:
+    {
+        const int i_cat = (int)va_arg( args, int );
+        const mtime_t i_delay = (mtime_t)va_arg( args, mtime_t );
+        EsOutSetDelay( out, i_cat, i_delay );
+        return VLC_SUCCESS;
+    }
 
-            return VLC_SUCCESS;
-        }
+    case ES_OUT_SET_RECORD_STATE:
+    {
+        bool b = va_arg( args, int );
+        return EsOutSetRecord( out, b );
+    }
 
-        case ES_OUT_SET_RATE:
-        {
-            const int i_src_rate = (int)va_arg( args, int );
-            const int i_rate = (int)va_arg( args, int );
+    case ES_OUT_SET_PAUSE_STATE:
+    {
+        const bool b_source_paused = (bool)va_arg( args, int );
+        const bool b_paused = (bool)va_arg( args, int );
+        const mtime_t i_date = (mtime_t) va_arg( args, mtime_t );
 
-            assert( i_src_rate == i_rate );
-            EsOutChangeRate( out, i_rate );
+        assert( !b_source_paused == !b_paused );
+        EsOutChangePause( out, b_paused, i_date );
 
-            return VLC_SUCCESS;
-        }
+        return VLC_SUCCESS;
+    }
 
-        case ES_OUT_SET_TIME:
-        {
-            const mtime_t i_date = (mtime_t)va_arg( args, mtime_t );
+    case ES_OUT_SET_RATE:
+    {
+        const int i_src_rate = (int)va_arg( args, int );
+        const int i_rate = (int)va_arg( args, int );
 
-            assert( i_date == -1 );
-            EsOutChangePosition( out );
+        assert( i_src_rate == i_rate );
+        EsOutChangeRate( out, i_rate );
 
-            return VLC_SUCCESS;
-        }
+        return VLC_SUCCESS;
+    }
 
-        case ES_OUT_SET_FRAME_NEXT:
-            EsOutFrameNext( out );
-            return VLC_SUCCESS;
+    case ES_OUT_SET_TIME:
+    {
+        const mtime_t i_date = (mtime_t)va_arg( args, mtime_t );
 
-        case ES_OUT_SET_TIMES:
-        {
-            double f_position = (double)va_arg( args, double );
-            mtime_t i_time = (mtime_t)va_arg( args, mtime_t );
-            mtime_t i_length = (mtime_t)va_arg( args, mtime_t );
+        assert( i_date == -1 );
+        EsOutChangePosition( out );
 
-            input_SendEventLength( p_sys->p_input, i_length );
+        return VLC_SUCCESS;
+    }
 
-            if( !p_sys->b_buffering )
-            {
-                /* Fix for buffering delay */
-                const mtime_t i_delay = EsOutGetBuffering( out );
+    case ES_OUT_SET_FRAME_NEXT:
+        EsOutFrameNext( out );
+        return VLC_SUCCESS;
 
-                i_time -= i_delay;
-                if( i_time < 0 )
-                    i_time = 0;
+    case ES_OUT_SET_TIMES:
+    {
+        double f_position = (double)va_arg( args, double );
+        mtime_t i_time = (mtime_t)va_arg( args, mtime_t );
+        mtime_t i_length = (mtime_t)va_arg( args, mtime_t );
 
-                if( i_length > 0 )
-                    f_position -= (double)i_delay / i_length;
-                if( f_position < 0 )
-                    f_position = 0;
+        input_SendEventLength( p_sys->p_input, i_length );
 
-                input_SendEventPosition( p_sys->p_input, f_position, i_time );
-            }
-            return VLC_SUCCESS;
-        }
-        case ES_OUT_SET_JITTER:
+        if( !p_sys->b_buffering )
         {
-            mtime_t i_pts_delay = (mtime_t)va_arg( args, mtime_t );
-            int     i_cr_average = (int)va_arg( args, int );
+            mtime_t i_delay;
 
-            if( i_pts_delay == p_sys->i_pts_delay &&
-                i_cr_average == p_sys->i_cr_average )
-                return VLC_SUCCESS;
+            /* Fix for buffering delay */
+            if( !p_sys->p_input->p->p_sout ||
+                !p_sys->p_input->p->b_out_pace_control )
+                i_delay = EsOutGetBuffering( out );
+            else
+                i_delay = 0;
 
-            p_sys->i_pts_delay = i_pts_delay;
-            p_sys->i_cr_average = i_cr_average;
+            i_time -= i_delay;
+            if( i_time < 0 )
+                i_time = 0;
 
-            for( int i = 0; i < p_sys->i_pgrm; i++ )
-                input_clock_SetJitter( p_sys->pgrm[i]->p_clock,
-                                       i_pts_delay, i_cr_average );
-            return VLC_SUCCESS;
+            if( i_length > 0 )
+                f_position -= (double)i_delay / i_length;
+            if( f_position < 0 )
+                f_position = 0;
+
+            input_SendEventPosition( p_sys->p_input, f_position, i_time );
         }
+        return VLC_SUCCESS;
+    }
+    case ES_OUT_SET_JITTER:
+    {
+        mtime_t i_pts_delay  = (mtime_t)va_arg( args, mtime_t );
+        mtime_t i_pts_jitter = (mtime_t)va_arg( args, mtime_t );
+        int     i_cr_average = (int)va_arg( args, int );
 
-        default:
-            msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
+        bool b_change_clock =
+            i_pts_delay + i_pts_jitter != p_sys->i_pts_delay ||
+            i_cr_average != p_sys->i_cr_average;
+
+        assert( i_pts_jitter >= 0 );
+        p_sys->i_pts_delay  = i_pts_delay + i_pts_jitter;
+        p_sys->i_pts_jitter = i_pts_jitter;
+        p_sys->i_cr_average = i_cr_average;
+
+        for( int i = 0; i < p_sys->i_pgrm && b_change_clock; i++ )
+            input_clock_SetJitter( p_sys->pgrm[i]->p_clock,
+                                   i_pts_delay + i_pts_jitter, i_cr_average );
+        return VLC_SUCCESS;
+    }
+
+    case ES_OUT_GET_PCR_SYSTEM:
+    {
+        if( p_sys->b_buffering )
+            return VLC_EGENERIC;
+
+        es_out_pgrm_t *p_pgrm = p_sys->p_pgrm;
+        if( !p_pgrm )
+            return VLC_EGENERIC;
+
+        mtime_t *pi_system = va_arg( args, mtime_t *);
+        mtime_t *pi_delay  = va_arg( args, mtime_t *);
+        input_clock_GetSystemOrigin( p_pgrm->p_clock, pi_system, pi_delay );
+        return VLC_SUCCESS;
+    }
+
+    case ES_OUT_MODIFY_PCR_SYSTEM:
+    {
+        if( p_sys->b_buffering )
+            return VLC_EGENERIC;
+
+        es_out_pgrm_t *p_pgrm = p_sys->p_pgrm;
+        if( !p_pgrm )
             return VLC_EGENERIC;
+
+        const bool    b_absolute = va_arg( args, int );
+        const mtime_t i_system   = va_arg( args, mtime_t );
+        input_clock_ChangeSystemOrigin( p_pgrm->p_clock, b_absolute, i_system );
+        return VLC_SUCCESS;
+    }
+    case ES_OUT_SET_EOS:
+    {
+        for (int i = 0; i < p_sys->i_es; i++) {
+            es_out_id_t *id = p_sys->es[i];
+            if (id->p_dec != NULL)
+                input_DecoderDrain(id->p_dec);
+        }
+        return VLC_SUCCESS;
+    }
+
+    default:
+        msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
+        return VLC_EGENERIC;
     }
 }
 static int EsOutControl( es_out_t *out, int i_query, va_list args )
@@ -2588,7 +2714,7 @@ static char *LanguageGetName( const char *psz_code )
 {
     const iso639_lang_t *pl;
 
-    if( psz_code == NULL )
+    if( psz_code == NULL || !strcmp( psz_code, "und" ) )
     {
         return strdup( "" );
     }
@@ -2616,11 +2742,7 @@ static char *LanguageGetName( const char *psz_code )
     }
     else
     {
-        if( *pl->psz_native_name )
-        {
-            return strdup( pl->psz_native_name );
-        }
-        return strdup( pl->psz_eng_name );
+        return strdup( vlc_gettext(pl->psz_eng_name) );
     }
 }
 
@@ -2635,20 +2757,16 @@ static char *LanguageGetCode( const char *psz_lang )
     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 ) ||
             !strcasecmp( pl->psz_iso639_1, psz_lang ) ||
             !strcasecmp( pl->psz_iso639_2T, psz_lang ) ||
             !strcasecmp( pl->psz_iso639_2B, psz_lang ) )
-            break;
+            return strdup( pl->psz_iso639_1 );
     }
 
-    if( pl->psz_eng_name != NULL )
-        return strdup( pl->psz_iso639_1 );
-
     return strdup("??");
 }
 
-static char **LanguageSplit( const char *psz_langs )
+static char **LanguageSplit( const char *psz_langs, bool b_default_any )
 {
     char *psz_dup;
     char *psz_parser;
@@ -2671,6 +2789,10 @@ static char **LanguageSplit( const char *psz_langs )
         {
             TAB_APPEND( i_psz, ppsz, strdup("any") );
         }
+        else if( !strcmp( psz_parser, "none" ) )
+        {
+            TAB_APPEND( i_psz, ppsz, strdup("none") );
+        }
         else
         {
             psz_code = LanguageGetCode( psz_parser );
@@ -2689,6 +2811,8 @@ static char **LanguageSplit( const char *psz_langs )
 
     if( i_psz )
     {
+        if( b_default_any && strcmp( ppsz[i_psz - 1], "none" ) )
+            TAB_APPEND( i_psz, ppsz, strdup("any") );
         TAB_APPEND( i_psz, ppsz, NULL );
     }
 
@@ -2696,19 +2820,18 @@ static char **LanguageSplit( const char *psz_langs )
     return ppsz;
 }
 
-static int LanguageArrayIndex( char **ppsz_langs, char *psz_lang )
+static int LanguageArrayIndex( char **ppsz_langs, const char *psz_lang )
 {
-    int i;
-
-    if( !ppsz_langs || !psz_lang ) return -1;
+    if( !ppsz_langs || !psz_lang )
+        return -1;
 
-    for( i = 0; ppsz_langs[i]; i++ )
+    for( int i = 0; ppsz_langs[i]; i++ )
     {
         if( !strcasecmp( ppsz_langs[i], psz_lang ) ||
             !strcasecmp( ppsz_langs[i], "any" ) )
-        {
             return i;
-        }
+        if( !strcasecmp( ppsz_langs[i], "none" ) )
+            break;
     }
 
     return -1;
@@ -2723,17 +2846,25 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
     es_out_sys_t   *p_sys = out->p_sys;
     input_thread_t *p_input = p_sys->p_input;
     const es_format_t *p_fmt_es = &es->fmt;
-    char           *psz_cat;
     lldiv_t         div;
 
-    /* Create category name */
-    if( asprintf( &psz_cat, _("Stream %d"), es->i_meta_id ) == -1 )
-        return;
+    if( es->fmt.i_cat == fmt->i_cat )
+    {
+        es_format_t update = *fmt;
+        update.i_id = es->i_meta_id;
+        update.i_codec = es->fmt.i_codec;
+        update.i_original_fourcc = es->fmt.i_original_fourcc;
+        input_item_UpdateTracksInfo(input_GetItem(p_input), &update);
+    }
 
-    /* Remove previous information */
-    input_Control( p_input, INPUT_DEL_INFO, psz_cat, NULL );
+    /* Create category */
+    char psz_cat[128];
+    snprintf( psz_cat, sizeof(psz_cat),_("Stream %d"), es->i_meta_id );
+    info_category_t *p_cat = info_category_New( psz_cat );
+    if( !p_cat )
+        return;
 
-    /* Add informations */
+    /* Add information */
     const char *psz_type;
     switch( fmt->i_cat )
     {
@@ -2752,46 +2883,43 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
     }
 
     if( psz_type )
-        input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Type"), psz_type );
+        info_category_AddInfo( p_cat, _("Type"), "%s", psz_type );
 
     if( es->i_meta_id != es->i_id )
-        input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Original ID"),
+        info_category_AddInfo( p_cat, _("Original ID"),
                        "%d", es->i_id );
 
     const char *psz_codec_description =
         vlc_fourcc_GetDescription( p_fmt_es->i_cat, p_fmt_es->i_codec );
-    const vlc_fourcc_t i_codec_fourcc = p_fmt_es->i_original_fourcc ?: p_fmt_es->i_codec;
-    if( psz_codec_description )
-        input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Codec"),
-                       "%s (%.4s)", psz_codec_description, (char*)&i_codec_fourcc );
-    else
-        input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Codec"),
-                       "%.4s", (char*)&i_codec_fourcc );
+    const vlc_fourcc_t i_codec_fourcc = ( p_fmt_es->i_original_fourcc )?
+                               p_fmt_es->i_original_fourcc : p_fmt_es->i_codec;
+    if( psz_codec_description && *psz_codec_description )
+        info_category_AddInfo( p_cat, _("Codec"), "%s (%.4s)",
+                               psz_codec_description, (char*)&i_codec_fourcc );
+    else if ( i_codec_fourcc != VLC_FOURCC(0,0,0,0) )
+        info_category_AddInfo( p_cat, _("Codec"), "%.4s",
+                               (char*)&i_codec_fourcc );
 
     if( es->psz_language && *es->psz_language )
-        input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Language"),
-                       "%s", es->psz_language );
+        info_category_AddInfo( p_cat, _("Language"), "%s",
+                               es->psz_language );
     if( fmt->psz_description && *fmt->psz_description )
-        input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Description"),
-                       "%s", fmt->psz_description );
+        info_category_AddInfo( p_cat, _("Description"), "%s",
+                               fmt->psz_description );
 
     switch( fmt->i_cat )
     {
     case AUDIO_ES:
-        input_Control( p_input, INPUT_ADD_INFO, psz_cat,
-                       _("Type"), _("Audio") );
+        info_category_AddInfo( p_cat, _("Type"), _("Audio") );
 
-        if( fmt->audio.i_physical_channels & AOUT_CHAN_PHYSMASK )
-            input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
-                           "%s", _( aout_FormatPrintChannels( &fmt->audio ) ) );
-        else if( fmt->audio.i_channels > 0 )
-            input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Channels"),
-                           "%u", fmt->audio.i_channels );
+        if( fmt->audio.i_physical_channels )
+            info_category_AddInfo( p_cat, _("Channels"), "%s",
+                                   _( aout_FormatPrintChannels( &fmt->audio ) ) );
 
         if( fmt->audio.i_rate > 0 )
         {
-            input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Sample rate"),
-                           _("%u Hz"), fmt->audio.i_rate );
+            info_category_AddInfo( p_cat, _("Sample rate"), _("%u Hz"),
+                                   fmt->audio.i_rate );
             /* FIXME that should be removed or improved ! (used by text/strings.c) */
             var_SetInteger( p_input, "sample-rate", fmt->audio.i_rate );
         }
@@ -2800,14 +2928,13 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
         if( i_bitspersample <= 0 )
             i_bitspersample = aout_BitsPerSample( p_fmt_es->i_codec );
         if( i_bitspersample > 0 )
-            input_Control( p_input, INPUT_ADD_INFO, psz_cat,
-                           _("Bits per sample"), "%u",
-                           i_bitspersample );
+            info_category_AddInfo( p_cat, _("Bits per sample"), "%u",
+                                   i_bitspersample );
 
         if( fmt->i_bitrate > 0 )
         {
-            input_Control( p_input, INPUT_ADD_INFO, psz_cat, _("Bitrate"),
-                           _("%u kb/s"), fmt->i_bitrate / 1000 );
+            info_category_AddInfo( p_cat, _("Bitrate"), _("%u kb/s"),
+                                   fmt->i_bitrate / 1000 );
             /* FIXME that should be removed or improved ! (used by text/strings.c) */
             var_SetInteger( p_input, "bit-rate", fmt->i_bitrate );
         }
@@ -2821,26 +2948,23 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
                 psz_name = _("Track replay gain");
             else
                 psz_name = _("Album replay gain");
-            input_Control( p_input, INPUT_ADD_INFO, psz_cat,
-                           psz_name, _("%.2f dB"), p_rg->pf_gain[i] );
+            info_category_AddInfo( p_cat, psz_name, _("%.2f dB"),
+                                   p_rg->pf_gain[i] );
         }
         break;
 
     case VIDEO_ES:
-        input_Control( p_input, INPUT_ADD_INFO, psz_cat,
-                       _("Type"), _("Video") );
+        info_category_AddInfo( p_cat, _("Type"), _("Video") );
 
         if( fmt->video.i_width > 0 && fmt->video.i_height > 0 )
-            input_Control( p_input, INPUT_ADD_INFO, psz_cat,
-                           _("Resolution"), "%ux%u",
-                           fmt->video.i_width, fmt->video.i_height );
+            info_category_AddInfo( p_cat, _("Resolution"), "%ux%u",
+                                   fmt->video.i_width, fmt->video.i_height );
 
         if( fmt->video.i_visible_width > 0 &&
             fmt->video.i_visible_height > 0 )
-            input_Control( p_input, INPUT_ADD_INFO, psz_cat,
-                           _("Display resolution"), "%ux%u",
-                           fmt->video.i_visible_width,
-                           fmt->video.i_visible_height);
+            info_category_AddInfo( p_cat, _("Display resolution"), "%ux%u",
+                                   fmt->video.i_visible_width,
+                                   fmt->video.i_visible_height);
        if( fmt->video.i_frame_rate > 0 &&
            fmt->video.i_frame_rate_base > 0 )
        {
@@ -2848,18 +2972,25 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
                                fmt->video.i_frame_rate_base * 1000000,
                                1000000 );
            if( div.rem > 0 )
-               input_Control( p_input, INPUT_ADD_INFO, psz_cat,
-                              _("Frame rate"), "%"PRId64".%06u",
-                              div.quot, (unsigned int )div.rem );
+               info_category_AddInfo( p_cat, _("Frame rate"), "%"PRId64".%06u",
+                                      div.quot, (unsigned int )div.rem );
            else
-               input_Control( p_input, INPUT_ADD_INFO, psz_cat,
-                              _("Frame rate"), "%"PRId64, div.quot );
+               info_category_AddInfo( p_cat, _("Frame rate"), "%"PRId64,
+                                      div.quot );
        }
+       if( fmt->i_codec != p_fmt_es->i_codec )
+       {
+           const char *psz_chroma_description =
+                vlc_fourcc_GetDescription( VIDEO_ES, fmt->i_codec );
+           if( psz_chroma_description )
+               info_category_AddInfo( p_cat, _("Decoded format"), "%s",
+                                      psz_chroma_description );
+       }
+
        break;
 
     case SPU_ES:
-        input_Control( p_input, INPUT_ADD_INFO, psz_cat,
-                       _("Type"), _("Subtitle") );
+        info_category_AddInfo( p_cat, _("Type"), _("Subtitle") );
         break;
 
     default:
@@ -2869,19 +3000,19 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
     /* Append generic meta */
     if( p_meta )
     {
-        char **ppsz_all_keys = vlc_dictionary_all_keys( &p_meta->extra_tags );
+        char **ppsz_all_keys = vlc_meta_CopyExtraNames( p_meta );
         for( int i = 0; ppsz_all_keys && ppsz_all_keys[i]; i++ )
         {
             char *psz_key = ppsz_all_keys[i];
-            char *psz_value = vlc_dictionary_value_for_key( &p_meta->extra_tags, psz_key );
+            const char *psz_value = vlc_meta_GetExtra( p_meta, psz_key );
 
             if( psz_value )
-                input_Control( p_input, INPUT_ADD_INFO, psz_cat,
-                               vlc_gettext(psz_key), vlc_gettext(psz_value) );
+                info_category_AddInfo( p_cat, vlc_gettext(psz_key), "%s",
+                                       vlc_gettext(psz_value) );
             free( psz_key );
         }
         free( ppsz_all_keys );
     }
-
-    free( psz_cat );
+    /* */
+    input_Control( p_input, INPUT_REPLACE_INFOS, p_cat );
 }