2013-03-01 01:27:50 +00:00
|
|
|
/* GStreamer Editing Services
|
|
|
|
* Copyright (C) <2013> Thibault Saunier <thibault.saunier@collabora.com>
|
|
|
|
* <2013> Collabora Ltd.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-04-07 19:02:48 +00:00
|
|
|
* SECTION:gescontainer
|
2017-03-08 21:13:48 +00:00
|
|
|
* @title: GESContainer
|
2020-01-08 09:26:07 +00:00
|
|
|
* @short_description: Base Class for elements responsible for controlling
|
|
|
|
* other #GESTimelineElement-s
|
|
|
|
*
|
|
|
|
* A #GESContainer is a timeline element that controls other
|
|
|
|
* #GESTimelineElement-s, which are its children. In particular, it is
|
|
|
|
* responsible for maintaining the relative #GESTimelineElement:start and
|
|
|
|
* #GESTimelineElement:duration times of its children. Therefore, if a
|
|
|
|
* container is temporally adjusted or moved to a new layer, it may
|
|
|
|
* accordingly adjust and move its children. Similarly, a change in one of
|
|
|
|
* its children may prompt the parent to correspondingly change its
|
|
|
|
* siblings.
|
2013-03-01 01:27:50 +00:00
|
|
|
*/
|
2018-09-24 14:41:24 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2013-03-01 01:27:50 +00:00
|
|
|
|
|
|
|
#include "ges-container.h"
|
|
|
|
#include "ges.h"
|
|
|
|
#include "ges-internal.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (ges_container_debug);
|
|
|
|
#undef GST_CAT_DEFAULT
|
|
|
|
#define GST_CAT_DEFAULT ges_container_debug
|
|
|
|
|
|
|
|
/* Mapping of relationship between a Container and the TimelineElements
|
|
|
|
* it controls
|
|
|
|
*
|
|
|
|
* NOTE : Does it make sense to make it public in the future ?
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GESTimelineElement *child;
|
|
|
|
|
|
|
|
GstClockTime start_offset;
|
|
|
|
GstClockTime duration_offset;
|
|
|
|
|
2020-03-03 14:31:10 +00:00
|
|
|
gulong start_notifyid;
|
|
|
|
gulong duration_notifyid;
|
|
|
|
gulong child_property_added_notifyid;
|
|
|
|
gulong child_property_removed_notifyid;
|
2013-03-01 01:27:50 +00:00
|
|
|
} ChildMapping;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CHILD_ADDED_SIGNAL,
|
|
|
|
CHILD_REMOVED_SIGNAL,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint ges_container_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
struct _GESContainerPrivate
|
|
|
|
{
|
|
|
|
/*< public > */
|
2013-04-23 23:04:04 +00:00
|
|
|
GESLayer *layer;
|
2013-03-01 01:27:50 +00:00
|
|
|
|
|
|
|
/*< private > */
|
|
|
|
/* Set to TRUE when the container is doing updates of track object
|
|
|
|
* properties so we don't end up in infinite property update loops
|
|
|
|
*/
|
|
|
|
GHashTable *mappings;
|
2015-09-24 11:21:15 +00:00
|
|
|
|
|
|
|
/* List of GESTimelineElement being in the "child-added" signal
|
|
|
|
* emission stage */
|
|
|
|
GList *adding_children;
|
2016-01-01 10:56:27 +00:00
|
|
|
|
|
|
|
GList *copied_children;
|
2013-03-01 01:27:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_HEIGHT,
|
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *properties[PROP_LAST];
|
|
|
|
|
2018-09-06 01:55:02 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GESContainer, ges_container,
|
|
|
|
GES_TYPE_TIMELINE_ELEMENT);
|
|
|
|
|
2013-03-01 01:27:50 +00:00
|
|
|
/************************
|
|
|
|
* Private methods *
|
|
|
|
************************/
|
|
|
|
static void
|
|
|
|
_free_mapping (ChildMapping * mapping)
|
|
|
|
{
|
|
|
|
GESTimelineElement *child = mapping->child;
|
|
|
|
|
|
|
|
/* Disconnect all notify listeners */
|
2016-01-01 10:56:27 +00:00
|
|
|
if (mapping->start_notifyid)
|
|
|
|
g_signal_handler_disconnect (child, mapping->start_notifyid);
|
|
|
|
if (mapping->duration_notifyid)
|
|
|
|
g_signal_handler_disconnect (child, mapping->duration_notifyid);
|
2020-03-03 14:31:10 +00:00
|
|
|
if (mapping->child_property_added_notifyid)
|
|
|
|
g_signal_handler_disconnect (child, mapping->child_property_added_notifyid);
|
|
|
|
if (mapping->child_property_removed_notifyid)
|
|
|
|
g_signal_handler_disconnect (child,
|
|
|
|
mapping->child_property_removed_notifyid);
|
2020-04-06 11:21:54 +00:00
|
|
|
if (child) {
|
|
|
|
ges_timeline_element_set_parent (child, NULL);
|
|
|
|
gst_object_unref (child);
|
|
|
|
}
|
2020-04-02 10:58:18 +00:00
|
|
|
|
2013-03-01 01:27:50 +00:00
|
|
|
g_slice_free (ChildMapping, mapping);
|
|
|
|
}
|
|
|
|
|
2013-03-23 08:46:38 +00:00
|
|
|
static gint
|
|
|
|
compare_grouping_prio (GType * a, GType * b)
|
|
|
|
{
|
|
|
|
gint ret = 0;
|
|
|
|
GObjectClass *aclass = g_type_class_ref (*a);
|
|
|
|
GObjectClass *bclass = g_type_class_ref (*b);
|
|
|
|
|
2013-06-25 22:34:44 +00:00
|
|
|
/* We want higher prios to be first */
|
2013-03-23 08:46:38 +00:00
|
|
|
if (GES_CONTAINER_CLASS (aclass)->grouping_priority <
|
|
|
|
GES_CONTAINER_CLASS (bclass)->grouping_priority)
|
2013-06-25 22:34:44 +00:00
|
|
|
ret = 1;
|
2013-03-23 08:46:38 +00:00
|
|
|
else if (GES_CONTAINER_CLASS (aclass)->grouping_priority >
|
|
|
|
GES_CONTAINER_CLASS (bclass)->grouping_priority)
|
2013-06-25 22:34:44 +00:00
|
|
|
ret = -1;
|
2013-03-23 08:46:38 +00:00
|
|
|
|
|
|
|
g_type_class_unref (aclass);
|
|
|
|
g_type_class_unref (bclass);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-01-06 16:20:20 +00:00
|
|
|
static void
|
2020-04-18 15:34:56 +00:00
|
|
|
_resync_position_offsets (GESTimelineElement * child,
|
2016-01-06 16:20:20 +00:00
|
|
|
ChildMapping * map, GESContainer * container)
|
|
|
|
{
|
|
|
|
map->start_offset = _START (container) - _START (child);
|
2020-04-18 15:34:56 +00:00
|
|
|
map->duration_offset = _DURATION (container) - _DURATION (child);
|
2016-01-06 16:20:20 +00:00
|
|
|
}
|
|
|
|
|
2013-06-26 23:55:37 +00:00
|
|
|
/*****************************************************
|
|
|
|
* *
|
|
|
|
* GESTimelineElement virtual methods implementation *
|
|
|
|
* *
|
|
|
|
*****************************************************/
|
|
|
|
static gboolean
|
|
|
|
_set_start (GESTimelineElement * element, GstClockTime start)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
ChildMapping *map;
|
|
|
|
GESContainer *container = GES_CONTAINER (element);
|
|
|
|
GESContainerPrivate *priv = container->priv;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (element, "Updating children offsets, (initiated_move: %"
|
|
|
|
GST_PTR_FORMAT ")", container->initiated_move);
|
|
|
|
|
|
|
|
for (tmp = container->children; tmp; tmp = g_list_next (tmp)) {
|
|
|
|
GESTimelineElement *child = (GESTimelineElement *) tmp->data;
|
|
|
|
|
|
|
|
map = g_hash_table_lookup (priv->mappings, child);
|
|
|
|
map->start_offset = start - _START (child);
|
|
|
|
}
|
2013-07-01 21:51:32 +00:00
|
|
|
container->children_control_mode = GES_CHILDREN_UPDATE;
|
2013-06-26 23:55:37 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_set_duration (GESTimelineElement * element, GstClockTime duration)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
GESContainer *container = GES_CONTAINER (element);
|
|
|
|
GESContainerPrivate *priv = container->priv;
|
|
|
|
|
|
|
|
for (tmp = container->children; tmp; tmp = g_list_next (tmp)) {
|
|
|
|
GESTimelineElement *child = (GESTimelineElement *) tmp->data;
|
|
|
|
ChildMapping *map = g_hash_table_lookup (priv->mappings, child);
|
|
|
|
|
|
|
|
map->duration_offset = duration - _DURATION (child);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-03-03 14:31:10 +00:00
|
|
|
static void
|
|
|
|
_add_childs_child_property (GESTimelineElement * container_child,
|
|
|
|
GObject * prop_child, GParamSpec * property, GESContainer * container)
|
|
|
|
{
|
|
|
|
/* the container_child is kept as the owner of this child property when
|
|
|
|
* we register it on ourselves, but we use the same GObject child
|
|
|
|
* instance who the property comes from */
|
|
|
|
gboolean res =
|
|
|
|
ges_timeline_element_add_child_property_full (GES_TIMELINE_ELEMENT
|
|
|
|
(container), container_child, property, prop_child);
|
|
|
|
if (!res)
|
|
|
|
GST_INFO_OBJECT (container, "Could not register the child property '%s' "
|
|
|
|
"of our child %" GES_FORMAT " for the object %" GST_PTR_FORMAT,
|
|
|
|
property->name, GES_ARGS (container_child), prop_child);
|
|
|
|
}
|
|
|
|
|
2015-02-19 17:19:44 +00:00
|
|
|
static void
|
|
|
|
_ges_container_add_child_properties (GESContainer * container,
|
|
|
|
GESTimelineElement * child)
|
|
|
|
{
|
|
|
|
guint n_props, i;
|
|
|
|
|
2020-03-03 14:31:10 +00:00
|
|
|
/* use get_children_properties, rather than list_children_properties
|
|
|
|
* to ensure we are getting all the properties, without any interference
|
|
|
|
* from the ->list_children_properties vmethods */
|
2015-02-19 17:19:44 +00:00
|
|
|
GParamSpec **child_props =
|
2020-03-03 14:31:10 +00:00
|
|
|
ges_timeline_element_get_children_properties (child,
|
2015-02-19 17:19:44 +00:00
|
|
|
&n_props);
|
|
|
|
|
|
|
|
for (i = 0; i < n_props; i++) {
|
2020-03-03 14:31:10 +00:00
|
|
|
GParamSpec *property = child_props[i];
|
|
|
|
GObject *prop_child =
|
|
|
|
ges_timeline_element_get_child_from_child_property (child, property);
|
|
|
|
if (prop_child)
|
|
|
|
_add_childs_child_property (child, prop_child, property, container);
|
|
|
|
g_param_spec_unref (property);
|
2015-02-19 17:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (child_props);
|
|
|
|
}
|
|
|
|
|
2020-03-03 14:31:10 +00:00
|
|
|
static void
|
|
|
|
_remove_childs_child_property (GESTimelineElement * container_child,
|
|
|
|
GObject * prop_child, GParamSpec * property, GESContainer * container)
|
|
|
|
{
|
|
|
|
/* NOTE: some children may share the same GParamSpec. Currently, only
|
|
|
|
* the first such child added will have its children properties
|
|
|
|
* successfully registered for the container (even though the GObject
|
|
|
|
* child who the properties belong to will be a different instance). As
|
|
|
|
* such, we only want to remove the child property if it corresponds to
|
|
|
|
* the same instance that the parent container has.
|
|
|
|
* E.g. if we add child1 and child2, that have the same (or some
|
|
|
|
* overlapping) children properties. And child1 is added before child2,
|
|
|
|
* then child2's overlapping children properties would not be registered.
|
|
|
|
* If we remove child2, we do *not* want to removed the child properties
|
|
|
|
* for child1 because they belong to a GObject instance that we still
|
|
|
|
* have in our control.
|
|
|
|
* If we remove child1, we *do* want to remove the child properties for
|
|
|
|
* child1, even though child2 may overlap with some of them, because we
|
|
|
|
* are loosing the specific GObject instance that it belongs to!
|
|
|
|
* We could try and register the ones that match for the other children.
|
|
|
|
* However, it is probably simpler to change
|
|
|
|
* ges_timeline_element_add_child_property_full to accept the same
|
|
|
|
* GParamSpec, for different instances.
|
|
|
|
*/
|
|
|
|
GESTimelineElement *element = GES_TIMELINE_ELEMENT (container);
|
|
|
|
GObject *our_prop_child =
|
|
|
|
ges_timeline_element_get_child_from_child_property (element, property);
|
|
|
|
if (our_prop_child == prop_child)
|
|
|
|
ges_timeline_element_remove_child_property (element, property);
|
|
|
|
else
|
|
|
|
GST_INFO_OBJECT (container, "Not removing child property '%s' for child"
|
|
|
|
" %" GES_FORMAT " because it derives from the object %" GST_PTR_FORMAT
|
|
|
|
"(%p) rather than the object %" GST_PTR_FORMAT "(%p)", property->name,
|
|
|
|
GES_ARGS (container_child), prop_child, prop_child, our_prop_child,
|
|
|
|
our_prop_child);
|
|
|
|
}
|
|
|
|
|
2015-02-19 17:19:44 +00:00
|
|
|
static void
|
|
|
|
_ges_container_remove_child_properties (GESContainer * container,
|
|
|
|
GESTimelineElement * child)
|
|
|
|
{
|
|
|
|
guint n_props, i;
|
|
|
|
|
2020-03-03 14:31:10 +00:00
|
|
|
/* use get_children_properties, rather than list_children_properties
|
|
|
|
* to ensure we are getting all the properties, without any interference
|
|
|
|
* from the ->list_children_properties vmethods */
|
2015-02-19 17:19:44 +00:00
|
|
|
GParamSpec **child_props =
|
2020-03-03 14:31:10 +00:00
|
|
|
ges_timeline_element_get_children_properties (child,
|
2015-02-19 17:19:44 +00:00
|
|
|
&n_props);
|
|
|
|
|
|
|
|
for (i = 0; i < n_props; i++) {
|
2020-03-03 14:31:10 +00:00
|
|
|
GParamSpec *property = child_props[i];
|
|
|
|
GObject *prop_child =
|
|
|
|
ges_timeline_element_get_child_from_child_property (child, property);
|
|
|
|
if (prop_child)
|
|
|
|
_remove_childs_child_property (child, prop_child, property, container);
|
|
|
|
g_param_spec_unref (property);
|
2015-02-19 17:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (child_props);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_lookup_child (GESTimelineElement * self, const gchar * prop_name,
|
|
|
|
GObject ** child, GParamSpec ** pspec)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
|
2018-07-28 16:16:36 +00:00
|
|
|
/* FIXME Implement a syntax to precisely get properties by path */
|
2016-04-29 14:36:00 +00:00
|
|
|
for (tmp = GES_CONTAINER_CHILDREN (self); tmp; tmp = tmp->next) {
|
|
|
|
if (ges_timeline_element_lookup_child (tmp->data, prop_name, child, pspec))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2015-02-19 17:19:44 +00:00
|
|
|
}
|
|
|
|
|
2015-06-23 11:27:00 +00:00
|
|
|
static GESTrackType
|
|
|
|
_get_track_types (GESTimelineElement * object)
|
|
|
|
{
|
|
|
|
GESTrackType types = GES_TRACK_TYPE_UNKNOWN;
|
|
|
|
GList *tmp, *children = ges_container_get_children (GES_CONTAINER (object),
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
for (tmp = children; tmp; tmp = tmp->next) {
|
|
|
|
if (GES_IS_TRACK_ELEMENT (tmp->data)) {
|
|
|
|
types |= ges_timeline_element_get_track_types (tmp->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free_full (children, gst_object_unref);
|
|
|
|
|
|
|
|
return types ^ GES_TRACK_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2016-01-01 10:56:27 +00:00
|
|
|
static void
|
|
|
|
_deep_copy (GESTimelineElement * element, GESTimelineElement * copy)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
GESContainer *self = GES_CONTAINER (element), *ccopy = GES_CONTAINER (copy);
|
|
|
|
|
|
|
|
for (tmp = GES_CONTAINER_CHILDREN (element); tmp; tmp = tmp->next) {
|
2020-04-02 10:58:18 +00:00
|
|
|
ChildMapping *map, *orig_map;
|
|
|
|
orig_map = g_hash_table_lookup (self->priv->mappings, tmp->data);
|
|
|
|
map = g_slice_new0 (ChildMapping);
|
2016-01-01 10:56:27 +00:00
|
|
|
map->child = ges_timeline_element_copy (tmp->data, TRUE);
|
2020-04-02 10:58:18 +00:00
|
|
|
map->start_offset = orig_map->start_offset;
|
2016-01-01 10:56:27 +00:00
|
|
|
|
|
|
|
ccopy->priv->copied_children = g_list_prepend (ccopy->priv->copied_children,
|
|
|
|
map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GESTimelineElement *
|
2015-06-29 16:04:32 +00:00
|
|
|
_paste (GESTimelineElement * element, GESTimelineElement * ref,
|
|
|
|
GstClockTime paste_position)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
2016-01-01 10:56:27 +00:00
|
|
|
ChildMapping *map;
|
|
|
|
GESContainer *ncontainer =
|
|
|
|
GES_CONTAINER (ges_timeline_element_copy (element, FALSE));
|
2015-06-29 16:04:32 +00:00
|
|
|
GESContainer *self = GES_CONTAINER (element);
|
|
|
|
|
2016-01-01 10:56:27 +00:00
|
|
|
for (tmp = self->priv->copied_children; tmp; tmp = tmp->next) {
|
|
|
|
GESTimelineElement *nchild;
|
2015-06-29 16:04:32 +00:00
|
|
|
|
2016-01-01 10:56:27 +00:00
|
|
|
map = tmp->data;
|
|
|
|
nchild =
|
|
|
|
ges_timeline_element_paste (map->child,
|
|
|
|
paste_position - map->start_offset);
|
2019-05-26 00:20:07 +00:00
|
|
|
|
|
|
|
if (!nchild) {
|
|
|
|
while (ncontainer->children)
|
|
|
|
ges_container_remove (ncontainer, ncontainer->children->data);
|
|
|
|
|
|
|
|
g_object_unref (ncontainer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-04-02 10:58:18 +00:00
|
|
|
/* for GESGroups, this may register the group on the timeline */
|
2020-04-09 14:31:36 +00:00
|
|
|
if (!ges_container_add (ncontainer, nchild))
|
|
|
|
GST_ERROR ("%" GES_FORMAT " could not add child %p while"
|
|
|
|
" copying, this should never happen", GES_ARGS (ncontainer), nchild);
|
2015-06-29 16:04:32 +00:00
|
|
|
}
|
|
|
|
|
2016-01-01 10:56:27 +00:00
|
|
|
return GES_TIMELINE_ELEMENT (ncontainer);
|
2015-06-29 16:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-01 01:27:50 +00:00
|
|
|
/******************************************
|
|
|
|
* *
|
|
|
|
* GObject virtual methods implementation *
|
|
|
|
* *
|
|
|
|
******************************************/
|
|
|
|
static void
|
|
|
|
_dispose (GObject * object)
|
|
|
|
{
|
2016-06-18 20:16:00 +00:00
|
|
|
GList *tmp;
|
2013-03-01 01:27:50 +00:00
|
|
|
GESContainer *self = GES_CONTAINER (object);
|
2018-09-06 00:49:09 +00:00
|
|
|
GList *children;
|
2016-06-18 20:16:00 +00:00
|
|
|
|
2018-09-06 00:49:09 +00:00
|
|
|
_ges_container_sort_children (self);
|
|
|
|
children = ges_container_get_children (self, FALSE);
|
|
|
|
|
|
|
|
for (tmp = g_list_last (children); tmp; tmp = tmp->prev)
|
2016-06-18 20:16:00 +00:00
|
|
|
ges_container_remove (self, tmp->data);
|
2013-03-01 01:27:50 +00:00
|
|
|
|
2016-06-18 20:16:00 +00:00
|
|
|
g_list_free_full (children, gst_object_unref);
|
|
|
|
self->children = NULL;
|
2014-03-07 20:48:06 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (ges_container_parent_class)->dispose (object);
|
2013-03-01 01:27:50 +00:00
|
|
|
}
|
|
|
|
|
2016-01-01 10:56:27 +00:00
|
|
|
static void
|
|
|
|
_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GESContainer *self = GES_CONTAINER (object);
|
|
|
|
|
|
|
|
g_list_free_full (self->priv->copied_children,
|
|
|
|
(GDestroyNotify) _free_mapping);
|
|
|
|
|
2018-12-27 01:54:28 +00:00
|
|
|
if (self->priv->mappings)
|
|
|
|
g_hash_table_destroy (self->priv->mappings);
|
|
|
|
|
2018-12-26 15:15:30 +00:00
|
|
|
G_OBJECT_CLASS (ges_container_parent_class)->finalize (object);
|
2016-01-01 10:56:27 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 01:27:50 +00:00
|
|
|
static void
|
|
|
|
_get_property (GObject * container, guint property_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GESContainer *tobj = GES_CONTAINER (container);
|
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_HEIGHT:
|
|
|
|
g_value_set_uint (value, tobj->height);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (container, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_set_property (GObject * container, guint property_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (property_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (container, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_container_class_init (GESContainerClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2013-06-26 23:55:37 +00:00
|
|
|
GESTimelineElementClass *element_class = GES_TIMELINE_ELEMENT_CLASS (klass);
|
2013-03-01 01:27:50 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (ges_container_debug, "gescontainer",
|
|
|
|
GST_DEBUG_FG_YELLOW, "ges container");
|
|
|
|
|
|
|
|
object_class->get_property = _get_property;
|
|
|
|
object_class->set_property = _set_property;
|
|
|
|
object_class->dispose = _dispose;
|
2016-01-01 10:56:27 +00:00
|
|
|
object_class->finalize = _finalize;
|
2013-03-01 01:27:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GESContainer:height:
|
|
|
|
*
|
2020-01-08 09:26:07 +00:00
|
|
|
* The span of the container's children's #GESTimelineElement:priority
|
|
|
|
* values, which is the number of integers that lie between (inclusive)
|
|
|
|
* the minimum and maximum priorities found amongst the container's
|
|
|
|
* children (maximum - minimum + 1).
|
2013-03-01 01:27:50 +00:00
|
|
|
*/
|
|
|
|
properties[PROP_HEIGHT] = g_param_spec_uint ("height", "Height",
|
|
|
|
"The span of priorities this container occupies", 0, G_MAXUINT, 1,
|
|
|
|
G_PARAM_READABLE);
|
|
|
|
g_object_class_install_property (object_class, PROP_HEIGHT,
|
|
|
|
properties[PROP_HEIGHT]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GESContainer::child-added:
|
2020-01-08 09:26:07 +00:00
|
|
|
* @container: The #GESContainer
|
|
|
|
* @element: The child that was added
|
2013-03-01 01:27:50 +00:00
|
|
|
*
|
2020-01-08 09:26:07 +00:00
|
|
|
* Will be emitted after a child is added to the container. Usually,
|
|
|
|
* you should connect with g_signal_connect_after() since the signal
|
|
|
|
* may be stopped internally.
|
2013-03-01 01:27:50 +00:00
|
|
|
*/
|
|
|
|
ges_container_signals[CHILD_ADDED_SIGNAL] =
|
|
|
|
g_signal_new ("child-added", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESContainerClass, child_added),
|
2019-08-29 05:45:45 +00:00
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 1, GES_TYPE_TIMELINE_ELEMENT);
|
2013-03-01 01:27:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GESContainer::child-removed:
|
2020-01-08 09:26:07 +00:00
|
|
|
* @container: The #GESContainer
|
|
|
|
* @element: The child that was removed
|
2013-03-01 01:27:50 +00:00
|
|
|
*
|
2020-01-08 09:26:07 +00:00
|
|
|
* Will be emitted after a child is removed from the container.
|
2013-03-01 01:27:50 +00:00
|
|
|
*/
|
|
|
|
ges_container_signals[CHILD_REMOVED_SIGNAL] =
|
|
|
|
g_signal_new ("child-removed", G_TYPE_FROM_CLASS (klass),
|
2018-10-08 22:45:29 +00:00
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GESContainerClass, child_removed),
|
2019-08-29 05:45:45 +00:00
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 1, GES_TYPE_TIMELINE_ELEMENT);
|
2013-03-01 01:27:50 +00:00
|
|
|
|
|
|
|
|
2013-06-26 23:55:37 +00:00
|
|
|
element_class->set_start = _set_start;
|
|
|
|
element_class->set_duration = _set_duration;
|
2015-02-19 17:19:44 +00:00
|
|
|
element_class->lookup_child = _lookup_child;
|
2015-06-23 11:27:00 +00:00
|
|
|
element_class->get_track_types = _get_track_types;
|
2015-06-29 16:04:32 +00:00
|
|
|
element_class->paste = _paste;
|
2016-01-01 10:56:27 +00:00
|
|
|
element_class->deep_copy = _deep_copy;
|
2013-06-26 23:55:37 +00:00
|
|
|
|
2013-03-01 01:27:50 +00:00
|
|
|
/* No default implementations */
|
|
|
|
klass->remove_child = NULL;
|
|
|
|
klass->add_child = NULL;
|
2013-03-01 23:25:17 +00:00
|
|
|
klass->ungroup = NULL;
|
2013-03-02 21:35:34 +00:00
|
|
|
klass->group = NULL;
|
2013-03-23 08:46:38 +00:00
|
|
|
klass->grouping_priority = 0;
|
2013-06-28 15:23:27 +00:00
|
|
|
klass->edit = NULL;
|
2013-03-01 01:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ges_container_init (GESContainer * self)
|
|
|
|
{
|
2018-09-06 01:55:02 +00:00
|
|
|
self->priv = ges_container_get_instance_private (self);
|
2013-03-01 01:27:50 +00:00
|
|
|
|
|
|
|
/* FIXME, check why default was GST_SECOND? (before the existend of
|
|
|
|
* ges-container)
|
|
|
|
*
|
|
|
|
* _DURATION (self) = GST_SECOND; */
|
|
|
|
self->height = 1; /* FIXME Why 1 and not 0? */
|
|
|
|
self->children = NULL;
|
|
|
|
|
|
|
|
self->priv->mappings = g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
|
|
|
NULL, (GDestroyNotify) _free_mapping);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************
|
|
|
|
* *
|
|
|
|
* Property notifications from Children *
|
|
|
|
* *
|
|
|
|
**********************************************/
|
2020-04-18 15:34:56 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
_update_start_duration (GESContainer * container, GESTimelineElement * child)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
GstClockTime duration, end = 0, start = G_MAXUINT64;
|
2020-04-20 12:13:48 +00:00
|
|
|
gboolean was_being_edited = GES_TIMELINE_ELEMENT_BEING_EDITED (container);
|
2020-04-18 15:34:56 +00:00
|
|
|
|
|
|
|
if (!container->children) {
|
|
|
|
/* If we are now empty, keep the same duration and start. This works
|
|
|
|
* well for a clip. For a group, the duration should probably be set
|
|
|
|
* to 0, but it gets automatically removed from the timeline when it
|
|
|
|
* is emptied */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-20 12:13:48 +00:00
|
|
|
GES_TIMELINE_ELEMENT_SET_BEING_EDITED (container);
|
2020-04-18 15:34:56 +00:00
|
|
|
|
|
|
|
for (tmp = container->children; tmp; tmp = tmp->next) {
|
|
|
|
start = MIN (start, _START (tmp->data));
|
|
|
|
end = MAX (end, _END (tmp->data));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end < start)
|
|
|
|
duration = 0;
|
|
|
|
else
|
|
|
|
duration = end - start;
|
|
|
|
|
|
|
|
if (start != _START (container) || duration != _DURATION (container)) {
|
|
|
|
GstClockTime prev_dur = _DURATION (container);
|
|
|
|
GstClockTime prev_start = _START (container);
|
|
|
|
|
|
|
|
_DURATION (container) = duration;
|
|
|
|
_START (container) = start;
|
|
|
|
|
|
|
|
GST_INFO ("%" GES_FORMAT " child %" GES_FORMAT " move made us move",
|
|
|
|
GES_ARGS (container), GES_ARGS (child));
|
|
|
|
|
|
|
|
if (prev_start != start)
|
|
|
|
g_object_notify (G_OBJECT (container), "start");
|
|
|
|
if (prev_dur != duration)
|
|
|
|
g_object_notify (G_OBJECT (container), "duration");
|
|
|
|
}
|
2020-04-20 12:13:48 +00:00
|
|
|
if (!was_being_edited)
|
|
|
|
GES_TIMELINE_ELEMENT_UNSET_BEING_EDITED (container);
|
2020-04-18 15:34:56 +00:00
|
|
|
|
|
|
|
g_hash_table_foreach (container->priv->mappings,
|
|
|
|
(GHFunc) _resync_position_offsets, container);
|
|
|
|
}
|
|
|
|
|
2013-03-01 01:27:50 +00:00
|
|
|
static void
|
|
|
|
_child_start_changed_cb (GESTimelineElement * child,
|
|
|
|
GParamSpec * arg G_GNUC_UNUSED, GESContainer * container)
|
|
|
|
{
|
|
|
|
ChildMapping *map;
|
|
|
|
|
|
|
|
GESContainerPrivate *priv = container->priv;
|
|
|
|
GESTimelineElement *element = GES_TIMELINE_ELEMENT (container);
|
2020-04-20 12:13:48 +00:00
|
|
|
GESChildrenControlMode mode = container->children_control_mode;
|
|
|
|
|
|
|
|
if (mode == GES_CHILDREN_IGNORE_NOTIFIES)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (GES_TIMELINE_ELEMENT_BEING_EDITED (child))
|
|
|
|
mode = GES_CHILDREN_UPDATE_ALL_VALUES;
|
2013-03-01 01:27:50 +00:00
|
|
|
|
|
|
|
map = g_hash_table_lookup (priv->mappings, child);
|
|
|
|
g_assert (map);
|
|
|
|
|
2020-04-20 12:13:48 +00:00
|
|
|
switch (mode) {
|
2013-09-07 06:11:23 +00:00
|
|
|
case GES_CHILDREN_UPDATE_ALL_VALUES:
|
2020-04-18 15:34:56 +00:00
|
|
|
_update_start_duration (container, child);
|
|
|
|
break;
|
2013-09-07 06:11:23 +00:00
|
|
|
case GES_CHILDREN_UPDATE_OFFSETS:
|
|
|
|
map->start_offset = _START (container) - _START (child);
|
|
|
|
break;
|
|
|
|
case GES_CHILDREN_UPDATE:
|
|
|
|
/* We update all the children calling our set_start method */
|
|
|
|
container->initiated_move = child;
|
|
|
|
_set_start0 (element, _START (child) + map->start_offset);
|
|
|
|
container->initiated_move = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-03-01 01:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_child_duration_changed_cb (GESTimelineElement * child,
|
|
|
|
GParamSpec * arg G_GNUC_UNUSED, GESContainer * container)
|
|
|
|
{
|
|
|
|
ChildMapping *map;
|
|
|
|
|
|
|
|
GESContainerPrivate *priv = container->priv;
|
|
|
|
GESTimelineElement *element = GES_TIMELINE_ELEMENT (container);
|
2020-04-20 12:13:48 +00:00
|
|
|
GESChildrenControlMode mode = container->children_control_mode;
|
2013-03-01 01:27:50 +00:00
|
|
|
|
2020-04-20 12:13:48 +00:00
|
|
|
if (mode == GES_CHILDREN_IGNORE_NOTIFIES)
|
2013-03-01 01:27:50 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-20 12:13:48 +00:00
|
|
|
if (GES_TIMELINE_ELEMENT_BEING_EDITED (child))
|
|
|
|
mode = GES_CHILDREN_UPDATE_ALL_VALUES;
|
2019-03-01 22:32:19 +00:00
|
|
|
|
2013-03-01 01:27:50 +00:00
|
|
|
map = g_hash_table_lookup (priv->mappings, child);
|
|
|
|
g_assert (map);
|
|
|
|
|
2020-04-20 12:13:48 +00:00
|
|
|
switch (mode) {
|
2013-09-07 06:11:23 +00:00
|
|
|
case GES_CHILDREN_UPDATE_ALL_VALUES:
|
2020-04-18 15:34:56 +00:00
|
|
|
_update_start_duration (container, child);
|
|
|
|
break;
|
2013-09-07 06:11:23 +00:00
|
|
|
case GES_CHILDREN_UPDATE_OFFSETS:
|
2020-02-24 20:19:12 +00:00
|
|
|
map->duration_offset = _DURATION (container) - _DURATION (child);
|
2013-09-07 06:11:23 +00:00
|
|
|
break;
|
|
|
|
case GES_CHILDREN_UPDATE:
|
|
|
|
/* We update all the children calling our set_duration method */
|
|
|
|
container->initiated_move = child;
|
2020-01-09 12:09:15 +00:00
|
|
|
/* FIXME: this is *not* the correct duration for a group!
|
|
|
|
* the ->set_duration method for GESGroup tries to hack around
|
|
|
|
* this by calling set_duration on itself to the actual value */
|
2013-09-07 06:11:23 +00:00
|
|
|
_set_duration0 (element, _DURATION (child) + map->duration_offset);
|
|
|
|
container->initiated_move = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-06-26 21:08:57 +00:00
|
|
|
}
|
2013-03-01 01:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************
|
|
|
|
* *
|
|
|
|
* Internal methods implementation *
|
|
|
|
* *
|
|
|
|
****************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
_ges_container_sort_children (GESContainer * container)
|
|
|
|
{
|
|
|
|
container->children = g_list_sort (container->children,
|
|
|
|
(GCompareFunc) element_start_compare);
|
|
|
|
}
|
|
|
|
|
2013-06-28 18:39:16 +00:00
|
|
|
void
|
|
|
|
_ges_container_set_height (GESContainer * container, guint32 height)
|
|
|
|
{
|
|
|
|
if (container->height != height) {
|
|
|
|
container->height = height;
|
|
|
|
GST_DEBUG_OBJECT (container, "Updating height %i", container->height);
|
|
|
|
g_object_notify (G_OBJECT (container), "height");
|
|
|
|
}
|
2013-03-01 01:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************
|
|
|
|
* *
|
|
|
|
* API implementation *
|
|
|
|
* *
|
|
|
|
**********************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_container_add:
|
2020-01-08 09:26:07 +00:00
|
|
|
* @container: A #GESContainer
|
|
|
|
* @child: The element to add as a child
|
|
|
|
*
|
|
|
|
* Adds a timeline element to the container. The element will now be a
|
|
|
|
* child of the container (and the container will be the
|
|
|
|
* #GESTimelineElement:parent of the added element), which means that it
|
|
|
|
* is now controlled by the container. This may change the properties of
|
|
|
|
* the child or the container, depending on the subclass.
|
2013-03-01 01:27:50 +00:00
|
|
|
*
|
2020-01-08 09:26:07 +00:00
|
|
|
* Additionally, the children properties of the newly added element will
|
|
|
|
* be shared with the container, meaning they can also be read and set
|
|
|
|
* using ges_timeline_element_get_child_property() and
|
|
|
|
* ges_timeline_element_set_child_property() on the container.
|
2013-03-01 01:27:50 +00:00
|
|
|
*
|
2020-01-08 09:26:07 +00:00
|
|
|
* Returns: %TRUE if @child was successfully added to @container.
|
2013-03-01 01:27:50 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
ges_container_add (GESContainer * container, GESTimelineElement * child)
|
|
|
|
{
|
|
|
|
ChildMapping *mapping;
|
2020-03-02 12:23:07 +00:00
|
|
|
gboolean ret = FALSE;
|
2013-03-01 01:27:50 +00:00
|
|
|
GESContainerClass *class;
|
2020-03-02 12:23:07 +00:00
|
|
|
GList *current_children, *tmp;
|
2013-03-01 01:27:50 +00:00
|
|
|
GESContainerPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GES_IS_CONTAINER (container), FALSE);
|
|
|
|
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (child), FALSE);
|
2013-06-28 23:17:54 +00:00
|
|
|
g_return_val_if_fail (GES_TIMELINE_ELEMENT_PARENT (child) == NULL, FALSE);
|
2013-03-01 01:27:50 +00:00
|
|
|
|
|
|
|
class = GES_CONTAINER_GET_CLASS (container);
|
|
|
|
priv = container->priv;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (container, "adding timeline element %" GST_PTR_FORMAT,
|
|
|
|
child);
|
|
|
|
|
2020-03-02 12:23:07 +00:00
|
|
|
/* freeze all notifies */
|
|
|
|
g_object_freeze_notify (G_OBJECT (container));
|
|
|
|
/* copy to use at end, since container->children may have child
|
|
|
|
* added to it */
|
|
|
|
current_children = g_list_copy_deep (container->children,
|
|
|
|
(GCopyFunc) gst_object_ref, NULL);
|
|
|
|
for (tmp = current_children; tmp; tmp = tmp->next)
|
|
|
|
g_object_freeze_notify (G_OBJECT (tmp->data));
|
|
|
|
g_object_freeze_notify (G_OBJECT (child));
|
2020-04-06 11:21:54 +00:00
|
|
|
gst_object_ref_sink (child);
|
2020-03-02 12:23:07 +00:00
|
|
|
|
2013-03-01 01:27:50 +00:00
|
|
|
if (class->add_child) {
|
2013-03-15 03:01:47 +00:00
|
|
|
if (class->add_child (container, child) == FALSE) {
|
2020-03-02 12:56:03 +00:00
|
|
|
GST_WARNING_OBJECT (container, "Error adding child %p", child);
|
2020-03-02 12:23:07 +00:00
|
|
|
goto done;
|
2013-03-15 03:01:47 +00:00
|
|
|
}
|
2013-03-01 01:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mapping = g_slice_new0 (ChildMapping);
|
2013-03-16 22:05:04 +00:00
|
|
|
mapping->child = gst_object_ref (child);
|
2013-03-01 01:27:50 +00:00
|
|
|
g_hash_table_insert (priv->mappings, child, mapping);
|
2022-01-22 01:24:23 +00:00
|
|
|
container->children = g_list_append (container->children, child);
|
2013-03-01 01:27:50 +00:00
|
|
|
|
|
|
|
/* Listen to all property changes */
|
|
|
|
mapping->start_notifyid =
|
|
|
|
g_signal_connect (G_OBJECT (child), "notify::start",
|
|
|
|
G_CALLBACK (_child_start_changed_cb), container);
|
|
|
|
mapping->duration_notifyid =
|
|
|
|
g_signal_connect (G_OBJECT (child), "notify::duration",
|
|
|
|
G_CALLBACK (_child_duration_changed_cb), container);
|
|
|
|
|
|
|
|
if (ges_timeline_element_set_parent (child, GES_TIMELINE_ELEMENT (container))
|
|
|
|
== FALSE) {
|
2019-04-11 21:58:48 +00:00
|
|
|
if (class->remove_child)
|
|
|
|
class->remove_child (container, child);
|
2014-03-14 19:04:33 +00:00
|
|
|
|
|
|
|
g_hash_table_remove (priv->mappings, child);
|
|
|
|
container->children = g_list_remove (container->children, child);
|
2020-04-06 11:21:54 +00:00
|
|
|
|
2020-03-02 12:23:07 +00:00
|
|
|
goto done;
|
2013-03-01 01:27:50 +00:00
|
|
|
}
|
|
|
|
|
2020-04-18 15:34:56 +00:00
|
|
|
_update_start_duration (container, child);
|
|
|
|
_ges_container_sort_children (container);
|
|
|
|
|
2015-02-19 17:19:44 +00:00
|
|
|
_ges_container_add_child_properties (container, child);
|
2020-03-03 14:31:10 +00:00
|
|
|
mapping->child_property_added_notifyid =
|
|
|
|
g_signal_connect (G_OBJECT (child), "child-property-added",
|
|
|
|
G_CALLBACK (_add_childs_child_property), container);
|
|
|
|
mapping->child_property_removed_notifyid =
|
|
|
|
g_signal_connect (G_OBJECT (child), "child-property-removed",
|
|
|
|
G_CALLBACK (_remove_childs_child_property), container);
|
2015-02-19 17:19:44 +00:00
|
|
|
|
2015-09-24 11:21:15 +00:00
|
|
|
priv->adding_children = g_list_prepend (priv->adding_children, child);
|
2013-03-01 01:27:50 +00:00
|
|
|
g_signal_emit (container, ges_container_signals[CHILD_ADDED_SIGNAL], 0,
|
|
|
|
child);
|
2015-09-24 11:21:15 +00:00
|
|
|
priv->adding_children = g_list_remove (priv->adding_children, child);
|
2013-03-01 01:27:50 +00:00
|
|
|
|
2020-05-01 13:26:32 +00:00
|
|
|
ret = TRUE;
|
|
|
|
|
2020-03-02 12:23:07 +00:00
|
|
|
done:
|
|
|
|
/* thaw all notifies */
|
|
|
|
/* Ignore notifies for the start and duration since the child should
|
|
|
|
* already be correctly set up */
|
|
|
|
container->children_control_mode = GES_CHILDREN_IGNORE_NOTIFIES;
|
|
|
|
g_object_thaw_notify (G_OBJECT (container));
|
|
|
|
for (tmp = current_children; tmp; tmp = tmp->next)
|
|
|
|
g_object_thaw_notify (G_OBJECT (tmp->data));
|
|
|
|
g_object_thaw_notify (G_OBJECT (child));
|
|
|
|
g_list_free_full (current_children, gst_object_unref);
|
2020-04-06 11:21:54 +00:00
|
|
|
gst_object_unref (child);
|
2020-03-02 12:23:07 +00:00
|
|
|
container->children_control_mode = GES_CHILDREN_UPDATE;
|
|
|
|
return ret;
|
2013-03-01 01:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_container_remove:
|
2020-01-08 09:26:07 +00:00
|
|
|
* @container: A #GESContainer
|
|
|
|
* @child: The child to remove
|
2013-03-01 01:27:50 +00:00
|
|
|
*
|
2020-01-08 09:26:07 +00:00
|
|
|
* Removes a timeline element from the container. The element will no
|
|
|
|
* longer be controlled by the container.
|
2013-03-01 01:27:50 +00:00
|
|
|
*
|
2020-01-08 09:26:07 +00:00
|
|
|
* Returns: %TRUE if @child was successfully removed from @container.
|
2013-03-01 01:27:50 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2013-03-01 22:18:10 +00:00
|
|
|
ges_container_remove (GESContainer * container, GESTimelineElement * child)
|
2013-03-01 01:27:50 +00:00
|
|
|
{
|
|
|
|
GESContainerClass *klass;
|
|
|
|
GESContainerPrivate *priv;
|
2020-03-02 12:23:07 +00:00
|
|
|
GList *current_children, *tmp;
|
|
|
|
gboolean ret = FALSE;
|
2013-03-01 01:27:50 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GES_IS_CONTAINER (container), FALSE);
|
2013-03-01 22:18:10 +00:00
|
|
|
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (child), FALSE);
|
2013-03-01 01:27:50 +00:00
|
|
|
|
2013-03-01 22:18:10 +00:00
|
|
|
GST_DEBUG_OBJECT (container, "removing child: %" GST_PTR_FORMAT, child);
|
2013-03-01 01:27:50 +00:00
|
|
|
|
|
|
|
klass = GES_CONTAINER_GET_CLASS (container);
|
|
|
|
priv = container->priv;
|
|
|
|
|
2013-03-01 22:18:10 +00:00
|
|
|
if (!(g_hash_table_lookup (priv->mappings, child))) {
|
2013-03-01 01:27:50 +00:00
|
|
|
GST_WARNING_OBJECT (container, "Element isn't controlled by this "
|
|
|
|
"container");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-03-02 12:23:07 +00:00
|
|
|
/* ref the container since it might be destroyed when the child is
|
|
|
|
* removed! (see GESGroup ->child_removed) */
|
|
|
|
gst_object_ref (container);
|
|
|
|
/* freeze all notifies */
|
|
|
|
g_object_freeze_notify (G_OBJECT (container));
|
|
|
|
/* copy to use at end, since container->children may have child
|
|
|
|
* removed from it */
|
|
|
|
current_children = g_list_copy_deep (container->children,
|
|
|
|
(GCopyFunc) gst_object_ref, NULL);
|
|
|
|
for (tmp = current_children; tmp; tmp = tmp->next)
|
|
|
|
g_object_freeze_notify (G_OBJECT (tmp->data));
|
|
|
|
|
|
|
|
|
2013-03-01 01:27:50 +00:00
|
|
|
if (klass->remove_child) {
|
2013-03-01 22:18:10 +00:00
|
|
|
if (klass->remove_child (container, child) == FALSE)
|
2020-03-02 12:23:07 +00:00
|
|
|
goto done;
|
2013-03-01 01:27:50 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 22:18:10 +00:00
|
|
|
container->children = g_list_remove (container->children, child);
|
|
|
|
g_hash_table_remove (priv->mappings, child);
|
2013-03-01 01:27:50 +00:00
|
|
|
|
2015-02-19 17:19:44 +00:00
|
|
|
_ges_container_remove_child_properties (container, child);
|
|
|
|
|
2015-09-24 11:21:15 +00:00
|
|
|
if (!g_list_find (container->priv->adding_children, child)) {
|
|
|
|
g_signal_emit (container, ges_container_signals[CHILD_REMOVED_SIGNAL], 0,
|
|
|
|
child);
|
|
|
|
} else {
|
2020-03-18 14:12:55 +00:00
|
|
|
GESContainerClass *klass = GES_CONTAINER_GET_CLASS (container);
|
|
|
|
|
|
|
|
if (klass->child_removed)
|
|
|
|
klass->child_removed (container, child);
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (container,
|
|
|
|
"Not emitting 'child-removed' signal as child"
|
2015-09-24 11:21:15 +00:00
|
|
|
" removal happend during 'child-added' signal emission");
|
|
|
|
}
|
2013-03-01 01:27:50 +00:00
|
|
|
|
2020-04-18 15:34:56 +00:00
|
|
|
_update_start_duration (container, child);
|
|
|
|
|
2020-03-02 12:23:07 +00:00
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
done:
|
|
|
|
/* thaw all notifies */
|
|
|
|
g_object_thaw_notify (G_OBJECT (container));
|
|
|
|
for (tmp = current_children; tmp; tmp = tmp->next)
|
|
|
|
g_object_thaw_notify (G_OBJECT (tmp->data));
|
|
|
|
g_list_free_full (current_children, gst_object_unref);
|
|
|
|
|
|
|
|
gst_object_unref (container);
|
|
|
|
|
|
|
|
return ret;
|
2013-03-01 01:27:50 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 19:24:28 +00:00
|
|
|
static void
|
|
|
|
_get_children_recursively (GESContainer * container, GList ** children)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
|
|
|
|
|
|
|
*children =
|
|
|
|
g_list_concat (*children, g_list_copy_deep (container->children,
|
|
|
|
(GCopyFunc) gst_object_ref, NULL));
|
|
|
|
|
|
|
|
for (tmp = container->children; tmp; tmp = tmp->next) {
|
|
|
|
GESTimelineElement *element = tmp->data;
|
|
|
|
|
|
|
|
if (GES_IS_CONTAINER (element))
|
|
|
|
_get_children_recursively (tmp->data, children);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 01:27:50 +00:00
|
|
|
/**
|
|
|
|
* ges_container_get_children:
|
2020-01-08 09:26:07 +00:00
|
|
|
* @container: A #GESContainer
|
2013-07-10 19:24:28 +00:00
|
|
|
* @recursive: Whether to recursively get children in @container
|
2013-03-01 01:27:50 +00:00
|
|
|
*
|
2020-01-08 09:26:07 +00:00
|
|
|
* Get the list of timeline elements contained in the container. If
|
|
|
|
* @recursive is %TRUE, and the container contains other containers as
|
|
|
|
* children, then their children will be added to the list, in addition to
|
|
|
|
* themselves, and so on.
|
2013-03-01 01:27:50 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full) (element-type GESTimelineElement): The list of
|
2020-01-08 09:26:07 +00:00
|
|
|
* #GESTimelineElement-s contained in @container.
|
2013-03-01 01:27:50 +00:00
|
|
|
*/
|
|
|
|
GList *
|
2013-07-10 19:24:28 +00:00
|
|
|
ges_container_get_children (GESContainer * container, gboolean recursive)
|
2013-03-01 01:27:50 +00:00
|
|
|
{
|
2013-07-10 19:24:28 +00:00
|
|
|
GList *children = NULL;
|
|
|
|
|
2013-03-01 01:27:50 +00:00
|
|
|
g_return_val_if_fail (GES_IS_CONTAINER (container), NULL);
|
|
|
|
|
2013-07-10 19:24:28 +00:00
|
|
|
if (!recursive)
|
|
|
|
return g_list_copy_deep (container->children, (GCopyFunc) gst_object_ref,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
_get_children_recursively (container, &children);
|
|
|
|
return children;
|
2013-03-01 01:27:50 +00:00
|
|
|
}
|
2013-03-01 23:25:17 +00:00
|
|
|
|
|
|
|
/**
|
2013-03-02 21:35:34 +00:00
|
|
|
* ges_container_ungroup:
|
2020-01-08 09:26:07 +00:00
|
|
|
* @container: (transfer full): The container to ungroup
|
|
|
|
* @recursive: Whether to recursively ungroup @container
|
|
|
|
*
|
|
|
|
* Ungroups the container by splitting it into several containers
|
|
|
|
* containing various children of the original. The rules for how the
|
|
|
|
* container splits depends on the subclass. A #GESGroup will simply split
|
|
|
|
* into its children. A #GESClip will split into one #GESClip per
|
|
|
|
* #GESTrackType it overlaps with (so an audio-video clip will split into
|
|
|
|
* an audio clip and a video clip), where each clip contains all the
|
|
|
|
* #GESTrackElement-s from the original clip with a matching
|
|
|
|
* #GESTrackElement:track-type.
|
2013-03-01 23:25:17 +00:00
|
|
|
*
|
2020-01-08 09:26:07 +00:00
|
|
|
* If @recursive is %TRUE, and the container contains other containers as
|
|
|
|
* children, then they will also be ungrouped, and so on.
|
2013-03-01 23:25:17 +00:00
|
|
|
*
|
2013-06-28 16:56:17 +00:00
|
|
|
* Returns: (transfer full) (element-type GESContainer): The list of
|
2020-01-08 09:26:07 +00:00
|
|
|
* new #GESContainer-s created from the splitting of @container.
|
2013-03-01 23:25:17 +00:00
|
|
|
*/
|
|
|
|
GList *
|
|
|
|
ges_container_ungroup (GESContainer * container, gboolean recursive)
|
|
|
|
{
|
|
|
|
GESContainerClass *klass;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GES_IS_CONTAINER (container), NULL);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (container, "Ungrouping container %s recursively",
|
|
|
|
recursive ? "" : "not");
|
|
|
|
|
|
|
|
klass = GES_CONTAINER_GET_CLASS (container);
|
|
|
|
if (klass->ungroup == NULL) {
|
|
|
|
GST_INFO_OBJECT (container, "No ungoup virtual method, doint nothing");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return klass->ungroup (container, recursive);
|
|
|
|
}
|
2013-03-02 21:35:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_container_group:
|
2020-01-08 09:26:07 +00:00
|
|
|
* @containers: (transfer none)(element-type GESContainer) (allow-none):
|
|
|
|
* The #GESContainer-s to group
|
2013-03-02 21:35:34 +00:00
|
|
|
*
|
2020-01-08 09:26:07 +00:00
|
|
|
* Groups the containers into a single container by merging them. The
|
|
|
|
* containers must all belong to the same #GESTimelineElement:timeline.
|
2013-03-02 21:35:34 +00:00
|
|
|
*
|
2020-01-08 09:26:07 +00:00
|
|
|
* If the elements are all #GESClip-s then this method will attempt to
|
|
|
|
* combine them all into a single #GESClip. This should succeed if they:
|
|
|
|
* share the same #GESTimelineElement:start, #GESTimelineElement:duration
|
|
|
|
* and #GESTimelineElement:in-point; exist in the same layer; and all of
|
|
|
|
* the sources share the same #GESAsset. If this fails, or one of the
|
|
|
|
* elements is not a #GESClip, this method will try to create a #GESGroup
|
|
|
|
* instead.
|
|
|
|
*
|
|
|
|
* Returns: (transfer floating): The container created by merging
|
|
|
|
* @containers, or %NULL if they could not be merged into a single
|
|
|
|
* container.
|
2013-03-02 21:35:34 +00:00
|
|
|
*/
|
|
|
|
GESContainer *
|
|
|
|
ges_container_group (GList * containers)
|
|
|
|
{
|
|
|
|
GList *tmp;
|
2013-03-23 08:46:38 +00:00
|
|
|
guint n_children;
|
|
|
|
GType *children_types;
|
2013-03-02 21:35:34 +00:00
|
|
|
GESTimelineElement *element;
|
|
|
|
GObjectClass *clip_class;
|
|
|
|
|
2013-03-23 08:46:38 +00:00
|
|
|
guint i = 0;
|
|
|
|
GESContainer *ret = NULL;
|
2013-09-02 17:57:15 +00:00
|
|
|
GESTimeline *timeline = NULL;
|
2013-03-23 08:46:38 +00:00
|
|
|
|
2013-07-10 21:33:51 +00:00
|
|
|
if (containers) {
|
|
|
|
element = GES_TIMELINE_ELEMENT (containers->data);
|
|
|
|
timeline = GES_TIMELINE_ELEMENT_TIMELINE (element);
|
|
|
|
g_return_val_if_fail (timeline, NULL);
|
|
|
|
}
|
2013-03-02 21:35:34 +00:00
|
|
|
|
2020-01-08 09:26:07 +00:00
|
|
|
if (g_list_length (containers) == 1) {
|
|
|
|
/* FIXME: Should return a floating **copy**. API specifies that the
|
|
|
|
* returned element is created. So users might expect to be able to
|
|
|
|
* freely dispose of the list, without the risk of the returned
|
|
|
|
* element being freed as well.
|
|
|
|
* TODO 2.0: (transfer full) would have been better */
|
2013-03-02 21:35:34 +00:00
|
|
|
return containers->data;
|
2020-01-08 09:26:07 +00:00
|
|
|
}
|
2013-03-02 21:35:34 +00:00
|
|
|
|
|
|
|
for (tmp = containers; tmp; tmp = tmp->next) {
|
|
|
|
g_return_val_if_fail (GES_IS_CONTAINER (tmp->data), NULL);
|
2013-06-28 23:15:59 +00:00
|
|
|
g_return_val_if_fail (GES_TIMELINE_ELEMENT_PARENT (tmp->data) == NULL,
|
|
|
|
NULL);
|
|
|
|
g_return_val_if_fail (GES_TIMELINE_ELEMENT_TIMELINE (tmp->data) == timeline,
|
|
|
|
NULL);
|
2013-03-02 21:35:34 +00:00
|
|
|
}
|
|
|
|
|
2020-01-08 09:26:07 +00:00
|
|
|
/* FIXME: how can user sub-classes interact with this if
|
|
|
|
* ->grouping_priority is private? */
|
2013-03-23 08:46:38 +00:00
|
|
|
children_types = g_type_children (GES_TYPE_CONTAINER, &n_children);
|
|
|
|
g_qsort_with_data (children_types, n_children, sizeof (GType),
|
|
|
|
(GCompareDataFunc) compare_grouping_prio, NULL);
|
|
|
|
|
|
|
|
for (i = 0; i < n_children; i++) {
|
|
|
|
clip_class = g_type_class_peek (children_types[i]);
|
2020-01-08 09:26:07 +00:00
|
|
|
/* FIXME: handle NULL ->group */
|
2013-03-23 08:46:38 +00:00
|
|
|
ret = GES_CONTAINER_CLASS (clip_class)->group (containers);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
2013-03-02 21:35:34 +00:00
|
|
|
|
2013-03-23 08:46:38 +00:00
|
|
|
g_free (children_types);
|
2013-03-02 21:35:34 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2013-06-28 15:23:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ges_container_edit:
|
2020-01-08 09:26:07 +00:00
|
|
|
* @container: The #GESContainer to edit
|
|
|
|
* @layers: (element-type GESLayer) (nullable): A whitelist of layers
|
|
|
|
* where the edit can be performed, %NULL allows all layers in the
|
|
|
|
* timeline
|
|
|
|
* @new_layer_priority: The priority/index of the layer @container should
|
|
|
|
* be moved to. -1 means no move
|
|
|
|
* @mode: The edit mode
|
|
|
|
* @edge: The edge of @container where the edit should occur
|
|
|
|
* @position: The edit position: a new location for the edge of @container
|
|
|
|
* (in nanoseconds)
|
2013-06-28 15:23:27 +00:00
|
|
|
*
|
2020-01-08 09:26:07 +00:00
|
|
|
* Edits the container within its timeline.
|
2013-06-28 15:23:27 +00:00
|
|
|
*
|
2020-01-08 09:26:07 +00:00
|
|
|
* Returns: %TRUE if the edit of @container completed, %FALSE on failure.
|
2019-05-01 16:09:45 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 1.18: use #ges_timeline_element_edit instead.
|
2013-06-28 15:23:27 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
ges_container_edit (GESContainer * container, GList * layers,
|
|
|
|
gint new_layer_priority, GESEditMode mode, GESEdge edge, guint64 position)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GES_IS_CONTAINER (container), FALSE);
|
|
|
|
|
2019-05-01 16:09:45 +00:00
|
|
|
return ges_timeline_element_edit (GES_TIMELINE_ELEMENT (container),
|
|
|
|
layers, new_layer_priority, mode, edge, position);
|
2013-06-28 15:23:27 +00:00
|
|
|
}
|