1 /* GStreamer
2  *
3  * unit test for audioresample, based on the audioresample unit test
4  *
5  * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
6  * Copyright (C) <2006> Tim-Philipp Müller <tim at centricular net>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include <gst/check/gstcheck.h>
28 
29 #include <gst/audio/audio.h>
30 
31 #include <gst/fft/gstfft.h>
32 #include <gst/fft/gstffts16.h>
33 #include <gst/fft/gstffts32.h>
34 #include <gst/fft/gstfftf32.h>
35 #include <gst/fft/gstfftf64.h>
36 
37 /* For ease of programming we use globals to keep refs for our floating
38  * src and sink pads we create; otherwise we always have to do get_pad,
39  * get_peer, and then remove references in every test function */
40 static GstPad *mysrcpad, *mysinkpad;
41 
42 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
43 #define FORMATS  "{ F32LE, F64LE, S16LE, S32LE }"
44 #else
45 #define FORMATS  "{ F32BE, F64BE, S16BE, S32BE }"
46 #endif
47 
48 #define RESAMPLE_CAPS                   \
49     "audio/x-raw, "                     \
50     "format = (string) "FORMATS", "     \
51     "channels = (int) [ 1, MAX ], "     \
52     "rate = (int) [ 1,  MAX ], "        \
53     "layout = (string) interleaved"
54 
55 static GstElement *
setup_audioresample(int channels,guint64 mask,int inrate,int outrate,const gchar * format)56 setup_audioresample (int channels, guint64 mask, int inrate, int outrate,
57     const gchar * format)
58 {
59   GstPadTemplate *sinktemplate;
60   static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
61       GST_PAD_SRC,
62       GST_PAD_ALWAYS,
63       GST_STATIC_CAPS (RESAMPLE_CAPS)
64       );
65   GstElement *audioresample;
66   GstCaps *caps;
67   GstStructure *structure;
68 
69   GST_DEBUG ("setup_audioresample");
70   audioresample = gst_check_setup_element ("audioresample");
71 
72   caps = gst_caps_from_string (RESAMPLE_CAPS);
73   structure = gst_caps_get_structure (caps, 0);
74   gst_structure_set (structure, "channels", G_TYPE_INT, channels,
75       "rate", G_TYPE_INT, inrate, "format", G_TYPE_STRING, format,
76       "channel-mask", GST_TYPE_BITMASK, mask, NULL);
77   fail_unless (gst_caps_is_fixed (caps));
78 
79   fail_unless (gst_element_set_state (audioresample,
80           GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS,
81       "could not set to paused");
82 
83   mysrcpad = gst_check_setup_src_pad (audioresample, &srctemplate);
84   gst_pad_set_active (mysrcpad, TRUE);
85   gst_check_setup_events (mysrcpad, audioresample, caps, GST_FORMAT_TIME);
86   gst_caps_unref (caps);
87 
88   caps = gst_caps_from_string (RESAMPLE_CAPS);
89   structure = gst_caps_get_structure (caps, 0);
90   gst_structure_set (structure, "channels", G_TYPE_INT, channels,
91       "rate", G_TYPE_INT, outrate, "format", G_TYPE_STRING, format, NULL);
92   fail_unless (gst_caps_is_fixed (caps));
93   sinktemplate =
94       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps);
95 
96   mysinkpad =
97       gst_check_setup_sink_pad_from_template (audioresample, sinktemplate);
98   gst_pad_set_active (mysinkpad, TRUE);
99   /* this installs a getcaps func that will always return the caps we set
100    * later */
101   gst_pad_use_fixed_caps (mysinkpad);
102 
103   gst_caps_unref (caps);
104   gst_object_unref (sinktemplate);
105 
106   return audioresample;
107 }
108 
109 static void
cleanup_audioresample(GstElement * audioresample)110 cleanup_audioresample (GstElement * audioresample)
111 {
112   GST_DEBUG ("cleanup_audioresample");
113 
114   fail_unless (gst_element_set_state (audioresample,
115           GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to NULL");
116 
117   gst_pad_set_active (mysrcpad, FALSE);
118   gst_pad_set_active (mysinkpad, FALSE);
119   gst_check_teardown_src_pad (audioresample);
120   gst_check_teardown_sink_pad (audioresample);
121   gst_check_teardown_element (audioresample);
122   gst_check_drop_buffers ();
123 }
124 
125 static void
fail_unless_perfect_stream(void)126 fail_unless_perfect_stream (void)
127 {
128   guint64 timestamp = 0L, duration = 0L;
129   guint64 offset = 0L, offset_end = 0L;
130 
131   GList *l;
132   GstBuffer *buffer;
133 
134   for (l = buffers; l; l = l->next) {
135     buffer = GST_BUFFER (l->data);
136     ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
137     GST_DEBUG ("buffer timestamp %" G_GUINT64_FORMAT ", duration %"
138         G_GUINT64_FORMAT " offset %" G_GUINT64_FORMAT " offset_end %"
139         G_GUINT64_FORMAT,
140         GST_BUFFER_TIMESTAMP (buffer),
141         GST_BUFFER_DURATION (buffer),
142         GST_BUFFER_OFFSET (buffer), GST_BUFFER_OFFSET_END (buffer));
143 
144     fail_unless_equals_uint64 (timestamp, GST_BUFFER_TIMESTAMP (buffer));
145     fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET (buffer));
146     duration = GST_BUFFER_DURATION (buffer);
147     offset_end = GST_BUFFER_OFFSET_END (buffer);
148 
149     timestamp += duration;
150     offset = offset_end;
151     gst_buffer_unref (buffer);
152   }
153   g_list_free (buffers);
154   buffers = NULL;
155 }
156 
157 /* this tests that the output is a perfect stream if the input is */
158 static void
test_perfect_stream_instance(int inrate,int outrate,int samples,int numbuffers)159 test_perfect_stream_instance (int inrate, int outrate, int samples,
160     int numbuffers)
161 {
162   GstElement *audioresample;
163   GstBuffer *inbuffer, *outbuffer;
164   GstCaps *caps;
165   guint64 offset = 0;
166   int i, j;
167   GstMapInfo map;
168   gint16 *p;
169 
170   audioresample =
171       setup_audioresample (2, 0x3, inrate, outrate, GST_AUDIO_NE (S16));
172   caps = gst_pad_get_current_caps (mysrcpad);
173   fail_unless (gst_caps_is_fixed (caps));
174 
175   fail_unless (gst_element_set_state (audioresample,
176           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
177       "could not set to playing");
178 
179   for (j = 1; j <= numbuffers; ++j) {
180 
181     inbuffer = gst_buffer_new_and_alloc (samples * 4);
182     GST_BUFFER_DURATION (inbuffer) = GST_FRAMES_TO_CLOCK_TIME (samples, inrate);
183     GST_BUFFER_TIMESTAMP (inbuffer) = GST_BUFFER_DURATION (inbuffer) * (j - 1);
184     GST_BUFFER_OFFSET (inbuffer) = offset;
185     offset += samples;
186     GST_BUFFER_OFFSET_END (inbuffer) = offset;
187 
188     gst_buffer_map (inbuffer, &map, GST_MAP_WRITE);
189     p = (gint16 *) map.data;
190 
191     /* create a 16 bit signed ramp */
192     for (i = 0; i < samples; ++i) {
193       *p = -32767 + i * (65535 / samples);
194       ++p;
195       *p = -32767 + i * (65535 / samples);
196       ++p;
197     }
198     gst_buffer_unmap (inbuffer, &map);
199 
200     /* pushing gives away my reference ... */
201     fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
202     /* ... but it ends up being collected on the global buffer list */
203     fail_unless_equals_int (g_list_length (buffers), j);
204   }
205 
206   /* FIXME: we should make audioresample handle eos by flushing out the last
207    * samples, which will give us one more, small, buffer */
208   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
209   ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
210 
211   fail_unless_perfect_stream ();
212 
213   /* cleanup */
214   gst_caps_unref (caps);
215   cleanup_audioresample (audioresample);
216 }
217 
218 
219 /* make sure that outgoing buffers are contiguous in timestamp/duration and
220  * offset/offsetend
221  */
GST_START_TEST(test_perfect_stream)222 GST_START_TEST (test_perfect_stream)
223 {
224   /* integral scalings */
225   test_perfect_stream_instance (48000, 24000, 500, 20);
226   test_perfect_stream_instance (48000, 12000, 500, 20);
227   test_perfect_stream_instance (12000, 24000, 500, 20);
228   test_perfect_stream_instance (12000, 48000, 500, 20);
229 
230   /* non-integral scalings */
231   test_perfect_stream_instance (44100, 8000, 500, 20);
232   test_perfect_stream_instance (8000, 44100, 500, 20);
233 
234   /* wacky scalings */
235   test_perfect_stream_instance (12345, 54321, 500, 20);
236   test_perfect_stream_instance (101, 99, 500, 20);
237 }
238 
239 GST_END_TEST;
240 
241 /* this tests that the output is a correct discontinuous stream
242  * if the input is; ie input drops in time come out the same way */
243 static void
test_discont_stream_instance(int inrate,int outrate,int samples,int numbuffers)244 test_discont_stream_instance (int inrate, int outrate, int samples,
245     int numbuffers)
246 {
247   GstElement *audioresample;
248   GstBuffer *inbuffer, *outbuffer;
249   GstCaps *caps;
250   GstClockTime ints;
251 
252   int i, j;
253   GstMapInfo map;
254   gint16 *p;
255 
256   GST_DEBUG ("inrate:%d outrate:%d samples:%d numbuffers:%d",
257       inrate, outrate, samples, numbuffers);
258 
259   audioresample =
260       setup_audioresample (2, 3, inrate, outrate, GST_AUDIO_NE (S16));
261   caps = gst_pad_get_current_caps (mysrcpad);
262   fail_unless (gst_caps_is_fixed (caps));
263 
264   fail_unless (gst_element_set_state (audioresample,
265           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
266       "could not set to playing");
267 
268   for (j = 1; j <= numbuffers; ++j) {
269 
270     inbuffer = gst_buffer_new_and_alloc (samples * 4);
271     GST_BUFFER_DURATION (inbuffer) = samples * GST_SECOND / inrate;
272     /* "drop" half the buffers */
273     ints = GST_BUFFER_DURATION (inbuffer) * 2 * (j - 1);
274     GST_BUFFER_TIMESTAMP (inbuffer) = ints;
275     GST_BUFFER_OFFSET (inbuffer) = (j - 1) * 2 * samples;
276     GST_BUFFER_OFFSET_END (inbuffer) = j * 2 * samples + samples;
277 
278     gst_buffer_map (inbuffer, &map, GST_MAP_WRITE);
279     p = (gint16 *) map.data;
280     /* create a 16 bit signed ramp */
281     for (i = 0; i < samples; ++i) {
282       *p = -32767 + i * (65535 / samples);
283       ++p;
284       *p = -32767 + i * (65535 / samples);
285       ++p;
286     }
287     gst_buffer_unmap (inbuffer, &map);
288 
289     GST_DEBUG ("Sending Buffer time:%" G_GUINT64_FORMAT " duration:%"
290         G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%"
291         G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (inbuffer),
292         GST_BUFFER_DURATION (inbuffer), GST_BUFFER_IS_DISCONT (inbuffer),
293         GST_BUFFER_OFFSET (inbuffer), GST_BUFFER_OFFSET_END (inbuffer));
294     /* pushing gives away my reference ... */
295     fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
296 
297     /* check if the timestamp of the pushed buffer matches the incoming one */
298     outbuffer = g_list_nth_data (buffers, g_list_length (buffers) - 1);
299     fail_if (outbuffer == NULL);
300     fail_unless_equals_uint64 (ints, GST_BUFFER_TIMESTAMP (outbuffer));
301     GST_DEBUG ("Got Buffer time:%" G_GUINT64_FORMAT " duration:%"
302         G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%"
303         G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (outbuffer),
304         GST_BUFFER_DURATION (outbuffer), GST_BUFFER_IS_DISCONT (outbuffer),
305         GST_BUFFER_OFFSET (outbuffer), GST_BUFFER_OFFSET_END (outbuffer));
306     if (j > 1) {
307       fail_unless (GST_BUFFER_IS_DISCONT (outbuffer),
308           "expected discont for buffer #%d", j);
309     }
310   }
311 
312   /* cleanup */
313   gst_caps_unref (caps);
314   cleanup_audioresample (audioresample);
315 }
316 
GST_START_TEST(test_discont_stream)317 GST_START_TEST (test_discont_stream)
318 {
319   /* integral scalings */
320   test_discont_stream_instance (48000, 24000, 5000, 20);
321   test_discont_stream_instance (48000, 12000, 5000, 20);
322   test_discont_stream_instance (12000, 24000, 5000, 20);
323   test_discont_stream_instance (12000, 48000, 5000, 20);
324 
325   /* non-integral scalings */
326   test_discont_stream_instance (44100, 8000, 5000, 20);
327   test_discont_stream_instance (8000, 44100, 5000, 20);
328 
329   /* wacky scalings */
330   test_discont_stream_instance (12345, 54321, 5000, 20);
331   test_discont_stream_instance (101, 99, 5000, 20);
332 }
333 
334 GST_END_TEST;
335 
336 
337 
GST_START_TEST(test_reuse)338 GST_START_TEST (test_reuse)
339 {
340   GstElement *audioresample;
341   GstEvent *newseg;
342   GstBuffer *inbuffer;
343   GstCaps *caps;
344   GstSegment segment;
345 
346   audioresample = setup_audioresample (1, 0, 9343, 48000, GST_AUDIO_NE (S16));
347   caps = gst_pad_get_current_caps (mysrcpad);
348   fail_unless (gst_caps_is_fixed (caps));
349 
350   fail_unless (gst_element_set_state (audioresample,
351           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
352       "could not set to playing");
353 
354   gst_segment_init (&segment, GST_FORMAT_TIME);
355   newseg = gst_event_new_segment (&segment);
356   fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE);
357 
358   inbuffer = gst_buffer_new_and_alloc (9343 * 4);
359   gst_buffer_memset (inbuffer, 0, 0, 9343 * 4);
360   GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
361   GST_BUFFER_TIMESTAMP (inbuffer) = 0;
362   GST_BUFFER_OFFSET (inbuffer) = 0;
363 
364   /* pushing gives away my reference ... */
365   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
366 
367   /* ... but it ends up being collected on the global buffer list */
368   fail_unless_equals_int (g_list_length (buffers), 1);
369 
370   /* now reset and try again ... */
371   fail_unless (gst_element_set_state (audioresample,
372           GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to NULL");
373 
374   fail_unless (gst_element_set_state (audioresample,
375           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
376       "could not set to playing");
377 
378   newseg = gst_event_new_segment (&segment);
379   fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE);
380 
381   inbuffer = gst_buffer_new_and_alloc (9343 * 4);
382   gst_buffer_memset (inbuffer, 0, 0, 9343 * 4);
383   GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
384   GST_BUFFER_TIMESTAMP (inbuffer) = 0;
385   GST_BUFFER_OFFSET (inbuffer) = 0;
386 
387   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
388 
389   /* ... it also ends up being collected on the global buffer list. If we
390    * now have more than 2 buffers, then audioresample probably didn't clean
391    * up its internal buffer properly and tried to push the remaining samples
392    * when it got the second NEWSEGMENT event */
393   fail_unless_equals_int (g_list_length (buffers), 2);
394 
395   cleanup_audioresample (audioresample);
396   gst_caps_unref (caps);
397 }
398 
399 GST_END_TEST;
400 
GST_START_TEST(test_shutdown)401 GST_START_TEST (test_shutdown)
402 {
403   GstElement *pipeline, *src, *cf1, *ar, *cf2, *sink;
404   GstCaps *caps;
405   guint i;
406 
407   /* create pipeline, force audioresample to actually resample */
408   pipeline = gst_pipeline_new (NULL);
409 
410   src = gst_check_setup_element ("audiotestsrc");
411   cf1 = gst_check_setup_element ("capsfilter");
412   ar = gst_check_setup_element ("audioresample");
413   cf2 = gst_check_setup_element ("capsfilter");
414   g_object_set (cf2, "name", "capsfilter2", NULL);
415   sink = gst_check_setup_element ("fakesink");
416 
417   caps = gst_caps_new_simple ("audio/x-raw", "rate", G_TYPE_INT, 11025, NULL);
418   g_object_set (cf1, "caps", caps, NULL);
419   gst_caps_unref (caps);
420 
421   caps = gst_caps_new_simple ("audio/x-raw", "rate", G_TYPE_INT, 48000, NULL);
422   g_object_set (cf2, "caps", caps, NULL);
423   gst_caps_unref (caps);
424 
425   /* don't want to sync against the clock, the more throughput the better */
426   g_object_set (src, "is-live", FALSE, NULL);
427   g_object_set (sink, "sync", FALSE, NULL);
428 
429   gst_bin_add_many (GST_BIN (pipeline), src, cf1, ar, cf2, sink, NULL);
430   fail_if (!gst_element_link_many (src, cf1, ar, cf2, sink, NULL));
431 
432   /* now, wait until pipeline is running and then shut it down again; repeat */
433   for (i = 0; i < 20; ++i) {
434     gst_element_set_state (pipeline, GST_STATE_PAUSED);
435     gst_element_get_state (pipeline, NULL, NULL, -1);
436     gst_element_set_state (pipeline, GST_STATE_PLAYING);
437     g_usleep (100);
438     gst_element_set_state (pipeline, GST_STATE_NULL);
439   }
440 
441   gst_object_unref (pipeline);
442 }
443 
444 GST_END_TEST;
445 
446 #if 0
447 static GstFlowReturn
448 live_switch_alloc_only_48000 (GstPad * pad, guint64 offset,
449     guint size, GstCaps * caps, GstBuffer ** buf)
450 {
451   GstStructure *structure;
452   gint rate;
453   gint channels;
454   GstCaps *desired;
455 
456   structure = gst_caps_get_structure (caps, 0);
457   fail_unless (gst_structure_get_int (structure, "rate", &rate));
458   fail_unless (gst_structure_get_int (structure, "channels", &channels));
459 
460   if (rate < 48000)
461     return GST_FLOW_NOT_NEGOTIATED;
462 
463   desired = gst_caps_copy (caps);
464   gst_caps_set_simple (desired, "rate", G_TYPE_INT, 48000, NULL);
465 
466   *buf = gst_buffer_new_and_alloc (channels * 48000);
467   gst_buffer_set_caps (*buf, desired);
468   gst_caps_unref (desired);
469 
470   return GST_FLOW_OK;
471 }
472 
473 static GstCaps *
474 live_switch_get_sink_caps (GstPad * pad)
475 {
476   GstCaps *result;
477 
478   result = gst_caps_make_writable (gst_pad_get_current_caps (pad));
479 
480   gst_caps_set_simple (result,
481       "rate", GST_TYPE_INT_RANGE, 48000, G_MAXINT, NULL);
482 
483   return result;
484 }
485 #endif
486 
487 static void
live_switch_push(int rate,GstCaps * caps)488 live_switch_push (int rate, GstCaps * caps)
489 {
490   GstBuffer *inbuffer;
491   GstCaps *desired;
492   GList *l;
493 
494   desired = gst_caps_copy (caps);
495   gst_caps_set_simple (desired, "rate", G_TYPE_INT, rate, NULL);
496   gst_pad_set_caps (mysrcpad, desired);
497 
498 #if 0
499   fail_unless (gst_pad_alloc_buffer_and_set_caps (mysrcpad,
500           GST_BUFFER_OFFSET_NONE, rate * 4, desired, &inbuffer) == GST_FLOW_OK);
501 #endif
502   inbuffer = gst_buffer_new_and_alloc (rate * 4);
503   gst_buffer_memset (inbuffer, 0, 0, rate * 4);
504 
505   GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
506   GST_BUFFER_TIMESTAMP (inbuffer) = 0;
507   GST_BUFFER_OFFSET (inbuffer) = 0;
508 
509   /* pushing gives away my reference ... */
510   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
511 
512   /* ... but it ends up being collected on the global buffer list */
513   fail_unless_equals_int (g_list_length (buffers), 1);
514 
515   for (l = buffers; l; l = l->next) {
516     GstBuffer *buffer = GST_BUFFER (l->data);
517 
518     gst_buffer_unref (buffer);
519   }
520 
521   g_list_free (buffers);
522   buffers = NULL;
523 
524   gst_caps_unref (desired);
525 }
526 
GST_START_TEST(test_live_switch)527 GST_START_TEST (test_live_switch)
528 {
529   GstElement *audioresample;
530   GstEvent *newseg;
531   GstCaps *caps;
532   GstSegment segment;
533 
534   audioresample =
535       setup_audioresample (4, 0xf, 48000, 48000, GST_AUDIO_NE (S16));
536 
537   /* Let the sinkpad act like something that can only handle things of
538    * rate 48000- and can only allocate buffers for that rate, but if someone
539    * tries to get a buffer with a rate higher then 48000 tries to renegotiate
540    * */
541   //gst_pad_set_bufferalloc_function (mysinkpad, live_switch_alloc_only_48000);
542   //gst_pad_set_getcaps_function (mysinkpad, live_switch_get_sink_caps);
543 
544   gst_pad_use_fixed_caps (mysrcpad);
545 
546   caps = gst_pad_get_current_caps (mysrcpad);
547   fail_unless (gst_caps_is_fixed (caps));
548 
549   fail_unless (gst_element_set_state (audioresample,
550           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
551       "could not set to playing");
552 
553   gst_segment_init (&segment, GST_FORMAT_TIME);
554   newseg = gst_event_new_segment (&segment);
555   fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE);
556 
557   /* downstream can provide the requested rate, a buffer alloc will be passed
558    * on */
559   live_switch_push (48000, caps);
560 
561   /* Downstream can never accept this rate, buffer alloc isn't passed on */
562   live_switch_push (40000, caps);
563 
564   /* Downstream can provide the requested rate but will re-negotiate */
565   live_switch_push (50000, caps);
566 
567   cleanup_audioresample (audioresample);
568   gst_caps_unref (caps);
569 }
570 
571 GST_END_TEST;
572 
573 #ifndef GST_DISABLE_PARSE
574 
575 static GMainLoop *loop;
576 static gint messages = 0;
577 
578 static void
element_message_cb(GstBus * bus,GstMessage * message,gpointer user_data)579 element_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
580 {
581   gchar *s;
582 
583   s = gst_structure_to_string (gst_message_get_structure (message));
584   GST_DEBUG ("Received message: %s", s);
585   g_free (s);
586 
587   messages++;
588 }
589 
590 static void
eos_message_cb(GstBus * bus,GstMessage * message,gpointer user_data)591 eos_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
592 {
593   GST_DEBUG ("Received eos");
594   g_main_loop_quit (loop);
595 }
596 
597 static void
test_pipeline(const gchar * format,gint inrate,gint outrate,gint quality)598 test_pipeline (const gchar * format, gint inrate, gint outrate, gint quality)
599 {
600   GstElement *pipeline;
601   GstBus *bus;
602   GError *error = NULL;
603   gchar *pipe_str;
604 
605   pipe_str =
606       g_strdup_printf
607       ("audiotestsrc num-buffers=10 ! audioconvert ! audio/x-raw,format=%s,rate=%d,channels=2 ! audioresample quality=%d ! audio/x-raw,format=%s,rate=%d ! identity check-imperfect-timestamp=TRUE ! fakesink",
608       format, inrate, quality, format, outrate);
609 
610   pipeline = gst_parse_launch (pipe_str, &error);
611   fail_unless (pipeline != NULL, "Error parsing pipeline: %s",
612       error ? error->message : "(invalid error)");
613   g_free (pipe_str);
614 
615   bus = gst_element_get_bus (pipeline);
616   fail_if (bus == NULL);
617   gst_bus_add_signal_watch (bus);
618   g_signal_connect (bus, "message::element", (GCallback) element_message_cb,
619       NULL);
620   g_signal_connect (bus, "message::eos", (GCallback) eos_message_cb, NULL);
621 
622   gst_element_set_state (pipeline, GST_STATE_PLAYING);
623 
624   /* run until we receive EOS */
625   loop = g_main_loop_new (NULL, FALSE);
626 
627   g_main_loop_run (loop);
628 
629   g_main_loop_unref (loop);
630   loop = NULL;
631 
632   gst_element_set_state (pipeline, GST_STATE_NULL);
633 
634   gst_bus_remove_signal_watch (bus);
635   gst_object_unref (bus);
636 
637   fail_if (messages > 0, "Received imperfect timestamp messages");
638   gst_object_unref (pipeline);
639 }
640 
GST_START_TEST(test_pipelines)641 GST_START_TEST (test_pipelines)
642 {
643   gint quality;
644 
645   /* Test qualities 0, 5 and 10 */
646   for (quality = 0; quality < 11; quality += 5) {
647     GST_DEBUG ("Checking with quality %d", quality);
648 
649     test_pipeline ("S8", 44100, 48000, quality);
650     test_pipeline ("S8", 48000, 44100, quality);
651 
652     test_pipeline (GST_AUDIO_NE (S16), 44100, 48000, quality);
653     test_pipeline (GST_AUDIO_NE (S16), 48000, 44100, quality);
654 
655     test_pipeline (GST_AUDIO_NE (S24), 44100, 48000, quality);
656     test_pipeline (GST_AUDIO_NE (S24), 48000, 44100, quality);
657 
658     test_pipeline (GST_AUDIO_NE (S32), 44100, 48000, quality);
659     test_pipeline (GST_AUDIO_NE (S32), 48000, 44100, quality);
660 
661     test_pipeline (GST_AUDIO_NE (F32), 44100, 48000, quality);
662     test_pipeline (GST_AUDIO_NE (F32), 48000, 44100, quality);
663 
664     test_pipeline (GST_AUDIO_NE (F64), 44100, 48000, quality);
665     test_pipeline (GST_AUDIO_NE (F64), 48000, 44100, quality);
666   }
667 }
668 
669 GST_END_TEST;
670 
GST_START_TEST(test_preference_passthrough)671 GST_START_TEST (test_preference_passthrough)
672 {
673   GstStateChangeReturn ret;
674   GstElement *pipeline, *src;
675   GstStructure *s;
676   GstMessage *msg;
677   GstCaps *caps;
678   GstPad *pad;
679   GstBus *bus;
680   GError *error = NULL;
681   gint rate = 0;
682 
683   pipeline = gst_parse_launch ("audiotestsrc num-buffers=1 name=src ! "
684       "audioresample ! audio/x-raw,format=" GST_AUDIO_NE (S16) ",channels=1,"
685       "rate=8000 ! fakesink can-activate-pull=false", &error);
686   fail_unless (pipeline != NULL, "Error parsing pipeline: %s",
687       error ? error->message : "(invalid error)");
688 
689   ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
690   fail_unless_equals_int (ret, GST_STATE_CHANGE_ASYNC);
691 
692   /* run until we receive EOS */
693   bus = gst_element_get_bus (pipeline);
694   fail_if (bus == NULL);
695   msg = gst_bus_timed_pop_filtered (bus, -1, GST_MESSAGE_EOS);
696   gst_message_unref (msg);
697   gst_object_unref (bus);
698 
699   src = gst_bin_get_by_name (GST_BIN (pipeline), "src");
700   fail_unless (src != NULL);
701   pad = gst_element_get_static_pad (src, "src");
702   fail_unless (pad != NULL);
703   caps = gst_pad_get_current_caps (pad);
704   GST_LOG ("current audiotestsrc caps: %" GST_PTR_FORMAT, caps);
705   fail_unless (caps != NULL);
706   s = gst_caps_get_structure (caps, 0);
707   fail_unless (gst_structure_get_int (s, "rate", &rate));
708   /* there's no need to resample, audiotestsrc supports any rate, so make
709    * sure audioresample provided upstream with the right caps to negotiate
710    * this correctly */
711   fail_unless_equals_int (rate, 8000);
712   gst_caps_unref (caps);
713   gst_object_unref (pad);
714   gst_object_unref (src);
715 
716   gst_element_set_state (pipeline, GST_STATE_NULL);
717   gst_object_unref (pipeline);
718 }
719 
720 GST_END_TEST;
721 
722 #endif
723 
724 static void
_message_cb(GstBus * bus,GstMessage * message,gpointer user_data)725 _message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
726 {
727   GMainLoop *loop = user_data;
728 
729   switch (GST_MESSAGE_TYPE (message)) {
730     case GST_MESSAGE_ERROR:
731     case GST_MESSAGE_WARNING:
732       g_assert_not_reached ();
733       break;
734     case GST_MESSAGE_EOS:
735       g_main_loop_quit (loop);
736       break;
737     default:
738       break;
739   }
740 }
741 
742 typedef struct
743 {
744   guint64 latency;
745   GstClockTime in_ts;
746 
747   GstClockTime next_out_ts;
748   guint64 next_out_off;
749 
750   guint64 in_buffer_count, out_buffer_count;
751 } TimestampDriftCtx;
752 
753 static void
fakesink_handoff_cb(GstElement * object,GstBuffer * buffer,GstPad * pad,gpointer user_data)754 fakesink_handoff_cb (GstElement * object, GstBuffer * buffer, GstPad * pad,
755     gpointer user_data)
756 {
757   TimestampDriftCtx *ctx = user_data;
758 
759   ctx->out_buffer_count++;
760   if (ctx->latency == GST_CLOCK_TIME_NONE) {
761     ctx->latency = 1000 - gst_buffer_get_size (buffer) / 8;
762   }
763 
764   /* Check if we have a perfectly timestamped stream */
765   if (ctx->next_out_ts != GST_CLOCK_TIME_NONE)
766     fail_unless (ctx->next_out_ts == GST_BUFFER_TIMESTAMP (buffer),
767         "expected timestamp %" GST_TIME_FORMAT " got timestamp %"
768         GST_TIME_FORMAT, GST_TIME_ARGS (ctx->next_out_ts),
769         GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
770 
771   /* Check if we have a perfectly offsetted stream */
772   fail_unless (GST_BUFFER_OFFSET_END (buffer) ==
773       GST_BUFFER_OFFSET (buffer) + gst_buffer_get_size (buffer) / 8,
774       "expected offset end %" G_GUINT64_FORMAT " got offset end %"
775       G_GUINT64_FORMAT,
776       GST_BUFFER_OFFSET (buffer) + gst_buffer_get_size (buffer) / 8,
777       GST_BUFFER_OFFSET_END (buffer));
778   if (ctx->next_out_off != GST_BUFFER_OFFSET_NONE) {
779     fail_unless (GST_BUFFER_OFFSET (buffer) == ctx->next_out_off,
780         "expected offset %" G_GUINT64_FORMAT " got offset %" G_GUINT64_FORMAT,
781         ctx->next_out_off, GST_BUFFER_OFFSET (buffer));
782   }
783 
784   if (ctx->in_buffer_count != ctx->out_buffer_count) {
785     GST_INFO ("timestamp %" GST_TIME_FORMAT,
786         GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
787   }
788 
789   if (ctx->in_ts != GST_CLOCK_TIME_NONE && ctx->in_buffer_count > 1
790       && ctx->in_buffer_count == ctx->out_buffer_count) {
791     fail_unless (GST_BUFFER_TIMESTAMP (buffer) ==
792         ctx->in_ts - gst_util_uint64_scale_round (ctx->latency, GST_SECOND,
793             4096),
794         "expected output timestamp %" GST_TIME_FORMAT " (%" G_GUINT64_FORMAT
795         ") got output timestamp %" GST_TIME_FORMAT " (%" G_GUINT64_FORMAT ")",
796         GST_TIME_ARGS (ctx->in_ts - gst_util_uint64_scale_round (ctx->latency,
797                 GST_SECOND, 4096)),
798         ctx->in_ts - gst_util_uint64_scale_round (ctx->latency, GST_SECOND,
799             4096), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
800         GST_BUFFER_TIMESTAMP (buffer));
801   }
802 
803   ctx->next_out_ts =
804       GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer);
805   ctx->next_out_off = GST_BUFFER_OFFSET_END (buffer);
806 }
807 
808 static void
identity_handoff_cb(GstElement * object,GstBuffer * buffer,gpointer user_data)809 identity_handoff_cb (GstElement * object, GstBuffer * buffer,
810     gpointer user_data)
811 {
812   TimestampDriftCtx *ctx = user_data;
813 
814   ctx->in_ts = GST_BUFFER_TIMESTAMP (buffer);
815   ctx->in_buffer_count++;
816 }
817 
GST_START_TEST(test_timestamp_drift)818 GST_START_TEST (test_timestamp_drift)
819 {
820   TimestampDriftCtx ctx =
821       { GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE,
822     GST_BUFFER_OFFSET_NONE, 0, 0
823   };
824   GstElement *pipeline;
825   GstElement *audiotestsrc, *capsfilter1, *identity, *audioresample,
826       *capsfilter2, *fakesink;
827   GstBus *bus;
828   GMainLoop *loop;
829   GstCaps *caps;
830 
831   pipeline = gst_pipeline_new ("pipeline");
832   fail_unless (pipeline != NULL);
833 
834   audiotestsrc = gst_element_factory_make ("audiotestsrc", "src");
835   fail_unless (audiotestsrc != NULL);
836   g_object_set (G_OBJECT (audiotestsrc), "num-buffers", 10000,
837       "samplesperbuffer", 4000, NULL);
838 
839   capsfilter1 = gst_element_factory_make ("capsfilter", "capsfilter1");
840   fail_unless (capsfilter1 != NULL);
841   caps = gst_caps_from_string ("audio/x-raw, format=" GST_AUDIO_NE (F64)
842       ", channels=1, rate=16384");
843   g_object_set (G_OBJECT (capsfilter1), "caps", caps, NULL);
844   gst_caps_unref (caps);
845 
846   identity = gst_element_factory_make ("identity", "identity");
847   fail_unless (identity != NULL);
848   g_object_set (G_OBJECT (identity), "sync", FALSE, "signal-handoffs", TRUE,
849       NULL);
850   g_signal_connect (identity, "handoff", (GCallback) identity_handoff_cb, &ctx);
851 
852   audioresample = gst_element_factory_make ("audioresample", "resample");
853   fail_unless (audioresample != NULL);
854   capsfilter2 = gst_element_factory_make ("capsfilter", "capsfilter2");
855   fail_unless (capsfilter2 != NULL);
856   caps = gst_caps_from_string ("audio/x-raw, format=" GST_AUDIO_NE (F64)
857       ", channels=1, rate=4096");
858   g_object_set (G_OBJECT (capsfilter2), "caps", caps, NULL);
859   gst_caps_unref (caps);
860 
861   fakesink = gst_element_factory_make ("fakesink", "sink");
862   fail_unless (fakesink != NULL);
863   g_object_set (G_OBJECT (fakesink), "sync", FALSE, "async", FALSE,
864       "signal-handoffs", TRUE, NULL);
865   g_signal_connect (fakesink, "handoff", (GCallback) fakesink_handoff_cb, &ctx);
866 
867 
868   gst_bin_add_many (GST_BIN (pipeline), audiotestsrc, capsfilter1, identity,
869       audioresample, capsfilter2, fakesink, NULL);
870   fail_unless (gst_element_link_many (audiotestsrc, capsfilter1, identity,
871           audioresample, capsfilter2, fakesink, NULL));
872 
873   loop = g_main_loop_new (NULL, FALSE);
874 
875   bus = gst_element_get_bus (pipeline);
876   gst_bus_add_signal_watch (bus);
877   g_signal_connect (bus, "message", (GCallback) _message_cb, loop);
878 
879   fail_unless (gst_element_set_state (pipeline,
880           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
881   g_main_loop_run (loop);
882 
883   fail_unless (gst_element_set_state (pipeline,
884           GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
885   g_main_loop_unref (loop);
886   gst_bus_remove_signal_watch (bus);
887   gst_object_unref (bus);
888 
889   gst_object_unref (pipeline);
890 
891 } GST_END_TEST;
892 
893 #define FFT_HELPERS(type,ffttag,ffttag2,scale);                                                 \
894 static gdouble magnitude##ffttag (const GstFFT##ffttag##Complex *c)                             \
895 {                                                                                               \
896   gdouble mag = (gdouble) c->r * (gdouble) c->r;                                                \
897   mag += (gdouble) c->i * (gdouble) c->i;                                                       \
898   mag /= scale * scale;                                                                         \
899   mag = 10.0 * log10 (mag);                                                                     \
900   return mag;                                                                                   \
901 }                                                                                               \
902 static gdouble find_main_frequency_spot_##ffttag (const GstFFT##ffttag##Complex *v,             \
903                                                   int elements)                                 \
904 {                                                                                               \
905   int i;                                                                                        \
906   gdouble maxmag = -9999;                                                                       \
907   int maxidx = 0;                                                                               \
908   for (i=0; i<elements; ++i) {                                                                  \
909     gdouble mag = magnitude##ffttag (v+i);                                                      \
910     if (mag > maxmag) {                                                                         \
911       maxmag = mag;                                                                             \
912       maxidx = i;                                                                               \
913     }                                                                                           \
914   }                                                                                             \
915   return maxidx / (gdouble) elements;                                                           \
916 }                                                                                               \
917 static gboolean is_zero_except_##ffttag (const GstFFT##ffttag##Complex *v, int elements,        \
918                                 gdouble spot)                                                   \
919 {                                                                                               \
920   int i;                                                                                        \
921   for (i=0; i<elements; ++i) {                                                                  \
922     gdouble pos = i / (gdouble) elements;                                                       \
923     gdouble mag = magnitude##ffttag (v+i);                                                      \
924     if (fabs (pos - spot) > 0.01) {                                                             \
925       if (mag > -55.0) {                                                                        \
926         return FALSE;                                                                           \
927       }                                                                                         \
928     }                                                                                           \
929   }                                                                                             \
930   return TRUE;                                                                                  \
931 }                                                                                               \
932 static void compare_ffts_##ffttag (GstBuffer *inbuffer, GstBuffer *outbuffer)                   \
933 {                                                                                               \
934   GstMapInfo inmap, outmap;                                                                     \
935   int insamples, outsamples;                                                                    \
936   gdouble inspot, outspot;                                                                      \
937   GstFFT##ffttag *inctx, *outctx;                                                               \
938   GstFFT##ffttag##Complex *in, *out;                                                            \
939                                                                                                 \
940   gst_buffer_map (inbuffer, &inmap, GST_MAP_READ);                                              \
941   gst_buffer_map (outbuffer, &outmap, GST_MAP_READWRITE);                                       \
942                                                                                                 \
943   insamples = inmap.size / sizeof(type) & ~1;                                                   \
944   outsamples = outmap.size / sizeof(type) & ~1;                                                 \
945   inctx = gst_fft_##ffttag2##_new (insamples, FALSE);                                           \
946   outctx = gst_fft_##ffttag2##_new (outsamples, FALSE);                                         \
947   in = g_new (GstFFT##ffttag##Complex, insamples / 2 + 1);                                      \
948   out = g_new (GstFFT##ffttag##Complex, outsamples / 2 + 1);                                    \
949                                                                                                 \
950   gst_fft_##ffttag2##_window (inctx, (type*)inmap.data,                                         \
951       GST_FFT_WINDOW_HAMMING);                                                                  \
952   gst_fft_##ffttag2##_fft (inctx, (type*)inmap.data, in);                                       \
953   gst_fft_##ffttag2##_window (outctx, (type*)outmap.data,                                       \
954       GST_FFT_WINDOW_HAMMING);                                                                  \
955   gst_fft_##ffttag2##_fft (outctx, (type*)outmap.data, out);                                    \
956                                                                                                 \
957   inspot = find_main_frequency_spot_##ffttag (in, insamples / 2 + 1);                           \
958   outspot = find_main_frequency_spot_##ffttag (out, outsamples / 2 + 1);                        \
959   GST_LOG ("Spots are %.3f and %.3f", inspot, outspot);                                         \
960   fail_unless (fabs (outspot - inspot) < 0.05);                                                 \
961   fail_unless (is_zero_except_##ffttag (in, insamples / 2 + 1, inspot));                        \
962   fail_unless (is_zero_except_##ffttag (out, outsamples / 2 + 1, outspot));                     \
963                                                                                                 \
964   gst_buffer_unmap (inbuffer, &inmap);                                                          \
965   gst_buffer_unmap (outbuffer, &outmap);                                                        \
966                                                                                                 \
967   gst_fft_##ffttag2##_free (inctx);                                                             \
968   gst_fft_##ffttag2##_free (outctx);                                                            \
969   g_free (in);                                                                                  \
970   g_free (out);                                                                                 \
971 }
972 FFT_HELPERS (float, F32, f32, 2048.0f);
973 FFT_HELPERS (double, F64, f64, 2048.0);
974 FFT_HELPERS (gint16, S16, s16, 32767.0);
975 FFT_HELPERS (gint32, S32, s32, 2147483647.0);
976 
977 #define FILL_BUFFER(type, desc, value);                         \
978   static void init_##type##_##desc (GstBuffer *buffer)          \
979   {                                                             \
980     GstMapInfo map;                                             \
981     type *ptr;                                                  \
982     int i, nsamples;                                            \
983     gst_buffer_map (buffer, &map, GST_MAP_WRITE);               \
984     ptr = (type *)map.data;                                     \
985     nsamples = map.size / sizeof (type);                        \
986     for (i = 0; i < nsamples; ++i) {                            \
987       *ptr++ = value;                                           \
988     }                                                           \
989     gst_buffer_unmap (buffer, &map);                            \
990   }
991 
992 FILL_BUFFER (float, silence, 0.0f);
993 FILL_BUFFER (double, silence, 0.0);
994 FILL_BUFFER (gint16, silence, 0);
995 FILL_BUFFER (gint32, silence, 0);
996 FILL_BUFFER (float, sine, sinf (i * 0.01f));
997 FILL_BUFFER (float, sine2, sinf (i * 1.8f));
998 FILL_BUFFER (double, sine, sin (i * 0.01));
999 FILL_BUFFER (double, sine2, sin (i * 1.8));
1000 FILL_BUFFER (gint16, sine, (gint16) (32767 * sinf (i * 0.01f)));
1001 FILL_BUFFER (gint16, sine2, (gint16) (32767 * sinf (i * 1.8f)));
1002 FILL_BUFFER (gint32, sine, (gint32) (2147483647 * sinf (i * 0.01f)));
1003 FILL_BUFFER (gint32, sine2, (gint32) (2147483647 * sinf (i * 1.8f)));
1004 
1005 static void
run_fft_pipeline(int inrate,int outrate,int quality,int width,const gchar * format,void (* init)(GstBuffer *),void (* compare_ffts)(GstBuffer *,GstBuffer *))1006 run_fft_pipeline (int inrate, int outrate, int quality, int width,
1007     const gchar * format, void (*init) (GstBuffer *),
1008     void (*compare_ffts) (GstBuffer *, GstBuffer *))
1009 {
1010   GstElement *audioresample;
1011   GstBuffer *inbuffer, *outbuffer;
1012   const int nsamples = 2048;
1013 
1014   audioresample = setup_audioresample (1, 0, inrate, outrate, format);
1015   fail_unless (audioresample != NULL);
1016   g_object_set (audioresample, "quality", quality, NULL);
1017 
1018   fail_unless (gst_element_set_state (audioresample,
1019           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
1020       "could not set to playing");
1021 
1022   inbuffer = gst_buffer_new_and_alloc (nsamples * width / 8);
1023   GST_BUFFER_DURATION (inbuffer) = GST_FRAMES_TO_CLOCK_TIME (nsamples, inrate);
1024   GST_BUFFER_TIMESTAMP (inbuffer) = 0;
1025 
1026   (*init) (inbuffer);
1027 
1028   gst_buffer_ref (inbuffer);
1029   /* pushing gives away my reference ... */
1030   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
1031   /* ... but it ends up being collected on the global buffer list */
1032   fail_unless_equals_int (g_list_length (buffers), 1);
1033   /* retrieve out buffer */
1034   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
1035 
1036   fail_unless (gst_element_set_state (audioresample,
1037           GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
1038 
1039   if (inbuffer == outbuffer)
1040     gst_buffer_unref (inbuffer);
1041 
1042   (*compare_ffts) (inbuffer, outbuffer);
1043 
1044   /* cleanup */
1045   cleanup_audioresample (audioresample);
1046 }
1047 
GST_START_TEST(test_fft)1048 GST_START_TEST (test_fft)
1049 {
1050   int quality;
1051   size_t f0, f1;
1052   static const int frequencies[] =
1053       { 8000, 16000, 44100, 48000, 128000, 12345, 54321 };
1054 
1055   /* audioresample uses a mixed float/double code path for floats with quality>8, make sure we test it */
1056   for (quality = 0; quality <= 10; quality += 5) {
1057     for (f0 = 0; f0 < G_N_ELEMENTS (frequencies); ++f0) {
1058       for (f1 = 0; f1 < G_N_ELEMENTS (frequencies); ++f1) {
1059         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32,
1060             GST_AUDIO_NE (F32), &init_float_silence, &compare_ffts_F32);
1061         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32,
1062             GST_AUDIO_NE (F32), &init_float_sine, &compare_ffts_F32);
1063         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32,
1064             GST_AUDIO_NE (F32), &init_float_sine2, &compare_ffts_F32);
1065         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64,
1066             GST_AUDIO_NE (F64), &init_double_silence, &compare_ffts_F64);
1067         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64,
1068             GST_AUDIO_NE (F64), &init_double_sine, &compare_ffts_F64);
1069         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 64,
1070             GST_AUDIO_NE (F64), &init_double_sine2, &compare_ffts_F64);
1071         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16,
1072             GST_AUDIO_NE (S16), &init_gint16_silence, &compare_ffts_S16);
1073         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16,
1074             GST_AUDIO_NE (S16), &init_gint16_sine, &compare_ffts_S16);
1075         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 16,
1076             GST_AUDIO_NE (S16), &init_gint16_sine2, &compare_ffts_S16);
1077         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32,
1078             GST_AUDIO_NE (S32), &init_gint32_silence, &compare_ffts_S32);
1079         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32,
1080             GST_AUDIO_NE (S32), &init_gint32_sine, &compare_ffts_S32);
1081         run_fft_pipeline (frequencies[f0], frequencies[f0], quality, 32,
1082             GST_AUDIO_NE (S32), &init_gint32_sine2, &compare_ffts_S32);
1083       }
1084     }
1085   }
1086 }
1087 
1088 GST_END_TEST;
1089 
1090 static Suite *
audioresample_suite(void)1091 audioresample_suite (void)
1092 {
1093   Suite *s = suite_create ("audioresample");
1094   TCase *tc_chain = tcase_create ("general");
1095 
1096   suite_add_tcase (s, tc_chain);
1097   tcase_add_test (tc_chain, test_perfect_stream);
1098   tcase_add_test (tc_chain, test_discont_stream);
1099   tcase_add_test (tc_chain, test_reuse);
1100   tcase_add_test (tc_chain, test_shutdown);
1101   tcase_add_test (tc_chain, test_live_switch);
1102   tcase_add_test (tc_chain, test_timestamp_drift);
1103   tcase_add_test (tc_chain, test_fft);
1104 
1105 #ifndef GST_DISABLE_PARSE
1106   tcase_set_timeout (tc_chain, 360);
1107   tcase_add_test (tc_chain, test_pipelines);
1108   tcase_add_test (tc_chain, test_preference_passthrough);
1109 #endif
1110 
1111   return s;
1112 }
1113 
1114 GST_CHECK_MAIN (audioresample);
1115