Debian Codegraph @

tests/check/ges/effects.c

raw
1 /* GStreamer Editing Services
2 * Copyright (C) 2010 Thibault Saunier <[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
20 #include "test-utils.h"
21 #include <ges/ges.h>
22 #include <gst/check/gstcheck.h>
23
24 void
25 deep_prop_changed_cb (GESTrackElement * track_element, GstElement * element,
26 GParamSpec * spec);
27
28 GST_START_TEST (test_effect_basic)
29 {
30 GESEffect *effect;
31
32 ges_init ();
33
34 effect = ges_effect_new ("agingtv");
35 fail_unless (effect != NULL);
36 gst_object_unref (effect);
37
38 ges_deinit ();
39 }
40
41 GST_END_TEST;
42
43 GST_START_TEST (test_add_effect_to_clip)
44 {
45 GESTimeline *timeline;
46 GESLayer *layer;
47 GESTrack *track_audio, *track_video;
48 GESEffect *effect;
49 GESTestClip *source;
50
51 ges_init ();
52
53 timeline = ges_timeline_new ();
54 layer = ges_layer_new ();
55 track_audio = GES_TRACK (ges_audio_track_new ());
56 track_video = GES_TRACK (ges_video_track_new ());
57
58 ges_timeline_add_track (timeline, track_audio);
59 ges_timeline_add_track (timeline, track_video);
60 ges_timeline_add_layer (timeline, layer);
61
62 source = ges_test_clip_new ();
63
64 g_object_set (source, "duration", 10 * GST_SECOND, NULL);
65
66 ges_layer_add_clip (layer, (GESClip *) source);
67
68
69 GST_DEBUG ("Create effect");
70 effect = ges_effect_new ("agingtv");
71
72 fail_unless (GES_IS_EFFECT (effect));
73 fail_unless (ges_container_add (GES_CONTAINER (source),
74 GES_TIMELINE_ELEMENT (effect)));
75 fail_unless (ges_track_element_get_track (GES_TRACK_ELEMENT (effect)) !=
76 NULL);
77
78 assert_equals_int (GES_TRACK_ELEMENT (effect)->active, TRUE);
79
80 ges_layer_remove_clip (layer, (GESClip *) source);
81
82 gst_object_unref (timeline);
83
84 ges_deinit ();
85 }
86
87 GST_END_TEST;
88
89 GST_START_TEST (test_get_effects_from_tl)
90 {
91 GESTimeline *timeline;
92 GESLayer *layer;
93 GESTrack *track_video;
94 GESTrackElement *video_source;
95 GESEffect *effect, *effect1, *effect2;
96 GESTestClip *source;
97 GList *effects, *tmp = NULL;
98 gint effect_prio = -1;
99
100 ges_init ();
101
102 timeline = ges_timeline_new ();
103 layer = ges_layer_new ();
104 track_video = GES_TRACK (ges_video_track_new ());
105
106 ges_timeline_add_track (timeline, track_video);
107 ges_timeline_add_layer (timeline, layer);
108
109 source = ges_test_clip_new ();
110
111 g_object_set (source, "duration", 10 * GST_SECOND, NULL);
112
113 GST_DEBUG ("Adding source to layer");
114 ges_layer_add_clip (layer, (GESClip *) source);
115 assert_equals_int (g_list_length (GES_CONTAINER_CHILDREN (source)), 1);
116 video_source = GES_CONTAINER_CHILDREN (source)->data;
117 fail_unless (GES_IS_VIDEO_TEST_SOURCE (video_source));
118 assert_equals_int (_PRIORITY (video_source),
119 MIN_NLE_PRIO + TRANSITIONS_HEIGHT);
120
121 GST_DEBUG ("Create effect");
122 effect = ges_effect_new ("agingtv");
123 effect1 = ges_effect_new ("agingtv");
124 effect2 = ges_effect_new ("agingtv");
125
126 fail_unless (GES_IS_EFFECT (effect));
127 fail_unless (GES_IS_EFFECT (effect1));
128 fail_unless (GES_IS_EFFECT (effect2));
129
130 GST_DEBUG ("Adding effect (0)");
131 fail_unless (ges_container_add (GES_CONTAINER (source),
132 GES_TIMELINE_ELEMENT (effect)));
133 fail_unless (ges_track_element_get_track (GES_TRACK_ELEMENT (effect)) ==
134 track_video);
135 assert_equals_int (_PRIORITY (effect), MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 0);
136 assert_equals_int (_PRIORITY (video_source),
137 MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 1);
138
139 GST_DEBUG ("Adding effect 1");
140 fail_unless (ges_container_add (GES_CONTAINER (source),
141 GES_TIMELINE_ELEMENT (effect1)));
142 fail_unless (ges_track_element_get_track (GES_TRACK_ELEMENT (effect1)) ==
143 track_video);
144 assert_equals_int (_PRIORITY (effect), MIN_NLE_PRIO + TRANSITIONS_HEIGHT);
145 assert_equals_int (_PRIORITY (effect1),
146 MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 1);
147 assert_equals_int (_PRIORITY (video_source),
148 MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 2);
149
150 GST_DEBUG ("Adding effect 2");
151 fail_unless (ges_container_add (GES_CONTAINER (source),
152 GES_TIMELINE_ELEMENT (effect2)));
153 fail_unless (ges_track_element_get_track (GES_TRACK_ELEMENT (effect2)) ==
154 track_video);
155 assert_equals_int (GES_CONTAINER_HEIGHT (source), 4);
156
157 effects = ges_clip_get_top_effects (GES_CLIP (source));
158 fail_unless (g_list_length (effects) == 3);
159 for (tmp = effects; tmp; tmp = tmp->next) {
160 gint priority = ges_clip_get_top_effect_position (GES_CLIP (source),
161 GES_BASE_EFFECT (tmp->data));
162 fail_unless (priority > effect_prio);
163 fail_unless (GES_IS_EFFECT (tmp->data));
164 effect_prio = priority;
165
166 gst_object_unref (tmp->data);
167 }
168 g_list_free (effects);
169
170 ges_layer_remove_clip (layer, (GESClip *) source);
171
172 gst_object_unref (timeline);
173
174 ges_deinit ();
175 }
176
177 GST_END_TEST;
178
179 GST_START_TEST (test_effect_clip)
180 {
181 GESTimeline *timeline;
182 GESLayer *layer;
183 GESTrack *track_audio, *track_video;
184 GESEffectClip *effect_clip;
185 GESEffect *effect, *effect1, *core_effect, *core_effect1;
186 GList *children, *top_effects, *tmp;
187 gint clip_height;
188 gint core_effect_prio;
189 gint effect_index, effect1_index;
190
191 ges_init ();
192
193 timeline = ges_timeline_new ();
194 layer = ges_layer_new ();
195 track_audio = GES_TRACK (ges_audio_track_new ());
196 track_video = GES_TRACK (ges_video_track_new ());
197
198 ges_timeline_add_track (timeline, track_audio);
199 ges_timeline_add_track (timeline, track_video);
200 ges_timeline_add_layer (timeline, layer);
201
202 GST_DEBUG ("Create effect");
203 /* these are the core video and audio effects for the clip */
204 effect_clip = ges_effect_clip_new ("videobalance", "audioecho");
205
206 g_object_set (effect_clip, "duration", 25 * GST_SECOND, NULL);
207
208 ges_layer_add_clip (layer, (GESClip *) effect_clip);
209
210 /* core elements should now be created */
211 fail_unless (children = GES_CONTAINER_CHILDREN (effect_clip));
212 core_effect = GES_EFFECT (children->data);
213 fail_unless (children = children->next);
214 core_effect1 = GES_EFFECT (children->data);
215 fail_unless (children->next == NULL);
216
217 /* both effects are placed at the same priority since they are core
218 * children of the clip, destined for different tracks */
219 core_effect_prio = _PRIORITY (core_effect);
220 assert_equals_int (core_effect_prio, _PRIORITY (core_effect1));
221 g_object_get (effect_clip, "height", &clip_height, NULL);
222 assert_equals_int (clip_height, 1);
223
224 /* add additional non-core effects */
225 effect = ges_effect_new ("agingtv");
226 fail_unless (ges_container_add (GES_CONTAINER (effect_clip),
227 GES_TIMELINE_ELEMENT (effect)));
228 fail_unless (ges_track_element_get_track (GES_TRACK_ELEMENT (effect)) ==
229 track_video);
230
231 /* placed at a higher priority than the effects */
232 core_effect_prio = _PRIORITY (core_effect);
233 assert_equals_int (core_effect_prio, _PRIORITY (core_effect1));
234 fail_unless (_PRIORITY (effect) < core_effect_prio);
235 g_object_get (effect_clip, "height", &clip_height, NULL);
236 assert_equals_int (clip_height, 2);
237
238 effect_index =
239 ges_clip_get_top_effect_index (GES_CLIP (effect_clip),
240 GES_BASE_EFFECT (effect));
241 assert_equals_int (effect_index, 0);
242
243 /* 'effect1' is placed in between the core children and 'effect' */
244 effect1 = ges_effect_new ("audiopanorama");
245 fail_unless (ges_container_add (GES_CONTAINER (effect_clip),
246 GES_TIMELINE_ELEMENT (effect1)));
247 fail_unless (ges_track_element_get_track (GES_TRACK_ELEMENT (effect1)) ==
248 track_audio);
249
250 /* 'effect' is still the highest priority effect, and the core
251 * elements are at the lowest priority */
252 core_effect_prio = _PRIORITY (core_effect);
253 assert_equals_int (core_effect_prio, _PRIORITY (core_effect1));
254 fail_unless (_PRIORITY (effect1) < core_effect_prio);
255 fail_unless (_PRIORITY (effect1) > _PRIORITY (effect));
256 g_object_get (effect_clip, "height", &clip_height, NULL);
257 assert_equals_int (clip_height, 3);
258
259 effect_index =
260 ges_clip_get_top_effect_index (GES_CLIP (effect_clip),
261 GES_BASE_EFFECT (effect));
262 effect1_index =
263 ges_clip_get_top_effect_index (GES_CLIP (effect_clip),
264 GES_BASE_EFFECT (effect1));
265 assert_equals_int (effect_index, 0);
266 assert_equals_int (effect1_index, 1);
267
268 /* all effects are children of the effect_clip, ordered by priority */
269 fail_unless (children = GES_CONTAINER_CHILDREN (effect_clip));
270 fail_unless (children->data == effect);
271 fail_unless (children = children->next);
272 fail_unless (children->data == effect1);
273 fail_unless (children = children->next);
274 fail_unless (children->data == core_effect);
275 fail_unless (children = children->next);
276 fail_unless (children->data == core_effect1);
277 fail_unless (children->next == NULL);
278
279 /* but only the additional effects are part of the top effects */
280 top_effects = ges_clip_get_top_effects (GES_CLIP (effect_clip));
281 fail_unless (tmp = top_effects);
282 fail_unless (tmp->data == effect);
283 fail_unless (tmp = tmp->next);
284 fail_unless (tmp->data == effect1);
285 fail_unless (tmp->next == NULL);
286
287 g_list_free_full (top_effects, gst_object_unref);
288
289 gst_object_unref (timeline);
290
291 ges_deinit ();
292 }
293
294 GST_END_TEST;
295
296 GST_START_TEST (test_priorities_clip)
297 {
298 GList *top_effects, *tmp;
299 GESTimeline *timeline;
300 GESLayer *layer;
301 GESClip *effect_clip;
302 GESTrack *track_audio, *track_video, *track;
303 GESBaseEffect *effects[6], *audio_effect = NULL, *video_effect = NULL;
304 gint prev_index, i, num_effects = G_N_ELEMENTS (effects);
305 guint32 base_prio = MIN_NLE_PRIO + TRANSITIONS_HEIGHT;
306
307 ges_init ();
308
309 timeline = ges_timeline_new ();
310 layer = ges_layer_new ();
311 track_audio = GES_TRACK (ges_audio_track_new ());
312 track_video = GES_TRACK (ges_video_track_new ());
313
314 ges_timeline_add_track (timeline, track_audio);
315 ges_timeline_add_track (timeline, track_video);
316 ges_timeline_add_layer (timeline, layer);
317
318 GST_DEBUG ("Create effect");
319 effect_clip = GES_CLIP (ges_effect_clip_new ("videobalance", "audioecho"));
320
321 g_object_set (effect_clip, "duration", 25 * GST_SECOND, NULL);
322
323 ges_layer_add_clip ((layer), (GESClip *) effect_clip);
324 for (tmp = GES_CONTAINER_CHILDREN (effect_clip); tmp; tmp = tmp->next) {
325 if (ges_track_element_get_track_type (GES_TRACK_ELEMENT (tmp->data)) ==
326 GES_TRACK_TYPE_AUDIO)
327 audio_effect = tmp->data;
328 else if (ges_track_element_get_track_type (GES_TRACK_ELEMENT (tmp->data)) ==
329 GES_TRACK_TYPE_VIDEO)
330 video_effect = tmp->data;
331 else
332 g_assert_true (0);
333 }
334 fail_unless (GES_IS_EFFECT (audio_effect));
335 fail_unless (GES_IS_EFFECT (video_effect));
336 fail_unless (ges_track_element_get_track (GES_TRACK_ELEMENT (audio_effect)) ==
337 track_audio);
338 fail_unless (ges_track_element_get_track (GES_TRACK_ELEMENT (video_effect)) ==
339 track_video);
340
341 /* both the core effects have the same priority */
342 assert_equals_int (_PRIORITY (audio_effect), base_prio);
343 assert_equals_int (_PRIORITY (video_effect), base_prio);
344 assert_equals_int (GES_CONTAINER_HEIGHT (effect_clip), 1);
345
346 /* can not change their priority using the top effect methods since
347 * they are not top effects */
348 fail_unless (ges_clip_set_top_effect_index (effect_clip, audio_effect, 1)
349 == FALSE);
350 fail_unless (ges_clip_set_top_effect_index (effect_clip, video_effect, 0)
351 == FALSE);
352
353 /* adding non-core effects */
354 GST_DEBUG ("Adding effects to the effect clip ");
355 for (i = 0; i < num_effects; i++) {
356 if (i % 2)
357 effects[i] = GES_BASE_EFFECT (ges_effect_new ("agingtv"));
358 else
359 effects[i] = GES_BASE_EFFECT (ges_effect_new ("audiopanorama"));
360 fail_unless (ges_container_add (GES_CONTAINER (effect_clip),
361 GES_TIMELINE_ELEMENT (effects[i])));
362 assert_equals_int (GES_CONTAINER_HEIGHT (effect_clip), 2 + i);
363 track = ges_track_element_get_track (GES_TRACK_ELEMENT (effects[i]));
364 if (i % 2)
365 fail_unless (track == track_video);
366 else
367 fail_unless (track == track_audio);
368 }
369
370 /* change top effect index */
371 for (i = 0; i < num_effects; i++) {
372 assert_equals_int (ges_clip_get_top_effect_index (effect_clip, effects[i]),
373 i);
374 assert_equals_int (_PRIORITY (effects[i]), i + base_prio);
375 }
376
377 assert_equals_int (_PRIORITY (video_effect), num_effects + base_prio);
378 assert_equals_int (_PRIORITY (audio_effect), num_effects + base_prio);
379 assert_equals_int (_PRIORITY (effect_clip), 1);
380 assert_equals_int (GES_CONTAINER_HEIGHT (effect_clip), num_effects + 1);
381
382 /* moving 4th effect to index 1 should only change the priority of
383 * effects 1, 2, 3, and 4 because these lie between the new index (1)
384 * and the old index (4). */
385 fail_unless (ges_clip_set_top_effect_index (effect_clip, effects[4], 1));
386
387 assert_equals_int (_PRIORITY (effects[0]), 0 + base_prio);
388 assert_equals_int (_PRIORITY (effects[1]), 2 + base_prio);
389 assert_equals_int (_PRIORITY (effects[2]), 3 + base_prio);
390 assert_equals_int (_PRIORITY (effects[3]), 4 + base_prio);
391 assert_equals_int (_PRIORITY (effects[4]), 1 + base_prio);
392 assert_equals_int (_PRIORITY (effects[5]), 5 + base_prio);
393
394 /* everything else stays the same */
395 assert_equals_int (_PRIORITY (video_effect), num_effects + base_prio);
396 assert_equals_int (_PRIORITY (audio_effect), num_effects + base_prio);
397 assert_equals_int (_PRIORITY (effect_clip), 1);
398 assert_equals_int (GES_CONTAINER_HEIGHT (effect_clip), num_effects + 1);
399
400 /* move back */
401 fail_unless (ges_clip_set_top_effect_index (effect_clip, effects[4], 4));
402
403 for (i = 0; i < num_effects; i++) {
404 assert_equals_int (ges_clip_get_top_effect_index (effect_clip, effects[i]),
405 i);
406 assert_equals_int (_PRIORITY (effects[i]), i + base_prio);
407 }
408
409 assert_equals_int (_PRIORITY (video_effect), num_effects + base_prio);
410 assert_equals_int (_PRIORITY (audio_effect), num_effects + base_prio);
411 assert_equals_int (_PRIORITY (effect_clip), 1);
412 assert_equals_int (GES_CONTAINER_HEIGHT (effect_clip), num_effects + 1);
413
414 /* moving 2nd effect to index 4 should only change the priority of
415 * effects 2, 3 and 4 because these lie between the new index (4) and
416 * the old index (2). */
417
418 fail_unless (ges_clip_set_top_effect_index (effect_clip, effects[2], 4));
419
420 assert_equals_int (_PRIORITY (effects[0]), 0 + base_prio);
421 assert_equals_int (_PRIORITY (effects[1]), 1 + base_prio);
422 assert_equals_int (_PRIORITY (effects[2]), 4 + base_prio);
423 assert_equals_int (_PRIORITY (effects[3]), 2 + base_prio);
424 assert_equals_int (_PRIORITY (effects[4]), 3 + base_prio);
425 assert_equals_int (_PRIORITY (effects[5]), 5 + base_prio);
426
427 /* everything else stays the same */
428 assert_equals_int (_PRIORITY (video_effect), num_effects + base_prio);
429 assert_equals_int (_PRIORITY (audio_effect), num_effects + base_prio);
430 assert_equals_int (_PRIORITY (effect_clip), 1);
431 assert_equals_int (GES_CONTAINER_HEIGHT (effect_clip), num_effects + 1);
432
433 /* move 4th effect to index 0 should only change the priority of
434 * effects 0, 1, 3 and 4 because these lie between the new index (0) and
435 * the old index (3) */
436
437 fail_unless (ges_clip_set_top_effect_index (effect_clip, effects[4], 0));
438
439 assert_equals_int (_PRIORITY (effects[0]), 1 + base_prio);
440 assert_equals_int (_PRIORITY (effects[1]), 2 + base_prio);
441 assert_equals_int (_PRIORITY (effects[2]), 4 + base_prio);
442 assert_equals_int (_PRIORITY (effects[3]), 3 + base_prio);
443 assert_equals_int (_PRIORITY (effects[4]), 0 + base_prio);
444 assert_equals_int (_PRIORITY (effects[5]), 5 + base_prio);
445
446 /* everything else stays the same */
447 assert_equals_int (_PRIORITY (video_effect), num_effects + base_prio);
448 assert_equals_int (_PRIORITY (audio_effect), num_effects + base_prio);
449 assert_equals_int (_PRIORITY (effect_clip), 1);
450 assert_equals_int (GES_CONTAINER_HEIGHT (effect_clip), num_effects + 1);
451
452 /* make sure top effects are ordered by index */
453 top_effects = ges_clip_get_top_effects (effect_clip);
454 prev_index = -1;
455 for (tmp = top_effects; tmp; tmp = tmp->next) {
456 gint index = ges_clip_get_top_effect_index (effect_clip,
457 GES_BASE_EFFECT (tmp->data));
458 fail_unless (index >= 0);
459 fail_unless (index > prev_index);
460 fail_unless (GES_IS_EFFECT (tmp->data));
461 prev_index = index;
462 }
463 g_list_free_full (top_effects, gst_object_unref);
464
465 gst_object_unref (timeline);
466
467 ges_deinit ();
468 }
469
470 GST_END_TEST;
471
472 GST_START_TEST (test_effect_set_properties)
473 {
474 GESTimeline *timeline;
475 GESLayer *layer;
476 GESTrack *track_video;
477 GESEffectClip *effect_clip;
478 GESTimelineElement *effect;
479 guint scratch_line, n_props, i;
480 gboolean color_aging;
481 GParamSpec **pspecs, *spec;
482 GValue val = { 0 };
483 GValue nval = { 0 };
484
485 ges_init ();
486
487 timeline = ges_timeline_new ();
488 layer = ges_layer_new ();
489 track_video = GES_TRACK (ges_video_track_new ());
490
491 ges_timeline_add_track (timeline, track_video);
492 ges_timeline_add_layer (timeline, layer);
493
494 GST_DEBUG ("Create effect");
495 effect_clip = ges_effect_clip_new ("agingtv", NULL);
496
497 g_object_set (effect_clip, "duration", 25 * GST_SECOND, NULL);
498
499 ges_layer_add_clip (layer, (GESClip *) effect_clip);
500
501 effect = GES_TIMELINE_ELEMENT (ges_effect_new ("agingtv"));
502 fail_unless (ges_container_add (GES_CONTAINER (effect_clip),
503 GES_TIMELINE_ELEMENT (effect)));
504 fail_unless (ges_track_element_get_track (GES_TRACK_ELEMENT (effect)) ==
505 track_video);
506
507 ges_timeline_element_set_child_properties (effect,
508 "GstAgingTV::scratch-lines", 17, "color-aging", FALSE, NULL);
509 ges_timeline_element_get_child_properties (effect,
510 "GstAgingTV::scratch-lines", &scratch_line,
511 "color-aging", &color_aging, NULL);
512 assert_equals_int (scratch_line, 17);
513 assert_equals_int (color_aging, FALSE);
514
515 pspecs = ges_timeline_element_list_children_properties (effect, &n_props);
516 assert_equals_int (n_props, 7);
517
518 spec = pspecs[0];
519 i = 1;
520 while (g_strcmp0 (spec->name, "scratch-lines")) {
521 spec = pspecs[i++];
522 }
523
524 g_value_init (&val, G_TYPE_UINT);
525 g_value_init (&nval, G_TYPE_UINT);
526 g_value_set_uint (&val, 10);
527
528 ges_timeline_element_set_child_property_by_pspec (effect, spec, &val);
529 ges_timeline_element_get_child_property_by_pspec (effect, spec, &nval);
530 assert_equals_int (g_value_get_uint (&nval), 10);
531
532 for (i = 0; i < n_props; i++) {
533 g_param_spec_unref (pspecs[i]);
534 }
535 g_free (pspecs);
536
537 ges_layer_remove_clip (layer, (GESClip *) effect_clip);
538
539 gst_object_unref (timeline);
540
541 ges_deinit ();
542 }
543
544 GST_END_TEST;
545
546 static void
547 effect_added_cb (GESClip * clip, GESBaseEffect * trop, gboolean * effect_added)
548 {
549 GST_DEBUG ("Effect added");
550 fail_unless (GES_IS_CLIP (clip));
551 fail_unless (GES_IS_EFFECT (trop));
552 *effect_added = TRUE;
553 }
554
555 void
556 deep_prop_changed_cb (GESTrackElement * track_element, GstElement * element,
557 GParamSpec * spec)
558 {
559 GST_DEBUG ("%s property changed", g_param_spec_get_name (spec));
560 fail_unless (GES_IS_TRACK_ELEMENT (track_element));
561 fail_unless (GST_IS_ELEMENT (element));
562 }
563
564 GST_START_TEST (test_clip_signals)
565 {
566 GESTimeline *timeline;
567 GESLayer *layer;
568 GESTrack *track_video;
569 GESEffectClip *effect_clip;
570 GESTimelineElement *effect;
571 GValue val = { 0, };
572 gboolean effect_added = FALSE;
573
574 ges_init ();
575
576 timeline = ges_timeline_new ();
577 layer = ges_layer_new ();
578 track_video = GES_TRACK (ges_video_track_new ());
579
580 ges_timeline_add_track (timeline, track_video);
581 ges_timeline_add_layer (timeline, layer);
582
583 GST_DEBUG ("Create effect");
584 effect_clip = ges_effect_clip_new ("agingtv", NULL);
585 g_signal_connect (effect_clip, "child-added", (GCallback) effect_added_cb,
586 &effect_added);
587
588 g_object_set (effect_clip, "duration", 25 * GST_SECOND, NULL);
589
590 ges_layer_add_clip (layer, (GESClip *) effect_clip);
591
592 effect = GES_TIMELINE_ELEMENT (ges_effect_new ("agingtv"));
593 fail_unless (ges_container_add (GES_CONTAINER (effect_clip), effect));
594 fail_unless (effect_added);
595 g_signal_handlers_disconnect_by_func (effect_clip, effect_added_cb,
596 &effect_added);
597 fail_unless (ges_track_element_get_track (GES_TRACK_ELEMENT (effect)) ==
598 track_video);
599 g_signal_connect (effect, "deep-notify", (GCallback) deep_prop_changed_cb,
600 effect);
601
602 ges_timeline_element_set_child_properties (effect,
603 "GstAgingTV::scratch-lines", 17, NULL);
604
605 g_value_init (&val, G_TYPE_UINT);
606 ges_timeline_element_get_child_property (effect,
607 "GstAgingTV::scratch-lines", &val);
608 fail_unless (G_VALUE_HOLDS_UINT (&val));
609 g_value_unset (&val);
610
611 ges_layer_remove_clip (layer, (GESClip *) effect_clip);
612
613 gst_object_unref (timeline);
614
615 ges_deinit ();
616 }
617
618 GST_END_TEST;
619
620 GST_START_TEST (test_split_clip_effect_priorities)
621 {
622 GESLayer *layer;
623 GESTimeline *timeline;
624 GESTrack *track_video;
625 GESClip *clip, *nclip;
626 GESEffect *effect;
627 GESTrackElement *source, *nsource, *neffect;
628
629 ges_init ();
630
631 timeline = ges_timeline_new ();
632 layer = ges_timeline_append_layer (timeline);
633 track_video = GES_TRACK (ges_video_track_new ());
634
635 g_object_set (timeline, "auto-transition", TRUE, NULL);
636 ges_timeline_add_track (timeline, track_video);
637 ges_timeline_add_layer (timeline, layer);
638
639 GST_DEBUG ("Create effect");
640 effect = ges_effect_new ("agingtv");
641 clip = GES_CLIP (ges_test_clip_new ());
642 g_object_set (clip, "duration", GST_SECOND * 2, NULL);
643
644 fail_unless (ges_container_add (GES_CONTAINER (clip),
645 GES_TIMELINE_ELEMENT (effect)));
646 ges_layer_add_clip (layer, clip);
647
648 source = ges_clip_find_track_element (clip, NULL, GES_TYPE_VIDEO_SOURCE);
649 assert_equals_uint64 (GES_TIMELINE_ELEMENT_PRIORITY (effect), 3);
650 assert_equals_uint64 (GES_TIMELINE_ELEMENT_PRIORITY (source), 4);
651
652 nclip = ges_clip_split (clip, GST_SECOND);
653 fail_unless (nclip);
654 neffect = ges_clip_find_track_element (nclip, NULL, GES_TYPE_EFFECT);
655 nsource = ges_clip_find_track_element (nclip, NULL, GES_TYPE_VIDEO_SOURCE);
656
657 assert_equals_uint64 (GES_TIMELINE_ELEMENT_PRIORITY (effect), 3);
658 assert_equals_uint64 (GES_TIMELINE_ELEMENT_PRIORITY (source), 4);
659 assert_equals_uint64 (GES_TIMELINE_ELEMENT_PRIORITY (neffect), 5);
660 assert_equals_uint64 (GES_TIMELINE_ELEMENT_PRIORITY (nsource), 6);
661
662 /* Create a transition ... */
663 ges_timeline_element_set_start (GES_TIMELINE_ELEMENT (clip), GST_SECOND / 2);
664
665 assert_equals_uint64 (GES_TIMELINE_ELEMENT_PRIORITY (effect), 3);
666 assert_equals_uint64 (GES_TIMELINE_ELEMENT_PRIORITY (source), 4);
667 assert_equals_uint64 (GES_TIMELINE_ELEMENT_PRIORITY (neffect), 5);
668 assert_equals_uint64 (GES_TIMELINE_ELEMENT_PRIORITY (nsource), 6);
669
670 gst_object_unref (timeline);
671
672 ges_deinit ();
673 }
674
675 GST_END_TEST;
676
677 #define _NO_ERROR -1
678 #define _set_rate(videorate, rate, error_code) \
679 { \
680 g_value_set_double (&val, rate); \
681 if (error_code != _NO_ERROR) { \
682 fail_if (ges_timeline_element_set_child_property_full ( \
683 GES_TIMELINE_ELEMENT (videorate), "rate", &val, &error)); \
684 assert_GESError (error, error_code); \
685 } else { \
686 fail_unless (ges_timeline_element_set_child_property_full ( \
687 GES_TIMELINE_ELEMENT (videorate), "rate", &val, &error)); \
688 fail_if (error); \
689 } \
690 }
691
692 #define _add_effect(clip, effect, _index, error_code) \
693 { \
694 gint index = _index; \
695 if (error_code != _NO_ERROR) { \
696 fail_if (ges_clip_add_top_effect (clip, effect, index, &error)); \
697 assert_GESError (error, error_code); \
698 } else { \
699 GList *effects; \
700 gboolean res = ges_clip_add_top_effect (clip, effect, index, &error); \
701 fail_unless (res, "Adding effect " #effect " failed: %s", \
702 error ? error->message : "No error produced"); \
703 fail_if (error); \
704 effects = ges_clip_get_top_effects (clip); \
705 fail_unless (g_list_find (effects, effect)); \
706 if (index < 0 || index >= g_list_length (effects)) \
707 index = g_list_length (effects) - 1; \
708 assert_equals_int (ges_clip_get_top_effect_index (clip, effect), index); \
709 fail_unless (g_list_nth_data (effects, index) == effect); \
710 g_list_free_full (effects, gst_object_unref); \
711 } \
712 }
713
714 #define _remove_effect(clip, effect, error_code) \
715 { \
716 if (error_code != _NO_ERROR) { \
717 fail_if (ges_clip_remove_top_effect (clip, effect, &error)); \
718 assert_GESError (error, error_code); \
719 } else { \
720 GList *effects; \
721 gboolean res = ges_clip_remove_top_effect (clip, effect, &error); \
722 fail_unless (res, "Removing effect " #effect " failed: %s", \
723 error ? error->message : "No error produced"); \
724 fail_if (error); \
725 effects = ges_clip_get_top_effects (clip); \
726 fail_if (g_list_find (effects, effect)); \
727 g_list_free_full (effects, gst_object_unref); \
728 } \
729 }
730
731 #define _move_effect(clip, effect, index, error_code) \
732 { \
733 if (error_code != _NO_ERROR) { \
734 fail_if ( \
735 ges_clip_set_top_effect_index_full (clip, effect, index, &error)); \
736 assert_GESError (error, error_code); \
737 } else { \
738 GList *effects; \
739 gboolean res = \
740 ges_clip_set_top_effect_index_full (clip, effect, index, &error); \
741 fail_unless (res, "Moving effect " #effect " failed: %s", \
742 error ? error->message : "No error produced"); \
743 fail_if (error); \
744 effects = ges_clip_get_top_effects (clip); \
745 fail_unless (g_list_find (effects, effect)); \
746 assert_equals_int (ges_clip_get_top_effect_index (clip, effect), index); \
747 fail_unless (g_list_nth_data (effects, index) == effect); \
748 g_list_free_full (effects, gst_object_unref); \
749 } \
750 }
751
752 GST_START_TEST (test_move_time_effect)
753 {
754 GESTimeline *timeline;
755 GESTrack *track;
756 GESLayer *layer;
757 GESAsset *asset;
758 GESClip *clip;
759 GESBaseEffect *rate0, *rate1, *overlay;
760 GError *error = NULL;
761 GValue val = G_VALUE_INIT;
762
763 ges_init ();
764
765 g_value_init (&val, G_TYPE_DOUBLE);
766
767
768 timeline = ges_timeline_new ();
769 track = GES_TRACK (ges_video_track_new ());
770 fail_unless (ges_timeline_add_track (timeline, track));
771
772 layer = ges_timeline_append_layer (timeline);
773
774 /* add a dummy clip for overlap */
775 asset = ges_asset_request (GES_TYPE_TEST_CLIP, "max-duration=16", &error);
776 fail_unless (asset);
777 fail_if (error);
778
779 fail_unless (ges_layer_add_asset_full (layer, asset, 0, 0, 16,
780 GES_TRACK_TYPE_UNKNOWN, &error));
781 fail_if (error);
782
783 clip = GES_CLIP (ges_asset_extract (asset, &error));
784 fail_unless (clip);
785 fail_if (error);
786 assert_set_start (clip, 8);
787 assert_set_duration (clip, 16);
788
789 rate0 = GES_BASE_EFFECT (ges_effect_new ("videorate"));
790 rate1 = GES_BASE_EFFECT (ges_effect_new ("videorate"));
791 overlay = GES_BASE_EFFECT (ges_effect_new ("textoverlay"));
792
793 ges_track_element_set_has_internal_source (GES_TRACK_ELEMENT (overlay), TRUE);
794 /* only has 8ns of content */
795 assert_set_inpoint (overlay, 13);
796 assert_set_max_duration (overlay, 21);
797
798 _set_rate (rate0, 2.0, _NO_ERROR);
799 _set_rate (rate1, 0.5, _NO_ERROR);
800
801 /* keep alive */
802 gst_object_ref (clip);
803 gst_object_ref (rate0);
804 gst_object_ref (rate1);
805 gst_object_ref (overlay);
806
807 /* cannot add to layer with rate effect because it would cause a full
808 * overlap */
809 _add_effect (clip, rate0, 0, _NO_ERROR);
810 fail_if (ges_layer_add_clip_full (layer, clip, &error));
811 assert_GESError (error, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
812 _remove_effect (clip, rate0, _NO_ERROR);
813
814 /* same with overlay */
815 _add_effect (clip, overlay, 0, _NO_ERROR);
816 fail_if (ges_layer_add_clip_full (layer, clip, &error));
817 assert_GESError (error, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
818 _remove_effect (clip, overlay, _NO_ERROR);
819
820 CHECK_OBJECT_PROPS (clip, 8, 0, 16);
821
822 fail_unless (ges_layer_add_clip_full (layer, clip, &error));
823 fail_if (error);
824
825 CHECK_OBJECT_PROPS_MAX (clip, 8, 0, 16, 16);
826
827 /* can't add rate0 or overlay in the same way */
828 _add_effect (clip, rate0, 0, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
829 _add_effect (clip, overlay, 0, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
830
831 /* rate1 extends the duration-limit instead */
832 _add_effect (clip, rate1, 0, _NO_ERROR);
833
834 /* can't add overlay next to the timeline */
835 _add_effect (clip, overlay, 0, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
836 /* but next to source is ok */
837 _add_effect (clip, overlay, 1, _NO_ERROR);
838
839 /* can't add rate0 after overlay */
840 _add_effect (clip, rate0, 1, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
841 /* but before is ok */
842 _add_effect (clip, rate0, -1, _NO_ERROR);
843
844 /* can't move rate0 to end */
845 _move_effect (clip, rate0, 0, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
846 /* can't move overlay to start or end */
847 _move_effect (clip, overlay, 0, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
848 _move_effect (clip, overlay, 2, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
849
850 /* can now move: swap places with rate1 */
851 _set_rate (rate0, 0.5, _NO_ERROR);
852 _move_effect (clip, rate0, 0, _NO_ERROR);
853 _move_effect (clip, rate1, 2, _NO_ERROR);
854 _set_rate (rate1, 2.0, _NO_ERROR);
855
856 /* cannot speed up either rate too much */
857 _set_rate (rate0, 1.0, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
858 _set_rate (rate1, 4.0, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
859
860 /* cannot remove rate0 which is slowing down */
861 _remove_effect (clip, rate0, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
862
863 /* removing the speed-up is fine */
864 _remove_effect (clip, rate1, _NO_ERROR);
865
866 /* removing the overlay is fine */
867 _remove_effect (clip, overlay, _NO_ERROR);
868
869 CHECK_OBJECT_PROPS_MAX (clip, 8, 0, 16, 16);
870 assert_set_max_duration (clip, 8);
871 CHECK_OBJECT_PROPS_MAX (clip, 8, 0, 16, 8);
872 /* still can't remove the slow down since it is the only thing stopping
873 * a full overlap */
874 _remove_effect (clip, rate0, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
875
876 gst_object_unref (clip);
877 /* shouldn't have any problems when removing from the layer */
878 fail_unless (ges_layer_remove_clip (layer, clip));
879
880 g_value_reset (&val);
881 gst_object_unref (rate0);
882 gst_object_unref (rate1);
883 gst_object_unref (overlay);
884 gst_object_unref (asset);
885 gst_object_unref (timeline);
886
887 ges_deinit ();
888 }
889
890 GST_END_TEST;
891
892 static Suite *
893 ges_suite (void)
894 {
895 Suite *s = suite_create ("ges");
896 TCase *tc_chain = tcase_create ("effect");
897
898 suite_add_tcase (s, tc_chain);
899
900 tcase_add_test (tc_chain, test_effect_basic);
901 tcase_add_test (tc_chain, test_add_effect_to_clip);
902 tcase_add_test (tc_chain, test_get_effects_from_tl);
903 tcase_add_test (tc_chain, test_effect_clip);
904 tcase_add_test (tc_chain, test_priorities_clip);
905 tcase_add_test (tc_chain, test_effect_set_properties);
906 tcase_add_test (tc_chain, test_clip_signals);
907 tcase_add_test (tc_chain, test_split_clip_effect_priorities);
908 tcase_add_test (tc_chain, test_move_time_effect);
909
910 return s;
911 }
912
913 GST_CHECK_MAIN (ges);