gstutils: Add helpers to get/set array properties
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Mon, 20 Mar 2017 20:46:33 +0000 (16:46 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Fri, 24 Mar 2017 17:30:45 +0000 (13:30 -0400)
This is to help bindings access properties of type GST_TYPE_ARRAY.
This function will get/set the property and convert form/to
GValueArray.

New API:
  gst_util_set_object_array
  gst_util_get_object_array

https://bugzilla.gnome.org/show_bug.cgi?id=753754

docs/gst/gstreamer-sections.txt
gst/gstutils.c
gst/gstutils.h
win32/common/libgstreamer.def

index 5acc42d..18f106f 100644 (file)
@@ -3546,6 +3546,8 @@ gst_util_seqnum_compare
 gst_util_group_id_next
 gst_util_set_object_arg
 gst_util_set_value_from_string
+gst_util_set_object_array
+gst_util_get_object_array
 gst_util_get_timestamp
 GstSearchMode
 gst_util_array_binary_search
index 31a23c8..ec3a335 100644 (file)
  *
  */
 
+/* FIXME 2.0: suppress warnings for deprecated API such as GValueArray
+ * with newer GLib versions (>= 2.31.0) */
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
 #include "gst_private.h"
 #include <stdio.h>
 #include <string.h>
@@ -167,6 +171,75 @@ done:
   g_value_unset (&v);
 }
 
+/**
+ * gst_util_set_object_array:
+ * @object: the object to set the array to
+ * @name: the name of the property to set
+ * @array: a #GValueArray containing the values
+ *
+ * Transfer a #GValueArray to %GST_TYPE_ARRAY and set this value on the
+ * specified property name. This allow language bindings to set GST_TYPE_ARRAY
+ * properties which are otherwise not an accessible type.
+ *
+ * Since: 1.12
+ */
+gboolean
+gst_util_set_object_array (GObject * object, const gchar * name,
+    const GValueArray * array)
+{
+  GValue v1 = G_VALUE_INIT, v2 = G_VALUE_INIT;
+  gboolean ret = FALSE;
+
+  g_value_init (&v1, G_TYPE_VALUE_ARRAY);
+  g_value_init (&v2, GST_TYPE_ARRAY);
+
+  g_value_set_static_boxed (&v1, array);
+
+  if (g_value_transform (&v1, &v2)) {
+    g_object_set_property (object, name, &v2);
+    ret = TRUE;
+  }
+
+  g_value_unset (&v1);
+  g_value_unset (&v2);
+
+  return ret;
+}
+
+/**
+ * gst_util_get_object_array:
+ * @object: the object to set the array to
+ * @name: the name of the property to set
+ * @array: (out): a return #GValueArray
+ *
+ * Get a property of type %GST_TYPE_ARRAY and transform it into a
+ * #GValueArray. This allow language bindings to get GST_TYPE_ARRAY
+ * properties which are otherwise not an accessible type.
+ *
+ * Since: 1.12
+ */
+gboolean
+gst_util_get_object_array (GObject * object, const gchar * name,
+    GValueArray ** array)
+{
+  GValue v1 = G_VALUE_INIT, v2 = G_VALUE_INIT;
+  gboolean ret = FALSE;
+
+  g_value_init (&v1, G_TYPE_VALUE_ARRAY);
+  g_value_init (&v2, GST_TYPE_ARRAY);
+
+  g_object_get_property (object, name, &v2);
+
+  if (g_value_transform (&v2, &v1)) {
+    *array = g_value_get_boxed (&v1);
+    ret = TRUE;
+  }
+
+  g_value_unset (&v2);
+
+  return ret;
+}
+
 /* work around error C2520: conversion from unsigned __int64 to double
  * not implemented, use signed __int64
  *
index e3ab890..b56ad09 100644 (file)
@@ -34,6 +34,10 @@ G_BEGIN_DECLS
 
 void            gst_util_set_value_from_string  (GValue *value, const gchar *value_str);
 void            gst_util_set_object_arg         (GObject *object, const gchar *name, const gchar *value);
+gboolean        gst_util_set_object_array       (GObject * object, const gchar * name,
+                                                 const GValueArray * array);
+gboolean        gst_util_get_object_array       (GObject * object, const gchar * name,
+                                                 GValueArray ** array);
 void            gst_util_dump_mem               (const guchar *mem, guint size);
 
 guint64         gst_util_gdouble_to_guint64     (gdouble value)  G_GNUC_CONST;
index 99a1541..3b2aecc 100644 (file)
@@ -1563,6 +1563,8 @@ EXPORTS
        gst_util_seqnum_compare
        gst_util_seqnum_next
        gst_util_set_object_arg
+       gst_util_set_object_array
+       gst_util_get_object_array
        gst_util_set_value_from_string
        gst_util_uint64_scale
        gst_util_uint64_scale_ceil