[vlc-commits] tests: add h264 packetizer

Francois Cartegnie git at videolan.org
Wed Sep 25 21:46:54 CEST 2019


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Sep  8 16:24:59 2019 +0200| [10d85acafd60e4f130675ff090de8bc2d93e848e] | committer: Francois Cartegnie

tests: add h264 packetizer

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

 test/Makefile.am                     |   4 +
 test/modules/packetizer/h264.c       | 132 +++++++++++++++++++++++++++++++
 test/modules/packetizer/packetizer.h | 149 +++++++++++++++++++++++++++++++++++
 3 files changed, 285 insertions(+)

diff --git a/test/Makefile.am b/test/Makefile.am
index 80b56d0fce..3fa52d6895 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -35,6 +35,7 @@ check_PROGRAMS = \
 	test_src_misc_keystore \
 	test_modules_packetizer_helpers \
 	test_modules_packetizer_hxxx \
+	test_modules_packetizer_h264 \
 	test_modules_keystore \
 	test_modules_demux_dashuri
 if ENABLE_SOUT
@@ -138,6 +139,9 @@ test_modules_packetizer_helpers_SOURCES = modules/packetizer/helpers.c
 test_modules_packetizer_helpers_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_modules_packetizer_hxxx_SOURCES = modules/packetizer/hxxx.c
 test_modules_packetizer_hxxx_LDADD = $(LIBVLCCORE) $(LIBVLC)
+test_modules_packetizer_h264_SOURCES = modules/packetizer/h264.c \
+				modules/packetizer/packetizer.h
+test_modules_packetizer_h264_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_modules_keystore_SOURCES = modules/keystore/test.c
 test_modules_keystore_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_modules_tls_SOURCES = modules/misc/tls.c
