Debian Codegraph @

tests/check/ges/clip.c

raw
1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <[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-structured-interface.h"
22 #include <ges/ges.h>
23 #include <gst/check/gstcheck.h>
24
25 #define _assert_add(clip, child) \
26 fail_unless (ges_container_add (GES_CONTAINER (clip), \
27 GES_TIMELINE_ELEMENT (child)))
28
29 #define _assert_remove(clip, child) \
30 fail_unless (ges_container_remove (GES_CONTAINER (clip), \
31 GES_TIMELINE_ELEMENT (child)))
32
33 GST_START_TEST (test_object_properties)
34 {
35 GESClip *clip;
36 GESTrack *track;
37 GESTimeline *timeline;
38 GESLayer *layer;
39 GESTrackElement *trackelement;
40
41 ges_init ();
42
43 track = GES_TRACK (ges_video_track_new ());
44 fail_unless (track != NULL);
45
46 layer = ges_layer_new ();
47 fail_unless (layer != NULL);
48 timeline = ges_timeline_new ();
49 fail_unless (timeline != NULL);
50 fail_unless (ges_timeline_add_layer (timeline, layer));
51 fail_unless (ges_timeline_add_track (timeline, track));
52
53 clip = (GESClip *) ges_test_clip_new ();
54 fail_unless (clip != NULL);
55
56 /* Set some properties */
57 g_object_set (clip, "start", (guint64) 42, "duration", (guint64) 51,
58 "in-point", (guint64) 12, NULL);
59 assert_equals_uint64 (_START (clip), 42);
60 assert_equals_uint64 (_DURATION (clip), 51);
61 assert_equals_uint64 (_INPOINT (clip), 12);
62
63 ges_layer_add_clip (layer, GES_CLIP (clip));
64 ges_timeline_commit (timeline);
65 assert_num_children (clip, 1);
66 trackelement = GES_CONTAINER_CHILDREN (clip)->data;
67 fail_unless (trackelement != NULL);
68 fail_unless (GES_TIMELINE_ELEMENT_PARENT (trackelement) ==
69 GES_TIMELINE_ELEMENT (clip));
70 fail_unless (ges_track_element_get_track (trackelement) == track);
71
72 /* Check that trackelement has the same properties */
73 assert_equals_uint64 (_START (trackelement), 42);
74 assert_equals_uint64 (_DURATION (trackelement), 51);
75 assert_equals_uint64 (_INPOINT (trackelement), 12);
76
77 /* And let's also check that it propagated correctly to GNonLin */
78 nle_object_check (ges_track_element_get_nleobject (trackelement), 42, 51, 12,
79 51, MIN_NLE_PRIO + TRANSITIONS_HEIGHT, TRUE);
80
81 /* Change more properties, see if they propagate */
82 g_object_set (clip, "start", (guint64) 420, "duration", (guint64) 510,
83 "in-point", (guint64) 120, NULL);
84 assert_equals_uint64 (_START (clip), 420);
85 assert_equals_uint64 (_DURATION (clip), 510);
86 assert_equals_uint64 (_INPOINT (clip), 120);
87 assert_equals_uint64 (_START (trackelement), 420);
88 assert_equals_uint64 (_DURATION (trackelement), 510);
89 assert_equals_uint64 (_INPOINT (trackelement), 120);
90
91 /* And let's also check that it propagated correctly to GNonLin */
92 ges_timeline_commit (timeline);
93 nle_object_check (ges_track_element_get_nleobject (trackelement), 420, 510,
94 120, 510, MIN_NLE_PRIO + TRANSITIONS_HEIGHT, TRUE);
95
96
97 /* This time, we move the trackelement to see if the changes move
98 * along to the parent and the gnonlin clip */
99 g_object_set (trackelement, "start", (guint64) 400, NULL);
100 ges_timeline_commit (timeline);
101 assert_equals_uint64 (_START (clip), 400);
102 assert_equals_uint64 (_START (trackelement), 400);
103 nle_object_check (ges_track_element_get_nleobject (trackelement), 400, 510,
104 120, 510, MIN_NLE_PRIO + TRANSITIONS_HEIGHT, TRUE);
105
106 _assert_remove (clip, trackelement);
107
108 gst_object_unref (timeline);
109
110 ges_deinit ();
111 }
112
113 GST_END_TEST;
114
115 GST_START_TEST (test_split_direct_bindings)
116 {
117 GstTimedValue *values;
118 gsize n_values;
119 GstControlSource *source;
120 GESTimeline *timeline;
121 GESClip *clip, *splitclip;
122 GstControlBinding *binding = NULL, *splitbinding;
123 GstTimedValueControlSource *splitsource;
124 GESLayer *layer;
125 GESAsset *asset;
126 GValue *tmpvalue;
127
128 GESTrackElement *element;
129
130 ges_init ();
131
132 fail_unless ((timeline = ges_timeline_new ()));
133 fail_unless ((layer = ges_layer_new ()));
134 fail_unless (ges_timeline_add_track (timeline,
135 GES_TRACK (ges_video_track_new ())));
136 fail_unless (ges_timeline_add_layer (timeline, layer));
137
138 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
139 clip = ges_layer_add_asset (layer, asset, 0, 10 * GST_SECOND, 10 * GST_SECOND,
140 GES_TRACK_TYPE_UNKNOWN);
141 g_object_unref (asset);
142
143 CHECK_OBJECT_PROPS (clip, 0 * GST_SECOND, 10 * GST_SECOND, 10 * GST_SECOND);
144 assert_num_children (clip, 1);
145 check_layer (clip, 0);
146
147 source = gst_interpolation_control_source_new ();
148 g_object_set (source, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
149 element = GES_CONTAINER_CHILDREN (clip)->data;
150 fail_unless (ges_track_element_set_control_source (element,
151 source, "alpha", "direct"));
152
153 gst_timed_value_control_source_set (GST_TIMED_VALUE_CONTROL_SOURCE (source),
154 10 * GST_SECOND, 0.0);
155 gst_timed_value_control_source_set (GST_TIMED_VALUE_CONTROL_SOURCE (source),
156 20 * GST_SECOND, 1.0);
157
158 binding = ges_track_element_get_control_binding (element, "alpha");
159 tmpvalue = gst_control_binding_get_value (binding, 10 * GST_SECOND);
160 assert_equals_int (g_value_get_double (tmpvalue), 0.0);
161 g_value_unset (tmpvalue);
162 g_free (tmpvalue);
163
164 tmpvalue = gst_control_binding_get_value (binding, 20 * GST_SECOND);
165 assert_equals_int (g_value_get_double (tmpvalue), 1.0);
166 g_value_unset (tmpvalue);
167 g_free (tmpvalue);
168
169 splitclip = ges_clip_split (clip, 5 * GST_SECOND);
170 CHECK_OBJECT_PROPS (splitclip, 5 * GST_SECOND, 15 * GST_SECOND,
171 5 * GST_SECOND);
172 check_layer (splitclip, 0);
173
174 splitbinding =
175 ges_track_element_get_control_binding (GES_CONTAINER_CHILDREN
176 (splitclip)->data, "alpha");
177 g_object_get (splitbinding, "control_source", &splitsource, NULL);
178
179 GST_ERROR_OBJECT (splitsource, "------------- HERE I AM --------");
180 values =
181 gst_timed_value_control_source_list_control_points
182 (GST_TIMED_VALUE_CONTROL_SOURCE (splitsource), &n_values);
183 assert_equals_int (n_values, 2);
184 assert_equals_uint64 (values[0].timestamp, 15 * GST_SECOND);
185 assert_equals_float (values[0].value, 0.5);
186
187 assert_equals_uint64 (values[1].timestamp, 20 * GST_SECOND);
188 assert_equals_float (values[1].value, 1.0);
189 g_free (values);
190
191 values =
192 gst_timed_value_control_source_list_control_points
193 (GST_TIMED_VALUE_CONTROL_SOURCE (source), &n_values);
194 assert_equals_int (n_values, 2);
195 assert_equals_uint64 (values[0].timestamp, 10 * GST_SECOND);
196 assert_equals_float (values[0].value, 0.0);
197
198 assert_equals_uint64 (values[1].timestamp, 15 * GST_SECOND);
199 assert_equals_float (values[1].value, 0.50);
200 g_free (values);
201
202 CHECK_OBJECT_PROPS (clip, 0 * GST_SECOND, 10 * GST_SECOND, 5 * GST_SECOND);
203 check_layer (clip, 0);
204
205 gst_object_unref (timeline);
206 gst_object_unref (source);
207 gst_object_unref (splitsource);
208
209 ges_deinit ();
210 }
211
212 GST_END_TEST;
213
214 GST_START_TEST (test_split_direct_absolute_bindings)
215 {
216 GstTimedValue *values;
217 gsize n_values;
218 GstControlSource *source;
219 GESTimeline *timeline;
220 GESClip *clip, *splitclip;
221 GstControlBinding *binding = NULL, *splitbinding;
222 GstTimedValueControlSource *splitsource;
223 GESLayer *layer;
224 GESAsset *asset;
225 GValue *tmpvalue;
226
227 GESTrackElement *element;
228
229 ges_init ();
230
231 fail_unless ((timeline = ges_timeline_new ()));
232 fail_unless ((layer = ges_layer_new ()));
233 fail_unless (ges_timeline_add_track (timeline,
234 GES_TRACK (ges_video_track_new ())));
235 fail_unless (ges_timeline_add_layer (timeline, layer));
236
237 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
238 clip = ges_layer_add_asset (layer, asset, 0, 10 * GST_SECOND, 10 * GST_SECOND,
239 GES_TRACK_TYPE_UNKNOWN);
240 g_object_unref (asset);
241
242 CHECK_OBJECT_PROPS (clip, 0 * GST_SECOND, 10 * GST_SECOND, 10 * GST_SECOND);
243 assert_num_children (clip, 1);
244 check_layer (clip, 0);
245
246 source = gst_interpolation_control_source_new ();
247 g_object_set (source, "mode", GST_INTERPOLATION_MODE_LINEAR, NULL);
248 element = GES_CONTAINER_CHILDREN (clip)->data;
249 fail_unless (ges_track_element_set_control_source (element,
250 source, "posx", "direct-absolute"));
251
252 gst_timed_value_control_source_set (GST_TIMED_VALUE_CONTROL_SOURCE (source),
253 10 * GST_SECOND, 0);
254 gst_timed_value_control_source_set (GST_TIMED_VALUE_CONTROL_SOURCE (source),
255 20 * GST_SECOND, 500);
256
257 binding = ges_track_element_get_control_binding (element, "posx");
258 tmpvalue = gst_control_binding_get_value (binding, 10 * GST_SECOND);
259 assert_equals_int (g_value_get_int (tmpvalue), 0);
260 g_value_unset (tmpvalue);
261 g_free (tmpvalue);
262
263 tmpvalue = gst_control_binding_get_value (binding, 20 * GST_SECOND);
264 assert_equals_int (g_value_get_int (tmpvalue), 500);
265 g_value_unset (tmpvalue);
266 g_free (tmpvalue);
267
268 splitclip = ges_clip_split (clip, 5 * GST_SECOND);
269 CHECK_OBJECT_PROPS (splitclip, 5 * GST_SECOND, 15 * GST_SECOND,
270 5 * GST_SECOND);
271 check_layer (splitclip, 0);
272
273 splitbinding =
274 ges_track_element_get_control_binding (GES_CONTAINER_CHILDREN
275 (splitclip)->data, "posx");
276 g_object_get (splitbinding, "control_source", &splitsource, NULL);
277
278 values =
279 gst_timed_value_control_source_list_control_points
280 (GST_TIMED_VALUE_CONTROL_SOURCE (splitsource), &n_values);
281 assert_equals_int (n_values, 2);
282 assert_equals_uint64 (values[0].timestamp, 15 * GST_SECOND);
283 assert_equals_float (values[0].value, 250.0);
284
285 assert_equals_uint64 (values[1].timestamp, 20 * GST_SECOND);
286 assert_equals_float (values[1].value, 500.0);
287 g_free (values);
288
289 values =
290 gst_timed_value_control_source_list_control_points
291 (GST_TIMED_VALUE_CONTROL_SOURCE (source), &n_values);
292 assert_equals_int (n_values, 2);
293 assert_equals_uint64 (values[0].timestamp, 10 * GST_SECOND);
294 assert_equals_float (values[0].value, 0.0);
295
296 assert_equals_uint64 (values[1].timestamp, 15 * GST_SECOND);
297 assert_equals_float (values[1].value, 250.0);
298 g_free (values);
299
300 CHECK_OBJECT_PROPS (clip, 0 * GST_SECOND, 10 * GST_SECOND, 5 * GST_SECOND);
301 check_layer (clip, 0);
302
303 gst_object_unref (timeline);
304 gst_object_unref (source);
305 gst_object_unref (splitsource);
306
307 ges_deinit ();
308 }
309
310 GST_END_TEST;
311
312 static GESTimelineElement *
313 _find_auto_transition (GESTrack * track, GESClip * from_clip, GESClip * to_clip)
314 {
315 GstClockTime start, end;
316 GList *tmp, *track_els;
317 GESTimelineElement *ret = NULL;
318 GESLayer *layer0, *layer1;
319
320 layer0 = ges_clip_get_layer (from_clip);
321 layer1 = ges_clip_get_layer (to_clip);
322
323 fail_unless (layer0 == layer1, "%" GES_FORMAT " and %" GES_FORMAT " do not "
324 "share the same layer", GES_ARGS (from_clip), GES_ARGS (to_clip));
325 gst_object_unref (layer1);
326
327 start = GES_TIMELINE_ELEMENT_START (to_clip);
328 end = GES_TIMELINE_ELEMENT_START (from_clip)
329 + GES_TIMELINE_ELEMENT_DURATION (from_clip);
330
331 fail_if (end <= start, "%" GES_FORMAT " starts after %" GES_FORMAT " ends",
332 GES_ARGS (to_clip), GES_ARGS (from_clip));
333
334 track_els = ges_track_get_elements (track);
335
336 for (tmp = track_els; tmp; tmp = tmp->next) {
337 GESTimelineElement *el = tmp->data;
338 if (GES_IS_TRANSITION (el) && el->start == start
339 && (el->start + el->duration) == end) {
340 fail_if (ret, "Found two transitions %" GES_FORMAT " and %" GES_FORMAT
341 " between %" GES_FORMAT " and %" GES_FORMAT " in track %"
342 GST_PTR_FORMAT, GES_ARGS (el), GES_ARGS (ret), GES_ARGS (from_clip),
343 GES_ARGS (to_clip), track);
344 ret = el;
345 }
346 }
347 fail_unless (ret, "Found no transitions between %" GES_FORMAT " and %"
348 GES_FORMAT " in track %" GST_PTR_FORMAT, GES_ARGS (from_clip),
349 GES_ARGS (to_clip), track);
350
351 g_list_free_full (track_els, gst_object_unref);
352
353 fail_unless (GES_IS_CLIP (ret->parent), "Transition %" GES_FORMAT
354 " between %" GES_FORMAT " and %" GES_FORMAT " in track %"
355 GST_PTR_FORMAT " has no parent clip", GES_ARGS (ret),
356 GES_ARGS (from_clip), GES_ARGS (to_clip), track);
357
358 layer1 = ges_clip_get_layer (GES_CLIP (ret->parent));
359
360 fail_unless (layer0 == layer1, "Transition %" GES_FORMAT " between %"
361 GES_FORMAT " and %" GES_FORMAT " in track %" GST_PTR_FORMAT
362 " belongs to layer %" GST_PTR_FORMAT " rather than %" GST_PTR_FORMAT,
363 GES_ARGS (ret), GES_ARGS (from_clip), GES_ARGS (to_clip), track,
364 layer1, layer0);
365
366 gst_object_unref (layer0);
367 gst_object_unref (layer1);
368
369 return ret;
370 }
371
372 GST_START_TEST (test_split_with_auto_transitions)
373 {
374 GESTimeline *timeline;
375 GESLayer *layer;
376 GESTrack *tracks[3];
377 GESTimelineElement *found;
378 GESTimelineElement *prev_trans[3];
379 GESTimelineElement *post_trans[3];
380 GESAsset *asset;
381 GESClip *clip, *split, *prev, *post;
382 guint i;
383
384 ges_init ();
385
386 timeline = ges_timeline_new ();
387
388 ges_timeline_set_auto_transition (timeline, TRUE);
389
390 tracks[0] = GES_TRACK (ges_audio_track_new ());
391 tracks[1] = GES_TRACK (ges_audio_track_new ());
392 tracks[2] = GES_TRACK (ges_video_track_new ());
393
394 for (i = 0; i < 3; i++)
395 fail_unless (ges_timeline_add_track (timeline, tracks[i]));
396
397 layer = ges_timeline_append_layer (timeline);
398 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
399
400 prev = ges_layer_add_asset (layer, asset, 0, 0, 10, GES_TRACK_TYPE_UNKNOWN);
401 clip = ges_layer_add_asset (layer, asset, 5, 0, 20, GES_TRACK_TYPE_UNKNOWN);
402 post = ges_layer_add_asset (layer, asset, 20, 0, 10, GES_TRACK_TYPE_UNKNOWN);
403
404 fail_unless (prev);
405 fail_unless (clip);
406 fail_unless (post);
407
408 for (i = 0; i < 3; i++) {
409 prev_trans[i] = _find_auto_transition (tracks[i], prev, clip);
410 post_trans[i] = _find_auto_transition (tracks[i], clip, post);
411 /* 3 sources, 2 auto-transitions */
412 assert_num_in_track (tracks[i], 5);
413
414 }
415
416 /* cannot split within a transition */
417 fail_if (ges_clip_split (clip, 5));
418 fail_if (ges_clip_split (clip, 20));
419
420 /* we should keep the same auto-transitions during a split */
421 split = ges_clip_split (clip, 15);
422 fail_unless (split);
423
424 for (i = 0; i < 3; i++) {
425 found = _find_auto_transition (tracks[i], prev, clip);
426 fail_unless (found == prev_trans[i], "Transition between %" GES_FORMAT
427 " and %" GES_FORMAT " changed", GES_ARGS (prev), GES_ARGS (clip));
428
429 found = _find_auto_transition (tracks[i], split, post);
430 fail_unless (found == post_trans[i], "Transition between %" GES_FORMAT
431 " and %" GES_FORMAT " changed", GES_ARGS (clip), GES_ARGS (post));
432 }
433
434 gst_object_unref (timeline);
435 gst_object_unref (asset);
436
437 ges_deinit ();
438 }
439
440 GST_END_TEST;
441
442 static GPtrArray *
443 _select_none (GESTimeline * timeline, GESClip * clip,
444 GESTrackElement * track_element, guint * called_p)
445 {
446 (*called_p)++;
447 return NULL;
448 }
449
450 static GPtrArray *
451 _select_track (GESTimeline * timeline, GESClip * clip,
452 GESTrackElement * track_element, GESTrack ** track_p)
453 {
454 GPtrArray *tracks = g_ptr_array_new ();
455 fail_unless (track_p);
456 fail_unless (*track_p);
457 g_ptr_array_insert (tracks, -1, gst_object_ref (*track_p));
458 *track_p = NULL;
459 return tracks;
460 }
461
462 GST_START_TEST (test_split_object)
463 {
464 GESTimeline *timeline;
465 GESTrack *track1, *track2, *effect_track;
466 GESLayer *layer;
467 GESClip *clip, *splitclip;
468 GList *splittrackelements;
469 GESTrackElement *trackelement1, *trackelement2, *effect1, *effect2,
470 *splittrackelement;
471 guint32 priority1, priority2, effect_priority1, effect_priority2;
472 guint selection_called = 0;
473 const gchar *meta;
474
475 ges_init ();
476
477 layer = ges_layer_new ();
478 fail_unless (layer != NULL);
479 timeline = ges_timeline_new_audio_video ();
480 fail_unless (timeline != NULL);
481 fail_unless (ges_timeline_add_layer (timeline, layer));
482 ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1);
483
484 clip = GES_CLIP (ges_test_clip_new ());
485 fail_unless (clip != NULL);
486 ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1);
487
488 /* Set some properties */
489 g_object_set (clip, "start", (guint64) 42, "duration", (guint64) 50,
490 "in-point", (guint64) 12, NULL);
491 ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1);
492 CHECK_OBJECT_PROPS (clip, 42, 12, 50);
493
494 ges_layer_add_clip (layer, GES_CLIP (clip));
495 ges_timeline_commit (timeline);
496 assert_num_children (clip, 2);
497 trackelement1 = GES_CONTAINER_CHILDREN (clip)->data;
498 fail_unless (trackelement1 != NULL);
499 fail_unless (GES_TIMELINE_ELEMENT_PARENT (trackelement1) ==
500 GES_TIMELINE_ELEMENT (clip));
501 ges_meta_container_set_string (GES_META_CONTAINER (trackelement1), "test_key",
502 "test_value");
503
504 trackelement2 = GES_CONTAINER_CHILDREN (clip)->next->data;
505 fail_unless (trackelement2 != NULL);
506 fail_unless (GES_TIMELINE_ELEMENT_PARENT (trackelement2) ==
507 GES_TIMELINE_ELEMENT (clip));
508
509 effect1 = GES_TRACK_ELEMENT (ges_effect_new ("agingtv"));
510 _assert_add (clip, effect1);
511
512 effect2 = GES_TRACK_ELEMENT (ges_effect_new ("vertigotv"));
513 _assert_add (clip, effect2);
514
515 /* Check that trackelement has the same properties */
516 CHECK_OBJECT_PROPS (trackelement1, 42, 12, 50);
517 CHECK_OBJECT_PROPS (trackelement2, 42, 12, 50);
518 CHECK_OBJECT_PROPS (effect1, 42, 0, 50);
519 CHECK_OBJECT_PROPS (effect2, 42, 0, 50);
520
521 /* And let's also check that it propagated correctly to GNonLin */
522 nle_object_check (ges_track_element_get_nleobject (trackelement1), 42, 50, 12,
523 50, MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 2, TRUE);
524 nle_object_check (ges_track_element_get_nleobject (trackelement2), 42, 50, 12,
525 50, MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 2, TRUE);
526
527 track1 = ges_track_element_get_track (trackelement1);
528 fail_unless (track1);
529 track2 = ges_track_element_get_track (trackelement2);
530 fail_unless (track2);
531 fail_unless (track1 != track2);
532 effect_track = ges_track_element_get_track (effect1);
533 fail_unless (effect_track);
534 fail_unless (ges_track_element_get_track (effect2) == effect_track);
535
536 priority1 = GES_TIMELINE_ELEMENT_PRIORITY (trackelement1);
537 priority2 = GES_TIMELINE_ELEMENT_PRIORITY (trackelement2);
538 effect_priority1 = GES_TIMELINE_ELEMENT_PRIORITY (effect1);
539 effect_priority2 = GES_TIMELINE_ELEMENT_PRIORITY (effect2);
540
541 fail_unless (priority1 == priority2);
542 fail_unless (priority1 > effect_priority2);
543 fail_unless (effect_priority2 > effect_priority1);
544
545 ges_timeline_element_set_child_properties (GES_TIMELINE_ELEMENT (clip),
546 "font-desc", "Normal", "posx", 30, "posy", 50, "alpha", 0.1,
547 "freq", 449.0, "scratch-lines", 2, "zoom-speed", 1.05, NULL);
548
549 /* splitting should avoid track selection */
550 g_signal_connect (timeline, "select-tracks-for-object",
551 G_CALLBACK (_select_none), &selection_called);
552
553 splitclip = ges_clip_split (clip, 67);
554 fail_unless (GES_IS_CLIP (splitclip));
555 fail_unless (splitclip != clip);
556
557 fail_if (selection_called);
558
559 CHECK_OBJECT_PROPS (clip, 42, 12, 25);
560 CHECK_OBJECT_PROPS (trackelement1, 42, 12, 25);
561 CHECK_OBJECT_PROPS (trackelement1, 42, 12, 25);
562 CHECK_OBJECT_PROPS (effect1, 42, 0, 25);
563 CHECK_OBJECT_PROPS (effect2, 42, 0, 25);
564
565 CHECK_OBJECT_PROPS (splitclip, 67, 37, 25);
566
567 assert_equal_children_properties (splitclip, clip);
568
569 splittrackelements = GES_CONTAINER_CHILDREN (splitclip);
570 fail_unless_equals_int (g_list_length (splittrackelements), 4);
571
572 /* first is the effects */
573 splittrackelement = GES_TRACK_ELEMENT (splittrackelements->data);
574 fail_unless (GES_IS_TRACK_ELEMENT (splittrackelement));
575 CHECK_OBJECT_PROPS (splittrackelement, 67, 0, 25);
576
577 assert_equal_children_properties (splittrackelement, effect1);
578 fail_unless (ges_track_element_get_track (splittrackelement) == effect_track);
579 fail_unless (ges_track_element_get_track (effect1) == effect_track);
580 /* +3 priority from layer */
581 assert_equals_int (GES_TIMELINE_ELEMENT_PRIORITY (splittrackelement),
582 effect_priority1 + 3);
583 fail_unless (GES_TIMELINE_ELEMENT_PRIORITY (effect1) == effect_priority1);
584
585 fail_unless (splittrackelement != trackelement1);
586 fail_unless (splittrackelement != trackelement2);
587 fail_unless (splittrackelement != effect1);
588 fail_unless (splittrackelement != effect2);
589
590 splittrackelement = GES_TRACK_ELEMENT (splittrackelements->next->data);
591 fail_unless (GES_IS_TRACK_ELEMENT (splittrackelement));
592 CHECK_OBJECT_PROPS (splittrackelement, 67, 0, 25);
593
594 assert_equal_children_properties (splittrackelement, effect2);
595 fail_unless (ges_track_element_get_track (splittrackelement) == effect_track);
596 fail_unless (ges_track_element_get_track (effect2) == effect_track);
597 assert_equals_int (GES_TIMELINE_ELEMENT_PRIORITY (splittrackelement),
598 effect_priority2 + 3);
599 fail_unless (GES_TIMELINE_ELEMENT_PRIORITY (effect2) == effect_priority2);
600
601 fail_unless (splittrackelement != trackelement1);
602 fail_unless (splittrackelement != trackelement2);
603 fail_unless (splittrackelement != effect1);
604 fail_unless (splittrackelement != effect2);
605
606 splittrackelement = GES_TRACK_ELEMENT (splittrackelements->next->next->data);
607 fail_unless (GES_IS_TRACK_ELEMENT (splittrackelement));
608 CHECK_OBJECT_PROPS (splittrackelement, 67, 37, 25);
609
610 /* core elements have swapped order in the clip, this is ok since they
611 * share the same priority */
612 assert_equal_children_properties (splittrackelement, trackelement1);
613 fail_unless (ges_track_element_get_track (splittrackelement) == track1);
614 fail_unless (ges_track_element_get_track (trackelement1) == track1);
615 assert_equals_int (GES_TIMELINE_ELEMENT_PRIORITY (splittrackelement),
616 priority1 + 3);
617 fail_unless (GES_TIMELINE_ELEMENT_PRIORITY (trackelement1) == priority1);
618 meta = ges_meta_container_get_string (GES_META_CONTAINER (splittrackelement),
619 "test_key");
620 fail_unless_equals_string (meta, "test_value");
621
622 fail_unless (splittrackelement != trackelement1);
623 fail_unless (splittrackelement != trackelement2);
624 fail_unless (splittrackelement != effect1);
625 fail_unless (splittrackelement != effect2);
626
627 splittrackelement =
628 GES_TRACK_ELEMENT (splittrackelements->next->next->next->data);
629 fail_unless (GES_IS_TRACK_ELEMENT (splittrackelement));
630 CHECK_OBJECT_PROPS (splittrackelement, 67, 37, 25);
631
632 assert_equal_children_properties (splittrackelement, trackelement2);
633 fail_unless (ges_track_element_get_track (splittrackelement) == track2);
634 fail_unless (ges_track_element_get_track (trackelement2) == track2);
635 assert_equals_int (GES_TIMELINE_ELEMENT_PRIORITY (splittrackelement),
636 priority2 + 3);
637 fail_unless (GES_TIMELINE_ELEMENT_PRIORITY (trackelement2) == priority2);
638
639 fail_unless (splittrackelement != trackelement1);
640 fail_unless (splittrackelement != trackelement2);
641 fail_unless (splittrackelement != effect1);
642 fail_unless (splittrackelement != effect2);
643
644 /* We own the only ref */
645 ASSERT_OBJECT_REFCOUNT (splitclip, "1 ref for us + 1 for the timeline", 2);
646 /* 1 ref for the Clip, 1 ref for the Track and 2 ref for the timeline
647 * (1 for the "all_element" hashtable, another for the sequence of TrackElement*/
648 ASSERT_OBJECT_REFCOUNT (splittrackelement,
649 "1 ref for the Clip, 1 ref for the Track and 1 ref for the timeline", 3);
650
651 check_destroyed (G_OBJECT (timeline), G_OBJECT (splitclip), clip,
652 splittrackelement, NULL);
653
654 ges_deinit ();
655 }
656
657 GST_END_TEST;
658
659 typedef struct
660 {
661 gboolean duration_cb_called;
662 gboolean clip_added_cb_called;
663 gboolean track_selected_cb_called;
664 GESClip *clip;
665 } SplitOrderData;
666
667 static void
668 _track_selected_cb (GESTimelineElement * el, GParamSpec * spec,
669 SplitOrderData * data)
670 {
671 GESClip *clip = GES_CLIP (el->parent);
672
673 fail_unless (data->clip == clip, "Parent is %" GES_FORMAT " rather than %"
674 GES_FORMAT, GES_ARGS (clip), GES_ARGS (data->clip));
675
676 fail_unless (data->duration_cb_called, "notify::duration not emitted "
677 "for neighbour of %" GES_FORMAT, GES_ARGS (data->clip));
678 fail_unless (data->clip_added_cb_called, "child-added not emitted for %"
679 GES_FORMAT, GES_ARGS (data->clip));
680
681 data->track_selected_cb_called = TRUE;
682 }
683
684 static void
685 _child_added_cb (GESClip * clip, GESTimelineElement * child,
686 SplitOrderData * data)
687 {
688 fail_unless (data->clip == clip, "Received %" GES_FORMAT " rather than %"
689 GES_FORMAT, GES_ARGS (clip), GES_ARGS (data->clip));
690
691 g_signal_connect (child, "notify::track", G_CALLBACK (_track_selected_cb),
692 data);
693 }
694
695 static void
696 _clip_added_cb (GESLayer * layer, GESClip * clip, SplitOrderData * data)
697 {
698 GList *tmp;
699
700 data->clip = clip;
701
702 fail_unless (data->duration_cb_called, "notify::duration not emitted "
703 "for neighbour of %" GES_FORMAT, GES_ARGS (data->clip));
704 /* only called once */
705 fail_if (data->clip_added_cb_called, "clip-added already emitted for %"
706 GES_FORMAT, GES_ARGS (data->clip));
707 fail_if (data->track_selected_cb_called, "track selection already "
708 "occurred for %" GES_FORMAT, GES_ARGS (data->clip));
709
710 data->clip_added_cb_called = TRUE;
711
712 g_signal_connect (clip, "child-added", G_CALLBACK (_child_added_cb), data);
713
714 for (tmp = GES_CONTAINER_CHILDREN (clip); tmp; tmp = tmp->next)
715 g_signal_connect (tmp->data, "notify::track",
716 G_CALLBACK (_track_selected_cb), data);
717 }
718
719 static void
720 _disconnect_cbs (GESLayer * layer, GESClip * clip, SplitOrderData * data)
721 {
722 GList *tmp;
723 g_signal_handlers_disconnect_by_func (clip, _child_added_cb, data);
724 for (tmp = GES_CONTAINER_CHILDREN (clip); tmp; tmp = tmp->next)
725 g_signal_handlers_disconnect_by_func (tmp->data, _track_selected_cb, data);
726 }
727
728 static void
729 _duration_cb (GObject * object, GParamSpec * pspec, SplitOrderData * data)
730 {
731 /* only called once */
732 fail_if (data->duration_cb_called, "notify::duration of neighbour %"
733 GES_FORMAT " already emitted ", GES_ARGS (object));
734 fail_if (data->clip_added_cb_called, "clip-added already emitted");
735 fail_if (data->track_selected_cb_called, "track selection already "
736 "occurred");
737
738 data->duration_cb_called = TRUE;
739 }
740
741 GST_START_TEST (test_split_ordering)
742 {
743 GESTimeline *timeline;
744 GESLayer *layer;
745 GESClip *clip, *splitclip;
746 SplitOrderData data;
747
748 ges_init ();
749
750 timeline = ges_timeline_new_audio_video ();
751
752 layer = ges_timeline_append_layer (timeline);
753
754 clip = GES_CLIP (ges_test_clip_new ());
755 assert_set_duration (clip, 10);
756
757 /* test order when adding clip to a layer */
758 /* don't care about duration yet */
759 data.duration_cb_called = TRUE;
760 data.clip_added_cb_called = FALSE;
761 data.track_selected_cb_called = FALSE;
762 data.clip = NULL;
763
764 g_signal_connect (layer, "clip-added", G_CALLBACK (_clip_added_cb), &data);
765
766 fail_unless (ges_layer_add_clip (layer, clip));
767
768 fail_unless (data.duration_cb_called);
769 fail_unless (data.clip_added_cb_called);
770 fail_unless (data.track_selected_cb_called);
771 fail_unless (data.clip == clip);
772
773 /* now check for the same ordering when splitting, which the original
774 * clip shrinking before the new one is added to the layer */
775 data.duration_cb_called = FALSE;
776 data.clip_added_cb_called = FALSE;
777 data.track_selected_cb_called = FALSE;
778 data.clip = NULL;
779
780 g_signal_connect (clip, "notify::duration", G_CALLBACK (_duration_cb), &data);
781
782 splitclip = ges_clip_split (clip, 5);
783
784 fail_unless (splitclip);
785 fail_unless (data.duration_cb_called);
786 fail_unless (data.clip_added_cb_called);
787 fail_unless (data.track_selected_cb_called);
788 fail_unless (data.clip == splitclip);
789
790 /* disconnect since track of children will change when timeline is
791 * freed */
792 _disconnect_cbs (layer, clip, &data);
793 _disconnect_cbs (layer, splitclip, &data);
794
795 gst_object_unref (timeline);
796
797 ges_deinit ();
798 }
799
800 GST_END_TEST;
801
802 #define _assert_higher_priority(el, higher) \
803 { \
804 if (higher) { \
805 guint32 el_prio = GES_TIMELINE_ELEMENT_PRIORITY (el); \
806 guint32 higher_prio = GES_TIMELINE_ELEMENT_PRIORITY (higher); \
807 fail_unless (el_prio > higher_prio, "%s does not have a higher " \
808 "priority than %s (%u vs %u)", GES_TIMELINE_ELEMENT_NAME (el), \
809 GES_TIMELINE_ELEMENT_NAME (higher), el_prio, higher_prio); \
810 } \
811 }
812
813 #define _assert_regroup_fails(clip_list) \
814 { \
815 GESContainer *regrouped = ges_container_group (clip_list); \
816 fail_unless (GES_IS_GROUP (regrouped)); \
817 assert_equals_int (g_list_length (regrouped->children), \
818 g_list_length (clip_list)); \
819 g_list_free_full (ges_container_ungroup (regrouped, FALSE), \
820 gst_object_unref); \
821 }
822
823 GST_START_TEST (test_clip_group_ungroup)
824 {
825 GESAsset *asset;
826 GESTimeline *timeline;
827 GESClip *clip, *video_clip, *audio_clip;
828 GESTrackElement *el;
829 GList *containers, *tmp;
830 GESLayer *layer;
831 GESContainer *regrouped_clip;
832 GESTrack *audio_track, *video_track;
833 guint selection_called = 0;
834 struct
835 {
836 GESTrackElement *element;
837 GESTrackElement *higher_priority;
838 } audio_els[2];
839 struct
840 {
841 GESTrackElement *element;
842 GESTrackElement *higher_priority;
843 } video_els[3];
844 guint i, j;
845 const gchar *name;
846 GESTrackType type;
847
848 ges_init ();
849
850 timeline = ges_timeline_new ();
851 layer = ges_layer_new ();
852 audio_track = GES_TRACK (ges_audio_track_new ());
853 video_track = GES_TRACK (ges_video_track_new ());
854
855 fail_unless (ges_timeline_add_track (timeline, audio_track));
856 fail_unless (ges_timeline_add_track (timeline, video_track));
857 fail_unless (ges_timeline_add_layer (timeline, layer));
858
859 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
860 assert_is_type (asset, GES_TYPE_ASSET);
861
862 clip = ges_layer_add_asset (layer, asset, 0, 0, 10, GES_TRACK_TYPE_UNKNOWN);
863 ASSERT_OBJECT_REFCOUNT (clip, "1 layer + 1 timeline.all_els", 2);
864 assert_num_children (clip, 2);
865 CHECK_OBJECT_PROPS (clip, 0, 0, 10);
866
867 el = GES_TRACK_ELEMENT (ges_effect_new ("audioecho"));
868 ges_track_element_set_track_type (el, GES_TRACK_TYPE_AUDIO);
869 _assert_add (clip, el);
870
871 el = GES_TRACK_ELEMENT (ges_effect_new ("agingtv"));
872 ges_track_element_set_track_type (el, GES_TRACK_TYPE_VIDEO);
873 _assert_add (clip, el);
874
875 el = GES_TRACK_ELEMENT (ges_effect_new ("videobalance"));
876 ges_track_element_set_track_type (el, GES_TRACK_TYPE_VIDEO);
877 _assert_add (clip, el);
878
879 assert_num_children (clip, 5);
880 CHECK_OBJECT_PROPS (clip, 0, 0, 10);
881
882 i = j = 0;
883 for (tmp = GES_CONTAINER_CHILDREN (clip); tmp; tmp = tmp->next) {
884 el = tmp->data;
885 type = ges_track_element_get_track_type (el);
886 if (type == GES_TRACK_TYPE_AUDIO) {
887 fail_unless (i < G_N_ELEMENTS (audio_els));
888 audio_els[i].element = el;
889 fail_unless (ges_track_element_get_track (el) == audio_track,
890 "%s not in audio track", GES_TIMELINE_ELEMENT_NAME (el));
891 if (i == 0)
892 audio_els[i].higher_priority = NULL;
893 else
894 audio_els[i].higher_priority = audio_els[i - 1].element;
895 _assert_higher_priority (el, audio_els[i].higher_priority);
896 i++;
897 }
898 if (type == GES_TRACK_TYPE_VIDEO) {
899 fail_unless (j < G_N_ELEMENTS (video_els));
900 video_els[j].element = el;
901 fail_unless (ges_track_element_get_track (el) == video_track,
902 "%s not in video track", GES_TIMELINE_ELEMENT_NAME (el));
903 if (j == 0)
904 video_els[j].higher_priority = NULL;
905 else
906 video_els[j].higher_priority = video_els[j - 1].element;
907 _assert_higher_priority (el, video_els[j].higher_priority);
908 j++;
909 }
910 }
911 fail_unless (i == G_N_ELEMENTS (audio_els));
912 fail_unless (j == G_N_ELEMENTS (video_els));
913 assert_num_in_track (audio_track, 2);
914 assert_num_in_track (video_track, 3);
915
916 /* group and ungroup should avoid track selection */
917 g_signal_connect (timeline, "select-tracks-for-object",
918 G_CALLBACK (_select_none), &selection_called);
919
920 containers = ges_container_ungroup (GES_CONTAINER (clip), FALSE);
921
922 fail_if (selection_called);
923
924 video_clip = NULL;
925 audio_clip = NULL;
926
927 assert_equals_int (g_list_length (containers), 2);
928
929 type = ges_clip_get_supported_formats (containers->data);
930 if (type == GES_TRACK_TYPE_VIDEO)
931 video_clip = containers->data;
932 if (type == GES_TRACK_TYPE_AUDIO)
933 audio_clip = containers->data;
934
935 type = ges_clip_get_supported_formats (containers->next->data);
936 if (type == GES_TRACK_TYPE_VIDEO)
937 video_clip = containers->next->data;
938 if (type == GES_TRACK_TYPE_AUDIO)
939 audio_clip = containers->next->data;
940
941 fail_unless (video_clip);
942 fail_unless (audio_clip);
943 fail_unless (video_clip == clip || audio_clip == clip);
944
945 assert_layer (video_clip, layer);
946 assert_num_children (video_clip, 3);
947 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (video_clip) == timeline);
948 CHECK_OBJECT_PROPS (video_clip, 0, 0, 10);
949 ASSERT_OBJECT_REFCOUNT (video_clip, "1 for the layer + 1 for the timeline + "
950 "1 in containers list", 3);
951
952 assert_layer (audio_clip, layer);
953 assert_num_children (audio_clip, 2);
954 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (audio_clip) == timeline);
955 CHECK_OBJECT_PROPS (audio_clip, 0, 0, 10);
956 ASSERT_OBJECT_REFCOUNT (audio_clip, "1 for the layer + 1 for the timeline + "
957 "1 in containers list", 3);
958
959 for (i = 0; i < G_N_ELEMENTS (audio_els); i++) {
960 el = audio_els[i].element;
961 name = GES_TIMELINE_ELEMENT_NAME (el);
962 fail_unless (ges_track_element_get_track (el) == audio_track,
963 "%s not in audio track", name);
964 fail_unless (GES_TIMELINE_ELEMENT_PARENT (el) ==
965 GES_TIMELINE_ELEMENT (audio_clip), "%s not in the audio clip", name);
966 ASSERT_OBJECT_REFCOUNT (el,
967 "1 for the track + 1 for the container " "+ 1 for the timeline", 3);
968 _assert_higher_priority (el, audio_els[i].higher_priority);
969 }
970 for (i = 0; i < G_N_ELEMENTS (video_els); i++) {
971 el = video_els[i].element;
972 name = GES_TIMELINE_ELEMENT_NAME (el);
973 fail_unless (ges_track_element_get_track (el) == video_track,
974 "%s not in video track", name);
975 fail_unless (GES_TIMELINE_ELEMENT_PARENT (el) ==
976 GES_TIMELINE_ELEMENT (video_clip), "%s not in the video clip", name);
977 ASSERT_OBJECT_REFCOUNT (el,
978 "1 for the track + 1 for the container " "+ 1 for the timeline", 3);
979 _assert_higher_priority (el, video_els[i].higher_priority);
980 }
981 assert_num_in_track (audio_track, 2);
982 assert_num_in_track (video_track, 3);
983
984 assert_set_start (video_clip, 10);
985 CHECK_OBJECT_PROPS (video_clip, 10, 0, 10);
986 CHECK_OBJECT_PROPS (audio_clip, 0, 0, 10);
987
988 _assert_regroup_fails (containers);
989
990 assert_set_start (video_clip, 0);
991 assert_set_inpoint (video_clip, 10);
992 CHECK_OBJECT_PROPS (video_clip, 0, 10, 10);
993 CHECK_OBJECT_PROPS (audio_clip, 0, 0, 10);
994
995 _assert_regroup_fails (containers);
996
997 assert_set_inpoint (video_clip, 0);
998 assert_set_duration (video_clip, 15);
999 CHECK_OBJECT_PROPS (video_clip, 0, 0, 15);
1000 CHECK_OBJECT_PROPS (audio_clip, 0, 0, 10);
1001
1002 _assert_regroup_fails (containers);
1003
1004 assert_set_duration (video_clip, 10);
1005 CHECK_OBJECT_PROPS (video_clip, 0, 0, 10);
1006 CHECK_OBJECT_PROPS (audio_clip, 0, 0, 10);
1007
1008 regrouped_clip = ges_container_group (containers);
1009
1010 fail_if (selection_called);
1011
1012 assert_is_type (regrouped_clip, GES_TYPE_CLIP);
1013 assert_num_children (regrouped_clip, 5);
1014 assert_equals_int (ges_clip_get_supported_formats (GES_CLIP (regrouped_clip)),
1015 GES_TRACK_TYPE_VIDEO | GES_TRACK_TYPE_AUDIO);
1016 g_list_free_full (containers, gst_object_unref);
1017
1018 assert_layer (regrouped_clip, layer);
1019
1020 for (i = 0; i < G_N_ELEMENTS (audio_els); i++) {
1021 el = audio_els[i].element;
1022 name = GES_TIMELINE_ELEMENT_NAME (el);
1023 fail_unless (ges_track_element_get_track (el) == audio_track,
1024 "%s not in audio track", name);
1025 fail_unless (GES_TIMELINE_ELEMENT_PARENT (el) ==
1026 GES_TIMELINE_ELEMENT (regrouped_clip), "%s not in the regrouped clip",
1027 name);
1028 ASSERT_OBJECT_REFCOUNT (el,
1029 "1 for the track + 1 for the container " "+ 1 for the timeline", 3);
1030 _assert_higher_priority (el, audio_els[i].higher_priority);
1031 }
1032 for (i = 0; i < G_N_ELEMENTS (video_els); i++) {
1033 el = video_els[i].element;
1034 name = GES_TIMELINE_ELEMENT_NAME (el);
1035 fail_unless (ges_track_element_get_track (el) == video_track,
1036 "%s not in video track", name);
1037 fail_unless (GES_TIMELINE_ELEMENT_PARENT (el) ==
1038 GES_TIMELINE_ELEMENT (regrouped_clip), "%s not in the regrouped clip",
1039 name);
1040 ASSERT_OBJECT_REFCOUNT (el,
1041 "1 for the track + 1 for the container " "+ 1 for the timeline", 3);
1042 _assert_higher_priority (el, video_els[i].higher_priority);
1043 }
1044 assert_num_in_track (audio_track, 2);
1045 assert_num_in_track (video_track, 3);
1046
1047 gst_object_unref (timeline);
1048 gst_object_unref (asset);
1049
1050 ges_deinit ();
1051 }
1052
1053 GST_END_TEST;
1054
1055 GST_START_TEST (test_clip_can_group)
1056 {
1057 GESTimeline *timeline;
1058 GESLayer *layer1, *layer2;
1059 GESTrack *track1, *track2, *track3, *select_track;
1060 GESAsset *asset1, *asset2, *asset3;
1061 GESContainer *container;
1062 GESClip *clip1, *clip2, *clip3, *grouped;
1063 GList *clips = NULL;
1064
1065 ges_init ();
1066
1067 timeline = ges_timeline_new ();
1068
1069 track1 = GES_TRACK (ges_audio_track_new ());
1070 track2 = GES_TRACK (ges_video_track_new ());
1071 track3 = GES_TRACK (ges_video_track_new ());
1072
1073 fail_unless (ges_timeline_add_track (timeline, track1));
1074 fail_unless (ges_timeline_add_track (timeline, track2));
1075
1076 layer1 = ges_timeline_append_layer (timeline);
1077 layer2 = ges_timeline_append_layer (timeline);
1078
1079 asset1 = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
1080 asset2 = ges_asset_request (GES_TYPE_TEST_CLIP, "width=700", NULL);
1081 asset3 =
1082 ges_asset_request (GES_TYPE_EFFECT_CLIP, "audioecho || agingtv", NULL);
1083
1084 /* fail if different layer */
1085 clip1 = ges_layer_add_asset (layer1, asset1, 0, 0, 10, GES_TRACK_TYPE_VIDEO);
1086 fail_unless (clip1);
1087 assert_num_children (clip1, 1);
1088 assert_num_in_track (track1, 0);
1089 assert_num_in_track (track2, 1);
1090
1091 clip2 = ges_layer_add_asset (layer2, asset1, 0, 0, 10, GES_TRACK_TYPE_AUDIO);
1092 fail_unless (clip2);
1093 assert_num_children (clip2, 1);
1094 assert_num_in_track (track1, 1);
1095 assert_num_in_track (track2, 1);
1096
1097 clips = g_list_append (clips, clip1);
1098 clips = g_list_append (clips, clip2);
1099
1100 _assert_regroup_fails (clips);
1101
1102 g_list_free (clips);
1103 clips = NULL;
1104
1105 gst_object_ref (clip1);
1106 gst_object_ref (clip2);
1107 fail_unless (ges_layer_remove_clip (layer1, clip1));
1108 fail_unless (ges_layer_remove_clip (layer2, clip2));
1109 assert_num_children (clip1, 1);
1110 assert_num_children (clip2, 1);
1111 gst_object_unref (clip1);
1112 gst_object_unref (clip2);
1113 assert_num_in_track (track1, 0);
1114 assert_num_in_track (track2, 0);
1115
1116 /* fail if different asset */
1117 clip1 = ges_layer_add_asset (layer1, asset1, 0, 0, 10, GES_TRACK_TYPE_VIDEO);
1118 fail_unless (clip1);
1119 assert_num_children (clip1, 1);
1120
1121 clip2 = ges_layer_add_asset (layer1, asset2, 0, 0, 10, GES_TRACK_TYPE_AUDIO);
1122 fail_unless (clip2);
1123 assert_num_children (clip2, 1);
1124 assert_num_in_track (track1, 1);
1125 assert_num_in_track (track2, 1);
1126
1127 clips = g_list_append (clips, clip1);
1128 clips = g_list_append (clips, clip2);
1129
1130 _assert_regroup_fails (clips);
1131
1132 g_list_free (clips);
1133 clips = NULL;
1134
1135 fail_unless (ges_layer_remove_clip (layer1, clip1));
1136 fail_unless (ges_layer_remove_clip (layer1, clip2));
1137
1138 /* fail if sharing track */
1139 clip1 = ges_layer_add_asset (layer1, asset3, 0, 0, 10, GES_TRACK_TYPE_VIDEO);
1140 fail_unless (clip1);
1141 assert_num_children (clip1, 1);
1142
1143 clip2 = ges_layer_add_asset (layer1, asset3, 0, 0, 10, GES_TRACK_TYPE_VIDEO);
1144 fail_unless (clip2);
1145 assert_num_children (clip2, 1);
1146 assert_num_in_track (track1, 0);
1147 assert_num_in_track (track2, 2);
1148
1149 clips = g_list_append (clips, clip1);
1150 clips = g_list_append (clips, clip2);
1151
1152 _assert_regroup_fails (clips);
1153
1154 g_list_free (clips);
1155 clips = NULL;
1156
1157 fail_unless (ges_layer_remove_clip (layer1, clip1));
1158 fail_unless (ges_layer_remove_clip (layer1, clip2));
1159
1160 clip1 = ges_layer_add_asset (layer1, asset1, 0, 0, 10, GES_TRACK_TYPE_VIDEO);
1161 fail_unless (clip1);
1162 assert_num_children (clip1, 1);
1163 assert_num_in_track (track1, 0);
1164 assert_num_in_track (track2, 1);
1165
1166 clip2 = ges_layer_add_asset (layer1, asset2, 0, 0, 10, GES_TRACK_TYPE_AUDIO);
1167 fail_unless (clip2);
1168 assert_num_children (clip2, 1);
1169 assert_num_in_track (track1, 1);
1170 assert_num_in_track (track2, 1);
1171
1172 clips = g_list_append (clips, clip1);
1173 clips = g_list_append (clips, clip2);
1174
1175 _assert_regroup_fails (clips);
1176
1177 g_list_free (clips);
1178 clips = NULL;
1179
1180 fail_unless (ges_layer_remove_clip (layer1, clip1));
1181 fail_unless (ges_layer_remove_clip (layer1, clip2));
1182
1183 /* can group if same asset but different tracks */
1184 clip1 = ges_layer_add_asset (layer1, asset2, 0, 0, 10, GES_TRACK_TYPE_VIDEO);
1185 fail_unless (clip1);
1186 _assert_add (clip1, ges_effect_new ("agingtv"));
1187 assert_num_children (clip1, 2);
1188
1189 clip2 = ges_layer_add_asset (layer1, asset2, 0, 0, 10, GES_TRACK_TYPE_AUDIO);
1190 fail_unless (clip2);
1191 assert_num_children (clip2, 1);
1192
1193 fail_unless (ges_timeline_add_track (timeline, track3));
1194 assert_num_children (clip1, 2);
1195 assert_num_children (clip2, 1);
1196 assert_num_in_track (track1, 1);
1197 assert_num_in_track (track2, 2);
1198 assert_num_in_track (track3, 0);
1199
1200 select_track = track3;
1201 g_signal_connect (timeline, "select-tracks-for-object",
1202 G_CALLBACK (_select_track), &select_track);
1203
1204 clip3 = ges_layer_add_asset (layer1, asset2, 0, 0, 10, GES_TRACK_TYPE_VIDEO);
1205 fail_unless (select_track == NULL);
1206 assert_num_children (clip1, 2);
1207 assert_num_children (clip2, 1);
1208 assert_num_children (clip3, 1);
1209 assert_num_in_track (track1, 1);
1210 assert_num_in_track (track2, 2);
1211 assert_num_in_track (track3, 1);
1212
1213 clips = g_list_append (clips, clip1);
1214 clips = g_list_append (clips, clip2);
1215 clips = g_list_append (clips, clip3);
1216
1217 container = ges_container_group (clips);
1218
1219 fail_unless (GES_IS_CLIP (container));
1220 grouped = GES_CLIP (container);
1221 assert_num_children (grouped, 4);
1222 assert_num_in_track (track1, 1);
1223 assert_num_in_track (track2, 2);
1224 assert_num_in_track (track3, 1);
1225
1226 fail_unless (ges_clip_get_supported_formats (grouped),
1227 GES_TRACK_TYPE_VIDEO | GES_TRACK_TYPE_AUDIO);
1228 fail_unless (ges_extractable_get_asset (GES_EXTRACTABLE (grouped))
1229 == asset2);
1230 CHECK_OBJECT_PROPS (grouped, 0, 0, 10);
1231
1232 g_list_free (clips);
1233
1234 clips = ges_layer_get_clips (layer1);
1235 fail_unless (g_list_length (clips), 1);
1236 fail_unless (GES_CLIP (clips->data) == grouped);
1237 g_list_free_full (clips, gst_object_unref);
1238
1239 gst_object_unref (asset1);
1240 gst_object_unref (asset2);
1241 gst_object_unref (asset3);
1242
1243 gst_object_unref (timeline);
1244
1245 ges_deinit ();
1246 }
1247
1248 GST_END_TEST;
1249
1250 GST_START_TEST (test_adding_children_to_track)
1251 {
1252 GESTimeline *timeline;
1253 GESLayer *layer;
1254 GESTrack *track1, *track2;
1255 GESClip *clip, *clip2;
1256 GESAsset *asset;
1257 GESTrackElement *source, *effect, *effect2, *added, *added2, *added3;
1258 GstControlSource *ctrl_source;
1259 guint selection_called = 0;
1260 GError *error = NULL;
1261
1262 ges_init ();
1263
1264 timeline = ges_timeline_new ();
1265 ges_timeline_set_auto_transition (timeline, TRUE);
1266 track1 = GES_TRACK (ges_video_track_new ());
1267 track2 = GES_TRACK (ges_video_track_new ());
1268
1269 /* only add two for now */
1270 fail_unless (ges_timeline_add_track (timeline, track1));
1271
1272 layer = ges_timeline_append_layer (timeline);
1273
1274 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
1275
1276 clip = ges_layer_add_asset (layer, asset, 0, 0, 10, GES_TRACK_TYPE_UNKNOWN);
1277 fail_unless (clip);
1278 assert_num_children (clip, 1);
1279 assert_num_in_track (track1, 1);
1280 assert_num_in_track (track2, 0);
1281 source = GES_CONTAINER_CHILDREN (clip)->data;
1282 fail_unless (ges_track_element_get_track (source) == track1);
1283
1284 effect = GES_TRACK_ELEMENT (ges_effect_new ("agingtv"));
1285 _assert_add (clip, effect);
1286 effect2 = GES_TRACK_ELEMENT (ges_effect_new ("vertigotv"));
1287 _assert_add (clip, effect2);
1288 assert_num_children (clip, 3);
1289 assert_num_in_track (track1, 3);
1290 assert_num_in_track (track2, 0);
1291 fail_unless (ges_track_element_get_track (effect) == track1);
1292 fail_unless (ges_track_element_get_track (effect2) == track1);
1293
1294 ges_timeline_element_set_child_properties (GES_TIMELINE_ELEMENT (clip),
1295 "font-desc", "Normal", "posx", 30, "posy", 50, "alpha", 0.1,
1296 "freq", 449.0, "scratch-lines", 2, NULL);
1297
1298 ctrl_source = GST_CONTROL_SOURCE (gst_interpolation_control_source_new ());
1299 g_object_set (G_OBJECT (ctrl_source), "mode",
1300 GST_INTERPOLATION_MODE_CUBIC, NULL);
1301 fail_unless (gst_timed_value_control_source_set
1302 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), 0, 20.0));
1303 fail_unless (gst_timed_value_control_source_set
1304 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), 5, 45.0));
1305 fail_unless (ges_track_element_set_control_source (source, ctrl_source,
1306 "posx", "direct-absolute"));
1307 gst_object_unref (ctrl_source);
1308
1309 ctrl_source = GST_CONTROL_SOURCE (gst_interpolation_control_source_new ());
1310 g_object_set (G_OBJECT (ctrl_source), "mode",
1311 GST_INTERPOLATION_MODE_LINEAR, NULL);
1312 fail_unless (gst_timed_value_control_source_set
1313 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), 2, 0.1));
1314 fail_unless (gst_timed_value_control_source_set
1315 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), 5, 0.7));
1316 fail_unless (gst_timed_value_control_source_set
1317 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), 8, 0.3));
1318 fail_unless (ges_track_element_set_control_source (source, ctrl_source,
1319 "alpha", "direct"));
1320 gst_object_unref (ctrl_source);
1321
1322 ctrl_source = GST_CONTROL_SOURCE (gst_interpolation_control_source_new ());
1323 g_object_set (G_OBJECT (ctrl_source), "mode",
1324 GST_INTERPOLATION_MODE_NONE, NULL);
1325 fail_unless (gst_timed_value_control_source_set
1326 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), 0, 1.0));
1327 fail_unless (gst_timed_value_control_source_set
1328 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), 4, 7.0));
1329 fail_unless (gst_timed_value_control_source_set
1330 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), 8, 3.0));
1331 fail_unless (ges_track_element_set_control_source (effect, ctrl_source,
1332 "scratch-lines", "direct-absolute"));
1333 gst_object_unref (ctrl_source);
1334
1335 /* can't add to a track that does not belong to the timeline */
1336 fail_if (ges_clip_add_child_to_track (clip, source, track2, &error));
1337 assert_num_children (clip, 3);
1338 fail_unless (ges_track_element_get_track (source) == track1);
1339 assert_num_in_track (track1, 3);
1340 assert_num_in_track (track2, 0);
1341 /* programming/usage error gives no error code/message */
1342 fail_if (error);
1343
1344 /* can't add the clip to a track that already contains our source */
1345 fail_if (ges_clip_add_child_to_track (clip, source, track1, &error));
1346 assert_num_children (clip, 3);
1347 fail_unless (ges_track_element_get_track (source) == track1);
1348 assert_num_in_track (track1, 3);
1349 assert_num_in_track (track2, 0);
1350 fail_if (error);
1351
1352 /* can't remove a core element from its track whilst a non-core sits
1353 * above it */
1354 fail_if (ges_track_remove_element (track1, source));
1355 assert_num_children (clip, 3);
1356 fail_unless (ges_track_element_get_track (source) == track1);
1357 assert_num_in_track (track1, 3);
1358 assert_num_in_track (track2, 0);
1359
1360 /* can not add to the same track as it is currently in */
1361 fail_if (ges_clip_add_child_to_track (clip, effect, track1, &error));
1362 fail_unless (ges_track_element_get_track (effect) == track1);
1363 assert_num_in_track (track1, 3);
1364 assert_num_in_track (track2, 0);
1365 fail_if (error);
1366
1367 /* adding another video track, select-tracks-for-object will do nothing
1368 * since no each track element is already part of a track */
1369 fail_unless (ges_timeline_add_track (timeline, track2));
1370 assert_num_children (clip, 3);
1371 assert_num_in_track (track1, 3);
1372 assert_num_in_track (track2, 0);
1373
1374 /* can not add effect to a track that does not contain a core child */
1375 fail_if (ges_clip_add_child_to_track (clip, effect, track2, &error));
1376 assert_num_children (clip, 3);
1377 assert_num_in_track (track1, 3);
1378 assert_num_in_track (track2, 0);
1379 fail_if (error);
1380
1381 /* can add core */
1382
1383 added = ges_clip_add_child_to_track (clip, source, track2, &error);
1384 fail_unless (added);
1385 assert_num_children (clip, 4);
1386 fail_unless (added != source);
1387 fail_unless (ges_track_element_get_track (source) == track1);
1388 fail_unless (ges_track_element_get_track (added) == track2);
1389 assert_num_in_track (track1, 3);
1390 assert_num_in_track (track2, 1);
1391 fail_if (error);
1392
1393 assert_equal_children_properties (added, source);
1394 assert_equal_bindings (added, source);
1395
1396 /* can now add non-core */
1397 assert_equals_int (0,
1398 ges_clip_get_top_effect_index (clip, GES_BASE_EFFECT (effect)));
1399 assert_equals_int (1,
1400 ges_clip_get_top_effect_index (clip, GES_BASE_EFFECT (effect2)));
1401
1402 added2 = ges_clip_add_child_to_track (clip, effect, track2, &error);
1403 fail_unless (added2);
1404 fail_if (error);
1405 assert_num_children (clip, 5);
1406 fail_unless (added2 != effect);
1407 fail_unless (ges_track_element_get_track (effect) == track1);
1408 fail_unless (ges_track_element_get_track (added2) == track2);
1409 assert_num_in_track (track1, 3);
1410 assert_num_in_track (track2, 2);
1411
1412 assert_equal_children_properties (added2, effect);
1413 assert_equal_bindings (added2, effect);
1414
1415 assert_equals_int (0,
1416 ges_clip_get_top_effect_index (clip, GES_BASE_EFFECT (effect)));
1417 assert_equals_int (1,
1418 ges_clip_get_top_effect_index (clip, GES_BASE_EFFECT (added2)));
1419 assert_equals_int (2,
1420 ges_clip_get_top_effect_index (clip, GES_BASE_EFFECT (effect2)));
1421
1422 added3 = ges_clip_add_child_to_track (clip, effect2, track2, &error);
1423 fail_unless (added3);
1424 fail_if (error);
1425 assert_num_children (clip, 6);
1426 fail_unless (added3 != effect2);
1427 fail_unless (ges_track_element_get_track (effect2) == track1);
1428 fail_unless (ges_track_element_get_track (added3) == track2);
1429 assert_num_in_track (track1, 3);
1430 assert_num_in_track (track2, 3);
1431
1432 assert_equal_children_properties (added3, effect2);
1433 assert_equal_bindings (added3, effect2);
1434
1435 /* priorities within new track match that in previous track! */
1436 assert_equals_int (0,
1437 ges_clip_get_top_effect_index (clip, GES_BASE_EFFECT (effect)));
1438 assert_equals_int (1,
1439 ges_clip_get_top_effect_index (clip, GES_BASE_EFFECT (added2)));
1440 assert_equals_int (2,
1441 ges_clip_get_top_effect_index (clip, GES_BASE_EFFECT (effect2)));
1442 assert_equals_int (3,
1443 ges_clip_get_top_effect_index (clip, GES_BASE_EFFECT (added3)));
1444
1445 /* removing core from the container, empties the non-core from their
1446 * tracks */
1447 gst_object_ref (added);
1448 _assert_remove (clip, added);
1449 assert_num_children (clip, 5);
1450 fail_unless (ges_track_element_get_track (source) == track1);
1451 fail_if (ges_track_element_get_track (added));
1452 fail_if (ges_track_element_get_track (added2));
1453 fail_unless (GES_TIMELINE_ELEMENT_PARENT (added) == NULL);
1454 fail_unless (GES_TIMELINE_ELEMENT_PARENT (added2) ==
1455 GES_TIMELINE_ELEMENT (clip));
1456 assert_num_in_track (track1, 3);
1457 assert_num_in_track (track2, 0);
1458 gst_object_unref (added);
1459
1460 _assert_remove (clip, added2);
1461 _assert_remove (clip, added3);
1462 assert_num_children (clip, 3);
1463 assert_num_in_track (track1, 3);
1464 assert_num_in_track (track2, 0);
1465
1466 /* remove from layer empties all children from the tracks */
1467 gst_object_ref (clip);
1468
1469 fail_unless (ges_layer_remove_clip (layer, clip));
1470 assert_num_children (clip, 3);
1471 fail_if (ges_track_element_get_track (source));
1472 fail_if (ges_track_element_get_track (effect));
1473 assert_num_in_track (track1, 0);
1474 assert_num_in_track (track2, 0);
1475
1476 /* add different sources to the layer */
1477 fail_unless (ges_layer_add_asset (layer, asset, 0, 0, 10,
1478 GES_TRACK_TYPE_UNKNOWN));
1479 fail_unless (ges_layer_add_asset (layer, asset, 20, 0, 10,
1480 GES_TRACK_TYPE_UNKNOWN));
1481 fail_unless (clip2 = ges_layer_add_asset (layer, asset, 25, 0, 10,
1482 GES_TRACK_TYPE_UNKNOWN));
1483 assert_num_children (clip2, 2);
1484 /* 3 sources + 1 transition */
1485 assert_num_in_track (track1, 4);
1486 assert_num_in_track (track2, 4);
1487
1488 /* removing the track from the timeline empties it of track elements */
1489 gst_object_ref (track2);
1490 fail_unless (ges_timeline_remove_track (timeline, track2));
1491 /* but children remain in the clips */
1492 assert_num_children (clip2, 2);
1493 assert_num_in_track (track1, 4);
1494 assert_num_in_track (track2, 0);
1495 gst_object_unref (track2);
1496
1497 /* add clip back in, but don't select any tracks */
1498 g_signal_connect (timeline, "select-tracks-for-object",
1499 G_CALLBACK (_select_none), &selection_called);
1500
1501 /* can add the clip to the layer, despite a source existing between
1502 * 0 and 10 because the clip will not fill any track */
1503 /* NOTE: normally this would be useless because it would not trigger
1504 * the creation of any core children. But clip currently still has
1505 * its core children */
1506 fail_unless (ges_layer_add_clip (layer, clip));
1507 gst_object_unref (clip);
1508
1509 /* one call for each child */
1510 assert_equals_int (selection_called, 3);
1511
1512 fail_if (ges_track_element_get_track (source));
1513 fail_if (ges_track_element_get_track (effect));
1514 assert_num_children (clip, 3);
1515 assert_num_in_track (track1, 4);
1516
1517 /* can not add the source to the track because it would overlap another
1518 * source */
1519 fail_if (ges_clip_add_child_to_track (clip, source, track1, &error));
1520 assert_num_children (clip, 3);
1521 assert_num_in_track (track1, 4);
1522 assert_GESError (error, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
1523
1524 /* can not add source at time 23 because it would result in three
1525 * overlapping sources in the track */
1526 assert_set_start (clip, 23);
1527 fail_if (ges_clip_add_child_to_track (clip, source, track1, &error));
1528 assert_num_children (clip, 3);
1529 assert_num_in_track (track1, 4);
1530 assert_GESError (error, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
1531
1532 /* can add at 5, with overlap */
1533 assert_set_start (clip, 5);
1534 added = ges_clip_add_child_to_track (clip, source, track1, &error);
1535 /* added is the source since it was not already in a track */
1536 fail_unless (added == source);
1537 fail_if (error);
1538 assert_num_children (clip, 3);
1539 /* 4 sources + 2 transitions */
1540 assert_num_in_track (track1, 6);
1541
1542 /* also add effect */
1543 added = ges_clip_add_child_to_track (clip, effect, track1, &error);
1544 /* added is the source since it was not already in a track */
1545 fail_unless (added == effect);
1546 fail_if (error);
1547 assert_num_children (clip, 3);
1548 assert_num_in_track (track1, 7);
1549
1550 added = ges_clip_add_child_to_track (clip, effect2, track1, &error);
1551 /* added is the source since it was not already in a track */
1552 fail_unless (added == effect2);
1553 fail_if (error);
1554 assert_num_children (clip, 3);
1555 assert_num_in_track (track1, 8);
1556
1557 assert_equals_int (0,
1558 ges_clip_get_top_effect_index (clip, GES_BASE_EFFECT (effect)));
1559 assert_equals_int (1,
1560 ges_clip_get_top_effect_index (clip, GES_BASE_EFFECT (effect2)));
1561
1562 gst_object_unref (timeline);
1563 gst_object_unref (asset);
1564
1565 ges_deinit ();
1566 }
1567
1568 GST_END_TEST;
1569
1570 static void
1571 child_removed_cb (GESClip * clip, GESTimelineElement * effect,
1572 gboolean * called)
1573 {
1574 ASSERT_OBJECT_REFCOUNT (effect, "1 test ref + 1 keeping alive ref + "
1575 "emission ref", 3);
1576 *called = TRUE;
1577 }
1578
1579 GST_START_TEST (test_clip_refcount_remove_child)
1580 {
1581 GESClip *clip;
1582 GESTrack *track;
1583 gboolean called;
1584 GESTrackElement *effect, *source;
1585 GESTimeline *timeline;
1586 GESLayer *layer;
1587
1588 ges_init ();
1589
1590 timeline = ges_timeline_new ();
1591 track = GES_TRACK (ges_audio_track_new ());
1592 fail_unless (ges_timeline_add_track (timeline, track));
1593
1594 layer = ges_timeline_append_layer (timeline);
1595 clip = GES_CLIP (ges_test_clip_new ());
1596 fail_unless (ges_layer_add_clip (layer, clip));
1597
1598 assert_num_children (clip, 1);
1599 assert_num_in_track (track, 1);
1600
1601 source = GES_CONTAINER_CHILDREN (clip)->data;
1602 ASSERT_OBJECT_REFCOUNT (source, "1 for the container + 1 for the track"
1603 " + 1 timeline", 3);
1604
1605 effect = GES_TRACK_ELEMENT (ges_effect_new ("identity"));
1606 fail_unless (ges_track_add_element (track, effect));
1607 assert_num_in_track (track, 2);
1608 ASSERT_OBJECT_REFCOUNT (effect, "1 for the track + 1 timeline", 2);
1609
1610 _assert_add (clip, effect);
1611 assert_num_children (clip, 2);
1612 ASSERT_OBJECT_REFCOUNT (effect, "1 for the container + 1 for the track"
1613 " + 1 timeline", 3);
1614
1615 fail_unless (ges_track_remove_element (track, effect));
1616 ASSERT_OBJECT_REFCOUNT (effect, "1 for the container", 1);
1617
1618 g_signal_connect (clip, "child-removed", G_CALLBACK (child_removed_cb),
1619 &called);
1620 gst_object_ref (effect);
1621 _assert_remove (clip, effect);
1622 fail_unless (called == TRUE);
1623 ASSERT_OBJECT_REFCOUNT (effect, "1 test ref", 1);
1624 gst_object_unref (effect);
1625
1626 check_destroyed (G_OBJECT (timeline), G_OBJECT (track),
1627 G_OBJECT (layer), G_OBJECT (clip), G_OBJECT (source), NULL);
1628
1629 ges_deinit ();
1630 }
1631
1632 GST_END_TEST;
1633
1634 GST_START_TEST (test_clip_find_track_element)
1635 {
1636 GESClip *clip;
1637 GList *foundelements;
1638 GESTimeline *timeline;
1639 GESLayer *layer;
1640 GESTrack *track, *track1, *track2;
1641 guint selection_called = 0;
1642
1643 GESTrackElement *effect, *effect1, *effect2, *foundelem, *video_source;
1644
1645 ges_init ();
1646
1647 track = GES_TRACK (ges_audio_track_new ());
1648 track1 = GES_TRACK (ges_audio_track_new ());
1649 track2 = GES_TRACK (ges_video_track_new ());
1650
1651 timeline = ges_timeline_new ();
1652 fail_unless (ges_timeline_add_track (timeline, track));
1653 fail_unless (ges_timeline_add_track (timeline, track1));
1654 fail_unless (ges_timeline_add_track (timeline, track2));
1655
1656 layer = ges_timeline_append_layer (timeline);
1657 clip = GES_CLIP (ges_test_clip_new ());
1658
1659 /* should have a source in every track */
1660 fail_unless (ges_layer_add_clip (layer, clip));
1661 assert_num_children (clip, 3);
1662 assert_num_in_track (track, 1);
1663 assert_num_in_track (track1, 1);
1664 assert_num_in_track (track2, 1);
1665
1666 g_signal_connect (timeline, "select-tracks-for-object",
1667 G_CALLBACK (_select_none), &selection_called);
1668
1669 effect = GES_TRACK_ELEMENT (ges_effect_new ("audio identity"));
1670 fail_unless (ges_track_add_element (track, effect));
1671 _assert_add (clip, effect);
1672
1673 effect1 = GES_TRACK_ELEMENT (ges_effect_new ("audio identity"));
1674 fail_unless (ges_track_add_element (track1, effect1));
1675 _assert_add (clip, effect1);
1676
1677 effect2 = GES_TRACK_ELEMENT (ges_effect_new ("identity"));
1678 fail_unless (ges_track_add_element (track2, effect2));
1679 _assert_add (clip, effect2);
1680
1681 fail_if (selection_called);
1682 assert_num_children (clip, 6);
1683 assert_num_in_track (track, 2);
1684 assert_num_in_track (track1, 2);
1685 assert_num_in_track (track2, 2);
1686
1687 foundelem = ges_clip_find_track_element (clip, track, GES_TYPE_EFFECT);
1688 fail_unless (foundelem == effect);
1689 gst_object_unref (foundelem);
1690
1691 foundelem = ges_clip_find_track_element (clip, track1, GES_TYPE_EFFECT);
1692 fail_unless (foundelem == effect1);
1693 gst_object_unref (foundelem);
1694
1695 foundelem = ges_clip_find_track_element (clip, track2, GES_TYPE_EFFECT);
1696 fail_unless (foundelem == effect2);
1697 gst_object_unref (foundelem);
1698
1699 foundelem = ges_clip_find_track_element (clip, NULL, GES_TYPE_TRANSITION);
1700 fail_unless (foundelem == NULL);
1701
1702 foundelem = ges_clip_find_track_element (clip, track, GES_TYPE_TRANSITION);
1703 fail_unless (foundelem == NULL);
1704
1705 foundelem = ges_clip_find_track_element (clip, track1, GES_TYPE_TRANSITION);
1706 fail_unless (foundelem == NULL);
1707
1708 foundelem = ges_clip_find_track_element (clip, track2, GES_TYPE_TRANSITION);
1709 fail_unless (foundelem == NULL);
1710
1711 foundelem = ges_clip_find_track_element (clip, track, GES_TYPE_SOURCE);
1712 fail_unless (GES_IS_AUDIO_TEST_SOURCE (foundelem));
1713 gst_object_unref (foundelem);
1714
1715 foundelem = ges_clip_find_track_element (clip, track1, GES_TYPE_SOURCE);
1716 fail_unless (GES_IS_AUDIO_TEST_SOURCE (foundelem));
1717 gst_object_unref (foundelem);
1718
1719 foundelem = ges_clip_find_track_element (clip, track2, GES_TYPE_SOURCE);
1720 fail_unless (GES_IS_VIDEO_TEST_SOURCE (foundelem));
1721 gst_object_unref (foundelem);
1722
1723 video_source = ges_clip_find_track_element (clip, NULL,
1724 GES_TYPE_VIDEO_TEST_SOURCE);
1725 fail_unless (foundelem == video_source);
1726 gst_object_unref (video_source);
1727
1728
1729 foundelements = ges_clip_find_track_elements (clip, NULL,
1730 GES_TRACK_TYPE_AUDIO, G_TYPE_NONE);
1731 fail_unless_equals_int (g_list_length (foundelements), 4);
1732 g_list_free_full (foundelements, gst_object_unref);
1733
1734 foundelements = ges_clip_find_track_elements (clip, NULL,
1735 GES_TRACK_TYPE_VIDEO, G_TYPE_NONE);
1736 fail_unless_equals_int (g_list_length (foundelements), 2);
1737 g_list_free_full (foundelements, gst_object_unref);
1738
1739 foundelements = ges_clip_find_track_elements (clip, NULL,
1740 GES_TRACK_TYPE_UNKNOWN, GES_TYPE_SOURCE);
1741 fail_unless_equals_int (g_list_length (foundelements), 3);
1742 fail_unless (g_list_find (foundelements, video_source));
1743 g_list_free_full (foundelements, gst_object_unref);
1744
1745 foundelements = ges_clip_find_track_elements (clip, NULL,
1746 GES_TRACK_TYPE_UNKNOWN, GES_TYPE_EFFECT);
1747 fail_unless_equals_int (g_list_length (foundelements), 3);
1748 fail_unless (g_list_find (foundelements, effect));
1749 fail_unless (g_list_find (foundelements, effect1));
1750 fail_unless (g_list_find (foundelements, effect2));
1751 g_list_free_full (foundelements, gst_object_unref);
1752
1753 foundelements = ges_clip_find_track_elements (clip, NULL,
1754 GES_TRACK_TYPE_VIDEO, GES_TYPE_SOURCE);
1755 fail_unless_equals_int (g_list_length (foundelements), 1);
1756 fail_unless (foundelements->data == video_source);
1757 g_list_free_full (foundelements, gst_object_unref);
1758
1759 foundelements = ges_clip_find_track_elements (clip, track2,
1760 GES_TRACK_TYPE_UNKNOWN, GES_TYPE_SOURCE);
1761 fail_unless_equals_int (g_list_length (foundelements), 1);
1762 fail_unless (foundelements->data == video_source);
1763 g_list_free_full (foundelements, gst_object_unref);
1764
1765 foundelements = ges_clip_find_track_elements (clip, track2,
1766 GES_TRACK_TYPE_UNKNOWN, G_TYPE_NONE);
1767 fail_unless_equals_int (g_list_length (foundelements), 2);
1768 fail_unless (g_list_find (foundelements, effect2));
1769 fail_unless (g_list_find (foundelements, video_source));
1770 g_list_free_full (foundelements, gst_object_unref);
1771
1772 foundelements = ges_clip_find_track_elements (clip, track1,
1773 GES_TRACK_TYPE_UNKNOWN, GES_TYPE_EFFECT);
1774 fail_unless_equals_int (g_list_length (foundelements), 1);
1775 fail_unless (foundelements->data == effect1);
1776 g_list_free_full (foundelements, gst_object_unref);
1777
1778 /* NOTE: search in *either* track or track type
1779 * TODO 2.0: this should be an AND condition, rather than OR */
1780 foundelements = ges_clip_find_track_elements (clip, track,
1781 GES_TRACK_TYPE_VIDEO, G_TYPE_NONE);
1782 fail_unless_equals_int (g_list_length (foundelements), 4);
1783 fail_unless (g_list_find (foundelements, effect));
1784 fail_unless (g_list_find (foundelements, effect2));
1785 fail_unless (g_list_find (foundelements, video_source));
1786 g_list_free_full (foundelements, gst_object_unref);
1787
1788 gst_object_unref (timeline);
1789
1790 ges_deinit ();
1791 }
1792
1793 GST_END_TEST;
1794
1795 GST_START_TEST (test_effects_priorities)
1796 {
1797 GESClip *clip;
1798 GESTimeline *timeline;
1799 GESTrack *audio_track, *video_track;
1800 GESLayer *layer, *layer1;
1801
1802 GESTrackElement *effect, *effect1, *effect2;
1803
1804 ges_init ();
1805
1806 clip = GES_CLIP (ges_test_clip_new ());
1807 audio_track = GES_TRACK (ges_audio_track_new ());
1808 video_track = GES_TRACK (ges_video_track_new ());
1809
1810 timeline = ges_timeline_new ();
1811 fail_unless (ges_timeline_add_track (timeline, audio_track));
1812 fail_unless (ges_timeline_add_track (timeline, video_track));
1813
1814 layer = ges_timeline_append_layer (timeline);
1815 layer1 = ges_timeline_append_layer (timeline);
1816
1817 ges_layer_add_clip (layer, clip);
1818
1819 effect = GES_TRACK_ELEMENT (ges_effect_new ("agingtv"));
1820 _assert_add (clip, effect);
1821
1822 effect1 = GES_TRACK_ELEMENT (ges_effect_new ("agingtv"));
1823 _assert_add (clip, effect1);
1824
1825 effect2 = GES_TRACK_ELEMENT (ges_effect_new ("agingtv"));
1826 _assert_add (clip, effect2);
1827
1828 fail_unless_equals_int (MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 0,
1829 _PRIORITY (effect));
1830 fail_unless_equals_int (MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 1,
1831 _PRIORITY (effect1));
1832 fail_unless_equals_int (MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 2,
1833 _PRIORITY (effect2));
1834
1835 fail_unless (ges_clip_set_top_effect_index (clip, GES_BASE_EFFECT (effect),
1836 2));
1837 fail_unless_equals_int (MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 0,
1838 _PRIORITY (effect1));
1839 fail_unless_equals_int (MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 1,
1840 _PRIORITY (effect2));
1841 fail_unless_equals_int (MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 2,
1842 _PRIORITY (effect));
1843
1844 fail_unless (ges_clip_set_top_effect_index (clip, GES_BASE_EFFECT (effect),
1845 0));
1846 fail_unless_equals_int (MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 0,
1847 _PRIORITY (effect));
1848 fail_unless_equals_int (MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 1,
1849 _PRIORITY (effect1));
1850 fail_unless_equals_int (MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 2,
1851 _PRIORITY (effect2));
1852
1853 fail_unless (ges_clip_move_to_layer (clip, layer1));
1854 fail_unless_equals_int (LAYER_HEIGHT + MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 0,
1855 _PRIORITY (effect));
1856 fail_unless_equals_int (LAYER_HEIGHT + MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 1,
1857 _PRIORITY (effect1));
1858 fail_unless_equals_int (LAYER_HEIGHT + MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 2,
1859 _PRIORITY (effect2));
1860
1861 fail_unless (ges_clip_set_top_effect_index (clip, GES_BASE_EFFECT (effect),
1862 2));
1863 fail_unless_equals_int (LAYER_HEIGHT + MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 0,
1864 _PRIORITY (effect1));
1865 fail_unless_equals_int (LAYER_HEIGHT + MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 1,
1866 _PRIORITY (effect2));
1867 fail_unless_equals_int (LAYER_HEIGHT + MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 2,
1868 _PRIORITY (effect));
1869
1870 fail_unless (ges_clip_set_top_effect_index (clip, GES_BASE_EFFECT (effect),
1871 0));
1872 fail_unless_equals_int (LAYER_HEIGHT + MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 0,
1873 _PRIORITY (effect));
1874 fail_unless_equals_int (LAYER_HEIGHT + MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 1,
1875 _PRIORITY (effect1));
1876 fail_unless_equals_int (LAYER_HEIGHT + MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 2,
1877 _PRIORITY (effect2));
1878
1879 gst_object_unref (timeline);
1880
1881 ges_deinit ();
1882 }
1883
1884 GST_END_TEST;
1885
1886 static void
1887 _count_cb (GObject * obj, GParamSpec * pspec, gint * count)
1888 {
1889 *count = *count + 1;
1890 }
1891
1892 #define _assert_children_time_setter(clip, child, prop, setter, val1, val2) \
1893 { \
1894 gint clip_count = 0; \
1895 gint child_count = 0; \
1896 gchar *notify_name = g_strconcat ("notify::", prop, NULL); \
1897 gchar *clip_name = GES_TIMELINE_ELEMENT_NAME (clip); \
1898 gchar *child_name = NULL; \
1899 g_signal_connect (clip, notify_name, G_CALLBACK (_count_cb), \
1900 &clip_count); \
1901 if (child) { \
1902 child_name = GES_TIMELINE_ELEMENT_NAME (child); \
1903 g_signal_connect (child, notify_name, G_CALLBACK (_count_cb), \
1904 &child_count); \
1905 } \
1906 \
1907 fail_unless (setter (GES_TIMELINE_ELEMENT (clip), val1), \
1908 "Failed to set the %s property for clip %s", prop, clip_name); \
1909 assert_clip_children_time_val (clip, prop, val1); \
1910 \
1911 fail_unless (clip_count == 1, "The callback for the %s property was " \
1912 "called %i times for clip %s, rather than once", \
1913 prop, clip_count, clip_name); \
1914 if (child) { \
1915 fail_unless (child_count == 1, "The callback for the %s property " \
1916 "was called %i times for the child %s of clip %s, rather than " \
1917 "once", prop, child_count, child_name, clip_name); \
1918 } \
1919 \
1920 clip_count = 0; \
1921 if (child) { \
1922 child_count = 0; \
1923 fail_unless (setter (GES_TIMELINE_ELEMENT (child), val2), \
1924 "Failed to set the %s property for the child %s of clip %s", \
1925 prop, child_name, clip_name); \
1926 fail_unless (child_count == 1, "The callback for the %s property " \
1927 "was called %i more times for the child %s of clip %s, rather " \
1928 "than once more", prop, child_count, child_name, clip_name); \
1929 } else { \
1930 fail_unless (setter (GES_TIMELINE_ELEMENT (clip), val2), \
1931 "Failed to set the %s property for clip %s", prop, clip_name); \
1932 } \
1933 assert_clip_children_time_val (clip, prop, val2); \
1934 \
1935 fail_unless (clip_count == 1, "The callback for the %s property " \
1936 "was called %i more times for clip %s, rather than once more", \
1937 prop, clip_count, clip_name); \
1938 assert_equals_int (g_signal_handlers_disconnect_by_func (clip, \
1939 G_CALLBACK (_count_cb), &clip_count), 1); \
1940 if (child) { \
1941 assert_equals_int (g_signal_handlers_disconnect_by_func (child, \
1942 G_CALLBACK (_count_cb), &child_count), 1); \
1943 } \
1944 \
1945 g_free (notify_name); \
1946 }
1947
1948 static void
1949 _test_children_time_setting_on_clip (GESClip * clip, GESTrackElement * child)
1950 {
1951 _assert_children_time_setter (clip, child, "in-point",
1952 ges_timeline_element_set_inpoint, 11, 101);
1953 _assert_children_time_setter (clip, child, "in-point",
1954 ges_timeline_element_set_inpoint, 51, 1);
1955 _assert_children_time_setter (clip, child, "start",
1956 ges_timeline_element_set_start, 12, 102);
1957 _assert_children_time_setter (clip, child, "start",
1958 ges_timeline_element_set_start, 52, 2);
1959 _assert_children_time_setter (clip, child, "duration",
1960 ges_timeline_element_set_duration, 13, 103);
1961 _assert_children_time_setter (clip, child, "duration",
1962 ges_timeline_element_set_duration, 53, 3);
1963 }
1964
1965 GST_START_TEST (test_children_time_setters)
1966 {
1967 GESTimeline *timeline;
1968 GESLayer *layer;
1969 GESClip *clips[] = { NULL, NULL };
1970 gint i;
1971
1972 ges_init ();
1973
1974 timeline = ges_timeline_new_audio_video ();
1975 fail_unless (timeline);
1976
1977 layer = ges_timeline_append_layer (timeline);
1978
1979 clips[0] =
1980 GES_CLIP (ges_transition_clip_new
1981 (GES_VIDEO_STANDARD_TRANSITION_TYPE_CROSSFADE));
1982 clips[1] = GES_CLIP (ges_test_clip_new ());
1983
1984 for (i = 0; i < G_N_ELEMENTS (clips); i++) {
1985 GESClip *clip = clips[i];
1986 GESContainer *group = GES_CONTAINER (ges_group_new ());
1987 GList *children;
1988 GESTrackElement *child;
1989 /* no children */
1990 _test_children_time_setting_on_clip (clip, NULL);
1991 /* child in timeline */
1992 fail_unless (ges_layer_add_clip (layer, clip));
1993 children = GES_CONTAINER_CHILDREN (clip);
1994 fail_unless (children);
1995 child = GES_TRACK_ELEMENT (children->data);
1996 /* make sure the child can have its in-point set */
1997 ges_track_element_set_has_internal_source (child, TRUE);
1998 _test_children_time_setting_on_clip (clip, child);
1999 /* clip in a group */
2000 _assert_add (group, clip);
2001 _test_children_time_setting_on_clip (clip, child);
2002 /* group is removed from the timeline and destroyed when empty */
2003 _assert_remove (group, clip);
2004 /* child not in timeline */
2005 gst_object_ref (clip);
2006 fail_unless (ges_layer_remove_clip (layer, clip));
2007 children = GES_CONTAINER_CHILDREN (clip);
2008 fail_unless (children);
2009 child = GES_TRACK_ELEMENT (children->data);
2010 ges_track_element_set_has_internal_source (child, TRUE);
2011 _test_children_time_setting_on_clip (clip, child);
2012 gst_object_unref (clip);
2013 }
2014 gst_object_unref (timeline);
2015
2016 ges_deinit ();
2017 }
2018
2019 GST_END_TEST;
2020
2021 GST_START_TEST (test_not_enough_internal_content_for_core)
2022 {
2023 GESTimeline *timeline;
2024 GESLayer *layer;
2025 GESAsset *asset;
2026 GError *error = NULL;
2027
2028 ges_init ();
2029
2030 timeline = ges_timeline_new_audio_video ();
2031 layer = ges_timeline_append_layer (timeline);
2032
2033 asset = ges_asset_request (GES_TYPE_TEST_CLIP, "max-duration=30", NULL);
2034 fail_unless (asset);
2035
2036 fail_if (ges_layer_add_asset_full (layer, asset, 0, 31, 10,
2037 GES_TRACK_TYPE_UNKNOWN, &error));
2038 assert_GESError (error, GES_ERROR_NOT_ENOUGH_INTERNAL_CONTENT);
2039
2040 gst_object_unref (timeline);
2041 gst_object_unref (asset);
2042
2043 ges_deinit ();
2044 }
2045
2046 GST_END_TEST;
2047
2048 GST_START_TEST (test_can_add_effect)
2049 {
2050 struct CanAddEffectData
2051 {
2052 GESClip *clip;
2053 gboolean can_add_effect;
2054 } clips[6];
2055 guint i;
2056 gchar *uri;
2057
2058 ges_init ();
2059
2060 uri = ges_test_get_audio_video_uri ();
2061
2062 clips[0] = (struct CanAddEffectData) {
2063 GES_CLIP (ges_test_clip_new ()), TRUE
2064 };
2065 clips[1] = (struct CanAddEffectData) {
2066 GES_CLIP (ges_uri_clip_new (uri)), TRUE
2067 };
2068 clips[2] = (struct CanAddEffectData) {
2069 GES_CLIP (ges_title_clip_new ()), TRUE
2070 };
2071 clips[3] = (struct CanAddEffectData) {
2072 GES_CLIP (ges_effect_clip_new ("agingtv", "audioecho")), TRUE
2073 };
2074 clips[4] = (struct CanAddEffectData) {
2075 GES_CLIP (ges_transition_clip_new
2076 (GES_VIDEO_STANDARD_TRANSITION_TYPE_CROSSFADE)), FALSE
2077 };
2078 clips[5] = (struct CanAddEffectData) {
2079 GES_CLIP (ges_text_overlay_clip_new ()), FALSE
2080 };
2081
2082 g_free (uri);
2083
2084 for (i = 0; i < G_N_ELEMENTS (clips); i++) {
2085 GESClip *clip = clips[i].clip;
2086 GESTimelineElement *effect =
2087 GES_TIMELINE_ELEMENT (ges_effect_new ("agingtv"));
2088 gst_object_ref_sink (effect);
2089 gst_object_ref_sink (clip);
2090 fail_unless (clip);
2091 if (clips[i].can_add_effect)
2092 fail_unless (ges_container_add (GES_CONTAINER (clip), effect),
2093 "Could not add an effect to clip %s",
2094 GES_TIMELINE_ELEMENT_NAME (clip));
2095 else
2096 fail_if (ges_container_add (GES_CONTAINER (clip), effect),
2097 "Could add an effect to clip %s, but we expect this to fail",
2098 GES_TIMELINE_ELEMENT_NAME (clip));
2099 gst_object_unref (effect);
2100 gst_object_unref (clip);
2101 }
2102
2103 ges_deinit ();
2104 }
2105
2106 GST_END_TEST;
2107
2108 #define _assert_active(el, active) \
2109 fail_unless (ges_track_element_is_active (el) == active)
2110
2111 #define _assert_set_active(el, active) \
2112 fail_unless (ges_track_element_set_active (el, active))
2113
2114 GST_START_TEST (test_children_active)
2115 {
2116 GESTimeline *timeline;
2117 GESLayer *layer;
2118 GESClip *clip;
2119 GESTrack *track0, *track1, *select_track;
2120 GESTrackElement *effect0, *effect1, *effect2, *effect3;
2121 GESTrackElement *source0, *source1;
2122
2123 ges_init ();
2124
2125 timeline = ges_timeline_new ();
2126
2127 track0 = GES_TRACK (ges_video_track_new ());
2128 track1 = GES_TRACK (ges_video_track_new ());
2129
2130 fail_unless (ges_timeline_add_track (timeline, track0));
2131 fail_unless (ges_timeline_add_track (timeline, track1));
2132
2133 layer = ges_timeline_append_layer (timeline);
2134
2135 clip = GES_CLIP (ges_test_clip_new ());
2136
2137 fail_unless (ges_layer_add_clip (layer, clip));
2138
2139 assert_num_children (clip, 2);
2140
2141 source0 =
2142 ges_clip_find_track_element (clip, track0, GES_TYPE_VIDEO_TEST_SOURCE);
2143 source1 =
2144 ges_clip_find_track_element (clip, track1, GES_TYPE_VIDEO_TEST_SOURCE);
2145
2146 fail_unless (source0);
2147 fail_unless (source1);
2148
2149 gst_object_unref (source0);
2150 gst_object_unref (source1);
2151
2152 _assert_active (source0, TRUE);
2153 _assert_active (source1, TRUE);
2154
2155 _assert_set_active (source0, FALSE);
2156
2157 _assert_active (source0, FALSE);
2158 _assert_active (source1, TRUE);
2159
2160 select_track = track0;
2161 g_signal_connect (timeline, "select-tracks-for-object",
2162 G_CALLBACK (_select_track), &select_track);
2163
2164 /* add an active effect should become inactive to match the core */
2165 effect0 = GES_TRACK_ELEMENT (ges_effect_new ("videobalance"));
2166 _assert_active (effect0, TRUE);
2167
2168 _assert_add (clip, effect0);
2169 fail_if (select_track);
2170
2171 _assert_active (source0, FALSE);
2172 _assert_active (effect0, FALSE);
2173 _assert_active (source1, TRUE);
2174
2175 /* adding inactive to track with inactive core does nothing */
2176 effect1 = GES_TRACK_ELEMENT (ges_effect_new ("vertigotv"));
2177 _assert_active (effect1, TRUE);
2178 _assert_set_active (effect1, FALSE);
2179 _assert_active (effect1, FALSE);
2180
2181 select_track = track0;
2182 _assert_add (clip, effect1);
2183 fail_if (select_track);
2184
2185 _assert_active (source0, FALSE);
2186 _assert_active (effect0, FALSE);
2187 _assert_active (effect1, FALSE);
2188 _assert_active (source1, TRUE);
2189
2190 /* adding active to track with active core does nothing */
2191 effect2 = GES_TRACK_ELEMENT (ges_effect_new ("agingtv"));
2192 _assert_active (effect2, TRUE);
2193
2194 select_track = track1;
2195 _assert_add (clip, effect2);
2196 fail_if (select_track);
2197
2198 _assert_active (source0, FALSE);
2199 _assert_active (effect0, FALSE);
2200 _assert_active (effect1, FALSE);
2201 _assert_active (source1, TRUE);
2202 _assert_active (effect2, TRUE);
2203
2204 /* adding inactive to track with active core does nothing */
2205 effect3 = GES_TRACK_ELEMENT (ges_effect_new ("alpha"));
2206 _assert_active (effect3, TRUE);
2207 _assert_set_active (effect3, FALSE);
2208 _assert_active (effect3, FALSE);
2209
2210 select_track = track1;
2211 _assert_add (clip, effect3);
2212 fail_if (select_track);
2213
2214 _assert_active (source0, FALSE);
2215 _assert_active (effect0, FALSE);
2216 _assert_active (effect1, FALSE);
2217 _assert_active (source1, TRUE);
2218 _assert_active (effect2, TRUE);
2219 _assert_active (effect3, FALSE);
2220
2221 /* activate a core does not change non-core */
2222 _assert_set_active (source0, TRUE);
2223
2224 _assert_active (source0, TRUE);
2225 _assert_active (effect0, FALSE);
2226 _assert_active (effect1, FALSE);
2227 _assert_active (source1, TRUE);
2228 _assert_active (effect2, TRUE);
2229 _assert_active (effect3, FALSE);
2230
2231 /* but de-activating a core will de-activate the non-core */
2232 _assert_set_active (source1, FALSE);
2233
2234 _assert_active (source0, TRUE);
2235 _assert_active (effect0, FALSE);
2236 _assert_active (effect1, FALSE);
2237 _assert_active (source1, FALSE);
2238 _assert_active (effect2, FALSE);
2239 _assert_active (effect3, FALSE);
2240
2241 /* activate a non-core will activate the core */
2242 _assert_set_active (effect3, TRUE);
2243
2244 _assert_active (source0, TRUE);
2245 _assert_active (effect0, FALSE);
2246 _assert_active (effect1, FALSE);
2247 _assert_active (source1, TRUE);
2248 _assert_active (effect2, FALSE);
2249 _assert_active (effect3, TRUE);
2250
2251 /* if core is already active, nothing else happens */
2252 _assert_set_active (effect0, TRUE);
2253
2254 _assert_active (source0, TRUE);
2255 _assert_active (effect0, TRUE);
2256 _assert_active (effect1, FALSE);
2257 _assert_active (source1, TRUE);
2258 _assert_active (effect2, FALSE);
2259 _assert_active (effect3, TRUE);
2260
2261 _assert_set_active (effect1, TRUE);
2262
2263 _assert_active (source0, TRUE);
2264 _assert_active (effect0, TRUE);
2265 _assert_active (effect1, TRUE);
2266 _assert_active (source1, TRUE);
2267 _assert_active (effect2, FALSE);
2268 _assert_active (effect3, TRUE);
2269
2270 _assert_set_active (effect2, TRUE);
2271
2272 _assert_active (source0, TRUE);
2273 _assert_active (effect0, TRUE);
2274 _assert_active (effect1, TRUE);
2275 _assert_active (source1, TRUE);
2276 _assert_active (effect2, TRUE);
2277 _assert_active (effect3, TRUE);
2278
2279 /* de-activate a core will de-active all the non-core */
2280 _assert_set_active (source0, FALSE);
2281
2282 _assert_active (source0, FALSE);
2283 _assert_active (effect0, FALSE);
2284 _assert_active (effect1, FALSE);
2285 _assert_active (source1, TRUE);
2286 _assert_active (effect2, TRUE);
2287 _assert_active (effect3, TRUE);
2288
2289 /* de-activate a non-core does nothing else */
2290 _assert_set_active (effect3, FALSE);
2291
2292 _assert_active (source0, FALSE);
2293 _assert_active (effect0, FALSE);
2294 _assert_active (effect1, FALSE);
2295 _assert_active (source1, TRUE);
2296 _assert_active (effect2, TRUE);
2297 _assert_active (effect3, FALSE);
2298
2299 gst_object_unref (timeline);
2300
2301 ges_deinit ();
2302 }
2303
2304 GST_END_TEST;
2305
2306 GST_START_TEST (test_children_inpoint)
2307 {
2308 GESTimeline *timeline;
2309 GESLayer *layer;
2310 GESTimelineElement *clip, *child0, *child1, *effect;
2311 GList *children;
2312
2313 ges_init ();
2314
2315 timeline = ges_timeline_new_audio_video ();
2316 fail_unless (timeline);
2317
2318 layer = ges_timeline_append_layer (timeline);
2319
2320 clip = GES_TIMELINE_ELEMENT (ges_test_clip_new ());
2321
2322 assert_set_start (clip, 5);
2323 assert_set_duration (clip, 20);
2324 assert_set_inpoint (clip, 30);
2325
2326 CHECK_OBJECT_PROPS (clip, 5, 30, 20);
2327
2328 fail_unless (ges_layer_add_clip (layer, GES_CLIP (clip)));
2329
2330 /* clip now has children */
2331 children = GES_CONTAINER_CHILDREN (clip);
2332 fail_unless (children);
2333 child0 = children->data;
2334 fail_unless (children->next);
2335 child1 = children->next->data;
2336 fail_unless (children->next->next == NULL);
2337
2338 fail_unless (ges_track_element_has_internal_source (GES_TRACK_ELEMENT
2339 (child0)));
2340 fail_unless (ges_track_element_has_internal_source (GES_TRACK_ELEMENT
2341 (child1)));
2342
2343 CHECK_OBJECT_PROPS (clip, 5, 30, 20);
2344 CHECK_OBJECT_PROPS (child0, 5, 30, 20);
2345 CHECK_OBJECT_PROPS (child1, 5, 30, 20);
2346
2347 /* add a non-core element */
2348 effect = GES_TIMELINE_ELEMENT (ges_effect_new ("agingtv"));
2349 fail_if (ges_track_element_has_internal_source (GES_TRACK_ELEMENT (effect)));
2350 /* allow us to choose our own in-point */
2351 ges_track_element_set_has_internal_source (GES_TRACK_ELEMENT (effect), TRUE);
2352 assert_set_start (effect, 104);
2353 assert_set_duration (effect, 53);
2354 assert_set_inpoint (effect, 67);
2355
2356 /* adding the effect will change its start and duration, but not its
2357 * in-point */
2358 _assert_add (clip, effect);
2359
2360 CHECK_OBJECT_PROPS (clip, 5, 30, 20);
2361 CHECK_OBJECT_PROPS (child0, 5, 30, 20);
2362 CHECK_OBJECT_PROPS (child1, 5, 30, 20);
2363 CHECK_OBJECT_PROPS (effect, 5, 67, 20);
2364
2365 /* register child0 as having no internal source, which means its
2366 * in-point will be set to 0 */
2367 ges_track_element_set_has_internal_source (GES_TRACK_ELEMENT (child0), FALSE);
2368
2369 CHECK_OBJECT_PROPS (clip, 5, 30, 20);
2370 CHECK_OBJECT_PROPS (child0, 5, 0, 20);
2371 CHECK_OBJECT_PROPS (child1, 5, 30, 20);
2372 CHECK_OBJECT_PROPS (effect, 5, 67, 20);
2373
2374 /* should not be able to set the in-point to non-zero */
2375 assert_fail_set_inpoint (child0, 40);
2376
2377 CHECK_OBJECT_PROPS (clip, 5, 30, 20);
2378 CHECK_OBJECT_PROPS (child0, 5, 0, 20);
2379 CHECK_OBJECT_PROPS (child1, 5, 30, 20);
2380 CHECK_OBJECT_PROPS (effect, 5, 67, 20);
2381
2382 /* when we set the in-point on a core-child with an internal source we
2383 * also set the clip and siblings with the same features */
2384 assert_set_inpoint (child1, 50);
2385
2386 CHECK_OBJECT_PROPS (clip, 5, 50, 20);
2387 /* child with no internal source not changed */
2388 CHECK_OBJECT_PROPS (child0, 5, 0, 20);
2389 CHECK_OBJECT_PROPS (child1, 5, 50, 20);
2390 /* non-core no changed */
2391 CHECK_OBJECT_PROPS (effect, 5, 67, 20);
2392
2393 /* setting back to having internal source will put in sync with the
2394 * in-point of the clip */
2395 ges_track_element_set_has_internal_source (GES_TRACK_ELEMENT (child0), TRUE);
2396
2397 CHECK_OBJECT_PROPS (clip, 5, 50, 20);
2398 CHECK_OBJECT_PROPS (child0, 5, 50, 20);
2399 CHECK_OBJECT_PROPS (child1, 5, 50, 20);
2400 CHECK_OBJECT_PROPS (effect, 5, 67, 20);
2401
2402 assert_set_inpoint (child0, 40);
2403
2404 CHECK_OBJECT_PROPS (clip, 5, 40, 20);
2405 CHECK_OBJECT_PROPS (child0, 5, 40, 20);
2406 CHECK_OBJECT_PROPS (child1, 5, 40, 20);
2407 CHECK_OBJECT_PROPS (effect, 5, 67, 20);
2408
2409 /* setting in-point on effect shouldn't change any other siblings */
2410 assert_set_inpoint (effect, 77);
2411
2412 CHECK_OBJECT_PROPS (clip, 5, 40, 20);
2413 CHECK_OBJECT_PROPS (child0, 5, 40, 20);
2414 CHECK_OBJECT_PROPS (child1, 5, 40, 20);
2415 CHECK_OBJECT_PROPS (effect, 5, 77, 20);
2416
2417 gst_object_unref (timeline);
2418
2419 ges_deinit ();
2420 }
2421
2422 GST_END_TEST;
2423
2424 GST_START_TEST (test_children_max_duration)
2425 {
2426 GESTimeline *timeline;
2427 GESLayer *layer;
2428 gchar *uri;
2429 GESTimelineElement *child0, *child1, *effect;
2430 guint i;
2431 GstClockTime max_duration, new_max;
2432 GList *children;
2433 struct
2434 {
2435 GESTimelineElement *clip;
2436 GstClockTime max_duration;
2437 } clips[] = {
2438 {
2439 NULL, GST_SECOND}, {
2440 NULL, GST_CLOCK_TIME_NONE}
2441 };
2442
2443 ges_init ();
2444
2445 timeline = ges_timeline_new_audio_video ();
2446 fail_unless (timeline);
2447
2448 layer = ges_timeline_append_layer (timeline);
2449
2450 uri = ges_test_get_audio_video_uri ();
2451 clips[0].clip = GES_TIMELINE_ELEMENT (ges_uri_clip_new (uri));
2452 fail_unless (clips[0].clip);
2453 g_free (uri);
2454
2455 clips[1].clip = GES_TIMELINE_ELEMENT (ges_test_clip_new ());
2456
2457 for (i = 0; i < G_N_ELEMENTS (clips); i++) {
2458 GESTimelineElement *clip = clips[i].clip;
2459
2460 max_duration = clips[i].max_duration;
2461 fail_unless_equals_uint64 (_MAX_DURATION (clip), max_duration);
2462 assert_set_start (clip, 5);
2463 assert_set_duration (clip, 20);
2464 assert_set_inpoint (clip, 30);
2465
2466 /* can set the max duration the clip to anything whilst it has
2467 * no core child */
2468 assert_set_max_duration (clip, 150);
2469
2470 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 150);
2471
2472 /* add a non-core element */
2473 effect = GES_TIMELINE_ELEMENT (ges_effect_new ("agingtv"));
2474 fail_if (ges_track_element_has_internal_source (GES_TRACK_ELEMENT
2475 (effect)));
2476 /* allow us to choose our own max-duration */
2477 ges_track_element_set_has_internal_source (GES_TRACK_ELEMENT (effect),
2478 TRUE);
2479 assert_set_start (effect, 104);
2480 assert_set_duration (effect, 53);
2481 assert_set_max_duration (effect, 400);
2482
2483 /* adding the effect will change its start and duration, but not its
2484 * max-duration (or in-point) */
2485 _assert_add (clip, effect);
2486
2487 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 150);
2488 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2489
2490 /* only non-core, so can still set the max-duration */
2491 assert_set_max_duration (clip, 200);
2492
2493 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 200);
2494 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2495
2496 /* removing should not change the max-duration we set on the clip */
2497 gst_object_ref (effect);
2498 _assert_remove (clip, effect);
2499
2500 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 200);
2501 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2502
2503 _assert_add (clip, effect);
2504 gst_object_unref (effect);
2505
2506 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 200);
2507 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2508
2509 /* now add to a layer to create the core children */
2510 fail_unless (ges_layer_add_clip (layer, GES_CLIP (clip)));
2511
2512 children = GES_CONTAINER_CHILDREN (clip);
2513 fail_unless (children);
2514 fail_unless (GES_TIMELINE_ELEMENT (children->data) == effect);
2515 fail_unless (children->next);
2516 child0 = children->next->data;
2517 fail_unless (children->next->next);
2518 child1 = children->next->next->data;
2519 fail_unless (children->next->next->next == NULL);
2520
2521 fail_unless (ges_track_element_has_internal_source (GES_TRACK_ELEMENT
2522 (child0)));
2523 fail_unless (ges_track_element_has_internal_source (GES_TRACK_ELEMENT
2524 (child1)));
2525
2526 if (GES_IS_URI_CLIP (clip))
2527 new_max = max_duration;
2528 else
2529 /* need a valid clock time that is not too large */
2530 new_max = 500;
2531
2532 /* added children do not change the clip's max-duration, but will
2533 * instead set it to the minimum value of its children */
2534 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, max_duration);
2535 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, max_duration);
2536 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, max_duration);
2537 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2538
2539 /* when setting max_duration of core children, clip will take the
2540 * minimum value */
2541 assert_set_max_duration (child0, new_max - 1);
2542
2543 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 1);
2544 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max - 1);
2545 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, max_duration);
2546 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2547
2548 assert_set_max_duration (child1, new_max - 2);
2549
2550 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2551 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max - 1);
2552 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2553 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2554
2555 assert_set_max_duration (child0, new_max + 1);
2556
2557 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2558 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2559 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2560 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2561
2562 /* can not set in-point above max_duration, nor max_duration below
2563 * in-point */
2564
2565 assert_fail_set_max_duration (child0, 29);
2566
2567 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2568 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2569 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2570 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2571
2572 assert_fail_set_max_duration (child1, 29);
2573
2574 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2575 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2576 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2577 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2578
2579 assert_fail_set_max_duration (clip, 29);
2580
2581 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2582 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2583 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2584 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2585
2586 /* can't set the inpoint to (new_max), even though it is lower than
2587 * our own max-duration (new_max + 1) because it is too high for our
2588 * sibling child1 */
2589 assert_fail_set_inpoint (child0, new_max);
2590
2591 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2592 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2593 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2594 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2595
2596 assert_fail_set_inpoint (child1, new_max);
2597
2598 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2599 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2600 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2601 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2602
2603 assert_fail_set_inpoint (clip, new_max);
2604
2605 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2606 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2607 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2608 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2609
2610 /* setting below new_max is ok */
2611 assert_set_inpoint (child0, 15);
2612
2613 CHECK_OBJECT_PROPS_MAX (clip, 5, 15, 20, new_max - 2);
2614 CHECK_OBJECT_PROPS_MAX (child0, 5, 15, 20, new_max + 1);
2615 CHECK_OBJECT_PROPS_MAX (child1, 5, 15, 20, new_max - 2);
2616 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2617
2618 assert_set_inpoint (child1, 25);
2619
2620 CHECK_OBJECT_PROPS_MAX (clip, 5, 25, 20, new_max - 2);
2621 CHECK_OBJECT_PROPS_MAX (child0, 5, 25, 20, new_max + 1);
2622 CHECK_OBJECT_PROPS_MAX (child1, 5, 25, 20, new_max - 2);
2623 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2624
2625 assert_set_inpoint (clip, 30);
2626
2627 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2628 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2629 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2630 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2631
2632 /* non-core has no effect */
2633 assert_set_max_duration (effect, new_max + 500);
2634
2635 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2636 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2637 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2638 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, new_max + 500);
2639
2640 /* can set the in-point of non-core to be higher than the max_duration
2641 * of the clip */
2642 assert_set_inpoint (effect, new_max + 2);
2643
2644 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2645 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2646 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2647 CHECK_OBJECT_PROPS_MAX (effect, 5, new_max + 2, 20, new_max + 500);
2648
2649 /* but not higher than our own */
2650 assert_fail_set_inpoint (effect, new_max + 501);
2651
2652 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2653 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2654 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2655 CHECK_OBJECT_PROPS_MAX (effect, 5, new_max + 2, 20, new_max + 500);
2656
2657 assert_fail_set_max_duration (effect, new_max + 1);
2658
2659 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2660 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2661 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2662 CHECK_OBJECT_PROPS_MAX (effect, 5, new_max + 2, 20, new_max + 500);
2663
2664 assert_set_inpoint (effect, 0);
2665
2666 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2667 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2668 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2669 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, new_max + 500);
2670
2671 assert_set_max_duration (effect, 400);
2672
2673 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, new_max - 2);
2674 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, new_max + 1);
2675 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, new_max - 2);
2676 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2677
2678 /* setting on the clip will set all the core children to the same
2679 * value */
2680 assert_set_max_duration (clip, 180);
2681
2682 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 180);
2683 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, 180);
2684 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, 180);
2685 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2686
2687 /* register child0 as having no internal source, which means its
2688 * in-point will be set to 0 and max-duration set to
2689 * GST_CLOCK_TIME_NONE */
2690 ges_track_element_set_has_internal_source (GES_TRACK_ELEMENT (child0),
2691 FALSE);
2692
2693 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 180);
2694 CHECK_OBJECT_PROPS_MAX (child0, 5, 0, 20, GST_CLOCK_TIME_NONE);
2695 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, 180);
2696 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2697
2698 /* should not be able to set the max-duration to a valid time */
2699 assert_fail_set_max_duration (child0, 40);
2700
2701 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 180);
2702 CHECK_OBJECT_PROPS_MAX (child0, 5, 0, 20, GST_CLOCK_TIME_NONE);
2703 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, 180);
2704 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2705
2706 /* same with child1 */
2707 /* clock time of the clip should now be GST_CLOCK_TIME_NONE */
2708 ges_track_element_set_has_internal_source (GES_TRACK_ELEMENT (child1),
2709 FALSE);
2710
2711 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, GST_CLOCK_TIME_NONE);
2712 CHECK_OBJECT_PROPS_MAX (child0, 5, 0, 20, GST_CLOCK_TIME_NONE);
2713 CHECK_OBJECT_PROPS_MAX (child1, 5, 0, 20, GST_CLOCK_TIME_NONE);
2714 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2715
2716 /* should not be able to set the max of the clip to anything else
2717 * when it has no core children with an internal source */
2718 assert_fail_set_max_duration (clip, 150);
2719
2720 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, GST_CLOCK_TIME_NONE);
2721 CHECK_OBJECT_PROPS_MAX (child0, 5, 0, 20, GST_CLOCK_TIME_NONE);
2722 CHECK_OBJECT_PROPS_MAX (child1, 5, 0, 20, GST_CLOCK_TIME_NONE);
2723 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2724
2725 /* setting back to having an internal source will not immediately
2726 * change the max-duration (unlike in-point) */
2727 ges_track_element_set_has_internal_source (GES_TRACK_ELEMENT (child0),
2728 TRUE);
2729
2730 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, GST_CLOCK_TIME_NONE);
2731 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, GST_CLOCK_TIME_NONE);
2732 CHECK_OBJECT_PROPS_MAX (child1, 5, 0, 20, GST_CLOCK_TIME_NONE);
2733 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2734
2735 /* can now set the max-duration, which will effect the clip */
2736 assert_set_max_duration (child0, 140);
2737
2738 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 140);
2739 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, 140);
2740 CHECK_OBJECT_PROPS_MAX (child1, 5, 0, 20, GST_CLOCK_TIME_NONE);
2741 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2742
2743 ges_track_element_set_has_internal_source (GES_TRACK_ELEMENT (child1),
2744 TRUE);
2745
2746 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 140);
2747 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, 140);
2748 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, GST_CLOCK_TIME_NONE);
2749 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2750
2751 assert_set_max_duration (child1, 130);
2752
2753 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 130);
2754 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, 140);
2755 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, 130);
2756 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2757
2758 /* removing a child may change the max_duration of the clip */
2759 gst_object_ref (child0);
2760 gst_object_ref (child1);
2761 gst_object_ref (effect);
2762
2763 /* removing non-core does nothing */
2764 _assert_remove (clip, effect);
2765
2766 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 130);
2767 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, 140);
2768 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, 130);
2769 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2770
2771 /* new minimum max-duration for the clip when we remove child1 */
2772 _assert_remove (clip, child1);
2773
2774 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 140);
2775 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, 140);
2776 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, 130);
2777 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2778
2779 /* with no core-children, the max-duration of the clip is set to
2780 * GST_CLOCK_TIME_NONE */
2781 _assert_remove (clip, child0);
2782
2783 CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, GST_CLOCK_TIME_NONE);
2784 CHECK_OBJECT_PROPS_MAX (child0, 5, 30, 20, 140);
2785 CHECK_OBJECT_PROPS_MAX (child1, 5, 30, 20, 130);
2786 CHECK_OBJECT_PROPS_MAX (effect, 5, 0, 20, 400);
2787
2788 fail_unless (ges_layer_remove_clip (layer, GES_CLIP (clip)));
2789
2790 gst_object_unref (child0);
2791 gst_object_unref (child1);
2792 gst_object_unref (effect);
2793 }
2794
2795 gst_object_unref (timeline);
2796
2797 ges_deinit ();
2798 }
2799
2800 GST_END_TEST;
2801
2802 #define _assert_duration_limit(clip, expect) \
2803 assert_equals_uint64 (ges_clip_get_duration_limit (GES_CLIP (clip)), expect)
2804
2805 GST_START_TEST (test_duration_limit)
2806 {
2807 GESTimeline *timeline;
2808 GESLayer *layer;
2809 GESClip *clip;
2810 GESTrackElement *video_source, *audio_source;
2811 GESTrackElement *effect1, *effect2, *effect3;
2812 GESTrack *track1, *track2;
2813 gint limit_notify_count = 0;
2814 gint duration_notify_count = 0;
2815
2816 ges_init ();
2817
2818 timeline = ges_timeline_new ();
2819 track1 = GES_TRACK (ges_video_track_new ());
2820 track2 = GES_TRACK (ges_audio_track_new ());
2821
2822 fail_unless (ges_timeline_add_track (timeline, track1));
2823 fail_unless (ges_timeline_add_track (timeline, track2));
2824 /* add track3 later */
2825
2826 layer = ges_timeline_append_layer (timeline);
2827
2828 clip = GES_CLIP (ges_test_clip_new ());
2829 g_signal_connect (clip, "notify::duration-limit", G_CALLBACK (_count_cb),
2830 &limit_notify_count);
2831 g_signal_connect (clip, "notify::duration", G_CALLBACK (_count_cb),
2832 &duration_notify_count);
2833
2834 /* no limit to begin with */
2835 _assert_duration_limit (clip, GST_CLOCK_TIME_NONE);
2836
2837 /* add effects */
2838 effect1 = GES_TRACK_ELEMENT (ges_effect_new ("textoverlay"));
2839 ges_track_element_set_has_internal_source (effect1, TRUE);
2840
2841 effect2 = GES_TRACK_ELEMENT (ges_effect_new ("agingtv"));
2842 ges_track_element_set_has_internal_source (effect2, TRUE);
2843
2844 effect3 = GES_TRACK_ELEMENT (ges_effect_new ("audioecho"));
2845 ges_track_element_set_has_internal_source (effect3, TRUE);
2846
2847 _assert_add (clip, effect1);
2848 _assert_add (clip, effect2);
2849 _assert_add (clip, effect3);
2850 assert_num_children (clip, 3);
2851 _assert_duration_limit (clip, GST_CLOCK_TIME_NONE);
2852 assert_equals_int (limit_notify_count, 0);
2853 assert_equals_int (duration_notify_count, 0);
2854
2855 /* no change in duration limit whilst children are not in any track */
2856 assert_set_max_duration (effect1, 20);
2857 _assert_duration_limit (clip, GST_CLOCK_TIME_NONE);
2858 assert_equals_int (limit_notify_count, 0);
2859 assert_equals_int (duration_notify_count, 0);
2860
2861 assert_set_inpoint (effect1, 5);
2862 _assert_duration_limit (clip, GST_CLOCK_TIME_NONE);
2863 assert_equals_int (limit_notify_count, 0);
2864 assert_equals_int (duration_notify_count, 0);
2865
2866 /* set a duration that will be above the duration-limit */
2867 assert_set_duration (clip, 20);
2868 assert_equals_int (duration_notify_count, 1);
2869
2870 /* add to layer to create sources */
2871 fail_unless (ges_layer_add_clip (layer, clip));
2872
2873 /* duration-limit changes once because of effect1 */
2874 _assert_duration_limit (clip, 15);
2875 assert_equals_int (limit_notify_count, 1);
2876 assert_equals_int (duration_notify_count, 2);
2877 /* duration has automatically been set to the duration-limit */
2878 CHECK_OBJECT_PROPS_MAX (clip, 0, 0, 15, GST_CLOCK_TIME_NONE);
2879
2880 assert_num_children (clip, 5);
2881 assert_num_in_track (track1, 3);
2882 assert_num_in_track (track2, 2);
2883
2884 video_source = ges_clip_find_track_element (clip, track1, GES_TYPE_SOURCE);
2885 fail_unless (video_source);
2886 gst_object_unref (video_source);
2887
2888 audio_source = ges_clip_find_track_element (clip, track2, GES_TYPE_SOURCE);
2889 fail_unless (audio_source);
2890 gst_object_unref (audio_source);
2891
2892 CHECK_OBJECT_PROPS_MAX (video_source, 0, 0, 15, GST_CLOCK_TIME_NONE);
2893 fail_unless (ges_track_element_get_track (video_source) == track1);
2894 fail_unless (ges_track_element_get_track_type (video_source) ==
2895 GES_TRACK_TYPE_VIDEO);
2896 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 0, 15, GST_CLOCK_TIME_NONE);
2897 fail_unless (ges_track_element_get_track (audio_source) == track2);
2898 fail_unless (ges_track_element_get_track_type (audio_source) ==
2899 GES_TRACK_TYPE_AUDIO);
2900 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 15, 20);
2901 fail_unless (ges_track_element_get_track (effect1) == track1);
2902 CHECK_OBJECT_PROPS_MAX (effect2, 0, 0, 15, GST_CLOCK_TIME_NONE);
2903 fail_unless (ges_track_element_get_track (effect2) == track1);
2904 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 15, GST_CLOCK_TIME_NONE);
2905 fail_unless (ges_track_element_get_track (effect3) == track2);
2906
2907 /* Make effect1 inactive, which will remove the duration-limit */
2908 fail_unless (ges_track_element_set_active (effect1, FALSE));
2909 _assert_duration_limit (clip, GST_CLOCK_TIME_NONE);
2910 assert_equals_int (limit_notify_count, 2);
2911 /* duration is unchanged */
2912 assert_equals_int (duration_notify_count, 2);
2913 CHECK_OBJECT_PROPS_MAX (clip, 0, 0, 15, GST_CLOCK_TIME_NONE);
2914 CHECK_OBJECT_PROPS_MAX (video_source, 0, 0, 15, GST_CLOCK_TIME_NONE);
2915 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 0, 15, GST_CLOCK_TIME_NONE);
2916 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 15, 20);
2917 CHECK_OBJECT_PROPS_MAX (effect2, 0, 0, 15, GST_CLOCK_TIME_NONE);
2918 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 15, GST_CLOCK_TIME_NONE);
2919
2920 /* changing the in-point does not change the duration limit whilst
2921 * there is no max-duration */
2922 assert_set_inpoint (clip, 10);
2923 _assert_duration_limit (clip, GST_CLOCK_TIME_NONE);
2924 assert_equals_int (limit_notify_count, 2);
2925 assert_equals_int (duration_notify_count, 2);
2926 CHECK_OBJECT_PROPS_MAX (clip, 0, 10, 15, GST_CLOCK_TIME_NONE);
2927 CHECK_OBJECT_PROPS_MAX (video_source, 0, 10, 15, GST_CLOCK_TIME_NONE);
2928 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 10, 15, GST_CLOCK_TIME_NONE);
2929 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 15, 20);
2930 CHECK_OBJECT_PROPS_MAX (effect2, 0, 0, 15, GST_CLOCK_TIME_NONE);
2931 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 15, GST_CLOCK_TIME_NONE);
2932
2933 assert_set_max_duration (video_source, 40);
2934 _assert_duration_limit (clip, 30);
2935 assert_equals_int (limit_notify_count, 3);
2936 assert_equals_int (duration_notify_count, 2);
2937 CHECK_OBJECT_PROPS_MAX (clip, 0, 10, 15, 40);
2938 CHECK_OBJECT_PROPS_MAX (video_source, 0, 10, 15, 40);
2939 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 10, 15, GST_CLOCK_TIME_NONE);
2940 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 15, 20);
2941 CHECK_OBJECT_PROPS_MAX (effect2, 0, 0, 15, GST_CLOCK_TIME_NONE);
2942 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 15, GST_CLOCK_TIME_NONE);
2943
2944 /* set in-point using child */
2945 assert_set_inpoint (audio_source, 15);
2946 _assert_duration_limit (clip, 25);
2947 assert_equals_int (limit_notify_count, 4);
2948 assert_equals_int (duration_notify_count, 2);
2949 CHECK_OBJECT_PROPS_MAX (clip, 0, 15, 15, 40);
2950 CHECK_OBJECT_PROPS_MAX (video_source, 0, 15, 15, 40);
2951 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 15, 15, GST_CLOCK_TIME_NONE);
2952 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 15, 20);
2953 CHECK_OBJECT_PROPS_MAX (effect2, 0, 0, 15, GST_CLOCK_TIME_NONE);
2954 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 15, GST_CLOCK_TIME_NONE);
2955
2956 /* set max-duration of core children */
2957 assert_set_max_duration (clip, 60);
2958 _assert_duration_limit (clip, 45);
2959 assert_equals_int (limit_notify_count, 5);
2960 assert_equals_int (duration_notify_count, 2);
2961 CHECK_OBJECT_PROPS_MAX (clip, 0, 15, 15, 60);
2962 CHECK_OBJECT_PROPS_MAX (video_source, 0, 15, 15, 60);
2963 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 15, 15, 60);
2964 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 15, 20);
2965 CHECK_OBJECT_PROPS_MAX (effect2, 0, 0, 15, GST_CLOCK_TIME_NONE);
2966 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 15, GST_CLOCK_TIME_NONE);
2967
2968 /* can set duration up to the limit */
2969 assert_set_duration (clip, 45);
2970 _assert_duration_limit (clip, 45);
2971 assert_equals_int (limit_notify_count, 5);
2972 assert_equals_int (duration_notify_count, 3);
2973 CHECK_OBJECT_PROPS_MAX (clip, 0, 15, 45, 60);
2974 CHECK_OBJECT_PROPS_MAX (video_source, 0, 15, 45, 60);
2975 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 15, 45, 60);
2976 /* effect1 has a duration that exceeds max-duration - in-point
2977 * ok since it is currently inactive */
2978 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 45, 20);
2979 CHECK_OBJECT_PROPS_MAX (effect2, 0, 0, 45, GST_CLOCK_TIME_NONE);
2980 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 45, GST_CLOCK_TIME_NONE);
2981
2982 /* limit the effects */
2983 assert_set_max_duration (effect2, 70);
2984 _assert_duration_limit (clip, 45);
2985 assert_equals_int (limit_notify_count, 5);
2986 assert_equals_int (duration_notify_count, 3);
2987 CHECK_OBJECT_PROPS_MAX (clip, 0, 15, 45, 60);
2988 CHECK_OBJECT_PROPS_MAX (video_source, 0, 15, 45, 60);
2989 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 15, 45, 60);
2990 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 45, 20);
2991 CHECK_OBJECT_PROPS_MAX (effect2, 0, 0, 45, 70);
2992 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 45, GST_CLOCK_TIME_NONE);
2993
2994 assert_set_inpoint (effect2, 40);
2995 _assert_duration_limit (clip, 30);
2996 assert_equals_int (limit_notify_count, 6);
2997 assert_equals_int (duration_notify_count, 4);
2998 CHECK_OBJECT_PROPS_MAX (clip, 0, 15, 30, 60);
2999 CHECK_OBJECT_PROPS_MAX (video_source, 0, 15, 30, 60);
3000 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 15, 30, 60);
3001 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 30, 20);
3002 CHECK_OBJECT_PROPS_MAX (effect2, 0, 40, 30, 70);
3003 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 30, GST_CLOCK_TIME_NONE);
3004
3005 /* no change */
3006 assert_set_max_duration (effect3, 35);
3007 _assert_duration_limit (clip, 30);
3008 assert_equals_int (limit_notify_count, 6);
3009 assert_equals_int (duration_notify_count, 4);
3010 CHECK_OBJECT_PROPS_MAX (clip, 0, 15, 30, 60);
3011 CHECK_OBJECT_PROPS_MAX (video_source, 0, 15, 30, 60);
3012 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 15, 30, 60);
3013 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 30, 20);
3014 CHECK_OBJECT_PROPS_MAX (effect2, 0, 40, 30, 70);
3015 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 30, 35);
3016
3017 /* make effect1 active again */
3018 fail_unless (ges_track_element_set_active (effect1, TRUE));
3019 _assert_duration_limit (clip, 15);
3020 assert_equals_int (limit_notify_count, 7);
3021 assert_equals_int (duration_notify_count, 5);
3022 CHECK_OBJECT_PROPS_MAX (clip, 0, 15, 15, 60);
3023 CHECK_OBJECT_PROPS_MAX (video_source, 0, 15, 15, 60);
3024 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 15, 15, 60);
3025 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 15, 20);
3026 CHECK_OBJECT_PROPS_MAX (effect2, 0, 40, 15, 70);
3027 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 15, 35);
3028
3029 /* removing effect2 from track does not change limit */
3030 fail_unless (ges_track_remove_element (track1, effect2));
3031 _assert_duration_limit (clip, 15);
3032 assert_equals_int (limit_notify_count, 7);
3033 assert_equals_int (duration_notify_count, 5);
3034 CHECK_OBJECT_PROPS_MAX (clip, 0, 15, 15, 60);
3035 CHECK_OBJECT_PROPS_MAX (video_source, 0, 15, 15, 60);
3036 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 15, 15, 60);
3037 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 15, 20);
3038 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 15, 35);
3039 /* no track */
3040 CHECK_OBJECT_PROPS_MAX (effect2, 0, 40, 15, 70);
3041
3042 /* removing effect1 does */
3043 fail_unless (ges_track_remove_element (track1, effect1));
3044 _assert_duration_limit (clip, 35);
3045 assert_equals_int (limit_notify_count, 8);
3046 assert_equals_int (duration_notify_count, 5);
3047 CHECK_OBJECT_PROPS_MAX (clip, 0, 15, 15, 60);
3048 CHECK_OBJECT_PROPS_MAX (video_source, 0, 15, 15, 60);
3049 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 15, 15, 60);
3050 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 15, 35);
3051 /* no track */
3052 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 15, 20);
3053 CHECK_OBJECT_PROPS_MAX (effect2, 0, 40, 15, 70);
3054
3055 /* add back */
3056 fail_unless (ges_track_add_element (track1, effect2));
3057 _assert_duration_limit (clip, 30);
3058 assert_equals_int (limit_notify_count, 9);
3059 assert_equals_int (duration_notify_count, 5);
3060 CHECK_OBJECT_PROPS_MAX (clip, 0, 15, 15, 60);
3061 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 15, 15, 60);
3062 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 15, 35);
3063 CHECK_OBJECT_PROPS_MAX (video_source, 0, 15, 15, 60);
3064 CHECK_OBJECT_PROPS_MAX (effect2, 0, 40, 15, 70);
3065 /* no track */
3066 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 15, 20);
3067
3068 assert_set_duration (clip, 20);
3069 _assert_duration_limit (clip, 30);
3070 assert_equals_int (limit_notify_count, 9);
3071 assert_equals_int (duration_notify_count, 6);
3072 CHECK_OBJECT_PROPS_MAX (clip, 0, 15, 20, 60);
3073 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 15, 20, 60);
3074 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 20, 35);
3075 CHECK_OBJECT_PROPS_MAX (video_source, 0, 15, 20, 60);
3076 CHECK_OBJECT_PROPS_MAX (effect2, 0, 40, 20, 70);
3077 /* no track */
3078 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 20, 20);
3079
3080 fail_unless (ges_track_add_element (track1, effect1));
3081 _assert_duration_limit (clip, 15);
3082 assert_equals_int (limit_notify_count, 10);
3083 assert_equals_int (duration_notify_count, 7);
3084 CHECK_OBJECT_PROPS_MAX (clip, 0, 15, 15, 60);
3085 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 15, 15, 60);
3086 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 15, 35);
3087 CHECK_OBJECT_PROPS_MAX (video_source, 0, 15, 15, 60);
3088 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 15, 20);
3089 CHECK_OBJECT_PROPS_MAX (effect2, 0, 40, 15, 70);
3090
3091 gst_object_ref (clip);
3092 fail_unless (ges_layer_remove_clip (layer, clip));
3093
3094 assert_num_in_track (track1, 0);
3095 assert_num_in_track (track2, 0);
3096 assert_num_children (clip, 5);
3097
3098 _assert_duration_limit (clip, GST_CLOCK_TIME_NONE);
3099 /* may have several changes in duration limit as the children are
3100 * emptied from their tracks */
3101 fail_unless (limit_notify_count > 10);
3102 assert_equals_int (duration_notify_count, 7);
3103 /* none in any track */
3104 CHECK_OBJECT_PROPS_MAX (clip, 0, 15, 15, 60);
3105 CHECK_OBJECT_PROPS_MAX (audio_source, 0, 15, 15, 60);
3106 CHECK_OBJECT_PROPS_MAX (effect3, 0, 0, 15, 35);
3107 CHECK_OBJECT_PROPS_MAX (video_source, 0, 15, 15, 60);
3108 CHECK_OBJECT_PROPS_MAX (effect1, 0, 5, 15, 20);
3109 CHECK_OBJECT_PROPS_MAX (effect2, 0, 40, 15, 70);
3110
3111 gst_object_unref (timeline);
3112 gst_object_unref (clip);
3113
3114 ges_deinit ();
3115 }
3116
3117 GST_END_TEST;
3118
3119 GST_START_TEST (test_can_set_duration_limit)
3120 {
3121 GESTimeline *timeline;
3122 GESLayer *layer;
3123 GESClip *clip;
3124 GESTrackElement *source0, *source1;
3125 GESTrackElement *effect0, *effect1, *effect2;
3126 GESTrack *track0, *track1;
3127 gint limit_notify_count = 0;
3128 GError *error = NULL;
3129
3130 ges_init ();
3131
3132 timeline = ges_timeline_new ();
3133 track0 = GES_TRACK (ges_video_track_new ());
3134 track1 = GES_TRACK (ges_audio_track_new ());
3135
3136 fail_unless (ges_timeline_add_track (timeline, track0));
3137 fail_unless (ges_timeline_add_track (timeline, track1));
3138 /* add track3 later */
3139
3140 layer = ges_timeline_append_layer (timeline);
3141
3142 /* place a dummy clip at the start of the layer */
3143 clip = GES_CLIP (ges_test_clip_new ());
3144 assert_set_start (clip, 0);
3145 assert_set_duration (clip, 20);
3146
3147 fail_unless (ges_layer_add_clip (layer, clip));
3148
3149 /* the clip we will be editing overlaps the first clip at its start */
3150 clip = GES_CLIP (ges_test_clip_new ());
3151
3152 g_signal_connect (clip, "notify::duration-limit", G_CALLBACK (_count_cb),
3153 &limit_notify_count);
3154
3155 assert_set_start (clip, 10);
3156 assert_set_duration (clip, 20);
3157
3158 fail_unless (ges_layer_add_clip (layer, clip));
3159
3160 source0 =
3161 ges_clip_find_track_element (clip, track0, GES_TYPE_VIDEO_TEST_SOURCE);
3162 source1 =
3163 ges_clip_find_track_element (clip, track1, GES_TYPE_AUDIO_TEST_SOURCE);
3164
3165 fail_unless (source0);
3166 fail_unless (source1);
3167
3168 gst_object_unref (source0);
3169 gst_object_unref (source1);
3170
3171 assert_equals_int (limit_notify_count, 0);
3172 _assert_duration_limit (clip, GST_CLOCK_TIME_NONE);
3173 CHECK_OBJECT_PROPS_MAX (clip, 10, 0, 20, GST_CLOCK_TIME_NONE);
3174 CHECK_OBJECT_PROPS_MAX (source0, 10, 0, 20, GST_CLOCK_TIME_NONE);
3175 CHECK_OBJECT_PROPS_MAX (source1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3176
3177 assert_set_inpoint (clip, 16);
3178
3179 assert_equals_int (limit_notify_count, 0);
3180 _assert_duration_limit (clip, GST_CLOCK_TIME_NONE);
3181 CHECK_OBJECT_PROPS_MAX (clip, 10, 16, 20, GST_CLOCK_TIME_NONE);
3182 CHECK_OBJECT_PROPS_MAX (source0, 10, 16, 20, GST_CLOCK_TIME_NONE);
3183 CHECK_OBJECT_PROPS_MAX (source1, 10, 16, 20, GST_CLOCK_TIME_NONE);
3184
3185 assert_set_max_duration (clip, 36);
3186
3187 assert_equals_int (limit_notify_count, 1);
3188 _assert_duration_limit (clip, 20);
3189 CHECK_OBJECT_PROPS_MAX (clip, 10, 16, 20, 36);
3190 CHECK_OBJECT_PROPS_MAX (source0, 10, 16, 20, 36);
3191 CHECK_OBJECT_PROPS_MAX (source1, 10, 16, 20, 36);
3192
3193 /* add effects */
3194 effect0 = GES_TRACK_ELEMENT (ges_effect_new ("agingtv"));
3195 effect1 = GES_TRACK_ELEMENT (ges_effect_new ("vertigotv"));
3196 effect2 = GES_TRACK_ELEMENT (ges_effect_new ("alpha"));
3197
3198 ges_track_element_set_has_internal_source (effect0, TRUE);
3199 fail_unless (ges_track_element_has_internal_source (effect1) == FALSE);
3200 ges_track_element_set_has_internal_source (effect2, TRUE);
3201
3202 assert_set_max_duration (effect0, 10);
3203 /* already set the track */
3204 fail_unless (ges_track_add_element (track0, effect0));
3205 /* cannot add because it would cause the duration-limit to go to 10,
3206 * causing a full overlap with the clip at the beginning of the layer */
3207
3208 gst_object_ref (effect0);
3209 fail_if (ges_container_add (GES_CONTAINER (clip),
3210 GES_TIMELINE_ELEMENT (effect0)));
3211
3212 assert_equals_int (limit_notify_count, 1);
3213 _assert_duration_limit (clip, 20);
3214 CHECK_OBJECT_PROPS_MAX (clip, 10, 16, 20, 36);
3215 CHECK_OBJECT_PROPS_MAX (source0, 10, 16, 20, 36);
3216 CHECK_OBJECT_PROPS_MAX (source1, 10, 16, 20, 36);
3217
3218 /* removing from the track and adding will work, but track selection
3219 * will fail */
3220 fail_unless (ges_track_remove_element (track0, effect0));
3221
3222 _assert_add (clip, effect0);
3223 fail_if (ges_track_element_get_track (effect0));
3224 gst_object_unref (effect0);
3225
3226 assert_equals_int (limit_notify_count, 1);
3227 _assert_duration_limit (clip, 20);
3228 CHECK_OBJECT_PROPS_MAX (clip, 10, 16, 20, 36);
3229 CHECK_OBJECT_PROPS_MAX (source0, 10, 16, 20, 36);
3230 CHECK_OBJECT_PROPS_MAX (source1, 10, 16, 20, 36);
3231 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 10);
3232
3233 fail_if (ges_clip_add_child_to_track (clip, effect0, track0, &error));
3234 assert_GESError (error, GES_ERROR_INVALID_OVERLAP_IN_TRACK);
3235
3236 /* set max-duration to 11 and we are fine to select a track */
3237 assert_set_max_duration (effect0, 11);
3238 assert_equals_int (limit_notify_count, 1);
3239 _assert_duration_limit (clip, 20);
3240
3241 fail_unless (ges_clip_add_child_to_track (clip, effect0, track0,
3242 &error) == effect0);
3243 fail_if (error);
3244
3245 assert_equals_int (limit_notify_count, 2);
3246 _assert_duration_limit (clip, 11);
3247 CHECK_OBJECT_PROPS_MAX (clip, 10, 16, 11, 36);
3248 CHECK_OBJECT_PROPS_MAX (source0, 10, 16, 11, 36);
3249 CHECK_OBJECT_PROPS_MAX (source1, 10, 16, 11, 36);
3250 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 11, 11);
3251
3252 /* cannot set duration above the limit */
3253 assert_fail_set_duration (clip, 12);
3254 assert_fail_set_duration (source0, 12);
3255 assert_fail_set_duration (effect0, 12);
3256
3257 /* allow the max_duration to increase again */
3258 assert_set_max_duration (effect0, 25);
3259
3260 assert_equals_int (limit_notify_count, 3);
3261 _assert_duration_limit (clip, 20);
3262 CHECK_OBJECT_PROPS_MAX (clip, 10, 16, 11, 36);
3263 CHECK_OBJECT_PROPS_MAX (source0, 10, 16, 11, 36);
3264 CHECK_OBJECT_PROPS_MAX (source1, 10, 16, 11, 36);
3265 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 11, 25);
3266
3267 assert_set_duration (clip, 20);
3268
3269 assert_equals_int (limit_notify_count, 3);
3270 _assert_duration_limit (clip, 20);
3271 CHECK_OBJECT_PROPS_MAX (clip, 10, 16, 20, 36);
3272 CHECK_OBJECT_PROPS_MAX (source0, 10, 16, 20, 36);
3273 CHECK_OBJECT_PROPS_MAX (source1, 10, 16, 20, 36);
3274 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3275
3276 /* add another effect */
3277 _assert_add (clip, effect1);
3278 fail_unless (ges_track_element_get_track (effect1) == track0);
3279
3280 assert_equals_int (limit_notify_count, 3);
3281 _assert_duration_limit (clip, 20);
3282 CHECK_OBJECT_PROPS_MAX (clip, 10, 16, 20, 36);
3283 CHECK_OBJECT_PROPS_MAX (source0, 10, 16, 20, 36);
3284 CHECK_OBJECT_PROPS_MAX (source1, 10, 16, 20, 36);
3285 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3286 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3287
3288 /* make source0 inactive and reduce its max-duration
3289 * note that this causes effect0 and effect1 to also become in-active */
3290 _assert_set_active (source0, FALSE);
3291 _assert_active (source0, FALSE);
3292 _assert_active (effect0, FALSE);
3293 _assert_active (effect1, FALSE);
3294
3295 assert_equals_int (limit_notify_count, 3);
3296 _assert_duration_limit (clip, 20);
3297 CHECK_OBJECT_PROPS_MAX (clip, 10, 16, 20, 36);
3298 CHECK_OBJECT_PROPS_MAX (source0, 10, 16, 20, 36);
3299 CHECK_OBJECT_PROPS_MAX (source1, 10, 16, 20, 36);
3300 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3301 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3302
3303 /* can set a low max duration whilst the source is inactive */
3304 assert_set_max_duration (source0, 26);
3305
3306 assert_equals_int (limit_notify_count, 3);
3307 _assert_duration_limit (clip, 20);
3308 CHECK_OBJECT_PROPS_MAX (clip, 10, 16, 20, 26);
3309 CHECK_OBJECT_PROPS_MAX (source0, 10, 16, 20, 26);
3310 CHECK_OBJECT_PROPS_MAX (source1, 10, 16, 20, 36);
3311 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3312 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3313
3314 /* add the last effect */
3315 assert_set_inpoint (effect2, 7);
3316 assert_set_max_duration (effect2, 17);
3317 _assert_active (effect2, TRUE);
3318
3319 /* safe to add because the source is inactive */
3320 assert_equals_int (limit_notify_count, 3);
3321 _assert_add (clip, effect2);
3322 assert_equals_int (limit_notify_count, 3);
3323 _assert_active (source0, FALSE);
3324 _assert_active (effect0, FALSE);
3325 _assert_active (effect1, FALSE);
3326 _assert_active (effect2, FALSE);
3327
3328 fail_unless (ges_track_element_get_track (effect2) == track0);
3329
3330 assert_equals_int (limit_notify_count, 3);
3331 _assert_duration_limit (clip, 20);
3332 CHECK_OBJECT_PROPS_MAX (clip, 10, 16, 20, 26);
3333 CHECK_OBJECT_PROPS_MAX (source0, 10, 16, 20, 26);
3334 CHECK_OBJECT_PROPS_MAX (source1, 10, 16, 20, 36);
3335 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3336 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3337 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 17);
3338
3339 /* want to make the source and its effects active again */
3340 assert_set_inpoint (source0, 6);
3341 assert_set_max_duration (effect2, 33);
3342
3343 assert_equals_int (limit_notify_count, 4);
3344 _assert_duration_limit (clip, 30);
3345 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3346 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3347 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 36);
3348 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3349 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3350 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 33);
3351
3352 _assert_set_active (source0, TRUE);
3353 _assert_set_active (effect0, TRUE);
3354 _assert_set_active (effect1, TRUE);
3355 _assert_set_active (effect2, TRUE);
3356
3357 assert_equals_int (limit_notify_count, 5);
3358 _assert_duration_limit (clip, 20);
3359 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3360 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3361 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 36);
3362 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3363 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3364 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 33);
3365
3366 /* cannot set in-point of clip to 16, nor of either source */
3367 assert_fail_set_inpoint (clip, 16);
3368 assert_fail_set_inpoint (source0, 16);
3369 assert_fail_set_inpoint (source1, 16);
3370
3371 assert_equals_int (limit_notify_count, 5);
3372 _assert_duration_limit (clip, 20);
3373 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3374 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3375 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 36);
3376 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3377 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3378 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 33);
3379
3380 /* can set just below */
3381 assert_set_inpoint (source1, 15);
3382
3383 assert_equals_int (limit_notify_count, 6);
3384 _assert_duration_limit (clip, 11);
3385 CHECK_OBJECT_PROPS_MAX (clip, 10, 15, 11, 26);
3386 CHECK_OBJECT_PROPS_MAX (source0, 10, 15, 11, 26);
3387 CHECK_OBJECT_PROPS_MAX (source1, 10, 15, 11, 36);
3388 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 11, 25);
3389 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 11, GST_CLOCK_TIME_NONE);
3390 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 11, 33);
3391
3392 assert_set_inpoint (clip, 6);
3393 assert_set_duration (clip, 20);
3394
3395 assert_equals_int (limit_notify_count, 7);
3396 _assert_duration_limit (clip, 20);
3397 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3398 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3399 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 36);
3400 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3401 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3402 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 33);
3403
3404 /* cannot set in-point of non-core in a way that would cause limit to
3405 * drop */
3406 assert_fail_set_inpoint (effect2, 23);
3407 assert_fail_set_inpoint (effect0, 15);
3408
3409 assert_equals_int (limit_notify_count, 7);
3410 _assert_duration_limit (clip, 20);
3411 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3412 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3413 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 36);
3414 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3415 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3416 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 33);
3417
3418 /* can set just below */
3419 assert_set_inpoint (effect2, 22);
3420
3421 assert_equals_int (limit_notify_count, 8);
3422 _assert_duration_limit (clip, 11);
3423 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 11, 26);
3424 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 11, 26);
3425 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 11, 36);
3426 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 11, 25);
3427 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 11, GST_CLOCK_TIME_NONE);
3428 CHECK_OBJECT_PROPS_MAX (effect2, 10, 22, 11, 33);
3429
3430 assert_set_inpoint (effect2, 7);
3431 assert_set_duration (clip, 20);
3432
3433 assert_equals_int (limit_notify_count, 9);
3434 _assert_duration_limit (clip, 20);
3435 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3436 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3437 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 36);
3438 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3439 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3440 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 33);
3441
3442 /* same but with max-duration */
3443
3444 /* core */
3445 assert_fail_set_max_duration (clip, 16);
3446 assert_fail_set_max_duration (source0, 16);
3447 assert_fail_set_max_duration (source1, 16);
3448
3449 assert_equals_int (limit_notify_count, 9);
3450 _assert_duration_limit (clip, 20);
3451 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3452 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3453 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 36);
3454 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3455 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3456 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 33);
3457
3458 assert_set_max_duration (source1, 17);
3459
3460 assert_equals_int (limit_notify_count, 10);
3461 _assert_duration_limit (clip, 11);
3462 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 11, 17);
3463 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 11, 26);
3464 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 11, 17);
3465 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 11, 25);
3466 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 11, GST_CLOCK_TIME_NONE);
3467 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 11, 33);
3468
3469 assert_set_max_duration (source1, 30);
3470 assert_set_duration (clip, 20);
3471
3472 assert_equals_int (limit_notify_count, 11);
3473 _assert_duration_limit (clip, 20);
3474 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3475 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3476 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 30);
3477 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3478 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3479 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 33);
3480
3481 assert_set_max_duration (clip, 17);
3482
3483 assert_equals_int (limit_notify_count, 12);
3484 _assert_duration_limit (clip, 11);
3485 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 11, 17);
3486 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 11, 17);
3487 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 11, 17);
3488 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 11, 25);
3489 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 11, GST_CLOCK_TIME_NONE);
3490 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 11, 33);
3491
3492 assert_set_max_duration (clip, 26);
3493 assert_set_duration (clip, 20);
3494
3495 assert_equals_int (limit_notify_count, 13);
3496 _assert_duration_limit (clip, 20);
3497 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3498 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3499 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 26);
3500 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3501 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3502 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 33);
3503
3504 /* non-core */
3505 assert_fail_set_max_duration (effect0, 10);
3506 assert_fail_set_max_duration (effect2, 17);
3507
3508 assert_equals_int (limit_notify_count, 13);
3509 _assert_duration_limit (clip, 20);
3510 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3511 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3512 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 26);
3513 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3514 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3515 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 33);
3516
3517 assert_set_max_duration (effect2, 18);
3518
3519 assert_equals_int (limit_notify_count, 14);
3520 _assert_duration_limit (clip, 11);
3521 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 11, 26);
3522 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 11, 26);
3523 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 11, 26);
3524 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 11, 25);
3525 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 11, GST_CLOCK_TIME_NONE);
3526 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 11, 18);
3527
3528 assert_set_max_duration (effect2, 33);
3529 assert_set_duration (clip, 20);
3530
3531 assert_equals_int (limit_notify_count, 15);
3532 _assert_duration_limit (clip, 20);
3533 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3534 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3535 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 26);
3536 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3537 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3538 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 33);
3539
3540 /* test setting active */
3541 _assert_active (effect2, TRUE);
3542 _assert_set_active (effect2, FALSE);
3543 assert_set_max_duration (effect2, 17);
3544
3545 assert_equals_int (limit_notify_count, 15);
3546 _assert_duration_limit (clip, 20);
3547 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3548 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3549 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 26);
3550 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3551 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3552 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 17);
3553
3554 fail_if (ges_track_element_set_active (effect2, TRUE));
3555
3556 assert_equals_int (limit_notify_count, 15);
3557 _assert_duration_limit (clip, 20);
3558 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3559 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3560 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 26);
3561 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3562 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3563 CHECK_OBJECT_PROPS_MAX (effect2, 10, 7, 20, 17);
3564
3565 assert_set_inpoint (effect2, 6);
3566 _assert_set_active (effect2, TRUE);
3567
3568 assert_equals_int (limit_notify_count, 16);
3569 _assert_duration_limit (clip, 11);
3570 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 11, 26);
3571 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 11, 26);
3572 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 11, 26);
3573 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 11, 25);
3574 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 11, GST_CLOCK_TIME_NONE);
3575 CHECK_OBJECT_PROPS_MAX (effect2, 10, 6, 11, 17);
3576
3577 /* make source0 in-active */
3578 _assert_active (source0, TRUE);
3579 _assert_set_active (source0, FALSE);
3580 _assert_active (source0, FALSE);
3581 _assert_active (effect0, FALSE);
3582 _assert_active (effect1, FALSE);
3583 _assert_active (effect2, FALSE);
3584
3585 assert_set_duration (source0, 20);
3586
3587 assert_equals_int (limit_notify_count, 17);
3588 _assert_duration_limit (clip, 20);
3589 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 26);
3590 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 26);
3591 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 26);
3592 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3593 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3594 CHECK_OBJECT_PROPS_MAX (effect2, 10, 6, 20, 17);
3595
3596 /* lower duration-limit for source for when it becomes active */
3597 assert_set_max_duration (source0, 16);
3598
3599 assert_equals_int (limit_notify_count, 17);
3600 _assert_duration_limit (clip, 20);
3601 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 16);
3602 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 16);
3603 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 26);
3604 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3605 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3606 CHECK_OBJECT_PROPS_MAX (effect2, 10, 6, 20, 17);
3607
3608 /* cannot make the source active */
3609 fail_if (ges_track_element_set_active (source0, TRUE));
3610
3611 assert_equals_int (limit_notify_count, 17);
3612 _assert_duration_limit (clip, 20);
3613 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 16);
3614 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 16);
3615 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 26);
3616 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3617 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3618 CHECK_OBJECT_PROPS_MAX (effect2, 10, 6, 20, 17);
3619
3620 /* nor can we make the effects active because this would activate the
3621 * source */
3622 fail_if (ges_track_element_set_active (effect0, TRUE));
3623 fail_if (ges_track_element_set_active (effect1, TRUE));
3624 fail_if (ges_track_element_set_active (effect2, TRUE));
3625
3626 assert_equals_int (limit_notify_count, 17);
3627 _assert_duration_limit (clip, 20);
3628 CHECK_OBJECT_PROPS_MAX (clip, 10, 6, 20, 16);
3629 CHECK_OBJECT_PROPS_MAX (source0, 10, 6, 20, 16);
3630 CHECK_OBJECT_PROPS_MAX (source1, 10, 6, 20, 26);
3631 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3632 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3633 CHECK_OBJECT_PROPS_MAX (effect2, 10, 6, 20, 17);
3634
3635 /* allow it to just succeed */
3636 assert_set_inpoint (source0, 5);
3637
3638 assert_equals_int (limit_notify_count, 18);
3639 _assert_duration_limit (clip, 21);
3640 CHECK_OBJECT_PROPS_MAX (clip, 10, 5, 20, 16);
3641 CHECK_OBJECT_PROPS_MAX (source0, 10, 5, 20, 16);
3642 CHECK_OBJECT_PROPS_MAX (source1, 10, 5, 20, 26);
3643 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 20, 25);
3644 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 20, GST_CLOCK_TIME_NONE);
3645 CHECK_OBJECT_PROPS_MAX (effect2, 10, 6, 20, 17);
3646
3647 _assert_set_active (effect1, TRUE);
3648
3649 assert_equals_int (limit_notify_count, 19);
3650 _assert_duration_limit (clip, 11);
3651 CHECK_OBJECT_PROPS_MAX (clip, 10, 5, 11, 16);
3652 CHECK_OBJECT_PROPS_MAX (source0, 10, 5, 11, 16);
3653 CHECK_OBJECT_PROPS_MAX (source1, 10, 5, 11, 26);
3654 CHECK_OBJECT_PROPS_MAX (effect0, 10, 0, 11, 25);
3655 CHECK_OBJECT_PROPS_MAX (effect1, 10, 0, 11, GST_CLOCK_TIME_NONE);
3656 CHECK_OBJECT_PROPS_MAX (effect2, 10, 6, 11, 17);
3657
3658 gst_object_unref (timeline);
3659
3660 ges_deinit ();
3661 }
3662
3663 GST_END_TEST;
3664
3665 #define _assert_set_rate(element, prop_name, rate, val) \
3666 { \
3667 GError *error = NULL; \
3668 if (G_VALUE_TYPE (&val) == G_TYPE_DOUBLE) \
3669 g_value_set_double (&val, rate); \
3670 else if (G_VALUE_TYPE (&val) == G_TYPE_FLOAT) \
3671 g_value_set_float (&val, rate); \
3672 \
3673 fail_unless (ges_timeline_element_set_child_property_full ( \
3674 GES_TIMELINE_ELEMENT (element), prop_name, &val, &error)); \
3675 fail_if (error); \
3676 g_value_reset (&val); \
3677 }
3678
3679 #define _assert_fail_set_rate(element, prop_name, rate, val, code) \
3680 { \
3681 GError * error = NULL; \
3682 if (G_VALUE_TYPE (&val) == G_TYPE_DOUBLE) \
3683 g_value_set_double (&val, rate); \
3684 else if (G_VALUE_TYPE (&val) == G_TYPE_FLOAT) \
3685 g_value_set_float (&val, rate); \
3686 \
3687 fail_if (ges_timeline_element_set_child_property_full ( \
3688 GES_TIMELINE_ELEMENT (element), prop_name, &val, &error)); \
3689 assert_GESError (error, code); \
3690 g_value_reset (&val); \
3691 }
3692
3693 #define _assert_rate_equal(element, prop_name, rate, val) \
3694 { \
3695 gdouble found = -1.0; \
3696 fail_unless (ges_timeline_element_get_child_property ( \
3697 GES_TIMELINE_ELEMENT (element), prop_name, &val)); \
3698 \
3699 if (G_VALUE_TYPE (&val) == G_TYPE_DOUBLE) \
3700 found = g_value_get_double (&val); \
3701 else if (G_VALUE_TYPE (&val) == G_TYPE_FLOAT) \
3702 found = g_value_get_float (&val); \
3703 \
3704 fail_unless (found == rate, "found %s: %g != expected: %g", found, \
3705 prop_name, rate); \
3706 g_value_reset (&val); \
3707 }
3708
3709 GST_START_TEST (test_rate_effects_duration_limit)
3710 {
3711 GESTimeline *timeline;
3712 GESLayer *layer;
3713 GESClip *clip;
3714 GESTrackElement *source0, *source1;
3715 GESTrackElement *overlay0, *overlay1, *videorate, *pitch;
3716 GESTrack *track0, *track1;
3717 gint limit_notify_count = 0;
3718 GValue fval = G_VALUE_INIT;
3719 GValue dval = G_VALUE_INIT;
3720
3721 ges_init ();
3722
3723 g_value_init (&fval, G_TYPE_FLOAT);
3724 g_value_init (&dval, G_TYPE_DOUBLE);
3725
3726 timeline = ges_timeline_new ();
3727 track0 = GES_TRACK (ges_video_track_new ());
3728 track1 = GES_TRACK (ges_audio_track_new ());
3729
3730 fail_unless (ges_timeline_add_track (timeline, track0));
3731 fail_unless (ges_timeline_add_track (timeline, track1));
3732
3733 layer = ges_timeline_append_layer (timeline);
3734
3735 /* place a dummy clip at the start of the layer */
3736 clip = GES_CLIP (ges_test_clip_new ());
3737 assert_set_start (clip, 0);
3738 assert_set_duration (clip, 26);
3739
3740 fail_unless (ges_layer_add_clip (layer, clip));
3741
3742 /* the clip we will be editing overlaps first clip by 16 at its start */
3743 clip = GES_CLIP (ges_test_clip_new ());
3744
3745 g_signal_connect (clip, "notify::duration-limit", G_CALLBACK (_count_cb),
3746 &limit_notify_count);
3747
3748 assert_set_start (clip, 10);
3749 assert_set_duration (clip, 64);
3750
3751 fail_unless (ges_layer_add_clip (layer, clip));
3752
3753 source0 =
3754 ges_clip_find_track_element (clip, track0, GES_TYPE_VIDEO_TEST_SOURCE);
3755 source1 =
3756 ges_clip_find_track_element (clip, track1, GES_TYPE_AUDIO_TEST_SOURCE);
3757
3758 fail_unless (source0);
3759 fail_unless (source1);
3760
3761 gst_object_unref (source0);
3762 gst_object_unref (source1);
3763
3764 assert_equals_int (limit_notify_count, 0);
3765 _assert_duration_limit (clip, GST_CLOCK_TIME_NONE);
3766 CHECK_OBJECT_PROPS_MAX (clip, 10, 0, 64, GST_CLOCK_TIME_NONE);
3767 CHECK_OBJECT_PROPS_MAX (source0, 10, 0, 64, GST_CLOCK_TIME_NONE);
3768 CHECK_OBJECT_PROPS_MAX (source1, 10, 0, 64, GST_CLOCK_TIME_NONE);
3769
3770 assert_set_inpoint (clip, 13);
3771
3772 assert_equals_int (limit_notify_count, 0);
3773 _assert_duration_limit (clip, GST_CLOCK_TIME_NONE);
3774 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, GST_CLOCK_TIME_NONE);
3775 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, GST_CLOCK_TIME_NONE);
3776 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, GST_CLOCK_TIME_NONE);
3777
3778 assert_set_max_duration (clip, 77);
3779
3780 assert_equals_int (limit_notify_count, 1);
3781 _assert_duration_limit (clip, 64);
3782 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
3783 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
3784 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, 77);
3785
3786 /* add effects */
3787 overlay0 = GES_TRACK_ELEMENT (ges_effect_new ("textoverlay"));
3788 ges_track_element_set_has_internal_source (overlay0, TRUE);
3789
3790 videorate = GES_TRACK_ELEMENT (ges_effect_new ("videorate"));
3791 fail_unless (ges_base_effect_is_time_effect (GES_BASE_EFFECT (videorate)));
3792
3793 overlay1 = GES_TRACK_ELEMENT (ges_effect_new ("textoverlay"));
3794 ges_track_element_set_has_internal_source (overlay1, TRUE);
3795
3796 pitch = GES_TRACK_ELEMENT (ges_effect_new ("pitch"));
3797 fail_unless (ges_base_effect_is_time_effect (GES_BASE_EFFECT (pitch)));
3798
3799 /* add overlay1 at highest priority */
3800 _assert_add (clip, overlay1);
3801
3802 assert_equals_int (limit_notify_count, 1);
3803 _assert_duration_limit (clip, 64);
3804 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
3805 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
3806 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, 77);
3807 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 64, GST_CLOCK_TIME_NONE);
3808
3809 _assert_set_rate (videorate, "rate", 4.0, dval);
3810 _assert_rate_equal (videorate, "rate", 4.0, dval);
3811 fail_unless (ges_track_add_element (track0, videorate));
3812
3813 /* cannot add videorate as it would cause the duration-limit to drop
3814 * to 16, causing a full overlap */
3815 /* track keeps alive */
3816 fail_if (ges_container_add (GES_CONTAINER (clip),
3817 GES_TIMELINE_ELEMENT (videorate)));
3818
3819 /* setting to 1.0 makes it work again */
3820 _assert_set_rate (videorate, "rate", 1.0, dval);
3821 _assert_add (clip, videorate);
3822
3823 assert_equals_int (limit_notify_count, 1);
3824 _assert_duration_limit (clip, 64);
3825 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
3826 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
3827 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, 77);
3828 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 64, GST_CLOCK_TIME_NONE);
3829 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 64, GST_CLOCK_TIME_NONE);
3830 _assert_rate_equal (videorate, "rate", 1.0, dval);
3831
3832 /* add second overlay at lower priority */
3833 _assert_add (clip, overlay0);
3834
3835 assert_equals_int (limit_notify_count, 1);
3836 _assert_duration_limit (clip, 64);
3837 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
3838 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
3839 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, 77);
3840 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 0, 64, GST_CLOCK_TIME_NONE);
3841 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 64, GST_CLOCK_TIME_NONE);
3842 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 64, GST_CLOCK_TIME_NONE);
3843 _assert_rate_equal (videorate, "rate", 1.0, dval);
3844
3845 /* also add a pitch element in another track */
3846 _assert_add (clip, pitch);
3847 _assert_set_rate (pitch, "rate", 1.0, fval);
3848 _assert_set_rate (pitch, "tempo", 1.0, fval);
3849
3850 assert_equals_int (limit_notify_count, 1);
3851 _assert_duration_limit (clip, 64);
3852 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
3853 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
3854 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, 77);
3855 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 0, 64, GST_CLOCK_TIME_NONE);
3856 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 64, GST_CLOCK_TIME_NONE);
3857 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 64, GST_CLOCK_TIME_NONE);
3858 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 64, GST_CLOCK_TIME_NONE);
3859 _assert_rate_equal (videorate, "rate", 1.0, dval);
3860 _assert_rate_equal (pitch, "rate", 1.0, fval);
3861 _assert_rate_equal (pitch, "tempo", 1.0, fval);
3862
3863 fail_unless (ges_track_element_get_track (overlay0) == track0);
3864 fail_unless (ges_track_element_get_track (videorate) == track0);
3865 fail_unless (ges_track_element_get_track (overlay1) == track0);
3866 fail_unless (ges_track_element_get_track (pitch) == track1);
3867
3868 /* flow in track0:
3869 * source0 -> overlay0 -> videorate -> overlay1 -> timeline output
3870 *
3871 * flow in track1:
3872 * source1 -> pitch -> timeline output
3873 */
3874
3875 /* cannot set the rates to 4.0 since this would cause a full overlap */
3876 _assert_fail_set_rate (videorate, "rate", 4.0, dval,
3877 GES_ERROR_INVALID_OVERLAP_IN_TRACK);
3878 _assert_fail_set_rate (pitch, "rate", 4.0, fval,
3879 GES_ERROR_INVALID_OVERLAP_IN_TRACK);
3880 _assert_fail_set_rate (pitch, "tempo", 4.0, fval,
3881 GES_ERROR_INVALID_OVERLAP_IN_TRACK);
3882
3883 assert_equals_int (limit_notify_count, 1);
3884 _assert_duration_limit (clip, 64);
3885 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
3886 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
3887 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, 77);
3888 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 0, 64, GST_CLOCK_TIME_NONE);
3889 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 64, GST_CLOCK_TIME_NONE);
3890 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 64, GST_CLOCK_TIME_NONE);
3891 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 64, GST_CLOCK_TIME_NONE);
3892 _assert_rate_equal (videorate, "rate", 1.0, dval);
3893 _assert_rate_equal (pitch, "rate", 1.0, fval);
3894 _assert_rate_equal (pitch, "tempo", 1.0, fval);
3895
3896 /* limit overlay0 */
3897 assert_set_max_duration (overlay0, 91);
3898
3899 assert_equals_int (limit_notify_count, 1);
3900 _assert_duration_limit (clip, 64);
3901 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
3902 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
3903 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, 77);
3904 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 0, 64, 91);
3905 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 64, GST_CLOCK_TIME_NONE);
3906 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 64, GST_CLOCK_TIME_NONE);
3907 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 64, GST_CLOCK_TIME_NONE);
3908 _assert_rate_equal (videorate, "rate", 1.0, dval);
3909 _assert_rate_equal (pitch, "rate", 1.0, fval);
3910 _assert_rate_equal (pitch, "tempo", 1.0, fval);
3911
3912 assert_set_inpoint (overlay0, 59);
3913
3914 assert_equals_int (limit_notify_count, 2);
3915 _assert_duration_limit (clip, 32);
3916 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 32, 77);
3917 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 32, 77);
3918 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 32, 77);
3919 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 32, 91);
3920 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 32, GST_CLOCK_TIME_NONE);
3921 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 32, GST_CLOCK_TIME_NONE);
3922 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 32, GST_CLOCK_TIME_NONE);
3923 _assert_rate_equal (videorate, "rate", 1.0, dval);
3924 _assert_rate_equal (pitch, "rate", 1.0, fval);
3925 _assert_rate_equal (pitch, "tempo", 1.0, fval);
3926
3927 /* can set pitch rate to 2.0, but not videorate rate because videorate
3928 * shares a track with overlay0 */
3929
3930 _assert_set_rate (pitch, "rate", 2.0, fval);
3931 assert_equals_int (limit_notify_count, 2);
3932 _assert_fail_set_rate (videorate, "rate", 2.0, dval,
3933 GES_ERROR_INVALID_OVERLAP_IN_TRACK);
3934 assert_equals_int (limit_notify_count, 2);
3935 /* can't set tempo to 2.0 since overall effect would bring duration
3936 * limit too low */
3937 _assert_fail_set_rate (pitch, "tempo", 2.0, fval,
3938 GES_ERROR_INVALID_OVERLAP_IN_TRACK);
3939
3940 assert_equals_int (limit_notify_count, 2);
3941 _assert_duration_limit (clip, 32);
3942 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 32, 77);
3943 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 32, 77);
3944 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 32, 77);
3945 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 32, 91);
3946 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 32, GST_CLOCK_TIME_NONE);
3947 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 32, GST_CLOCK_TIME_NONE);
3948 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 32, GST_CLOCK_TIME_NONE);
3949 _assert_rate_equal (videorate, "rate", 1.0, dval);
3950 _assert_rate_equal (pitch, "rate", 2.0, fval);
3951 _assert_rate_equal (pitch, "tempo", 1.0, fval);
3952
3953 /* cannot set in-point of clip because pitch would cause limit to go
3954 * to 16 */
3955 assert_fail_set_inpoint (clip, 45);
3956 /* same for max-duration of source1 */
3957 assert_fail_set_max_duration (source1, 45);
3958
3959 assert_equals_int (limit_notify_count, 2);
3960 _assert_duration_limit (clip, 32);
3961 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 32, 77);
3962 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 32, 77);
3963 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 32, 77);
3964 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 32, 91);
3965 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 32, GST_CLOCK_TIME_NONE);
3966 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 32, GST_CLOCK_TIME_NONE);
3967 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 32, GST_CLOCK_TIME_NONE);
3968 _assert_rate_equal (videorate, "rate", 1.0, dval);
3969 _assert_rate_equal (pitch, "rate", 2.0, fval);
3970 _assert_rate_equal (pitch, "tempo", 1.0, fval);
3971
3972 /* can set rate to 0.5 */
3973 _assert_set_rate (videorate, "rate", 0.5, dval);
3974
3975 /* no change yet, since pitch rate is still 2.0 */
3976 assert_equals_int (limit_notify_count, 2);
3977 _assert_duration_limit (clip, 32);
3978 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 32, 77);
3979 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 32, 77);
3980 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 32, 77);
3981 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 32, 91);
3982 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 32, GST_CLOCK_TIME_NONE);
3983 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 32, GST_CLOCK_TIME_NONE);
3984 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 32, GST_CLOCK_TIME_NONE);
3985 _assert_rate_equal (videorate, "rate", 0.5, dval);
3986 _assert_rate_equal (pitch, "rate", 2.0, fval);
3987 _assert_rate_equal (pitch, "tempo", 1.0, fval);
3988
3989 _assert_set_rate (pitch, "rate", 0.5, fval);
3990
3991 assert_equals_int (limit_notify_count, 3);
3992 /* duration-limit is 64 because overlay0 only has 32 nanoseconds of
3993 * content, stretched to 64 by videorate */
3994 _assert_duration_limit (clip, 64);
3995 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 32, 77);
3996 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 32, 77);
3997 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 32, 77);
3998 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 32, 91);
3999 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 32, GST_CLOCK_TIME_NONE);
4000 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 32, GST_CLOCK_TIME_NONE);
4001 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 32, GST_CLOCK_TIME_NONE);
4002 _assert_rate_equal (videorate, "rate", 0.5, dval);
4003 _assert_rate_equal (pitch, "rate", 0.5, fval);
4004 _assert_rate_equal (pitch, "tempo", 1.0, fval);
4005
4006 /* setting the max-duration of the sources does not change the limit
4007 * since the limit on overlay0 is fine.
4008 * Note that pitch handles the unlimited duration (GST_CLOCK_TIME_NONE)
4009 * without any problems */
4010 assert_set_max_duration (clip, GST_CLOCK_TIME_NONE);
4011
4012 assert_equals_int (limit_notify_count, 3);
4013 _assert_duration_limit (clip, 64);
4014 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 32, GST_CLOCK_TIME_NONE);
4015 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 32, GST_CLOCK_TIME_NONE);
4016 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 32, GST_CLOCK_TIME_NONE);
4017 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 32, 91);
4018 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 32, GST_CLOCK_TIME_NONE);
4019 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 32, GST_CLOCK_TIME_NONE);
4020 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 32, GST_CLOCK_TIME_NONE);
4021 _assert_rate_equal (videorate, "rate", 0.5, dval);
4022 _assert_rate_equal (pitch, "rate", 0.5, fval);
4023 _assert_rate_equal (pitch, "tempo", 1.0, fval);
4024
4025 assert_set_max_duration (clip, 77);
4026
4027 assert_equals_int (limit_notify_count, 3);
4028 _assert_duration_limit (clip, 64);
4029 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 32, 77);
4030 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 32, 77);
4031 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 32, 77);
4032 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 32, 91);
4033 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 32, GST_CLOCK_TIME_NONE);
4034 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 32, GST_CLOCK_TIME_NONE);
4035 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 32, GST_CLOCK_TIME_NONE);
4036 _assert_rate_equal (videorate, "rate", 0.5, dval);
4037 _assert_rate_equal (pitch, "rate", 0.5, fval);
4038 _assert_rate_equal (pitch, "tempo", 1.0, fval);
4039
4040 /* limit overlay1. It should not be changes by the videorate element
4041 * since it acts at a lower priority
4042 * first make it last longer, so no change in duration-limit */
4043
4044 assert_set_max_duration (overlay1, 81);
4045
4046 assert_equals_int (limit_notify_count, 3);
4047 _assert_duration_limit (clip, 64);
4048 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 32, 77);
4049 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 32, 77);
4050 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 32, 77);
4051 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 32, 91);
4052 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 32, GST_CLOCK_TIME_NONE);
4053 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 0, 32, 81);
4054 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 32, GST_CLOCK_TIME_NONE);
4055 _assert_rate_equal (videorate, "rate", 0.5, dval);
4056 _assert_rate_equal (pitch, "rate", 0.5, fval);
4057 _assert_rate_equal (pitch, "tempo", 1.0, fval);
4058
4059 /* now make it shorter */
4060 assert_set_inpoint (overlay1, 51);
4061
4062 assert_equals_int (limit_notify_count, 4);
4063 _assert_duration_limit (clip, 30);
4064 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 30, 77);
4065 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 30, 77);
4066 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 30, 77);
4067 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 30, 91);
4068 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 30, GST_CLOCK_TIME_NONE);
4069 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 51, 30, 81);
4070 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 30, GST_CLOCK_TIME_NONE);
4071 _assert_rate_equal (videorate, "rate", 0.5, dval);
4072 _assert_rate_equal (pitch, "rate", 0.5, fval);
4073 _assert_rate_equal (pitch, "tempo", 1.0, fval);
4074
4075 /* remove the overlay0 limit */
4076 assert_set_max_duration (overlay0, GST_CLOCK_TIME_NONE);
4077
4078 /* no change because of overlay1 */
4079 assert_equals_int (limit_notify_count, 4);
4080 _assert_duration_limit (clip, 30);
4081 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 30, 77);
4082 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 30, 77);
4083 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 30, 77);
4084 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 30, GST_CLOCK_TIME_NONE);
4085 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 30, GST_CLOCK_TIME_NONE);
4086 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 51, 30, 81);
4087 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 30, GST_CLOCK_TIME_NONE);
4088 _assert_rate_equal (videorate, "rate", 0.5, dval);
4089 _assert_rate_equal (pitch, "rate", 0.5, fval);
4090 _assert_rate_equal (pitch, "tempo", 1.0, fval);
4091
4092 assert_set_max_duration (overlay1, GST_CLOCK_TIME_NONE);
4093
4094 assert_equals_int (limit_notify_count, 5);
4095 _assert_duration_limit (clip, 128);
4096 /* can set up to the limit */
4097 assert_set_duration (clip, 128);
4098
4099 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 128, 77);
4100 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 128, 77);
4101 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 128, 77);
4102 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 128, GST_CLOCK_TIME_NONE);
4103 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 128, GST_CLOCK_TIME_NONE);
4104 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 51, 128, GST_CLOCK_TIME_NONE);
4105 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 128, GST_CLOCK_TIME_NONE);
4106 _assert_rate_equal (videorate, "rate", 0.5, dval);
4107 _assert_rate_equal (pitch, "rate", 0.5, fval);
4108 _assert_rate_equal (pitch, "tempo", 1.0, fval);
4109
4110 /* tempo contributes the same factor as rate */
4111
4112 _assert_set_rate (pitch, "tempo", 2.0, fval);
4113
4114 assert_equals_int (limit_notify_count, 6);
4115 _assert_duration_limit (clip, 64);
4116 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
4117 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
4118 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, 77);
4119 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 64, GST_CLOCK_TIME_NONE);
4120 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 64, GST_CLOCK_TIME_NONE);
4121 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 51, 64, GST_CLOCK_TIME_NONE);
4122 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 64, GST_CLOCK_TIME_NONE);
4123 _assert_rate_equal (videorate, "rate", 0.5, dval);
4124 _assert_rate_equal (pitch, "rate", 0.5, fval);
4125 _assert_rate_equal (pitch, "tempo", 2.0, fval);
4126
4127 _assert_set_rate (videorate, "rate", 0.1, dval);
4128 assert_equals_int (limit_notify_count, 6);
4129 _assert_set_rate (pitch, "tempo", 0.5, fval);
4130
4131 assert_equals_int (limit_notify_count, 7);
4132 _assert_duration_limit (clip, 256);
4133 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
4134 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
4135 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, 77);
4136 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 64, GST_CLOCK_TIME_NONE);
4137 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 64, GST_CLOCK_TIME_NONE);
4138 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 51, 64, GST_CLOCK_TIME_NONE);
4139 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 64, GST_CLOCK_TIME_NONE);
4140 _assert_rate_equal (videorate, "rate", 0.1, dval);
4141 _assert_rate_equal (pitch, "rate", 0.5, fval);
4142 _assert_rate_equal (pitch, "tempo", 0.5, fval);
4143
4144 _assert_set_rate (pitch, "tempo", 1.0, fval);
4145 assert_equals_int (limit_notify_count, 8);
4146 _assert_set_rate (videorate, "rate", 0.5, dval);
4147
4148 assert_equals_int (limit_notify_count, 8);
4149 _assert_duration_limit (clip, 128);
4150 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
4151 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
4152 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, 77);
4153 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 64, GST_CLOCK_TIME_NONE);
4154 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 64, GST_CLOCK_TIME_NONE);
4155 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 51, 64, GST_CLOCK_TIME_NONE);
4156 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 64, GST_CLOCK_TIME_NONE);
4157 _assert_rate_equal (videorate, "rate", 0.5, dval);
4158 _assert_rate_equal (pitch, "rate", 0.5, fval);
4159 _assert_rate_equal (pitch, "tempo", 1.0, fval);
4160
4161 /* make videorate in-active */
4162 fail_unless (ges_track_element_set_active (videorate, FALSE));
4163
4164 assert_equals_int (limit_notify_count, 9);
4165 _assert_duration_limit (clip, 64);
4166 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
4167 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
4168 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, 77);
4169 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 64, GST_CLOCK_TIME_NONE);
4170 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 64, GST_CLOCK_TIME_NONE);
4171 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 51, 64, GST_CLOCK_TIME_NONE);
4172 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 64, GST_CLOCK_TIME_NONE);
4173 _assert_rate_equal (videorate, "rate", 0.5, dval);
4174 _assert_rate_equal (pitch, "rate", 0.5, fval);
4175 _assert_rate_equal (pitch, "tempo", 1.0, fval);
4176
4177 fail_unless (ges_track_element_set_active (videorate, TRUE));
4178
4179 assert_equals_int (limit_notify_count, 10);
4180 _assert_duration_limit (clip, 128);
4181 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
4182 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
4183 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, 77);
4184 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 64, GST_CLOCK_TIME_NONE);
4185 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 64, GST_CLOCK_TIME_NONE);
4186 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 51, 64, GST_CLOCK_TIME_NONE);
4187 CHECK_OBJECT_PROPS_MAX (pitch, 10, 0, 64, GST_CLOCK_TIME_NONE);
4188 _assert_rate_equal (videorate, "rate", 0.5, dval);
4189 _assert_rate_equal (pitch, "rate", 0.5, fval);
4190 _assert_rate_equal (pitch, "tempo", 1.0, fval);
4191
4192 /* removing pitch, same effect as making inactive */
4193 _assert_remove (clip, pitch);
4194
4195 assert_equals_int (limit_notify_count, 11);
4196 _assert_duration_limit (clip, 64);
4197 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
4198 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
4199 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, 77);
4200 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 64, GST_CLOCK_TIME_NONE);
4201 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 64, GST_CLOCK_TIME_NONE);
4202 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 51, 64, GST_CLOCK_TIME_NONE);
4203 _assert_rate_equal (videorate, "rate", 0.5, dval);
4204
4205 /* no max-duration will give unlimited limit */
4206 assert_set_max_duration (source1, GST_CLOCK_TIME_NONE);
4207
4208 assert_equals_int (limit_notify_count, 12);
4209 _assert_duration_limit (clip, 128);
4210 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, 77);
4211 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, 77);
4212 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, GST_CLOCK_TIME_NONE);
4213 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 64, GST_CLOCK_TIME_NONE);
4214 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 64, GST_CLOCK_TIME_NONE);
4215 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 51, 64, GST_CLOCK_TIME_NONE);
4216 _assert_rate_equal (videorate, "rate", 0.5, dval);
4217
4218 assert_set_max_duration (source0, GST_CLOCK_TIME_NONE);
4219
4220 assert_equals_int (limit_notify_count, 13);
4221 _assert_duration_limit (clip, GST_CLOCK_TIME_NONE);
4222 CHECK_OBJECT_PROPS_MAX (clip, 10, 13, 64, GST_CLOCK_TIME_NONE);
4223 CHECK_OBJECT_PROPS_MAX (source0, 10, 13, 64, GST_CLOCK_TIME_NONE);
4224 CHECK_OBJECT_PROPS_MAX (source1, 10, 13, 64, GST_CLOCK_TIME_NONE);
4225 CHECK_OBJECT_PROPS_MAX (overlay0, 10, 59, 64, GST_CLOCK_TIME_NONE);
4226 CHECK_OBJECT_PROPS_MAX (videorate, 10, 0, 64, GST_CLOCK_TIME_NONE);
4227 CHECK_OBJECT_PROPS_MAX (overlay1, 10, 51, 64, GST_CLOCK_TIME_NONE);
4228 _assert_rate_equal (videorate, "rate", 0.5, dval);
4229
4230 gst_object_unref (timeline);
4231
4232 g_value_unset (&fval);
4233 g_value_unset (&dval);
4234
4235 ges_deinit ();
4236 }
4237
4238 GST_END_TEST;
4239
4240
4241 GST_START_TEST (test_children_properties_contain)
4242 {
4243 GESTimeline *timeline;
4244 GESLayer *layer;
4245 GESClip *clip;
4246 GList *tmp;
4247 GParamSpec **clips_child_props, **childrens_child_props = NULL;
4248 guint num_clips_props, num_childrens_props = 0;
4249
4250 ges_init ();
4251
4252 timeline = ges_timeline_new_audio_video ();
4253 layer = ges_timeline_append_layer (timeline);
4254 clip = GES_CLIP (ges_test_clip_new ());
4255 assert_set_duration (clip, 50);
4256
4257 fail_unless (ges_layer_add_clip (layer, clip));
4258
4259 clips_child_props =
4260 ges_timeline_element_list_children_properties (GES_TIMELINE_ELEMENT
4261 (clip), &num_clips_props);
4262 fail_unless (clips_child_props);
4263 fail_unless (num_clips_props);
4264
4265 fail_unless (GES_CONTAINER_CHILDREN (clip));
4266
4267 for (tmp = GES_CONTAINER_CHILDREN (clip); tmp; tmp = tmp->next)
4268 childrens_child_props =
4269 append_children_properties (childrens_child_props, tmp->data,
4270 &num_childrens_props);
4271
4272 assert_property_list_match (clips_child_props, num_clips_props,
4273 childrens_child_props, num_childrens_props);
4274
4275 free_children_properties (clips_child_props, num_clips_props);
4276 free_children_properties (childrens_child_props, num_childrens_props);
4277
4278 gst_object_unref (timeline);
4279
4280 ges_deinit ();
4281 }
4282
4283 GST_END_TEST;
4284
4285 static gboolean
4286 _has_child_property (GESTimelineElement * element, GParamSpec * property)
4287 {
4288 gboolean has_prop = FALSE;
4289 guint num_props, i;
4290 GParamSpec **props =
4291 ges_timeline_element_list_children_properties (element, &num_props);
4292 for (i = 0; i < num_props; i++) {
4293 if (props[i] == property)
4294 has_prop = TRUE;
4295 g_param_spec_unref (props[i]);
4296 }
4297 g_free (props);
4298 return has_prop;
4299 }
4300
4301 typedef struct
4302 {
4303 GstElement *child;
4304 GParamSpec *property;
4305 guint num_calls;
4306 } PropChangedData;
4307
4308 #define _INIT_PROP_CHANGED_DATA(data) \
4309 data.child = NULL; \
4310 data.property = NULL; \
4311 data.num_calls = 0;
4312
4313 static void
4314 _prop_changed_cb (GESTimelineElement * element, GstElement * child,
4315 GParamSpec * property, PropChangedData * data)
4316 {
4317 data->num_calls++;
4318 data->property = property;
4319 data->child = child;
4320 }
4321
4322 #define _assert_prop_changed_data(element, data, num_cmp, chld_cmp, prop_cmp) \
4323 fail_unless (num_cmp == data.num_calls, \
4324 "%s: num calls to callback (%u) not the expected %u", element->name, \
4325 data.num_calls, num_cmp); \
4326 fail_unless (prop_cmp == data.property, \
4327 "%s: property %s is not the expected property %s", element->name, \
4328 data.property->name, prop_cmp ? ((GParamSpec *)prop_cmp)->name : NULL); \
4329 fail_unless (chld_cmp == data.child, \
4330 "%s: child %s is not the expected child %s", element->name, \
4331 GST_ELEMENT_NAME (data.child), \
4332 chld_cmp ? GST_ELEMENT_NAME (chld_cmp) : NULL);
4333
4334 #define _assert_int_val_child_prop(element, val, int_cmp, prop, prop_name) \
4335 g_value_init (&val, G_TYPE_INT); \
4336 ges_timeline_element_get_child_property_by_pspec (element, prop, &val); \
4337 assert_equals_int (g_value_get_int (&val), int_cmp); \
4338 g_value_unset (&val); \
4339 g_value_init (&val, G_TYPE_INT); \
4340 fail_unless (ges_timeline_element_get_child_property ( \
4341 element, prop_name, &val)); \
4342 assert_equals_int (g_value_get_int (&val), int_cmp); \
4343 g_value_unset (&val); \
4344
4345 GST_START_TEST (test_children_properties_change)
4346 {
4347 GESTimeline *timeline;
4348 GESLayer *layer;
4349 GESTimelineElement *clip, *child;
4350 PropChangedData clip_add_data, clip_remove_data, clip_notify_data,
4351 child_add_data, child_remove_data, child_notify_data;
4352 GstElement *sub_child;
4353 GParamSpec *prop1, *prop2, *prop3;
4354 GValue val = G_VALUE_INIT;
4355 gint num_buffs;
4356
4357 ges_init ();
4358
4359 timeline = ges_timeline_new_audio_video ();
4360 layer = ges_timeline_append_layer (timeline);
4361 clip = GES_TIMELINE_ELEMENT (ges_test_clip_new ());
4362 assert_set_duration (clip, 50);
4363
4364 fail_unless (ges_layer_add_clip (layer, GES_CLIP (clip)));
4365 fail_unless (GES_CONTAINER_CHILDREN (clip));
4366 child = GES_CONTAINER_CHILDREN (clip)->data;
4367
4368 /* fake sub-child */
4369 sub_child = gst_element_factory_make ("fakesink", "sub-child");
4370 fail_unless (sub_child);
4371 gst_object_ref_sink (sub_child);
4372 prop1 = g_object_class_find_property (G_OBJECT_GET_CLASS (sub_child),
4373 "num-buffers");
4374 fail_unless (prop1);
4375 prop2 = g_object_class_find_property (G_OBJECT_GET_CLASS (sub_child), "dump");
4376 fail_unless (prop2);
4377 prop3 = g_object_class_find_property (G_OBJECT_GET_CLASS (sub_child),
4378 "silent");
4379 fail_unless (prop2);
4380
4381 _INIT_PROP_CHANGED_DATA (clip_add_data);
4382 _INIT_PROP_CHANGED_DATA (clip_remove_data);
4383 _INIT_PROP_CHANGED_DATA (clip_notify_data);
4384 _INIT_PROP_CHANGED_DATA (child_add_data);
4385 _INIT_PROP_CHANGED_DATA (child_remove_data);
4386 _INIT_PROP_CHANGED_DATA (child_notify_data);
4387 g_signal_connect (clip, "child-property-added",
4388 G_CALLBACK (_prop_changed_cb), &clip_add_data);
4389 g_signal_connect (clip, "child-property-removed",
4390 G_CALLBACK (_prop_changed_cb), &clip_remove_data);
4391 g_signal_connect (clip, "deep-notify",
4392 G_CALLBACK (_prop_changed_cb), &clip_notify_data);
4393 g_signal_connect (child, "child-property-added",
4394 G_CALLBACK (_prop_changed_cb), &child_add_data);
4395 g_signal_connect (child, "child-property-removed",
4396 G_CALLBACK (_prop_changed_cb), &child_remove_data);
4397 g_signal_connect (child, "deep-notify",
4398 G_CALLBACK (_prop_changed_cb), &child_notify_data);
4399
4400 /* adding to child should also add it to the parent clip */
4401 fail_unless (ges_timeline_element_add_child_property (child, prop1,
4402 G_OBJECT (sub_child)));
4403
4404 fail_unless (_has_child_property (child, prop1));
4405 fail_unless (_has_child_property (clip, prop1));
4406
4407 _assert_prop_changed_data (clip, clip_add_data, 1, sub_child, prop1);
4408 _assert_prop_changed_data (clip, clip_remove_data, 0, NULL, NULL);
4409 _assert_prop_changed_data (clip, clip_notify_data, 0, NULL, NULL);
4410 _assert_prop_changed_data (child, child_add_data, 1, sub_child, prop1);
4411 _assert_prop_changed_data (child, child_remove_data, 0, NULL, NULL);
4412 _assert_prop_changed_data (child, child_notify_data, 0, NULL, NULL);
4413
4414 fail_unless (ges_timeline_element_add_child_property (child, prop2,
4415 G_OBJECT (sub_child)));
4416
4417 fail_unless (_has_child_property (child, prop2));
4418 fail_unless (_has_child_property (clip, prop2));
4419
4420 _assert_prop_changed_data (clip, clip_add_data, 2, sub_child, prop2);
4421 _assert_prop_changed_data (clip, clip_remove_data, 0, NULL, NULL);
4422 _assert_prop_changed_data (clip, clip_notify_data, 0, NULL, NULL);
4423 _assert_prop_changed_data (child, child_add_data, 2, sub_child, prop2);
4424 _assert_prop_changed_data (child, child_remove_data, 0, NULL, NULL);
4425 _assert_prop_changed_data (child, child_notify_data, 0, NULL, NULL);
4426
4427 /* adding to parent does not add to the child */
4428
4429 fail_unless (ges_timeline_element_add_child_property (clip, prop3,
4430 G_OBJECT (sub_child)));
4431
4432 fail_if (_has_child_property (child, prop3));
4433 fail_unless (_has_child_property (clip, prop3));
4434
4435 _assert_prop_changed_data (clip, clip_add_data, 3, sub_child, prop3);
4436 _assert_prop_changed_data (clip, clip_remove_data, 0, NULL, NULL);
4437 _assert_prop_changed_data (clip, clip_notify_data, 0, NULL, NULL);
4438 _assert_prop_changed_data (child, child_add_data, 2, sub_child, prop2);
4439 _assert_prop_changed_data (child, child_remove_data, 0, NULL, NULL);
4440 _assert_prop_changed_data (child, child_notify_data, 0, NULL, NULL);
4441
4442 /* both should be notified of a change in the value */
4443
4444 g_object_set (G_OBJECT (sub_child), "num-buffers", 100, NULL);
4445
4446 _assert_prop_changed_data (clip, clip_add_data, 3, sub_child, prop3);
4447 _assert_prop_changed_data (clip, clip_remove_data, 0, NULL, NULL);
4448 _assert_prop_changed_data (clip, clip_notify_data, 1, sub_child, prop1);
4449 _assert_prop_changed_data (child, child_add_data, 2, sub_child, prop2);
4450 _assert_prop_changed_data (child, child_remove_data, 0, NULL, NULL);
4451 _assert_prop_changed_data (child, child_notify_data, 1, sub_child, prop1);
4452
4453 _assert_int_val_child_prop (clip, val, 100, prop1,
4454 "GstFakeSink::num-buffers");
4455 _assert_int_val_child_prop (child, val, 100, prop1,
4456 "GstFakeSink::num-buffers");
4457
4458 g_value_init (&val, G_TYPE_INT);
4459 g_value_set_int (&val, 79);
4460 ges_timeline_element_set_child_property_by_pspec (clip, prop1, &val);
4461 g_value_unset (&val);
4462
4463 _assert_prop_changed_data (clip, clip_add_data, 3, sub_child, prop3);
4464 _assert_prop_changed_data (clip, clip_remove_data, 0, NULL, NULL);
4465 _assert_prop_changed_data (clip, clip_notify_data, 2, sub_child, prop1);
4466 _assert_prop_changed_data (child, child_add_data, 2, sub_child, prop2);
4467 _assert_prop_changed_data (child, child_remove_data, 0, NULL, NULL);
4468 _assert_prop_changed_data (child, child_notify_data, 2, sub_child, prop1);
4469
4470 _assert_int_val_child_prop (clip, val, 79, prop1, "GstFakeSink::num-buffers");
4471 _assert_int_val_child_prop (child, val, 79, prop1,
4472 "GstFakeSink::num-buffers");
4473 g_object_get (G_OBJECT (sub_child), "num-buffers", &num_buffs, NULL);
4474 assert_equals_int (num_buffs, 79);
4475
4476 g_value_init (&val, G_TYPE_INT);
4477 g_value_set_int (&val, 97);
4478 fail_unless (ges_timeline_element_set_child_property (child,
4479 "GstFakeSink::num-buffers", &val));
4480 g_value_unset (&val);
4481
4482 _assert_prop_changed_data (clip, clip_add_data, 3, sub_child, prop3);
4483 _assert_prop_changed_data (clip, clip_remove_data, 0, NULL, NULL);
4484 _assert_prop_changed_data (clip, clip_notify_data, 3, sub_child, prop1);
4485 _assert_prop_changed_data (child, child_add_data, 2, sub_child, prop2);
4486 _assert_prop_changed_data (child, child_remove_data, 0, NULL, NULL);
4487 _assert_prop_changed_data (child, child_notify_data, 3, sub_child, prop1);
4488
4489 _assert_int_val_child_prop (clip, val, 97, prop1, "GstFakeSink::num-buffers");
4490 _assert_int_val_child_prop (child, val, 97, prop1,
4491 "GstFakeSink::num-buffers");
4492 g_object_get (G_OBJECT (sub_child), "num-buffers", &num_buffs, NULL);
4493 assert_equals_int (num_buffs, 97);
4494
4495 /* remove a property from the child, removes from the parent */
4496
4497 fail_unless (ges_timeline_element_remove_child_property (child, prop2));
4498
4499 _assert_prop_changed_data (clip, clip_add_data, 3, sub_child, prop3);
4500 _assert_prop_changed_data (clip, clip_remove_data, 1, sub_child, prop2);
4501 _assert_prop_changed_data (clip, clip_notify_data, 3, sub_child, prop1);
4502 _assert_prop_changed_data (child, child_add_data, 2, sub_child, prop2);
4503 _assert_prop_changed_data (child, child_remove_data, 1, sub_child, prop2);
4504 _assert_prop_changed_data (child, child_notify_data, 3, sub_child, prop1);
4505
4506 fail_if (_has_child_property (child, prop2));
4507 fail_if (_has_child_property (clip, prop2));
4508
4509 /* removing from parent doesn't remove from child */
4510
4511 fail_unless (ges_timeline_element_remove_child_property (clip, prop1));
4512
4513 _assert_prop_changed_data (clip, clip_add_data, 3, sub_child, prop3);
4514 _assert_prop_changed_data (clip, clip_remove_data, 2, sub_child, prop1);
4515 _assert_prop_changed_data (clip, clip_notify_data, 3, sub_child, prop1);
4516 _assert_prop_changed_data (child, child_add_data, 2, sub_child, prop2);
4517 _assert_prop_changed_data (child, child_remove_data, 1, sub_child, prop2);
4518 _assert_prop_changed_data (child, child_notify_data, 3, sub_child, prop1);
4519
4520 fail_unless (_has_child_property (child, prop1));
4521 fail_if (_has_child_property (clip, prop1));
4522
4523 /* but still safe to remove it from the child later */
4524
4525 fail_unless (ges_timeline_element_remove_child_property (child, prop1));
4526
4527 _assert_prop_changed_data (clip, clip_add_data, 3, sub_child, prop3);
4528 _assert_prop_changed_data (clip, clip_remove_data, 2, sub_child, prop1);
4529 _assert_prop_changed_data (clip, clip_notify_data, 3, sub_child, prop1);
4530 _assert_prop_changed_data (child, child_add_data, 2, sub_child, prop2);
4531 _assert_prop_changed_data (child, child_remove_data, 2, sub_child, prop1);
4532 _assert_prop_changed_data (child, child_notify_data, 3, sub_child, prop1);
4533
4534 fail_if (_has_child_property (child, prop1));
4535 fail_if (_has_child_property (clip, prop1));
4536
4537 gst_object_unref (sub_child);
4538 gst_object_unref (timeline);
4539
4540 ges_deinit ();
4541 }
4542
4543 GST_END_TEST;
4544
4545 static GESTimelineElement *
4546 _el_with_child_prop (GESTimelineElement * clip, GObject * prop_child,
4547 GParamSpec * prop)
4548 {
4549 GList *tmp;
4550 GESTimelineElement *child = NULL;
4551 for (tmp = GES_CONTAINER_CHILDREN (clip); tmp; tmp = tmp->next) {
4552 GObject *found_child;
4553 GParamSpec *found_prop;
4554 if (ges_timeline_element_lookup_child (tmp->data, prop->name,
4555 &found_child, &found_prop)) {
4556 if (found_child == prop_child && found_prop == prop) {
4557 g_param_spec_unref (found_prop);
4558 g_object_unref (found_child);
4559 child = tmp->data;
4560 break;
4561 }
4562 g_param_spec_unref (found_prop);
4563 g_object_unref (found_child);
4564 }
4565 }
4566 return child;
4567 }
4568
4569 static GstTimedValue *
4570 _new_timed_value (GstClockTime time, gdouble val)
4571 {
4572 GstTimedValue *tmval = g_new0 (GstTimedValue, 1);
4573 tmval->value = val;
4574 tmval->timestamp = time;
4575 return tmval;
4576 }
4577
4578 #define _assert_binding(element, prop_name, child, timed_vals, mode) \
4579 { \
4580 GstInterpolationMode found_mode; \
4581 GSList *tmp1; \
4582 gsize i; \
4583 GstTimedValue *found_timed_vals; \
4584 gsize found_n_timed_vals; \
4585 GObject *found_object = NULL; \
4586 GstControlSource *source = NULL; \
4587 GstControlBinding *binding = ges_track_element_get_control_binding ( \
4588 GES_TRACK_ELEMENT (element), prop_name); \
4589 fail_unless (binding, "No control binding found for %s on %s", \
4590 prop_name, GES_TIMELINE_ELEMENT_NAME (element)); \
4591 g_object_get (G_OBJECT (binding), "control-source", &source, \
4592 "object", &found_object, NULL); \
4593 \
4594 if (child) \
4595 fail_unless (found_object == child); \
4596 g_object_unref (found_object); \
4597 \
4598 fail_unless (GST_IS_INTERPOLATION_CONTROL_SOURCE (source)); \
4599 found_timed_vals = gst_timed_value_control_source_list_control_points ( \
4600 GST_TIMED_VALUE_CONTROL_SOURCE (source), &found_n_timed_vals); \
4601 \
4602 for (i = 0, tmp1 = timed_vals; tmp1 && i < found_n_timed_vals; \
4603 tmp1 = tmp1->next, i++) { \
4604 GstTimedValue *val1 = tmp1->data; \
4605 GstTimedValue *val2 = &found_timed_vals[i]; \
4606 gdouble diff = (val1->value > val2->value) ? \
4607 val1->value - val2->value : val2->value - val1->value; \
4608 fail_unless (val1->timestamp == val2->timestamp && diff < 0.0001, \
4609 "The %ith timed value (%lu: %g) does not match the found timed " \
4610 "value (%lu: %g)", i, val1->timestamp, val1->value, \
4611 val2->timestamp, val2->value); \
4612 } \
4613 fail_unless (tmp1 == NULL, "Found too few timed values"); \
4614 fail_unless (i == found_n_timed_vals, "Found too many timed values"); \
4615 \
4616 g_free (found_timed_vals); \
4617 g_object_get (G_OBJECT (source), "mode", &found_mode, NULL); \
4618 fail_unless (found_mode == mode); \
4619 g_object_unref (source); \
4620 }
4621
4622 GST_START_TEST (test_copy_paste_children_properties)
4623 {
4624 GESTimeline *timeline;
4625 GESLayer *layer;
4626 GESTimelineElement *clip, *copy, *pasted, *track_el, *pasted_el;
4627 GObject *sub_child, *pasted_sub_child;
4628 GParamSpec **orig_props;
4629 guint num_orig_props;
4630 GParamSpec *prop, *found_prop;
4631 GValue val = G_VALUE_INIT;
4632 GstControlSource *source;
4633 GSList *timed_vals;
4634
4635 ges_init ();
4636
4637 timeline = ges_timeline_new_audio_video ();
4638 layer = ges_timeline_append_layer (timeline);
4639 clip = GES_TIMELINE_ELEMENT (ges_source_clip_new_time_overlay ());
4640 assert_set_duration (clip, 50);
4641
4642 fail_unless (ges_layer_add_clip (layer, GES_CLIP (clip)));
4643
4644 /* get children properties */
4645 orig_props =
4646 ges_timeline_element_list_children_properties (clip, &num_orig_props);
4647 fail_unless (num_orig_props);
4648
4649 /* font-desc is originally "", but on setting switches to Normal, so we
4650 * set it explicitly */
4651 ges_timeline_element_set_child_properties (clip, "font-desc", "Normal",
4652 "posx", 30, "posy", 50, "alpha", 0.1, "freq", 449.0, NULL);
4653
4654 /* focus on one property */
4655 fail_unless (ges_timeline_element_lookup_child (clip, "posx",
4656 &sub_child, &prop));
4657 _assert_int_val_child_prop (clip, val, 30, prop, "posx");
4658
4659 /* find the track element where the child property comes from */
4660 fail_unless (track_el = _el_with_child_prop (clip, sub_child, prop));
4661 _assert_int_val_child_prop (track_el, val, 30, prop, "posx");
4662 ges_track_element_set_auto_clamp_control_sources (GES_TRACK_ELEMENT
4663 (track_el), FALSE);
4664
4665 /* set a control binding */
4666 timed_vals = g_slist_prepend (NULL, _new_timed_value (200, 5));
4667 timed_vals = g_slist_prepend (timed_vals, _new_timed_value (40, 50));
4668 timed_vals = g_slist_prepend (timed_vals, _new_timed_value (20, 10));
4669 timed_vals = g_slist_prepend (timed_vals, _new_timed_value (0, 20));
4670
4671 source = GST_CONTROL_SOURCE (gst_interpolation_control_source_new ());
4672 g_object_set (G_OBJECT (source), "mode", GST_INTERPOLATION_MODE_CUBIC, NULL);
4673 fail_unless (gst_timed_value_control_source_set_from_list
4674 (GST_TIMED_VALUE_CONTROL_SOURCE (source), timed_vals));
4675
4676 fail_unless (ges_track_element_set_control_source (GES_TRACK_ELEMENT
4677 (track_el), source, "posx", "direct-absolute"));
4678
4679 g_object_unref (source);
4680
4681 /* check the control binding */
4682 _assert_binding (track_el, "posx", sub_child, timed_vals,
4683 GST_INTERPOLATION_MODE_CUBIC);
4684
4685 /* copy and paste */
4686 fail_unless (copy = ges_timeline_element_copy (clip, TRUE));
4687 fail_unless (pasted = ges_timeline_element_paste (copy, 30));
4688
4689 gst_object_unref (copy);
4690 gst_object_unref (pasted);
4691
4692 /* test that the new clip has the same child properties */
4693 assert_equal_children_properties (clip, pasted);
4694
4695 /* get the details for the copied 'prop' property */
4696 fail_unless (ges_timeline_element_lookup_child (pasted,
4697 "posx", &pasted_sub_child, &found_prop));
4698 fail_unless (found_prop == prop);
4699 g_param_spec_unref (found_prop);
4700 fail_unless (G_OBJECT_TYPE (pasted_sub_child) == G_OBJECT_TYPE (sub_child));
4701
4702 _assert_int_val_child_prop (pasted, val, 30, prop, "posx");
4703
4704 /* get the associated child */
4705 fail_unless (pasted_el =
4706 _el_with_child_prop (pasted, pasted_sub_child, prop));
4707 _assert_int_val_child_prop (pasted_el, val, 30, prop, "posx");
4708
4709 assert_equal_children_properties (track_el, pasted_el);
4710
4711 /* check the control binding on the pasted element */
4712 _assert_binding (pasted_el, "posx", pasted_sub_child, timed_vals,
4713 GST_INTERPOLATION_MODE_CUBIC);
4714
4715 assert_equal_bindings (pasted_el, track_el);
4716
4717 /* free */
4718 g_slist_free_full (timed_vals, g_free);
4719
4720 free_children_properties (orig_props, num_orig_props);
4721
4722 g_param_spec_unref (prop);
4723 g_object_unref (pasted_sub_child);
4724 g_object_unref (sub_child);
4725 gst_object_unref (timeline);
4726
4727 ges_deinit ();
4728 }
4729
4730 GST_END_TEST;
4731
4732 #define _THREE_TIMED_VALS(timed_vals, tm1, val1, tm2, val2, tm3, val3) \
4733 if (timed_vals) \
4734 g_slist_free_full (timed_vals, g_free); \
4735 timed_vals = g_slist_prepend (NULL, _new_timed_value (tm3, val3)); \
4736 timed_vals = g_slist_prepend (timed_vals, _new_timed_value (tm2, val2)); \
4737 timed_vals = g_slist_prepend (timed_vals, _new_timed_value (tm1, val1));
4738
4739 #define _TWO_TIMED_VALS(timed_vals, tm1, val1, tm2, val2) \
4740 if (timed_vals) \
4741 g_slist_free_full (timed_vals, g_free); \
4742 timed_vals = g_slist_prepend (NULL, _new_timed_value (tm2, val2)); \
4743 timed_vals = g_slist_prepend (timed_vals, _new_timed_value (tm1, val1));
4744
4745 #define _assert_control_source(obj, prop, vals) \
4746 _assert_binding (obj, prop, NULL, vals, GST_INTERPOLATION_MODE_LINEAR);
4747
4748 GST_START_TEST (test_children_property_bindings_with_rate_effects)
4749 {
4750 GESTimeline *timeline;
4751 GESTrack *track;
4752 GESLayer *layer;
4753 GESClip *clip;
4754 GESTrackElement *video_source, *rate0, *rate1, *overlay;
4755 GstControlSource *ctrl_source;
4756 GSList *video_source_vals = NULL, *overlay_vals = NULL;
4757 GValue value = G_VALUE_INIT;
4758 GstControlBinding *binding;
4759
4760 ges_init ();
4761
4762 g_value_init (&value, G_TYPE_DOUBLE);
4763
4764 timeline = ges_timeline_new ();
4765 track = GES_TRACK (ges_video_track_new ());
4766 fail_unless (ges_timeline_add_track (timeline, track));
4767
4768 layer = ges_timeline_append_layer (timeline);
4769
4770 clip = GES_CLIP (ges_test_clip_new ());
4771 assert_set_duration (clip, 4);
4772 assert_set_start (clip, 20);
4773 assert_set_inpoint (clip, 3);
4774
4775 fail_unless (ges_layer_add_clip (layer, clip));
4776
4777 video_source = ges_clip_find_track_element (clip, track, GES_TYPE_SOURCE);
4778 fail_unless (video_source);
4779 gst_object_unref (video_source);
4780
4781 rate0 = GES_TRACK_ELEMENT (ges_effect_new ("videorate rate=0.5"));
4782 rate1 = GES_TRACK_ELEMENT (ges_effect_new ("videorate rate=4.0"));
4783 overlay = GES_TRACK_ELEMENT (ges_effect_new ("textoverlay"));
4784 ges_track_element_set_has_internal_source (overlay, TRUE);
4785 assert_set_inpoint (overlay, 9);
4786
4787 fail_unless (ges_clip_add_top_effect (clip, GES_BASE_EFFECT (rate0), -1,
4788 NULL));
4789 fail_unless (ges_clip_add_top_effect (clip, GES_BASE_EFFECT (overlay), 0,
4790 NULL));
4791 fail_unless (ges_clip_add_top_effect (clip, GES_BASE_EFFECT (rate1), 0,
4792 NULL));
4793
4794 fail_unless (ges_track_element_get_auto_clamp_control_sources (video_source));
4795 fail_unless (ges_track_element_get_auto_clamp_control_sources (overlay));
4796
4797 /* source's alpha property */
4798 _THREE_TIMED_VALS (video_source_vals, 1, 0.7, 7, 1.0, 15, 0.2);
4799
4800 ctrl_source = GST_CONTROL_SOURCE (gst_interpolation_control_source_new ());
4801 g_object_set (G_OBJECT (ctrl_source), "mode",
4802 GST_INTERPOLATION_MODE_LINEAR, NULL);
4803 fail_unless (gst_timed_value_control_source_set_from_list
4804 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), video_source_vals));
4805
4806 fail_unless (ges_track_element_set_control_source (video_source, ctrl_source,
4807 "alpha", "direct"));
4808 gst_object_unref (ctrl_source);
4809
4810 /* values have been clamped between its in-point:3 and its
4811 * out-point:11 (4ns in timeline is 8ns in source) */
4812 _THREE_TIMED_VALS (video_source_vals, 3, 0.8, 7, 1.0, 11, 0.6);
4813 _assert_control_source (video_source, "alpha", video_source_vals);
4814
4815 /* overlay's xpos property */
4816 _THREE_TIMED_VALS (overlay_vals, 9, 12, 17, 16, 25, 8);
4817
4818 ctrl_source = GST_CONTROL_SOURCE (gst_interpolation_control_source_new ());
4819 g_object_set (G_OBJECT (ctrl_source), "mode",
4820 GST_INTERPOLATION_MODE_LINEAR, NULL);
4821 fail_unless (gst_timed_value_control_source_set_from_list
4822 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), overlay_vals));
4823
4824 fail_unless (ges_track_element_set_control_source (overlay, ctrl_source,
4825 "xpos", "direct-absolute"));
4826 gst_object_unref (ctrl_source);
4827
4828 /* unchanged since values are at the edges already
4829 * in-point:9 out-point:25 (4ns in timeline is 16ns in source) */
4830 _assert_control_source (overlay, "xpos", overlay_vals);
4831
4832 /* setting the in-point changes the in-point and out-point */
4833 /* increase in-point */
4834 assert_set_inpoint (video_source, 5);
4835
4836 _THREE_TIMED_VALS (video_source_vals, 5, 0.9, 7, 1.0, 13, 0.4);
4837 _assert_control_source (video_source, "alpha", video_source_vals);
4838
4839 /* decrease in-point */
4840 assert_set_inpoint (overlay, 7);
4841
4842 _THREE_TIMED_VALS (overlay_vals, 7, 11, 17, 16, 23, 10);
4843 _assert_control_source (overlay, "xpos", overlay_vals);
4844
4845 /* when trimming start, out-point should stay the same */
4846 fail_unless (ges_timeline_element_edit_full (GES_TIMELINE_ELEMENT (clip),
4847 -1, GES_EDIT_MODE_TRIM, GES_EDGE_START, 19, NULL));
4848
4849 /* in-point of video_source now 3 */
4850 _THREE_TIMED_VALS (video_source_vals, 3, 0.8, 7, 1.0, 13, 0.4);
4851 _assert_control_source (video_source, "alpha", video_source_vals);
4852
4853 /* in-point of video_source now 3 */
4854 _THREE_TIMED_VALS (overlay_vals, 3, 9, 17, 16, 23, 10);
4855 _assert_control_source (overlay, "xpos", overlay_vals);
4856
4857 /* trim forwards */
4858 fail_unless (ges_timeline_element_edit_full (GES_TIMELINE_ELEMENT (clip),
4859 -1, GES_EDIT_MODE_TRIM, GES_EDGE_START, 20, NULL));
4860
4861 /* in-point of video_source now 5 again */
4862 _THREE_TIMED_VALS (video_source_vals, 5, 0.9, 7, 1.0, 13, 0.4);
4863 _assert_control_source (video_source, "alpha", video_source_vals);
4864
4865 /* in-point of overlay now 7 again */
4866 _THREE_TIMED_VALS (overlay_vals, 7, 11, 17, 16, 23, 10);
4867 _assert_control_source (overlay, "xpos", overlay_vals);
4868
4869 /* trim end */
4870 fail_unless (ges_timeline_element_edit_full (GES_TIMELINE_ELEMENT (clip),
4871 -1, GES_EDIT_MODE_TRIM, GES_EDGE_END, 25, NULL));
4872
4873 /* out-point of video_source now 15 */
4874 _THREE_TIMED_VALS (video_source_vals, 5, 0.9, 7, 1.0, 15, 0.2);
4875 _assert_control_source (video_source, "alpha", video_source_vals);
4876
4877 /* out-point of overlay now 27 */
4878 _THREE_TIMED_VALS (overlay_vals, 7, 11, 17, 16, 27, 6);
4879 _assert_control_source (overlay, "xpos", overlay_vals);
4880
4881 /* trim backwards */
4882 fail_unless (ges_timeline_element_edit_full (GES_TIMELINE_ELEMENT (clip),
4883 -1, GES_EDIT_MODE_TRIM, GES_EDGE_END, 23, NULL));
4884
4885 /* out-point of video_source now 11 */
4886 _THREE_TIMED_VALS (video_source_vals, 5, 0.9, 7, 1.0, 11, 0.6);
4887 _assert_control_source (video_source, "alpha", video_source_vals);
4888
4889 /* in-point of overlay now 19 */
4890 _THREE_TIMED_VALS (overlay_vals, 7, 11, 17, 16, 19, 14);
4891 _assert_control_source (overlay, "xpos", overlay_vals);
4892
4893 /* changing the rate changes the out-point */
4894 _assert_set_rate (rate0, "rate", 1.0, value);
4895
4896 /* out-point of video_source now 17 */
4897 _THREE_TIMED_VALS (video_source_vals, 5, 0.9, 7, 1.0, 17, 0.0);
4898 _assert_control_source (video_source, "alpha", video_source_vals);
4899
4900 /* unchanged for overlay, which is after rate0 */
4901 _assert_control_source (overlay, "xpos", overlay_vals);
4902
4903 /* change back */
4904 _assert_set_rate (rate0, "rate", 0.5, value);
4905
4906 _THREE_TIMED_VALS (video_source_vals, 5, 0.9, 7, 1.0, 11, 0.6);
4907 _assert_control_source (video_source, "alpha", video_source_vals);
4908
4909 /* unchanged for overlay, which is after rate0 */
4910 _assert_control_source (overlay, "xpos", overlay_vals);
4911
4912 /* make inactive */
4913 fail_unless (ges_track_element_set_active (rate0, FALSE));
4914
4915 _THREE_TIMED_VALS (video_source_vals, 5, 0.9, 7, 1.0, 17, 0.0);
4916 _assert_control_source (video_source, "alpha", video_source_vals);
4917
4918 /* unchanged for overlay, which is after rate0 */
4919 _assert_control_source (overlay, "xpos", overlay_vals);
4920
4921 /* make active again */
4922 fail_unless (ges_track_element_set_active (rate0, TRUE));
4923
4924 _THREE_TIMED_VALS (video_source_vals, 5, 0.9, 7, 1.0, 11, 0.6);
4925 _assert_control_source (video_source, "alpha", video_source_vals);
4926
4927 /* unchanged for overlay, which is after rate0 */
4928 _assert_control_source (overlay, "xpos", overlay_vals);
4929
4930 /* change order */
4931 fail_unless (ges_clip_set_top_effect_index (clip, GES_BASE_EFFECT (overlay),
4932 2));
4933
4934 /* video source unchanged */
4935 _assert_control_source (video_source, "alpha", video_source_vals);
4936
4937 /* new out-point is 13
4938 * new value is interpolated between the previous value
4939 * (at time 7, value 11) and the *final* value (at time 19, value 14)
4940 * Not the middle value at time 17, value 16! */
4941 _TWO_TIMED_VALS (overlay_vals, 7, 11, 13, 12.5);
4942 _assert_control_source (overlay, "xpos", overlay_vals);
4943
4944 /* removing time effect changes out-point */
4945 gst_object_ref (rate0);
4946 fail_unless (ges_clip_remove_top_effect (clip, GES_BASE_EFFECT (rate0),
4947 NULL));
4948
4949 _THREE_TIMED_VALS (video_source_vals, 5, 0.9, 7, 1.0, 17, 0.0);
4950 _assert_control_source (video_source, "alpha", video_source_vals);
4951
4952 _TWO_TIMED_VALS (overlay_vals, 7, 11, 19, 14);
4953 _assert_control_source (overlay, "xpos", overlay_vals);
4954
4955 /* adding also changes it */
4956 fail_unless (ges_clip_add_top_effect (clip, GES_BASE_EFFECT (rate0), 2,
4957 NULL));
4958
4959 _THREE_TIMED_VALS (video_source_vals, 5, 0.9, 7, 1.0, 11, 0.6);
4960 _assert_control_source (video_source, "alpha", video_source_vals);
4961
4962 /* unchanged for overlay */
4963 _assert_control_source (overlay, "xpos", overlay_vals);
4964
4965 /* new value will use the value already set at in-point if possible */
4966
4967 assert_set_inpoint (video_source, 7);
4968
4969 _TWO_TIMED_VALS (video_source_vals, 7, 1.0, 13, 0.4);
4970 _assert_control_source (video_source, "alpha", video_source_vals);
4971
4972 /* same with out-point for overlay */
4973 binding = ges_track_element_get_control_binding (overlay, "xpos");
4974 fail_unless (binding);
4975 g_object_get (binding, "control-source", &ctrl_source, NULL);
4976
4977 fail_unless (gst_timed_value_control_source_set
4978 (GST_TIMED_VALUE_CONTROL_SOURCE (ctrl_source), 11, 5));
4979 gst_object_unref (ctrl_source);
4980 _THREE_TIMED_VALS (overlay_vals, 7, 11, 11, 5, 19, 14);
4981
4982 _assert_control_source (overlay, "xpos", overlay_vals);
4983
4984 fail_unless (ges_timeline_element_edit_full (GES_TIMELINE_ELEMENT (clip),
4985 -1, GES_EDIT_MODE_TRIM, GES_EDGE_END, 21, NULL));
4986
4987 _TWO_TIMED_VALS (video_source_vals, 7, 1.0, 9, 0.8);
4988 _assert_control_source (video_source, "alpha", video_source_vals);
4989
4990 /* overlay uses existing value, rather than an interpolation */
4991 _TWO_TIMED_VALS (overlay_vals, 7, 11, 11, 5);
4992 _assert_control_source (overlay, "xpos", overlay_vals);
4993
4994 g_slist_free_full (video_source_vals, g_free);
4995 g_slist_free_full (overlay_vals, g_free);
4996
4997 gst_object_unref (timeline);
4998 g_value_unset (&value);
4999
5000 ges_deinit ();
5001 }
5002
5003 GST_END_TEST;
5004
5005 GST_START_TEST (test_unchanged_after_layer_add_failure)
5006 {
5007 GList *found;
5008 GESTrack *track;
5009 GESTimeline *timeline;
5010 GESLayer *layer;
5011 GESClip *clip0, *clip1;
5012 GESTimelineElement *effect, *source;
5013
5014 ges_init ();
5015
5016 timeline = ges_timeline_new ();
5017 layer = ges_timeline_append_layer (timeline);
5018
5019 /* two video tracks */
5020 track = GES_TRACK (ges_video_track_new ());
5021 fail_unless (ges_timeline_add_track (timeline, track));
5022
5023 track = GES_TRACK (ges_video_track_new ());
5024 fail_unless (ges_timeline_add_track (timeline, track));
5025
5026 clip0 = GES_CLIP (ges_test_clip_new ());
5027 clip1 = GES_CLIP (ges_test_clip_new ());
5028
5029 gst_object_ref (clip0);
5030 gst_object_ref (clip1);
5031
5032 assert_set_start (clip0, 0);
5033 assert_set_duration (clip0, 10);
5034 assert_set_start (clip1, 0);
5035 assert_set_duration (clip1, 10);
5036
5037 effect = GES_TIMELINE_ELEMENT (ges_effect_new ("agingtv"));
5038 _assert_add (clip1, effect);
5039
5040 assert_num_children (clip0, 0);
5041 assert_num_children (clip1, 1);
5042
5043 fail_unless (ges_layer_add_clip (layer, clip0));
5044
5045 assert_num_children (clip0, 2);
5046 assert_num_children (clip1, 1);
5047
5048 fail_unless (GES_CONTAINER_CHILDREN (clip1)->data == effect);
5049
5050 /* addition should fail since sources would fully overlap */
5051 fail_if (ges_layer_add_clip (layer, clip1));
5052
5053 /* children should be the same */
5054 assert_num_children (clip0, 2);
5055 assert_num_children (clip1, 1);
5056
5057 fail_unless (GES_CONTAINER_CHILDREN (clip1)->data == effect);
5058
5059 /* should be able to add again once we have fixed the problem */
5060 fail_unless (ges_layer_remove_clip (layer, clip0));
5061
5062 assert_num_children (clip0, 2);
5063 assert_num_children (clip1, 1);
5064
5065 fail_unless (ges_layer_add_clip (layer, clip1));
5066
5067 assert_num_children (clip0, 2);
5068 /* now has two sources and two effects */
5069 assert_num_children (clip1, 4);
5070
5071 found = ges_clip_find_track_elements (clip1, NULL, GES_TRACK_TYPE_VIDEO,
5072 GES_TYPE_VIDEO_SOURCE);
5073 fail_unless_equals_int (g_list_length (found), 2);
5074 g_list_free_full (found, gst_object_unref);
5075
5076 found = ges_clip_find_track_elements (clip1, NULL, GES_TRACK_TYPE_VIDEO,
5077 GES_TYPE_EFFECT);
5078 fail_unless_equals_int (g_list_length (found), 2);
5079 g_list_free_full (found, gst_object_unref);
5080
5081 /* similarly cannot add clip0 back, and children should not change */
5082 /* remove the extra source */
5083 _assert_remove (clip0, GES_CONTAINER_CHILDREN (clip0)->data);
5084 assert_num_children (clip0, 1);
5085 source = GES_CONTAINER_CHILDREN (clip0)->data;
5086
5087 fail_if (ges_layer_add_clip (layer, clip0));
5088
5089 /* children should be the same */
5090 assert_num_children (clip0, 1);
5091 assert_num_children (clip1, 4);
5092
5093 fail_unless (GES_CONTAINER_CHILDREN (clip0)->data == source);
5094
5095 gst_object_unref (clip0);
5096 gst_object_unref (clip1);
5097 gst_object_unref (timeline);
5098
5099 ges_deinit ();
5100 }
5101
5102 GST_END_TEST;
5103
5104 static void
5105 _check_ges_error (const gchar * file, gint line, GError * error,
5106 gint error_code)
5107 {
5108 if (!error)
5109 _ck_assert_failed (file, line, "Expected an error, but got none", NULL);
5110 if (error->domain != GES_ERROR)
5111 _ck_assert_failed (file, line, "Error domain check failed",
5112 "Error \"%s\" is not in the GES_ERROR domain", error->message, NULL);
5113 if (error->code != error_code)
5114 _ck_assert_failed (file, line, "Error code check failed",
5115 "Error code %i is not the expected %i (%s)", error->code, error_code,
5116 error->message, NULL);
5117 g_error_free (error);
5118 }
5119
5120 static void
5121 _check_timeline_to_internal (const gchar * file, gint line, GESClip * clip,
5122 GESTrackElement * child, gdouble in_s, gdouble expect_out_s)
5123 {
5124 GError *error = NULL;
5125 GstClockTime in = in_s * GST_SECOND;
5126 GstClockTime expect = expect_out_s * GST_SECOND;
5127 GstClockTime found =
5128 ges_clip_get_internal_time_from_timeline_time (clip, child, in, &error);
5129
5130 if (found != expect)
5131 _ck_assert_failed (file, line, "Conversion check failed",
5132 "Conversion from timeline time %" GST_TIME_FORMAT " to the internal "
5133 "time of %" GES_FORMAT " gave %" GST_TIME_FORMAT " rather than the "
5134 "expected %" GST_TIME_FORMAT " (error: %s)", GST_TIME_ARGS (in),
5135 GES_ARGS (child), GST_TIME_ARGS (found), GST_TIME_ARGS (expect),
5136 error ? error->message : "None", NULL);
5137 if (error)
5138 _ck_assert_failed (file, line, "Conversion returned an error",
5139 "Conversion from timeline time %" GST_TIME_FORMAT " to the internal "
5140 "time of %" GES_FORMAT " returned the error \"%s\"",
5141 GST_TIME_ARGS (in), GES_ARGS (child), error->message, NULL);
5142 _mark_point (file, line);
5143 }
5144
5145 static void
5146 _check_timeline_to_internal_fails (const gchar * file, gint line,
5147 GESClip * clip, GESTrackElement * child, gdouble in_s, gint error_code)
5148 {
5149 GError *error = NULL;
5150 GstClockTime in = in_s * GST_SECOND;
5151 GstClockTime found =
5152 ges_clip_get_internal_time_from_timeline_time (clip, child, in, &error);
5153
5154 if (GST_CLOCK_TIME_IS_VALID (found))
5155 _ck_assert_failed (file, line, "Conversion did not fail",
5156 "Conversion from timeline time %" GST_TIME_FORMAT " to the internal "
5157 "time of %" GES_FORMAT " successfully converted to %" GST_TIME_FORMAT
5158 " rather than GST_CLOCK_TIME_NONE", GST_TIME_ARGS (in),
5159 GES_ARGS (child), GST_TIME_ARGS (found), NULL);
5160 _check_ges_error (file, line, error, error_code);
5161 _mark_point (file, line);
5162 }
5163
5164 static void
5165 _check_internal_to_timeline (const gchar * file, gint line, GESClip * clip,
5166 GESTrackElement * child, gdouble in_s, gdouble expect_out_s)
5167 {
5168 GError *error = NULL;
5169 GstClockTime in = in_s * GST_SECOND;
5170 GstClockTime expect = expect_out_s * GST_SECOND;
5171 GstClockTime found =
5172 ges_clip_get_timeline_time_from_internal_time (clip, child, in, &error);
5173
5174 if (found != expect)
5175 _ck_assert_failed (file, line, "Conversion check failed",
5176 "Conversion from the internal time %" GST_TIME_FORMAT " of %"
5177 GES_FORMAT " to the timeline time gave %" GST_TIME_FORMAT " rather "
5178 "than the expected %" GST_TIME_FORMAT, GST_TIME_ARGS (in),
5179 GES_ARGS (child), GST_TIME_ARGS (found), GST_TIME_ARGS (expect), NULL);
5180 if (error)
5181 _ck_assert_failed (file, line, "Conversion returned an error",
5182 "Conversion from the internal time %" GST_TIME_FORMAT " of %"
5183 GES_FORMAT " to the timeline time returned the error \"%s\"",
5184 GST_TIME_ARGS (in), GES_ARGS (child), error->message, NULL);
5185 _mark_point (file, line);
5186 }
5187
5188 static void
5189 _check_internal_to_timeline_fails (const gchar * file, gint line,
5190 GESClip * clip, GESTrackElement * child, gdouble in_s, gint error_code)
5191 {
5192 GError *error = NULL;
5193 GstClockTime in = in_s * GST_SECOND;
5194 GstClockTime found =
5195 ges_clip_get_timeline_time_from_internal_time (clip, child, in, &error);
5196
5197 if (GST_CLOCK_TIME_IS_VALID (found))
5198 _ck_assert_failed (file, line, "Conversion did not fail",
5199 "Conversion from the internal time %" GST_TIME_FORMAT " of %"
5200 GES_FORMAT " to the timeline time gave %" GST_TIME_FORMAT " rather "
5201 "than GST_CLOCK_TIME_NONE", GST_TIME_ARGS (in), GES_ARGS (child),
5202 GST_TIME_ARGS (found), NULL);
5203 _check_ges_error (file, line, error, error_code);
5204 _mark_point (file, line);
5205 }
5206
5207 static void
5208 _check_frame_to_timeline (const gchar * file, gint line, GESClip * clip,
5209 GESFrameNumber frame, gdouble expect_out_s)
5210 {
5211 GError *error = NULL;
5212 GstClockTime expect = expect_out_s * GST_SECOND;
5213 GstClockTime found =
5214 ges_clip_get_timeline_time_from_source_frame (clip, frame, &error);
5215
5216 if (found != expect)
5217 _ck_assert_failed (file, line, "Conversion check failed",
5218 "Conversion from the source frame %" G_GINT64_FORMAT " to the "
5219 "timeline time gave %" GST_TIME_FORMAT " rather than the expected %"
5220 GST_TIME_FORMAT, frame, GST_TIME_ARGS (found), GST_TIME_ARGS (expect),
5221 NULL);
5222 if (error)
5223 _ck_assert_failed (file, line, "Conversion returned an error",
5224 "Conversion from the source frame %" G_GINT64_FORMAT " to the "
5225 "timeline time returned the error \"%s\"", frame, error->message, NULL);
5226 _mark_point (file, line);
5227 }
5228
5229 static void
5230 _check_frame_to_timeline_fails (const gchar * file, gint line, GESClip * clip,
5231 GESFrameNumber frame, gint error_code)
5232 {
5233 GError *error = NULL;
5234 GstClockTime found =
5235 ges_clip_get_timeline_time_from_source_frame (clip, frame, &error);
5236
5237 if (GST_CLOCK_TIME_IS_VALID (found))
5238 _ck_assert_failed (file, line, "Conversion did not fail",
5239 "Conversion from the source frame %" G_GINT64_FORMAT " to the "
5240 "timeline time gave %" GST_TIME_FORMAT " rather than the expected "
5241 "GST_CLOCK_TIME_NONE", frame, GST_TIME_ARGS (found), NULL);
5242 _check_ges_error (file, line, error, error_code);
5243 _mark_point (file, line);
5244 }
5245
5246 #define _assert_timeline_to_internal(clip, child, in, expect_out) \
5247 _check_timeline_to_internal (__FILE__, __LINE__, clip, child, in, expect_out)
5248
5249 #define _assert_timeline_to_internal_fails(clip, child, in, error_code) \
5250 _check_timeline_to_internal_fails (__FILE__, __LINE__, clip, child, in, \
5251 error_code)
5252
5253 #define _assert_internal_to_timeline(clip, child, in, expect_out) \
5254 _check_internal_to_timeline (__FILE__, __LINE__, clip, child, in, expect_out)
5255
5256 #define _assert_internal_to_timeline_fails(clip, child, in, error_code) \
5257 _check_internal_to_timeline_fails (__FILE__, __LINE__, clip, child, in, \
5258 error_code)
5259
5260 #define _assert_frame_to_timeline(clip, frame, expect_out) \
5261 _check_frame_to_timeline (__FILE__, __LINE__, clip, frame, expect_out)
5262
5263 #define _assert_frame_to_timeline_fails(clip, frame, error_code) \
5264 _check_frame_to_timeline_fails (__FILE__, __LINE__, clip, frame, error_code)
5265
5266 GST_START_TEST (test_convert_time)
5267 {
5268 GESTimeline *timeline;
5269 GESTrack *track0, *track1;
5270 GESAsset *asset;
5271 GESLayer *layer;
5272 GESClip *clip;
5273 GESTrackElement *source0, *source1, *rate0, *rate1, *rate2, *overlay;
5274 GValue val = G_VALUE_INIT;
5275
5276 ges_init ();
5277
5278 asset = ges_asset_request (GES_TYPE_TEST_CLIP,
5279 "framerate=30/1, max-duration=93.0", NULL);
5280 fail_unless (asset);
5281
5282 timeline = ges_timeline_new ();
5283
5284 track0 = GES_TRACK (ges_video_track_new ());
5285 track1 = GES_TRACK (ges_video_track_new ());
5286
5287 fail_unless (ges_timeline_add_track (timeline, track0));
5288 fail_unless (ges_timeline_add_track (timeline, track1));
5289
5290 layer = ges_timeline_append_layer (timeline);
5291
5292 clip = ges_layer_add_asset (layer, asset, 20 * GST_SECOND,
5293 13 * GST_SECOND, 10 * GST_SECOND, GES_TRACK_TYPE_VIDEO);
5294 fail_unless (clip);
5295 CHECK_OBJECT_PROPS_MAX (clip, 20 * GST_SECOND, 13 * GST_SECOND,
5296 10 * GST_SECOND, 93 * GST_SECOND);
5297
5298 source0 =
5299 ges_clip_find_track_element (clip, track0, GES_TYPE_VIDEO_TEST_SOURCE);
5300 source1 =
5301 ges_clip_find_track_element (clip, track1, GES_TYPE_VIDEO_TEST_SOURCE);
5302
5303 rate0 = GES_TRACK_ELEMENT (ges_effect_new ("videorate"));
5304 rate1 = GES_TRACK_ELEMENT (ges_effect_new ("videorate"));
5305 rate2 = GES_TRACK_ELEMENT (ges_effect_new ("videorate"));
5306 overlay = GES_TRACK_ELEMENT (ges_effect_new ("textoverlay"));
5307 ges_track_element_set_has_internal_source (overlay, TRUE);
5308 /* enough internal content to last 10 seconds at a rate of 4.0 */
5309 assert_set_inpoint (overlay, 7 * GST_SECOND);
5310 assert_set_max_duration (overlay, 50 * GST_SECOND);
5311
5312 fail_unless (ges_track_add_element (track0, rate0));
5313 fail_unless (ges_track_add_element (track1, rate1));
5314 fail_unless (ges_track_add_element (track1, rate2));
5315 fail_unless (ges_track_add_element (track1, overlay));
5316
5317 _assert_add (clip, rate0);
5318 _assert_add (clip, rate2);
5319 _assert_add (clip, overlay);
5320 _assert_add (clip, rate1);
5321
5322 /* in track0:
5323 *
5324 * source0 -> rate0 -> out
5325 *
5326 * in track1:
5327 *
5328 * source1 -> rate1 -> overlay -> rate2 -> out
5329 */
5330
5331 g_value_init (&val, G_TYPE_DOUBLE);
5332
5333 _assert_rate_equal (rate0, "rate", 1.0, val);
5334 _assert_rate_equal (rate1, "rate", 1.0, val);
5335 _assert_rate_equal (rate2, "rate", 1.0, val);
5336
5337 /* without rates */
5338
5339 /* start of the clip */
5340 _assert_internal_to_timeline (clip, source0, 13, 20);
5341 _assert_internal_to_timeline (clip, source1, 13, 20);
5342 _assert_internal_to_timeline (clip, overlay, 7, 20);
5343 _assert_frame_to_timeline (clip, 390, 20);
5344 _assert_timeline_to_internal (clip, source0, 20, 13);
5345 _assert_timeline_to_internal (clip, source1, 20, 13);
5346 _assert_timeline_to_internal (clip, overlay, 20, 7);
5347
5348 /* middle of the clip */
5349 _assert_internal_to_timeline (clip, source0, 18, 25);
5350 _assert_internal_to_timeline (clip, source1, 18, 25);
5351 _assert_internal_to_timeline (clip, overlay, 12, 25);
5352 _assert_frame_to_timeline (clip, 540, 25);
5353 _assert_timeline_to_internal (clip, source0, 25, 18);
5354 _assert_timeline_to_internal (clip, source1, 25, 18);
5355 _assert_timeline_to_internal (clip, overlay, 25, 12);
5356
5357 /* end of the clip */
5358 _assert_internal_to_timeline (clip, source0, 23, 30);
5359 _assert_internal_to_timeline (clip, source1, 23, 30);
5360 _assert_internal_to_timeline (clip, overlay, 17, 30);
5361 _assert_frame_to_timeline (clip, 690, 30);
5362 _assert_timeline_to_internal (clip, source0, 30, 23);
5363 _assert_timeline_to_internal (clip, source1, 30, 23);
5364 _assert_timeline_to_internal (clip, overlay, 30, 17);
5365
5366 /* beyond the end of the clip */
5367 /* exceeds the max-duration of the elements, but that is ok */
5368 _assert_internal_to_timeline (clip, source0, 123, 130);
5369 _assert_internal_to_timeline (clip, source1, 123, 130);
5370 _assert_internal_to_timeline (clip, overlay, 117, 130);
5371 _assert_frame_to_timeline (clip, 3690, 130);
5372 _assert_timeline_to_internal (clip, source0, 130, 123);
5373 _assert_timeline_to_internal (clip, source1, 130, 123);
5374 _assert_timeline_to_internal (clip, overlay, 130, 117);
5375
5376 /* before the start of the clip */
5377 _assert_internal_to_timeline (clip, source0, 8, 15);
5378 _assert_internal_to_timeline (clip, source1, 8, 15);
5379 _assert_internal_to_timeline (clip, overlay, 2, 15);
5380 _assert_frame_to_timeline (clip, 240, 15);
5381 _assert_timeline_to_internal (clip, source0, 15, 8);
5382 _assert_timeline_to_internal (clip, source1, 15, 8);
5383 _assert_timeline_to_internal (clip, overlay, 15, 2);
5384
5385 /* too early for overlay */
5386 _assert_timeline_to_internal (clip, source0, 10, 3);
5387 _assert_timeline_to_internal (clip, source1, 10, 3);
5388 _assert_timeline_to_internal_fails (clip, overlay, 10,
5389 GES_ERROR_NEGATIVE_TIME);
5390
5391 /* too early for sources */
5392 _assert_timeline_to_internal_fails (clip, source0, 5,
5393 GES_ERROR_NEGATIVE_TIME);
5394 _assert_timeline_to_internal_fails (clip, source1, 5,
5395 GES_ERROR_NEGATIVE_TIME);
5396 _assert_timeline_to_internal_fails (clip, overlay, 5,
5397 GES_ERROR_NEGATIVE_TIME);
5398
5399 assert_set_start (clip, 10 * GST_SECOND);
5400
5401 /* too early in the timeline */
5402 _assert_internal_to_timeline_fails (clip, source0, 2,
5403 GES_ERROR_NEGATIVE_TIME);
5404 _assert_internal_to_timeline_fails (clip, source1, 2,
5405 GES_ERROR_NEGATIVE_TIME);
5406 _assert_internal_to_timeline (clip, overlay, 2, 5);
5407 _assert_frame_to_timeline_fails (clip, 60, GES_ERROR_INVALID_FRAME_NUMBER);
5408
5409 assert_set_start (clip, 6 * GST_SECOND);
5410 _assert_internal_to_timeline_fails (clip, source0, 6,
5411 GES_ERROR_NEGATIVE_TIME);
5412 _assert_internal_to_timeline_fails (clip, source1, 6,
5413 GES_ERROR_NEGATIVE_TIME);
5414 _assert_internal_to_timeline_fails (clip, overlay, 0,
5415 GES_ERROR_NEGATIVE_TIME);
5416 _assert_frame_to_timeline_fails (clip, 180, GES_ERROR_INVALID_FRAME_NUMBER);
5417
5418 assert_set_start (clip, 20 * GST_SECOND);
5419
5420 /* now with rate effects
5421 * Note, they are currently out of sync */
5422 _assert_set_rate (rate0, "rate", 0.5, val);
5423 _assert_set_rate (rate1, "rate", 2.0, val);
5424 _assert_set_rate (rate2, "rate", 4.0, val);
5425
5426 CHECK_OBJECT_PROPS_MAX (clip, 20 * GST_SECOND, 13 * GST_SECOND,
5427 10 * GST_SECOND, 93 * GST_SECOND);
5428
5429 /* start of the clip is the same */
5430 _assert_internal_to_timeline (clip, source0, 13, 20);
5431 _assert_internal_to_timeline (clip, source1, 13, 20);
5432 _assert_internal_to_timeline (clip, overlay, 7, 20);
5433 _assert_timeline_to_internal (clip, source0, 20, 13);
5434 _assert_timeline_to_internal (clip, source1, 20, 13);
5435 _assert_timeline_to_internal (clip, overlay, 20, 7);
5436
5437 /* middle is different */
5438 /* 5 seconds in the timeline is 2.5 seconds into the source */
5439 _assert_internal_to_timeline (clip, source0, 15.5, 25);
5440 /* 5 seconds in the timeline is 40 seconds into the source */
5441 _assert_internal_to_timeline (clip, source1, 53, 25);
5442 /* 5 seconds in the timeline is 20 seconds into the source */
5443 _assert_internal_to_timeline (clip, overlay, 27, 25);
5444 /* reverse */
5445 _assert_timeline_to_internal (clip, source0, 25, 15.5);
5446 _assert_timeline_to_internal (clip, source1, 25, 53);
5447 _assert_timeline_to_internal (clip, overlay, 25, 27);
5448
5449 /* end is different */
5450 _assert_internal_to_timeline (clip, source0, 18, 30);
5451 _assert_internal_to_timeline (clip, source1, 93, 30);
5452 _assert_internal_to_timeline (clip, overlay, 47, 30);
5453 _assert_timeline_to_internal (clip, source0, 30, 18);
5454 _assert_timeline_to_internal (clip, source1, 30, 93);
5455 _assert_timeline_to_internal (clip, overlay, 30, 47);
5456
5457 /* beyond end is different */
5458 _assert_internal_to_timeline (clip, source0, 68, 130);
5459 _assert_internal_to_timeline (clip, source1, 893, 130);
5460 _assert_internal_to_timeline (clip, overlay, 447, 130);
5461 _assert_timeline_to_internal (clip, source0, 130, 68);
5462 _assert_timeline_to_internal (clip, source1, 130, 893);
5463 _assert_timeline_to_internal (clip, overlay, 130, 447);
5464
5465 /* before the start */
5466 _assert_internal_to_timeline (clip, source0, 12.5, 19);
5467 _assert_internal_to_timeline (clip, source1, 5, 19);
5468 _assert_internal_to_timeline (clip, overlay, 3, 19);
5469 _assert_timeline_to_internal (clip, source0, 19, 12.5);
5470 _assert_timeline_to_internal (clip, source1, 19, 5);
5471 _assert_timeline_to_internal (clip, overlay, 19, 3);
5472
5473 /* too early for source1 and overlay */
5474 _assert_internal_to_timeline (clip, source0, 12, 18);
5475 _assert_timeline_to_internal (clip, source0, 18, 12);
5476 _assert_timeline_to_internal_fails (clip, source1, 18,
5477 GES_ERROR_NEGATIVE_TIME);
5478 _assert_timeline_to_internal_fails (clip, overlay, 18,
5479 GES_ERROR_NEGATIVE_TIME);
5480
5481 assert_set_inpoint (overlay, 8 * GST_SECOND);
5482 /* now fine */
5483 _assert_internal_to_timeline (clip, overlay, 0, 18);
5484 _assert_timeline_to_internal (clip, overlay, 18, 0);
5485
5486 assert_set_inpoint (overlay, 7 * GST_SECOND);
5487
5488 /* still not too early for source0 */
5489 _assert_internal_to_timeline (clip, source0, 5.5, 5);
5490 _assert_timeline_to_internal (clip, source0, 5, 5.5);
5491 _assert_timeline_to_internal_fails (clip, source1, 5,
5492 GES_ERROR_NEGATIVE_TIME);
5493 _assert_timeline_to_internal_fails (clip, overlay, 5,
5494 GES_ERROR_NEGATIVE_TIME);
5495
5496 _assert_internal_to_timeline (clip, source0, 3, 0);
5497 _assert_timeline_to_internal (clip, source0, 0, 3);
5498 _assert_timeline_to_internal_fails (clip, source1, 5,
5499 GES_ERROR_NEGATIVE_TIME);
5500 _assert_timeline_to_internal_fails (clip, overlay, 5,
5501 GES_ERROR_NEGATIVE_TIME);
5502
5503 /* too early for the timeline */
5504 _assert_internal_to_timeline_fails (clip, source0, 2,
5505 GES_ERROR_NEGATIVE_TIME);
5506
5507 /* re-sync rates between tracks */
5508 _assert_set_rate (rate2, "rate", 0.25, val);
5509
5510 CHECK_OBJECT_PROPS_MAX (clip, 20 * GST_SECOND, 13 * GST_SECOND,
5511 10 * GST_SECOND, 93 * GST_SECOND);
5512
5513 /* start of the clip */
5514 _assert_internal_to_timeline (clip, source0, 13, 20);
5515 _assert_internal_to_timeline (clip, source1, 13, 20);
5516 _assert_internal_to_timeline (clip, overlay, 7, 20);
5517 _assert_frame_to_timeline (clip, 390, 20);
5518 _assert_timeline_to_internal (clip, source0, 20, 13);
5519 _assert_timeline_to_internal (clip, source1, 20, 13);
5520 _assert_timeline_to_internal (clip, overlay, 20, 7);
5521
5522 /* middle of the clip */
5523 _assert_internal_to_timeline (clip, source0, 15.5, 25);
5524 _assert_internal_to_timeline (clip, source1, 15.5, 25);
5525 _assert_internal_to_timeline (clip, overlay, 8.25, 25);
5526 _assert_frame_to_timeline (clip, 465, 25);
5527 _assert_timeline_to_internal (clip, source0, 25, 15.5);
5528 _assert_timeline_to_internal (clip, source1, 25, 15.5);
5529 _assert_timeline_to_internal (clip, overlay, 25, 8.25);
5530
5531 /* end of the clip */
5532 _assert_internal_to_timeline (clip, source0, 18, 30);
5533 _assert_internal_to_timeline (clip, source1, 18, 30);
5534 _assert_internal_to_timeline (clip, overlay, 9.5, 30);
5535 _assert_frame_to_timeline (clip, 540, 30);
5536 _assert_timeline_to_internal (clip, source0, 30, 18);
5537 _assert_timeline_to_internal (clip, source1, 30, 18);
5538 _assert_timeline_to_internal (clip, overlay, 30, 9.5);
5539
5540 /* beyond the end of the clip */
5541 /* exceeds the max-duration of the elements, but that is ok */
5542 _assert_internal_to_timeline (clip, source0, 68, 130);
5543 _assert_internal_to_timeline (clip, source1, 68, 130);
5544 _assert_internal_to_timeline (clip, overlay, 34.5, 130);
5545 _assert_frame_to_timeline (clip, 2040, 130);
5546 _assert_timeline_to_internal (clip, source0, 130, 68);
5547 _assert_timeline_to_internal (clip, source1, 130, 68);
5548 _assert_timeline_to_internal (clip, overlay, 130, 34.5);
5549
5550 /* before the start of the clip */
5551 _assert_internal_to_timeline (clip, source0, 10.5, 15);
5552 _assert_internal_to_timeline (clip, source1, 10.5, 15);
5553 _assert_internal_to_timeline (clip, overlay, 5.75, 15);
5554 _assert_frame_to_timeline (clip, 315, 15);
5555 _assert_timeline_to_internal (clip, source0, 15, 10.5);
5556 _assert_timeline_to_internal (clip, source1, 15, 10.5);
5557 _assert_timeline_to_internal (clip, overlay, 15, 5.75);
5558
5559 /* not too early */
5560 _assert_internal_to_timeline (clip, source0, 3, 0);
5561 _assert_internal_to_timeline (clip, source1, 3, 0);
5562 _assert_internal_to_timeline (clip, overlay, 2, 0);
5563 _assert_frame_to_timeline (clip, 90, 0);
5564 _assert_timeline_to_internal (clip, source0, 0, 3);
5565 _assert_timeline_to_internal (clip, source1, 0, 3);
5566 _assert_timeline_to_internal (clip, overlay, 0, 2);
5567
5568 /* too early for timeline */
5569 _assert_internal_to_timeline_fails (clip, source0, 2,
5570 GES_ERROR_NEGATIVE_TIME);
5571 _assert_internal_to_timeline_fails (clip, source1, 2,
5572 GES_ERROR_NEGATIVE_TIME);
5573 _assert_internal_to_timeline_fails (clip, overlay, 1,
5574 GES_ERROR_NEGATIVE_TIME);
5575 _assert_frame_to_timeline_fails (clip, 89, GES_ERROR_INVALID_FRAME_NUMBER);
5576
5577 assert_set_start (clip, 30 * GST_SECOND);
5578 /* timeline times have shifted by 10 */
5579 _assert_timeline_to_internal (clip, source0, 10, 3);
5580 _assert_timeline_to_internal (clip, source1, 10, 3);
5581 _assert_timeline_to_internal (clip, overlay, 10, 2);
5582
5583 _assert_timeline_to_internal (clip, source0, 4, 0);
5584 _assert_timeline_to_internal (clip, source1, 4, 0);
5585 _assert_timeline_to_internal (clip, overlay, 2, 0);
5586 /* too early for internal */
5587 _assert_timeline_to_internal_fails (clip, source0, 3,
5588 GES_ERROR_NEGATIVE_TIME);
5589 _assert_timeline_to_internal_fails (clip, source1, 3,
5590 GES_ERROR_NEGATIVE_TIME);
5591 _assert_timeline_to_internal_fails (clip, overlay, 1,
5592 GES_ERROR_NEGATIVE_TIME);
5593
5594 g_value_unset (&val);
5595 gst_object_unref (asset);
5596 gst_object_unref (timeline);
5597
5598 ges_deinit ();
5599 }
5600
5601 GST_END_TEST;
5602
5603 static Suite *
5604 ges_suite (void)
5605 {
5606 Suite *s = suite_create ("ges-clip");
5607 TCase *tc_chain = tcase_create ("clip");
5608
5609 suite_add_tcase (s, tc_chain);
5610
5611 tcase_add_test (tc_chain, test_object_properties);
5612 tcase_add_test (tc_chain, test_split_object);
5613 tcase_add_test (tc_chain, test_split_ordering);
5614 tcase_add_test (tc_chain, test_split_direct_bindings);
5615 tcase_add_test (tc_chain, test_split_direct_absolute_bindings);
5616 tcase_add_test (tc_chain, test_split_with_auto_transitions);
5617 tcase_add_test (tc_chain, test_clip_group_ungroup);
5618 tcase_add_test (tc_chain, test_clip_can_group);
5619 tcase_add_test (tc_chain, test_adding_children_to_track);
5620 tcase_add_test (tc_chain, test_clip_refcount_remove_child);
5621 tcase_add_test (tc_chain, test_clip_find_track_element);
5622 tcase_add_test (tc_chain, test_effects_priorities);
5623 tcase_add_test (tc_chain, test_children_time_setters);
5624 tcase_add_test (tc_chain, test_not_enough_internal_content_for_core);
5625 tcase_add_test (tc_chain, test_can_add_effect);
5626 tcase_add_test (tc_chain, test_children_active);
5627 tcase_add_test (tc_chain, test_children_inpoint);
5628 tcase_add_test (tc_chain, test_children_max_duration);
5629 tcase_add_test (tc_chain, test_duration_limit);
5630 tcase_add_test (tc_chain, test_can_set_duration_limit);
5631 tcase_add_test (tc_chain, test_rate_effects_duration_limit);
5632 tcase_add_test (tc_chain, test_children_properties_contain);
5633 tcase_add_test (tc_chain, test_children_properties_change);
5634 tcase_add_test (tc_chain, test_copy_paste_children_properties);
5635 tcase_add_test (tc_chain, test_children_property_bindings_with_rate_effects);
5636 tcase_add_test (tc_chain, test_unchanged_after_layer_add_failure);
5637 tcase_add_test (tc_chain, test_convert_time);
5638
5639 return s;
5640 }
5641
5642 GST_CHECK_MAIN (ges);