[vlc-devel] [RFC PATCH] decoder: implement pf_flush for all decoders/packetizers

Thomas Guillem thomas at gllm.fr
Fri Dec 4 20:23:06 CET 2015


For now, a lot of decoder/packetizer are also flushing on
BLOCK_FLAG_DISCONTINUITY flag. Some others are also flushing on
BLOCK_FLAG_CORRUPTED flag (omxil, videotoolbox, avcodec audio).

This patch doesn't change the current behavior. But maybe we shouldn't flush
anymore on BLOCK_FLAG_DISCONTINUITY/BLOCK_FLAG_CORRUPTED.

---
 modules/codec/a52.c              | 21 +++++++++++++++++---
 modules/codec/adpcm.c            | 14 +++++++++++++-
 modules/codec/aes3.c             | 13 ++++++++++++-
 modules/codec/araw.c             | 14 +++++++++++++-
 modules/codec/avcodec/audio.c    | 26 ++++++++++++++++++-------
 modules/codec/avcodec/video.c    | 26 ++++++++++++++++++-------
 modules/codec/cc.c               | 16 ++++++++++++++--
 modules/codec/cdg.c              | 12 ++++++++++++
 modules/codec/dts.c              | 20 +++++++++++++++++---
 modules/codec/dvbsub.c           | 14 +++++++++++++-
 modules/codec/faad.c             | 14 +++++++++++++-
 modules/codec/flac.c             | 14 +++++++++++++-
 modules/codec/fluidsynth.c       | 21 +++++++++++++-------
 modules/codec/g711.c             | 11 ++++++++++-
 modules/codec/gstdecode.c        | 41 ++++++++++++++++++++++++----------------
 modules/codec/kate.c             | 18 ++++++++++++++++++
 modules/codec/libass.c           | 14 +++++++++++++-
 modules/codec/libmpeg2.c         |  1 +
 modules/codec/lpcm.c             | 14 +++++++++++++-
 modules/codec/mpeg_audio.c       | 21 +++++++++++++++++---
 modules/codec/mpg123.c           | 14 +++++++++++++-
 modules/codec/omxil/mediacodec.c | 17 ++++++++++++++++-
 modules/codec/omxil/omxil.c      | 25 +++++++++++++++++-------
 modules/codec/opus.c             | 14 +++++++++++++-
 modules/codec/rawvideo.c         | 13 +++++++++++++
 modules/codec/schroedinger.c     | 16 ++++++++++++++--
 modules/codec/speex.c            | 14 +++++++++++++-
 modules/codec/theora.c           | 12 ++++++++++++
 modules/codec/uleaddvaudio.c     | 10 +++++++++-
 modules/codec/videotoolbox.m     | 25 ++++++++++++++++--------
 modules/codec/vorbis.c           | 14 +++++++++++++-
 modules/codec/wmafixed/wma.c     | 14 +++++++++++++-
 modules/hw/mmal/codec.c          |  7 +++----
 modules/packetizer/dirac.c       | 32 ++++++++++++++++++++++---------
 modules/packetizer/flac.c        | 12 ++++++++++--
 modules/packetizer/mlp.c         | 20 ++++++++++++++++----
 modules/packetizer/mpeg4audio.c  | 32 +++++++++++++++++++++++++++----
 37 files changed, 532 insertions(+), 104 deletions(-)

diff --git a/modules/codec/a52.c b/modules/codec/a52.c
index 7450d6b..044905b 100644
--- a/modules/codec/a52.c
+++ b/modules/codec/a52.c
@@ -90,6 +90,7 @@ struct decoder_sys_t
  * Local prototypes
  ****************************************************************************/
 static block_t *DecodeBlock  ( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 static uint8_t *GetOutBuffer ( decoder_t *, block_t ** );
 static block_t *GetAoutBuffer( decoder_t * );
@@ -144,6 +145,7 @@ static int OpenCommon( vlc_object_t *p_this, bool b_packetizer )
         p_dec->pf_packetize    = DecodeBlock;
     else
         p_dec->pf_decode_audio = DecodeBlock;
+    p_dec->pf_flush            = Flush;
     return VLC_SUCCESS;
 }
 
@@ -160,6 +162,18 @@ static int OpenPacketizer( vlc_object_t *p_this )
     return OpenCommon( p_this, true );
 }
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, 0 );
+    p_sys->i_state = STATE_NOSYNC;
+    block_BytestreamEmpty( &p_sys->bytestream );
+}
+
 /****************************************************************************
  * DecodeBlock: the whole thing
  ****************************************************************************
@@ -176,15 +190,16 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
     if( (*pp_block)->i_flags & (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED) )
     {
-        date_Set( &p_sys->end_date, 0 );
         if( (*pp_block)->i_flags & BLOCK_FLAG_CORRUPTED )
         {
-            p_sys->i_state = STATE_NOSYNC;
-            block_BytestreamEmpty( &p_sys->bytestream );
+            Flush( p_dec );
             block_Release( *pp_block );
             *pp_block = NULL;
             return NULL;
         }
+        else /* BLOCK_FLAG_DISCONTINUITY */
+            date_Set( &p_sys->end_date, 0 );
+
     }
 
     if( !date_Get( &p_sys->end_date ) && (*pp_block)->i_pts <= VLC_TS_INVALID)
diff --git a/modules/codec/adpcm.c b/modules/codec/adpcm.c
index fd72308..2c74185 100644
--- a/modules/codec/adpcm.c
+++ b/modules/codec/adpcm.c
@@ -42,6 +42,7 @@ static int  OpenDecoder( vlc_object_t * );
 static void CloseDecoder( vlc_object_t * );
 
 static block_t *DecodeBlock( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 vlc_module_begin ()
     set_description( N_("ADPCM audio decoder") )
@@ -261,11 +262,22 @@ static int OpenDecoder( vlc_object_t *p_this )
     date_Set( &p_sys->end_date, 0 );
 
     p_dec->pf_decode_audio = DecodeBlock;
+    p_dec->pf_flush        = Flush;
 
     return VLC_SUCCESS;
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, 0 );
+}
+
+/*****************************************************************************
  * DecodeBlock:
  *****************************************************************************/
 static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
@@ -285,7 +297,7 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     }
 
     if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
-        date_Set( &p_sys->end_date, 0 );
+        Flush( p_dec );
 
     if( p_block->i_pts > VLC_TS_INVALID &&
         p_block->i_pts != date_Get( &p_sys->end_date ) )
