[vlc-commits] test: input: test decoder from demux

Shaleen Jain git at videolan.org
Sun Nov 12 14:42:14 CET 2017


vlc | branch: master | Shaleen Jain <shaleen.jain95 at gmail.com> | Fri Oct 13 15:28:23 2017 +0200| [b83e9fe08d12ae798390bfa64c08096801fcd8c1] | committer: Thomas Guillem

test: input: test decoder from demux

This a merge of the work done by Shaleen during GSOC 2017. See
https://code.videolan.org/GSoC2017/shalzz/vlc.git

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

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

 test/Makefile.am           |  39 +++++++++
 test/src/input/decoder.c   | 210 +++++++++++++++++++++++++++++++++++++++++++++
 test/src/input/decoder.h   |  25 ++++++
 test/src/input/demux-run.c |  60 ++++++++++++-
 4 files changed, 330 insertions(+), 4 deletions(-)

diff --git a/test/Makefile.am b/test/Makefile.am
index 29cb26f2fa..059f9a24bd 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -200,6 +200,35 @@ endif
 endif
 EXTRA_LTLIBRARIES = libvlc_demux_run.la
 
+libvlc_demux_dec_run_la_SOURCES = $(libvlc_demux_run_la_SOURCES) \
+	src/input/decoder.c src/input/decoder.h
+libvlc_demux_dec_run_la_CPPFLAGS = $(libvlc_demux_run_la_CPPFLAGS) -DHAVE_DECODERS
+libvlc_demux_dec_run_la_LDFLAGS = $(libvlc_demux_run_la_LDFLAGS)
+libvlc_demux_dec_run_la_LIBADD = $(libvlc_demux_run_la_LIBADD)
+if !HAVE_DYNAMIC_PLUGINS
+libvlc_demux_dec_run_la_LIBADD += \
+	../modules/libadpcm_plugin.la \
+	../modules/libaes3_plugin.la \
+	../modules/libaraw_plugin.la \
+	../modules/libg711_plugin.la \
+	../modules/liblpcm_plugin.la \
+	../modules/libuleaddvaudio_plugin.la \
+	../modules/librawvideo_plugin.la \
+	../modules/libcc_plugin.la \
+	../modules/libcvdsub_plugin.la \
+	../modules/libdvbsub_plugin.la \
+	../modules/libscte18_plugin.la \
+	../modules/libscte27_plugin.la \
+	../modules/libspudec_plugin.la \
+	../modules/libstl_plugin.la \
+	../modules/libsubsdec_plugin.la \
+	../modules/libsubsusf_plugin.la \
+	../modules/libsvcdsub_plugin.la \
+	../modules/libtextst_plugin.la \
+	../modules/libsubstx3g_plugin.la
+endif
+EXTRA_LTLIBRARIES += libvlc_demux_dec_run.la
+
 #
 # Fuzzers
 #
@@ -210,3 +239,13 @@ EXTRA_PROGRAMS += vlc-demux-run
 vlc_demux_libfuzzer_CPPFLAGS = $(vlc_static_CPPFLAGS)
 vlc_demux_libfuzzer_LDADD = libvlc_demux_run.la
 EXTRA_PROGRAMS += vlc-demux-libfuzzer
