1 /* GStreamer
2 * Copyright (C) 2008 Sebastian Dröge <slomo@circular-chaos.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include <gst/check/gstcheck.h>
21
22 static gboolean found_fingerprint = FALSE;
23
24 static gboolean
bus_handler(GstBus * bus,GstMessage * message,gpointer data)25 bus_handler (GstBus * bus, GstMessage * message, gpointer data)
26 {
27 GMainLoop *loop = (GMainLoop *) data;
28
29 switch (message->type) {
30 case GST_MESSAGE_EOS:
31 g_main_loop_quit (loop);
32 break;
33 case GST_MESSAGE_WARNING:
34 case GST_MESSAGE_ERROR:{
35 GError *gerror;
36 gchar *debug;
37
38 if (message->type == GST_MESSAGE_WARNING)
39 gst_message_parse_warning (message, &gerror, &debug);
40 else
41 gst_message_parse_error (message, &gerror, &debug);
42 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
43 g_error_free (gerror);
44 g_free (debug);
45 g_main_loop_quit (loop);
46 break;
47 }
48 case GST_MESSAGE_TAG:
49 {
50 GstTagList *tag_list;
51 gchar *fpr, *p;
52
53 gst_message_parse_tag (message, &tag_list);
54
55 GST_DEBUG ("tag message: %" GST_PTR_FORMAT, tag_list);
56
57 if (!gst_tag_list_get_value_index (tag_list, "ofa-fingerprint", 0)) {
58 gst_tag_list_unref (tag_list);
59 break;
60 }
61
62 fail_unless (gst_tag_list_get_string (tag_list, "ofa-fingerprint", &fpr));
63
64 p = fpr;
65 while (*p) {
66 fail_unless (g_ascii_isalnum (*p) || *p == '=' || *p == '+'
67 || *p == '/');
68 p++;
69 }
70
71 g_free (fpr);
72 gst_tag_list_unref (tag_list);
73
74 found_fingerprint = TRUE;
75
76 g_main_loop_quit (loop);
77 break;
78 }
79 default:
80 break;
81 }
82
83 return TRUE;
84 }
85
GST_START_TEST(test_ofa_le_1ch)86 GST_START_TEST (test_ofa_le_1ch)
87 {
88 GstElement *pipeline;
89 GstElement *audiotestsrc, *audioconvert, *capsfilter, *ofa, *fakesink;
90
91 GstBus *bus;
92 GMainLoop *loop;
93 GstCaps *caps;
94 gint64 position;
95 GstFormat fmt = GST_FORMAT_TIME;
96 guint bus_watch = 0;
97
98 pipeline = gst_pipeline_new ("pipeline");
99 fail_unless (pipeline != NULL);
100
101 audiotestsrc = gst_element_factory_make ("audiotestsrc", "src");
102 fail_unless (audiotestsrc != NULL);
103 g_object_set (G_OBJECT (audiotestsrc), "wave", 0, "freq", 440.0, NULL);
104
105 audioconvert = gst_element_factory_make ("audioconvert", "audioconvert");
106 fail_unless (audioconvert != NULL);
107 g_object_set (G_OBJECT (audioconvert), "dithering", 0, NULL);
108
109 capsfilter = gst_element_factory_make ("capsfilter", "capsfilter");
110 fail_unless (capsfilter != NULL);
111 caps = gst_caps_new_simple ("audio/x-raw", "format", G_TYPE_STRING, "S16LE",
112 "rate", G_TYPE_INT, 44100, "channels", G_TYPE_INT, 1, NULL);
113 g_object_set (G_OBJECT (capsfilter), "caps", caps, NULL);
114 gst_caps_unref (caps);
115
116 ofa = gst_element_factory_make ("ofa", "ofa");
117 fail_unless (ofa != NULL);
118
119 fakesink = gst_element_factory_make ("fakesink", "sink");
120 fail_unless (fakesink != NULL);
121
122 gst_bin_add_many (GST_BIN (pipeline), audiotestsrc, audioconvert, capsfilter,
123 ofa, fakesink, NULL);
124
125 fail_unless (gst_element_link_many (audiotestsrc, audioconvert, capsfilter,
126 ofa, fakesink, NULL));
127
128 loop = g_main_loop_new (NULL, TRUE);
129 fail_unless (loop != NULL);
130
131 bus = gst_element_get_bus (pipeline);
132 fail_unless (bus != NULL);
133 bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
134 gst_object_unref (bus);
135
136 found_fingerprint = FALSE;
137 gst_element_set_state (pipeline, GST_STATE_PLAYING);
138 g_main_loop_run (loop);
139
140 fail_unless (gst_element_query_position (audiotestsrc, fmt, &position));
141 fail_unless (position >= 135 * GST_SECOND);
142
143 gst_element_set_state (pipeline, GST_STATE_NULL);
144
145 fail_unless (found_fingerprint == TRUE);
146 g_object_unref (pipeline);
147 g_main_loop_unref (loop);
148 g_source_remove (bus_watch);
149 }
150
151 GST_END_TEST;
152
153
GST_START_TEST(test_ofa_be_1ch)154 GST_START_TEST (test_ofa_be_1ch)
155 {
156 GstElement *pipeline;
157 GstElement *audiotestsrc, *audioconvert, *capsfilter, *ofa, *fakesink;
158 GstBus *bus;
159 GMainLoop *loop;
160 GstCaps *caps;
161 gint64 position;
162 GstFormat fmt = GST_FORMAT_TIME;
163 guint bus_watch = 0;
164
165 pipeline = gst_pipeline_new ("pipeline");
166 fail_unless (pipeline != NULL);
167
168 audiotestsrc = gst_element_factory_make ("audiotestsrc", "src");
169 fail_unless (audiotestsrc != NULL);
170 g_object_set (G_OBJECT (audiotestsrc), "wave", 0, "freq", 440.0, NULL);
171
172 audioconvert = gst_element_factory_make ("audioconvert", "audioconvert");
173 fail_unless (audioconvert != NULL);
174 g_object_set (G_OBJECT (audioconvert), "dithering", 0, NULL);
175
176 capsfilter = gst_element_factory_make ("capsfilter", "capsfilter");
177 fail_unless (capsfilter != NULL);
178 caps = gst_caps_new_simple ("audio/x-raw", "format", G_TYPE_STRING, "S16BE",
179 "rate", G_TYPE_INT, 44100, "channels", G_TYPE_INT, 1, NULL);
180 g_object_set (G_OBJECT (capsfilter), "caps", caps, NULL);
181 gst_caps_unref (caps);
182
183 ofa = gst_element_factory_make ("ofa", "ofa");
184 fail_unless (ofa != NULL);
185
186 fakesink = gst_element_factory_make ("fakesink", "sink");
187 fail_unless (fakesink != NULL);
188
189 gst_bin_add_many (GST_BIN (pipeline), audiotestsrc, audioconvert, capsfilter,
190 ofa, fakesink, NULL);
191
192 fail_unless (gst_element_link_many (audiotestsrc, audioconvert, capsfilter,
193 ofa, fakesink, NULL));
194
195 loop = g_main_loop_new (NULL, TRUE);
196 fail_unless (loop != NULL);
197
198 bus = gst_element_get_bus (pipeline);
199 fail_unless (bus != NULL);
200 bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
201 gst_object_unref (bus);
202
203 found_fingerprint = FALSE;
204 gst_element_set_state (pipeline, GST_STATE_PLAYING);
205 g_main_loop_run (loop);
206
207 fail_unless (gst_element_query_position (audiotestsrc, fmt, &position));
208 fail_unless (position >= 135 * GST_SECOND);
209
210 gst_element_set_state (pipeline, GST_STATE_NULL);
211
212 fail_unless (found_fingerprint == TRUE);
213 g_object_unref (pipeline);
214 g_main_loop_unref (loop);
215 g_source_remove (bus_watch);
216 }
217
218 GST_END_TEST;
219
GST_START_TEST(test_ofa_le_2ch)220 GST_START_TEST (test_ofa_le_2ch)
221 {
222 GstElement *pipeline;
223 GstElement *audiotestsrc, *audioconvert, *capsfilter, *ofa, *fakesink;
224 GstBus *bus;
225 GMainLoop *loop;
226 GstCaps *caps;
227 gint64 position;
228 GstFormat fmt = GST_FORMAT_TIME;
229 guint bus_watch = 0;
230
231 pipeline = gst_pipeline_new ("pipeline");
232 fail_unless (pipeline != NULL);
233
234 audiotestsrc = gst_element_factory_make ("audiotestsrc", "src");
235 fail_unless (audiotestsrc != NULL);
236 g_object_set (G_OBJECT (audiotestsrc), "wave", 0, "freq", 440.0, NULL);
237
238 audioconvert = gst_element_factory_make ("audioconvert", "audioconvert");
239 fail_unless (audioconvert != NULL);
240 g_object_set (G_OBJECT (audioconvert), "dithering", 0, NULL);
241
242 capsfilter = gst_element_factory_make ("capsfilter", "capsfilter");
243 fail_unless (capsfilter != NULL);
244 caps = gst_caps_new_simple ("audio/x-raw", "format", G_TYPE_STRING, "S16LE",
245 "rate", G_TYPE_INT, 44100, "channels", G_TYPE_INT, 2, NULL);
246 g_object_set (G_OBJECT (capsfilter), "caps", caps, NULL);
247 gst_caps_unref (caps);
248
249 ofa = gst_element_factory_make ("ofa", "ofa");
250 fail_unless (ofa != NULL);
251
252 fakesink = gst_element_factory_make ("fakesink", "sink");
253 fail_unless (fakesink != NULL);
254
255 gst_bin_add_many (GST_BIN (pipeline), audiotestsrc, audioconvert, capsfilter,
256 ofa, fakesink, NULL);
257
258 fail_unless (gst_element_link_many (audiotestsrc, audioconvert, capsfilter,
259 ofa, fakesink, NULL));
260
261 loop = g_main_loop_new (NULL, TRUE);
262 fail_unless (loop != NULL);
263
264 bus = gst_element_get_bus (pipeline);
265 fail_unless (bus != NULL);
266 bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
267 gst_object_unref (bus);
268
269 found_fingerprint = FALSE;
270 gst_element_set_state (pipeline, GST_STATE_PLAYING);
271 g_main_loop_run (loop);
272
273 fail_unless (gst_element_query_position (audiotestsrc, fmt, &position));
274 fail_unless (position >= 135 * GST_SECOND);
275
276 gst_element_set_state (pipeline, GST_STATE_NULL);
277
278 fail_unless (found_fingerprint == TRUE);
279 g_object_unref (pipeline);
280 g_main_loop_unref (loop);
281 g_source_remove (bus_watch);
282 }
283
284 GST_END_TEST;
285
286
GST_START_TEST(test_ofa_be_2ch)287 GST_START_TEST (test_ofa_be_2ch)
288 {
289 GstElement *pipeline;
290 GstElement *audiotestsrc, *audioconvert, *capsfilter, *ofa, *fakesink;
291 GstBus *bus;
292 GMainLoop *loop;
293 GstCaps *caps;
294 gint64 position;
295 GstFormat fmt = GST_FORMAT_TIME;
296 guint bus_watch = 0;
297
298 pipeline = gst_pipeline_new ("pipeline");
299 fail_unless (pipeline != NULL);
300
301 audiotestsrc = gst_element_factory_make ("audiotestsrc", "src");
302 fail_unless (audiotestsrc != NULL);
303 g_object_set (G_OBJECT (audiotestsrc), "wave", 0, "freq", 440.0, NULL);
304
305 audioconvert = gst_element_factory_make ("audioconvert", "audioconvert");
306 fail_unless (audioconvert != NULL);
307 g_object_set (G_OBJECT (audioconvert), "dithering", 0, NULL);
308
309 capsfilter = gst_element_factory_make ("capsfilter", "capsfilter");
310 fail_unless (capsfilter != NULL);
311 caps = gst_caps_new_simple ("audio/x-raw", "format", G_TYPE_STRING, "S16BE",
312 "rate", G_TYPE_INT, 44100, "channels", G_TYPE_INT, 2, NULL);
313 g_object_set (G_OBJECT (capsfilter), "caps", caps, NULL);
314 gst_caps_unref (caps);
315
316 ofa = gst_element_factory_make ("ofa", "ofa");
317 fail_unless (ofa != NULL);
318
319 fakesink = gst_element_factory_make ("fakesink", "sink");
320 fail_unless (fakesink != NULL);
321
322 gst_bin_add_many (GST_BIN (pipeline), audiotestsrc, audioconvert, capsfilter,
323 ofa, fakesink, NULL);
324
325 fail_unless (gst_element_link_many (audiotestsrc, audioconvert, capsfilter,
326 ofa, fakesink, NULL));
327
328 loop = g_main_loop_new (NULL, TRUE);
329 fail_unless (loop != NULL);
330
331 bus = gst_element_get_bus (pipeline);
332 fail_unless (bus != NULL);
333 bus_watch = gst_bus_add_watch (bus, bus_handler, loop);
334 gst_object_unref (bus);
335
336 found_fingerprint = FALSE;
337 gst_element_set_state (pipeline, GST_STATE_PLAYING);
338 g_main_loop_run (loop);
339
340 fail_unless (gst_element_query_position (audiotestsrc, fmt, &position));
341 fail_unless (position >= 135 * GST_SECOND);
342
343 gst_element_set_state (pipeline, GST_STATE_NULL);
344
345 fail_unless (found_fingerprint == TRUE);
346 g_object_unref (pipeline);
347 g_main_loop_unref (loop);
348 g_source_remove (bus_watch);
349 }
350
351 GST_END_TEST;
352
353 static Suite *
ofa_suite(void)354 ofa_suite (void)
355 {
356 Suite *s = suite_create ("OFA");
357 TCase *tc_chain = tcase_create ("linear");
358
359 /* time out after 120s, not the default 3 */
360 tcase_set_timeout (tc_chain, 120);
361
362 suite_add_tcase (s, tc_chain);
363 tcase_add_test (tc_chain, test_ofa_le_1ch);
364 tcase_add_test (tc_chain, test_ofa_be_1ch);
365 tcase_add_test (tc_chain, test_ofa_le_2ch);
366 tcase_add_test (tc_chain, test_ofa_be_2ch);
367
368 return s;
369 }
370
371 GST_CHECK_MAIN (ofa)
372