diff --git a/modules/codec/aes3.c b/modules/codec/aes3.c
index e6a8795..48278ea 100644
--- a/modules/codec/aes3.c
+++ b/modules/codec/aes3.c
@@ -218,6 +218,16 @@ exit:
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, 0 );
+}
+
+/*****************************************************************************
  * Packetize: packetizes an aes3 frame.
  ****************************************************************************
  * Beware, this function must be fed with complete frames (PES packet).
@@ -279,6 +289,7 @@ static int Open( decoder_t *p_dec, bool b_packetizer )
         p_dec->pf_decode_audio = Decode;
         p_dec->pf_packetize    = NULL;
     }
+    p_dec->pf_flush            = Flush;
     return VLC_SUCCESS;
 }
 
@@ -317,7 +328,7 @@ static block_t *Parse( decoder_t *p_dec, int *pi_frame_length, int *pi_bits,
     }
 
     if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
-        date_Set( &p_sys->end_date, 0 );
+        Flush( p_dec );
 
     /* Date management */
     if( p_block->i_pts > VLC_TS_INVALID &&
diff --git a/modules/codec/araw.c b/modules/codec/araw.c
index 85cec83..7b076e6 100644
--- a/modules/codec/araw.c
+++ b/modules/codec/araw.c
@@ -67,6 +67,7 @@ vlc_module_end ()
  * Local prototypes
  *****************************************************************************/
 static block_t *DecodeBlock( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 struct decoder_sys_t
 {
@@ -293,11 +294,22 @@ static int DecoderOpen( vlc_object_t *p_this )
     date_Set( &p_sys->end_date, 0 );
 
     p_dec->pf_decode_audio = DecodeBlock;
+    p_dec->pf_flush        = Flush;
     p_dec->p_sys = p_sys;
 
     return VLC_SUCCESS;
 }
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, 0 );
+}
+
 /****************************************************************************
  * DecodeBlock: the whole thing
  ****************************************************************************
@@ -318,7 +330,7 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         goto skip;
 
     if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
-        date_Set( &p_sys->end_date, 0 );
+        Flush( p_dec );
 
     if( p_block->i_pts > VLC_TS_INVALID &&
         p_block->i_pts != date_Get( &p_sys->end_date ) )
diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index 2a5b5de..159dbf1 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -71,6 +71,7 @@ struct decoder_sys_t
 
 static void SetupOutputFormat( decoder_t *p_dec, bool b_trust );
 static block_t *DecodeAudio( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 static void InitDecoderConfig( decoder_t *p_dec, AVCodecContext *p_context )
 {
@@ -235,10 +236,27 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
         date_Init( &p_sys->end_date, p_dec->fmt_in.audio.i_rate, 1 );
 
     p_dec->pf_decode_audio = DecodeAudio;
+    p_dec->pf_flush        = Flush;
     return VLC_SUCCESS;
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+    AVCodecContext *ctx = p_sys->p_context;
+
+    avcodec_flush_buffers( ctx );
+    date_Set( &p_sys->end_date, VLC_TS_INVALID );
+
+    if( ctx->codec_id == AV_CODEC_ID_MP2 ||
+        ctx->codec_id == AV_CODEC_ID_MP3 )
+        p_sys->i_reject_count = 3;
+}
+
+/*****************************************************************************
  * DecodeAudio: Called to decode one frame
  *****************************************************************************/
 static block_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
@@ -263,13 +281,7 @@ static block_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
 
     if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
     {
-        avcodec_flush_buffers( ctx );
-        date_Set( &p_sys->end_date, VLC_TS_INVALID );
-
-        if( ctx->codec_id == AV_CODEC_ID_MP2 ||
-            ctx->codec_id == AV_CODEC_ID_MP3 )
-            p_sys->i_reject_count = 3;
-
+        Flush( p_dec );
         goto end;
     }
 
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 69d6f6e..0666166 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -107,6 +107,7 @@ static int lavc_GetFrame(struct AVCodecContext *, AVFrame *, int);
 static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *,
                                           const enum PixelFormat * );
 static picture_t *DecodeVideo( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 static uint32_t ffmpeg_CodecTag( vlc_fourcc_t fcc )
 {
@@ -490,11 +491,29 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
     }
 
     p_dec->pf_decode_video = DecodeVideo;
+    p_dec->pf_flush        = Flush;
+    p_dec->pf_flush        = Flush;
 
     return VLC_SUCCESS;
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    p_sys->i_pts = VLC_TS_INVALID; /* To make sure we recover properly */
+    p_sys->i_late_frames = 0;
+#if 0
+    post_mt( p_sys );
+    avcodec_flush_buffers( p_context );
+    wait_mt( p_sys );
+#endif
+}
+
+/*****************************************************************************
  * DecodeVideo: Called to decode one or more frames
  *****************************************************************************/
 static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
@@ -532,13 +551,6 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
             p_sys->i_pts = VLC_TS_INVALID; /* To make sure we recover properly */
 
             p_sys->i_late_frames = 0;
-#if 0
-            /* NOTE: data is good only the timeline changed so do not flush decoder */
-            post_mt( p_sys );
-            if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
-                avcodec_flush_buffers( p_context );
-            wait_mt( p_sys );
-#endif
             if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
             {
                 block_Release( p_block );
diff --git a/modules/codec/cc.c b/modules/codec/cc.c
index e3cb87b..006015e 100644
--- a/modules/codec/cc.c
+++ b/modules/codec/cc.c
@@ -226,6 +226,7 @@ struct decoder_sys_t
 };
 
 static subpicture_t *Decode( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 /*****************************************************************************
  * Open: probe the decoder and return score
@@ -260,6 +261,7 @@ static int Open( vlc_object_t *p_this )
     }
 
     p_dec->pf_decode_sub = Decode;
+    p_dec->pf_flush      = Flush;
 
     /* Allocate the memory needed to store the decoder's structure */
     p_dec->p_sys = p_sys = calloc( 1, sizeof( *p_sys ) );
@@ -279,6 +281,17 @@ static int Open( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    Eia608Init( &p_sys->eia608 );
+    p_sys->i_display_time = VLC_TS_INVALID;
+}
+
 /****************************************************************************
  * Decode: the whole thing
  ****************************************************************************
@@ -307,8 +320,7 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
         if( p_sys->p_block &&
            (p_sys->p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED)) )
         {
-            Eia608Init( &p_sys->eia608 );
-            p_sys->i_display_time = VLC_TS_INVALID;
+            Flush( p_dec );
             /* clear flags, as we might process it more than once */
             p_sys->p_block->i_flags ^= (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED);
             continue;
diff --git a/modules/codec/cdg.c b/modules/codec/cdg.c
index 763ba1a..f590efc 100644
--- a/modules/codec/cdg.c
+++ b/modules/codec/cdg.c
@@ -76,6 +76,7 @@ static void Close( vlc_object_t * );
 static picture_t *Decode( decoder_t *, block_t ** );
 
 static int DecodePacket( decoder_sys_t *p_cdg, uint8_t *p_buffer, int i_buffer );
+static void Flush( decoder_t * );
 static int Render( decoder_sys_t *p_cdg, picture_t *p_picture );
 
 /*****************************************************************************
@@ -124,10 +125,21 @@ static int Open( vlc_object_t *p_this )
 
     /* Set callbacks */
     p_dec->pf_decode_video = Decode;
+    p_dec->pf_flush        = Flush;
 
     return VLC_SUCCESS;
 }
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    p_sys->i_packet = 0;
+}
+
 /****************************************************************************
  * Decode: the whole thing
  ****************************************************************************
diff --git a/modules/codec/dts.c b/modules/codec/dts.c
index b90eba3..ff0849d 100644
--- a/modules/codec/dts.c
+++ b/modules/codec/dts.c
@@ -97,6 +97,7 @@ struct decoder_sys_t
  ****************************************************************************/
 static int OpenCommon( vlc_object_t *, bool b_packetizer );
 static block_t *DecodeBlock( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 static int  SyncInfo( const uint8_t *, bool *, unsigned int *, unsigned int *,
                       unsigned int *, unsigned int *, unsigned int * );
@@ -157,10 +158,23 @@ static int OpenCommon( vlc_object_t *p_this, bool b_packetizer )
     /* Set callback */
     p_dec->pf_decode_audio = DecodeBlock;
     p_dec->pf_packetize    = DecodeBlock;
+    p_dec->pf_flush        = Flush;
 
     return VLC_SUCCESS;
 }
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, 0 );
+    p_sys->i_state = STATE_NOSYNC;
+    block_BytestreamEmpty( &p_sys->bytestream );
+}
+
 /****************************************************************************
  * DecodeBlock: the whole thing
  ****************************************************************************/
