[vlc-devel] [PATCH 08/11] decoder: add a function to create a decoder module

Steve Lhomme robux4 at videolabs.io
Thu Jul 13 15:44:41 CEST 2017


And add a sanity check for the ES category.
---
 include/vlc_codec.h |  5 +++++
 src/input/decoder.c | 29 ++++++++++++++++++++++-------
 src/libvlccore.sym  |  1 +
 3 files changed, 28 insertions(+), 7 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 36ed920ecc..f2bb533a23 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -151,6 +151,27 @@ 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 *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
  */
@@ -170,14 +191,8 @@ static int LoadDecoder( decoder_t *p_dec, bool b_packetizer,
     /* 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",
-        };
         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 );
+        p_dec->p_module = decoder_LoadModule( p_dec );
     }
     else
     {
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