gstreamer/ges/ges-layer.c

776 lines
22 KiB
C
Raw Normal View History

2009-08-04 15:13:11 +00:00
/* GStreamer Editing Services
2009-11-30 14:14:25 +00:00
* Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
* 2009 Nokia Corporation
2011-12-22 20:21:37 +00:00
* 2011 Mathieu Duponchelle <mathieu.duponchelle@epitech.eu>
* 2013 Thibault Saunier <thibault.saunier@collabora.com>
2009-08-04 15:13:11 +00:00
*
* 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
2012-11-04 00:25:20 +00:00
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
2009-08-04 15:13:11 +00:00
*/
/**
* SECTION:geslayer
* @title: GESLayer
2013-01-20 15:42:29 +00:00
* @short_description: Non-overlapping sequence of GESClip
2009-08-04 15:13:11 +00:00
*
2013-01-20 15:42:29 +00:00
* Responsible for the ordering of the various contained Clip(s). A
2010-05-31 16:59:12 +00:00
* timeline layer has a "priority" property, which is used to manage the
2013-01-20 15:42:29 +00:00
* priorities of individual Clips. Two layers should not have the
2010-05-31 16:59:12 +00:00
* same priority within a given timeline.
2009-08-04 15:13:11 +00:00
*/
#include "ges-internal.h"
2013-04-23 23:04:04 +00:00
#include "ges-layer.h"
#include "ges.h"
#include "ges-source-clip.h"
static void ges_meta_container_interface_init
(GESMetaContainerInterface * iface);
2013-04-23 23:04:04 +00:00
G_DEFINE_TYPE_WITH_CODE (GESLayer, ges_layer,
G_TYPE_INITIALLY_UNOWNED, G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE, NULL)
G_IMPLEMENT_INTERFACE (GES_TYPE_META_CONTAINER,
ges_meta_container_interface_init));
2013-04-23 23:04:04 +00:00
struct _GESLayerPrivate
2010-12-04 18:54:13 +00:00
{
/*< private > */
GList *clips_start; /* The Clips sorted by start and
* priority */
2012-04-08 01:24:18 +00:00
guint32 priority; /* The priority of the layer within the
* containing timeline */
gboolean auto_transition;
2010-12-04 18:54:13 +00:00
};
typedef struct
{
GESClip *clip;
2013-04-23 23:04:04 +00:00
GESLayer *layer;
} NewAssetUData;
enum
{
PROP_0,
PROP_PRIORITY,
PROP_AUTO_TRANSITION,
PROP_LAST
};
enum
{
OBJECT_ADDED,
OBJECT_REMOVED,
LAST_SIGNAL
};
2013-04-23 23:04:04 +00:00
static guint ges_layer_signals[LAST_SIGNAL] = { 0 };
2012-04-08 01:24:18 +00:00
/* GObject standard vmethods */
static void
2013-04-23 23:04:04 +00:00
ges_layer_get_property (GObject * object, guint property_id,
2009-08-04 15:16:31 +00:00
GValue * value, GParamSpec * pspec)
2009-08-04 15:13:11 +00:00
{
2013-04-23 23:04:04 +00:00
GESLayer *layer = GES_LAYER (object);
2009-08-04 15:13:11 +00:00
switch (property_id) {
case PROP_PRIORITY:
g_value_set_uint (value, layer->priv->priority);
break;
case PROP_AUTO_TRANSITION:
g_value_set_boolean (value, layer->priv->auto_transition);
break;
2009-08-04 15:16:31 +00:00
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2009-08-04 15:13:11 +00:00
}
}
static void
2013-04-23 23:04:04 +00:00
ges_layer_set_property (GObject * object, guint property_id,
2009-08-04 15:16:31 +00:00
const GValue * value, GParamSpec * pspec)
2009-08-04 15:13:11 +00:00
{
2013-04-23 23:04:04 +00:00
GESLayer *layer = GES_LAYER (object);
2009-08-04 15:13:11 +00:00
switch (property_id) {
case PROP_PRIORITY:
2013-04-23 23:04:04 +00:00
ges_layer_set_priority (layer, g_value_get_uint (value));
break;
case PROP_AUTO_TRANSITION:
2013-04-23 23:04:04 +00:00
ges_layer_set_auto_transition (layer, g_value_get_boolean (value));
break;
2009-08-04 15:16:31 +00:00
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2009-08-04 15:13:11 +00:00
}
}
static void
2013-04-23 23:04:04 +00:00
ges_layer_dispose (GObject * object)
2009-08-04 15:13:11 +00:00
{
2013-04-23 23:04:04 +00:00
GESLayer *layer = GES_LAYER (object);
GESLayerPrivate *priv = layer->priv;
GST_DEBUG ("Disposing layer");
while (priv->clips_start)
2013-04-23 23:04:04 +00:00
ges_layer_remove_clip (layer, (GESClip *) priv->clips_start->data);
2013-04-23 23:04:04 +00:00
G_OBJECT_CLASS (ges_layer_parent_class)->dispose (object);
2009-08-04 15:13:11 +00:00
}
static gboolean
_register_metas (GESLayer * layer)
{
ges_meta_container_register_meta_float (GES_META_CONTAINER (layer),
GES_META_READ_WRITE, GES_META_VOLUME, 1.0);
return TRUE;
}
static void
ges_meta_container_interface_init (GESMetaContainerInterface * iface)
{
}
2009-08-04 15:13:11 +00:00
static void
2013-04-23 23:04:04 +00:00
ges_layer_class_init (GESLayerClass * klass)
2009-08-04 15:13:11 +00:00
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
2013-04-23 23:04:04 +00:00
g_type_class_add_private (klass, sizeof (GESLayerPrivate));
2010-12-04 18:54:13 +00:00
2013-04-23 23:04:04 +00:00
object_class->get_property = ges_layer_get_property;
object_class->set_property = ges_layer_set_property;
object_class->dispose = ges_layer_dispose;
/**
2013-04-23 23:04:04 +00:00
* GESLayer:priority:
*
* The priority of the layer in the #GESTimeline. 0 is the highest
2013-04-23 23:04:04 +00:00
* priority. Conceptually, a #GESTimeline is a stack of GESLayers,
2010-05-31 16:59:12 +00:00
* and the priority of the layer represents its position in the stack. Two
* layers should not have the same priority within a given GESTimeline.
2015-05-19 16:18:30 +00:00
*
* Note that the timeline needs to be commited (with #ges_timeline_commit)
* for the change to be taken into account.
*/
g_object_class_install_property (object_class, PROP_PRIORITY,
g_param_spec_uint ("priority", "Priority",
"The priority of the layer", 0, G_MAXUINT, 0, G_PARAM_READWRITE));
/**
2013-04-23 23:04:04 +00:00
* GESLayer:auto-transition:
*
* Sets whether transitions are added automagically when clips overlap.
*/
g_object_class_install_property (object_class, PROP_AUTO_TRANSITION,
g_param_spec_boolean ("auto-transition", "Auto-Transition",
"whether the transitions are added", FALSE, G_PARAM_READWRITE));
2009-09-16 10:37:45 +00:00
/**
2013-04-23 23:04:04 +00:00
* GESLayer::clip-added:
* @layer: the #GESLayer
* @clip: the #GESClip that was added.
2009-09-16 10:37:45 +00:00
*
* Will be emitted after the clip was added to the layer.
2009-09-16 10:37:45 +00:00
*/
2013-04-23 23:04:04 +00:00
ges_layer_signals[OBJECT_ADDED] =
g_signal_new ("clip-added", G_TYPE_FROM_CLASS (klass),
2013-04-23 23:04:04 +00:00
G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESLayerClass, object_added),
2013-01-20 15:42:29 +00:00
NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GES_TYPE_CLIP);
2009-09-16 10:37:45 +00:00
/**
2013-04-23 23:04:04 +00:00
* GESLayer::clip-removed:
* @layer: the #GESLayer
* @clip: the #GESClip that was removed
2009-09-16 10:37:45 +00:00
*
* Will be emitted after the clip was removed from the layer.
2009-09-16 10:37:45 +00:00
*/
2013-04-23 23:04:04 +00:00
ges_layer_signals[OBJECT_REMOVED] =
g_signal_new ("clip-removed", G_TYPE_FROM_CLASS (klass),
2013-04-23 23:04:04 +00:00
G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESLayerClass,
object_removed), NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE,
2013-01-20 15:42:29 +00:00
1, GES_TYPE_CLIP);
2009-08-04 15:13:11 +00:00
}
static void
2013-04-23 23:04:04 +00:00
ges_layer_init (GESLayer * self)
2009-08-04 15:13:11 +00:00
{
2010-12-04 18:54:13 +00:00
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
2013-04-23 23:04:04 +00:00
GES_TYPE_LAYER, GESLayerPrivate);
2010-12-04 18:54:13 +00:00
self->priv->priority = 0;
self->priv->auto_transition = FALSE;
Cleanup import of GNL and rename gnl to nle for Non Linear Engine Conflicts: ges/ges-track-element.c gnl/Makefile.am gnl/common Conflicts: ges/ges-internal.h ges/ges-track.c ges/ges-utils.c ges/nle/.gitignore ges/nle/gnlmarshal.list ges/nle/nle.h ges/nle/nlecomposition.c ges/nle/nlecomposition.h ges/nle/nleghostpad.c ges/nle/nleghostpad.h ges/nle/nleobject.c ges/nle/nleoperation.c ges/nle/nleoperation.h ges/nle/nlesource.c ges/nle/nlesource.h ges/nle/nletypes.h ges/nle/nleurisource.c ges/nle/nleurisource.h gnl/Makefile.am gnl/gnl.c gnl/gnl.h gnl/gnl/gnl.h gnl/gnl/gnlcomposition.c gnl/gnl/gnlcomposition.h gnl/gnl/gnlghostpad.c gnl/gnl/gnlghostpad.h gnl/gnl/gnlmarshal.list gnl/gnl/gnlobject.c gnl/gnl/gnloperation.c gnl/gnl/gnloperation.h gnl/gnl/gnlsource.c gnl/gnl/gnlsource.h gnl/gnl/gnltypes.h gnl/gnl/gnlurisource.c gnl/gnl/gnlurisource.h gnl/gnlcomposition.c gnl/gnlcomposition.h gnl/gnlghostpad.c gnl/gnlghostpad.h gnl/gnlmarshal.list gnl/gnlobject.c gnl/gnlobject.h gnl/gnloperation.c gnl/gnloperation.h gnl/gnlsource.c gnl/gnlsource.h gnl/gnltypes.h gnl/gnlurisource.c gnl/gnlurisource.h gnl/tests/check/gnl/common.c gnl/tests/check/gnl/common.h gnl/tests/check/gnl/complex.c gnl/tests/check/gnl/gnlcomposition.c gnl/tests/check/gnl/gnloperation.c gnl/tests/check/gnl/gnlsource.c gnl/tests/check/gnl/seek.c gnl/tests/check/gnl/simple.c tests/check/gnl/common.c tests/check/gnl/common.h tests/check/gnl/complex.c tests/check/gnl/gnlcomposition.c tests/check/gnl/gnloperation.c tests/check/gnl/gnlsource.c tests/check/gnl/seek.c tests/check/gnl/simple.c tests/check/nle/common.c tests/check/nle/common.h tests/check/nle/complex.c tests/check/nle/nlecomposition.c tests/check/nle/nleoperation.c tests/check/nle/nlesource.c tests/check/nle/seek.c tests/check/nle/simple.c
2014-08-15 13:48:14 +00:00
self->min_nle_priority = MIN_NLE_PRIO;
self->max_nle_priority = LAYER_HEIGHT + MIN_NLE_PRIO;
_register_metas (self);
}
static gint
ges_layer_resync_priorities_by_type (GESLayer * layer,
gint starting_priority, GType type)
2012-04-08 01:24:18 +00:00
{
GstClockTime next_reset = 0;
gint priority = starting_priority, max_priority = priority;
2012-04-08 01:24:18 +00:00
GList *tmp;
GESTimelineElement *element;
for (tmp = layer->priv->clips_start; tmp; tmp = tmp->next) {
element = GES_TIMELINE_ELEMENT (tmp->data);
if (GES_IS_TRANSITION_CLIP (element)) {
/* Blindly set transitions priorities to 0 */
_set_priority0 (element, 0);
continue;
} else if (!g_type_is_a (G_OBJECT_TYPE (element), type))
continue;
if (element->start > next_reset) {
priority = starting_priority;
next_reset = 0;
}
if (element->start + element->duration > next_reset)
next_reset = element->start + element->duration;
_set_priority0 (element, priority);
priority = priority + GES_CONTAINER_HEIGHT (element);
if (priority > max_priority)
max_priority = priority;
}
return max_priority;
}
/**
* ges_layer_resync_priorities:
* @layer: a #GESLayer
*
* Resyncs the priorities of the clips controlled by @layer.
*/
gboolean
ges_layer_resync_priorities (GESLayer * layer)
{
gint min_source_prios;
GST_INFO_OBJECT (layer, "Resync priorities (prio: %d)",
layer->priv->priority);
min_source_prios = ges_layer_resync_priorities_by_type (layer, 1,
GES_TYPE_OPERATION_CLIP);
ges_layer_resync_priorities_by_type (layer, min_source_prios,
GES_TYPE_SOURCE_CLIP);
2012-04-08 01:24:18 +00:00
return TRUE;
}
static void
new_asset_cb (GESAsset * source, GAsyncResult * res, NewAssetUData * udata)
{
GError *error = NULL;
GESAsset *asset = ges_asset_request_finish (res, &error);
GST_DEBUG_OBJECT (udata->layer, "%" GST_PTR_FORMAT " Asset loaded, "
"setting its asset", udata->clip);
if (error) {
GESProject *project = udata->layer->timeline ?
GES_PROJECT (ges_extractable_get_asset (GES_EXTRACTABLE
(udata->layer->timeline))) : NULL;
if (project) {
gchar *possible_id;
possible_id = ges_project_try_updating_id (project, source, error);
if (possible_id) {
ges_asset_request_async (ges_asset_get_extractable_type (source),
possible_id, NULL, (GAsyncReadyCallback) new_asset_cb, udata);
g_free (possible_id);
return;
}
}
GST_ERROR ("Asset could not be created for uri %s, error: %s",
ges_asset_get_id (asset), error->message);
} else {
GESProject *project = udata->layer->timeline ?
GES_PROJECT (ges_extractable_get_asset (GES_EXTRACTABLE
(udata->layer->timeline))) : NULL;
ges_extractable_set_asset (GES_EXTRACTABLE (udata->clip), asset);
ges_project_add_asset (project, asset);
/* clip was already ref-sinked when creating udata,
* gst_layer_add_clip() creates a new ref as such and
* below we unref the ref from udata */
2013-04-23 23:04:04 +00:00
ges_layer_add_clip (udata->layer, udata->clip);
}
gst_object_unref (asset);
gst_object_unref (udata->clip);
g_slice_free (NewAssetUData, udata);
}
/**
* ges_layer_get_duration:
* @layer: The #GESLayer to get the duration from
*
* Lets you retrieve the duration of the layer, which means
* the end time of the last clip inside it
*
* Returns: The duration of a layer
*/
GstClockTime
ges_layer_get_duration (GESLayer * layer)
{
GList *tmp;
GstClockTime duration = 0;
for (tmp = layer->priv->clips_start; tmp; tmp = tmp->next) {
duration = MAX (duration, _END (tmp->data));
}
return duration;
}
2012-04-08 01:24:18 +00:00
/* Public methods */
/**
2013-04-23 23:04:04 +00:00
* ges_layer_remove_clip:
* @layer: a #GESLayer
* @clip: the #GESClip to remove
*
* Removes the given @clip from the @layer and unparents it.
* Unparenting it means the reference owned by @layer on the @clip will be
* removed. If you wish to use the @clip after this function, make sure you
* call gst_object_ref() before removing it from the @layer.
*
* Returns: %TRUE if the clip could be removed, %FALSE if the layer does
* not want to remove the clip.
*/
gboolean
2013-04-23 23:04:04 +00:00
ges_layer_remove_clip (GESLayer * layer, GESClip * clip)
{
2013-04-23 23:04:04 +00:00
GESLayer *current_layer;
2013-04-23 23:04:04 +00:00
g_return_val_if_fail (GES_IS_LAYER (layer), FALSE);
g_return_val_if_fail (GES_IS_CLIP (clip), FALSE);
GST_DEBUG ("layer:%p, clip:%p", layer, clip);
current_layer = ges_clip_get_layer (clip);
if (G_UNLIKELY (current_layer != layer)) {
2013-01-20 15:42:29 +00:00
GST_WARNING ("Clip doesn't belong to this layer");
if (current_layer != NULL)
gst_object_unref (current_layer);
return FALSE;
}
gst_object_unref (current_layer);
/* Remove it from our list of controlled objects */
layer->priv->clips_start = g_list_remove (layer->priv->clips_start, clip);
/* emit 'clip-removed' */
2013-04-23 23:04:04 +00:00
g_signal_emit (layer, ges_layer_signals[OBJECT_REMOVED], 0, clip);
/* inform the clip it's no longer in a layer */
ges_clip_set_layer (clip, NULL);
/* so neither in a timeline */
if (layer->timeline)
ges_timeline_element_set_timeline (GES_TIMELINE_ELEMENT (clip), NULL);
/* Remove our reference to the clip */
gst_object_unref (clip);
return TRUE;
}
2010-07-06 14:27:08 +00:00
/**
2013-04-23 23:04:04 +00:00
* ges_layer_set_priority:
* @layer: a #GESLayer
2010-07-06 14:27:08 +00:00
* @priority: the priority to set
*
* Sets the layer to the given @priority. See the documentation of the
* priority property for more information.
2010-07-06 14:27:08 +00:00
*/
void
2013-04-23 23:04:04 +00:00
ges_layer_set_priority (GESLayer * layer, guint priority)
{
2013-04-23 23:04:04 +00:00
g_return_if_fail (GES_IS_LAYER (layer));
GST_DEBUG ("layer:%p, priority:%d", layer, priority);
if (priority != layer->priv->priority) {
layer->priv->priority = priority;
Cleanup import of GNL and rename gnl to nle for Non Linear Engine Conflicts: ges/ges-track-element.c gnl/Makefile.am gnl/common Conflicts: ges/ges-internal.h ges/ges-track.c ges/ges-utils.c ges/nle/.gitignore ges/nle/gnlmarshal.list ges/nle/nle.h ges/nle/nlecomposition.c ges/nle/nlecomposition.h ges/nle/nleghostpad.c ges/nle/nleghostpad.h ges/nle/nleobject.c ges/nle/nleoperation.c ges/nle/nleoperation.h ges/nle/nlesource.c ges/nle/nlesource.h ges/nle/nletypes.h ges/nle/nleurisource.c ges/nle/nleurisource.h gnl/Makefile.am gnl/gnl.c gnl/gnl.h gnl/gnl/gnl.h gnl/gnl/gnlcomposition.c gnl/gnl/gnlcomposition.h gnl/gnl/gnlghostpad.c gnl/gnl/gnlghostpad.h gnl/gnl/gnlmarshal.list gnl/gnl/gnlobject.c gnl/gnl/gnloperation.c gnl/gnl/gnloperation.h gnl/gnl/gnlsource.c gnl/gnl/gnlsource.h gnl/gnl/gnltypes.h gnl/gnl/gnlurisource.c gnl/gnl/gnlurisource.h gnl/gnlcomposition.c gnl/gnlcomposition.h gnl/gnlghostpad.c gnl/gnlghostpad.h gnl/gnlmarshal.list gnl/gnlobject.c gnl/gnlobject.h gnl/gnloperation.c gnl/gnloperation.h gnl/gnlsource.c gnl/gnlsource.h gnl/gnltypes.h gnl/gnlurisource.c gnl/gnlurisource.h gnl/tests/check/gnl/common.c gnl/tests/check/gnl/common.h gnl/tests/check/gnl/complex.c gnl/tests/check/gnl/gnlcomposition.c gnl/tests/check/gnl/gnloperation.c gnl/tests/check/gnl/gnlsource.c gnl/tests/check/gnl/seek.c gnl/tests/check/gnl/simple.c tests/check/gnl/common.c tests/check/gnl/common.h tests/check/gnl/complex.c tests/check/gnl/gnlcomposition.c tests/check/gnl/gnloperation.c tests/check/gnl/gnlsource.c tests/check/gnl/seek.c tests/check/gnl/simple.c tests/check/nle/common.c tests/check/nle/common.h tests/check/nle/complex.c tests/check/nle/nlecomposition.c tests/check/nle/nleoperation.c tests/check/nle/nlesource.c tests/check/nle/seek.c tests/check/nle/simple.c
2014-08-15 13:48:14 +00:00
layer->min_nle_priority = (priority * LAYER_HEIGHT) + MIN_NLE_PRIO;
layer->max_nle_priority = ((priority + 1) * LAYER_HEIGHT) + MIN_NLE_PRIO;
2013-04-23 23:04:04 +00:00
ges_layer_resync_priorities (layer);
}
2013-04-30 17:19:39 +00:00
g_object_notify (G_OBJECT (layer), "priority");
}
/**
2013-04-23 23:04:04 +00:00
* ges_layer_get_auto_transition:
* @layer: a #GESLayer
*
2012-01-12 15:34:13 +00:00
* Gets whether transitions are automatically added when objects
* overlap or not.
*
2012-01-12 15:34:13 +00:00
* Returns: %TRUE if transitions are automatically added, else %FALSE.
*/
gboolean
2013-04-23 23:04:04 +00:00
ges_layer_get_auto_transition (GESLayer * layer)
{
2013-04-23 23:04:04 +00:00
g_return_val_if_fail (GES_IS_LAYER (layer), 0);
return layer->priv->auto_transition;
}
/**
2013-04-23 23:04:04 +00:00
* ges_layer_set_auto_transition:
* @layer: a #GESLayer
2011-12-07 02:11:25 +00:00
* @auto_transition: whether the auto_transition is active
*
* Sets the layer to the given @auto_transition. See the documentation of the
2011-12-07 02:11:25 +00:00
* property auto_transition for more information.
*/
void
2013-04-23 23:04:04 +00:00
ges_layer_set_auto_transition (GESLayer * layer, gboolean auto_transition)
{
2011-11-02 16:51:36 +00:00
2013-04-23 23:04:04 +00:00
g_return_if_fail (GES_IS_LAYER (layer));
layer->priv->auto_transition = auto_transition;
g_object_notify (G_OBJECT (layer), "auto-transition");
}
/**
2013-04-23 23:04:04 +00:00
* ges_layer_get_priority:
* @layer: a #GESLayer
*
* Get the priority of @layer within the timeline.
*
* Returns: The priority of the @layer within the timeline.
*/
guint
2013-04-23 23:04:04 +00:00
ges_layer_get_priority (GESLayer * layer)
{
2013-04-23 23:04:04 +00:00
g_return_val_if_fail (GES_IS_LAYER (layer), 0);
return layer->priv->priority;
}
/**
2013-04-23 23:04:04 +00:00
* ges_layer_get_clips:
* @layer: a #GESLayer
*
* Get the clips this layer contains.
*
2013-01-20 15:42:29 +00:00
* Returns: (transfer full) (element-type GESClip): a #GList of
* clips. The user is responsible for
* unreffing the contained objects and freeing the list.
*/
GList *
2013-04-23 23:04:04 +00:00
ges_layer_get_clips (GESLayer * layer)
{
2013-04-23 23:04:04 +00:00
GESLayerClass *klass;
2013-04-23 23:04:04 +00:00
g_return_val_if_fail (GES_IS_LAYER (layer), NULL);
2013-04-23 23:04:04 +00:00
klass = GES_LAYER_GET_CLASS (layer);
if (klass->get_objects) {
return klass->get_objects (layer);
}
return g_list_sort (g_list_copy_deep (layer->priv->clips_start,
(GCopyFunc) gst_object_ref, NULL),
(GCompareFunc) element_start_compare);
}
/**
2013-04-23 23:04:04 +00:00
* ges_layer_is_empty:
* @layer: The #GESLayer to check
*
* Convenience method to check if @layer is empty (doesn't contain any clip),
* or not.
*
* Returns: %TRUE if @layer is empty, %FALSE if it already contains at least
2013-01-20 15:42:29 +00:00
* one #GESClip
*/
gboolean
2013-04-23 23:04:04 +00:00
ges_layer_is_empty (GESLayer * layer)
{
2013-04-23 23:04:04 +00:00
g_return_val_if_fail (GES_IS_LAYER (layer), FALSE);
return (layer->priv->clips_start == NULL);
}
2012-04-08 01:24:18 +00:00
/**
2013-04-23 23:04:04 +00:00
* ges_layer_add_clip:
* @layer: a #GESLayer
* @clip: (transfer floating): the #GESClip to add.
2012-04-08 01:24:18 +00:00
*
* Adds the given clip to the layer. Sets the clip's parent, and thus
* takes ownership of the clip.
2012-04-08 01:24:18 +00:00
*
* An clip can only be added to one layer.
2012-04-08 01:24:18 +00:00
*
* Calling this method will construct and properly set all the media related
* elements on @clip. If you need to know when those objects (actually #GESTrackElement)
* are constructed, you should connect to the container::child-added signal which
2012-04-08 01:24:18 +00:00
* is emited right after those elements are ready to be used.
*
* Returns: %TRUE if the clip was properly added to the layer, or %FALSE
* if the @layer refuses to add the clip.
2012-04-08 01:24:18 +00:00
*/
gboolean
2013-04-23 23:04:04 +00:00
ges_layer_add_clip (GESLayer * layer, GESClip * clip)
2012-04-08 01:24:18 +00:00
{
GESAsset *asset;
2013-04-23 23:04:04 +00:00
GESLayerPrivate *priv;
GESLayer *current_layer;
2012-04-08 01:24:18 +00:00
2013-04-23 23:04:04 +00:00
g_return_val_if_fail (GES_IS_LAYER (layer), FALSE);
g_return_val_if_fail (GES_IS_CLIP (clip), FALSE);
2012-04-08 01:24:18 +00:00
GST_DEBUG_OBJECT (layer, "adding clip:%p", clip);
2012-04-08 01:24:18 +00:00
priv = layer->priv;
current_layer = ges_clip_get_layer (clip);
if (G_UNLIKELY (current_layer)) {
GST_WARNING ("Clip %p already belongs to another layer", clip);
gst_object_ref_sink (clip);
gst_object_unref (current_layer);
2012-04-08 01:24:18 +00:00
return FALSE;
}
asset = ges_extractable_get_asset (GES_EXTRACTABLE (clip));
if (asset == NULL) {
gchar *id;
NewAssetUData *mudata = g_slice_new (NewAssetUData);
mudata->clip = gst_object_ref_sink (clip);
mudata->layer = layer;
GST_DEBUG_OBJECT (layer, "%" GST_PTR_FORMAT " as no reference to any "
"assets creating a asset... trying sync", clip);
id = ges_extractable_get_id (GES_EXTRACTABLE (clip));
asset = ges_asset_request (G_OBJECT_TYPE (clip), id, NULL);
if (asset == NULL) {
GESProject *project = layer->timeline ?
GES_PROJECT (ges_extractable_get_asset (GES_EXTRACTABLE
(layer->timeline))) : NULL;
ges_asset_request_async (G_OBJECT_TYPE (clip),
id, NULL, (GAsyncReadyCallback) new_asset_cb, mudata);
if (project)
ges_project_add_loading_asset (project, G_OBJECT_TYPE (clip), id);
g_free (id);
GST_LOG_OBJECT (layer, "Object added async");
return TRUE;
}
g_free (id);
ges_extractable_set_asset (GES_EXTRACTABLE (clip), asset);
g_slice_free (NewAssetUData, mudata);
} else {
gst_object_ref_sink (clip);
}
/* Take a reference to the clip and store it stored by start/priority */
priv->clips_start = g_list_insert_sorted (priv->clips_start, clip,
(GCompareFunc) element_start_compare);
2012-04-08 01:24:18 +00:00
/* Inform the clip it's now in this layer */
ges_clip_set_layer (clip, layer);
2012-04-08 01:24:18 +00:00
GST_DEBUG ("current clip priority : %d, Height: %d", _PRIORITY (clip),
LAYER_HEIGHT);
2012-04-08 01:24:18 +00:00
/* Set the priority. */
if (_PRIORITY (clip) > LAYER_HEIGHT) {
GST_WARNING_OBJECT (layer,
"%p is out of the layer space, setting its priority to "
"%d, setting it to the maximum priority of the layer: %d", clip,
_PRIORITY (clip), LAYER_HEIGHT - 1);
_set_priority0 (GES_TIMELINE_ELEMENT (clip), LAYER_HEIGHT - 1);
2012-04-08 01:24:18 +00:00
}
2013-04-23 23:04:04 +00:00
ges_layer_resync_priorities (layer);
ges_timeline_element_set_timeline (GES_TIMELINE_ELEMENT (clip),
layer->timeline);
2012-04-08 01:24:18 +00:00
/* emit 'clip-added' */
2013-04-23 23:04:04 +00:00
g_signal_emit (layer, ges_layer_signals[OBJECT_ADDED], 0, clip);
2012-04-08 01:24:18 +00:00
return TRUE;
}
/**
2013-04-23 23:04:04 +00:00
* ges_layer_add_asset:
* @layer: a #GESLayer
* @asset: The asset to add to
* @start: The start value to set on the new #GESClip,
* if @start == GST_CLOCK_TIME_NONE, it will be set to
* the current duration of @layer
2013-01-20 15:42:29 +00:00
* @inpoint: The inpoint value to set on the new #GESClip
* @duration: The duration value to set on the new #GESClip
* @track_types: The #GESTrackType to set on the the new #GESClip
*
2013-01-20 15:42:29 +00:00
* Creates Clip from asset, adds it to layer and
* returns a reference to it.
*
2013-01-20 15:42:29 +00:00
* Returns: (transfer none): Created #GESClip
2012-12-29 21:24:05 +00:00
*/
2013-01-20 15:42:29 +00:00
GESClip *
2013-04-23 23:04:04 +00:00
ges_layer_add_asset (GESLayer * layer,
GESAsset * asset, GstClockTime start, GstClockTime inpoint,
GstClockTime duration, GESTrackType track_types)
{
2013-01-20 15:42:29 +00:00
GESClip *clip;
2013-04-23 23:04:04 +00:00
g_return_val_if_fail (GES_IS_LAYER (layer), NULL);
g_return_val_if_fail (GES_IS_ASSET (asset), NULL);
g_return_val_if_fail (g_type_is_a (ges_asset_get_extractable_type
2013-01-20 15:42:29 +00:00
(asset), GES_TYPE_CLIP), NULL);
2013-01-10 15:41:13 +00:00
GST_DEBUG_OBJECT (layer, "Adding asset %s with: start: %" GST_TIME_FORMAT
" inpoint: %" GST_TIME_FORMAT " duration: %" GST_TIME_FORMAT
2013-01-10 15:41:13 +00:00
" track types: %d (%s)", ges_asset_get_id (asset), GST_TIME_ARGS (start),
GST_TIME_ARGS (inpoint), GST_TIME_ARGS (duration), track_types,
2013-01-10 15:41:13 +00:00
ges_track_type_name (track_types));
2013-01-20 15:42:29 +00:00
clip = GES_CLIP (ges_asset_extract (asset, NULL));
if (!GST_CLOCK_TIME_IS_VALID (start)) {
start = ges_layer_get_duration (layer);
GST_DEBUG_OBJECT (layer,
"No start specified, setting it to %" GST_TIME_FORMAT,
GST_TIME_ARGS (start));
}
2013-01-20 15:42:29 +00:00
_set_start0 (GES_TIMELINE_ELEMENT (clip), start);
_set_inpoint0 (GES_TIMELINE_ELEMENT (clip), inpoint);
if (track_types != GES_TRACK_TYPE_UNKNOWN)
2013-01-20 15:42:29 +00:00
ges_clip_set_supported_formats (clip, track_types);
if (GST_CLOCK_TIME_IS_VALID (duration)) {
2013-01-20 15:42:29 +00:00
_set_duration0 (GES_TIMELINE_ELEMENT (clip), duration);
}
2013-04-23 23:04:04 +00:00
if (!ges_layer_add_clip (layer, clip)) {
return NULL;
}
2013-01-20 15:42:29 +00:00
return clip;
}
2012-04-08 01:24:18 +00:00
/**
2013-04-23 23:04:04 +00:00
* ges_layer_new:
2012-04-08 01:24:18 +00:00
*
2013-04-23 23:04:04 +00:00
* Creates a new #GESLayer.
2012-04-08 01:24:18 +00:00
*
* Returns: (transfer floating): A new #GESLayer
2012-04-08 01:24:18 +00:00
*/
2013-04-23 23:04:04 +00:00
GESLayer *
ges_layer_new (void)
2012-04-08 01:24:18 +00:00
{
2013-04-23 23:04:04 +00:00
return g_object_new (GES_TYPE_LAYER, NULL);
2012-04-08 01:24:18 +00:00
}
/**
2013-04-23 23:04:04 +00:00
* ges_layer_get_timeline:
* @layer: The #GESLayer to get the parent #GESTimeline from
2012-04-08 01:24:18 +00:00
*
2013-04-23 23:04:04 +00:00
* Get the #GESTimeline in which #GESLayer currently is.
2012-04-08 01:24:18 +00:00
*
* Returns: (transfer none) (nullable): the #GESTimeline in which #GESLayer
2012-04-08 01:24:18 +00:00
* currently is or %NULL if not in any timeline yet.
*/
GESTimeline *
2013-04-23 23:04:04 +00:00
ges_layer_get_timeline (GESLayer * layer)
2012-04-08 01:24:18 +00:00
{
2013-04-23 23:04:04 +00:00
g_return_val_if_fail (GES_IS_LAYER (layer), NULL);
2012-04-08 01:24:18 +00:00
return layer->timeline;
}
void
2013-04-23 23:04:04 +00:00
ges_layer_set_timeline (GESLayer * layer, GESTimeline * timeline)
2012-04-08 01:24:18 +00:00
{
GList *tmp;
2012-04-08 01:24:18 +00:00
GST_DEBUG ("layer:%p, timeline:%p", layer, timeline);
for (tmp = layer->priv->clips_start; tmp; tmp = tmp->next) {
ges_timeline_element_set_timeline (tmp->data, timeline);
}
layer->timeline = timeline;
2012-04-08 01:24:18 +00:00
}
/**
* ges_layer_get_clips_in_interval:
* @layer: a #GESLayer
* @start: start of the interval
* @end: end of the interval
*
* Gets the clips which appear between @start and @end on @layer.
*
* Returns: (transfer full) (element-type GESClip): a #GList of clips intersecting [@start, @end) interval on @layer.
*/
GList *
ges_layer_get_clips_in_interval (GESLayer * layer, GstClockTime start,
GstClockTime end)
{
GList *tmp;
GList *intersecting_clips = NULL;
GstClockTime clip_start, clip_end;
gboolean clip_intersects;
for (tmp = layer->priv->clips_start; tmp; tmp = tmp->next) {
clip_intersects = FALSE;
clip_start = ges_timeline_element_get_start (tmp->data);
clip_end = clip_start + ges_timeline_element_get_duration (tmp->data);
if (start <= clip_start && clip_start < end)
clip_intersects = TRUE;
else if (start < clip_end && clip_end <= end)
clip_intersects = TRUE;
else if (clip_start < start && clip_end > end)
clip_intersects = TRUE;
if (clip_intersects)
intersecting_clips =
g_list_insert_sorted (intersecting_clips, tmp->data,
(GCompareFunc) element_start_compare);
}
return intersecting_clips;
}