layer: Handle operation priorities
authorThibault Saunier <tsaunier@gnome.org>
Thu, 11 Aug 2016 14:36:44 +0000 (10:36 -0400)
committerThibault Saunier <thibault.saunier@osg.samsung.com>
Mon, 26 Sep 2016 16:32:57 +0000 (13:32 -0300)
All operations should have higher priorites and sources should be
on top of those. We now first set the operations priorities in
a first pass and then stack sources on top of those.

Differential Revision: https://phabricator.freedesktop.org/D1279

ges/ges-layer.c

index 8160294..f7e9844 100644 (file)
@@ -218,36 +218,28 @@ ges_layer_init (GESLayer * self)
   _register_metas (self);
 }
 
-/**
- * ges_layer_resync_priorities:
- * @layer: a #GESLayer
- *
- * Resyncs the priorities of the clips controlled by @layer.
- * This method
- */
-gboolean
-ges_layer_resync_priorities (GESLayer * layer)
+static gint
+ges_layer_resync_priorities_by_type (GESLayer * layer,
+    gint starting_priority, GType type)
 {
   GstClockTime next_reset = 0;
-  gint priority = 1;
+  gint priority = starting_priority, max_priority = priority;
   GList *tmp;
   GESTimelineElement *element;
 
-  GST_INFO_OBJECT (layer, "Resync priorities (prio: %d)",
-      layer->priv->priority);
-
   for (tmp = layer->priv->clips_start; tmp; tmp = tmp->next) {
 
     element = GES_TIMELINE_ELEMENT (tmp->data);
 
     if (GES_IS_TRANSITION_CLIP (element)) {
+      /* Blindly set transitions priorities to 0 */
       _set_priority0 (element, 0);
-
       continue;
-    }
+    } else if (!g_type_is_a (G_OBJECT_TYPE (element), type))
+      continue;
 
     if (element->start > next_reset) {
-      priority = 1;
+      priority = starting_priority;
       next_reset = 0;
     }
 
@@ -256,8 +248,34 @@ ges_layer_resync_priorities (GESLayer * layer)
 
     _set_priority0 (element, priority);
     priority = priority + GES_CONTAINER_HEIGHT (element);
+
+    if (priority > max_priority)
+      max_priority = priority;
   }
 
+  return max_priority;
+}
+
+/**
+ * ges_layer_resync_priorities:
+ * @layer: a #GESLayer
+ *
+ * Resyncs the priorities of the clips controlled by @layer.
+ */
+gboolean
+ges_layer_resync_priorities (GESLayer * layer)
+{
+  gint min_source_prios;
+
+  GST_INFO_OBJECT (layer, "Resync priorities (prio: %d)",
+      layer->priv->priority);
+
+  min_source_prios = ges_layer_resync_priorities_by_type (layer, 1,
+      GES_TYPE_OPERATION_CLIP);
+
+  ges_layer_resync_priorities_by_type (layer, min_source_prios,
+      GES_TYPE_SOURCE_CLIP);
+
   return TRUE;
 }
 
@@ -398,6 +416,7 @@ ges_layer_set_priority (GESLayer * layer, guint priority)
     layer->priv->priority = priority;
     layer->min_nle_priority = (priority * LAYER_HEIGHT) + MIN_NLE_PRIO;
     layer->max_nle_priority = ((priority + 1) * LAYER_HEIGHT) + MIN_NLE_PRIO;
+
     ges_layer_resync_priorities (layer);
   }
 
@@ -530,7 +549,7 @@ ges_layer_add_clip (GESLayer * layer, GESClip * clip)
   g_return_val_if_fail (GES_IS_LAYER (layer), FALSE);
   g_return_val_if_fail (GES_IS_CLIP (clip), FALSE);
 
-  GST_DEBUG_OBJECT (layer, "adding clip: %s", GES_TIMELINE_ELEMENT_NAME (clip));
+  GST_DEBUG_OBJECT (layer, "adding clip:%p", clip);
 
   priv = layer->priv;
   current_layer = ges_clip_get_layer (clip);