GESTrackObject: Implement a get/set_child_property_by_spec and get/set_child_propert...
authorThibault Saunier <thibault.saunier@collabora.co.uk>
Fri, 25 Feb 2011 11:13:03 +0000 (12:13 +0100)
committerEdward Hervey <edward.hervey@collabora.co.uk>
Fri, 6 May 2011 08:39:05 +0000 (10:39 +0200)
Reimplement the get/set_property accordingly

docs/libs/ges-sections.txt
ges/ges-track-object.c
ges/ges-track-object.h
tests/check/ges/effects.c

index ae4695a37d109db1e016d932dfebc5aec49db252..4653be0e2b1212b0d8a7496a3e4c1debb1869c0a 100644 (file)
@@ -85,7 +85,11 @@ ges_track_object_get_priority
 ges_track_object_is_active
 ges_track_object_lookup_child
 ges_track_object_set_child_property
+ges_track_object_set_child_property_valist
+ges_track_object_set_child_property_by_pspec
 ges_track_object_get_child_property
+ges_track_object_get_child_property_valist
+ges_track_object_get_child_property_by_pspec
 <SUBSECTION Standard>
 GES_TRACK_OBJECT_DURATION
 GES_TRACK_OBJECT_INPOINT
index a5c716a393eee404c7bb7f8464324c9d9d9cf69a..d92d14d1830d1e2a9d2e3deb00107890485c4d8e 100644 (file)
@@ -34,6 +34,7 @@
 #include "gesmarshal.h"
 #include "ges-track-object.h"
 #include "ges-timeline-object.h"
+#include <gobject/gvaluecollector.h>
 
 G_DEFINE_ABSTRACT_TYPE (GESTrackObject, ges_track_object,
     G_TYPE_INITIALLY_UNOWNED);
@@ -1051,64 +1052,250 @@ ges_track_object_lookup_child (GESTrackObject * object, const gchar * prop_name,
 }
 
 /**
- * ges_track_object_set_child_property:
+ * ges_track_object_set_child_property_by_pspec:
  * @object: a #GESTrackObject
- * @property_name: The name of the property to set
+ * @pspec: The #GParamSpec that specifies the property you want to set
  * @value: the value
  *
- * Sets a property of a child of @object. The property name
- * should look like ClasseName-property-name
+ * Sets a property of a child of @object.
  */
 void
