[vlc-commits] test: timestamps_filter

Francois Cartegnie git at videolan.org
Thu Jan 16 22:45:07 CET 2020


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Dec 15 17:11:27 2019 +0100| [caf561c9a60fbe5e62bc5a9c54622ffa4fd0def4] | committer: Francois Cartegnie

test: timestamps_filter

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

 test/Makefile.am                       |   5 +-
 test/modules/demux/timestamps_filter.c | 196 +++++++++++++++++++++++++++++++++
 2 files changed, 200 insertions(+), 1 deletion(-)

diff --git a/test/Makefile.am b/test/Makefile.am
index 647df6016e..08e4ee5ef0 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -39,7 +39,8 @@ check_PROGRAMS = \
 	test_modules_packetizer_hevc \
 	test_modules_packetizer_mpegvideo \
 	test_modules_keystore \
-	test_modules_demux_dashuri
+	test_modules_demux_dashuri \
+	test_modules_demux_timestamps_filter
 if ENABLE_SOUT
 check_PROGRAMS += test_modules_tls
 endif
@@ -155,6 +156,8 @@ test_modules_keystore_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_modules_tls_SOURCES = modules/misc/tls.c
 test_modules_tls_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_modules_demux_dashuri_SOURCES = modules/demux/dashuri.cpp
+test_modules_demux_timestamps_filter_LDADD = $(LIBVLC)
+test_modules_demux_timestamps_filter_SOURCES = modules/demux/timestamps_filter.c
 
 checkall:
 	$(MAKE) check_PROGRAMS="$(check_PROGRAMS) $(EXTRA_PROGRAMS)" check
