From 1192a598eee41395f632cfebd2d8fb4bec08af7f Mon Sep 17 00:00:00 2001 From: "Wang,Fei" Date: Fri, 9 Mar 2018 10:48:11 -0900 Subject: tests: add msdkh264enc element unit test https://bugzilla.gnome.org/show_bug.cgi?id=793236 --- tests/check/Makefile.am | 11 +++ tests/check/elements/msdkh264enc.c | 163 +++++++++++++++++++++++++++++++++++++ tests/check/meson.build | 1 + 3 files changed, 175 insertions(+) create mode 100644 tests/check/elements/msdkh264enc.c (limited to 'tests') diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index e23a05f1f..163ef068e 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -210,6 +210,12 @@ else check_webrtc= endif +if USE_MSDK +check_msdk=elements/msdkh264enc +else +check_msdk= +endif + VALGRIND_TO_FIX = \ elements/mpeg2enc \ elements/mplex \ @@ -290,6 +296,7 @@ check_PROGRAMS = \ $(check_srtp) \ $(check_player) \ $(check_webrtc) \ + $(check_msdk) \ $(EXPERIMENTAL_CHECKS) noinst_HEADERS = elements/mxfdemux.h libs/isoff.h @@ -570,6 +577,10 @@ elements_webrtcbin_CFLAGS = \ $(GST_PLUGINS_BASE_CLAGS) $(GST_PLUGINS_BAD_CFLAGS) $(GST_SDP_CFLAGS) \ $(GST_BASE_CFLAGS) $(CFLAGS) $(AM_CFLAGS) +elements_msdk_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(AM_CFLAGS) +elements_msdk_LDADD = $(GST_PLUGINS_BASE_LIBS) $(GST_VIDEO_LIBS) $(GST_BASE_LIBS) $(LDADD) +elements_msdk_SOURCES = elements/msdkh264enc.c + distclean-local-orc: rm -rf orc diff --git a/tests/check/elements/msdkh264enc.c b/tests/check/elements/msdkh264enc.c new file mode 100644 index 000000000..6e0635cf0 --- /dev/null +++ b/tests/check/elements/msdkh264enc.c @@ -0,0 +1,163 @@ +/* GStreamer + * + * Unit test for msdkh264enc + * + * Copyright (c) 2018 Wang,Fei + * + * 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. + */ + +#include + +static GstStaticPadTemplate h264enc_sinktemp = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/x-h264, " + "width = (int) [1, MAX], " + "height = (int) [1, MAX], " "framerate = (fraction) [0, MAX]")); + +static GstStaticPadTemplate h264enc_srctemp = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("video/x-raw, " + "format = (string) NV12, " + "width = (int) [1, MAX], " + "height = (int) [1, MAX], " "framerate = (fraction) [0, MAX]")); + + +static GstPad *sinkpad, *srcpad; + +static GstElement * +setup_element (const gchar * caps) +{ + GstElement *element = NULL; + GstCaps *srccaps = NULL; + GstBus *bus = NULL; + + if (caps) { + srccaps = gst_caps_from_string (caps); + fail_unless (srccaps != NULL); + } + element = gst_check_setup_element ("msdkh264enc"); + fail_unless (element != NULL); + srcpad = gst_check_setup_src_pad (element, &h264enc_srctemp); + sinkpad = gst_check_setup_sink_pad (element, &h264enc_sinktemp); + gst_pad_set_active (srcpad, TRUE); + gst_pad_set_active (sinkpad, TRUE); + gst_check_setup_events (srcpad, element, srccaps, GST_FORMAT_TIME); + + bus = gst_bus_new (); + gst_element_set_bus (element, bus); + + fail_unless (gst_element_set_state (element, + GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE, + "could not set to playing"); + + if (srccaps) + gst_caps_unref (srccaps); + + buffers = NULL; + return element; + +} + +static void +cleanup_element (GstElement * element) +{ + GstBus *bus; + + /* Free parsed buffers */ + gst_check_drop_buffers (); + + bus = GST_ELEMENT_BUS (element); + gst_bus_set_flushing (bus, TRUE); + gst_object_unref (bus); + + gst_pad_set_active (srcpad, FALSE); + gst_pad_set_active (sinkpad, FALSE); + gst_check_teardown_src_pad (element); + gst_check_teardown_sink_pad (element); + gst_check_teardown_element (element); +} + + +GST_START_TEST (msdk_h264enc) +{ + GstElement *msdkh264enc; + GstBuffer *buffer; + gint i; + GList *l; + GstCaps *outcaps, *sinkcaps; + GstSegment seg; + + msdkh264enc = + setup_element + ("video/x-raw,format=(string)NV12,width=(int)320,height=(int)240,framerate=(fraction)25/1,interlace-mode=(string)progressive"); + + gst_segment_init (&seg, GST_FORMAT_TIME); + seg.stop = gst_util_uint64_scale (10, GST_SECOND, 25); + fail_unless (gst_pad_push_event (srcpad, gst_event_new_segment (&seg))); + + buffer = gst_buffer_new_allocate (NULL, 320 * 240 + 2 * 160 * 120, NULL); + gst_buffer_memset (buffer, 0, 0, -1); + + for (i = 0; i < 10; i++) { + GST_BUFFER_TIMESTAMP (buffer) = gst_util_uint64_scale (i, GST_SECOND, 25); + GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale (1, GST_SECOND, 25); + fail_unless (gst_pad_push (srcpad, gst_buffer_ref (buffer)) == GST_FLOW_OK); + } + + gst_buffer_unref (buffer); + + fail_unless (gst_pad_push_event (srcpad, gst_event_new_eos ())); + + fail_unless_equals_int (g_list_length (buffers), 10); + + outcaps = + gst_caps_from_string + ("video/x-h264,width=(int)320,height=(int)240,framerate=(fraction)25/1"); + + for (l = buffers, i = 0; l; l = l->next, i++) { + buffer = l->data; + + fail_unless_equals_uint64 (GST_BUFFER_DURATION (buffer), + gst_util_uint64_scale (1, GST_SECOND, 25)); + + sinkcaps = gst_pad_get_current_caps (sinkpad); + fail_unless (gst_caps_can_intersect (sinkcaps, outcaps)); + gst_caps_unref (sinkcaps); + } + + gst_caps_unref (outcaps); + cleanup_element (msdkh264enc); +} + +GST_END_TEST; + +static Suite * +msdkh264enc_suite (void) +{ + Suite *s = suite_create ("msdkh264enc"); + + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, msdk_h264enc); + + return s; +} + +GST_CHECK_MAIN (msdkh264enc); diff --git a/tests/check/meson.build b/tests/check/meson.build index 51da3e449..6a2fb95c7 100644 --- a/tests/check/meson.build +++ b/tests/check/meson.build @@ -56,6 +56,7 @@ base_tests = [ [['elements/webrtcbin.c'], not libnice_dep.found(), [gstwebrtc_dep]], [['elements/x265enc.c'], not x265_dep.found(), [x265_dep]], [['elements/zbar.c'], not zbar_dep.found(), [zbar_dep]], + [['elements/msdkh264enc.c'], not msdk_dep.found(), [msdk_dep]], [['libs/h264parser.c'], false, [gstcodecparsers_dep]], [['libs/h265parser.c'], false, [gstcodecparsers_dep]], [['libs/insertbin.c'], false, [gstinsertbin_dep]], -- cgit v1.2.1