[vlc-devel] [PATCH 3/5] decoder: refactor decoder module create/delete

Thomas Guillem thomas at gllm.fr
Wed Jun 3 17:35:43 CEST 2015


Move module create and delete in a specific function.
---
 src/input/decoder.c | 265 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 146 insertions(+), 119 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 3fb695f..e922589 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1394,6 +1394,146 @@ flush:
         DecoderProcessOnFlush( p_dec );
 }
 
+static int CreateDecoderModule( decoder_t *p_dec )
+{
+    decoder_owner_sys_t *p_owner = p_dec->p_owner;
+    es_format_t null_es_format;
+
+    memset( &null_es_format, 0, sizeof(es_format_t) );
+    es_format_Copy( &p_dec->fmt_out, &null_es_format );
+
+    /* Find a suitable decoder/packetizer module */
+    if( !p_owner->b_packetizer )
+        p_dec->p_module = module_need( p_dec, "decoder", "$codec", false );
+    else
+        p_dec->p_module = module_need( p_dec, "packetizer", "$packetizer", false );
+
+    if (!p_dec->p_module)
+        return VLC_EGENERIC;
+
+    /* Check if decoder requires already packetized data */
+    if( !p_owner->b_packetizer &&
+        p_dec->b_need_packetized && !p_dec->fmt_in.b_packetized )
+    {
+        p_owner->p_packetizer =
+            vlc_custom_create( p_dec->p_parent, sizeof( decoder_t ), "packetizer" );
+        if( p_owner->p_packetizer )
+        {
+            es_format_Copy( &p_owner->p_packetizer->fmt_in,
+                            &p_dec->fmt_in );
+
+            es_format_Copy( &p_owner->p_packetizer->fmt_out,
+                            &null_es_format );
+
+            p_owner->p_packetizer->p_module =
+                module_need( p_owner->p_packetizer,
+                             "packetizer", "$packetizer", false );
+
+            if( !p_owner->p_packetizer->p_module )
+            {
+                es_format_Clean( &p_owner->p_packetizer->fmt_in );
+                vlc_object_release( p_owner->p_packetizer );
+                p_owner->p_packetizer = NULL;
+            }
+        }
+    }
+
+    /* Copy ourself the input replay gain */
+    if( p_dec->fmt_in.i_cat == AUDIO_ES )
+    {
+        for( unsigned i = 0; i < AUDIO_REPLAY_GAIN_MAX; i++ )
+        {
+            if( !p_dec->fmt_out.audio_replay_gain.pb_peak[i] )
+            {
+                p_dec->fmt_out.audio_replay_gain.pb_peak[i] = p_dec->fmt_in.audio_replay_gain.pb_peak[i];
+                p_dec->fmt_out.audio_replay_gain.pf_peak[i] = p_dec->fmt_in.audio_replay_gain.pf_peak[i];
+            }
+            if( !p_dec->fmt_out.audio_replay_gain.pb_gain[i] )
+            {
+                p_dec->fmt_out.audio_replay_gain.pb_gain[i] = p_dec->fmt_in.audio_replay_gain.pb_gain[i];
+                p_dec->fmt_out.audio_replay_gain.pf_gain[i] = p_dec->fmt_in.audio_replay_gain.pf_gain[i];
+            }
+        }
+    }
+
+    /* */
+    p_owner->cc.b_supported = false;
+    if( !p_owner->b_packetizer )
+    {
+        if( p_owner->p_packetizer && p_owner->p_packetizer->pf_get_cc )
+            p_owner->cc.b_supported = true;
+        if( p_dec->pf_get_cc )
+            p_owner->cc.b_supported = true;
+    }
+
+    for( unsigned i = 0; i < 4; i++ )
+    {
+        p_owner->cc.pb_present[i] = false;
+        p_owner->cc.pp_decoder[i] = NULL;
+    }
+
+    return VLC_SUCCESS;
+}
+
+static void DeleteDecoderModule( decoder_t *p_dec )
+{
+    decoder_owner_sys_t *p_owner = p_dec->p_owner;
+
+    /* Cleanup */
+    if( p_owner->p_aout )
+    {
+        /* TODO: REVISIT gap-less audio */
+        aout_DecFlush( p_owner->p_aout, false );
+        aout_DecDelete( p_owner->p_aout );
+        input_resource_PutAout( p_owner->p_resource, p_owner->p_aout );
+        if( p_owner->p_input != NULL )
+            input_SendEventAout( p_owner->p_input );
+    }
+    if( p_owner->p_vout )
+    {
+        /* Hack to make sure all the the pictures are freed by the decoder
+         * and that the vout is not paused anymore */
+        vout_Reset( p_owner->p_vout );
+
+        /* */
+        input_resource_RequestVout( p_owner->p_resource, p_owner->p_vout, NULL,
+                                    0, true );
+        if( p_owner->p_input != NULL )
+            input_SendEventVout( p_owner->p_input );
+    }
+
+#ifdef ENABLE_SOUT
+    if( p_owner->p_sout_input )
+    {
+        sout_InputDelete( p_owner->p_sout_input );
+    }
+#endif
+    es_format_Clean( &p_owner->fmt );
+
+    if( p_dec->fmt_out.i_cat == SPU_ES )
+    {
+        vout_thread_t *p_vout = input_resource_HoldVout( p_owner->p_resource );
+        if( p_vout )
+        {
+            if( p_owner->p_spu_vout == p_vout )
+                vout_FlushSubpictureChannel( p_vout, p_owner->i_spu_channel );
+            vlc_object_release( p_vout );
+        }
+    }
+
+    es_format_Clean( &p_dec->fmt_out );
+
+    if( p_owner->p_packetizer )
+    {
+        module_unneed( p_owner->p_packetizer,
+                       p_owner->p_packetizer->p_module );
+        es_format_Clean( &p_owner->p_packetizer->fmt_in );
+        es_format_Clean( &p_owner->p_packetizer->fmt_out );
+        if( p_owner->p_packetizer->p_description )
+            vlc_meta_Delete( p_owner->p_packetizer->p_description );
+        vlc_object_release( p_owner->p_packetizer );
+    }
+}
 
 /**
  * The decoding main loop
@@ -1470,7 +1610,6 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
 {
     decoder_t *p_dec;
     decoder_owner_sys_t *p_owner;
-    es_format_t null_es_format;
 
     p_dec = vlc_custom_create( p_parent, sizeof( *p_dec ), "decoder" );
     if( p_dec == NULL )
@@ -1485,9 +1624,7 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
     /* Initialize the decoder */
     p_dec->p_module = NULL;
 
