[vlc-devel] [PATCH 1/3] decoder: factorize the code to load a packetizer module

Steve Lhomme robux4 at videolabs.io
Wed Jul 19 16:02:59 CEST 2017


And force the b_packetized flag on success.
---
 src/input/decoder.c | 24 +++++++++++++++++++++---
 src/input/decoder.h | 14 ++++++++++++++
 src/input/demux.c   |  6 ++++--
 3 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 0cacb4ccfd..c7ab1e3052 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -151,6 +151,25 @@ struct decoder_owner_sys_t
 #define DECODER_SPU_VOUT_WAIT_DURATION ((int)(0.200*CLOCK_FREQ))
 #define BLOCK_FLAG_CORE_PRIVATE_RELOADED (1 << BLOCK_FLAG_CORE_PRIVATE_SHIFT)
 
+module_t *packetizer_LoadModule( decoder_t *p_dec, const char *name )
+{
+    switch (p_dec->fmt_in.i_cat)
+    {
+    case VIDEO_ES:
+    case AUDIO_ES:
+    case SPU_ES:
+        break; /* fine */
+    default:
+        return NULL; /* no packetizer possible */
+    }
+
+    es_format_Init( &p_dec->fmt_out, p_dec->fmt_in.i_cat, 0 );
+    module_t *p_module = module_need( p_dec, "packetizer", name, false );
+    if ( p_module != NULL )
+        p_dec->fmt_out.b_packetized = true;
+    return p_module;
+}
+
 /**
  * Load a decoder module
  */
@@ -166,7 +185,6 @@ static int LoadDecoder( decoder_t *p_dec, bool b_packetizer,
     p_dec->pf_flush = NULL;
 
     es_format_Copy( &p_dec->fmt_in, p_fmt );
-    es_format_Init( &p_dec->fmt_out, p_fmt->i_cat, 0 );
 
     /* Find a suitable decoder/packetizer module */
     if( !b_packetizer )
@@ -176,11 +194,12 @@ static int LoadDecoder( decoder_t *p_dec, bool b_packetizer,
             [AUDIO_ES] = "audio decoder",
             [SPU_ES] = "spu decoder",
         };
+        es_format_Init( &p_dec->fmt_out, p_fmt->i_cat, 0 );
         p_dec->p_module = module_need( p_dec, caps[p_dec->fmt_in.i_cat],
                                        "$codec", false );
     }
     else
-        p_dec->p_module = module_need( p_dec, "packetizer", "$packetizer", false );
+        p_dec->p_module = packetizer_LoadModule( p_dec, "$packetizer" );
 
     if( !p_dec->p_module )
     {
@@ -1722,7 +1741,6 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
             }
             else
             {
-                p_owner->p_packetizer->fmt_out.b_packetized = true;
                 fmt = &p_owner->p_packetizer->fmt_out;
             }
         }
diff --git a/src/input/decoder.h b/src/input/decoder.h
index 226ecde862..675d04b649 100644
--- a/src/input/decoder.h
+++ b/src/input/decoder.h
@@ -108,4 +108,18 @@ size_t input_DecoderGetFifoSize( decoder_t *p_dec );
  */
 void input_DecoderGetObjects( decoder_t *, vout_thread_t **, audio_output_t ** );
 
+/**
+ * This function loads a packetizer module with the given name
+ * @param name can de NULL to load any packetizer matching the fmt_in
+ *
+ * The caller owns the fmt_in and must fill it correctly.
+ * The caller MUST NOT fill the fmt_out but will own it if a module is loaded.
+ *
+ * The loaded module is provided an initialized fmt_out. This module is
+ * responsible for filling the rest of the fmt_out based on the fmt_in.
+ *
+ * \note The fmt_out.i_codec may not be filled right after loading the module.
+ */
+module_t *packetizer_LoadModule( decoder_t *p_dec, const char *name );
+
 #endif
diff --git a/src/input/demux.c b/src/input/demux.c
index 109a386775..f5102e42f5 100644
--- a/src/input/demux.c
+++ b/src/input/demux.c
@@ -36,6 +36,9 @@
 #include <vlc_modules.h>
 #include <vlc_strings.h>
 
+#include "clock.h"
+#include "decoder.h"
+
 typedef const struct
 {
     char const key[20];
@@ -519,9 +522,8 @@ decoder_t *demux_PacketizerNew( demux_t *p_demux, es_format_t *p_fmt, const char
     p_packetizer->pf_packetize = NULL;
 
     p_packetizer->fmt_in = *p_fmt;
-    es_format_Init( &p_packetizer->fmt_out, p_fmt->i_cat, 0 );
 
-    p_packetizer->p_module = module_need( p_packetizer, "packetizer", NULL, false );
+    p_packetizer->p_module = packetizer_LoadModule( p_packetizer, NULL );
     if( !p_packetizer->p_module )
     {
         es_format_Clean( p_fmt );
-- 
2.12.1



More information about the vlc-devel mailing list