-ges_track_object_set_child_property (GESTrackObject * object,
-    const gchar * property_name, GValue * value)
+ges_track_object_set_child_property_by_pspec (GESTrackObject * object,
+    GParamSpec * pspec, GValue * value)
 {
+  GstElement *element;
+
   GESTrackObjectPrivate *priv = object->priv;
 
-  if (priv->properties_hashtable) {
-    GstElement *element;
-    gchar **prop_name;
-
-    element = g_hash_table_lookup (priv->properties_hashtable, property_name);
-    if (element) {
-      prop_name = g_strsplit (property_name, "-", 2);
-      g_object_set_property (G_OBJECT (element), prop_name[1], value);
-      g_strfreev (prop_name);
-    } else {
-      GST_ERROR ("The %s property doesn't exist", property_name);
-    }
-  } else {
+  if (!priv->properties_hashtable)
+    goto prop_hash_not_set;
+
+  element = g_hash_table_lookup (priv->properties_hashtable, pspec);
+  if (!element)
+    goto not_found;
+
+  g_object_set_property (G_OBJECT (element), pspec->name, value);
+
+  return;
+
+not_found:
+  {
+    GST_ERROR ("The %s property doesn't exist", pspec->name);
+    return;
+  }
+prop_hash_not_set:
+  {
     GST_DEBUG ("The child properties haven't been set on %p", object);
+    return;
   }
 }
 
 /**
-* ges_track_object_get_child_property:
-* @object: The origin #GESTrackObject
-* @property_name: The name of the property
-* @value: return location for the property value
-*
-* Gets a property of a child of @object.
-*/
+ * ges_track_object_set_child_property_valist:
+ * @object: The #GESTrackObject parent object
+ * @first_property_name: The name of the first property to set
+ * @var_args: value for the first property, followed optionally by more
+ * name/return location pairs, followed by NULL
+ *
+ * Sets a property of a child of @object. If there are various child elements
+ * that have the same property name, you can distinguish them using the following
+ * synthaxe: 'ClasseName::property_name' as property name. If you don't, the
+ * corresponding property of the first element found will be set.
+ */
+void
+ges_track_object_set_child_property_valist (GESTrackObject * object,
+    const gchar * first_property_name, va_list var_args)
+{
+  const gchar *name;
+  GParamSpec *pspec;
+  GstElement *element;
+
+  gchar *error = NULL;
+  GValue value = { 0, };
+
+  g_return_if_fail (G_IS_OBJECT (object));
+
+  name = first_property_name;
+
+  /* Note: This part is in big part copied from the gst_child_object_set_valist
+   * method. */
+
+  /* iterate over pairs */
+  while (name) {
+    if (!ges_track_object_lookup_child (object, name, &element, &pspec))
+      goto not_found;
+
+#if GLIB_CHECK_VERSION(2,23,3)
+    G_VALUE_COLLECT_INIT (&value, pspec->value_type, var_args,
+        G_VALUE_NOCOPY_CONTENTS, &error);
+#else
+    g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
+    G_VALUE_COLLECT (&value, var_args, G_VALUE_NOCOPY_CONTENTS, &error);
+#endif
+
+    if (error)
+      goto cant_copy;
+
+    g_object_set_property (G_OBJECT (element), pspec->name, &value);
+
+    g_object_unref (element);
+    g_value_unset (&value);
+
+    name = va_arg (var_args, gchar *);
+  }
+  return;
+
+not_found:
+  {
+    GST_WARNING ("No property %s in OBJECT\n", name);
+    return;
+  }
+cant_copy:
+  {
+    GST_WARNING ("error copying value %s in object %p: %s", pspec->name, object,
+        error);
+    g_value_unset (&value);
+    return;
+  }
+}
+
+/**
+ * ges_track_object_set_child_property:
+ * @object: The #GESTrackObject parent object
+ * @first_property_name: The name of the first property to set
+ * @...: value for the first property, followed optionally by more
+ * name/return location pairs, followed by NULL
+ *
+ * Sets a property of a child of @object. If there are various child elements
+ * that have the same property name, you can distinguish them using the following
+ * synthaxe: 'ClasseName::property_name' as property name. If you don't, the
+ * corresponding property of the first element found will be set.
+ */
+void
+ges_track_object_set_child_property (GESTrackObject * object,
+    const gchar * first_property_name, ...)
+{
+  va_list var_args;
+
+  va_start (var_args, first_property_name);
+  ges_track_object_set_child_property_valist (object, first_property_name,
+      var_args);
+  va_end (var_args);
+}
+
+/**
+ * ges_track_object_get_child_property_valist:
+ * @object: The #GESTrackObject parent object
+ * @first_property_name: The name of the first property to get
+ * @var_args: value for the first property, followed optionally by more
+ * name/return location pairs, followed by NULL
+ *
+ * Gets a property of a child of @object. If there are various child elements
+ * that have the same property name, you can distinguish them using the following
+ * synthaxe: 'ClasseName::property_name' as property name. If you don't, the
+ * corresponding property of the first element found will be set.
+ */
+void
+ges_track_object_get_child_property_valist (GESTrackObject * object,
+    const gchar * first_property_name, va_list var_args)
+{
+  const gchar *name;
+  gchar *error = NULL;
+  GValue value = { 0, };
+  GParamSpec *pspec;
+  GstElement *element;
+
+  g_return_if_fail (G_IS_OBJECT (object));
+
+  name = first_property_name;
+
+  /* This part is in big part copied from the gst_child_object_get_valist method */
+  while (name) {
+    if (!ges_track_object_lookup_child (object, name, &element, &pspec))
+      goto not_found;
+
+    g_value_init (&value, pspec->value_type);
+    g_object_get_property (G_OBJECT (element), pspec->name, &value);
+    g_object_unref (element);
+
+    G_VALUE_LCOPY (&value, var_args, 0, &error);
+    if (error)
+      goto cant_copy;
+    g_value_unset (&value);
+    name = va_arg (var_args, gchar *);
+  }
+  return;
+
+not_found:
+  {
+    GST_WARNING ("no property %s in object", name);
+    return;
+  }
+cant_copy:
+  {
+    GST_WARNING ("error copying value %s in object %p: %s", pspec->name, object,
+        error);
+    g_value_unset (&value);
+    return;
+  }
+}
+
+/**
+ * ges_track_object_get_child_property:
+ * @object: The origin #GESTrackObject
+ * @first_property_name: The name of the first property to get
+ * @...: return location for the first property, followed optionally by more
+ * name/return location pairs, followed by NULL
+ *
+ * Gets properties of a child of @object.
+ */
 void
 ges_track_object_get_child_property (GESTrackObject * object,
-    const gchar * property_name, gpointer value)
+    const gchar * first_property_name, ...)
 {
+  va_list var_args;
+
+  va_start (var_args, first_property_name);
+  ges_track_object_get_child_property_valist (object, first_property_name,
+      var_args);
+  va_end (var_args);
+}
+
+/**
+ * ges_track_object_get_child_property_by_pspec:
+ * @object: a #GESTrackObject
+ * @pspec: The #GParamSpec that specifies the property you want to get
+ * @value: return location for the value
+ *
+ * Gets a property of a child of @object.
+ */
+void
+ges_track_object_get_child_property_by_pspec (GESTrackObject * object,
+    GParamSpec * pspec, GValue * value)
+{
+  GstElement *element;
+
   GESTrackObjectPrivate *priv = object->priv;
 
-  if (priv->properties_hashtable) {
-    GstElement *element;
-    gchar **prop_name;
-
-    element = g_hash_table_lookup (priv->properties_hashtable, property_name);
-    if (element) {
-      prop_name = g_strsplit (property_name, "-", 2);
-      g_object_get (G_OBJECT (element), prop_name[1], value, NULL);
-      g_strfreev (prop_name);
-    } else {
-      GST_ERROR ("The %s property doesn't exist", property_name);
-    }
-  } else {
-    GST_DEBUG ("The child properties haven't been set on %p", object);
+  if (!priv->properties_hashtable)
+    goto prop_hash_not_set;
+
+  element = g_hash_table_lookup (priv->properties_hashtable, pspec);
+  if (!element)
+    goto not_found;
+
+  g_object_get_property (G_OBJECT (element), pspec->name, value);
+
+  return;
+
+not_found:
+  {
+    GST_ERROR ("The %s property doesn't exist", pspec->name);
+    return;
+  }
+prop_hash_not_set:
+  {
+    GST_ERROR ("The child properties haven't been set on %p", object);
+    return;
   }
 }
index 64c693ced9d65652aa0cae7cea60a006b925acfb..813c61b29a3c9901fdd463b70b67999f5af8bfc1 100644 (file)
@@ -164,8 +164,19 @@ gboolean ges_track_object_is_active (GESTrackObject * object);
 gboolean ges_track_object_lookup_child (GESTrackObject *object,
      const gchar *prop_name, GstElement **element, GParamSpec **pspec);
 
+void ges_track_object_get_child_property_by_pspec (GESTrackObject * object,
+     GParamSpec * pspec, GValue * value);
+void ges_track_object_get_child_property_valist (GESTrackObject * object,
+    const gchar * first_property_name, va_list var_args);
 void ges_track_object_get_child_property (GESTrackObject *object,
-                                          const gchar *property_name,
-                                          gpointer value);
+    const gchar * first_property_name, ...)  G_GNUC_NULL_TERMINATED;
+
+void ges_track_object_set_child_property_valist (GESTrackObject * object,
+      const gchar * first_property_name, va_list var_args);
+void ges_track_object_set_child_property_by_pspec (GESTrackObject * object,
+    GParamSpec * pspec, GValue * value);
+void ges_track_object_set_child_property (GESTrackObject * object,
+    const gchar * first_property_name, ...) G_GNUC_NULL_TERMINATED;
+
 G_END_DECLS
 #endif /* _GES_TRACK_OBJECT */