-    memset( &null_es_format, 0, sizeof(es_format_t) );
     es_format_Copy( &p_dec->fmt_in, fmt );
-    es_format_Copy( &p_dec->fmt_out, &null_es_format );
 
     p_dec->p_description = NULL;
 
@@ -1554,72 +1691,13 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
     p_dec->pf_get_display_date = DecoderGetDisplayDate;
     p_dec->pf_get_display_rate = DecoderGetDisplayRate;
 
-    /* Find a suitable decoder/packetizer module */
-    if( !b_packetizer )
-        p_dec->p_module = module_need( p_dec, "decoder", "$codec", false );
-    else
-        p_dec->p_module = module_need( p_dec, "packetizer", "$packetizer", false );
-
-    /* Check if decoder requires already packetized data */
-    if( !b_packetizer &&
-        p_dec->b_need_packetized && !p_dec->fmt_in.b_packetized )
+    if( CreateDecoderModule( p_dec ) != VLC_SUCCESS )
     {
-        p_owner->p_packetizer =
-            vlc_custom_create( p_parent, sizeof( decoder_t ), "packetizer" );
-        if( p_owner->p_packetizer )
-        {
-            es_format_Copy( &p_owner->p_packetizer->fmt_in,
-                            &p_dec->fmt_in );
-
-            es_format_Copy( &p_owner->p_packetizer->fmt_out,
-                            &null_es_format );
-
-            p_owner->p_packetizer->p_module =
-                module_need( p_owner->p_packetizer,
-                             "packetizer", "$packetizer", false );
-
-            if( !p_owner->p_packetizer->p_module )
-            {
-                es_format_Clean( &p_owner->p_packetizer->fmt_in );
-                vlc_object_release( p_owner->p_packetizer );
-                p_owner->p_packetizer = NULL;
-            }
-        }
-    }
-
-    /* Copy ourself the input replay gain */
-    if( fmt->i_cat == AUDIO_ES )
-    {
-        for( unsigned i = 0; i < AUDIO_REPLAY_GAIN_MAX; i++ )
-        {
-            if( !p_dec->fmt_out.audio_replay_gain.pb_peak[i] )
-            {
-                p_dec->fmt_out.audio_replay_gain.pb_peak[i] = fmt->audio_replay_gain.pb_peak[i];
-                p_dec->fmt_out.audio_replay_gain.pf_peak[i] = fmt->audio_replay_gain.pf_peak[i];
-            }
-            if( !p_dec->fmt_out.audio_replay_gain.pb_gain[i] )
-            {
-                p_dec->fmt_out.audio_replay_gain.pb_gain[i] = fmt->audio_replay_gain.pb_gain[i];
-                p_dec->fmt_out.audio_replay_gain.pf_gain[i] = fmt->audio_replay_gain.pf_gain[i];
-            }
-        }
-    }
-
-    /* */
-    p_owner->cc.b_supported = false;
-    if( !b_packetizer )
-    {
-        if( p_owner->p_packetizer && p_owner->p_packetizer->pf_get_cc )
-            p_owner->cc.b_supported = true;
-        if( p_dec->pf_get_cc )
-            p_owner->cc.b_supported = true;
+        free( p_owner );
+        vlc_object_release( p_dec );
+        return NULL;
     }
 
