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 #ifdef HAVE_LIBVISUAL
124   s = "audiotestsrc num-buffers=30 ! tee name=t ! alsasink t. ! audioconvert ! "
125       "libvisual_lv_scope ! videoconvert ! xvimagesink";
126   run_pipeline (setup_pipeline (s), s,
127       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
128       GST_MESSAGE_UNKNOWN);
129 #endif
130 }
131 
132 GST_END_TEST;
133 
GST_START_TEST(test_basetransform_based)134 GST_START_TEST (test_basetransform_based)
135 {
136   /* Each of these tests is to check whether various basetransform based
137    * elements can select output caps when not allowed to do passthrough
138    * and going to a generic sink such as fakesink or filesink */
139   const gchar *s;
140 
141   /* Check that videoscale can pick a height given only a width */
142   s = "videotestsrc num-buffers=2 ! "
143       "video/x-raw,format=(string)I420,width=320,height=240 ! "
144       "videoscale ! video/x-raw,width=640 ! fakesink";
145   run_pipeline (setup_pipeline (s), s,
146       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
147       GST_MESSAGE_UNKNOWN);
148 
149   /* Test that videoconvert can pick an output format that isn't
150    * passthrough without completely specified output caps */
151   s = "videotestsrc num-buffers=2 ! "
152       "video/x-raw,format=(string)I420,width=320,height=240 ! "
153       "videoconvert ! video/x-raw,format=(string)RGB ! fakesink";
154   run_pipeline (setup_pipeline (s), s,
155       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
156       GST_MESSAGE_UNKNOWN);
157 
158   /* Check that audioresample can pick a samplerate to use from a
159    * range that doesn't include the input */
160   s = "audiotestsrc num-buffers=2 ! "
161       "audio/x-raw,format=" GST_AUDIO_NE (S16) ",rate=8000 ! "
162       "audioresample ! audio/x-raw,rate=[16000,48000] ! fakesink";
163   run_pipeline (setup_pipeline (s), s,
164       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
165       GST_MESSAGE_UNKNOWN);
166 
167   /* Check that audioconvert can pick a depth to use, given a width */
168   s = "audiotestsrc num-buffers=30 ! audio/x-raw,format=" GST_AUDIO_NE (S16)
169       " ! audioconvert ! " "audio/x-raw,format=" GST_AUDIO_NE (S32)
170       " ! fakesink";
171   run_pipeline (setup_pipeline (s), s,
172       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
173       GST_MESSAGE_UNKNOWN);
174 
175   /* Check that videoscale doesn't claim to be able to transform input in
176    * formats it can't handle for a given scaling method; videoconvert
177    * should then make sure a format that can be handled is chosen (4-tap
178    * scaling is not implemented for RGB and packed yuv currently) */
179   s = "videotestsrc num-buffers=2 ! video/x-raw,format=(string)ARGB64 ! "
180       "videoconvert ! videoscale method=4-tap ! videoconvert ! "
181       "video/x-raw,format=(string)RGB, width=32,height=32,framerate=(fraction)30/1,"
182       "pixel-aspect-ratio=(fraction)1/1 ! fakesink";
183   run_pipeline (setup_pipeline (s), s,
184       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
185       GST_MESSAGE_UNKNOWN);
186   s = "videotestsrc num-buffers=2 ! video/x-raw,format=(string)AYUV,"
187       "width=64,height=64 ! videoconvert ! videoscale method=4-tap ! "
188       "videoconvert ! video/x-raw,format=(string)AYUV,width=32,"
189       "height=32 ! fakesink";
190   run_pipeline (setup_pipeline (s), s,
191       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
192       GST_MESSAGE_UNKNOWN);
193   /* make sure nothing funny happens in passthrough mode (we don't check that
194    * passthrough mode is chosen though) */
195   s = "videotestsrc num-buffers=2 ! video/x-raw,format=(string)I420,"
196       "width=64,height=64 ! videoconvert ! videoscale method=4-tap ! "
197       "videoconvert ! video/x-raw,format=(string)I420,width=32,"
198       "height=32 ! fakesink";
199   run_pipeline (setup_pipeline (s), s,
200       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
201       GST_MESSAGE_UNKNOWN);
202 }
203 
204 GST_END_TEST;
205 
206 #endif /* #ifndef GST_DISABLE_PARSE */
207 static Suite *
simple_launch_lines_suite(void)208 simple_launch_lines_suite (void)
209 {
210   Suite *s = suite_create ("Pipelines");
211   TCase *tc_chain = tcase_create ("linear");
212 
213   /* time out after 60s, not the default 3 */
214   tcase_set_timeout (tc_chain, 60);
215 
216   suite_add_tcase (s, tc_chain);
217 #ifndef GST_DISABLE_PARSE
218   tcase_add_test (tc_chain, test_element_negotiation);
219   tcase_add_test (tc_chain, test_basetransform_based);
220 #endif
221   return s;
222 }
223 
224 GST_CHECK_MAIN (simple_launch_lines);
225