1 /* GStreamer Editing Services
2  * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3  *               2009 Nokia Corporation
4  *
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.
9  *
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.
14  *
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., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef __GES_INTERNAL_H__
22 #define __GES_INTERNAL_H__
23 #include <gst/gst.h>
24 #include <gst/pbutils/encoding-profile.h>
25 #include <gio/gio.h>
26 
27 #include "ges-timeline.h"
28 #include "ges-track-element.h"
29 #include "ges-timeline-element.h"
30 
31 #include "ges-asset.h"
32 #include "ges-base-xml-formatter.h"
33 #include "ges-timeline-tree.h"
34 
35 G_BEGIN_DECLS
36 
37 #ifndef GST_CAT_DEFAULT
38 #define GST_CAT_DEFAULT (_ges_debug ())
39 #endif
40 
41 G_GNUC_INTERNAL
42 GstDebugCategory * _ges_debug (void);
43 
44 /*  The first 2 NLE priorities are used for:
45  *    0- The Mixing element
46  *    1- The Gaps
47  */
48 #define MIN_NLE_PRIO 2
49 #define LAYER_HEIGHT 1000
50 
51 #define _START(obj) GES_TIMELINE_ELEMENT_START (obj)
52 #define _INPOINT(obj) GES_TIMELINE_ELEMENT_INPOINT (obj)
53 #define _DURATION(obj) GES_TIMELINE_ELEMENT_DURATION (obj)
54 #define _MAXDURATION(obj) GES_TIMELINE_ELEMENT_MAX_DURATION (obj)
55 #define _PRIORITY(obj) GES_TIMELINE_ELEMENT_PRIORITY (obj)
56 #ifndef _END
57 #define _END(obj) (_START (obj) + _DURATION (obj))
58 #endif
59 #define _set_start0 ges_timeline_element_set_start
60 #define _set_inpoint0 ges_timeline_element_set_inpoint
61 #define _set_duration0 ges_timeline_element_set_duration
62 #define _set_priority0 ges_timeline_element_set_priority
63 
64 #define GES_TIMELINE_ELEMENT_FORMAT \
65     "s<%p>" \
66     " [ %" GST_TIME_FORMAT \
67     " (%" GST_TIME_FORMAT \
68     ") - %" GST_TIME_FORMAT "(%" GST_TIME_FORMAT") layer: %" G_GINT32_FORMAT "] "
69 
70 #define GES_TIMELINE_ELEMENT_ARGS(element) \
71     GES_TIMELINE_ELEMENT_NAME(element), element, \
72     GST_TIME_ARGS(GES_TIMELINE_ELEMENT_START(element)), \
73     GST_TIME_ARGS(GES_TIMELINE_ELEMENT_INPOINT(element)), \
74     GST_TIME_ARGS(GES_TIMELINE_ELEMENT_DURATION(element)), \
75     GST_TIME_ARGS(GES_TIMELINE_ELEMENT_MAX_DURATION(element)), \
76     GES_TIMELINE_ELEMENT_LAYER_PRIORITY(element)
77 
78 #define GES_FORMAT GES_TIMELINE_ELEMENT_FORMAT
79 #define GES_ARGS GES_TIMELINE_ELEMENT_ARGS
80 
81 G_GNUC_INTERNAL gboolean
82 timeline_ripple_object         (GESTimeline *timeline, GESTimelineElement *obj,
83                                 gint new_layer_priority,
84                                 GList * layers, GESEdge edge,
85                                 guint64 position);
86 
87 G_GNUC_INTERNAL gboolean
88 timeline_slide_object          (GESTimeline *timeline, GESTrackElement *obj,
89                                     GList * layers, GESEdge edge, guint64 position);
90 
91 G_GNUC_INTERNAL gboolean
92 timeline_roll_object           (GESTimeline *timeline, GESTimelineElement *obj,
93                                 GList * layers, GESEdge edge, guint64 position);
94 
95 G_GNUC_INTERNAL gboolean
96 timeline_trim_object           (GESTimeline *timeline, GESTimelineElement * object,
97                                 guint32 new_layer_priority, GList * layers, GESEdge edge,
98                                 guint64 position);
99 G_GNUC_INTERNAL gboolean
100 ges_timeline_trim_object_simple (GESTimeline * timeline, GESTimelineElement * obj,
101                                  guint32 new_layer_priority, GList * layers, GESEdge edge,
102                                  guint64 position, gboolean snapping);
103 
104 G_GNUC_INTERNAL gboolean
105 ges_timeline_move_object_simple (GESTimeline * timeline, GESTimelineElement * object,
106                                  GList * layers, GESEdge edge, guint64 position);
107 
108 G_GNUC_INTERNAL gboolean
109 timeline_move_object           (GESTimeline *timeline, GESTimelineElement * object,
110                                 guint32 new_layer_priority, GList * layers, GESEdge edge,
111                                 guint64 position);
112 
113 G_GNUC_INTERNAL void
114 timeline_add_group             (GESTimeline *timeline,
115                                 GESGroup *group);
116 G_GNUC_INTERNAL void
117 timeline_remove_group          (GESTimeline *timeline,
118                                 GESGroup *group);
119 G_GNUC_INTERNAL void
120 timeline_emit_group_added      (GESTimeline *timeline,
121                                 GESGroup *group);
122 G_GNUC_INTERNAL void
123 timeline_emit_group_removed    (GESTimeline * timeline,
124                                 GESGroup * group, GPtrArray * array);
125 
126 G_GNUC_INTERNAL
127 gboolean
128 timeline_add_element           (GESTimeline *timeline,
129                                 GESTimelineElement *element);
130 G_GNUC_INTERNAL
131 gboolean
132 timeline_remove_element       (GESTimeline *timeline,
133                                GESTimelineElement *element);
134 
135 G_GNUC_INTERNAL
136 GNode *
137 timeline_get_tree           (GESTimeline *timeline);
138 
139 G_GNUC_INTERNAL
140 void
141 timeline_update_transition (GESTimeline *timeline);
142 
143 G_GNUC_INTERNAL
144 void
145 timeline_fill_gaps            (GESTimeline *timeline);
146 
147 G_GNUC_INTERNAL void
148 timeline_create_transitions (GESTimeline * timeline, GESTrackElement * track_element);
149 
150 G_GNUC_INTERNAL
151 void
152 track_resort_and_fill_gaps    (GESTrack *track);
153 
154 G_GNUC_INTERNAL
155 void
156 track_disable_last_gap        (GESTrack *track, gboolean disabled);
157 
158 G_GNUC_INTERNAL void
159 ges_asset_cache_init (void);
160 
161 G_GNUC_INTERNAL void
162 ges_asset_cache_deinit (void);
163 
164 G_GNUC_INTERNAL void
165 ges_asset_set_id (GESAsset *asset, const gchar *id);
166 
167 G_GNUC_INTERNAL void
168 ges_asset_cache_put (GESAsset * asset, GTask *task);
169 
170 G_GNUC_INTERNAL gboolean
171 ges_asset_cache_set_loaded(GType extractable_type, const gchar * id, GError *error);
172 
173 GES_API GESAsset*
174 ges_asset_cache_lookup(GType extractable_type, const gchar * id);
175 
176 GES_API gboolean
177 ges_asset_try_proxy (GESAsset *asset, const gchar *new_id);
178 
179 G_GNUC_INTERNAL gboolean
180 ges_asset_request_id_update (GESAsset *asset, gchar **proposed_id,
181     GError *error);
182 G_GNUC_INTERNAL gchar *
183 ges_effect_assect_id_get_type_and_bindesc (const char    *id,
184                                            GESTrackType  *track_type,
185                                            GError       **error);
186 
187 G_GNUC_INTERNAL void _ges_uri_asset_cleanup (void);
188 
189 G_GNUC_INTERNAL gboolean _ges_uri_asset_ensure_setup (gpointer uriasset_class);
190 
191 /* GESExtractable internall methods
192  *
193  * FIXME Check if that should be public later
194  */
195 G_GNUC_INTERNAL GType
196 ges_extractable_type_get_asset_type              (GType type);
197 
198 G_GNUC_INTERNAL gchar *
199 ges_extractable_type_check_id                    (GType type, const gchar *id, GError **error);
200 
201 G_GNUC_INTERNAL GParameter *
202 ges_extractable_type_get_parameters_from_id      (GType type, const gchar *id,
203                                                   guint *n_params);
204 G_GNUC_INTERNAL GType
205 ges_extractable_get_real_extractable_type_for_id (GType type, const gchar * id);
206 
207 G_GNUC_INTERNAL gboolean
208 ges_extractable_register_metas                   (GType extractable_type, GESAsset *asset);
209 
210 /************************************************
211  *                                              *
212  *        GESFormatter internal methods         *
213  *                                              *
214  ************************************************/
215 G_GNUC_INTERNAL void
216 ges_formatter_set_project                        (GESFormatter *formatter,
217                                                   GESProject *project);
218 G_GNUC_INTERNAL GESProject *
219 ges_formatter_get_project                        (GESFormatter *formatter);
220 G_GNUC_INTERNAL  GESAsset *
221 _find_formatter_asset_for_id                     (const gchar *id);
222 
223 
224 
225 /************************************************
226  *                                              *
227  *        GESProject internal methods           *
228  *                                              *
229  ************************************************/
230 
231 /* FIXME This should probably become public, but we need to make sure it
232  * is the right API before doing so */
233 G_GNUC_INTERNAL  gboolean ges_project_set_loaded                  (GESProject * project,
234                                                                    GESFormatter *formatter);
235 G_GNUC_INTERNAL  gchar * ges_project_try_updating_id              (GESProject *self,
236                                                                    GESAsset *asset,
237                                                                    GError *error);
238 G_GNUC_INTERNAL  void ges_project_add_loading_asset               (GESProject *project,
239                                                                    GType extractable_type,
240                                                                    const gchar *id);
241 G_GNUC_INTERNAL  gchar* ges_uri_asset_try_update_id               (GError *error, GESAsset *wrong_asset);
242 /************************************************
243  *                                              *
244  *   GESBaseXmlFormatter internal methods       *
245  *                                              *
246  ************************************************/
247 
248 /* FIXME GESBaseXmlFormatter is all internal for now, the API is not stable
249  * fo now, so do not expose it */
250 G_GNUC_INTERNAL void ges_base_xml_formatter_add_clip (GESBaseXmlFormatter * self,
251                                                                  const gchar *id,
252                                                                  const char *asset_id,
253                                                                  GType type,
254                                                                  GstClockTime start,
255                                                                  GstClockTime inpoint,
256                                                                  GstClockTime duration,
257                                                                  guint layer_prio,
258                                                                  GESTrackType track_types,
259                                                                  GstStructure *properties,
260                                                                  GstStructure * children_properties,
261                                                                  const gchar *metadatas,
262                                                                  GError **error);
263 G_GNUC_INTERNAL void ges_base_xml_formatter_add_asset        (GESBaseXmlFormatter * self,
264                                                                  const gchar * id,
265                                                                  GType extractable_type,
266                                                                  GstStructure *properties,
267                                                                  const gchar *metadatas,
268                                                                  const gchar *proxy_id,
269                                                                  GError **error);
270 G_GNUC_INTERNAL void ges_base_xml_formatter_add_layer           (GESBaseXmlFormatter *self,
271                                                                  GType extractable_type,
272                                                                  guint priority,
273                                                                  GstStructure *properties,
274                                                                  const gchar *metadatas,
275                                                                  GError **error);
276 G_GNUC_INTERNAL void ges_base_xml_formatter_add_track           (GESBaseXmlFormatter *self,
277                                                                  GESTrackType track_type,
278                                                                  GstCaps *caps,
279                                                                  const gchar *id,
280                                                                  GstStructure *properties,
281                                                                  const gchar *metadatas,
282                                                                  GError **error);
283 G_GNUC_INTERNAL void ges_base_xml_formatter_add_encoding_profile(GESBaseXmlFormatter * self,
284                                                                  const gchar *type,
285                                                                  const gchar *parent,
286                                                                  const gchar * name,
287                                                                  const gchar * description,
288                                                                  GstCaps * format,
289                                                                  const gchar * preset,
290                                                                  GstStructure * preset_properties,
291                                                                  const gchar * preset_name,
292                                                                  guint id,
293                                                                  guint presence,
294                                                                  GstCaps * restriction,
295                                                                  guint pass,
296                                                                  gboolean variableframerate,
297                                                                  GstStructure * properties,
298                                                                  gboolean enabled,
299                                                                  GError ** error);
300 G_GNUC_INTERNAL void ges_base_xml_formatter_add_track_element   (GESBaseXmlFormatter *self,
301                                                                  GType effect_type,
302                                                                  const gchar *asset_id,
303                                                                  const gchar * track_id,
304                                                                  const gchar *timeline_obj_id,
305                                                                  GstStructure *children_properties,
306                                                                  GstStructure *properties,
307                                                                  const gchar *metadatas,
308                                                                  GError **error);
309 
310 G_GNUC_INTERNAL void ges_base_xml_formatter_add_source          (GESBaseXmlFormatter *self,
311                                                                  const gchar * track_id,
312                                                                  GstStructure *children_properties);
313 
314 G_GNUC_INTERNAL void ges_base_xml_formatter_add_group           (GESBaseXmlFormatter *self,
315                                                                  const gchar *name,
316                                                                  const gchar *properties,
317                                                                  const gchar *metadatas);
318 
319 G_GNUC_INTERNAL void ges_base_xml_formatter_last_group_add_child(GESBaseXmlFormatter *self,
320                                                                  const gchar * id,
321                                                                  const gchar * name);
322 
323 G_GNUC_INTERNAL void ges_base_xml_formatter_add_control_binding (GESBaseXmlFormatter * self,
324                                                                   const gchar * binding_type,
325                                                                   const gchar * source_type,
326                                                                   const gchar * property_name,
327                                                                   gint mode,
328                                                                   const gchar *track_id,
329                                                                   GSList * timed_values);
330 
331 G_GNUC_INTERNAL gboolean set_property_foreach                   (GQuark field_id,
332                                                                  const GValue * value,
333                                                                  GObject * object);
334 
335 G_GNUC_INTERNAL GstElement * get_element_for_encoding_profile   (GstEncodingProfile *prof,
336                                                                  GstElementFactoryListType type);
337 
338 /* Function to initialise GES */
339 G_GNUC_INTERNAL void _init_standard_transition_assets        (void);
340 G_GNUC_INTERNAL void _init_formatter_assets                  (void);
341 
342 /* Utilities */
343 G_GNUC_INTERNAL gint element_start_compare                (GESTimelineElement * a,
344                                                            GESTimelineElement * b);
345 G_GNUC_INTERNAL gint element_end_compare                  (GESTimelineElement * a,
346                                                            GESTimelineElement * b);
347 G_GNUC_INTERNAL GstElementFactory *
348 ges_get_compositor_factory                                (void);
349 
350 G_GNUC_INTERNAL void
351 ges_base_xml_formatter_set_timeline_properties(GESBaseXmlFormatter * self,
352 					       GESTimeline *timeline,
353 					       const gchar *properties,
354 					       const gchar *metadatas);
355 
356 /****************************************************
357  *              GESContainer                        *
358  ****************************************************/
359 G_GNUC_INTERNAL void _ges_container_sort_children         (GESContainer *container);
360 G_GNUC_INTERNAL void _ges_container_sort_children_by_end  (GESContainer *container);
361 G_GNUC_INTERNAL void _ges_container_set_height            (GESContainer * container,
362                                                            guint32 height);
363 G_GNUC_INTERNAL gint  _ges_container_get_priority_offset  (GESContainer * container,
364                                                            GESTimelineElement *elem);
365 G_GNUC_INTERNAL void _ges_container_set_priority_offset   (GESContainer * container,
366                                                            GESTimelineElement *elem,
367                                                            gint32 priority_offset);
368 
369 
370 /****************************************************
371  *                  GESClip                         *
372  ****************************************************/
373 G_GNUC_INTERNAL void              ges_clip_set_layer              (GESClip *clip, GESLayer  *layer);
374 G_GNUC_INTERNAL gboolean          ges_clip_is_moving_from_layer   (GESClip *clip);
375 G_GNUC_INTERNAL void              ges_clip_set_moving_from_layer  (GESClip *clip, gboolean is_moving);
376 G_GNUC_INTERNAL GESTrackElement*  ges_clip_create_track_element   (GESClip *clip, GESTrackType type);
377 G_GNUC_INTERNAL GList*            ges_clip_create_track_elements  (GESClip *clip, GESTrackType type);
378 
379 /****************************************************
380  *              GESLayer                            *
381  ****************************************************/
382 G_GNUC_INTERNAL gboolean ges_layer_resync_priorities (GESLayer * layer);
383 G_GNUC_INTERNAL void layer_set_priority               (GESLayer * layer, guint priority, gboolean emit);
384 
385 /****************************************************
386  *              GESTrackElement                     *
387  ****************************************************/
388 #define         NLE_OBJECT_TRACK_ELEMENT_QUARK                  (g_quark_from_string ("nle_object_track_element_quark"))
389 G_GNUC_INTERNAL gboolean  ges_track_element_set_track           (GESTrackElement * object, GESTrack * track);
390 G_GNUC_INTERNAL void ges_track_element_copy_properties          (GESTimelineElement * element,
391                                                                  GESTimelineElement * elementcopy);
392 
393 G_GNUC_INTERNAL void ges_track_element_copy_bindings (GESTrackElement *element,
394 						       GESTrackElement *new_element,
395 						       guint64 position);
396 
397 G_GNUC_INTERNAL GstElement *ges_source_create_topbin (const gchar * bin_name, GstElement * sub_element, ...);
398 G_GNUC_INTERNAL void ges_track_set_caps                (GESTrack *track,
399                                                         const GstCaps *caps);
400 G_GNUC_INTERNAL GstElement * ges_track_get_composition (GESTrack *track);
401 
402 
403 /*********************************************
404  *  GESTrackElement subclasses contructores  *
405  ********************************************/
406 G_GNUC_INTERNAL GESAudioTestSource * ges_audio_test_source_new (void);
407 G_GNUC_INTERNAL GESAudioUriSource  * ges_audio_uri_source_new  (gchar *uri);
408 G_GNUC_INTERNAL GESVideoUriSource  * ges_video_uri_source_new  (gchar *uri);
409 G_GNUC_INTERNAL GESImageSource     * ges_image_source_new      (gchar *uri);
410 G_GNUC_INTERNAL GESTitleSource     * ges_title_source_new      (void);
411 G_GNUC_INTERNAL GESVideoTestSource * ges_video_test_source_new (void);
412 
413 /****************************************************
414  *              GESTimelineElement                  *
415  ****************************************************/
416 typedef enum
417 {
418   GES_CLIP_IS_MOVING = (1 << 0),
419   GES_TIMELINE_ELEMENT_SET_SIMPLE = (1 << 1),
420 } GESTimelineElementFlags;
421 
422 G_GNUC_INTERNAL gdouble ges_timeline_element_get_media_duration_factor(GESTimelineElement *self);
423 G_GNUC_INTERNAL GESTimelineElement * ges_timeline_element_get_copied_from (GESTimelineElement *self);
424 G_GNUC_INTERNAL GESTimelineElementFlags ges_timeline_element_flags (GESTimelineElement *self);
425 G_GNUC_INTERNAL void                ges_timeline_element_set_flags (GESTimelineElement *self, GESTimelineElementFlags flags);
426 
427 #define ELEMENT_FLAGS(obj)             (ges_timeline_element_flags (GES_TIMELINE_ELEMENT(obj)))
428 #define ELEMENT_SET_FLAG(obj,flag)     (ges_timeline_element_set_flags(GES_TIMELINE_ELEMENT(obj), (ELEMENT_FLAGS(obj) | (flag))))
429 #define ELEMENT_UNSET_FLAG(obj,flag)   (ges_timeline_element_set_flags(GES_TIMELINE_ELEMENT(obj), (ELEMENT_FLAGS(obj) & ~(flag))))
430 #define ELEMENT_FLAG_IS_SET(obj,flag)  ((ELEMENT_FLAGS (obj) & (flag)) == (flag))
431 
432 /******************************
433  *  GESMultiFile internal API *
434  ******************************/
435 typedef struct GESMultiFileURI
436 {
437   gchar *location;
438   gint start;
439   gint end;
440 } GESMultiFileURI;
441 
442 G_GNUC_INTERNAL GESMultiFileURI * ges_multi_file_uri_new (const gchar * uri);
443 
444 /************************
445  * Our property masks   *
446  ************************/
447 #define GES_PARAM_NO_SERIALIZATION (1 << (G_PARAM_USER_SHIFT + 1))
448 
449 /********************
450  *  Gnonlin helpers *
451  ********************/
452 
453 G_GNUC_INTERNAL gboolean ges_nle_composition_add_object (GstElement *comp, GstElement *object);
454 G_GNUC_INTERNAL gboolean ges_nle_composition_remove_object (GstElement *comp, GstElement *object);
455 G_GNUC_INTERNAL gboolean ges_nle_object_commit (GstElement * nlesource, gboolean recurse);
456 
457 G_END_DECLS
458 
459 #endif /* __GES_INTERNAL_H__ */
460