timelineelement: Make sure that we will never set a negative start
authorThibault Saunier <thibault.saunier@collabora.com>
Thu, 11 Jul 2013 03:15:17 +0000 (23:15 -0400)
committerThibault Saunier <thibault.saunier@collabora.com>
Thu, 11 Jul 2013 03:17:54 +0000 (23:17 -0400)
Currently we can end up overflowing the start of others child of our
parent, avoid that making sure we can set our start to what was
requested by the user before actually doing it

+ Add a test

ges/ges-timeline-element.c
tests/check/ges/group.c

index 744abf9..67108d1 100644 (file)
@@ -378,6 +378,7 @@ void
 ges_timeline_element_set_start (GESTimelineElement * self, GstClockTime start)
 {
   GESTimelineElementClass *klass;
+  GESTimelineElement *toplevel_container;
 
   g_return_if_fail (GES_IS_TIMELINE_ELEMENT (self));
 
@@ -387,6 +388,17 @@ ges_timeline_element_set_start (GESTimelineElement * self, GstClockTime start)
       " new start: %" GST_TIME_FORMAT,
       GST_TIME_ARGS (GES_TIMELINE_ELEMENT_START (self)), GST_TIME_ARGS (start));
 
+  toplevel_container = ges_timeline_element_get_toplevel_parent (self);
+
+  if (((gint64) (_START (toplevel_container) + start - _START (self))) < 0) {
+    GST_INFO_OBJECT (self, "Can not move the object as it would imply its"
+        "container to have a negative start value");
+
+    gst_object_unref (toplevel_container);
+    return;
+  }
+
+  gst_object_unref (toplevel_container);
   if (klass->set_start) {
     if (klass->set_start (self, start)) {
       self->start = start;
index 5644b23..e60b61e 100644 (file)
@@ -69,6 +69,10 @@ GST_START_TEST (test_move_group)
   ASSERT_OBJECT_REFCOUNT (group, "1 ref for the timeline", 1);
   fail_unless (g_list_length (GES_CONTAINER_CHILDREN (group)) == 3);
   assert_equals_int (GES_CONTAINER_HEIGHT (group), 2);
+
+  /* Nothing should move */
+  ges_timeline_element_set_start (GES_TIMELINE_ELEMENT (clip1), 5);
+
   CHECK_OBJECT_PROPS (clip, 0, 0, 10);
   CHECK_OBJECT_PROPS (clip1, 10, 0, 10);
   CHECK_OBJECT_PROPS (clip2, 50, 0, 60);