@@ -176,15 +190,15 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
     if( (*pp_block)->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
     {
-        date_Set( &p_sys->end_date, 0 );
         if( (*pp_block)->i_flags & BLOCK_FLAG_CORRUPTED )
         {
-            p_sys->i_state = STATE_NOSYNC;
-            block_BytestreamEmpty( &p_sys->bytestream );
+            Flush( p_dec );
             block_Release( *pp_block );
             *pp_block = NULL;
             return NULL;
         }
+        else /* BLOCK_FLAG_DISCONTINUITY */
+            date_Set( &p_sys->end_date, 0 );
     }
 
     if( !date_Get( &p_sys->end_date ) && (*pp_block)->i_pts <= VLC_TS_INVALID )
diff --git a/modules/codec/dvbsub.c b/modules/codec/dvbsub.c
index e73c9d5..0ab0956 100644
--- a/modules/codec/dvbsub.c
+++ b/modules/codec/dvbsub.c
@@ -108,6 +108,7 @@ static const char *const ppsz_pos_descriptions[] =
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 static subpicture_t *Decode( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 #ifdef ENABLE_SOUT
 static int OpenEncoder  ( vlc_object_t * );
@@ -334,6 +335,7 @@ static int Open( vlc_object_t *p_this )
     }
 
     p_dec->pf_decode_sub = Decode;
+    p_dec->pf_flush      = Flush;
     p_sys = p_dec->p_sys = calloc( 1, sizeof(decoder_sys_t) );
     if( !p_sys )
         return VLC_ENOMEM;
@@ -390,6 +392,16 @@ static void Close( vlc_object_t *p_this )
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    p_sys->i_pts = VLC_TS_INVALID;
+}
+
+/*****************************************************************************
  * Decode:
  *****************************************************************************/
 static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
@@ -404,7 +416,7 @@ static subpicture_t *Decode( decoder_t *p_dec, block_t **pp_block )
 
     if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED) )
     {
-        p_sys->i_pts = VLC_TS_INVALID;
+        Flush( p_dec );
         if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
         {
             block_Release( p_block );
diff --git a/modules/codec/faad.c b/modules/codec/faad.c
index bf05018..f246f25 100644
--- a/modules/codec/faad.c
+++ b/modules/codec/faad.c
@@ -60,6 +60,7 @@ vlc_module_end ()
  * Local prototypes
  ****************************************************************************/
 static block_t *DecodeBlock( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 static void DoReordering( uint32_t *, uint32_t *, int, int, uint32_t * );
 
 #define MAX_CHANNEL_POSITIONS 9
@@ -195,10 +196,21 @@ static int Open( vlc_object_t *p_this )
     p_sys->b_sbr = p_sys->b_ps = false;
 
     p_dec->pf_decode_audio = DecodeBlock;
+    p_dec->pf_flush        = Flush;
     return VLC_SUCCESS;
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->date, 0 );
+}
+
+/*****************************************************************************
  * DecodeBlock:
  *****************************************************************************/
 static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
@@ -213,7 +225,7 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
     if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED) )
     {
-        date_Set( &p_sys->date, 0 );
+        Flush( p_dec );
         if( p_block->i_flags & (BLOCK_FLAG_CORRUPTED) )
         {
             block_Release( p_block );
diff --git a/modules/codec/flac.c b/modules/codec/flac.c
index 9a7d1d1..deb8dde 100644
--- a/modules/codec/flac.c
+++ b/modules/codec/flac.c
@@ -103,6 +103,7 @@ static void CloseEncoder ( vlc_object_t * );
 #endif
 
 static block_t *DecodeBlock( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 /*****************************************************************************
  * Module descriptor
@@ -358,6 +359,7 @@ static int OpenDecoder( vlc_object_t *p_this )
 
     /* Set callbacks */
     p_dec->pf_decode_audio = DecodeBlock;
+    p_dec->pf_flush        = Flush;
 
     return VLC_SUCCESS;
 }
@@ -491,6 +493,16 @@ static void decoder_state_error( decoder_t *p_dec,
     }
 }
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, 0 );
+}
+
 /****************************************************************************
  * DecodeBlock: the whole thing
  ****************************************************************************/
@@ -502,7 +514,7 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     if( (*pp_block)->i_flags & (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED) )
     {
-        date_Set( &p_sys->end_date, 0 );
+        Flush( p_dec );
         if( (*pp_block)->i_flags & BLOCK_FLAG_CORRUPTED )
         {
             block_Release( *pp_block );
diff --git a/modules/codec/fluidsynth.c b/modules/codec/fluidsynth.c
index 65cb208..3730c10 100644
--- a/modules/codec/fluidsynth.c
+++ b/modules/codec/fluidsynth.c
@@ -94,7 +94,7 @@ struct decoder_sys_t
 
 
 static block_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block);
-
+static void Flush (decoder_t *);
 
 static int Open (vlc_object_t *p_this)
 {
@@ -178,6 +178,7 @@ static int Open (vlc_object_t *p_this)
 
     p_dec->p_sys = p_sys;
     p_dec->pf_decode_audio = DecodeBlock;
+    p_dec->pf_flush        = Flush;
     return VLC_SUCCESS;
 }
 
@@ -192,6 +193,17 @@ static void Close (vlc_object_t *p_this)
     free (p_sys);
 }
 
+static void Flush (decoder_t *p_dec)
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set (&p_sys->end_date, VLC_TS_INVALID);
+    //fluid_synth_system_reset (p_sys->synth);
+    fluid_synth_program_reset (p_sys->synth);
+    for (unsigned channel = 0; channel < 16; channel++)
+        for (unsigned note = 0; note < 128; note++)
+            fluid_synth_noteoff (p_sys->synth, channel, note);
+}
 
 static block_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block)
 {
@@ -208,12 +220,7 @@ static block_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block)
 
     if (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED))
     {
-        date_Set (&p_sys->end_date, VLC_TS_INVALID);
-        //fluid_synth_system_reset (p_sys->synth);
-        fluid_synth_program_reset (p_sys->synth);
-        for (unsigned channel = 0; channel < 16; channel++)
-            for (unsigned note = 0; note < 128; note++)
-                fluid_synth_noteoff (p_sys->synth, channel, note);
+        Flush (p_dec);
         if (p_block->i_flags & BLOCK_FLAG_CORRUPTED)
         {
             block_Release(p_block);
diff --git a/modules/codec/g711.c b/modules/codec/g711.c
index 119c36a..0ac5fcc 100644
--- a/modules/codec/g711.c
+++ b/modules/codec/g711.c
@@ -35,6 +35,7 @@
 static int  DecoderOpen ( vlc_object_t * );
 static void DecoderClose( vlc_object_t * );
 static block_t *DecodeBlock( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 #ifdef ENABLE_SOUT
 static int  EncoderOpen ( vlc_object_t * );
@@ -184,6 +185,7 @@ static int DecoderOpen( vlc_object_t *p_this )
 
     /* Set output properties */
     p_dec->pf_decode_audio = DecodeBlock;
+    p_dec->pf_flush        = Flush;
     p_dec->p_sys = p_sys;
 
     p_dec->fmt_out.i_cat = AUDIO_ES;
@@ -212,6 +214,13 @@ static int DecoderOpen( vlc_object_t *p_this )
     return VLC_SUCCESS;
 }
 
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, 0 );
+}
+
 static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
@@ -230,7 +239,7 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     }
 
     if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
-        date_Set( &p_sys->end_date, 0 );
+        Flush( p_dec );
 
     if( p_block->i_pts > VLC_TS_INVALID &&
         p_block->i_pts != date_Get( &p_sys->end_date ) )
diff --git a/modules/codec/gstdecode.c b/modules/codec/gstdecode.c
index 7615b45..0f65ec3 100644
--- a/modules/codec/gstdecode.c
+++ b/modules/codec/gstdecode.c
@@ -65,6 +65,7 @@ typedef struct
 static int  OpenDecoder( vlc_object_t* );
 static void CloseDecoder( vlc_object_t* );
 static picture_t *DecodeBlock( decoder_t*, block_t** );
