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;
104 GstPad *srcpad, *sinkpad;
105 GstStreamConsistency *chk_1, *chk_2, *chk_3;
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 chk_3 = gst_consistency_checker_new (srcpad);
134 gst_object_unref (srcpad);
136 /* create consistency checkers for the pads */
137 srcpad = gst_element_get_static_pad (src1, "src");
138 chk_1 = gst_consistency_checker_new (srcpad);
139 sinkpad = gst_pad_get_peer (srcpad);
140 gst_consistency_checker_add_pad (chk_3, sinkpad);
141 gst_object_unref (sinkpad);
142 gst_object_unref (srcpad);
144 srcpad = gst_element_get_static_pad (src2, "src");
145 chk_2 = gst_consistency_checker_new (srcpad);
146 sinkpad = gst_pad_get_peer (srcpad);
147 gst_consistency_checker_add_pad (chk_3, sinkpad);
148 gst_object_unref (sinkpad);
149 gst_object_unref (srcpad);
151 seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
152 GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
153 GST_SEEK_TYPE_SET, (GstClockTime) 0,
154 GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
156 format = GST_FORMAT_UNDEFINED;
159 main_loop = g_main_loop_new (NULL, FALSE);
160 g_signal_connect (bus, "message::segment-done",
161 (GCallback) test_event_message_received, bin);
162 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
163 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
164 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
166 GST_INFO ("starting test");
168 /* prepare playing */
169 res = gst_element_set_state (bin, GST_STATE_PAUSED);
170 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
172 /* wait for completion */
173 res = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE);
174 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
176 res = gst_element_send_event (bin, seek_event);
177 fail_unless (res == TRUE, NULL);
180 res = gst_element_set_state (bin, GST_STATE_PLAYING);
181 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
183 g_main_loop_run (main_loop);
185 res = gst_element_set_state (bin, GST_STATE_NULL);
186 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
188 fail_unless (position == 2 * GST_SECOND, NULL);
191 g_main_loop_unref (main_loop);
192 gst_consistency_checker_free (chk_1);
193 gst_consistency_checker_free (chk_2);
194 gst_consistency_checker_free (chk_3);
195 gst_object_unref (G_OBJECT (bus));
196 gst_object_unref (G_OBJECT (bin));
201 static guint play_count = 0;
202 static GstEvent *play_seek_event = NULL;
205 test_play_twice_message_received (GstBus * bus, GstMessage * message,
210 GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
211 GST_MESSAGE_SRC (message), message);
213 switch (message->type) {
214 case GST_MESSAGE_SEGMENT_DONE:
216 if (play_count == 1) {
217 res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
218 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
220 /* prepare playing again */
221 res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
222 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
224 /* wait for completion */
226 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
227 GST_CLOCK_TIME_NONE);
228 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
230 res = gst_element_send_event (GST_ELEMENT (bin),
231 gst_event_ref (play_seek_event));
232 fail_unless (res == TRUE, NULL);
234 res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
235 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
237 g_main_loop_quit (main_loop);
241 g_assert_not_reached ();
247 GST_START_TEST (test_play_twice)
249 GstElement *bin, *src1, *src2, *adder, *sink;
253 GstStreamConsistency *consist;
255 GST_INFO ("preparing test");
258 bin = gst_pipeline_new ("pipeline");
259 bus = gst_element_get_bus (bin);
260 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
262 src1 = gst_element_factory_make ("audiotestsrc", "src1");
263 g_object_set (src1, "wave", 4, NULL); /* silence */
264 src2 = gst_element_factory_make ("audiotestsrc", "src2");
265 g_object_set (src2, "wave", 4, NULL); /* silence */
266 adder = gst_element_factory_make ("adder", "adder");
267 sink = gst_element_factory_make ("fakesink", "sink");
268 gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL);
270 res = gst_element_link (src1, adder);
271 fail_unless (res == TRUE, NULL);
272 res = gst_element_link (src2, adder);
273 fail_unless (res == TRUE, NULL);
274 res = gst_element_link (adder, sink);
275 fail_unless (res == TRUE, NULL);
277 srcpad = gst_element_get_static_pad (adder, "src");
278 consist = gst_consistency_checker_new (srcpad);
279 gst_object_unref (srcpad);
281 play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
282 GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
283 GST_SEEK_TYPE_SET, (GstClockTime) 0,
284 GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
288 main_loop = g_main_loop_new (NULL, FALSE);
289 g_signal_connect (bus, "message::segment-done",
290 (GCallback) test_play_twice_message_received, bin);
291 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
292 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
293 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
295 GST_INFO ("starting test");
297 /* prepare playing */
298 res = gst_element_set_state (bin, GST_STATE_PAUSED);
299 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
301 /* wait for completion */
303 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
304 GST_CLOCK_TIME_NONE);
305 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
307 res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
308 fail_unless (res == TRUE, NULL);
313 res = gst_element_set_state (bin, GST_STATE_PLAYING);
314 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
316 g_main_loop_run (main_loop);
318 res = gst_element_set_state (bin, GST_STATE_NULL);
319 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
321 fail_unless (play_count == 2, NULL);
324 g_main_loop_unref (main_loop);
325 gst_consistency_checker_free (consist);
326 gst_event_ref (play_seek_event);
327 gst_object_unref (G_OBJECT (bus));
328 gst_object_unref (G_OBJECT (bin));
333 GST_START_TEST (test_play_twice_then_add_and_play_again)
335 GstElement *bin, *src1, *src2, *src3, *adder, *sink;
340 GstStreamConsistency *consist;
342 GST_INFO ("preparing test");
345 bin = gst_pipeline_new ("pipeline");
346 bus = gst_element_get_bus (bin);
347 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
349 src1 = gst_element_factory_make ("audiotestsrc", "src1");
350 g_object_set (src1, "wave", 4, NULL); /* silence */
351 src2 = gst_element_factory_make ("audiotestsrc", "src2");
352 g_object_set (src2, "wave", 4, NULL); /* silence */
353 adder = gst_element_factory_make ("adder", "adder");
354 sink = gst_element_factory_make ("fakesink", "sink");
355 gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL);
357 srcpad = gst_element_get_static_pad (adder, "src");
358 consist = gst_consistency_checker_new (srcpad);
359 gst_object_unref (srcpad);
361 res = gst_element_link (src1, adder);
362 fail_unless (res == TRUE, NULL);
363 res = gst_element_link (src2, adder);
364 fail_unless (res == TRUE, NULL);
365 res = gst_element_link (adder, sink);
366 fail_unless (res == TRUE, NULL);
368 play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
369 GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH,
370 GST_SEEK_TYPE_SET, (GstClockTime) 0,
371 GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
373 main_loop = g_main_loop_new (NULL, FALSE);
374 g_signal_connect (bus, "message::segment-done",
375 (GCallback) test_play_twice_message_received, bin);
376 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
377 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
378 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
381 for (i = 0; i < 2; i++) {
384 GST_INFO ("starting test-loop %d", i);
386 /* prepare playing */
387 res = gst_element_set_state (bin, GST_STATE_PAUSED);
388 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
390 /* wait for completion */
392 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
393 GST_CLOCK_TIME_NONE);
394 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
396 res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
397 fail_unless (res == TRUE, NULL);
402 res = gst_element_set_state (bin, GST_STATE_PLAYING);
403 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
405 g_main_loop_run (main_loop);
407 res = gst_element_set_state (bin, GST_STATE_READY);
408 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
410 fail_unless (play_count == 2, NULL);
412 /* plug another source */
414 src3 = gst_element_factory_make ("audiotestsrc", "src3");
415 g_object_set (src3, "wave", 4, NULL); /* silence */
416 gst_bin_add (GST_BIN (bin), src3);
418 res = gst_element_link (src3, adder);
419 fail_unless (res == TRUE, NULL);
422 gst_consistency_checker_reset (consist);
425 res = gst_element_set_state (bin, GST_STATE_NULL);
426 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
429 g_main_loop_unref (main_loop);
430 gst_event_ref (play_seek_event);
431 gst_consistency_checker_free (consist);
432 gst_object_unref (G_OBJECT (bus));
433 gst_object_unref (G_OBJECT (bin));
440 test_live_seeking_eos_message_received (GstBus * bus, GstMessage * message,
443 GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT,
444 GST_MESSAGE_SRC (message), message);
446 switch (message->type) {
447 case GST_MESSAGE_EOS:
448 g_main_loop_quit (main_loop);
451 g_assert_not_reached ();
457 /* test failing seeks on live-sources */
458 GST_START_TEST (test_live_seeking)
460 GstElement *bin, *src1, *src2, *ac1, *ac2, *adder, *sink;
465 GstStreamConsistency *consist;
467 GST_INFO ("preparing test");
469 play_seek_event = NULL;
472 bin = gst_pipeline_new ("pipeline");
473 bus = gst_element_get_bus (bin);
474 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
476 /* normal audiosources behave differently than audiotestsrc */
478 src1 = gst_element_factory_make ("audiotestsrc", "src1");
479 g_object_set (src1, "wave", 4, "is-live", TRUE, NULL); /* silence */
481 src1 = gst_element_factory_make ("alsasrc", "src1");
483 GST_INFO ("no audiosrc, skipping");
486 /* Test that the audio source can get to paused, else skip */
487 res = gst_element_set_state (src1, GST_STATE_PAUSED);
488 (void) gst_element_set_state (src1, GST_STATE_NULL);
489 gst_object_unref (src1);
491 if (res == GST_STATE_CHANGE_FAILURE)
493 src1 = gst_element_factory_make ("alsasrc", "src1");
495 /* live sources ignore seeks, force eos after 2 sec (4 buffers half second
496 * each) - don't use autoaudiosrc, as then we can't set anything here */
497 g_object_set (src1, "num-buffers", 4, "blocksize", 44100, NULL);
499 ac1 = gst_element_factory_make ("audioconvert", "ac1");
500 src2 = gst_element_factory_make ("audiotestsrc", "src2");
501 g_object_set (src2, "wave", 4, NULL); /* silence */
502 ac2 = gst_element_factory_make ("audioconvert", "ac2");
503 adder = gst_element_factory_make ("adder", "adder");
504 sink = gst_element_factory_make ("fakesink", "sink");
505 gst_bin_add_many (GST_BIN (bin), src1, ac1, src2, ac2, adder, sink, NULL);
507 res = gst_element_link (src1, ac1);
508 fail_unless (res == TRUE, NULL);
509 res = gst_element_link (ac1, adder);
510 fail_unless (res == TRUE, NULL);
511 res = gst_element_link (src2, ac2);
512 fail_unless (res == TRUE, NULL);
513 res = gst_element_link (ac2, adder);
514 fail_unless (res == TRUE, NULL);
515 res = gst_element_link (adder, sink);
516 fail_unless (res == TRUE, NULL);
518 play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME,
520 GST_SEEK_TYPE_SET, (GstClockTime) 0,
521 GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
523 main_loop = g_main_loop_new (NULL, FALSE);
524 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
525 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
526 g_signal_connect (bus, "message::eos",
527 (GCallback) test_live_seeking_eos_message_received, bin);
529 srcpad = gst_element_get_static_pad (adder, "src");
530 consist = gst_consistency_checker_new (srcpad);
531 gst_object_unref (srcpad);
533 GST_INFO ("starting test");
536 for (i = 0; i < 2; i++) {
538 GST_INFO ("starting test-loop %d", i);
540 /* prepare playing */
541 res = gst_element_set_state (bin, GST_STATE_PAUSED);
542 fail_unless (res != GST_STATE_CHANGE_FAILURE);
544 /* wait for completion */
546 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
547 GST_CLOCK_TIME_NONE);
548 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
550 res = gst_element_send_event (bin, gst_event_ref (play_seek_event));
552 fail_unless (res == TRUE, NULL);
554 /* adder is picky, if a single seek fails it totally fails */
555 fail_unless (res == FALSE, NULL);
561 res = gst_element_set_state (bin, GST_STATE_PLAYING);
562 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
564 GST_INFO ("playing");
566 g_main_loop_run (main_loop);
568 res = gst_element_set_state (bin, GST_STATE_NULL);
569 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
571 gst_consistency_checker_reset (consist);
576 GST_INFO ("cleaning up");
578 g_main_loop_unref (main_loop);
580 gst_event_unref (play_seek_event);
581 gst_object_unref (G_OBJECT (bus));
582 gst_object_unref (G_OBJECT (bin));
587 /* check if adding pads work as expected */
588 GST_START_TEST (test_add_pad)
590 GstElement *bin, *src1, *src2, *adder, *sink;
595 GST_INFO ("preparing test");
598 bin = gst_pipeline_new ("pipeline");
599 bus = gst_element_get_bus (bin);
600 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
602 src1 = gst_element_factory_make ("audiotestsrc", "src1");
603 g_object_set (src1, "num-buffers", 4, NULL);
604 g_object_set (src1, "wave", 4, NULL); /* silence */
605 src2 = gst_element_factory_make ("audiotestsrc", "src2");
606 /* one buffer less, we connect with 1 buffer of delay */
607 g_object_set (src2, "num-buffers", 3, NULL);
608 g_object_set (src2, "wave", 4, NULL); /* silence */
609 adder = gst_element_factory_make ("adder", "adder");
610 sink = gst_element_factory_make ("fakesink", "sink");
611 gst_bin_add_many (GST_BIN (bin), src1, adder, sink, NULL);
613 res = gst_element_link (src1, adder);
614 fail_unless (res == TRUE, NULL);
615 res = gst_element_link (adder, sink);
616 fail_unless (res == TRUE, NULL);
618 srcpad = gst_element_get_static_pad (adder, "src");
619 gst_object_unref (srcpad);
621 main_loop = g_main_loop_new (NULL, FALSE);
622 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
624 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
625 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
626 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
628 GST_INFO ("starting test");
630 /* prepare playing */
631 res = gst_element_set_state (bin, GST_STATE_PAUSED);
632 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
634 /* wait for completion */
636 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
637 GST_CLOCK_TIME_NONE);
638 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
640 /* add other element */
641 gst_bin_add_many (GST_BIN (bin), src2, NULL);
643 /* now link the second element */
644 res = gst_element_link (src2, adder);
645 fail_unless (res == TRUE, NULL);
647 /* set to PAUSED as well */
648 res = gst_element_set_state (src2, GST_STATE_PAUSED);
651 res = gst_element_set_state (bin, GST_STATE_PLAYING);
652 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
654 g_main_loop_run (main_loop);
656 res = gst_element_set_state (bin, GST_STATE_NULL);
657 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
660 g_main_loop_unref (main_loop);
661 gst_object_unref (G_OBJECT (bus));
662 gst_object_unref (G_OBJECT (bin));
667 /* check if removing pads work as expected */
668 GST_START_TEST (test_remove_pad)
670 GstElement *bin, *src, *adder, *sink;
672 GstPad *pad, *srcpad;
675 GST_INFO ("preparing test");
678 bin = gst_pipeline_new ("pipeline");
679 bus = gst_element_get_bus (bin);
680 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
682 src = gst_element_factory_make ("audiotestsrc", "src");
683 g_object_set (src, "num-buffers", 4, NULL);
684 g_object_set (src, "wave", 4, NULL);
685 adder = gst_element_factory_make ("adder", "adder");
686 sink = gst_element_factory_make ("fakesink", "sink");
687 gst_bin_add_many (GST_BIN (bin), src, adder, sink, NULL);
689 res = gst_element_link (src, adder);
690 fail_unless (res == TRUE, NULL);
691 res = gst_element_link (adder, sink);
692 fail_unless (res == TRUE, NULL);
694 /* create an unconnected sinkpad in adder */
695 pad = gst_element_get_request_pad (adder, "sink_%u");
696 fail_if (pad == NULL, NULL);
698 srcpad = gst_element_get_static_pad (adder, "src");
699 gst_object_unref (srcpad);
701 main_loop = g_main_loop_new (NULL, FALSE);
702 g_signal_connect (bus, "message::segment-done", (GCallback) message_received,
704 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
705 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
706 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
708 GST_INFO ("starting test");
710 /* prepare playing, this will not preroll as adder is waiting
711 * on the unconnected sinkpad. */
712 res = gst_element_set_state (bin, GST_STATE_PAUSED);
713 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
715 /* wait for completion for one second, will return ASYNC */
716 res = gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_SECOND);
717 fail_unless (res == GST_STATE_CHANGE_ASYNC, NULL);
719 /* get rid of the pad now, adder should stop waiting on it and
720 * continue the preroll */
721 gst_element_release_request_pad (adder, pad);
722 gst_object_unref (pad);
724 /* wait for completion, should work now */
726 gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
727 GST_CLOCK_TIME_NONE);
728 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
731 res = gst_element_set_state (bin, GST_STATE_PLAYING);
732 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
734 g_main_loop_run (main_loop);
736 res = gst_element_set_state (bin, GST_STATE_NULL);
737 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
740 g_main_loop_unref (main_loop);
741 gst_object_unref (G_OBJECT (bus));
742 gst_object_unref (G_OBJECT (bin));
748 static GstBuffer *handoff_buffer = NULL;
750 handoff_buffer_cb (GstElement * fakesink, GstBuffer * buffer, GstPad * pad,
753 GST_DEBUG ("got buffer %p", buffer);
754 gst_buffer_replace (&handoff_buffer, buffer);
757 /* check if clipping works as expected */
758 GST_START_TEST (test_clip)
761 GstElement *bin, *adder, *sink;
768 //FIXME: GstCaps *caps;
770 GST_INFO ("preparing test");
773 bin = gst_pipeline_new ("pipeline");
774 bus = gst_element_get_bus (bin);
775 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
777 g_signal_connect (bus, "message::error", (GCallback) message_received, bin);
778 g_signal_connect (bus, "message::warning", (GCallback) message_received, bin);
779 g_signal_connect (bus, "message::eos", (GCallback) message_received, bin);
781 /* just an adder and a fakesink */
782 adder = gst_element_factory_make ("adder", "adder");
783 sink = gst_element_factory_make ("fakesink", "sink");
784 g_object_set (sink, "signal-handoffs", TRUE, NULL);
785 g_signal_connect (sink, "handoff", (GCallback) handoff_buffer_cb, NULL);
786 gst_bin_add_many (GST_BIN (bin), adder, sink, NULL);
788 res = gst_element_link (adder, sink);
789 fail_unless (res == TRUE, NULL);
792 res = gst_element_set_state (bin, GST_STATE_PLAYING);
793 fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
795 /* create an unconnected sinkpad in adder, should also automatically activate
797 sinkpad = gst_element_get_request_pad (adder, "sink_%u");
798 fail_if (sinkpad == NULL, NULL);
800 /* send segment to adder */
801 gst_segment_init (&segment, GST_FORMAT_TIME);
802 segment.start = GST_SECOND;
803 segment.stop = 2 * GST_SECOND;
805 event = gst_event_new_segment (&segment);
806 gst_pad_send_event (sinkpad, event);
808 /*FIXME: caps = gst_caps_new_simple ("audio/x-raw",
809 "format", G_TYPE_STRING, GST_AUDIO_NE (S16),
810 "rate", G_TYPE_INT, 44100,
811 "channels", G_TYPE_INT, 2, NULL);
814 /* should be clipped and ok */
815 buffer = gst_buffer_new_and_alloc (44100);
816 GST_BUFFER_TIMESTAMP (buffer) = 0;
817 GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND;
818 //FIXME: gst_buffer_set_caps (buffer, caps);
819 GST_DEBUG ("pushing buffer %p", buffer);
820 ret = gst_pad_chain (sinkpad, buffer);
821 fail_unless (ret == GST_FLOW_OK);
822 fail_unless (handoff_buffer == NULL);
824 /* should be partially clipped */
825 buffer = gst_buffer_new_and_alloc (44100);
826 GST_BUFFER_TIMESTAMP (buffer) = 900 * GST_MSECOND;
827 GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND;
828 //FIXME: gst_buffer_set_caps (buffer, caps);
829 GST_DEBUG ("pushing buffer %p", buffer);
830 ret = gst_pad_chain (sinkpad, buffer);
831 fail_unless (ret == GST_FLOW_OK);
832 fail_unless (handoff_buffer != NULL);
833 gst_buffer_replace (&handoff_buffer, NULL);
835 /* should not be clipped */
836 buffer = gst_buffer_new_and_alloc (44100);
837 GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
838 GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND;
839 //FIXME: gst_buffer_set_caps (buffer, caps);
840 GST_DEBUG ("pushing buffer %p", buffer);
841 ret = gst_pad_chain (sinkpad, buffer);
842 fail_unless (ret == GST_FLOW_OK);
843 fail_unless (handoff_buffer != NULL);
844 gst_buffer_replace (&handoff_buffer, NULL);
846 /* should be clipped and ok */
847 buffer = gst_buffer_new_and_alloc (44100);
848 GST_BUFFER_TIMESTAMP (buffer) = 2 * GST_SECOND;
849 GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND;
850 //FIXME: gst_buffer_set_caps (buffer, caps);
851 GST_DEBUG ("pushing buffer %p", buffer);
852 ret = gst_pad_chain (sinkpad, buffer);
853 fail_unless (ret == GST_FLOW_OK);
854 fail_unless (handoff_buffer == NULL);
864 Suite *s = suite_create ("adder");
865 TCase *tc_chain = tcase_create ("general");
867 suite_add_tcase (s, tc_chain);
868 tcase_add_test (tc_chain, test_event);
869 tcase_add_test (tc_chain, test_play_twice);
870 tcase_add_test (tc_chain, test_play_twice_then_add_and_play_again);
871 tcase_add_test (tc_chain, test_live_seeking);
872 tcase_add_test (tc_chain, test_add_pad);
873 tcase_add_test (tc_chain, test_remove_pad);
874 tcase_add_test (tc_chain, test_clip);
876 /* Use a longer timeout */
878 if (RUNNING_ON_VALGRIND) {
879 tcase_set_timeout (tc_chain, 5 * 60);
883 /* this is shorter than the default 60 seconds?! (tpm) */
884 /* tcase_set_timeout (tc_chain, 6); */
890 GST_CHECK_MAIN (adder);