validate: Add action type to copy/paste clips
authorThibault Saunier <tsaunier@igalia.com>
Sun, 26 May 2019 13:55:03 +0000 (09:55 -0400)
committerTim-Philipp Müller <tim@centricular.com>
Wed, 14 Aug 2019 22:37:58 +0000 (23:37 +0100)
ges/ges-validate.c

index 5cd4e15..4d17354 100644 (file)
@@ -495,6 +495,56 @@ _ungroup (GstValidateScenario * scenario, GstValidateAction * action)
   return res;
 }
 
+static GstValidateExecuteActionReturn
+_copy_element (GstValidateScenario * scenario, GstValidateAction * action)
+{
+  GESTimelineElement *element, *copied, *pasted;
+  gboolean recursive = FALSE;
+  const gchar *element_name, *paste_name;
+  GstClockTime position;
+  DECLARE_AND_GET_TIMELINE (scenario, action);
+
+
+  element_name = gst_structure_get_string (action->structure, "element-name");
+  element = ges_timeline_get_element (timeline, element_name);
+
+  g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (element),
+      GST_VALIDATE_EXECUTE_ACTION_ERROR);
+
+  gst_validate_printf (action, "Copying element %s\n",
+      GES_TIMELINE_ELEMENT_NAME (element));
+
+  if (!gst_structure_get_boolean (action->structure, "recursive", &recursive))
+    recursive = TRUE;
+
+  g_return_val_if_fail (gst_validate_action_get_clocktime (scenario, action,
+          "position", &position), FALSE);
+
+  copied = ges_timeline_element_copy (element, recursive);
+  pasted = ges_timeline_element_paste (copied, position);
+  gst_object_unref (timeline);
+
+  if (!pasted) {
+    GST_VALIDATE_REPORT (scenario,
+        g_quark_from_string ("scenario::execution-error"),
+        "Could not paste clip %s", element_name);
+    return GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
+  }
+
+  paste_name = gst_structure_get_string (action->structure, "paste-name");
+  if (paste_name) {
+    if (!ges_timeline_element_set_name (pasted, paste_name)) {
+      GST_VALIDATE_REPORT (scenario,
+          g_quark_from_string ("scenario::execution-error"),
+          "Could not set element name %s", paste_name);
+
+      return GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
+    }
+  }
+
+  return GST_VALIDATE_EXECUTE_ACTION_OK;
+}
+
 static gboolean
 _set_control_source (GstValidateScenario * scenario, GstValidateAction * action)
 {
@@ -1100,6 +1150,36 @@ ges_validate_register_action_types (void)
         {NULL}
       }, "Remove a child from @container-name.", GST_VALIDATE_ACTION_TYPE_NONE);
 
+  gst_validate_register_action_type ("copy-element", "ges", _copy_element,
+      (GstValidateActionParameter []) {
+        {
+          .name = "element-name",
+          .description = "The name of the GESTtimelineElement to copy",
+          .types = "string",
+          .mandatory = TRUE,
+        },
+        {
+          .name = "recurse",
+          .description = "Copy recursively or not",
+          .types = "boolean",
+          .def = "true",
+          .mandatory = FALSE,
+        },
+        {
+          .name = "position",
+          .description = "The time where to paste the element",
+          .types = "string or float",
+          .mandatory = TRUE,
+        },
+        {
+          .name = "paste-name",
+          .description = "The name of the copied element",
+          .types = "string",
+          .mandatory = FALSE,
+        },
+        {NULL}
+      }, "Remove a child from @container-name.", GST_VALIDATE_ACTION_TYPE_NONE);
+
   gst_validate_register_action_type ("remove-keyframe", "ges", _validate_action_execute,
       (GstValidateActionParameter []) {
         {