+static void Flush( decoder_t * );
 
 #define MODULE_DESCRIPTION N_( "Uses GStreamer framework's plugins " \
         "to decode the media codecs" )
@@ -626,6 +627,7 @@ static int OpenDecoder( vlc_object_t *p_this )
 
     /* Set callbacks */
     p_dec->pf_decode_video = DecodeBlock;
+    p_dec->pf_flush        = Flush;
 
     return VLC_SUCCESS;
 
@@ -640,6 +642,28 @@ fail:
     return i_rval;
 }
 
+/* Flush */
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+    GstBuffer *p_buffer;
+    gboolean b_ret;
+
+    /* Send a new segment event. Seeking position is
+     * irrelevant in this case, as the main motive for a
+     * seek here, is to tell the elements to start flushing
+     * and start accepting buffers from a new time segment */
+    b_ret = gst_element_seek_simple( p_sys->p_decoder,
+            GST_FORMAT_BYTES, GST_SEEK_FLAG_FLUSH, 0 );
+    msg_Dbg( p_dec, "new segment event : %d", b_ret );
+
+    /* flush the output buffers from the queue */
+    while( ( p_buffer = gst_atomic_queue_pop( p_sys->p_que ) ) )
+        gst_buffer_unref( p_buffer );
+
+    p_sys->b_prerolled = false;
+}
+
 /* Decode */
 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 {
@@ -662,22 +686,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                     BLOCK_FLAG_CORRUPTED ) ) )
     {
         if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
-        {
-            GstBuffer *p_buffer;
-            /* Send a new segment event. Seeking position is
-             * irrelevant in this case, as the main motive for a
-             * seek here, is to tell the elements to start flushing
-             * and start accepting buffers from a new time segment */
-            b_ret = gst_element_seek_simple( p_sys->p_decoder,
-                    GST_FORMAT_BYTES, GST_SEEK_FLAG_FLUSH, 0 );
-            msg_Dbg( p_dec, "new segment event : %d", b_ret );
-
-            /* flush the output buffers from the queue */
-            while( ( p_buffer = gst_atomic_queue_pop( p_sys->p_que ) ) )
-                gst_buffer_unref( p_buffer );
-
-            p_sys->b_prerolled = false;
-        }
+            Flush( p_dec );
 
         if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
         {
diff --git a/modules/codec/kate.c b/modules/codec/kate.c
index b427662..f0c2b27 100644
--- a/modules/codec/kate.c
+++ b/modules/codec/kate.c
@@ -157,6 +157,7 @@ static int OpenPacketizer( vlc_object_t *p_this );
 #endif
 
 static subpicture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block );
+static void Flush( decoder_t * );
 static int ProcessHeaders( decoder_t *p_dec );
 static subpicture_t *ProcessPacket( decoder_t *p_dec, kate_packet *p_kp,
                             block_t **pp_block );
@@ -354,6 +355,7 @@ static int OpenDecoder( vlc_object_t *p_this )
         DecodeBlock;
     p_dec->pf_packetize    = (block_t *(*)(decoder_t *, block_t **))
         DecodeBlock;
+    p_dec->pf_flush        = Flush;
 
     /* Allocate the memory needed to store the decoder's structure */
     if( ( p_dec->p_sys = p_sys = malloc(sizeof(*p_sys)) ) == NULL )
@@ -453,6 +455,22 @@ static int OpenPacketizer( vlc_object_t *p_this )
 }
 #endif
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+#ifdef HAVE_TIGER
+    /* Hmm, should we wait before flushing the renderer ? I think not, but not certain... */
+    vlc_mutex_lock( &p_sys->lock );
+    tiger_renderer_seek( p_sys->p_tr, 0 );
+    vlc_mutex_unlock( &p_sys->lock );
+#endif
+    p_sys->i_max_stop = VLC_TS_INVALID;
+}
+
 /****************************************************************************
  * DecodeBlock: the whole thing
  ****************************************************************************
diff --git a/modules/codec/libass.c b/modules/codec/libass.c
index 9c6a80c..77240e7 100644
--- a/modules/codec/libass.c
+++ b/modules/codec/libass.c
@@ -65,6 +65,7 @@ vlc_module_end ()
  * Local prototypes
  *****************************************************************************/
 static subpicture_t *DecodeBlock( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 /* */
 struct decoder_sys_t
@@ -132,6 +133,7 @@ static int Create( vlc_object_t *p_this )
         return VLC_EGENERIC;
 
     p_dec->pf_decode_sub = DecodeBlock;
+    p_dec->pf_flush      = Flush;
 
     p_dec->p_sys = p_sys = malloc( sizeof( decoder_sys_t ) );
     if( !p_sys )
@@ -295,6 +297,16 @@ static void DecSysRelease( decoder_sys_t *p_sys )
     free( p_sys );
 }
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    p_sys->i_max_stop = VLC_TS_INVALID;
+}
+
 /****************************************************************************
  * DecodeBlock:
  ****************************************************************************/
@@ -313,7 +325,7 @@ static subpicture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
     if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
     {
-        p_sys->i_max_stop = VLC_TS_INVALID;
+        Flush( p_dec );
         block_Release( p_block );
         return NULL;
     }
diff --git a/modules/codec/libmpeg2.c b/modules/codec/libmpeg2.c
index 85c4b6f..598e10f 100644
--- a/modules/codec/libmpeg2.c
+++ b/modules/codec/libmpeg2.c
@@ -241,6 +241,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_sys->p_info = mpeg2_info( p_sys->p_mpeg2dec );
 
     p_dec->pf_decode_video = DecodeBlock;
+    p_dec->pf_flush        = Reset;
     p_dec->fmt_out.i_cat = VIDEO_ES;
     p_dec->fmt_out.i_codec = 0;
 
diff --git a/modules/codec/lpcm.c b/modules/codec/lpcm.c
index 0c0ba35..a380252 100644
--- a/modules/codec/lpcm.c
+++ b/modules/codec/lpcm.c
@@ -179,6 +179,7 @@ typedef struct
  * Local prototypes
  *****************************************************************************/
 static block_t *DecodeFrame  ( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 /* */
 static int VobHeader( unsigned *pi_rate,
@@ -298,6 +299,7 @@ static int OpenCommon( vlc_object_t *p_this, bool b_packetizer )
     /* Set callback */
     p_dec->pf_decode_audio = DecodeFrame;
     p_dec->pf_packetize    = DecodeFrame;
+    p_dec->pf_flush        = Flush;
 
     return VLC_SUCCESS;
 }
@@ -311,6 +313,16 @@ static int OpenPacketizer( vlc_object_t *p_this )
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, 0 );
+}
+
+/*****************************************************************************
  * DecodeFrame: decodes an lpcm frame.
  ****************************************************************************
  * Beware, this function must be fed with complete frames (PES packet).
@@ -328,7 +340,7 @@ static block_t *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
     *pp_block = NULL; /* So the packet doesn't get re-sent */
 
     if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
