3 * unit test for audiomixer
5 * Copyright (C) 2005 Thomas Vander Stichele <thomas at apestaart dot org>
6 * Copyright (C) 2013 Sebastian Dröge <sebastian@centricular.com>
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.
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.
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.
29 # include <valgrind/valgrind.h>
32 #include <gst/check/gstcheck.h>
33 #include <gst/check/gstconsistencychecker.h>
34 #include <gst/audio/audio.h>
35 #include <gst/base/gstbasesrc.h>
36 #include <gst/controller/gstdirectcontrolbinding.h>
37 #include <gst/controller/gstinterpolationcontrolsource.h>
39 static GMainLoop *main_loop;
46 main_loop = g_main_loop_new (NULL, FALSE);
52 g_main_loop_unref (main_loop);
57 /* some test helpers */
60 setup_pipeline (GstElement * audiomixer, gint num_srcs, GstElement * capsfilter)
62 GstElement *pipeline, *src, *sink;
65 pipeline = gst_pipeline_new ("pipeline");
67 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
70 sink = gst_element_factory_make ("fakesink", "sink");
71 gst_bin_add_many (GST_BIN (pipeline), audiomixer, sink, NULL);
74 gst_bin_add (GST_BIN (pipeline), capsfilter);
75 gst_element_link_many (audiomixer, capsfilter, sink, NULL);
77 gst_element_link (audiomixer, sink);
80 for (i = 0; i < num_srcs; i++) {
81 src = gst_element_factory_make ("audiotestsrc", NULL);
82 g_object_set (src, "wave", 4, NULL); /* silence */
83 gst_bin_add (GST_BIN (pipeline), src);
84 gst_element_link (src, audiomixer);
90 get_element_sink_pad_caps (GstElement * pipeline, const gchar * element_name)
96 sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
97 pad = gst_element_get_static_pad (sink, "sink");
98 caps = gst_pad_get_current_caps (pad);
99 gst_object_unref (pad);
100 gst_object_unref (sink);
106 set_state_and_wait (GstElement * pipeline, GstState state)
108 GstStateChangeReturn state_res;
110 /* prepare paused/playing */
111 state_res = gst_element_set_state (pipeline, state);
112 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
114 /* wait for preroll */
115 state_res = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
116 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
120 set_playing (GstElement * element)
122 GstStateChangeReturn state_res;
124 state_res = gst_element_set_state (element, GST_STATE_PLAYING);
125 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
131 play_and_wait (GstElement * pipeline)
133 GstStateChangeReturn state_res;
135 g_idle_add ((GSourceFunc) set_playing, pipeline);
137 GST_INFO ("running main loop");
138 g_main_loop_run (main_loop);
140 state_res = gst_element_set_state (pipeline, GST_STATE_NULL);
141 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
145 message_received (GstBus * bus, GstMessage * message, GstPipeline * bin)
147 GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
148 GST_MESSAGE_SRC (message), message);
150 switch (message->type) {
151 case GST_MESSAGE_EOS:
152 g_main_loop_quit (main_loop);
154 case GST_MESSAGE_WARNING:{
158 gst_message_parse_warning (message, &gerror, &debug);
159 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
160 g_error_free (gerror);
164 case GST_MESSAGE_ERROR:{
168 gst_message_parse_error (message, &gerror, &debug);
169 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
170 g_error_free (gerror);
172 g_main_loop_quit (main_loop);
181 new_buffer (gsize num_bytes, gint data, GstClockTime ts, GstClockTime dur,
182 GstBufferFlags flags)
185 GstBuffer *buffer = gst_buffer_new_and_alloc (num_bytes);
187 gst_buffer_map (buffer, &map, GST_MAP_WRITE);
188 memset (map.data, data, map.size);
189 gst_buffer_unmap (buffer, &map);
190 GST_BUFFER_TIMESTAMP (buffer) = ts;
191 GST_BUFFER_DURATION (buffer) = dur;
193 GST_BUFFER_FLAG_SET (buffer, flags);
194 GST_DEBUG ("created buffer %p", buffer);
198 /* make sure downstream gets a CAPS event before buffers are sent */
199 GST_START_TEST (test_caps)
201 GstElement *pipeline;
205 pipeline = setup_pipeline (NULL, 1, NULL);
207 /* prepare playing */
208 set_state_and_wait (pipeline, GST_STATE_PAUSED);
210 /* check caps on fakesink */
211 caps = get_element_sink_pad_caps (pipeline, "sink");
212 fail_unless (caps != NULL);
213 gst_caps_unref (caps);
215 gst_element_set_state (pipeline, GST_STATE_NULL);
216 gst_object_unref (pipeline);
221 /* check that caps set on the property are honoured */
222 GST_START_TEST (test_filter_caps)
224 GstElement *pipeline, *audiomixer, *capsfilter;
225 GstCaps *filter_caps, *caps;
227 filter_caps = gst_caps_new_simple ("audio/x-raw",
228 "format", G_TYPE_STRING, GST_AUDIO_NE (F32),
229 "layout", G_TYPE_STRING, "interleaved",
230 "rate", G_TYPE_INT, 44100, "channels", G_TYPE_INT, 1,
231 "channel-mask", GST_TYPE_BITMASK, (guint64) 0x04, NULL);
233 capsfilter = gst_element_factory_make ("capsfilter", NULL);
236 audiomixer = gst_element_factory_make ("audiomixer", NULL);
237 g_object_set (capsfilter, "caps", filter_caps, NULL);
238 pipeline = setup_pipeline (audiomixer, 1, capsfilter);
240 /* prepare playing */
241 set_state_and_wait (pipeline, GST_STATE_PAUSED);
243 /* check caps on fakesink */
244 caps = get_element_sink_pad_caps (pipeline, "sink");
245 fail_unless (caps != NULL);
246 GST_INFO_OBJECT (pipeline, "received caps: %" GST_PTR_FORMAT, caps);
247 fail_unless (gst_caps_is_equal_fixed (caps, filter_caps));
248 gst_caps_unref (caps);
250 gst_element_set_state (pipeline, GST_STATE_NULL);
251 gst_object_unref (pipeline);
253 gst_caps_unref (filter_caps);
258 static GstFormat format = GST_FORMAT_UNDEFINED;
259 static gint64 position = -1;
262 test_event_message_received (GstBus * bus, GstMessage * message,
265 GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
266 GST_MESSAGE_SRC (message), message);
268 switch (message->type) {
269 case GST_MESSAGE_SEGMENT_DONE:
270 gst_message_parse_segment_done (message, &format, &position);
271 GST_INFO ("received segment_done : %" G_GINT64_FORMAT, position);
272 g_main_loop_quit (main_loop);
275 g_assert_not_reached ();
281 GST_START_TEST (test_event)
283 GstElement *bin, *src1, *src2, *audiomixer, *sink;
285 GstEvent *seek_event;
287 GstPad *srcpad, *sinkpad;
288 GstStreamConsistency *chk_1, *chk_2, *chk_3;
290 GST_INFO ("preparing test");
293 bin = gst_pipeline_new ("pipeline");
294 bus = gst_element_get_bus (bin);
295 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
297 src1 = gst_element_factory_make ("audiotestsrc", "src1");
298 g_object_set (src1, "wave", 4, NULL); /* silence */
299 src2 = gst_element_factory_make ("audiotestsrc", "src2");
300 g_object_set (src2, "wave", 4, NULL); /* silence */
301 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
302 sink = gst_element_factory_make ("fakesink", "sink");
303 gst_bin_add_many (GST_BIN (bin), src1, src2, audiomixer, sink, NULL);
305 res = gst_element_link (src1, audiomixer);
306 fail_unless (res == TRUE, NULL);
307 res = gst_element_link (src2, audiomixer);
308 fail_unless (res == TRUE, NULL);
309 res = gst_element_link (audiomixer, sink);
310 fail_unless (res == TRUE, NULL);
312 srcpad = gst_element_get_static_pad (audiomixer, "src");
313 chk_3 = gst_consistency_checker_new (srcpad);
314 gst_object_unref (srcpad);
316 /* create consistency checkers for the pads */
317 srcpad = gst_element_get_static_pad (src1, "src");
318 chk_1 = gst_consistency_checker_new (srcpad);
319 sinkpad = gst_pad_get_peer (srcpad);
320 gst_consistency_checker_add_pad (chk_3, sinkpad);
321 gst_object_unref (sinkpad);
322 gst_object_unref (srcpad);
324 srcpad = gst_element_get_static_pad (src2, "src");
325 chk_2 = gst_consistency_checker_new (srcpad);
326 sinkpad = gst_pad_get_peer (srcpad);
327 gst_consistency_checker_add_pad (chk_3, sinkpad);
328 gst_object_unref (sinkpad);
329 gst_object_unref (srcpad);
331 seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
332 GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
333 GST_SEEK_TYPE_SET, (GstClockTime) 0,
334 GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
336 format = GST_FORMAT_UNDEFINED;
339 g_signal_connect (bus, "message::segment-done",
340 (GCallback) test_event_message_received, bin);
341 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
342 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
343 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
345 GST_INFO ("starting test");
347 /* prepare playing */
348 set_state_and_wait (bin, GST_STATE_PAUSED);
350 res = gst_element_send_event (bin, seek_event);
351 fail_unless (res == TRUE, NULL);
356 ck_assert_int_eq (position, 2 * GST_SECOND);
359 gst_consistency_checker_free (chk_1);
360 gst_consistency_checker_free (chk_2);
361 gst_consistency_checker_free (chk_3);
362 gst_bus_remove_signal_watch (bus);
363 gst_object_unref (bus);
364 gst_object_unref (bin);
369 static guint play_count = 0;
370 static GstEvent *play_seek_event = NULL;
373 test_play_twice_message_received (GstBus * bus, GstMessage * message,
377 GstStateChangeReturn state_res;
379 GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
380 GST_MESSAGE_SRC (message), message);
382 switch (message->type) {
383 case GST_MESSAGE_SEGMENT_DONE:
385 if (play_count == 1) {
386 state_res = gst_element_set_state (bin, GST_STATE_READY);
387 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
389 /* prepare playing again */
390 set_state_and_wait (bin, GST_STATE_PAUSED);
392 gst_event_set_seqnum (play_seek_event, gst_util_seqnum_next ());
393 res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
394 fail_unless (res == TRUE, NULL);
396 state_res = gst_element_set_state (bin, GST_STATE_PLAYING);
397 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
399 g_main_loop_quit (main_loop);
403 g_assert_not_reached ();
409 GST_START_TEST (test_play_twice)
411 GstElement *bin, *audiomixer;
415 GstStreamConsistency *consist;
417 GST_INFO ("preparing test");
420 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
421 bin = setup_pipeline (audiomixer, 2, NULL);
422 bus = gst_element_get_bus (bin);
423 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
425 srcpad = gst_element_get_static_pad (audiomixer, "src");
426 consist = gst_consistency_checker_new (srcpad);
427 gst_object_unref (srcpad);
429 play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
430 GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
431 GST_SEEK_TYPE_SET, (GstClockTime) 0,
432 GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
436 g_signal_connect (bus, "message::segment-done",
437 (GCallback) test_play_twice_message_received, bin);
438 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
439 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
440 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
442 GST_INFO ("starting test");
444 /* prepare playing */
445 set_state_and_wait (bin, GST_STATE_PAUSED);
447 gst_event_set_seqnum (play_seek_event, gst_util_seqnum_next ());
448 res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
449 fail_unless (res == TRUE, NULL);
456 ck_assert_int_eq (play_count, 2);
459 gst_consistency_checker_free (consist);
460 gst_event_unref (play_seek_event);
461 gst_bus_remove_signal_watch (bus);
462 gst_object_unref (bus);
463 gst_object_unref (bin);
468 GST_START_TEST (test_play_twice_then_add_and_play_again)
470 GstElement *bin, *src, *audiomixer;
473 GstStateChangeReturn state_res;
476 GstStreamConsistency *consist;
478 GST_INFO ("preparing test");
481 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
482 bin = setup_pipeline (audiomixer, 2, NULL);
483 bus = gst_element_get_bus (bin);
484 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
486 srcpad = gst_element_get_static_pad (audiomixer, "src");
487 consist = gst_consistency_checker_new (srcpad);
488 gst_object_unref (srcpad);
490 play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
491 GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
492 GST_SEEK_TYPE_SET, (GstClockTime) 0,
493 GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
495 g_signal_connect (bus, "message::segment-done",
496 (GCallback) test_play_twice_message_received, bin);
497 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
498 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
499 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
502 for (i = 0; i < 2; i++) {
505 GST_INFO ("starting test-loop %d", i);
507 /* prepare playing */
508 set_state_and_wait (bin, GST_STATE_PAUSED);
510 gst_event_set_seqnum (play_seek_event, gst_util_seqnum_next ());
511 res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
512 fail_unless (res == TRUE, NULL);
519 ck_assert_int_eq (play_count, 2);
521 /* plug another source */
523 src = gst_element_factory_make ("audiotestsrc", NULL);
524 g_object_set (src, "wave", 4, NULL); /* silence */
525 gst_bin_add (GST_BIN (bin), src);
527 res = gst_element_link (src, audiomixer);
528 fail_unless (res == TRUE, NULL);
531 gst_consistency_checker_reset (consist);
534 state_res = gst_element_set_state (bin, GST_STATE_NULL);
535 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
538 gst_event_unref (play_seek_event);
539 gst_consistency_checker_free (consist);
540 gst_bus_remove_signal_watch (bus);
541 gst_object_unref (bus);
542 gst_object_unref (bin);
547 /* test failing seeks on live-sources */
548 GST_START_TEST (test_live_seeking)
550 GstElement *bin, *src1 = NULL, *cf, *src2, *audiomixer, *sink;
557 GstStreamConsistency *consist;
559 GST_INFO ("preparing test");
560 play_seek_event = NULL;
563 bin = gst_pipeline_new ("pipeline");
564 bus = gst_element_get_bus (bin);
565 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
567 src1 = gst_element_factory_make ("audiotestsrc", "src1");
568 g_object_set (src1, "wave", 4, "is-live", TRUE, NULL); /* silence */
570 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
571 cf = gst_element_factory_make ("capsfilter", "capsfilter");
572 sink = gst_element_factory_make ("fakesink", "sink");
574 gst_bin_add_many (GST_BIN (bin), src1, cf, audiomixer, sink, NULL);
575 res = gst_element_link_many (src1, cf, audiomixer, sink, NULL);
576 fail_unless (res == TRUE, NULL);
578 /* get the caps for the livesrc, we'll reuse this for the non-live source */
579 set_state_and_wait (bin, GST_STATE_PLAYING);
581 sinkpad = gst_element_get_static_pad (sink, "sink");
582 fail_unless (sinkpad != NULL);
583 caps = gst_pad_get_current_caps (sinkpad);
584 fail_unless (caps != NULL);
585 gst_object_unref (sinkpad);
587 gst_element_set_state (bin, GST_STATE_NULL);
589 g_object_set (cf, "caps", caps, NULL);
591 src2 = gst_element_factory_make ("audiotestsrc", "src2");
592 g_object_set (src2, "wave", 4, NULL); /* silence */
593 gst_bin_add (GST_BIN (bin), src2);
595 res = gst_element_link_filtered (src2, audiomixer, caps);
596 fail_unless (res == TRUE, NULL);
598 gst_caps_unref (caps);
600 play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
602 GST_SEEK_TYPE_SET, (GstClockTime) 0,
603 GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
605 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
606 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
607 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
609 srcpad = gst_element_get_static_pad (audiomixer, "src");
610 consist = gst_consistency_checker_new (srcpad);
611 gst_object_unref (srcpad);
613 GST_INFO ("starting test");
616 for (i = 0; i < 2; i++) {
618 GST_INFO ("starting test-loop %d", i);
620 /* prepare playing */
621 set_state_and_wait (bin, GST_STATE_PAUSED);
623 gst_event_set_seqnum (play_seek_event, gst_util_seqnum_next ());
624 res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
625 fail_unless (res == TRUE, NULL);
632 gst_consistency_checker_reset (consist);
636 GST_INFO ("cleaning up");
637 gst_consistency_checker_free (consist);
639 gst_event_unref (play_seek_event);
640 gst_bus_remove_signal_watch (bus);
641 gst_object_unref (bus);
642 gst_object_unref (bin);
647 /* check if adding pads work as expected */
648 GST_START_TEST (test_add_pad)
650 GstElement *bin, *src1, *src2, *audiomixer, *sink;
654 GstStateChangeReturn state_res;
656 GST_INFO ("preparing test");
659 bin = gst_pipeline_new ("pipeline");
660 bus = gst_element_get_bus (bin);
661 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
663 src1 = gst_element_factory_make ("audiotestsrc", "src1");
664 g_object_set (src1, "num-buffers", 4, "wave", /* silence */ 4, NULL);
665 src2 = gst_element_factory_make ("audiotestsrc", "src2");
666 /* one buffer less, we connect with 1 buffer of delay */
667 g_object_set (src2, "num-buffers", 3, "wave", /* silence */ 4, NULL);
668 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
669 sink = gst_element_factory_make ("fakesink", "sink");
670 gst_bin_add_many (GST_BIN (bin), src1, audiomixer, sink, NULL);
672 res = gst_element_link (src1, audiomixer);
673 fail_unless (res == TRUE, NULL);
674 res = gst_element_link (audiomixer, sink);
675 fail_unless (res == TRUE, NULL);
677 srcpad = gst_element_get_static_pad (audiomixer, "src");
678 gst_object_unref (srcpad);
680 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
682 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
683 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
684 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
686 GST_INFO ("starting test");
688 /* prepare playing */
689 set_state_and_wait (bin, GST_STATE_PAUSED);
691 /* add other element */
692 gst_bin_add_many (GST_BIN (bin), src2, NULL);
694 /* now link the second element */
695 res = gst_element_link (src2, audiomixer);
696 fail_unless (res == TRUE, NULL);
698 /* set to PAUSED as well */
699 state_res = gst_element_set_state (src2, GST_STATE_PAUSED);
700 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
706 gst_bus_remove_signal_watch (bus);
707 gst_object_unref (bus);
708 gst_object_unref (bin);
713 /* check if removing pads work as expected */
714 GST_START_TEST (test_remove_pad)
716 GstElement *bin, *src, *audiomixer, *sink;
718 GstPad *pad, *srcpad;
720 GstStateChangeReturn state_res;
722 GST_INFO ("preparing test");
725 bin = gst_pipeline_new ("pipeline");
726 bus = gst_element_get_bus (bin);
727 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
729 src = gst_element_factory_make ("audiotestsrc", "src");
730 g_object_set (src, "num-buffers", 4, "wave", 4, NULL);
731 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
732 sink = gst_element_factory_make ("fakesink", "sink");
733 gst_bin_add_many (GST_BIN (bin), src, audiomixer, sink, NULL);
735 res = gst_element_link (src, audiomixer);
736 fail_unless (res == TRUE, NULL);
737 res = gst_element_link (audiomixer, sink);
738 fail_unless (res == TRUE, NULL);
740 /* create an unconnected sinkpad in audiomixer */
741 pad = gst_element_request_pad_simple (audiomixer, "sink_%u");
742 fail_if (pad == NULL, NULL);
744 srcpad = gst_element_get_static_pad (audiomixer, "src");
745 gst_object_unref (srcpad);
747 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
749 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
750 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
751 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
753 GST_INFO ("starting test");
755 /* prepare playing, this will not preroll as audiomixer is waiting
756 * on the unconnected sinkpad. */
757 state_res = gst_element_set_state (bin, GST_STATE_PAUSED);
758 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
760 /* wait for completion for one second, will return ASYNC */
761 state_res = gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_SECOND);
762 ck_assert_int_eq (state_res, GST_STATE_CHANGE_ASYNC);
764 /* get rid of the pad now, audiomixer should stop waiting on it and
765 * continue the preroll */
766 gst_element_release_request_pad (audiomixer, pad);
767 gst_object_unref (pad);
769 /* wait for completion, should work now */
771 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
772 GST_CLOCK_TIME_NONE);
773 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
779 gst_bus_remove_signal_watch (bus);
780 gst_object_unref (G_OBJECT (bus));
781 gst_object_unref (G_OBJECT (bin));
787 static GstBuffer *handoff_buffer = NULL;
790 handoff_buffer_cb (GstElement * fakesink, GstBuffer * buffer, GstPad * pad,
793 GST_DEBUG ("got buffer -- SIZE: %" G_GSIZE_FORMAT
794 " -- %p PTS is %" GST_TIME_FORMAT " END is %" GST_TIME_FORMAT,
795 gst_buffer_get_size (buffer), buffer,
796 GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
797 GST_TIME_ARGS (GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer)));
799 gst_buffer_replace (&handoff_buffer, buffer);
802 /* check if clipping works as expected */
803 GST_START_TEST (test_clip)
806 GstElement *bin, *audiomixer, *sink;
810 GstStateChangeReturn state_res;
815 GstQuery *drain = gst_query_new_drain ();
817 GST_INFO ("preparing test");
820 bin = gst_pipeline_new ("pipeline");
821 bus = gst_element_get_bus (bin);
822 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
824 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
825 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
826 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
828 /* just an audiomixer and a fakesink */
829 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
830 g_object_set (audiomixer, "output-buffer-duration", 50 * GST_MSECOND, NULL);
831 sink = gst_element_factory_make ("fakesink", "sink");
832 g_object_set (sink, "signal-handoffs", TRUE, NULL);
833 g_signal_connect (sink, "handoff", (GCallback) handoff_buffer_cb, NULL);
834 gst_bin_add_many (GST_BIN (bin), audiomixer, sink, NULL);
836 res = gst_element_link (audiomixer, sink);
837 fail_unless (res == TRUE, NULL);
840 state_res = gst_element_set_state (bin, GST_STATE_PLAYING);
841 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
843 /* create an unconnected sinkpad in audiomixer, should also automatically activate
845 sinkpad = gst_element_request_pad_simple (audiomixer, "sink_%u");
846 fail_if (sinkpad == NULL, NULL);
848 gst_pad_send_event (sinkpad, gst_event_new_stream_start ("test"));
850 caps = gst_caps_new_simple ("audio/x-raw",
851 "format", G_TYPE_STRING, GST_AUDIO_NE (S16),
852 "layout", G_TYPE_STRING, "interleaved",
853 "rate", G_TYPE_INT, 44100, "channels", G_TYPE_INT, 2, NULL);
855 gst_pad_set_caps (sinkpad, caps);
856 gst_caps_unref (caps);
858 /* send segment to audiomixer */
859 gst_segment_init (&segment, GST_FORMAT_TIME);
860 segment.start = GST_SECOND;
861 segment.stop = 2 * GST_SECOND;
863 event = gst_event_new_segment (&segment);
864 gst_pad_send_event (sinkpad, event);
866 /* should be clipped and ok */
867 buffer = new_buffer (44100, 0, 0, 250 * GST_MSECOND, 0);
868 GST_DEBUG ("pushing buffer %p END is %" GST_TIME_FORMAT,
870 GST_TIME_ARGS (GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer)));
871 ret = gst_pad_chain (sinkpad, buffer);
872 ck_assert_int_eq (ret, GST_FLOW_OK);
873 /* The aggregation is done in a dedicated thread, so we can't
874 * know when it is actually going to happen, so we use a DRAIN query
875 * to wait for it to complete.
877 gst_pad_query (sinkpad, drain);
878 fail_unless (handoff_buffer == NULL);
880 /* should be partially clipped */
881 buffer = new_buffer (44100, 0, 900 * GST_MSECOND, 250 * GST_MSECOND,
882 GST_BUFFER_FLAG_DISCONT);
883 GST_DEBUG ("pushing buffer %p START %" GST_TIME_FORMAT " -- DURATION is %"
884 GST_TIME_FORMAT, buffer, GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
885 GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
886 ret = gst_pad_chain (sinkpad, buffer);
887 ck_assert_int_eq (ret, GST_FLOW_OK);
888 gst_pad_query (sinkpad, drain);
890 fail_unless (handoff_buffer != NULL);
891 ck_assert_int_eq (GST_BUFFER_PTS (handoff_buffer) +
892 GST_BUFFER_DURATION (handoff_buffer), 150 * GST_MSECOND);
893 gst_buffer_replace (&handoff_buffer, NULL);
895 /* should not be clipped */
896 buffer = new_buffer (44100, 0, 1150 * GST_MSECOND, 250 * GST_MSECOND, 0);
897 GST_DEBUG ("pushing buffer %p END is %" GST_TIME_FORMAT,
899 GST_TIME_ARGS (GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer)));
900 ret = gst_pad_chain (sinkpad, buffer);
901 ck_assert_int_eq (ret, GST_FLOW_OK);
902 gst_pad_query (sinkpad, drain);
903 fail_unless (handoff_buffer != NULL);
904 ck_assert_int_eq (GST_BUFFER_PTS (handoff_buffer) +
905 GST_BUFFER_DURATION (handoff_buffer), 400 * GST_MSECOND);
906 gst_buffer_replace (&handoff_buffer, NULL);
907 fail_unless (handoff_buffer == NULL);
909 /* should be clipped and ok */
910 buffer = new_buffer (44100, 0, 2 * GST_SECOND, 250 * GST_MSECOND,
911 GST_BUFFER_FLAG_DISCONT);
912 GST_DEBUG ("pushing buffer %p PTS is %" GST_TIME_FORMAT
913 " END is %" GST_TIME_FORMAT,
915 GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
916 GST_TIME_ARGS (GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer)));
917 ret = gst_pad_chain (sinkpad, buffer);
918 ck_assert_int_eq (ret, GST_FLOW_OK);
919 gst_pad_query (sinkpad, drain);
920 fail_unless (handoff_buffer == NULL);
922 gst_element_release_request_pad (audiomixer, sinkpad);
923 gst_object_unref (sinkpad);
924 gst_element_set_state (bin, GST_STATE_NULL);
925 gst_bus_remove_signal_watch (bus);
926 gst_object_unref (bus);
927 gst_object_unref (bin);
928 gst_query_unref (drain);
933 GST_START_TEST (test_duration_is_max)
935 GstElement *bin, *src[3], *audiomixer, *sink;
936 GstStateChangeReturn state_res;
937 GstFormat format = GST_FORMAT_TIME;
941 GST_INFO ("preparing test");
944 bin = gst_pipeline_new ("pipeline");
946 /* 3 sources, an audiomixer and a fakesink */
947 src[0] = gst_element_factory_make ("audiotestsrc", NULL);
948 src[1] = gst_element_factory_make ("audiotestsrc", NULL);
949 src[2] = gst_element_factory_make ("audiotestsrc", NULL);
950 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
951 sink = gst_element_factory_make ("fakesink", "sink");
952 gst_bin_add_many (GST_BIN (bin), src[0], src[1], src[2], audiomixer, sink,
955 gst_element_link (src[0], audiomixer);
956 gst_element_link (src[1], audiomixer);
957 gst_element_link (src[2], audiomixer);
958 gst_element_link (audiomixer, sink);
960 /* irks, duration is reset on basesrc */
961 state_res = gst_element_set_state (bin, GST_STATE_PAUSED);
962 fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
964 /* set durations on src */
965 GST_BASE_SRC (src[0])->segment.duration = 1000;
966 GST_BASE_SRC (src[1])->segment.duration = 3000;
967 GST_BASE_SRC (src[2])->segment.duration = 2000;
970 set_state_and_wait (bin, GST_STATE_PLAYING);
972 res = gst_element_query_duration (GST_ELEMENT (bin), format, &duration);
973 fail_unless (res, NULL);
975 ck_assert_int_eq (duration, 3000);
977 gst_element_set_state (bin, GST_STATE_NULL);
978 gst_object_unref (bin);
983 GST_START_TEST (test_duration_unknown_overrides)
985 GstElement *bin, *src[3], *audiomixer, *sink;
986 GstStateChangeReturn state_res;
987 GstFormat format = GST_FORMAT_TIME;
991 GST_INFO ("preparing test");
994 bin = gst_pipeline_new ("pipeline");
996 /* 3 sources, an audiomixer and a fakesink */
997 src[0] = gst_element_factory_make ("audiotestsrc", NULL);
998 src[1] = gst_element_factory_make ("audiotestsrc", NULL);
999 src[2] = gst_element_factory_make ("audiotestsrc", NULL);
1000 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
1001 sink = gst_element_factory_make ("fakesink", "sink");
1002 gst_bin_add_many (GST_BIN (bin), src[0], src[1], src[2], audiomixer, sink,
1005 gst_element_link (src[0], audiomixer);
1006 gst_element_link (src[1], audiomixer);
1007 gst_element_link (src[2], audiomixer);
1008 gst_element_link (audiomixer, sink);
1010 /* irks, duration is reset on basesrc */
1011 state_res = gst_element_set_state (bin, GST_STATE_PAUSED);
1012 fail_unless (state_res != GST_STATE_CHANGE_FAILURE, NULL);
1014 /* set durations on src */
1015 GST_BASE_SRC (src[0])->segment.duration = GST_CLOCK_TIME_NONE;
1016 GST_BASE_SRC (src[1])->segment.duration = 3000;
1017 GST_BASE_SRC (src[2])->segment.duration = 2000;
1019 /* set to playing */
1020 set_state_and_wait (bin, GST_STATE_PLAYING);
1022 res = gst_element_query_duration (GST_ELEMENT (bin), format, &duration);
1023 fail_unless (res, NULL);
1025 ck_assert_int_eq (duration, GST_CLOCK_TIME_NONE);
1027 gst_element_set_state (bin, GST_STATE_NULL);
1028 gst_object_unref (bin);
1034 static gboolean looped = FALSE;
1037 loop_segment_done (GstBus * bus, GstMessage * message, GstElement * bin)
1039 GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
1040 GST_MESSAGE_SRC (message), message);
1043 g_main_loop_quit (main_loop);
1045 GstEvent *seek_event;
1048 seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
1049 GST_SEEK_FLAG_SEGMENT,
1050 GST_SEEK_TYPE_SET, (GstClockTime) 0,
1051 GST_SEEK_TYPE_SET, (GstClockTime) 1 * GST_SECOND);
1053 res = gst_element_send_event (bin, seek_event);
1054 fail_unless (res == TRUE, NULL);
1059 GST_START_TEST (test_loop)
1063 GstEvent *seek_event;
1066 GST_INFO ("preparing test");
1068 /* build pipeline */
1069 bin = setup_pipeline (NULL, 2, NULL);
1070 bus = gst_element_get_bus (bin);
1071 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
1073 seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
1074 GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
1075 GST_SEEK_TYPE_SET, (GstClockTime) 0,
1076 GST_SEEK_TYPE_SET, (GstClockTime) 1 * GST_SECOND);
1078 g_signal_connect (bus, "message::segment-done",
1079 (GCallback) loop_segment_done, bin);
1080 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
1081 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
1082 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
1084 GST_INFO ("starting test");
1086 /* prepare playing */
1087 set_state_and_wait (bin, GST_STATE_PAUSED);
1089 res = gst_element_send_event (bin, seek_event);
1090 fail_unless (res == TRUE, NULL);
1093 play_and_wait (bin);
1095 fail_unless (looped);
1098 gst_bus_remove_signal_watch (bus);
1099 gst_object_unref (bus);
1100 gst_object_unref (bin);
1105 GST_START_TEST (test_flush_start_flush_stop)
1107 GstPadTemplate *sink_template;
1108 GstPad *tmppad, *srcpad1, *sinkpad1, *sinkpad2, *audiomixer_src;
1109 GstElement *pipeline, *src1, *src2, *audiomixer, *sink;
1111 GST_INFO ("preparing test");
1113 /* build pipeline */
1114 pipeline = gst_pipeline_new ("pipeline");
1115 src1 = gst_element_factory_make ("audiotestsrc", "src1");
1116 g_object_set (src1, "wave", 4, NULL); /* silence */
1117 src2 = gst_element_factory_make ("audiotestsrc", "src2");
1118 g_object_set (src2, "wave", 4, NULL); /* silence */
1119 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
1120 sink = gst_element_factory_make ("fakesink", "sink");
1121 gst_bin_add_many (GST_BIN (pipeline), src1, src2, audiomixer, sink, NULL);
1124 gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (audiomixer),
1126 fail_unless (GST_IS_PAD_TEMPLATE (sink_template));
1127 sinkpad1 = gst_element_request_pad (audiomixer, sink_template, NULL, NULL);
1128 srcpad1 = gst_element_get_static_pad (src1, "src");
1129 gst_pad_link (srcpad1, sinkpad1);
1131 sinkpad2 = gst_element_request_pad (audiomixer, sink_template, NULL, NULL);
1132 tmppad = gst_element_get_static_pad (src2, "src");
1133 gst_pad_link (tmppad, sinkpad2);
1134 gst_object_unref (tmppad);
1136 gst_element_link (audiomixer, sink);
1138 /* prepare playing */
1139 set_state_and_wait (pipeline, GST_STATE_PLAYING);
1141 audiomixer_src = gst_element_get_static_pad (audiomixer, "src");
1142 fail_if (GST_PAD_IS_FLUSHING (audiomixer_src));
1143 gst_pad_send_event (sinkpad1, gst_event_new_flush_start ());
1144 fail_if (GST_PAD_IS_FLUSHING (audiomixer_src));
1145 fail_unless (GST_PAD_IS_FLUSHING (sinkpad1));
1146 /* Hold the streamlock to make sure the flush stop is not between
1147 the attempted push of a segment event and of the following buffer. */
1148 GST_PAD_STREAM_LOCK (srcpad1);
1149 gst_pad_send_event (sinkpad1, gst_event_new_flush_stop (TRUE));
1150 GST_PAD_STREAM_UNLOCK (srcpad1);
1151 fail_if (GST_PAD_IS_FLUSHING (audiomixer_src));
1152 fail_if (GST_PAD_IS_FLUSHING (sinkpad1));
1153 gst_object_unref (audiomixer_src);
1155 gst_element_release_request_pad (audiomixer, sinkpad1);
1156 gst_object_unref (sinkpad1);
1157 gst_element_release_request_pad (audiomixer, sinkpad2);
1158 gst_object_unref (sinkpad2);
1159 gst_object_unref (srcpad1);
1162 gst_element_set_state (pipeline, GST_STATE_NULL);
1163 gst_object_unref (pipeline);
1169 handoff_buffer_collect_cb (GstElement * fakesink, GstBuffer * buffer,
1170 GstPad * pad, gpointer user_data)
1172 GList **received_buffers = user_data;
1174 GST_DEBUG ("got buffer %p", buffer);
1176 g_list_append (*received_buffers, gst_buffer_ref (buffer));
1179 typedef void (*SendBuffersFunction) (GstPad * pad1, GstPad * pad2);
1180 typedef void (*CheckBuffersFunction) (GList * buffers);
1183 run_sync_test (SendBuffersFunction send_buffers,
1184 CheckBuffersFunction check_buffers)
1187 GstElement *bin, *audiomixer, *queue1, *queue2, *sink;
1189 GstPad *sinkpad1, *sinkpad2;
1190 GstPad *queue1_sinkpad, *queue2_sinkpad;
1193 GstStateChangeReturn state_res;
1196 GList *received_buffers = NULL;
1198 GST_INFO ("preparing test");
1200 /* build pipeline */
1201 bin = gst_pipeline_new ("pipeline");
1202 bus = gst_element_get_bus (bin);
1203 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
1205 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
1206 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
1207 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
1209 /* just an audiomixer and a fakesink */
1210 queue1 = gst_element_factory_make ("queue", "queue1");
1211 queue2 = gst_element_factory_make ("queue", "queue2");
1212 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
1213 g_object_set (audiomixer, "output-buffer-duration", 500 * GST_MSECOND, NULL);
1214 sink = gst_element_factory_make ("fakesink", "sink");
1215 g_object_set (sink, "signal-handoffs", TRUE, NULL);
1216 g_signal_connect (sink, "handoff", (GCallback) handoff_buffer_collect_cb,
1218 gst_bin_add_many (GST_BIN (bin), queue1, queue2, audiomixer, sink, NULL);
1220 res = gst_element_link (audiomixer, sink);
1221 fail_unless (res == TRUE, NULL);
1224 state_res = gst_element_set_state (bin, GST_STATE_PAUSED);
1225 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
1227 /* create an unconnected sinkpad in audiomixer, should also automatically activate
1229 sinkpad1 = gst_element_request_pad_simple (audiomixer, "sink_%u");
1230 fail_if (sinkpad1 == NULL, NULL);
1232 queue1_sinkpad = gst_element_get_static_pad (queue1, "sink");
1233 pad = gst_element_get_static_pad (queue1, "src");
1234 fail_unless (gst_pad_link (pad, sinkpad1) == GST_PAD_LINK_OK);
1235 gst_object_unref (pad);
1237 sinkpad2 = gst_element_request_pad_simple (audiomixer, "sink_%u");
1238 fail_if (sinkpad2 == NULL, NULL);
1240 queue2_sinkpad = gst_element_get_static_pad (queue2, "sink");
1241 pad = gst_element_get_static_pad (queue2, "src");
1242 fail_unless (gst_pad_link (pad, sinkpad2) == GST_PAD_LINK_OK);
1243 gst_object_unref (pad);
1245 gst_pad_send_event (queue1_sinkpad, gst_event_new_stream_start ("test"));
1246 gst_pad_send_event (queue2_sinkpad, gst_event_new_stream_start ("test"));
1248 caps = gst_caps_new_simple ("audio/x-raw",
1249 "format", G_TYPE_STRING, GST_AUDIO_NE (S16),
1250 "layout", G_TYPE_STRING, "interleaved",
1251 "rate", G_TYPE_INT, 1000, "channels", G_TYPE_INT, 1, NULL);
1253 gst_pad_set_caps (queue1_sinkpad, caps);
1254 gst_pad_set_caps (queue2_sinkpad, caps);
1255 gst_caps_unref (caps);
1257 /* send segment to audiomixer */
1258 gst_segment_init (&segment, GST_FORMAT_TIME);
1259 event = gst_event_new_segment (&segment);
1260 gst_pad_send_event (queue1_sinkpad, gst_event_ref (event));
1261 gst_pad_send_event (queue2_sinkpad, event);
1264 send_buffers (queue1_sinkpad, queue2_sinkpad);
1267 g_idle_add ((GSourceFunc) set_playing, bin);
1269 /* Collect buffers and messages */
1270 g_main_loop_run (main_loop);
1272 /* Here we get once we got EOS, for errors we failed */
1274 check_buffers (received_buffers);
1276 g_list_free_full (received_buffers, (GDestroyNotify) gst_buffer_unref);
1278 gst_element_release_request_pad (audiomixer, sinkpad1);
1279 gst_object_unref (sinkpad1);
1280 gst_object_unref (queue1_sinkpad);
1281 gst_element_release_request_pad (audiomixer, sinkpad2);
1282 gst_object_unref (sinkpad2);
1283 gst_object_unref (queue2_sinkpad);
1284 gst_element_set_state (bin, GST_STATE_NULL);
1285 gst_bus_remove_signal_watch (bus);
1286 gst_object_unref (bus);
1287 gst_object_unref (bin);
1291 send_buffers_sync (GstPad * pad1, GstPad * pad2)
1296 buffer = new_buffer (2000, 1, 1 * GST_SECOND, 1 * GST_SECOND, 0);
1297 ret = gst_pad_chain (pad1, buffer);
1298 ck_assert_int_eq (ret, GST_FLOW_OK);
1300 buffer = new_buffer (2000, 1, 2 * GST_SECOND, 1 * GST_SECOND, 0);
1301 ret = gst_pad_chain (pad1, buffer);
1302 ck_assert_int_eq (ret, GST_FLOW_OK);
1304 gst_pad_send_event (pad1, gst_event_new_eos ());
1306 buffer = new_buffer (2000, 2, 2 * GST_SECOND, 1 * GST_SECOND, 0);
1307 ret = gst_pad_chain (pad2, buffer);
1308 ck_assert_int_eq (ret, GST_FLOW_OK);
1310 buffer = new_buffer (2000, 2, 3 * GST_SECOND, 1 * GST_SECOND, 0);
1311 ret = gst_pad_chain (pad2, buffer);
1312 ck_assert_int_eq (ret, GST_FLOW_OK);
1314 gst_pad_send_event (pad2, gst_event_new_eos ());
1318 check_buffers_sync (GList * received_buffers)
1325 /* Should have 8 * 0.5s buffers */
1326 fail_unless_equals_int (g_list_length (received_buffers), 8);
1327 for (i = 0, l = received_buffers; l; l = l->next, i++) {
1330 gst_buffer_map (buffer, &map, GST_MAP_READ);
1332 if (i == 0 && GST_BUFFER_TIMESTAMP (buffer) == 0) {
1333 fail_unless (map.data[0] == 0);
1334 fail_unless (map.data[map.size - 1] == 0);
1335 } else if (i == 1 && GST_BUFFER_TIMESTAMP (buffer) == 500 * GST_MSECOND) {
1336 fail_unless (map.data[0] == 0);
1337 fail_unless (map.data[map.size - 1] == 0);
1338 } else if (i == 2 && GST_BUFFER_TIMESTAMP (buffer) == 1000 * GST_MSECOND) {
1339 fail_unless (map.data[0] == 1);
1340 fail_unless (map.data[map.size - 1] == 1);
1341 } else if (i == 3 && GST_BUFFER_TIMESTAMP (buffer) == 1500 * GST_MSECOND) {
1342 fail_unless (map.data[0] == 1);
1343 fail_unless (map.data[map.size - 1] == 1);
1344 } else if (i == 4 && GST_BUFFER_TIMESTAMP (buffer) == 2000 * GST_MSECOND) {
1345 fail_unless (map.data[0] == 3);
1346 fail_unless (map.data[map.size - 1] == 3);
1347 } else if (i == 5 && GST_BUFFER_TIMESTAMP (buffer) == 2500 * GST_MSECOND) {
1348 fail_unless (map.data[0] == 3);
1349 fail_unless (map.data[map.size - 1] == 3);
1350 } else if (i == 6 && GST_BUFFER_TIMESTAMP (buffer) == 3000 * GST_MSECOND) {
1351 fail_unless (map.data[0] == 2);
1352 fail_unless (map.data[map.size - 1] == 2);
1353 } else if (i == 7 && GST_BUFFER_TIMESTAMP (buffer) == 3500 * GST_MSECOND) {
1354 fail_unless (map.data[0] == 2);
1355 fail_unless (map.data[map.size - 1] == 2);
1357 g_assert_not_reached ();
1360 gst_buffer_unmap (buffer, &map);
1365 GST_START_TEST (test_sync)
1367 run_sync_test (send_buffers_sync, check_buffers_sync);
1373 send_buffers_sync_discont (GstPad * pad1, GstPad * pad2)
1378 buffer = new_buffer (2000, 1, 1 * GST_SECOND, 1 * GST_SECOND, 0);
1379 ret = gst_pad_chain (pad1, buffer);
1380 ck_assert_int_eq (ret, GST_FLOW_OK);
1382 buffer = new_buffer (2000, 1, 3 * GST_SECOND, 1 * GST_SECOND,
1383 GST_BUFFER_FLAG_DISCONT);
1384 ret = gst_pad_chain (pad1, buffer);
1385 ck_assert_int_eq (ret, GST_FLOW_OK);
1387 gst_pad_send_event (pad1, gst_event_new_eos ());
1389 buffer = new_buffer (2000, 2, 2 * GST_SECOND, 1 * GST_SECOND, 0);
1390 ret = gst_pad_chain (pad2, buffer);
1391 ck_assert_int_eq (ret, GST_FLOW_OK);
1393 buffer = new_buffer (2000, 2, 3 * GST_SECOND, 1 * GST_SECOND, 0);
1394 ret = gst_pad_chain (pad2, buffer);
1395 ck_assert_int_eq (ret, GST_FLOW_OK);
1397 gst_pad_send_event (pad2, gst_event_new_eos ());
1401 check_buffers_sync_discont (GList * received_buffers)
1408 /* Should have 8 * 0.5s buffers */
1409 fail_unless_equals_int (g_list_length (received_buffers), 8);
1410 for (i = 0, l = received_buffers; l; l = l->next, i++) {
1413 gst_buffer_map (buffer, &map, GST_MAP_READ);
1415 if (i == 0 && GST_BUFFER_TIMESTAMP (buffer) == 0) {
1416 fail_unless (map.data[0] == 0);
1417 fail_unless (map.data[map.size - 1] == 0);
1418 } else if (i == 1 && GST_BUFFER_TIMESTAMP (buffer) == 500 * GST_MSECOND) {
1419 fail_unless (map.data[0] == 0);
1420 fail_unless (map.data[map.size - 1] == 0);
1421 } else if (i == 2 && GST_BUFFER_TIMESTAMP (buffer) == 1000 * GST_MSECOND) {
1422 fail_unless (map.data[0] == 1);
1423 fail_unless (map.data[map.size - 1] == 1);
1424 } else if (i == 3 && GST_BUFFER_TIMESTAMP (buffer) == 1500 * GST_MSECOND) {
1425 fail_unless (map.data[0] == 1);
1426 fail_unless (map.data[map.size - 1] == 1);
1427 } else if (i == 4 && GST_BUFFER_TIMESTAMP (buffer) == 2000 * GST_MSECOND) {
1428 fail_unless (map.data[0] == 2);
1429 fail_unless (map.data[map.size - 1] == 2);
1430 } else if (i == 5 && GST_BUFFER_TIMESTAMP (buffer) == 2500 * GST_MSECOND) {
1431 fail_unless (map.data[0] == 2);
1432 fail_unless (map.data[map.size - 1] == 2);
1433 } else if (i == 6 && GST_BUFFER_TIMESTAMP (buffer) == 3000 * GST_MSECOND) {
1434 fail_unless (map.data[0] == 3);
1435 fail_unless (map.data[map.size - 1] == 3);
1436 } else if (i == 7 && GST_BUFFER_TIMESTAMP (buffer) == 3500 * GST_MSECOND) {
1437 fail_unless (map.data[0] == 3);
1438 fail_unless (map.data[map.size - 1] == 3);
1440 g_assert_not_reached ();
1443 gst_buffer_unmap (buffer, &map);
1448 GST_START_TEST (test_sync_discont)
1450 run_sync_test (send_buffers_sync_discont, check_buffers_sync_discont);
1457 send_buffers_sync_discont_backwards (GstPad * pad1, GstPad * pad2)
1462 buffer = new_buffer (2300, 1, 1 * GST_SECOND, 1.25 * GST_SECOND, 0);
1463 ret = gst_pad_chain (pad1, buffer);
1464 ck_assert_int_eq (ret, GST_FLOW_OK);
1466 buffer = new_buffer (2000, 1, 2 * GST_SECOND, 1 * GST_SECOND,
1467 GST_BUFFER_FLAG_DISCONT);
1468 ret = gst_pad_chain (pad1, buffer);
1469 ck_assert_int_eq (ret, GST_FLOW_OK);
1471 gst_pad_send_event (pad1, gst_event_new_eos ());
1473 buffer = new_buffer (2000, 1, 2 * GST_SECOND, 1 * GST_SECOND, 0);
1474 ret = gst_pad_chain (pad2, buffer);
1475 ck_assert_int_eq (ret, GST_FLOW_OK);
1478 gst_pad_send_event (pad2, gst_event_new_eos ());
1482 check_buffers_sync_discont_backwards (GList * received_buffers)
1489 /* Should have 6 * 0.5s buffers */
1490 fail_unless_equals_int (g_list_length (received_buffers), 6);
1491 for (i = 0, l = received_buffers; l; l = l->next, i++) {
1494 gst_buffer_map (buffer, &map, GST_MAP_READ);
1496 if (i == 0 && GST_BUFFER_TIMESTAMP (buffer) == 0) {
1497 fail_unless (map.data[0] == 0);
1498 fail_unless (map.data[map.size - 1] == 0);
1499 } else if (i == 1 && GST_BUFFER_TIMESTAMP (buffer) == 500 * GST_MSECOND) {
1500 fail_unless (map.data[0] == 0);
1501 fail_unless (map.data[map.size - 1] == 0);
1502 } else if (i == 2 && GST_BUFFER_TIMESTAMP (buffer) == 1000 * GST_MSECOND) {
1503 fail_unless (map.data[0] == 1);
1504 fail_unless (map.data[map.size - 1] == 1);
1505 } else if (i == 3 && GST_BUFFER_TIMESTAMP (buffer) == 1500 * GST_MSECOND) {
1506 fail_unless (map.data[0] == 1);
1507 fail_unless (map.data[map.size - 1] == 1);
1508 } else if (i == 4 && GST_BUFFER_TIMESTAMP (buffer) == 2000 * GST_MSECOND) {
1509 fail_unless (map.data[0] == 2);
1510 fail_unless (map.data[map.size - 1] == 2);
1511 } else if (i == 5 && GST_BUFFER_TIMESTAMP (buffer) == 2500 * GST_MSECOND) {
1512 fail_unless (map.data[0] == 2);
1513 fail_unless (map.data[map.size - 1] == 2);
1515 g_assert_not_reached ();
1518 gst_buffer_unmap (buffer, &map);
1523 GST_START_TEST (test_sync_discont_backwards)
1525 run_sync_test (send_buffers_sync_discont_backwards,
1526 check_buffers_sync_discont_backwards);
1533 send_buffers_sync_unaligned (GstPad * pad1, GstPad * pad2)
1538 buffer = new_buffer (2000, 1, 750 * GST_MSECOND, 1 * GST_SECOND, 0);
1539 ret = gst_pad_chain (pad1, buffer);
1540 ck_assert_int_eq (ret, GST_FLOW_OK);
1542 buffer = new_buffer (2000, 1, 1750 * GST_MSECOND, 1 * GST_SECOND, 0);
1543 ret = gst_pad_chain (pad1, buffer);
1544 ck_assert_int_eq (ret, GST_FLOW_OK);
1546 gst_pad_send_event (pad1, gst_event_new_eos ());
1548 buffer = new_buffer (2000, 2, 1750 * GST_MSECOND, 1 * GST_SECOND, 0);
1549 ret = gst_pad_chain (pad2, buffer);
1550 ck_assert_int_eq (ret, GST_FLOW_OK);
1552 buffer = new_buffer (2000, 2, 2750 * GST_MSECOND, 1 * GST_SECOND, 0);
1553 ret = gst_pad_chain (pad2, buffer);
1554 ck_assert_int_eq (ret, GST_FLOW_OK);
1556 gst_pad_send_event (pad2, gst_event_new_eos ());
1560 check_buffers_sync_unaligned (GList * received_buffers)
1567 /* Should have 8 * 0.5s buffers */
1568 fail_unless_equals_int (g_list_length (received_buffers), 8);
1569 for (i = 0, l = received_buffers; l; l = l->next, i++) {
1572 gst_buffer_map (buffer, &map, GST_MAP_READ);
1574 if (i == 0 && GST_BUFFER_TIMESTAMP (buffer) == 0) {
1575 fail_unless (map.data[0] == 0);
1576 fail_unless (map.data[map.size - 1] == 0);
1577 } else if (i == 1 && GST_BUFFER_TIMESTAMP (buffer) == 500 * GST_MSECOND) {
1578 fail_unless (map.data[0] == 0);
1579 fail_unless (map.data[499] == 0);
1580 fail_unless (map.data[500] == 1);
1581 fail_unless (map.data[map.size - 1] == 1);
1582 } else if (i == 2 && GST_BUFFER_TIMESTAMP (buffer) == 1000 * GST_MSECOND) {
1583 fail_unless (map.data[0] == 1);
1584 fail_unless (map.data[map.size - 1] == 1);
1585 } else if (i == 3 && GST_BUFFER_TIMESTAMP (buffer) == 1500 * GST_MSECOND) {
1586 fail_unless (map.data[0] == 1);
1587 fail_unless (map.data[499] == 1);
1588 fail_unless (map.data[500] == 3);
1589 fail_unless (map.data[map.size - 1] == 3);
1590 } else if (i == 4 && GST_BUFFER_TIMESTAMP (buffer) == 2000 * GST_MSECOND) {
1591 fail_unless (map.data[0] == 3);
1592 fail_unless (map.data[499] == 3);
1593 fail_unless (map.data[500] == 3);
1594 fail_unless (map.data[map.size - 1] == 3);
1595 } else if (i == 5 && GST_BUFFER_TIMESTAMP (buffer) == 2500 * GST_MSECOND) {
1596 fail_unless (map.data[0] == 3);
1597 fail_unless (map.data[499] == 3);
1598 fail_unless (map.data[500] == 2);
1599 fail_unless (map.data[map.size - 1] == 2);
1600 } else if (i == 6 && GST_BUFFER_TIMESTAMP (buffer) == 3000 * GST_MSECOND) {
1601 fail_unless (map.data[0] == 2);
1602 fail_unless (map.data[499] == 2);
1603 fail_unless (map.data[500] == 2);
1604 fail_unless (map.data[map.size - 1] == 2);
1605 } else if (i == 7 && GST_BUFFER_TIMESTAMP (buffer) == 3500 * GST_MSECOND) {
1606 fail_unless (map.size == 500);
1607 fail_unless (GST_BUFFER_DURATION (buffer) == 250 * GST_MSECOND);
1608 fail_unless (map.data[0] == 2);
1609 fail_unless (map.data[499] == 2);
1611 g_assert_not_reached ();
1614 gst_buffer_unmap (buffer, &map);
1619 GST_START_TEST (test_sync_unaligned)
1621 run_sync_test (send_buffers_sync_unaligned, check_buffers_sync_unaligned);
1626 GST_START_TEST (test_segment_base_handling)
1628 GstElement *pipeline, *sink, *mix, *src1, *src2;
1629 GstPad *srcpad, *sinkpad;
1630 GstClockTime end_time;
1631 GstSample *last_sample = NULL;
1636 caps = gst_caps_new_simple ("audio/x-raw", "rate", G_TYPE_INT, 44100,
1637 "channels", G_TYPE_INT, 2, NULL);
1639 pipeline = gst_pipeline_new ("pipeline");
1640 mix = gst_element_factory_make ("audiomixer", "audiomixer");
1641 sink = gst_element_factory_make ("appsink", "sink");
1642 g_object_set (sink, "caps", caps, "sync", FALSE, NULL);
1643 gst_caps_unref (caps);
1644 /* 50 buffers of 1/10 sec = 5 sec */
1645 src1 = gst_element_factory_make ("audiotestsrc", "src1");
1646 g_object_set (src1, "samplesperbuffer", 4410, "num-buffers", 50, NULL);
1647 src2 = gst_element_factory_make ("audiotestsrc", "src2");
1648 g_object_set (src2, "samplesperbuffer", 4410, "num-buffers", 50, NULL);
1649 gst_bin_add_many (GST_BIN (pipeline), src1, src2, mix, sink, NULL);
1650 fail_unless (gst_element_link (mix, sink));
1652 srcpad = gst_element_get_static_pad (src1, "src");
1653 sinkpad = gst_element_request_pad_simple (mix, "sink_1");
1654 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK);
1655 gst_object_unref (sinkpad);
1656 gst_object_unref (srcpad);
1658 srcpad = gst_element_get_static_pad (src2, "src");
1659 sinkpad = gst_element_request_pad_simple (mix, "sink_2");
1660 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK);
1661 /* set a pad offset of another 5 seconds */
1662 gst_pad_set_offset (sinkpad, 5 * GST_SECOND);
1663 gst_object_unref (sinkpad);
1664 gst_object_unref (srcpad);
1666 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1669 g_signal_emit_by_name (sink, "pull-sample", &sample);
1673 gst_sample_unref (last_sample);
1674 last_sample = sample;
1677 buf = gst_sample_get_buffer (last_sample);
1678 end_time = GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf);
1679 fail_unless_equals_int64 (end_time, 10 * GST_SECOND);
1680 gst_sample_unref (last_sample);
1682 gst_element_set_state (pipeline, GST_STATE_NULL);
1683 gst_object_unref (pipeline);
1689 set_pad_volume_fade (GstPad * pad, GstClockTime start, gdouble start_value,
1690 GstClockTime end, gdouble end_value)
1692 GstControlSource *cs;
1693 GstTimedValueControlSource *tvcs;
1695 cs = gst_interpolation_control_source_new ();
1696 fail_unless (gst_object_add_control_binding (GST_OBJECT_CAST (pad),
1697 gst_direct_control_binding_new_absolute (GST_OBJECT_CAST (pad),
1700 /* set volume interpolation mode */
1701 g_object_set (cs, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
1703 tvcs = (GstTimedValueControlSource *) cs;
1704 fail_unless (gst_timed_value_control_source_set (tvcs, start, start_value));
1705 fail_unless (gst_timed_value_control_source_set (tvcs, end, end_value));
1706 gst_object_unref (cs);
1709 GST_START_TEST (test_sinkpad_property_controller)
1713 GstElement *pipeline, *sink, *mix, *src1;
1714 GstPad *srcpad, *sinkpad;
1715 GError *error = NULL;
1718 pipeline = gst_pipeline_new ("pipeline");
1719 mix = gst_element_factory_make ("audiomixer", "audiomixer");
1720 sink = gst_element_factory_make ("fakesink", "sink");
1721 src1 = gst_element_factory_make ("audiotestsrc", "src1");
1722 g_object_set (src1, "num-buffers", 100, NULL);
1723 gst_bin_add_many (GST_BIN (pipeline), src1, mix, sink, NULL);
1724 fail_unless (gst_element_link (mix, sink));
1726 srcpad = gst_element_get_static_pad (src1, "src");
1727 sinkpad = gst_element_request_pad_simple (mix, "sink_0");
1728 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK);
1729 set_pad_volume_fade (sinkpad, 0, 0, 1.0, 2.0);
1730 gst_object_unref (sinkpad);
1731 gst_object_unref (srcpad);
1733 gst_element_set_state (pipeline, GST_STATE_PLAYING);
1735 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
1736 msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
1737 GST_MESSAGE_EOS | GST_MESSAGE_ERROR);
1738 switch (GST_MESSAGE_TYPE (msg)) {
1739 case GST_MESSAGE_ERROR:
1740 gst_message_parse_error (msg, &error, &debug);
1741 g_printerr ("ERROR from element %s: %s\n",
1742 GST_OBJECT_NAME (msg->src), error->message);
1743 g_printerr ("Debug info: %s\n", debug);
1744 g_error_free (error);
1747 case GST_MESSAGE_EOS:
1750 g_assert_not_reached ();
1752 gst_message_unref (msg);
1753 g_object_unref (bus);
1755 gst_element_set_state (pipeline, GST_STATE_NULL);
1756 gst_object_unref (pipeline);
1762 change_src_caps (GstElement * fakesink, GstBuffer * buffer, GstPad * pad,
1763 GstElement * capsfilter)
1765 GstCaps *caps = gst_caps_new_simple ("audio/x-raw",
1766 "format", G_TYPE_STRING, GST_AUDIO_NE (S32),
1767 "layout", G_TYPE_STRING, "interleaved",
1768 "rate", G_TYPE_INT, 10, "channels", G_TYPE_INT, 1, NULL);
1770 g_object_set (capsfilter, "caps", caps, NULL);
1771 gst_caps_unref (caps);
1772 g_signal_connect (fakesink, "handoff", (GCallback) handoff_buffer_cb, NULL);
1773 g_signal_handlers_disconnect_by_func (fakesink, change_src_caps, capsfilter);
1776 /* In this test, we create an input buffer with a duration of 2 seconds,
1777 * and require the audiomixer to output 1 second long buffers.
1778 * The input buffer will thus be mixed twice, and the audiomixer will
1779 * output two buffers.
1781 * After audiomixer has output a first buffer, we change its output format
1782 * from S8 to S32. As our sample rate stays the same at 10 fps, and we use
1783 * mono, the first buffer should be 10 bytes long, and the second 40.
1785 * The input buffer is made up of 15 0-valued bytes, and 5 1-valued bytes.
1786 * We verify that the second buffer contains 5 0-valued integers, and
1787 * 5 1 << 24 valued integers.
1789 GST_START_TEST (test_change_output_caps)
1792 GstElement *bin, *audiomixer, *capsfilter, *sink;
1796 GstStateChangeReturn state_res;
1801 GstQuery *drain = gst_query_new_drain ();
1806 bin = gst_pipeline_new ("pipeline");
1807 bus = gst_element_get_bus (bin);
1808 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
1810 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
1811 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
1812 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
1814 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
1815 g_object_set (audiomixer, "output-buffer-duration", GST_SECOND, NULL);
1816 capsfilter = gst_element_factory_make ("capsfilter", NULL);
1817 sink = gst_element_factory_make ("fakesink", "sink");
1818 g_object_set (sink, "signal-handoffs", TRUE, NULL);
1819 g_signal_connect (sink, "handoff", (GCallback) change_src_caps, capsfilter);
1820 gst_bin_add_many (GST_BIN (bin), audiomixer, capsfilter, sink, NULL);
1822 res = gst_element_link_many (audiomixer, capsfilter, sink, NULL);
1823 fail_unless (res == TRUE, NULL);
1825 state_res = gst_element_set_state (bin, GST_STATE_PLAYING);
1826 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
1828 sinkpad = gst_element_request_pad_simple (audiomixer, "sink_%u");
1829 fail_if (sinkpad == NULL, NULL);
1831 gst_pad_send_event (sinkpad, gst_event_new_stream_start ("test"));
1833 caps = gst_caps_new_simple ("audio/x-raw",
1834 "format", G_TYPE_STRING, "S8",
1835 "layout", G_TYPE_STRING, "interleaved",
1836 "rate", G_TYPE_INT, 10, "channels", G_TYPE_INT, 1, NULL);
1838 gst_pad_set_caps (sinkpad, caps);
1839 g_object_set (capsfilter, "caps", caps, NULL);
1840 gst_caps_unref (caps);
1842 gst_segment_init (&segment, GST_FORMAT_TIME);
1844 segment.stop = 2 * GST_SECOND;
1846 event = gst_event_new_segment (&segment);
1847 gst_pad_send_event (sinkpad, event);
1849 gst_buffer_replace (&handoff_buffer, NULL);
1851 buffer = new_buffer (20, 0, 0, 2 * GST_SECOND, 0);
1852 gst_buffer_map (buffer, &inmap, GST_MAP_WRITE);
1853 memset (inmap.data + 15, 1, 5);
1854 gst_buffer_unmap (buffer, &inmap);
1855 ret = gst_pad_chain (sinkpad, buffer);
1856 ck_assert_int_eq (ret, GST_FLOW_OK);
1857 gst_pad_query (sinkpad, drain);
1858 fail_unless (handoff_buffer != NULL);
1859 fail_unless_equals_int (gst_buffer_get_size (handoff_buffer), 40);
1861 gst_buffer_map (handoff_buffer, &outmap, GST_MAP_READ);
1862 for (i = 0; i < 10; i++) {
1865 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1866 sample = GUINT32_FROM_LE (((guint32 *) outmap.data)[i]);
1868 sample = GUINT32_FROM_BE (((guint32 *) outmap.data)[i]);
1872 fail_unless_equals_int (sample, 0);
1874 fail_unless_equals_int (sample, 1 << 24);
1877 gst_buffer_unmap (handoff_buffer, &outmap);
1878 gst_clear_buffer (&handoff_buffer);
1880 gst_element_release_request_pad (audiomixer, sinkpad);
1881 gst_object_unref (sinkpad);
1882 gst_element_set_state (bin, GST_STATE_NULL);
1883 gst_bus_remove_signal_watch (bus);
1884 gst_object_unref (bus);
1885 gst_object_unref (bin);
1886 gst_query_unref (drain);
1891 /* In this test, we create two input buffers with a duration of 1 second,
1892 * and require the audiomixer to output 1.5 second long buffers.
1894 * After we have input two buffers, we change the output format
1895 * from S8 to S32, then push a last buffer.
1897 * This makes audioaggregator convert its "half-mixed" current_buffer,
1898 * we can then ensure that the second output buffer is as expected.
1900 GST_START_TEST (test_change_output_caps_mid_output_buffer)
1903 GstElement *bin, *audiomixer, *capsfilter, *sink;
1907 GstStateChangeReturn state_res;
1917 bin = gst_pipeline_new ("pipeline");
1918 bus = gst_element_get_bus (bin);
1919 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
1921 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
1922 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
1923 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
1925 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
1926 g_object_set (audiomixer, "output-buffer-duration", 1500 * GST_MSECOND, NULL);
1927 capsfilter = gst_element_factory_make ("capsfilter", NULL);
1928 sink = gst_element_factory_make ("fakesink", "sink");
1929 gst_bin_add_many (GST_BIN (bin), audiomixer, capsfilter, sink, NULL);
1931 res = gst_element_link_many (audiomixer, capsfilter, sink, NULL);
1932 fail_unless (res == TRUE, NULL);
1934 state_res = gst_element_set_state (bin, GST_STATE_PLAYING);
1935 ck_assert_int_ne (state_res, GST_STATE_CHANGE_FAILURE);
1937 sinkpad = gst_element_request_pad_simple (audiomixer, "sink_%u");
1938 fail_if (sinkpad == NULL, NULL);
1940 gst_pad_send_event (sinkpad, gst_event_new_stream_start ("test"));
1942 caps = gst_caps_new_simple ("audio/x-raw",
1943 "format", G_TYPE_STRING, "S8",
1944 "layout", G_TYPE_STRING, "interleaved",
1945 "rate", G_TYPE_INT, 10, "channels", G_TYPE_INT, 1, NULL);
1947 gst_pad_set_caps (sinkpad, caps);
1948 g_object_set (capsfilter, "caps", caps, NULL);
1949 gst_caps_unref (caps);
1951 gst_segment_init (&segment, GST_FORMAT_TIME);
1953 segment.stop = 3 * GST_SECOND;
1955 event = gst_event_new_segment (&segment);
1956 gst_pad_send_event (sinkpad, event);
1958 buffer = new_buffer (10, 0, 0, 1 * GST_SECOND, 0);
1959 ret = gst_pad_chain (sinkpad, buffer);
1960 ck_assert_int_eq (ret, GST_FLOW_OK);
1962 buffer = new_buffer (10, 0, 1 * GST_SECOND, 1 * GST_SECOND, 0);
1963 gst_buffer_map (buffer, &inmap, GST_MAP_WRITE);
1964 memset (inmap.data, 1, 10);
1965 gst_buffer_unmap (buffer, &inmap);
1966 ret = gst_pad_chain (sinkpad, buffer);
1967 ck_assert_int_eq (ret, GST_FLOW_OK);
1969 drain = gst_query_new_drain ();
1970 gst_pad_query (sinkpad, drain);
1971 gst_query_unref (drain);
1973 caps = gst_caps_new_simple ("audio/x-raw",
1974 "format", G_TYPE_STRING, GST_AUDIO_NE (S32),
1975 "layout", G_TYPE_STRING, "interleaved",
1976 "rate", G_TYPE_INT, 10, "channels", G_TYPE_INT, 1, NULL);
1977 g_object_set (capsfilter, "caps", caps, NULL);
1978 gst_caps_unref (caps);
1980 gst_buffer_replace (&handoff_buffer, NULL);
1981 g_object_set (sink, "signal-handoffs", TRUE, NULL);
1982 g_signal_connect (sink, "handoff", (GCallback) handoff_buffer_cb, NULL);
1984 buffer = new_buffer (10, 0, 2 * GST_SECOND, 1 * GST_SECOND, 0);
1985 gst_buffer_map (buffer, &inmap, GST_MAP_WRITE);
1986 memset (inmap.data, 0, 10);
1987 gst_buffer_unmap (buffer, &inmap);
1988 ret = gst_pad_chain (sinkpad, buffer);
1989 ck_assert_int_eq (ret, GST_FLOW_OK);
1991 drain = gst_query_new_drain ();
1992 gst_pad_query (sinkpad, drain);
1993 gst_query_unref (drain);
1995 fail_unless (handoff_buffer);
1996 fail_unless_equals_int (gst_buffer_get_size (handoff_buffer), 60);
1998 gst_buffer_map (handoff_buffer, &outmap, GST_MAP_READ);
1999 for (i = 0; i < 15; i++) {
2002 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
2003 sample = GUINT32_FROM_LE (((guint32 *) outmap.data)[i]);
2005 sample = GUINT32_FROM_BE (((guint32 *) outmap.data)[i]);
2009 fail_unless_equals_int (sample, 1 << 24);
2011 fail_unless_equals_int (sample, 0);
2015 gst_buffer_unmap (handoff_buffer, &outmap);
2016 gst_clear_buffer (&handoff_buffer);
2018 gst_element_release_request_pad (audiomixer, sinkpad);
2019 gst_object_unref (sinkpad);
2020 gst_element_set_state (bin, GST_STATE_NULL);
2021 gst_bus_remove_signal_watch (bus);
2022 gst_object_unref (bus);
2023 gst_object_unref (bin);
2028 audiomixer_suite (void)
2030 Suite *s = suite_create ("audiomixer");
2031 TCase *tc_chain = tcase_create ("general");
2033 suite_add_tcase (s, tc_chain);
2034 tcase_add_test (tc_chain, test_caps);
2035 tcase_add_test (tc_chain, test_filter_caps);
2036 tcase_add_test (tc_chain, test_event);
2037 tcase_add_test (tc_chain, test_play_twice);
2038 tcase_add_test (tc_chain, test_play_twice_then_add_and_play_again);
2039 tcase_add_test (tc_chain, test_live_seeking);
2040 tcase_add_test (tc_chain, test_add_pad);
2041 tcase_add_test (tc_chain, test_remove_pad);
2042 tcase_add_test (tc_chain, test_clip);
2043 tcase_add_test (tc_chain, test_duration_is_max);
2044 tcase_add_test (tc_chain, test_duration_unknown_overrides);
2045 tcase_add_test (tc_chain, test_loop);
2046 tcase_add_test (tc_chain, test_flush_start_flush_stop);
2047 tcase_add_test (tc_chain, test_sync);
2048 tcase_add_test (tc_chain, test_sync_discont);
2049 tcase_add_test (tc_chain, test_sync_discont_backwards);
2050 tcase_add_test (tc_chain, test_sync_unaligned);
2051 tcase_add_test (tc_chain, test_segment_base_handling);
2052 tcase_add_test (tc_chain, test_sinkpad_property_controller);
2053 tcase_add_checked_fixture (tc_chain, test_setup, test_teardown);
2054 tcase_add_test (tc_chain, test_change_output_caps);
2055 tcase_add_test (tc_chain, test_change_output_caps_mid_output_buffer);
2057 /* Use a longer timeout */
2058 #ifdef HAVE_VALGRIND
2059 if (RUNNING_ON_VALGRIND) {
2060 tcase_set_timeout (tc_chain, 5 * 60);
2064 /* this is shorter than the default 60 seconds?! (tpm) */
2065 /* tcase_set_timeout (tc_chain, 6); */
2071 GST_CHECK_MAIN (audiomixer);