[vlc-devel] [PATCH 04/18] decoder: add a function to create a decoder module

Steve Lhomme robux4 at videolabs.io
Mon Jul 17 17:41:41 CEST 2017


And add a sanity check for the ES category.
---
 include/vlc_codec.h |  5 +++++
 src/input/decoder.c | 31 +++++++++++++++++++++++--------
 src/libvlccore.sym  |  1 +
 3 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/include/vlc_codec.h b/include/vlc_codec.h
index c62ccd0e94..76a86767f1 100644
--- a/include/vlc_codec.h
+++ b/include/vlc_codec.h
@@ -409,6 +409,11 @@ VLC_API mtime_t decoder_GetDisplayDate( decoder_t *, mtime_t ) VLC_USED;
  */
 VLC_API int decoder_GetDisplayRate( decoder_t * ) VLC_USED;
 
+/**
+ * This function loads a decoder module matching the fmt_in of the decoder object.
+ */
+VLC_API module_t *decoder_LoadModule( decoder_t * ) VLC_USED;
+
 /** @} */
 /** @} */
 #endif /* _VLC_CODEC_H */
diff --git a/src/input/decoder.c b/src/input/decoder.c
index cff170462d..ef103a888e 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -166,6 +166,27 @@ int PacketizerLoader(void *func, va_list ap)
     return res;
 }
 
+module_t *decoder_LoadModule( decoder_t *p_dec )
+{
+    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 */
+    }
+
+    return module_need( p_dec, caps[p_dec->fmt_in.i_cat], "$codec", false);
+}
+
 /**
  * Load a decoder module
  */
@@ -181,21 +202,15 @@ 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 )
     {
-        const char caps[ES_CATEGORY_COUNT][16] = {
-            [VIDEO_ES] = "video decoder",
-            [AUDIO_ES] = "audio decoder",
-            [SPU_ES] = "spu decoder",
-        };
-        p_dec->p_module = module_need( p_dec, caps[p_dec->fmt_in.i_cat],
-                                       "$codec", false );
+        p_dec->p_module = decoder_LoadModule( p_dec );
     }
     else
     {
-        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 );
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 93c56d3749..393e6c055d 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -82,6 +82,7 @@ decoder_GetDisplayRate
 decoder_GetInputAttachments
 decoder_NewAudioBuffer
 decoder_NewSubpicture
+decoder_LoadModule
 demux_Delete
 demux_PacketizerDestroy
 demux_PacketizerNew
-- 
2.12.1



More information about the vlc-devel mailing list