+
+vlc_demux_dec_run_SOURCES = vlc-demux-run.c
+vlc_demux_dec_run_LDFLAGS = -no-install -static
+vlc_demux_dec_run_LDADD = libvlc_demux_dec_run.la
+EXTRA_PROGRAMS += vlc-demux-dec-run
+
+vlc_demux_dec_libfuzzer_SOURCES = vlc-demux-libfuzzer.c
+vlc_demux_dec_libfuzzer_CPPFLAGS = $(vlc_static_CPPFLAGS)
+vlc_demux_dec_libfuzzer_LDADD = libvlc_demux_dec_run.la
+EXTRA_PROGRAMS += vlc-demux-dec-libfuzzer
diff --git a/test/src/input/decoder.c b/test/src/input/decoder.c
new file mode 100644
index 0000000000..1de05af4a4
--- /dev/null
+++ b/test/src/input/decoder.c
@@ -0,0 +1,210 @@
+/*****************************************************************************
+ * decoder.c
+ *****************************************************************************
+ * Copyright (C) 2017 VLC authors and VideoLAN
+ *
+ * Authors: Shaleen Jain <shaleen.jain95 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_modules.h>
+#include <vlc_codec.h>
+#include <vlc_stream.h>
+#include <vlc_access.h>
+#include <vlc_block.h>
+#include <vlc_url.h>
+
+#include <vlc/libvlc.h>
+#include "../../lib/libvlc_internal.h"
+
+#include "common.h"
+#include "decoder.h"
+
+static picture_t *video_new_buffer_decoder(decoder_t *dec)
+{
+    return picture_NewFromFormat(&dec->fmt_out.video);
+}
+
+static subpicture_t *spu_new_buffer_decoder(decoder_t *dec,
+                                            const subpicture_updater_t * p_subpic)
+{
+    (void) dec;
+    return subpicture_New (p_subpic);
+}
+
+static int video_update_format_decoder(decoder_t *dec)
+{
+    (void) dec;
+    return 0;
+}
+static int queue_video(decoder_t *dec, picture_t *pic)
+{
+    (void) dec;
+    picture_Release(pic);
+    return 0;
+}
+
+static int queue_audio(decoder_t *dec, block_t *p_block)
+{
+    (void) dec;
+    block_Release(p_block);
+    return 0;
+}
+static int queue_cc(decoder_t *dec, block_t *p_block, const decoder_cc_desc_t *desc)
+{
+    (void) dec; (void) desc;
+    block_Release(p_block);
+    return 0;
+}
+static int queue_sub(decoder_t *dec, subpicture_t *p_subpic)
+{
+    (void) dec;
+    subpicture_Delete(p_subpic);
+    return 0;
+}
+
+void test_decoder_destroy(decoder_t *decoder)
+{
+    decoder_t *packetizer = (void *) decoder->p_owner;
+
+    if (packetizer->p_module != NULL)
+        module_unneed(packetizer, packetizer->p_module);
+    es_format_Clean(&packetizer->fmt_in);
+    es_format_Clean(&packetizer->fmt_out);
+    vlc_object_release(packetizer);
+
+    if (decoder->p_module != NULL)
+        module_unneed(decoder, decoder->p_module);
+    es_format_Clean(&decoder->fmt_in);
+    es_format_Clean(&decoder->fmt_out);
+    vlc_object_release(decoder);
+}
+
+decoder_t *test_decoder_create(vlc_object_t *parent, const es_format_t *fmt)
+{
+    assert(parent && fmt);
+    decoder_t *packetizer = NULL;
+    decoder_t *decoder = NULL;
+
+    packetizer = vlc_object_create(parent, sizeof(*packetizer));
+    decoder = vlc_object_create(parent, sizeof(*decoder));
+
+    if (packetizer == NULL || decoder == NULL)
+    {
+        if (packetizer)
+            vlc_object_release(packetizer);
+        return NULL;
+    }
+
+    decoder->pf_vout_format_update = video_update_format_decoder;
+    decoder->pf_vout_buffer_new = video_new_buffer_decoder;
+    decoder->pf_spu_buffer_new = spu_new_buffer_decoder;
+    decoder->pf_queue_video = queue_video;
+    decoder->pf_queue_audio = queue_audio;
+    decoder->pf_queue_cc = queue_cc;
+    decoder->pf_queue_sub = queue_sub;
+    decoder->b_frame_drop_allowed = true;
+    decoder->i_extra_picture_buffers = 0;
+    decoder->p_owner = (void *)packetizer;
+    packetizer->b_frame_drop_allowed = true;
+    packetizer->i_extra_picture_buffers = 0;
+
+    es_format_Copy(&packetizer->fmt_in, fmt);
+    es_format_Init(&packetizer->fmt_out, fmt->i_cat, 0);
+
+    packetizer->p_module = module_need(packetizer, "packetizer", NULL, false);
+    if (packetizer->p_module == NULL)
+        goto end;
+
+    es_format_Copy(&decoder->fmt_in, &packetizer->fmt_out);
+    es_format_Init(&decoder->fmt_out, UNKNOWN_ES, 0);
+
+    static const char caps[ES_CATEGORY_COUNT][16] = {
+        [VIDEO_ES] = "video decoder",
+        [AUDIO_ES] = "audio decoder",
+        [SPU_ES] = "spu decoder",
+    };
+    decoder->p_module = module_need(decoder, caps[decoder->fmt_in.i_cat], NULL,
+                                    false);
+    if (decoder->p_module == NULL)
+        goto end;
+
+    return decoder;
+
+end:
+    test_decoder_destroy(decoder);
+    return NULL;
+}
+
+int test_decoder_process(decoder_t *decoder, block_t *p_block)
+{
+    decoder_t *packetizer = (void *) decoder->p_owner;
+
+    block_t **pp_block = p_block ? &p_block : NULL;
+    block_t *p_packetized_block;
+    while ((p_packetized_block =
+                packetizer->pf_packetize(packetizer, pp_block)))
+    {
+
+        if (!es_format_IsSimilar(&decoder->fmt_in, &packetizer->fmt_out))
+        {
+            debug("restarting module due to input format change\n");
+
+            /* Drain the decoder module */
+            decoder->pf_decode(decoder, NULL);
+
+            /* Reload decoder */
+            module_unneed(decoder, decoder->p_module);
+            es_format_Clean(&decoder->fmt_in);
+            es_format_Copy(&decoder->fmt_in, &packetizer->fmt_out);
+            decoder->p_module = module_need(decoder, "video decoder",
+                                            NULL, false);
+        }
+
+        if (packetizer->pf_get_cc)
+        {
+            decoder_cc_desc_t desc;
+            block_t *p_cc = packetizer->pf_get_cc(packetizer, &desc);
+            if (p_cc)
+                block_Release(p_cc);
+        }
+
+        while (p_packetized_block != NULL)
+        {
+
+            block_t *p_next = p_packetized_block->p_next;
+            p_packetized_block->p_next = NULL;
+
+            int ret = decoder->pf_decode(decoder, p_packetized_block);
+
+            if (ret == VLCDEC_ECRITICAL)
+            {
+                block_ChainRelease(p_next);
+                return VLC_EGENERIC;
+            }
+
+            p_packetized_block = p_next;
+        }
+    }
+    if (p_block == NULL) /* Drain */
+        decoder->pf_decode(decoder, NULL);
+    return VLC_SUCCESS;
+}
diff --git a/test/src/input/decoder.h b/test/src/input/decoder.h
new file mode 100644
index 0000000000..2c64d6f14d
--- /dev/null
+++ b/test/src/input/decoder.h
@@ -0,0 +1,25 @@
+/*****************************************************************************
+ * decoder.c
+ *****************************************************************************
+ * Copyright (C) 2017 VLC authors and VideoLAN
+ *
+ * Authors: Shaleen Jain <shaleen.jain95 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+decoder_t *test_decoder_create(vlc_object_t *parent, const es_format_t *fmt);
+void test_decoder_destroy(decoder_t *decoder);
+int test_decoder_process(decoder_t *decoder, block_t *block);
diff --git a/test/src/input/demux-run.c b/test/src/input/demux-run.c
index a192d48c13..bcdc95017e 100644
--- a/test/src/input/demux-run.c
+++ b/test/src/input/demux-run.c
@@ -47,6 +47,7 @@
 #include <vlc/vlc.h>
 
 #include "demux-run.h"
+#include "decoder.h"
 
 struct test_es_out_t
 {
@@ -57,6 +58,9 @@ struct test_es_out_t
 struct es_out_id_t
 {
     struct es_out_id_t *next;
+#ifdef HAVE_DECODERS
+    decoder_t *decoder;
+#endif
 };
 
 static es_out_id_t *EsOutAdd(es_out_t *out, const es_format_t *fmt)
@@ -72,6 +76,9 @@ static es_out_id_t *EsOutAdd(es_out_t *out, const es_format_t *fmt)
 
     id->next = ctx->ids;
     ctx->ids = id;
+#ifdef HAVE_DECODERS
+    id->decoder = test_decoder_create((void *)out->p_sys, fmt);
+#endif
 
     debug("[%p] Added   ES\n", (void *)id);
     return id;
@@ -92,10 +99,28 @@ static int EsOutSend(es_out_t *out, es_out_id_t *id, block_t *block)
 {
     //debug("[%p] Sent    ES: %zu\n", (void *)idd, block->i_buffer);
     EsOutCheckId(out, id);
-    block_Release(block);
+#ifdef HAVE_DECODERS
+    if (id->decoder)
+        test_decoder_process(id->decoder, block);
+    else
+#endif
+        block_Release(block);
     return VLC_SUCCESS;
 }
 
+static void IdDelete(es_out_id_t *id)
+{
+#ifdef HAVE_DECODERS
+    if (id->decoder)
+    {
+        /* Drain */
+        test_decoder_process(id->decoder, NULL);
+        test_decoder_destroy(id->decoder);
+    }
+#endif
+    free(id);
+}
+
 static void EsOutDelete(es_out_t *out, es_out_id_t *id)
 {
     struct test_es_out_t *ctx = (struct test_es_out_t *) out;
@@ -110,7 +135,7 @@ static void EsOutDelete(es_out_t *out, es_out_id_t *id)
 
     debug("[%p] Deleted ES\n", (void *)id);
     *pp = id->next;
-    free(id);
+    IdDelete(id);
 }
 
 static int EsOutControl(es_out_t *out, int query, va_list args)