diff --git a/test/modules/demux/timestamps_filter.c b/test/modules/demux/timestamps_filter.c
new file mode 100644
index 0000000000..cfeb2eb0f4
--- /dev/null
+++ b/test/modules/demux/timestamps_filter.c
@@ -0,0 +1,196 @@
+/*****************************************************************************
+ * timestamps_filter.c:
+ *****************************************************************************
+ * Copyright © 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
+
+#undef NDEBUG
+#include <assert.h>
+
+#include <vlc_common.h>
+#include <vlc_es.h>
+#include <vlc_block.h>
+#include "../../../modules/demux/moving_avg.h"
+#define DEBUG_TIMESTAMPS_FILTER
+#include "../../../modules/demux/timestamps_filter.h"
+
+#define TRASH_ID 0xfeca1
+#define ESID(n) ((void *)(INT64_C(0)+TRASH_ID+n))
+
+static int trash_es_out_Control(es_out_t *out, int i_query, va_list va_list)
+{
+    VLC_UNUSED(i_query);
+    VLC_UNUSED(out);
+    VLC_UNUSED(va_list);
+    return VLC_EGENERIC;
+}
+
+static int trash_es_out_Send(es_out_t *out, es_out_id_t *id, block_t *p_block)
+{
+    VLC_UNUSED(out);
+    VLC_UNUSED(id);
+    VLC_UNUSED(p_block); /* We will reuse it ! */
+    return VLC_SUCCESS;
+}
+
+static void trash_es_out_Delete(es_out_t *out)
+{
+    VLC_UNUSED(out);
+}
+
+static es_out_id_t *trash_es_out_Add(es_out_t *out, const es_format_t *fmt)
+{
+    VLC_UNUSED(out);
+    VLC_UNUSED(fmt);
+    return ESID(fmt->i_id);
+}
+
+static void trash_es_out_Del(es_out_t *out, es_out_id_t *id)
+{
+    VLC_UNUSED(out);
+    VLC_UNUSED(id);
+}
+
+static const struct es_out_callbacks trash_es_out_cbs =
+{
+    trash_es_out_Add,
+    trash_es_out_Send,
+    trash_es_out_Del,
+    trash_es_out_Control,
+    trash_es_out_Delete,
+};
+
+#define TIMELINE_0 (CLOCK_FREQ)
+#define TIMELINE_1 (CLOCK_FREQ * 10)
+#define TIMELINE_2 (CLOCK_FREQ * 5)
+
+int main(void)
+{
+    es_out_t trash_es_out = { .cbs = &trash_es_out_cbs };
+    es_out_t *out = timestamps_filter_es_out_New(&trash_es_out);
+    if(!out)
+        return 1;
+    block_t *p_block = block_Alloc(0);
+    if(!p_block)
+    {
+        timestamps_filter_es_out_Delete(out);
+        return 1;
+    }
+    es_format_t fmt;
+    int64_t i_pcrtime;
+
+    es_format_Init(&fmt, VIDEO_ES, VLC_FOURCC('V','I','D','E'));
+    fmt.i_id = 0;
+    assert(es_out_Add(out, &fmt) == ESID(0));
+    p_block->i_dts = TIMELINE_0 + 0;
+    es_out_Send(out, ESID(0), p_block);
+    assert(p_block->i_dts == TIMELINE_0 + 0);
+    p_block->i_dts = TIMELINE_0 + 100;
+    es_out_Send(out, ESID(0), p_block);
+    assert(p_block->i_dts == TIMELINE_0 + 100);
+    p_block->i_dts = TIMELINE_0 +200;
+    es_out_Send(out, ESID(0), p_block);
+    p_block->i_dts = TIMELINE_0 +300;
+    es_out_Send(out, ESID(0), p_block);
+    es_out_SetPCR(out, TIMELINE_0 +300);
+    assert(es_out_Control(out, ES_OUT_TF_FILTER_GET_TIME, &i_pcrtime) == VLC_SUCCESS);
+    assert(i_pcrtime == TIMELINE_0 + 300);
+
+    /* New Timeline: Handle PTS jump in the future */
+    p_block->i_dts = TIMELINE_1 + 0;
+    es_out_SetPCR(out, p_block->i_dts);
+    assert(es_out_Control(out, ES_OUT_TF_FILTER_GET_TIME, &i_pcrtime) == VLC_SUCCESS);
+    assert(i_pcrtime == TIMELINE_0 + 300);
+
+    es_out_Send(out, ESID(0), p_block);
+    assert(p_block->i_dts == TIMELINE_0 + 400);
+    p_block->i_dts = TIMELINE_1 + 100;
+    es_out_Send(out, ESID(0), p_block);
+    assert(p_block->i_dts == TIMELINE_0 + 500);
+
+    /* New Timeline: Handle PTS jump in the past */
+    p_block->i_dts = TIMELINE_2 + 0;
+    es_out_SetPCR(out, p_block->i_dts);
+    assert(es_out_Control(out, ES_OUT_TF_FILTER_GET_TIME, &i_pcrtime) == VLC_SUCCESS);
+    assert(i_pcrtime == TIMELINE_0 + 300);
+    es_out_Send(out, ESID(0), p_block);
+    assert(p_block->i_dts == TIMELINE_0 + 600);
+
+    es_format_Init(&fmt, VIDEO_ES, VLC_FOURCC('V','I','D','2'));
+    fmt.i_id = 1;
+    assert(es_out_Add(out, &fmt) == ESID(1));
+    p_block->i_dts = TIMELINE_2 + 333;
+    es_out_Send(out, ESID(1), p_block);
+    assert(p_block->i_dts == i_pcrtime + 333);
+
+    for(int i=1; i<MVA_PACKETS + 2; i++)
+    {
+        p_block->i_dts = TIMELINE_2 + i * 333;
+        es_out_Send(out, ESID(1), p_block);
+        assert(p_block->i_dts == i_pcrtime + i * 333);
+    }
+
+    es_format_Init(&fmt, SPU_ES, VLC_FOURCC('S','P','U','0'));
+    fmt.i_id = 2;
+    assert(es_out_Add(out, &fmt) == ESID(2));
+    p_block->i_dts = TIMELINE_2;
+    es_out_Send(out, ESID(2), p_block);
+    assert(p_block->i_dts == i_pcrtime);
+    p_block->i_dts = TIMELINE_2 + CLOCK_FREQ;
+    es_out_Send(out, ESID(2), p_block);
+    assert(p_block->i_dts == i_pcrtime + CLOCK_FREQ);
+
+    /* Test Reset */
+    assert(es_out_Control(out, ES_OUT_TF_FILTER_RESET) == VLC_SUCCESS);
+    assert(es_out_Control(out, ES_OUT_TF_FILTER_GET_TIME, &i_pcrtime) == VLC_SUCCESS);
+    assert(i_pcrtime == VLC_TICK_INVALID);
+
+    /* Test PCR interpolation */
+    es_format_Init(&fmt, VIDEO_ES, VLC_FOURCC('V','I','D','E'));
+    fmt.i_id = 0;
+    assert(es_out_Add(out, &fmt) == ESID(0));
+    p_block->i_dts = TIMELINE_0 + 0;
+    es_out_Send(out, ESID(0), p_block);
+    assert(p_block->i_dts == TIMELINE_0 + 0);
+    es_out_SetPCR(out, TIMELINE_0 +0);
+    p_block->i_dts = TIMELINE_0 + 100;
+    es_out_Send(out, ESID(0), p_block);
+    assert(p_block->i_dts == TIMELINE_0 + 100);
+    es_out_SetPCR(out, TIMELINE_0 +100);
+    es_out_SetPCR(out, TIMELINE_0 +200);
+    es_out_SetPCR(out, TIMELINE_0 +300);
+    es_out_SetPCR(out, TIMELINE_0 +400);
+    es_out_SetPCR(out, TIMELINE_0 +500);
+    assert(es_out_Control(out, ES_OUT_TF_FILTER_GET_TIME, &i_pcrtime) == VLC_SUCCESS);
+    assert(i_pcrtime == TIMELINE_0 +500);
+
+    assert(es_out_Control(out, ES_OUT_TF_FILTER_DISCONTINUITY) == VLC_SUCCESS);
+    assert(es_out_Control(out, ES_OUT_TF_FILTER_GET_TIME, &i_pcrtime) == VLC_SUCCESS);
+    assert(i_pcrtime == TIMELINE_0 +500);
+
+    es_out_SetPCR(out, TIMELINE_1 +0);
+    assert(es_out_Control(out, ES_OUT_TF_FILTER_GET_TIME, &i_pcrtime) == VLC_SUCCESS);
+    assert(i_pcrtime == TIMELINE_0 +600);
+
+    block_Release(p_block);
+    es_out_Delete(out);
+    return 0;
+}



More information about the vlc-commits mailing list