Skip to content

Commit f34367a

Browse files
committed
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: <https://gstreamer.freedesktop.org/documentation/application-development/advanced/pipeline-manipulation.html?gi-language=c>
1 parent 6736795 commit f34367a

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ else # not Linux
9999
endif
100100

101101
subdir ('src')
102-
subdir ('tests')
103102

104103
viewer_enabled = false
105104
viewer_option = get_option ('viewer')
@@ -116,6 +115,8 @@ gst_deps = aravis_dependencies + [dependency ('gstreamer-base-1.0', required: gs
116115
dependency ('gstreamer-app-1.0', required: gst_option)]
117116
subdir('gst', if_found: gst_deps)
118117

118+
subdir ('tests')
119+
119120
doc_deps = dependency ('gi-docgen', version:'>= 2021.1', fallback: ['gi-docgen', 'dummy_dep'], required:get_option('documentation'))
120121
subdir('docs', if_found: doc_deps)
121122

tests/arvgsttest.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/* Simple script which will start an aravis pipeline, then restart ONLY the camera. */
2+
#include <gst/gst.h>
3+
#include <stdio.h>
4+
#include <unistd.h>
5+
6+
int
7+
main (int argc, char *argv[])
8+
{
9+
GstElement *pipeline;
10+
GstElement *source;
11+
GstElement *sink;
12+
GstElement *new_source;
13+
GstState current_state, pending_state;
14+
15+
gst_init (&argc, &argv);
16+
17+
pipeline = gst_pipeline_new ("aravis_pipeline");
18+
source = gst_element_factory_make ("aravissrc", "source");
19+
if (!source) {
20+
printf ("Failed to create the source element\n");
21+
return EXIT_FAILURE;
22+
}
23+
24+
g_object_set(G_OBJECT(source),
25+
"camera-name", "Aravis-Fake-GV01",
26+
"num-arv-buffers", 5,
27+
"packet-resend", FALSE,
28+
"packet-size", 9000,
29+
"auto-packet-size", FALSE,
30+
NULL);
31+
32+
sink = gst_element_factory_make ("fakesink", "fake_sink");
33+
34+
if (!pipeline || !source || !sink) {
35+
printf ("Not all elements could be created.\n");
36+
return EXIT_FAILURE;
37+
}
38+
39+
gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);
40+
41+
if (!gst_element_link (source, sink)) {
42+
printf ("Elements could not be linked.\n");
43+
gst_object_unref (pipeline);
44+
return EXIT_FAILURE;
45+
}
46+
47+
printf ("Start the pipeline\n");
48+
g_assert_cmpint (gst_element_set_state(pipeline, GST_STATE_PLAYING), ==, GST_STATE_CHANGE_ASYNC);
49+
50+
printf ("Wait for a few frames\n");
51+
sleep (1);
52+
53+
printf ("Stop the source\n");
54+
g_assert_cmpint (gst_element_set_state(source, GST_STATE_NULL), ==, GST_STATE_CHANGE_SUCCESS);
55+
56+
gst_element_get_state (source, &current_state, &pending_state, 0);
57+
printf ("source current state:%d - pending state:%d\n", current_state, pending_state);
58+
59+
sleep (1);
60+
61+
gst_element_unlink(source, sink);
62+
g_assert (gst_bin_remove(GST_BIN(pipeline), source));
63+
64+
printf ("Create a new source\n");
65+
new_source = gst_element_factory_make ("aravissrc", "new_source");
66+
if (!new_source) {
67+
printf ("Failed to create the source element\n");
68+
return EXIT_FAILURE;
69+
}
70+
g_object_set(G_OBJECT(new_source),
71+
"camera-name", "Aravis-Fake-GV01",
72+
"num-arv-buffers", 5,
73+
"packet-resend", FALSE,
74+
"packet-size", 9000,
75+
"auto-packet-size", FALSE,
76+
NULL);
77+
78+
g_assert (gst_bin_add(GST_BIN(pipeline), new_source));
79+
g_assert (gst_element_link(new_source, sink));
80+
g_assert (gst_element_sync_state_with_parent(new_source));
81+
82+
gst_element_get_state (source, &current_state, &pending_state, 0);
83+
printf ("new source current state:%d - pending state:%d\n", current_state, pending_state);
84+
85+
printf ("Start the new source\n");
86+
g_assert_cmpint (gst_element_set_state(source, GST_STATE_PLAYING), ==, GST_STATE_CHANGE_SUCCESS);
87+
88+
gst_element_get_state (source, &current_state, &pending_state, 0);
89+
printf ("new source current state:%d - pending state:%d\n", current_state, pending_state);
90+
91+
printf ("Wait for a few frames\n");
92+
93+
printf ("Stop the pipeline\n");
94+
g_assert_cmpint (gst_element_set_state (pipeline, GST_STATE_NULL), ==, GST_STATE_CHANGE_SUCCESS);
95+
96+
printf ("Free the pipeline\n");
97+
gst_object_unref (pipeline);
98+
99+
return EXIT_SUCCESS;
100+
}

tests/meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,12 @@ if get_option('tests')
101101
include_directories: [library_inc])
102102
endforeach
103103

104+
if gst_enabled
105+
executable ('arv-gst-test', 'arvgsttest.c',
106+
link_with: aravis_library,
107+
dependencies: aravis_dependencies + gst_deps,
108+
include_directories: [library_inc])
109+
110+
endif
111+
104112
endif

0 commit comments

Comments
 (0)