diff --git a/test/modules/packetizer/h264.c b/test/modules/packetizer/h264.c
new file mode 100644
index 0000000000..4c6ac33f98
--- /dev/null
+++ b/test/modules/packetizer/h264.c
@@ -0,0 +1,132 @@
+/*****************************************************************************
+ * h264.c: H264 packetizer unit testing
+ *****************************************************************************
+ * Copyright (C) 2019 VideoLabs, VideoLAN and VLC Authors
+ *
+ * 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/vlc.h>
+#include "../../../lib/libvlc_internal.h"
+#include "../../libvlc/test.h"
+
+#include "packetizer.h"
+
+/* 16x16, keyint 25, 50 frames */
+const uint8_t test_samples_raw_h264[] = {
+  0x00, 0x00, 0x00, 0x01, 0x67, 0xf4, 0x00, 0x0a, 0x91, 0x9b, 0x2b, 0xd0,
+  0x80, 0x00, 0x00, 0x03, 0x00, 0x80, 0x00, 0x00, 0x19, 0x07, 0x89, 0x12,
+  0xcb, 0x00, 0x00, 0x00, 0x01, 0x68, 0xeb, 0xec, 0x44, 0x84, 0x40, 0x00,
+  0x00, 0x01, 0x65, 0x88, 0x84, 0x00, 0x37, 0xff, 0xfe, 0xf5, 0xdb, 0xf3,
+  0x2c, 0xac, 0x66, 0x67, 0xff, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9a, 0x24,
+  0x6c, 0x46, 0xff, 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9e, 0x42,
+  0x78, 0x9f, 0xff, 0xdd, 0x81, 0x00, 0x00, 0x00, 0x01, 0x01, 0x9e, 0x61,
+  0x74, 0x4b, 0xff, 0xe0, 0x80, 0x00, 0x00, 0x00, 0x01, 0x01, 0x9e, 0x63,
+  0x6a, 0x4b, 0xff, 0xe0, 0x81, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9a, 0x68,
+  0x49, 0xa8, 0x41, 0x68, 0x99, 0x4c, 0x08, 0x4f, 0xff, 0xfe, 0xc1, 0x00,
+  0x00, 0x00, 0x01, 0x41, 0x9e, 0x86, 0x45, 0x11, 0x2c, 0x4f, 0xdb, 0x81,
+  0x00, 0x00, 0x00, 0x01, 0x01, 0x9e, 0xa5, 0x74, 0x4b, 0xff, 0xe0, 0x81,
+  0x00, 0x00, 0x00, 0x01, 0x01, 0x9e, 0xa7, 0x6a, 0x44, 0xff, 0xdb, 0x80,
+  0x00, 0x00, 0x00, 0x01, 0x41, 0x9a, 0xac, 0x49, 0xa8, 0x41, 0x6c, 0x99,
+  0x4c, 0x08, 0x6f, 0xff, 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9e,
+  0xca, 0x45, 0x15, 0x2c, 0x7f, 0xd6, 0x81, 0x00, 0x00, 0x00, 0x01, 0x01,
+  0x9e, 0xe9, 0x74, 0x45, 0xff, 0xda, 0x80, 0x00, 0x00, 0x00, 0x01, 0x01,
+  0x9e, 0xeb, 0x6a, 0x47, 0xff, 0xd6, 0x80, 0x00, 0x00, 0x00, 0x01, 0x41,
+  0x9a, 0xf0, 0x49, 0xa8, 0x41, 0x6c, 0x99, 0x4c, 0x08, 0x21, 0xff, 0xfe,
+  0xe1, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9f, 0x0e, 0x45, 0x15, 0x2c, 0x2f,
+  0xff, 0xca, 0x81, 0x00, 0x00, 0x00, 0x01, 0x01, 0x9f, 0x2d, 0x74, 0x42,
+  0x7f, 0xd1, 0x81, 0x00, 0x00, 0x00, 0x01, 0x01, 0x9f, 0x2f, 0x6a, 0x42,
+  0xff, 0xca, 0x80, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9b, 0x34, 0x49, 0xa8,
+  0x41, 0x6c, 0x99, 0x4c, 0x08, 0x25, 0xff, 0xfe, 0xe0, 0x00, 0x00, 0x00,
+  0x01, 0x41, 0x9f, 0x52, 0x45, 0x15, 0x2c, 0x3b, 0xff, 0xc1, 0x81, 0x00,
+  0x00, 0x00, 0x01, 0x01, 0x9f, 0x71, 0x74, 0x43, 0x3f, 0xc7, 0x80, 0x00,
+  0x00, 0x00, 0x01, 0x01, 0x9f, 0x73, 0x6a, 0x43, 0x7f, 0xc4, 0x80, 0x00,
+  0x00, 0x00, 0x01, 0x41, 0x9b, 0x78, 0x49, 0xa8, 0x41, 0x6c, 0x99, 0x4c,
+  0x08, 0x29, 0xff, 0xfe, 0xe1, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9f, 0x96,
+  0x45, 0x15, 0x2c, 0x10, 0xff, 0xba, 0x80, 0x00, 0x00, 0x00, 0x01, 0x01,
+  0x9f, 0xb5, 0x74, 0x43, 0xbf, 0xc1, 0x81, 0x00, 0x00, 0x00, 0x01, 0x01,
+  0x9f, 0xb7, 0x6a, 0x41, 0x0f, 0xba, 0x81, 0x00, 0x00, 0x00, 0x01, 0x67,
+  0xf4, 0x00, 0x0a, 0x91, 0x9b, 0x2b, 0xd0, 0x80, 0x00, 0x00, 0x03, 0x00,
+  0x80, 0x00, 0x00, 0x19, 0x07, 0x89, 0x12, 0xcb, 0x00, 0x00, 0x00, 0x01,
+  0x68, 0xeb, 0xec, 0x44, 0x84, 0x40, 0x00, 0x00, 0x01, 0x65, 0x88, 0x82,
+  0x00, 0x04, 0x7f, 0xfe, 0xf6, 0xfc, 0xfc, 0x0a, 0x6d, 0x53, 0x09, 0xff,
+  0xc0, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9a, 0x24, 0x6c, 0x41, 0x7f, 0xfe,
+  0xf1, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9e, 0x42, 0x78, 0x82, 0x5f, 0xb3,
+  0x80, 0x00, 0x00, 0x00, 0x01, 0x01, 0x9e, 0x61, 0x74, 0x41, 0x2f, 0xb3,
+  0x81, 0x00, 0x00, 0x00, 0x01, 0x01, 0x9e, 0x63, 0x6a, 0x41, 0x2f, 0xb3,
+  0x81, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9a, 0x68, 0x49, 0xa8, 0x41, 0x68,
+  0x99, 0x4c, 0x08, 0x31, 0xff, 0xfe, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x41,
+  0x9e, 0x86, 0x45, 0x11, 0x2c, 0x14, 0xff, 0xa6, 0x80, 0x00, 0x00, 0x00,
+  0x01, 0x01, 0x9e, 0xa5, 0x74, 0x41, 0x3f, 0xab, 0x81, 0x00, 0x00, 0x00,
+  0x01, 0x01, 0x9e, 0xa7, 0x6a, 0x41, 0x3f, 0xab, 0x80, 0x00, 0x00, 0x00,
+  0x01, 0x41, 0x9a, 0xac, 0x49, 0xa8, 0x41, 0x6c, 0x99, 0x4c, 0x08, 0x33,
+  0xff, 0xfe, 0xf1, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9e, 0xca, 0x45, 0x15,
+  0x2c, 0x16, 0xff, 0x9c, 0x80, 0x00, 0x00, 0x00, 0x01, 0x01, 0x9e, 0xe9,
+  0x74, 0x41, 0x4f, 0xa6, 0x81, 0x00, 0x00, 0x00, 0x01, 0x01, 0x9e, 0xeb,
+  0x6a, 0x41, 0x5f, 0xa1, 0x81, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9a, 0xf0,
+  0x49, 0xa8, 0x41, 0x6c, 0x99, 0x4c, 0x08, 0x35, 0xff, 0xfe, 0xf1, 0x00,
+  0x00, 0x00, 0x01, 0x41, 0x9f, 0x0e, 0x45, 0x15, 0x2c, 0x17, 0xff, 0x97,
+  0x81, 0x00, 0x00, 0x00, 0x01, 0x01, 0x9f, 0x2d, 0x74, 0x41, 0x6f, 0x9c,
+  0x80, 0x00, 0x00, 0x00, 0x01, 0x01, 0x9f, 0x2f, 0x6a, 0x41, 0x6f, 0x9c,
+  0x80, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9b, 0x34, 0x49, 0xa8, 0x41, 0x6c,
+  0x99, 0x4c, 0x08, 0x35, 0xff, 0xfe, 0xf1, 0x00, 0x00, 0x00, 0x01, 0x41,
+  0x9f, 0x52, 0x45, 0x15, 0x2c, 0x19, 0xff, 0x8c, 0x80, 0x00, 0x00, 0x00,
+  0x01, 0x01, 0x9f, 0x71, 0x74, 0x41, 0x7f, 0x97, 0x80, 0x00, 0x00, 0x00,
+  0x01, 0x01, 0x9f, 0x73, 0x6a, 0x41, 0x8f, 0x92, 0x81, 0x00, 0x00, 0x00,
+  0x01, 0x41, 0x9b, 0x78, 0x49, 0xa8, 0x41, 0x6c, 0x99, 0x4c, 0x08, 0x33,
+  0xff, 0xfe, 0xf1, 0x00, 0x00, 0x00, 0x01, 0x41, 0x9f, 0x96, 0x45, 0x15,
+  0x2c, 0x1a, 0xff, 0x86, 0x81, 0x00, 0x00, 0x00, 0x01, 0x01, 0x9f, 0xb5,
+  0x74, 0x41, 0x8f, 0x92, 0x80, 0x00, 0x00, 0x00, 0x01, 0x01, 0x9f, 0xb7,
+  0x6a, 0x41, 0x9f, 0x8c, 0x80
+};
+const size_t test_samples_raw_h264_len = 761;
+
+int main(void)
+{
+    test_init();
+
+    libvlc_instance_t *vlc = libvlc_new(0, NULL);
+    if(!vlc)
+        return 1;
+
+    struct params_s params;
+    params.vlc = vlc;
+    params.obj = VLC_OBJECT(vlc->p_libvlc_int);
+    params.codec = VLC_CODEC_H264;
+    params.i_rate_num = 0;
+    params.i_rate_den = 0;
+    params.i_frame_count = 2*25;
+
+    params.i_read_size = 500;
+    RUN("block 500", test_packetize,
+        test_samples_raw_h264, test_samples_raw_h264_len, 0);
+
+    params.i_rate_num = 60000;
+    params.i_rate_den = 1001;
+    params.i_read_size = 8;
+    RUN("block 8", test_packetize,
+        test_samples_raw_h264, test_samples_raw_h264_len, 0);
+
+    params.i_frame_count = 1*25;
+    params.i_read_size = 500;
+    RUN("skip 1st Iframe", test_packetize,
+        test_samples_raw_h264 + 10, test_samples_raw_h264_len - 10, 0);
+
+    libvlc_release(vlc);
+    return 0;
+}
diff --git a/test/modules/packetizer/packetizer.h b/test/modules/packetizer/packetizer.h
new file mode 100644
index 0000000000..481344bded
--- /dev/null
+++ b/test/modules/packetizer/packetizer.h
@@ -0,0 +1,149 @@
+/*****************************************************************************
+ * packetizer.h: packetizer unit testing
+ *****************************************************************************
+ * Copyright (C) 2019 VideoLabs, VideoLAN and VLC Authors
+ *
+ * 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.
+ *****************************************************************************/
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_modules.h>
+#include <vlc_demux.h>
+#include <vlc_codec.h>
+#include <vlc_meta.h>
+
+enum
+{
+    OK = VLC_SUCCESS,
+    FAIL = VLC_EGENERIC,
+};
+
+struct params_s
+{
+    libvlc_instance_t *vlc;
+    vlc_object_t *obj;
+    vlc_fourcc_t codec;
+    unsigned i_rate_num;
+    unsigned i_rate_den;
+    unsigned i_read_size;
+    unsigned i_frame_count;
+};
+
+#define BAILOUT(run) { fprintf(stderr, "failed %s line %d\n", run, __LINE__); \
+                        return 1; }
+#define RUN(run, test, a, b, res) \
+    if(test(#test " " run, a, b, &params) != res) BAILOUT(#test " " run)
+#define EXPECT(foo) if(!(foo)) BAILOUT(run)
+
+
+static void delete_packetizer(decoder_t *p_pack)
+{
+    if(p_pack->p_module)
+        module_unneed(p_pack, p_pack->p_module);
+    es_format_Clean(&p_pack->fmt_in);
+    es_format_Clean(&p_pack->fmt_out);
+    if(p_pack->p_description)
+        vlc_meta_Delete(p_pack->p_description);
+    vlc_object_delete(p_pack);
+}
+
+static decoder_t *create_packetizer(libvlc_instance_t *vlc,
+                                    unsigned num, unsigned den,
+                                    vlc_fourcc_t codec)
+{
+    decoder_t *p_pack = vlc_object_create(vlc->p_libvlc_int,
+                                          sizeof(*p_pack));
+    if(!p_pack)
+        return NULL;
+    p_pack->pf_decode = NULL;
+    p_pack->pf_packetize = NULL;
+
+    es_format_Init(&p_pack->fmt_in, VIDEO_ES, codec);
+    es_format_Init(&p_pack->fmt_out, VIDEO_ES, 0);
+    p_pack->fmt_in.video.i_frame_rate = num;
+    p_pack->fmt_in.video.i_frame_rate_base = den;
+    p_pack->fmt_in.b_packetized = false;
+
+    p_pack->p_module = module_need( p_pack, "packetizer", NULL, false );
+    if(!p_pack->p_module)
+        delete_packetizer(p_pack);
+    return p_pack;
+}
+
+static int test_packetize(const char *run,
+                          const uint8_t *p_data, size_t i_data,
+                          const struct params_s *params)
+{
+    decoder_t *p = create_packetizer(params->vlc,
+                                     params->i_rate_num,
+                                     params->i_rate_den,
+                                     params->codec);
+    EXPECT(p != NULL);
+
+    stream_t *s = vlc_stream_MemoryNew(params->obj,
+                                       (uint8_t *)p_data, i_data, true);
+    EXPECT(s != NULL);
+    block_t *outchain = NULL;
+    block_t **outappend = &outchain;
+    block_t *p_block;
+    unsigned i_count = 0;
+    do
+    {
+        p_block = vlc_stream_Block(s, params->i_read_size);
+        block_t *in = p_block;
+        if(in && outchain == NULL)
+            in->i_dts = VLC_TICK_0;
+        block_t *out;
+        do
+        {
+            out = p->pf_packetize(p, in ? &in : NULL);
+            if(out)
+            {
+                fprintf(stderr, "block #%u dts %"PRId64" sz %"PRId64
+                                " flags %x sz %"PRId64"\n",
+                        i_count, out->i_dts, out->i_buffer,
+                        out->i_flags, out->i_buffer );
+                block_ChainLastAppend(&outappend, out);
+                ++i_count;
+            }
+        } while(out);
+    } while(p_block);
+
+    EXPECT(i_count == params->i_frame_count);
+
+    if(params->i_rate_num && params->i_rate_den)
+    {
+        EXPECT(p->fmt_out.video.i_frame_rate == params->i_rate_num);
+        EXPECT(p->fmt_out.video.i_frame_rate_base == params->i_rate_den);
+        EXPECT(p->fmt_out.video.i_visible_width);
+        EXPECT(p->fmt_out.video.i_visible_height);
+    }
+
+    if(params->i_frame_count)
+    {
+        EXPECT(outchain != NULL);
+
+        p_block = block_ChainGather(outchain);
+        EXPECT(p_block != NULL);
+    }
+
+    EXPECT(p->fmt_out.i_extra);
+
+    delete_packetizer(p);
+
+    vlc_stream_Delete(s);
+
+    return OK;
+}



More information about the vlc-commits mailing list