]> git.sesse.net Git - vlc/blobdiff - src/input/decoder.c
Merge VLC_OBJECT_PACKETIZER with VLC_OBJECT_DECODER
[vlc] / src / input / decoder.c
index 47538bb635bd2d1220ed2cbabf79e29c79237880..b795c7cba52cf2dc83746825f299d1d80332e4ca 100644 (file)
 #include <vlc_codec.h>
 #include <vlc_osd.h>
 #include <vlc_meta.h>
+#include <vlc_dialog.h>
 
-#include <vlc_interface.h>
 #include "audio_output/aout_internal.h"
 #include "stream_output/stream_output.h"
 #include "input_internal.h"
 #include "clock.h"
 #include "decoder.h"
 #include "event.h"
-#include "ressource.h"
+#include "resource.h"
 
 #include "../video_output/vout_control.h"
 
-static decoder_t *CreateDecoder( input_thread_t *, es_format_t *, int, sout_instance_t *p_sout );
+static decoder_t *CreateDecoder( input_thread_t *, es_format_t *, bool,
+                                 sout_instance_t *p_sout );
 static void       DeleteDecoder( decoder_t * );
 
 static void      *DecoderThread( vlc_object_t * );
@@ -94,6 +95,7 @@ struct decoder_owner_sys_t
 
     /* Some decoders require already packetized data (ie. not truncated) */
     decoder_t *p_packetizer;
+    bool b_packetizer;
 
     /* Current format in use by the output */
     video_format_t video;
@@ -110,7 +112,8 @@ struct decoder_owner_sys_t
 
     /* Lock for communication with decoder thread */
     vlc_mutex_t lock;
-    vlc_cond_t  wait;
+    vlc_cond_t  wait_request;
+    vlc_cond_t  wait_acknowledge;
 
     /* -- These variables need locking on write(only) -- */
     aout_instance_t *p_aout;
