command-line-formatter: Stop uselessly looping over options
[platform/upstream/gstreamer.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 (_validate_action_execute)
880 {
881   GError *err = NULL;
882   ActionFromStructureFunc func;
883
884   gst_structure_remove_field (action->structure, "playback-time");
885   if (gst_structure_has_name (action->structure, "add-keyframe") ||
886       gst_structure_has_name (action->structure, "remove-keyframe")) {
887     func = _ges_add_remove_keyframe_from_struct;
888   } else if (gst_structure_has_name (action->structure, "set-control-source")) {
889     func = _ges_set_control_source_from_struct;
890   } else if (gst_structure_has_name (action->structure, "add-clip")) {
891     func = _ges_add_clip_from_struct;
892   } else if (gst_structure_has_name (action->structure, "container-add-child")) {
893     func = _ges_container_add_child_from_struct;
894   } else if (gst_structure_has_name (action->structure, "set-child-property")) {
895     func = _ges_set_child_property_from_struct;
896   } else {
897     g_assert_not_reached ();
898   }
899
900   if (!func (timeline, action->structure, &err)) {
901     GST_VALIDATE_REPORT_ACTION (scenario, action,
902         g_quark_from_string ("scenario::execution-error"),
903         "Could not execute %s (error: %s)",
904         gst_structure_get_name (action->structure),
905         err ? err->message : "None");
906
907     g_clear_error (&err);
908     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
909   }
910 }
911
912 GST_END_VALIDATE_ACTION;
913
914 static void
915 _project_loaded_cb (GESProject * project, GESTimeline * timeline,
916     GstValidateAction * action)
917 {
918   gst_validate_action_set_done (action);
919 }
920
921 GES_START_VALIDATE_ACTION (_load_project)
922 {
923   GstState state;
924   GESProject *project = NULL;
925   GList *tmp, *tmp_full;
926
927   gchar *uri = NULL;
928   GError *error = NULL;
929   const gchar *content = NULL;
930
931   gchar *tmpfile = g_strdup_printf ("%s%s%s", g_get_tmp_dir (),
932       G_DIR_SEPARATOR_S, "tmpxgesload.xges");
933
934   res = GST_VALIDATE_EXECUTE_ACTION_ASYNC;
935   REPORT_UNLESS (GES_IS_PIPELINE (pipeline), local_done,
936       "Not a GES pipeline, can't work with it");
937
938   gst_element_get_state (pipeline, &state, NULL, 0);
939   gst_element_set_state (pipeline, GST_STATE_NULL);
940
941   content = gst_structure_get_string (action->structure, "serialized-content");
942   if (content) {
943
944     g_file_set_contents (tmpfile, content, -1, &error);
945     REPORT_UNLESS (!error, local_done,
946         "Could not set XML content: %s", error->message);
947
948     uri = gst_filename_to_uri (tmpfile, &error);
949     REPORT_UNLESS (!error, local_done,
950         "Could not set filename to URI: %s", error->message);
951   } else {
952     uri = g_strdup (gst_structure_get_string (action->structure, "uri"));
953     REPORT_UNLESS (uri, local_done,
954         "None of 'uri' or 'content' passed as parameter"
955         " can't load any timeline!");
956   }
957
958   tmp_full = ges_timeline_get_layers (timeline);
959   for (tmp = tmp_full; tmp; tmp = tmp->next)
960     ges_timeline_remove_layer (timeline, tmp->data);
961   g_list_free_full (tmp_full, gst_object_unref);
962
963   tmp_full = ges_timeline_get_tracks (timeline);
964   for (tmp = tmp_full; tmp; tmp = tmp->next)
965     ges_timeline_remove_track (timeline, tmp->data);
966   g_list_free_full (tmp_full, gst_object_unref);
967
968   project = ges_project_new (uri);
969   g_signal_connect (project, "loaded", G_CALLBACK (_project_loaded_cb), action);
970   ges_project_load (project, gst_object_ref (timeline), &error);
971   REPORT_UNLESS (!error, local_done,
972       "Could not load timeline: %s", error->message);
973
974   gst_element_set_state (pipeline, state);
975
976 local_done:
977   gst_clear_object (&project);
978   g_clear_error (&error);
979   g_free (uri);
980   g_free (tmpfile);
981 }
982
983 GST_END_VALIDATE_ACTION;
984
985 static gint
986 prepare_seek_action (GstValidateAction * action)
987 {
988   gint res = GST_VALIDATE_EXECUTE_ACTION_ERROR;
989   GESFrameNumber fstart, fstop;
990   GstValidateScenario *scenario = gst_validate_action_get_scenario (action);
991   GstValidateActionType *type = gst_validate_get_action_type (action->type);
992   GError *err = NULL;
993
994   DECLARE_AND_GET_TIMELINE (scenario, action);
995
996   if (timeline
997       && ges_util_structure_get_clocktime (action->structure, "start", NULL,
998           &fstart)) {
999     GstClockTime start = ges_timeline_get_frame_time (timeline, fstart);
1000
1001     if (err) {
1002       GST_VALIDATE_REPORT_ACTION (scenario, action,
1003           SCENARIO_ACTION_EXECUTION_ERROR,
1004           "Invalid seeking frame number '%" G_GINT64_FORMAT "': %s", fstart,
1005           err->message);
1006       goto done;
1007     }
1008     gst_structure_set (action->structure, "start", G_TYPE_UINT64, start, NULL);
1009   }
1010
1011   if (timeline
1012       && ges_util_structure_get_clocktime (action->structure, "stop", NULL,
1013           &fstop)) {
1014     GstClockTime stop = ges_timeline_get_frame_time (timeline, fstop);
1015
1016     if (err) {
1017       GST_VALIDATE_REPORT_ACTION (scenario, action,
1018           SCENARIO_ACTION_EXECUTION_ERROR,
1019           "Invalid seeking frame number '%" G_GINT64_FORMAT "': %s", fstop,
1020           err->message);
1021       goto done;
1022     }
1023     gst_structure_set (action->structure, "stop", G_TYPE_UINT64, stop, NULL);
1024   }
1025
1026   gst_object_unref (scenario);
1027   gst_object_unref (timeline);
1028   return type->overriden_type->prepare (action);
1029
1030 done:
1031   gst_object_unref (scenario);
1032   gst_object_unref (timeline);
1033   return res;
1034 }
1035
1036 static gint
1037 set_layer_active (GstValidateScenario * scenario, GstValidateAction * action)
1038 {
1039   gboolean active;
1040   gint i, layer_prio;
1041   GESLayer *layer;
1042   GList *tracks = NULL;
1043   GstValidateExecuteActionReturn res = GST_VALIDATE_EXECUTE_ACTION_OK;
1044   gchar **track_names =
1045       gst_validate_utils_get_strv (action->structure, "tracks");
1046
1047   DECLARE_AND_GET_TIMELINE (scenario, action);
1048
1049   for (i = 0; track_names[i]; i++) {
1050     GESTrack *track =
1051         (GESTrack *) gst_bin_get_by_name (GST_BIN (timeline), track_names[i]);
1052
1053     if (!track) {
1054       GST_VALIDATE_REPORT_ACTION (scenario, action,
1055           SCENARIO_ACTION_EXECUTION_ERROR,
1056           "Could not find track %s", track_names[i]);
1057       res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1058       goto done;
1059     }
1060
1061     tracks = g_list_prepend (tracks, track);
1062   }
1063
1064   if (!gst_structure_get_int (action->structure, "layer-priority", &layer_prio)) {
1065     GST_VALIDATE_REPORT_ACTION (scenario, action,
1066         SCENARIO_ACTION_EXECUTION_ERROR,
1067         "Could not find layer from %" GST_PTR_FORMAT, action->structure);
1068     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1069     goto done;
1070   }
1071   if (!(layer = g_list_nth_data (timeline->layers, layer_prio))) {
1072     GST_VALIDATE_REPORT_ACTION (scenario, action,
1073         SCENARIO_ACTION_EXECUTION_ERROR, "Could not find layer %d", layer_prio);
1074     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1075     goto done;
1076   }
1077
1078   if (!gst_structure_get_boolean (action->structure, "active", &active)) {
1079     GST_VALIDATE_REPORT_ACTION (scenario, action,
1080         SCENARIO_ACTION_EXECUTION_ERROR,
1081         "Could not find 'active' boolean in %" GST_PTR_FORMAT,
1082         action->structure);
1083     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1084     goto done;
1085   }
1086
1087   if (!ges_layer_set_active_for_tracks (layer, active, tracks)) {
1088     GST_VALIDATE_REPORT_ACTION (scenario, action,
1089         SCENARIO_ACTION_EXECUTION_ERROR,
1090         "Could not set active for track defined in %" GST_PTR_FORMAT,
1091         action->structure);
1092     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1093     goto done;
1094   }
1095
1096 done:
1097   g_strfreev (track_names);
1098   gst_object_unref (timeline);
1099   g_list_free_full (tracks, gst_object_unref);
1100
1101   return res;
1102 }
1103
1104 #endif
1105
1106 gboolean
1107 ges_validate_register_action_types (void)
1108 {
1109 #ifdef HAVE_GST_VALIDATE
1110   GstValidateActionType *validate_seek, *seek_override;
1111
1112
1113   gst_validate_init ();
1114   validate_seek = gst_validate_get_action_type ("seek");
1115
1116   /*  *INDENT-OFF* */
1117   seek_override = gst_validate_register_action_type("seek", "ges", validate_seek->execute,
1118                                     validate_seek->parameters, validate_seek->description,
1119                                     validate_seek->flags);
1120   gst_mini_object_unref(GST_MINI_OBJECT(validate_seek));
1121   seek_override->prepare = prepare_seek_action;
1122
1123   gst_validate_register_action_type ("edit-container", "ges", _edit,
1124       (GstValidateActionParameter [])  {
1125         {
1126          .name = "container-name",
1127          .description = "The name of the GESContainer to edit",
1128          .mandatory = TRUE,
1129          .types = "string",
1130         },
1131         {
1132           .name = "position",
1133           .description = "The new position of the GESContainer",
1134           .mandatory = FALSE,
1135           .types = "double or string",
1136           .possible_variables = "position: The current position in the stream\n"
1137             "duration: The duration of the stream",
1138            NULL
1139         },
1140         {
1141           .name = "edit-mode",
1142           .description = "The GESEditMode to use to edit @container-name",
1143           .mandatory = FALSE,
1144           .types = "string",
1145           .def = "normal",
1146         },
1147         {
1148           .name = "edge",
1149           .description = "The GESEdge to use to edit @container-name\n"
1150                          "should be in [ start, end, none ] ",
1151           .mandatory = FALSE,
1152           .types = "string",
1153           .def = "none",
1154         },
1155         {
1156           .name = "new-layer-priority",
1157           .description = "The priority of the layer @container should land in.\n"
1158                          "If the layer you're trying to move the container to doesn't exist, it will\n"
1159                          "be created automatically. -1 means no move.",
1160           .mandatory = FALSE,
1161           .types = "int",
1162           .def = "-1",
1163         },
1164         {
1165           .name = "project-uri",
1166           .description = "The project URI with the serialized timeline to execute the action on",
1167           .types = "string",
1168           .mandatory = FALSE,
1169         },
1170         {NULL}
1171        },
1172        "Allows to edit a container (like a GESClip), for more details, have a look at:\n"
1173        "ges_timeline_element_edit documentation, Note that the timeline will\n"
1174        "be committed, and flushed so that the edition is taken into account",
1175        GST_VALIDATE_ACTION_TYPE_NONE);
1176
1177   gst_validate_register_action_type ("edit", "ges", _edit,
1178       (GstValidateActionParameter [])  {
1179         {
1180          .name = "element-name",
1181          .description = "The name of the element to edit",
1182          .mandatory = TRUE,
1183          .types = "string",
1184         },
1185         {
1186           .name = "position",
1187           .description = "The new position of the element",
1188           .mandatory = FALSE,
1189           .types = "double or string",
1190           .possible_variables = "position: The current position in the stream\n"
1191             "duration: The duration of the stream",
1192            NULL
1193         },
1194         {
1195           .name = "source-frame",
1196           .description = "The new frame of the element, computed from the @element-name"
1197             "clip's source frame.",
1198           .mandatory = FALSE,
1199           .types = "double or string",
1200            NULL
1201         },
1202         {
1203           .name = "edit-mode",
1204           .description = "The GESEditMode to use to edit @element-name",
1205           .mandatory = FALSE,
1206           .types = "string",
1207           .def = "normal",
1208         },
1209         {
1210           .name = "edge",
1211           .description = "The GESEdge to use to edit @element-name\n"
1212                          "should be in [ start, end, none ] ",
1213           .mandatory = FALSE,
1214           .types = "string",
1215           .def = "none",
1216         },
1217         {
1218           .name = "new-layer-priority",
1219           .description = "The priority of the layer @element should land in.\n"
1220                          "If the layer you're trying to move the element to doesn't exist, it will\n"
1221                          "be created automatically. -1 means no move.",
1222           .mandatory = FALSE,
1223           .types = "int",
1224           .def = "-1",
1225         },
1226         {
1227           .name = "project-uri",
1228           .description = "The project URI with the serialized timeline to execute the action on",
1229           .types = "string",
1230           .mandatory = FALSE,
1231         },
1232         {NULL}
1233        },
1234        "Allows to edit a element (like a GESClip), for more details, have a look at:\n"
1235        "ges_timeline_element_edit documentation, Note that the timeline will\n"
1236        "be committed, and flushed so that the edition is taken into account",
1237        GST_VALIDATE_ACTION_TYPE_NONE);
1238
1239   gst_validate_register_action_type ("add-asset", "ges", _add_asset,
1240       (GstValidateActionParameter [])  {
1241         {
1242           .name = "id",
1243           .description = "Adds an asset to a project.",
1244           .mandatory = TRUE,
1245           NULL
1246         },
1247         {
1248           .name = "type",
1249           .description = "The type of asset to add",
1250           .mandatory = TRUE,
1251           NULL
1252         },
1253         {
1254           .name = "project-uri",
1255           .description = "The project URI with the serialized timeline to execute the action on",
1256           .types = "string",
1257           .mandatory = FALSE,
1258         },
1259         {NULL}
1260       },
1261       "Allows to add an asset to the current project", GST_VALIDATE_ACTION_TYPE_NONE);
1262
1263   gst_validate_register_action_type ("remove-asset", "ges", _remove_asset,
1264       (GstValidateActionParameter [])  {
1265         {
1266           .name = "id",
1267           .description = "The ID of the clip to remove",
1268           .mandatory = TRUE,
1269           NULL
1270         },
1271         {
1272           .name = "type",
1273           .description = "The type of asset to remove",
1274           .mandatory = TRUE,
1275           NULL
1276         },
1277         {
1278           .name = "project-uri",
1279           .description = "The project URI with the serialized timeline to execute the action on",
1280           .types = "string",
1281           .mandatory = FALSE,
1282         },
1283         { NULL }
1284       },
1285       "Allows to remove an asset from the current project", GST_VALIDATE_ACTION_TYPE_NONE);
1286
1287   gst_validate_register_action_type ("add-layer", "ges", _add_layer,
1288       (GstValidateActionParameter [])  {
1289         {
1290           .name = "priority",
1291           .description = "The priority of the new layer to add,"
1292                          "if not specified, the new layer will be"
1293                          " appended to the timeline",
1294           .mandatory = FALSE,
1295           NULL
1296         },
1297         {
1298           .name = "project-uri",
1299           .description = "The project URI with the serialized timeline to execute the action on",
1300           .types = "string",
1301           .mandatory = FALSE,
1302         },
1303         { NULL }
1304       },
1305       "Allows to add a layer to the current timeline", GST_VALIDATE_ACTION_TYPE_NONE);
1306
1307   gst_validate_register_action_type ("remove-layer", "ges", _remove_layer,
1308       (GstValidateActionParameter [])  {
1309         {
1310           .name = "priority",
1311           .description = "The priority of the layer to remove",
1312           .mandatory = TRUE,
1313           NULL
1314         },
1315         {
1316           .name = "auto-transition",
1317           .description = "Whether auto-transition is activated on the new layer.",
1318           .mandatory = FALSE,
1319           .types="boolean",
1320           .def = "False"
1321         },
1322         {
1323           .name = "project-uri",
1324           .description = "The nested timeline to add clip to",
1325           .types = "string",
1326           .mandatory = FALSE,
1327         },
1328         { NULL }
1329       },
1330       "Allows to remove a layer from the current timeline", GST_VALIDATE_ACTION_TYPE_NONE);
1331
1332   gst_validate_register_action_type ("add-clip", "ges", _validate_action_execute,
1333       (GstValidateActionParameter []) {
1334         {
1335           .name = "name",
1336           .description = "The name of the clip to add",
1337           .types = "string",
1338           .mandatory = TRUE,
1339         },
1340         {
1341           .name = "layer-priority",
1342           .description = "The priority of the clip to add",
1343           .types = "int",
1344           .mandatory = TRUE,
1345         },
1346         {
1347           .name = "asset-id",
1348           .description = "The id of the asset from which to extract the clip",
1349           .types = "string",
1350           .mandatory = TRUE,
1351         },
1352         {
1353           .name = "type",
1354           .description = "The type of the clip to create",
1355           .types = "string",
1356           .mandatory = TRUE,
1357         },
1358         {
1359           .name = "start",
1360           .description = "The start value to set on the new GESClip.",
1361           .types = "double or string",
1362           .mandatory = FALSE,
1363         },
1364         {
1365           .name = "inpoint",
1366           .description = "The  inpoint value to set on the new GESClip",
1367           .types = "double or string",
1368           .mandatory = FALSE,
1369         },
1370         {
1371           .name = "duration",
1372           .description = "The  duration value to set on the new GESClip",
1373           .types = "double or string",
1374           .mandatory = FALSE,
1375         },
1376         {
1377           .name = "project-uri",
1378           .description = "The project URI with the serialized timeline to execute the action on",
1379           .types = "string",
1380           .mandatory = FALSE,
1381         },
1382         {NULL}
1383       }, "Allows to add a clip to a given layer", GST_VALIDATE_ACTION_TYPE_NONE);
1384
1385   gst_validate_register_action_type ("remove-clip", "ges", _remove_clip,
1386       (GstValidateActionParameter []) {
1387         {
1388           .name = "name",
1389           .description = "The name of the clip to remove",
1390           .types = "string",
1391           .mandatory = TRUE,
1392         },
1393         {
1394           .name = "project-uri",
1395           .description = "The project URI with the serialized timeline to execute the action on",
1396           .types = "string",
1397           .mandatory = FALSE,
1398         },
1399         {NULL}
1400       }, "Allows to remove a clip from a given layer", GST_VALIDATE_ACTION_TYPE_NONE);
1401
1402   gst_validate_register_action_type ("serialize-project", "ges", _serialize_project,
1403       (GstValidateActionParameter []) {
1404         {
1405           .name = "uri",
1406           .description = "The uri where to store the serialized project",
1407           .types = "string",
1408           .mandatory = TRUE,
1409         },
1410         {NULL}
1411       }, "serializes a project", GST_VALIDATE_ACTION_TYPE_NONE);
1412
1413   gst_validate_register_action_type ("set-child-property", "ges", _validate_action_execute,
1414       (GstValidateActionParameter []) {
1415         {
1416           .name = "element-name",
1417           .description = "The name of the element on which to modify the property",
1418           .types = "string",
1419           .mandatory = TRUE,
1420         },
1421         {
1422           .name = "property",
1423           .description = "The name of the property to modify",
1424           .types = "string",
1425           .mandatory = TRUE,
1426         },
1427         {
1428           .name = "value",
1429           .description = "The value of the property",
1430           .types = "gvalue",
1431           .mandatory = TRUE,
1432         },
1433         {
1434           .name = "project-uri",
1435           .description = "The project URI with the serialized timeline to execute the action on",
1436           .types = "string",
1437           .mandatory = FALSE,
1438         },
1439         {NULL}
1440       }, "Allows to change child property of an object", GST_VALIDATE_ACTION_TYPE_NONE);
1441
1442   gst_validate_register_action_type ("set-layer-active", "ges", set_layer_active,
1443       (GstValidateActionParameter []) {
1444         {
1445           .name = "layer-priority",
1446           .description = "The priority of the layer to set activness on",
1447           .types = "gint",
1448           .mandatory = TRUE,
1449         },
1450         {
1451           .name = "active",
1452           .description = "The activness of the layer",
1453           .types = "gboolean",
1454           .mandatory = TRUE,
1455         },
1456         {
1457           .name = "tracks",
1458           .description = "tracks",
1459           .types = "{string, }",
1460           .mandatory = FALSE,
1461         },
1462         {NULL}
1463       }, "Set activness of a layer (on optional tracks).",
1464         GST_VALIDATE_ACTION_TYPE_NONE);
1465
1466   gst_validate_register_action_type ("set-ges-properties", "ges", set_or_check_properties,
1467       (GstValidateActionParameter []) {
1468         {
1469           .name = "element-name",
1470           .description = "The name of the element on which to set properties",
1471           .types = "string",
1472           .mandatory = TRUE,
1473         },
1474         {NULL}
1475       }, "Set `element-name` properties values defined by the"
1476          " fields in the following format: `property_name=expected-value`",
1477         GST_VALIDATE_ACTION_TYPE_NONE);
1478
1479   gst_validate_register_action_type ("check-ges-properties", "ges", set_or_check_properties,
1480       (GstValidateActionParameter []) {
1481         {
1482           .name = "element-name",
1483           .description = "The name of the element on which to check properties",
1484           .types = "string",
1485           .mandatory = TRUE,
1486         },
1487         {NULL}
1488       }, "Check `element-name` properties values defined by the"
1489          " fields in the following format: `property_name=expected-value`",
1490         GST_VALIDATE_ACTION_TYPE_NONE);
1491
1492   gst_validate_register_action_type ("check-child-properties", "ges", set_or_check_properties,
1493       (GstValidateActionParameter []) {
1494         {
1495           .name = "element-name",
1496           .description = "The name of the element on which to check children properties",
1497           .types = "string",
1498           .mandatory = TRUE,
1499         },
1500         {
1501           .name = "at-time",
1502           .description = "The time at which to check the values, taking into"
1503             " account the ControlBinding if any set.",
1504           .types = "string",
1505           .mandatory = FALSE,
1506         },
1507         {NULL}
1508       }, "Check `element-name` children properties values defined by the"
1509          " fields in the following format: `property_name=expected-value`",
1510         GST_VALIDATE_ACTION_TYPE_NONE);
1511
1512   gst_validate_register_action_type ("set-child-properties", "ges", set_or_check_properties,
1513       (GstValidateActionParameter []) {
1514         {
1515           .name = "element-name",
1516           .description = "The name of the element on which to modify child properties",
1517           .types = "string",
1518           .mandatory = TRUE,
1519         },
1520         {NULL}
1521       }, "Sets `element-name` children properties values defined by the"
1522          " fields in the following format: `property-name=new-value`",
1523         GST_VALIDATE_ACTION_TYPE_NONE);
1524
1525   gst_validate_register_action_type ("split-clip", "ges", _split_clip,
1526       (GstValidateActionParameter []) {
1527         {
1528           .name = "clip-name",
1529           .description = "The name of the clip to split",
1530           .types = "string",
1531           .mandatory = TRUE,
1532         },
1533         {
1534           .name = "position",
1535           .description = "The position at which to split the clip",
1536           .types = "double or string",
1537           .mandatory = TRUE,
1538         },
1539         {
1540           .name = "project-uri",
1541           .description = "The project URI with the serialized timeline to execute the action on",
1542           .types = "string",
1543           .mandatory = FALSE,
1544         },
1545         {NULL}
1546       }, "Split a clip at a specified position.", GST_VALIDATE_ACTION_TYPE_NONE);
1547
1548   gst_validate_register_action_type ("set-track-restriction-caps", "ges", _set_track_restriction_caps,
1549       (GstValidateActionParameter []) {
1550         {
1551           .name = "track-type",
1552           .description = "The type of track to set restriction caps on",
1553           .types = "string",
1554           .mandatory = TRUE,
1555         },
1556         {
1557           .name = "caps",
1558           .description = "The caps to set on the track",
1559           .types = "string",
1560           .mandatory = TRUE,
1561         },
1562         {
1563           .name = "project-uri",
1564           .description = "The project URI with the serialized timeline to execute the action on",
1565           .types = "string",
1566           .mandatory = FALSE,
1567         },
1568         {NULL}
1569       }, "Sets restriction caps on tracks of a specific type.", GST_VALIDATE_ACTION_TYPE_NONE);
1570
1571   gst_validate_register_action_type ("element-set-asset", "ges", _set_asset_on_element,
1572       (GstValidateActionParameter []) {
1573         {
1574           .name = "element-name",
1575           .description = "The name of the TimelineElement to set an asset on",
1576           .types = "string",
1577           .mandatory = TRUE,
1578         },
1579         {
1580           .name = "asset-id",
1581           .description = "The id of the asset from which to extract the clip",
1582           .types = "string",
1583           .mandatory = TRUE,
1584         },
1585         {
1586           .name = "project-uri",
1587           .description = "The project URI with the serialized timeline to execute the action on",
1588           .types = "string",
1589           .mandatory = FALSE,
1590         },
1591         {NULL}
1592       }, "Sets restriction caps on tracks of a specific type.", GST_VALIDATE_ACTION_TYPE_NONE);
1593
1594
1595   gst_validate_register_action_type ("container-add-child", "ges", _validate_action_execute,
1596       (GstValidateActionParameter []) {
1597         {
1598           .name = "container-name",
1599           .description = "The name of the GESContainer to add a child to",
1600           .types = "string",
1601           .mandatory = TRUE,
1602         },
1603         {
1604           .name = "child-name",
1605           .description = "The name of the child to add to @container-name",
1606           .types = "string",
1607           .mandatory = FALSE,
1608           .def = "NULL"
1609         },
1610         {
1611           .name = "asset-id",
1612           .description = "The id of the asset from which to extract the child",
1613           .types = "string",
1614           .mandatory = TRUE,
1615           .def = "NULL"
1616         },
1617         {
1618           .name = "child-type",
1619           .description = "The type of the child to create",
1620           .types = "string",
1621           .mandatory = FALSE,
1622           .def = "NULL"
1623         },
1624         {
1625           .name = "project-uri",
1626           .description = "The project URI with the serialized timeline to execute the action on",
1627           .types = "string",
1628           .mandatory = FALSE,
1629         },
1630         {NULL}
1631       }, "Add a child to @container-name. If asset-id and child-type are specified,"
1632        " the child will be created and added. Otherwise @child-name has to be specified"
1633        " and will be added to the container.", GST_VALIDATE_ACTION_TYPE_NONE);
1634
1635   gst_validate_register_action_type ("container-remove-child", "ges", _container_remove_child,
1636       (GstValidateActionParameter []) {
1637         {
1638           .name = "container-name",
1639           .description = "The name of the GESContainer to remove a child from",
1640           .types = "string",
1641           .mandatory = TRUE,
1642         },
1643         {
1644           .name = "child-name",
1645           .description = "The name of the child to reomve from @container-name",
1646           .types = "string",
1647           .mandatory = TRUE,
1648         },
1649         {
1650           .name = "project-uri",
1651           .description = "The project URI with the serialized timeline to execute the action on",
1652           .types = "string",
1653           .mandatory = FALSE,
1654         },
1655         {NULL}
1656       }, "Remove a child from @container-name.", FALSE);
1657
1658   gst_validate_register_action_type ("ungroup-container", "ges", _ungroup,
1659       (GstValidateActionParameter []) {
1660         {
1661           .name = "container-name",
1662           .description = "The name of the GESContainer to ungroup children from",
1663           .types = "string",
1664           .mandatory = TRUE,
1665         },
1666         {
1667           .name = "recursive",
1668           .description = "Whether to recurse ungrouping or not.",
1669           .types = "boolean",
1670           .mandatory = FALSE,
1671         },
1672         {
1673           .name = "project-uri",
1674           .description = "The project URI with the serialized timeline to execute the action on",
1675           .types = "string",
1676           .mandatory = FALSE,
1677         },
1678         {NULL}
1679       }, "Ungroup children of @container-name.", FALSE);
1680
1681   gst_validate_register_action_type ("set-control-source", "ges", _validate_action_execute,
1682       (GstValidateActionParameter []) {
1683         {
1684           .name = "element-name",
1685           .description = "The name of the GESTrackElement to set the control source on",
1686           .types = "string",
1687           .mandatory = TRUE,
1688         },
1689         {
1690           .name = "property-name",
1691           .description = "The name of the property for which to set a control source",
1692           .types = "string",
1693           .mandatory = TRUE,
1694         },
1695         {
1696           .name = "binding-type",
1697           .description = "The name of the type of binding to use",
1698           .types = "string",
1699           .mandatory = FALSE,
1700           .def = "direct",
1701         },
1702         {
1703           .name = "source-type",
1704           .description = "The name of the type of ControlSource to use",
1705           .types = "string",
1706           .mandatory = FALSE,
1707           .def = "interpolation",
1708         },
1709         {
1710           .name = "interpolation-mode",
1711           .description = "The name of the GstInterpolationMode to on the source",
1712           .types = "string",
1713           .mandatory = FALSE,
1714           .def = "linear",
1715         },
1716         {
1717           .name = "project-uri",
1718           .description = "The project URI with the serialized timeline to execute the action on",
1719           .types = "string",
1720           .mandatory = FALSE,
1721         },
1722         {NULL}
1723       }, "Adds a GstControlSource on @element-name::@property-name"
1724          " allowing you to then add keyframes on that property.", GST_VALIDATE_ACTION_TYPE_NONE);
1725
1726   gst_validate_register_action_type ("add-keyframe", "ges", _validate_action_execute,
1727       (GstValidateActionParameter []) {
1728         {
1729           .name = "element-name",
1730           .description = "The name of the GESTrackElement to add a keyframe on",
1731           .types = "string",
1732           .mandatory = TRUE,
1733         },
1734         {
1735           .name = "property-name",
1736           .description = "The name of the property for which to add a keyframe on",
1737           .types = "string",
1738           .mandatory = TRUE,
1739         },
1740         {
1741           .name = "timestamp",
1742           .description = "The timestamp of the keyframe",
1743           .types = "string or float",
1744           .mandatory = TRUE,
1745         },
1746         {
1747           .name = "value",
1748           .description = "The value of the keyframe",
1749           .types = "float",
1750           .mandatory = TRUE,
1751         },
1752         {
1753           .name = "project-uri",
1754           .description = "The project URI with the serialized timeline to execute the action on",
1755           .types = "string",
1756           .mandatory = FALSE,
1757         },
1758         {NULL}
1759       }, "Set a keyframe on @element-name:property-name.", GST_VALIDATE_ACTION_TYPE_NONE);
1760
1761   gst_validate_register_action_type ("copy-element", "ges", _copy_element,
1762       (GstValidateActionParameter []) {
1763         {
1764           .name = "element-name",
1765           .description = "The name of the GESTtimelineElement to copy",
1766           .types = "string",
1767           .mandatory = TRUE,
1768         },
1769         {
1770           .name = "recurse",
1771           .description = "Copy recursively or not",
1772           .types = "boolean",
1773           .def = "true",
1774           .mandatory = FALSE,
1775         },
1776         {
1777           .name = "position",
1778           .description = "The time where to paste the element",
1779           .types = "string or float",
1780           .mandatory = TRUE,
1781         },
1782         {
1783           .name = "paste-name",
1784           .description = "The name of the copied element",
1785           .types = "string",
1786           .mandatory = FALSE,
1787         },
1788         {
1789           .name = "project-uri",
1790           .description = "The project URI with the serialized timeline to execute the action on",
1791           .types = "string",
1792           .mandatory = FALSE,
1793         },
1794         {NULL}
1795       }, "Remove a child from @container-name.", GST_VALIDATE_ACTION_TYPE_NONE);
1796
1797   gst_validate_register_action_type ("remove-keyframe", "ges", _validate_action_execute,
1798       (GstValidateActionParameter []) {
1799         {
1800           .name = "element-name",
1801           .description = "The name of the GESTrackElement to add a keyframe on",
1802           .types = "string",
1803           .mandatory = TRUE,
1804         },
1805         {
1806           .name = "property-name",
1807           .description = "The name of the property for which to add a keyframe on",
1808           .types = "string",
1809           .mandatory = TRUE,
1810         },
1811         {
1812           .name = "timestamp",
1813           .description = "The timestamp of the keyframe",
1814           .types = "string or 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       }, "Remove a keyframe on @element-name:property-name.", GST_VALIDATE_ACTION_TYPE_NONE);
1825
1826   gst_validate_register_action_type ("load-project", "ges", _load_project,
1827       (GstValidateActionParameter [])  {
1828         {
1829           .name = "serialized-content",
1830           .description = "The full content of the XML describing project in XGES format.",
1831           .mandatory = FALSE,
1832           .types = "string",
1833           NULL
1834         },
1835         {
1836           .name = "uri",
1837           .description = "The uri of the project to load (used only if serialized-content is not provided)",
1838           .mandatory = FALSE,
1839           .types = "string",
1840           NULL
1841         },
1842         {NULL}
1843       },
1844       "Loads a project either from its content passed in the 'serialized-content' field or using the provided 'uri'.\n"
1845       "Note that it will completely clean the previous timeline",
1846       GST_VALIDATE_ACTION_TYPE_NONE);
1847
1848
1849   gst_validate_register_action_type ("commit", "ges", _commit, NULL,
1850        "Commit the timeline.", GST_VALIDATE_ACTION_TYPE_ASYNC);
1851   /*  *INDENT-ON* */
1852
1853   return TRUE;
1854 #else
1855   return FALSE;
1856 #endif
1857 }