[vlc-devel] [PATCH] decoder: process the last block when closing

Rafaël Carré rafael.carre at gmail.com
Mon Aug 8 07:50:31 CEST 2011


There might be a buffer still stored in packetizer buffers
refs: #3178
---
 src/input/decoder.c          |    8 ++++++++
 src/input/decoder.h          |    1 +
 src/input/es_out.c           |   17 ++++++++++++++++-
 src/input/es_out.h           |    8 ++++++++
 src/input/es_out_timeshift.c |    3 +++
 src/input/input.c            |    1 +
 6 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index e478294..73be684 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -930,6 +930,14 @@ static void *DecoderThread( void *p_data )
         {
             int canc = vlc_savecancel();
 
+            if( p_block->i_flags & BLOCK_FLAG_CORE_EOS )
+            {
+                /* calling DecoderProcess() with NULL block will make
+                 * decoders/packetizers flush their buffers */
+                block_Release( p_block );
+                p_block = NULL;
+            }
+
             if( p_dec->b_error )
                 DecoderError( p_dec, p_block );
             else
diff --git a/src/input/decoder.h b/src/input/decoder.h
index 6f2dcb2..abb9f66 100644
--- a/src/input/decoder.h
+++ b/src/input/decoder.h
@@ -29,6 +29,7 @@
 #include <vlc_codec.h>
 
 #define BLOCK_FLAG_CORE_FLUSH (1 <<BLOCK_FLAG_CORE_PRIVATE_SHIFT)
+#define BLOCK_FLAG_CORE_EOS   (1 <<(BLOCK_FLAG_CORE_PRIVATE_SHIFT + 1))
 
 decoder_t *input_DecoderNew( input_thread_t *, es_format_t *, input_clock_t *,
                              sout_instance_t * ) VLC_USED;
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 1bb92bc..12e1c9b 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -2689,6 +2689,22 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
             input_clock_ChangeSystemOrigin( p_pgrm->p_clock, b_absolute, i_system );
             return VLC_SUCCESS;
         }
+        case ES_OUT_SET_EOS:
+        {
+            for (int i = 0; i < p_sys->i_es; i++) {
+                es_out_id_t *id = p_sys->es[i];
+                decoder_t *p_dec = id->p_dec;
+                if (!p_dec)
+                    continue;
+                block_t *p_block = block_Alloc(0);
+                if( !p_block )
+                    break;
+
+                p_block->i_flags |= BLOCK_FLAG_CORE_EOS;
+                input_DecoderDecode(p_dec, p_block, false);
+            }
+            return VLC_SUCCESS;
+        }
 
         default:
             msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
@@ -3019,4 +3035,3 @@ static void EsOutUpdateInfo( es_out_t *out, es_out_id_t *es, const es_format_t *
     /* */
     input_Control( p_input, INPUT_REPLACE_INFOS, p_cat );
 }
-
diff --git a/src/input/es_out.h b/src/input/es_out.h
index ddb3c5a..f42dbf5 100644
--- a/src/input/es_out.h
+++ b/src/input/es_out.h
@@ -79,6 +79,9 @@ enum es_out_query_private_e
 
     /* Get forced group */
     ES_OUT_GET_GROUP_FORCED,                        /* arg1=int * res=cannot fail */
+
+    /* Set End Of Stream */
+    ES_OUT_SET_EOS,                                 /* res=cannot fail */
 };
 
 static inline void es_out_SetMode( es_out_t *p_out, int i_mode )
@@ -159,6 +162,11 @@ static inline int es_out_GetGroupForced( es_out_t *p_out )
     assert( !i_ret );
     return i_group;
 }
+static inline void es_out_Eos( es_out_t *p_out )
+{
+    int i_ret = es_out_Control( p_out, ES_OUT_SET_EOS );
+    assert( !i_ret );
+}
 
 es_out_t  *input_EsOutNew( input_thread_t *, int i_rate );
 
diff --git a/src/input/es_out_timeshift.c b/src/input/es_out_timeshift.c
index d2d9b43..ad595b8 100644
--- a/src/input/es_out_timeshift.c
+++ b/src/input/es_out_timeshift.c
@@ -606,6 +606,7 @@ static int ControlLocked( es_out_t *p_out, int i_query, va_list args )
     case ES_OUT_SET_ES_FMT:
     case ES_OUT_SET_TIMES:
     case ES_OUT_SET_JITTER:
+    case ES_OUT_SET_EOS:
     {
         ts_cmd_t cmd;
         if( CmdInitControl( &cmd, i_query, args, p_sys->b_delayed ) )
@@ -1328,6 +1329,7 @@ static int CmdInitControl( ts_cmd_t *p_cmd, int i_query, va_list args, bool b_co
         break;
 
     case ES_OUT_RESET_PCR:           /* no arg */
+    case ES_OUT_SET_EOS:
         break;
 
     case ES_OUT_SET_META:        /* arg1=const vlc_meta_t* */
@@ -1463,6 +1465,7 @@ static int CmdExecuteControl( es_out_t *p_out, ts_cmd_t *p_cmd )
                                                p_cmd->u.control.u.int_i64.i_i64 );
 
     case ES_OUT_RESET_PCR:           /* no arg */
+    case ES_OUT_SET_EOS:
         return es_out_Control( p_out, i_query );
 
     case ES_OUT_SET_GROUP_META:  /* arg1=int i_group arg2=const vlc_meta_t* */
diff --git a/src/input/input.c b/src/input/input.c
index 7927480..7404c53 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -617,6 +617,7 @@ static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, bool *pb_d
     {
         msg_Dbg( p_input, "EOF reached" );
         p_input->p->input.b_eof = true;
+        es_out_Eos(p_input->p->p_es_out);
     }
     else if( i_ret < 0 )
     {
-- 
1.7.5.4





More information about the vlc-devel mailing list