-        date_Set( &p_sys->end_date, 0 );
+        Flush( p_dec );
 
     if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
     {
diff --git a/modules/codec/mpeg_audio.c b/modules/codec/mpeg_audio.c
index 12aa704..9cb4f4f 100644
--- a/modules/codec/mpeg_audio.c
+++ b/modules/codec/mpeg_audio.c
@@ -91,6 +91,7 @@ static block_t *GetAoutBuffer( decoder_t * );
 #endif
 static int  Open( vlc_object_t * );
 static block_t *DecodeBlock  ( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 static uint8_t *GetOutBuffer ( decoder_t *, block_t ** );
 static block_t *GetSoutBuffer( decoder_t * );
 static void Close(  vlc_object_t * );
@@ -160,6 +161,7 @@ static int Open( vlc_object_t *p_this )
     /* Set callback */
     p_dec->pf_decode_audio = DecodeBlock;
     p_dec->pf_packetize    = DecodeBlock;
+    p_dec->pf_flush        = Flush;
 
     /* Start with the minimum size for a free bitrate frame */
     p_sys->i_free_frame_size = MPGA_HEADER_SIZE;
@@ -185,6 +187,19 @@ static int OpenDecoder( vlc_object_t *p_this )
 }
 #endif
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, 0 );
+    p_sys->i_state = STATE_NOSYNC;
+    block_BytestreamEmpty( &p_sys->bytestream );
+    p_sys->b_discontinuity = true;
+}
+
 /****************************************************************************
  * DecodeBlock: the whole thing
  ****************************************************************************
@@ -204,15 +219,15 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     {
         if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
         {
-            date_Set( &p_sys->end_date, 0 );
             if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
             {
-                p_sys->i_state = STATE_NOSYNC;
-                block_BytestreamEmpty( &p_sys->bytestream );
+                Flush( p_dec );
                 block_Release( p_block );
                 *pp_block = NULL;
                 return NULL;
             }
+            else /* BLOCK_FLAG_DISCONTINUITY */
+                date_Set( &p_sys->end_date, 0 );
             p_sys->b_discontinuity = true;
         }
 
diff --git a/modules/codec/mpg123.c b/modules/codec/mpg123.c
index a7e1ffe..8daae72 100644
--- a/modules/codec/mpg123.c
+++ b/modules/codec/mpg123.c
@@ -42,6 +42,7 @@
 static int      OpenDecoder( vlc_object_t * );
 static void     CloseDecoder( vlc_object_t * );
 static block_t *DecodeBlock( decoder_t *, block_t ** );
+static void     Flush( decoder_t * );
 static int      InitMPG123( void );
 static void     ExitMPG123( void );
 
@@ -71,6 +72,16 @@ vlc_module_begin ()
     set_callbacks( OpenDecoder, CloseDecoder )
 vlc_module_end ()
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, 0 );
+}
+
 /****************************************************************************
  * DecodeBlock: the whole thing
  ****************************************************************************/
@@ -95,7 +106,7 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
     if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED) )
     {
-        date_Set( &p_sys->end_date, 0 );
+        Flush( p_dec );
         if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
             goto error;
     }
@@ -260,6 +271,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_dec->fmt_out.audio.i_rate = 0; /* So end_date gets initialized */
     p_dec->fmt_out.audio.i_format = p_dec->fmt_out.i_codec;
     p_dec->pf_decode_audio = DecodeBlock;
+    p_dec->pf_flush        = Flush;
 
     msg_Dbg( p_this, "%4.4s->%4.4s, bits per sample: %i",
              (char *)&p_dec->fmt_in.i_codec,
diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index 2c44e53..b73d329 100644
--- a/modules/codec/omxil/mediacodec.c
+++ b/modules/codec/omxil/mediacodec.c
@@ -144,6 +144,7 @@ static int Audio_OnNewBlock(decoder_t *, block_t *, int *);
 static void Audio_OnFlush(decoder_t *);
 static int Audio_ProcessOutput(decoder_t *, mc_api_out *, picture_t **, block_t **);
 static block_t *DecodeAudio(decoder_t *, block_t **);
+static void Flush( decoder_t * );
 
 static void InvalidateAllPictures(decoder_t *);
 static void RemoveInflightPictures(decoder_t *);
@@ -553,6 +554,7 @@ static int OpenDecoder(vlc_object_t *p_this, pf_MediaCodecApi_init pf_init)
 
     p_dec->pf_decode_video = DecodeVideo;
     p_dec->pf_decode_audio = DecodeAudio;
+    p_dec->pf_flush        = Flush;
 
     p_dec->fmt_out.i_cat = p_dec->fmt_in.i_cat;
     p_dec->fmt_out.video = p_dec->fmt_in.video;
@@ -1026,6 +1028,18 @@ static int DecodeFlush(decoder_t *p_dec)
     return VLC_SUCCESS;
 }
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush(decoder_t *p_dec)
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    if (DecodeFlush(p_dec) != VLC_SUCCESS)
+        p_sys->error_state = true;
+    /* TODO: inline with DecodeFlush when async */
+}
+
 static int GetAndProcessOutput(decoder_t *p_dec, picture_t **pp_out_pic,
                                block_t **pp_out_block, mtime_t i_timeout)
 {
@@ -1080,7 +1094,8 @@ static int DecodeCommon(decoder_t *p_dec, block_t **pp_block,
         {
             if (DecodeFlush(p_dec) != VLC_SUCCESS)
                 b_error = true;
-            goto endclean;
+            if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
+                goto endclean;
         }
 
         i_ret = p_sys->pf_on_new_block(p_dec, p_block, &i_flags);
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index 2d04583..4ec30a8 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -80,6 +80,7 @@ static void CloseGeneric( vlc_object_t * );
 static picture_t *DecodeVideo( decoder_t *, block_t ** );
 static block_t *DecodeAudio ( decoder_t *, block_t ** );
 static block_t *EncodeVideo( encoder_t *, picture_t * );
+static void Flush( decoder_t * );
 
 static OMX_ERRORTYPE OmxEventHandler( OMX_HANDLETYPE, OMX_PTR, OMX_EVENTTYPE,
                                       OMX_U32, OMX_U32, OMX_PTR );
@@ -1020,6 +1021,7 @@ static int OpenDecoder( vlc_object_t *p_this )
 
     p_dec->pf_decode_video = DecodeVideo;
     p_dec->pf_decode_audio = DecodeAudio;
+    p_dec->pf_flush        = Flush;
 
     return VLC_SUCCESS;
 }
@@ -1516,6 +1518,21 @@ static int DecodeVideoInput( decoder_t *p_dec, OmxPort *p_port, block_t **pp_blo
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    if(!p_sys->in.b_flushed)
+    {
+        msg_Dbg(p_dec, "flushing");
+        OMX_SendCommand( p_sys->omx_handle, OMX_CommandFlush,
+                         p_sys->in.definition.nPortIndex, 0 );
+    }
+    p_sys->in.b_flushed = true;
+}
+/*****************************************************************************
  * DecodeVideo: Called to decode one frame
  *****************************************************************************/
 static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
@@ -1542,13 +1559,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
     if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
     {
         block_Release( p_block );
-        if(!p_sys->in.b_flushed)
-        {
-            msg_Dbg(p_dec, "flushing");
-            OMX_SendCommand( p_sys->omx_handle, OMX_CommandFlush,
-                             p_sys->in.definition.nPortIndex, 0 );
-        }
-        p_sys->in.b_flushed = true;
+        Flush( p_dec );
         return NULL;
     }
 
diff --git a/modules/codec/opus.c b/modules/codec/opus.c
index 044ce0d..8c055ab 100644
--- a/modules/codec/opus.c
+++ b/modules/codec/opus.c
@@ -155,6 +155,7 @@ static const uint32_t pi_3channels_in[] =
  ****************************************************************************/
 
 static block_t *DecodeBlock  ( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 static int  ProcessHeaders( decoder_t * );
 static int  ProcessInitialHeader ( decoder_t *, ogg_packet * );
 static void *ProcessPacket( decoder_t *, ogg_packet *, block_t ** );
@@ -185,6 +186,7 @@ static int OpenDecoder( vlc_object_t *p_this )
 
     p_dec->pf_decode_audio = DecodeBlock;
     p_dec->pf_packetize    = DecodeBlock;
+    p_dec->pf_flush        = Flush;
 
     p_sys->p_st = NULL;
 
@@ -360,6 +362,16 @@ static int ProcessInitialHeader( decoder_t *p_dec, ogg_packet *p_oggpacket )
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, 0 );
+}
+
+/*****************************************************************************
  * ProcessPacket: processes a Opus packet.
  *****************************************************************************/
 static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
