From c19d21f46490d91b6285f68374156735d2fa7938 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Tue, 28 Apr 2020 19:58:53 +0900 Subject: [PATCH] tests: mfvideosrc: Add unit test Simple test for reuse scenario Part-of: --- tests/check/elements/mfvideosrc.c | 111 ++++++++++++++++++++++++++++++ tests/check/meson.build | 1 + 2 files changed, 112 insertions(+) create mode 100644 tests/check/elements/mfvideosrc.c diff --git a/tests/check/elements/mfvideosrc.c b/tests/check/elements/mfvideosrc.c new file mode 100644 index 0000000000..530d21f742 --- /dev/null +++ b/tests/check/elements/mfvideosrc.c @@ -0,0 +1,111 @@ +/* GStreamer + * + * Copyright (C) 2020 Seungha Yang + * + * 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 + +GST_START_TEST (test_mf_video_src_reuse) +{ + GstElement *pipeline; + GstStateChangeReturn ret; + GstBus *bus; + GstMessage *msg; + + pipeline = gst_parse_launch ("mfvideosrc ! fakevideosink name=sink", NULL); + fail_unless (pipeline != NULL); + + bus = gst_element_get_bus (GST_ELEMENT (pipeline)); + fail_unless (bus != NULL); + + GST_INFO ("Set state playing"); + ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); + msg = gst_bus_poll (bus, GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR, -1); + fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ASYNC_DONE); + gst_message_unref (msg); + + GST_INFO ("Set state ready"); + ret = gst_element_set_state (pipeline, GST_STATE_READY); + fail_unless (ret == GST_STATE_CHANGE_SUCCESS); + + GST_INFO ("Set state playing again"); + ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); + msg = gst_bus_poll (bus, GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR, -1); + fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ASYNC_DONE); + gst_message_unref (msg); + + ret = gst_element_set_state (pipeline, GST_STATE_NULL); + fail_unless (ret == GST_STATE_CHANGE_SUCCESS); + + gst_object_unref (bus); + gst_object_unref (pipeline); +} + +GST_END_TEST; + +static gboolean +check_mf_available (void) +{ + gboolean ret = TRUE; + GstElement *mfvideosrc; + + mfvideosrc = gst_element_factory_make ("mfvideosrc", NULL); + if (!mfvideosrc) { + GST_INFO ("nvh264dec is not available"); + return FALSE; + } + + /* GST_STATE_READY is meaning that camera is available */ + if (gst_element_set_state (mfvideosrc, + GST_STATE_READY) != GST_STATE_CHANGE_SUCCESS) { + GST_INFO ("cannot open device"); + ret = FALSE; + } + + gst_element_set_state (mfvideosrc, GST_STATE_NULL); + gst_object_unref (mfvideosrc); + + return ret; +} + +static Suite * +mfvideosrc_suite (void) +{ + Suite *s = suite_create ("mfvideosrc"); + TCase *tc_basic = tcase_create ("general"); + gboolean have_mf = FALSE; + + suite_add_tcase (s, tc_basic); + + have_mf = check_mf_available (); + + if (have_mf) { + tcase_add_test (tc_basic, test_mf_video_src_reuse); + } else { + GST_INFO ("Skipping tests, media foundation plugin is unavailable"); + } + + return s; +} + +GST_CHECK_MAIN (mfvideosrc); diff --git a/tests/check/meson.build b/tests/check/meson.build index 6bc198226c..bc1b714a8c 100644 --- a/tests/check/meson.build +++ b/tests/check/meson.build @@ -34,6 +34,7 @@ base_tests = [ [['elements/hlsdemux_m3u8.c'], not hls_dep.found(), [hls_dep]], [['elements/id3mux.c']], [['elements/jpeg2000parse.c'], false, [libparser_dep, gstcodecparsers_dep]], + [['elements/mfvideosrc.c'], host_machine.system() != 'windows', ], [['elements/mpegtsmux.c'], false, [gstmpegts_dep]], [['elements/mpeg4videoparse.c'], false, [libparser_dep, gstcodecparsers_dep]], [['elements/mpegvideoparse.c'], false, [libparser_dep, gstcodecparsers_dep]],