[vlc-commits] decoder: add Destroy helper function for decoder owners

Steve Lhomme git at videolan.org
Mon Feb 18 17:02:47 CET 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Feb 18 14:50:21 2019 +0100| [efbacd8f91ed665e1ec461f55d83afb3d0df279f] | committer: Steve Lhomme

decoder: add Destroy helper function for decoder owners

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=efbacd8f91ed665e1ec461f55d83afb3d0df279f
---

 include/vlc_codec.h         |  7 +++++++
 src/input/decoder_helpers.c | 28 ++++++++++++++++++++++++++++
 src/libvlccore.sym          |  1 +
 3 files changed, 36 insertions(+)

diff --git a/include/vlc_codec.h b/include/vlc_codec.h
index c287953ba7..43d3a6d4f7 100644
--- a/include/vlc_codec.h
+++ b/include/vlc_codec.h
@@ -320,6 +320,13 @@ VLC_API void decoder_AbortPictures( decoder_t *dec, bool b_abort );
 VLC_API void decoder_Init( decoder_t *dec, const es_format_t * );
 
 /**
+ * Destroy a decoder and reset the structure.
+ *
+ * To be used by decoder owners.
+ */
+VLC_API void decoder_Destroy( decoder_t *p_dec );
+
+/**
  * This function queues a single picture to the video output.
  *
  * \note
diff --git a/src/input/decoder_helpers.c b/src/input/decoder_helpers.c
index 51f7ce8f6d..90abcb0c6e 100644
--- a/src/input/decoder_helpers.c
+++ b/src/input/decoder_helpers.c
@@ -28,6 +28,8 @@
 
 #include <vlc_common.h>
 #include <vlc_codec.h>
+#include <vlc_meta.h>
+#include <vlc_modules.h>
 
 void decoder_Init( decoder_t *p_dec, const es_format_t *restrict p_fmt )
 {
@@ -43,3 +45,29 @@ void decoder_Init( decoder_t *p_dec, const es_format_t *restrict p_fmt )
     es_format_Copy( &p_dec->fmt_in, p_fmt );
     es_format_Init( &p_dec->fmt_out, p_fmt->i_cat, 0 );
 }
+
+static void decoder_Clean( decoder_t *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);
+        p_dec->p_description = NULL;
+    }
+    if ( p_dec->p_module != NULL )
+    {
+        module_unneed(p_dec, p_dec->p_module);
+        p_dec->p_module = NULL;
+    }
+}
+
+void decoder_Destroy( decoder_t *p_dec )
+{
+    if (p_dec != NULL)
+    {
+        decoder_Clean( p_dec );
+        vlc_object_release( p_dec );
+    }
+}
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 09b5936180..906a449f2b 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -74,6 +74,7 @@ date_Decrement
 date_Increment
 date_Init
 decoder_Init
+decoder_Destroy
 decoder_AbortPictures
 decoder_NewAudioBuffer
 demux_PacketizerDestroy



More information about the vlc-commits mailing list