ges: Minor debug logging level and typo fixes
[platform/upstream/gst-editing-services.git] / ges / ges-validate.c
1 /* GStreamer Editing Services
2  *
3  * Copyright (C) <2014> Thibault Saunier <thibault.saunier@collabora.com>
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., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <ges/ges.h>
26
27 #ifdef HAVE_GST_VALIDATE
28 #include <gst/validate/validate.h>
29 #include <gst/validate/gst-validate-scenario.h>
30 #include <gst/validate/gst-validate-utils.h>
31 #include "ges-internal.h"
32 #include "ges-structured-interface.h"
33
34 #define MONITOR_ON_PIPELINE "validate-monitor"
35 #define RUNNER_ON_PIPELINE "runner-monitor"
36
37 typedef struct
38 {
39   GMainLoop *ml;
40   GError *error;
41 } LoadTimelineData;
42
43 static gboolean
44 _get_clocktime (GstStructure * structure, const gchar * name,
45     GstClockTime * val, GESFrameNumber * frames)
46 {
47   const GValue *gvalue = gst_structure_get_value (structure, name);
48
49   if (!gvalue)
50     return FALSE;
51
52   if (frames && G_VALUE_TYPE (gvalue) == G_TYPE_STRING) {
53     const gchar *str = g_value_get_string (gvalue);
54
55     if (str && str[0] == 'f') {
56       GValue v = G_VALUE_INIT;
57
58       g_value_init (&v, G_TYPE_UINT64);
59       if (gst_value_deserialize (&v, &str[1])) {
60         *frames = g_value_get_uint64 (&v);
61         if (val)
62           *val = GST_CLOCK_TIME_NONE;
63         g_value_reset (&v);
64
65         return TRUE;
66       }
67       g_value_reset (&v);
68     }
69   }
70
71   if (!val)
72     return FALSE;
73
74   return gst_validate_utils_get_clocktime (structure, name, val);
75 }
76
77 static void
78 project_loaded_cb (GESProject * project, GESTimeline * timeline,
79     LoadTimelineData * data)
80 {
81   g_main_loop_quit (data->ml);
82 }
83
84 static void
85 error_loading_asset_cb (GESProject * project, GError * err,
86     const gchar * unused_id, GType extractable_type, LoadTimelineData * data)
87 {
88   data->error = g_error_copy (err);
89   g_main_loop_quit (data->ml);
90 }
91
92 static GESTimeline *
93 _ges_load_timeline (GstValidateScenario * scenario, GstValidateAction * action,
94     const gchar * project_uri)
95 {
96   GESProject *project = ges_project_new (project_uri);
97   GESTimeline *timeline;
98   LoadTimelineData data = { 0 };
99
100   data.ml = g_main_loop_new (NULL, TRUE);
101   timeline =
102       GES_TIMELINE (ges_asset_extract (GES_ASSET (project), &data.error));
103   if (!timeline)
104     goto done;
105
106   g_signal_connect (project, "loaded", (GCallback) project_loaded_cb, &data);
107   g_signal_connect (project, "error-loading-asset",
108       (GCallback) error_loading_asset_cb, &data);
109   g_main_loop_run (data.ml);
110   g_signal_handlers_disconnect_by_func (project, project_loaded_cb, &data);
111   g_signal_handlers_disconnect_by_func (project, error_loading_asset_cb, &data);
112   GST_INFO_OBJECT (scenario, "Loaded timeline from %s", project_uri);
113
114 done:
115   if (data.error) {
116     GST_VALIDATE_REPORT_ACTION (scenario, action,
117         SCENARIO_ACTION_EXECUTION_ERROR, "Can not load timeline from: %s (%s)",
118         project_uri, data.error->message);
119     g_clear_error (&data.error);
120     gst_clear_object (&timeline);
121   }
122
123   g_main_loop_unref (data.ml);
124   gst_object_unref (project);
125   return timeline;
126 }
127
128 #ifdef G_HAVE_ISO_VARARGS
129 #define REPORT_UNLESS(condition, errpoint, ...)                                \
130   G_STMT_START {                                                               \
131     if (!(condition)) {                                                        \
132       res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;                        \
133       gst_validate_report_action(GST_VALIDATE_REPORTER(scenario), action,      \
134                                  SCENARIO_ACTION_EXECUTION_ERROR,              \
135                                  __VA_ARGS__);                                 \
136       goto errpoint;                                                           \
137     }                                                                          \
138   }                                                                            \
139   G_STMT_END
140 #else /* G_HAVE_GNUC_VARARGS */
141 #ifdef G_HAVE_GNUC_VARARGS
142 #define REPORT_UNLESS(condition, errpoint, args...)                            \
143   G_STMT_START {                                                               \
144     if (!(condition)) {                                                        \
145       res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;                        \
146       gst_validate_report_action(GST_VALIDATE_REPORTER(scenario), action,      \
147                                  SCENARIO_ACTION_EXECUTION_ERROR, ##args);     \
148       goto errpoint;                                                           \
149     }                                                                          \
150   }                                                                            \
151   G_STMT_END
152 #endif /* G_HAVE_ISO_VARARGS */
153 #endif /* G_HAVE_GNUC_VARARGS */
154
155 #define DECLARE_AND_GET_TIMELINE_AND_PIPELINE(scenario, action)                \
156   GESTimeline *timeline = NULL;                                                \
157   GstElement *pipeline = NULL;                                                 \
158   const gchar *project_uri =                                                   \
159       gst_structure_get_string(action->structure, "project-uri");              \
160   if (!project_uri) {                                                          \
161     pipeline = gst_validate_scenario_get_pipeline(scenario);                   \
162     REPORT_UNLESS(GES_IS_PIPELINE(pipeline), done,                     \
163                   "Can't execute a '%s' action after the pipeline "            \
164                   "has been destroyed.",                                       \
165                   action->type);                                               \
166     g_object_get(pipeline, "timeline", &timeline, NULL);                       \
167   } else {                                                                     \
168     timeline = _ges_load_timeline(scenario, action, project_uri);              \
169     if (!timeline)                                                             \
170       return GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;                       \
171   }
172
173 #define DECLARE_AND_GET_TIMELINE(scenario, action)         \
174   DECLARE_AND_GET_TIMELINE_AND_PIPELINE(scenario, action); \
175   if (pipeline)                                            \
176     gst_object_unref(pipeline);
177
178 #define GES_START_VALIDATE_ACTION(funcname)                                    \
179 static gint                                                                    \
180 funcname(GstValidateScenario *scenario, GstValidateAction *action) {           \
181   GstValidateActionReturn res = GST_VALIDATE_EXECUTE_ACTION_OK;                \
182   DECLARE_AND_GET_TIMELINE_AND_PIPELINE(scenario, action);
183
184 #define GST_END_VALIDATE_ACTION                                                \
185 done:                                                                          \
186   if (res == GST_VALIDATE_EXECUTE_ACTION_OK) {                                        \
187     REPORT_UNLESS(                                                             \
188         _ges_save_timeline_if_needed(timeline, action->structure, NULL),       \
189         done_no_save, "Could not save timeline to %s",                         \
190         gst_structure_get_string(action->structure, "project-id"));            \
191   }                                                                            \
192                                                                                \
193 done_no_save:                                                                  \
194   gst_clear_object(&pipeline);                                                 \
195   gst_clear_object(&timeline);                                                 \
196   return res;                                                                  \
197 }
198
199 #define TRY_GET(name,type,var,def) G_STMT_START {\
200   if  (!gst_structure_get (action->structure, name, type, var, NULL)) {\
201     *var = def; \
202   } \
203 } G_STMT_END
204
205 GES_START_VALIDATE_ACTION (_serialize_project)
206 {
207   const gchar *uri = gst_structure_get_string (action->structure, "uri");
208   gchar *location = gst_uri_get_location (uri),
209       *dir = g_path_get_dirname (location);
210
211   gst_validate_printf (action, "Saving project to %s", uri);
212
213   g_mkdir_with_parents (dir, 0755);
214   g_free (location);
215   g_free (dir);
216
217   res = ges_timeline_save_to_uri (timeline, uri, NULL, TRUE, NULL);
218 }
219
220 GST_END_VALIDATE_ACTION;
221
222 GES_START_VALIDATE_ACTION (_remove_asset)
223 {
224   const gchar *id = NULL;
225   const gchar *type_string = NULL;
226   GType type;
227   GESAsset *asset;
228   GESProject *project;
229
230   project = ges_timeline_get_project (timeline);
231
232   id = gst_structure_get_string (action->structure, "id");
233   type_string = gst_structure_get_string (action->structure, "type");
234
235   REPORT_UNLESS (type_string && id, done,
236       "Missing parameters, we got type %s and id %s", type_string, id);
237   REPORT_UNLESS ((type = g_type_from_name (type_string)), done,
238       "This type doesn't exist : %s", type_string);
239
240   asset = ges_project_get_asset (project, id, type);
241   REPORT_UNLESS (asset, done, "No asset with id %s and type %s", id,
242       type_string);
243   res = ges_project_remove_asset (project, asset);
244   gst_object_unref (asset);
245 }
246
247 GST_END_VALIDATE_ACTION;
248
249 GES_START_VALIDATE_ACTION (_add_asset)
250 {
251   const gchar *id = NULL;
252   const gchar *type_string = NULL;
253   GType type;
254   GESAsset *asset = NULL;
255   GESProject *project;
256
257   project = ges_timeline_get_project (timeline);
258
259   id = gst_structure_get_string (action->structure, "id");
260   type_string = gst_structure_get_string (action->structure, "type");
261
262   gst_validate_printf (action, "Adding asset of type %s with ID %s\n",
263       id, type_string);
264
265   REPORT_UNLESS (type_string
266       && id, beach, "Missing parameters, we got type %s and id %s", type_string,
267       id);
268   REPORT_UNLESS ((type =
269           g_type_from_name (type_string)), beach,
270       "This type doesn't exist : %s", type_string);
271
272   asset = _ges_get_asset_from_timeline (timeline, type, id, NULL);
273
274   REPORT_UNLESS (asset, beach, "Could not get asset for %s id: %s", type_string,
275       id);
276   res = ges_project_add_asset (project, asset);
277
278 beach:
279   gst_clear_object (&asset);
280 }
281
282 GST_END_VALIDATE_ACTION;
283
284 GES_START_VALIDATE_ACTION (_add_layer)
285 {
286   GESLayer *layer;
287   gint priority;
288   gboolean auto_transition = FALSE;
289
290   REPORT_UNLESS (gst_structure_get_int (action->structure, "priority",
291           &priority), done, "priority is needed when adding a layer");
292   REPORT_UNLESS ((layer =
293           _ges_get_layer_by_priority (timeline, priority)), done,
294       "No layer with priority: %d", priority);
295
296   gst_structure_get_boolean (action->structure, "auto-transition",
297       &auto_transition);
298   g_object_set (layer, "priority", priority, "auto-transition", auto_transition,
299       NULL);
300   gst_object_unref (layer);
301 }
302
303 GST_END_VALIDATE_ACTION;
304
305 GES_START_VALIDATE_ACTION (_remove_layer)
306 {
307   GESLayer *layer = NULL;
308   gint priority;
309
310   REPORT_UNLESS (gst_structure_get_int (action->structure, "priority",
311           &priority), done, "'priority' is required when removing a layer");
312   layer = _ges_get_layer_by_priority (timeline, priority);
313   REPORT_UNLESS (layer, beach, "No layer with priority %d", priority);
314
315   res = ges_timeline_remove_layer (timeline, layer);
316
317 beach:
318   gst_clear_object (&layer);
319 }
320
321 GST_END_VALIDATE_ACTION;
322
323 GES_START_VALIDATE_ACTION (_remove_clip)
324 {
325   GESTimelineElement *clip;
326   GESLayer *layer = NULL;
327   const gchar *name;
328
329   name = gst_structure_get_string (action->structure, "name");
330   clip = ges_timeline_get_element (timeline, name);
331   REPORT_UNLESS (GES_IS_CLIP (clip), beach, "Couldn't find clip: %s", name);
332
333   layer = ges_clip_get_layer (GES_CLIP (clip));
334   REPORT_UNLESS (layer, beach, "Clip %s not in a layer", name);
335
336   res = ges_layer_remove_clip (layer, GES_CLIP (clip));
337
338 beach:
339   gst_clear_object (&layer);
340   gst_clear_object (&clip);
341 }
342
343 GST_END_VALIDATE_ACTION;
344
345 GES_START_VALIDATE_ACTION (_edit)
346 {
347   GList *layers = NULL;
348   GESTimelineElement *element;
349   GESFrameNumber fposition = GES_FRAME_NUMBER_NONE;
350   GstClockTime position;
351   GError *err = NULL;
352   gboolean source_position = FALSE;
353
354   gint new_layer_priority = -1;
355   guint edge = GES_EDGE_NONE;
356   guint mode = GES_EDIT_MODE_NORMAL;
357
358   const gchar *edit_mode_str = NULL, *edge_str = NULL;
359   const gchar *element_name;
360
361   res = GST_VALIDATE_EXECUTE_ACTION_ERROR;
362   element_name = gst_structure_get_string (action->structure,
363       gst_structure_has_name (action->structure, "edit-container") ?
364       "container-name" : "element-name");
365
366   element = ges_timeline_get_element (timeline, element_name);
367   REPORT_UNLESS (element, beach, "Could not find element %s", element_name);
368
369   if (!_get_clocktime (action->structure, "position", &position, &fposition)) {
370     fposition = 0;
371     if (!gst_structure_get_int (action->structure, "source-frame",
372             (gint *) & fposition)
373         && !gst_structure_get_int64 (action->structure, "source-frame",
374             &fposition)) {
375       gchar *structstr = gst_structure_to_string (action->structure);
376
377       GST_VALIDATE_REPORT_ACTION (scenario, action,
378           SCENARIO_ACTION_EXECUTION_ERROR,
379           "could not find `position` or `source-frame` in %s", structstr);
380       g_free (structstr);
381       goto beach;
382     }
383
384     source_position = TRUE;
385     position = GST_CLOCK_TIME_NONE;
386   }
387
388   if ((edit_mode_str =
389           gst_structure_get_string (action->structure, "edit-mode"))) {
390     REPORT_UNLESS (gst_validate_utils_enum_from_str (GES_TYPE_EDIT_MODE,
391             edit_mode_str, &mode), beach,
392         "Could not get enum from %s", edit_mode_str);
393   }
394
395   if ((edge_str = gst_structure_get_string (action->structure, "edge"))) {
396     REPORT_UNLESS (gst_validate_utils_enum_from_str (GES_TYPE_EDGE, edge_str,
397             &edge), beach, "Could not get enum from %s", edge_str);
398   }
399
400   if (GES_FRAME_NUMBER_IS_VALID (fposition)) {
401     if (source_position) {
402       GESClip *clip = NULL;
403
404       if (GES_IS_CLIP (element))
405         clip = GES_CLIP (element);
406       else if (GES_IS_TRACK_ELEMENT (element))
407         clip = GES_CLIP (element->parent);
408
409       REPORT_UNLESS (clip, beach,
410           "Could not get find element to edit using source frame for %"
411           GST_PTR_FORMAT, action->structure);
412       position =
413           ges_clip_get_timeline_time_from_source_frame (clip, fposition, &err);
414     } else {
415       position = ges_timeline_get_frame_time (timeline, fposition);
416     }
417
418     REPORT_UNLESS (GST_CLOCK_TIME_IS_VALID (position), beach,
419         "Invalid frame number '%" G_GINT64_FORMAT "': %s", fposition,
420         err ? err->message : "Unknown");
421   }
422
423   gst_structure_get_int (action->structure, "new-layer-priority",
424       &new_layer_priority);
425
426   if (!(res = ges_timeline_element_edit (element, layers,
427               new_layer_priority, mode, edge, position))) {
428
429     gchar *fpositionstr = GES_FRAME_NUMBER_IS_VALID (fposition)
430         ? g_strdup_printf ("(%" G_GINT64_FORMAT ")", fposition)
431         : NULL;
432
433     GST_VALIDATE_REPORT_ACTION (scenario, action,
434         SCENARIO_ACTION_EXECUTION_ERROR,
435         "Could not edit '%s' to %" GST_TIME_FORMAT
436         "%s in %s mode, edge: %s "
437         "with new layer prio: %d",
438         element_name, GST_TIME_ARGS (position),
439         fpositionstr ? fpositionstr : "",
440         edit_mode_str ? edit_mode_str : "normal",
441         edge_str ? edge_str : "None", new_layer_priority);
442     g_free (fpositionstr);
443     goto beach;
444   }
445
446 beach:
447   gst_clear_object (&element);
448   g_clear_error (&err);
449 }
450
451 GST_END_VALIDATE_ACTION;
452
453
454 static void
455 _state_changed_cb (GstBus * bus, GstMessage * message,
456     GstValidateAction * action)
457 {
458   GstState next_state;
459
460   if (!GST_IS_PIPELINE (GST_MESSAGE_SRC (message)))
461     return;
462
463   gst_message_parse_state_changed (message, NULL, NULL, &next_state);
464
465   if (next_state == GST_STATE_VOID_PENDING) {
466     gst_validate_action_set_done (action);
467
468     g_signal_handlers_disconnect_by_func (bus, _state_changed_cb, action);
469   }
470 }
471
472 GES_START_VALIDATE_ACTION (_commit)
473 {
474   GstBus *bus;
475   GstState state;
476
477   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
478
479   gst_validate_printf (action, "Committing timeline %s\n",
480       GST_OBJECT_NAME (timeline));
481
482   g_signal_connect (bus, "message::state-changed",
483       G_CALLBACK (_state_changed_cb), action);
484
485   gst_element_get_state (pipeline, &state, NULL, 0);
486   if (!ges_timeline_commit (timeline) || state < GST_STATE_PAUSED) {
487     g_signal_handlers_disconnect_by_func (bus, G_CALLBACK (_state_changed_cb),
488         action);
489     gst_object_unref (bus);
490     goto done;
491   }
492
493   gst_object_unref (bus);
494
495   res = GST_VALIDATE_EXECUTE_ACTION_ASYNC;
496 }
497
498 GST_END_VALIDATE_ACTION;
499
500 GES_START_VALIDATE_ACTION (_split_clip)
501 {
502   const gchar *clip_name;
503   GESTimelineElement *element;
504   GstClockTime position;
505
506   clip_name = gst_structure_get_string (action->structure, "clip-name");
507
508   element = ges_timeline_get_element (timeline, clip_name);
509   REPORT_UNLESS (GES_IS_CLIP (element), beach, "Could not find clip: %s",
510       clip_name);
511   REPORT_UNLESS (gst_validate_action_get_clocktime (scenario, action,
512           "position", &position), beach,
513       "Could not find position in %" GST_PTR_FORMAT, action->structure);
514   res = (ges_clip_split (GES_CLIP (element), position) != NULL);
515
516 beach:
517   gst_clear_object (&element);
518 }
519
520 GST_END_VALIDATE_ACTION;
521
522 typedef struct
523 {
524   GstValidateScenario *scenario;
525   GESTimelineElement *element;
526   GstValidateActionReturn res;
527   GstClockTime time;
528   gboolean on_children;
529   GstValidateAction *action;
530 } PropertyData;
531
532 static gboolean
533 check_property (GQuark field_id, GValue * expected_value, PropertyData * data)
534 {
535   GValue cvalue = G_VALUE_INIT, *tvalue = NULL, comparable_value = G_VALUE_INIT,
536       *observed_value;
537   const gchar *property = g_quark_to_string (field_id);
538   GstControlBinding *binding = NULL;
539
540   if (!data->on_children) {
541     GParamSpec *pspec =
542         g_object_class_find_property (G_OBJECT_GET_CLASS (data->element),
543         property);
544     if (!pspec) {
545       GST_VALIDATE_REPORT_ACTION (data->scenario, data->action,
546           SCENARIO_ACTION_EXECUTION_ERROR,
547           "Could not get property %s on %" GES_FORMAT,
548           property, GES_ARGS (data->element));
549       data->res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
550
551       return FALSE;
552     }
553
554     g_value_init (&cvalue, pspec->value_type);
555     g_object_get_property (G_OBJECT (data->element), property, &cvalue);
556     goto compare;
557   }
558
559   if (GST_CLOCK_TIME_IS_VALID (data->time)) {
560     if (!GES_IS_TRACK_ELEMENT (data->element)) {
561       GST_VALIDATE_REPORT_ACTION (data->scenario, data->action,
562           SCENARIO_ACTION_EXECUTION_ERROR,
563           "Could not get property at time for type %s - only GESTrackElement supported",
564           G_OBJECT_TYPE_NAME (data->element));
565       data->res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
566
567       return FALSE;
568     }
569
570     binding =
571         ges_track_element_get_control_binding (GES_TRACK_ELEMENT
572         (data->element), property);
573     if (binding) {
574       tvalue = gst_control_binding_get_value (binding, data->time);
575
576       if (!tvalue) {
577         GST_VALIDATE_REPORT_ACTION (data->scenario, data->action,
578             SCENARIO_ACTION_EXECUTION_ERROR,
579             "Could not get property: %s at %" GST_TIME_FORMAT, property,
580             GST_TIME_ARGS (data->time));
581         data->res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
582
583         return FALSE;
584       }
585     }
586   }
587
588   if (!tvalue
589       && !ges_timeline_element_get_child_property (data->element, property,
590           &cvalue)) {
591     GST_VALIDATE_REPORT_ACTION (data->scenario, data->action,
592         SCENARIO_ACTION_EXECUTION_ERROR, "Could not get property: %s:",
593         property);
594     data->res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
595
596     return FALSE;
597   }
598
599 compare:
600   observed_value = tvalue ? tvalue : &cvalue;
601
602   if (G_VALUE_TYPE (observed_value) != G_VALUE_TYPE (expected_value)) {
603     g_value_init (&comparable_value, G_VALUE_TYPE (observed_value));
604
605     if (G_VALUE_TYPE (observed_value) == GST_TYPE_CLOCK_TIME) {
606       GstClockTime t;
607
608       if (gst_validate_utils_get_clocktime (data->action->structure, property,
609               &t)) {
610         g_value_set_uint64 (&comparable_value, t);
611         expected_value = &comparable_value;
612       }
613     } else if (g_value_transform (expected_value, &comparable_value)) {
614       expected_value = &comparable_value;
615     }
616   }
617
618   if (gst_value_compare (observed_value, expected_value) != GST_VALUE_EQUAL) {
619     gchar *expected = gst_value_serialize (expected_value), *observed =
620         gst_value_serialize (observed_value);
621
622     GST_VALIDATE_REPORT_ACTION (data->scenario, data->action,
623         SCENARIO_ACTION_CHECK_ERROR,
624         "%s:%s expected value: '(%s)%s' different than observed: '(%s)%s'",
625         GES_TIMELINE_ELEMENT_NAME (data->element), property,
626         G_VALUE_TYPE_NAME (observed_value), expected,
627         G_VALUE_TYPE_NAME (expected_value), observed);
628
629     g_free (expected);
630     g_free (observed);
631     data->res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
632   }
633
634   if (G_VALUE_TYPE (&comparable_value) != G_TYPE_NONE)
635     g_value_unset (&comparable_value);
636
637   if (tvalue) {
638     g_value_unset (tvalue);
639     g_free (tvalue);
640   } else
641     g_value_reset (&cvalue);
642   return TRUE;
643 }
644
645 static gboolean
646 set_property (GQuark field_id, const GValue * value, PropertyData * data)
647 {
648   const gchar *property = g_quark_to_string (field_id);
649
650   if (data->on_children) {
651     if (!ges_timeline_element_set_child_property (data->element, property,
652             value)) {
653       gchar *v = gst_value_serialize (value);
654
655       GST_VALIDATE_REPORT_ACTION (data->scenario, data->action,
656           SCENARIO_ACTION_EXECUTION_ERROR,
657           "Could not set %s child property %s to %s",
658           GES_TIMELINE_ELEMENT_NAME (data->element), property, v);
659
660       data->res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
661       g_free (v);
662
663       return FALSE;
664     }
665   } else {
666     data->res =
667         gst_validate_object_set_property (GST_VALIDATE_REPORTER
668         (data->scenario), G_OBJECT (data->element), property, value, FALSE);
669   }
670
671   return TRUE;
672 }
673
674 GES_START_VALIDATE_ACTION (set_or_check_properties)
675 {
676   GESTimelineElement *element;
677   GstStructure *structure;
678   const gchar *element_name;
679   gboolean is_setting = FALSE;
680   PropertyData data = {
681     .scenario = scenario,
682     .element = NULL,
683     .res = GST_VALIDATE_EXECUTE_ACTION_OK,
684     .time = GST_CLOCK_TIME_NONE,
685     .on_children =
686         !gst_structure_has_name (action->structure, "check-ges-properties")
687         && !gst_structure_has_name (action->structure, "set-ges-properties"),
688     .action = action,
689   };
690
691   is_setting = gst_structure_has_name (action->structure, "set-ges-properties")
692       || gst_structure_has_name (action->structure, "set-child-properties");
693   gst_validate_action_get_clocktime (scenario, action, "at-time", &data.time);
694
695   structure = gst_structure_copy (action->structure);
696   element_name = gst_structure_get_string (structure, "element-name");
697   element = ges_timeline_get_element (timeline, element_name);
698   if (!element) {
699     GST_VALIDATE_REPORT_ACTION (scenario, action,
700         SCENARIO_ACTION_EXECUTION_ERROR,
701         "Can not find element: %s", element_name);
702
703     data.res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
704     goto local_done;
705   }
706
707   data.element = element;
708   gst_structure_remove_fields (structure, "element-name", "at-time",
709       "project-uri", NULL);
710   gst_structure_foreach (structure,
711       is_setting ? (GstStructureForeachFunc) set_property
712       : (GstStructureForeachFunc) check_property, &data);
713   gst_object_unref (element);
714
715 local_done:
716   gst_structure_free (structure);
717   res = data.res;
718 }
719
720 GST_END_VALIDATE_ACTION;
721
722 GES_START_VALIDATE_ACTION (_set_track_restriction_caps)
723 {
724   GList *tmp;
725   GstCaps *caps;
726   GESTrackType track_types;
727
728   const gchar *track_type_str =
729       gst_structure_get_string (action->structure, "track-type");
730   const gchar *caps_str = gst_structure_get_string (action->structure, "caps");
731
732   REPORT_UNLESS (track_types =
733       gst_validate_utils_flags_from_str (GES_TYPE_TRACK_TYPE, track_type_str),
734       done, "Invalid track types: %s", track_type_str);
735
736   REPORT_UNLESS (caps = gst_caps_from_string (caps_str),
737       done, "Invalid track restriction caps: %s", caps_str);
738
739   res = GST_VALIDATE_EXECUTE_ACTION_ERROR;
740   for (tmp = timeline->tracks; tmp; tmp = tmp->next) {
741     GESTrack *track = tmp->data;
742
743     if (track->type & track_types) {
744       gchar *str;
745
746       str = gst_caps_to_string (caps);
747       g_free (str);
748
749       ges_track_set_restriction_caps (track, caps);
750
751       res = GST_VALIDATE_EXECUTE_ACTION_OK;
752     }
753   }
754   gst_caps_unref (caps);
755 }
756
757 GST_END_VALIDATE_ACTION;
758
759 GES_START_VALIDATE_ACTION (_set_asset_on_element)
760 {
761   GESAsset *asset;
762   GESTimelineElement *element;
763   const gchar *element_name, *id;
764
765   element_name = gst_structure_get_string (action->structure, "element-name");
766   element = ges_timeline_get_element (timeline, element_name);
767   REPORT_UNLESS (element, done, "Can't find %s", element_name);
768
769   id = gst_structure_get_string (action->structure, "asset-id");
770
771   gst_validate_printf (action, "Setting asset %s on element %s\n",
772       id, element_name);
773
774   asset = _ges_get_asset_from_timeline (timeline, G_OBJECT_TYPE (element), id,
775       NULL);
776   REPORT_UNLESS (asset, beach, "Could not find asset: %s", id);
777
778   res = ges_extractable_set_asset (GES_EXTRACTABLE (element), asset);
779
780 beach:
781   gst_clear_object (&asset);
782   gst_clear_object (&element);
783 }
784
785 GST_END_VALIDATE_ACTION;
786
787 GES_START_VALIDATE_ACTION (_container_remove_child)
788 {
789   GESContainer *container = NULL;
790   GESTimelineElement *child = NULL;
791   const gchar *container_name, *child_name;
792
793   container_name =
794       gst_structure_get_string (action->structure, "container-name");
795   container =
796       (GESContainer *) ges_timeline_get_element (timeline, container_name);
797   REPORT_UNLESS (GES_IS_CONTAINER (container), beach,
798       "Could not find container: %s", container_name);
799
800   child_name = gst_structure_get_string (action->structure, "child-name");
801   child = ges_timeline_get_element (timeline, child_name);
802   REPORT_UNLESS (GES_IS_TIMELINE_ELEMENT (child), beach, "Could not find %s",
803       child_name);
804
805   res = ges_container_remove (container, child);
806
807 beach:
808   gst_clear_object (&container);
809   gst_clear_object (&child);
810 }
811
812 GST_END_VALIDATE_ACTION;
813
814 GES_START_VALIDATE_ACTION (_ungroup)
815 {
816   GESContainer *container;
817   gboolean recursive = FALSE;
818   const gchar *container_name;
819
820   container_name =
821       gst_structure_get_string (action->structure, "container-name");
822   container =
823       (GESContainer *) ges_timeline_get_element (timeline, container_name);
824   REPORT_UNLESS (GES_IS_CONTAINER (container), beach, "Could not find %s",
825       container_name);
826
827   gst_structure_get_boolean (action->structure, "recursive", &recursive);
828
829   g_list_free (ges_container_ungroup (container, recursive));
830
831 beach:
832   gst_clear_object (&container);
833 }
834
835 GST_END_VALIDATE_ACTION;
836
837 GES_START_VALIDATE_ACTION (_copy_element)
838 {
839   GESTimelineElement *element = NULL, *copied = NULL, *pasted = NULL;
840   gboolean recursive = FALSE;
841   const gchar *element_name, *paste_name;
842   GstClockTime position;
843
844   element_name = gst_structure_get_string (action->structure, "element-name");
845   element = ges_timeline_get_element (timeline, element_name);
846
847   REPORT_UNLESS (GES_IS_CONTAINER (element), beach, "Could not find %s",
848       element_name);
849
850   if (!gst_structure_get_boolean (action->structure, "recursive", &recursive))
851     recursive = TRUE;
852
853   REPORT_UNLESS (gst_validate_action_get_clocktime (scenario, action,
854           "position", &position), beach, "Could not find position");
855
856   copied = ges_timeline_element_copy (element, recursive);
857   pasted = ges_timeline_element_paste (copied, position);
858
859   REPORT_UNLESS (pasted, beach, "Could not paste clip %s", element_name);
860
861   paste_name = gst_structure_get_string (action->structure, "paste-name");
862   if (paste_name)
863     REPORT_UNLESS (ges_timeline_element_set_name (pasted, paste_name),
864         beach, "Could not set element name %s", paste_name);
865
866 beach:
867   gst_clear_object (&pasted);
868   gst_clear_object (&element);
869
870   /* `copied` is only used for the single paste operation, and is not
871    * actually in any timeline. We own it (it is actually still floating).
872    * `pasted` is the actual new object in the timeline. We own a
873    * reference to it. */
874   gst_clear_object (&copied);
875 }
876
877 GST_END_VALIDATE_ACTION;
878
879 GES_START_VALIDATE_ACTION (_set_control_source)
880 {
881   guint mode;
882   GESTrackElement *element = NULL;
883
884   GstControlSource *source = NULL;
885   gchar *element_name, *property_name, *binding_type = NULL,
886       *source_type = NULL, *interpolation_mode = NULL;
887
888   REPORT_UNLESS (gst_structure_get (action->structure,
889           "element-name", G_TYPE_STRING, &element_name,
890           "property-name", G_TYPE_STRING, &property_name, NULL),
891       beach, "Wrong parameters");
892
893   TRY_GET ("binding-type", G_TYPE_STRING, &binding_type, NULL);
894   TRY_GET ("source-type", G_TYPE_STRING, &source_type, NULL);
895   TRY_GET ("interpolation-mode", G_TYPE_STRING, &interpolation_mode, NULL);
896
897   element =
898       (GESTrackElement *) (ges_timeline_get_element (timeline, element_name));
899   if (GES_IS_CLIP (element)) {
900     GList *tmp;
901     for (tmp = GES_CONTAINER_CHILDREN (element); tmp; tmp = tmp->next) {
902       if (ges_timeline_element_lookup_child (tmp->data, property_name, NULL,
903               NULL)) {
904         gst_object_replace ((GstObject **) & element, tmp->data);
905
906         break;
907       }
908     }
909   }
910   REPORT_UNLESS (GES_IS_TRACK_ELEMENT (element), beach,
911       "Could not find track element element %s (got %" GST_PTR_FORMAT ")",
912       element_name, element);
913
914   if (!binding_type)
915     binding_type = g_strdup ("direct");
916
917   REPORT_UNLESS (source_type == NULL
918       || !g_strcmp0 (source_type, "interpolation"), beach,
919       "Interpolation type %s not supported", source_type);
920   source = gst_interpolation_control_source_new ();
921
922   if (interpolation_mode)
923     REPORT_UNLESS (gst_validate_utils_enum_from_str
924         (GST_TYPE_INTERPOLATION_MODE, interpolation_mode, &mode), beach,
925         "Wrong intorpolation mode: %s", interpolation_mode);
926   else
927     mode = GST_INTERPOLATION_MODE_LINEAR;
928
929   g_object_set (source, "mode", mode, NULL);
930
931   res = ges_track_element_set_control_source (element,
932       source, property_name, binding_type);
933
934 beach:
935   gst_clear_object (&element);
936   gst_clear_object (&source);
937   g_free (property_name);
938   g_free (element_name);
939   g_free (binding_type);
940   g_free (source_type);
941   g_free (interpolation_mode);
942 }
943
944 GST_END_VALIDATE_ACTION;
945
946 GES_START_VALIDATE_ACTION (_validate_action_execute)
947 {
948   GError *err = NULL;
949   ActionFromStructureFunc func;
950
951   gst_structure_remove_field (action->structure, "playback-time");
952   if (gst_structure_has_name (action->structure, "add-keyframe") ||
953       gst_structure_has_name (action->structure, "remove-keyframe")) {
954     func = _ges_add_remove_keyframe_from_struct;
955   } else if (gst_structure_has_name (action->structure, "add-clip")) {
956     func = _ges_add_clip_from_struct;
957   } else if (gst_structure_has_name (action->structure, "container-add-child")) {
958     func = _ges_container_add_child_from_struct;
959   } else if (gst_structure_has_name (action->structure, "set-child-property")) {
960     func = _ges_set_child_property_from_struct;
961   } else {
962     g_assert_not_reached ();
963   }
964
965   if (!func (timeline, action->structure, &err)) {
966     GST_VALIDATE_REPORT_ACTION (scenario, action,
967         g_quark_from_string ("scenario::execution-error"),
968         "Could not execute %s (error: %s)",
969         gst_structure_get_name (action->structure),
970         err ? err->message : "None");
971
972     g_clear_error (&err);
973     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
974   }
975 }
976
977 GST_END_VALIDATE_ACTION;
978
979 static void
980 _project_loaded_cb (GESProject * project, GESTimeline * timeline,
981     GstValidateAction * action)
982 {
983   gst_validate_action_set_done (action);
984 }
985
986 GES_START_VALIDATE_ACTION (_load_project)
987 {
988   GstState state;
989   GESProject *project = NULL;
990   GList *tmp, *tmp_full;
991
992   gchar *uri = NULL;
993   GError *error = NULL;
994   const gchar *content = NULL;
995
996   gchar *tmpfile = g_strdup_printf ("%s%s%s", g_get_tmp_dir (),
997       G_DIR_SEPARATOR_S, "tmpxgesload.xges");
998
999   res = GST_VALIDATE_EXECUTE_ACTION_ASYNC;
1000   REPORT_UNLESS (GES_IS_PIPELINE (pipeline), local_done,
1001       "Not a GES pipeline, can't work with it");
1002
1003   gst_element_get_state (pipeline, &state, NULL, 0);
1004   gst_element_set_state (pipeline, GST_STATE_NULL);
1005
1006   content = gst_structure_get_string (action->structure, "serialized-content");
1007   if (content) {
1008
1009     g_file_set_contents (tmpfile, content, -1, &error);
1010     REPORT_UNLESS (!error, local_done,
1011         "Could not set XML content: %s", error->message);
1012
1013     uri = gst_filename_to_uri (tmpfile, &error);
1014     REPORT_UNLESS (!error, local_done,
1015         "Could not set filename to URI: %s", error->message);
1016   } else {
1017     uri = g_strdup (gst_structure_get_string (action->structure, "uri"));
1018     REPORT_UNLESS (uri, local_done,
1019         "None of 'uri' or 'content' passed as parameter"
1020         " can't load any timeline!");
1021   }
1022
1023   tmp_full = ges_timeline_get_layers (timeline);
1024   for (tmp = tmp_full; tmp; tmp = tmp->next)
1025     ges_timeline_remove_layer (timeline, tmp->data);
1026   g_list_free_full (tmp_full, gst_object_unref);
1027
1028   tmp_full = ges_timeline_get_tracks (timeline);
1029   for (tmp = tmp_full; tmp; tmp = tmp->next)
1030     ges_timeline_remove_track (timeline, tmp->data);
1031   g_list_free_full (tmp_full, gst_object_unref);
1032
1033   project = ges_project_new (uri);
1034   g_signal_connect (project, "loaded", G_CALLBACK (_project_loaded_cb), action);
1035   ges_project_load (project, gst_object_ref (timeline), &error);
1036   REPORT_UNLESS (!error, local_done,
1037       "Could not load timeline: %s", error->message);
1038
1039   gst_element_set_state (pipeline, state);
1040
1041 local_done:
1042   gst_clear_object (&project);
1043   g_clear_error (&error);
1044   g_free (uri);
1045   g_free (tmpfile);
1046 }
1047
1048 GST_END_VALIDATE_ACTION;
1049
1050 static gint
1051 prepare_seek_action (GstValidateAction * action)
1052 {
1053   gint res = GST_VALIDATE_EXECUTE_ACTION_ERROR;
1054   GESFrameNumber fstart, fstop;
1055   GstValidateScenario *scenario = gst_validate_action_get_scenario (action);
1056   GstValidateActionType *type = gst_validate_get_action_type (action->type);
1057   GError *err = NULL;
1058
1059   DECLARE_AND_GET_TIMELINE (scenario, action);
1060
1061   if (timeline
1062       && ges_util_structure_get_clocktime (action->structure, "start", NULL,
1063           &fstart)) {
1064     GstClockTime start = ges_timeline_get_frame_time (timeline, fstart);
1065
1066     if (err) {
1067       GST_VALIDATE_REPORT_ACTION (scenario, action,
1068           SCENARIO_ACTION_EXECUTION_ERROR,
1069           "Invalid seeking frame number '%" G_GINT64_FORMAT "': %s", fstart,
1070           err->message);
1071       goto done;
1072     }
1073     gst_structure_set (action->structure, "start", G_TYPE_UINT64, start, NULL);
1074   }
1075
1076   if (timeline
1077       && ges_util_structure_get_clocktime (action->structure, "stop", NULL,
1078           &fstop)) {
1079     GstClockTime stop = ges_timeline_get_frame_time (timeline, fstop);
1080
1081     if (err) {
1082       GST_VALIDATE_REPORT_ACTION (scenario, action,
1083           SCENARIO_ACTION_EXECUTION_ERROR,
1084           "Invalid seeking frame number '%" G_GINT64_FORMAT "': %s", fstop,
1085           err->message);
1086       goto done;
1087     }
1088     gst_structure_set (action->structure, "stop", G_TYPE_UINT64, stop, NULL);
1089   }
1090
1091   gst_object_unref (scenario);
1092   gst_object_unref (timeline);
1093   return type->overriden_type->prepare (action);
1094
1095 done:
1096   gst_object_unref (scenario);
1097   gst_object_unref (timeline);
1098   return res;
1099 }
1100
1101 static gint
1102 set_layer_active (GstValidateScenario * scenario, GstValidateAction * action)
1103 {
1104   gboolean active;
1105   gint i, layer_prio;
1106   GESLayer *layer;
1107   GList *tracks = NULL;
1108   GstValidateExecuteActionReturn res = GST_VALIDATE_EXECUTE_ACTION_OK;
1109   gchar **track_names =
1110       gst_validate_utils_get_strv (action->structure, "tracks");
1111
1112   DECLARE_AND_GET_TIMELINE (scenario, action);
1113
1114   for (i = 0; track_names[i]; i++) {
1115     GESTrack *track =
1116         (GESTrack *) gst_bin_get_by_name (GST_BIN (timeline), track_names[i]);
1117
1118     if (!track) {
1119       GST_VALIDATE_REPORT_ACTION (scenario, action,
1120           SCENARIO_ACTION_EXECUTION_ERROR,
1121           "Could not find track %s", track_names[i]);
1122       res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1123       goto done;
1124     }
1125
1126     tracks = g_list_prepend (tracks, track);
1127   }
1128
1129   if (!gst_structure_get_int (action->structure, "layer-priority", &layer_prio)) {
1130     GST_VALIDATE_REPORT_ACTION (scenario, action,
1131         SCENARIO_ACTION_EXECUTION_ERROR,
1132         "Could not find layer from %" GST_PTR_FORMAT, action->structure);
1133     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1134     goto done;
1135   }
1136   if (!(layer = g_list_nth_data (timeline->layers, layer_prio))) {
1137     GST_VALIDATE_REPORT_ACTION (scenario, action,
1138         SCENARIO_ACTION_EXECUTION_ERROR, "Could not find layer %d", layer_prio);
1139     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1140     goto done;
1141   }
1142
1143   if (!gst_structure_get_boolean (action->structure, "active", &active)) {
1144     GST_VALIDATE_REPORT_ACTION (scenario, action,
1145         SCENARIO_ACTION_EXECUTION_ERROR,
1146         "Could not find 'active' boolean in %" GST_PTR_FORMAT,
1147         action->structure);
1148     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1149     goto done;
1150   }
1151
1152   if (!ges_layer_set_active_for_tracks (layer, active, tracks)) {
1153     GST_VALIDATE_REPORT_ACTION (scenario, action,
1154         SCENARIO_ACTION_EXECUTION_ERROR,
1155         "Could not set active for track defined in %" GST_PTR_FORMAT,
1156         action->structure);
1157     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1158     goto done;
1159   }
1160
1161 done:
1162   g_strfreev (track_names);
1163   gst_object_unref (timeline);
1164   g_list_free_full (tracks, gst_object_unref);
1165
1166   return res;
1167 }
1168
1169 #endif
1170
1171 gboolean
1172 ges_validate_register_action_types (void)
1173 {
1174 #ifdef HAVE_GST_VALIDATE
1175   GstValidateActionType *validate_seek, *seek_override;
1176
1177
1178   gst_validate_init ();
1179   validate_seek = gst_validate_get_action_type ("seek");
1180
1181   /*  *INDENT-OFF* */
1182   seek_override = gst_validate_register_action_type("seek", "ges", validate_seek->execute,
1183                                     validate_seek->parameters, validate_seek->description,
1184                                     validate_seek->flags);
1185   gst_mini_object_unref(GST_MINI_OBJECT(validate_seek));
1186   seek_override->prepare = prepare_seek_action;
1187
1188   gst_validate_register_action_type ("edit-container", "ges", _edit,
1189       (GstValidateActionParameter [])  {
1190         {
1191          .name = "container-name",
1192          .description = "The name of the GESContainer to edit",
1193          .mandatory = TRUE,
1194          .types = "string",
1195         },
1196         {
1197           .name = "position",
1198           .description = "The new position of the GESContainer",
1199           .mandatory = FALSE,
1200           .types = "double or string",
1201           .possible_variables = "position: The current position in the stream\n"
1202             "duration: The duration of the stream",
1203            NULL
1204         },
1205         {
1206           .name = "edit-mode",
1207           .description = "The GESEditMode to use to edit @container-name",
1208           .mandatory = FALSE,
1209           .types = "string",
1210           .def = "normal",
1211         },
1212         {
1213           .name = "edge",
1214           .description = "The GESEdge to use to edit @container-name\n"
1215                          "should be in [ start, end, none ] ",
1216           .mandatory = FALSE,
1217           .types = "string",
1218           .def = "none",
1219         },
1220         {
1221           .name = "new-layer-priority",
1222           .description = "The priority of the layer @container should land in.\n"
1223                          "If the layer you're trying to move the container to doesn't exist, it will\n"
1224                          "be created automatically. -1 means no move.",
1225           .mandatory = FALSE,
1226           .types = "int",
1227           .def = "-1",
1228         },
1229         {
1230           .name = "project-uri",
1231           .description = "The project URI with the serialized timeline to execute the action on",
1232           .types = "string",
1233           .mandatory = FALSE,
1234         },
1235         {NULL}
1236        },
1237        "Allows to edit a container (like a GESClip), for more details, have a look at:\n"
1238        "ges_timeline_element_edit documentation, Note that the timeline will\n"
1239        "be committed, and flushed so that the edition is taken into account",
1240        GST_VALIDATE_ACTION_TYPE_NONE);
1241
1242   gst_validate_register_action_type ("edit", "ges", _edit,
1243       (GstValidateActionParameter [])  {
1244         {
1245          .name = "element-name",
1246          .description = "The name of the element to edit",
1247          .mandatory = TRUE,
1248          .types = "string",
1249         },
1250         {
1251           .name = "position",
1252           .description = "The new position of the element",
1253           .mandatory = FALSE,
1254           .types = "double or string",
1255           .possible_variables = "position: The current position in the stream\n"
1256             "duration: The duration of the stream",
1257            NULL
1258         },
1259         {
1260           .name = "source-frame",
1261           .description = "The new frame of the element, computed from the @element-name"
1262             "clip's source frame.",
1263           .mandatory = FALSE,
1264           .types = "double or string",
1265            NULL
1266         },
1267         {
1268           .name = "edit-mode",
1269           .description = "The GESEditMode to use to edit @element-name",
1270           .mandatory = FALSE,
1271           .types = "string",
1272           .def = "normal",
1273         },
1274         {
1275           .name = "edge",
1276           .description = "The GESEdge to use to edit @element-name\n"
1277                          "should be in [ start, end, none ] ",
1278           .mandatory = FALSE,
1279           .types = "string",
1280           .def = "none",
1281         },
1282         {
1283           .name = "new-layer-priority",
1284           .description = "The priority of the layer @element should land in.\n"
1285                          "If the layer you're trying to move the element to doesn't exist, it will\n"
1286                          "be created automatically. -1 means no move.",
1287           .mandatory = FALSE,
1288           .types = "int",
1289           .def = "-1",
1290         },
1291         {
1292           .name = "project-uri",
1293           .description = "The project URI with the serialized timeline to execute the action on",
1294           .types = "string",
1295           .mandatory = FALSE,
1296         },
1297         {NULL}
1298        },
1299        "Allows to edit a element (like a GESClip), for more details, have a look at:\n"
1300        "ges_timeline_element_edit documentation, Note that the timeline will\n"
1301        "be committed, and flushed so that the edition is taken into account",
1302        GST_VALIDATE_ACTION_TYPE_NONE);
1303
1304   gst_validate_register_action_type ("add-asset", "ges", _add_asset,
1305       (GstValidateActionParameter [])  {
1306         {
1307           .name = "id",
1308           .description = "Adds an asset to a project.",
1309           .mandatory = TRUE,
1310           NULL
1311         },
1312         {
1313           .name = "type",
1314           .description = "The type of asset to add",
1315           .mandatory = TRUE,
1316           NULL
1317         },
1318         {
1319           .name = "project-uri",
1320           .description = "The project URI with the serialized timeline to execute the action on",
1321           .types = "string",
1322           .mandatory = FALSE,
1323         },
1324         {NULL}
1325       },
1326       "Allows to add an asset to the current project", GST_VALIDATE_ACTION_TYPE_NONE);
1327
1328   gst_validate_register_action_type ("remove-asset", "ges", _remove_asset,
1329       (GstValidateActionParameter [])  {
1330         {
1331           .name = "id",
1332           .description = "The ID of the clip to remove",
1333           .mandatory = TRUE,
1334           NULL
1335         },
1336         {
1337           .name = "type",
1338           .description = "The type of asset to remove",
1339           .mandatory = TRUE,
1340           NULL
1341         },
1342         {
1343           .name = "project-uri",
1344           .description = "The project URI with the serialized timeline to execute the action on",
1345           .types = "string",
1346           .mandatory = FALSE,
1347         },
1348         { NULL }
1349       },
1350       "Allows to remove an asset from the current project", GST_VALIDATE_ACTION_TYPE_NONE);
1351
1352   gst_validate_register_action_type ("add-layer", "ges", _add_layer,
1353       (GstValidateActionParameter [])  {
1354         {
1355           .name = "priority",
1356           .description = "The priority of the new layer to add,"
1357                          "if not specified, the new layer will be"
1358                          " appended to the timeline",
1359           .mandatory = FALSE,
1360           NULL
1361         },
1362         {
1363           .name = "project-uri",
1364           .description = "The project URI with the serialized timeline to execute the action on",
1365           .types = "string",
1366           .mandatory = FALSE,
1367         },
1368         { NULL }
1369       },
1370       "Allows to add a layer to the current timeline", GST_VALIDATE_ACTION_TYPE_NONE);
1371
1372   gst_validate_register_action_type ("remove-layer", "ges", _remove_layer,
1373       (GstValidateActionParameter [])  {
1374         {
1375           .name = "priority",
1376           .description = "The priority of the layer to remove",
1377           .mandatory = TRUE,
1378           NULL
1379         },
1380         {
1381           .name = "auto-transition",
1382           .description = "Whether auto-transition is activated on the new layer.",
1383           .mandatory = FALSE,
1384           .types="boolean",
1385           .def = "False"
1386         },
1387         {
1388           .name = "project-uri",
1389           .description = "The nested timeline to add clip to",
1390           .types = "string",
1391           .mandatory = FALSE,
1392         },
1393         { NULL }
1394       },
1395       "Allows to remove a layer from the current timeline", GST_VALIDATE_ACTION_TYPE_NONE);
1396
1397   gst_validate_register_action_type ("add-clip", "ges", _validate_action_execute,
1398       (GstValidateActionParameter []) {
1399         {
1400           .name = "name",
1401           .description = "The name of the clip to add",
1402           .types = "string",
1403           .mandatory = TRUE,
1404         },
1405         {
1406           .name = "layer-priority",
1407           .description = "The priority of the clip to add",
1408           .types = "int",
1409           .mandatory = TRUE,
1410         },
1411         {
1412           .name = "asset-id",
1413           .description = "The id of the asset from which to extract the clip",
1414           .types = "string",
1415           .mandatory = TRUE,
1416         },
1417         {
1418           .name = "type",
1419           .description = "The type of the clip to create",
1420           .types = "string",
1421           .mandatory = TRUE,
1422         },
1423         {
1424           .name = "start",
1425           .description = "The start value to set on the new GESClip.",
1426           .types = "double or string",
1427           .mandatory = FALSE,
1428         },
1429         {
1430           .name = "inpoint",
1431           .description = "The  inpoint value to set on the new GESClip",
1432           .types = "double or string",
1433           .mandatory = FALSE,
1434         },
1435         {
1436           .name = "duration",
1437           .description = "The  duration value to set on the new GESClip",
1438           .types = "double or string",
1439           .mandatory = FALSE,
1440         },
1441         {
1442           .name = "project-uri",
1443           .description = "The project URI with the serialized timeline to execute the action on",
1444           .types = "string",
1445           .mandatory = FALSE,
1446         },
1447         {NULL}
1448       }, "Allows to add a clip to a given layer", GST_VALIDATE_ACTION_TYPE_NONE);
1449
1450   gst_validate_register_action_type ("remove-clip", "ges", _remove_clip,
1451       (GstValidateActionParameter []) {
1452         {
1453           .name = "name",
1454           .description = "The name of the clip to remove",
1455           .types = "string",
1456           .mandatory = TRUE,
1457         },
1458         {
1459           .name = "project-uri",
1460           .description = "The project URI with the serialized timeline to execute the action on",
1461           .types = "string",
1462           .mandatory = FALSE,
1463         },
1464         {NULL}
1465       }, "Allows to remove a clip from a given layer", GST_VALIDATE_ACTION_TYPE_NONE);
1466
1467   gst_validate_register_action_type ("serialize-project", "ges", _serialize_project,
1468       (GstValidateActionParameter []) {
1469         {
1470           .name = "uri",
1471           .description = "The uri where to store the serialized project",
1472           .types = "string",
1473           .mandatory = TRUE,
1474         },
1475         {NULL}
1476       }, "serializes a project", GST_VALIDATE_ACTION_TYPE_NONE);
1477
1478   gst_validate_register_action_type ("set-child-property", "ges", _validate_action_execute,
1479       (GstValidateActionParameter []) {
1480         {
1481           .name = "element-name",
1482           .description = "The name of the element on which to modify the property",
1483           .types = "string",
1484           .mandatory = TRUE,
1485         },
1486         {
1487           .name = "property",
1488           .description = "The name of the property to modify",
1489           .types = "string",
1490           .mandatory = TRUE,
1491         },
1492         {
1493           .name = "value",
1494           .description = "The value of the property",
1495           .types = "gvalue",
1496           .mandatory = TRUE,
1497         },
1498         {
1499           .name = "project-uri",
1500           .description = "The project URI with the serialized timeline to execute the action on",
1501           .types = "string",
1502           .mandatory = FALSE,
1503         },
1504         {NULL}
1505       }, "Allows to change child property of an object", GST_VALIDATE_ACTION_TYPE_NONE);
1506
1507   gst_validate_register_action_type ("set-layer-active", "ges", set_layer_active,
1508       (GstValidateActionParameter []) {
1509         {
1510           .name = "layer-priority",
1511           .description = "The priority of the layer to set activness on",
1512           .types = "gint",
1513           .mandatory = TRUE,
1514         },
1515         {
1516           .name = "active",
1517           .description = "The activness of the layer",
1518           .types = "gboolean",
1519           .mandatory = TRUE,
1520         },
1521         {
1522           .name = "tracks",
1523           .description = "tracks",
1524           .types = "{string, }",
1525           .mandatory = FALSE,
1526         },
1527         {NULL}
1528       }, "Set activness of a layer (on optional tracks).",
1529         GST_VALIDATE_ACTION_TYPE_NONE);
1530
1531   gst_validate_register_action_type ("set-ges-properties", "ges", set_or_check_properties,
1532       (GstValidateActionParameter []) {
1533         {
1534           .name = "element-name",
1535           .description = "The name of the element on which to set properties",
1536           .types = "string",
1537           .mandatory = TRUE,
1538         },
1539         {NULL}
1540       }, "Set `element-name` properties values defined by the"
1541          " fields in the following format: `property_name=expected-value`",
1542         GST_VALIDATE_ACTION_TYPE_NONE);
1543
1544   gst_validate_register_action_type ("check-ges-properties", "ges", set_or_check_properties,
1545       (GstValidateActionParameter []) {
1546         {
1547           .name = "element-name",
1548           .description = "The name of the element on which to check properties",
1549           .types = "string",
1550           .mandatory = TRUE,
1551         },
1552         {NULL}
1553       }, "Check `element-name` properties values defined by the"
1554          " fields in the following format: `property_name=expected-value`",
1555         GST_VALIDATE_ACTION_TYPE_NONE);
1556
1557   gst_validate_register_action_type ("check-child-properties", "ges", set_or_check_properties,
1558       (GstValidateActionParameter []) {
1559         {
1560           .name = "element-name",
1561           .description = "The name of the element on which to check children properties",
1562           .types = "string",
1563           .mandatory = TRUE,
1564         },
1565         {
1566           .name = "at-time",
1567           .description = "The time at which to check the values, taking into"
1568             " account the ControlBinding if any set.",
1569           .types = "string",
1570           .mandatory = FALSE,
1571         },
1572         {NULL}
1573       }, "Check `element-name` children properties values defined by the"
1574          " fields in the following format: `property_name=expected-value`",
1575         GST_VALIDATE_ACTION_TYPE_NONE);
1576
1577   gst_validate_register_action_type ("set-child-properties", "ges", set_or_check_properties,
1578       (GstValidateActionParameter []) {
1579         {
1580           .name = "element-name",
1581           .description = "The name of the element on which to modify child properties",
1582           .types = "string",
1583           .mandatory = TRUE,
1584         },
1585         {NULL}
1586       }, "Sets `element-name` children properties values defined by the"
1587          " fields in the following format: `property-name=new-value`",
1588         GST_VALIDATE_ACTION_TYPE_NONE);
1589
1590   gst_validate_register_action_type ("split-clip", "ges", _split_clip,
1591       (GstValidateActionParameter []) {
1592         {
1593           .name = "clip-name",
1594           .description = "The name of the clip to split",
1595           .types = "string",
1596           .mandatory = TRUE,
1597         },
1598         {
1599           .name = "position",
1600           .description = "The position at which to split the clip",
1601           .types = "double or string",
1602           .mandatory = TRUE,
1603         },
1604         {
1605           .name = "project-uri",
1606           .description = "The project URI with the serialized timeline to execute the action on",
1607           .types = "string",
1608           .mandatory = FALSE,
1609         },
1610         {NULL}
1611       }, "Split a clip at a specified position.", GST_VALIDATE_ACTION_TYPE_NONE);
1612
1613   gst_validate_register_action_type ("set-track-restriction-caps", "ges", _set_track_restriction_caps,
1614       (GstValidateActionParameter []) {
1615         {
1616           .name = "track-type",
1617           .description = "The type of track to set restriction caps on",
1618           .types = "string",
1619           .mandatory = TRUE,
1620         },
1621         {
1622           .name = "caps",
1623           .description = "The caps to set on the track",
1624           .types = "string",
1625           .mandatory = TRUE,
1626         },
1627         {
1628           .name = "project-uri",
1629           .description = "The project URI with the serialized timeline to execute the action on",
1630           .types = "string",
1631           .mandatory = FALSE,
1632         },
1633         {NULL}
1634       }, "Sets restriction caps on tracks of a specific type.", GST_VALIDATE_ACTION_TYPE_NONE);
1635
1636   gst_validate_register_action_type ("element-set-asset", "ges", _set_asset_on_element,
1637       (GstValidateActionParameter []) {
1638         {
1639           .name = "element-name",
1640           .description = "The name of the TimelineElement to set an asset on",
1641           .types = "string",
1642           .mandatory = TRUE,
1643         },
1644         {
1645           .name = "asset-id",
1646           .description = "The id of the asset from which to extract the clip",
1647           .types = "string",
1648           .mandatory = TRUE,
1649         },
1650         {
1651           .name = "project-uri",
1652           .description = "The project URI with the serialized timeline to execute the action on",
1653           .types = "string",
1654           .mandatory = FALSE,
1655         },
1656         {NULL}
1657       }, "Sets restriction caps on tracks of a specific type.", GST_VALIDATE_ACTION_TYPE_NONE);
1658
1659
1660   gst_validate_register_action_type ("container-add-child", "ges", _validate_action_execute,
1661       (GstValidateActionParameter []) {
1662         {
1663           .name = "container-name",
1664           .description = "The name of the GESContainer to add a child to",
1665           .types = "string",
1666           .mandatory = TRUE,
1667         },
1668         {
1669           .name = "child-name",
1670           .description = "The name of the child to add to @container-name",
1671           .types = "string",
1672           .mandatory = FALSE,
1673           .def = "NULL"
1674         },
1675         {
1676           .name = "asset-id",
1677           .description = "The id of the asset from which to extract the child",
1678           .types = "string",
1679           .mandatory = TRUE,
1680           .def = "NULL"
1681         },
1682         {
1683           .name = "child-type",
1684           .description = "The type of the child to create",
1685           .types = "string",
1686           .mandatory = FALSE,
1687           .def = "NULL"
1688         },
1689         {
1690           .name = "project-uri",
1691           .description = "The project URI with the serialized timeline to execute the action on",
1692           .types = "string",
1693           .mandatory = FALSE,
1694         },
1695         {NULL}
1696       }, "Add a child to @container-name. If asset-id and child-type are specified,"
1697        " the child will be created and added. Otherwise @child-name has to be specified"
1698        " and will be added to the container.", GST_VALIDATE_ACTION_TYPE_NONE);
1699
1700   gst_validate_register_action_type ("container-remove-child", "ges", _container_remove_child,
1701       (GstValidateActionParameter []) {
1702         {
1703           .name = "container-name",
1704           .description = "The name of the GESContainer to remove a child from",
1705           .types = "string",
1706           .mandatory = TRUE,
1707         },
1708         {
1709           .name = "child-name",
1710           .description = "The name of the child to reomve from @container-name",
1711           .types = "string",
1712           .mandatory = TRUE,
1713         },
1714         {
1715           .name = "project-uri",
1716           .description = "The project URI with the serialized timeline to execute the action on",
1717           .types = "string",
1718           .mandatory = FALSE,
1719         },
1720         {NULL}
1721       }, "Remove a child from @container-name.", FALSE);
1722
1723   gst_validate_register_action_type ("ungroup-container", "ges", _ungroup,
1724       (GstValidateActionParameter []) {
1725         {
1726           .name = "container-name",
1727           .description = "The name of the GESContainer to ungroup children from",
1728           .types = "string",
1729           .mandatory = TRUE,
1730         },
1731         {
1732           .name = "recursive",
1733           .description = "Whether to recurse ungrouping or not.",
1734           .types = "boolean",
1735           .mandatory = FALSE,
1736         },
1737         {
1738           .name = "project-uri",
1739           .description = "The project URI with the serialized timeline to execute the action on",
1740           .types = "string",
1741           .mandatory = FALSE,
1742         },
1743         {NULL}
1744       }, "Ungroup children of @container-name.", FALSE);
1745
1746   gst_validate_register_action_type ("set-control-source", "ges", _set_control_source,
1747       (GstValidateActionParameter []) {
1748         {
1749           .name = "element-name",
1750           .description = "The name of the GESTrackElement to set the control source on",
1751           .types = "string",
1752           .mandatory = TRUE,
1753         },
1754         {
1755           .name = "property-name",
1756           .description = "The name of the property for which to set a control source",
1757           .types = "string",
1758           .mandatory = TRUE,
1759         },
1760         {
1761           .name = "binding-type",
1762           .description = "The name of the type of binding to use",
1763           .types = "string",
1764           .mandatory = FALSE,
1765           .def = "direct",
1766         },
1767         {
1768           .name = "source-type",
1769           .description = "The name of the type of ControlSource to use",
1770           .types = "string",
1771           .mandatory = FALSE,
1772           .def = "interpolation",
1773         },
1774         {
1775           .name = "interpolation-mode",
1776           .description = "The name of the GstInterpolationMode to on the source",
1777           .types = "string",
1778           .mandatory = FALSE,
1779           .def = "linear",
1780         },
1781         {
1782           .name = "project-uri",
1783           .description = "The project URI with the serialized timeline to execute the action on",
1784           .types = "string",
1785           .mandatory = FALSE,
1786         },
1787         {NULL}
1788       }, "Adds a GstControlSource on @element-name::@property-name"
1789          " allowing you to then add keyframes on that property.", GST_VALIDATE_ACTION_TYPE_NONE);
1790
1791   gst_validate_register_action_type ("add-keyframe", "ges", _validate_action_execute,
1792       (GstValidateActionParameter []) {
1793         {
1794           .name = "element-name",
1795           .description = "The name of the GESTrackElement to add a keyframe on",
1796           .types = "string",
1797           .mandatory = TRUE,
1798         },
1799         {
1800           .name = "property-name",
1801           .description = "The name of the property for which to add a keyframe on",
1802           .types = "string",
1803           .mandatory = TRUE,
1804         },
1805         {
1806           .name = "timestamp",
1807           .description = "The timestamp of the keyframe",
1808           .types = "string or float",
1809           .mandatory = TRUE,
1810         },
1811         {
1812           .name = "value",
1813           .description = "The value of the keyframe",
1814           .types = "float",
1815           .mandatory = TRUE,
1816         },
1817         {
1818           .name = "project-uri",
1819           .description = "The project URI with the serialized timeline to execute the action on",
1820           .types = "string",
1821           .mandatory = FALSE,
1822         },
1823         {NULL}
1824       }, "Set a keyframe on @element-name:property-name.", GST_VALIDATE_ACTION_TYPE_NONE);
1825
1826   gst_validate_register_action_type ("copy-element", "ges", _copy_element,
1827       (GstValidateActionParameter []) {
1828         {
1829           .name = "element-name",
1830           .description = "The name of the GESTtimelineElement to copy",
1831           .types = "string",
1832           .mandatory = TRUE,
1833         },
1834         {
1835           .name = "recurse",
1836           .description = "Copy recursively or not",
1837           .types = "boolean",
1838           .def = "true",
1839           .mandatory = FALSE,
1840         },
1841         {
1842           .name = "position",
1843           .description = "The time where to paste the element",
1844           .types = "string or float",
1845           .mandatory = TRUE,
1846         },
1847         {
1848           .name = "paste-name",
1849           .description = "The name of the copied element",
1850           .types = "string",
1851           .mandatory = FALSE,
1852         },
1853         {
1854           .name = "project-uri",
1855           .description = "The project URI with the serialized timeline to execute the action on",
1856           .types = "string",
1857           .mandatory = FALSE,
1858         },
1859         {NULL}
1860       }, "Remove a child from @container-name.", GST_VALIDATE_ACTION_TYPE_NONE);
1861
1862   gst_validate_register_action_type ("remove-keyframe", "ges", _validate_action_execute,
1863       (GstValidateActionParameter []) {
1864         {
1865           .name = "element-name",
1866           .description = "The name of the GESTrackElement to add a keyframe on",
1867           .types = "string",
1868           .mandatory = TRUE,
1869         },
1870         {
1871           .name = "property-name",
1872           .description = "The name of the property for which to add a keyframe on",
1873           .types = "string",
1874           .mandatory = TRUE,
1875         },
1876         {
1877           .name = "timestamp",
1878           .description = "The timestamp of the keyframe",
1879           .types = "string or float",
1880           .mandatory = TRUE,
1881         },
1882         {
1883           .name = "project-uri",
1884           .description = "The project URI with the serialized timeline to execute the action on",
1885           .types = "string",
1886           .mandatory = FALSE,
1887         },
1888         {NULL}
1889       }, "Remove a keyframe on @element-name:property-name.", GST_VALIDATE_ACTION_TYPE_NONE);
1890
1891   gst_validate_register_action_type ("load-project", "ges", _load_project,
1892       (GstValidateActionParameter [])  {
1893         {
1894           .name = "serialized-content",
1895           .description = "The full content of the XML describing project in XGES format.",
1896           .mandatory = FALSE,
1897           .types = "string",
1898           NULL
1899         },
1900         {
1901           .name = "uri",
1902           .description = "The uri of the project to load (used only if serialized-content is not provided)",
1903           .mandatory = FALSE,
1904           .types = "string",
1905           NULL
1906         },
1907         {NULL}
1908       },
1909       "Loads a project either from its content passed in the 'serialized-content' field or using the provided 'uri'.\n"
1910       "Note that it will completely clean the previous timeline",
1911       GST_VALIDATE_ACTION_TYPE_NONE);
1912
1913
1914   gst_validate_register_action_type ("commit", "ges", _commit, NULL,
1915        "Commit the timeline.", GST_VALIDATE_ACTION_TYPE_ASYNC);
1916   /*  *INDENT-ON* */
1917
1918   return TRUE;
1919 #else
1920   return FALSE;
1921 #endif
1922 }