Debian Codegraph @

tests/check/nle/nlecomposition.c

raw
1 /* Gnonlin
2 * Copyright (C) <2009> Alessandro Decina <[email protected]>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19 #include "common.h"
20
21 typedef struct
22 {
23 GstElement *composition;
24 GstElement *source3;
25 } TestClosure;
26
27 static int seek_events;
28
29 static GstPadProbeReturn
30 on_source1_pad_event_cb (GstPad * pad, GstPadProbeInfo * info,
31 gpointer user_data)
32 {
33 if (GST_EVENT_TYPE (info->data) == GST_EVENT_SEEK)
34 ++seek_events;
35
36 return GST_PAD_PROBE_OK;
37 }
38
39 GST_START_TEST (test_change_object_start_stop_in_current_stack)
40 {
41 GstPad *srcpad;
42 GstElement *pipeline;
43 GstElement *comp, *source1, *def, *sink;
44 GstBus *bus;
45 GstMessage *message;
46 gboolean carry_on, ret = FALSE;
47
48 ges_init ();
49
50 pipeline = gst_pipeline_new ("test_pipeline");
51 comp =
52 gst_element_factory_make_or_warn ("nlecomposition", "test_composition");
53
54 gst_element_set_state (comp, GST_STATE_READY);
55
56 sink = gst_element_factory_make_or_warn ("fakevideosink", "sink");
57 g_object_set (sink, "sync", FALSE, NULL);
58 gst_bin_add_many (GST_BIN (pipeline), comp, sink, NULL);
59
60 gst_element_link (comp, sink);
61
62 /*
63 source1
64 Start : 0s
65 Duration : 2s
66 Priority : 2
67 */
68
69 source1 = videotest_nle_src ("source1", 0, 2 * GST_SECOND, 2, 2);
70 srcpad = gst_element_get_static_pad (source1, "src");
71 gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_EVENT_UPSTREAM,
72 (GstPadProbeCallback) on_source1_pad_event_cb, NULL, NULL);
73 gst_object_unref (srcpad);
74
75 /*
76 def (default source)
77 Priority = G_MAXUINT32
78 */
79 def =
80 videotest_nle_src ("default", 0 * GST_SECOND, 0 * GST_SECOND, 2,
81 G_MAXUINT32);
82 g_object_set (def, "expandable", TRUE, NULL);
83
84 ASSERT_OBJECT_REFCOUNT (source1, "source1", 1);
85 ASSERT_OBJECT_REFCOUNT (def, "default", 1);
86
87 /* Add source 1 */
88
89 nle_composition_add (GST_BIN (comp), source1);
90 nle_composition_add (GST_BIN (comp), def);
91 commit_and_wait (comp, &ret);
92 check_start_stop_duration (source1, 0, 2 * GST_SECOND, 2 * GST_SECOND);
93 check_start_stop_duration (comp, 0, 2 * GST_SECOND, 2 * GST_SECOND);
94
95 bus = gst_element_get_bus (GST_ELEMENT (pipeline));
96
97 GST_DEBUG ("Setting pipeline to PAUSED");
98 ASSERT_OBJECT_REFCOUNT (source1, "source1", 1);
99
100 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
101 GST_STATE_PAUSED) == GST_STATE_CHANGE_FAILURE);
102
103 GST_DEBUG ("Let's poll the bus");
104
105 carry_on = TRUE;
106 while (carry_on) {
107 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 10);
108 if (message) {
109 switch (GST_MESSAGE_TYPE (message)) {
110 case GST_MESSAGE_ASYNC_DONE:
111 {
112 carry_on = FALSE;
113 GST_DEBUG ("Pipeline reached PAUSED, stopping polling");
114 break;
115 }
116 case GST_MESSAGE_EOS:
117 {
118 GST_WARNING ("Saw EOS");
119
120 fail_if (TRUE);
121 }
122 case GST_MESSAGE_ERROR:
123 fail_error_message (message);
124 default:
125 break;
126 }
127 gst_mini_object_unref (GST_MINI_OBJECT (message));
128 }
129 }
130
131
132 /* pipeline is paused at this point */
133
134 /* move source1 out of the active segment */
135 g_object_set (source1, "start", (guint64) 4 * GST_SECOND, NULL);
136 commit_and_wait (comp, &ret);
137
138 /* remove source1 from the composition, which will become empty and remove the
139 * ghostpad */
140
141
142 /* keep an extra ref to source1 as we remove it from the bin */
143 gst_object_ref (source1);
144 fail_unless (nle_composition_remove (GST_BIN (comp), source1));
145 g_object_set (source1, "start", (guint64) 0 * GST_SECOND, NULL);
146 /* add the source again and check that the ghostpad is added again */
147 nle_composition_add (GST_BIN (comp), source1);
148 gst_object_unref (source1);
149 commit_and_wait (comp, &ret);
150
151
152 g_object_set (source1, "duration", (guint64) 1 * GST_SECOND, NULL);
153 commit_and_wait (comp, &ret);
154
155 GST_DEBUG ("Setting pipeline to NULL");
156
157 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
158 GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE);
159 gst_element_set_state (source1, GST_STATE_NULL);
160
161 GST_DEBUG ("Resetted pipeline to NULL");
162
163 ASSERT_OBJECT_REFCOUNT_BETWEEN (pipeline, "main pipeline", 1, 2);
164 gst_check_objects_destroyed_on_unref (pipeline, comp, def, NULL);
165 ASSERT_OBJECT_REFCOUNT_BETWEEN (bus, "main bus", 1, 2);
166 gst_object_unref (bus);
167
168 ges_deinit ();
169 }
170
171 GST_END_TEST;
172
173 GST_START_TEST (test_remove_invalid_object)
174 {
175 GstBin *composition;
176 GstElement *source1, *source2;
177
178 ges_init ();
179
180 composition = GST_BIN (gst_element_factory_make ("nlecomposition",
181 "composition"));
182 gst_element_set_state (GST_ELEMENT (composition), GST_STATE_READY);
183
184 source1 = gst_element_factory_make ("nlesource", "source1");
185 source2 = gst_element_factory_make ("nlesource", "source2");
186
187 nle_composition_add (composition, source1);
188 nle_composition_remove (composition, source2);
189 fail_unless (nle_composition_remove (composition, source1));
190
191 gst_element_set_state (GST_ELEMENT (composition), GST_STATE_NULL);
192 gst_object_unref (composition);
193 gst_object_unref (source2);
194
195 ges_deinit ();
196 }
197
198 GST_END_TEST;
199
200 GST_START_TEST (test_remove_last_object)
201 {
202 GstBin *composition;
203 GstElement *source1, *audiotestsrc, *source2, *audiotestsrc2, *fakesink,
204 *pipeline;
205 GstBus *bus;
206 GstMessage *message;
207 gboolean ret;
208 gint64 position = 0;
209 GstClockTime duration;
210
211 ges_init ();
212
213 pipeline = GST_ELEMENT (gst_pipeline_new (NULL));
214 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
215
216 composition = GST_BIN (gst_element_factory_make ("nlecomposition",
217 "composition"));
218
219 gst_element_set_state (GST_ELEMENT (composition), GST_STATE_READY);
220
221 fakesink = gst_element_factory_make ("fakeaudiosink", NULL);
222 g_object_set (fakesink, "sync", FALSE, NULL);
223 gst_bin_add_many (GST_BIN (pipeline), GST_ELEMENT (composition), fakesink,
224 NULL);
225 gst_element_link (GST_ELEMENT (composition), fakesink);
226
227 source1 = gst_element_factory_make ("nlesource", "source1");
228 audiotestsrc = gst_element_factory_make ("audiotestsrc", "audiotestsrc1");
229 gst_bin_add (GST_BIN (source1), audiotestsrc);
230 g_object_set (source1, "start", (guint64) 0 * GST_SECOND,
231 "duration", (gint64) 10 * GST_SECOND, "inpoint", (guint64) 0, "priority",
232 1, NULL);
233
234 nle_composition_add (composition, source1);
235
236 source2 = gst_element_factory_make ("nlesource", "source1");
237 audiotestsrc2 = gst_element_factory_make ("audiotestsrc", "audiotestsrc1");
238 gst_bin_add (GST_BIN (source2), audiotestsrc2);
239 g_object_set (source2, "start", (guint64) 10 * GST_SECOND,
240 "duration", (gint64) 10 * GST_SECOND, "inpoint", (guint64) 0, "priority",
241 1, NULL);
242
243 nle_composition_add (composition, source2);
244
245 fail_if (gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED)
246 == GST_STATE_CHANGE_FAILURE);
247 message = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
248 GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR);
249 gst_mini_object_unref (GST_MINI_OBJECT (message));
250
251 commit_and_wait (GST_ELEMENT (composition), &ret);
252
253 message = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
254 GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR);
255 gst_mini_object_unref (GST_MINI_OBJECT (message));
256
257 gst_element_seek_simple (pipeline,
258 GST_FORMAT_TIME,
259 GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, 15 * GST_SECOND);
260
261 message = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
262 GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR);
263 gst_mini_object_unref (GST_MINI_OBJECT (message));
264
265 ret =
266 gst_element_query_position (GST_ELEMENT (pipeline), GST_FORMAT_TIME,
267 &position);
268 fail_unless_equals_uint64 (position, 15 * GST_SECOND);
269
270 gst_element_seek_simple (pipeline,
271 GST_FORMAT_TIME,
272 GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, 18 * GST_SECOND);
273
274 message = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
275 GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR);
276 gst_mini_object_unref (GST_MINI_OBJECT (message));
277
278 ret =
279 gst_element_query_position (GST_ELEMENT (pipeline), GST_FORMAT_TIME,
280 &position);
281 fail_unless_equals_uint64 (position, 18 * GST_SECOND);
282
283 nle_composition_remove (composition, source2);
284
285 commit_and_wait (GST_ELEMENT (composition), &ret);
286 g_object_get (composition, "duration", &duration, NULL);
287 fail_unless_equals_uint64 (duration, 10 * GST_SECOND);
288
289 ret =
290 gst_element_query_position (GST_ELEMENT (pipeline), GST_FORMAT_TIME,
291 &position);
292 fail_unless_equals_uint64 (position, 10 * GST_SECOND - 1);
293
294 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
295 gst_object_unref (pipeline);
296 gst_object_unref (bus);
297
298 ges_deinit ();
299 }
300
301 GST_END_TEST;
302
303 GST_START_TEST (test_dispose_on_commit)
304 {
305 GstElement *composition;
306 GstElement *nlesource;
307 GstElement *audiotestsrc;
308 GstElement *pipeline, *fakesink;
309 gboolean ret;
310
311 ges_init ();
312
313 composition = gst_element_factory_make ("nlecomposition", "composition");
314 pipeline = GST_ELEMENT (gst_pipeline_new (NULL));
315 fakesink = gst_element_factory_make ("fakevideosink", NULL);
316 g_object_set (fakesink, "sync", FALSE, NULL);
317
318 nlesource = gst_element_factory_make ("nlesource", "nlesource1");
319 audiotestsrc = gst_element_factory_make ("audiotestsrc", "audiotestsrc1");
320 gst_bin_add (GST_BIN (nlesource), audiotestsrc);
321 g_object_set (nlesource, "start", (guint64) 0 * GST_SECOND,
322 "duration", (gint64) 10 * GST_SECOND, "inpoint", (guint64) 0, "priority",
323 1, NULL);
324 fail_unless (nle_composition_add (GST_BIN (composition), nlesource));
325
326 gst_bin_add_many (GST_BIN (pipeline), composition, fakesink, NULL);
327 fail_unless (gst_element_link (composition, fakesink) == TRUE);
328
329
330 ASSERT_OBJECT_REFCOUNT (composition, "composition", 1);
331 g_signal_emit_by_name (composition, "commit", TRUE, &ret);
332
333 gst_object_unref (pipeline);
334
335 ges_deinit ();
336 }
337
338 GST_END_TEST;
339
340 GST_START_TEST (test_simple_audiomixer)
341 {
342 GstBus *bus;
343 GstMessage *message;
344 GstElement *pipeline;
345 GstElement *nle_audiomixer;
346 GstElement *composition;
347 GstElement *audiomixer, *fakesink;
348 GstElement *nlesource1, *nlesource2;
349 GstElement *audiotestsrc1, *audiotestsrc2;
350
351 gboolean carry_on = TRUE, ret;
352 GstClockTime total_time = 10 * GST_SECOND;
353
354 ges_init ();
355
356 pipeline = GST_ELEMENT (gst_pipeline_new (NULL));
357 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
358
359 composition = gst_element_factory_make ("nlecomposition", "composition");
360 gst_element_set_state (composition, GST_STATE_READY);
361 fakesink = gst_element_factory_make ("fakeaudiosink", NULL);
362 g_object_set (fakesink, "sync", FALSE, NULL);
363
364 /* nle_audiomixer */
365 nle_audiomixer = gst_element_factory_make ("nleoperation", "nle_audiomixer");
366 audiomixer = gst_element_factory_make ("audiomixer", "audiomixer");
367 fail_unless (audiomixer != NULL);
368 gst_bin_add (GST_BIN (nle_audiomixer), audiomixer);
369 g_object_set (nle_audiomixer, "start", (guint64) 0 * GST_SECOND,
370 "duration", total_time, "inpoint", (guint64) 0 * GST_SECOND,
371 "priority", 0, NULL);
372 nle_composition_add (GST_BIN (composition), nle_audiomixer);
373
374 /* source 1 */
375 nlesource1 = gst_element_factory_make ("nlesource", "nlesource1");
376 audiotestsrc1 = gst_element_factory_make ("audiotestsrc", "audiotestsrc1");
377 gst_bin_add (GST_BIN (nlesource1), audiotestsrc1);
378 g_object_set (nlesource1, "start", (guint64) 0 * GST_SECOND,
379 "duration", (gint64) total_time / 2, "inpoint", (guint64) 0, "priority",
380 1, NULL);
381 fail_unless (nle_composition_add (GST_BIN (composition), nlesource1));
382
383 /* nlesource2 */
384 nlesource2 = gst_element_factory_make ("nlesource", "nlesource2");
385 audiotestsrc2 = gst_element_factory_make ("audiotestsrc", "audiotestsrc2");
386 gst_bin_add (GST_BIN (nlesource2), GST_ELEMENT (audiotestsrc2));
387 g_object_set (nlesource2, "start", (guint64) 0 * GST_SECOND,
388 "duration", total_time, "inpoint", (guint64) 0 * GST_SECOND, "priority",
389 2, NULL);
390
391 GST_DEBUG ("Adding composition to pipeline");
392 gst_bin_add_many (GST_BIN (pipeline), composition, fakesink, NULL);
393
394 fail_unless (nle_composition_add (GST_BIN (composition), nlesource2));
395 fail_unless (gst_element_link (composition, fakesink) == TRUE);
396
397 GST_DEBUG ("Setting pipeline to PLAYING");
398
399 commit_and_wait (composition, &ret);
400 fail_if (gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING)
401 == GST_STATE_CHANGE_FAILURE);
402
403 message = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
404 GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR);
405
406 if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR)
407 fail_error_message (message);
408 gst_mini_object_unref (GST_MINI_OBJECT (message));
409
410 GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
411 GST_DEBUG_GRAPH_SHOW_ALL, "nle-simple-audiomixer-test-play");
412
413 /* Now play the 10 second composition */
414 while (carry_on) {
415 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 10);
416 GST_LOG ("poll: %" GST_PTR_FORMAT, message);
417 if (message) {
418 switch (GST_MESSAGE_TYPE (message)) {
419 case GST_MESSAGE_EOS:
420 /* we should check if we really finished here */
421 GST_WARNING ("Got an EOS");
422 carry_on = FALSE;
423 break;
424 case GST_MESSAGE_SEGMENT_START:
425 case GST_MESSAGE_SEGMENT_DONE:
426 /* We shouldn't see any segement messages, since we didn't do a segment seek */
427 GST_WARNING ("Saw a Segment start/stop");
428 fail_if (TRUE);
429 carry_on = FALSE;
430 break;
431 case GST_MESSAGE_ERROR:
432 fail_error_message (message);
433 default:
434 break;
435 }
436 gst_mini_object_unref (GST_MINI_OBJECT (message));
437 }
438 }
439
440 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
441 gst_object_unref (bus);
442 gst_object_unref (pipeline);
443
444 ges_deinit ();
445 }
446
447 GST_END_TEST;
448
449 static GstElement *
450 create_nested_source (gint nesting_depth)
451 {
452 gint i;
453 GstElement *source, *nested_comp, *bin;
454
455 source = videotest_nle_src ("source", 0, 2 * GST_SECOND, 2, 2);
456 for (i = 0; i < nesting_depth; i++) {
457 gchar *name = g_strdup_printf ("nested_comp%d", i);
458 gchar *desc = g_strdup_printf ("nlecomposition name=%s ! queue", name);
459 bin = gst_parse_bin_from_description (desc, TRUE, NULL);
460 nested_comp = gst_bin_get_by_name (GST_BIN (bin), name);
461 g_free (name);
462 g_free (desc);
463
464 nle_composition_add (GST_BIN (nested_comp), source);
465 gst_object_unref (nested_comp);
466
467 name = g_strdup_printf ("nested_src%d", i);
468 source = gst_element_factory_make_or_warn ("nlesource", name);
469 g_free (name);
470 g_object_set (source, "start", (guint64) 0, "duration",
471 (gint64) 2 * GST_SECOND, NULL);
472 gst_bin_add (GST_BIN (source), bin);
473 }
474
475
476 return source;
477 }
478
479 GST_START_TEST (test_seek_on_nested)
480 {
481 GstBus *bus;
482 GstPad *srcpad;
483 GstElement *pipeline, *comp, *nested_source, *sink;
484 GstMessage *message;
485 gboolean carry_on, ret = FALSE;
486 GstClockTime position;
487
488 ges_init ();
489
490 pipeline = gst_pipeline_new ("test_pipeline");
491 comp = gst_element_factory_make_or_warn ("nlecomposition", NULL);
492
493 gst_element_set_state (comp, GST_STATE_READY);
494 sink = gst_element_factory_make_or_warn ("fakevideosink", "sink");
495 g_object_set (sink, "sync", FALSE, NULL);
496 gst_bin_add_many (GST_BIN (pipeline), comp, sink, NULL);
497
498 gst_element_link (comp, sink);
499
500 nested_source = create_nested_source (1);
501 srcpad = gst_element_get_static_pad (nested_source, "src");
502 gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_EVENT_UPSTREAM,
503 (GstPadProbeCallback) on_source1_pad_event_cb, NULL, NULL);
504 gst_object_unref (srcpad);
505
506 /* Add nested source */
507 nle_composition_add (GST_BIN (comp), nested_source);
508 commit_and_wait (comp, &ret);
509 check_start_stop_duration (comp, 0, 2 * GST_SECOND, 2 * GST_SECOND);
510
511 bus = gst_element_get_bus (GST_ELEMENT (pipeline));
512
513 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
514 GST_STATE_PAUSED) == GST_STATE_CHANGE_FAILURE);
515
516 GST_DEBUG ("Let's poll the bus");
517
518 carry_on = TRUE;
519 while (carry_on) {
520 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 10);
521 if (message) {
522 switch (GST_MESSAGE_TYPE (message)) {
523 case GST_MESSAGE_ASYNC_DONE:
524 {
525 carry_on = FALSE;
526 GST_DEBUG ("Pipeline reached PAUSED, stopping polling");
527 break;
528 }
529 case GST_MESSAGE_EOS:
530 {
531 GST_WARNING ("Saw EOS");
532
533 fail_if (TRUE);
534 }
535 case GST_MESSAGE_ERROR:
536 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (pipeline),
537 GST_DEBUG_GRAPH_SHOW_ALL, "error");
538 fail_error_message (message);
539 default:
540 break;
541 }
542 gst_mini_object_unref (GST_MINI_OBJECT (message));
543 }
544 }
545
546 gst_element_seek_simple (pipeline,
547 GST_FORMAT_TIME,
548 GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, 1 * GST_SECOND);
549
550 message = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
551 GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR);
552 gst_mini_object_unref (GST_MINI_OBJECT (message));
553
554 ret =
555 gst_element_query_position (GST_ELEMENT (pipeline), GST_FORMAT_TIME,
556 (gint64 *) & position);
557 fail_unless_equals_uint64 (position, 1 * GST_SECOND);
558
559 GST_DEBUG ("Setting pipeline to NULL");
560
561 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
562 GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE);
563
564 GST_DEBUG ("Resetted pipeline to NULL");
565
566 ASSERT_OBJECT_REFCOUNT_BETWEEN (pipeline, "main pipeline", 1, 2);
567 ASSERT_OBJECT_REFCOUNT_BETWEEN (bus, "main bus", 1, 2);
568 gst_object_unref (bus);
569 gst_check_objects_destroyed_on_unref (pipeline, comp, nested_source, NULL);
570
571 ges_deinit ();
572 }
573
574 GST_END_TEST;
575
576 GST_START_TEST (test_error_in_nested_timeline)
577 {
578 GstBus *bus;
579 GstPad *srcpad;
580 GstElement *pipeline, *comp, *nested_source, *sink;
581 GstMessage *message;
582 gboolean carry_on, ret = FALSE;
583
584 ges_init ();
585
586 pipeline = gst_pipeline_new ("test_pipeline");
587 comp = gst_element_factory_make_or_warn ("nlecomposition", NULL);
588
589 gst_element_set_state (comp, GST_STATE_READY);
590 sink = gst_element_factory_make_or_warn ("fakevideosink", "sink");
591 g_object_set (sink, "sync", FALSE, NULL);
592 gst_bin_add_many (GST_BIN (pipeline), comp, sink, NULL);
593
594 gst_element_link (comp, sink);
595
596 nested_source = create_nested_source (1);
597 srcpad = gst_element_get_static_pad (nested_source, "src");
598 gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_EVENT_UPSTREAM,
599 (GstPadProbeCallback) on_source1_pad_event_cb, NULL, NULL);
600 gst_object_unref (srcpad);
601
602 /* Add nested source */
603 nle_composition_add (GST_BIN (comp), nested_source);
604 commit_and_wait (comp, &ret);
605 check_start_stop_duration (comp, 0, 2 * GST_SECOND, 2 * GST_SECOND);
606
607 bus = gst_element_get_bus (GST_ELEMENT (pipeline));
608
609 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
610 GST_STATE_PAUSED) == GST_STATE_CHANGE_FAILURE);
611
612 GST_DEBUG ("Let's poll the bus");
613
614 carry_on = TRUE;
615 while (carry_on) {
616 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 10);
617 if (message) {
618 switch (GST_MESSAGE_TYPE (message)) {
619 case GST_MESSAGE_ASYNC_DONE:
620 {
621 carry_on = FALSE;
622 GST_DEBUG ("Pipeline reached PAUSED, stopping polling");
623 break;
624 }
625 case GST_MESSAGE_EOS:
626 {
627 GST_WARNING ("Saw EOS");
628
629 fail_if (TRUE);
630 }
631 case GST_MESSAGE_ERROR:
632 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (pipeline),
633 GST_DEBUG_GRAPH_SHOW_ALL, "error");
634 fail_error_message (message);
635 default:
636 break;
637 }
638 gst_mini_object_unref (GST_MINI_OBJECT (message));
639 }
640 }
641
642 GST_ELEMENT_ERROR (nested_source, STREAM, FAILED,
643 ("Faking an error message"), ("Nothing"));
644
645 message =
646 gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR);
647 gst_mini_object_unref (GST_MINI_OBJECT (message));
648
649 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
650 GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE);
651
652 GST_DEBUG ("Resetted pipeline to NULL");
653
654 ASSERT_OBJECT_REFCOUNT_BETWEEN (bus, "main bus", 1, 2);
655 gst_object_unref (bus);
656
657 ges_deinit ();
658 }
659
660 GST_END_TEST;
661
662 GST_START_TEST (test_nest_deep)
663 {
664 GstBus *bus;
665 GstPad *srcpad;
666 GstElement *pipeline, *comp, *nested_source, *sink;
667 GstMessage *message;
668 gboolean carry_on, ret = FALSE;
669 GstClockTime position;
670
671 ges_init ();
672
673 pipeline = gst_pipeline_new ("test_pipeline");
674 comp = gst_element_factory_make_or_warn ("nlecomposition", NULL);
675
676 gst_element_set_state (comp, GST_STATE_READY);
677 sink = gst_element_factory_make_or_warn ("fakevideosink", "sink");
678 g_object_set (sink, "sync", FALSE, NULL);
679 gst_bin_add_many (GST_BIN (pipeline), comp, sink, NULL);
680
681 gst_element_link (comp, sink);
682
683 nested_source = create_nested_source (2);
684 srcpad = gst_element_get_static_pad (nested_source, "src");
685 gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_EVENT_UPSTREAM,
686 (GstPadProbeCallback) on_source1_pad_event_cb, NULL, NULL);
687 gst_object_unref (srcpad);
688
689 /* Add nested source */
690 nle_composition_add (GST_BIN (comp), nested_source);
691 commit_and_wait (comp, &ret);
692 check_start_stop_duration (comp, 0, 2 * GST_SECOND, 2 * GST_SECOND);
693
694 bus = gst_element_get_bus (GST_ELEMENT (pipeline));
695
696 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
697 GST_STATE_PAUSED) == GST_STATE_CHANGE_FAILURE);
698
699 GST_DEBUG ("Let's poll the bus");
700
701 carry_on = TRUE;
702 while (carry_on) {
703 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 10);
704 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (pipeline),
705 GST_DEBUG_GRAPH_SHOW_ALL, "nothing");
706 if (message) {
707 switch (GST_MESSAGE_TYPE (message)) {
708 case GST_MESSAGE_ASYNC_DONE:
709 {
710 carry_on = FALSE;
711 GST_DEBUG ("Pipeline reached PAUSED, stopping polling");
712 break;
713 }
714 case GST_MESSAGE_EOS:
715 {
716 GST_WARNING ("Saw EOS");
717
718 fail_if (TRUE);
719 }
720 case GST_MESSAGE_ERROR:
721 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (pipeline),
722 GST_DEBUG_GRAPH_SHOW_ALL, "error");
723 fail_error_message (message);
724 default:
725 break;
726 }
727 gst_mini_object_unref (GST_MINI_OBJECT (message));
728 }
729 }
730
731 gst_element_seek_simple (pipeline,
732 GST_FORMAT_TIME,
733 GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, 1 * GST_SECOND);
734
735 message = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
736 GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR);
737 gst_mini_object_unref (GST_MINI_OBJECT (message));
738
739 ret =
740 gst_element_query_position (GST_ELEMENT (pipeline), GST_FORMAT_TIME,
741 (gint64 *) & position);
742 fail_unless_equals_uint64 (position, 1 * GST_SECOND);
743
744 GST_DEBUG ("Setting pipeline to NULL");
745
746 fail_if (gst_element_set_state (GST_ELEMENT (pipeline),
747 GST_STATE_NULL) == GST_STATE_CHANGE_FAILURE);
748
749 GST_DEBUG ("Resetted pipeline to NULL");
750
751 ASSERT_OBJECT_REFCOUNT_BETWEEN (pipeline, "main pipeline", 1, 2);
752 gst_check_objects_destroyed_on_unref (pipeline, comp, nested_source, NULL);
753 ASSERT_OBJECT_REFCOUNT_BETWEEN (bus, "main bus", 1, 2);
754 gst_object_unref (bus);
755
756 ges_deinit ();
757 }
758
759 GST_END_TEST;
760
761
762
763 static Suite *
764 gnonlin_suite (void)
765 {
766 Suite *s = suite_create ("nlecomposition");
767 TCase *tc_chain = tcase_create ("nlecomposition");
768
769 suite_add_tcase (s, tc_chain);
770
771 tcase_add_test (tc_chain, test_change_object_start_stop_in_current_stack);
772 tcase_add_test (tc_chain, test_remove_invalid_object);
773 tcase_add_test (tc_chain, test_remove_last_object);
774 tcase_add_test (tc_chain, test_seek_on_nested);
775 tcase_add_test (tc_chain, test_error_in_nested_timeline);
776 tcase_add_test (tc_chain, test_nest_deep);
777
778 tcase_add_test (tc_chain, test_dispose_on_commit);
779
780 if (gst_registry_check_feature_version (gst_registry_get (), "audiomixer", 1,
781 0, 0)) {
782 tcase_add_test (tc_chain, test_simple_audiomixer);
783 } else {
784 GST_WARNING ("audiomixer element not available, skipping 1 test");
785 }
786
787 return s;
788 }
789
790 GST_CHECK_MAIN (gnonlin)