1 /* GStreamer
2 *
3 * unit test for audiopanorama
4 *
5 * Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 #include <gst/audio/audio.h>
24 #include <gst/base/gstbasetransform.h>
25 #include <gst/check/gstcheck.h>
26
27 gboolean have_eos = FALSE;
28
29 /* For ease of programming we use globals to keep refs for our floating
30 * src and sink pads we create; otherwise we always have to do get_pad,
31 * get_peer, and then remove references in every test function */
32 GstPad *mysrcpad, *mysinkpad;
33
34
35 #define PANORAMA_S16_MONO_CAPS_STRING \
36 "audio/x-raw, " \
37 "channels = (int) 1, " \
38 "rate = (int) 44100, " \
39 "layout = (string) interleaved, " \
40 "format = (string) " GST_AUDIO_NE(S16)
41
42 #define PANORAMA_S16_STEREO_CAPS_STRING \
43 "audio/x-raw, " \
44 "channels = (int) 2, " \
45 "channel-mask = (bitmask) 3, " \
46 "rate = (int) 44100, " \
47 "layout = (string) interleaved, " \
48 "format = (string) " GST_AUDIO_NE(S16)
49
50 #define PANORAMA_F32_MONO_CAPS_STRING \
51 "audio/x-raw, " \
52 "channels = (int) 1, " \
53 "rate = (int) 44100, " \
54 "layout = (string) interleaved, " \
55 "format = (string) " GST_AUDIO_NE(F32)
56
57 #define PANORAMA_F32_STEREO_CAPS_STRING \
58 "audio/x-raw, " \
59 "channels = (int) 2, " \
60 "channel-mask = (bitmask) 3, " \
61 "rate = (int) 44100, " \
62 "layout = (string) interleaved, " \
63 "format = (string) " GST_AUDIO_NE(F32)
64
65 #define PANORAMA_WRONG_CAPS_STRING \
66 "audio/x-raw, " \
67 "channels = (int) 5, " \
68 "rate = (int) 44100, " \
69 "layout = (string) interleaved, " \
70 "format = (string) " GST_AUDIO_NE(U16)
71
72
73 static GstStaticPadTemplate sinktemplate[2] = {
74 GST_STATIC_PAD_TEMPLATE ("sink",
75 GST_PAD_SINK,
76 GST_PAD_ALWAYS,
77 GST_STATIC_CAPS ("audio/x-raw, "
78 "channels = (int) 2, "
79 "rate = (int) [ 1, MAX ], "
80 "layout = (string) interleaved, "
81 "format = (string) " GST_AUDIO_NE (S16))
82 ),
83 GST_STATIC_PAD_TEMPLATE ("sink",
84 GST_PAD_SINK,
85 GST_PAD_ALWAYS,
86 GST_STATIC_CAPS ("audio/x-raw, "
87 "channels = (int) 2, "
88 "rate = (int) [ 1, MAX ], "
89 "layout = (string) interleaved, "
90 "format = (string) " GST_AUDIO_NE (F32))
91 ),
92 };
93
94 static GstStaticPadTemplate msrctemplate[2] = {
95 GST_STATIC_PAD_TEMPLATE ("src",
96 GST_PAD_SRC,
97 GST_PAD_ALWAYS,
98 GST_STATIC_CAPS ("audio/x-raw, "
99 "channels = (int) 1, "
100 "rate = (int) [ 1, MAX ], "
101 "layout = (string) interleaved, "
102 "format = (string) " GST_AUDIO_NE (S16))
103 ),
104 GST_STATIC_PAD_TEMPLATE ("src",
105 GST_PAD_SRC,
106 GST_PAD_ALWAYS,
107 GST_STATIC_CAPS ("audio/x-raw, "
108 "channels = (int) 1, "
109 "rate = (int) [ 1, MAX ], "
110 "layout = (string) interleaved, "
111 "format = (string) " GST_AUDIO_NE (F32))
112 ),
113 };
114
115 static GstStaticPadTemplate ssrctemplate[2] = {
116 GST_STATIC_PAD_TEMPLATE ("src",
117 GST_PAD_SRC,
118 GST_PAD_ALWAYS,
119 GST_STATIC_CAPS ("audio/x-raw, "
120 "channels = (int) 2, "
121 "rate = (int) [ 1, MAX ], "
122 "layout = (string) interleaved, "
123 "format = (string) " GST_AUDIO_NE (S16))
124 ),
125 GST_STATIC_PAD_TEMPLATE ("src",
126 GST_PAD_SRC,
127 GST_PAD_ALWAYS,
128 GST_STATIC_CAPS ("audio/x-raw, "
129 "channels = (int) 2, "
130 "rate = (int) [ 1, MAX ], "
131 "layout = (string) interleaved, "
132 "format = (string) " GST_AUDIO_NE (F32))
133 ),
134 };
135
136 static GstElement *
setup_panorama(GstStaticPadTemplate * srctemplate,gint fmt,const gchar * caps_str)137 setup_panorama (GstStaticPadTemplate * srctemplate, gint fmt,
138 const gchar * caps_str)
139 {
140 GstElement *panorama;
141
142 GST_DEBUG ("setup_panorama");
143 panorama = gst_check_setup_element ("audiopanorama");
144 mysrcpad = gst_check_setup_src_pad (panorama, &srctemplate[fmt]);
145 mysinkpad = gst_check_setup_sink_pad (panorama, &sinktemplate[fmt]);
146 gst_pad_set_active (mysrcpad, TRUE);
147 gst_pad_set_active (mysinkpad, TRUE);
148
149 if (caps_str) {
150 GstCaps *caps = gst_caps_from_string (caps_str);
151 gst_check_setup_events (mysrcpad, panorama, caps, GST_FORMAT_TIME);
152 gst_caps_unref (caps);
153 }
154 return panorama;
155 }
156
157 static GstElement *
setup_panorama_s16_m(gint method,gfloat pan)158 setup_panorama_s16_m (gint method, gfloat pan)
159 {
160 GstElement *panorama;
161 panorama = setup_panorama (msrctemplate, 0, PANORAMA_S16_MONO_CAPS_STRING);
162 g_object_set (G_OBJECT (panorama), "method", method, "panorama", pan, NULL);
163 gst_element_set_state (panorama, GST_STATE_PLAYING);
164 GST_DEBUG ("panorama(mono) ready");
165
166 return panorama;
167 }
168
169 static GstElement *
setup_panorama_f32_m(gint method,gfloat pan)170 setup_panorama_f32_m (gint method, gfloat pan)
171 {
172 GstElement *panorama;
173 panorama = setup_panorama (msrctemplate, 1, PANORAMA_F32_MONO_CAPS_STRING);
174 g_object_set (G_OBJECT (panorama), "method", method, "panorama", pan, NULL);
175 gst_element_set_state (panorama, GST_STATE_PLAYING);
176 GST_DEBUG ("panorama(mono) ready");
177
178 return panorama;
179 }
180
181 static GstElement *
setup_panorama_s16_s(gint method,gfloat pan)182 setup_panorama_s16_s (gint method, gfloat pan)
183 {
184 GstElement *panorama;
185 panorama = setup_panorama (ssrctemplate, 0, PANORAMA_S16_STEREO_CAPS_STRING);
186 g_object_set (G_OBJECT (panorama), "method", method, "panorama", pan, NULL);
187 gst_element_set_state (panorama, GST_STATE_PLAYING);
188 GST_DEBUG ("panorama(stereo) ready");
189
190 return panorama;
191 }
192
193 static GstElement *
setup_panorama_f32_s(gint method,gfloat pan)194 setup_panorama_f32_s (gint method, gfloat pan)
195 {
196 GstElement *panorama;
197 panorama = setup_panorama (ssrctemplate, 1, PANORAMA_F32_STEREO_CAPS_STRING);
198 g_object_set (G_OBJECT (panorama), "method", method, "panorama", pan, NULL);
199 gst_element_set_state (panorama, GST_STATE_PLAYING);
200 GST_DEBUG ("panorama(stereo) ready");
201
202 return panorama;
203 }
204
205 static void
cleanup_panorama(GstElement * panorama)206 cleanup_panorama (GstElement * panorama)
207 {
208 GST_DEBUG ("cleaning up");
209 gst_element_set_state (panorama, GST_STATE_NULL);
210
211 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
212 g_list_free (buffers);
213 buffers = NULL;
214
215 gst_pad_set_active (mysrcpad, FALSE);
216 gst_pad_set_active (mysinkpad, FALSE);
217 gst_check_teardown_src_pad (panorama);
218 gst_check_teardown_sink_pad (panorama);
219 gst_check_teardown_element (panorama);
220 }
221
222 static GstBuffer *
setup_buffer(gpointer data,gsize size)223 setup_buffer (gpointer data, gsize size)
224 {
225 return gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, data, size, 0,
226 size, NULL, NULL);
227 }
228
229 static void
do_panorama(gpointer in_data,gsize in_size,gpointer out_data,gsize out_size)230 do_panorama (gpointer in_data, gsize in_size, gpointer out_data, gsize out_size)
231 {
232 GstBuffer *in, *out;
233
234 in = setup_buffer (in_data, in_size);
235 fail_unless (gst_pad_push (mysrcpad, in) == GST_FLOW_OK);
236 fail_unless_equals_int (g_list_length (buffers), 1);
237 fail_if ((out = (GstBuffer *) buffers->data) == NULL);
238 fail_unless (gst_buffer_extract (out, 0, out_data, out_size) == out_size);
239 }
240
241 /* the tests */
242
GST_START_TEST(test_ref_counts)243 GST_START_TEST (test_ref_counts)
244 {
245 GstElement *panorama;
246 GstBuffer *inbuffer, *outbuffer;
247 gint16 in[2] = { 16384, -256 };
248
249 panorama = setup_panorama (msrctemplate, 0, PANORAMA_S16_MONO_CAPS_STRING);
250 fail_unless (gst_element_set_state (panorama,
251 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
252 "could not set to playing");
253
254 inbuffer = setup_buffer (in, sizeof (in));
255 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
256
257 /* pushing gives away my reference ... */
258 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
259 /* ... but it ends up being collected on the global buffer list */
260 fail_unless_equals_int (g_list_length (buffers), 1);
261 fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
262 fail_if (inbuffer == outbuffer);
263
264 /* cleanup */
265 fail_unless (gst_element_set_state (panorama,
266 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
267 ASSERT_OBJECT_REFCOUNT (panorama, "panorama", 1);
268 cleanup_panorama (panorama);
269 }
270
271 GST_END_TEST;
272
GST_START_TEST(test_wrong_caps)273 GST_START_TEST (test_wrong_caps)
274 {
275 GstElement *panorama;
276 GstBuffer *inbuffer;
277 gint16 in[2] = { 16384, -256 };
278 GstBus *bus;
279 GstMessage *message;
280 GstCaps *caps;
281
282 panorama = setup_panorama (msrctemplate, 0, NULL);
283 bus = gst_bus_new ();
284 gst_element_set_state (panorama, GST_STATE_PLAYING);
285
286 inbuffer = setup_buffer (in, sizeof (in));
287 gst_buffer_ref (inbuffer);
288
289 /* set a bus here so we avoid getting state change messages */
290 gst_element_set_bus (panorama, bus);
291
292 caps = gst_caps_from_string (PANORAMA_WRONG_CAPS_STRING);
293 /* this actually succeeds, because the caps event is sticky */
294 gst_check_setup_events (mysrcpad, panorama, caps, GST_FORMAT_TIME);
295 gst_caps_unref (caps);
296
297 /* pushing gives an error because it can't negotiate with wrong caps */
298 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer),
299 GST_FLOW_NOT_NEGOTIATED);
300 /* ... and the buffer would have been lost if we didn't ref it ourselves */
301 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
302 gst_buffer_unref (inbuffer);
303 fail_unless_equals_int (g_list_length (buffers), 0);
304
305 /* panorama_set_caps should not have been called since basetransform caught
306 * the negotiation problem */
307 fail_if ((message = gst_bus_pop (bus)) != NULL);
308
309 /* cleanup */
310 gst_element_set_bus (panorama, NULL);
311 gst_object_unref (GST_OBJECT (bus));
312 gst_element_set_state (panorama, GST_STATE_NULL);
313 cleanup_panorama (panorama);
314 }
315
316 GST_END_TEST;
317
318 /* processing for method=psy */
319
GST_START_TEST(test_s16_mono_middle)320 GST_START_TEST (test_s16_mono_middle)
321 {
322 gint16 in[2] = { 16384, -256 };
323 gint16 out[4] = { 8192, 8192, -128, -128 };
324 gint16 res[4];
325 GstElement *panorama = setup_panorama_s16_m (0, 0.0);
326
327 do_panorama (in, sizeof (in), res, sizeof (res));
328
329 GST_INFO ("exp. %+5d %+5d %+5d %+5d", out[0], out[1], out[2], out[3]);
330 GST_INFO ("real %+5d %+5d %+5d %+5d", res[0], res[1], res[2], res[3]);
331 fail_unless (memcmp (res, out, sizeof (res)) == 0);
332
333 cleanup_panorama (panorama);
334 }
335
336 GST_END_TEST;
337
GST_START_TEST(test_s16_mono_left)338 GST_START_TEST (test_s16_mono_left)
339 {
340 gint16 in[2] = { 16384, -256 };
341 gint16 out[4] = { 16384, 0, -256, 0 };
342 gint16 res[4];
343 GstElement *panorama = setup_panorama_s16_m (0, -1.0);
344
345 do_panorama (in, sizeof (in), res, sizeof (res));
346
347 GST_INFO ("exp. %+5d %+5d %+5d %+5d", out[0], out[1], out[2], out[3]);
348 GST_INFO ("real %+5d %+5d %+5d %+5d", res[0], res[1], res[2], res[3]);
349 fail_unless (memcmp (res, out, sizeof (res)) == 0);
350
351 cleanup_panorama (panorama);
352 }
353
354 GST_END_TEST;
355
GST_START_TEST(test_s16_mono_right)356 GST_START_TEST (test_s16_mono_right)
357 {
358 gint16 in[2] = { 16384, -256 };
359 gint16 out[4] = { 0, 16384, 0, -256 };
360 gint16 res[4];
361 GstElement *panorama = setup_panorama_s16_m (0, 1.0);
362
363 do_panorama (in, sizeof (in), res, sizeof (res));
364
365 GST_INFO ("exp. %+5d %+5d %+5d %+5d", out[0], out[1], out[2], out[3]);
366 GST_INFO ("real %+5d %+5d %+5d %+5d", res[0], res[1], res[2], res[3]);
367 fail_unless (memcmp (res, out, sizeof (res)) == 0);
368
369 cleanup_panorama (panorama);
370 }
371
372 GST_END_TEST;
373
GST_START_TEST(test_s16_stereo_middle)374 GST_START_TEST (test_s16_stereo_middle)
375 {
376 gint16 in[4] = { 16384, -256, 8192, 128 };
377 gint16 res[4];
378 GstElement *panorama = setup_panorama_s16_s (0, 0.0);
379
380 do_panorama (in, sizeof (in), res, sizeof (res));
381
382 GST_INFO ("exp. %+5d %+5d %+5d %+5d", in[0], in[1], in[2], in[3]);
383 GST_INFO ("real %+5d %+5d %+5d %+5d", res[0], res[1], res[2], res[3]);
384 fail_unless (memcmp (res, in, sizeof (res)) == 0);
385
386 cleanup_panorama (panorama);
387 }
388
389 GST_END_TEST;
390
GST_START_TEST(test_s16_stereo_left)391 GST_START_TEST (test_s16_stereo_left)
392 {
393 gint16 in[4] = { 16384, -256, 8192, 128 };
394 gint16 out[4] = { 16384 - 256, 0, 8192 + 128, 0 };
395 gint16 res[4];
396 GstElement *panorama = setup_panorama_s16_s (0, -1.0);
397
398 do_panorama (in, sizeof (in), res, sizeof (res));
399
400 GST_INFO ("exp. %+5d %+5d %+5d %+5d", out[0], out[1], out[2], out[3]);
401 GST_INFO ("real %+5d %+5d %+5d %+5d", res[0], res[1], res[2], res[3]);
402 fail_unless (memcmp (res, out, sizeof (res)) == 0);
403
404 cleanup_panorama (panorama);
405 }
406
407 GST_END_TEST;
408
GST_START_TEST(test_s16_stereo_right)409 GST_START_TEST (test_s16_stereo_right)
410 {
411 gint16 in[4] = { 16384, -256, 8192, 128 };
412 gint16 out[4] = { 0, -256 + 16384, 0, 128 + 8192 };
413 gint16 res[4];
414 GstElement *panorama = setup_panorama_s16_s (0, 1.0);
415
416 do_panorama (in, sizeof (in), res, sizeof (res));
417
418 GST_INFO ("exp. %+5d %+5d %+5d %+5d", out[0], out[1], out[2], out[3]);
419 GST_INFO ("real %+5d %+5d %+5d %+5d", res[0], res[1], res[2], res[3]);
420 fail_unless (memcmp (res, out, sizeof (res)) == 0);
421
422 cleanup_panorama (panorama);
423 }
424
425 GST_END_TEST;
426
GST_START_TEST(test_f32_mono_middle)427 GST_START_TEST (test_f32_mono_middle)
428 {
429 gfloat in[2] = { 0.5, -0.2 };
430 gfloat out[4] = { 0.25, 0.25, -0.1, -0.1 };
431 gfloat res[4];
432 GstElement *panorama = setup_panorama_f32_m (0, 0.0);
433 gint i;
434
435 do_panorama (in, sizeof (in), res, sizeof (res));
436
437 GST_INFO ("exp. %+4.2f %+4.2f %+4.2f %+4.2f", out[0], out[1], out[2], out[3]);
438 GST_INFO ("real %+4.2f %+4.2f %+4.2f %+4.2f", res[0], res[1], res[2], res[3]);
439 for (i = 0; i < 4; i++)
440 fail_unless (res[i] == out[i], "difference at pos=%d", i);
441
442 cleanup_panorama (panorama);
443 }
444
445 GST_END_TEST;
446
GST_START_TEST(test_f32_mono_left)447 GST_START_TEST (test_f32_mono_left)
448 {
449 gfloat in[2] = { 0.5, -0.2 };
450 gfloat out[4] = { 0.5, 0.0, -0.2, 0.0 };
451 gfloat res[4];
452 GstElement *panorama = setup_panorama_f32_m (0, -1.0);
453 gint i;
454
455 do_panorama (in, sizeof (in), res, sizeof (res));
456
457 GST_INFO ("exp. %+4.2f %+4.2f %+4.2f %+4.2f", out[0], out[1], out[2], out[3]);
458 GST_INFO ("real %+4.2f %+4.2f %+4.2f %+4.2f", res[0], res[1], res[2], res[3]);
459 for (i = 0; i < 4; i++)
460 fail_unless (res[i] == out[i], "difference at pos=%d", i);
461
462 cleanup_panorama (panorama);
463 }
464
465 GST_END_TEST;
466
GST_START_TEST(test_f32_mono_right)467 GST_START_TEST (test_f32_mono_right)
468 {
469 gfloat in[2] = { 0.5, -0.2 };
470 gfloat out[4] = { 0.0, 0.5, 0.0, -0.2 };
471 gfloat res[4];
472 GstElement *panorama = setup_panorama_f32_m (0, 1.0);
473 gint i;
474
475 do_panorama (in, sizeof (in), res, sizeof (res));
476
477 GST_INFO ("exp. %+4.2f %+4.2f %+4.2f %+4.2f", out[0], out[1], out[2], out[3]);
478 GST_INFO ("real %+4.2f %+4.2f %+4.2f %+4.2f", res[0], res[1], res[2], res[3]);
479 for (i = 0; i < 4; i++)
480 fail_unless (res[i] == out[i], "difference at pos=%d", i);
481
482 cleanup_panorama (panorama);
483 }
484
485 GST_END_TEST;
486
GST_START_TEST(test_f32_stereo_middle)487 GST_START_TEST (test_f32_stereo_middle)
488 {
489 gfloat in[4] = { 0.5, -0.2, 0.25, 0.1 };
490 gfloat res[4];
491 GstElement *panorama = setup_panorama_f32_s (0, 0.0);
492 gint i;
493
494 do_panorama (in, sizeof (in), res, sizeof (res));
495
496 GST_INFO ("exp. %+4.2f %+4.2f %+4.2f %+4.2f", in[0], in[1], in[2], in[3]);
497 GST_INFO ("real %+4.2f %+4.2f %+4.2f %+4.2f", res[0], res[1], res[2], res[3]);
498 for (i = 0; i < 4; i++)
499 fail_unless (res[i] == in[i], "difference at pos=%d", i);
500
501 cleanup_panorama (panorama);
502 }
503
504 GST_END_TEST;
505
GST_START_TEST(test_f32_stereo_left)506 GST_START_TEST (test_f32_stereo_left)
507 {
508 gfloat in[4] = { 0.5, -0.2, 0.25, 0.1 };
509 gfloat out[4] = { 0.5 - 0.2, 0.0, 0.25 + 0.1, 0.0 };
510 gfloat res[4];
511 GstElement *panorama = setup_panorama_f32_s (0, -1.0);
512 gint i;
513
514 do_panorama (in, sizeof (in), res, sizeof (res));
515
516 GST_INFO ("exp. %+4.2f %+4.2f %+4.2f %+4.2f", out[0], out[1], out[2], out[3]);
517 GST_INFO ("real %+4.2f %+4.2f %+4.2f %+4.2f", res[0], res[1], res[2], res[3]);
518 for (i = 0; i < 4; i++)
519 fail_unless (res[i] == out[i], "difference at pos=%d", i);
520
521 cleanup_panorama (panorama);
522 }
523
524 GST_END_TEST;
525
GST_START_TEST(test_f32_stereo_right)526 GST_START_TEST (test_f32_stereo_right)
527 {
528 gfloat in[4] = { 0.5, -0.2, 0.25, 0.1 };
529 gfloat out[4] = { 0.0, -0.2 + 0.5, 0.0, 0.1 + 0.25 };
530 gfloat res[4];
531 GstElement *panorama = setup_panorama_f32_s (0, 1.0);
532 gint i;
533
534 do_panorama (in, sizeof (in), res, sizeof (res));
535
536 GST_INFO ("exp. %+4.2f %+4.2f %+4.2f %+4.2f", out[0], out[1], out[2], out[3]);
537 GST_INFO ("real %+4.2f %+4.2f %+4.2f %+4.2f", res[0], res[1], res[2], res[3]);
538 for (i = 0; i < 4; i++)
539 fail_unless (res[i] == out[i], "difference at pos=%d", i);
540
541 cleanup_panorama (panorama);
542 }
543
544 GST_END_TEST;
545
546 /* processing for method=simple */
547
GST_START_TEST(test_s16_mono_middle_simple)548 GST_START_TEST (test_s16_mono_middle_simple)
549 {
550 gint16 in[2] = { 16384, -256 };
551 gint16 out[4] = { 16384, 16384, -256, -256 };
552 gint16 res[4];
553 GstElement *panorama = setup_panorama_s16_m (1, 0.0);
554
555 do_panorama (in, sizeof (in), res, sizeof (res));
556
557 GST_INFO ("exp. %+5d %+5d %+5d %+5d", out[0], out[1], out[2], out[3]);
558 GST_INFO ("real %+5d %+5d %+5d %+5d", res[0], res[1], res[2], res[3]);
559 fail_unless (memcmp (res, out, sizeof (res)) == 0);
560
561 cleanup_panorama (panorama);
562 }
563
564 GST_END_TEST;
565
GST_START_TEST(test_s16_mono_left_simple)566 GST_START_TEST (test_s16_mono_left_simple)
567 {
568 gint16 in[2] = { 16384, -256 };
569 gint16 out[4] = { 16384, 0, -256, 0 };
570 gint16 res[4];
571 GstElement *panorama = setup_panorama_s16_m (1, -1.0);
572
573 do_panorama (in, sizeof (in), res, sizeof (res));
574
575 GST_INFO ("exp. %+5d %+5d %+5d %+5d", out[0], out[1], out[2], out[3]);
576 GST_INFO ("real %+5d %+5d %+5d %+5d", res[0], res[1], res[2], res[3]);
577 fail_unless (memcmp (res, out, sizeof (res)) == 0);
578
579 cleanup_panorama (panorama);
580 }
581
582 GST_END_TEST;
583
GST_START_TEST(test_s16_mono_right_simple)584 GST_START_TEST (test_s16_mono_right_simple)
585 {
586 gint16 in[2] = { 16384, -256 };
587 gint16 out[4] = { 0, 16384, 0, -256 };
588 gint16 res[4];
589 GstElement *panorama = setup_panorama_s16_m (1, 1.0);
590
591 do_panorama (in, sizeof (in), res, sizeof (res));
592
593 GST_INFO ("exp. %+5d %+5d %+5d %+5d", out[0], out[1], out[2], out[3]);
594 GST_INFO ("real %+5d %+5d %+5d %+5d", res[0], res[1], res[2], res[3]);
595 fail_unless (memcmp (res, out, sizeof (res)) == 0);
596
597 cleanup_panorama (panorama);
598 }
599
600 GST_END_TEST;
601
GST_START_TEST(test_s16_stereo_middle_simple)602 GST_START_TEST (test_s16_stereo_middle_simple)
603 {
604 gint16 in[4] = { 16384, -256, 8192, 128 };
605 gint16 res[4];
606 GstElement *panorama = setup_panorama_s16_s (1, 0.0);
607
608 do_panorama (in, sizeof (in), res, sizeof (res));
609
610 GST_INFO ("exp. %+5d %+5d %+5d %+5d", in[0], in[1], in[2], in[3]);
611 GST_INFO ("real %+5d %+5d %+5d %+5d", res[0], res[1], res[2], res[3]);
612 fail_unless (memcmp (res, in, sizeof (res)) == 0);
613
614 cleanup_panorama (panorama);
615 }
616
617 GST_END_TEST;
618
GST_START_TEST(test_s16_stereo_left_simple)619 GST_START_TEST (test_s16_stereo_left_simple)
620 {
621 gint16 in[4] = { 16384, -256, 8192, 128 };
622 gint16 out[4] = { 16384, 0, 8192, 0 };
623 gint16 res[4];
624 GstElement *panorama = setup_panorama_s16_s (1, -1.0);
625
626 do_panorama (in, sizeof (in), res, sizeof (res));
627
628 GST_INFO ("exp. %+5d %+5d %+5d %+5d", out[0], out[1], out[2], out[3]);
629 GST_INFO ("real %+5d %+5d %+5d %+5d", res[0], res[1], res[2], res[3]);
630 fail_unless (memcmp (res, out, sizeof (res)) == 0);
631
632 cleanup_panorama (panorama);
633 }
634
635 GST_END_TEST;
636
GST_START_TEST(test_s16_stereo_right_simple)637 GST_START_TEST (test_s16_stereo_right_simple)
638 {
639 gint16 in[4] = { 16384, -256, 8192, 128 };
640 gint16 out[4] = { 0, -256, 0, 128 };
641 gint16 res[4];
642 GstElement *panorama = setup_panorama_s16_s (1, 1.0);
643
644 do_panorama (in, sizeof (in), res, sizeof (res));
645
646 GST_INFO ("exp. %+5d %+5d %+5d %+5d", out[0], out[1], out[2], out[3]);
647 GST_INFO ("real %+5d %+5d %+5d %+5d", res[0], res[1], res[2], res[3]);
648 fail_unless (memcmp (res, out, sizeof (res)) == 0);
649
650 cleanup_panorama (panorama);
651 }
652
653 GST_END_TEST;
654
655 //-----------------------------------------------------------------------------
656
GST_START_TEST(test_f32_mono_middle_simple)657 GST_START_TEST (test_f32_mono_middle_simple)
658 {
659 gfloat in[2] = { 0.5, -0.2 };
660 gfloat out[4] = { 0.5, 0.5, -0.2, -0.2 };
661 gfloat res[4];
662 GstElement *panorama = setup_panorama_f32_m (1, 0.0);
663 gint i;
664
665 do_panorama (in, sizeof (in), res, sizeof (res));
666
667 GST_INFO ("exp. %+4.2f %+4.2f %+4.2f %+4.2f", out[0], out[1], out[2], out[3]);
668 GST_INFO ("real %+4.2f %+4.2f %+4.2f %+4.2f", res[0], res[1], res[2], res[3]);
669 for (i = 0; i < 4; i++)
670 fail_unless (res[i] == out[i], "difference at pos=%d", i);
671
672 cleanup_panorama (panorama);
673 }
674
675 GST_END_TEST;
676
GST_START_TEST(test_f32_mono_left_simple)677 GST_START_TEST (test_f32_mono_left_simple)
678 {
679 gfloat in[2] = { 0.5, -0.2 };
680 gfloat out[4] = { 0.5, 0.0, -0.2, 0.0 };
681 gfloat res[4];
682 GstElement *panorama = setup_panorama_f32_m (1, -1.0);
683 gint i;
684
685 do_panorama (in, sizeof (in), res, sizeof (res));
686
687 GST_INFO ("exp. %+4.2f %+4.2f %+4.2f %+4.2f", out[0], out[1], out[2], out[3]);
688 GST_INFO ("real %+4.2f %+4.2f %+4.2f %+4.2f", res[0], res[1], res[2], res[3]);
689 for (i = 0; i < 4; i++)
690 fail_unless (res[i] == out[i], "difference at pos=%d", i);
691
692 cleanup_panorama (panorama);
693 }
694
695 GST_END_TEST;
696
GST_START_TEST(test_f32_mono_right_simple)697 GST_START_TEST (test_f32_mono_right_simple)
698 {
699 gfloat in[2] = { 0.5, -0.2 };
700 gfloat out[4] = { 0.0, 0.5, 0.0, -0.2 };
701 gfloat res[4];
702 GstElement *panorama = setup_panorama_f32_m (1, 1.0);
703 gint i;
704
705 do_panorama (in, sizeof (in), res, sizeof (res));
706
707 GST_INFO ("exp. %+4.2f %+4.2f %+4.2f %+4.2f", out[0], out[1], out[2], out[3]);
708 GST_INFO ("real %+4.2f %+4.2f %+4.2f %+4.2f", res[0], res[1], res[2], res[3]);
709 for (i = 0; i < 4; i++)
710 fail_unless (res[i] == out[i], "difference at pos=%d", i);
711
712 cleanup_panorama (panorama);
713 }
714
715 GST_END_TEST;
716
GST_START_TEST(test_f32_stereo_middle_simple)717 GST_START_TEST (test_f32_stereo_middle_simple)
718 {
719 gfloat in[4] = { 0.5, -0.2, 0.25, 0.1 };
720 gfloat res[4];
721 GstElement *panorama = setup_panorama_f32_s (1, 0.0);
722 gint i;
723
724 do_panorama (in, sizeof (in), res, sizeof (res));
725
726 GST_INFO ("exp. %+4.2f %+4.2f %+4.2f %+4.2f", in[0], in[1], in[2], in[3]);
727 GST_INFO ("real %+4.2f %+4.2f %+4.2f %+4.2f", res[0], res[1], res[2], res[3]);
728 for (i = 0; i < 4; i++)
729 fail_unless (res[i] == in[i], "difference at pos=%d", i);
730
731 cleanup_panorama (panorama);
732 }
733
734 GST_END_TEST;
735
GST_START_TEST(test_f32_stereo_left_simple)736 GST_START_TEST (test_f32_stereo_left_simple)
737 {
738 gfloat in[4] = { 0.5, -0.2, 0.25, 0.1 };
739 gfloat out[4] = { 0.5, 0.0, 0.25, 0.0 };
740 gfloat res[4];
741 GstElement *panorama = setup_panorama_f32_s (1, -1.0);
742 gint i;
743
744 do_panorama (in, sizeof (in), res, sizeof (res));
745
746 GST_INFO ("exp. %+4.2f %+4.2f %+4.2f %+4.2f", out[0], out[1], out[2], out[3]);
747 GST_INFO ("real %+4.2f %+4.2f %+4.2f %+4.2f", res[0], res[1], res[2], res[3]);
748 for (i = 0; i < 4; i++)
749 fail_unless (res[i] == out[i], "difference at pos=%d", i);
750
751 cleanup_panorama (panorama);
752 }
753
754 GST_END_TEST;
755
GST_START_TEST(test_f32_stereo_right_simple)756 GST_START_TEST (test_f32_stereo_right_simple)
757 {
758 gfloat in[4] = { 0.5, -0.2, 0.25, 0.1 };
759 gfloat out[4] = { 0.0, -0.2, 0.0, 0.1 };
760 gfloat res[4];
761 GstElement *panorama = setup_panorama_f32_s (1, 1.0);
762 gint i;
763
764 do_panorama (in, sizeof (in), res, sizeof (res));
765
766 GST_INFO ("exp. %+4.2f %+4.2f %+4.2f %+4.2f", out[0], out[1], out[2], out[3]);
767 GST_INFO ("real %+4.2f %+4.2f %+4.2f %+4.2f", res[0], res[1], res[2], res[3]);
768 for (i = 0; i < 4; i++)
769 fail_unless (res[i] == out[i], "difference at pos=%d", i);
770
771 cleanup_panorama (panorama);
772 }
773
774 GST_END_TEST;
775
776
777 static Suite *
panorama_suite(void)778 panorama_suite (void)
779 {
780 Suite *s = suite_create ("panorama");
781 TCase *tc_chain = tcase_create ("general");
782
783 suite_add_tcase (s, tc_chain);
784 tcase_add_test (tc_chain, test_ref_counts);
785 tcase_add_test (tc_chain, test_wrong_caps);
786 /* processing for method=psy */
787 tcase_add_test (tc_chain, test_s16_mono_middle);
788 tcase_add_test (tc_chain, test_s16_mono_left);
789 tcase_add_test (tc_chain, test_s16_mono_right);
790 tcase_add_test (tc_chain, test_s16_stereo_middle);
791 tcase_add_test (tc_chain, test_s16_stereo_left);
792 tcase_add_test (tc_chain, test_s16_stereo_right);
793 tcase_add_test (tc_chain, test_f32_mono_middle);
794 tcase_add_test (tc_chain, test_f32_mono_left);
795 tcase_add_test (tc_chain, test_f32_mono_right);
796 tcase_add_test (tc_chain, test_f32_stereo_middle);
797 tcase_add_test (tc_chain, test_f32_stereo_left);
798 tcase_add_test (tc_chain, test_f32_stereo_right);
799 /* processing for method=simple */
800 tcase_add_test (tc_chain, test_s16_mono_middle_simple);
801 tcase_add_test (tc_chain, test_s16_mono_left_simple);
802 tcase_add_test (tc_chain, test_s16_mono_right_simple);
803 tcase_add_test (tc_chain, test_s16_stereo_middle_simple);
804 tcase_add_test (tc_chain, test_s16_stereo_left_simple);
805 tcase_add_test (tc_chain, test_s16_stereo_right_simple);
806 tcase_add_test (tc_chain, test_f32_mono_middle_simple);
807 tcase_add_test (tc_chain, test_f32_mono_left_simple);
808 tcase_add_test (tc_chain, test_f32_mono_right_simple);
809 tcase_add_test (tc_chain, test_f32_stereo_middle_simple);
810 tcase_add_test (tc_chain, test_f32_stereo_left_simple);
811 tcase_add_test (tc_chain, test_f32_stereo_right_simple);
812
813 return s;
814 }
815
816 GST_CHECK_MAIN (panorama);
817