From f8334dba247334d4a37d545b7f0cae56536a45ae Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Mon, 18 Mar 2013 10:02:10 -0300 Subject: [PATCH] clip: Make it mandatory that a clip is in a layer to be splittable Otherwize we will not be able to describe if the returned object has a floating reference or not, and this would screw the introspection. --- ges/ges-clip.c | 18 +++++++++------- tests/check/ges/clip.c | 57 +++++++++++++++++++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/ges/ges-clip.c b/ges/ges-clip.c index 61c4bb1..5e43068 100644 --- a/ges/ges-clip.c +++ b/ges/ges-clip.c @@ -990,8 +990,12 @@ ges_clip_edit (GESClip * clip, GList * layers, * * The function modifies @clip, and creates another #GESClip so * we have two clips at the end, splitted at the time specified by @position. + * The newly created clip will be added to the same layer as @clip is in. + * This implies that @clip must be in a #GESTimelineLayer for the operation to + * be possible. * - * Returns: (transfer floating): The newly created #GESClip resulting from the splitting + * Returns: (transfer none): The newly created #GESClip resulting from the + * splitting */ GESClip * ges_clip_split (GESClip * clip, guint64 position) @@ -1002,6 +1006,7 @@ ges_clip_split (GESClip * clip, guint64 position) GstClockTime start, inpoint, duration; g_return_val_if_fail (GES_IS_CLIP (clip), NULL); + g_return_val_if_fail (clip->priv->layer, NULL); g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (position), NULL); duration = _DURATION (clip); @@ -1029,12 +1034,10 @@ ges_clip_split (GESClip * clip, guint64 position) _set_duration0 (GES_TIMELINE_ELEMENT (new_object), duration + start - position); - if (clip->priv->layer) { - /* We do not want the timeline to create again TrackElement-s */ - ges_clip_set_moving_from_layer (new_object, TRUE); - ges_timeline_layer_add_clip (clip->priv->layer, new_object); - ges_clip_set_moving_from_layer (new_object, FALSE); - } + /* We do not want the timeline to create again TrackElement-s */ + ges_clip_set_moving_from_layer (new_object, TRUE); + ges_timeline_layer_add_clip (clip->priv->layer, new_object); + ges_clip_set_moving_from_layer (new_object, FALSE); /* We first set the new duration and the child mapping will be updated * properly in the following loop @@ -1272,7 +1275,6 @@ _trim (GESTimelineElement * element, GstClockTime start) * * Returns: %TRUE on success, %FALSE on failure. */ - gboolean ges_clip_add_asset (GESClip * clip, GESAsset * asset) { diff --git a/tests/check/ges/clip.c b/tests/check/ges/clip.c index d471030..e1028dc 100644 --- a/tests/check/ges/clip.c +++ b/tests/check/ges/clip.c @@ -41,15 +41,24 @@ my_fill_track_func (GESClip * clip, GST_START_TEST (test_object_properties) { + GESClip *clip; GESTrack *track; + GESTimeline *timeline; + GESTimelineLayer *layer; GESTrackElement *trackelement; - GESClip *clip; ges_init (); track = ges_track_new (GES_TRACK_TYPE_CUSTOM, gst_caps_ref (GST_CAPS_ANY)); fail_unless (track != NULL); + layer = ges_timeline_layer_new (); + fail_unless (layer != NULL); + timeline = ges_timeline_new (); + fail_unless (timeline != NULL); + fail_unless (ges_timeline_add_layer (timeline, layer)); + fail_unless (ges_timeline_add_track (timeline, track)); + clip = (GESClip *) ges_custom_source_clip_new (my_fill_track_func, NULL); fail_unless (clip != NULL); @@ -60,10 +69,13 @@ GST_START_TEST (test_object_properties) assert_equals_uint64 (_DURATION (clip), 51); assert_equals_uint64 (_INPOINT (clip), 12); - trackelement = ges_clip_create_track_element (clip, track->type); - ges_container_add (GES_CONTAINER (clip), GES_TIMELINE_ELEMENT (trackelement)); + ges_timeline_layer_add_clip (layer, GES_CLIP (clip)); + assert_equals_int (g_list_length (GES_CONTAINER_CHILDREN (clip)), 1); + trackelement = GES_CONTAINER_CHILDREN (clip)->data; fail_unless (trackelement != NULL); - fail_unless (ges_track_element_set_track (trackelement, track)); + fail_unless (GES_TIMELINE_ELEMENT_PARENT (trackelement) == + GES_TIMELINE_ELEMENT (clip)); + fail_unless (ges_track_element_get_track (trackelement) == track); /* Check that trackelement has the same properties */ assert_equals_uint64 (_START (trackelement), 42); @@ -100,8 +112,7 @@ GST_START_TEST (test_object_properties) ges_container_remove (GES_CONTAINER (clip), GES_TIMELINE_ELEMENT (trackelement)); - g_object_unref (clip); - g_object_unref (track); + gst_object_unref (timeline); } GST_END_TEST; @@ -109,29 +120,44 @@ GST_END_TEST; GST_START_TEST (test_split_object) { GESTrack *track; - GESTrackElement *trackelement, *splittrackelement; + GESTimeline *timeline; + GESTimelineLayer *layer; GESClip *clip, *splitclip; GList *splittrackelements; + GESTrackElement *trackelement, *splittrackelement; ges_init (); track = ges_track_new (GES_TRACK_TYPE_CUSTOM, gst_caps_ref (GST_CAPS_ANY)); fail_unless (track != NULL); + layer = ges_timeline_layer_new (); + fail_unless (layer != NULL); + timeline = ges_timeline_new (); + fail_unless (timeline != NULL); + fail_unless (ges_timeline_add_layer (timeline, layer)); + fail_unless (ges_timeline_add_track (timeline, track)); + ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1); + clip = (GESClip *) ges_custom_source_clip_new (my_fill_track_func, NULL); fail_unless (clip != NULL); + ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1); /* Set some properties */ g_object_set (clip, "start", (guint64) 42, "duration", (guint64) 50, "in-point", (guint64) 12, NULL); + ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1); assert_equals_uint64 (_START (clip), 42); assert_equals_uint64 (_DURATION (clip), 50); assert_equals_uint64 (_INPOINT (clip), 12); - trackelement = ges_clip_create_track_element (clip, track->type); - ges_container_add (GES_CONTAINER (clip), GES_TIMELINE_ELEMENT (trackelement)); + ges_timeline_layer_add_clip (layer, GES_CLIP (clip)); + assert_equals_int (g_list_length (GES_CONTAINER_CHILDREN (clip)), 1); + trackelement = GES_CONTAINER_CHILDREN (clip)->data; fail_unless (trackelement != NULL); - fail_unless (ges_track_element_set_track (trackelement, track)); + fail_unless (GES_TIMELINE_ELEMENT_PARENT (trackelement) == + GES_TIMELINE_ELEMENT (clip)); + fail_unless (ges_track_element_get_track (trackelement) == track); /* Check that trackelement has the same properties */ assert_equals_uint64 (_START (trackelement), 42); @@ -167,12 +193,13 @@ GST_START_TEST (test_split_object) /* We own the only ref */ ASSERT_OBJECT_REFCOUNT (splitclip, "splitclip", 1); - /* 1 ref for the Clip and 1 ref for the Track */ - ASSERT_OBJECT_REFCOUNT (splittrackelement, "splittrackelement", 2); + /* 1 ref for the Clip, 1 ref for the Track and 1 ref for the timeline */ + ASSERT_OBJECT_REFCOUNT (splittrackelement, "splittrackelement", 3); - g_object_unref (track); - g_object_unref (splitclip); - g_object_unref (clip); + g_object_unref (timeline); + fail_if (G_IS_OBJECT (splitclip)); + fail_if (G_IS_OBJECT (clip)); + fail_if (G_IS_OBJECT (splittrackelement)); } GST_END_TEST; -- 2.7.4