Move files from gst-editing-services into the "subprojects/gst-editing-services...
[platform/upstream/gstreamer.git] / subprojects / gst-editing-services / 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     GObject *tmpobject, *object = g_object_ref (G_OBJECT (data->element));
542     gchar **object_prop_name = g_strsplit (property, "::", 2);
543     gint i = 0;
544     GParamSpec *pspec = NULL;
545
546     while (TRUE) {
547       pspec =
548           g_object_class_find_property (G_OBJECT_GET_CLASS (object),
549           object_prop_name[i]);
550
551       if (!pspec) {
552         GST_VALIDATE_REPORT_ACTION (data->scenario, data->action,
553             SCENARIO_ACTION_EXECUTION_ERROR,
554             "Could not get property %s on %" GES_FORMAT,
555             object_prop_name[i], GES_ARGS (data->element));
556         data->res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
557         g_strfreev (object_prop_name);
558
559         return FALSE;
560       }
561
562       if (!object_prop_name[++i])
563         break;
564
565       tmpobject = object;
566       g_object_get (tmpobject, pspec->name, &object, NULL);
567       g_object_unref (tmpobject);
568     }
569
570     g_strfreev (object_prop_name);
571     g_value_init (&cvalue, pspec->value_type);
572     g_object_get_property (object, pspec->name, &cvalue);
573     g_object_unref (object);
574     goto compare;
575   }
576
577   if (GST_CLOCK_TIME_IS_VALID (data->time)) {
578     if (!GES_IS_TRACK_ELEMENT (data->element)) {
579       GST_VALIDATE_REPORT_ACTION (data->scenario, data->action,
580           SCENARIO_ACTION_EXECUTION_ERROR,
581           "Could not get property at time for type %s - only GESTrackElement supported",
582           G_OBJECT_TYPE_NAME (data->element));
583       data->res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
584
585       return FALSE;
586     }
587
588     binding =
589         ges_track_element_get_control_binding (GES_TRACK_ELEMENT
590         (data->element), property);
591     if (binding) {
592       tvalue = gst_control_binding_get_value (binding, data->time);
593
594       if (!tvalue) {
595         GST_VALIDATE_REPORT_ACTION (data->scenario, data->action,
596             SCENARIO_ACTION_EXECUTION_ERROR,
597             "Could not get property: %s at %" GST_TIME_FORMAT, property,
598             GST_TIME_ARGS (data->time));
599         data->res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
600
601         return FALSE;
602       }
603     }
604   }
605
606   if (!tvalue
607       && !ges_timeline_element_get_child_property (data->element, property,
608           &cvalue)) {
609     GST_VALIDATE_REPORT_ACTION (data->scenario, data->action,
610         SCENARIO_ACTION_EXECUTION_ERROR, "Could not get child property: %s:",
611         property);
612     data->res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
613
614     return FALSE;
615   }
616
617 compare:
618   observed_value = tvalue ? tvalue : &cvalue;
619
620   if (G_VALUE_TYPE (observed_value) != G_VALUE_TYPE (expected_value)) {
621     g_value_init (&comparable_value, G_VALUE_TYPE (observed_value));
622
623     if (G_VALUE_TYPE (observed_value) == GST_TYPE_CLOCK_TIME) {
624       GstClockTime t;
625
626       if (gst_validate_utils_get_clocktime (data->action->structure, property,
627               &t)) {
628         g_value_set_uint64 (&comparable_value, t);
629         expected_value = &comparable_value;
630       }
631     } else if (g_value_transform (expected_value, &comparable_value)) {
632       expected_value = &comparable_value;
633     }
634   }
635
636   if (gst_value_compare (observed_value, expected_value) != GST_VALUE_EQUAL) {
637     gchar *expected = gst_value_serialize (expected_value), *observed =
638         gst_value_serialize (observed_value);
639
640     GST_VALIDATE_REPORT_ACTION (data->scenario, data->action,
641         SCENARIO_ACTION_CHECK_ERROR,
642         "%s::%s expected value: '(%s)%s' different than observed: '(%s)%s'",
643         GES_TIMELINE_ELEMENT_NAME (data->element), property,
644         G_VALUE_TYPE_NAME (observed_value), expected,
645         G_VALUE_TYPE_NAME (expected_value), observed);
646
647     g_free (expected);
648     g_free (observed);
649     data->res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
650   }
651
652   if (G_VALUE_TYPE (&comparable_value) != G_TYPE_NONE)
653     g_value_unset (&comparable_value);
654
655   if (tvalue) {
656     g_value_unset (tvalue);
657     g_free (tvalue);
658   } else
659     g_value_reset (&cvalue);
660   return TRUE;
661 }
662
663 static gboolean
664 set_property (GQuark field_id, const GValue * value, PropertyData * data)
665 {
666   const gchar *property = g_quark_to_string (field_id);
667
668   if (data->on_children) {
669     if (!ges_timeline_element_set_child_property (data->element, property,
670             value)) {
671       gchar *v = gst_value_serialize (value);
672
673       GST_VALIDATE_REPORT_ACTION (data->scenario, data->action,
674           SCENARIO_ACTION_EXECUTION_ERROR,
675           "Could not set %s child property %s to %s",
676           GES_TIMELINE_ELEMENT_NAME (data->element), property, v);
677
678       data->res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
679       g_free (v);
680
681       return FALSE;
682     }
683   } else {
684     data->res =
685         gst_validate_object_set_property (GST_VALIDATE_REPORTER
686         (data->scenario), G_OBJECT (data->element), property, value, FALSE);
687   }
688
689   return TRUE;
690 }
691
692 GES_START_VALIDATE_ACTION (set_or_check_properties)
693 {
694   GESTimelineElement *element;
695   GstStructure *structure;
696   const gchar *element_name;
697   gboolean is_setting = FALSE;
698   PropertyData data = {
699     .scenario = scenario,
700     .element = NULL,
701     .res = GST_VALIDATE_EXECUTE_ACTION_OK,
702     .time = GST_CLOCK_TIME_NONE,
703     .on_children =
704         !gst_structure_has_name (action->structure, "check-ges-properties")
705         && !gst_structure_has_name (action->structure, "set-ges-properties"),
706     .action = action,
707   };
708
709   is_setting = gst_structure_has_name (action->structure, "set-ges-properties")
710       || gst_structure_has_name (action->structure, "set-child-properties");
711   gst_validate_action_get_clocktime (scenario, action, "at-time", &data.time);
712
713   structure = gst_structure_copy (action->structure);
714   element_name = gst_structure_get_string (structure, "element-name");
715   element = ges_timeline_get_element (timeline, element_name);
716   if (!element) {
717     GST_VALIDATE_REPORT_ACTION (scenario, action,
718         SCENARIO_ACTION_EXECUTION_ERROR,
719         "Can not find element: %s", element_name);
720
721     data.res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
722     goto local_done;
723   }
724
725   data.element = element;
726   gst_structure_remove_fields (structure, "element-name", "at-time",
727       "project-uri", NULL);
728   gst_structure_foreach (structure,
729       is_setting ? (GstStructureForeachFunc) set_property
730       : (GstStructureForeachFunc) check_property, &data);
731   gst_object_unref (element);
732
733 local_done:
734   gst_structure_free (structure);
735   res = data.res;
736 }
737
738 GST_END_VALIDATE_ACTION;
739
740 GES_START_VALIDATE_ACTION (_set_track_restriction_caps)
741 {
742   GList *tmp;
743   GstCaps *caps;
744   GESTrackType track_types;
745
746   const gchar *track_type_str =
747       gst_structure_get_string (action->structure, "track-type");
748   const gchar *caps_str = gst_structure_get_string (action->structure, "caps");
749
750   REPORT_UNLESS (track_types =
751       gst_validate_utils_flags_from_str (GES_TYPE_TRACK_TYPE, track_type_str),
752       done, "Invalid track types: %s", track_type_str);
753
754   REPORT_UNLESS (caps = gst_caps_from_string (caps_str),
755       done, "Invalid track restriction caps: %s", caps_str);
756
757   res = GST_VALIDATE_EXECUTE_ACTION_ERROR;
758   for (tmp = timeline->tracks; tmp; tmp = tmp->next) {
759     GESTrack *track = tmp->data;
760
761     if (track->type & track_types) {
762       gchar *str;
763
764       str = gst_caps_to_string (caps);
765       g_free (str);
766
767       ges_track_set_restriction_caps (track, caps);
768
769       res = GST_VALIDATE_EXECUTE_ACTION_OK;
770     }
771   }
772   gst_caps_unref (caps);
773 }
774
775 GST_END_VALIDATE_ACTION;
776
777 GES_START_VALIDATE_ACTION (_set_asset_on_element)
778 {
779   GESAsset *asset;
780   GESTimelineElement *element;
781   const gchar *element_name, *id;
782
783   element_name = gst_structure_get_string (action->structure, "element-name");
784   element = ges_timeline_get_element (timeline, element_name);
785   REPORT_UNLESS (element, done, "Can't find %s", element_name);
786
787   id = gst_structure_get_string (action->structure, "asset-id");
788
789   gst_validate_printf (action, "Setting asset %s on element %s\n",
790       id, element_name);
791
792   asset = _ges_get_asset_from_timeline (timeline, G_OBJECT_TYPE (element), id,
793       NULL);
794   REPORT_UNLESS (asset, beach, "Could not find asset: %s", id);
795
796   res = ges_extractable_set_asset (GES_EXTRACTABLE (element), asset);
797
798 beach:
799   gst_clear_object (&asset);
800   gst_clear_object (&element);
801 }
802
803 GST_END_VALIDATE_ACTION;
804
805 GES_START_VALIDATE_ACTION (_container_remove_child)
806 {
807   GESContainer *container = NULL;
808   GESTimelineElement *child = NULL;
809   const gchar *container_name, *child_name;
810
811   container_name =
812       gst_structure_get_string (action->structure, "container-name");
813   container =
814       (GESContainer *) ges_timeline_get_element (timeline, container_name);
815   REPORT_UNLESS (GES_IS_CONTAINER (container), beach,
816       "Could not find container: %s", container_name);
817
818   child_name = gst_structure_get_string (action->structure, "child-name");
819   child = ges_timeline_get_element (timeline, child_name);
820   REPORT_UNLESS (GES_IS_TIMELINE_ELEMENT (child), beach, "Could not find %s",
821       child_name);
822
823   res = ges_container_remove (container, child);
824
825 beach:
826   gst_clear_object (&container);
827   gst_clear_object (&child);
828 }
829
830 GST_END_VALIDATE_ACTION;
831
832 GES_START_VALIDATE_ACTION (_ungroup)
833 {
834   GESContainer *container;
835   gboolean recursive = FALSE;
836   const gchar *container_name;
837
838   container_name =
839       gst_structure_get_string (action->structure, "container-name");
840   container =
841       (GESContainer *) ges_timeline_get_element (timeline, container_name);
842   REPORT_UNLESS (GES_IS_CONTAINER (container), beach, "Could not find %s",
843       container_name);
844
845   gst_structure_get_boolean (action->structure, "recursive", &recursive);
846
847   g_list_free (ges_container_ungroup (container, recursive));
848
849 beach:
850   gst_clear_object (&container);
851 }
852
853 GST_END_VALIDATE_ACTION;
854
855 GES_START_VALIDATE_ACTION (_copy_element)
856 {
857   GESTimelineElement *element = NULL, *copied = NULL, *pasted = NULL;
858   gboolean recursive = FALSE;
859   const gchar *element_name, *paste_name;
860   GstClockTime position;
861
862   element_name = gst_structure_get_string (action->structure, "element-name");
863   element = ges_timeline_get_element (timeline, element_name);
864
865   REPORT_UNLESS (GES_IS_CONTAINER (element), beach, "Could not find %s",
866       element_name);
867
868   if (!gst_structure_get_boolean (action->structure, "recursive", &recursive))
869     recursive = TRUE;
870
871   REPORT_UNLESS (gst_validate_action_get_clocktime (scenario, action,
872           "position", &position), beach, "Could not find position");
873
874   copied = ges_timeline_element_copy (element, recursive);
875   pasted = ges_timeline_element_paste (copied, position);
876
877   REPORT_UNLESS (pasted, beach, "Could not paste clip %s", element_name);
878
879   paste_name = gst_structure_get_string (action->structure, "paste-name");
880   if (paste_name)
881     REPORT_UNLESS (ges_timeline_element_set_name (pasted, paste_name),
882         beach, "Could not set element name %s", paste_name);
883
884 beach:
885   gst_clear_object (&pasted);
886   gst_clear_object (&element);
887
888   /* `copied` is only used for the single paste operation, and is not
889    * actually in any timeline. We own it (it is actually still floating).
890    * `pasted` is the actual new object in the timeline. We own a
891    * reference to it. */
892   gst_clear_object (&copied);
893 }
894
895 GST_END_VALIDATE_ACTION;
896
897 GES_START_VALIDATE_ACTION (_validate_action_execute)
898 {
899   GError *err = NULL;
900   ActionFromStructureFunc func;
901
902   gst_structure_remove_field (action->structure, "playback-time");
903   if (gst_structure_has_name (action->structure, "add-keyframe") ||
904       gst_structure_has_name (action->structure, "remove-keyframe")) {
905     func = _ges_add_remove_keyframe_from_struct;
906   } else if (gst_structure_has_name (action->structure, "set-control-source")) {
907     func = _ges_set_control_source_from_struct;
908   } else if (gst_structure_has_name (action->structure, "add-clip")) {
909     func = _ges_add_clip_from_struct;
910   } else if (gst_structure_has_name (action->structure, "container-add-child")) {
911     func = _ges_container_add_child_from_struct;
912   } else if (gst_structure_has_name (action->structure, "set-child-property")) {
913     func = _ges_set_child_property_from_struct;
914   } else {
915     g_assert_not_reached ();
916   }
917
918   if (!func (timeline, action->structure, &err)) {
919     GST_VALIDATE_REPORT_ACTION (scenario, action,
920         g_quark_from_string ("scenario::execution-error"),
921         "Could not execute %s (error: %s)",
922         gst_structure_get_name (action->structure),
923         err ? err->message : "None");
924
925     g_clear_error (&err);
926     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
927   }
928 }
929
930 GST_END_VALIDATE_ACTION;
931
932 static void
933 _project_loaded_cb (GESProject * project, GESTimeline * timeline,
934     GstValidateAction * action)
935 {
936   gst_validate_action_set_done (action);
937 }
938
939 GES_START_VALIDATE_ACTION (_load_project)
940 {
941   GstState state;
942   GESProject *project = NULL;
943   GList *tmp, *tmp_full;
944
945   gchar *uri = NULL;
946   GError *error = NULL;
947   const gchar *content = NULL;
948
949   gchar *tmpfile = g_strdup_printf ("%s%s%s", g_get_tmp_dir (),
950       G_DIR_SEPARATOR_S, "tmpxgesload.xges");
951
952   res = GST_VALIDATE_EXECUTE_ACTION_ASYNC;
953   REPORT_UNLESS (GES_IS_PIPELINE (pipeline), local_done,
954       "Not a GES pipeline, can't work with it");
955
956   gst_element_get_state (pipeline, &state, NULL, 0);
957   gst_element_set_state (pipeline, GST_STATE_NULL);
958
959   content = gst_structure_get_string (action->structure, "serialized-content");
960   if (content) {
961
962     g_file_set_contents (tmpfile, content, -1, &error);
963     REPORT_UNLESS (!error, local_done,
964         "Could not set XML content: %s", error->message);
965
966     uri = gst_filename_to_uri (tmpfile, &error);
967     REPORT_UNLESS (!error, local_done,
968         "Could not set filename to URI: %s", error->message);
969   } else {
970     uri = g_strdup (gst_structure_get_string (action->structure, "uri"));
971     REPORT_UNLESS (uri, local_done,
972         "None of 'uri' or 'content' passed as parameter"
973         " can't load any timeline!");
974   }
975
976   tmp_full = ges_timeline_get_layers (timeline);
977   for (tmp = tmp_full; tmp; tmp = tmp->next)
978     ges_timeline_remove_layer (timeline, tmp->data);
979   g_list_free_full (tmp_full, gst_object_unref);
980
981   tmp_full = ges_timeline_get_tracks (timeline);
982   for (tmp = tmp_full; tmp; tmp = tmp->next)
983     ges_timeline_remove_track (timeline, tmp->data);
984   g_list_free_full (tmp_full, gst_object_unref);
985
986   project = ges_project_new (uri);
987   g_signal_connect (project, "loaded", G_CALLBACK (_project_loaded_cb), action);
988   ges_project_load (project, gst_object_ref (timeline), &error);
989   REPORT_UNLESS (!error, local_done,
990       "Could not load timeline: %s", error->message);
991
992   gst_element_set_state (pipeline, state);
993
994 local_done:
995   gst_clear_object (&project);
996   g_clear_error (&error);
997   g_free (uri);
998   g_free (tmpfile);
999 }
1000
1001 GST_END_VALIDATE_ACTION;
1002
1003 static gint
1004 prepare_seek_action (GstValidateAction * action)
1005 {
1006   gint res = GST_VALIDATE_EXECUTE_ACTION_ERROR;
1007   GESFrameNumber fstart, fstop;
1008   GstValidateScenario *scenario = gst_validate_action_get_scenario (action);
1009   GstValidateActionType *type = gst_validate_get_action_type (action->type);
1010   GError *err = NULL;
1011
1012   DECLARE_AND_GET_TIMELINE (scenario, action);
1013
1014   if (timeline
1015       && ges_util_structure_get_clocktime (action->structure, "start", NULL,
1016           &fstart)) {
1017     GstClockTime start = ges_timeline_get_frame_time (timeline, fstart);
1018
1019     if (err) {
1020       GST_VALIDATE_REPORT_ACTION (scenario, action,
1021           SCENARIO_ACTION_EXECUTION_ERROR,
1022           "Invalid seeking frame number '%" G_GINT64_FORMAT "': %s", fstart,
1023           err->message);
1024       goto done;
1025     }
1026     gst_structure_set (action->structure, "start", G_TYPE_UINT64, start, NULL);
1027   }
1028
1029   if (timeline
1030       && ges_util_structure_get_clocktime (action->structure, "stop", NULL,
1031           &fstop)) {
1032     GstClockTime stop = ges_timeline_get_frame_time (timeline, fstop);
1033
1034     if (err) {
1035       GST_VALIDATE_REPORT_ACTION (scenario, action,
1036           SCENARIO_ACTION_EXECUTION_ERROR,
1037           "Invalid seeking frame number '%" G_GINT64_FORMAT "': %s", fstop,
1038           err->message);
1039       goto done;
1040     }
1041     gst_structure_set (action->structure, "stop", G_TYPE_UINT64, stop, NULL);
1042   }
1043
1044   gst_object_unref (scenario);
1045   gst_object_unref (timeline);
1046   return type->overriden_type->prepare (action);
1047
1048 done:
1049   gst_object_unref (scenario);
1050   gst_object_unref (timeline);
1051   return res;
1052 }
1053
1054 static gint
1055 set_layer_active (GstValidateScenario * scenario, GstValidateAction * action)
1056 {
1057   gboolean active;
1058   gint i, layer_prio;
1059   GESLayer *layer;
1060   GList *tracks = NULL;
1061   GstValidateExecuteActionReturn res = GST_VALIDATE_EXECUTE_ACTION_OK;
1062   gchar **track_names =
1063       gst_validate_utils_get_strv (action->structure, "tracks");
1064
1065   DECLARE_AND_GET_TIMELINE (scenario, action);
1066
1067   for (i = 0; track_names[i]; i++) {
1068     GESTrack *track =
1069         (GESTrack *) gst_bin_get_by_name (GST_BIN (timeline), track_names[i]);
1070
1071     if (!track) {
1072       GST_VALIDATE_REPORT_ACTION (scenario, action,
1073           SCENARIO_ACTION_EXECUTION_ERROR,
1074           "Could not find track %s", track_names[i]);
1075       res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1076       goto done;
1077     }
1078
1079     tracks = g_list_prepend (tracks, track);
1080   }
1081
1082   if (!gst_structure_get_int (action->structure, "layer-priority", &layer_prio)) {
1083     GST_VALIDATE_REPORT_ACTION (scenario, action,
1084         SCENARIO_ACTION_EXECUTION_ERROR,
1085         "Could not find layer from %" GST_PTR_FORMAT, action->structure);
1086     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1087     goto done;
1088   }
1089   if (!(layer = g_list_nth_data (timeline->layers, layer_prio))) {
1090     GST_VALIDATE_REPORT_ACTION (scenario, action,
1091         SCENARIO_ACTION_EXECUTION_ERROR, "Could not find layer %d", layer_prio);
1092     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1093     goto done;
1094   }
1095
1096   if (!gst_structure_get_boolean (action->structure, "active", &active)) {
1097     GST_VALIDATE_REPORT_ACTION (scenario, action,
1098         SCENARIO_ACTION_EXECUTION_ERROR,
1099         "Could not find 'active' boolean in %" GST_PTR_FORMAT,
1100         action->structure);
1101     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1102     goto done;
1103   }
1104
1105   if (!ges_layer_set_active_for_tracks (layer, active, tracks)) {
1106     GST_VALIDATE_REPORT_ACTION (scenario, action,
1107         SCENARIO_ACTION_EXECUTION_ERROR,
1108         "Could not set active for track defined in %" GST_PTR_FORMAT,
1109         action->structure);
1110     res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
1111     goto done;
1112   }
1113
1114 done:
1115   g_strfreev (track_names);
1116   gst_object_unref (timeline);
1117   g_list_free_full (tracks, gst_object_unref);
1118
1119   return res;
1120 }
1121
1122 #endif
1123
1124 gboolean
1125 ges_validate_register_action_types (void)
1126 {
1127 #ifdef HAVE_GST_VALIDATE
1128   GstValidateActionType *validate_seek, *seek_override;
1129
1130
1131   gst_validate_init ();
1132   validate_seek = gst_validate_get_action_type ("seek");
1133
1134   /*  *INDENT-OFF* */
1135   seek_override = gst_validate_register_action_type("seek", "ges", validate_seek->execute,
1136                                     validate_seek->parameters, validate_seek->description,
1137                                     validate_seek->flags);
1138   gst_mini_object_unref(GST_MINI_OBJECT(validate_seek));
1139   seek_override->prepare = prepare_seek_action;
1140
1141   gst_validate_register_action_type ("edit-container", "ges", _edit,
1142       (GstValidateActionParameter [])  {
1143         {
1144          .name = "container-name",
1145          .description = "The name of the GESContainer to edit",
1146          .mandatory = TRUE,
1147          .types = "string",
1148         },
1149         {
1150           .name = "position",
1151           .description = "The new position of the GESContainer",
1152           .mandatory = FALSE,
1153           .types = "double or string",
1154           .possible_variables = "position: The current position in the stream\n"
1155             "duration: The duration of the stream",
1156            NULL
1157         },
1158         {
1159           .name = "edit-mode",
1160           .description = "The GESEditMode to use to edit @container-name",
1161           .mandatory = FALSE,
1162           .types = "string",
1163           .def = "normal",
1164         },
1165         {
1166           .name = "edge",
1167           .description = "The GESEdge to use to edit @container-name\n"
1168                          "should be in [ start, end, none ] ",
1169           .mandatory = FALSE,
1170           .types = "string",
1171           .def = "none",
1172         },
1173         {
1174           .name = "new-layer-priority",
1175           .description = "The priority of the layer @container should land in.\n"
1176                          "If the layer you're trying to move the container to doesn't exist, it will\n"
1177                          "be created automatically. -1 means no move.",
1178           .mandatory = FALSE,
1179           .types = "int",
1180           .def = "-1",
1181         },
1182         {
1183           .name = "project-uri",
1184           .description = "The project URI with the serialized timeline to execute the action on",
1185           .types = "string",
1186           .mandatory = FALSE,
1187         },
1188         {NULL}
1189        },
1190        "Allows to edit a container (like a GESClip), for more details, have a look at:\n"
1191        "ges_timeline_element_edit documentation, Note that the timeline will\n"
1192        "be committed, and flushed so that the edition is taken into account",
1193        GST_VALIDATE_ACTION_TYPE_NONE);
1194
1195   gst_validate_register_action_type ("edit", "ges", _edit,
1196       (GstValidateActionParameter [])  {
1197         {
1198          .name = "element-name",
1199          .description = "The name of the element to edit",
1200          .mandatory = TRUE,
1201          .types = "string",
1202         },
1203         {
1204           .name = "position",
1205           .description = "The new position of the element",
1206           .mandatory = FALSE,
1207           .types = "double or string",
1208           .possible_variables = "position: The current position in the stream\n"
1209             "duration: The duration of the stream",
1210            NULL
1211         },
1212         {
1213           .name = "source-frame",
1214           .description = "The new frame of the element, computed from the @element-name"
1215             "clip's source frame.",
1216           .mandatory = FALSE,
1217           .types = "double or string",
1218            NULL
1219         },
1220         {
1221           .name = "edit-mode",
1222           .description = "The GESEditMode to use to edit @element-name",
1223           .mandatory = FALSE,
1224           .types = "string",
1225           .def = "normal",
1226         },
1227         {
1228           .name = "edge",
1229           .description = "The GESEdge to use to edit @element-name\n"
1230                          "should be in [ start, end, none ] ",
1231           .mandatory = FALSE,
1232           .types = "string",
1233           .def = "none",
1234         },
1235         {
1236           .name = "new-layer-priority",
1237           .description = "The priority of the layer @element should land in.\n"
1238                          "If the layer you're trying to move the element to doesn't exist, it will\n"
1239                          "be created automatically. -1 means no move.",
1240           .mandatory = FALSE,
1241           .types = "int",
1242           .def = "-1",
1243         },
1244         {
1245           .name = "project-uri",
1246           .description = "The project URI with the serialized timeline to execute the action on",
1247           .types = "string",
1248           .mandatory = FALSE,
1249         },
1250         {NULL}
1251        },
1252        "Allows to edit a element (like a GESClip), for more details, have a look at:\n"
1253        "ges_timeline_element_edit documentation, Note that the timeline will\n"
1254        "be committed, and flushed so that the edition is taken into account",
1255        GST_VALIDATE_ACTION_TYPE_NONE);
1256
1257   gst_validate_register_action_type ("add-asset", "ges", _add_asset,
1258       (GstValidateActionParameter [])  {
1259         {
1260           .name = "id",
1261           .description = "Adds an asset to a project.",
1262           .mandatory = TRUE,
1263           NULL
1264         },
1265         {
1266           .name = "type",
1267           .description = "The type of asset to add",
1268           .mandatory = TRUE,
1269           NULL
1270         },
1271         {
1272           .name = "project-uri",
1273           .description = "The project URI with the serialized timeline to execute the action on",
1274           .types = "string",
1275           .mandatory = FALSE,
1276         },
1277         {NULL}
1278       },
1279       "Allows to add an asset to the current project", GST_VALIDATE_ACTION_TYPE_NONE);
1280
1281   gst_validate_register_action_type ("remove-asset", "ges", _remove_asset,
1282       (GstValidateActionParameter [])  {
1283         {
1284           .name = "id",
1285           .description = "The ID of the clip to remove",
1286           .mandatory = TRUE,
1287           NULL
1288         },
1289         {
1290           .name = "type",
1291           .description = "The type of asset to remove",
1292           .mandatory = TRUE,
1293           NULL
1294         },
1295         {
1296           .name = "project-uri",
1297           .description = "The project URI with the serialized timeline to execute the action on",
1298           .types = "string",
1299           .mandatory = FALSE,
1300         },
1301         { NULL }
1302       },
1303       "Allows to remove an asset from the current project", GST_VALIDATE_ACTION_TYPE_NONE);
1304
1305   gst_validate_register_action_type ("add-layer", "ges", _add_layer,
1306       (GstValidateActionParameter [])  {
1307         {
1308           .name = "priority",
1309           .description = "The priority of the new layer to add,"
1310                          "if not specified, the new layer will be"
1311                          " appended to the timeline",
1312           .mandatory = FALSE,
1313           NULL
1314         },
1315         {
1316           .name = "project-uri",
1317           .description = "The project URI with the serialized timeline to execute the action on",
1318           .types = "string",
1319           .mandatory = FALSE,
1320         },
1321         { NULL }
1322       },
1323       "Allows to add a layer to the current timeline", GST_VALIDATE_ACTION_TYPE_NONE);
1324
1325   gst_validate_register_action_type ("remove-layer", "ges", _remove_layer,
1326       (GstValidateActionParameter [])  {
1327         {
1328           .name = "priority",
1329           .description = "The priority of the layer to remove",
1330           .mandatory = TRUE,
1331           NULL
1332         },
1333         {
1334           .name = "auto-transition",
1335           .description = "Whether auto-transition is activated on the new layer.",
1336           .mandatory = FALSE,
1337           .types="boolean",
1338           .def = "False"
1339         },
1340         {
1341           .name = "project-uri",
1342           .description = "The nested timeline to add clip to",
1343           .types = "string",
1344           .mandatory = FALSE,
1345         },
1346         { NULL }
1347       },
1348       "Allows to remove a layer from the current timeline", GST_VALIDATE_ACTION_TYPE_NONE);
1349
1350   gst_validate_register_action_type ("add-clip", "ges", _validate_action_execute,
1351       (GstValidateActionParameter []) {
1352         {
1353           .name = "name",
1354           .description = "The name of the clip to add",
1355           .types = "string",
1356           .mandatory = TRUE,
1357         },
1358         {
1359           .name = "layer-priority",
1360           .description = "The priority of the clip to add",
1361           .types = "int",
1362           .mandatory = TRUE,
1363         },
1364         {
1365           .name = "asset-id",
1366           .description = "The id of the asset from which to extract the clip",
1367           .types = "string",
1368           .mandatory = TRUE,
1369         },
1370         {
1371           .name = "type",
1372           .description = "The type of the clip to create",
1373           .types = "string",
1374           .mandatory = TRUE,
1375         },
1376         {
1377           .name = "start",
1378           .description = "The start value to set on the new GESClip.",
1379           .types = "double or string",
1380           .mandatory = FALSE,
1381         },
1382         {
1383           .name = "inpoint",
1384           .description = "The  inpoint value to set on the new GESClip",
1385           .types = "double or string",
1386           .mandatory = FALSE,
1387         },
1388         {
1389           .name = "duration",
1390           .description = "The  duration value to set on the new GESClip",
1391           .types = "double or string",
1392           .mandatory = FALSE,
1393         },
1394         {
1395           .name = "project-uri",
1396           .description = "The project URI with the serialized timeline to execute the action on",
1397           .types = "string",
1398           .mandatory = FALSE,
1399         },
1400         {NULL}
1401       }, "Allows to add a clip to a given layer", GST_VALIDATE_ACTION_TYPE_NONE);
1402
1403   gst_validate_register_action_type ("remove-clip", "ges", _remove_clip,
1404       (GstValidateActionParameter []) {
1405         {
1406           .name = "name",
1407           .description = "The name of the clip to remove",
1408           .types = "string",
1409           .mandatory = TRUE,
1410         },
1411         {
1412           .name = "project-uri",
1413           .description = "The project URI with the serialized timeline to execute the action on",
1414           .types = "string",
1415           .mandatory = FALSE,
1416         },
1417         {NULL}
1418       }, "Allows to remove a clip from a given layer", GST_VALIDATE_ACTION_TYPE_NONE);
1419
1420   gst_validate_register_action_type ("serialize-project", "ges", _serialize_project,
1421       (GstValidateActionParameter []) {
1422         {
1423           .name = "uri",
1424           .description = "The uri where to store the serialized project",
1425           .types = "string",
1426           .mandatory = TRUE,
1427         },
1428         {NULL}
1429       }, "serializes a project", GST_VALIDATE_ACTION_TYPE_NONE);
1430
1431   gst_validate_register_action_type ("set-child-property", "ges", _validate_action_execute,
1432       (GstValidateActionParameter []) {
1433         {
1434           .name = "element-name",
1435           .description = "The name of the element on which to modify the property",
1436           .types = "string",
1437           .mandatory = TRUE,
1438         },
1439         {
1440           .name = "property",
1441           .description = "The name of the property to modify",
1442           .types = "string",
1443           .mandatory = TRUE,
1444         },
1445         {
1446           .name = "value",
1447           .description = "The value of the property",
1448           .types = "gvalue",
1449           .mandatory = TRUE,
1450         },
1451         {
1452           .name = "project-uri",
1453           .description = "The project URI with the serialized timeline to execute the action on",
1454           .types = "string",
1455           .mandatory = FALSE,
1456         },
1457         {NULL}
1458       }, "Allows to change child property of an object", GST_VALIDATE_ACTION_TYPE_NONE);
1459
1460   gst_validate_register_action_type ("set-layer-active", "ges", set_layer_active,
1461       (GstValidateActionParameter []) {
1462         {
1463           .name = "layer-priority",
1464           .description = "The priority of the layer to set activness on",
1465           .types = "gint",
1466           .mandatory = TRUE,
1467         },
1468         {
1469           .name = "active",
1470           .description = "The activness of the layer",
1471           .types = "gboolean",
1472           .mandatory = TRUE,
1473         },
1474         {
1475           .name = "tracks",
1476           .description = "tracks",
1477           .types = "{string, }",
1478           .mandatory = FALSE,
1479         },
1480         {NULL}
1481       }, "Set activness of a layer (on optional tracks).",
1482         GST_VALIDATE_ACTION_TYPE_NONE);
1483
1484   gst_validate_register_action_type ("set-ges-properties", "ges", set_or_check_properties,
1485       (GstValidateActionParameter []) {
1486         {
1487           .name = "element-name",
1488           .description = "The name of the element on which to set properties",
1489           .types = "string",
1490           .mandatory = TRUE,
1491         },
1492         {NULL}
1493       }, "Set `element-name` properties values defined by the"
1494          " fields in the following format: `property_name=expected-value`",
1495         GST_VALIDATE_ACTION_TYPE_NONE);
1496
1497   gst_validate_register_action_type ("check-ges-properties", "ges", set_or_check_properties,
1498       (GstValidateActionParameter []) {
1499         {
1500           .name = "element-name",
1501           .description = "The name of the element on which to check properties",
1502           .types = "string",
1503           .mandatory = TRUE,
1504         },
1505         {NULL}
1506       }, "Check `element-name` properties values defined by the"
1507          " fields in the following format: `property_name=expected-value`",
1508         GST_VALIDATE_ACTION_TYPE_NONE);
1509
1510   gst_validate_register_action_type ("check-child-properties", "ges", set_or_check_properties,
1511       (GstValidateActionParameter []) {
1512         {
1513           .name = "element-name",
1514           .description = "The name of the element on which to check children properties",
1515           .types = "string",
1516           .mandatory = TRUE,
1517         },
1518         {
1519           .name = "at-time",
1520           .description = "The time at which to check the values, taking into"
1521             " account the ControlBinding if any set.",
1522           .types = "string",
1523           .mandatory = FALSE,
1524         },
1525         {NULL}
1526       }, "Check `element-name` children properties values defined by the"
1527          " fields in the following format: `property_name=expected-value`",
1528         GST_VALIDATE_ACTION_TYPE_NONE);
1529
1530   gst_validate_register_action_type ("set-child-properties", "ges", set_or_check_properties,
1531       (GstValidateActionParameter []) {
1532         {
1533           .name = "element-name",
1534           .description = "The name of the element on which to modify child properties",
1535           .types = "string",
1536           .mandatory = TRUE,
1537         },
1538         {NULL}
1539       }, "Sets `element-name` children properties values defined by the"
1540          " fields in the following format: `property-name=new-value`",
1541         GST_VALIDATE_ACTION_TYPE_NONE);
1542
1543   gst_validate_register_action_type ("split-clip", "ges", _split_clip,
1544       (GstValidateActionParameter []) {
1545         {
1546           .name = "clip-name",
1547           .description = "The name of the clip to split",
1548           .types = "string",
1549           .mandatory = TRUE,
1550         },
1551         {
1552           .name = "position",
1553           .description = "The position at which to split the clip",
1554           .types = "double or string",
1555           .mandatory = TRUE,
1556         },
1557         {
1558           .name = "project-uri",
1559           .description = "The project URI with the serialized timeline to execute the action on",
1560           .types = "string",
1561           .mandatory = FALSE,
1562         },
1563         {NULL}
1564       }, "Split a clip at a specified position.", GST_VALIDATE_ACTION_TYPE_NONE);
1565
1566   gst_validate_register_action_type ("set-track-restriction-caps", "ges", _set_track_restriction_caps,
1567       (GstValidateActionParameter []) {
1568         {
1569           .name = "track-type",
1570           .description = "The type of track to set restriction caps on",
1571           .types = "string",
1572           .mandatory = TRUE,
1573         },
1574         {
1575           .name = "caps",
1576           .description = "The caps to set on the track",
1577           .types = "string",
1578           .mandatory = TRUE,
1579         },
1580         {
1581           .name = "project-uri",
1582           .description = "The project URI with the serialized timeline to execute the action on",
1583           .types = "string",
1584           .mandatory = FALSE,
1585         },
1586         {NULL}
1587       }, "Sets restriction caps on tracks of a specific type.", GST_VALIDATE_ACTION_TYPE_NONE);
1588
1589   gst_validate_register_action_type ("element-set-asset", "ges", _set_asset_on_element,
1590       (GstValidateActionParameter []) {
1591         {
1592           .name = "element-name",
1593           .description = "The name of the TimelineElement to set an asset on",
1594           .types = "string",
1595           .mandatory = TRUE,
1596         },
1597         {
1598           .name = "asset-id",
1599           .description = "The id of the asset from which to extract the clip",
1600           .types = "string",
1601           .mandatory = TRUE,
1602         },
1603         {
1604           .name = "project-uri",
1605           .description = "The project URI with the serialized timeline to execute the action on",
1606           .types = "string",
1607           .mandatory = FALSE,
1608         },
1609         {NULL}
1610       }, "Sets restriction caps on tracks of a specific type.", GST_VALIDATE_ACTION_TYPE_NONE);
1611
1612
1613   gst_validate_register_action_type ("container-add-child", "ges", _validate_action_execute,
1614       (GstValidateActionParameter []) {
1615         {
1616           .name = "container-name",
1617           .description = "The name of the GESContainer to add a child to",
1618           .types = "string",
1619           .mandatory = TRUE,
1620         },
1621         {
1622           .name = "child-name",
1623           .description = "The name of the child to add to @container-name",
1624           .types = "string",
1625           .mandatory = FALSE,
1626           .def = "NULL"
1627         },
1628         {
1629           .name = "asset-id",
1630           .description = "The id of the asset from which to extract the child",
1631           .types = "string",
1632           .mandatory = TRUE,
1633           .def = "NULL"
1634         },
1635         {
1636           .name = "child-type",
1637           .description = "The type of the child to create",
1638           .types = "string",
1639           .mandatory = FALSE,
1640           .def = "NULL"
1641         },
1642         {
1643           .name = "project-uri",
1644           .description = "The project URI with the serialized timeline to execute the action on",
1645           .types = "string",
1646           .mandatory = FALSE,
1647         },
1648         {NULL}
1649       }, "Add a child to @container-name. If asset-id and child-type are specified,"
1650        " the child will be created and added. Otherwise @child-name has to be specified"
1651        " and will be added to the container.", GST_VALIDATE_ACTION_TYPE_NONE);
1652
1653   gst_validate_register_action_type ("container-remove-child", "ges", _container_remove_child,
1654       (GstValidateActionParameter []) {
1655         {
1656           .name = "container-name",
1657           .description = "The name of the GESContainer to remove a child from",
1658           .types = "string",
1659           .mandatory = TRUE,
1660         },
1661         {
1662           .name = "child-name",
1663           .description = "The name of the child to reomve from @container-name",
1664           .types = "string",
1665           .mandatory = TRUE,
1666         },
1667         {
1668           .name = "project-uri",
1669           .description = "The project URI with the serialized timeline to execute the action on",
1670           .types = "string",
1671           .mandatory = FALSE,
1672         },
1673         {NULL}
1674       }, "Remove a child from @container-name.", FALSE);
1675
1676   gst_validate_register_action_type ("ungroup-container", "ges", _ungroup,
1677       (GstValidateActionParameter []) {
1678         {
1679           .name = "container-name",
1680           .description = "The name of the GESContainer to ungroup children from",
1681           .types = "string",
1682           .mandatory = TRUE,
1683         },
1684         {
1685           .name = "recursive",
1686           .description = "Whether to recurse ungrouping or not.",
1687           .types = "boolean",
1688           .mandatory = FALSE,
1689         },
1690         {
1691           .name = "project-uri",
1692           .description = "The project URI with the serialized timeline to execute the action on",
1693           .types = "string",
1694           .mandatory = FALSE,
1695         },
1696         {NULL}
1697       }, "Ungroup children of @container-name.", FALSE);
1698
1699   gst_validate_register_action_type ("set-control-source", "ges", _validate_action_execute,
1700       (GstValidateActionParameter []) {
1701         {
1702           .name = "element-name",
1703           .description = "The name of the GESTrackElement to set the control source on",
1704           .types = "string",
1705           .mandatory = TRUE,
1706         },
1707         {
1708           .name = "property-name",
1709           .description = "The name of the property for which to set a control source",
1710           .types = "string",
1711           .mandatory = TRUE,
1712         },
1713         {
1714           .name = "binding-type",
1715           .description = "The name of the type of binding to use",
1716           .types = "string",
1717           .mandatory = FALSE,
1718           .def = "direct",
1719         },
1720         {
1721           .name = "source-type",
1722           .description = "The name of the type of ControlSource to use",
1723           .types = "string",
1724           .mandatory = FALSE,
1725           .def = "interpolation",
1726         },
1727         {
1728           .name = "interpolation-mode",
1729           .description = "The name of the GstInterpolationMode to on the source",
1730           .types = "string",
1731           .mandatory = FALSE,
1732           .def = "linear",
1733         },
1734         {
1735           .name = "project-uri",
1736           .description = "The project URI with the serialized timeline to execute the action on",
1737           .types = "string",
1738           .mandatory = FALSE,
1739         },
1740         {NULL}
1741       }, "Adds a GstControlSource on @element-name::@property-name"
1742          " allowing you to then add keyframes on that property.", GST_VALIDATE_ACTION_TYPE_NONE);
1743
1744   gst_validate_register_action_type ("add-keyframe", "ges", _validate_action_execute,
1745       (GstValidateActionParameter []) {
1746         {
1747           .name = "element-name",
1748           .description = "The name of the GESTrackElement to add a keyframe on",
1749           .types = "string",
1750           .mandatory = TRUE,
1751         },
1752         {
1753           .name = "property-name",
1754           .description = "The name of the property for which to add a keyframe on",
1755           .types = "string",
1756           .mandatory = TRUE,
1757         },
1758         {
1759           .name = "timestamp",
1760           .description = "The timestamp of the keyframe",
1761           .types = "string or float",
1762           .mandatory = TRUE,
1763         },
1764         {
1765           .name = "value",
1766           .description = "The value of the keyframe",
1767           .types = "float",
1768           .mandatory = TRUE,
1769         },
1770         {
1771           .name = "project-uri",
1772           .description = "The project URI with the serialized timeline to execute the action on",
1773           .types = "string",
1774           .mandatory = FALSE,
1775         },
1776         {NULL}
1777       }, "Set a keyframe on @element-name:property-name.", GST_VALIDATE_ACTION_TYPE_NONE);
1778
1779   gst_validate_register_action_type ("copy-element", "ges", _copy_element,
1780       (GstValidateActionParameter []) {
1781         {
1782           .name = "element-name",
1783           .description = "The name of the GESTtimelineElement to copy",
1784           .types = "string",
1785           .mandatory = TRUE,
1786         },
1787         {
1788           .name = "recurse",
1789           .description = "Copy recursively or not",
1790           .types = "boolean",
1791           .def = "true",
1792           .mandatory = FALSE,
1793         },
1794         {
1795           .name = "position",
1796           .description = "The time where to paste the element",
1797           .types = "string or float",
1798           .mandatory = TRUE,
1799         },
1800         {
1801           .name = "paste-name",
1802           .description = "The name of the copied element",
1803           .types = "string",
1804           .mandatory = FALSE,
1805         },
1806         {
1807           .name = "project-uri",
1808           .description = "The project URI with the serialized timeline to execute the action on",
1809           .types = "string",
1810           .mandatory = FALSE,
1811         },
1812         {NULL}
1813       }, "Remove a child from @container-name.", GST_VALIDATE_ACTION_TYPE_NONE);
1814
1815   gst_validate_register_action_type ("remove-keyframe", "ges", _validate_action_execute,
1816       (GstValidateActionParameter []) {
1817         {
1818           .name = "element-name",
1819           .description = "The name of the GESTrackElement to add a keyframe on",
1820           .types = "string",
1821           .mandatory = TRUE,
1822         },
1823         {
1824           .name = "property-name",
1825           .description = "The name of the property for which to add a keyframe on",
1826           .types = "string",
1827           .mandatory = TRUE,
1828         },
1829         {
1830           .name = "timestamp",
1831           .description = "The timestamp of the keyframe",
1832           .types = "string or float",
1833           .mandatory = TRUE,
1834         },
1835         {
1836           .name = "project-uri",
1837           .description = "The project URI with the serialized timeline to execute the action on",
1838           .types = "string",
1839           .mandatory = FALSE,
1840         },
1841         {NULL}
1842       }, "Remove a keyframe on @element-name:property-name.", GST_VALIDATE_ACTION_TYPE_NONE);
1843
1844   gst_validate_register_action_type ("load-project", "ges", _load_project,
1845       (GstValidateActionParameter [])  {
1846         {
1847           .name = "serialized-content",
1848           .description = "The full content of the XML describing project in XGES format.",
1849           .mandatory = FALSE,
1850           .types = "string",
1851           NULL
1852         },
1853         {
1854           .name = "uri",
1855           .description = "The uri of the project to load (used only if serialized-content is not provided)",
1856           .mandatory = FALSE,
1857           .types = "string",
1858           NULL
1859         },
1860         {NULL}
1861       },
1862       "Loads a project either from its content passed in the 'serialized-content' field or using the provided 'uri'.\n"
1863       "Note that it will completely clean the previous timeline",
1864       GST_VALIDATE_ACTION_TYPE_NONE);
1865
1866
1867   gst_validate_register_action_type ("commit", "ges", _commit, NULL,
1868        "Commit the timeline.", GST_VALIDATE_ACTION_TYPE_ASYNC);
1869   /*  *INDENT-ON* */
1870
1871   return TRUE;
1872 #else
1873   return FALSE;
1874 #endif
1875 }