1 /*
2  * gst-editing-services
3  * Copyright (C) <2013> Thibault Saunier <thibault.saunier@collabora.com>
4  *               <2013> Collabora Ltd.
5  *
6  * gst-editing-services is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * gst-editing-services is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef _GES_TIMELINE_ELEMENT_H_
21 #define _GES_TIMELINE_ELEMENT_H_
22 
23 #include <glib-object.h>
24 #include <gst/gst.h>
25 #include "ges-enums.h"
26 #include "ges-types.h"
27 
28 G_BEGIN_DECLS
29 
30 #define GES_TYPE_TIMELINE_ELEMENT             (ges_timeline_element_get_type ())
31 #define GES_TIMELINE_ELEMENT(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GES_TYPE_TIMELINE_ELEMENT, GESTimelineElement))
32 #define GES_TIMELINE_ELEMENT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GES_TYPE_TIMELINE_ELEMENT, GESTimelineElementClass))
33 #define GES_IS_TIMELINE_ELEMENT(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GES_TYPE_TIMELINE_ELEMENT))
34 #define GES_IS_TIMELINE_ELEMENT_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GES_TYPE_TIMELINE_ELEMENT))
35 #define GES_TIMELINE_ELEMENT_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GES_TYPE_TIMELINE_ELEMENT, GESTimelineElementClass))
36 
37 typedef struct _GESTimelineElementPrivate GESTimelineElementPrivate;
38 
39 /**
40  * GES_TIMELINE_ELEMENT_START:
41  * @obj: a #GESTimelineElement
42  *
43  * The start position of the object (in nanoseconds).
44  */
45 #define GES_TIMELINE_ELEMENT_START(obj) (((GESTimelineElement*)obj)->start)
46 
47 /**
48  * GES_TIMELINE_ELEMENT_END:
49  * @obj: a #GESTimelineElement
50  *
51  * The end position of the object (in nanoseconds).
52  */
53 #define GES_TIMELINE_ELEMENT_END(obj) ((((GESTimelineElement*)obj)->start) + (((GESTimelineElement*)obj)->duration))
54 
55 /**
56  * GES_TIMELINE_ELEMENT_INPOINT:
57  * @obj: a #GESTimelineElement
58  *
59  * The in-point of the object (in nanoseconds).
60  */
61 #define GES_TIMELINE_ELEMENT_INPOINT(obj) (((GESTimelineElement*)obj)->inpoint)
62 
63 /**
64  * GES_TIMELINE_ELEMENT_DURATION:
65  * @obj: a #GESTimelineElement
66  *
67  * The duration of the object (in nanoseconds).
68  */
69 #define GES_TIMELINE_ELEMENT_DURATION(obj) (((GESTimelineElement*)obj)->duration)
70 
71 /**
72  * GES_TIMELINE_ELEMENT_MAX_DURATION:
73  * @obj: a #GESTimelineElement
74  *
75  * The maximun duration of the object (in nanoseconds).
76  */
77 #define GES_TIMELINE_ELEMENT_MAX_DURATION(obj) (((GESTimelineElement*)obj)->maxduration)
78 
79 /**
80  * GES_TIMELINE_ELEMENT_PRIORITY:
81  * @obj: a #GESTimelineElement
82  *
83  * The priority of the object.
84  */
85 #define GES_TIMELINE_ELEMENT_PRIORITY(obj) (((GESTimelineElement*)obj)->priority)
86 
87 /**
88  * GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY:
89  *
90  * Layer priority when the element is not in a layer
91  */
92 #define GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY ((guint32) -1)
93 
94 /**
95  * GES_TIMELINE_ELEMENT_LAYER_PRIORITY:
96  * @obj: The object to retrieve the layer priority from
97  *
98  * See #ges_timeline_element_get_layer_priority
99  */
100 #define GES_TIMELINE_ELEMENT_LAYER_PRIORITY(obj) (ges_timeline_element_get_layer_priority(((GESTimelineElement*)obj)))
101 
102 /**
103  * GES_TIMELINE_ELEMENT_PARENT:
104  * @obj: a #GESTimelineElement
105  *
106  * The parent of the object.
107  */
108 #define GES_TIMELINE_ELEMENT_PARENT(obj) (((GESTimelineElement*)obj)->parent)
109 
110 /**
111  * GES_TIMELINE_ELEMENT_TIMELINE:
112  * @obj: a #GESTimelineElement
113  *
114  * The timeline in which the object is.
115  */
116 #define GES_TIMELINE_ELEMENT_TIMELINE(obj) (((GESTimelineElement*)obj)->timeline)
117 
118 /**
119  * GES_TIMELINE_ELEMENT_NAME:
120  * @obj: a #GESTimelineElement
121  *
122  * The name of the object.
123  */
124 #define GES_TIMELINE_ELEMENT_NAME(obj) (((GESTimelineElement*)obj)->name)
125 
126 /**
127  * GESTimelineElement:
128  * @parent: The #GESTimelineElement that controls the object
129  * @asset: The #GESAsset from which the object has been extracted
130  * @start: position (in time) of the object
131  * @inpoint: Position in the media from which the object should be used
132  * @duration: duration of the object to be used
133  * @maxduration: The maximum duration the object can have
134  * @priority: priority of the object in the layer (0:top priority)
135  *
136  * Those filed can be accessed from outside but in no case should
137  * be changed from there. Subclasses can write them but should make
138  * sure to properly call g_object_notify.
139  */
140 struct _GESTimelineElement
141 {
142   GInitiallyUnowned parent_instance;
143 
144   /*< public > */
145   /*< read only >*/
146   GESTimelineElement *parent;
147   GESAsset *asset;
148   GstClockTime start;
149   GstClockTime inpoint;
150   GstClockTime duration;
151   GstClockTime maxduration;
152   guint32 priority;
153   GESTimeline *timeline;
154   gchar *name;
155 
156   /*< private >*/
157   GESTimelineElementPrivate *priv;
158 
159   /* Padding for API extension */
160   gpointer _ges_reserved[GES_PADDING_LARGE];
161 };
162 
163 /**
164  * GESTimelineElementClass:
165  * @set_parent: method to set the parent of a #GESTimelineElement.
166  * @set_start: method to set the start of a #GESTimelineElement
167  * @set_duration: method to set the duration of a #GESTimelineElement
168  * @set_inpoint: method to set the inpoint of a #GESTimelineElement
169  * @set_max_duration: method to set the maximun duration of a #GESTimelineElement
170  * @set_priority: method to set the priority of a #GESTimelineElement
171  * @ripple: method to ripple an object
172  * @ripple_end: method to ripple an object on its #GES_EDGE_END edge
173  * @roll_start: method to roll an object on its #GES_EDGE_START edge
174  * @roll_end: method to roll an object on its #GES_EDGE_END edge
175  * @trim: method to trim an object
176  * @deep_copy: Copy the children properties of @self into @copy
177  *
178  * The GESTimelineElement base class. Subclasses should override at least
179  * @set_start @set_inpoint @set_duration @ripple @ripple_end @roll_start
180  * @roll_end and @trim.
181  *
182  * Vmethods in subclasses should apply all the operation they need to but
183  * the real method implementation is in charge of setting the proper field,
184  * and emit the notify signal.
185  */
186 struct _GESTimelineElementClass
187 {
188   GInitiallyUnownedClass parent_class;
189 
190   /*< public > */
191   gboolean (*set_parent)       (GESTimelineElement * self, GESTimelineElement *parent);
192   gboolean (*set_start)        (GESTimelineElement * self, GstClockTime start);
193   gboolean (*set_inpoint)      (GESTimelineElement * self, GstClockTime inpoint);
194   gboolean (*set_duration)     (GESTimelineElement * self, GstClockTime duration);
195   gboolean (*set_max_duration) (GESTimelineElement * self, GstClockTime maxduration);
196   gboolean (*set_priority)     (GESTimelineElement * self, guint32 priority); /* set_priority is now protected */
197 
198   gboolean (*ripple)           (GESTimelineElement *self, guint64  start);
199   gboolean (*ripple_end)       (GESTimelineElement *self, guint64  end);
200   gboolean (*roll_start)       (GESTimelineElement *self, guint64  start);
201   gboolean (*roll_end)         (GESTimelineElement *self, guint64  end);
202   gboolean (*trim)             (GESTimelineElement *self, guint64  start);
203   void     (*deep_copy)        (GESTimelineElement *self, GESTimelineElement *copy);
204 
205   GESTimelineElement * (*paste) (GESTimelineElement *self,
206                                    GESTimelineElement *ref_element,
207                                    GstClockTime paste_position);
208 
209   GParamSpec** (*list_children_properties) (GESTimelineElement * self, guint *n_properties);
210   gboolean (*lookup_child)                 (GESTimelineElement *self, const gchar *prop_name,
211                                             GObject **child, GParamSpec **pspec);
212   GESTrackType (*get_track_types)          (GESTimelineElement * self);
213   void         (*set_child_property)       (GESTimelineElement * self, GObject *child,
214                                             GParamSpec *pspec, GValue *value);
215 
216   guint32      (*get_layer_priority)       (GESTimelineElement *self);
217 
218   /*< private > */
219   /* Padding for API extension */
220   gpointer _ges_reserved[GES_PADDING_LARGE - 4];
221 };
222 
223 GES_API
224 GType ges_timeline_element_get_type (void) G_GNUC_CONST;
225 
226 GES_API GESTimelineElement *
227 ges_timeline_element_get_toplevel_parent             (GESTimelineElement *self);
228 GES_API
229 GESTimelineElement * ges_timeline_element_get_parent (GESTimelineElement * self);
230 GES_API
231 gboolean ges_timeline_element_set_parent             (GESTimelineElement *self, GESTimelineElement *parent);
232 GES_API
233 gboolean ges_timeline_element_set_timeline           (GESTimelineElement *self, GESTimeline *timeline);
234 GES_API
235 gboolean ges_timeline_element_set_start              (GESTimelineElement *self, GstClockTime start);
236 GES_API
237 gboolean ges_timeline_element_set_inpoint            (GESTimelineElement *self, GstClockTime inpoint);
238 GES_API
239 gboolean ges_timeline_element_set_duration           (GESTimelineElement *self, GstClockTime duration);
240 GES_API
241 gboolean ges_timeline_element_set_max_duration       (GESTimelineElement *self, GstClockTime maxduration);
242 GES_API
243 gboolean ges_timeline_element_set_priority           (GESTimelineElement *self, guint32 priority);
244 
245 GES_API
246 GstClockTime ges_timeline_element_get_start          (GESTimelineElement *self);
247 GES_API
248 GstClockTime ges_timeline_element_get_inpoint        (GESTimelineElement *self);
249 GES_API
250 GstClockTime ges_timeline_element_get_duration       (GESTimelineElement *self);
251 GES_API
252 GstClockTime ges_timeline_element_get_max_duration   (GESTimelineElement *self);
253 GES_API
254 GESTimeline * ges_timeline_element_get_timeline      (GESTimelineElement *self);
255 GES_API
256 guint32 ges_timeline_element_get_priority            (GESTimelineElement *self);
257 
258 GES_API
259 gboolean ges_timeline_element_ripple                 (GESTimelineElement *self, GstClockTime  start);
260 GES_API
261 gboolean ges_timeline_element_ripple_end             (GESTimelineElement *self, GstClockTime  end);
262 GES_API
263 gboolean ges_timeline_element_roll_start             (GESTimelineElement *self, GstClockTime  start);
264 GES_API
265 gboolean ges_timeline_element_roll_end               (GESTimelineElement *self, GstClockTime  end);
266 GES_API
267 gboolean ges_timeline_element_trim                   (GESTimelineElement *self, GstClockTime  start);
268 GES_API
269 GESTimelineElement * ges_timeline_element_copy       (GESTimelineElement *self, gboolean deep);
270 GES_API
271 gchar  * ges_timeline_element_get_name               (GESTimelineElement *self);
272 GES_API
273 gboolean  ges_timeline_element_set_name              (GESTimelineElement *self, const gchar *name);
274 GES_API GParamSpec **
275 ges_timeline_element_list_children_properties        (GESTimelineElement *self,
276                                                       guint *n_properties);
277 
278 GES_API
279 gboolean ges_timeline_element_lookup_child           (GESTimelineElement *self,
280                                                       const gchar *prop_name,
281                                                       GObject  **child,
282                                                       GParamSpec **pspec);
283 
284 GES_API void
285 ges_timeline_element_get_child_property_by_pspec     (GESTimelineElement * self,
286                                                       GParamSpec * pspec,
287                                                       GValue * value);
288 
289 GES_API void
290 ges_timeline_element_get_child_property_valist       (GESTimelineElement * self,
291                                                       const gchar * first_property_name,
292                                                       va_list var_args);
293 
294 GES_API void
295 ges_timeline_element_get_child_properties           (GESTimelineElement *self,
296                                                       const gchar * first_property_name,
297                                                       ...) G_GNUC_NULL_TERMINATED;
298 
299 GES_API void
300 ges_timeline_element_set_child_property_valist      (GESTimelineElement * self,
301                                                      const gchar * first_property_name,
302                                                      va_list var_args);
303 
304 GES_API void
305 ges_timeline_element_set_child_property_by_pspec    (GESTimelineElement * self,
306                                                      GParamSpec * pspec,
307                                                      const GValue * value);
308 GES_API
309 void ges_timeline_element_set_child_properties     (GESTimelineElement * self,
310                                                      const gchar * first_property_name,
311                                                      ...) G_GNUC_NULL_TERMINATED;
312 
313 GES_API
314 gboolean ges_timeline_element_set_child_property   (GESTimelineElement *self,
315                                                     const gchar *property_name,
316                                                     const GValue * value);
317 
318 GES_API
319 gboolean ges_timeline_element_get_child_property   (GESTimelineElement *self,
320                                                     const gchar *property_name,
321                                                     GValue * value);
322 
323 GES_API
324 gboolean ges_timeline_element_add_child_property   (GESTimelineElement * self,
325                                                     GParamSpec *pspec,
326                                                     GObject *child);
327 
328 GES_API
329 gboolean ges_timeline_element_remove_child_property(GESTimelineElement * self,
330                                                     GParamSpec *pspec);
331 
332 GES_API
333 GESTimelineElement * ges_timeline_element_paste    (GESTimelineElement * self,
334                                                     GstClockTime paste_position);
335 
336 GES_API
337 GESTrackType ges_timeline_element_get_track_types  (GESTimelineElement * self);
338 
339 GES_API
340 guint32 ges_timeline_element_get_layer_priority    (GESTimelineElement * self);
341 
342 G_END_DECLS
343 
344 #endif /* _GES_TIMELINE_ELEMENT_H_ */
345