|
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., 59 Temple Place - Suite 330, |
|
19 * Boston, MA 02111-1307, USA. |
|
20 */ |
|
21 |
|
22 |
|
23 #include <gst/check/gstcheck.h> |
|
24 |
|
25 #ifndef GST_DISABLE_PARSE |
|
26 |
|
27 static GstElement * |
|
28 setup_pipeline (const gchar * pipe_descr) |
|
29 { |
|
30 GstElement *pipeline; |
|
31 |
|
32 GST_LOG ("pipeline: %s", pipe_descr); |
|
33 pipeline = gst_parse_launch (pipe_descr, NULL); |
|
34 g_return_val_if_fail (GST_IS_PIPELINE (pipeline), NULL); |
|
35 return pipeline; |
|
36 } |
|
37 |
|
38 /* |
|
39 * run_pipeline: |
|
40 * @pipe: the pipeline to run |
|
41 * @desc: the description for use in messages |
|
42 * @events: is a mask of expected events |
|
43 * @tevent: is the expected terminal event. |
|
44 * |
|
45 * the poll call will time out after half a second. |
|
46 */ |
|
47 static void |
|
48 run_pipeline (GstElement * pipe, const gchar * descr, |
|
49 GstMessageType events, GstMessageType tevent) |
|
50 { |
|
51 GstBus *bus; |
|
52 GstMessage *message; |
|
53 GstMessageType revent; |
|
54 GstStateChangeReturn ret; |
|
55 |
|
56 g_assert (pipe); |
|
57 bus = gst_element_get_bus (pipe); |
|
58 g_assert (bus); |
|
59 |
|
60 fail_if (gst_element_set_state (pipe, GST_STATE_PLAYING) == |
|
61 GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to playing", descr); |
|
62 ret = gst_element_get_state (pipe, NULL, NULL, 10 * GST_SECOND); |
|
63 if (ret == GST_STATE_CHANGE_ASYNC) { |
|
64 g_critical ("Pipeline '%s' failed to go to PLAYING fast enough", descr); |
|
65 goto done; |
|
66 } else if (ret != GST_STATE_CHANGE_SUCCESS) { |
|
67 g_critical ("Pipeline '%s' failed to go into PLAYING state", descr); |
|
68 goto done; |
|
69 } |
|
70 |
|
71 while (1) { |
|
72 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2); |
|
73 |
|
74 |
|
75 /* always have to pop the message before getting back into poll */ |
|
76 if (message) { |
|
77 revent = GST_MESSAGE_TYPE (message); |
|
78 gst_message_unref (message); |
|
79 } else { |
|
80 revent = GST_MESSAGE_UNKNOWN; |
|
81 } |
|
82 |
|
83 if (revent == tevent) { |
|
84 break; |
|
85 } else if (revent == GST_MESSAGE_UNKNOWN) { |
|
86 g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s", |
|
87 tevent, descr); |
|
88 break; |
|
89 } else if (revent & events) { |
|
90 continue; |
|
91 } |
|
92 g_critical |
|
93 ("Unexpected message received of type %d, '%s', looking for %d: %s", |
|
94 revent, gst_message_type_get_name (revent), tevent, descr); |
|
95 } |
|
96 |
|
97 done: |
|
98 fail_if (gst_element_set_state (pipe, GST_STATE_NULL) == |
|
99 GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to NULL", descr); |
|
100 gst_element_get_state (pipe, NULL, NULL, GST_CLOCK_TIME_NONE); |
|
101 gst_object_unref (pipe); |
|
102 |
|
103 gst_bus_set_flushing (bus, TRUE); |
|
104 gst_object_unref (bus); |
|
105 } |
|
106 |
|
107 GST_START_TEST (test_element_negotiation) |
|
108 { |
|
109 gchar *s; |
|
110 |
|
111 /* Ensures that filtering buffers with unknown caps down to fixed-caps |
|
112 * will apply those caps to the buffers. |
|
113 * see http://bugzilla.gnome.org/show_bug.cgi?id=315126 */ |
|
114 s = "fakesrc num-buffers=2 ! " |
|
115 "audio/x-raw-int,width=16,depth=16,rate=22050,channels=1," |
|
116 "signed=(boolean)true,endianness=1234 ! " |
|
117 "audioconvert ! audio/x-raw-int,width=16,depth=16,rate=22050,channels=1 " |
|
118 "! 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 ! ffmpegcolorspace ! 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 |
|
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-yuv,format=(fourcc)I420,width=320,height=240 ! " |
|
144 "videoscale ! video/x-raw-yuv,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 ffmpegcolorspace 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-yuv,format=(fourcc)I420,width=320,height=240 ! " |
|
153 "ffmpegcolorspace ! video/x-raw-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-int,width=16,depth=16,rate=8000 ! " |
|
162 "audioresample ! audio/x-raw-int,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-int,width=16,depth=16 ! " |
|
169 "audioconvert ! " "audio/x-raw-int,width=32 ! fakesink"; |
|
170 run_pipeline (setup_pipeline (s), s, |
|
171 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING), |
|
172 GST_MESSAGE_UNKNOWN); |
|
173 |
|
174 /* Check that videoscale doesn't claim to be able to transform input in |
|
175 * formats it can't handle for a given scaling method; ffmpegcolorspace |
|
176 * should then make sure a format that can be handled is chosen (4-tap |
|
177 * scaling is not implemented for RGB and packed yuv currently) */ |
|
178 s = "videotestsrc num-buffers=2 ! video/x-raw-rgb,width=64,height=64 ! " |
|
179 "ffmpegcolorspace ! videoscale method=4-tap ! ffmpegcolorspace ! " |
|
180 "video/x-raw-rgb,width=32,height=32,framerate=(fraction)30/1," |
|
181 "pixel-aspect-ratio=(fraction)1/1,bpp=(int)24,depth=(int)24," |
|
182 "red_mask=(int)16711680,green_mask=(int)65280,blue_mask=(int)255," |
|
183 "endianness=(int)4321 ! fakesink"; |
|
184 run_pipeline (setup_pipeline (s), s, |
|
185 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING), |
|
186 GST_MESSAGE_UNKNOWN); |
|
187 s = "videotestsrc num-buffers=2 ! video/x-raw-yuv,format=(fourcc)AYUV," |
|
188 "width=64,height=64 ! ffmpegcolorspace ! videoscale method=4-tap ! " |
|
189 "ffmpegcolorspace ! video/x-raw-yuv,format=(fourcc)AYUV,width=32," |
|
190 "height=32 ! fakesink"; |
|
191 run_pipeline (setup_pipeline (s), s, |
|
192 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING), |
|
193 GST_MESSAGE_UNKNOWN); |
|
194 /* make sure nothing funny happens in passthrough mode (we don't check that |
|
195 * passthrough mode is chosen though) */ |
|
196 s = "videotestsrc num-buffers=2 ! video/x-raw-yuv,format=(fourcc)I420," |
|
197 "width=64,height=64 ! ffmpegcolorspace ! videoscale method=4-tap ! " |
|
198 "ffmpegcolorspace ! video/x-raw-yuv,format=(fourcc)I420,width=32," |
|
199 "height=32 ! fakesink"; |
|
200 run_pipeline (setup_pipeline (s), s, |
|
201 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING), |
|
202 GST_MESSAGE_UNKNOWN); |
|
203 } |
|
204 |
|
205 GST_END_TEST; |
|
206 |
|
207 #endif /* #ifndef GST_DISABLE_PARSE */ |
|
208 static Suite * |
|
209 simple_launch_lines_suite (void) |
|
210 { |
|
211 Suite *s = suite_create ("Pipelines"); |
|
212 TCase *tc_chain = tcase_create ("linear"); |
|
213 |
|
214 /* time out after 60s, not the default 3 */ |
|
215 tcase_set_timeout (tc_chain, 60); |
|
216 |
|
217 suite_add_tcase (s, tc_chain); |
|
218 #ifndef GST_DISABLE_PARSE |
|
219 tcase_add_test (tc_chain, test_element_negotiation); |
|
220 tcase_add_test (tc_chain, test_basetransform_based); |
|
221 #endif |
|
222 return s; |
|
223 } |
|
224 |
|
225 int |
|
226 main (int argc, char **argv) |
|
227 { |
|
228 int nf; |
|
229 |
|
230 Suite *s = simple_launch_lines_suite (); |
|
231 SRunner *sr = srunner_create (s); |
|
232 |
|
233 gst_check_init (&argc, &argv); |
|
234 |
|
235 srunner_run_all (sr, CK_NORMAL); |
|
236 nf = srunner_ntests_failed (sr); |
|
237 srunner_free (sr); |
|
238 |
|
239 return nf; |
|
240 } |