From 2723ef561e2f13dc463dc632a47cf62cf71ebdb6 Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Wed, 10 Jul 2013 23:33:51 +0200 Subject: [PATCH] container/group/clip: Allow creating an empty group. This is a legitimate use case. --- ges/ges-clip.c | 3 +++ ges/ges-container.c | 11 ++++++----- ges/ges-group.c | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/ges/ges-clip.c b/ges/ges-clip.c index de40280bd9..bcc3cdf7f7 100644 --- a/ges/ges-clip.c +++ b/ges/ges-clip.c @@ -440,6 +440,9 @@ _group (GList * containers) start = inpoint = duration = GST_CLOCK_TIME_NONE; + if (!containers) + return NULL; + /* First check if all the containers are clips, if they * all have the same start/inpoint/duration and are in the same * layer. diff --git a/ges/ges-container.c b/ges/ges-container.c index 7f0e956f4a..b9cdb6914b 100644 --- a/ges/ges-container.c +++ b/ges/ges-container.c @@ -643,7 +643,7 @@ ges_container_ungroup (GESContainer * container, gboolean recursive) /** * ges_container_group: - * @containers: (transfer none)(element-type GESContainer): The + * @containers: (transfer none)(element-type GESContainer) (allow-none): The * #GESContainer to group, they must all be in a same #GESTimeline * * Groups the #GESContainer-s provided in @containers. It creates a subclass @@ -669,10 +669,11 @@ ges_container_group (GList * containers) guint i = 0; GESContainer *ret = NULL; - g_return_val_if_fail (containers, NULL); - element = GES_TIMELINE_ELEMENT (containers->data); - timeline = GES_TIMELINE_ELEMENT_TIMELINE (element); - g_return_val_if_fail (timeline, NULL); + if (containers) { + element = GES_TIMELINE_ELEMENT (containers->data); + timeline = GES_TIMELINE_ELEMENT_TIMELINE (element); + g_return_val_if_fail (timeline, NULL); + } if (g_list_length (containers) == 1) return containers->data; diff --git a/ges/ges-group.c b/ges/ges-group.c index 4410f668c0..63f2577bf5 100644 --- a/ges/ges-group.c +++ b/ges/ges-group.c @@ -380,6 +380,11 @@ _child_added (GESContainer * group, GESTimelineElement * child) GESGroupPrivate *priv = GES_GROUP (group)->priv; GstClockTime last_child_end = 0, first_child_start = G_MAXUINT64; + if (!GES_TIMELINE_ELEMENT_TIMELINE (group)) { + timeline_add_group (GES_TIMELINE_ELEMENT_TIMELINE (child), + GES_GROUP (group)); + } + children = GES_CONTAINER_CHILDREN (group); for (tmp = children; tmp; tmp = tmp->next) { @@ -432,6 +437,8 @@ _child_removed (GESContainer * group, GESTimelineElement * child) if (children == NULL) { GST_FIXME_OBJECT (group, "Auto destroy myself?"); + timeline_remove_group (GES_TIMELINE_ELEMENT_TIMELINE (group), + GES_GROUP (group)); return; } @@ -460,8 +467,7 @@ _ungroup (GESContainer * group, gboolean recursive) } g_list_free_full (children, gst_object_unref); - timeline_remove_group (GES_TIMELINE_ELEMENT_TIMELINE (group), - GES_GROUP (group)); + /* No need to remove from the timeline here, this will be done in _child_removed */ return ret; } @@ -473,6 +479,9 @@ _group (GList * containers) GESTimeline *timeline = NULL; GESContainer *ret = g_object_new (GES_TYPE_GROUP, NULL); + if (!containers) + return ret; + for (tmp = containers; tmp; tmp = tmp->next) { if (!timeline) { timeline = GES_TIMELINE_ELEMENT_TIMELINE (tmp->data); @@ -485,7 +494,7 @@ _group (GList * containers) ges_container_add (ret, tmp->data); } - timeline_add_group (timeline, GES_GROUP (ret)); + /* No need to add to the timeline here, this will be done in _child_added */ return ret; }