clip: Allow setting max-duration clips without TrackElements

Otherwise this breaks quite a few assumption in user code, several
pitivi tests broke because of that.
This commit is contained in:
Thibault Saunier 2020-03-18 13:36:47 -03:00
parent fc0333922f
commit 314db9f1bd
5 changed files with 44 additions and 17 deletions

View 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;

View 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;
}

Binary file not shown.

View 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 */

View 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):