5 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
28 # include <valgrind/valgrind.h>
33 #include <gst/check/gstcheck.h>
34 #include <gst/check/gstconsistencychecker.h>
36 static GMainLoop *main_loop;
39 message_received (GstBus * bus, GstMessage * message, GstPipeline * bin)
41 GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
42 GST_MESSAGE_SRC (message), message);
44 switch (message->type) {
46 g_main_loop_quit (main_loop);
48 case GST_MESSAGE_WARNING:{
52 gst_message_parse_warning (message, &gerror, &debug);
53 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
54 g_error_free (gerror);
58 case GST_MESSAGE_ERROR:{
62 gst_message_parse_error (message, &gerror, &debug);
63 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
64 g_error_free (gerror);
66 g_main_loop_quit (main_loop);
75 static GstFormat format = GST_FORMAT_UNDEFINED;
76 static gint64 position = -1;
79 test_event_message_received (GstBus * bus, GstMessage * message,
82 GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
83 GST_MESSAGE_SRC (message), message);
85 switch (message->type) {
86 case GST_MESSAGE_SEGMENT_DONE:
87 gst_message_parse_segment_done (message, &format, &position);
88 GST_INFO ("received segment_done : %" G_GINT64_FORMAT, position);
89 g_main_loop_quit (main_loop);
92 g_assert_not_reached ();
98 GST_START_TEST (test_event)
100 GstElement *bin, *src1, *src2, *adder, *sink;
102 GstEvent *seek_event;
105 GstStreamConsistency *consist;
107 GST_INFO ("preparing test");
110 bin = gst_pipeline_new ("pipeline");
111 bus = gst_element_get_bus (bin);
112 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
114 /* FIXME, fakesrc with default setting will produce 0 sized
115 * buffers and incompatible caps for adder that will make
116 * adder EOS and error out */
117 src1 = gst_element_factory_make ("audiotestsrc", "src1");
118 g_object_set (src1, "wave", 4, NULL); /* silence */
119 src2 = gst_element_factory_make ("audiotestsrc", "src2");
120 g_object_set (src2, "wave", 4, NULL); /* silence */
121 adder = gst_element_factory_make ("adder", "adder");
122 sink = gst_element_factory_make ("fakesink", "sink");
123 gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL);
125 res = gst_element_link (src1, adder);
126 fail_unless (res == TRUE, NULL);
127 res = gst_element_link (src2, adder);
128 fail_unless (res == TRUE, NULL);
129 res = gst_element_link (adder, sink);
130 fail_unless (res == TRUE, NULL);
132 srcpad = gst_element_get_static_pad (adder, "src");
133 consist = gst_consistency_checker_new (srcpad);
134 gst_object_unref (srcpad);
136 seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
137 GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
138 GST_SEEK_TYPE_SET, (GstClockTime) 0,
139 GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
141 format = GST_FORMAT_UNDEFINED;
144 main_loop = g_main_loop_new (NULL, FALSE);
145 g_signal_connect (bus, "message::segment-done",
146 (GCallback) test_event_message_received, bin);
147 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
148 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
149 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
151 GST_INFO ("starting test");
153 /* prepare playing */
154 res = gst_element_set_state (bin, GST_STATE_PAUSED);
155 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
157 /* wait for completion */
158 res = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE);
159 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
161 res = gst_element_send_event (bin, seek_event);
162 fail_unless (res == TRUE, NULL);
165 res = gst_element_set_state (bin, GST_STATE_PLAYING);
166 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
168 g_main_loop_run (main_loop);
170 res = gst_element_set_state (bin, GST_STATE_NULL);
171 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
173 fail_unless (position == 2 * GST_SECOND, NULL);
176 g_main_loop_unref (main_loop);
177 gst_consistency_checker_free (consist);
178 gst_object_unref (G_OBJECT (bus));
179 gst_object_unref (G_OBJECT (bin));
184 static guint play_count = 0;
185 static GstEvent *play_seek_event = NULL;
188 test_play_twice_message_received (GstBus * bus, GstMessage * message,
193 GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
194 GST_MESSAGE_SRC (message), message);
196 switch (message->type) {
197 case GST_MESSAGE_SEGMENT_DONE:
199 if (play_count == 1) {
200 res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
201 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
203 /* prepare playing again */
204 res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
205 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
207 /* wait for completion */
209 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
210 GST_CLOCK_TIME_NONE);
211 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
213 res = gst_element_send_event (GST_ELEMENT (bin),
214 gst_event_ref (play_seek_event));
215 fail_unless (res == TRUE, NULL);
217 res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
218 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
220 g_main_loop_quit (main_loop);
224 g_assert_not_reached ();
230 GST_START_TEST (test_play_twice)
232 GstElement *bin, *src1, *src2, *adder, *sink;
236 GstStreamConsistency *consist;
238 GST_INFO ("preparing test");
241 bin = gst_pipeline_new ("pipeline");
242 bus = gst_element_get_bus (bin);
243 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
245 src1 = gst_element_factory_make ("audiotestsrc", "src1");
246 g_object_set (src1, "wave", 4, NULL); /* silence */
247 src2 = gst_element_factory_make ("audiotestsrc", "src2");
248 g_object_set (src2, "wave", 4, NULL); /* silence */
249 adder = gst_element_factory_make ("adder", "adder");
250 sink = gst_element_factory_make ("fakesink", "sink");
251 gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL);
253 res = gst_element_link (src1, adder);
254 fail_unless (res == TRUE, NULL);
255 res = gst_element_link (src2, adder);
256 fail_unless (res == TRUE, NULL);
257 res = gst_element_link (adder, sink);
258 fail_unless (res == TRUE, NULL);
260 srcpad = gst_element_get_static_pad (adder, "src");
261 consist = gst_consistency_checker_new (srcpad);
262 gst_object_unref (srcpad);
264 play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
265 GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
266 GST_SEEK_TYPE_SET, (GstClockTime) 0,
267 GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
271 main_loop = g_main_loop_new (NULL, FALSE);
272 g_signal_connect (bus, "message::segment-done",
273 (GCallback) test_play_twice_message_received, bin);
274 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
275 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
276 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
278 GST_INFO ("starting test");
280 /* prepare playing */
281 res = gst_element_set_state (bin, GST_STATE_PAUSED);
282 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
284 /* wait for completion */
286 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
287 GST_CLOCK_TIME_NONE);
288 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
290 res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
291 fail_unless (res == TRUE, NULL);
296 res = gst_element_set_state (bin, GST_STATE_PLAYING);
297 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
299 g_main_loop_run (main_loop);
301 res = gst_element_set_state (bin, GST_STATE_NULL);
302 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
304 fail_unless (play_count == 2, NULL);
307 g_main_loop_unref (main_loop);
308 gst_consistency_checker_free (consist);
309 gst_event_ref (play_seek_event);
310 gst_object_unref (G_OBJECT (bus));
311 gst_object_unref (G_OBJECT (bin));
316 GST_START_TEST (test_play_twice_then_add_and_play_again)
318 GstElement *bin, *src1, *src2, *src3, *adder, *sink;
323 GstStreamConsistency *consist;
325 GST_INFO ("preparing test");
328 bin = gst_pipeline_new ("pipeline");
329 bus = gst_element_get_bus (bin);
330 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
332 src1 = gst_element_factory_make ("audiotestsrc", "src1");
333 g_object_set (src1, "wave", 4, NULL); /* silence */
334 src2 = gst_element_factory_make ("audiotestsrc", "src2");
335 g_object_set (src2, "wave", 4, NULL); /* silence */
336 adder = gst_element_factory_make ("adder", "adder");
337 sink = gst_element_factory_make ("fakesink", "sink");
338 gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL);
340 srcpad = gst_element_get_static_pad (adder, "src");
341 consist = gst_consistency_checker_new (srcpad);
342 gst_object_unref (srcpad);
344 res = gst_element_link (src1, adder);
345 fail_unless (res == TRUE, NULL);
346 res = gst_element_link (src2, adder);
347 fail_unless (res == TRUE, NULL);
348 res = gst_element_link (adder, sink);
349 fail_unless (res == TRUE, NULL);
351 play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
352 GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
353 GST_SEEK_TYPE_SET, (GstClockTime) 0,
354 GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
356 main_loop = g_main_loop_new (NULL, FALSE);
357 g_signal_connect (bus, "message::segment-done",
358 (GCallback) test_play_twice_message_received, bin);
359 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
360 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
361 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
364 for (i = 0; i < 2; i++) {
367 GST_INFO ("starting test-loop %d", i);
369 /* prepare playing */
370 res = gst_element_set_state (bin, GST_STATE_PAUSED);
371 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
373 /* wait for completion */
375 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
376 GST_CLOCK_TIME_NONE);
377 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
379 res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
380 fail_unless (res == TRUE, NULL);
385 res = gst_element_set_state (bin, GST_STATE_PLAYING);
386 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
388 g_main_loop_run (main_loop);
390 res = gst_element_set_state (bin, GST_STATE_READY);
391 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
393 fail_unless (play_count == 2, NULL);
395 /* plug another source */
397 src3 = gst_element_factory_make ("audiotestsrc", "src3");
398 g_object_set (src3, "wave", 4, NULL); /* silence */
399 gst_bin_add (GST_BIN (bin), src3);
401 res = gst_element_link (src3, adder);
402 fail_unless (res == TRUE, NULL);
405 gst_consistency_checker_reset (consist);
408 res = gst_element_set_state (bin, GST_STATE_NULL);
409 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
412 g_main_loop_unref (main_loop);
413 gst_event_ref (play_seek_event);
414 gst_consistency_checker_free (consist);
415 gst_object_unref (G_OBJECT (bus));
416 gst_object_unref (G_OBJECT (bin));
423 test_live_seeking_eos_message_received (GstBus * bus, GstMessage * message,
426 GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
427 GST_MESSAGE_SRC (message), message);
429 switch (message->type) {
430 case GST_MESSAGE_EOS:
431 g_main_loop_quit (main_loop);
434 g_assert_not_reached ();
440 /* test failing seeks on live-sources */
441 GST_START_TEST (test_live_seeking)
443 GstElement *bin, *src1, *src2, *ac1, *ac2, *adder, *sink;
448 GstStreamConsistency *consist;
450 GST_INFO ("preparing test");
452 play_seek_event = NULL;
455 bin = gst_pipeline_new ("pipeline");
456 bus = gst_element_get_bus (bin);
457 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
459 /* normal audiosources behave differently than audiotestsrc */
461 src1 = gst_element_factory_make ("audiotestsrc", "src1");
462 g_object_set (src1, "wave", 4, "is-live", TRUE, NULL); /* silence */
464 src1 = gst_element_factory_make ("alsasrc", "src1");
466 GST_INFO ("no audiosrc, skipping");
469 /* Test that the audio source can get to paused, else skip */
470 res = gst_element_set_state (src1, GST_STATE_PAUSED);
471 (void) gst_element_set_state (src1, GST_STATE_NULL);
472 gst_object_unref (src1);
474 if (res == GST_STATE_CHANGE_FAILURE)
476 src1 = gst_element_factory_make ("alsasrc", "src1");
478 /* live sources ignore seeks, force eos after 2 sec (4 buffers half second
479 * each) - don't use autoaudiosrc, as then we can't set anything here */
480 g_object_set (src1, "num-buffers", 4, "blocksize", 44100, NULL);
482 ac1 = gst_element_factory_make ("audioconvert", "ac1");
483 src2 = gst_element_factory_make ("audiotestsrc", "src2");
484 g_object_set (src2, "wave", 4, NULL); /* silence */
485 ac2 = gst_element_factory_make ("audioconvert", "ac2");
486 adder = gst_element_factory_make ("adder", "adder");
487 sink = gst_element_factory_make ("fakesink", "sink");
488 gst_bin_add_many (GST_BIN (bin), src1, ac1, src2, ac2, adder, sink, NULL);
490 res = gst_element_link (src1, ac1);
491 fail_unless (res == TRUE, NULL);
492 res = gst_element_link (ac1, adder);
493 fail_unless (res == TRUE, NULL);
494 res = gst_element_link (src2, ac2);
495 fail_unless (res == TRUE, NULL);
496 res = gst_element_link (ac2, adder);
497 fail_unless (res == TRUE, NULL);
498 res = gst_element_link (adder, sink);
499 fail_unless (res == TRUE, NULL);
501 play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
503 GST_SEEK_TYPE_SET, (GstClockTime) 0,
504 GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
506 main_loop = g_main_loop_new (NULL, FALSE);
507 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
508 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
509 g_signal_connect (bus, "message::eos",
510 (GCallback) test_live_seeking_eos_message_received, bin);
512 srcpad = gst_element_get_static_pad (adder, "src");
513 consist = gst_consistency_checker_new (srcpad);
514 gst_object_unref (srcpad);
516 GST_INFO ("starting test");
519 for (i = 0; i < 2; i++) {
521 GST_INFO ("starting test-loop %d", i);
523 /* prepare playing */
524 res = gst_element_set_state (bin, GST_STATE_PAUSED);
525 fail_unless (res != GST_STATE_CHANGE_FAILURE);
527 /* wait for completion */
529 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
530 GST_CLOCK_TIME_NONE);
531 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
533 res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
535 fail_unless (res == TRUE, NULL);
537 /* adder is picky, if a single seek fails it totaly fails */
538 fail_unless (res == FALSE, NULL);
544 res = gst_element_set_state (bin, GST_STATE_PLAYING);
545 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
547 GST_INFO ("playing");
549 g_main_loop_run (main_loop);
551 res = gst_element_set_state (bin, GST_STATE_NULL);
552 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
554 gst_consistency_checker_reset (consist);
559 GST_INFO ("cleaning up");
561 g_main_loop_unref (main_loop);
563 gst_event_unref (play_seek_event);
564 gst_object_unref (G_OBJECT (bus));
565 gst_object_unref (G_OBJECT (bin));
570 /* check if adding pads work as expected */
571 GST_START_TEST (test_add_pad)
573 GstElement *bin, *src1, *src2, *adder, *sink;
576 GstStreamConsistency *consist;
579 GST_INFO ("preparing test");
582 bin = gst_pipeline_new ("pipeline");
583 bus = gst_element_get_bus (bin);
584 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
586 src1 = gst_element_factory_make ("audiotestsrc", "src1");
587 g_object_set (src1, "num-buffers", 4, NULL);
588 g_object_set (src1, "wave", 4, NULL); /* silence */
589 src2 = gst_element_factory_make ("audiotestsrc", "src2");
590 /* one buffer less, we connect with 1 buffer of delay */
591 g_object_set (src2, "num-buffers", 3, NULL);
592 g_object_set (src2, "wave", 4, NULL); /* silence */
593 adder = gst_element_factory_make ("adder", "adder");
594 sink = gst_element_factory_make ("fakesink", "sink");
595 gst_bin_add_many (GST_BIN (bin), src1, adder, sink, NULL);
597 res = gst_element_link (src1, adder);
598 fail_unless (res == TRUE, NULL);
599 res = gst_element_link (adder, sink);
600 fail_unless (res == TRUE, NULL);
602 srcpad = gst_element_get_static_pad (adder, "src");
603 consist = gst_consistency_checker_new (srcpad);
604 gst_object_unref (srcpad);
606 main_loop = g_main_loop_new (NULL, FALSE);
607 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
609 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
610 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
611 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
613 GST_INFO ("starting test");
615 /* prepare playing */
616 res = gst_element_set_state (bin, GST_STATE_PAUSED);
617 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
619 /* wait for completion */
621 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
622 GST_CLOCK_TIME_NONE);
623 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
625 /* add other element */
626 gst_bin_add_many (GST_BIN (bin), src2, NULL);
628 /* now link the second element */
629 res = gst_element_link (src2, adder);
630 fail_unless (res == TRUE, NULL);
632 /* set to PAUSED as well */
633 res = gst_element_set_state (src2, GST_STATE_PAUSED);
636 res = gst_element_set_state (bin, GST_STATE_PLAYING);
637 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
639 g_main_loop_run (main_loop);
641 res = gst_element_set_state (bin, GST_STATE_NULL);
642 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
645 g_main_loop_unref (main_loop);
646 gst_object_unref (G_OBJECT (bus));
647 gst_object_unref (G_OBJECT (bin));
652 /* check if removing pads work as expected */
653 GST_START_TEST (test_remove_pad)
655 GstElement *bin, *src, *adder, *sink;
657 GstPad *pad, *srcpad;
659 GstStreamConsistency *consist;
661 GST_INFO ("preparing test");
664 bin = gst_pipeline_new ("pipeline");
665 bus = gst_element_get_bus (bin);
666 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
668 src = gst_element_factory_make ("audiotestsrc", "src");
669 g_object_set (src, "num-buffers", 4, NULL);
670 g_object_set (src, "wave", 4, NULL);
671 adder = gst_element_factory_make ("adder", "adder");
672 sink = gst_element_factory_make ("fakesink", "sink");
673 gst_bin_add_many (GST_BIN (bin), src, adder, sink, NULL);
675 res = gst_element_link (src, adder);
676 fail_unless (res == TRUE, NULL);
677 res = gst_element_link (adder, sink);
678 fail_unless (res == TRUE, NULL);
680 /* create an unconnected sinkpad in adder */
681 pad = gst_element_get_request_pad (adder, "sink%d");
682 fail_if (pad == NULL, NULL);
684 srcpad = gst_element_get_static_pad (adder, "src");
685 consist = gst_consistency_checker_new (srcpad);
686 gst_object_unref (srcpad);
688 main_loop = g_main_loop_new (NULL, FALSE);
689 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
691 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
692 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
693 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
695 GST_INFO ("starting test");
697 /* prepare playing, this will not preroll as adder is waiting
698 * on the unconnected sinkpad. */
699 res = gst_element_set_state (bin, GST_STATE_PAUSED);
700 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
702 /* wait for completion for one second, will return ASYNC */
703 res = gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_SECOND);
704 fail_unless (res == GST_STATE_CHANGE_ASYNC, NULL);
706 /* get rid of the pad now, adder should stop waiting on it and
707 * continue the preroll */
708 gst_element_release_request_pad (adder, pad);
709 gst_object_unref (pad);
711 /* wait for completion, should work now */
713 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
714 GST_CLOCK_TIME_NONE);
715 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
718 res = gst_element_set_state (bin, GST_STATE_PLAYING);
719 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
721 g_main_loop_run (main_loop);
723 res = gst_element_set_state (bin, GST_STATE_NULL);
724 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
727 g_main_loop_unref (main_loop);
728 gst_object_unref (G_OBJECT (bus));
729 gst_object_unref (G_OBJECT (bin));
735 static GstBuffer *handoff_buffer = NULL;
737 handoff_buffer_cb (GstElement * fakesink, GstBuffer * buffer, GstPad * pad,
740 GST_DEBUG ("got buffer %p", buffer);
741 gst_buffer_replace (&handoff_buffer, buffer);
744 /* check if clipping works as expected */
745 GST_START_TEST (test_clip)
747 GstElement *bin, *adder, *sink;
756 GST_INFO ("preparing test");
759 bin = gst_pipeline_new ("pipeline");
760 bus = gst_element_get_bus (bin);
761 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
763 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
764 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
765 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
767 /* just an adder and a fakesink */
768 adder = gst_element_factory_make ("adder", "adder");
769 sink = gst_element_factory_make ("fakesink", "sink");
770 g_object_set (sink, "signal-handoffs", TRUE, NULL);
771 g_signal_connect (sink, "handoff", (GCallback) handoff_buffer_cb, NULL);
772 gst_bin_add_many (GST_BIN (bin), adder, sink, NULL);
774 res = gst_element_link (adder, sink);
775 fail_unless (res == TRUE, NULL);
778 res = gst_element_set_state (bin, GST_STATE_PLAYING);
779 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
781 /* create an unconnected sinkpad in adder, should also automatically activate
783 sinkpad = gst_element_get_request_pad (adder, "sink%d");
784 fail_if (sinkpad == NULL, NULL);
786 /* send segment to adder */
787 event = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME,
788 GST_SECOND, 2 * GST_SECOND, 0);
789 gst_pad_send_event (sinkpad, event);
791 caps = gst_caps_new_simple ("audio/x-raw-int",
792 "rate", G_TYPE_INT, 44100,
793 "channels", G_TYPE_INT, 2,
794 "endianness", G_TYPE_INT, G_BYTE_ORDER,
795 "width", G_TYPE_INT, 16,
796 "depth", G_TYPE_INT, 16, "signed", G_TYPE_BOOLEAN, TRUE, NULL);
798 /* should be clipped and ok */
799 buffer = gst_buffer_new_and_alloc (44100);
800 GST_BUFFER_TIMESTAMP (buffer) = 0;
801 GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND;
802 gst_buffer_set_caps (buffer, caps);
803 GST_DEBUG ("pushing buffer %p", buffer);
804 ret = gst_pad_chain (sinkpad, buffer);
805 fail_unless (ret == GST_FLOW_OK);
806 fail_unless (handoff_buffer == NULL);
808 /* should be partially clipped */
809 buffer = gst_buffer_new_and_alloc (44100);
810 GST_BUFFER_TIMESTAMP (buffer) = 900 * GST_MSECOND;
811 GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND;
812 gst_buffer_set_caps (buffer, caps);
813 GST_DEBUG ("pushing buffer %p", buffer);
814 ret = gst_pad_chain (sinkpad, buffer);
815 fail_unless (ret == GST_FLOW_OK);
816 fail_unless (handoff_buffer != NULL);
817 gst_buffer_replace (&handoff_buffer, NULL);
819 /* should not be clipped */
820 buffer = gst_buffer_new_and_alloc (44100);
821 GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
822 GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND;
823 gst_buffer_set_caps (buffer, caps);
824 GST_DEBUG ("pushing buffer %p", buffer);
825 ret = gst_pad_chain (sinkpad, buffer);
826 fail_unless (ret == GST_FLOW_OK);
827 fail_unless (handoff_buffer != NULL);
828 gst_buffer_replace (&handoff_buffer, NULL);
830 /* should be clipped and ok */
831 buffer = gst_buffer_new_and_alloc (44100);
832 GST_BUFFER_TIMESTAMP (buffer) = 2 * GST_SECOND;
833 GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND;
834 gst_buffer_set_caps (buffer, caps);
835 GST_DEBUG ("pushing buffer %p", buffer);
836 ret = gst_pad_chain (sinkpad, buffer);
837 fail_unless (ret == GST_FLOW_OK);
838 fail_unless (handoff_buffer == NULL);
848 Suite *s = suite_create ("adder");
849 TCase *tc_chain = tcase_create ("general");
851 suite_add_tcase (s, tc_chain);
852 tcase_add_test (tc_chain, test_event);
853 tcase_add_test (tc_chain, test_play_twice);
854 tcase_add_test (tc_chain, test_play_twice_then_add_and_play_again);
855 tcase_add_test (tc_chain, test_live_seeking);
856 tcase_add_test (tc_chain, test_add_pad);
857 tcase_add_test (tc_chain, test_remove_pad);
858 tcase_add_test (tc_chain, test_clip);
860 /* Use a longer timeout */
862 if (RUNNING_ON_VALGRIND) {
863 tcase_set_timeout (tc_chain, 5 * 60);
867 /* this is shorter than the default 60 seconds?! (tpm) */
868 /* tcase_set_timeout (tc_chain, 6); */
874 GST_CHECK_MAIN (adder);