1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3 * 2009 Nokia Corporation
4 * 2011 Mathieu Duponchelle <mathieu.duponchelle@epitech.eu>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * SECTION:ges-timeline-layer
24 * @short_description: Non-overlapping sequence of #GESTimelineObject
26 * Responsible for the ordering of the various contained TimelineObject(s). A
27 * timeline layer has a "priority" property, which is used to manage the
28 * priorities of individual TimelineObjects. Two layers should not have the
29 * same priority within a given timeline.
32 #include "ges-internal.h"
33 #include "gesmarshal.h"
34 #include "ges-timeline-layer.h"
36 #include "ges-timeline-source.h"
38 #define LAYER_HEIGHT 1000
41 track_object_removed_cb (GESTimelineObject * object,
42 GESTrackObject * track_object);
43 static void track_object_added_cb (GESTimelineObject * object,
44 GESTrackObject * track_object, GHashTable * signal_table);
45 static void track_object_changed_cb (GESTrackObject * track_object,
46 GParamSpec * arg G_GNUC_UNUSED);
47 static void calculate_transitions (GESTrackObject * track_object);
48 static void calculate_next_transition (GESTrackObject * track_object,
49 GESTimelineLayer * layer);
52 timeline_object_height_changed_cb (GESTimelineObject * obj,
53 GESTrackEffect * tr_eff, GESTimelineObject * second_obj);
55 G_DEFINE_TYPE (GESTimelineLayer, ges_timeline_layer, G_TYPE_INITIALLY_UNOWNED);
57 struct _GESTimelineLayerPrivate
60 GList *objects_start; /* The TimelineObjects sorted by start and
63 guint32 priority; /* The priority of the layer within the
64 * containing timeline */
66 gboolean auto_transition;
69 GHashTable *signal_table;
87 static guint ges_timeline_layer_signals[LAST_SIGNAL] = { 0 };
89 static gboolean ges_timeline_layer_resync_priorities (GESTimelineLayer * layer);
91 static GList *track_get_by_layer (GESTimelineLayer * layer, GESTrack * track);
93 static void compare (GList * compared, GESTrackObject * track_object,
97 ges_timeline_layer_get_property (GObject * object, guint property_id,
98 GValue * value, GParamSpec * pspec)
100 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
102 switch (property_id) {
104 g_value_set_uint (value, layer->priv->priority);
106 case PROP_AUTO_TRANSITION:
107 g_value_set_boolean (value, layer->priv->auto_transition);
110 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
115 ges_timeline_layer_set_property (GObject * object, guint property_id,
116 const GValue * value, GParamSpec * pspec)
118 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
120 switch (property_id) {
122 ges_timeline_layer_set_priority (layer, g_value_get_uint (value));
124 case PROP_AUTO_TRANSITION:
125 ges_timeline_layer_set_auto_transition (layer,
126 g_value_get_boolean (value));
129 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
134 ges_timeline_layer_dispose (GObject * object)
136 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
137 GESTimelineLayerPrivate *priv = layer->priv;
139 GST_DEBUG ("Disposing layer");
141 while (priv->objects_start)
142 ges_timeline_layer_remove_object (layer,
143 (GESTimelineObject *) priv->objects_start->data);
145 G_OBJECT_CLASS (ges_timeline_layer_parent_class)->dispose (object);
149 ges_timeline_layer_class_init (GESTimelineLayerClass * klass)
151 GObjectClass *object_class = G_OBJECT_CLASS (klass);
153 g_type_class_add_private (klass, sizeof (GESTimelineLayerPrivate));
155 object_class->get_property = ges_timeline_layer_get_property;
156 object_class->set_property = ges_timeline_layer_set_property;
157 object_class->dispose = ges_timeline_layer_dispose;
160 * GESTimelineLayer:priority
162 * The priority of the layer in the #GESTimeline. 0 is the highest
163 * priority. Conceptually, a #GESTimeline is a stack of GESTimelineLayers,
164 * and the priority of the layer represents its position in the stack. Two
165 * layers should not have the same priority within a given GESTimeline.
167 g_object_class_install_property (object_class, PROP_PRIORITY,
168 g_param_spec_uint ("priority", "Priority",
169 "The priority of the layer", 0, G_MAXUINT, 0, G_PARAM_READWRITE));
172 * GESTimelineLayer:auto_transitioning
174 * Sets whether transitions are added automagically when timeline objects overlap.
176 g_object_class_install_property (object_class, PROP_AUTO_TRANSITION,
177 g_param_spec_boolean ("auto-transition", "Auto-Transition",
178 "whether the transitions are added", FALSE, G_PARAM_READWRITE));
181 * GESTimelineLayer::object-added
182 * @layer: the #GESTimelineLayer
183 * @object: the #GESTimelineObject that was added.
185 * Will be emitted after the object was added to the layer.
187 ges_timeline_layer_signals[OBJECT_ADDED] =
188 g_signal_new ("object-added", G_TYPE_FROM_CLASS (klass),
189 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass, object_added),
190 NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
191 GES_TYPE_TIMELINE_OBJECT);
194 * GESTimelineLayer::object-removed
195 * @layer: the #GESTimelineLayer
196 * @object: the #GESTimelineObject that was removed
198 * Will be emitted after the object was removed from the layer.
200 ges_timeline_layer_signals[OBJECT_REMOVED] =
201 g_signal_new ("object-removed", G_TYPE_FROM_CLASS (klass),
202 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass,
203 object_removed), NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
204 GES_TYPE_TIMELINE_OBJECT);
208 ges_timeline_layer_init (GESTimelineLayer * self)
210 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
211 GES_TYPE_TIMELINE_LAYER, GESTimelineLayerPrivate);
213 self->priv->priority = 0;
214 self->priv->auto_transition = FALSE;
215 self->min_gnl_priority = 0;
216 self->max_gnl_priority = LAYER_HEIGHT;
217 self->priv->signal_table =
218 g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref,
223 * ges_timeline_layer_new:
225 * Creates a new #GESTimelineLayer.
227 * Returns: A new #GESTimelineLayer
230 ges_timeline_layer_new (void)
232 return g_object_new (GES_TYPE_TIMELINE_LAYER, NULL);
236 ges_timeline_layer_set_timeline (GESTimelineLayer * layer,
237 GESTimeline * timeline)
239 GST_DEBUG ("layer:%p, timeline:%p", layer, timeline);
241 layer->timeline = timeline;
245 objects_start_compare (GESTimelineObject * a, GESTimelineObject * b)
247 if (a->start == b->start) {
248 if (a->priority < b->priority)
250 if (a->priority > b->priority)
254 if (a->start < b->start)
256 if (a->start > b->start)
262 track_get_by_layer (GESTimelineLayer * layer, GESTrack * track)
264 GList *tck_objects_list = NULL, *tmp = NULL, *return_list = NULL;
265 GESTimelineObject *tl_obj;
267 tck_objects_list = ges_track_get_objects (track);
268 for (tmp = tck_objects_list; tmp; tmp = tmp->next) {
269 tl_obj = ges_track_object_get_timeline_object (tmp->data);
271 if (ges_timeline_object_get_layer (tl_obj) == layer) {
272 /* We steal the reference from tck_objects_list */
273 return_list = g_list_append (return_list, tmp->data);
276 g_object_unref (tmp->data);
283 * ges_timeline_layer_add_object:
284 * @layer: a #GESTimelineLayer
285 * @object: (transfer full): the #GESTimelineObject to add.
287 * Adds the given object to the layer. Sets the object's parent, and thus
288 * takes ownership of the object.
290 * An object can only be added to one layer.
292 * Returns: TRUE if the object was properly added to the layer, or FALSE
293 * if the @layer refuses to add the object.
296 ges_timeline_layer_add_object (GESTimelineLayer * layer,
297 GESTimelineObject * object)
299 GESTimelineLayer *tl_obj_layer;
300 guint32 maxprio, minprio, prio;
302 GST_DEBUG ("layer:%p, object:%p", layer, object);
304 tl_obj_layer = ges_timeline_object_get_layer (object);
306 if (G_UNLIKELY (tl_obj_layer)) {
307 GST_WARNING ("TimelineObject %p already belongs to another layer", object);
308 g_object_unref (tl_obj_layer);
312 g_object_ref_sink (object);
314 /* Take a reference to the object and store it stored by start/priority */
315 layer->priv->objects_start =
316 g_list_insert_sorted (layer->priv->objects_start, object,
317 (GCompareFunc) objects_start_compare);
319 /* We have to wait for the track objects to be created to calculate transitions */
320 if (layer->priv->auto_transition) {
321 if (GES_IS_TIMELINE_SOURCE (object)) {
322 g_signal_connect (G_OBJECT (object), "track-object-added",
323 G_CALLBACK (track_object_added_cb), layer->priv->signal_table);
324 g_signal_connect (G_OBJECT (object), "track-object-removed",
325 G_CALLBACK (track_object_removed_cb), NULL);
329 /* Inform the object it's now in this layer */
330 ges_timeline_object_set_layer (object, layer);
332 GST_DEBUG ("current object priority : %d, layer min/max : %d/%d",
333 GES_TIMELINE_OBJECT_PRIORITY (object),
334 layer->min_gnl_priority, layer->max_gnl_priority);
336 /* Set the priority. */
337 maxprio = layer->max_gnl_priority;
338 minprio = layer->min_gnl_priority;
339 prio = GES_TIMELINE_OBJECT_PRIORITY (object);
340 if (minprio + prio > (maxprio)) {
341 GST_WARNING ("%p is out of the layer %p space, setting its priority to "
342 "setting its priority %d to failthe maximum priority of the layer %d",
343 object, layer, prio, maxprio - minprio);
344 ges_timeline_object_set_priority (object, LAYER_HEIGHT - 1);
346 /* If the object has an acceptable priority, we just let it with its current
349 ges_timeline_layer_resync_priorities (layer);
351 /* emit 'object-added' */
352 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_ADDED], 0, object);
358 track_object_duration_cb (GESTrackObject * track_object,
359 GParamSpec * arg G_GNUC_UNUSED)
361 GESTimelineLayer *layer;
362 GESTimelineObject *tlobj;
364 tlobj = ges_track_object_get_timeline_object (track_object);
365 layer = ges_timeline_object_get_layer (tlobj);
366 if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
367 GST_DEBUG ("Here we should recalculate");
368 calculate_next_transition (track_object, layer);
372 track_object_deleted_cb (GESTrack * track, GESTrackObject * track_object)
374 GList *track_objects, *tmp, *cur;
375 GESTimelineLayer *layer;
377 track_objects = ges_track_get_objects (track);
378 cur = g_list_find (track_objects, track_object);
379 for (tmp = cur->next; tmp; tmp = tmp->next) {
380 if (GES_IS_TRACK_SOURCE (tmp->data)) {
383 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
384 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
386 ges_timeline_object_get_layer (ges_track_object_get_timeline_object
388 if (ges_timeline_layer_get_auto_transition (layer)) {
389 ges_track_enable_update (track, FALSE);
390 ges_timeline_layer_remove_object (layer,
391 ges_track_object_get_timeline_object (tmp->data));
392 ges_track_enable_update (track, TRUE);
394 g_object_unref (layer);
398 for (tmp = cur->prev; tmp; tmp = tmp->prev) {
399 if (GES_IS_TRACK_SOURCE (tmp->data)) {
402 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
403 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
405 ges_timeline_object_get_layer (ges_track_object_get_timeline_object
407 if (ges_timeline_layer_get_auto_transition (layer)) {
408 ges_track_enable_update (track, FALSE);
409 ges_timeline_layer_remove_object (layer,
410 ges_track_object_get_timeline_object (tmp->data));
411 ges_track_enable_update (track, TRUE);
413 g_object_unref (layer);
416 g_object_unref (track_object);
420 track_object_added_cb (GESTimelineObject * object,
421 GESTrackObject * track_object, GHashTable * signal_table)
426 if (GES_IS_TRACK_SOURCE (track_object)) {
427 g_signal_connect (G_OBJECT (track_object), "notify::start",
428 G_CALLBACK (track_object_changed_cb), NULL);
429 g_signal_connect (G_OBJECT (track_object), "notify::duration",
430 G_CALLBACK (track_object_duration_cb), NULL);
431 calculate_transitions (track_object);
433 track = ges_track_object_get_track (track_object);
434 if (!g_hash_table_lookup (signal_table, track)) {
435 ptr = g_signal_connect (track, "track-object-removed",
436 (GCallback) track_object_deleted_cb, NULL);
437 g_hash_table_insert (signal_table, track, GINT_TO_POINTER (ptr));
443 track_object_removed_cb (GESTimelineObject * object,
444 GESTrackObject * track_object)
447 if (GES_IS_TRACK_SOURCE (track_object)) {
448 g_signal_handlers_disconnect_by_func (track_object, track_object_changed_cb,
455 timeline_object_height_changed_cb (GESTimelineObject * obj,
456 GESTrackEffect * tr_eff, GESTimelineObject * second_obj)
458 gint priority, height;
459 g_object_get (obj, "height", &height, "priority", &priority, NULL);
460 g_object_set (second_obj, "priority", priority + height, NULL);
464 track_object_changed_cb (GESTrackObject * track_object,
465 GParamSpec * arg G_GNUC_UNUSED)
467 if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
468 calculate_transitions (track_object);
472 calculate_next_transition_with_list (GESTrackObject * track_object,
473 GList * tckobjs_in_layer, GESTimelineLayer * layer)
477 if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
480 if (compared == NULL)
481 /* This is the last TrackObject of the Track */
485 compared = compared->next;
486 if (compared == NULL)
488 } while (!GES_IS_TRACK_SOURCE (compared->data));
490 compare (compared, track_object, FALSE);
495 calculate_next_transition (GESTrackObject * track_object,
496 GESTimelineLayer * layer)
498 GESTrack *track = ges_track_object_get_track (track_object);
499 GList *tckobjs_in_layer = track_get_by_layer (layer, track);
501 if (ges_track_object_get_track (track_object)) {
502 calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
505 g_list_foreach (tckobjs_in_layer, (GFunc) g_object_unref, NULL);
506 g_list_free (tckobjs_in_layer);
510 calculate_transitions (GESTrackObject * track_object)
512 GList *tckobjs_in_layer, *compared;
513 GESTrack *track = ges_track_object_get_track (track_object);
514 GESTimelineLayer *layer;
515 GESTimelineObject *tlobj;
517 tlobj = ges_track_object_get_timeline_object (track_object);
518 layer = ges_timeline_object_get_layer (tlobj);
519 tckobjs_in_layer = track_get_by_layer (layer, track);
520 if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
523 compared = compared->prev;
525 if (compared == NULL) {
526 /* Nothing before, let's check after */
527 calculate_next_transition_with_list (track_object, tckobjs_in_layer,
532 } while (!GES_IS_TRACK_SOURCE (compared->data));
534 compare (compared, track_object, TRUE);
536 calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
539 g_list_foreach (tckobjs_in_layer, (GFunc) g_object_unref, NULL);
540 g_list_free (tckobjs_in_layer);
545 * @compared: The #GList of #GESTrackObjects that we compare with @track_object
546 * @track_object: The #GESTrackObject that serves as a reference
547 * @ahead: %TRUE if we are comparing frontward %FALSE if we are comparing
550 compare (GList * compared, GESTrackObject * track_object, gboolean ahead)
553 gint64 start, duration, compared_start, compared_duration, end, compared_end,
554 tr_start, tr_duration;
555 GESTimelineStandardTransition *trans = NULL;
557 GESTimelineLayer *layer;
558 GESTimelineObject *object, *compared_object, *first_object, *second_object;
561 g_return_if_fail (compared);
563 GST_DEBUG ("Recalculating transitions");
565 object = ges_track_object_get_timeline_object (track_object);
568 GST_WARNING ("Trackobject not in a timeline object: "
569 "Can not calulate transitions");
574 compared_object = ges_track_object_get_timeline_object (compared->data);
575 layer = ges_timeline_object_get_layer (object);
577 start = ges_track_object_get_start (track_object);
578 duration = ges_track_object_get_duration (track_object);
579 compared_start = ges_track_object_get_start (compared->data);
580 compared_duration = ges_track_object_get_duration (compared->data);
581 end = start + duration;
582 compared_end = compared_start + compared_duration;
585 /* Make sure we remove the last transition we created it is not needed
586 * FIXME make it a smarter way */
587 if (compared->prev && GES_IS_TRACK_TRANSITION (compared->prev->data)) {
588 trans = GES_TIMELINE_STANDARD_TRANSITION
589 (ges_track_object_get_timeline_object (compared->prev->data));
590 g_object_get (compared->prev->data, "start", &tr_start, "duration",
592 if (tr_start >= compared_start && tr_start + tr_duration <= compared_end)
593 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
597 for (tmp = compared->next; tmp; tmp = tmp->next) {
598 /* If we have a transitionmnmnm we recaluculuculate its values */
599 if (GES_IS_TRACK_TRANSITION (tmp->data)) {
600 g_object_get (tmp->data, "start", &tr_start, "duration", &tr_duration,
603 if (tr_start + tr_duration == compared_start + compared_duration) {
604 GESTimelineObject *tlobj;
605 tlobj = ges_track_object_get_timeline_object (tmp->data);
607 trans = GES_TIMELINE_STANDARD_TRANSITION (tlobj);
613 if (compared_end <= start) {
615 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
616 g_object_get (compared_object, "priority", &priority, NULL);
617 g_object_set (object, "priority", priority, NULL);
621 } else if (start > compared_start && end < compared_end) {
623 /* Transition not needed anymore */
624 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
627 } else if (start <= compared_start) {
629 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
636 if (compared->next && GES_IS_TRACK_TRANSITION (compared->next->data)) {
637 trans = GES_TIMELINE_STANDARD_TRANSITION
638 (ges_track_object_get_timeline_object (compared->next->data));
639 g_object_get (compared->prev->data, "start", &tr_start, "duration",
641 if (tr_start >= compared_start && tr_start + tr_duration <= compared_end)
642 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
645 for (tmp = compared->prev; tmp; tmp = tmp->prev) {
646 if GES_IS_TRACK_TRANSITION
648 g_object_get (tmp->data, "start", &tr_start, "duration", &tr_duration,
650 if (tr_start == compared_start) {
651 trans = GES_TIMELINE_STANDARD_TRANSITION
652 (ges_track_object_get_timeline_object (tmp->data));
658 if (start + duration <= compared_start) {
660 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
661 g_object_get (object, "priority", &priority, NULL);
662 g_object_set (compared_object, "priority", priority, NULL);
666 } else if (start > compared_start) {
668 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
671 } else if (start < compared_start && end > compared_end) {
673 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
684 ges_timeline_standard_transition_new_for_nick ((gchar *) "crossfade");
685 track = ges_track_object_get_track (track_object);
687 ges_timeline_object_set_supported_formats (GES_TIMELINE_OBJECT (trans),
690 ges_timeline_layer_add_object (layer, GES_TIMELINE_OBJECT (trans));
693 first_object = ges_track_object_get_timeline_object (compared->data);
694 second_object = object;
696 second_object = ges_track_object_get_timeline_object (compared->data);
697 first_object = object;
700 g_object_get (first_object, "priority", &priority, "height", &height, NULL);
701 g_object_set (second_object, "priority", priority + height, NULL);
702 g_signal_connect (first_object, "notify::height",
703 (GCallback) timeline_object_height_changed_cb, second_object);
707 g_object_set (trans, "start", start, "duration",
708 compared_duration + compared_start - start, NULL);
710 g_object_set (trans, "start", compared_start, "duration",
711 start + duration - compared_start, NULL);
715 g_object_unref (layer);
719 look_for_transition (GESTrackObject * track_object, GESTimelineLayer * layer)
722 GList *track_objects, *tmp, *cur;
724 track = ges_track_object_get_track (track_object);
726 track_objects = ges_track_get_objects (track);
728 cur = g_list_find (track_objects, track_object);
730 for (tmp = cur->next; tmp; tmp = tmp->next) {
731 if (GES_IS_TRACK_SOURCE (tmp->data)) {
734 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
735 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
736 ges_timeline_layer_remove_object (layer,
737 ges_track_object_get_timeline_object (tmp->data));
741 for (tmp = cur->prev; tmp; tmp = tmp->prev) {
742 if (GES_IS_TRACK_SOURCE (tmp->data)) {
745 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
746 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
747 ges_timeline_layer_remove_object (layer,
748 ges_track_object_get_timeline_object (tmp->data));
751 g_list_foreach (track_objects, (GFunc) g_object_unref, NULL);
752 g_list_free (track_objects);
756 disconnect_handlers (GESTrack * track, gpointer * ptr)
758 g_signal_handler_disconnect (track, GPOINTER_TO_INT (ptr));
764 * ges_timeline_layer_remove_object:
765 * @layer: a #GESTimelineLayer
766 * @object: the #GESTimelineObject to remove
768 * Removes the given @object from the @layer and unparents it.
769 * Unparenting it means the reference owned by @layer on the @object will be
770 * removed. If you wish to use the @object after this function, make sure you
771 * call g_object_ref() before removing it from the @layer.
773 * Returns: TRUE if the object could be removed, FALSE if the layer does
774 * not want to remove the object.
777 ges_timeline_layer_remove_object (GESTimelineLayer * layer,
778 GESTimelineObject * object)
780 GESTimelineLayer *tl_obj_layer;
781 GList *trackobjects, *tmp;
783 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), FALSE);
784 g_return_val_if_fail (GES_IS_TIMELINE_OBJECT (object), FALSE);
786 GST_DEBUG ("layer:%p, object:%p", layer, object);
788 tl_obj_layer = ges_timeline_object_get_layer (object);
789 if (G_UNLIKELY (tl_obj_layer != layer)) {
790 GST_WARNING ("TimelineObject doesn't belong to this layer");
791 if (tl_obj_layer != NULL)
792 g_object_unref (tl_obj_layer);
795 g_object_unref (tl_obj_layer);
797 if (layer->priv->auto_transition) {
798 trackobjects = ges_timeline_object_get_track_objects (object);
800 for (tmp = trackobjects; tmp; tmp = tmp->next) {
801 look_for_transition (tmp->data, layer);
804 g_list_foreach (trackobjects, (GFunc) g_object_unref, NULL);
805 g_list_free (trackobjects);
808 g_hash_table_foreach_remove (layer->priv->signal_table,
809 (GHRFunc) disconnect_handlers, NULL);
811 /* emit 'object-removed' */
812 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_REMOVED], 0, object);
814 /* inform the object it's no longer in a layer */
815 ges_timeline_object_set_layer (object, NULL);
817 /* Remove it from our list of controlled objects */
818 layer->priv->objects_start =
819 g_list_remove (layer->priv->objects_start, object);
821 /* Remove our reference to the object */
822 g_object_unref (object);
828 * ges_timeline_layer_resync_priorities:
829 * @layer: a #GESTimelineLayer
831 * Resyncs the priorities of the objects controlled by @layer.
835 ges_timeline_layer_resync_priorities (GESTimelineLayer * layer)
838 GESTimelineObject *obj;
840 GST_DEBUG ("Resync priorities of %p", layer);
842 /* TODO : Inhibit composition updates while doing this.
843 * Ideally we want to do it from an even higher level, but here will
844 * do in the meantime. */
846 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
847 obj = GES_TIMELINE_OBJECT (tmp->data);
848 ges_timeline_object_set_priority (obj, GES_TIMELINE_OBJECT_PRIORITY (obj));
855 * ges_timeline_layer_set_priority:
856 * @layer: a #GESTimelineLayer
857 * @priority: the priority to set
859 * Sets the layer to the given @priority. See the documentation of the
860 * priority property for more information.
863 ges_timeline_layer_set_priority (GESTimelineLayer * layer, guint priority)
865 g_return_if_fail (GES_IS_TIMELINE_LAYER (layer));
867 GST_DEBUG ("layer:%p, priority:%d", layer, priority);
869 if (priority != layer->priv->priority) {
870 layer->priv->priority = priority;
871 layer->min_gnl_priority = (priority * LAYER_HEIGHT);
872 layer->max_gnl_priority = ((priority + 1) * LAYER_HEIGHT) - 1;
874 ges_timeline_layer_resync_priorities (layer);
879 * ges_timeline_layer_get_auto_transition:
880 * @layer: a #GESTimelineLayer
882 * Get the priority of @layer within the timeline.
884 * Returns: The priority of the @layer within the timeline.
887 ges_timeline_layer_get_auto_transition (GESTimelineLayer * layer)
889 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), 0);
891 return layer->priv->auto_transition;
895 * ges_timeline_layer_set_auto_transition:
896 * @layer: a #GESTimelineLayer
897 * @auto_transition: whether the auto_transition is active
899 * Sets the layer to the given @auto_transition. See the documentation of the
900 * property auto_transition for more information.
903 ges_timeline_layer_set_auto_transition (GESTimelineLayer * layer,
904 gboolean auto_transition)
908 g_return_if_fail (GES_IS_TIMELINE_LAYER (layer));
910 if (auto_transition) {
911 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
912 if (GES_IS_TIMELINE_SOURCE (tmp->data)) {
913 g_signal_connect (G_OBJECT (tmp->data), "track-object-added",
914 G_CALLBACK (track_object_added_cb), layer);
915 g_signal_connect (G_OBJECT (tmp->data), "track-object-removed",
916 G_CALLBACK (track_object_removed_cb), layer);
919 /* FIXME calculate all the transitions at that time */
921 layer->priv->auto_transition = auto_transition;
925 * ges_timeline_layer_get_priority:
926 * @layer: a #GESTimelineLayer
928 * Get the priority of @layer within the timeline.
930 * Returns: The priority of the @layer within the timeline.
933 ges_timeline_layer_get_priority (GESTimelineLayer * layer)
935 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), 0);
937 return layer->priv->priority;
941 * ges_timeline_layer_get_objects:
942 * @layer: a #GESTimelineLayer
944 * Get the timeline objects this layer contains.
946 * Returns: (transfer full) (element-type GESTimelineObject): a #GList of
947 * timeline objects. The user is responsible for
948 * unreffing the contained objects and freeing the list.
952 ges_timeline_layer_get_objects (GESTimelineLayer * layer)
956 GESTimelineLayerClass *klass;
958 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), NULL);
960 klass = GES_TIMELINE_LAYER_GET_CLASS (layer);
962 if (klass->get_objects) {
963 return klass->get_objects (layer);
966 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
967 ret = g_list_prepend (ret, tmp->data);
968 g_object_ref (tmp->data);
971 ret = g_list_reverse (ret);