index 88297e9c98bd43144ecb52f9b08a9427e2f1d7bd..d5632bf635012c8ef6fc0f035d928b3e10b226b0 100644 (file)
@@ -328,8 +328,8 @@ GST_START_TEST (test_track_effect_set_properties)
   GESTrack *track_video;
   GESTimelineParseLaunchEffect *tl_effect;
   GESTrackParseLaunchEffect *tck_effect;
-  GValue value = { 0 };
-  guint val;
+  guint scratch_line;
+  gboolean color_aging;
 
   ges_init ();
 
@@ -354,13 +354,13 @@ GST_START_TEST (test_track_effect_set_properties)
   fail_unless (ges_track_add_object (track_video,
           GES_TRACK_OBJECT (tck_effect)));
 
-  g_value_init (&value, G_TYPE_UINT);
-  g_value_set_uint (&value, 17);
   ges_track_object_set_child_property (GES_TRACK_OBJECT (tck_effect),
-      "GstAgingTV-scratch-lines", &value);
+      "GstAgingTV::scratch-lines", 17, "color-aging", FALSE, NULL);
   ges_track_object_get_child_property (GES_TRACK_OBJECT (tck_effect),
-      "GstAgingTV-scratch-lines", &val);
-  fail_unless (val == 17);
+      "GstAgingTV::scratch-lines", &scratch_line,
+      "color-aging", &color_aging, NULL);
+  fail_unless (scratch_line == 17);
+  fail_unless (color_aging == FALSE);
 
   ges_timeline_layer_remove_object (layer, (GESTimelineObject *) tl_effect);
 
@@ -393,7 +393,6 @@ GST_START_TEST (test_tl_obj_signals)
   GESTrack *track_video;
   GESTimelineParseLaunchEffect *tl_effect;
   GESTrackParseLaunchEffect *tck_effect;
-  GValue value = { 0 };
   guint val;
 
   ges_init ();
@@ -423,12 +422,10 @@ GST_START_TEST (test_tl_obj_signals)
   g_signal_connect (tck_effect, "deep-notify", (GCallback) deep_prop_changed_cb,
       tck_effect);
 
-  g_value_init (&value, G_TYPE_UINT);
-  g_value_set_uint (&value, 17);
   ges_track_object_set_child_property (GES_TRACK_OBJECT (tck_effect),
-      "GstAgingTV-scratch-lines", &value);
+      "GstAgingTV::scratch-lines", 17, NULL);
   ges_track_object_get_child_property (GES_TRACK_OBJECT (tck_effect),
-      "GstAgingTV-scratch-lines", &val);
+      "GstAgingTV::scratch-lines", &val, NULL);
   fail_unless (val == 17);
 
   ges_timeline_layer_remove_object (layer, (GESTimelineObject *) tl_effect);