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-transition
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_get_timeline:
237 * @layer: The #GESTimelineLayer to get the parent #GESTimeline from
239 * Get the #GESTimeline in which #GESTimelineLayer currently is.
241 * Returns: (transfer none): the #GESTimeline in which #GESTimelineLayer
242 * currently is or %NULL if not in any timeline yet.
245 ges_timeline_layer_get_timeline (GESTimelineLayer * layer)
247 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), NULL);
249 return layer->timeline;
253 ges_timeline_layer_set_timeline (GESTimelineLayer * layer,
254 GESTimeline * timeline)
256 GST_DEBUG ("layer:%p, timeline:%p", layer, timeline);
258 layer->timeline = timeline;
262 objects_start_compare (GESTimelineObject * a, GESTimelineObject * b)
264 if (a->start == b->start) {
265 if (a->priority < b->priority)
267 if (a->priority > b->priority)
271 if (a->start < b->start)
273 if (a->start > b->start)
279 track_get_by_layer (GESTimelineLayer * layer, GESTrack * track)
281 GList *tck_objects_list = NULL, *tmp = NULL, *return_list = NULL;
282 GESTimelineObject *tl_obj;
284 tck_objects_list = ges_track_get_objects (track);
285 for (tmp = tck_objects_list; tmp; tmp = tmp->next) {
286 tl_obj = ges_track_object_get_timeline_object (tmp->data);
288 if (ges_timeline_object_get_layer (tl_obj) == layer) {
289 /* We steal the reference from tck_objects_list */
290 return_list = g_list_append (return_list, tmp->data);
293 g_object_unref (tmp->data);
300 * ges_timeline_layer_add_object:
301 * @layer: a #GESTimelineLayer
302 * @object: (transfer full): the #GESTimelineObject to add.
304 * Adds the given object to the layer. Sets the object's parent, and thus
305 * takes ownership of the object.
307 * An object can only be added to one layer.
309 * Calling this method will construct and properly set all the media related
310 * elements on @object. If you need to know when those objects (actually #GESTrackObject)
311 * are constructed, you should connect to the object::track-object-added signal which
312 * is emited right after those elements are ready to be used.
314 * Returns: TRUE if the object was properly added to the layer, or FALSE
315 * if the @layer refuses to add the object.
318 ges_timeline_layer_add_object (GESTimelineLayer * layer,
319 GESTimelineObject * object)
321 GESTimelineLayer *tl_obj_layer;
322 guint32 maxprio, minprio, prio;
324 GST_DEBUG ("layer:%p, object:%p", layer, object);
326 tl_obj_layer = ges_timeline_object_get_layer (object);
328 if (G_UNLIKELY (tl_obj_layer)) {
329 GST_WARNING ("TimelineObject %p already belongs to another layer", object);
330 g_object_unref (tl_obj_layer);
334 g_object_ref_sink (object);
336 /* Take a reference to the object and store it stored by start/priority */
337 layer->priv->objects_start =
338 g_list_insert_sorted (layer->priv->objects_start, object,
339 (GCompareFunc) objects_start_compare);
341 /* We have to wait for the track objects to be created to calculate transitions */
342 if (layer->priv->auto_transition) {
343 if (GES_IS_TIMELINE_SOURCE (object)) {
344 g_signal_connect (G_OBJECT (object), "track-object-added",
345 G_CALLBACK (track_object_added_cb), layer->priv->signal_table);
346 g_signal_connect (G_OBJECT (object), "track-object-removed",
347 G_CALLBACK (track_object_removed_cb), NULL);
351 /* Inform the object it's now in this layer */
352 ges_timeline_object_set_layer (object, layer);
354 GST_DEBUG ("current object priority : %d, layer min/max : %d/%d",
355 GES_TIMELINE_OBJECT_PRIORITY (object),
356 layer->min_gnl_priority, layer->max_gnl_priority);
358 /* Set the priority. */
359 maxprio = layer->max_gnl_priority;
360 minprio = layer->min_gnl_priority;
361 prio = GES_TIMELINE_OBJECT_PRIORITY (object);
362 if (minprio + prio > (maxprio)) {
363 GST_WARNING ("%p is out of the layer %p space, setting its priority to "
364 "setting its priority %d to failthe maximum priority of the layer %d",
365 object, layer, prio, maxprio - minprio);
366 ges_timeline_object_set_priority (object, LAYER_HEIGHT - 1);
368 /* If the object has an acceptable priority, we just let it with its current
371 ges_timeline_layer_resync_priorities (layer);
373 /* emit 'object-added' */
374 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_ADDED], 0, object);
380 track_object_duration_cb (GESTrackObject * track_object,
381 GParamSpec * arg G_GNUC_UNUSED)
383 GESTimelineLayer *layer;
384 GESTimelineObject *tlobj;
386 tlobj = ges_track_object_get_timeline_object (track_object);
387 layer = ges_timeline_object_get_layer (tlobj);
388 if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
389 calculate_next_transition (track_object, layer);
393 track_object_deleted_cb (GESTrack * track, GESTrackObject * track_object)
395 GList *track_objects, *tmp, *cur;
396 GESTimelineLayer *layer;
398 track_objects = ges_track_get_objects (track);
399 cur = g_list_find (track_objects, track_object);
400 for (tmp = cur->next; tmp; tmp = tmp->next) {
401 if (GES_IS_TRACK_SOURCE (tmp->data)) {
404 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
405 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
407 ges_timeline_object_get_layer (ges_track_object_get_timeline_object
409 if (ges_timeline_layer_get_auto_transition (layer)) {
410 ges_track_enable_update (track, FALSE);
411 ges_timeline_layer_remove_object (layer,
412 ges_track_object_get_timeline_object (tmp->data));
413 ges_track_enable_update (track, TRUE);
415 g_object_unref (layer);
419 for (tmp = cur->prev; tmp; tmp = tmp->prev) {
420 if (GES_IS_TRACK_SOURCE (tmp->data)) {
423 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
424 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
426 ges_timeline_object_get_layer (ges_track_object_get_timeline_object
428 if (ges_timeline_layer_get_auto_transition (layer)) {
429 ges_track_enable_update (track, FALSE);
430 ges_timeline_layer_remove_object (layer,
431 ges_track_object_get_timeline_object (tmp->data));
432 ges_track_enable_update (track, TRUE);
434 g_object_unref (layer);
437 g_object_unref (track_object);
441 track_object_added_cb (GESTimelineObject * object,
442 GESTrackObject * track_object, GHashTable * signal_table)
447 if (GES_IS_TRACK_SOURCE (track_object)) {
448 g_signal_connect (G_OBJECT (track_object), "notify::start",
449 G_CALLBACK (track_object_changed_cb), NULL);
450 g_signal_connect (G_OBJECT (track_object), "notify::duration",
451 G_CALLBACK (track_object_duration_cb), NULL);
452 calculate_transitions (track_object);
454 track = ges_track_object_get_track (track_object);
455 if (!g_hash_table_lookup (signal_table, track)) {
456 ptr = g_signal_connect (track, "track-object-removed",
457 (GCallback) track_object_deleted_cb, NULL);
458 g_hash_table_insert (signal_table, track, GINT_TO_POINTER (ptr));
464 track_object_removed_cb (GESTimelineObject * object,
465 GESTrackObject * track_object)
468 if (GES_IS_TRACK_SOURCE (track_object)) {
469 g_signal_handlers_disconnect_by_func (track_object, track_object_changed_cb,
476 timeline_object_height_changed_cb (GESTimelineObject * obj,
477 GESTrackEffect * tr_eff, GESTimelineObject * second_obj)
479 gint priority, height;
480 g_object_get (obj, "height", &height, "priority", &priority, NULL);
481 g_object_set (second_obj, "priority", priority + height, NULL);
485 track_object_changed_cb (GESTrackObject * track_object,
486 GParamSpec * arg G_GNUC_UNUSED)
488 if (G_LIKELY (GES_IS_TRACK_SOURCE (track_object)))
489 calculate_transitions (track_object);
493 calculate_next_transition_with_list (GESTrackObject * track_object,
494 GList * tckobjs_in_layer, GESTimelineLayer * layer)
498 if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
501 if (compared == NULL)
502 /* This is the last TrackObject of the Track */
506 compared = compared->next;
507 if (compared == NULL)
509 } while (!GES_IS_TRACK_SOURCE (compared->data));
511 compare (compared, track_object, FALSE);
516 calculate_next_transition (GESTrackObject * track_object,
517 GESTimelineLayer * layer)
520 GList *tckobjs_in_layer;
522 if ((track = ges_track_object_get_track (track_object))) {
523 tckobjs_in_layer = track_get_by_layer (layer, track);
524 calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
526 g_list_foreach (tckobjs_in_layer, (GFunc) g_object_unref, NULL);
527 g_list_free (tckobjs_in_layer);
532 calculate_transitions (GESTrackObject * track_object)
534 GList *tckobjs_in_layer, *compared;
535 GESTimelineLayer *layer;
536 GESTimelineObject *tlobj;
538 GESTrack *track = ges_track_object_get_track (track_object);
543 tlobj = ges_track_object_get_timeline_object (track_object);
544 layer = ges_timeline_object_get_layer (tlobj);
545 tckobjs_in_layer = track_get_by_layer (layer, track);
546 if (!(compared = g_list_find (tckobjs_in_layer, track_object)))
549 compared = compared->prev;
551 if (compared == NULL) {
552 /* Nothing before, let's check after */
553 calculate_next_transition_with_list (track_object, tckobjs_in_layer,
558 } while (!GES_IS_TRACK_SOURCE (compared->data));
560 compare (compared, track_object, TRUE);
562 calculate_next_transition_with_list (track_object, tckobjs_in_layer, layer);
565 g_list_foreach (tckobjs_in_layer, (GFunc) g_object_unref, NULL);
566 g_list_free (tckobjs_in_layer);
571 * @compared: The #GList of #GESTrackObjects that we compare with @track_object
572 * @track_object: The #GESTrackObject that serves as a reference
573 * @ahead: %TRUE if we are comparing frontward %FALSE if we are comparing
576 compare (GList * compared, GESTrackObject * track_object, gboolean ahead)
579 gint64 start, duration, compared_start, compared_duration, end, compared_end,
580 tr_start, tr_duration;
581 GESTimelineStandardTransition *trans = NULL;
583 GESTimelineLayer *layer;
584 GESTimelineObject *object, *compared_object, *first_object, *second_object;
587 g_return_if_fail (compared);
589 GST_DEBUG ("Recalculating transitions");
591 object = ges_track_object_get_timeline_object (track_object);
594 GST_WARNING ("Trackobject not in a timeline object: "
595 "Can not calulate transitions");
600 compared_object = ges_track_object_get_timeline_object (compared->data);
601 layer = ges_timeline_object_get_layer (object);
603 start = ges_track_object_get_start (track_object);
604 duration = ges_track_object_get_duration (track_object);
605 compared_start = ges_track_object_get_start (compared->data);
606 compared_duration = ges_track_object_get_duration (compared->data);
607 end = start + duration;
608 compared_end = compared_start + compared_duration;
611 /* Make sure we remove the last transition we created it is not needed
612 * FIXME make it a smarter way */
613 if (compared->prev && GES_IS_TRACK_TRANSITION (compared->prev->data)) {
614 trans = GES_TIMELINE_STANDARD_TRANSITION
615 (ges_track_object_get_timeline_object (compared->prev->data));
616 g_object_get (compared->prev->data, "start", &tr_start, "duration",
618 if (tr_start >= compared_start && tr_start + tr_duration <= compared_end)
619 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
623 for (tmp = compared->next; tmp; tmp = tmp->next) {
624 /* If we have a transitionmnmnm we recaluculuculate its values */
625 if (GES_IS_TRACK_TRANSITION (tmp->data)) {
626 g_object_get (tmp->data, "start", &tr_start, "duration", &tr_duration,
629 if (tr_start + tr_duration == compared_start + compared_duration) {
630 GESTimelineObject *tlobj;
631 tlobj = ges_track_object_get_timeline_object (tmp->data);
633 trans = GES_TIMELINE_STANDARD_TRANSITION (tlobj);
639 if (compared_end <= start) {
641 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
642 g_object_get (compared_object, "priority", &priority, NULL);
643 g_object_set (object, "priority", priority, NULL);
647 } else if (start > compared_start && end < compared_end) {
649 /* Transition not needed anymore */
650 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
653 } else if (start <= compared_start) {
655 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
662 if (compared->next && GES_IS_TRACK_TRANSITION (compared->next->data)) {
663 trans = GES_TIMELINE_STANDARD_TRANSITION
664 (ges_track_object_get_timeline_object (compared->next->data));
665 g_object_get (compared->prev->data, "start", &tr_start, "duration",
667 if (tr_start >= compared_start && tr_start + tr_duration <= compared_end)
668 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
671 for (tmp = compared->prev; tmp; tmp = tmp->prev) {
672 if GES_IS_TRACK_TRANSITION
674 g_object_get (tmp->data, "start", &tr_start, "duration", &tr_duration,
676 if (tr_start == compared_start) {
677 trans = GES_TIMELINE_STANDARD_TRANSITION
678 (ges_track_object_get_timeline_object (tmp->data));
684 if (start + duration <= compared_start) {
686 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
687 g_object_get (object, "priority", &priority, NULL);
688 g_object_set (compared_object, "priority", priority, NULL);
692 } else if (start > compared_start) {
694 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
697 } else if (start < compared_start && end > compared_end) {
699 ges_timeline_layer_remove_object (layer, GES_TIMELINE_OBJECT (trans));
710 ges_timeline_standard_transition_new_for_nick ((gchar *) "crossfade");
711 track = ges_track_object_get_track (track_object);
713 ges_timeline_object_set_supported_formats (GES_TIMELINE_OBJECT (trans),
716 ges_timeline_layer_add_object (layer, GES_TIMELINE_OBJECT (trans));
719 first_object = ges_track_object_get_timeline_object (compared->data);
720 second_object = object;
722 second_object = ges_track_object_get_timeline_object (compared->data);
723 first_object = object;
726 g_object_get (first_object, "priority", &priority, "height", &height, NULL);
727 g_object_set (second_object, "priority", priority + height, NULL);
728 g_signal_connect (first_object, "notify::height",
729 (GCallback) timeline_object_height_changed_cb, second_object);
733 g_object_set (trans, "start", start, "duration",
734 compared_duration + compared_start - start, NULL);
736 g_object_set (trans, "start", compared_start, "duration",
737 start + duration - compared_start, NULL);
741 g_object_unref (layer);
745 look_for_transition (GESTrackObject * track_object, GESTimelineLayer * layer)
748 GList *track_objects, *tmp, *cur;
750 track = ges_track_object_get_track (track_object);
752 track_objects = ges_track_get_objects (track);
754 cur = g_list_find (track_objects, track_object);
756 for (tmp = cur->next; tmp; tmp = tmp->next) {
757 if (GES_IS_TRACK_SOURCE (tmp->data)) {
760 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
761 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
762 ges_timeline_layer_remove_object (layer,
763 ges_track_object_get_timeline_object (tmp->data));
767 for (tmp = cur->prev; tmp; tmp = tmp->prev) {
768 if (GES_IS_TRACK_SOURCE (tmp->data)) {
771 if (GES_IS_TRACK_AUDIO_TRANSITION (tmp->data)
772 || GES_IS_TRACK_VIDEO_TRANSITION (tmp->data)) {
773 ges_timeline_layer_remove_object (layer,
774 ges_track_object_get_timeline_object (tmp->data));
777 g_list_foreach (track_objects, (GFunc) g_object_unref, NULL);
778 g_list_free (track_objects);
782 disconnect_handlers (GESTrack * track, gpointer * ptr)
784 g_signal_handler_disconnect (track, GPOINTER_TO_INT (ptr));
790 * ges_timeline_layer_remove_object:
791 * @layer: a #GESTimelineLayer
792 * @object: the #GESTimelineObject to remove
794 * Removes the given @object from the @layer and unparents it.
795 * Unparenting it means the reference owned by @layer on the @object will be
796 * removed. If you wish to use the @object after this function, make sure you
797 * call g_object_ref() before removing it from the @layer.
799 * Returns: TRUE if the object could be removed, FALSE if the layer does
800 * not want to remove the object.
803 ges_timeline_layer_remove_object (GESTimelineLayer * layer,
804 GESTimelineObject * object)
806 GESTimelineLayer *tl_obj_layer;
807 GList *trackobjects, *tmp;
809 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), FALSE);
810 g_return_val_if_fail (GES_IS_TIMELINE_OBJECT (object), FALSE);
812 GST_DEBUG ("layer:%p, object:%p", layer, object);
814 tl_obj_layer = ges_timeline_object_get_layer (object);
815 if (G_UNLIKELY (tl_obj_layer != layer)) {
816 GST_WARNING ("TimelineObject doesn't belong to this layer");
817 if (tl_obj_layer != NULL)
818 g_object_unref (tl_obj_layer);
821 g_object_unref (tl_obj_layer);
823 if (layer->priv->auto_transition) {
824 trackobjects = ges_timeline_object_get_track_objects (object);
826 for (tmp = trackobjects; tmp; tmp = tmp->next) {
827 look_for_transition (tmp->data, layer);
830 g_list_foreach (trackobjects, (GFunc) g_object_unref, NULL);
831 g_list_free (trackobjects);
834 g_hash_table_foreach_remove (layer->priv->signal_table,
835 (GHRFunc) disconnect_handlers, NULL);
837 /* emit 'object-removed' */
838 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_REMOVED], 0, object);
840 /* inform the object it's no longer in a layer */
841 ges_timeline_object_set_layer (object, NULL);
843 /* Remove it from our list of controlled objects */
844 layer->priv->objects_start =
845 g_list_remove (layer->priv->objects_start, object);
847 /* Remove our reference to the object */
848 g_object_unref (object);
854 * ges_timeline_layer_resync_priorities:
855 * @layer: a #GESTimelineLayer
857 * Resyncs the priorities of the objects controlled by @layer.
861 ges_timeline_layer_resync_priorities (GESTimelineLayer * layer)
864 GESTimelineObject *obj;
866 GST_DEBUG ("Resync priorities of %p", layer);
868 /* TODO : Inhibit composition updates while doing this.
869 * Ideally we want to do it from an even higher level, but here will
870 * do in the meantime. */
872 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
873 obj = GES_TIMELINE_OBJECT (tmp->data);
874 ges_timeline_object_set_priority (obj, GES_TIMELINE_OBJECT_PRIORITY (obj));
881 * ges_timeline_layer_set_priority:
882 * @layer: a #GESTimelineLayer
883 * @priority: the priority to set
885 * Sets the layer to the given @priority. See the documentation of the
886 * priority property for more information.
889 ges_timeline_layer_set_priority (GESTimelineLayer * layer, guint priority)
891 g_return_if_fail (GES_IS_TIMELINE_LAYER (layer));
893 GST_DEBUG ("layer:%p, priority:%d", layer, priority);
895 if (priority != layer->priv->priority) {
896 layer->priv->priority = priority;
897 layer->min_gnl_priority = (priority * LAYER_HEIGHT);
898 layer->max_gnl_priority = ((priority + 1) * LAYER_HEIGHT) - 1;
900 ges_timeline_layer_resync_priorities (layer);
905 * ges_timeline_layer_get_auto_transition:
906 * @layer: a #GESTimelineLayer
908 * Gets whether transitions are automatically added when objects
911 * Returns: %TRUE if transitions are automatically added, else %FALSE.
914 ges_timeline_layer_get_auto_transition (GESTimelineLayer * layer)
916 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), 0);
918 return layer->priv->auto_transition;
922 * ges_timeline_layer_set_auto_transition:
923 * @layer: a #GESTimelineLayer
924 * @auto_transition: whether the auto_transition is active
926 * Sets the layer to the given @auto_transition. See the documentation of the
927 * property auto_transition for more information.
930 ges_timeline_layer_set_auto_transition (GESTimelineLayer * layer,
931 gboolean auto_transition)
935 g_return_if_fail (GES_IS_TIMELINE_LAYER (layer));
937 if (auto_transition) {
938 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
939 if (GES_IS_TIMELINE_SOURCE (tmp->data)) {
940 g_signal_connect (G_OBJECT (tmp->data), "track-object-added",
941 G_CALLBACK (track_object_added_cb), layer);
942 g_signal_connect (G_OBJECT (tmp->data), "track-object-removed",
943 G_CALLBACK (track_object_removed_cb), layer);
946 /* FIXME calculate all the transitions at that time */
948 layer->priv->auto_transition = auto_transition;
952 * ges_timeline_layer_get_priority:
953 * @layer: a #GESTimelineLayer
955 * Get the priority of @layer within the timeline.
957 * Returns: The priority of the @layer within the timeline.
960 ges_timeline_layer_get_priority (GESTimelineLayer * layer)
962 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), 0);
964 return layer->priv->priority;
968 * ges_timeline_layer_get_objects:
969 * @layer: a #GESTimelineLayer
971 * Get the timeline objects this layer contains.
973 * Returns: (transfer full) (element-type GESTimelineObject): a #GList of
974 * timeline objects. The user is responsible for
975 * unreffing the contained objects and freeing the list.
979 ges_timeline_layer_get_objects (GESTimelineLayer * layer)
983 GESTimelineLayerClass *klass;
985 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), NULL);
987 klass = GES_TIMELINE_LAYER_GET_CLASS (layer);
989 if (klass->get_objects) {
990 return klass->get_objects (layer);
993 for (tmp = layer->priv->objects_start; tmp; tmp = tmp->next) {
994 ret = g_list_prepend (ret, tmp->data);
995 g_object_ref (tmp->data);
998 ret = g_list_reverse (ret);
1003 * ges_timeline_layer_is_empty:
1004 * @layer: The #GESTimelineLayer to check
1006 * Convenience method to check if @layer is empty (doesn't contain any object),
1009 * Returns: %TRUE if @layer is empty, %FALSE if it already contains at least
1010 * one #GESTimelineObject
1013 ges_timeline_layer_is_empty (GESTimelineLayer * layer)
1015 g_return_val_if_fail (GES_IS_TIMELINE_LAYER (layer), FALSE);
1017 return (layer->priv->objects_start == NULL);