From c651741ef0bb62e50f06b1a7224feae7a0986de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 5 Nov 2018 17:00:20 +0200 Subject: [PATCH] cccombiner: Add unit test --- tests/check/Makefile.am | 9 +- tests/check/elements/.gitignore | 1 + tests/check/elements/cccombiner.c | 249 ++++++++++++++++++++++++++++++ tests/check/meson.build | 1 + 4 files changed, 257 insertions(+), 3 deletions(-) create mode 100644 tests/check/elements/cccombiner.c diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index a1061a93c9..111a41f359 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -41,9 +41,9 @@ check_assrender = endif if USE_PANGO -check_ccextractor = elements/ccextractor +check_closedcaption = elements/cccombiner elements/ccextractor else -check_ccextractor = +check_closedcaption = endif if USE_DASH @@ -246,7 +246,7 @@ noinst_PROGRAMS = \ check_PROGRAMS = \ generic/states \ $(check_assrender) \ - $(check_ccextractor) \ + $(check_closedcaption) \ $(check_dash) \ $(check_dtls) \ $(check_faac) \ @@ -458,6 +458,9 @@ elements_camerabin_LDADD = \ $(GST_BASE_LIBS) $(GST_LIBS) $(LDADD) elements_camerabin_SOURCES = elements/camerabin.c +elements_cccombiner_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(AM_CFLAGS) +elements_cccombiner_LDADD = $(GST_PLUGINS_BASE_LIBS) $(GST_VIDEO_LIBS) $(GST_BASE_LIBS) $(LDADD) + elements_ccextractor_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(AM_CFLAGS) elements_ccextractor_LDADD = $(GST_PLUGINS_BASE_LIBS) $(GST_VIDEO_LIBS) $(GST_BASE_LIBS) $(LDADD) diff --git a/tests/check/elements/.gitignore b/tests/check/elements/.gitignore index f09b5df536..57065d4b93 100644 --- a/tests/check/elements/.gitignore +++ b/tests/check/elements/.gitignore @@ -6,6 +6,7 @@ autoconvert autovideoconvert avwait camerabin +cccombiner ccextractor compositor curlfilesink diff --git a/tests/check/elements/cccombiner.c b/tests/check/elements/cccombiner.c new file mode 100644 index 0000000000..92d1d46bd9 --- /dev/null +++ b/tests/check/elements/cccombiner.c @@ -0,0 +1,249 @@ +/* GStreamer + * + * Copyright (C) 2018 Sebastian Dröge + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include +#include + +#include + +static GstStaticCaps foo_bar_caps = GST_STATIC_CAPS ("foo/bar"); +static GstStaticCaps cea708_cc_data_caps = +GST_STATIC_CAPS ("closedcaption/x-cea-708,format=(string) cc_data"); +static GstStaticCaps cea708_cdp_caps = +GST_STATIC_CAPS ("closedcaption/x-cea-708,format=(string) cdp"); + +GST_START_TEST (no_captions) +{ + GstHarness *h; + GstBuffer *buf, *outbuf; + GstCaps *caps; + + h = gst_harness_new_with_padnames ("cccombiner", "sink", "src"); + + gst_harness_set_src_caps_str (h, foo_bar_caps.string); + + buf = gst_buffer_new_and_alloc (128); + GST_BUFFER_PTS (buf) = 0; + GST_BUFFER_DURATION (buf) = 40 * GST_MSECOND; + outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf)); + + fail_unless (outbuf != NULL); + fail_unless (outbuf == buf); + + caps = gst_pad_get_current_caps (h->sinkpad); + fail_unless (caps != NULL); + fail_unless (gst_caps_can_intersect (caps, + gst_static_caps_get (&foo_bar_caps))); + gst_caps_unref (caps); + + gst_buffer_unref (buf); + gst_buffer_unref (outbuf); + + gst_harness_teardown (h); +} + +GST_END_TEST; + +GST_START_TEST (captions_and_eos) +{ + GstHarness *h, *h2; + GstBuffer *buf, *outbuf; + GstPad *caption_pad; + GstCaps *caps; + GstVideoCaptionMeta *meta; + + h = gst_harness_new_with_padnames ("cccombiner", "sink", "src"); + h2 = gst_harness_new_with_element (h->element, NULL, NULL); + caption_pad = gst_element_get_request_pad (h->element, "caption"); + gst_harness_add_element_sink_pad (h2, caption_pad); + gst_object_unref (caption_pad); + + gst_harness_set_src_caps_str (h, foo_bar_caps.string); + gst_harness_set_src_caps_str (h2, cea708_cc_data_caps.string); + + /* Push a buffer and caption buffer */ + buf = gst_buffer_new_and_alloc (128); + GST_BUFFER_PTS (buf) = 0; + GST_BUFFER_DURATION (buf) = 40 * GST_MSECOND; + gst_harness_push (h, buf); + + buf = gst_buffer_new_and_alloc (128); + GST_BUFFER_PTS (buf) = 0; + GST_BUFFER_DURATION (buf) = 40 * GST_MSECOND; + gst_harness_push (h2, buf); + + /* And another one: the first video buffer should be retrievable + * after the second caption buffer is pushed */ + buf = gst_buffer_new_and_alloc (128); + GST_BUFFER_PTS (buf) = 40 * GST_MSECOND; + GST_BUFFER_DURATION (buf) = 40 * GST_MSECOND; + gst_harness_push (h, buf); + + buf = gst_buffer_new_and_alloc (128); + GST_BUFFER_PTS (buf) = 40 * GST_MSECOND; + GST_BUFFER_DURATION (buf) = 40 * GST_MSECOND; + gst_harness_push (h2, buf); + + /* Pull the first output buffer */ + outbuf = gst_harness_pull (h); + fail_unless (outbuf != NULL); + + meta = gst_buffer_get_video_caption_meta (outbuf); + fail_unless (meta != NULL); + fail_unless_equals_int (meta->caption_type, + GST_VIDEO_CAPTION_TYPE_CEA708_RAW); + fail_unless_equals_int (meta->size, 128); + + gst_buffer_unref (outbuf); + + /* Push EOS on both pads get the second output buffer, we otherwise wait + * in case there are further captions for the current video buffer */ + gst_harness_push_event (h, gst_event_new_eos ()); + gst_harness_push_event (h2, gst_event_new_eos ()); + + outbuf = gst_harness_pull (h); + fail_unless (outbuf != NULL); + + meta = gst_buffer_get_video_caption_meta (outbuf); + fail_unless (meta != NULL); + fail_unless_equals_int (meta->caption_type, + GST_VIDEO_CAPTION_TYPE_CEA708_RAW); + fail_unless_equals_int (meta->size, 128); + + gst_buffer_unref (outbuf); + + /* Caps should be equal to input caps */ + caps = gst_pad_get_current_caps (h->sinkpad); + fail_unless (caps != NULL); + fail_unless (gst_caps_can_intersect (caps, + gst_static_caps_get (&foo_bar_caps))); + gst_caps_unref (caps); + + gst_harness_teardown (h); + gst_harness_teardown (h2); +} + +GST_END_TEST; + +GST_START_TEST (captions_type_change_and_eos) +{ + GstHarness *h, *h2; + GstBuffer *buf, *outbuf; + GstPad *caption_pad; + GstCaps *caps; + GstVideoCaptionMeta *meta; + + h = gst_harness_new_with_padnames ("cccombiner", "sink", "src"); + h2 = gst_harness_new_with_element (h->element, NULL, NULL); + caption_pad = gst_element_get_request_pad (h->element, "caption"); + gst_harness_add_element_sink_pad (h2, caption_pad); + gst_object_unref (caption_pad); + + gst_harness_set_src_caps_str (h, foo_bar_caps.string); + gst_harness_set_src_caps_str (h2, cea708_cc_data_caps.string); + + /* Push a buffer and caption buffer */ + buf = gst_buffer_new_and_alloc (128); + GST_BUFFER_PTS (buf) = 0; + GST_BUFFER_DURATION (buf) = 40 * GST_MSECOND; + gst_harness_push (h, buf); + + buf = gst_buffer_new_and_alloc (128); + GST_BUFFER_PTS (buf) = 0; + GST_BUFFER_DURATION (buf) = 40 * GST_MSECOND; + gst_harness_push (h2, buf); + + /* Change caption type */ + gst_harness_set_src_caps_str (h2, cea708_cdp_caps.string); + + /* And another one: the first video buffer should be retrievable + * after the second caption buffer is pushed */ + buf = gst_buffer_new_and_alloc (128); + GST_BUFFER_PTS (buf) = 40 * GST_MSECOND; + GST_BUFFER_DURATION (buf) = 40 * GST_MSECOND; + gst_harness_push (h, buf); + + buf = gst_buffer_new_and_alloc (128); + GST_BUFFER_PTS (buf) = 40 * GST_MSECOND; + GST_BUFFER_DURATION (buf) = 40 * GST_MSECOND; + gst_harness_push (h2, buf); + + /* Pull the first output buffer */ + outbuf = gst_harness_pull (h); + fail_unless (outbuf != NULL); + + meta = gst_buffer_get_video_caption_meta (outbuf); + fail_unless (meta != NULL); + fail_unless_equals_int (meta->caption_type, + GST_VIDEO_CAPTION_TYPE_CEA708_RAW); + fail_unless_equals_int (meta->size, 128); + + gst_buffer_unref (outbuf); + + /* Push EOS on both pads get the second output buffer, we otherwise wait + * in case there are further captions for the current video buffer */ + gst_harness_push_event (h, gst_event_new_eos ()); + gst_harness_push_event (h2, gst_event_new_eos ()); + + outbuf = gst_harness_pull (h); + fail_unless (outbuf != NULL); + + meta = gst_buffer_get_video_caption_meta (outbuf); + fail_unless (meta != NULL); + fail_unless_equals_int (meta->caption_type, + GST_VIDEO_CAPTION_TYPE_CEA708_CDP); + fail_unless_equals_int (meta->size, 128); + + gst_buffer_unref (outbuf); + + /* Caps should be equal to input caps */ + caps = gst_pad_get_current_caps (h->sinkpad); + fail_unless (caps != NULL); + fail_unless (gst_caps_can_intersect (caps, + gst_static_caps_get (&foo_bar_caps))); + gst_caps_unref (caps); + + gst_harness_teardown (h); + gst_harness_teardown (h2); +} + +GST_END_TEST; + +static Suite * +cccombiner_suite (void) +{ + Suite *s = suite_create ("cccombiner"); + TCase *tc = tcase_create ("general"); + + suite_add_tcase (s, tc); + + tcase_add_test (tc, no_captions); + tcase_add_test (tc, captions_and_eos); + tcase_add_test (tc, captions_type_change_and_eos); + + return s; +} + +GST_CHECK_MAIN (cccombiner); diff --git a/tests/check/meson.build b/tests/check/meson.build index 4f698394d1..ee03b89b5d 100644 --- a/tests/check/meson.build +++ b/tests/check/meson.build @@ -23,6 +23,7 @@ base_tests = [ [['elements/autovideoconvert.c']], [['elements/avwait.c']], [['elements/camerabin.c']], + [['elements/cccombiner.c']], [['elements/ccextractor.c']], [['elements/compositor.c']], [['elements/curlhttpsink.c'], not curl_dep.found(), [curl_dep]],