[vlc-devel] [RFC PATCH 5/9] decoder: factor decoder reload when fmt_in changes

Thomas Guillem thomas at gllm.fr
Sat Jul 9 12:20:13 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 8608976..74e08de 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -189,6 +189,26 @@ static void UnloadDecoder( decoder_t *p_dec )
     p_dec->b_error = false;
 }
 
+static int ReloadDecoder( decoder_t *p_dec, const char *psz_name,
+                          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, "decoder", psz_name, &fmt_in ) )
+    {
+        p_dec->b_error = true;
+        es_format_Clean( &fmt_in );
+        return VLC_EGENERIC;
+    }
+    es_format_Clean( &fmt_in );
+    return VLC_SUCCESS;
+}
+
 static decoder_t *CreateExtraPacketizer( decoder_t *p_dec, const es_format_t *fmt,
                                          const char *psz_name )
 {
@@ -1025,11 +1045,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, "decoder", NULL, &p_packetizer->fmt_out ) )
+
+                if( ReloadDecoder( p_dec, NULL,
+                    &p_packetizer->fmt_out ) != VLC_SUCCESS )
                 {
-                    p_dec->b_error = true;
                     block_ChainRelease( p_packetized_block );
                     return;
                 }
@@ -1208,11 +1227,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, "decoder", NULL, &p_packetizer->fmt_out ) )
+
+                if( ReloadDecoder( p_dec, NULL,
+                                   &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