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 timeline_object_height_changed_cb (GESTimelineObject * obj,
42 GESTrackEffect * tr_eff, GESTimelineObject * second_obj);
44 G_DEFINE_TYPE (GESTimelineLayer, ges_timeline_layer, G_TYPE_INITIALLY_UNOWNED);
46 struct _GESTimelineLayerPrivate
49 GList *objects_start; /* The TimelineObjects sorted by start and
52 guint32 priority; /* The priority of the layer within the
53 * containing timeline */
54 gboolean auto_transition;
72 static guint ges_timeline_layer_signals[LAST_SIGNAL] = { 0 };
74 /* GObject standard vmethods */
76 ges_timeline_layer_get_property (GObject * object, guint property_id,
77 GValue * value, GParamSpec * pspec)
79 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
81 switch (property_id) {
83 g_value_set_uint (value, layer->priv->priority);
85 case PROP_AUTO_TRANSITION:
86 g_value_set_boolean (value, layer->priv->auto_transition);
89 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
94 ges_timeline_layer_set_property (GObject * object, guint property_id,
95 const GValue * value, GParamSpec * pspec)
97 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
99 switch (property_id) {
101 ges_timeline_layer_set_priority (layer, g_value_get_uint (value));
103 case PROP_AUTO_TRANSITION:
104 ges_timeline_layer_set_auto_transition (layer,
105 g_value_get_boolean (value));
108 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
113 ges_timeline_layer_dispose (GObject * object)
115 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
116 GESTimelineLayerPrivate *priv = layer->priv;
118 GST_DEBUG ("Disposing layer");
120 while (priv->objects_start)
121 ges_timeline_layer_remove_object (layer,
122 (GESTimelineObject *) priv->objects_start->data);
124 G_OBJECT_CLASS (ges_timeline_layer_parent_class)->dispose (object);
128 ges_timeline_layer_class_init (GESTimelineLayerClass * klass)
130 GObjectClass *object_class = G_OBJECT_CLASS (klass);
132 g_type_class_add_private (klass, sizeof (GESTimelineLayerPrivate));
134 object_class->get_property = ges_timeline_layer_get_property;
135 object_class->set_property = ges_timeline_layer_set_property;
136 object_class->dispose = ges_timeline_layer_dispose;
139 * GESTimelineLayer:priority
141 * The priority of the layer in the #GESTimeline. 0 is the highest
142 * priority. Conceptually, a #GESTimeline is a stack of GESTimelineLayers,
143 * and the priority of the layer represents its position in the stack. Two
144 * layers should not have the same priority within a given GESTimeline.
146 g_object_class_install_property (object_class, PROP_PRIORITY,
147 g_param_spec_uint ("priority", "Priority",
148 "The priority of the layer", 0, G_MAXUINT, 0, G_PARAM_READWRITE));
151 * GESTimelineLayer:auto-transition
153 * Sets whether transitions are added automagically when timeline objects overlap.
155 g_object_class_install_property (object_class, PROP_AUTO_TRANSITION,
156 g_param_spec_boolean ("auto-transition", "Auto-Transition",
157 "whether the transitions are added", FALSE, G_PARAM_READWRITE));
160 * GESTimelineLayer::object-added
161 * @layer: the #GESTimelineLayer
162 * @object: the #GESTimelineObject that was added.
164 * Will be emitted after the object was added to the layer.
166 ges_timeline_layer_signals[OBJECT_ADDED] =
167 g_signal_new ("object-added", G_TYPE_FROM_CLASS (klass),
168 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass, object_added),
169 NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
170 GES_TYPE_TIMELINE_OBJECT);
173 * GESTimelineLayer::object-removed
174 * @layer: the #GESTimelineLayer
175 * @object: the #GESTimelineObject that was removed
177 * Will be emitted after the object was removed from the layer.
179 ges_timeline_layer_signals[OBJECT_REMOVED] =
180 g_signal_new ("object-removed", G_TYPE_FROM_CLASS (klass),
181 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass,
182 object_removed), NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
183 GES_TYPE_TIMELINE_OBJECT);
187 ges_timeline_layer_init (GESTimelineLayer * self)
189 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
190 GES_TYPE_TIMELINE_LAYER, GESTimelineLayerPrivate);
192 self->priv->priority = 0;
193 self->priv->auto_transition = FALSE;
194 self->min_gnl_priority = 0;
195 self->max_gnl_priority = LAYER_HEIGHT;
198 /* Private methods and utils */
200 objects_start_compare (GESTimelineObject * a, GESTimelineObject * b)
202 if (a->start == b->start) {
203 if (a->priority < b->priority)
205 if (a->priority > b->priority)
209 if (a->start < b->start)
211 if (a->start > b->start)
217 track_get_by_layer (GESTimelineLayer * layer, GESTrack * track)
219 GList *tck_objects_list = NULL, *tmp = NULL, *return_list = NULL;
220 GESTimelineObject *tl_obj;
222 tck_objects_list = ges_track_get_objects (track);
223 for (tmp = tck_objects_list; tmp; tmp = tmp->next) {
224 tl_obj = ges_track_object_get_timeline_object (tmp->data);
226 if (ges_timeline_object_get_layer (tl_obj) == layer) {
227 /* We steal the reference from tck_objects_list */
228 return_list = g_list_append (return_list, tmp->data);
231 g_object_unref (tmp->data);
238 * @compared: The #GList of #GESTrackObjects that we compare with @track_object
239 * @track_object: The #GESTrackObject that serves as a reference
240 * @ahead: %TRUE if we are comparing frontward %FALSE if we are comparing
243 compare (GList * compared, GESTrackObject * track_object, gboolean ahead)
246 gint64 start, duration, compared_start, compared_duration, end, compared_end,
247 tr_start, tr_duration;
248 GESTimelineStandardTransition *trans = NULL;
250 GESTimelineLayer *layer;
251 GESTimelineObject *object, *compared_object, *first_object, *second_object;
254 g_return_if_fail (compared);
256 GST_DEBUG ("Recalculating transitions");
258 object = ges_track_object_get_timeline_object (track_object);
261 GST_WARNING ("Trackobject not in a timeline object: "
262 "Can not calulate transitions");
267 compared_object = ges_track_object_get_timeline_object (compared->data);
268 layer = ges_timeline_object_get_layer (object);
270 start = ges_track_object_get_start (track_object);
271 duration = ges_track_object_get_duration (track_object);
272 compared_start = ges_track_object_get_start (compared->data);
273 compared_duration = ges_track_object_get_duration (compared->data);
274 end = start + duration;
275 compared_end = compared_start + compared_duration;
278 /* Make sure we remove the last transition we created it is not needed
279 * FIXME make it a smarter way */
280 if (compared->prev && GES_IS_TRACK_TRANSITION (compared->prev->data)) {
281 trans = GES_TIMELINE_STANDARD_TRANSITION
282 (ges_track_object_get_timeline_object (compared->prev->data));
283 g_object_get (compared->prev->data, "start", &tr_start, "duration",
285 if (tr_start >= compared_start && tr_start + tr_duration <= compared_end)
286 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
290 for (tmp = compared->next; tmp; tmp = tmp->next) {
291 /* If we have a transitionmnmnm we recaluculuculate its values */
292 if (GES_IS_TRACK_TRANSITION (tmp->data)) {
293 g_object_get (tmp->data, "start", &tr_start, "duration", &tr_duration,
296 if (tr_start + tr_duration == compared_start + compared_duration) {
297 GESTimelineObject *tlobj;
298 tlobj = ges_track_object_get_timeline_object (tmp->data);
300 trans = GES_TIMELINE_STANDARD_TRANSITION (tlobj);
306 if (compared_end <= start) {
308 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
309 g_object_get (compared_object, "priority", &priority, NULL);
310 g_object_set (object, "priority", priority, NULL);
314 } else if (start > compared_start && end < compared_end) {
316 /* Transition not needed anymore */
317 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
320 } else if (start <= compared_start) {
322 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
329 if (compared->next && GES_IS_TRACK_TRANSITION (compared->next->data)) {
330 trans = GES_TIMELINE_STANDARD_TRANSITION
331 (ges_track_object_get_timeline_object (compared->next->data));
332 g_object_get (compared->prev->data, "start", &tr_start, "duration",
334 if (tr_start >= compared_start && tr_start + tr_duration <= compared_end)
335 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
338 for (tmp = compared->prev; tmp; tmp = tmp->prev) {
339 if GES_IS_TRACK_TRANSITION
341 g_object_get (tmp->data, "start", &tr_start, "duration", &tr_duration,
343 if (tr_start == compared_start) {
344 trans = GES_TIMELINE_STANDARD_TRANSITION
345 (ges_track_object_get_timeline_object (tmp->data));
351 if (start + duration <= compared_start) {
353 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
354 g_object_get (object, "priority", &priority, NULL);
355 g_object_set (compared_object, "priority", priority, NULL);
359 } else if (start > compared_start) {
361 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
364 } else if (start < compared_start && end > compared_end) {
366 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
377 ges_timeline_standard_transition_new_for_nick ((gchar *) "crossfade");
378 track = ges_track_object_get_track (track_object);
380 ges_timeline_object_set_supported_formats (GES_TIMELINE_OBJECT (trans),
383 ges_timeline_layer_add_object (layer, GES_TIMELINE_OBJECT (trans));
386 first_object = ges_track_object_get_timeline_object (compared->data);
387 second_object = object;
389 second_object = ges_track_object_get_timeline_object (compared->data);
390 first_object = object;
393 g_object_get (first_object, "priority", &priority, "height", &height, NULL);
394 g_object_set (second_object, "priority", priority + height, NULL);
395 g_signal_connect (first_object, "notify::height",
396 (GCallback) timeline_object_height_changed_cb, second_object);
400 g_object_set (trans, "start", start, "duration",
401 compared_duration + compared_start - start, NULL);
403 g_object_set (trans, "start", compared_start, "duration",
404 start + duration - compared_start, NULL);
408 g_object_unref (layer);
412 calculate_next_transition_with_list (GESTrackObject * track_object,
413 GList * tckobjs_in_layer, GESTimelineLayer * layer)
417 if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
420 if (compared == NULL)
421 /* This is the last TrackObject of the Track */
425 compared = compared->next;
426 if (compared == NULL)
428 } while (!GES_IS_TRACK_SOURCE (compared->data));
430 compare (compared, track_object, FALSE);
435 calculate_next_transition (GESTrackObject * track_object,
436 GESTimelineLayer * layer)
439 GList *tckobjs_in_layer;
441 if ((track = ges_track_object_get_track (track_object))) {
442 tckobjs_in_layer = track_get_by_layer (layer, track);
443 calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
445 g_list_foreach (tckobjs_in_layer, (GFunc) g_object_unref, NULL);
446 g_list_free (tckobjs_in_layer);
451 calculate_transitions (GESTrackObject * track_object)
453 GList *tckobjs_in_layer, *compared;
454 GESTimelineLayer *layer;
455 GESTimelineObject *tlobj;
457 GESTrack *track = ges_track_object_get_track (track_object);
462 tlobj = ges_track_object_get_timeline_object (track_object);
463 layer = ges_timeline_object_get_layer (tlobj);
464 tckobjs_in_layer = track_get_by_layer (layer, track);
465 if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
468 compared = compared->prev;
470 if (compared == NULL) {
471 /* Nothing before, let's check after */
472 calculate_next_transition_with_list (track_object, tckobjs_in_layer,
477 } while (!GES_IS_TRACK_SOURCE (compared->data));
479 compare (compared, track_object, TRUE);
481 calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
484 g_list_foreach (tckobjs_in_layer, (GFunc) g_object_unref, NULL);
485 g_list_free (tckobjs_in_layer);
490 look_for_transition (GESTrackObject * track_object, GESTimelineLayer * layer)
493 GList *track_objects, *tmp, *cur;
495 track = ges_track_object_get_track (track_object);
497 track_objects = ges_track_get_objects (track);
499 cur = g_list_find (track_objects, track_object);
501 for (tmp = cur->next; tmp; tmp = tmp->next) {
502 if (GES_IS_TRACK_SOURCE (tmp->data)) {
505 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
506 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
507 ges_timeline_layer_remove_object (layer,
508 ges_track_object_get_timeline_object (tmp->data));
512 for (tmp = cur->prev; tmp; tmp = tmp->prev) {
513 if (GES_IS_TRACK_SOURCE (tmp->data)) {
516 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
517 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
518 ges_timeline_layer_remove_object (layer,
519 ges_track_object_get_timeline_object (tmp->data));
522 g_list_foreach (track_objects, (GFunc) g_object_unref, NULL);
523 g_list_free (track_objects);
527 * ges_timeline_layer_resync_priorities:
528 * @layer: a #GESTimelineLayer
530 * Resyncs the priorities of the objects controlled by @layer.
534 ges_timeline_layer_resync_priorities (GESTimelineLayer * layer)
537 GESTimelineObject *obj;
539 GST_DEBUG ("Resync priorities of %p", layer);
541 /* TODO : Inhibit composition updates while doing this.
542 * Ideally we want to do it from an even higher level, but here will
543 * do in the meantime. */
545 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
546 obj = GES_TIMELINE_OBJECT (tmp->data);
547 ges_timeline_object_set_priority (obj, GES_TIMELINE_OBJECT_PRIORITY (obj));
556 track_object_duration_cb (GESTrackObject * track_object,
557 GParamSpec * arg G_GNUC_UNUSED)
559 GESTimelineLayer *layer;
560 GESTimelineObject *tlobj;
562 tlobj = ges_track_object_get_timeline_object (track_object);
563 layer = ges_timeline_object_get_layer (tlobj);
564 if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
565 calculate_next_transition (track_object, layer);
569 track_object_removed_cb (GESTrack * track, GESTrackObject * track_object)
571 GList *track_objects, *tmp, *cur;
572 GESTimelineLayer *layer;
574 track_objects = ges_track_get_objects (track);
575 cur = g_list_find (track_objects, track_object);
576 for (tmp = cur->next; tmp; tmp = tmp->next) {
577 if (GES_IS_TRACK_SOURCE (tmp->data)) {
580 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
581 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
583 ges_timeline_object_get_layer (ges_track_object_get_timeline_object
585 if (ges_timeline_layer_get_auto_transition (layer)) {
586 ges_track_enable_update (track, FALSE);
587 ges_timeline_layer_remove_object (layer,
588 ges_track_object_get_timeline_object (tmp->data));
589 ges_track_enable_update (track, TRUE);
591 g_object_unref (layer);
595 for (tmp = cur->prev; tmp; tmp = tmp->prev) {
596 if (GES_IS_TRACK_SOURCE (tmp->data)) {
599 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
600 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
602 ges_timeline_object_get_layer (ges_track_object_get_timeline_object
604 if (ges_timeline_layer_get_auto_transition (layer)) {
605 ges_track_enable_update (track, FALSE);
606 ges_timeline_layer_remove_object (layer,
607 ges_track_object_get_timeline_object (tmp->data));
608 ges_track_enable_update (track, TRUE);
610 g_object_unref (layer);
613 g_object_unref (track_object);
617 track_object_changed_cb (GESTrackObject * track_object,
618 GParamSpec * arg G_GNUC_UNUSED)
620 if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
621 calculate_transitions (track_object);
625 track_object_added_cb (GESTrack * track, GESTrackObject * track_object,
626 GESTimelineLayer * layer)
628 GST_ERROR ("TRACKOBJECTADDED %i", GES_IS_TRACK_SOURCE (track_object));
629 if (GES_IS_TRACK_SOURCE (track_object)) {
630 g_signal_connect (G_OBJECT (track_object), "notify::start",
631 G_CALLBACK (track_object_changed_cb), NULL);
632 g_signal_connect (G_OBJECT (track_object), "notify::duration",
633 G_CALLBACK (track_object_duration_cb), NULL);
634 calculate_transitions (track_object);
640 track_removed_cb (GESTrack * track, GESTrackObject * track_object,
641 GESTimelineLayer * layer)
643 g_signal_handlers_disconnect_by_func (track, track_object_added_cb, layer);
644 g_signal_handlers_disconnect_by_func (track, track_object_removed_cb, NULL);
648 track_added_cb (GESTrack * track, GESTrackObject * track_object,
649 GESTimelineLayer * layer)
651 g_signal_connect (track, "track-object-removed",
652 (GCallback) track_object_removed_cb, NULL);
653 g_signal_connect (track, "track-object-added",
654 (GCallback) track_object_added_cb, NULL);
658 timeline_object_height_changed_cb (GESTimelineObject * obj,
659 GESTrackEffect * tr_eff, GESTimelineObject * second_obj)
661 gint priority, height;
662 g_object_get (obj, "height", &height, "priority", &priority, NULL);
663 g_object_set (second_obj, "priority", priority + height, NULL);
668 * ges_timeline_layer_remove_object:
669 * @layer: a #GESTimelineLayer
670 * @object: the #GESTimelineObject to remove
672 * Removes the given @object from the @layer and unparents it.
673 * Unparenting it means the reference owned by @layer on the @object will be
674 * removed. If you wish to use the @object after this function, make sure you
675 * call g_object_ref() before removing it from the @layer.
677 * Returns: TRUE if the object could be removed, FALSE if the layer does
678 * not want to remove the object.
681 ges_timeline_layer_remove_object (GESTimelineLayer * layer,
682 GESTimelineObject * object)
684 GESTimelineLayer *tl_obj_layer;
685 GList *trackobjects, *tmp;
687 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), FALSE);
688 g_return_val_if_fail (GES_IS_TIMELINE_OBJECT (object), FALSE);
690 GST_DEBUG ("layer:%p, object:%p", layer, object);
692 tl_obj_layer = ges_timeline_object_get_layer (object);
693 if (G_UNLIKELY (tl_obj_layer != layer)) {
694 GST_WARNING ("TimelineObject doesn't belong to this layer");
695 if (tl_obj_layer != NULL)
696 g_object_unref (tl_obj_layer);
699 g_object_unref (tl_obj_layer);
701 if (layer->priv->auto_transition) {
702 trackobjects = ges_timeline_object_get_track_objects (object);
704 for (tmp = trackobjects; tmp; tmp = tmp->next) {
705 look_for_transition (tmp->data, layer);
708 g_list_foreach (trackobjects, (GFunc) g_object_unref, NULL);
709 g_list_free (trackobjects);
712 /* emit 'object-removed' */
713 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_REMOVED], 0, object);
715 /* inform the object it's no longer in a layer */
716 ges_timeline_object_set_layer (object, NULL);
718 /* Remove it from our list of controlled objects */
719 layer->priv->objects_start =
720 g_list_remove (layer->priv->objects_start, object);
722 /* Remove our reference to the object */
723 g_object_unref (object);
729 * ges_timeline_layer_set_priority:
730 * @layer: a #GESTimelineLayer
731 * @priority: the priority to set
733 * Sets the layer to the given @priority. See the documentation of the
734 * priority property for more information.
737 ges_timeline_layer_set_priority (GESTimelineLayer * layer, guint priority)
739 g_return_if_fail (GES_IS_TIMELINE_LAYER (layer));
741 GST_DEBUG ("layer:%p, priority:%d", layer, priority);
743 if (priority != layer->priv->priority) {
744 layer->priv->priority = priority;
745 layer->min_gnl_priority = (priority * LAYER_HEIGHT);
746 layer->max_gnl_priority = ((priority + 1) * LAYER_HEIGHT) - 1;
748 ges_timeline_layer_resync_priorities (layer);
753 * ges_timeline_layer_get_auto_transition:
754 * @layer: a #GESTimelineLayer
756 * Gets whether transitions are automatically added when objects
759 * Returns: %TRUE if transitions are automatically added, else %FALSE.
762 ges_timeline_layer_get_auto_transition (GESTimelineLayer * layer)
764 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), 0);
766 return layer->priv->auto_transition;
770 * ges_timeline_layer_set_auto_transition:
771 * @layer: a #GESTimelineLayer
772 * @auto_transition: whether the auto_transition is active
774 * Sets the layer to the given @auto_transition. See the documentation of the
775 * property auto_transition for more information.
778 ges_timeline_layer_set_auto_transition (GESTimelineLayer * layer,
779 gboolean auto_transition)
783 g_return_if_fail (GES_IS_TIMELINE_LAYER (layer));
785 if (auto_transition && layer->timeline) {
786 GList *tracks = ges_timeline_get_tracks (layer->timeline);
788 for (tmp = tracks; tmp; tmp = tmp->next) {
789 g_signal_connect (G_OBJECT (tmp->data), "track-object-added",
790 G_CALLBACK (track_object_added_cb), layer);
791 g_signal_connect (G_OBJECT (tmp->data), "track-object-removed",
792 G_CALLBACK (track_object_removed_cb), NULL);
794 /* FIXME calculate all the transitions at that time */
796 layer->priv->auto_transition = auto_transition;
800 * ges_timeline_layer_get_priority:
801 * @layer: a #GESTimelineLayer
803 * Get the priority of @layer within the timeline.
805 * Returns: The priority of the @layer within the timeline.
808 ges_timeline_layer_get_priority (GESTimelineLayer * layer)
810 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), 0);
812 return layer->priv->priority;
816 * ges_timeline_layer_get_objects:
817 * @layer: a #GESTimelineLayer
819 * Get the timeline objects this layer contains.
821 * Returns: (transfer full) (element-type GESTimelineObject): a #GList of
822 * timeline objects. The user is responsible for
823 * unreffing the contained objects and freeing the list.
827 ges_timeline_layer_get_objects (GESTimelineLayer * layer)
831 GESTimelineLayerClass *klass;
833 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), NULL);
835 klass = GES_TIMELINE_LAYER_GET_CLASS (layer);
837 if (klass->get_objects) {
838 return klass->get_objects (layer);
841 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
842 ret = g_list_prepend (ret, tmp->data);
843 g_object_ref (tmp->data);
846 ret = g_list_reverse (ret);
851 * ges_timeline_layer_is_empty:
852 * @layer: The #GESTimelineLayer to check
854 * Convenience method to check if @layer is empty (doesn't contain any object),
857 * Returns: %TRUE if @layer is empty, %FALSE if it already contains at least
858 * one #GESTimelineObject
861 ges_timeline_layer_is_empty (GESTimelineLayer * layer)
863 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), FALSE);
865 return (layer->priv->objects_start == NULL);
869 * ges_timeline_layer_add_object:
870 * @layer: a #GESTimelineLayer
871 * @object: (transfer full): the #GESTimelineObject to add.
873 * Adds the given object to the layer. Sets the object's parent, and thus
874 * takes ownership of the object.
876 * An object can only be added to one layer.
878 * Calling this method will construct and properly set all the media related
879 * elements on @object. If you need to know when those objects (actually #GESTrackObject)
880 * are constructed, you should connect to the object::track-object-added signal which
881 * is emited right after those elements are ready to be used.
883 * Returns: TRUE if the object was properly added to the layer, or FALSE
884 * if the @layer refuses to add the object.
887 ges_timeline_layer_add_object (GESTimelineLayer * layer,
888 GESTimelineObject * object)
890 GESTimelineLayer *tl_obj_layer;
891 guint32 maxprio, minprio, prio;
893 GST_DEBUG ("layer:%p, object:%p", layer, object);
895 tl_obj_layer = ges_timeline_object_get_layer (object);
897 if (G_UNLIKELY (tl_obj_layer)) {
898 GST_WARNING ("TimelineObject %p already belongs to another layer", object);
899 g_object_unref (tl_obj_layer);
903 g_object_ref_sink (object);
905 /* Take a reference to the object and store it stored by start/priority */
906 layer->priv->objects_start =
907 g_list_insert_sorted (layer->priv->objects_start, object,
908 (GCompareFunc) objects_start_compare);
910 /* Inform the object it's now in this layer */
911 ges_timeline_object_set_layer (object, layer);
913 GST_DEBUG ("current object priority : %d, layer min/max : %d/%d",
914 GES_TIMELINE_OBJECT_PRIORITY (object),
915 layer->min_gnl_priority, layer->max_gnl_priority);
917 /* Set the priority. */
918 maxprio = layer->max_gnl_priority;
919 minprio = layer->min_gnl_priority;
920 prio = GES_TIMELINE_OBJECT_PRIORITY (object);
921 if (minprio + prio > (maxprio)) {
922 GST_WARNING ("%p is out of the layer %p space, setting its priority to "
923 "setting its priority %d to failthe maximum priority of the layer %d",
924 object, layer, prio, maxprio - minprio);
925 ges_timeline_object_set_priority (object, LAYER_HEIGHT - 1);
927 /* If the object has an acceptable priority, we just let it with its current
930 ges_timeline_layer_resync_priorities (layer);
932 /* emit 'object-added' */
933 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_ADDED], 0, object);
939 * ges_timeline_layer_new:
941 * Creates a new #GESTimelineLayer.
943 * Returns: A new #GESTimelineLayer
946 ges_timeline_layer_new (void)
948 return g_object_new (GES_TYPE_TIMELINE_LAYER, NULL);
952 * ges_timeline_layer_get_timeline:
953 * @layer: The #GESTimelineLayer to get the parent #GESTimeline from
955 * Get the #GESTimeline in which #GESTimelineLayer currently is.
957 * Returns: (transfer none): the #GESTimeline in which #GESTimelineLayer
958 * currently is or %NULL if not in any timeline yet.
961 ges_timeline_layer_get_timeline (GESTimelineLayer * layer)
963 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), NULL);
965 return layer->timeline;
969 ges_timeline_layer_set_timeline (GESTimelineLayer * layer,
970 GESTimeline * timeline)
972 GST_DEBUG ("layer:%p, timeline:%p", layer, timeline);
974 if (layer->priv->auto_transition == TRUE) {
975 if (layer->timeline != NULL) {
976 g_signal_handlers_disconnect_by_func (layer->timeline, track_added_cb,
978 g_signal_handlers_disconnect_by_func (layer->timeline, track_removed_cb,
982 if (timeline != NULL) {
983 GList *tmp, *tracks = ges_timeline_get_tracks (timeline);
985 g_signal_connect (timeline, "track-added", G_CALLBACK (track_added_cb),
987 g_signal_connect (timeline, "track-removed",
988 G_CALLBACK (track_removed_cb), layer);
990 for (tmp = tracks; tmp; tmp = tmp->next) {
991 g_signal_connect (G_OBJECT (tmp->data), "track-object-added",
992 G_CALLBACK (track_object_added_cb), layer);
993 g_signal_connect (G_OBJECT (tmp->data), "track-object-removed",
994 G_CALLBACK (track_object_removed_cb), NULL);
999 layer->timeline = timeline;