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
23 * @short_description: Multimedia timeline
25 * #GESTimeline is the central object for any multimedia timeline.
27 * Contains a list of #GESTimelineLayer which users should use to arrange the
28 * various timeline objects through time.
30 * The output type is determined by the #GESTrack that are set on
33 * To save/load a timeline, you can use the ges_timeline_load_from_uri() and
34 * ges_timeline_save_to_uri() methods to use the default format. If you wish
35 * to specify the format to save/load the timeline from, please consult the
36 * documentation about #GESFormatter.
39 #include "ges-internal.h"
40 #include "ges-timeline.h"
41 #include "ges-track.h"
42 #include "ges-timeline-layer.h"
45 typedef struct _MoveContext MoveContext;
47 static inline void init_movecontext (MoveContext * mv_ctx);
49 G_DEFINE_TYPE (GESTimeline, ges_timeline, GST_TYPE_BIN);
51 #define GES_TIMELINE_PENDINGOBJS_GET_LOCK(timeline) \
52 (&GES_TIMELINE(timeline)->priv->pendingobjects_lock)
53 #define GES_TIMELINE_PENDINGOBJS_LOCK(timeline) \
54 (g_mutex_lock(GES_TIMELINE_PENDINGOBJS_GET_LOCK (timeline)))
55 #define GES_TIMELINE_PENDINGOBJS_UNLOCK(timeline) \
56 (g_mutex_unlock(GES_TIMELINE_PENDINGOBJS_GET_LOCK (timeline)))
59 * The move context is used for the timeline editing modes functions in order to
60 * + Ripple / Roll / Slide / Move / Trim
62 * The context aims at avoiding to recalculate values/objects on each call of the
67 GESTimelineObject *obj;
71 /* Ripple and Roll Objects */
72 GList *moving_tckobjs;
74 /* We use it as a set of TimelineObject to move between layers */
75 GHashTable *moving_tlobjs;
76 /* Min priority of the objects currently in moving_tlobjs */
78 /* Max priority of the objects currently in moving_tlobjs */
81 /* Never trim so duration would becomes < 0 */
84 /* fields to force/avoid new context */
85 /* Set to %TRUE when the track is doing updates of track objects
86 * properties so we don't end up always needing new move context */
87 gboolean ignore_needs_ctx;
88 gboolean needs_move_ctx;
90 /* Last snapping properties */
91 GESTrackObject *last_snaped1;
92 GESTrackObject *last_snaped2;
93 GstClockTime last_snap_ts;
96 struct _GESTimelinePrivate
98 GList *layers; /* A list of GESTimelineLayer sorted by priority */
99 GList *tracks; /* A list of private track data */
101 /* The duration of the timeline */
104 /* discoverer used for virgin sources */
105 GstDiscoverer *discoverer;
106 GList *pendingobjects;
107 /* lock to avoid discovery of objects that will be removed */
108 GMutex pendingobjects_lock;
110 /* Whether we are changing state asynchronously or not */
111 gboolean async_pending;
113 /* Timeline edition modes and snapping management */
114 guint64 snapping_distance;
116 /* FIXME: Should we offer an API over those fields ?
117 * FIXME: Should other classes than subclasses of TrackSource also
120 /* Snapping fields */
121 GHashTable *by_start; /* {TrackSource: start} */
122 GHashTable *by_end; /* {TrackSource: end} */
123 GHashTable *by_object; /* {timecode: TrackSource} */
124 GSequence *starts_ends; /* Sorted list of starts/ends */
125 /* We keep 1 reference to our trackobject here */
126 GSequence *tracksources; /* TrackSource-s sorted by start/priorities */
128 MoveContext movecontext;
131 /* private structure to contain our track-related information */
135 GESTimeline *timeline;
137 GstPad *pad; /* Pad from the track */
145 PROP_SNAPPING_DISTANCE,
149 static GParamSpec *properties[PROP_LAST];
163 static GstBinClass *parent_class;
165 static guint ges_timeline_signals[LAST_SIGNAL] = { 0 };
167 static gint custom_find_track (TrackPrivate * tr_priv, GESTrack * track);
168 static GstStateChangeReturn
169 ges_timeline_change_state (GstElement * element, GstStateChange transition);
171 discoverer_finished_cb (GstDiscoverer * discoverer, GESTimeline * timeline);
173 discoverer_discovered_cb (GstDiscoverer * discoverer,
174 GstDiscovererInfo * info, GError * err, GESTimeline * timeline);
176 /* GObject Standard vmethods*/
178 ges_timeline_get_property (GObject * object, guint property_id,
179 GValue * value, GParamSpec * pspec)
181 GESTimeline *timeline = GES_TIMELINE (object);
183 switch (property_id) {
185 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
187 g_value_set_uint64 (value, timeline->priv->duration);
189 case PROP_SNAPPING_DISTANCE:
190 g_value_set_uint64 (value, timeline->priv->snapping_distance);
196 ges_timeline_set_property (GObject * object, guint property_id,
197 const GValue * value, GParamSpec * pspec)
199 GESTimeline *timeline = GES_TIMELINE (object);
201 switch (property_id) {
202 case PROP_SNAPPING_DISTANCE:
203 timeline->priv->snapping_distance = g_value_get_uint64 (value);
206 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
211 ges_timeline_dispose (GObject * object)
213 GESTimelinePrivate *priv = GES_TIMELINE (object)->priv;
215 if (priv->discoverer) {
216 gst_discoverer_stop (priv->discoverer);
217 g_object_unref (priv->discoverer);
218 priv->discoverer = NULL;
221 while (priv->layers) {
222 GESTimelineLayer *layer = (GESTimelineLayer *) priv->layers->data;
223 ges_timeline_remove_layer (GES_TIMELINE (object), layer);
226 /* FIXME: it should be possible to remove tracks before removing
227 * layers, but at the moment this creates a problem because the track
228 * objects aren't notified that their gnlobjects have been destroyed.
231 while (priv->tracks) {
232 TrackPrivate *tr_priv = (TrackPrivate *) priv->tracks->data;
233 ges_timeline_remove_track (GES_TIMELINE (object), tr_priv->track);
236 g_hash_table_unref (priv->by_start);
237 g_hash_table_unref (priv->by_end);
238 g_hash_table_unref (priv->by_object);
239 g_sequence_free (priv->starts_ends);
240 g_sequence_free (priv->tracksources);
242 G_OBJECT_CLASS (ges_timeline_parent_class)->dispose (object);
246 ges_timeline_finalize (GObject * object)
248 GESTimeline *timeline = GES_TIMELINE (object);
250 g_mutex_clear (&timeline->priv->pendingobjects_lock);
252 G_OBJECT_CLASS (ges_timeline_parent_class)->finalize (object);
256 ges_timeline_class_init (GESTimelineClass * klass)
258 GObjectClass *object_class = G_OBJECT_CLASS (klass);
259 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
261 g_type_class_add_private (klass, sizeof (GESTimelinePrivate));
263 parent_class = g_type_class_peek_parent (klass);
265 element_class->change_state = ges_timeline_change_state;
267 object_class->get_property = ges_timeline_get_property;
268 object_class->set_property = ges_timeline_set_property;
269 object_class->dispose = ges_timeline_dispose;
270 object_class->finalize = ges_timeline_finalize;
273 * GESTimeline:duration
275 * Current duration (in nanoseconds) of the #GESTimeline
277 properties[PROP_DURATION] =
278 g_param_spec_uint64 ("duration", "Duration",
279 "The duration of the timeline", 0, G_MAXUINT64,
280 GST_CLOCK_TIME_NONE, G_PARAM_READABLE);
281 g_object_class_install_property (object_class, PROP_DURATION,
282 properties[PROP_DURATION]);
285 * GESTimeline:snapping-distance
287 * Distance (in nanoseconds) from which a moving object will snap
288 * with it neighboors. 0 means no snapping.
290 properties[PROP_SNAPPING_DISTANCE] =
291 g_param_spec_uint64 ("snapping-distance", "Snapping distance",
292 "Distance from which moving an object will snap with neighboors", 0,
293 G_MAXUINT64, 0, G_PARAM_READWRITE);
294 g_object_class_install_property (object_class, PROP_SNAPPING_DISTANCE,
295 properties[PROP_SNAPPING_DISTANCE]);
298 * GESTimeline::track-added
299 * @timeline: the #GESTimeline
300 * @track: the #GESTrack that was added to the timeline
302 * Will be emitted after the track was added to the timeline.
304 ges_timeline_signals[TRACK_ADDED] =
305 g_signal_new ("track-added", G_TYPE_FROM_CLASS (klass),
306 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineClass, track_added), NULL,
307 NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_TRACK);
310 * GESTimeline::track-removed
311 * @timeline: the #GESTimeline
312 * @track: the #GESTrack that was removed from the timeline
314 * Will be emitted after the track was removed from the timeline.
316 ges_timeline_signals[TRACK_REMOVED] =
317 g_signal_new ("track-removed", G_TYPE_FROM_CLASS (klass),
318 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineClass, track_removed),
319 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_TRACK);
322 * GESTimeline::layer-added
323 * @timeline: the #GESTimeline
324 * @layer: the #GESTimelineLayer that was added to the timeline
326 * Will be emitted after the layer was added to the timeline.
328 ges_timeline_signals[LAYER_ADDED] =
329 g_signal_new ("layer-added", G_TYPE_FROM_CLASS (klass),
330 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineClass, layer_added), NULL,
331 NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
332 GES_TYPE_TIMELINE_LAYER);
335 * GESTimeline::layer-removed
336 * @timeline: the #GESTimeline
337 * @layer: the #GESTimelineLayer that was removed from the timeline
339 * Will be emitted after the layer was removed from the timeline.
341 ges_timeline_signals[LAYER_REMOVED] =
342 g_signal_new ("layer-removed", G_TYPE_FROM_CLASS (klass),
343 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineClass, layer_removed),
344 NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
345 GES_TYPE_TIMELINE_LAYER);
348 * GESTimeline::discovery-error:
349 * @timeline: the #GESTimeline
350 * @formatter: the #GESFormatter
351 * @source: The #GESTimelineFileSource that could not be discovered properly
352 * @error: (type GLib.Error): #GError, which will be non-NULL if an error
353 * occurred during discovery
355 ges_timeline_signals[DISCOVERY_ERROR] =
356 g_signal_new ("discovery-error", G_TYPE_FROM_CLASS (klass),
357 G_SIGNAL_RUN_FIRST, 0, NULL, NULL, g_cclosure_marshal_generic,
358 G_TYPE_NONE, 2, GES_TYPE_TIMELINE_FILE_SOURCE, G_TYPE_ERROR);
361 * GESTimeline::track-objects-snapping:
362 * @timeline: the #GESTimeline
363 * @obj1: the first #GESTrackObject that was snapping.
364 * @obj2: the second #GESTrackObject that was snapping.
365 * @position: the position where the two objects finally snapping.
367 * Will be emitted when the 2 #GESTrackObject first snapped
371 ges_timeline_signals[SNAPING_STARTED] =
372 g_signal_new ("snapping-started", G_TYPE_FROM_CLASS (klass),
373 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL,
374 G_TYPE_NONE, 3, GES_TYPE_TRACK_OBJECT, GES_TYPE_TRACK_OBJECT,
378 * GESTimeline::snapping-end:
379 * @timeline: the #GESTimeline
380 * @obj1: the first #GESTrackObject that was snapping.
381 * @obj2: the second #GESTrackObject that was snapping.
382 * @position: the position where the two objects finally snapping.
384 * Will be emitted when the 2 #GESTrackObject ended to snap
388 ges_timeline_signals[SNAPING_ENDED] =
389 g_signal_new ("snapping-ended", G_TYPE_FROM_CLASS (klass),
390 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL,
391 G_TYPE_NONE, 3, GES_TYPE_TRACK_OBJECT, GES_TYPE_TRACK_OBJECT,
396 ges_timeline_init (GESTimeline * self)
398 GESTimelinePrivate *priv;
400 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
401 GES_TYPE_TIMELINE, GESTimelinePrivate);
407 priv->snapping_distance = 0;
409 /* Move context initialization */
410 init_movecontext (&self->priv->movecontext);
411 priv->movecontext.ignore_needs_ctx = FALSE;
413 priv->by_start = g_hash_table_new (g_direct_hash, g_direct_equal);
414 priv->by_end = g_hash_table_new (g_direct_hash, g_direct_equal);
415 priv->by_object = g_hash_table_new (g_direct_hash, g_direct_equal);
416 priv->starts_ends = g_sequence_new (g_free);
417 priv->tracksources = g_sequence_new (g_object_unref);
419 g_mutex_init (&priv->pendingobjects_lock);
420 /* New discoverer with a 15s timeout */
421 priv->discoverer = gst_discoverer_new (15 * GST_SECOND, NULL);
422 g_signal_connect (priv->discoverer, "finished",
423 G_CALLBACK (discoverer_finished_cb), self);
424 g_signal_connect (priv->discoverer, "discovered",
425 G_CALLBACK (discoverer_discovered_cb), self);
426 gst_discoverer_start (priv->discoverer);
429 /* Private methods */
433 sort_layers (gpointer a, gpointer b)
435 GESTimelineLayer *layer_a, *layer_b;
436 guint prio_a, prio_b;
438 layer_a = GES_TIMELINE_LAYER (a);
439 layer_b = GES_TIMELINE_LAYER (b);
441 prio_a = ges_timeline_layer_get_priority (layer_a);
442 prio_b = ges_timeline_layer_get_priority (layer_b);
444 if ((gint) prio_a > (guint) prio_b)
446 if ((guint) prio_a < (guint) prio_b)
453 objects_start_compare (GESTrackObject * a, GESTrackObject * b)
455 if (a->start == b->start) {
456 if (a->priority < b->priority)
458 if (a->priority > b->priority)
462 if (a->start < b->start)
464 if (a->start > b->start)
470 sort_track_objects (GESTimeline * timeline)
472 g_sequence_sort (timeline->priv->tracksources,
473 (GCompareDataFunc) objects_start_compare, NULL);
477 compare_uint64 (guint64 * a, guint64 * b, gpointer user_data)
488 custom_find_track (TrackPrivate * tr_priv, GESTrack * track)
490 if (tr_priv->track == track)
495 /* Look for the pointer passed as @value */
496 static GSequenceIter *
497 lookup_pointer_uint (GSequence * seq, guint64 * value)
499 GSequenceIter *iter, *tmpiter;
500 guint64 *found, *tmpval;
502 iter = g_sequence_lookup (seq, value,
503 (GCompareDataFunc) compare_uint64, NULL);
505 found = g_sequence_get (iter);
507 /* We have the same pointer so we are all fine */
511 if (!g_sequence_iter_is_end (iter)) {
512 /* Looking frontward for the good pointer */
514 while ((tmpiter = g_sequence_iter_next (tmpiter))) {
515 if (g_sequence_iter_is_end (tmpiter))
518 tmpval = g_sequence_get (tmpiter);
521 else if (*tmpval != *value)
526 if (!g_sequence_iter_is_begin (iter)) {
527 /* Looking backward for the good pointer */
529 while ((tmpiter = g_sequence_iter_prev (tmpiter))) {
530 tmpval = g_sequence_get (tmpiter);
533 else if (*tmpval != *value || g_sequence_iter_is_begin (tmpiter))
538 GST_ERROR ("Missing timecode %p %" GST_TIME_FORMAT
539 " this should never happen", value, GST_TIME_ARGS (*value));
545 sort_starts_ends_end (GESTimeline * timeline, GESTrackObject * obj)
549 GESTimelinePrivate *priv = timeline->priv;
550 guint64 *end = g_hash_table_lookup (priv->by_end, obj);
552 iter = lookup_pointer_uint (priv->starts_ends, end);
553 *end = obj->start + obj->duration;
555 g_sequence_sort_changed (iter, (GCompareDataFunc) compare_uint64, NULL);
559 sort_starts_ends_start (GESTimeline * timeline, GESTrackObject * obj)
563 GESTimelinePrivate *priv = timeline->priv;
564 guint64 *start = g_hash_table_lookup (priv->by_start, obj);
566 iter = lookup_pointer_uint (priv->starts_ends, start);
569 g_sequence_sort_changed (iter, (GCompareDataFunc) compare_uint64, NULL);
573 resort_all_starts_ends (GESTimeline * timeline)
576 GESTrackObject *tckobj;
577 guint64 *start, *end;
579 GESTimelinePrivate *priv = timeline->priv;
581 for (iter = g_sequence_get_begin_iter (priv->tracksources);
582 !g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter)) {
583 tckobj = GES_TRACK_OBJECT (g_sequence_get (iter));
585 start = g_hash_table_lookup (priv->by_start, tckobj);
586 end = g_hash_table_lookup (priv->by_end, tckobj);
588 *start = tckobj->start;
589 *end = tckobj->start + tckobj->duration;
592 g_sequence_sort (priv->starts_ends, (GCompareDataFunc) compare_uint64, NULL);
596 sort_all (GESTimeline * timeline)
598 sort_track_objects (timeline);
599 resort_all_starts_ends (timeline);
602 /* Timeline edition functions */
604 init_movecontext (MoveContext * mv_ctx)
606 mv_ctx->moving_tckobjs = NULL;
607 mv_ctx->moving_tlobjs = g_hash_table_new (g_direct_hash, g_direct_equal);
608 mv_ctx->max_trim_pos = G_MAXUINT64;
609 mv_ctx->min_move_layer = G_MAXUINT;
610 mv_ctx->max_layer_prio = 0;
611 mv_ctx->last_snaped1 = NULL;
612 mv_ctx->last_snaped2 = NULL;
613 mv_ctx->last_snap_ts = GST_CLOCK_TIME_NONE;
617 clean_movecontext (MoveContext * mv_ctx)
619 g_list_free (mv_ctx->moving_tckobjs);
620 g_hash_table_unref (mv_ctx->moving_tlobjs);
621 init_movecontext (mv_ctx);
625 stop_tracking_for_snapping (GESTimeline * timeline, GESTrackObject * tckobj)
627 guint64 *start, *end;
628 GESTimelinePrivate *priv = timeline->priv;
629 GSequenceIter *iter_start, *iter_end, *tckobj_iter;
632 start = g_hash_table_lookup (priv->by_start, tckobj);
633 end = g_hash_table_lookup (priv->by_end, tckobj);
635 iter_start = lookup_pointer_uint (priv->starts_ends, start);
636 iter_end = lookup_pointer_uint (priv->starts_ends, end);
637 tckobj_iter = g_sequence_lookup (timeline->priv->tracksources, tckobj,
638 (GCompareDataFunc) objects_start_compare, NULL);
640 g_hash_table_remove (priv->by_start, tckobj);
641 g_hash_table_remove (priv->by_end, tckobj);
642 g_hash_table_remove (priv->by_object, end);
643 g_hash_table_remove (priv->by_object, start);
645 g_sequence_remove (iter_start);
646 g_sequence_remove (iter_end);
647 g_sequence_remove (tckobj_iter);
652 start_tracking_track_obj (GESTimeline * timeline, GESTrackObject * tckobj)
654 guint64 *pstart, *pend;
655 GESTimelinePrivate *priv = timeline->priv;
657 pstart = g_malloc (sizeof (guint64));
658 pend = g_malloc (sizeof (guint64));
659 *pstart = tckobj->start;
660 *pend = *pstart + tckobj->duration;
662 g_sequence_insert_sorted (priv->starts_ends, pstart,
663 (GCompareDataFunc) compare_uint64, NULL);
664 g_sequence_insert_sorted (priv->starts_ends, pend,
665 (GCompareDataFunc) compare_uint64, NULL);
666 g_sequence_insert_sorted (priv->tracksources, g_object_ref (tckobj),
667 (GCompareDataFunc) objects_start_compare, NULL);
669 g_hash_table_insert (priv->by_start, tckobj, pstart);
670 g_hash_table_insert (priv->by_object, pstart, tckobj);
671 g_hash_table_insert (priv->by_end, tckobj, pend);
672 g_hash_table_insert (priv->by_object, pend, tckobj);
674 timeline->priv->movecontext.needs_move_ctx = TRUE;
678 ges_timeline_emit_snappig (GESTimeline * timeline, GESTrackObject * obj1,
681 GESTrackObject *obj2;
682 MoveContext *mv_ctx = &timeline->priv->movecontext;
684 if (timecode == NULL) {
685 if (mv_ctx->last_snaped1 != NULL && mv_ctx->last_snaped2 != NULL) {
686 g_signal_emit (timeline, ges_timeline_signals[SNAPING_ENDED], 0,
687 mv_ctx->last_snaped1, mv_ctx->last_snaped2, mv_ctx->last_snap_ts);
689 /* We then need to recalculate the moving context */
690 timeline->priv->movecontext.needs_move_ctx = TRUE;
696 obj2 = g_hash_table_lookup (timeline->priv->by_object, timecode);
698 if (mv_ctx->last_snap_ts != *timecode) {
699 g_signal_emit (timeline, ges_timeline_signals[SNAPING_ENDED], 0,
700 mv_ctx->last_snaped1, mv_ctx->last_snaped2, mv_ctx->last_snap_ts);
702 /* We want the snap start signal to be emited anyway */
703 mv_ctx->last_snap_ts = GST_CLOCK_TIME_NONE;
706 if (GST_CLOCK_TIME_IS_VALID (mv_ctx->last_snap_ts) == FALSE) {
708 mv_ctx->last_snaped1 = obj1;
709 mv_ctx->last_snaped2 = obj2;
710 mv_ctx->last_snap_ts = *timecode;
712 g_signal_emit (timeline, ges_timeline_signals[SNAPING_STARTED], 0,
713 obj1, obj2, *timecode);
719 ges_timeline_snap_position (GESTimeline * timeline, GESTrackObject * trackobj,
720 guint64 * current, guint64 timecode, gboolean emit)
722 GESTimelinePrivate *priv = timeline->priv;
723 GSequenceIter *iter, *prev_iter, *nxt_iter;
724 GESTrackObject *tmp_tckobj;
725 GESTimelineObject *tmp_tlobj, *tlobj;
727 guint64 snap_distance = timeline->priv->snapping_distance;
729 guint64 *prev_tc, *next_tc, *ret = NULL, off = G_MAXUINT64, off1 =
732 /* Avoid useless calculations */
733 if (snap_distance == 0)
736 tlobj = ges_track_object_get_timeline_object (trackobj);
738 iter = g_sequence_search (priv->starts_ends, &timecode,
739 (GCompareDataFunc) compare_uint64, NULL);
741 /* Getting the next/previous values, and use the closest one if any "respects"
742 * the snap_distance value */
744 while (!g_sequence_iter_is_end (nxt_iter)) {
745 next_tc = g_sequence_get (iter);
746 tmp_tckobj = g_hash_table_lookup (timeline->priv->by_object, next_tc);
747 tmp_tlobj = ges_track_object_get_timeline_object (tmp_tckobj);
749 off = timecode > *next_tc ? timecode - *next_tc : *next_tc - timecode;
750 if (next_tc != current && off <= snap_distance && tlobj != tmp_tlobj) {
756 nxt_iter = g_sequence_iter_next (nxt_iter);
759 prev_iter = g_sequence_iter_prev (iter);
760 while (!g_sequence_iter_is_begin (prev_iter)) {
761 prev_tc = g_sequence_get (prev_iter);
762 tmp_tckobj = g_hash_table_lookup (timeline->priv->by_object, prev_tc);
763 tmp_tlobj = ges_track_object_get_timeline_object (tmp_tckobj);
765 off1 = timecode > *prev_tc ? timecode - *prev_tc : *prev_tc - timecode;
766 if (prev_tc != current && off1 < off && off1 <= snap_distance &&
767 tlobj != tmp_tlobj) {
773 prev_iter = g_sequence_iter_prev (prev_iter);
776 /* We emit the snapping signal only if we snapped with a different value
777 * than the current one */
779 ges_timeline_emit_snappig (timeline, trackobj, ret);
780 GST_DEBUG_OBJECT (timeline, "Snaping at %" GST_TIME_FORMAT,
781 GST_TIME_ARGS (*ret));
787 static inline GESTimelineObject *
788 add_moving_timeline_object (MoveContext * mv_ctx, GESTrackObject * tckobj)
790 GESTimelineObject *tlobj;
791 GESTimelineLayer *layer;
794 tlobj = ges_track_object_get_timeline_object (tckobj);
796 /* Avoid recalculating */
797 if (!g_hash_table_lookup (mv_ctx->moving_tlobjs, tlobj)) {
798 layer = ges_timeline_object_get_layer (tlobj);
800 GST_WARNING_OBJECT (tlobj, "Not in any layer, can not move"
805 g_hash_table_insert (mv_ctx->moving_tlobjs, tlobj, tlobj);
807 layer_prio = ges_timeline_layer_get_priority (layer);
808 mv_ctx->min_move_layer = MIN (mv_ctx->min_move_layer, layer_prio);
809 mv_ctx->max_layer_prio = MAX (mv_ctx->max_layer_prio, layer_prio);
811 g_object_unref (layer);
819 ges_move_context_set_objects (GESTimeline * timeline, GESTrackObject * obj,
822 GSequenceIter *iter, *tckobj_iter;
823 guint64 start, end, tmpend;
824 GESTrackObject *tmptckobj;
826 MoveContext *mv_ctx = &timeline->priv->movecontext;
828 tckobj_iter = g_sequence_lookup (timeline->priv->tracksources, obj,
829 (GCompareDataFunc) objects_start_compare, NULL);
833 /* set it properly int the context of "trimming" */
834 mv_ctx->max_trim_pos = 0;
837 if (g_sequence_iter_is_begin (tckobj_iter))
840 /* Look for the objects */
841 for (iter = g_sequence_iter_prev (tckobj_iter);
842 iter && !g_sequence_iter_is_end (iter);
843 iter = g_sequence_iter_prev (iter)) {
845 tmptckobj = GES_TRACK_OBJECT (g_sequence_get (iter));
846 tmpend = tmptckobj->start + tmptckobj->duration;
848 if (tmpend <= start) {
849 mv_ctx->max_trim_pos = MAX (mv_ctx->max_trim_pos, tmptckobj->start);
850 mv_ctx->moving_tckobjs =
851 g_list_prepend (mv_ctx->moving_tckobjs, tmptckobj);
854 if (g_sequence_iter_is_begin (iter))
860 case GES_EDGE_NONE: /* In this case only works for ripple */
861 end = ges_track_object_get_start (obj) +
862 ges_track_object_get_duration (obj);
864 mv_ctx->max_trim_pos = G_MAXUINT64;
866 /* Look for folowing objects */
867 for (iter = g_sequence_iter_next (tckobj_iter);
868 iter && !g_sequence_iter_is_end (iter);
869 iter = g_sequence_iter_next (iter)) {
870 tmptckobj = GES_TRACK_OBJECT (g_sequence_get (iter));
872 if (tmptckobj->start >= end) {
873 tmpend = tmptckobj->start + tmptckobj->duration;
874 mv_ctx->max_trim_pos = MIN (mv_ctx->max_trim_pos, tmpend);
875 mv_ctx->moving_tckobjs =
876 g_list_prepend (mv_ctx->moving_tckobjs, tmptckobj);
881 GST_DEBUG ("Edge type %d no supported", edge);
889 ges_timeline_set_moving_context (GESTimeline * timeline, GESTrackObject * obj,
890 GESEditMode mode, GESEdge edge, GList * layers)
892 MoveContext *mv_ctx = &timeline->priv->movecontext;
893 GESTimelineObject *tlobj = ges_track_object_get_timeline_object (obj);
895 /* Still in the same mv_ctx */
896 if ((mv_ctx->obj == tlobj && mv_ctx->mode == mode &&
897 mv_ctx->edge == edge && !mv_ctx->needs_move_ctx)) {
899 GST_DEBUG ("Keeping the same moving mv_ctx");
903 GST_DEBUG_OBJECT (tlobj,
904 "Changing context:\nold: obj: %p, mode: %d, edge: %d \n"
905 "new: obj: %p, mode: %d, edge: %d ! Has changed %i", mv_ctx->obj,
906 mv_ctx->mode, mv_ctx->edge, tlobj, mode, edge, mv_ctx->needs_move_ctx);
908 clean_movecontext (mv_ctx);
912 mv_ctx->needs_move_ctx = FALSE;
915 case GES_EDIT_MODE_RIPPLE:
916 case GES_EDIT_MODE_ROLL:
917 if (!(ges_move_context_set_objects (timeline, obj, edge)))
923 /* And we add the main object to the moving_tlobjs set */
924 add_moving_timeline_object (&timeline->priv->movecontext, obj);
931 ges_timeline_trim_object_simple (GESTimeline * timeline, GESTrackObject * obj,
932 GList * layers, GESEdge edge, guint64 position, gboolean snapping)
934 guint64 nstart, start, inpoint, duration, max_duration, *snapped, *cur;
938 GST_DEBUG_OBJECT (obj, "Trimming to %" GST_TIME_FORMAT " %s snaping, edge %i",
939 GST_TIME_ARGS (position), snapping ? "Is" : "Not", edge);
941 start = ges_track_object_get_start (obj);
942 g_object_get (obj, "max-duration", &max_duration, NULL);
946 inpoint = obj->inpoint;
947 duration = obj->duration;
950 cur = g_hash_table_lookup (timeline->priv->by_start, obj);
952 snapped = ges_timeline_snap_position (timeline, obj, cur, position,
960 /* Calculate new values */
961 position = MAX (start > inpoint ? start - inpoint : 0, position);
962 position = MIN (position, start + duration);
963 inpoint = MAX (0, inpoint + position - start);
965 real_dur = start + duration - nstart;
966 /* FIXME: Why CLAMP (0, real_dur, max_duration) doesn't work? */
967 duration = MAX (0, real_dur);
968 duration = MIN (duration, max_duration - obj->inpoint);
970 ges_track_object_set_start (obj, nstart);
971 ges_track_object_set_duration (obj, duration);
972 ges_track_object_set_inpoint (obj, inpoint);
976 cur = g_hash_table_lookup (timeline->priv->by_end, obj);
977 snapped = ges_timeline_snap_position (timeline, obj, cur, position, TRUE);
981 /* Calculate new values */
982 real_dur = position - start;
983 duration = MAX (0, real_dur);
984 duration = MIN (duration, max_duration - obj->inpoint);
986 ges_track_object_set_duration (obj, duration);
990 GST_WARNING ("Can not trim with %i GESEdge", edge);
998 timeline_ripple_object (GESTimeline * timeline, GESTrackObject * obj,
999 GList * layers, GESEdge edge, guint64 position)
1001 GList *tmp, *moved_tlobjs = NULL;
1002 GESTrackObject *tckobj;
1003 GESTimelineObject *tlobj;
1004 guint64 duration, new_start, *snapped, *cur;
1007 MoveContext *mv_ctx = &timeline->priv->movecontext;
1009 mv_ctx->ignore_needs_ctx = TRUE;
1011 if (!ges_timeline_set_moving_context (timeline, obj, GES_EDIT_MODE_RIPPLE,
1017 GST_DEBUG ("Simply rippling");
1019 cur = g_hash_table_lookup (timeline->priv->by_end, obj);
1020 snapped = ges_timeline_snap_position (timeline, obj, cur, position, TRUE);
1022 position = *snapped;
1024 offset = position - obj->start;
1026 for (tmp = mv_ctx->moving_tckobjs; tmp; tmp = tmp->next) {
1027 tckobj = GES_TRACK_OBJECT (tmp->data);
1028 new_start = tckobj->start + offset;
1030 tlobj = add_moving_timeline_object (mv_ctx, tckobj);
1032 if (ges_track_object_is_locked (tckobj) == TRUE) {
1034 /* Make sure not to move 2 times the same TimelineObject */
1035 if (g_list_find (moved_tlobjs, tlobj) == NULL) {
1036 ges_track_object_set_start (tckobj, new_start);
1037 moved_tlobjs = g_list_prepend (moved_tlobjs, tlobj);
1041 ges_track_object_set_start (tckobj, new_start);
1044 g_list_free (moved_tlobjs);
1045 ges_track_object_set_start (obj, position);
1049 GST_DEBUG ("Rippling end");
1051 cur = g_hash_table_lookup (timeline->priv->by_end, obj);
1052 snapped = ges_timeline_snap_position (timeline, obj, cur, position, TRUE);
1054 position = *snapped;
1056 duration = obj->duration;
1058 ges_track_object_set_duration (obj, position - obj->start);
1060 offset = obj->duration - duration;
1061 for (tmp = mv_ctx->moving_tckobjs; tmp; tmp = tmp->next) {
1062 tckobj = GES_TRACK_OBJECT (tmp->data);
1063 new_start = tckobj->start + offset;
1065 tlobj = add_moving_timeline_object (mv_ctx, tckobj);
1067 if (ges_track_object_is_locked (tckobj) == TRUE) {
1069 /* Make sure not to move 2 times the same TimelineObject */
1070 if (g_list_find (moved_tlobjs, tlobj) == NULL) {
1071 ges_track_object_set_start (tckobj, new_start);
1072 moved_tlobjs = g_list_prepend (moved_tlobjs, tlobj);
1076 ges_track_object_set_start (tckobj, new_start);
1080 g_list_free (moved_tlobjs);
1081 GST_DEBUG ("Done Rippling end");
1083 case GES_EDGE_START:
1084 GST_WARNING ("Ripple start doesn't exist!");
1088 GST_DEBUG ("Can not ripple edge: %i", edge);
1093 mv_ctx->ignore_needs_ctx = FALSE;
1098 mv_ctx->ignore_needs_ctx = FALSE;
1104 timeline_slide_object (GESTimeline * timeline, GESTrackObject * obj,
1105 GList * layers, GESEdge edge, guint64 position)
1108 /* FIXME implement me! */
1109 GST_WARNING ("Slide mode editing not implemented yet");
1115 timeline_trim_object (GESTimeline * timeline, GESTrackObject * object,
1116 GList * layers, GESEdge edge, guint64 position)
1118 gboolean ret = FALSE;
1119 MoveContext *mv_ctx = &timeline->priv->movecontext;
1121 mv_ctx->ignore_needs_ctx = TRUE;
1123 if (!ges_timeline_set_moving_context (timeline, object, GES_EDIT_MODE_TRIM,
1128 ges_timeline_trim_object_simple (timeline, object, layers, edge, position,
1132 mv_ctx->ignore_needs_ctx = FALSE;
1138 timeline_roll_object (GESTimeline * timeline, GESTrackObject * obj,
1139 GList * layers, GESEdge edge, guint64 position)
1141 MoveContext *mv_ctx = &timeline->priv->movecontext;
1142 guint64 start, duration, end, tmpstart, tmpduration, tmpend, *snapped, *cur;
1143 gboolean ret = TRUE;
1146 mv_ctx->ignore_needs_ctx = TRUE;
1148 GST_DEBUG_OBJECT (obj, "Rolling object to %" GST_TIME_FORMAT,
1149 GST_TIME_ARGS (position));
1151 if (!ges_timeline_set_moving_context (timeline, obj, GES_EDIT_MODE_ROLL,
1155 start = ges_track_object_get_start (obj);
1156 duration = ges_track_object_get_duration (obj);
1157 end = start + duration;
1160 case GES_EDGE_START:
1162 /* Avoid negative durations */
1163 if (position < mv_ctx->max_trim_pos || position > end)
1166 cur = g_hash_table_lookup (timeline->priv->by_start, obj);
1167 snapped = ges_timeline_snap_position (timeline, obj, cur, position, TRUE);
1169 position = *snapped;
1172 ges_timeline_trim_object_simple (timeline, obj, layers,
1173 GES_EDGE_START, position, FALSE);
1175 /* In the case we reached max_duration we just make sure to roll
1176 * everything to the real new position */
1177 position = obj->start;
1179 /* Send back changes to the neighbourhood */
1180 for (tmp = mv_ctx->moving_tckobjs; tmp; tmp = tmp->next) {
1181 GESTrackObject *tmptckobj = GES_TRACK_OBJECT (tmp->data);
1183 tmpstart = ges_track_object_get_start (tmptckobj);
1184 tmpduration = ges_track_object_get_duration (tmptckobj);
1185 tmpend = tmpstart + tmpduration;
1187 /* Check that the object should be resized at this position
1188 * even if an error accurs, we keep doing our job */
1189 if (tmpend == start) {
1190 ret &= ges_timeline_trim_object_simple (timeline, tmptckobj, NULL,
1191 GES_EDGE_END, position, FALSE);
1198 /* Avoid negative durations */
1199 if (position > mv_ctx->max_trim_pos || position < start)
1202 end = obj->start + obj->duration;
1204 cur = g_hash_table_lookup (timeline->priv->by_end, obj);
1205 snapped = ges_timeline_snap_position (timeline, obj, cur, position, TRUE);
1207 position = *snapped;
1209 ret &= ges_timeline_trim_object_simple (timeline, obj, NULL, GES_EDGE_END,
1212 /* In the case we reached max_duration we just make sure to roll
1213 * everything to the real new position */
1214 position = obj->start + obj->duration;
1216 /* Send back changes to the neighbourhood */
1217 for (tmp = mv_ctx->moving_tckobjs; tmp; tmp = tmp->next) {
1218 GESTrackObject *tmptckobj = GES_TRACK_OBJECT (tmp->data);
1220 tmpstart = ges_track_object_get_start (tmptckobj);
1221 tmpduration = ges_track_object_get_duration (tmptckobj);
1222 tmpend = tmpstart + tmpduration;
1224 /* Check that the object should be resized at this position
1225 * even if an error accure, we keep doing our job */
1226 if (end == tmpstart) {
1227 ret &= ges_timeline_trim_object_simple (timeline, tmptckobj, NULL,
1228 GES_EDGE_START, position, FALSE);
1233 GST_DEBUG ("Edge type %i not handled here", edge);
1237 mv_ctx->ignore_needs_ctx = FALSE;
1242 mv_ctx->ignore_needs_ctx = FALSE;
1244 GST_DEBUG_OBJECT (obj, "Could not roll edge %d to %" GST_TIME_FORMAT,
1245 edge, GST_TIME_ARGS (position));
1251 timeline_move_object (GESTimeline * timeline, GESTrackObject * object,
1252 GList * layers, GESEdge edge, guint64 position)
1254 if (!ges_timeline_set_moving_context (timeline, object, GES_EDIT_MODE_RIPPLE,
1256 GST_DEBUG_OBJECT (object, "Could not move to %" GST_TIME_FORMAT,
1257 GST_TIME_ARGS (position));
1262 return ges_timeline_move_object_simple (timeline, object, layers, edge,
1267 ges_timeline_move_object_simple (GESTimeline * timeline,
1268 GESTrackObject * object, GList * layers, GESEdge edge, guint64 position)
1270 guint64 *snap_end, *snap_st, *cur, off1, off2, end;
1272 GST_DEBUG_OBJECT (timeline, "Moving to %" GST_TIME_FORMAT,
1273 GST_TIME_ARGS (position));
1275 end = position + object->duration;
1276 cur = g_hash_table_lookup (timeline->priv->by_end, object);
1277 snap_end = ges_timeline_snap_position (timeline, object, cur, end, FALSE);
1279 off1 = end > *snap_end ? end - *snap_end : *snap_end - end;
1283 cur = g_hash_table_lookup (timeline->priv->by_start, object);
1284 snap_st = ges_timeline_snap_position (timeline, object, cur, position, FALSE);
1286 off2 = position > *snap_st ? position - *snap_st : *snap_st - position;
1290 /* In the case we could snap on both sides, we snap on the end */
1291 if (snap_end && off1 <= off2) {
1292 position = position + *snap_end - end;
1293 ges_timeline_emit_snappig (timeline, object, snap_end);
1294 GST_DEBUG_OBJECT (timeline, "Real snap at %" GST_TIME_FORMAT,
1295 GST_TIME_ARGS (position));
1296 } else if (snap_st) {
1297 position = position + *snap_st - position;
1298 ges_timeline_emit_snappig (timeline, object, snap_st);
1299 GST_DEBUG_OBJECT (timeline, "Real snap at %" GST_TIME_FORMAT,
1300 GST_TIME_ARGS (position));
1302 ges_timeline_emit_snappig (timeline, object, NULL);
1305 ges_track_object_set_start (object, position);
1311 timeline_context_to_layer (GESTimeline * timeline, gint offset)
1313 gboolean ret = TRUE;
1314 MoveContext *mv_ctx = &timeline->priv->movecontext;
1318 /* Layer's priority is always positive */
1319 if (offset != 0 && (offset > 0 || mv_ctx->min_move_layer >= -offset)) {
1320 GHashTableIter iter;
1321 GESTimelineObject *key, *value;
1322 GESTimelineLayer *new_layer, *layer;
1325 mv_ctx->ignore_needs_ctx = TRUE;
1327 GST_DEBUG ("Moving %d object, offset %d",
1328 g_hash_table_size (mv_ctx->moving_tlobjs), offset);
1330 g_hash_table_iter_init (&iter, mv_ctx->moving_tlobjs);
1331 while (g_hash_table_iter_next (&iter, (gpointer *) & key,
1332 (gpointer *) & value)) {
1333 layer = ges_timeline_object_get_layer (value);
1334 prio = ges_timeline_layer_get_priority (layer);
1336 /* We know that the layer exists as we created it */
1337 new_layer = GES_TIMELINE_LAYER (g_list_nth_data (timeline->priv->layers,
1340 if (new_layer == NULL) {
1342 new_layer = ges_timeline_append_layer (timeline);
1343 } while (ges_timeline_layer_get_priority (new_layer) < prio + offset);
1346 ret &= ges_timeline_object_move_to_layer (key, new_layer);
1348 g_object_unref (layer);
1351 /* Readjust min_move_layer */
1352 mv_ctx->min_move_layer = mv_ctx->min_move_layer + offset;
1354 mv_ctx->ignore_needs_ctx = FALSE;
1361 add_object_to_track (GESTimelineObject * object, GESTrack * track)
1363 if (!ges_timeline_object_create_track_objects (object, track)) {
1364 if ((track->type & ges_timeline_object_get_supported_formats (object))) {
1365 GST_WARNING ("Error creating track objects");
1371 add_object_to_tracks (GESTimeline * timeline, GESTimelineObject * object)
1375 for (tmp = timeline->priv->tracks; tmp; tmp = g_list_next (tmp)) {
1376 TrackPrivate *tr_priv = (TrackPrivate *) tmp->data;
1377 GESTrack *track = tr_priv->track;
1379 GST_LOG ("Trying with track %p", track);
1380 add_object_to_track (object, track);
1385 do_async_start (GESTimeline * timeline)
1387 GstMessage *message;
1390 timeline->priv->async_pending = TRUE;
1392 /* Freeze state of tracks */
1393 for (tmp = timeline->priv->tracks; tmp; tmp = tmp->next) {
1394 TrackPrivate *tr_priv = (TrackPrivate *) tmp->data;
1395 gst_element_set_locked_state ((GstElement *) tr_priv->track, TRUE);
1398 message = gst_message_new_async_start (GST_OBJECT_CAST (timeline));
1399 parent_class->handle_message (GST_BIN_CAST (timeline), message);
1403 do_async_done (GESTimeline * timeline)
1405 GstMessage *message;
1407 if (timeline->priv->async_pending) {
1409 /* Unfreeze state of tracks */
1410 for (tmp = timeline->priv->tracks; tmp; tmp = tmp->next) {
1411 TrackPrivate *tr_priv = (TrackPrivate *) tmp->data;
1412 gst_element_set_locked_state ((GstElement *) tr_priv->track, FALSE);
1413 gst_element_sync_state_with_parent ((GstElement *) tr_priv->track);
1416 GST_DEBUG_OBJECT (timeline, "Emitting async-done");
1417 message = gst_message_new_async_done (GST_OBJECT_CAST (timeline), FALSE);
1418 parent_class->handle_message (GST_BIN_CAST (timeline), message);
1420 timeline->priv->async_pending = FALSE;
1426 discoverer_finished_cb (GstDiscoverer * discoverer, GESTimeline * timeline)
1428 do_async_done (timeline);
1432 discoverer_discovered_cb (GstDiscoverer * discoverer,
1433 GstDiscovererInfo * info, GError * err, GESTimeline * timeline)
1437 GESTrackType tfs_supportedformats;
1439 gboolean found = FALSE;
1440 gboolean is_image = FALSE;
1441 GESTimelineFileSource *tfs = NULL;
1442 GESTimelinePrivate *priv = timeline->priv;
1443 const gchar *uri = gst_discoverer_info_get_uri (info);
1445 GES_TIMELINE_PENDINGOBJS_LOCK (timeline);
1447 /* Find corresponding TimelineFileSource in the sources */
1448 for (tmp = priv->pendingobjects; tmp; tmp = tmp->next) {
1449 tfs = (GESTimelineFileSource *) tmp->data;
1451 if (!g_strcmp0 (ges_timeline_filesource_get_uri (tfs), uri)) {
1458 GST_WARNING ("Discovered %s, that seems not to be in the list of sources"
1459 "to discover", uri);
1460 GES_TIMELINE_PENDINGOBJS_UNLOCK (timeline);
1465 GError *propagate_error = NULL;
1467 priv->pendingobjects = g_list_delete_link (priv->pendingobjects, tmp);
1468 GES_TIMELINE_PENDINGOBJS_UNLOCK (timeline);
1469 GST_WARNING ("Error while discovering %s: %s", uri, err->message);
1471 g_propagate_error (&propagate_error, err);
1472 g_signal_emit (timeline, ges_timeline_signals[DISCOVERY_ERROR], 0, tfs,
1478 /* Everything went fine... let's do our job! */
1479 GST_DEBUG ("Discovered uri %s", uri);
1481 /* The timeline file source will be updated with discovered information
1482 * so it needs to not be finalized during this process */
1485 /* Remove object from list */
1486 priv->pendingobjects = g_list_delete_link (priv->pendingobjects, tmp);
1487 GES_TIMELINE_PENDINGOBJS_UNLOCK (timeline);
1489 /* FIXME : Handle errors in discovery */
1490 stream_list = gst_discoverer_info_get_stream_list (info);
1492 tfs_supportedformats = ges_timeline_filesource_get_supported_formats (tfs);
1493 if (tfs_supportedformats != GES_TRACK_TYPE_UNKNOWN)
1496 /* Update timelinefilesource properties based on info */
1497 for (tmp = stream_list; tmp; tmp = tmp->next) {
1498 GstDiscovererStreamInfo *sinf = (GstDiscovererStreamInfo *) tmp->data;
1500 if (GST_IS_DISCOVERER_AUDIO_INFO (sinf)) {
1501 tfs_supportedformats |= GES_TRACK_TYPE_AUDIO;
1502 ges_timeline_filesource_set_supported_formats (tfs, tfs_supportedformats);
1503 } else if (GST_IS_DISCOVERER_VIDEO_INFO (sinf)) {
1504 tfs_supportedformats |= GES_TRACK_TYPE_VIDEO;
1505 ges_timeline_filesource_set_supported_formats (tfs, tfs_supportedformats);
1506 if (gst_discoverer_video_info_is_image ((GstDiscovererVideoInfo *)
1508 tfs_supportedformats |= GES_TRACK_TYPE_AUDIO;
1509 ges_timeline_filesource_set_supported_formats (tfs,
1510 tfs_supportedformats);
1517 gst_discoverer_stream_info_list_free (stream_list);
1522 /* don't set max-duration on still images */
1523 g_object_set (tfs, "is_image", (gboolean) TRUE, NULL);
1526 /* Continue the processing on tfs */
1527 add_object_to_tracks (timeline, GES_TIMELINE_OBJECT (tfs));
1530 g_object_set (tfs, "max-duration",
1531 gst_discoverer_info_get_duration (info), NULL);
1534 /* Remove the ref as the timeline file source is no longer needed here */
1535 g_object_unref (tfs);
1539 layer_object_added_cb (GESTimelineLayer * layer, GESTimelineObject * object,
1540 GESTimeline * timeline)
1542 if (ges_timeline_object_is_moving_from_layer (object)) {
1543 GST_DEBUG ("TimelineObject %p is moving from a layer to another, not doing"
1544 " anything on it", object);
1545 if (!timeline->priv->movecontext.ignore_needs_ctx)
1546 timeline->priv->movecontext.needs_move_ctx = TRUE;
1550 GST_DEBUG ("New TimelineObject %p added to layer %p", object, layer);
1552 if (GES_IS_TIMELINE_FILE_SOURCE (object)) {
1553 GESTimelineFileSource *tfs = GES_TIMELINE_FILE_SOURCE (object);
1554 GESTrackType tfs_supportedformats =
1555 ges_timeline_filesource_get_supported_formats (tfs);
1556 guint64 tfs_maxdur = ges_timeline_filesource_get_max_duration (tfs);
1557 const gchar *tfs_uri;
1559 /* Send the filesource to the discoverer if:
1560 * * it doesn't have specified supported formats
1561 * * OR it doesn't have a specified max-duration
1562 * * OR it doesn't have a valid duration */
1564 if (tfs_supportedformats == GES_TRACK_TYPE_UNKNOWN ||
1565 tfs_maxdur == GST_CLOCK_TIME_NONE || object->duration == 0) {
1566 GST_LOG ("Incomplete TimelineFileSource, discovering it");
1567 tfs_uri = ges_timeline_filesource_get_uri (tfs);
1569 GES_TIMELINE_PENDINGOBJS_LOCK (timeline);
1570 timeline->priv->pendingobjects =
1571 g_list_append (timeline->priv->pendingobjects, object);
1572 GES_TIMELINE_PENDINGOBJS_UNLOCK (timeline);
1574 gst_discoverer_discover_uri_async (timeline->priv->discoverer, tfs_uri);
1576 add_object_to_tracks (timeline, object);
1578 add_object_to_tracks (timeline, object);
1585 layer_priority_changed_cb (GESTimelineLayer * layer,
1586 GParamSpec * arg G_GNUC_UNUSED, GESTimeline * timeline)
1588 timeline->priv->layers = g_list_sort (timeline->priv->layers, (GCompareFunc)
1593 layer_object_removed_cb (GESTimelineLayer * layer, GESTimelineObject * object,
1594 GESTimeline * timeline)
1596 GList *trackobjects, *tmp;
1598 if (ges_timeline_object_is_moving_from_layer (object)) {
1599 GST_DEBUG ("TimelineObject %p is moving from a layer to another, not doing"
1600 " anything on it", object);
1604 GST_DEBUG ("TimelineObject %p removed from layer %p", object, layer);
1606 /* Go over the object's track objects and figure out which one belongs to
1607 * the list of tracks we control */
1609 trackobjects = ges_timeline_object_get_track_objects (object);
1610 for (tmp = trackobjects; tmp; tmp = tmp->next) {
1611 GESTrackObject *trobj = (GESTrackObject *) tmp->data;
1613 GST_DEBUG ("Trying to remove TrackObject %p", trobj);
1614 if (G_LIKELY (g_list_find_custom (timeline->priv->tracks,
1615 ges_track_object_get_track (trobj),
1616 (GCompareFunc) custom_find_track))) {
1617 GST_DEBUG ("Belongs to one of the tracks we control");
1618 ges_track_remove_object (ges_track_object_get_track (trobj), trobj);
1620 ges_timeline_object_release_track_object (object, trobj);
1622 /* removing the reference added by _get_track_objects() */
1623 g_object_unref (trobj);
1626 g_list_free (trackobjects);
1628 /* if the object is a timeline file source that has not yet been discovered,
1629 * it no longer needs to be discovered so remove it from the pendingobjects
1630 * list if it belongs to this layer */
1631 if (GES_IS_TIMELINE_FILE_SOURCE (object)) {
1632 GES_TIMELINE_PENDINGOBJS_LOCK (timeline);
1633 timeline->priv->pendingobjects =
1634 g_list_remove_all (timeline->priv->pendingobjects, object);
1635 GES_TIMELINE_PENDINGOBJS_UNLOCK (timeline);
1642 trackobj_start_changed_cb (GESTrackObject * child,
1643 GParamSpec * arg G_GNUC_UNUSED, GESTimeline * timeline)
1645 sort_track_objects (timeline);
1646 sort_starts_ends_start (timeline, child);
1647 sort_starts_ends_end (timeline, child);
1649 if (!timeline->priv->movecontext.ignore_needs_ctx)
1650 timeline->priv->movecontext.needs_move_ctx = TRUE;
1654 trackobj_duration_changed_cb (GESTrackObject * child,
1655 GParamSpec * arg G_GNUC_UNUSED, GESTimeline * timeline)
1657 sort_starts_ends_end (timeline, child);
1659 if (!timeline->priv->movecontext.ignore_needs_ctx)
1660 timeline->priv->movecontext.needs_move_ctx = TRUE;
1664 trackobj_inpoint_changed_cb (GESTrackObject * child,
1665 GParamSpec * arg G_GNUC_UNUSED, GESTimeline * timeline)
1667 if (!timeline->priv->movecontext.ignore_needs_ctx)
1668 timeline->priv->movecontext.needs_move_ctx = TRUE;
1672 track_object_added_cb (GESTrack * track, GESTrackObject * object,
1673 GESTimeline * timeline)
1675 /* We only work with sources */
1676 if (GES_IS_TRACK_SOURCE (object)) {
1677 start_tracking_track_obj (timeline, object);
1679 g_signal_connect (GES_TRACK_OBJECT (object), "notify::start",
1680 G_CALLBACK (trackobj_start_changed_cb), timeline);
1681 g_signal_connect (GES_TRACK_OBJECT (object), "notify::duration",
1682 G_CALLBACK (trackobj_duration_changed_cb), timeline);
1683 g_signal_connect (GES_TRACK_OBJECT (object), "notify::in-point",
1684 G_CALLBACK (trackobj_inpoint_changed_cb), timeline);
1689 track_object_removed_cb (GESTrack * track, GESTrackObject * object,
1690 GESTimeline * timeline)
1692 /* We only work with sources */
1693 if (GES_IS_TRACK_SOURCE (object)) {
1694 g_signal_handlers_disconnect_by_func (object, trackobj_start_changed_cb,
1696 g_signal_handlers_disconnect_by_func (object, trackobj_duration_changed_cb,
1698 g_signal_handlers_disconnect_by_func (object, trackobj_inpoint_changed_cb,
1701 /* Make sure to reinitialise the moving context next time */
1702 timeline->priv->movecontext.needs_move_ctx = TRUE;
1703 stop_tracking_for_snapping (timeline, object);
1708 track_duration_cb (GstElement * track,
1709 GParamSpec * arg G_GNUC_UNUSED, GESTimeline * timeline)
1711 guint64 duration, max_duration = 0;
1714 for (tmp = timeline->priv->tracks; tmp; tmp = g_list_next (tmp)) {
1715 TrackPrivate *tr_priv = (TrackPrivate *) tmp->data;
1716 g_object_get (tr_priv->track, "duration", &duration, NULL);
1718 GST_DEBUG_OBJECT (track, "track duration : %" GST_TIME_FORMAT,
1719 GST_TIME_ARGS (duration));
1720 max_duration = MAX (duration, max_duration);
1723 if (timeline->priv->duration != max_duration) {
1724 GST_DEBUG ("track duration : %" GST_TIME_FORMAT " current : %"
1725 GST_TIME_FORMAT, GST_TIME_ARGS (max_duration),
1726 GST_TIME_ARGS (timeline->priv->duration));
1728 timeline->priv->duration = max_duration;
1730 #if GLIB_CHECK_VERSION(2,26,0)
1731 g_object_notify_by_pspec (G_OBJECT (timeline), properties[PROP_DURATION]);
1733 g_object_notify (G_OBJECT (timeline), "duration");
1738 static GstStateChangeReturn
1739 ges_timeline_change_state (GstElement * element, GstStateChange transition)
1741 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1742 GESTimeline *timeline = GES_TIMELINE (element);
1744 switch (transition) {
1745 case GST_STATE_CHANGE_READY_TO_PAUSED:
1746 GES_TIMELINE_PENDINGOBJS_LOCK (timeline);
1747 if (timeline->priv->pendingobjects) {
1748 GES_TIMELINE_PENDINGOBJS_UNLOCK (timeline);
1749 do_async_start (timeline);
1750 ret = GST_STATE_CHANGE_ASYNC;
1752 GES_TIMELINE_PENDINGOBJS_UNLOCK (timeline);
1760 GstStateChangeReturn bret;
1762 bret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1763 if (G_UNLIKELY (bret == GST_STATE_CHANGE_NO_PREROLL)) {
1764 do_async_done (timeline);
1769 switch (transition) {
1770 case GST_STATE_CHANGE_PAUSED_TO_READY:
1771 do_async_done (timeline);
1784 * Creates a new empty #GESTimeline.
1786 * Returns: The new timeline.
1790 ges_timeline_new (void)
1792 return g_object_new (GES_TYPE_TIMELINE, NULL);
1796 * ges_timeline_new_from_uri:
1797 * @uri: the URI to load from
1799 * Creates a timeline from the given URI.
1801 * Returns: A new timeline if the uri was loaded successfully, or NULL if the
1802 * uri could not be loaded
1806 ges_timeline_new_from_uri (const gchar * uri)
1810 /* FIXME : we should have a GError** argument so the user can know why
1811 * it wasn't able to load the uri
1814 ret = ges_timeline_new ();
1816 if (!ges_timeline_load_from_uri (ret, uri)) {
1817 g_object_unref (ret);
1826 * ges_timeline_load_from_uri:
1827 * @timeline: an empty #GESTimeline into which to load the formatter
1828 * @uri: The URI to load from
1830 * Loads the contents of URI into the given timeline.
1832 * Returns: TRUE if the timeline was loaded successfully, or FALSE if the uri
1833 * could not be loaded.
1837 ges_timeline_load_from_uri (GESTimeline * timeline, const gchar * uri)
1839 GESFormatter *p = NULL;
1840 gboolean ret = FALSE;
1842 /* FIXME : we should have a GError** argument so the user can know why
1843 * it wasn't able to load the uri
1846 if (!(p = ges_formatter_new_for_uri (uri))) {
1847 GST_ERROR ("unsupported uri '%s'", uri);
1851 if (!ges_formatter_load_from_uri (p, timeline, uri)) {
1852 GST_ERROR ("error deserializing formatter");
1865 * ges_timeline_save_to_uri:
1866 * @timeline: a #GESTimeline
1867 * @uri: The location to save to
1869 * Saves the timeline to the given location
1871 * Returns: TRUE if the timeline was successfully saved to the given location,
1876 ges_timeline_save_to_uri (GESTimeline * timeline, const gchar * uri)
1878 GESFormatter *p = NULL;
1879 gboolean ret = FALSE;
1881 /* FIXME : How will the user be able to chose the format he
1882 * wishes to store to ? */
1884 /* FIXME : How will we ensure a timeline loaded with a certain format
1885 * will be saved with the same one by default ? We need to make this
1886 * easy from an API perspective */
1888 /* FIXME : we should have a GError** argument so the user can know why
1889 * it wasn't able to save
1892 if (!(p = ges_formatter_new_for_uri (uri))) {
1893 GST_ERROR ("unsupported uri '%s'", uri);
1897 if (!ges_formatter_save_to_uri (p, timeline, uri)) {
1898 GST_ERROR ("error serializing formatter");
1911 * ges_timeline_append_layer:
1912 * @timeline: a #GESTimeline
1914 * Append a newly created #GESTimelineLayer to @timeline
1915 * Note that you do not own any reference to the returned layer.
1917 * Returns: (transfer none): The newly created #GESTimelineLayer, or the last (empty)
1918 * #GESTimelineLayer of @timeline.
1921 ges_timeline_append_layer (GESTimeline * timeline)
1924 GESTimelinePrivate *priv = timeline->priv;
1925 GESTimelineLayer *layer;
1927 layer = ges_timeline_layer_new ();
1928 priority = g_list_length (priv->layers);
1929 ges_timeline_layer_set_priority (layer, priority);
1931 ges_timeline_add_layer (timeline, layer);
1937 * ges_timeline_add_layer:
1938 * @timeline: a #GESTimeline
1939 * @layer: the #GESTimelineLayer to add
1941 * Add the layer to the timeline. The reference to the @layer will be stolen
1944 * Returns: TRUE if the layer was properly added, else FALSE.
1947 ges_timeline_add_layer (GESTimeline * timeline, GESTimelineLayer * layer)
1949 GList *objects, *tmp;
1950 GESTimelinePrivate *priv = timeline->priv;
1952 GST_DEBUG ("timeline:%p, layer:%p", timeline, layer);
1954 /* We can only add a layer that doesn't already belong to another timeline */
1955 if (G_UNLIKELY (layer->timeline)) {
1956 GST_WARNING ("Layer belongs to another timeline, can't add it");
1960 /* Add to the list of layers, make sure we don't already control it */
1961 if (G_UNLIKELY (g_list_find (priv->layers, (gconstpointer) layer))) {
1962 GST_WARNING ("Layer is already controlled by this timeline");
1966 g_object_ref_sink (layer);
1967 priv->layers = g_list_insert_sorted (priv->layers, layer,
1968 (GCompareFunc) sort_layers);
1970 /* Inform the layer that it belongs to a new timeline */
1971 ges_timeline_layer_set_timeline (layer, timeline);
1973 /* Connect to 'object-added'/'object-removed' signal from the new layer */
1974 g_signal_connect (layer, "object-added", G_CALLBACK (layer_object_added_cb),
1976 g_signal_connect (layer, "object-removed",
1977 G_CALLBACK (layer_object_removed_cb), timeline);
1978 g_signal_connect (layer, "notify::priority",
1979 G_CALLBACK (layer_priority_changed_cb), timeline);
1981 GST_DEBUG ("Done adding layer, emitting 'layer-added' signal");
1982 g_signal_emit (timeline, ges_timeline_signals[LAYER_ADDED], 0, layer);
1984 /* add any existing timeline objects to the timeline */
1985 objects = ges_timeline_layer_get_objects (layer);
1986 for (tmp = objects; tmp; tmp = tmp->next) {
1987 layer_object_added_cb (layer, tmp->data, timeline);
1988 g_object_unref (tmp->data);
1991 g_list_free (objects);
1997 * ges_timeline_remove_layer:
1998 * @timeline: a #GESTimeline
1999 * @layer: the #GESTimelineLayer to remove
2001 * Removes the layer from the timeline. The reference that the @timeline holds on
2002 * the layer will be dropped. If you wish to use the @layer after calling this
2003 * method, you need to take a reference before calling.
2005 * Returns: TRUE if the layer was properly removed, else FALSE.
2009 ges_timeline_remove_layer (GESTimeline * timeline, GESTimelineLayer * layer)
2011 GList *layer_objects, *tmp;
2012 GESTimelinePrivate *priv = timeline->priv;
2014 GST_DEBUG ("timeline:%p, layer:%p", timeline, layer);
2016 if (G_UNLIKELY (!g_list_find (priv->layers, layer))) {
2017 GST_WARNING ("Layer doesn't belong to this timeline");
2021 /* remove objects from any private data structures */
2023 layer_objects = ges_timeline_layer_get_objects (layer);
2024 for (tmp = layer_objects; tmp; tmp = tmp->next) {
2025 layer_object_removed_cb (layer, GES_TIMELINE_OBJECT (tmp->data), timeline);
2026 g_object_unref (G_OBJECT (tmp->data));
2029 g_list_free (layer_objects);
2031 /* Disconnect signals */
2032 GST_DEBUG ("Disconnecting signal callbacks");
2033 g_signal_handlers_disconnect_by_func (layer, layer_object_added_cb, timeline);
2034 g_signal_handlers_disconnect_by_func (layer, layer_object_removed_cb,
2037 priv->layers = g_list_remove (priv->layers, layer);
2039 ges_timeline_layer_set_timeline (layer, NULL);
2041 g_signal_emit (timeline, ges_timeline_signals[LAYER_REMOVED], 0, layer);
2043 g_object_unref (layer);
2049 pad_added_cb (GESTrack * track, GstPad * pad, TrackPrivate * tr_priv)
2055 GST_DEBUG ("track:%p, pad:%s:%s", track, GST_DEBUG_PAD_NAME (pad));
2057 if (G_UNLIKELY (tr_priv->pad)) {
2058 GST_WARNING ("We are already controlling a pad for this track");
2062 /* Remember the pad */
2063 GST_OBJECT_LOCK (track);
2067 for (tmp = tr_priv->timeline->priv->tracks; tmp; tmp = g_list_next (tmp)) {
2068 TrackPrivate *tr_priv = (TrackPrivate *) tmp->data;
2070 if (!tr_priv->pad) {
2071 GST_LOG ("Found track without pad %p", tr_priv->track);
2075 GST_OBJECT_UNLOCK (track);
2078 GST_DEBUG ("Ghosting pad and adding it to ourself");
2079 padname = g_strdup_printf ("track_%p_src", track);
2080 tr_priv->ghostpad = gst_ghost_pad_new (padname, pad);
2082 gst_pad_set_active (tr_priv->ghostpad, TRUE);
2083 gst_element_add_pad (GST_ELEMENT (tr_priv->timeline), tr_priv->ghostpad);
2086 GST_DEBUG ("Signaling no-more-pads");
2087 gst_element_no_more_pads (GST_ELEMENT (tr_priv->timeline));
2092 pad_removed_cb (GESTrack * track, GstPad * pad, TrackPrivate * tr_priv)
2094 GST_DEBUG ("track:%p, pad:%s:%s", track, GST_DEBUG_PAD_NAME (pad));
2096 if (G_UNLIKELY (tr_priv->pad != pad)) {
2097 GST_WARNING ("Not the pad we're controlling");
2101 if (G_UNLIKELY (tr_priv->ghostpad == NULL)) {
2102 GST_WARNING ("We don't have a ghostpad for this pad !");
2106 GST_DEBUG ("Removing ghostpad");
2107 gst_pad_set_active (tr_priv->ghostpad, FALSE);
2108 gst_element_remove_pad (GST_ELEMENT (tr_priv->timeline), tr_priv->ghostpad);
2109 tr_priv->ghostpad = NULL;
2110 tr_priv->pad = NULL;
2114 * ges_timeline_add_track:
2115 * @timeline: a #GESTimeline
2116 * @track: the #GESTrack to add
2118 * Add a track to the timeline. The reference to the track will be stolen by the
2121 * Returns: TRUE if the track was properly added, else FALSE.
2124 /* FIXME: create track objects for timeline objects which have already been
2125 * added to existing layers.
2129 ges_timeline_add_track (GESTimeline * timeline, GESTrack * track)
2131 TrackPrivate *tr_priv;
2132 GESTimelinePrivate *priv = timeline->priv;
2135 GST_DEBUG ("timeline:%p, track:%p", timeline, track);
2137 /* make sure we don't already control it */
2138 if (G_UNLIKELY (g_list_find_custom (priv->tracks, (gconstpointer) track,
2139 (GCompareFunc) custom_find_track))) {
2140 GST_WARNING ("Track is already controlled by this timeline");
2144 /* Add the track to ourself (as a GstBin)
2145 * Reference is stolen ! */
2146 if (G_UNLIKELY (!gst_bin_add (GST_BIN (timeline), GST_ELEMENT (track)))) {
2147 GST_WARNING ("Couldn't add track to ourself (GST)");
2151 tr_priv = g_new0 (TrackPrivate, 1);
2152 tr_priv->timeline = timeline;
2153 tr_priv->track = track;
2155 /* Add the track to the list of tracks we track */
2156 priv->tracks = g_list_append (priv->tracks, tr_priv);
2158 /* Listen to pad-added/-removed */
2159 g_signal_connect (track, "pad-added", (GCallback) pad_added_cb, tr_priv);
2160 g_signal_connect (track, "pad-removed", (GCallback) pad_removed_cb, tr_priv);
2162 /* Inform the track that it's currently being used by ourself */
2163 ges_track_set_timeline (track, timeline);
2165 GST_DEBUG ("Done adding track, emitting 'track-added' signal");
2167 /* emit 'track-added' */
2168 g_signal_emit (timeline, ges_timeline_signals[TRACK_ADDED], 0, track);
2170 /* ensure that each existing timeline object has the opportunity to create a
2171 * track object for this track*/
2173 /* We connect to the duration change notify, so we can update
2174 * our duration accordingly */
2175 g_signal_connect (G_OBJECT (track), "notify::duration",
2176 G_CALLBACK (track_duration_cb), timeline);
2178 /* We connect to the object for the timeline editing mode management */
2179 g_signal_connect (G_OBJECT (track), "track-object-added",
2180 G_CALLBACK (track_object_added_cb), timeline);
2181 g_signal_connect (G_OBJECT (track), "track-object-removed",
2182 G_CALLBACK (track_object_removed_cb), timeline);
2184 for (tmp = priv->layers; tmp; tmp = tmp->next) {
2185 GList *objects, *obj;
2186 objects = ges_timeline_layer_get_objects (tmp->data);
2188 for (obj = objects; obj; obj = obj->next) {
2189 add_object_to_track (obj->data, track);
2190 g_object_unref (obj->data);
2193 g_list_free (objects);
2196 track_duration_cb (GST_ELEMENT (track), NULL, timeline);
2202 * ges_timeline_remove_track:
2203 * @timeline: a #GESTimeline
2204 * @track: the #GESTrack to remove
2206 * Remove the @track from the @timeline. The reference stolen when adding the
2207 * @track will be removed. If you wish to use the @track after calling this
2208 * function you must ensure that you have a reference to it.
2210 * Returns: TRUE if the @track was properly removed, else FALSE.
2213 /* FIXME: release any track objects associated with this layer. currenly this
2214 * will not happen if you remove the track before removing *all*
2215 * timelineobjects which have a track object in this track.
2219 ges_timeline_remove_track (GESTimeline * timeline, GESTrack * track)
2222 TrackPrivate *tr_priv;
2223 GESTimelinePrivate *priv = timeline->priv;
2225 GST_DEBUG ("timeline:%p, track:%p", timeline, track);
2227 if (G_UNLIKELY (!(tmp =
2228 g_list_find_custom (priv->tracks, (gconstpointer) track,
2229 (GCompareFunc) custom_find_track)))) {
2230 GST_WARNING ("Track doesn't belong to this timeline");
2234 tr_priv = tmp->data;
2235 priv->tracks = g_list_remove (priv->tracks, tr_priv);
2237 ges_track_set_timeline (track, NULL);
2239 /* Remove ghost pad */
2240 if (tr_priv->ghostpad) {
2241 GST_DEBUG ("Removing ghostpad");
2242 gst_pad_set_active (tr_priv->ghostpad, FALSE);
2243 gst_ghost_pad_set_target ((GstGhostPad *) tr_priv->ghostpad, NULL);
2244 gst_element_remove_pad (GST_ELEMENT (timeline), tr_priv->ghostpad);
2247 /* Remove pad-added/-removed handlers */
2248 g_signal_handlers_disconnect_by_func (track, pad_added_cb, tr_priv);
2249 g_signal_handlers_disconnect_by_func (track, pad_removed_cb, tr_priv);
2250 g_signal_handlers_disconnect_by_func (track, track_duration_cb,
2252 g_signal_handlers_disconnect_by_func (track, track_object_added_cb, timeline);
2253 g_signal_handlers_disconnect_by_func (track, track_object_removed_cb,
2256 /* Signal track removal to all layers/objects */
2257 g_signal_emit (timeline, ges_timeline_signals[TRACK_REMOVED], 0, track);
2259 /* remove track from our bin */
2260 gst_object_ref (track);
2261 if (G_UNLIKELY (!gst_bin_remove (GST_BIN (timeline), GST_ELEMENT (track)))) {
2262 GST_WARNING ("Couldn't remove track to ourself (GST)");
2263 gst_object_unref (track);
2267 /* set track state to NULL */
2269 gst_element_set_state (GST_ELEMENT (track), GST_STATE_NULL);
2271 gst_object_unref (track);
2279 * ges_timeline_get_track_for_pad:
2280 * @timeline: The #GESTimeline
2283 * Search the #GESTrack corresponding to the given @timeline's @pad.
2285 * Returns: (transfer none): The corresponding #GESTrack if it is found,
2286 * or %NULL if there is an error.
2290 ges_timeline_get_track_for_pad (GESTimeline * timeline, GstPad * pad)
2294 for (tmp = timeline->priv->tracks; tmp; tmp = g_list_next (tmp)) {
2295 TrackPrivate *tr_priv = (TrackPrivate *) tmp->data;
2296 if (pad == tr_priv->ghostpad)
2297 return tr_priv->track;
2304 * ges_timeline_get_tracks:
2305 * @timeline: a #GESTimeline
2307 * Returns the list of #GESTrack used by the Timeline.
2309 * Returns: (transfer full) (element-type GESTrack): A list of #GESTrack.
2310 * The caller should unref each track once he is done with them.
2313 ges_timeline_get_tracks (GESTimeline * timeline)
2315 GList *tmp, *res = NULL;
2317 for (tmp = timeline->priv->tracks; tmp; tmp = g_list_next (tmp)) {
2318 TrackPrivate *tr_priv = (TrackPrivate *) tmp->data;
2319 res = g_list_append (res, g_object_ref (tr_priv->track));
2326 * ges_timeline_get_layers:
2327 * @timeline: a #GESTimeline
2329 * Get the list of #GESTimelineLayer present in the Timeline.
2331 * Returns: (transfer full) (element-type GESTimelineLayer): the list of
2332 * #GESTimelineLayer present in the Timeline sorted by priority.
2333 * The caller should unref each Layer once he is done with them.
2336 ges_timeline_get_layers (GESTimeline * timeline)
2338 GList *tmp, *res = NULL;
2340 for (tmp = timeline->priv->layers; tmp; tmp = g_list_next (tmp)) {
2341 res = g_list_insert_sorted (res, g_object_ref (tmp->data),
2342 (GCompareFunc) sort_layers);
2349 * ges_timeline_is_updating:
2350 * @timeline: a #GESTimeline
2352 * Get whether the timeline is updated for every change happening within or not.
2354 * Returns: %TRUE if @timeline is updating on every changes, else %FALSE.
2357 ges_timeline_is_updating (GESTimeline * timeline)
2361 g_return_val_if_fail (GES_IS_TIMELINE (timeline), FALSE);
2363 for (tmp = timeline->priv->tracks; tmp; tmp = tmp->next) {
2364 if (!ges_track_is_updating (((TrackPrivate *) tmp->data)->track))
2372 * ges_timeline_enable_update:
2373 * @timeline: a #GESTimeline
2374 * @enabled: Whether the timeline should update on every change or not.
2376 * Control whether the timeline is updated for every change happening within.
2378 * Users will want to use this method with %FALSE before doing lots of changes,
2379 * and then call again with %TRUE for the changes to take effect in one go.
2381 * Returns: %TRUE if the update status could be changed, else %FALSE.
2384 ges_timeline_enable_update (GESTimeline * timeline, gboolean enabled)
2387 gboolean res = TRUE;
2389 GST_DEBUG_OBJECT (timeline, "%s updates", enabled ? "Enabling" : "Disabling");
2391 for (tmp = timeline->priv->tracks; tmp; tmp = tmp->next) {
2392 if (!ges_track_enable_update (((TrackPrivate *) tmp->data)->track, enabled))
2396 /* Make sure we reset the context */
2397 timeline->priv->movecontext.needs_move_ctx = TRUE;