@@ -379,7 +391,7 @@ static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
     }
 
     if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
-        date_Set( &p_sys->end_date, 0 );
+        Flush( p_dec );
 
     /* Date management */
     if( p_block->i_pts > VLC_TS_INVALID &&
diff --git a/modules/codec/rawvideo.c b/modules/codec/rawvideo.c
index 1abd66f..eb0f8a9 100644
--- a/modules/codec/rawvideo.c
+++ b/modules/codec/rawvideo.c
@@ -129,6 +129,16 @@ static int OpenCommon( decoder_t *p_dec )
     return VLC_SUCCESS;
 }
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->pts, VLC_TS_INVALID );
+}
+
 /****************************************************************************
  * DecodeBlock: the whole thing
  ****************************************************************************
@@ -252,7 +262,10 @@ static int OpenDecoder( vlc_object_t *p_this )
 
     int ret = OpenCommon( p_dec );
     if( ret == VLC_SUCCESS )
+    {
         p_dec->pf_decode_video = DecodeFrame;
+        p_dec->pf_flush        = Flush;
+    }
     return ret;
 }
 
diff --git a/modules/codec/schroedinger.c b/modules/codec/schroedinger.c
index cf0932b..44afbf0 100644
--- a/modules/codec/schroedinger.c
+++ b/modules/codec/schroedinger.c
@@ -525,6 +525,7 @@ vlc_module_end ()
  * Local prototypes
  *****************************************************************************/
 static picture_t *DecodeBlock  ( decoder_t *p_dec, block_t **pp_block );
+static void Flush( decoder_t * );
 
 struct picture_free_t
 {
@@ -588,6 +589,7 @@ static int OpenDecoder( vlc_object_t *p_this )
 
     /* Set callbacks */
     p_dec->pf_decode_video = DecodeBlock;
+    p_dec->pf_flush        = Flush;
 
     return VLC_SUCCESS;
 }
@@ -738,6 +740,17 @@ static void CloseDecoder( vlc_object_t *p_this )
     free( p_sys );
 }
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    schro_decoder_reset( p_sys->p_schro );
+    p_sys->i_lastpts = VLC_TS_INVALID;
+}
+
 /****************************************************************************
  * DecodeBlock: the whole thing
  ****************************************************************************
@@ -761,9 +774,8 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         /* reset the decoder when seeking as the decode in progress is invalid */
         /* discard the block as it is just a null magic block */
         if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED) ) {
-            schro_decoder_reset( p_sys->p_schro );
+            Flush( p_dec );
 
-            p_sys->i_lastpts = VLC_TS_INVALID;
             block_Release( p_block );
             *pp_block = NULL;
             return NULL;
diff --git a/modules/codec/speex.c b/modules/codec/speex.c
index 2d35527..d985e1d 100644
--- a/modules/codec/speex.c
+++ b/modules/codec/speex.c
@@ -194,6 +194,7 @@ static block_t *DecodeRtpSpeexPacket( decoder_t *, block_t **);
 static int  ProcessHeaders( decoder_t * );
 static int  ProcessInitialHeader ( decoder_t *, ogg_packet * );
 static void *ProcessPacket( decoder_t *, ogg_packet *, block_t ** );
+static void Flush( decoder_t * );
 
 static block_t *DecodePacket( decoder_t *, ogg_packet * );
 static block_t *SendPacket( decoder_t *, block_t * );
@@ -242,6 +243,7 @@ static int OpenDecoder( vlc_object_t *p_this )
         p_dec->pf_decode_audio = DecodeBlock;
     }
     p_dec->pf_packetize    = DecodeBlock;
+    p_dec->pf_flush        = Flush;
 
     p_sys->p_state = NULL;
     p_sys->p_header = NULL;
@@ -526,6 +528,16 @@ static int ProcessInitialHeader( decoder_t *p_dec, ogg_packet *p_oggpacket )
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, 0 );
+}
+
+/*****************************************************************************
  * ProcessPacket: processes a Speex packet.
  *****************************************************************************/
 static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
@@ -535,7 +547,7 @@ static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
     block_t *p_block = *pp_block;
 
     if( p_block && p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
-        date_Set( &p_sys->end_date, 0 );
+        Flush( p_dec );
 
     /* Date management */
     if( p_block && p_block->i_pts > VLC_TS_INVALID &&
diff --git a/modules/codec/theora.c b/modules/codec/theora.c
index 735dfbb..f1f100d 100644
--- a/modules/codec/theora.c
+++ b/modules/codec/theora.c
@@ -85,6 +85,7 @@ static void CloseDecoder  ( vlc_object_t * );
 static void *DecodeBlock  ( decoder_t *, block_t ** );
 static int  ProcessHeaders( decoder_t * );
 static void *ProcessPacket ( decoder_t *, ogg_packet *, block_t ** );
+static void Flush( decoder_t * );
 
 static picture_t *DecodePacket( decoder_t *, ogg_packet * );
 
@@ -172,6 +173,7 @@ static int OpenDecoder( vlc_object_t *p_this )
         DecodeBlock;
     p_dec->pf_packetize    = (block_t *(*)(decoder_t *, block_t **))
         DecodeBlock;
+    p_dec->pf_flush        = Flush;
 
     /* Init supporting Theora structures needed in header parsing */
     th_comment_init( &p_sys->tc );
@@ -415,6 +417,16 @@ error:
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    p_sys->i_pts = VLC_TS_INVALID;
+}
+
+/*****************************************************************************
  * ProcessPacket: processes a theora packet.
  *****************************************************************************/
 static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
diff --git a/modules/codec/uleaddvaudio.c b/modules/codec/uleaddvaudio.c
index 5fdba60..a8f6165 100644
--- a/modules/codec/uleaddvaudio.c
+++ b/modules/codec/uleaddvaudio.c
@@ -54,6 +54,13 @@ struct decoder_sys_t
     uint16_t shuffle[2000];
 };
 
+static void Flush(decoder_t *dec)
+{
+    decoder_sys_t *sys = dec->p_sys;
+
+    date_Set(&sys->end_date, 0);
+}
+
 static block_t *Decode(decoder_t *dec, block_t **block_ptr)
 {
     decoder_sys_t *sys  = dec->p_sys;
@@ -63,7 +70,7 @@ static block_t *Decode(decoder_t *dec, block_t **block_ptr)
 
     block_t *block = *block_ptr;
     if (block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED)) {
-        date_Set(&sys->end_date, 0);
+        Flush(dec);
         if (block->i_flags & BLOCK_FLAG_CORRUPTED) {
             block_Release(block);
             *block_ptr = NULL;
@@ -151,6 +158,7 @@ static int Open(vlc_object_t *object)
     dec->fmt_out.audio.i_original_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
 
     dec->pf_decode_audio = Decode;
+    dec->pf_flush        = Flush;
 
     return VLC_SUCCESS;
 }
diff --git a/modules/codec/videotoolbox.m b/modules/codec/videotoolbox.m
index 3725623..56a9a12 100644
--- a/modules/codec/videotoolbox.m
+++ b/modules/codec/videotoolbox.m
@@ -89,6 +89,7 @@ vlc_module_end()
 
 static CFDataRef ESDSCreate(decoder_t *, uint8_t *, uint32_t);
 static picture_t *DecodeBlock(decoder_t *, block_t **);
+static void Flush(decoder_t *);
 static void DecoderCallback(void *, void *, OSStatus, VTDecodeInfoFlags,
                             CVPixelBufferRef, CMTime, CMTime);
 void VTDictionarySetInt32(CFMutableDictionaryRef, CFStringRef, int);
@@ -694,6 +695,7 @@ static int OpenDecoder(vlc_object_t *p_this)
     }
 
     p_dec->pf_decode_video = DecodeBlock;
