[vlc-devel] [PATCH 02/18] core: force the output to b_packetized when a packetizer is opened successfully

Steve Lhomme robux4 at videolabs.io
Mon Jul 17 16:33:08 CEST 2017


--
replaces https://patches.videolan.org/patch/17456/
- set the flag before opening the packetizer
replaces https://patches.videolan.org/patch/17485/
- use a callback between module loads to reset the fmt_out
- don't copy the fmt_in in the fmt_out
---
 src/input/decoder.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 src/input/decoder.h |  5 +++++
 src/input/demux.c   |  7 +++++-
 3 files changed, 68 insertions(+), 6 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 0cacb4ccfd..63edadf994 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -151,6 +151,56 @@ 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)
 
+static int DecoderLoader(void *func, va_list ap)
+{
+    decoder_t *p_dec = va_arg(ap, decoder_t *);
+    int (*activate)(vlc_object_t *) = func;
+
+    int res = activate( VLC_OBJECT(p_dec) );
+    if ( res != VLC_SUCCESS )
+        es_format_Change( &p_dec->fmt_out, p_dec->fmt_in.i_cat, 0 );
+    return res;
+}
+
+int PacketizerLoader(void *func, va_list ap)
+{
+    decoder_t *p_dec = va_arg(ap, decoder_t *);
+    int (*activate)(vlc_object_t *) = func;
+
+    int res = activate( VLC_OBJECT(p_dec) );
+    assert( p_dec->fmt_out.b_packetized );
+    if ( res != VLC_SUCCESS )
+    {
+        es_format_Change( &p_dec->fmt_out, p_dec->fmt_in.i_cat, 0 );
+        p_dec->fmt_out.b_packetized = true;
+    }
+    return res;
+}
+
+module_t *decoder_LoadModule( decoder_t *p_dec, vlc_activate_t probe )
+{
+    const char caps[ES_CATEGORY_COUNT][16] = {
+        [VIDEO_ES] = "video decoder",
+        [AUDIO_ES] = "audio decoder",
+        [SPU_ES] = "spu decoder",
+    };
+
+    switch (p_dec->fmt_in.i_cat)
+    {
+    case VIDEO_ES:
+    case AUDIO_ES:
+    case SPU_ES:
+        break; /* fine */
+    default:
+        return NULL; /* no decoder for this type */
+    }
+
+    if ( probe == NULL )
+        es_format_Init( &p_dec->fmt_out, p_dec->fmt_in.i_cat, 0 );
+    return vlc_module_load( p_dec, caps[p_dec->fmt_in.i_cat], "$codec",
+                     false, probe ? probe : DecoderLoader, p_dec );
+}
+
 /**
  * Load a decoder module
  */
@@ -166,7 +216,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 )
@@ -180,15 +229,19 @@ static int LoadDecoder( decoder_t *p_dec, bool b_packetizer,
                                        "$codec", false );
     }
     else
-        p_dec->p_module = module_need( p_dec, "packetizer", "$packetizer", false );
+    {
+        es_format_Init( &p_dec->fmt_out, p_fmt->i_cat, 0 );
+        p_dec->fmt_out.b_packetized = true;
+        p_dec->p_module = vlc_module_load( p_dec, "packetizer", "$packetizer",
+                                           false, PacketizerLoader, p_dec );
+    }
 
     if( !p_dec->p_module )
     {
         es_format_Clean( &p_dec->fmt_in );
         return -1;
     }
-    else
-        return 0;
+    return 0;
 }
 
 /**
@@ -1722,7 +1775,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..fdc2e397db 100644
--- a/src/input/decoder.h
+++ b/src/input/decoder.h
@@ -108,4 +108,9 @@ size_t input_DecoderGetFifoSize( decoder_t *p_dec );
  */
 void input_DecoderGetObjects( decoder_t *, vout_thread_t **, audio_output_t ** );
 
+/**
+ * Function to use to load a packetizer module
+ */
+int PacketizerLoader(void *func, va_list ap);
+
 #endif
diff --git a/src/input/demux.c b/src/input/demux.c
index 109a386775..766b5364e9 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];
@@ -520,8 +523,10 @@ decoder_t *demux_PacketizerNew( demux_t *p_demux, es_format_t *p_fmt, const char
 
     p_packetizer->fmt_in = *p_fmt;
     es_format_Init( &p_packetizer->fmt_out, p_fmt->i_cat, 0 );
+    p_packetizer->fmt_out.b_packetized = true;
 
-    p_packetizer->p_module = module_need( p_packetizer, "packetizer", NULL, false );
+    p_packetizer->p_module = vlc_module_load( p_packetizer, "packetizer", NULL,
+                                              false, PacketizerLoader, p_packetizer );
     if( !p_packetizer->p_module )
     {
         es_format_Clean( p_fmt );
-- 
2.12.1



More information about the vlc-devel mailing list