Debian Codegraph @

tests/check/ges/basic.c

raw
1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <[email protected]>
3 * 2012 Collabora Ltd.
4 * Author: Sebastian Dröge <[email protected]>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #include "test-utils.h"
23
24 #include <ges/ges.h>
25 #include <gst/check/gstcheck.h>
26
27
28 GST_START_TEST (test_ges_scenario)
29 {
30 GESTimeline *timeline;
31 GESLayer *layer, *tmp_layer;
32 GESTrack *track;
33 GESTestClip *source;
34 GESTrackElement *trackelement;
35 GList *trackelements, *layers, *tracks;
36
37 ges_init ();
38 /* This is the simplest scenario ever */
39
40 /* Timeline and 1 Layer */
41 GST_DEBUG ("Create a timeline");
42 timeline = ges_timeline_new ();
43 fail_unless (timeline != NULL);
44
45 GST_DEBUG ("Create a layer");
46 layer = ges_layer_new ();
47 fail_unless (layer != NULL);
48
49 GST_DEBUG ("Add the layer to the timeline");
50 fail_unless (ges_timeline_add_layer (timeline, layer));
51 /* The timeline steals our reference to the layer */
52 ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
53 fail_unless (layer->timeline == timeline);
54
55 layers = ges_timeline_get_layers (timeline);
56 fail_unless (g_list_find (layers, layer) != NULL);
57 g_list_free_full (layers, gst_object_unref);
58
59 /* Give the Timeline a Track */
60 GST_DEBUG ("Create a Track");
61 track = GES_TRACK (ges_video_track_new ());
62 fail_unless (track != NULL);
63
64 GST_DEBUG ("Add the track to the timeline");
65 fail_unless (ges_timeline_add_track (timeline, track));
66
67 /* The timeline steals the reference to the track */
68 ASSERT_OBJECT_REFCOUNT (track, "track", 1);
69 fail_unless (ges_track_get_timeline (track) == timeline);
70 fail_unless ((gpointer) GST_ELEMENT_PARENT (track) == (gpointer) timeline);
71
72 /* Create a source and add it to the Layer */
73 GST_DEBUG ("Creating a source");
74 source = ges_test_clip_new ();
75 fail_unless (source != NULL);
76
77 /* The source will be floating before added to the layer... */
78 fail_unless (g_object_is_floating (source));
79 GST_DEBUG ("Adding the source to the timeline layer");
80 fail_unless (ges_layer_add_clip (layer, GES_CLIP (source)));
81 fail_if (g_object_is_floating (source));
82 tmp_layer = ges_clip_get_layer (GES_CLIP (source));
83 fail_unless (tmp_layer == layer);
84 /* The timeline stole our reference */
85 ASSERT_OBJECT_REFCOUNT (source, "source + 1 timeline", 2);
86 gst_object_unref (tmp_layer);
87 ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
88
89 /* Make sure the associated TrackElement is in the Track */
90 trackelements = GES_CONTAINER_CHILDREN (source);
91 fail_unless (trackelements != NULL);
92 trackelement = GES_TRACK_ELEMENT (trackelements->data);
93 /* There are 3 references:
94 * 1 by the clip
95 * 1 by the track
96 * 1 by the timeline */
97 ASSERT_OBJECT_REFCOUNT (trackelement, "trackelement", 3);
98 /* There are 3 references:
99 * 1 by the clip
100 * 3 by the timeline
101 * 1 by the track */
102 ASSERT_OBJECT_REFCOUNT (trackelement, "trackelement", 3);
103 fail_unless (ges_track_element_get_track (trackelement) == track);
104
105 GST_DEBUG ("Remove the Clip from the layer");
106
107 /* Now remove the clip */
108 gst_object_ref (source);
109 ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
110 fail_unless (ges_layer_remove_clip (layer, GES_CLIP (source)));
111 /* track elements emptied from the track, but stay in clip */
112 fail_unless (GES_TIMELINE_ELEMENT_PARENT (trackelement) ==
113 GES_TIMELINE_ELEMENT (source));
114 fail_unless (ges_track_element_get_track (trackelement) == NULL);
115 ASSERT_OBJECT_REFCOUNT (source, "source", 1);
116 ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
117 tmp_layer = ges_clip_get_layer (GES_CLIP (source));
118 fail_unless (tmp_layer == NULL);
119 gst_object_unref (source);
120
121 GST_DEBUG ("Removing track from the timeline");
122 /* Remove the track from the timeline */
123 gst_object_ref (track);
124 fail_unless (ges_timeline_remove_track (timeline, track));
125 assert_num_in_track (track, 0);
126
127 tracks = ges_timeline_get_tracks (timeline);
128 fail_unless (tracks == NULL);
129 ASSERT_OBJECT_REFCOUNT (track, "track", 1);
130 gst_object_unref (track);
131
132 GST_DEBUG ("Removing layer from the timeline");
133 /* Remove the layer from the timeline */
134 gst_object_ref (layer);
135 fail_unless (ges_timeline_remove_layer (timeline, layer));
136 fail_unless (layer->timeline == NULL);
137
138 layers = ges_timeline_get_layers (timeline);
139 fail_unless (layers == NULL);
140 ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
141 gst_object_unref (layer);
142
143 /* Finally clean up our object */
144 ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1);
145 gst_object_unref (timeline);
146
147 ges_deinit ();
148 }
149
150 GST_END_TEST;
151
152 /* very similar to the above, except we add the clip to the layer
153 * and then add it to the timeline.
154 */
155
156 #define _CREATE_SOURCE(layer, clip, start, duration) \
157 { \
158 GESAsset *asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL); \
159 GST_DEBUG ("Creating a source"); \
160 fail_unless (clip = ges_layer_add_asset (layer, asset, start, 0, \
161 duration, GES_TRACK_TYPE_UNKNOWN)); \
162 assert_layer(clip, layer); \
163 ASSERT_OBJECT_REFCOUNT (layer, "layer", 1); \
164 gst_object_unref (asset); \
165 }
166
167 GST_START_TEST (test_ges_timeline_add_layer)
168 {
169 GESTimeline *timeline;
170 GESLayer *layer;
171 GESTrack *track;
172 GESClip *s1, *s2, *s3;
173 GList *trackelements, *layers;
174 GESTrackElement *trackelement;
175
176 ges_init ();
177
178 /* Timeline and 1 Layer */
179 GST_DEBUG ("Create a timeline");
180 timeline = ges_timeline_new ();
181 fail_unless (timeline != NULL);
182
183 GST_DEBUG ("Create a layer");
184 layer = ges_layer_new ();
185 fail_unless (layer != NULL);
186 /* Give the Timeline a Track */
187 GST_DEBUG ("Create a Track");
188 track = GES_TRACK (ges_video_track_new ());
189 fail_unless (track != NULL);
190
191 GST_DEBUG ("Add the track to the timeline");
192 fail_unless (ges_timeline_add_track (timeline, track));
193 /* The timeline steals the reference to the track */
194 ASSERT_OBJECT_REFCOUNT (track, "track", 1);
195 fail_unless (ges_track_get_timeline (track) == timeline);
196 fail_unless ((gpointer) GST_ELEMENT_PARENT (track) == (gpointer) timeline);
197
198 GST_DEBUG ("Add the layer to the timeline");
199 fail_unless (ges_timeline_add_layer (timeline, layer));
200 /* The timeline steals our reference to the layer */
201 ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
202 fail_unless (layer->timeline == timeline);
203 layers = ges_timeline_get_layers (timeline);
204 fail_unless (g_list_find (layers, layer) != NULL);
205 g_list_free_full (layers, gst_object_unref);
206
207 _CREATE_SOURCE (layer, s1, 0, 10);
208 ASSERT_OBJECT_REFCOUNT (layer, "1 for the timeline", 1);
209 _CREATE_SOURCE (layer, s2, 20, 10);
210 ASSERT_OBJECT_REFCOUNT (layer, "1 for the timeline", 1);
211 _CREATE_SOURCE (layer, s3, 40, 10);
212 ASSERT_OBJECT_REFCOUNT (layer, "1 for the timeline", 1);
213
214 /* Make sure the associated TrackElements are in the Track */
215 trackelements = GES_CONTAINER_CHILDREN (s1);
216 fail_unless (trackelements != NULL);
217 trackelement = GES_TRACK_ELEMENT (trackelements->data);
218 /* There are 3 references:
219 * 1 by the clip
220 * 1 by the trackelement
221 * 1 by the timeline */
222 ASSERT_OBJECT_REFCOUNT (trackelement, "trackelement", 3);
223 /* There are 3 references:
224 * 1 by the clip
225 * 1 by the timeline
226 * 1 by the trackelement */
227 ASSERT_OBJECT_REFCOUNT (trackelement, "trackelement", 3);
228
229 trackelements = GES_CONTAINER_CHILDREN (s2);
230 trackelement = GES_TRACK_ELEMENT (trackelements->data);
231 fail_unless (trackelements != NULL);
232
233 /* There are 3 references:
234 * 1 by the clip
235 * 1 by the timeline
236 * 1 by the trackelement */
237 ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (trackelement), "trackelement", 3);
238
239 trackelements = GES_CONTAINER_CHILDREN (s3);
240 trackelement = GES_TRACK_ELEMENT (trackelements->data);
241 fail_unless (trackelements != NULL);
242
243 /* There are 3 references:
244 * 1 by the clip
245 * 1 by the timeline
246 * 2 by the trackelement */
247 ASSERT_OBJECT_REFCOUNT (trackelement, "trackelement", 3);
248
249 /* theoretically this is all we need to do to ensure cleanup */
250 gst_object_unref (timeline);
251
252 ges_deinit ();
253 }
254
255 GST_END_TEST;
256
257 /* this time we add the layer before we add the track. */
258
259 #define _assert_child_in_track(clip, child_type, track) \
260 { \
261 GESTrackElement *el; \
262 GList *tmp = ges_clip_find_track_elements (clip, NULL, \
263 GES_TRACK_TYPE_UNKNOWN, child_type); \
264 fail_unless (g_list_length (tmp), 1); \
265 el = tmp->data; \
266 g_list_free_full (tmp, gst_object_unref); \
267 fail_unless (ges_track_element_get_track (el) == track); \
268 if (track) \
269 ASSERT_OBJECT_REFCOUNT (el, "1 clip + 1 track + 1 timeline", 3); \
270 else \
271 ASSERT_OBJECT_REFCOUNT (el, "1 clip", 1); \
272 }
273
274 #define _assert_no_child_in_track(clip, track) \
275 fail_if (ges_clip_find_track_elements (clip, track, \
276 GES_TRACK_TYPE_UNKNOWN, G_TYPE_NONE));
277
278 #define _assert_add_track(timeline, track) \
279 { \
280 GList *tmp; \
281 GST_DEBUG ("Adding " #track " to the timeline"); \
282 fail_unless (ges_timeline_add_track (timeline, track)); \
283 ASSERT_OBJECT_REFCOUNT (track, #track, 1); \
284 fail_unless (ges_track_get_timeline (track) == timeline); \
285 fail_unless ((gpointer) GST_ELEMENT_PARENT (track) \
286 == (gpointer) timeline); \
287 tmp = ges_timeline_get_tracks (timeline); \
288 fail_unless (g_list_find (tmp, track), #track " not found in tracks"); \
289 g_list_free_full (tmp, gst_object_unref); \
290 }
291
292 #define _remove_sources(clip, expect_num) \
293 { \
294 GList *tmp, *els; \
295 els = ges_clip_find_track_elements (clip, NULL, GES_TRACK_TYPE_UNKNOWN, \
296 GES_TYPE_SOURCE); \
297 assert_equals_int (g_list_length (els), expect_num); \
298 for (tmp = els; tmp; tmp = tmp->next) \
299 fail_unless (ges_container_remove (GES_CONTAINER (clip), tmp->data)); \
300 g_list_free_full (els, gst_object_unref); \
301 }
302
303 #define _remove_from_track(clip, track, expect_num) \
304 { \
305 GList *tmp, *els; \
306 els = ges_clip_find_track_elements (clip, track, GES_TRACK_TYPE_UNKNOWN, \
307 G_TYPE_NONE); \
308 assert_equals_int (g_list_length (els), expect_num); \
309 for (tmp = els; tmp; tmp = tmp->next) \
310 fail_unless (ges_track_remove_element (track, tmp->data)); \
311 g_list_free_full (els, gst_object_unref); \
312 }
313
314 GST_START_TEST (test_ges_timeline_add_layer_first)
315 {
316 GESTimeline *timeline;
317 GESLayer *layer;
318 GESTrack *track, *track1, *track2, *track3;
319 GESClip *s1, *s2, *s3;
320 GList *layers;
321
322 ges_init ();
323
324 /* Timeline and 1 Layer */
325 GST_DEBUG ("Create a timeline");
326 timeline = ges_timeline_new ();
327 fail_unless (timeline != NULL);
328
329 GST_DEBUG ("Create a layer");
330 layer = ges_layer_new ();
331 fail_unless (layer != NULL);
332 /* Give the Timeline a Track */
333 GST_DEBUG ("Create a Track");
334 track = GES_TRACK (ges_video_track_new ());
335 fail_unless (track != NULL);
336
337 _CREATE_SOURCE (layer, s1, 0, 10);
338 _CREATE_SOURCE (layer, s2, 20, 10);
339 _CREATE_SOURCE (layer, s3, 40, 10);
340
341 fail_unless (ges_container_add (GES_CONTAINER (s1),
342 GES_TIMELINE_ELEMENT (ges_effect_new ("agingtv"))));
343 assert_num_children (s1, 1);
344 assert_num_children (s2, 0);
345 assert_num_children (s3, 0);
346
347 GST_DEBUG ("Add the layer to the timeline");
348 fail_unless (ges_timeline_add_layer (timeline, layer));
349 /* The timeline steals our reference to the layer */
350 ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
351 fail_unless (layer->timeline == timeline);
352 layers = ges_timeline_get_layers (timeline);
353 fail_unless (g_list_find (layers, layer) != NULL);
354 g_list_free_full (layers, gst_object_unref);
355
356 /* core children not created yet since no tracks */
357 assert_num_children (s1, 1);
358 assert_num_children (s2, 0);
359 assert_num_children (s3, 0);
360
361 _assert_add_track (timeline, track);
362 /* 3 sources, 1 effect */
363 assert_num_in_track (track, 4);
364
365 /* Make sure the associated TrackElements are in the Track */
366 assert_num_children (s1, 2);
367 _assert_child_in_track (s1, GES_TYPE_EFFECT, track);
368 _assert_child_in_track (s1, GES_TYPE_VIDEO_TEST_SOURCE, track);
369
370 assert_num_children (s2, 1);
371 _assert_child_in_track (s2, GES_TYPE_VIDEO_TEST_SOURCE, track);
372
373 assert_num_children (s3, 1);
374 _assert_child_in_track (s3, GES_TYPE_VIDEO_TEST_SOURCE, track);
375
376 /* adding an audio track should create new audio sources */
377
378 track1 = GES_TRACK (ges_audio_track_new ());
379 _assert_add_track (timeline, track1);
380 /* other track stays the same */
381 assert_num_in_track (track, 4);
382 /* 3 sources */
383 assert_num_in_track (track1, 3);
384
385 /* one new core child */
386 assert_num_children (s1, 3);
387 _assert_child_in_track (s1, GES_TYPE_EFFECT, track);
388 _assert_child_in_track (s1, GES_TYPE_VIDEO_TEST_SOURCE, track);
389 _assert_child_in_track (s1, GES_TYPE_AUDIO_TEST_SOURCE, track1);
390
391 assert_num_children (s2, 2);
392 _assert_child_in_track (s2, GES_TYPE_VIDEO_TEST_SOURCE, track);
393 _assert_child_in_track (s2, GES_TYPE_AUDIO_TEST_SOURCE, track1);
394
395 assert_num_children (s3, 2);
396 _assert_child_in_track (s3, GES_TYPE_VIDEO_TEST_SOURCE, track);
397 _assert_child_in_track (s3, GES_TYPE_AUDIO_TEST_SOURCE, track1);
398
399 /* adding another track should not prompt the change anything
400 * unrelated to the new track */
401
402 /* remove the core children from s1 */
403 _remove_sources (s1, 2);
404
405 /* only have effect left, and not in any track */
406 assert_num_children (s1, 1);
407 /* effect is emptied from its track, since the corresponding core child
408 * was removed */
409 _assert_child_in_track (s1, GES_TYPE_EFFECT, NULL);
410
411 assert_num_in_track (track, 2);
412 assert_num_in_track (track1, 2);
413
414 track2 = GES_TRACK (ges_video_track_new ());
415 _assert_add_track (timeline, track2);
416 /* other tracks stay the same */
417 assert_num_in_track (track, 2);
418 assert_num_in_track (track1, 2);
419 /* 1 sources + 1 effect */
420 assert_num_in_track (track2, 2);
421
422 /* s1 only has a child created for the new track, not the other two */
423 assert_num_children (s1, 2);
424 _assert_child_in_track (s1, GES_TYPE_EFFECT, track2);
425 _assert_child_in_track (s1, GES_TYPE_VIDEO_TEST_SOURCE, track2);
426 _assert_no_child_in_track (s1, track);
427 _assert_no_child_in_track (s1, track1);
428
429 /* other clips stay the same since their children were already created
430 * with set tracks */
431 assert_num_children (s2, 2);
432 _assert_child_in_track (s2, GES_TYPE_VIDEO_TEST_SOURCE, track);
433 _assert_child_in_track (s2, GES_TYPE_AUDIO_TEST_SOURCE, track1);
434 _assert_no_child_in_track (s2, track2);
435
436 assert_num_children (s3, 2);
437 _assert_child_in_track (s3, GES_TYPE_VIDEO_TEST_SOURCE, track);
438 _assert_child_in_track (s3, GES_TYPE_AUDIO_TEST_SOURCE, track1);
439 _assert_no_child_in_track (s3, track2);
440
441 /* same with an audio track */
442
443 /* remove the core child from s1 */
444 _remove_sources (s1, 1);
445
446 assert_num_children (s1, 1);
447 _assert_child_in_track (s1, GES_TYPE_EFFECT, NULL);
448
449 assert_num_in_track (track, 2);
450 assert_num_in_track (track1, 2);
451 assert_num_in_track (track2, 0);
452
453 /* unset the core tracks for s2 */
454 _remove_from_track (s2, track, 1);
455 _remove_from_track (s2, track1, 1);
456 /* but keep children in clip */
457 assert_num_children (s2, 2);
458
459 assert_num_in_track (track, 1);
460 assert_num_in_track (track1, 1);
461 assert_num_in_track (track2, 0);
462
463 track3 = GES_TRACK (ges_audio_track_new ());
464 _assert_add_track (timeline, track3);
465 /* other tracks stay the same */
466 assert_num_in_track (track, 1);
467 assert_num_in_track (track1, 1);
468 assert_num_in_track (track2, 0);
469 /* 2 sources */
470 assert_num_in_track (track3, 2);
471
472 /* s1 creates core for the new track, but effect does not have a track
473 * set since the new track is not a video track */
474 assert_num_children (s1, 2);
475 _assert_child_in_track (s1, GES_TYPE_AUDIO_TEST_SOURCE, track3);
476 _assert_child_in_track (s1, GES_TYPE_EFFECT, NULL);
477 _assert_no_child_in_track (s1, track);
478 _assert_no_child_in_track (s1, track1);
479 _assert_no_child_in_track (s1, track2);
480
481 /* s2 audio core is in the new track, but video remains trackless */
482 assert_num_children (s2, 2);
483 _assert_child_in_track (s2, GES_TYPE_AUDIO_TEST_SOURCE, track3);
484 _assert_child_in_track (s2, GES_TYPE_VIDEO_TEST_SOURCE, NULL);
485 _assert_no_child_in_track (s1, track);
486 _assert_no_child_in_track (s1, track1);
487 _assert_no_child_in_track (s1, track2);
488
489 /* s3 remains the same since core already had tracks */
490 assert_num_children (s3, 2);
491 _assert_child_in_track (s3, GES_TYPE_VIDEO_TEST_SOURCE, track);
492 _assert_child_in_track (s3, GES_TYPE_AUDIO_TEST_SOURCE, track1);
493 _assert_no_child_in_track (s3, track2);
494 _assert_no_child_in_track (s3, track3);
495
496 /* theoretically this is all we need to do to ensure cleanup */
497 gst_object_unref (timeline);
498
499 ges_deinit ();
500 }
501
502 GST_END_TEST;
503
504 GST_START_TEST (test_ges_timeline_remove_track)
505 {
506 GESTimeline *timeline;
507 GESLayer *layer;
508 GESTrack *track;
509 GESClip *s1, *s2, *s3;
510 GESTrackElement *t1, *t2, *t3;
511 GList *trackelements, *tmp, *layers;
512
513 ges_init ();
514
515 /* Timeline and 1 Layer */
516 GST_DEBUG ("Create a timeline");
517 timeline = ges_timeline_new ();
518 fail_unless (timeline != NULL);
519
520 GST_DEBUG ("Create a layer");
521 layer = ges_layer_new ();
522 fail_unless (layer != NULL);
523 /* Give the Timeline a Track */
524 GST_DEBUG ("Create a Track");
525 track = GES_TRACK (ges_video_track_new ());
526 fail_unless (track != NULL);
527
528 _CREATE_SOURCE (layer, s1, 0, 10);
529 ASSERT_OBJECT_REFCOUNT (layer, "1 for the timeline", 1);
530 _CREATE_SOURCE (layer, s2, 20, 10);
531 ASSERT_OBJECT_REFCOUNT (layer, "1 for the timeline", 1);
532 _CREATE_SOURCE (layer, s3, 40, 10);
533 ASSERT_OBJECT_REFCOUNT (layer, "1 for the timeline", 1);
534
535 GST_DEBUG ("Add the layer to the timeline");
536 fail_unless (ges_timeline_add_layer (timeline, layer));
537 /* The timeline steals our reference to the layer */
538 ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
539 fail_unless (layer->timeline == timeline);
540
541 layers = ges_timeline_get_layers (timeline);
542 fail_unless (g_list_find (layers, layer) != NULL);
543 g_list_free_full (layers, gst_object_unref);
544 ASSERT_OBJECT_REFCOUNT (layer, "1 for the timeline", 1);
545
546 GST_DEBUG ("Add the track to the timeline");
547 fail_unless (ges_timeline_add_track (timeline, track));
548 ASSERT_OBJECT_REFCOUNT (track, "track", 1);
549 fail_unless (ges_track_get_timeline (track) == timeline);
550 fail_unless ((gpointer) GST_ELEMENT_PARENT (track) == (gpointer) timeline);
551
552 /* Make sure the associated TrackElements are in the Track */
553 trackelements = GES_CONTAINER_CHILDREN (s1);
554 fail_unless (trackelements != NULL);
555 t1 = GES_TRACK_ELEMENT ((trackelements)->data);
556 for (tmp = trackelements; tmp; tmp = tmp->next) {
557 /* There are 3 references held:
558 * 1 by the clip
559 * 1 by the track
560 * 1 by the timeline */
561 ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (tmp->data), "trackelement", 3);
562 }
563 /* There are 3 references held:
564 * 1 by the container
565 * 1 by the track
566 * 1 by the timeline */
567 ASSERT_OBJECT_REFCOUNT (t1, "trackelement", 3);
568
569 trackelements = GES_CONTAINER_CHILDREN (s2);
570 fail_unless (trackelements != NULL);
571 t2 = GES_TRACK_ELEMENT (trackelements->data);
572 for (tmp = trackelements; tmp; tmp = tmp->next) {
573 /* There are 3 references held:
574 * 1 by the clip
575 * 1 by the track
576 * 1 by the timeline */
577 ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (tmp->data), "trackelement", 3);
578 }
579 /* There are 3 references held:
580 * 1 by the container
581 * 1 by the track
582 * 1 by the timeline */
583 ASSERT_OBJECT_REFCOUNT (t2, "t2", 3);
584
585 trackelements = GES_CONTAINER_CHILDREN (s3);
586 fail_unless (trackelements != NULL);
587 t3 = GES_TRACK_ELEMENT (trackelements->data);
588 for (tmp = trackelements; tmp; tmp = tmp->next) {
589 /* There are 3 references held:
590 * 1 by the clip
591 * 1 by the track
592 * 1 by the timeline */
593 ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (tmp->data), "trackelement", 3);
594 }
595 /* There are 3 references held:
596 * 1 by the container
597 * 1 by the track
598 * 1 by the timeline */
599 ASSERT_OBJECT_REFCOUNT (t3, "t3", 3);
600
601 fail_unless (ges_track_element_get_track (t1) == track);
602 fail_unless (ges_track_element_get_track (t2) == track);
603 fail_unless (ges_track_element_get_track (t3) == track);
604
605 /* remove the track and check that the track elements have been released */
606 gst_object_ref (track);
607 fail_unless (ges_timeline_remove_track (timeline, track));
608 assert_num_in_track (track, 0);
609 gst_object_unref (track);
610 fail_unless (ges_track_element_get_track (t1) == NULL);
611 fail_unless (ges_track_element_get_track (t2) == NULL);
612 fail_unless (ges_track_element_get_track (t3) == NULL);
613
614 ASSERT_OBJECT_REFCOUNT (t1, "trackelement", 1);
615 ASSERT_OBJECT_REFCOUNT (t2, "trackelement", 1);
616 ASSERT_OBJECT_REFCOUNT (t3, "trackelement", 1);
617 ASSERT_OBJECT_REFCOUNT (layer, "1 for the timeline", 1);
618 ASSERT_OBJECT_REFCOUNT (timeline, "1 for the us", 1);
619 tmp = ges_layer_get_clips (layer);
620 assert_equals_int (g_list_length (tmp), 3);
621 g_list_free_full (tmp, (GDestroyNotify) gst_object_unref);
622
623 gst_check_objects_destroyed_on_unref (G_OBJECT (timeline),
624 G_OBJECT (layer), t1, t2, t3, NULL);
625
626 ges_deinit ();
627 }
628
629 GST_END_TEST;
630
631 GST_START_TEST (test_ges_timeline_remove_layer)
632 {
633 GESTimeline *timeline;
634 GESLayer *layer0, *layer1, *layer2, *layer3;
635 GESTrack *track;
636 GESClip *s1, *s2, *s3, *s4, *s5;
637 GList *tmp, *clips, *clip, *layers;
638
639 ges_init ();
640
641 timeline = ges_timeline_new ();
642
643 layer0 = ges_timeline_append_layer (timeline);
644 layer1 = ges_timeline_append_layer (timeline);
645 layer2 = ges_timeline_append_layer (timeline);
646
647 assert_equals_int (ges_layer_get_priority (layer0), 0);
648 assert_equals_int (ges_layer_get_priority (layer1), 1);
649 assert_equals_int (ges_layer_get_priority (layer2), 2);
650
651 track = GES_TRACK (ges_video_track_new ());
652 fail_unless (ges_timeline_add_track (timeline, track));
653
654 _CREATE_SOURCE (layer0, s1, 0, 10);
655 _CREATE_SOURCE (layer1, s2, 0, 10);
656 _CREATE_SOURCE (layer1, s3, 10, 20);
657 _CREATE_SOURCE (layer2, s4, 0, 10);
658 _CREATE_SOURCE (layer2, s5, 10, 20);
659
660 assert_num_in_track (track, 5);
661
662 gst_object_ref (layer1);
663 fail_unless (ges_timeline_remove_layer (timeline, layer1));
664 /* check removed, and rest of the layers stay */
665 layers = ges_timeline_get_layers (timeline);
666 fail_if (g_list_find (layers, layer1));
667 fail_unless (g_list_find (layers, layer0));
668 fail_unless (g_list_find (layers, layer2));
669 g_list_free_full (layers, gst_object_unref);
670 /* keeps its layer priority */
671 assert_equals_int (ges_layer_get_priority (layer1), 1);
672
673 /* Rest also keep their layer priority */
674 /* NOTE: it may be better to resync the layer priorities to plug the
675 * gap, but this way we leave the gap open to add the layer back in */
676 assert_equals_int (ges_layer_get_priority (layer0), 0);
677 assert_equals_int (ges_layer_get_priority (layer2), 2);
678 /* clip children removed from track */
679 assert_num_in_track (track, 3);
680
681 fail_unless (ges_layer_get_timeline (layer1) == NULL);
682 clips = ges_layer_get_clips (layer1);
683 for (clip = clips; clip; clip = clip->next) {
684 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (clip->data) == NULL);
685 for (tmp = GES_CONTAINER_CHILDREN (clip->data); tmp; tmp = tmp->next) {
686 GESTrackElement *el = GES_TRACK_ELEMENT (tmp->data);
687 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (el) == NULL);
688 fail_unless (ges_track_element_get_track (el) == NULL);
689 }
690 }
691 g_list_free_full (clips, gst_object_unref);
692
693 /* layer2 children have same layer priority */
694 clips = ges_layer_get_clips (layer2);
695 for (clip = clips; clip; clip = clip->next) {
696 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (clip->data) == timeline);
697 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (clip->data), 2);
698 for (tmp = GES_CONTAINER_CHILDREN (clip->data); tmp; tmp = tmp->next) {
699 GESTrackElement *el = GES_TRACK_ELEMENT (tmp->data);
700 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (el) == timeline);
701 fail_unless (ges_track_element_get_track (el) == track);
702 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (el), 2);
703 }
704 }
705 g_list_free_full (clips, gst_object_unref);
706
707 /* layer0 stays the same */
708 clips = ges_layer_get_clips (layer0);
709 for (clip = clips; clip; clip = clip->next) {
710 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (clip->data) == timeline);
711 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (clip->data), 0);
712 for (tmp = GES_CONTAINER_CHILDREN (clip->data); tmp; tmp = tmp->next) {
713 GESTrackElement *el = GES_TRACK_ELEMENT (tmp->data);
714 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (el) == timeline);
715 fail_unless (ges_track_element_get_track (el) == track);
716 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (el), 0);
717 }
718 }
719 g_list_free_full (clips, gst_object_unref);
720
721 /* can add a new layer with the correct priority */
722 layer3 = ges_timeline_append_layer (timeline);
723
724 assert_equals_int (ges_layer_get_priority (layer0), 0);
725 assert_equals_int (ges_layer_get_priority (layer2), 2);
726 assert_equals_int (ges_layer_get_priority (layer3), 3);
727
728 gst_object_unref (layer1);
729 gst_object_unref (timeline);
730
731 ges_deinit ();
732 }
733
734 GST_END_TEST;
735
736 typedef struct
737 {
738 GESClip *clips[4];
739 guint num_calls[4];
740 GESTrackElement *effects[3];
741 GESTrack *tr1, *tr2;
742 guint num_unrecognised;
743 } SelectTracksData;
744
745 static GPtrArray *
746 select_tracks_cb (GESTimeline * timeline, GESClip * clip,
747 GESTrackElement * track_element, SelectTracksData * data)
748 {
749 GPtrArray *ret = g_ptr_array_new ();
750 gboolean track1 = FALSE;
751 gboolean track2 = FALSE;
752 guint i;
753 gboolean recognise_clip = FALSE;
754
755 for (i = 0; i < 4; i++) {
756 if (clip == data->clips[i]) {
757 data->num_calls[i]++;
758 recognise_clip = TRUE;
759 }
760 }
761
762 if (!recognise_clip) {
763 GST_DEBUG_OBJECT (timeline, "unrecognised clip %" GES_FORMAT " for "
764 "track element %" GES_FORMAT, GES_ARGS (clip),
765 GES_ARGS (track_element));
766 data->num_unrecognised++;
767 return ret;
768 }
769
770 if (GES_IS_BASE_EFFECT (track_element)) {
771 if (track_element == data->effects[0]) {
772 track1 = TRUE;
773 } else if (track_element == data->effects[1]) {
774 track1 = TRUE;
775 track2 = TRUE;
776 } else if (track_element == data->effects[2]) {
777 track2 = TRUE;
778 } else {
779 GST_DEBUG_OBJECT (timeline, "unrecognised effect %" GES_FORMAT,
780 GES_ARGS (track_element));
781 data->num_unrecognised++;
782 }
783 } else if (GES_IS_SOURCE (track_element)) {
784 if (clip == data->clips[0] || clip == data->clips[1])
785 track1 = TRUE;
786 if (clip == data->clips[1] || clip == data->clips[2])
787 track2 = TRUE;
788 /* clips[3] has no tracks selected */
789 } else {
790 GST_DEBUG_OBJECT (timeline, "unrecognised track element %" GES_FORMAT,
791 GES_ARGS (track_element));
792 data->num_unrecognised++;
793 }
794
795 if (track1)
796 g_ptr_array_add (ret, gst_object_ref (data->tr1));
797 if (track2)
798 g_ptr_array_add (ret, gst_object_ref (data->tr2));
799
800 return ret;
801 }
802
803 GST_START_TEST (test_ges_timeline_multiple_tracks)
804 {
805 GESTimeline *timeline;
806 GESLayer *layer;
807 GESTrack *track1, *track2;
808 GESClip *s1, *s2, *s3, *s4, *transition;
809 GESTrackElement *e1, *e2, *e3, *el, *el2, *e_copy;
810 gboolean found_e1 = FALSE, found_e2 = FALSE, found_e3 = FALSE;
811 GList *trackelements, *tmp, *layers;
812 GstControlSource *ctrl_source;
813 SelectTracksData st_data;
814
815 ges_init ();
816
817 /* Timeline and 1 Layer */
818 GST_DEBUG ("Create a timeline");
819 timeline = ges_timeline_new ();
820 fail_unless (timeline != NULL);
821 ges_timeline_set_auto_transition (timeline, TRUE);
822
823 GST_DEBUG ("Create a layer");
824 layer = ges_layer_new ();
825 fail_unless (layer != NULL);
826 /* Give the Timeline a Track */
827 GST_DEBUG ("Create Track 1");
828 track1 = GES_TRACK (ges_video_track_new ());
829 fail_unless (track1 != NULL);
830 GST_DEBUG ("Create Track 2");
831 track2 = GES_TRACK (ges_video_track_new ());
832 fail_unless (track2 != NULL);
833
834 GST_DEBUG ("Add the track 1 to the timeline");
835 fail_unless (ges_timeline_add_track (timeline, track1));
836 ASSERT_OBJECT_REFCOUNT (track1, "track", 1);
837 fail_unless (ges_track_get_timeline (track1) == timeline);
838 fail_unless ((gpointer) GST_ELEMENT_PARENT (track1) == (gpointer) timeline);
839
840 GST_DEBUG ("Add the track 2 to the timeline");
841 fail_unless (ges_timeline_add_track (timeline, track2));
842 ASSERT_OBJECT_REFCOUNT (track2, "track", 1);
843 fail_unless (ges_track_get_timeline (track2) == timeline);
844 fail_unless ((gpointer) GST_ELEMENT_PARENT (track2) == (gpointer) timeline);
845
846 /* adding to the layer before it is part of the timeline does not
847 * trigger track selection */
848 /* s1 and s3 can overlap since they are destined for different tracks */
849 /* s2 will overlap both */
850 /* s4 destined for no track */
851 _CREATE_SOURCE (layer, s1, 0, 12);
852 _CREATE_SOURCE (layer, s2, 5, 10);
853 _CREATE_SOURCE (layer, s3, 0, 10);
854 _CREATE_SOURCE (layer, s4, 0, 20);
855
856 e1 = GES_TRACK_ELEMENT (ges_effect_new ("videobalance"));
857 fail_unless (ges_container_add (GES_CONTAINER (s2),
858 GES_TIMELINE_ELEMENT (e1)));
859 e2 = GES_TRACK_ELEMENT (ges_effect_new ("agingtv ! vertigotv"));
860 fail_unless (ges_container_add (GES_CONTAINER (s2),
861 GES_TIMELINE_ELEMENT (e2)));
862 e3 = GES_TRACK_ELEMENT (ges_effect_new ("alpha"));
863 fail_unless (ges_container_add (GES_CONTAINER (s2),
864 GES_TIMELINE_ELEMENT (e3)));
865 assert_equals_int (0,
866 ges_clip_get_top_effect_index (s2, GES_BASE_EFFECT (e1)));
867 assert_equals_int (1,
868 ges_clip_get_top_effect_index (s2, GES_BASE_EFFECT (e2)));
869 assert_equals_int (2,
870 ges_clip_get_top_effect_index (s2, GES_BASE_EFFECT (e3)));
871
872 assert_num_children (s1, 0);
873 assert_num_children (s2, 3);
874 assert_num_children (s3, 0);
875
876 ges_timeline_element_set_child_properties (GES_TIMELINE_ELEMENT (s2),
877 "scratch-lines", 2, "speed", 50.0, NULL);
878
879 ctrl_source = GST_CONTROL_SOURCE (gst_interpolation_control_source_new ());
880 g_object_set (G_OBJECT (ctrl_source), "mode",
881 GST_INTERPOLATION_MODE_NONE, NULL);
882 fail_unless (gst_timed_value_control_source_set
883 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), 0, 1.0));
884 fail_unless (gst_timed_value_control_source_set
885 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), 4, 7.0));
886 fail_unless (gst_timed_value_control_source_set
887 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), 8, 3.0));
888 fail_unless (ges_track_element_set_control_source (e2, ctrl_source,
889 "scratch-lines", "direct-absolute"));
890 gst_object_unref (ctrl_source);
891
892 st_data.tr1 = track1;
893 st_data.tr2 = track2;
894 st_data.clips[0] = s1;
895 st_data.clips[1] = s2;
896 st_data.clips[2] = s3;
897 st_data.clips[3] = s4;
898 st_data.num_calls[0] = 0;
899 st_data.num_calls[1] = 0;
900 st_data.num_calls[2] = 0;
901 st_data.num_calls[3] = 0;
902 st_data.effects[0] = e1;
903 st_data.effects[1] = e2;
904 st_data.effects[2] = e3;
905 st_data.num_unrecognised = 0;
906
907 g_signal_connect (timeline, "select-tracks-for-object",
908 G_CALLBACK (select_tracks_cb), &st_data);
909
910 /* adding layer to the timeline will trigger track selection, this */
911 GST_DEBUG ("Add the layer to the timeline");
912 fail_unless (ges_timeline_add_layer (timeline, layer));
913 /* The timeline steals our reference to the layer */
914 ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
915 fail_unless (layer->timeline == timeline);
916
917 layers = ges_timeline_get_layers (timeline);
918 fail_unless (g_list_find (layers, layer) != NULL);
919 g_list_free_full (layers, gst_object_unref);
920
921 fail_unless (ges_layer_get_auto_transition (layer));
922
923 assert_equals_int (st_data.num_unrecognised, 0);
924
925 /* Make sure the associated TrackElements are in the Track */
926 assert_num_children (s1, 1);
927 el = GES_CONTAINER_CHILDREN (s1)->data;
928 fail_unless (GES_IS_SOURCE (el));
929 fail_unless (ges_track_element_get_track (el) == track1);
930 ASSERT_OBJECT_REFCOUNT (el, "1 timeline + 1 track + 1 clip", 3);
931 /* called once for source */
932 assert_equals_int (st_data.num_calls[0], 1);
933
934 /* 2 sources + 4 effects */
935 assert_num_children (s2, 6);
936 trackelements = GES_CONTAINER_CHILDREN (s2);
937 /* sources at the end */
938 el = g_list_nth_data (trackelements, 5);
939 fail_unless (GES_IS_SOURCE (el));
940 el2 = g_list_nth_data (trackelements, 4);
941 fail_unless (GES_IS_SOURCE (el2));
942
943 /* font-desc is originally "", but on setting switches to Normal, so we
944 * set it explicitly */
945 ges_timeline_element_set_child_properties (GES_TIMELINE_ELEMENT (el),
946 "font-desc", "Normal", NULL);
947 assert_equal_children_properties (el, el2);
948 assert_equal_bindings (el, el2);
949
950 assert_equals_int (GES_TIMELINE_ELEMENT_PRIORITY (el),
951 GES_TIMELINE_ELEMENT_PRIORITY (el2));
952
953 /* check one in each track */
954 fail_unless (ges_track_element_get_track (el)
955 != ges_track_element_get_track (el2));
956 fail_unless (ges_track_element_get_track (el) == track1
957 || ges_track_element_get_track (el2) == track1);
958 fail_unless (ges_track_element_get_track (el) == track2
959 || ges_track_element_get_track (el2) == track2);
960
961 /* effects */
962 e_copy = NULL;
963 for (tmp = trackelements; tmp; tmp = tmp->next) {
964 el = tmp->data;
965 ASSERT_OBJECT_REFCOUNT (el, "1 timeline + 1 track + 1 clip", 3);
966 if (GES_IS_BASE_EFFECT (el)) {
967 if (el == e1) {
968 fail_if (found_e1);
969 found_e1 = TRUE;
970 } else if (el == e2) {
971 fail_if (found_e2);
972 found_e2 = TRUE;
973 } else if (el == e3) {
974 fail_if (found_e3);
975 found_e3 = TRUE;
976 } else {
977 fail_if (e_copy);
978 e_copy = el;
979 }
980 }
981 }
982 fail_unless (found_e1);
983 fail_unless (found_e2);
984 fail_unless (found_e3);
985 fail_unless (e_copy);
986
987 fail_unless (ges_track_element_get_track (e1) == track1);
988 fail_unless (ges_track_element_get_track (e3) == track2);
989
990 assert_equal_children_properties (e2, e_copy);
991 assert_equal_bindings (e2, e_copy);
992
993 /* check one in each track */
994 fail_unless (ges_track_element_get_track (e2)
995 != ges_track_element_get_track (e_copy));
996 fail_unless (ges_track_element_get_track (e2) == track1
997 || ges_track_element_get_track (e_copy) == track1);
998 fail_unless (ges_track_element_get_track (e2) == track2
999 || ges_track_element_get_track (e_copy) == track2);
1000
1001 /* e2 copy placed next to e2 in top effect list */
1002 assert_equals_int (0,
1003 ges_clip_get_top_effect_index (s2, GES_BASE_EFFECT (e1)));
1004 assert_equals_int (1,
1005 ges_clip_get_top_effect_index (s2, GES_BASE_EFFECT (e2)));
1006 assert_equals_int (2,
1007 ges_clip_get_top_effect_index (s2, GES_BASE_EFFECT (e_copy)));
1008 assert_equals_int (3,
1009 ges_clip_get_top_effect_index (s2, GES_BASE_EFFECT (e3)));
1010
1011 /* called 4 times: 1 for source, and 1 for each effect (3) */
1012 assert_equals_int (st_data.num_calls[1], 4);
1013
1014 assert_num_children (s3, 1);
1015 el = GES_CONTAINER_CHILDREN (s3)->data;
1016 fail_unless (GES_IS_SOURCE (el));
1017 fail_unless (ges_track_element_get_track (el) == track2);
1018 ASSERT_OBJECT_REFCOUNT (el, "1 timeline + 1 track + 1 clip", 3);
1019 /* called once for source */
1020 assert_equals_int (st_data.num_calls[2], 1);
1021
1022 /* one child but no track */
1023 assert_num_children (s4, 1);
1024 el = GES_CONTAINER_CHILDREN (s4)->data;
1025 fail_unless (GES_IS_SOURCE (el));
1026 fail_unless (ges_track_element_get_track (el) == NULL);
1027 ASSERT_OBJECT_REFCOUNT (el, "1 clip", 1);
1028 /* called once for source (where no track was selected) */
1029 assert_equals_int (st_data.num_calls[0], 1);
1030
1031 /* 2 sources + 1 transition + 2 effects */
1032 assert_num_in_track (track1, 5);
1033 assert_num_in_track (track2, 5);
1034
1035 el = NULL;
1036 trackelements = ges_track_get_elements (track1);
1037 for (tmp = trackelements; tmp; tmp = tmp->next) {
1038 if (GES_IS_VIDEO_TRANSITION (tmp->data)) {
1039 fail_if (el);
1040 el = tmp->data;
1041 }
1042 }
1043 g_list_free_full (trackelements, gst_object_unref);
1044 fail_unless (GES_IS_CLIP (GES_TIMELINE_ELEMENT_PARENT (el)));
1045 transition = GES_CLIP (GES_TIMELINE_ELEMENT_PARENT (el));
1046 assert_layer (transition, layer);
1047
1048 CHECK_OBJECT_PROPS (transition, 5, 0, 7);
1049 CHECK_OBJECT_PROPS (el, 5, 0, 7);
1050 fail_unless (ges_track_element_get_track (el) == track1);
1051 /* make sure we can change the transition type */
1052 fail_unless (ges_video_transition_set_transition_type (GES_VIDEO_TRANSITION
1053 (el), GES_VIDEO_STANDARD_TRANSITION_TYPE_BARNDOOR_H));
1054
1055 el = NULL;
1056 trackelements = ges_track_get_elements (track2);
1057 for (tmp = trackelements; tmp; tmp = tmp->next) {
1058 if (GES_IS_VIDEO_TRANSITION (tmp->data)) {
1059 fail_if (el);
1060 el = tmp->data;
1061 }
1062 }
1063 g_list_free_full (trackelements, gst_object_unref);
1064 fail_unless (GES_IS_CLIP (GES_TIMELINE_ELEMENT_PARENT (el)));
1065 transition = GES_CLIP (GES_TIMELINE_ELEMENT_PARENT (el));
1066 assert_layer (transition, layer);
1067
1068 CHECK_OBJECT_PROPS (transition, 5, 0, 5);
1069 CHECK_OBJECT_PROPS (el, 5, 0, 5);
1070 fail_unless (ges_track_element_get_track (el) == track2);
1071 /* make sure we can change the transition type */
1072 fail_unless (ges_video_transition_set_transition_type (GES_VIDEO_TRANSITION
1073 (el), GES_VIDEO_STANDARD_TRANSITION_TYPE_BARNDOOR_H));
1074
1075 gst_object_unref (timeline);
1076
1077 ges_deinit ();
1078 }
1079
1080 GST_END_TEST;
1081
1082 GST_START_TEST (test_ges_pipeline_change_state)
1083 {
1084 GstState state;
1085 GESAsset *asset;
1086 GESLayer *layer;
1087 GESTimeline *timeline;
1088 GESPipeline *pipeline;
1089
1090 ges_init ();
1091
1092 layer = ges_layer_new ();
1093 timeline = ges_timeline_new_audio_video ();
1094 fail_unless (ges_timeline_add_layer (timeline, layer));
1095
1096 pipeline = ges_test_create_pipeline (timeline);
1097
1098 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
1099 ges_layer_add_asset (layer, asset, 0, 0, 10, GES_TRACK_TYPE_UNKNOWN);
1100 gst_object_unref (asset);
1101
1102 ges_timeline_commit (timeline);
1103 ASSERT_SET_STATE (GST_ELEMENT (pipeline), GST_STATE_PLAYING,
1104 GST_STATE_CHANGE_ASYNC);
1105 fail_unless (gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL,
1106 GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_SUCCESS);
1107 fail_unless (state == GST_STATE_PLAYING);
1108 ASSERT_SET_STATE (GST_ELEMENT (pipeline), GST_STATE_NULL,
1109 GST_STATE_CHANGE_SUCCESS);
1110
1111 gst_object_unref (pipeline);
1112
1113 ges_deinit ();
1114 }
1115
1116 GST_END_TEST;
1117
1118 GST_START_TEST (test_ges_timeline_element_name)
1119 {
1120 GESClip *clip, *clip1, *clip2, *clip3, *clip4, *clip5;
1121 GESAsset *asset;
1122 GESTimeline *timeline;
1123 GESLayer *layer;
1124
1125 ges_init ();
1126
1127 timeline = ges_timeline_new_audio_video ();
1128 layer = ges_layer_new ();
1129 fail_unless (ges_timeline_add_layer (timeline, layer));
1130
1131 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
1132 clip = ges_layer_add_asset (layer, asset, 0, 0, 10, GES_TRACK_TYPE_UNKNOWN);
1133 fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip), "testclip0");
1134
1135
1136 clip1 = GES_CLIP (ges_test_clip_new ());
1137 fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip1), "testclip1");
1138
1139 ges_timeline_element_set_name (GES_TIMELINE_ELEMENT (clip1), "testclip1");
1140 fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip1), "testclip1");
1141
1142 /* Check that trying to set to a name that is already used leads to
1143 * a change in the name */
1144 ges_timeline_element_set_name (GES_TIMELINE_ELEMENT (clip), "testclip1");
1145 fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip), "testclip2");
1146
1147 ges_timeline_element_set_name (GES_TIMELINE_ELEMENT (clip1), "testclip4");
1148 fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip1), "testclip4");
1149
1150 clip2 = GES_CLIP (ges_test_clip_new ());
1151 fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip2), "testclip5");
1152 ges_timeline_element_set_name (GES_TIMELINE_ELEMENT (clip2), NULL);
1153 fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip2), "testclip6");
1154
1155 clip3 = GES_CLIP (ges_test_clip_new ());
1156 fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip3), "testclip7");
1157 ges_timeline_element_set_name (GES_TIMELINE_ELEMENT (clip3), "testclip5");
1158 fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip3), "testclip8");
1159
1160 clip4 = GES_CLIP (ges_test_clip_new ());
1161 fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip4), "testclip9");
1162
1163
1164 clip5 = GES_CLIP (ges_test_clip_new ());
1165 ges_timeline_element_set_name (GES_TIMELINE_ELEMENT (clip5),
1166 "Something I want!");
1167 fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip5),
1168 "Something I want!");
1169
1170 gst_object_unref (asset);
1171
1172 gst_object_unref (clip1);
1173 gst_object_unref (clip2);
1174 gst_object_unref (clip3);
1175 gst_object_unref (clip4);
1176 gst_object_unref (clip5);
1177 gst_object_unref (timeline);
1178
1179 ges_deinit ();
1180 }
1181
1182 GST_END_TEST;
1183
1184 GST_START_TEST (test_ges_pipeline_shared_pool_context)
1185 {
1186 GstState state;
1187 GESAsset *asset;
1188 GESLayer *layer;
1189 GESTimeline *timeline;
1190 GESPipeline *pipeline;
1191 GstContext *context;
1192 GstTaskPool *pool = NULL;
1193
1194 ges_init ();
1195
1196 layer = ges_layer_new ();
1197 timeline = ges_timeline_new_audio_video ();
1198 fail_unless (ges_timeline_add_layer (timeline, layer));
1199
1200 pipeline = ges_test_create_pipeline (timeline);
1201
1202 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
1203 ges_layer_add_asset (layer, asset, 0, 0, 10 * GST_MSECOND,
1204 GES_TRACK_TYPE_UNKNOWN);
1205 gst_object_unref (asset);
1206
1207 ges_timeline_commit (timeline);
1208 ASSERT_SET_STATE (GST_ELEMENT (pipeline), GST_STATE_PLAYING,
1209 GST_STATE_CHANGE_ASYNC);
1210 fail_unless (gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL,
1211 GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_SUCCESS);
1212
1213 /* Verify that the pipeline stored the shared task pool context on itself
1214 * so that subsequent NEED_CONTEXT requests reuse the same pool */
1215 context =
1216 gst_element_get_context (GST_ELEMENT (pipeline),
1217 GST_TASK_POOL_CONTEXT_TYPE);
1218 fail_unless (context != NULL,
1219 "Pipeline should store the shared task pool context");
1220 fail_unless (gst_context_get_task_pool (context, &pool));
1221 fail_unless (GST_IS_SHARED_TASK_POOL (pool));
1222 gst_object_unref (pool);
1223 gst_context_unref (context);
1224
1225 ASSERT_SET_STATE (GST_ELEMENT (pipeline), GST_STATE_NULL,
1226 GST_STATE_CHANGE_SUCCESS);
1227
1228 gst_object_unref (pipeline);
1229
1230 ges_deinit ();
1231 }
1232
1233 GST_END_TEST;
1234
1235 static Suite *
1236 ges_suite (void)
1237 {
1238 Suite *s = suite_create ("ges-basic");
1239 TCase *tc_chain = tcase_create ("basic");
1240
1241 suite_add_tcase (s, tc_chain);
1242
1243 tcase_add_test (tc_chain, test_ges_scenario);
1244 tcase_add_test (tc_chain, test_ges_timeline_add_layer);
1245 tcase_add_test (tc_chain, test_ges_timeline_add_layer_first);
1246 tcase_add_test (tc_chain, test_ges_timeline_remove_track);
1247 tcase_add_test (tc_chain, test_ges_timeline_remove_layer);
1248 tcase_add_test (tc_chain, test_ges_timeline_multiple_tracks);
1249 tcase_add_test (tc_chain, test_ges_pipeline_change_state);
1250 tcase_add_test (tc_chain, test_ges_timeline_element_name);
1251 tcase_add_test (tc_chain, test_ges_pipeline_shared_pool_context);
1252
1253 return s;
1254 }
1255
1256 GST_CHECK_MAIN (ges);