mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-26 02:00:33 +00:00
ccextractor: Add unit test
https://bugzilla.gnome.org/show_bug.cgi?id=797370
This commit is contained in:
parent
7cfe6b0bf3
commit
fca02f3dac
4 changed files with 354 additions and 0 deletions
tests/check
|
@ -40,6 +40,12 @@ else
|
|||
check_assrender =
|
||||
endif
|
||||
|
||||
if USE_PANGO
|
||||
check_ccextractor = elements/ccextractor
|
||||
else
|
||||
check_ccextractor =
|
||||
endif
|
||||
|
||||
if USE_DASH
|
||||
check_dash = elements/dash_mpd
|
||||
check_dash_demux = elements/dash_demux
|
||||
|
@ -240,6 +246,7 @@ noinst_PROGRAMS = \
|
|||
check_PROGRAMS = \
|
||||
generic/states \
|
||||
$(check_assrender) \
|
||||
$(check_ccextractor) \
|
||||
$(check_dash) \
|
||||
$(check_dtls) \
|
||||
$(check_faac) \
|
||||
|
@ -451,6 +458,9 @@ elements_camerabin_LDADD = \
|
|||
$(GST_BASE_LIBS) $(GST_LIBS) $(LDADD)
|
||||
elements_camerabin_SOURCES = elements/camerabin.c
|
||||
|
||||
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)
|
||||
|
||||
elements_jifmux_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(EXIF_CFLAGS) $(AM_CFLAGS)
|
||||
elements_jifmux_LDADD = $(GST_PLUGINS_BASE_LIBS) -lgsttag-$(GST_API_VERSION) $(GST_CHECK_LIBS) $(EXIF_LIBS) $(LDADD)
|
||||
elements_jifmux_SOURCES = elements/jifmux.c
|
||||
|
|
1
tests/check/elements/.gitignore
vendored
1
tests/check/elements/.gitignore
vendored
|
@ -6,6 +6,7 @@ autoconvert
|
|||
autovideoconvert
|
||||
avwait
|
||||
camerabin
|
||||
ccextractor
|
||||
compositor
|
||||
curlfilesink
|
||||
curlftpsink
|
||||
|
|
342
tests/check/elements/ccextractor.c
Normal file
342
tests/check/elements/ccextractor.c
Normal file
|
@ -0,0 +1,342 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com>
|
||||
*
|
||||
* 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 <gst/gst.h>
|
||||
#include <gst/check/gstcheck.h>
|
||||
#include <gst/check/gstharness.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
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 ("ccextractor");
|
||||
|
||||
gst_harness_set_src_caps_str (h, "foo/bar");
|
||||
|
||||
buf = gst_buffer_new_and_alloc (128);
|
||||
outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf));
|
||||
|
||||
fail_unless (outbuf != NULL);
|
||||
fail_unless (outbuf == buf);
|
||||
fail_unless (gst_element_get_static_pad (h->element, "caption") == NULL);
|
||||
|
||||
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;
|
||||
|
||||
static void
|
||||
on_caption_pad_added (GstElement * ccextractor, GstPad * pad, GstHarness * h)
|
||||
{
|
||||
fail_unless (strcmp (GST_OBJECT_NAME (pad), "caption") == 0);
|
||||
gst_harness_add_element_src_pad (h, pad);
|
||||
}
|
||||
|
||||
GST_START_TEST (captions)
|
||||
{
|
||||
GstHarness *h, *h2;
|
||||
GstBuffer *buf, *outbuf;
|
||||
const guint8 caption_data[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
GstCaps *caps;
|
||||
|
||||
h = gst_harness_new ("ccextractor");
|
||||
h2 = gst_harness_new_with_element (h->element, NULL, NULL);
|
||||
|
||||
g_signal_connect (h->element, "pad-added", G_CALLBACK (on_caption_pad_added),
|
||||
h2);
|
||||
|
||||
gst_harness_set_src_caps_str (h, "foo/bar");
|
||||
|
||||
buf = gst_buffer_new_and_alloc (128);
|
||||
gst_buffer_add_video_caption_meta (buf, GST_VIDEO_CAPTION_TYPE_CEA708_RAW,
|
||||
caption_data, sizeof (caption_data));
|
||||
|
||||
outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf));
|
||||
|
||||
fail_unless (outbuf != NULL);
|
||||
fail_unless (outbuf == buf);
|
||||
gst_buffer_unref (outbuf);
|
||||
gst_buffer_unref (buf);
|
||||
|
||||
fail_unless (h2->sinkpad != NULL);
|
||||
outbuf = gst_harness_pull (h2);
|
||||
fail_unless (outbuf != NULL);
|
||||
fail_unless (gst_buffer_memcmp (outbuf, 0, caption_data,
|
||||
sizeof (caption_data)) == 0);
|
||||
gst_buffer_unref (outbuf);
|
||||
|
||||
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);
|
||||
|
||||
caps = gst_pad_get_current_caps (h2->sinkpad);
|
||||
fail_unless (caps != NULL);
|
||||
fail_unless (gst_caps_can_intersect (caps,
|
||||
gst_static_caps_get (&cea708_cc_data_caps)));
|
||||
gst_caps_unref (caps);
|
||||
|
||||
buf = gst_buffer_new_and_alloc (128);
|
||||
gst_buffer_add_video_caption_meta (buf, GST_VIDEO_CAPTION_TYPE_CEA708_RAW,
|
||||
caption_data, sizeof (caption_data));
|
||||
|
||||
outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf));
|
||||
|
||||
fail_unless (outbuf != NULL);
|
||||
fail_unless (outbuf == buf);
|
||||
gst_buffer_unref (outbuf);
|
||||
gst_buffer_unref (buf);
|
||||
|
||||
fail_unless (h2->sinkpad != NULL);
|
||||
outbuf = gst_harness_pull (h2);
|
||||
fail_unless (outbuf != NULL);
|
||||
fail_unless (gst_buffer_memcmp (outbuf, 0, caption_data,
|
||||
sizeof (caption_data)) == 0);
|
||||
gst_buffer_unref (outbuf);
|
||||
|
||||
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);
|
||||
|
||||
caps = gst_pad_get_current_caps (h2->sinkpad);
|
||||
fail_unless (caps != NULL);
|
||||
fail_unless (gst_caps_can_intersect (caps,
|
||||
gst_static_caps_get (&cea708_cc_data_caps)));
|
||||
gst_caps_unref (caps);
|
||||
|
||||
gst_harness_teardown (h);
|
||||
gst_harness_teardown (h2);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (no_captions_at_beginning_and_end)
|
||||
{
|
||||
GstHarness *h, *h2;
|
||||
GstBuffer *buf, *outbuf;
|
||||
const guint8 caption_data[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
GstCaps *caps;
|
||||
|
||||
h = gst_harness_new ("ccextractor");
|
||||
h2 = gst_harness_new_with_element (h->element, NULL, NULL);
|
||||
|
||||
g_signal_connect (h->element, "pad-added", G_CALLBACK (on_caption_pad_added),
|
||||
h2);
|
||||
|
||||
gst_harness_set_src_caps_str (h, "foo/bar");
|
||||
|
||||
buf = gst_buffer_new_and_alloc (128);
|
||||
|
||||
outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf));
|
||||
|
||||
fail_unless (outbuf != NULL);
|
||||
fail_unless (outbuf == buf);
|
||||
gst_buffer_unref (outbuf);
|
||||
gst_buffer_unref (buf);
|
||||
|
||||
buf = gst_buffer_new_and_alloc (128);
|
||||
gst_buffer_add_video_caption_meta (buf, GST_VIDEO_CAPTION_TYPE_CEA708_RAW,
|
||||
caption_data, sizeof (caption_data));
|
||||
|
||||
outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf));
|
||||
|
||||
fail_unless (outbuf != NULL);
|
||||
fail_unless (outbuf == buf);
|
||||
gst_buffer_unref (outbuf);
|
||||
gst_buffer_unref (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);
|
||||
|
||||
fail_unless (h2->sinkpad != NULL);
|
||||
outbuf = gst_harness_pull (h2);
|
||||
fail_unless (outbuf != NULL);
|
||||
fail_unless (gst_buffer_memcmp (outbuf, 0, caption_data,
|
||||
sizeof (caption_data)) == 0);
|
||||
gst_buffer_unref (outbuf);
|
||||
|
||||
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);
|
||||
|
||||
caps = gst_pad_get_current_caps (h2->sinkpad);
|
||||
fail_unless (caps != NULL);
|
||||
fail_unless (gst_caps_can_intersect (caps,
|
||||
gst_static_caps_get (&cea708_cc_data_caps)));
|
||||
gst_caps_unref (caps);
|
||||
|
||||
buf = gst_buffer_new_and_alloc (128);
|
||||
|
||||
outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf));
|
||||
|
||||
fail_unless (outbuf != NULL);
|
||||
fail_unless (outbuf == buf);
|
||||
gst_buffer_unref (outbuf);
|
||||
gst_buffer_unref (buf);
|
||||
|
||||
fail_if (gst_harness_try_pull (h2) != NULL);
|
||||
|
||||
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);
|
||||
|
||||
caps = gst_pad_get_current_caps (h2->sinkpad);
|
||||
fail_unless (caps != NULL);
|
||||
fail_unless (gst_caps_can_intersect (caps,
|
||||
gst_static_caps_get (&cea708_cc_data_caps)));
|
||||
gst_caps_unref (caps);
|
||||
|
||||
gst_harness_teardown (h);
|
||||
gst_harness_teardown (h2);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (captions_format_change)
|
||||
{
|
||||
GstHarness *h, *h2;
|
||||
GstBuffer *buf, *outbuf;
|
||||
const guint8 caption_data[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
GstCaps *caps;
|
||||
|
||||
h = gst_harness_new ("ccextractor");
|
||||
h2 = gst_harness_new_with_element (h->element, NULL, NULL);
|
||||
|
||||
g_signal_connect (h->element, "pad-added", G_CALLBACK (on_caption_pad_added),
|
||||
h2);
|
||||
|
||||
gst_harness_set_src_caps_str (h, "foo/bar");
|
||||
|
||||
buf = gst_buffer_new_and_alloc (128);
|
||||
gst_buffer_add_video_caption_meta (buf, GST_VIDEO_CAPTION_TYPE_CEA708_RAW,
|
||||
caption_data, sizeof (caption_data));
|
||||
|
||||
outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf));
|
||||
|
||||
fail_unless (outbuf != NULL);
|
||||
fail_unless (outbuf == buf);
|
||||
gst_buffer_unref (outbuf);
|
||||
gst_buffer_unref (buf);
|
||||
|
||||
fail_unless (h2->sinkpad != NULL);
|
||||
outbuf = gst_harness_pull (h2);
|
||||
fail_unless (outbuf != NULL);
|
||||
fail_unless (gst_buffer_memcmp (outbuf, 0, caption_data,
|
||||
sizeof (caption_data)) == 0);
|
||||
gst_buffer_unref (outbuf);
|
||||
|
||||
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);
|
||||
|
||||
caps = gst_pad_get_current_caps (h2->sinkpad);
|
||||
fail_unless (caps != NULL);
|
||||
fail_unless (gst_caps_can_intersect (caps,
|
||||
gst_static_caps_get (&cea708_cc_data_caps)));
|
||||
gst_caps_unref (caps);
|
||||
|
||||
buf = gst_buffer_new_and_alloc (128);
|
||||
gst_buffer_add_video_caption_meta (buf, GST_VIDEO_CAPTION_TYPE_CEA708_CDP,
|
||||
caption_data, sizeof (caption_data));
|
||||
|
||||
outbuf = gst_harness_push_and_pull (h, gst_buffer_ref (buf));
|
||||
|
||||
fail_unless (outbuf != NULL);
|
||||
fail_unless (outbuf == buf);
|
||||
gst_buffer_unref (outbuf);
|
||||
gst_buffer_unref (buf);
|
||||
|
||||
fail_unless (h2->sinkpad != NULL);
|
||||
outbuf = gst_harness_pull (h2);
|
||||
fail_unless (outbuf != NULL);
|
||||
fail_unless (gst_buffer_memcmp (outbuf, 0, caption_data,
|
||||
sizeof (caption_data)) == 0);
|
||||
gst_buffer_unref (outbuf);
|
||||
|
||||
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);
|
||||
|
||||
caps = gst_pad_get_current_caps (h2->sinkpad);
|
||||
fail_unless (caps != NULL);
|
||||
fail_unless (gst_caps_can_intersect (caps,
|
||||
gst_static_caps_get (&cea708_cdp_caps)));
|
||||
gst_caps_unref (caps);
|
||||
|
||||
gst_harness_teardown (h);
|
||||
gst_harness_teardown (h2);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
static Suite *
|
||||
ccextractor_suite (void)
|
||||
{
|
||||
Suite *s = suite_create ("ccextractor");
|
||||
TCase *tc = tcase_create ("general");
|
||||
|
||||
suite_add_tcase (s, tc);
|
||||
|
||||
tcase_add_test (tc, no_captions);
|
||||
tcase_add_test (tc, captions);
|
||||
tcase_add_test (tc, no_captions_at_beginning_and_end);
|
||||
tcase_add_test (tc, captions_format_change);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
GST_CHECK_MAIN (ccextractor);
|
|
@ -23,6 +23,7 @@ base_tests = [
|
|||
[['elements/autovideoconvert.c']],
|
||||
[['elements/avwait.c']],
|
||||
[['elements/camerabin.c']],
|
||||
[['elements/ccextractor.c']],
|
||||
[['elements/compositor.c']],
|
||||
[['elements/curlhttpsink.c'], not curl_dep.found(), [curl_dep]],
|
||||
[['elements/curlfilesink.c'], not curl_dep.found(), [curl_dep]],
|
||||
|
|
Loading…
Reference in a new issue