gst-editing-services: ges: Keep layers sorted by priorities in the timeline

Thibault Saunier tsaunier at kemper.freedesktop.org
Wed Jan 11 07:04:29 PST 2012


Module: gst-editing-services
Branch: master
Commit: 2bbcbab17439756e8ea9665006e6093fe416d824
URL:    http://cgit.freedesktop.org/gstreamer/gst-editing-services/commit/?id=2bbcbab17439756e8ea9665006e6093fe416d824

Author: Thibault Saunier <thibault.saunier at collabora.com>
Date:   Thu Jun  2 22:03:19 2011 -0400

ges: Keep layers sorted by priorities in the timeline

---

 ges/ges-timeline.c |   37 ++++++++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/ges/ges-timeline.c b/ges/ges-timeline.c
index c04185a..ea88390 100644
--- a/ges/ges-timeline.c
+++ b/ges/ges-timeline.c
@@ -246,6 +246,26 @@ ges_timeline_init (GESTimeline * self)
   gst_discoverer_start (self->priv->discoverer);
 }
 
+static gint
+sort_layers (gpointer a, gpointer b)
+{
+  GESTimelineLayer *layer_a, *layer_b;
+  guint prio_a, prio_b;
+
+  layer_a = GES_TIMELINE_LAYER (a);
+  layer_b = GES_TIMELINE_LAYER (b);
+
+  prio_a = ges_timeline_layer_get_priority (layer_a);
+  prio_b = ges_timeline_layer_get_priority (layer_b);
+
+  if ((gint) prio_a > (guint) prio_b)
+    return 1;
+  if ((guint) prio_a < (guint) prio_b)
+    return -1;
+
+  return 0;
+}
+
 /**
  * ges_timeline_new:
  *
@@ -613,6 +633,13 @@ layer_object_added_cb (GESTimelineLayer * layer, GESTimelineObject * object,
   GST_DEBUG ("done");
 }
 
+static void
+layer_priority_changed_cb (GESTimelineLayer * layer,
+    GParamSpec * arg G_GNUC_UNUSED, GESTimeline * timeline)
+{
+  timeline->priv->layers = g_list_sort (timeline->priv->layers, (GCompareFunc)
+      sort_layers);
+}
 
 static void
 layer_object_removed_cb (GESTimelineLayer * layer, GESTimelineObject * object,
@@ -688,7 +715,8 @@ ges_timeline_add_layer (GESTimeline * timeline, GESTimelineLayer * layer)
   }
 
   g_object_ref_sink (layer);
-  priv->layers = g_list_append (priv->layers, layer);
+  priv->layers = g_list_insert_sorted (priv->layers, layer,
+      (GCompareFunc) sort_layers);
 
   /* Inform the layer that it belongs to a new timeline */
   ges_timeline_layer_set_timeline (layer, timeline);
@@ -698,6 +726,8 @@ ges_timeline_add_layer (GESTimeline * timeline, GESTimelineLayer * layer)
       timeline);
   g_signal_connect (layer, "object-removed",
       G_CALLBACK (layer_object_removed_cb), timeline);
+  g_signal_connect (layer, "notify::priority",
+      G_CALLBACK (layer_priority_changed_cb), timeline);
 
   GST_DEBUG ("Done adding layer, emitting 'layer-added' signal");
   g_signal_emit (timeline, ges_timeline_signals[LAYER_ADDED], 0, layer);
@@ -1022,7 +1052,7 @@ ges_timeline_get_tracks (GESTimeline * timeline)
  * Get the list of #GESTimelineLayer present in the Timeline.
  *
  * Returns: (transfer full) (element-type GESTimelineLayer): the list of
- * #GESTimelineLayer present in the Timeline.
+ * #GESTimelineLayer present in the Timeline sorted by priority.
  * The caller should unref each Layer once he is done with them.
  */
 GList *
@@ -1031,7 +1061,8 @@ ges_timeline_get_layers (GESTimeline * timeline)
   GList *tmp, *res = NULL;
 
   for (tmp = timeline->priv->layers; tmp; tmp = g_list_next (tmp)) {
-    res = g_list_append (res, g_object_ref (tmp->data));
+    res = g_list_insert_sorted (res, g_object_ref (tmp->data),
+        (GCompareFunc) sort_layers);
   }
 
   return res;



More information about the gstreamer-commits mailing list