From 3f832053998d28912c0458f4314f7f9a70d22908 Mon Sep 17 00:00:00 2001 From: Josep Torra Date: Fri, 28 Sep 2018 13:23:38 +0200 Subject: [PATCH] tests: shm: add an end to end test for live reception Add a unit test to exchange data between two pipelines with shmsrc acting as a live source. https://bugzilla.gnome.org/show_bug.cgi?id=797203 --- tests/check/elements/shm.c | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/check/elements/shm.c b/tests/check/elements/shm.c index f67e9ee028..69413cf0b9 100644 --- a/tests/check/elements/shm.c +++ b/tests/check/elements/shm.c @@ -169,6 +169,66 @@ GST_START_TEST (test_shm_alloc) GST_END_TEST; +GST_START_TEST (test_shm_live) +{ + GstElement *producer, *consumer; + GstElement *src, *sink; + gchar *socket_path = NULL; + GstStateChangeReturn state_res; + GstSample *sample = NULL; + + src = gst_element_factory_make ("fakesrc", NULL); + g_object_set (src, "sizetype", 2, NULL); + + sink = gst_element_factory_make ("shmsink", NULL); + g_object_set (sink, "socket-path", "shm-unit-test", "wait-for-connection", + FALSE, NULL); + + producer = gst_pipeline_new ("producer-pipeline"); + gst_bin_add_many (GST_BIN (producer), src, sink, NULL); + fail_unless (gst_element_link (src, sink)); + + state_res = gst_element_set_state (producer, GST_STATE_PLAYING); + fail_unless (state_res != GST_STATE_CHANGE_FAILURE); + + g_object_get (sink, "socket-path", &socket_path, NULL); + fail_unless (socket_path != NULL); + + src = gst_element_factory_make ("shmsrc", NULL); + sink = gst_element_factory_make ("appsink", NULL); + g_object_set (src, "is-live", TRUE, NULL); + g_object_set (sink, "async", FALSE, "enable-last-sample", FALSE, NULL); + + consumer = gst_pipeline_new ("consumer-pipeline"); + gst_bin_add_many (GST_BIN (consumer), src, sink, NULL); + fail_unless (gst_element_link (src, sink)); + + g_object_set (src, "socket-path", socket_path, NULL); + + state_res = gst_element_set_state (consumer, GST_STATE_PLAYING); + fail_unless (state_res != GST_STATE_CHANGE_FAILURE); + + /* wait for preroll */ + state_res = gst_element_get_state (consumer, NULL, NULL, GST_CLOCK_TIME_NONE); + fail_unless (state_res == GST_STATE_CHANGE_SUCCESS); + + g_signal_emit_by_name (sink, "pull-sample", &sample); + gst_sample_unref (sample); + + state_res = gst_element_set_state (consumer, GST_STATE_NULL); + fail_unless (state_res != GST_STATE_CHANGE_FAILURE); + + state_res = gst_element_set_state (producer, GST_STATE_NULL); + fail_unless (state_res != GST_STATE_CHANGE_FAILURE); + + gst_object_unref (consumer); + gst_object_unref (producer); + + g_free (socket_path); +} + +GST_END_TEST; + static Suite * shm_suite (void) { @@ -181,6 +241,10 @@ shm_suite (void) tcase_add_test (tc, test_shm_alloc); suite_add_tcase (s, tc); + tc = tcase_create ("shm2"); + tcase_add_test (tc, test_shm_live); + suite_add_tcase (s, tc); + return s; }