[vlc-devel] [RFC PATCH 04/12] decoder: factor decoder reload when fmt_in changes

Thomas Guillem thomas at gllm.fr
Tue Jul 19 19:36:26 CEST 2016


---
 src/input/decoder.c | 34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index cbc68e9..6a847d7 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -190,6 +190,26 @@ static void UnloadDecoder( decoder_t *p_dec )
     p_dec->b_error = false;
 }
 
+static int ReloadDecoder( decoder_t *p_dec, bool b_packetizer,
+                          const es_format_t *restrict p_fmt )
+{
+    /* Copy p_fmt since it can be destroyed by UnloadDecoder */
+    es_format_t fmt_in;
+    es_format_Init( &fmt_in, UNKNOWN_ES, 0 );
+    es_format_Copy( &fmt_in, p_fmt );
+
+    /* Restart the decoder module */
+    UnloadDecoder( p_dec );
+    if( LoadDecoder( p_dec, b_packetizer, &fmt_in ) )
+    {
+        p_dec->b_error = true;
+        es_format_Clean( &fmt_in );
+        return VLC_EGENERIC;
+    }
+    es_format_Clean( &fmt_in );
+    return VLC_SUCCESS;
+}
+
 static void DecoderUpdateFormatLocked( decoder_t *p_dec )
 {
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
@@ -1006,11 +1026,10 @@ static void DecoderProcessVideo( decoder_t *p_dec, block_t *p_block )
 
                 /* Drain the decoder module */
                 DecoderDecodeVideo( p_dec, NULL );
-                /* Restart the decoder module */
-                UnloadDecoder( p_dec );
-                if( LoadDecoder( p_dec, false, &p_packetizer->fmt_out ) )
+
+                if( ReloadDecoder( p_dec, false,
+                                   &p_packetizer->fmt_out ) != VLC_SUCCESS )
                 {
-                    p_dec->b_error = true;
                     block_ChainRelease( p_packetized_block );
                     return;
                 }
@@ -1189,11 +1208,10 @@ static void DecoderProcessAudio( decoder_t *p_dec, block_t *p_block )
 
                 /* Drain the decoder module */
                 DecoderDecodeAudio( p_dec, NULL );
-                /* Restart the decoder module */
-                UnloadDecoder( p_dec );
-                if( LoadDecoder( p_dec, false, &p_packetizer->fmt_out ) )
+
+                if( ReloadDecoder( p_dec, false,
+                                   &p_packetizer->fmt_out ) != VLC_SUCCESS )
                 {
-                    p_dec->b_error = true;
                     block_ChainRelease( p_packetized_block );
                     return;
                 }
-- 
2.8.1



More information about the vlc-devel mailing list