@@ -164,7 +189,7 @@ static void EsOutDestroy(es_out_t *out)
     while ((id = ctx->ids) != NULL)
     {
         ctx->ids = id->next;
-        free(id);
+        IdDelete(id);
     }
     free(ctx);
 }
@@ -340,6 +365,31 @@ int vlc_demux_process_memory(const struct vlc_run_args *args,
 typedef int (*vlc_plugin_cb)(int (*)(void *, void *, int, ...), void *);
 extern vlc_plugin_cb vlc_static_modules[];
 
+#ifdef HAVE_DECODERS
+#define DECODER_PLUGINS(f) \
+    f(adpcm) \
+    f(aes3) \
+    f(araw) \
+    f(g711) \
+    f(lpcm) \
+    f(uleaddvaudio) \
+    f(rawvideo) \
+    f(cc) \
+    f(cvdsub) \
+    f(dvbsub) \
+    f(scte18) \
+    f(scte27) \
+    f(spudec) \
+    f(stl) \
+    f(subsdec) \
+    f(subsusf) \
+    f(svcdsub) \
+    f(textst) \
+    f(substx3g)
+#else
+#define DECODER_PLUGINS(f)
+#endif
+
 #define PLUGINS(f) \
     f(xml) \
     f(console) \
@@ -383,7 +433,9 @@ extern vlc_plugin_cb vlc_static_modules[];
     f(mpeg4video) \
     f(mpegaudio) \
     f(mpegvideo) \
-    f(vc1)
+    f(vc1) \
+    DECODER_PLUGINS(f)
+
 #ifdef HAVE_DVBPSI
 # define PLUGIN_TS(f) f(ts)
 #else



More information about the vlc-commits mailing list