2 * Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
4 * simple_launch_lines.c: Unit test for simple pipelines
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.
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.
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.
23 #include <gst/check/gstcheck.h>
24 #include <gst/audio/audio-format.h>
26 #ifndef GST_DISABLE_PARSE
29 setup_pipeline (const gchar * pipe_descr)
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);
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.
46 * the poll call will time out after half a second.
49 run_pipeline (GstElement * pipe, const gchar * descr,
50 GstMessageType events, GstMessageType tevent)
54 GstMessageType revent;
55 GstStateChangeReturn ret;
58 bus = gst_element_get_bus (pipe);
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);
67 } else if (ret != GST_STATE_CHANGE_SUCCESS) {
68 g_critical ("Pipeline '%s' failed to go into PLAYING state", descr);
73 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
76 /* always have to pop the message before getting back into poll */
78 revent = GST_MESSAGE_TYPE (message);
79 gst_message_unref (message);
81 revent = GST_MESSAGE_UNKNOWN;
84 if (revent == tevent) {
86 } else if (revent == GST_MESSAGE_UNKNOWN) {
87 g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
90 } else if (revent & events) {
94 ("Unexpected message received of type %d, '%s', looking for %d: %s",
95 revent, gst_message_type_get_name (revent), tevent, descr);
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);
104 gst_bus_set_flushing (bus, TRUE);
105 gst_object_unref (bus);
108 GST_START_TEST (test_element_negotiation)
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);
123 /* FIXME: don't use real audio/video outputs */
126 gboolean have_libvisual_lv_scope;
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);
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);
145 GST_START_TEST (test_basetransform_based)
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 */
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);
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);
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);
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)
182 run_pipeline (setup_pipeline (s), s,
183 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
184 GST_MESSAGE_UNKNOWN);
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);
217 #endif /* #ifndef GST_DISABLE_PARSE */
219 simple_launch_lines_suite (void)
221 Suite *s = suite_create ("Pipelines");
222 TCase *tc_chain = tcase_create ("linear");
224 /* time out after 60s, not the default 3 */
225 tcase_set_timeout (tc_chain, 60);
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);
235 GST_CHECK_MAIN (simple_launch_lines);