+    p_dec->pf_flush        = Flush;
 
     msg_Info(p_dec, "Using Video Toolbox to decode '%4.4s'", (char *)&p_dec->fmt_in.i_codec);
 
@@ -960,6 +962,20 @@ static void copy420YpCbCr8Planar(picture_t *p_pic,
 
 #pragma mark - actual decoding
 
+static void Flush(decoder_t *p_dec)
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    if (likely(p_sys->b_started)) {
+        @synchronized(p_sys->outputTimeStamps) {
+            [p_sys->outputTimeStamps removeAllObjects];
+        }
+        @synchronized(p_sys->outputFrames) {
+            [p_sys->outputFrames removeAllObjects];
+        }
+    }
+}
+
 static picture_t *DecodeBlock(decoder_t *p_dec, block_t **pp_block)
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
@@ -976,14 +992,7 @@ static picture_t *DecodeBlock(decoder_t *p_dec, block_t **pp_block)
 
     if (likely(p_block != NULL)) {
         if (unlikely(p_block->i_flags&(BLOCK_FLAG_CORRUPTED))) {
-            if (likely(p_sys->b_started)) {
-                @synchronized(p_sys->outputTimeStamps) {
-                    [p_sys->outputTimeStamps removeAllObjects];
-                }
-                @synchronized(p_sys->outputFrames) {
-                    [p_sys->outputFrames removeAllObjects];
-                }
-            }
+            Flush(p_dec);
             block_Release(p_block);
             goto skip;
         }
diff --git a/modules/codec/vorbis.c b/modules/codec/vorbis.c
index ef3c7b8..eef9578 100644
--- a/modules/codec/vorbis.c
+++ b/modules/codec/vorbis.c
@@ -148,6 +148,7 @@ static int  OpenDecoder   ( vlc_object_t * );
 static int  OpenPacketizer( vlc_object_t * );
 static void CloseDecoder  ( vlc_object_t * );
 static block_t *DecodeBlock  ( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 static int  ProcessHeaders( decoder_t * );
 static void *ProcessPacket ( decoder_t *, ogg_packet *, block_t ** );
@@ -262,6 +263,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     /* Set callbacks */
     p_dec->pf_decode_audio = DecodeBlock;
     p_dec->pf_packetize    = DecodeBlock;
+    p_dec->pf_flush        = Flush;
 
     return VLC_SUCCESS;
 }
@@ -426,6 +428,16 @@ static int ProcessHeaders( decoder_t *p_dec )
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, 0 );
+}
+
+/*****************************************************************************
  * ProcessPacket: processes a Vorbis packet.
  *****************************************************************************/
 static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
@@ -439,7 +451,7 @@ static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
         return NULL;
 
     if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
-        date_Set( &p_sys->end_date, 0 );
+        Flush( p_dec );
 
     if( ( p_block->i_flags & BLOCK_FLAG_CORRUPTED ) != 0 )
     {
diff --git a/modules/codec/wmafixed/wma.c b/modules/codec/wmafixed/wma.c
index 7f385e0..42d38b8 100644
--- a/modules/codec/wmafixed/wma.c
+++ b/modules/codec/wmafixed/wma.c
@@ -72,6 +72,7 @@ static int  OpenDecoder   ( vlc_object_t * );
 static void CloseDecoder  ( vlc_object_t * );
 
 static block_t *DecodeFrame( decoder_t *, block_t ** );
+static void Flush( decoder_t * );
 
 /*****************************************************************************
  * Module descriptor
@@ -184,11 +185,22 @@ static int OpenDecoder( vlc_object_t *p_this )
 
     /* Set callback */
     p_dec->pf_decode_audio = DecodeFrame;
+    p_dec->pf_flush        = Flush;
 
     return VLC_SUCCESS;
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set( &p_sys->end_date, VLC_TS_INVALID );
+}
+
+/*****************************************************************************
  * DecodeFrame: decodes a wma frame.
  *****************************************************************************/
 static block_t *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
@@ -203,7 +215,7 @@ static block_t *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
 
     if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
     {
-        date_Set( &p_sys->end_date, VLC_TS_INVALID );
+        Flush( p_dec );
         if( p_block->i_flags & BLOCK_FLAG_CORRUPTED)
         {
             block_Release( p_block );
diff --git a/modules/hw/mmal/codec.c b/modules/hw/mmal/codec.c
index 7d652f6..76c1e41 100644
--- a/modules/hw/mmal/codec.c
+++ b/modules/hw/mmal/codec.c
@@ -91,6 +91,7 @@ static void fill_output_port(decoder_t *dec);
 
 /* VLC decoder callback */
 static picture_t *decode(decoder_t *dec, block_t **block);
+static void flush_decoder(decoder_t *dec);
 
 /* MMAL callbacks */
 static void control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
@@ -236,6 +237,7 @@ static int OpenDecoder(decoder_t *dec)
 
     dec->fmt_out.i_cat = VIDEO_ES;
     dec->pf_decode_video = decode;
+    dec->pf_flush        = flush_decoder;
 
     vlc_mutex_init_recursive(&sys->mutex);
     vlc_sem_init(&sys->sem, 0);
@@ -534,12 +536,11 @@ static void fill_output_port(decoder_t *dec)
             break;
 }
 
-static int flush_decoder(decoder_t *dec)
+static void flush_decoder(decoder_t *dec)
 {
     decoder_sys_t *sys = dec->p_sys;
     MMAL_BUFFER_HEADER_T *buffer;
     MMAL_STATUS_T status;
-    int ret = 0;
 
     msg_Dbg(dec, "Flushing decoder ports...");
     mmal_port_disable(sys->output);
@@ -589,8 +590,6 @@ static int flush_decoder(decoder_t *dec)
         }
     }
     msg_Dbg(dec, "Ports flushed, returning to normal operation");
-
-    return ret;
 }
 
 static picture_t *decode(decoder_t *dec, block_t **pblock)
diff --git a/modules/packetizer/dirac.c b/modules/packetizer/dirac.c
index 71b0b11..59b9474 100644
--- a/modules/packetizer/dirac.c
+++ b/modules/packetizer/dirac.c
@@ -1208,6 +1208,26 @@ static void dirac_ReorderDequeueAndReleaseBlock( decoder_t *p_dec, block_t *p_bl
 }
 
 /*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    /* pre-emptively insert an EOS at a discontinuity, protects
+     * any decoders from any sudden changes */
+    block_t *p_block = dirac_EmitEOS( p_dec, 0 );
+    if( p_block )
+    {
+        p_block->p_next = dirac_EmitEOS( p_dec, 13 );
+        /* need two EOS to ensure it gets detected by synchro
+         * duplicates get discarded in forming encapsulation unit */
+
+        block_BytestreamPush( &p_sys->bytestream, p_block );
+    }
+}
+
+/*****************************************************************************
  * Packetize: form dated encapsulation units from anything
  *****************************************************************************/
 static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
