Add unit test system. Adjust GST_DEBUG usage.
[platform/upstream/gstreamer.git] / ges / ges-timeline-layer.c
1 /* GStreamer Editing Services
2  * Copyright (C) 2009 Edward Hervey <bilboed@bilboed.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "ges-internal.h"
21 #include "gesmarshal.h"
22 #include "ges-timeline-layer.h"
23 #include "ges.h"
24
25 /**
26  * GESTimelineLayer
27  *
28  * Responsible for the ordering of the various contained TimelineObject(s)
29  */
30
31 G_DEFINE_TYPE (GESTimelineLayer, ges_timeline_layer, G_TYPE_OBJECT);
32
33 #define GET_PRIVATE(o) \
34   (G_TYPE_INSTANCE_GET_PRIVATE ((o), GES_TYPE_TIMELINE_LAYER, GESTimelineLayerPrivate));
35
36 typedef struct _GESTimelineLayerPrivate GESTimelineLayerPrivate;
37
38 struct _GESTimelineLayerPrivate
39 {
40   int dummy;
41 };
42
43 enum
44 {
45   OBJECT_ADDED,
46   OBJECT_REMOVED,
47   LAST_SIGNAL
48 };
49
50 static guint ges_timeline_layer_signals[LAST_SIGNAL] = { 0 };
51
52 static void
53 ges_timeline_layer_get_property (GObject * object, guint property_id,
54     GValue * value, GParamSpec * pspec)
55 {
56   switch (property_id) {
57     default:
58       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
59   }
60 }
61
62 static void
63 ges_timeline_layer_set_property (GObject * object, guint property_id,
64     const GValue * value, GParamSpec * pspec)
65 {
66   switch (property_id) {
67     default:
68       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
69   }
70 }
71
72 static void
73 ges_timeline_layer_dispose (GObject * object)
74 {
75   G_OBJECT_CLASS (ges_timeline_layer_parent_class)->dispose (object);
76 }
77
78 static void
79 ges_timeline_layer_finalize (GObject * object)
80 {
81   G_OBJECT_CLASS (ges_timeline_layer_parent_class)->finalize (object);
82 }
83
84 static void
85 ges_timeline_layer_class_init (GESTimelineLayerClass * klass)
86 {
87   GObjectClass *object_class = G_OBJECT_CLASS (klass);
88
89   g_type_class_add_private (klass, sizeof (GESTimelineLayerPrivate));
90
91   object_class->get_property = ges_timeline_layer_get_property;
92   object_class->set_property = ges_timeline_layer_set_property;
93   object_class->dispose = ges_timeline_layer_dispose;
94   object_class->finalize = ges_timeline_layer_finalize;
95
96   ges_timeline_layer_signals[OBJECT_ADDED] =
97       g_signal_new ("object-added", G_TYPE_FROM_CLASS (klass),
98       G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass, object_added),
99       NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
100       GES_TYPE_TIMELINE_OBJECT);
101
102   ges_timeline_layer_signals[OBJECT_REMOVED] =
103       g_signal_new ("object-removed", G_TYPE_FROM_CLASS (klass),
104       G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GESTimelineLayerClass,
105           object_removed), NULL, NULL, ges_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
106       GES_TYPE_TIMELINE_OBJECT);
107
108 }
109
110 static void
111 ges_timeline_layer_init (GESTimelineLayer * self)
112 {
113 }
114
115 GESTimelineLayer *
116 ges_timeline_layer_new (void)
117 {
118   return g_object_new (GES_TYPE_TIMELINE_LAYER, NULL);
119 }
120
121 void
122 ges_timeline_layer_set_timeline (GESTimelineLayer * layer,
123     GESTimeline * timeline)
124 {
125   GST_DEBUG ("layer:%p, timeline:%p", layer, timeline);
126
127   layer->timeline = timeline;
128 }
129
130 static gint
131 objects_start_compare (GESTimelineObject * a, GESTimelineObject * b)
132 {
133   if (a->start == b->start) {
134     if (a->priority < b->priority)
135       return -1;
136     if (a->priority > b->priority)
137       return 1;
138     return 0;
139   }
140   if (a->start < b->start)
141     return -1;
142   if (a->start > b->start)
143     return 1;
144   return 0;
145 }
146
147 gboolean
148 ges_timeline_layer_add_object (GESTimelineLayer * layer,
149     GESTimelineObject * object)
150 {
151   GST_DEBUG ("layer:%p, object:%p", layer, object);
152
153   if (G_UNLIKELY (object->layer)) {
154     GST_WARNING ("TimelineObject %p already belongs to another layer");
155     return FALSE;
156   }
157
158   /* Take a reference to the object and store it stored by start/priority */
159   layer->objects_start =
160       g_slist_insert_sorted (layer->objects_start, g_object_ref (object),
161       (GCompareFunc) objects_start_compare);
162
163   /* Inform the object it's now in this layer */
164   ges_timeline_object_set_layer (object, layer);
165
166   /* emit 'object-added' */
167   g_signal_emit (layer, ges_timeline_layer_signals[OBJECT_ADDED], 0, object);
168
169   return TRUE;
170 }