@@ -238,7 +241,7 @@ int decoder_GetInputAttachments( decoder_t *p_dec,
 mtime_t decoder_GetDisplayDate( decoder_t *p_dec, mtime_t i_ts )
 {
     if( !p_dec->pf_get_display_date )
-        return 0;
+        return VLC_TS_INVALID;
 
     return p_dec->pf_get_display_date( p_dec, i_ts );
 }
@@ -260,37 +263,22 @@ int decoder_GetDisplayRate( decoder_t *p_dec )
  * \return the spawned decoder object
  */
 decoder_t *input_DecoderNew( input_thread_t *p_input,
-                             es_format_t *fmt, input_clock_t *p_clock, sout_instance_t *p_sout  )
+                             es_format_t *fmt, input_clock_t *p_clock,
+                             sout_instance_t *p_sout  )
 {
     decoder_t *p_dec = NULL;
+    const char *psz_type = p_sout ? N_("packetizer") : N_("decoder");
     int i_priority;
 
-#ifdef ENABLE_SOUT
-    /* If we are in sout mode, search for packetizer module */
-    if( p_sout )
-    {
-        /* Create the decoder configuration structure */
-        p_dec = CreateDecoder( p_input, fmt, VLC_OBJECT_PACKETIZER, p_sout );
-        if( p_dec == NULL )
-        {
-            msg_Err( p_input, "could not create packetizer" );
-            intf_UserFatal( p_input, false, _("Streaming / Transcoding failed"),
-                            _("VLC could not open the packetizer module.") );
-            return NULL;
-        }
-    }
-    else
-#endif
+    /* Create the decoder configuration structure */
+    p_dec = CreateDecoder( p_input, fmt, p_sout != NULL, p_sout );
+    if( p_dec == NULL )
     {
-        /* Create the decoder configuration structure */
-        p_dec = CreateDecoder( p_input, fmt, VLC_OBJECT_DECODER, p_sout );
-        if( p_dec == NULL )
-        {
-            msg_Err( p_input, "could not create decoder" );
-            intf_UserFatal( p_input, false, _("Streaming / Transcoding failed"),
-                            _("VLC could not open the decoder module.") );
-            return NULL;
-        }
+        msg_Err( p_input, "could not create %s", psz_type );
+        dialog_Fatal( p_input, _("Streaming / Transcoding failed"),
+                      _("VLC could not open the %s module."),
+                      vlc_gettext( psz_type ) );
+        return NULL;
     }
 
     if( !p_dec->p_module )
@@ -303,8 +291,9 @@ decoder_t *input_DecoderNew( input_thread_t *p_input,
     }
 
     p_dec->p_owner->p_clock = p_clock;
+    assert( p_dec->fmt_out.i_cat != UNKNOWN_ES );
 
-    if( fmt->i_cat == AUDIO_ES )
+    if( p_dec->fmt_out.i_cat == AUDIO_ES )
         i_priority = VLC_THREAD_PRIORITY_AUDIO;
     else
         i_priority = VLC_THREAD_PRIORITY_VIDEO;
@@ -341,7 +330,7 @@ void input_DecoderDelete( decoder_t *p_dec )
     p_owner->b_paused = false;
     p_owner->b_buffering = false;
     p_owner->b_flushing = true;
-    vlc_cond_signal( &p_owner->wait );
+    vlc_cond_signal( &p_owner->wait_request );
     vlc_mutex_unlock( &p_owner->lock );
 
     vlc_thread_join( p_dec );
@@ -371,11 +360,11 @@ void input_DecoderDelete( decoder_t *p_dec )
  * \param p_dec the decoder object
  * \param p_block the data block
  */
-void input_DecoderDecode( decoder_t *p_dec, block_t *p_block )
+void input_DecoderDecode( decoder_t *p_dec, block_t *p_block, bool b_do_pace )
 {
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
 
-    if( p_owner->p_input->p->b_out_pace_control )
+    if( b_do_pace )
     {
         /* The fifo is not consummed when buffering and so will
          * deadlock vlc.
@@ -435,12 +424,12 @@ int input_DecoderSetCcState( decoder_t *p_dec, bool b_decode, int i_channel )
         es_format_t fmt;
 
         es_format_Init( &fmt, SPU_ES, fcc[i_channel] );
-        p_cc = CreateDecoder( p_owner->p_input, &fmt, VLC_OBJECT_DECODER, p_owner->p_sout );
+        p_cc = CreateDecoder( p_owner->p_input, &fmt, false, p_owner->p_sout );
         if( !p_cc )
         {
             msg_Err( p_dec, "could not create decoder" );
-            intf_UserFatal( p_dec, false, _("Streaming / Transcoding failed"),
-                            _("VLC could not open the decoder module.") );
+            dialog_Fatal( p_dec, _("Streaming / Transcoding failed"), "%s",
+                          _("VLC could not open the decoder module.") );
             return VLC_EGENERIC;
         }
         else if( !p_cc->p_module )
@@ -500,7 +489,7 @@ void input_DecoderChangePause( decoder_t *p_dec, bool b_paused, mtime_t i_date )
     p_owner->b_paused = b_paused;
     p_owner->pause.i_date = i_date;
     p_owner->pause.i_ignore = 0;
-    vlc_cond_signal( &p_owner->wait );
+    vlc_cond_signal( &p_owner->wait_request );
 
     DecoderOutputChangePause( p_dec, b_paused, i_date );
 
@@ -546,7 +535,7 @@ void input_DecoderStartBuffering( decoder_t *p_dec )
 
     p_owner->b_buffering = true;
 
-    vlc_cond_signal( &p_owner->wait );
+    vlc_cond_signal( &p_owner->wait_request );
 
     vlc_mutex_unlock( &p_owner->lock );
 }
@@ -559,7 +548,7 @@ void input_DecoderStopBuffering( decoder_t *p_dec )
 
     p_owner->b_buffering = false;
 
-    vlc_cond_signal( &p_owner->wait );
+    vlc_cond_signal( &p_owner->wait_request );
 
     vlc_mutex_unlock( &p_owner->lock );
 }
@@ -573,7 +562,7 @@ void input_DecoderWaitBuffering( decoder_t *p_dec )
     while( vlc_object_alive( p_dec ) && p_owner->b_buffering && !p_owner->buffer.b_full )
     {
         block_FifoWake( p_owner->p_fifo );
-        vlc_cond_wait( &p_owner->wait, &p_owner->lock );
+        vlc_cond_wait( &p_owner->wait_acknowledge, &p_owner->lock );
     }
 
     vlc_mutex_unlock( &p_owner->lock );
@@ -586,13 +575,13 @@ void input_DecoderFrameNext( decoder_t *p_dec, mtime_t *pi_duration )
     *pi_duration = 0;
 
     vlc_mutex_lock( &p_owner->lock );
-    if( p_dec->fmt_in.i_cat == VIDEO_ES )
+    if( p_dec->fmt_out.i_cat == VIDEO_ES )
     {
         if( p_owner->b_paused && p_owner->p_vout )
         {
             vout_NextPicture( p_owner->p_vout, pi_duration );
             p_owner->pause.i_ignore++;
-            vlc_cond_signal( &p_owner->wait );
+            vlc_cond_signal( &p_owner->wait_request );
         }
     }
     else
@@ -647,14 +636,14 @@ static mtime_t DecoderGetDisplayDate( decoder_t *p_dec, mtime_t i_ts )
 
     vlc_mutex_lock( &p_owner->lock );
     if( p_owner->b_buffering || p_owner->b_paused )
-        i_ts = 0;
+        i_ts = VLC_TS_INVALID;
     vlc_mutex_unlock( &p_owner->lock );
 
-    if( !p_owner->p_clock || !i_ts )
+    if( !p_owner->p_clock || i_ts <= VLC_TS_INVALID )
         return i_ts;
 
     if( input_clock_ConvertTS( p_owner->p_clock, NULL, &i_ts, NULL, INT64_MAX ) )
-        return 0;
+        return VLC_TS_INVALID;
 
     return i_ts;
 }
@@ -673,9 +662,10 @@ static void DecoderUnsupportedCodec( decoder_t *p_dec, vlc_fourcc_t codec )
     msg_Err( p_dec, "no suitable decoder module for fourcc `%4.4s'.\n"
              "VLC probably does not support this sound or video format.",
              (char*)&codec );
-    intf_UserFatal( p_dec, false, _("No suitable decoder module"), 
-                    _("VLC does not support the audio or video format \"%4.4s\". "
-                      "Unfortunately there is no way for you to fix this."), (char*)&codec );
+    dialog_Fatal( p_dec, _("No suitable decoder module"),
+                 _("VLC does not support the audio or video format \"%4.4s\". "
+                  "Unfortunately there is no way for you to fix this."),
+                  (char*)&codec );
 }
 
 
@@ -684,19 +674,18 @@ static void DecoderUnsupportedCodec( decoder_t *p_dec, vlc_fourcc_t codec )
  *
  * \param p_input the input thread
  * \param p_es the es descriptor
- * \param i_object_type Object type as define in include/vlc_objects.h
+ * \param b_packetizer instead of a decoder
  * \return the decoder object
  */
 static decoder_t * CreateDecoder( input_thread_t *p_input,
-                                  es_format_t *fmt, int i_object_type, sout_instance_t *p_sout )
+                                  es_format_t *fmt, bool b_packetizer,
+                                  sout_instance_t *p_sout )
 {
     decoder_t *p_dec;
     decoder_owner_sys_t *p_owner;
     es_format_t null_es_format;
 
-    int i;
-
-    p_dec = vlc_object_create( p_input, i_object_type );
+    p_dec = vlc_object_create( p_input, VLC_OBJECT_DECODER );
     if( p_dec == NULL )
         return NULL;
 
@@ -722,7 +711,7 @@ static decoder_t * CreateDecoder( input_thread_t *p_input,
         vlc_object_release( p_dec );
         return NULL;
     }
-    p_dec->p_owner->i_preroll_end = -1;
+    p_dec->p_owner->i_preroll_end = VLC_TS_INVALID;
     p_dec->p_owner->i_last_rate = INPUT_RATE_DEFAULT;
     p_dec->p_owner->p_input = p_input;
     p_dec->p_owner->p_aout = NULL;
@@ -734,6 +723,7 @@ static decoder_t * CreateDecoder( input_thread_t *p_input,
     p_dec->p_owner->p_sout = p_sout;
     p_dec->p_owner->p_sout_input = NULL;
     p_dec->p_owner->p_packetizer = NULL;
+    p_dec->p_owner->b_packetizer = b_packetizer;
 
     /* decoder fifo */
     if( ( p_dec->p_owner->p_fifo = block_FifoNew() ) == NULL )
@@ -760,17 +750,17 @@ static decoder_t * CreateDecoder( input_thread_t *p_input,
     vlc_object_attach( p_dec, p_input );
 
     /* Find a suitable decoder/packetizer module */
-    if( i_object_type == VLC_OBJECT_DECODER )
+    if( !b_packetizer )
         p_dec->p_module = module_need( p_dec, "decoder", "$codec", false );
     else
         p_dec->p_module = module_need( p_dec, "packetizer", "$packetizer", false );
 
     /* Check if decoder requires already packetized data */
-    if( i_object_type == VLC_OBJECT_DECODER &&
+    if( !b_packetizer &&
         p_dec->b_need_packetized && !p_dec->fmt_in.b_packetized )
     {
         p_dec->p_owner->p_packetizer =
-            vlc_object_create( p_input, VLC_OBJECT_PACKETIZER );
+            vlc_object_create( p_input, VLC_OBJECT_DECODER );
         if( p_dec->p_owner->p_packetizer )
         {
             es_format_Copy( &p_dec->p_owner->p_packetizer->fmt_in,
@@ -797,7 +787,7 @@ static decoder_t * CreateDecoder( input_thread_t *p_input,
     /* Copy ourself the input replay gain */
     if( fmt->i_cat == AUDIO_ES )
     {
-        for( i = 0; i < AUDIO_REPLAY_GAIN_MAX; i++ )
+        for( unsigned i = 0; i < AUDIO_REPLAY_GAIN_MAX; i++ )
         {
             if( !p_dec->fmt_out.audio_replay_gain.pb_peak[i] )
             {
@@ -814,14 +804,15 @@ static decoder_t * CreateDecoder( input_thread_t *p_input,
 
     /* */
     vlc_mutex_init( &p_owner->lock );
-    vlc_cond_init( &p_owner->wait );
+    vlc_cond_init( &p_owner->wait_request );
+    vlc_cond_init( &p_owner->wait_acknowledge );
 
     p_owner->b_fmt_description = false;
     es_format_Init( &p_owner->fmt_description, UNKNOWN_ES, 0 );
     p_owner->p_description = NULL;
 
     p_owner->b_paused = false;
-    p_owner->pause.i_date = 0;
+    p_owner->pause.i_date = VLC_TS_INVALID;
     p_owner->pause.i_ignore = 0;
 
     p_owner->b_buffering = false;
@@ -837,7 +828,7 @@ static decoder_t * CreateDecoder( input_thread_t *p_input,
 
     /* */
     p_owner->cc.b_supported = false;
-    if( i_object_type == VLC_OBJECT_DECODER )
+    if( !b_packetizer )
     {
         if( p_owner->p_packetizer && p_owner->p_packetizer->pf_get_cc )
             p_owner->cc.b_supported = true;
@@ -845,7 +836,7 @@ static decoder_t * CreateDecoder( input_thread_t *p_input,
             p_owner->cc.b_supported = true;
     }
 
-    for( i = 0; i < 4; i++ )
+    for( unsigned i = 0; i < 4; i++ )
     {
         p_owner->cc.pb_present[i] = false;
         p_owner->cc.pp_decoder[i] = NULL;
@@ -913,32 +904,17 @@ static void DecoderFlush( decoder_t *p_dec )
 
     /* Monitor for flush end */
     p_owner->b_flushing = true;
-    vlc_cond_signal( &p_owner->wait );
+    vlc_cond_signal( &p_owner->wait_request );
 
     /* Send a special block */
     block_t *p_null = DecoderBlockFlushNew();
     if( !p_null )
         return;
-    input_DecoderDecode( p_dec, p_null );
+    input_DecoderDecode( p_dec, p_null, false );
 
     /* */
     while( vlc_object_alive( p_dec ) && p_owner->b_flushing )
-        vlc_cond_wait( &p_owner->wait, &p_owner->lock );
-}
-
-static void DecoderSignalFlushed( decoder_t *p_dec )
-{
-    decoder_owner_sys_t *p_owner = p_dec->p_owner;
-
-    vlc_mutex_lock( &p_owner->lock );
-
-    if( p_owner->b_flushing )
-    {
-        p_owner->b_flushing = false;
-        vlc_cond_signal( &p_owner->wait );
-    }
-
-    vlc_mutex_unlock( &p_owner->lock );
+        vlc_cond_wait( &p_owner->wait_acknowledge, &p_owner->lock );
 }
 
 static void DecoderSignalBuffering( decoder_t *p_dec, bool b_full )
@@ -951,7 +927,7 @@ static void DecoderSignalBuffering( decoder_t *p_dec, bool b_full )
     {
         if( b_full )
             p_owner->buffer.b_full = true;
-        vlc_cond_signal( &p_owner->wait );
+        vlc_cond_signal( &p_owner->wait_acknowledge );
     }
 
     vlc_mutex_unlock( &p_owner->lock );
@@ -994,7 +970,7 @@ static void DecoderWaitUnblock( decoder_t *p_dec, bool *pb_reject )
             if( !p_owner->b_buffering || !p_owner->buffer.b_full )
                 break;
         }
-        vlc_cond_wait( &p_owner->wait, &p_owner->lock );
+        vlc_cond_wait( &p_owner->wait_request, &p_owner->lock );
     }
 
     if( pb_reject )
@@ -1011,13 +987,13 @@ static void DecoderOutputChangePause( decoder_t *p_dec, bool b_paused, mtime_t i
      * - for sout it is useless
      * - for subs, it is done by the vout
      */
-    if( p_dec->fmt_in.i_cat == AUDIO_ES )
+    if( p_dec->fmt_out.i_cat == AUDIO_ES )
     {
         if( p_owner->p_aout && p_owner->p_aout_input )
             aout_DecChangePause( p_owner->p_aout, p_owner->p_aout_input,
                                  b_paused, i_date );
     }
-    else if( p_dec->fmt_in.i_cat == VIDEO_ES )
+    else if( p_dec->fmt_out.i_cat == VIDEO_ES )
     {
         if( p_owner->p_vout )
             vout_ChangePause( p_owner->p_vout, b_paused, i_date );
@@ -1027,10 +1003,10 @@ static inline void DecoderUpdatePreroll( int64_t *pi_preroll, const block_t *p )
 {
     if( p->i_flags & (BLOCK_FLAG_PREROLL|BLOCK_FLAG_DISCONTINUITY) )
         *pi_preroll = INT64_MAX;
-    else if( p->i_pts > 0 )
-        *pi_preroll = __MIN( *pi_preroll, p->i_pts );
-    else if( p->i_dts > 0 )
+    else if( p->i_dts > VLC_TS_INVALID )
         *pi_preroll = __MIN( *pi_preroll, p->i_dts );
+    else if( p->i_pts > VLC_TS_INVALID )
+        *pi_preroll = __MIN( *pi_preroll, p->i_pts );
 }
 
 static mtime_t DecoderTeletextFixTs( mtime_t i_ts )
@@ -1038,7 +1014,7 @@ static mtime_t DecoderTeletextFixTs( mtime_t i_ts )
     mtime_t current_date = mdate();
 
     /* FIXME I don't really like that, es_out SHOULD do it using the video pts */
-    if( !i_ts || i_ts > current_date + 10000000 || i_ts < current_date )
+    if( i_ts <= VLC_TS_INVALID || i_ts > current_date + 10000000 || i_ts < current_date )
     {
         /* ETSI EN 300 472 Annex A : do not take into account the PTS
          * for teletext streams. */
@@ -1062,13 +1038,13 @@ static void DecoderFixTs( decoder_t *p_dec, mtime_t *pi_ts0, mtime_t *pi_ts1,
         const bool b_ephemere = pi_ts1 && *pi_ts0 == *pi_ts1;
         int i_rate;
 
-        if( *pi_ts0 > 0 )
+        if( *pi_ts0 > VLC_TS_INVALID )
         {
             *pi_ts0 += i_es_delay;
-            if( pi_ts1 && *pi_ts1 > 0 )
+            if( pi_ts1 && *pi_ts1 > VLC_TS_INVALID )
                 *pi_ts1 += i_es_delay;
             if( input_clock_ConvertTS( p_clock, &i_rate, pi_ts0, pi_ts1, i_ts_bound ) )
-                *pi_ts0 = 0;
+                *pi_ts0 = VLC_TS_INVALID;
         }
         else
         {
@@ -1089,7 +1065,7 @@ static void DecoderFixTs( decoder_t *p_dec, mtime_t *pi_ts0, mtime_t *pi_ts1,
         if( b_telx )
         {
             *pi_ts0 = DecoderTeletextFixTs( *pi_ts0 );
-            if( pi_ts1 && *pi_ts1 <= 0 )
+            if( pi_ts1 && *pi_ts1 <= VLC_TS_INVALID )
                 *pi_ts1 = *pi_ts0;
         }
     }
@@ -1103,7 +1079,7 @@ static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
     aout_input_t    *p_aout_input = p_owner->p_aout_input;
 
     /* */
-    if( p_audio->start_date <= 0 )
+    if( p_audio->start_date <= VLC_TS_INVALID ) // FIXME --VLC_TS_INVALID verify audio_output/*
     {
         msg_Warn( p_dec, "non-dated audio buffer received" );
         *pi_lost_sum += 1;
@@ -1126,7 +1102,7 @@ static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
             p_audio->start_date - p_owner->buffer.p_audio->start_date > DECODER_MAX_BUFFERING_AUDIO_DURATION )
         {
             p_owner->buffer.b_full = true;
-            vlc_cond_signal( &p_owner->wait );
+            vlc_cond_signal( &p_owner->wait_acknowledge );
         }
     }
 
@@ -1156,7 +1132,7 @@ static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
         }
 
         /* */
-        const bool b_dated = p_audio->start_date > 0;
+        const bool b_dated = p_audio->start_date > VLC_TS_INVALID;
         int i_rate = INPUT_RATE_DEFAULT;
 
         DecoderFixTs( p_dec, &p_audio->start_date, &p_audio->end_date, NULL,
@@ -1165,7 +1141,7 @@ static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
         vlc_mutex_unlock( &p_owner->lock );
 
         if( !p_aout || !p_aout_input ||
-            p_audio->start_date <= 0 ||
+            p_audio->start_date <= VLC_TS_INVALID ||
             i_rate < INPUT_RATE_DEFAULT/AOUT_MAX_INPUT_RATE ||
             i_rate > INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE )
             b_reject = true;
@@ -1181,7 +1157,7 @@ static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
                 vlc_mutex_unlock( &p_owner->lock );
                 break;
             }
-            vlc_cond_timedwait( &p_owner->wait, &p_owner->lock, i_deadline );
+            vlc_cond_timedwait( &p_owner->wait_request, &p_owner->lock, i_deadline );
             vlc_mutex_unlock( &p_owner->lock );
         }
 
@@ -1238,19 +1214,20 @@ static void DecoderDecodeAudio( decoder_t *p_dec, block_t *p_block )
         }
         i_decoded++;
 
-        if( p_aout_buf->start_date < p_owner->i_preroll_end )
+        if( p_owner->i_preroll_end > VLC_TS_INVALID &&
+            p_aout_buf->start_date < p_owner->i_preroll_end )
         {
             aout_DecDeleteBuffer( p_aout, p_aout_input, p_aout_buf );
             continue;
         }
 
-        if( p_owner->i_preroll_end > 0 )
+        if( p_owner->i_preroll_end > VLC_TS_INVALID )
         {
             msg_Dbg( p_dec, "End of audio preroll" );
             if( p_owner->p_aout && p_owner->p_aout_input )
                 aout_DecFlush( p_owner->p_aout, p_owner->p_aout_input );
             /* */
-            p_owner->i_preroll_end = -1;
+            p_owner->i_preroll_end = VLC_TS_INVALID;
         }
 
         DecoderPlayAudio( p_dec, p_aout_buf, &i_played, &i_lost );
@@ -1318,7 +1295,7 @@ static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
     vout_thread_t  *p_vout = p_owner->p_vout;
     bool b_first_buffered;
 
-    if( p_picture->date <= 0 )
+    if( p_picture->date <= VLC_TS_INVALID )
     {
         msg_Warn( p_vout, "non-dated video buffer received" );
         *pi_lost_sum += 1;
@@ -1341,7 +1318,7 @@ static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
             p_picture->date - p_owner->buffer.p_picture->date > DECODER_MAX_BUFFERING_VIDEO_DURATION )
         {
             p_owner->buffer.b_full = true;
-            vlc_cond_signal( &p_owner->wait );
+            vlc_cond_signal( &p_owner->wait_acknowledge );
         }
     }
     b_first_buffered = p_owner->buffer.p_picture != NULL;
@@ -1384,7 +1361,7 @@ static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
             p_picture->b_force = true;
         }
 
-        const bool b_dated = p_picture->date > 0;
+        const bool b_dated = p_picture->date > VLC_TS_INVALID;
         int i_rate = INPUT_RATE_DEFAULT;
         DecoderFixTs( p_dec, &p_picture->date, NULL, NULL,
                       &i_rate, DECODER_BOGUS_VIDEO_DELAY, false );
@@ -1392,7 +1369,7 @@ static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
         vlc_mutex_unlock( &p_owner->lock );
 
         /* */
-        if( !p_picture->b_force && p_picture->date <= 0 )
+        if( !p_picture->b_force && p_picture->date <= VLC_TS_INVALID ) // FIXME --VLC_TS_INVALID verify video_output/*
             b_reject = true;
 
         if( !b_reject )
@@ -1457,19 +1434,19 @@ static void DecoderDecodeVideo( decoder_t *p_dec, block_t *p_block )
 
         i_decoded++;
 
-        if( p_pic->date < p_owner->i_preroll_end )
+        if( p_owner->i_preroll_end > VLC_TS_INVALID && p_pic->date < p_owner->i_preroll_end )
         {
             vout_DropPicture( p_vout, p_pic );
             continue;
         }
 
-        if( p_owner->i_preroll_end > 0 )
+        if( p_owner->i_preroll_end > VLC_TS_INVALID )
         {
             msg_Dbg( p_dec, "End of video preroll" );
             if( p_vout )
-                vout_Flush( p_vout, 1 );
+                vout_Flush( p_vout, VLC_TS_INVALID+1 );
             /* */
-            p_owner->i_preroll_end = -1;
+            p_owner->i_preroll_end = VLC_TS_INVALID;
         }
 
         if( p_dec->pf_get_cc &&
@@ -1501,7 +1478,7 @@ static void DecoderPlaySpu( decoder_t *p_dec, subpicture_t *p_subpic,
     vout_thread_t *p_vout = p_owner->p_spu_vout;
 
     /* */
-    if( p_subpic->i_start <= 0 )
+    if( p_subpic->i_start <= VLC_TS_INVALID )
     {
         msg_Warn( p_dec, "non-dated spu buffer received" );
         subpicture_Delete( p_subpic );
@@ -1523,7 +1500,7 @@ static void DecoderPlaySpu( decoder_t *p_dec, subpicture_t *p_subpic,
         if( p_owner->buffer.i_count > 0 )
         {
             p_owner->buffer.b_full = true;
-            vlc_cond_signal( &p_owner->wait );
+            vlc_cond_signal( &p_owner->wait_acknowledge );
         }
     }
 
@@ -1593,7 +1570,7 @@ static void DecoderPlaySout( decoder_t *p_dec, block_t *p_sout_block,
         if( p_owner->buffer.i_count > 0 )
         {
             p_owner->buffer.b_full = true;
-            vlc_cond_signal( &p_owner->wait );
+            vlc_cond_signal( &p_owner->wait_acknowledge );
         }
     }
 
@@ -1630,7 +1607,7 @@ static void DecoderPlaySout( decoder_t *p_dec, block_t *p_sout_block,
         vlc_mutex_unlock( &p_owner->lock );
 
         if( !b_reject )
-            sout_InputSendBuffer( p_owner->p_sout_input, p_sout_block );
+            sout_InputSendBuffer( p_owner->p_sout_input, p_sout_block ); // FIXME --VLC_TS_INVALID inspect stream_output/*
         else
             block_Release( p_sout_block );
 
@@ -1704,7 +1681,7 @@ static void DecoderFlushBuffering( decoder_t *p_dec )
 static void DecoderProcessSout( decoder_t *p_dec, block_t *p_block )
 {
     decoder_owner_sys_t *p_owner = (decoder_owner_sys_t *)p_dec->p_owner;
-    const bool b_telx = p_dec->fmt_in.i_codec == VLC_FOURCC('t','e','l','x');
+    const bool b_telx = p_dec->fmt_in.i_codec == VLC_CODEC_TELETEXT;
     block_t *p_sout_block;
 
     while( ( p_sout_block =
@@ -1754,20 +1731,6 @@ static void DecoderProcessSout( decoder_t *p_dec, block_t *p_block )
 
             p_sout_block = p_next;
         }
-
-        /* For now it's enough, as only sout impact on this flag */
-        if( p_owner->p_sout->i_out_pace_nocontrol > 0 &&
-            p_owner->p_input->p->b_out_pace_control )
-        {
-            msg_Dbg( p_dec, "switching to sync mode" );
-            p_owner->p_input->p->b_out_pace_control = false;
-        }
-        else if( p_owner->p_sout->i_out_pace_nocontrol <= 0 &&
-                 !p_owner->p_input->p->b_out_pace_control )
-        {
-            msg_Dbg( p_dec, "switching to async mode" );
-            p_owner->p_input->p->b_out_pace_control = true;
-        }
     }
 }
 
@@ -1818,7 +1781,7 @@ static void DecoderProcessVideo( decoder_t *p_dec, block_t *p_block, bool b_flus
     }
 
     if( b_flush && p_owner->p_vout )
-        vout_Flush( p_owner->p_vout, 1 );
+        vout_Flush( p_owner->p_vout, VLC_TS_INVALID+1 );
 }
 
 /* This function process a audio block
@@ -1874,7 +1837,7 @@ static void DecoderProcessAudio( decoder_t *p_dec, block_t *p_block, bool b_flus
 static void DecoderProcessSpu( decoder_t *p_dec, block_t *p_block, bool b_flush )
 {
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
-    const bool b_telx = p_dec->fmt_in.i_codec == VLC_FOURCC('t','e','l','x');
+    const bool b_telx = p_dec->fmt_in.i_codec == VLC_CODEC_TELETEXT;
 
     input_thread_t *p_input = p_owner->p_input;
     vout_thread_t *p_vout;
@@ -1886,13 +1849,13 @@ static void DecoderProcessSpu( decoder_t *p_dec, block_t *p_block, bool b_flush
         stats_UpdateInteger( p_dec, p_input->p->counters.p_decoded_sub, 1, NULL );
         vlc_mutex_unlock( &p_input->p->counters.counters_lock );
 
-        p_vout = input_ressource_HoldVout( p_input->p->p_ressource );
+        p_vout = input_resource_HoldVout( p_input->p->p_resource );
         if( p_vout && p_owner->p_spu_vout == p_vout )
         {
             /* Preroll does not work very well with subtitle */
-            if( p_spu->i_start > 0 &&
+            if( p_spu->i_start > VLC_TS_INVALID &&
                 p_spu->i_start < p_owner->i_preroll_end &&
-                ( p_spu->i_stop <= 0 || p_spu->i_stop < p_owner->i_preroll_end ) )
+                ( p_spu->i_stop <= VLC_TS_INVALID || p_spu->i_stop < p_owner->i_preroll_end ) )
             {
                 subpicture_Delete( p_spu );
             }
@@ -1911,7 +1874,7 @@ static void DecoderProcessSpu( decoder_t *p_dec, block_t *p_block, bool b_flush
 
     if( b_flush && p_owner->p_spu_vout )
     {
-        p_vout = input_ressource_HoldVout( p_input->p->p_ressource );
+        p_vout = input_resource_HoldVout( p_input->p->p_resource );
 
         if( p_vout && p_owner->p_spu_vout == p_vout )
             spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR,
@@ -1929,10 +1892,15 @@ static void DecoderProcessOnFlush( decoder_t *p_dec )
 
     vlc_mutex_lock( &p_owner->lock );
     DecoderFlushBuffering( p_dec );
-    vlc_mutex_unlock( &p_owner->lock );
 
-    DecoderSignalFlushed( p_dec );
+    if( p_owner->b_flushing )
+    {
+        p_owner->b_flushing = false;
+        vlc_cond_signal( &p_owner->wait_acknowledge );
+    }
+    vlc_mutex_unlock( &p_owner->lock );
 }
+
 /**
  * Decode a block
  *
@@ -1953,7 +1921,7 @@ static void DecoderProcess( decoder_t *p_dec, block_t *p_block )
     }
 
 #ifdef ENABLE_SOUT
-    if( vlc_internals( p_dec )->i_object_type == VLC_OBJECT_PACKETIZER )
+    if( p_owner->b_packetizer )
     {
         if( p_block )
             p_block->i_flags &= ~BLOCK_FLAG_CORE_PRIVATE_MASK;
@@ -1975,15 +1943,15 @@ static void DecoderProcess( decoder_t *p_dec, block_t *p_block )
             p_block->i_flags &= ~BLOCK_FLAG_CORE_PRIVATE_MASK;
         }
 
-        if( p_dec->fmt_in.i_cat == AUDIO_ES )
+        if( p_dec->fmt_out.i_cat == AUDIO_ES )
         {
             DecoderProcessAudio( p_dec, p_block, b_flush );
         }
-        else if( p_dec->fmt_in.i_cat == VIDEO_ES )
+        else if( p_dec->fmt_out.i_cat == VIDEO_ES )
         {
             DecoderProcessVideo( p_dec, p_block, b_flush );
         }
-        else if( p_dec->fmt_in.i_cat == SPU_ES )
+        else if( p_dec->fmt_out.i_cat == SPU_ES )
         {
             DecoderProcessSpu( p_dec, p_block, b_flush );
         }
@@ -2040,7 +2008,7 @@ static void DeleteDecoder( decoder_t * p_dec )
         aout_DecDelete( p_owner->p_aout, p_owner->p_aout_input );
     if( p_owner->p_aout )
     {
-        input_ressource_RequestAout( p_owner->p_input->p->p_ressource,
+        input_resource_RequestAout( p_owner->p_input->p->p_resource,
                                      p_owner->p_aout );
         input_SendEventAout( p_owner->p_input );
         p_owner->p_aout = NULL;
@@ -2054,7 +2022,7 @@ static void DeleteDecoder( decoder_t * p_dec )
             vout_ChangePause( p_owner->p_vout, false, mdate() );
 
         /* */
-        input_ressource_RequestVout( p_owner->p_input->p->p_ressource, p_owner->p_vout, NULL, true );
+        input_resource_RequestVout( p_owner->p_input->p->p_resource, p_owner->p_vout, NULL, true );
         input_SendEventVout( p_owner->p_input );
     }
 
@@ -2066,11 +2034,11 @@ static void DeleteDecoder( decoder_t * p_dec )
     }
 #endif
 
-    if( p_dec->fmt_in.i_cat == SPU_ES )
+    if( p_dec->fmt_out.i_cat == SPU_ES )
     {
         vout_thread_t *p_vout;
 
-        p_vout = input_ressource_HoldVout( p_owner->p_input->p->p_ressource );
+        p_vout = input_resource_HoldVout( p_owner->p_input->p->p_resource );
         if( p_vout )
         {
             if( p_owner->p_spu_vout == p_vout )
@@ -2099,7 +2067,8 @@ static void DeleteDecoder( decoder_t * p_dec )
         vlc_object_release( p_owner->p_packetizer );
     }
 
-    vlc_cond_destroy( &p_owner->wait );
+    vlc_cond_destroy( &p_owner->wait_acknowledge );
+    vlc_cond_destroy( &p_owner->wait_request );
     vlc_mutex_destroy( &p_owner->lock );
 
     vlc_object_detach( p_dec );
@@ -2134,7 +2103,7 @@ static vout_thread_t *aout_request_vout( void *p_private,
     decoder_t *p_dec = p_private;
     input_thread_t *p_input = p_dec->p_owner->p_input;
 
-    p_vout = input_ressource_RequestVout( p_input->p->p_ressource, p_vout, p_fmt, b_recyle );
+    p_vout = input_resource_RequestVout( p_input->p->p_resource, p_vout, p_fmt, b_recyle );
     input_SendEventVout( p_input );
 
     return p_vout;
@@ -2198,7 +2167,7 @@ static aout_buffer_t *aout_new_buffer( decoder_t *p_dec, int i_samples )
 
         p_aout = p_owner->p_aout;
         if( !p_aout )
-            p_aout = input_ressource_RequestAout( p_owner->p_input->p->p_ressource, NULL );
+            p_aout = input_resource_RequestAout( p_owner->p_input->p->p_resource, NULL );
         p_aout_input = aout_DecNew( p_dec, &p_aout,
                                     &format, &p_dec->fmt_out.audio_replay_gain, &request_vout );
 
@@ -2312,7 +2281,7 @@ static picture_t *vout_new_buffer( decoder_t *p_dec )
         p_owner->p_vout = NULL;
         vlc_mutex_unlock( &p_owner->lock );
 
-        p_vout = input_ressource_RequestVout( p_owner->p_input->p->p_ressource,
+        p_vout = input_resource_RequestVout( p_owner->p_input->p->p_resource,
                                               p_vout, &p_dec->fmt_out.video, true );
 
         vlc_mutex_lock( &p_owner->lock );
@@ -2400,7 +2369,7 @@ static subpicture_t *spu_new_buffer( decoder_t *p_dec )
         if( p_dec->b_die || p_dec->b_error )
             break;
 
-        p_vout = input_ressource_HoldVout( p_owner->p_input->p->p_ressource );
+        p_vout = input_resource_HoldVout( p_owner->p_input->p->p_resource );
         if( p_vout )
             break;
 
@@ -2445,7 +2414,7 @@ static void spu_del_buffer( decoder_t *p_dec, subpicture_t *p_subpic )
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
     vout_thread_t *p_vout = NULL;
 
-    p_vout = input_ressource_HoldVout( p_owner->p_input->p->p_ressource );
+    p_vout = input_resource_HoldVout( p_owner->p_input->p->p_resource );
     if( !p_vout || p_owner->p_spu_vout != p_vout )
     {
         if( p_vout )