group: Update priority when a child is removed
authorThibault Saunier <tsaunier@igalia.com>
Wed, 4 Mar 2020 20:42:46 +0000 (17:42 -0300)
committerThibault Saunier <tsaunier@igalia.com>
Fri, 6 Mar 2020 18:18:28 +0000 (18:18 +0000)
Fixes https://gitlab.freedesktop.org/gstreamer/gst-editing-services/issues/93

ges/ges-group.c
tests/check/python/common.py
tests/check/python/test_group.py

index b14da0e1ebbcdc43775f90cba8ad5da2e1c36009..c96f36b3d840b01b035f7bc7ee2433f6b041e79a 100644 (file)
@@ -565,10 +565,11 @@ _disconnect_signals (GESGroup * group, GESTimelineElement * child,
 static void
 _child_removed (GESContainer * group, GESTimelineElement * child)
 {
-  GList *children;
+  GList *children, *tmp;
   GstClockTime first_child_start;
   gchar *signals_ids_key;
   ChildSignalIds *sigids;
+  guint32 new_priority = G_MAXUINT32;
   GESGroupPrivate *priv = GES_GROUP (group)->priv;
 
   _ges_container_sort_children (group);
@@ -588,8 +589,15 @@ _child_removed (GESContainer * group, GESTimelineElement * child)
     return;
   }
 
+  for (tmp = children; tmp; tmp = tmp->next)
+    new_priority =
+        MIN (new_priority, ges_timeline_element_get_priority (tmp->data));
+
   priv->setting_value = TRUE;
   ELEMENT_SET_FLAG (group, GES_TIMELINE_ELEMENT_SET_SIMPLE);
+  if (_PRIORITY (group) != new_priority)
+    ges_timeline_element_set_priority (GES_TIMELINE_ELEMENT (group),
+        new_priority);
   first_child_start = GES_TIMELINE_ELEMENT_START (children->data);
   if (first_child_start > GES_TIMELINE_ELEMENT_START (group)) {
     group->children_control_mode = GES_CHILDREN_IGNORE_NOTIFIES;
index 7bf43913b14f0c00158a5a317f079490b09a7f8d..81a439c6c4a51f2462f5b9cdaabad9ffde3c1a7e 100644 (file)
@@ -198,6 +198,8 @@ class GESSimpleTimelineTest(GESTest):
         return clip
 
     def append_clip(self, layer=0):
+        while len(self.timeline.get_layers()) < layer + 1:
+            self.timeline.append_layer()
         layer = self.timeline.get_layers()[layer]
         clip = GES.TestClip()
         clip.props.start = layer.get_duration()
index eb5a874e6830982e94b764c7bb8e8a50a58b63f4..ab026eb631bc97f542ceabd980d61a0031505509 100644 (file)
@@ -358,4 +358,50 @@ class TestGroup(common.GESSimpleTimelineTest):
                 (GES.TestClip, 20, 10),
                 (GES.TestClip, 30, 10),
             ],
-        ], groups=[group_clips])
\ No newline at end of file
+        ], groups=[group_clips])
+
+    def test_group_priority(self):
+        self.track_types = [GES.TrackType.AUDIO]
+        self.setUp()
+
+        clip0 = self.append_clip()
+        clip1 = self.append_clip(1)
+        clip1.props.start = 20
+
+        group = GES.Group.new()
+        group.add(clip0)
+        group.add(clip1)
+        self.assertEqual(group.get_layer_priority(), 0)
+        self.assertTimelineTopology([
+            [
+                (GES.TestClip, 0, 10),
+            ],
+            [
+                (GES.TestClip, 20, 10),
+            ]
+        ], groups=[(clip0, clip1)])
+        group.remove(clip0)
+        self.assertEqual(group.get_layer_priority(), 1)
+
+        clip1.edit(self.timeline.get_layers(), 2, GES.EditMode.EDIT_NORMAL, GES.Edge.EDGE_NONE, clip1.start)
+        self.assertTimelineTopology([
+            [
+                (GES.TestClip, 0, 10),
+            ],
+            [ ],
+            [
+                (GES.TestClip, 20, 10),
+            ]
+        ], groups=[(clip1,)])
+
+        self.assertEqual(group.get_layer_priority(), 2)
+        self.assertTrue(clip1.edit(self.timeline.get_layers(), 0, GES.EditMode.EDIT_NORMAL, GES.Edge.EDGE_NONE, clip1.start))
+
+        self.assertTimelineTopology([
+            [
+                (GES.TestClip, 0, 10),
+                (GES.TestClip, 20, 10),
+            ],
+            [ ],
+            [ ]
+        ], groups=[(clip1,)])