1 /* GStreamer Editing Services
2 * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3 * 2009 Nokia Corporation
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:ges-timeline-layer
23 * @short_description: Non-overlaping sequence of #GESTimelineObject
25 * Responsible for the ordering of the various contained TimelineObject(s). A
26 * timeline layer has a "priority" property, which is used to manage the
27 * priorities of individual TimelineObjects. Two layers should not have the
28 * same priority within a given timeline.
31 #include "ges-internal.h"
32 #include "gesmarshal.h"
33 #include "ges-timeline-layer.h"
36 G_DEFINE_TYPE (GESTimelineLayer, ges_timeline_layer, G_TYPE_OBJECT);
51 static guint ges_timeline_layer_signals[LAST_SIGNAL] = { 0 };
54 ges_timeline_layer_get_property (GObject * object, guint property_id,
55 GValue * value, GParamSpec * pspec)
57 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
59 switch (property_id) {
61 g_value_set_uint (value, layer->priority);
64 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
69 ges_timeline_layer_set_property (GObject * object, guint property_id,
70 const GValue * value, GParamSpec * pspec)
72 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
74 switch (property_id) {
76 ges_timeline_layer_set_priority (layer, g_value_get_uint (value));
79 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
84 ges_timeline_layer_dispose (GObject * object)
86 GESTimelineLayer *layer = GES_TIMELINE_LAYER (object);
88 GST_DEBUG ("Disposing layer");
90 while (layer->objects_start) {
91 GESTimelineObject *obj = (GESTimelineObject *) layer->objects_start->data;
92 ges_timeline_layer_remove_object (layer, obj);
95 G_OBJECT_CLASS (ges_timeline_layer_parent_class)->dispose (object);
99 ges_timeline_layer_finalize (GObject * object)
101 G_OBJECT_CLASS (ges_timeline_layer_parent_class)->finalize (object);
105 ges_timeline_layer_class_init (GESTimelineLayerClass * klass)
107 GObjectClass *object_class = G_OBJECT_CLASS (klass);
109 object_class->get_property = ges_timeline_layer_get_property;
110 object_class->set_property = ges_timeline_layer_set_property;
111 object_class->dispose = ges_timeline_layer_dispose;
112 object_class->finalize = ges_timeline_layer_finalize;
115 * GESTimelineLayer:priority
117 * The priority of the layer in the #GESTimeline. 0 is the highest
118 * priority. Conceptually, a #GESTimeline is a stack of GESTimelineLayers,
119 * and the priority of the layer represents its position in the stack. Two
120 * layers should not have the same priority within a given GESTimeline.
122 g_object_class_install_property (object_class, PROP_PRIORITY,
123 g_param_spec_uint ("priority", "Priority",
124 "The priority of the layer", 0, G_MAXUINT, 0, G_PARAM_READWRITE));
127 * GESTimelineLayer::object-added
128 * @layer: the #GESTimelineLayer
129 * @object: the #GESTimelineObject that was added.
131 * Will be emitted after the object was added to the layer.
133 ges_timeline_layer_signals[OBJECT_ADDED] =
134 g_signal_new ("object-added", G_TYPE_FROM_CLASS (klass),
135 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass, object_added),
136 NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
137 GES_TYPE_TIMELINE_OBJECT);
140 * GESTimelineLayer::object-removed
141 * @layer: the #GESTimelineLayer
142 * @object: the #GESTimelineObject that was removed
144 * Will be emitted after the object was removed from the layer.
146 ges_timeline_layer_signals[OBJECT_REMOVED] =
147 g_signal_new ("object-removed", G_TYPE_FROM_CLASS (klass),
148 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass,
149 object_removed), NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
150 GES_TYPE_TIMELINE_OBJECT);
155 ges_timeline_layer_init (GESTimelineLayer * self)
157 /* TODO : Keep those 3 values in sync */
159 self->min_gnl_priority = 0;
160 self->max_gnl_priority = 9;
164 * ges_timeline_layer_new:
166 * Creates a new #GESTimelineLayer.
168 * Returns: A new #GESTimelineLayer
171 ges_timeline_layer_new (void)
173 return g_object_new (GES_TYPE_TIMELINE_LAYER, NULL);
177 ges_timeline_layer_set_timeline (GESTimelineLayer * layer,
178 GESTimeline * timeline)
180 GST_DEBUG ("layer:%p, timeline:%p", layer, timeline);
182 layer->timeline = timeline;
186 objects_start_compare (GESTimelineObject * a, GESTimelineObject * b)
188 if (a->start == b->start) {
189 if (a->priority < b->priority)
191 if (a->priority > b->priority)
195 if (a->start < b->start)
197 if (a->start > b->start)
203 * ges_timeline_layer_add_object:
204 * @layer: a #GESTimelineLayer
205 * @object: the #GESTimelineObject to add.
207 * Adds the object to the layer. The layer will steal a reference to the
210 * Returns: TRUE if the object was properly added to the layer, or FALSE
211 * if the @layer refused to add the object.
215 ges_timeline_layer_add_object (GESTimelineLayer * layer,
216 GESTimelineObject * object)
218 GST_DEBUG ("layer:%p, object:%p", layer, object);
220 if (G_UNLIKELY (object->layer)) {
221 GST_WARNING ("TimelineObject %p already belongs to another layer");
225 /* Take a reference to the object and store it stored by start/priority */
226 layer->objects_start =
227 g_slist_insert_sorted (layer->objects_start, object,
228 (GCompareFunc) objects_start_compare);
230 /* Inform the object it's now in this layer */
231 ges_timeline_object_set_layer (object, layer);
233 /* Set the priority. */
234 if (GES_TIMELINE_OBJECT_PRIORITY (object) > (layer->max_gnl_priority)) {
235 ges_timeline_object_set_priority (object, layer->max_gnl_priority);
238 else if (GES_TIMELINE_OBJECT_PRIORITY (object) < (layer->min_gnl_priority)) {
239 ges_timeline_object_set_priority (object, layer->min_gnl_priority);
242 /* emit 'object-added' */
243 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_ADDED], 0, object);
249 * ges_timeline_layer_remove_object:
250 * @layer: a #GESTimelineLayer
251 * @object: the #GESTimelineObject to remove
253 * Removes the given @object from the @layer. The reference stolen by the @layer
254 * when the object was added will be removed. If you wish to use the object after
255 * this function, make sure you take an extra reference to the object before
256 * calling this function.
258 * Returns: TRUE if the object was properly remove, else FALSE.
261 ges_timeline_layer_remove_object (GESTimelineLayer * layer,
262 GESTimelineObject * object)
264 GST_DEBUG ("layer:%p, object:%p", layer, object);
266 if (G_UNLIKELY (object->layer != layer)) {
267 GST_WARNING ("TimelineObject doesn't belong to this layer");
271 /* emit 'object-removed' */
272 g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_REMOVED], 0, object);
274 /* inform the object it's no longer in a layer */
275 ges_timeline_object_set_layer (object, NULL);
277 /* Remove it from our list of controlled objects */
278 layer->objects_start = g_slist_remove (layer->objects_start, object);
280 /* Remove our reference to the object */
281 g_object_unref (object);
287 * ges_timeline_layer_resync_priorities:
288 * @layer: a #GESTimelineLayer
290 * Resyncs the priorities of the objects controlled by @layer.
293 ges_timeline_layer_resync_priorities (GESTimelineLayer * layer)
297 /* TODO : Inhibit composition updates while doing this.
298 * Ideally we want to do it from an even higher level, but here will
299 * do in the meantime. */
301 /* TODO : This is the dumb version where we put everything linearly,
302 * will need to be adjusted for more complex usages (like with
304 for (tmp = layer->objects_start; tmp; tmp = tmp->next) {
305 ges_timeline_object_set_priority ((GESTimelineObject *) tmp->data,
306 layer->min_gnl_priority);
313 ges_timeline_layer_set_priority (GESTimelineLayer * layer, guint priority)
315 GST_DEBUG ("layer:%p, priority:%d", layer, priority);
317 if (priority != layer->priority) {
318 layer->priority = priority;
319 layer->min_gnl_priority = (priority * 10);
320 layer->max_gnl_priority = ((priority + 1) * 10) - 1;
322 /* FIXME : Update controlled object's gnl priority accordingly */
323 ges_timeline_layer_resync_priorities (layer);