structure-interface: Convert fields type as much as possible
authorThibault Saunier <tsaunier@igalia.com>
Wed, 19 May 2021 01:31:38 +0000 (21:31 -0400)
committerThibault Saunier <tsaunier@igalia.com>
Wed, 19 May 2021 02:16:47 +0000 (22:16 -0400)
Since 60922c02889cf1ebcfaca4501936be689c342e01 we force string in the
command line parser which broke setting layers on clips for example

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-editing-services/-/merge_requests/253>

ges/ges-command-line-formatter.c
ges/ges-structured-interface.c
tests/check/meson.build
tests/check/scenarios/set-layer-on-command-line.validatetest [new file with mode: 0644]

index 30d1853..823d951 100644 (file)
@@ -247,7 +247,7 @@ static GESCommandLineOption options[] = {
         "The type of the tracks where the clip should be used (audio or video or audio+video)."
       },
       {
-        "layer", "l", 0, NULL,
+        "layer", "l", G_TYPE_INT, NULL,
         "The priority of the layer into which the clip should be added."
       },
       {NULL, 0, 0, NULL, FALSE},
index 253b9b4..0ee9ab1 100644 (file)
   }                                                        \
 } G_STMT_END
 
+static gboolean
+_get_structure_value (GstStructure * structure, const gchar * field, GType type,
+    gpointer v)
+{
+  gboolean res = TRUE;
+  const gchar *value_str;
+  const GValue *value;
+  GValue nvalue = G_VALUE_INIT;
+
+  if (gst_structure_get (structure, field, type, v, NULL))
+    return res;
+
+  g_value_init (&nvalue, type);
+  value = gst_structure_get_value (structure, field);
+  if (!value)
+    goto fail;
+
+  if (g_value_transform (value, &nvalue))
+    goto set_and_get_value;
+
+  if (!G_VALUE_HOLDS_STRING (value))
+    goto fail;
+
+  value_str = g_value_get_string (value);
+  if (!gst_value_deserialize (&nvalue, value_str))
+    goto done;
+
+set_and_get_value:
+  gst_structure_set_value (structure, field, &nvalue);
+  gst_structure_get (structure, field, type, v, NULL);
+
+done:
+  g_value_reset (&nvalue);
+  return res;
+
+fail:
+  res = FALSE;
+  goto done;
+}
+
 #define TRY_GET(name, type, var, def) G_STMT_START {\
   g_assert (type != GST_TYPE_CLOCK_TIME);                      \
-  if (!gst_structure_get (structure, name, type, var, NULL))\
+  if (!_get_structure_value (structure, name, type, var))\
     *var = def;                                             \
 } G_STMT_END
 
index 6cdac7d..9a6ada7 100644 (file)
@@ -89,6 +89,7 @@ if gstvalidate_dep.found()
     'complex_effect_bin_desc': true,
     'check_keyframes_in_compositor_two_sources': true,
     'check-clip-positioning': true,
+    'set-layer-on-command-line': true,
   }
 
   foreach scenario, is_validatetest: scenarios
diff --git a/tests/check/scenarios/set-layer-on-command-line.validatetest b/tests/check/scenarios/set-layer-on-command-line.validatetest
new file mode 100644 (file)
index 0000000..d590bb8
--- /dev/null
@@ -0,0 +1,11 @@
+meta, handles-states=true,
+    tool = "ges-launch-$(gst_api_version)",
+    handles-states=true,
+    args = {
+        +test-clip, blue, "d=0.5", "layer=0", "name=blue",
+        +test-clip, green, "d=0.5", "layer=1", "name=green",
+    }
+
+check-ges-properties, element-name=blue, layer::priority=0
+check-ges-properties, element-name=green, layer::priority=1
+stop
\ No newline at end of file