From f34367adad756f9abbfde795df7c3086ea434da2 Mon Sep 17 00:00:00 2001 From: Emmanuel Pacaud Date: Wed, 14 Aug 2024 09:38:55 +0200 Subject: [PATCH] tests: aravissrc gst element switch test This test crashes as soon as the new source element is put in PLAYING mode. But that is probably due to a mishandling of the pipeline. Doing this sort of pipeline manipulation seems not trivial: --- meson.build | 3 +- tests/arvgsttest.c | 100 +++++++++++++++++++++++++++++++++++++++++++++ tests/meson.build | 8 ++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 tests/arvgsttest.c diff --git a/meson.build b/meson.build index afd213db1..5f3185f42 100644 --- a/meson.build +++ b/meson.build @@ -99,7 +99,6 @@ else # not Linux endif subdir ('src') -subdir ('tests') viewer_enabled = false viewer_option = get_option ('viewer') @@ -116,6 +115,8 @@ gst_deps = aravis_dependencies + [dependency ('gstreamer-base-1.0', required: gs dependency ('gstreamer-app-1.0', required: gst_option)] subdir('gst', if_found: gst_deps) +subdir ('tests') + doc_deps = dependency ('gi-docgen', version:'>= 2021.1', fallback: ['gi-docgen', 'dummy_dep'], required:get_option('documentation')) subdir('docs', if_found: doc_deps) diff --git a/tests/arvgsttest.c b/tests/arvgsttest.c new file mode 100644 index 000000000..5166cc4ae --- /dev/null +++ b/tests/arvgsttest.c @@ -0,0 +1,100 @@ +/* Simple script which will start an aravis pipeline, then restart ONLY the camera. */ +#include +#include +#include + +int +main (int argc, char *argv[]) +{ + GstElement *pipeline; + GstElement *source; + GstElement *sink; + GstElement *new_source; + GstState current_state, pending_state; + + gst_init (&argc, &argv); + + pipeline = gst_pipeline_new ("aravis_pipeline"); + source = gst_element_factory_make ("aravissrc", "source"); + if (!source) { + printf ("Failed to create the source element\n"); + return EXIT_FAILURE; + } + + g_object_set(G_OBJECT(source), + "camera-name", "Aravis-Fake-GV01", + "num-arv-buffers", 5, + "packet-resend", FALSE, + "packet-size", 9000, + "auto-packet-size", FALSE, + NULL); + + sink = gst_element_factory_make ("fakesink", "fake_sink"); + + if (!pipeline || !source || !sink) { + printf ("Not all elements could be created.\n"); + return EXIT_FAILURE; + } + + gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL); + + if (!gst_element_link (source, sink)) { + printf ("Elements could not be linked.\n"); + gst_object_unref (pipeline); + return EXIT_FAILURE; + } + + printf ("Start the pipeline\n"); + g_assert_cmpint (gst_element_set_state(pipeline, GST_STATE_PLAYING), ==, GST_STATE_CHANGE_ASYNC); + + printf ("Wait for a few frames\n"); + sleep (1); + + printf ("Stop the source\n"); + g_assert_cmpint (gst_element_set_state(source, GST_STATE_NULL), ==, GST_STATE_CHANGE_SUCCESS); + + gst_element_get_state (source, ¤t_state, &pending_state, 0); + printf ("source current state:%d - pending state:%d\n", current_state, pending_state); + + sleep (1); + + gst_element_unlink(source, sink); + g_assert (gst_bin_remove(GST_BIN(pipeline), source)); + + printf ("Create a new source\n"); + new_source = gst_element_factory_make ("aravissrc", "new_source"); + if (!new_source) { + printf ("Failed to create the source element\n"); + return EXIT_FAILURE; + } + g_object_set(G_OBJECT(new_source), + "camera-name", "Aravis-Fake-GV01", + "num-arv-buffers", 5, + "packet-resend", FALSE, + "packet-size", 9000, + "auto-packet-size", FALSE, + NULL); + + g_assert (gst_bin_add(GST_BIN(pipeline), new_source)); + g_assert (gst_element_link(new_source, sink)); + g_assert (gst_element_sync_state_with_parent(new_source)); + + gst_element_get_state (source, ¤t_state, &pending_state, 0); + printf ("new source current state:%d - pending state:%d\n", current_state, pending_state); + + printf ("Start the new source\n"); + g_assert_cmpint (gst_element_set_state(source, GST_STATE_PLAYING), ==, GST_STATE_CHANGE_SUCCESS); + + gst_element_get_state (source, ¤t_state, &pending_state, 0); + printf ("new source current state:%d - pending state:%d\n", current_state, pending_state); + + printf ("Wait for a few frames\n"); + + printf ("Stop the pipeline\n"); + g_assert_cmpint (gst_element_set_state (pipeline, GST_STATE_NULL), ==, GST_STATE_CHANGE_SUCCESS); + + printf ("Free the pipeline\n"); + gst_object_unref (pipeline); + + return EXIT_SUCCESS; +} diff --git a/tests/meson.build b/tests/meson.build index 54151f26f..711f9d3b3 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -101,4 +101,12 @@ if get_option('tests') include_directories: [library_inc]) endforeach + if gst_enabled + executable ('arv-gst-test', 'arvgsttest.c', + link_with: aravis_library, + dependencies: aravis_dependencies + gst_deps, + include_directories: [library_inc]) + + endif + endif