[vlc-devel] [PATCH] [RFC] decoder: flush the sout when seeking

Steve Lhomme robux4 at videolabs.io
Sun Nov 15 14:17:07 CET 2015


---
 include/vlc_sout.h                | 10 ++++++++++
 src/input/decoder.c               | 37 ++++++++++++++++++++-----------------
 src/libvlccore.sym                |  1 +
 src/stream_output/stream_output.c | 17 +++++++++++++++++
 src/stream_output/stream_output.h |  1 +
 5 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/include/vlc_sout.h b/include/vlc_sout.h
index c2470f2..92efd81 100644
--- a/include/vlc_sout.h
+++ b/include/vlc_sout.h
@@ -175,6 +175,7 @@ VLC_API void sout_MuxDeleteStream( sout_mux_t *, sout_input_t * );
 VLC_API void sout_MuxDelete( sout_mux_t * );
 VLC_API int sout_MuxSendBuffer( sout_mux_t *, sout_input_t  *, block_t * );
 VLC_API int sout_MuxGetStream(sout_mux_t *, unsigned, mtime_t *);
+VLC_API int sout_MuxFlush( sout_mux_t *, sout_input_t * );
 
 static inline int sout_MuxControl( sout_mux_t *p_mux, int i_query, ... )
 {
@@ -205,6 +206,7 @@ struct sout_stream_t
     void              (*pf_del)( sout_stream_t *, sout_stream_id_sys_t * );
     /* manage a packet */
     int               (*pf_send)( sout_stream_t *, sout_stream_id_sys_t *, block_t* );
+    int               (*pf_flush)( sout_stream_t *, sout_stream_id_sys_t * );
 
     sout_stream_sys_t *p_sys;
     bool pace_nocontrol;
@@ -232,6 +234,14 @@ static inline int sout_StreamIdSend( sout_stream_t *s,
     return s->pf_send( s, id, b );
 }
 
+static inline int sout_StreamFlush( sout_stream_t *s,
+                                     sout_stream_id_sys_t *id )
+{
+    if (s->pf_flush)
+        return s->pf_flush( s, id );
+    return VLC_SUCCESS;
+}
+
 /****************************************************************************
  * Encoder
  ****************************************************************************/
diff --git a/src/input/decoder.c b/src/input/decoder.c
index dbbb1bb..f425291 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -707,7 +707,7 @@ static int DecoderPlaySout( decoder_t *p_dec, block_t *p_sout_block )
 
 /* This function process a block for sout
  */
-static void DecoderProcessSout( decoder_t *p_dec, block_t *p_block )
+static void DecoderProcessSout( decoder_t *p_dec, block_t *p_block, bool b_flush )
 {
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
     block_t *p_sout_block;
@@ -764,6 +764,12 @@ static void DecoderProcessSout( decoder_t *p_dec, block_t *p_block )
             p_sout_block = p_next;
         }
     }
+    /* The packetizer does not output a block that tell the decoder to flush
+     * do it ourself */
+    if( b_flush )
+    {
+        sout_InputFlush( p_owner->p_sout_input );
+    }
 }
 #endif
 
@@ -1269,29 +1275,26 @@ static void DecoderProcess( decoder_t *p_dec, block_t *p_block )
         return;
     }
 
+    bool b_flush = false;
+
+    if( p_block )
+    {
+        const bool b_flushing = p_owner->i_preroll_end == INT64_MAX;
+        DecoderUpdatePreroll( &p_owner->i_preroll_end, p_block );
+
+        b_flush = !b_flushing && b_flush_request;
+
+        p_block->i_flags &= ~BLOCK_FLAG_CORE_PRIVATE_MASK;
+    }
+
 #ifdef ENABLE_SOUT
     if( p_owner->b_packetizer )
     {
-        if( p_block )
-            p_block->i_flags &= ~BLOCK_FLAG_CORE_PRIVATE_MASK;
-
-        DecoderProcessSout( p_dec, p_block );
+        DecoderProcessSout( p_dec, p_block, b_flush );
     }
     else
 #endif
     {
-        bool b_flush = false;
-
-        if( p_block )
-        {
-            const bool b_flushing = p_owner->i_preroll_end == INT64_MAX;
-            DecoderUpdatePreroll( &p_owner->i_preroll_end, p_block );
-
-            b_flush = !b_flushing && b_flush_request;
-
-            p_block->i_flags &= ~BLOCK_FLAG_CORE_PRIVATE_MASK;
-        }
-
         if( p_dec->fmt_out.i_cat == AUDIO_ES )
         {
             DecoderProcessAudio( p_dec, p_block, b_flush );
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index a9e2636..7b4d5bd 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -387,6 +387,7 @@ sout_MuxDeleteStream
 sout_MuxGetStream
 sout_MuxNew
 sout_MuxSendBuffer
+sout_MuxFlush
 sout_StreamChainDelete
 sout_StreamChainNew
 spu_Create
diff --git a/src/stream_output/stream_output.c b/src/stream_output/stream_output.c
index 3d87b9b..a54f863 100644
--- a/src/stream_output/stream_output.c
+++ b/src/stream_output/stream_output.c
@@ -211,6 +211,17 @@ int sout_InputDelete( sout_packetizer_input_t *p_input )
     return( VLC_SUCCESS);
 }
 
+void sout_InputFlush( sout_packetizer_input_t *p_input )
+{
+    sout_instance_t     *p_sout = p_input->p_sout;
+
+    vlc_mutex_lock( &p_sout->lock );
+    sout_StreamFlush( p_sout->p_stream, p_input->id );
+    /* TODO block_FifoEmpty( p_input->p_fifo ); */
+    //p_input->b_flushed = true;
+    vlc_mutex_unlock( &p_sout->lock );
+}
+
 /*****************************************************************************
  *
  *****************************************************************************/
@@ -541,6 +552,12 @@ int sout_MuxSendBuffer( sout_mux_t *p_mux, sout_input_t *p_input,
     return p_mux->pf_mux( p_mux );
 }
 
+int sout_MuxFlush( sout_mux_t *p_mux, sout_input_t *p_input )
+{
+    msg_Info(p_mux, "%ld flush the sout FIFO", GetCurrentThreadId());
+    block_FifoEmpty( p_input->p_fifo );
+    return VLC_SUCCESS;
+}
 
 /*****************************************************************************
  * sout_MuxGetStream: find stream to be muxed
diff --git a/src/stream_output/stream_output.h b/src/stream_output/stream_output.h
index 1e48151..b623934 100644
--- a/src/stream_output/stream_output.h
+++ b/src/stream_output/stream_output.h
@@ -49,5 +49,6 @@ void sout_DeleteInstance( sout_instance_t * );
 sout_packetizer_input_t *sout_InputNew( sout_instance_t *, es_format_t * );
 int sout_InputDelete( sout_packetizer_input_t * );
 int sout_InputSendBuffer( sout_packetizer_input_t *, block_t* );
+void sout_InputFlush( sout_packetizer_input_t * );
 
 #endif
-- 
2.6.2



More information about the vlc-devel mailing list