-    for( unsigned i = 0; i < 4; i++ )
-    {
-        p_owner->cc.pb_present[i] = false;
-        p_owner->cc.pp_decoder[i] = NULL;
-    }
     p_owner->i_ts_delay = 0;
     return p_dec;
 }
@@ -1641,66 +1719,15 @@ static void DeleteDecoder( decoder_t * p_dec )
     /* Free all packets still in the decoder fifo. */
     block_FifoRelease( p_owner->p_fifo );
 
-    /* Cleanup */
-    if( p_owner->p_aout )
-    {
-        /* TODO: REVISIT gap-less audio */
-        aout_DecFlush( p_owner->p_aout, false );
-        aout_DecDelete( p_owner->p_aout );
-        input_resource_PutAout( p_owner->p_resource, p_owner->p_aout );
-        if( p_owner->p_input != NULL )
-            input_SendEventAout( p_owner->p_input );
-    }
-    if( p_owner->p_vout )
-    {
-        /* Hack to make sure all the the pictures are freed by the decoder
-         * and that the vout is not paused anymore */
-        vout_Reset( p_owner->p_vout );
-
-        /* */
-        input_resource_RequestVout( p_owner->p_resource, p_owner->p_vout, NULL,
-                                    0, true );
-        if( p_owner->p_input != NULL )
-            input_SendEventVout( p_owner->p_input );
-    }
-
-#ifdef ENABLE_SOUT
-    if( p_owner->p_sout_input )
-    {
-        sout_InputDelete( p_owner->p_sout_input );
-    }
-#endif
-    es_format_Clean( &p_owner->fmt );
+    es_format_Clean( &p_dec->fmt_in );
 
-    if( p_dec->fmt_out.i_cat == SPU_ES )
-    {
-        vout_thread_t *p_vout = input_resource_HoldVout( p_owner->p_resource );
-        if( p_vout )
-        {
-            if( p_owner->p_spu_vout == p_vout )
-                vout_FlushSubpictureChannel( p_vout, p_owner->i_spu_channel );
-            vlc_object_release( p_vout );
-        }
-    }
+    DeleteDecoderModule( p_dec );
 
-    es_format_Clean( &p_dec->fmt_in );
-    es_format_Clean( &p_dec->fmt_out );
     if( p_dec->p_description )
         vlc_meta_Delete( p_dec->p_description );
     if( p_owner->p_description )
         vlc_meta_Delete( p_owner->p_description );
 
-    if( p_owner->p_packetizer )
-    {
-        module_unneed( p_owner->p_packetizer,
-                       p_owner->p_packetizer->p_module );
-        es_format_Clean( &p_owner->p_packetizer->fmt_in );
-        es_format_Clean( &p_owner->p_packetizer->fmt_out );
-        if( p_owner->p_packetizer->p_description )
-            vlc_meta_Delete( p_owner->p_packetizer->p_description );
-        vlc_object_release( p_owner->p_packetizer );
-    }
-
     vlc_cond_destroy( &p_owner->wait_fifo );
     vlc_cond_destroy( &p_owner->wait_acknowledge );
     vlc_cond_destroy( &p_owner->wait_request );
-- 
2.1.4




More information about the vlc-devel mailing list