• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer unit tests for audiorate
2  *
3  * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24 
25 #include <gst/check/gstcheck.h>
26 #include <gst/audio/audio.h>
27 #include <gst/app/gstappsrc.h>
28 
29 /* helper element to insert additional buffers overlapping with previous ones */
30 static gdouble injector_inject_probability = 0.0;
31 
32 typedef GstElement TestInjector;
33 typedef GstElementClass TestInjectorClass;
34 
35 GType test_injector_get_type (void);
36 G_DEFINE_TYPE (TestInjector, test_injector, GST_TYPE_ELEMENT);
37 
38 #define FORMATS "{ "GST_AUDIO_NE(F32)", S8, S16LE, S16BE, " \
39                    "U16LE, U16NE, S32LE, S32BE, U32LE, U32BE }"
40 
41 #define INJECTOR_CAPS \
42   "audio/x-raw, "                                        \
43     "format = (string) "FORMATS", "                      \
44     "rate = (int) [ 1, MAX ], "                          \
45     "channels = (int) [ 1, 8 ]"
46 
47 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
48     GST_PAD_SRC,
49     GST_PAD_ALWAYS,
50     GST_STATIC_CAPS (INJECTOR_CAPS));
51 
52 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
53     GST_PAD_SINK,
54     GST_PAD_ALWAYS,
55     GST_STATIC_CAPS (INJECTOR_CAPS));
56 
57 static void
test_injector_class_init(TestInjectorClass * klass)58 test_injector_class_init (TestInjectorClass * klass)
59 {
60   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
61 
62   gst_element_class_add_static_pad_template (element_class, &src_template);
63   gst_element_class_add_static_pad_template (element_class, &sink_template);
64 }
65 
66 static GstFlowReturn
test_injector_chain(GstPad * pad,GstObject * parent,GstBuffer * buf)67 test_injector_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
68 {
69   GstFlowReturn ret;
70   GstPad *srcpad;
71 
72   srcpad = gst_element_get_static_pad (GST_ELEMENT (parent), "src");
73 
74   /* since we're increasing timestamp/offsets, push this one first */
75   GST_LOG (" passing buffer   [t=%" GST_TIME_FORMAT "-%" GST_TIME_FORMAT
76       "], offset=%" G_GINT64_FORMAT ", offset_end=%" G_GINT64_FORMAT,
77       GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
78       GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf)),
79       GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf));
80 
81   gst_buffer_ref (buf);
82 
83   ret = gst_pad_push (srcpad, buf);
84 
85   if (g_random_double () < injector_inject_probability) {
86     GstBuffer *ibuf;
87 
88     ibuf = gst_buffer_copy (buf);
89 
90     if (GST_BUFFER_OFFSET_IS_VALID (buf) &&
91         GST_BUFFER_OFFSET_END_IS_VALID (buf)) {
92       guint64 delta;
93 
94       delta = GST_BUFFER_OFFSET_END (buf) - GST_BUFFER_OFFSET (buf);
95       GST_BUFFER_OFFSET (ibuf) += delta / 4;
96       GST_BUFFER_OFFSET_END (ibuf) += delta / 4;
97     } else {
98       GST_BUFFER_OFFSET (ibuf) = GST_BUFFER_OFFSET_NONE;
99       GST_BUFFER_OFFSET_END (ibuf) = GST_BUFFER_OFFSET_NONE;
100     }
101 
102     if (GST_BUFFER_TIMESTAMP_IS_VALID (buf) &&
103         GST_BUFFER_DURATION_IS_VALID (buf)) {
104       GstClockTime delta;
105 
106       delta = GST_BUFFER_DURATION (buf);
107       GST_BUFFER_TIMESTAMP (ibuf) += delta / 4;
108     } else {
109       GST_BUFFER_TIMESTAMP (ibuf) = GST_CLOCK_TIME_NONE;
110       GST_BUFFER_DURATION (ibuf) = GST_CLOCK_TIME_NONE;
111     }
112 
113     if (GST_BUFFER_TIMESTAMP_IS_VALID (ibuf) ||
114         GST_BUFFER_OFFSET_IS_VALID (ibuf)) {
115       GST_LOG ("injecting buffer [t=%" GST_TIME_FORMAT "-%" GST_TIME_FORMAT
116           "], offset=%" G_GINT64_FORMAT ", offset_end=%" G_GINT64_FORMAT,
117           GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (ibuf)),
118           GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (ibuf) +
119               GST_BUFFER_DURATION (ibuf)), GST_BUFFER_OFFSET (ibuf),
120           GST_BUFFER_OFFSET_END (ibuf));
121 
122       if (gst_pad_push (srcpad, ibuf) != GST_FLOW_OK) {
123         /* ignore return value */
124       }
125     } else {
126       GST_WARNING ("couldn't inject buffer, no incoming timestamps or offsets");
127       gst_buffer_unref (ibuf);
128     }
129   }
130 
131   gst_buffer_unref (buf);
132   gst_object_unref (srcpad);
133 
134   return ret;
135 }
136 
137 static void
test_injector_init(TestInjector * injector)138 test_injector_init (TestInjector * injector)
139 {
140   GstPad *pad;
141 
142   pad = gst_pad_new_from_static_template (&sink_template, "sink");
143   gst_pad_set_chain_function (pad, test_injector_chain);
144   GST_PAD_SET_PROXY_CAPS (pad);
145   gst_element_add_pad (GST_ELEMENT (injector), pad);
146 
147   pad = gst_pad_new_from_static_template (&src_template, "src");
148   GST_PAD_SET_PROXY_CAPS (pad);
149   gst_element_add_pad (GST_ELEMENT (injector), pad);
150 }
151 
152 static GstPadProbeReturn
probe_cb(GstPad * pad,GstPadProbeInfo * info,gpointer user_data)153 probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
154 {
155   GstBuffer *buf = GST_PAD_PROBE_INFO_BUFFER (info);
156   gdouble *drop_probability = user_data;
157 
158   if (g_random_double () < *drop_probability) {
159     GST_LOG ("dropping buffer [t=%" GST_TIME_FORMAT "-%" GST_TIME_FORMAT "], "
160         "offset=%" G_GINT64_FORMAT ", offset_end=%" G_GINT64_FORMAT,
161         GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
162         GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf)),
163         GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf));
164     return GST_PAD_PROBE_DROP;  /* drop buffer */
165   }
166 
167   return GST_PAD_PROBE_OK;      /* don't drop buffer */
168 }
169 
170 static void
got_buf(GstElement * fakesink,GstBuffer * buf,GstPad * pad,GList ** p_bufs)171 got_buf (GstElement * fakesink, GstBuffer * buf, GstPad * pad, GList ** p_bufs)
172 {
173   *p_bufs = g_list_append (*p_bufs, gst_buffer_ref (buf));
174 }
175 
176 static void
do_perfect_stream_test(guint rate,const gchar * format,gdouble drop_probability,gdouble inject_probability)177 do_perfect_stream_test (guint rate, const gchar * format,
178     gdouble drop_probability, gdouble inject_probability)
179 {
180   GstElement *pipe, *src, *conv, *filter, *injector, *audiorate, *sink;
181   GstMessage *msg;
182   GstCaps *caps;
183   GstPad *srcpad;
184   GList *l, *bufs = NULL;
185   GstClockTime next_time = GST_CLOCK_TIME_NONE;
186   guint64 next_offset = GST_BUFFER_OFFSET_NONE;
187   GstAudioFormat fmt;
188   const GstAudioFormatInfo *finfo;
189   gint width;
190 
191   fmt = gst_audio_format_from_string (format);
192   fail_unless (fmt != GST_AUDIO_FORMAT_UNKNOWN);
193 
194   finfo = gst_audio_format_get_info (fmt);
195   width = GST_AUDIO_FORMAT_INFO_WIDTH (finfo);
196 
197   caps = gst_caps_new_simple ("audio/x-raw", "rate", G_TYPE_INT,
198       rate, "format", G_TYPE_STRING, format, NULL);
199 
200   GST_INFO ("-------- drop=%.0f%% caps = %" GST_PTR_FORMAT " ---------- ",
201       drop_probability * 100.0, caps);
202 
203   g_assert (drop_probability >= 0.0 && drop_probability <= 1.0);
204   g_assert (inject_probability >= 0.0 && inject_probability <= 1.0);
205 
206   pipe = gst_pipeline_new ("pipeline");
207   fail_unless (pipe != NULL);
208 
209   src = gst_element_factory_make ("audiotestsrc", "audiotestsrc");
210   fail_unless (src != NULL);
211 
212   g_object_set (src, "num-buffers", 10, NULL);
213 
214   conv = gst_element_factory_make ("audioconvert", "audioconvert");
215   fail_unless (conv != NULL);
216 
217   filter = gst_element_factory_make ("capsfilter", "capsfilter");
218   fail_unless (filter != NULL);
219 
220   g_object_set (filter, "caps", caps, NULL);
221 
222   injector_inject_probability = inject_probability;
223 
224   injector = GST_ELEMENT (g_object_new (test_injector_get_type (), NULL));
225 
226   srcpad = gst_element_get_static_pad (injector, "src");
227   fail_unless (srcpad != NULL);
228   gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_BUFFER, probe_cb,
229       &drop_probability, NULL);
230   gst_object_unref (srcpad);
231 
232   audiorate = gst_element_factory_make ("audiorate", "audiorate");
233   fail_unless (audiorate != NULL);
234 
235   sink = gst_element_factory_make ("fakesink", "fakesink");
236   fail_unless (sink != NULL);
237 
238   g_object_set (sink, "signal-handoffs", TRUE, NULL);
239 
240   g_signal_connect (sink, "handoff", G_CALLBACK (got_buf), &bufs);
241 
242   gst_bin_add_many (GST_BIN (pipe), src, conv, filter, injector, audiorate,
243       sink, NULL);
244   gst_element_link_many (src, conv, filter, injector, audiorate, sink, NULL);
245 
246   fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PLAYING),
247       GST_STATE_CHANGE_ASYNC);
248 
249   fail_unless_equals_int (gst_element_get_state (pipe, NULL, NULL, -1),
250       GST_STATE_CHANGE_SUCCESS);
251 
252   msg = gst_bus_poll (GST_ELEMENT_BUS (pipe),
253       GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
254   fail_unless_equals_string (GST_MESSAGE_TYPE_NAME (msg), "eos");
255 
256   for (l = bufs; l != NULL; l = l->next) {
257     GstBuffer *buf = GST_BUFFER (l->data);
258     guint num_samples;
259 
260     fail_unless (GST_BUFFER_TIMESTAMP_IS_VALID (buf));
261     fail_unless (GST_BUFFER_DURATION_IS_VALID (buf));
262     fail_unless (GST_BUFFER_OFFSET_IS_VALID (buf));
263     fail_unless (GST_BUFFER_OFFSET_END_IS_VALID (buf));
264 
265     GST_LOG ("buffer: ts=%" GST_TIME_FORMAT ", end_ts=%" GST_TIME_FORMAT
266         " off=%" G_GINT64_FORMAT ", end_off=%" G_GINT64_FORMAT,
267         GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
268         GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf)),
269         GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf));
270 
271     if (GST_CLOCK_TIME_IS_VALID (next_time)) {
272       fail_unless_equals_uint64 (next_time, GST_BUFFER_TIMESTAMP (buf));
273     }
274     if (next_offset != GST_BUFFER_OFFSET_NONE) {
275       fail_unless_equals_uint64 (next_offset, GST_BUFFER_OFFSET (buf));
276     }
277 
278     /* check buffer size for sanity */
279     fail_unless_equals_int (gst_buffer_get_size (buf) % (width / 8), 0);
280 
281     /* check there is actually as much data as there should be */
282     num_samples = GST_BUFFER_OFFSET_END (buf) - GST_BUFFER_OFFSET (buf);
283     fail_unless_equals_int (gst_buffer_get_size (buf),
284         num_samples * (width / 8));
285 
286     next_time = GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf);
287     next_offset = GST_BUFFER_OFFSET_END (buf);
288   }
289 
290   gst_message_unref (msg);
291   gst_element_set_state (pipe, GST_STATE_NULL);
292   gst_object_unref (pipe);
293 
294   g_list_foreach (bufs, (GFunc) gst_mini_object_unref, NULL);
295   g_list_free (bufs);
296 
297   gst_caps_unref (caps);
298 }
299 
300 static const guint rates[] = { 8000, 11025, 16000, 22050, 32000, 44100,
301   48000, 3333, 33333, 66666, 9999
302 };
303 
GST_START_TEST(test_perfect_stream_drop0)304 GST_START_TEST (test_perfect_stream_drop0)
305 {
306   guint i;
307 
308   for (i = 0; i < G_N_ELEMENTS (rates); ++i) {
309     do_perfect_stream_test (rates[i], "S8", 0.0, 0.0);
310     do_perfect_stream_test (rates[i], GST_AUDIO_NE (S16), 0.0, 0.0);
311   }
312 }
313 
314 GST_END_TEST;
315 
GST_START_TEST(test_perfect_stream_drop10)316 GST_START_TEST (test_perfect_stream_drop10)
317 {
318   guint i;
319 
320   for (i = 0; i < G_N_ELEMENTS (rates); ++i) {
321     do_perfect_stream_test (rates[i], "S8", 0.10, 0.0);
322     do_perfect_stream_test (rates[i], GST_AUDIO_NE (S16), 0.10, 0.0);
323   }
324 }
325 
326 GST_END_TEST;
327 
GST_START_TEST(test_perfect_stream_drop50)328 GST_START_TEST (test_perfect_stream_drop50)
329 {
330   guint i;
331 
332   for (i = 0; i < G_N_ELEMENTS (rates); ++i) {
333     do_perfect_stream_test (rates[i], "S8", 0.50, 0.0);
334     do_perfect_stream_test (rates[i], GST_AUDIO_NE (S16), 0.50, 0.0);
335   }
336 }
337 
338 GST_END_TEST;
339 
GST_START_TEST(test_perfect_stream_drop90)340 GST_START_TEST (test_perfect_stream_drop90)
341 {
342   guint i;
343 
344   for (i = 0; i < G_N_ELEMENTS (rates); ++i) {
345     do_perfect_stream_test (rates[i], "S8", 0.90, 0.0);
346     do_perfect_stream_test (rates[i], GST_AUDIO_NE (S16), 0.90, 0.0);
347   }
348 }
349 
350 GST_END_TEST;
351 
GST_START_TEST(test_perfect_stream_inject10)352 GST_START_TEST (test_perfect_stream_inject10)
353 {
354   guint i;
355 
356   for (i = 0; i < G_N_ELEMENTS (rates); ++i) {
357     do_perfect_stream_test (rates[i], "S8", 0.0, 0.10);
358     do_perfect_stream_test (rates[i], GST_AUDIO_NE (S16), 0.0, 0.10);
359   }
360 }
361 
362 GST_END_TEST;
363 
GST_START_TEST(test_perfect_stream_inject90)364 GST_START_TEST (test_perfect_stream_inject90)
365 {
366   guint i;
367 
368   for (i = 0; i < G_N_ELEMENTS (rates); ++i) {
369     do_perfect_stream_test (rates[i], "S8", 0.0, 0.90);
370     do_perfect_stream_test (rates[i], GST_AUDIO_NE (S16), 0.0, 0.90);
371   }
372 }
373 
374 GST_END_TEST;
375 
GST_START_TEST(test_perfect_stream_drop45_inject25)376 GST_START_TEST (test_perfect_stream_drop45_inject25)
377 {
378   guint i;
379 
380   for (i = 0; i < G_N_ELEMENTS (rates); ++i) {
381     do_perfect_stream_test (rates[i], "S8", 0.45, 0.25);
382     do_perfect_stream_test (rates[i], GST_AUDIO_NE (S16), 0.45, 0.25);
383   }
384 }
385 
386 GST_END_TEST;
387 
388 /* TODO: also do all tests with channels=1 and channels=2 */
389 
390 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
391     GST_PAD_SRC,
392     GST_PAD_ALWAYS,
393     GST_STATIC_CAPS ("audio/x-raw,format=" GST_AUDIO_NE (F32)
394         ",channels=1,rate=44100")
395     );
396 
397 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
398     GST_PAD_SINK,
399     GST_PAD_ALWAYS,
400     GST_STATIC_CAPS ("audio/x-raw,format=" GST_AUDIO_NE (F32)
401         ",channels=1,rate=44100")
402     );
403 
GST_START_TEST(test_large_discont)404 GST_START_TEST (test_large_discont)
405 {
406   GstElement *audiorate;
407   GstCaps *caps;
408   GstPad *srcpad, *sinkpad;
409   GstBuffer *buf;
410 
411   audiorate = gst_check_setup_element ("audiorate");
412   caps = gst_caps_new_simple ("audio/x-raw",
413       "format", G_TYPE_STRING, GST_AUDIO_NE (F32),
414       "layout", G_TYPE_STRING, "interleaved",
415       "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, 44100, NULL);
416 
417   srcpad = gst_check_setup_src_pad (audiorate, &srctemplate);
418   sinkpad = gst_check_setup_sink_pad (audiorate, &sinktemplate);
419 
420   gst_pad_set_active (srcpad, TRUE);
421 
422   gst_check_setup_events (srcpad, audiorate, caps, GST_FORMAT_TIME);
423 
424   gst_pad_set_active (sinkpad, TRUE);
425 
426   fail_unless (gst_element_set_state (audiorate,
427           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
428       "failed to set audiorate playing");
429 
430   buf = gst_buffer_new_and_alloc (4);
431   GST_BUFFER_TIMESTAMP (buf) = 0;
432   gst_pad_push (srcpad, buf);
433 
434   fail_unless_equals_int (g_list_length (buffers), 1);
435 
436   buf = gst_buffer_new_and_alloc (4);
437   GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
438   gst_pad_push (srcpad, buf);
439   /* Now we should have 3 more buffers: the one we injected, plus _two_ filler
440    * buffers, because the gap is > 1 second (but less than 2 seconds) */
441   fail_unless_equals_int (g_list_length (buffers), 4);
442 
443   gst_element_set_state (audiorate, GST_STATE_NULL);
444   gst_caps_unref (caps);
445 
446   gst_check_drop_buffers ();
447   gst_check_teardown_sink_pad (audiorate);
448   gst_check_teardown_src_pad (audiorate);
449 
450   gst_object_unref (audiorate);
451 }
452 
453 GST_END_TEST;
454 
455 
456 #define FIRST_CAPS \
457   "audio/x-raw,format=S16LE,layout=interleaved,rate=48000,channels=1"
458 #define SECOND_CAPS \
459   "audio/x-raw,format=S16LE,layout=interleaved,rate=8000,channels=1"
460 
461 #define BUFFERS_BEFORE_CHANGE 10
462 #define TOTAL_BUFFERS (BUFFERS_BEFORE_CHANGE * 2)
463 
464 static GList *
generate_buffers(gint from_rate,gint to_rate)465 generate_buffers (gint from_rate, gint to_rate)
466 {
467   GQueue q = G_QUEUE_INIT;
468   GstBuffer *buf;
469   guint i;
470   GstClockTime pts = 0;
471 
472   for (i = 0; i < BUFFERS_BEFORE_CHANGE; i++) {
473     buf = gst_buffer_new_allocate (NULL, 2 * from_rate / 100, NULL);
474     gst_buffer_memset (buf, 0, 1, gst_buffer_get_size (buf));
475     GST_BUFFER_PTS (buf) = pts;
476     GST_BUFFER_DURATION (buf) = GST_SECOND / 100;
477     pts += GST_BUFFER_DURATION (buf);
478     g_queue_push_tail (&q, buf);
479   }
480 
481   for (; i < TOTAL_BUFFERS; i++) {
482     buf = gst_buffer_new_allocate (NULL, 2 * to_rate / 100, NULL);
483     gst_buffer_memset (buf, 0, 1, gst_buffer_get_size (buf));
484     GST_BUFFER_PTS (buf) = pts;
485     GST_BUFFER_DURATION (buf) = GST_SECOND / 100;
486     pts += GST_BUFFER_DURATION (buf);
487     g_queue_push_tail (&q, buf);
488   }
489 
490   return q.head;
491 }
492 
GST_START_TEST(test_rate_change_down)493 GST_START_TEST (test_rate_change_down)
494 {
495   GList *l, *rbufs = NULL, *bufs = NULL;
496   GstElement *pipeline;
497   GstElement *sink;
498   GstElement *src;
499   GstElement *audiorate;
500   GstCaps *caps1, *caps2;
501   int i = 0;
502   gint64 drop, in, out;
503   GstBus *bus;
504 
505   caps1 = gst_caps_from_string (FIRST_CAPS);
506   caps2 = gst_caps_from_string (SECOND_CAPS);
507 
508   bufs = generate_buffers (48000, 8000);
509 
510   pipeline =
511       gst_parse_launch
512       ("appsrc name=src is-live=true format=time !"
513       " audiorate name=audiorate ! fakesink name=sink signal-handoffs=true",
514       NULL);
515 
516   fail_if (pipeline == NULL);
517 
518   sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
519   g_signal_connect (sink, "handoff", G_CALLBACK (got_buf), &rbufs);
520   gst_object_unref (sink);
521 
522   src = gst_bin_get_by_name (GST_BIN (pipeline), "src");
523   gst_app_src_set_caps (GST_APP_SRC (src), caps1);
524 
525   gst_element_set_state (pipeline, GST_STATE_PLAYING);
526 
527   for (l = bufs; l != NULL; l = l->next) {
528     if (i++ == BUFFERS_BEFORE_CHANGE) {
529       gst_app_src_set_caps (GST_APP_SRC (src), caps2);
530     }
531     GST_LOG ("Position: %" GST_TIME_FORMAT " Duration: %" GST_TIME_FORMAT "\n",
532         GST_TIME_ARGS (GST_BUFFER_PTS (l->data)),
533         GST_TIME_ARGS (GST_BUFFER_DURATION (l->data)));
534     fail_unless_equals_int (gst_app_src_push_buffer (GST_APP_SRC (src),
535             GST_BUFFER (l->data)), GST_FLOW_OK);
536   }
537 
538   g_list_free (bufs);
539 
540   gst_app_src_end_of_stream (GST_APP_SRC (src));
541   gst_object_unref (src);
542 
543   /* Give some time to the appsrc loop to push the buffers */
544   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
545   gst_message_unref (gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
546           GST_MESSAGE_EOS));
547   gst_object_unref (bus);
548 
549   audiorate = gst_bin_get_by_name (GST_BIN (pipeline), "audiorate");
550   g_object_get (audiorate, "drop", &drop, "out", &out, "in", &in, NULL);
551   gst_object_unref (audiorate);
552 
553   fail_unless_equals_int64 (drop, 0);
554 
555   g_list_foreach (rbufs, (GFunc) gst_mini_object_unref, NULL);
556   g_list_free (rbufs);
557 
558   gst_element_set_state (pipeline, GST_STATE_NULL);
559   gst_object_unref (pipeline);
560 
561   gst_caps_unref (caps1);
562   gst_caps_unref (caps2);
563 }
564 
565 GST_END_TEST;
566 
567 static Suite *
audiorate_suite(void)568 audiorate_suite (void)
569 {
570   Suite *s = suite_create ("audiorate");
571   TCase *tc_chain = tcase_create ("general");
572 
573   suite_add_tcase (s, tc_chain);
574 
575   tcase_add_test (tc_chain, test_perfect_stream_drop0);
576   tcase_add_test (tc_chain, test_perfect_stream_drop10);
577   tcase_add_test (tc_chain, test_perfect_stream_drop50);
578   tcase_add_test (tc_chain, test_perfect_stream_drop90);
579   tcase_add_test (tc_chain, test_perfect_stream_inject10);
580   tcase_add_test (tc_chain, test_perfect_stream_inject90);
581   tcase_add_test (tc_chain, test_perfect_stream_drop45_inject25);
582   tcase_add_test (tc_chain, test_large_discont);
583   tcase_add_test (tc_chain, test_rate_change_down);
584 
585   return s;
586 }
587 
588 GST_CHECK_MAIN (audiorate);
589