4 fill_pipeline_and_check (GstElement * comp, GList * segments)
6 GstElement *pipeline, *sink;
7 CollectStructure *collect;
10 gboolean carry_on = TRUE;
12 GList *listcopy = copy_segment_list (segments);
14 pipeline = gst_pipeline_new ("test_pipeline");
15 sink = gst_element_factory_make_or_warn ("fakesink", "sink");
16 fail_if (sink == NULL);
18 gst_bin_add_many (GST_BIN (pipeline), comp, sink, NULL);
21 collect = g_new0 (CollectStructure, 1);
25 /* Expected segments */
26 collect->expected_segments = segments;
28 gst_element_link (comp, sink);
30 sinkpad = gst_element_get_static_pad (sink, "sink");
31 gst_pad_add_probe (sinkpad, GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM,
32 (GstPadProbeCallback) sinkpad_probe, collect, NULL);
34 bus = gst_element_get_bus (GST_ELEMENT (pipeline));
36 GST_DEBUG ("Setting pipeline to PLAYING");
38 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
39 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE);
41 GST_DEBUG ("Let's poll the bus");
43 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 10);
45 switch (GST_MESSAGE_TYPE (message)) {
47 /* we should check if we really finished here */
48 GST_WARNING ("Got an EOS");
51 case GST_MESSAGE_SEGMENT_START:
52 case GST_MESSAGE_SEGMENT_DONE:
53 /* We shouldn't see any segement messages, since we didn't do a segment seek */
54 GST_WARNING ("Saw a Segment start/stop");
57 case GST_MESSAGE_ERROR:
58 fail_error_message (message);
62 gst_mini_object_unref (GST_MINI_OBJECT (message));
66 GST_DEBUG ("Setting pipeline to READY");
68 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
69 GST_STATE_READY) == GST_STATE_CHANGE_FAILURE);
71 fail_if (collect->expected_segments != NULL);
73 GST_DEBUG ("Resetted pipeline to READY");
75 collect->expected_base = 0;
76 collect->expected_segments = listcopy;
77 collect->gotsegment = FALSE;
79 GST_DEBUG ("Setting pipeline to PLAYING again");
81 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
82 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE);
86 GST_DEBUG ("Let's poll the bus");
89 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 10);
91 switch (GST_MESSAGE_TYPE (message)) {
93 /* we should check if we really finished here */
96 case GST_MESSAGE_SEGMENT_START:
97 case GST_MESSAGE_SEGMENT_DONE:
98 /* We shouldn't see any segement messages, since we didn't do a segment seek */
99 GST_WARNING ("Saw a Segment start/stop");
102 case GST_MESSAGE_ERROR:
103 fail_error_message (message);
107 gst_mini_object_unref (GST_MINI_OBJECT (message));
109 GST_DEBUG ("bus_poll responded, but there wasn't any message...");
113 fail_if (collect->expected_segments != NULL);
115 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
116 GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE);
118 gst_object_unref (GST_OBJECT (sinkpad));
119 ASSERT_OBJECT_REFCOUNT_BETWEEN (pipeline, "main pipeline", 1, 2);
120 gst_object_unref (pipeline);
121 ASSERT_OBJECT_REFCOUNT_BETWEEN (bus, "main bus", 1, 2);
122 gst_object_unref (bus);
127 GST_START_TEST (test_simple_operation)
129 gboolean ret = FALSE;
130 GstElement *comp, *oper, *source;
131 GList *segments = NULL;
134 gst_element_factory_make_or_warn ("gnlcomposition", "test_composition");
138 * 0 1 2 3 4 5 | Priority
139 * ----------------------------------------------------------------------------
141 * [------------- source -------------] | 1
151 source = videotest_gnl_src ("source", 0, 3 * GST_SECOND, 2, 1);
152 fail_if (source == NULL);
161 oper = new_operation ("oper", "identity", 1 * GST_SECOND, 1 * GST_SECOND, 0);
162 fail_if (oper == NULL);
165 ASSERT_OBJECT_REFCOUNT (source, "source", 1);
166 ASSERT_OBJECT_REFCOUNT (oper, "oper", 1);
168 gnl_composition_add (GST_BIN (comp), source);
169 commit_and_wait (comp, &ret);
170 check_start_stop_duration (comp, 0, 3 * GST_SECOND, 3 * GST_SECOND);
172 ASSERT_OBJECT_REFCOUNT (source, "source", 1);
176 gnl_composition_add (GST_BIN (comp), oper);
177 commit_and_wait (comp, &ret);
178 check_start_stop_duration (comp, 0, 3 * GST_SECOND, 3 * GST_SECOND);
180 ASSERT_OBJECT_REFCOUNT (oper, "oper", 1);
184 gst_object_ref (source);
185 gnl_composition_remove (GST_BIN (comp), source);
186 check_start_stop_duration (comp, 1 * GST_SECOND, 2 * GST_SECOND,
189 ASSERT_OBJECT_REFCOUNT (source, "source", 1);
192 gnl_composition_add (GST_BIN (comp), source);
193 commit_and_wait (comp, &ret);
194 check_start_stop_duration (comp, 0, 3 * GST_SECOND, 3 * GST_SECOND);
195 gst_object_unref (source);
197 ASSERT_OBJECT_REFCOUNT (source, "source", 1);
199 /* Expected segments */
200 segments = g_list_append (segments,
201 segment_new (1.0, GST_FORMAT_TIME, 0, 1 * GST_SECOND, 0));
202 segments = g_list_append (segments,
203 segment_new (1.0, GST_FORMAT_TIME,
204 1 * GST_SECOND, 2 * GST_SECOND, 1 * GST_SECOND));
205 segments = g_list_append (segments,
206 segment_new (1.0, GST_FORMAT_TIME,
207 2 * GST_SECOND, 3 * GST_SECOND, 2 * GST_SECOND));
209 fill_pipeline_and_check (comp, segments);
214 GST_START_TEST (test_pyramid_operations)
216 GstElement *comp, *oper1, *oper2, *source;
217 gboolean ret = FALSE;
218 GList *segments = NULL;
221 gst_element_factory_make_or_warn ("gnlcomposition", "test_composition");
230 source = videotest_gnl_src ("source", 0, 10 * GST_SECOND, 2, 2);
240 new_operation ("oper1", "identity", 4 * GST_SECOND, 2 * GST_SECOND, 1);
250 new_operation ("oper2", "identity", 2 * GST_SECOND, 6 * GST_SECOND, 0);
253 ASSERT_OBJECT_REFCOUNT (source, "source", 1);
254 ASSERT_OBJECT_REFCOUNT (oper1, "oper1", 1);
255 ASSERT_OBJECT_REFCOUNT (oper2, "oper2", 1);
257 gnl_composition_add (GST_BIN (comp), source);
258 commit_and_wait (comp, &ret);
259 check_start_stop_duration (source, 0, 10 * GST_SECOND, 10 * GST_SECOND);
260 check_start_stop_duration (comp, 0, 10 * GST_SECOND, 10 * GST_SECOND);
262 ASSERT_OBJECT_REFCOUNT (source, "source", 1);
264 /* Add operation 1 */
266 gnl_composition_add (GST_BIN (comp), oper1);
267 commit_and_wait (comp, &ret);
268 check_start_stop_duration (oper1, 4 * GST_SECOND, 6 * GST_SECOND,
270 check_start_stop_duration (comp, 0, 10 * GST_SECOND, 10 * GST_SECOND);
272 ASSERT_OBJECT_REFCOUNT (oper1, "oper1", 1);
274 /* Add operation 2 */
276 gnl_composition_add (GST_BIN (comp), oper2);
277 commit_and_wait (comp, &ret);
278 check_start_stop_duration (oper2, 2 * GST_SECOND, 8 * GST_SECOND,
280 check_start_stop_duration (comp, 0, 10 * GST_SECOND, 10 * GST_SECOND);
282 ASSERT_OBJECT_REFCOUNT (oper1, "oper2", 1);
284 /* Expected segments */
285 segments = g_list_append (segments,
286 segment_new (1.0, GST_FORMAT_TIME, 0, 2 * GST_SECOND, 0));
287 segments = g_list_append (segments,
288 segment_new (1.0, GST_FORMAT_TIME,
289 2 * GST_SECOND, 4 * GST_SECOND, 2 * GST_SECOND));
290 segments = g_list_append (segments,
291 segment_new (1.0, GST_FORMAT_TIME,
292 4 * GST_SECOND, 6 * GST_SECOND, 4 * GST_SECOND));
293 segments = g_list_append (segments,
294 segment_new (1.0, GST_FORMAT_TIME,
295 6 * GST_SECOND, 8 * GST_SECOND, 6 * GST_SECOND));
296 segments = g_list_append (segments,
297 segment_new (1.0, GST_FORMAT_TIME,
298 8 * GST_SECOND, 10 * GST_SECOND, 8 * GST_SECOND));
300 fill_pipeline_and_check (comp, segments);
305 GST_START_TEST (test_pyramid_operations2)
308 GstElement *comp, *oper, *source1, *source2, *def;
309 GList *segments = NULL;
312 gst_element_factory_make_or_warn ("gnlcomposition", "test_composition");
321 source1 = videotest_gnl_src ("source1", 0, 2 * GST_SECOND, 2, 2);
330 oper = new_operation ("oper", "identity", 1 * GST_SECOND, 4 * GST_SECOND, 1);
339 source2 = videotest_gnl_src ("source2", 4 * GST_SECOND, 2 * GST_SECOND, 2, 2);
343 Priority = G_MAXUINT32
346 videotest_gnl_src ("default", 0 * GST_SECOND, 0 * GST_SECOND, 2,
348 g_object_set (def, "expandable", TRUE, NULL);
350 ASSERT_OBJECT_REFCOUNT (source1, "source1", 1);
351 ASSERT_OBJECT_REFCOUNT (source2, "source2", 1);
352 ASSERT_OBJECT_REFCOUNT (oper, "oper", 1);
353 ASSERT_OBJECT_REFCOUNT (def, "default", 1);
357 gnl_composition_add (GST_BIN (comp), source1);
358 commit_and_wait (comp, &ret);
359 check_start_stop_duration (comp, 0, 2 * GST_SECOND, 2 * GST_SECOND);
363 gnl_composition_add (GST_BIN (comp), source2);
364 commit_and_wait (comp, &ret);
365 check_start_stop_duration (comp, 0, 6 * GST_SECOND, 6 * GST_SECOND);
369 gnl_composition_add (GST_BIN (comp), oper);
370 commit_and_wait (comp, &ret);
371 check_start_stop_duration (comp, 0, 6 * GST_SECOND, 6 * GST_SECOND);
375 gnl_composition_add (GST_BIN (comp), def);
376 commit_and_wait (comp, &ret);
377 check_start_stop_duration (comp, 0, 6 * GST_SECOND, 6 * GST_SECOND);
380 /* Expected segments */
381 segments = g_list_append (segments,
382 segment_new (1.0, GST_FORMAT_TIME, 0, 1 * GST_SECOND, 0));
383 segments = g_list_append (segments,
384 segment_new (1.0, GST_FORMAT_TIME,
385 1 * GST_SECOND, 2 * GST_SECOND, 1 * GST_SECOND));
386 segments = g_list_append (segments,
387 segment_new (1.0, GST_FORMAT_TIME,
388 2 * GST_SECOND, 4 * GST_SECOND, 2 * GST_SECOND));
389 segments = g_list_append (segments,
390 segment_new (1.0, GST_FORMAT_TIME,
391 4 * GST_SECOND, 5 * GST_SECOND, 4 * GST_SECOND));
392 segments = g_list_append (segments,
393 segment_new (1.0, GST_FORMAT_TIME,
394 5 * GST_SECOND, 6 * GST_SECOND, 5 * GST_SECOND));
396 fill_pipeline_and_check (comp, segments);
401 GST_START_TEST (test_pyramid_operations_expandable)
403 GstElement *comp, *oper, *source1, *source2, *def;
404 gboolean ret = FALSE;
405 GList *segments = NULL;
408 gst_element_factory_make_or_warn ("gnlcomposition", "test_composition");
417 source1 = videotest_gnl_src ("source1", 0, 2 * GST_SECOND, 2, 2);
420 operation (expandable)
426 oper = new_operation ("oper", "identity", 1 * GST_SECOND, 4 * GST_SECOND, 1);
427 g_object_set (oper, "expandable", TRUE, NULL);
436 source2 = videotest_gnl_src ("source2", 4 * GST_SECOND, 2 * GST_SECOND, 2, 2);
440 Priority = G_MAXUINT32
443 videotest_gnl_src ("default", 0 * GST_SECOND, 0 * GST_SECOND, 2,
445 g_object_set (def, "expandable", TRUE, NULL);
447 ASSERT_OBJECT_REFCOUNT (source1, "source1", 1);
448 ASSERT_OBJECT_REFCOUNT (source2, "source2", 1);
449 ASSERT_OBJECT_REFCOUNT (oper, "oper", 1);
450 ASSERT_OBJECT_REFCOUNT (def, "default", 1);
453 gnl_composition_add (GST_BIN (comp), source1);
455 gnl_composition_add (GST_BIN (comp), source2);
457 gnl_composition_add (GST_BIN (comp), oper);
459 gnl_composition_add (GST_BIN (comp), def);
461 commit_and_wait (comp, &ret);
462 check_start_stop_duration (source1, 0, 2 * GST_SECOND, 2 * GST_SECOND);
463 check_start_stop_duration (oper, 0 * GST_SECOND, 6 * GST_SECOND,
465 check_start_stop_duration (source2, 4 * GST_SECOND, 6 * GST_SECOND,
467 check_start_stop_duration (comp, 0, 6 * GST_SECOND, 6 * GST_SECOND);
469 /* Expected segments */
470 segments = g_list_append (segments,
471 segment_new (1.0, GST_FORMAT_TIME, 0, 2 * GST_SECOND, 0));
472 segments = g_list_append (segments,
473 segment_new (1.0, GST_FORMAT_TIME,
474 2 * GST_SECOND, 4 * GST_SECOND, 2 * GST_SECOND));
475 segments = g_list_append (segments,
476 segment_new (1.0, GST_FORMAT_TIME,
477 4 * GST_SECOND, 6 * GST_SECOND, 4 * GST_SECOND));
479 fill_pipeline_and_check (comp, segments);
485 GST_START_TEST (test_complex_operations)
487 GstElement *comp, *oper, *source1, *source2;
488 gboolean ret = FALSE;
489 GList *segments = NULL;
492 gst_element_factory_make_or_warn ("gnlcomposition", "test_composition");
496 * 0 1 2 3 4 5 6 | Priority
497 * ----------------------------------------------------------------------------
510 source1 = videotest_in_bin_gnl_src ("source1", 0, 4 * GST_SECOND, 2, 3);
511 fail_if (source1 == NULL);
521 videotest_in_bin_gnl_src ("source2", 2 * GST_SECOND, 4 * GST_SECOND, 2,
523 fail_if (source2 == NULL);
533 new_operation ("oper", "compositor", 2 * GST_SECOND, 2 * GST_SECOND, 1);
534 fail_if (oper == NULL);
536 ASSERT_OBJECT_REFCOUNT (source1, "source1", 1);
537 ASSERT_OBJECT_REFCOUNT (source2, "source2", 1);
538 ASSERT_OBJECT_REFCOUNT (oper, "oper", 1);
541 gnl_composition_add (GST_BIN (comp), source1);
542 check_start_stop_duration (comp, 0, 0, 0);
543 ASSERT_OBJECT_REFCOUNT (source1, "source1", 1);
546 gnl_composition_add (GST_BIN (comp), source2);
547 check_start_stop_duration (comp, 0, 0, 0);
548 ASSERT_OBJECT_REFCOUNT (source2, "source2", 1);
551 gnl_composition_add (GST_BIN (comp), oper);
552 check_start_stop_duration (comp, 0, 0, 0);
554 commit_and_wait (comp, &ret);
555 check_start_stop_duration (comp, 0, 6 * GST_SECOND, 6 * GST_SECOND);
557 ASSERT_OBJECT_REFCOUNT (oper, "oper", 1);
559 /* Expected segments */
560 segments = g_list_append (segments,
561 segment_new (1.0, GST_FORMAT_TIME, 0, 2 * GST_SECOND, 0));
562 segments = g_list_append (segments,
563 segment_new (1.0, GST_FORMAT_TIME,
564 0 * GST_SECOND, 2 * GST_SECOND, 2 * GST_SECOND));
565 segments = g_list_append (segments,
566 segment_new (1.0, GST_FORMAT_TIME,
567 4 * GST_SECOND, 6 * GST_SECOND, 4 * GST_SECOND));
569 fill_pipeline_and_check (comp, segments);
575 GST_START_TEST (test_complex_operations_bis)
577 GstElement *comp, *oper, *source1, *source2;
579 GList *segments = NULL;
582 gst_element_factory_make_or_warn ("gnlcomposition", "test_composition");
586 * 0 1 2 3 4 .. 6 | Priority
587 * ----------------------------------------------------------------------------
588 * [ ......................[------ oper ----------]..........] | 1 EXPANDABLE
589 * [--------------------- source1 ----------------] | 2
590 * [------------ source2 ------------] | 3
601 source1 = videotest_in_bin_gnl_src ("source1", 0, 4 * GST_SECOND, 3, 2);
602 fail_if (source1 == NULL);
612 videotest_in_bin_gnl_src ("source2", 2 * GST_SECOND, 4 * GST_SECOND, 2,
614 fail_if (source2 == NULL);
625 new_operation ("oper", "compositor", 2 * GST_SECOND, 2 * GST_SECOND, 1);
626 fail_if (oper == NULL);
627 g_object_set (oper, "expandable", TRUE, NULL);
629 ASSERT_OBJECT_REFCOUNT (source1, "source1", 1);
630 ASSERT_OBJECT_REFCOUNT (source2, "source2", 1);
631 ASSERT_OBJECT_REFCOUNT (oper, "oper", 1);
634 gnl_composition_add (GST_BIN (comp), source1);
635 commit_and_wait (comp, &ret);
636 check_start_stop_duration (comp, 0, 4 * GST_SECOND, 4 * GST_SECOND);
638 ASSERT_OBJECT_REFCOUNT (source1, "source1", 1);
641 gnl_composition_add (GST_BIN (comp), source2);
642 commit_and_wait (comp, &ret);
643 check_start_stop_duration (comp, 0, 6 * GST_SECOND, 6 * GST_SECOND);
645 ASSERT_OBJECT_REFCOUNT (source2, "source2", 1);
649 gnl_composition_add (GST_BIN (comp), oper);
650 commit_and_wait (comp, &ret);
651 check_start_stop_duration (comp, 0, 6 * GST_SECOND, 6 * GST_SECOND);
652 /* Since it's expandable, it should have changed to full length */
653 check_start_stop_duration (oper, 0 * GST_SECOND, 6 * GST_SECOND,
656 ASSERT_OBJECT_REFCOUNT (oper, "oper", 1);
658 /* Expected segments */
659 segments = g_list_append (segments,
660 segment_new (1.0, GST_FORMAT_TIME, 0, 2 * GST_SECOND, 0));
661 segments = g_list_append (segments,
662 segment_new (1.0, GST_FORMAT_TIME,
663 0 * GST_SECOND, 2 * GST_SECOND, 2 * GST_SECOND));
664 segments = g_list_append (segments,
665 segment_new (1.0, GST_FORMAT_TIME,
666 0 * GST_SECOND, 2 * GST_SECOND, 4 * GST_SECOND));
668 fill_pipeline_and_check (comp, segments);
678 Suite *s = suite_create ("gnloperation");
679 TCase *tc_chain = tcase_create ("gnloperation");
681 suite_add_tcase (s, tc_chain);
683 tcase_add_test (tc_chain, test_simple_operation);
684 tcase_add_test (tc_chain, test_pyramid_operations);
685 tcase_add_test (tc_chain, test_pyramid_operations2);
686 tcase_add_test (tc_chain, test_pyramid_operations_expandable);
687 if (gst_registry_check_feature_version (gst_registry_get (), "compositor", 0,
689 tcase_add_test (tc_chain, test_complex_operations);
690 tcase_add_test (tc_chain, test_complex_operations_bis);
692 GST_WARNING ("compositor element not available, skipping 1 test");
697 GST_CHECK_MAIN (gnonlin)