@@ -1223,16 +1243,9 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
 
         if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
         {
-            /* pre-emptively insert an EOS at a discontinuity, protects
-             * any decoders from any sudden changes */
             block_Release( p_block );
-            p_block = dirac_EmitEOS( p_dec, 0 );
-            if( p_block )
-            {
-                p_block->p_next = dirac_EmitEOS( p_dec, 13 );
-                /* need two EOS to ensure it gets detected by synchro
-                 * duplicates get discarded in forming encapsulation unit */
-            }
+            p_block = NULL;
+            Flush( p_dec );
         }
         else if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
         {
@@ -1359,6 +1372,7 @@ static int Open( vlc_object_t *p_this )
         return VLC_EGENERIC;
 
     p_dec->pf_packetize = Packetize;
+    p_dec->pf_flush     = Flush;
 
     /* Create the output format */
     es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
diff --git a/modules/packetizer/flac.c b/modules/packetizer/flac.c
index 0eef93e..9abe992 100644
--- a/modules/packetizer/flac.c
+++ b/modules/packetizer/flac.c
@@ -523,6 +523,14 @@ static int SyncInfo(decoder_t *p_dec, uint8_t *p_buf,
     return b_guessing ? -1 : 1;
 }
 
+static void Flush(decoder_t *p_dec)
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    p_sys->i_state = STATE_NOSYNC;
+    block_BytestreamEmpty(&p_sys->bytestream);
+}
+
 /* */
 static block_t *Packetize(decoder_t *p_dec, block_t **pp_block)
 {
@@ -535,8 +543,7 @@ static block_t *Packetize(decoder_t *p_dec, block_t **pp_block)
         in = *pp_block;
 
         if (in->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED)) {
-            p_sys->i_state = STATE_NOSYNC;
-            block_BytestreamEmpty(&p_sys->bytestream);
+            Flush(p_dec);
             if (in->i_flags&BLOCK_FLAG_CORRUPTED) {
                 block_Release(*pp_block);
                 return NULL;
@@ -795,6 +802,7 @@ static int Open(vlc_object_t *p_this)
     /* */
     p_dec->pf_decode_audio = NULL;
     p_dec->pf_packetize    = Packetize;
+    p_dec->pf_flush        = Flush;
 
     return VLC_SUCCESS;
 }
diff --git a/modules/packetizer/mlp.c b/modules/packetizer/mlp.c
index ee35391..853a71b 100644
--- a/modules/packetizer/mlp.c
+++ b/modules/packetizer/mlp.c
@@ -100,6 +100,7 @@ static const uint8_t pu_start_code[3] = { 0xf8, 0x72, 0x6f };
  * Local prototypes
  ****************************************************************************/
 static block_t *Packetize( decoder_t *, block_t **pp_block );
+static void Flush( decoder_t * );
 static int SyncInfo( const uint8_t *p_hdr, bool *pb_mlp, mlp_header_t *p_mlp );
 static int SyncInfoDolby( const uint8_t *p_buf );
 
@@ -134,9 +135,23 @@ static int Open( vlc_object_t *p_this )
 
     /* Set callback */
     p_dec->pf_packetize = Packetize;
+    p_dec->pf_flush     = Flush;
     return VLC_SUCCESS;
 }
 
+/*****************************************************************************
+ * Flush:
+ *****************************************************************************/
+static void Flush( decoder_t *p_dec )
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    p_sys->b_mlp = false;
+    p_sys->i_state = STATE_NOSYNC;
+    block_BytestreamEmpty( &p_sys->bytestream );
+    date_Set( &p_sys->end_date, 0 );
+}
+
 /****************************************************************************
  * Packetize:
  ****************************************************************************/
@@ -153,10 +168,7 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
     /* */
     if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
     {
-        p_sys->b_mlp = false;
-        p_sys->i_state = STATE_NOSYNC;
-        block_BytestreamEmpty( &p_sys->bytestream );
-        date_Set( &p_sys->end_date, 0 );
+        Flush( p_dec );
         if( (*pp_block)->i_flags&(BLOCK_FLAG_CORRUPTED) )
         {
             block_Release( *pp_block );
diff --git a/modules/packetizer/mpeg4audio.c b/modules/packetizer/mpeg4audio.c
index e88e9bd..6391cd7 100644
--- a/modules/packetizer/mpeg4audio.c
+++ b/modules/packetizer/mpeg4audio.c
@@ -178,7 +178,9 @@ static int  OpenPacketizer(vlc_object_t *);
 static void ClosePacketizer(vlc_object_t *);
 
 static block_t *PacketizeRawBlock    (decoder_t *, block_t **);
+static void     FlushRawBlock( decoder_t * );
 static block_t *PacketizeStreamBlock(decoder_t *, block_t **);
+static void     FlushStreamBlock( decoder_t * );
 
 /*****************************************************************************
  * Module descriptor
@@ -256,6 +258,7 @@ static int OpenPacketizer(vlc_object_t *p_this)
 
         /* Set callback */
         p_dec->pf_packetize = PacketizeRawBlock;
+        p_dec->pf_flush = FlushRawBlock;
         p_sys->i_type = TYPE_RAW;
     } else {
         msg_Dbg(p_dec, "no decoder specific info, must be an ADTS or LOAS stream");
@@ -268,6 +271,7 @@ static int OpenPacketizer(vlc_object_t *p_this)
 
         /* Set callback */
         p_dec->pf_packetize = PacketizeStreamBlock;
+        p_dec->pf_flush = FlushStreamBlock;
         p_sys->i_type = TYPE_NONE;
     }
 
@@ -286,6 +290,16 @@ static void ClosePacketizer(vlc_object_t *p_this)
     free(p_sys);
 }
 
+/*****************************************************************************
+ * FlushRawBlock:
+ *****************************************************************************/
+static void FlushRawBlock(decoder_t *p_dec)
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    date_Set(&p_sys->end_date, 0);
+}
+
 /****************************************************************************
  * PacketizeRawBlock: the whole thing
  ****************************************************************************
@@ -300,7 +314,7 @@ static block_t *PacketizeRawBlock(decoder_t *p_dec, block_t **pp_block)
         return NULL;
 
     if ((*pp_block)->i_flags & (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED)) {
-        date_Set(&p_sys->end_date, 0);
+        FlushRawBlock(p_dec);
         if ((*pp_block)->i_flags&(BLOCK_FLAG_CORRUPTED)) {
             block_Release(*pp_block);
             return NULL;
@@ -931,6 +945,18 @@ static void SetupOutput(decoder_t *p_dec, block_t *p_block)
         date_Increment(&p_sys->end_date, p_sys->i_frame_length) - p_block->i_pts;
 }
 
+/*****************************************************************************
+ * FlushStreamBlock:
+ *****************************************************************************/
+static void FlushStreamBlock(decoder_t *p_dec)
+{
+    decoder_sys_t *p_sys = p_dec->p_sys;
+
+    p_sys->i_state = STATE_NOSYNC;
+    block_BytestreamEmpty(&p_sys->bytestream);
+    date_Set(&p_sys->end_date, VLC_TS_INVALID);
+}
+
 /****************************************************************************
  * PacketizeStreamBlock: ADTS/LOAS packetizer
  ****************************************************************************/
@@ -945,9 +971,7 @@ static block_t *PacketizeStreamBlock(decoder_t *p_dec, block_t **pp_block)
         return NULL;
 
     if ((*pp_block)->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED)) {
-        p_sys->i_state = STATE_NOSYNC;
-        block_BytestreamEmpty(&p_sys->bytestream);
-        date_Set(&p_sys->end_date, VLC_TS_INVALID);
+        FlushStreamBlock(p_dec);
         if ((*pp_block)->i_flags & BLOCK_FLAG_CORRUPTED) {
             block_Release(*pp_block);
             return NULL;
-- 
2.1.4



More information about the vlc-devel mailing list