clip: Allow setting max-duration clips without TrackElements
authorThibault Saunier <tsaunier@igalia.com>
Wed, 18 Mar 2020 16:36:47 +0000 (13:36 -0300)
committerThibault Saunier <tsaunier@igalia.com>
Thu, 19 Mar 2020 00:58:11 +0000 (21:58 -0300)
Otherwise this breaks quite a few assumption in user code, several
pitivi tests broke because of that.

ges/ges-clip.c
ges/ges-uri-clip.c
tests/check/assets/30frames.ogv [deleted file]
tests/check/ges/clip.c
tests/check/python/test_clip.py

index 3599022aa9950ebf0419beba74a2871ebd4d4f9d..01e8d32a5bf2b928aa27c3ef3f830db408378b80 100644 (file)
@@ -395,6 +395,16 @@ _set_max_duration (GESTimelineElement * element, GstClockTime maxduration)
   if (priv->updating_max_duration)
     return TRUE;
 
+  if (!GES_CONTAINER_CHILDREN (element)) {
+    /* If any child added later on has a lower max duration, this max duration
+     * will be used instead anyway */
+    GST_INFO_OBJECT (element,
+        "Setting max duration %" GST_TIME_FORMAT " as %" GES_FORMAT
+        " doesn't have any child yet",
+        GST_TIME_ARGS (maxduration), GES_ARGS (element));
+    return TRUE;
+  }
+
   /* else, we set every core child to have the same max duration */
 
   priv->prevent_max_duration_update = TRUE;
index de704d8c201239f652f76d1664c1b3ee28554adf..9344fa69426c9a9acb8a846a81b2056c9538710f 100644 (file)
@@ -362,6 +362,10 @@ extractable_set_asset (GESExtractable * self, GESAsset * asset)
     uriclip->priv->uri = g_strdup (ges_asset_get_id (asset));
   }
 
+  if (!GES_CONTAINER_CHILDREN (uriclip))
+    ges_timeline_element_set_max_duration (GES_TIMELINE_ELEMENT (uriclip),
+        ges_uri_clip_asset_get_max_duration (uri_clip_asset));
+
   return res;
 }
 
diff --git a/tests/check/assets/30frames.ogv b/tests/check/assets/30frames.ogv
deleted file mode 100644 (file)
index c6eef47..0000000
Binary files a/tests/check/assets/30frames.ogv and /dev/null differ
index f64be618e6a5d8d30fa883a850159855d7f0a884..fbd4772f6d742a01603179618fec5c715cb8a449 100644 (file)
@@ -1047,11 +1047,19 @@ GST_START_TEST (test_children_max_duration)
   GESTimeline *timeline;
   GESLayer *layer;
   gchar *uri;
-  GESTimelineElement *clips[] = { NULL, NULL };
   GESTimelineElement *child0, *child1, *effect;
   guint i;
   GstClockTime max_duration, new_max;
   GList *children;
+  struct
+  {
+    GESTimelineElement *clip;
+    GstClockTime max_duration;
+  } clips[] = {
+    {
+    NULL, GST_SECOND}, {
+    NULL, GST_CLOCK_TIME_NONE}
+  };
 
   ges_init ();
 
@@ -1061,23 +1069,24 @@ GST_START_TEST (test_children_max_duration)
   layer = ges_timeline_append_layer (timeline);
 
   uri = ges_test_get_audio_video_uri ();
-  clips[0] = GES_TIMELINE_ELEMENT (ges_uri_clip_new (uri));
-  fail_unless (clips[0]);
+  clips[0].clip = GES_TIMELINE_ELEMENT (ges_uri_clip_new (uri));
+  fail_unless (clips[0].clip);
   g_free (uri);
 
-  clips[1] = GES_TIMELINE_ELEMENT (ges_test_clip_new ());
+  clips[1].clip = GES_TIMELINE_ELEMENT (ges_test_clip_new ());
 
   for (i = 0; i < G_N_ELEMENTS (clips); i++) {
-    GESTimelineElement *clip = clips[i];
-    fail_unless (_MAX_DURATION (clip) == GST_CLOCK_TIME_NONE);
+    GESTimelineElement *clip = clips[i].clip;
 
+    max_duration = clips[i].max_duration;
+    fail_unless_equals_uint64 (_MAX_DURATION (clip), max_duration);
     fail_unless (ges_timeline_element_set_start (clip, 5));
     fail_unless (ges_timeline_element_set_duration (clip, 20));
     fail_unless (ges_timeline_element_set_inpoint (clip, 30));
-    /* can not set the max duration when we have no children */
-    fail_if (ges_timeline_element_set_max_duration (clip, 150));
+    /* can not the max duration the clip has no child */
+    fail_unless (ges_timeline_element_set_max_duration (clip, 150));
 
-    CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, GST_CLOCK_TIME_NONE);
+    CHECK_OBJECT_PROPS_MAX (clip, 5, 30, 20, 150);
 
     fail_unless (ges_layer_add_clip (layer, GES_CLIP (clip)));
 
@@ -1094,17 +1103,11 @@ GST_START_TEST (test_children_max_duration)
     fail_unless (ges_track_element_has_internal_source (GES_TRACK_ELEMENT
             (child1)));
 
-    if (GES_IS_URI_CLIP (clip)) {
-      /* uri clip children should be created with a max-duration set */
-      /* each created child has the same max-duration */
-      max_duration = _MAX_DURATION (child0);
-      fail_unless (max_duration != GST_CLOCK_TIME_NONE);
+    if (GES_IS_URI_CLIP (clip))
       new_max = max_duration;
-    } else {
-      max_duration = GST_CLOCK_TIME_NONE;
+    else
       /* need a valid clock time that is not too large */
       new_max = 500;
-    }
 
     /* added children do not change the clip's max-duration, but will
      * instead set it to the minimum value of its children */
index 7aed040bfa7ce289332c0524b44d7dd351697b5f..31076fc281cc6095f7360ac6f4d7b4ea90c7e37e 100644 (file)
@@ -19,6 +19,7 @@
 
 from . import overrides_hack
 
+import os
 import tempfile
 
 import gi
@@ -143,6 +144,15 @@ class TestTitleClip(unittest.TestCase):
                             children2[1].props.priority)
 
 
+class TestUriClip(common.GESSimpleTimelineTest):
+    def test_max_duration_on_extract(self):
+        uri = Gst.filename_to_uri(os.path.join(__file__, "../../ges/audio_video.ogg"))
+        asset = GES.UriClipAsset.request_sync(uri)
+        clip = asset.extract()
+
+        self.assertEqual(clip.props.max_duration, Gst.SECOND)
+
+
 class TestTrackElements(common.GESSimpleTimelineTest):
 
     def test_add_to_layer_with_effect_remove_add(self):