1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3 * 2009 Nokia Corporation
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:ges-timeline-layer
23 * @short_description: Non-overlaping sequence of #GESTimelineObject
25 * Responsible for the ordering of the various contained TimelineObject(s). A
26 * timeline layer has a "priority" property, which is used to manage the
27 * priorities of individual TimelineObjects. Two layers should not have the
28 * same priority within a given timeline.
31 #include "ges-internal.h"
32 #include "gesmarshal.h"
33 #include "ges-timeline-layer.h"
35 #include "ges-timeline-source.h"
37 #define LAYER_HEIGHT 1000
40 track_object_removed_cb (GESTimelineObject * object,
41 GESTrackObject * track_object);
42 static void track_object_added_cb (GESTimelineObject * object,
43 GESTrackObject * track_object, GHashTable * signal_table);
44 static void track_object_changed_cb (GESTrackObject * track_object,
45 GParamSpec * arg G_GNUC_UNUSED);
46 static void calculate_transitions (GESTrackObject * track_object);
47 static void calculate_next_transition (GESTrackObject * track_object,
48 GESTimelineLayer * layer);
51 timeline_object_height_changed_cb (GESTimelineObject * obj,
52 GESTrackEffect * tr_eff, GESTimelineObject * second_obj);
54 G_DEFINE_TYPE (GESTimelineLayer, ges_timeline_layer, G_TYPE_INITIALLY_UNOWNED);
56 struct _GESTimelineLayerPrivate
59 GList *objects_start; /* The TimelineObjects sorted by start and
62 guint32 priority; /* The priority of the layer within the
63 * containing timeline */
65 gboolean auto_transition;
68 GHashTable *signal_table;
86 static guint ges_timeline_layer_signals[LAST_SIGNAL] = { 0 };
88 static gboolean ges_timeline_layer_resync_priorities (GESTimelineLayer * layer);
90 static GList *track_get_by_layer (GESTimelineLayer * layer, GESTrack * track);
92 static void compare (GList * compared, GESTrackObject * track_object,
96 ges_timeline_layer_get_property (GObject * object, guint property_id,
97 GValue * value, GParamSpec * pspec)
99 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
101 switch (property_id) {
103 g_value_set_uint (value, layer->priv->priority);
105 case PROP_AUTO_TRANSITION:
106 g_value_set_boolean (value, layer->priv->auto_transition);
109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
114 ges_timeline_layer_set_property (GObject * object, guint property_id,
115 const GValue * value, GParamSpec * pspec)
117 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
119 switch (property_id) {
121 ges_timeline_layer_set_priority (layer, g_value_get_uint (value));
123 case PROP_AUTO_TRANSITION:
124 ges_timeline_layer_set_auto_transition (layer,
125 g_value_get_boolean (value));
128 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
133 ges_timeline_layer_dispose (GObject * object)
135 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
136 GESTimelineLayerPrivate *priv = layer->priv;
138 GST_DEBUG ("Disposing layer");
140 while (priv->objects_start)
141 ges_timeline_layer_remove_object (layer,
142 (GESTimelineObject *) priv->objects_start->data);
144 G_OBJECT_CLASS (ges_timeline_layer_parent_class)->dispose (object);
148 ges_timeline_layer_class_init (GESTimelineLayerClass * klass)
150 GObjectClass *object_class = G_OBJECT_CLASS (klass);
152 g_type_class_add_private (klass, sizeof (GESTimelineLayerPrivate));
154 object_class->get_property = ges_timeline_layer_get_property;
155 object_class->set_property = ges_timeline_layer_set_property;
156 object_class->dispose = ges_timeline_layer_dispose;
159 * GESTimelineLayer:priority
161 * The priority of the layer in the #GESTimeline. 0 is the highest
162 * priority. Conceptually, a #GESTimeline is a stack of GESTimelineLayers,
163 * and the priority of the layer represents its position in the stack. Two
164 * layers should not have the same priority within a given GESTimeline.
166 g_object_class_install_property (object_class, PROP_PRIORITY,
167 g_param_spec_uint ("priority", "Priority",
168 "The priority of the layer", 0, G_MAXUINT, 0, G_PARAM_READWRITE));
171 * GESTimelineLayer:auto_transitioning
173 * Sets whether transitions are added automatically when timeline objects overlap
175 g_object_class_install_property (object_class, PROP_AUTO_TRANSITION,
176 g_param_spec_boolean ("auto-transition", "Auto-Transition",
177 "whether the transitions are added", FALSE, G_PARAM_READWRITE));
180 * GESTimelineLayer::object-added
181 * @layer: the #GESTimelineLayer
182 * @object: the #GESTimelineObject that was added.
184 * Will be emitted after the object was added to the layer.
186 ges_timeline_layer_signals[OBJECT_ADDED] =
187 g_signal_new ("object-added", G_TYPE_FROM_CLASS (klass),
188 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass, object_added),
189 NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
190 GES_TYPE_TIMELINE_OBJECT);
193 * GESTimelineLayer::object-removed
194 * @layer: the #GESTimelineLayer
195 * @object: the #GESTimelineObject that was removed
197 * Will be emitted after the object was removed from the layer.
199 ges_timeline_layer_signals[OBJECT_REMOVED] =
200 g_signal_new ("object-removed", G_TYPE_FROM_CLASS (klass),
201 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass,
202 object_removed), NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
203 GES_TYPE_TIMELINE_OBJECT);
207 ges_timeline_layer_init (GESTimelineLayer * self)
209 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
210 GES_TYPE_TIMELINE_LAYER, GESTimelineLayerPrivate);
212 self->priv->priority = 0;
213 self->priv->auto_transition = FALSE;
214 self->min_gnl_priority = 0;
215 self->max_gnl_priority = LAYER_HEIGHT;
216 self->priv->signal_table =
217 g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref,
222 * ges_timeline_layer_new:
224 * Creates a new #GESTimelineLayer.
226 * Returns: A new #GESTimelineLayer
229 ges_timeline_layer_new (void)
231 return g_object_new (GES_TYPE_TIMELINE_LAYER, NULL);
235 ges_timeline_layer_set_timeline (GESTimelineLayer * layer,
236 GESTimeline * timeline)
238 GST_DEBUG ("layer:%p, timeline:%p", layer, timeline);
240 layer->timeline = timeline;
244 objects_start_compare (GESTimelineObject * a, GESTimelineObject * b)
246 if (a->start == b->start) {
247 if (a->priority < b->priority)
249 if (a->priority > b->priority)
253 if (a->start < b->start)
255 if (a->start > b->start)
261 track_get_by_layer (GESTimelineLayer * layer, GESTrack * track)
263 GList *tck_objects_list = NULL, *tmp = NULL, *return_list = NULL;
264 GESTimelineObject *tl_obj;
266 tck_objects_list = ges_track_get_objects (track);
267 for (tmp = tck_objects_list; tmp; tmp = tmp->next) {
268 tl_obj = ges_track_object_get_timeline_object (tmp->data);
270 if (ges_timeline_object_get_layer (tl_obj) == layer) {
271 /* We steal the reference from tck_objects_list */
272 return_list = g_list_append (return_list, tmp->data);
275 g_object_unref (tmp->data);
282 * ges_timeline_layer_add_object:
283 * @layer: a #GESTimelineLayer
284 * @object: (transfer full): the #GESTimelineObject to add.
286 * Adds the given object to the layer. Sets the object's parent, and thus
287 * takes ownership of the object.
289 * An object can only be added to one layer.
291 * Returns: TRUE if the object was properly added to the layer, or FALSE
292 * if the @layer refuses to add the object.
295 ges_timeline_layer_add_object (GESTimelineLayer * layer,
296 GESTimelineObject * object)
298 GESTimelineLayer *tl_obj_layer;
299 guint32 maxprio, minprio, prio;
301 GST_DEBUG ("layer:%p, object:%p", layer, object);
303 tl_obj_layer = ges_timeline_object_get_layer (object);
305 if (G_UNLIKELY (tl_obj_layer)) {
306 GST_WARNING ("TimelineObject %p already belongs to another layer", object);
307 g_object_unref (tl_obj_layer);
311 g_object_ref_sink (object);
313 /* Take a reference to the object and store it stored by start/priority */
314 layer->priv->objects_start =
315 g_list_insert_sorted (layer->priv->objects_start, object,
316 (GCompareFunc) objects_start_compare);
318 if (layer->priv->auto_transition) {
319 if (GES_IS_TIMELINE_SOURCE (object)) {
320 g_signal_connect (G_OBJECT (object), "track-object-added",
321 G_CALLBACK (track_object_added_cb), layer->priv->signal_table);
322 g_signal_connect (G_OBJECT (object), "track-object-removed",
323 G_CALLBACK (track_object_removed_cb), NULL);
327 /* Inform the object it's now in this layer */
328 ges_timeline_object_set_layer (object, layer);
330 GST_DEBUG ("current object priority : %d, layer min/max : %d/%d",
331 GES_TIMELINE_OBJECT_PRIORITY (object),
332 layer->min_gnl_priority, layer->max_gnl_priority);
334 /* Set the priority. */
335 maxprio = layer->max_gnl_priority;
336 minprio = layer->min_gnl_priority;
337 prio = GES_TIMELINE_OBJECT_PRIORITY (object);
338 if (minprio + prio > (maxprio)) {
339 GST_WARNING ("%p is out of the layer %p space, setting its priority to "
340 "setting its priority %d to failthe maximum priority of the layer %d",
341 object, layer, prio, maxprio - minprio);
342 ges_timeline_object_set_priority (object, LAYER_HEIGHT - 1);
344 /* If the object has an acceptable priority, we just let it with its current
347 ges_timeline_layer_resync_priorities (layer);
349 /* emit 'object-added' */
350 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_ADDED], 0, object);
356 track_object_duration_cb (GESTrackObject * track_object,
357 GParamSpec * arg G_GNUC_UNUSED)
359 GESTimelineLayer *layer;
360 GESTimelineObject *tlobj;
362 tlobj = ges_track_object_get_timeline_object (track_object);
363 layer = ges_timeline_object_get_layer (tlobj);
364 if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
365 GST_DEBUG ("Here we should recalculate");
366 calculate_next_transition (track_object, layer);
370 track_object_deleted_cb (GESTrack * track, GESTrackObject * track_object)
372 GList *track_objects, *tmp, *cur;
373 GESTimelineLayer *layer;
375 track_objects = ges_track_get_objects (track);
376 cur = g_list_find (track_objects, track_object);
377 for (tmp = cur->next; tmp; tmp = tmp->next) {
378 if (GES_IS_TRACK_SOURCE (tmp->data)) {
381 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
382 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
384 ges_timeline_object_get_layer (ges_track_object_get_timeline_object
386 if (ges_timeline_layer_get_auto_transition (layer)) {
387 ges_track_enable_update (track, FALSE);
388 ges_timeline_layer_remove_object (layer,
389 ges_track_object_get_timeline_object (tmp->data));
390 ges_track_enable_update (track, TRUE);
392 g_object_unref (layer);
396 for (tmp = cur->prev; tmp; tmp = tmp->prev) {
397 if (GES_IS_TRACK_SOURCE (tmp->data)) {
400 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
401 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
403 ges_timeline_object_get_layer (ges_track_object_get_timeline_object
405 if (ges_timeline_layer_get_auto_transition (layer)) {
406 ges_track_enable_update (track, FALSE);
407 ges_timeline_layer_remove_object (layer,
408 ges_track_object_get_timeline_object (tmp->data));
409 ges_track_enable_update (track, TRUE);
411 g_object_unref (layer);
414 g_object_unref (track_object);
418 track_object_added_cb (GESTimelineObject * object,
419 GESTrackObject * track_object, GHashTable * signal_table)
424 if (GES_IS_TRACK_SOURCE (track_object)) {
425 g_signal_connect (G_OBJECT (track_object), "notify::start",
426 G_CALLBACK (track_object_changed_cb), NULL);
427 g_signal_connect (G_OBJECT (track_object), "notify::duration",
428 G_CALLBACK (track_object_duration_cb), NULL);
429 calculate_transitions (track_object);
431 track = ges_track_object_get_track (track_object);
432 if (!g_hash_table_lookup (signal_table, track)) {
433 ptr = g_signal_connect (track, "track-object-removed",
434 (GCallback) track_object_deleted_cb, NULL);
435 g_hash_table_insert (signal_table, track, &ptr);
441 track_object_removed_cb (GESTimelineObject * object,
442 GESTrackObject * track_object)
445 if (GES_IS_TRACK_SOURCE (track_object)) {
446 g_signal_handlers_disconnect_by_func (track_object, track_object_changed_cb,
448 calculate_transitions (track_object);
454 timeline_object_height_changed_cb (GESTimelineObject * obj,
455 GESTrackEffect * tr_eff, GESTimelineObject * second_obj)
457 gint priority, height;
458 g_object_get (obj, "height", &height, "priority", &priority, NULL);
459 g_object_set (second_obj, "priority", priority + height, NULL);
463 track_object_changed_cb (GESTrackObject * track_object,
464 GParamSpec * arg G_GNUC_UNUSED)
466 if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
467 calculate_transitions (track_object);
471 calculate_next_transition_with_list (GESTrackObject * track_object,
472 GList * tckobjs_in_layer, GESTimelineLayer * layer)
476 if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
479 if (compared == NULL)
480 /* This is the last TrackObject of the Track */
484 compared = compared->next;
485 if (compared == NULL)
487 } while (!GES_IS_TRACK_SOURCE (compared->data));
489 compare (compared, track_object, FALSE);
494 calculate_next_transition (GESTrackObject * track_object,
495 GESTimelineLayer * layer)
497 GESTrack *track = ges_track_object_get_track (track_object);
498 GList *tckobjs_in_layer = track_get_by_layer (layer, track);
500 if (ges_track_object_get_track (track_object)) {
501 calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
504 g_list_free_full (tckobjs_in_layer, g_object_unref);
508 calculate_transitions (GESTrackObject * track_object)
510 GList *tckobjs_in_layer, *compared;
511 GESTrack *track = ges_track_object_get_track (track_object);
512 GESTimelineLayer *layer;
513 GESTimelineObject *tlobj;
515 tlobj = ges_track_object_get_timeline_object (track_object);
516 layer = ges_timeline_object_get_layer (tlobj);
517 tckobjs_in_layer = track_get_by_layer (layer, track);
518 if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
521 compared = compared->prev;
523 if (compared == NULL) {
524 /* Nothing before, let's check after */
525 calculate_next_transition_with_list (track_object, tckobjs_in_layer,
530 } while (!GES_IS_TRACK_SOURCE (compared->data));
532 compare (compared, track_object, TRUE);
534 calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
537 g_list_free_full (tckobjs_in_layer, g_object_unref);
542 * @compared: The #GList of #GESTrackObjects that we compare with @track_object
543 * @track_object: The #GESTrackObject that serves as a reference
544 * @ahead: %TRUE if we are comparing frontward %FALSE if we are comparing
547 compare (GList * compared, GESTrackObject * track_object, gboolean ahead)
550 gint64 start, duration, compared_start, compared_duration, end, compared_end,
551 tr_start, tr_duration;
552 GESTimelineStandardTransition *trans = NULL;
554 GESTimelineLayer *layer;
555 GESTimelineObject *object, *compared_object, *first_object, *second_object;
558 g_return_if_fail (compared);
560 GST_DEBUG ("Recalculating transitions");
562 object = ges_track_object_get_timeline_object (track_object);
565 GST_WARNING ("Trackobject not in a timeline object: "
566 "Can not calulate transitions");
571 compared_object = ges_track_object_get_timeline_object (compared->data);
572 layer = ges_timeline_object_get_layer (object);
574 start = ges_track_object_get_start (track_object);
575 duration = ges_track_object_get_duration (track_object);
576 compared_start = ges_track_object_get_start (compared->data);
577 compared_duration = ges_track_object_get_duration (compared->data);
578 end = start + duration;
579 compared_end = compared_start + compared_duration;
582 /* Make sure we remove the last transition we created it is not needed
583 * FIXME make it a smarter way */
584 if (compared->prev && GES_IS_TRACK_TRANSITION (compared->prev->data)) {
585 trans = GES_TIMELINE_STANDARD_TRANSITION
586 (ges_track_object_get_timeline_object (compared->prev->data));
587 g_object_get (compared->prev->data, "start", &tr_start, "duration",
589 if (tr_start >= compared_start && tr_start + tr_duration <= compared_end)
590 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
594 for (tmp = compared->next; tmp; tmp = tmp->next) {
595 /* If we have a transitionmnmnm we recaluculuculate its values */
596 if (GES_IS_TRACK_TRANSITION (tmp->data)) {
597 g_object_get (tmp->data, "start", &tr_start, "duration", &tr_duration,
600 if (tr_start + tr_duration == compared_start + compared_duration) {
601 GESTimelineObject *tlobj;
602 tlobj = ges_track_object_get_timeline_object (tmp->data);
604 trans = GES_TIMELINE_STANDARD_TRANSITION (tlobj);
610 if (compared_end <= start) {
612 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
613 g_object_get (compared_object, "priority", &priority, NULL);
614 g_object_set (object, "priority", priority, NULL);
618 } else if (start > compared_start && end < compared_end) {
620 /* Transition not needed anymore */
621 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
624 } else if (start <= compared_start) {
626 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
633 if (compared->next && GES_IS_TRACK_TRANSITION (compared->next->data)) {
634 trans = GES_TIMELINE_STANDARD_TRANSITION
635 (ges_track_object_get_timeline_object (compared->next->data));
636 g_object_get (compared->prev->data, "start", &tr_start, "duration",
638 if (tr_start >= compared_start && tr_start + tr_duration <= compared_end)
639 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
642 for (tmp = compared->prev; tmp; tmp = tmp->prev) {
643 if GES_IS_TRACK_TRANSITION
645 g_object_get (tmp->data, "start", &tr_start, "duration", &tr_duration,
647 if (tr_start == compared_start) {
648 trans = GES_TIMELINE_STANDARD_TRANSITION
649 (ges_track_object_get_timeline_object (tmp->data));
655 if (start + duration <= compared_start) {
657 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
658 g_object_get (object, "priority", &priority, NULL);
659 g_object_set (compared_object, "priority", priority, NULL);
663 } else if (start > compared_start) {
665 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
668 } else if (start < compared_start && end > compared_end) {
670 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
681 ges_timeline_standard_transition_new_for_nick ((gchar *) "crossfade");
682 track = ges_track_object_get_track (track_object);
684 ges_timeline_object_set_supported_formats (GES_TIMELINE_OBJECT (trans),
687 ges_timeline_layer_add_object (layer, GES_TIMELINE_OBJECT (trans));
690 first_object = ges_track_object_get_timeline_object (compared->data);
691 second_object = object;
693 second_object = ges_track_object_get_timeline_object (compared->data);
694 first_object = object;
697 g_object_get (first_object, "priority", &priority, "height", &height, NULL);
698 g_object_set (second_object, "priority", priority + height, NULL);
699 g_signal_connect (first_object, "notify::height",
700 (GCallback) timeline_object_height_changed_cb, second_object);
704 g_object_set (trans, "start", start, "duration",
705 compared_duration + compared_start - start, NULL);
707 g_object_set (trans, "start", compared_start, "duration",
708 start + duration - compared_start, NULL);
712 g_object_unref (layer);
716 look_for_transition (GESTrackObject * track_object, GESTimelineLayer * layer)
719 GList *track_objects, *tmp, *cur;
721 track = ges_track_object_get_track (track_object);
723 track_objects = ges_track_get_objects (track);
725 cur = g_list_find (track_objects, track_object);
727 for (tmp = cur->next; tmp; tmp = tmp->next) {
728 if (GES_IS_TRACK_SOURCE (tmp->data)) {
731 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
732 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
733 ges_timeline_layer_remove_object (layer,
734 ges_track_object_get_timeline_object (tmp->data));
738 for (tmp = cur->prev; tmp; tmp = tmp->prev) {
739 if (GES_IS_TRACK_SOURCE (tmp->data)) {
742 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
743 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
744 ges_timeline_layer_remove_object (layer,
745 ges_track_object_get_timeline_object (tmp->data));
748 g_list_free_full (track_objects, g_object_unref);
752 * ges_timeline_layer_remove_object:
753 * @layer: a #GESTimelineLayer
754 * @object: the #GESTimelineObject to remove
756 * Removes the given @object from the @layer and unparents it.
757 * Unparenting it means the reference owned by @layer on the @object will be
758 * removed. If you wish to use the @object after this function, make sure you
759 * call g_object_ref() before removing it from the @layer.
761 * Returns: TRUE if the object could be removed, FALSE if the layer does
762 * not want to remove the object.
765 ges_timeline_layer_remove_object (GESTimelineLayer * layer,
766 GESTimelineObject * object)
768 GESTimelineLayer *tl_obj_layer;
769 GList *trackobjects, *tmp;
771 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), FALSE);
772 g_return_val_if_fail (GES_IS_TIMELINE_OBJECT (object), FALSE);
774 GST_DEBUG ("layer:%p, object:%p", layer, object);
776 tl_obj_layer = ges_timeline_object_get_layer (object);
777 if (G_UNLIKELY (tl_obj_layer != layer)) {
778 GST_WARNING ("TimelineObject doesn't belong to this layer");
779 if (tl_obj_layer != NULL)
780 g_object_unref (tl_obj_layer);
783 g_object_unref (tl_obj_layer);
785 if (layer->priv->auto_transition) {
786 trackobjects = ges_timeline_object_get_track_objects (object);
788 for (tmp = trackobjects; tmp; tmp = tmp->next) {
789 look_for_transition (tmp->data, layer);
792 g_list_free_full (trackobjects, g_object_unref);
795 /* emit 'object-removed' */
796 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_REMOVED], 0, object);
798 /* inform the object it's no longer in a layer */
799 ges_timeline_object_set_layer (object, NULL);
801 /* Remove it from our list of controlled objects */
802 layer->priv->objects_start =
803 g_list_remove (layer->priv->objects_start, object);
805 /* Remove our reference to the object */
806 g_object_unref (object);
812 * ges_timeline_layer_resync_priorities:
813 * @layer: a #GESTimelineLayer
815 * Resyncs the priorities of the objects controlled by @layer.
819 ges_timeline_layer_resync_priorities (GESTimelineLayer * layer)
822 GESTimelineObject *obj;
824 GST_DEBUG ("Resync priorities of %p", layer);
826 /* TODO : Inhibit composition updates while doing this.
827 * Ideally we want to do it from an even higher level, but here will
828 * do in the meantime. */
830 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
831 obj = GES_TIMELINE_OBJECT (tmp->data);
832 ges_timeline_object_set_priority (obj, GES_TIMELINE_OBJECT_PRIORITY (obj));
839 * ges_timeline_layer_set_priority:
840 * @layer: a #GESTimelineLayer
841 * @priority: the priority to set
843 * Sets the layer to the given @priority. See the documentation of the
844 * priority property for more information.
847 ges_timeline_layer_set_priority (GESTimelineLayer * layer, guint priority)
849 g_return_if_fail (GES_IS_TIMELINE_LAYER (layer));
851 GST_DEBUG ("layer:%p, priority:%d", layer, priority);
853 if (priority != layer->priv->priority) {
854 layer->priv->priority = priority;
855 layer->min_gnl_priority = (priority * LAYER_HEIGHT);
856 layer->max_gnl_priority = ((priority + 1) * LAYER_HEIGHT) - 1;
858 ges_timeline_layer_resync_priorities (layer);
863 * ges_timeline_layer_get_auto_transition:
864 * @layer: a #GESTimelineLayer
866 * Get the priority of @layer within the timeline.
868 * Returns: The priority of the @layer within the timeline.
871 ges_timeline_layer_get_auto_transition (GESTimelineLayer * layer)
873 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), 0);
875 return layer->priv->auto_transition;
879 * ges_timeline_layer_set_auto_transition:
880 * @layer: a #GESTimelineLayer
881 * @auto_transition: whether the auto_transition is active
883 * Sets the layer to the given @auto_transition. See the documentation of the
884 * property auto_transition for more information.
887 ges_timeline_layer_set_auto_transition (GESTimelineLayer * layer,
888 gboolean auto_transition)
892 g_return_if_fail (GES_IS_TIMELINE_LAYER (layer));
894 if (auto_transition) {
895 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
896 if (GES_IS_TIMELINE_SOURCE (tmp->data)) {
897 g_signal_connect (G_OBJECT (tmp->data), "track-object-added",
898 G_CALLBACK (track_object_added_cb), layer);
899 g_signal_connect (G_OBJECT (tmp->data), "track-object-removed",
900 G_CALLBACK (track_object_removed_cb), layer);
903 /* FIXME calculate all the transitions at that time */
905 layer->priv->auto_transition = auto_transition;
909 * ges_timeline_layer_get_priority:
910 * @layer: a #GESTimelineLayer
912 * Get the priority of @layer within the timeline.
914 * Returns: The priority of the @layer within the timeline.
917 ges_timeline_layer_get_priority (GESTimelineLayer * layer)
919 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), 0);
921 return layer->priv->priority;
925 * ges_timeline_layer_get_objects:
926 * @layer: a #GESTimelineLayer
928 * Get the timeline objects this layer contains.
930 * Returns: (transfer full) (element-type GESTimelineObject): a #GList of
931 * timeline objects. The user is responsible for
932 * unreffing the contained objects and freeing the list.
936 ges_timeline_layer_get_objects (GESTimelineLayer * layer)
940 GESTimelineLayerClass *klass;
942 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), NULL);
944 klass = GES_TIMELINE_LAYER_GET_CLASS (layer);
946 if (klass->get_objects) {
947 return klass->get_objects (layer);
950 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
951 ret = g_list_prepend (ret, tmp->data);
952 g_object_ref (tmp->data);
955 ret = g_list_reverse (ret);