1 /* GStreamer
2 * Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
3 *
4 * simple_launch_lines.c: Unit test for simple pipelines
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22
23 #include <gst/check/gstcheck.h>
24 #include <gst/audio/audio-format.h>
25
26 #ifndef GST_DISABLE_PARSE
27
28 static GstElement *
setup_pipeline(const gchar * pipe_descr)29 setup_pipeline (const gchar * pipe_descr)
30 {
31 GstElement *pipeline;
32
33 GST_LOG ("pipeline: %s", pipe_descr);
34 pipeline = gst_parse_launch (pipe_descr, NULL);
35 g_return_val_if_fail (GST_IS_PIPELINE (pipeline), NULL);
36 return pipeline;
37 }
38
39 /*
40 * run_pipeline:
41 * @pipe: the pipeline to run
42 * @desc: the description for use in messages
43 * @events: is a mask of expected events
44 * @tevent: is the expected terminal event.
45 *
46 * the poll call will time out after half a second.
47 */
48 static void
run_pipeline(GstElement * pipe,const gchar * descr,GstMessageType events,GstMessageType tevent)49 run_pipeline (GstElement * pipe, const gchar * descr,
50 GstMessageType events, GstMessageType tevent)
51 {
52 GstBus *bus;
53 GstMessage *message;
54 GstMessageType revent;
55 GstStateChangeReturn ret;
56
57 g_assert (pipe);
58 bus = gst_element_get_bus (pipe);
59 g_assert (bus);
60
61 fail_if (gst_element_set_state (pipe, GST_STATE_PLAYING) ==
62 GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to playing", descr);
63 ret = gst_element_get_state (pipe, NULL, NULL, 10 * GST_SECOND);
64 if (ret == GST_STATE_CHANGE_ASYNC) {
65 g_critical ("Pipeline '%s' failed to go to PLAYING fast enough", descr);
66 goto done;
67 } else if (ret != GST_STATE_CHANGE_SUCCESS) {
68 g_critical ("Pipeline '%s' failed to go into PLAYING state", descr);
69 goto done;
70 }
71
72 while (1) {
73 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
74
75
76 /* always have to pop the message before getting back into poll */
77 if (message) {
78 revent = GST_MESSAGE_TYPE (message);
79 gst_message_unref (message);
80 } else {
81 revent = GST_MESSAGE_UNKNOWN;
82 }
83
84 if (revent == tevent) {
85 break;
86 } else if (revent == GST_MESSAGE_UNKNOWN) {
87 g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
88 tevent, descr);
89 break;
90 } else if (revent & events) {
91 continue;
92 }
93 g_critical
94 ("Unexpected message received of type %d, '%s', looking for %d: %s",
95 revent, gst_message_type_get_name (revent), tevent, descr);
96 }
97
98 done:
99 fail_if (gst_element_set_state (pipe, GST_STATE_NULL) ==
100 GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to NULL", descr);
101 gst_element_get_state (pipe, NULL, NULL, GST_CLOCK_TIME_NONE);
102 gst_object_unref (pipe);
103
104 gst_bus_set_flushing (bus, TRUE);
105 gst_object_unref (bus);
106 }
107
GST_START_TEST(test_element_negotiation)108 GST_START_TEST (test_element_negotiation)
109 {
110 const gchar *s;
111
112 /* Ensures that filtering buffers with unknown caps down to fixed-caps
113 * will apply those caps to the buffers.
114 * see http://bugzilla.gnome.org/show_bug.cgi?id=315126 */
115 s = "fakesrc num-buffers=2 ! " "audio/x-raw,format=" GST_AUDIO_NE (S16)
116 ",rate=22050,channels=1,layout=interleaved " "! audioconvert "
117 "! audio/x-raw,format=" GST_AUDIO_NE (S16)
118 ",rate=22050,channels=1,layout=interleaved " "! fakesink";
119 run_pipeline (setup_pipeline (s), s,
120 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
121 GST_MESSAGE_UNKNOWN);
122
123 /* FIXME: don't use real audio/video outputs */
124 #if 0
125 {
126 gboolean have_libvisual_lv_scope;
127
128 have_libvisual_lv_scope =
129 gst_registry_check_feature_version (gst_registry_get (),
130 "libvisual_lv_scope", GST_VERSION_MAJOR, GST_VERSION_MINOR, 0);
131
132 if (have_libvisual_lv_scope) {
133 s = "audiotestsrc num-buffers=30 ! tee name=t ! alsasink t. ! "
134 "audioconvert ! libvisual_lv_scope ! videoconvert ! xvimagesink";
135 run_pipeline (setup_pipeline (s), s,
136 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
137 GST_MESSAGE_UNKNOWN);
138 }
139 }
140 #endif
141 }
142
143 GST_END_TEST;
144
GST_START_TEST(test_basetransform_based)145 GST_START_TEST (test_basetransform_based)
146 {
147 /* Each of these tests is to check whether various basetransform based
148 * elements can select output caps when not allowed to do passthrough
149 * and going to a generic sink such as fakesink or filesink */
150 const gchar *s;
151
152 /* Check that videoscale can pick a height given only a width */
153 s = "videotestsrc num-buffers=2 ! "
154 "video/x-raw,format=(string)I420,width=320,height=240 ! "
155 "videoscale ! video/x-raw,width=640 ! fakesink";
156 run_pipeline (setup_pipeline (s), s,
157 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
158 GST_MESSAGE_UNKNOWN);
159
160 /* Test that videoconvert can pick an output format that isn't
161 * passthrough without completely specified output caps */
162 s = "videotestsrc num-buffers=2 ! "
163 "video/x-raw,format=(string)I420,width=320,height=240 ! "
164 "videoconvert ! video/x-raw,format=(string)RGB ! fakesink";
165 run_pipeline (setup_pipeline (s), s,
166 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
167 GST_MESSAGE_UNKNOWN);
168
169 /* Check that audioresample can pick a samplerate to use from a
170 * range that doesn't include the input */
171 s = "audiotestsrc num-buffers=2 ! "
172 "audio/x-raw,format=" GST_AUDIO_NE (S16) ",rate=8000 ! "
173 "audioresample ! audio/x-raw,rate=[16000,48000] ! fakesink";
174 run_pipeline (setup_pipeline (s), s,
175 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
176 GST_MESSAGE_UNKNOWN);
177
178 /* Check that audioconvert can pick a depth to use, given a width */
179 s = "audiotestsrc num-buffers=30 ! audio/x-raw,format=" GST_AUDIO_NE (S16)
180 " ! audioconvert ! " "audio/x-raw,format=" GST_AUDIO_NE (S32)
181 " ! fakesink";
182 run_pipeline (setup_pipeline (s), s,
183 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
184 GST_MESSAGE_UNKNOWN);
185
186 /* Check that videoscale doesn't claim to be able to transform input in
187 * formats it can't handle for a given scaling method; videoconvert
188 * should then make sure a format that can be handled is chosen (4-tap
189 * scaling is not implemented for RGB and packed yuv currently) */
190 s = "videotestsrc num-buffers=2 ! video/x-raw,format=(string)ARGB64 ! "
191 "videoconvert ! videoscale method=4-tap ! videoconvert ! "
192 "video/x-raw,format=(string)RGB, width=32,height=32,framerate=(fraction)30/1,"
193 "pixel-aspect-ratio=(fraction)1/1 ! fakesink";
194 run_pipeline (setup_pipeline (s), s,
195 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
196 GST_MESSAGE_UNKNOWN);
197 s = "videotestsrc num-buffers=2 ! video/x-raw,format=(string)AYUV,"
198 "width=64,height=64 ! videoconvert ! videoscale method=4-tap ! "
199 "videoconvert ! video/x-raw,format=(string)AYUV,width=32,"
200 "height=32 ! fakesink";
201 run_pipeline (setup_pipeline (s), s,
202 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
203 GST_MESSAGE_UNKNOWN);
204 /* make sure nothing funny happens in passthrough mode (we don't check that
205 * passthrough mode is chosen though) */
206 s = "videotestsrc num-buffers=2 ! video/x-raw,format=(string)I420,"
207 "width=64,height=64 ! videoconvert ! videoscale method=4-tap ! "
208 "videoconvert ! video/x-raw,format=(string)I420,width=32,"
209 "height=32 ! fakesink";
210 run_pipeline (setup_pipeline (s), s,
211 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
212 GST_MESSAGE_UNKNOWN);
213 }
214
215 GST_END_TEST;
216
217 #endif /* #ifndef GST_DISABLE_PARSE */
218 static Suite *
simple_launch_lines_suite(void)219 simple_launch_lines_suite (void)
220 {
221 Suite *s = suite_create ("Pipelines");
222 TCase *tc_chain = tcase_create ("linear");
223
224 /* time out after 60s, not the default 3 */
225 tcase_set_timeout (tc_chain, 60);
226
227 suite_add_tcase (s, tc_chain);
228 #ifndef GST_DISABLE_PARSE
229 tcase_add_test (tc_chain, test_element_negotiation);
230 tcase_add_test (tc_chain, test_basetransform_based);
231 #endif
232 return s;
233 }
234
235 GST_CHECK_MAIN (simple_launch_lines);
236