structure: Add getters for int64 and uint64 values
authorSebastian Dröge <sebastian@centricular.com>
Tue, 25 Feb 2014 14:41:45 +0000 (15:41 +0100)
committerSebastian Dröge <sebastian@centricular.com>
Tue, 25 Feb 2014 14:41:45 +0000 (15:41 +0100)
docs/gst/gstreamer-sections.txt
gst/gststructure.c
gst/gststructure.h
tests/check/gst/gststructure.c
win32/common/libgstreamer.def

index 47374f8..db1a6ee 100644 (file)
@@ -2541,6 +2541,8 @@ gst_structure_id_has_field_typed
 gst_structure_get_boolean
 gst_structure_get_int
 gst_structure_get_uint
+gst_structure_get_int64
+gst_structure_get_uint64
 gst_structure_get_double
 gst_structure_get_string
 gst_structure_get_date
index 5f354bf..6edc359 100644 (file)
@@ -1369,6 +1369,82 @@ gst_structure_get_uint (const GstStructure * structure,
 }
 
 /**
+ * gst_structure_get_int64:
+ * @structure: a #GstStructure
+ * @fieldname: the name of a field
+ * @value: (out): a pointer to an int64 to set
+ *
+ * Sets the int64 pointed to by @value corresponding to the value of the
+ * given field. Caller is responsible for making sure the field exists
+ * and has the correct type.
+ *
+ * Returns: %TRUE if the value could be set correctly. If there was no field
+ * with @fieldname or the existing field did not contain an int64, this function
+ * returns %FALSE.
+ *
+ * Since: 1.4
+ */
+gboolean
+gst_structure_get_int64 (const GstStructure * structure,
+    const gchar * fieldname, gint64 * value)
+{
+  GstStructureField *field;
+
+  g_return_val_if_fail (structure != NULL, FALSE);
+  g_return_val_if_fail (fieldname != NULL, FALSE);
+  g_return_val_if_fail (value != NULL, FALSE);
+
+  field = gst_structure_get_field (structure, fieldname);
+
+  if (field == NULL)
+    return FALSE;
+  if (!G_VALUE_HOLDS_INT64 (&field->value))
+    return FALSE;
+
+  *value = gst_g_value_get_int64_unchecked (&field->value);
+
+  return TRUE;
+}
+
+/**
+ * gst_structure_get_uint64:
+ * @structure: a #GstStructure
+ * @fieldname: the name of a field
+ * @value: (out): a pointer to a uint64 to set
+ *
+ * Sets the uint64 pointed to by @value corresponding to the value of the
+ * given field. Caller is responsible for making sure the field exists
+ * and has the correct type.
+ *
+ * Returns: %TRUE if the value could be set correctly. If there was no field
+ * with @fieldname or the existing field did not contain a uint64, this function
+ * returns %FALSE.
+ *
+ * Since: 1.4
+ */
+gboolean
+gst_structure_get_uint64 (const GstStructure * structure,
+    const gchar * fieldname, guint64 * value)
+{
+  GstStructureField *field;
+
+  g_return_val_if_fail (structure != NULL, FALSE);
+  g_return_val_if_fail (fieldname != NULL, FALSE);
+  g_return_val_if_fail (value != NULL, FALSE);
+
+  field = gst_structure_get_field (structure, fieldname);
+
+  if (field == NULL)
+    return FALSE;
+  if (!G_VALUE_HOLDS_UINT64 (&field->value))
+    return FALSE;
+
+  *value = gst_g_value_get_uint64_unchecked (&field->value);
+
+  return TRUE;
+}
+
+/**
  * gst_structure_get_date:
  * @structure: a #GstStructure
  * @fieldname: the name of a field
index f7cc61b..684f558 100644 (file)
@@ -230,6 +230,14 @@ gboolean              gst_structure_get_uint             (const GstStructure  *
                                                           const gchar         * fieldname,
                                                           guint               * value);
 
+gboolean              gst_structure_get_int64            (const GstStructure  * structure,
+                                                          const gchar         * fieldname,
+                                                          gint64              * value);
+
+gboolean              gst_structure_get_uint64           (const GstStructure  * structure,
+                                                          const gchar         * fieldname,
+                                                          guint64             * value);
+
 gboolean              gst_structure_get_double           (const GstStructure  * structure,
                                                           const gchar         * fieldname,
                                                           gdouble             * value);
index 8a0bf7d..58ee819 100644 (file)
@@ -284,24 +284,26 @@ GST_START_TEST (test_structure_new)
   gboolean bool;
   gint num, den;
   GstClockTime clocktime;
+  guint64 uint64;
 
   s = gst_structure_new ("name",
       "key", G_TYPE_STRING, "value",
       "bool", G_TYPE_BOOLEAN, TRUE,
       "fraction", GST_TYPE_FRACTION, 1, 5,
-      "clocktime", GST_TYPE_CLOCK_TIME, GST_CLOCK_TIME_NONE, NULL);
+      "clocktime", GST_TYPE_CLOCK_TIME, GST_CLOCK_TIME_NONE,
+      "uint64", G_TYPE_UINT64, (guint64) 1234, NULL);
 
   fail_unless (gst_structure_get_field_type (s, "unknown") == G_TYPE_INVALID);
   /* test setting a different name */
   gst_structure_set_name (s, "newname");
   fail_unless (strcmp (gst_structure_get_string (s, "key"), "value") == 0);
   fail_unless (gst_structure_has_field (s, "key"));
-  fail_unless_equals_int (gst_structure_n_fields (s), 4);
+  fail_unless_equals_int (gst_structure_n_fields (s), 5);
   /* test removing a field */
   gst_structure_remove_field (s, "key");
   fail_if (gst_structure_get_string (s, "key"));
   fail_if (gst_structure_has_field (s, "key"));
-  fail_unless_equals_int (gst_structure_n_fields (s), 3);
+  fail_unless_equals_int (gst_structure_n_fields (s), 4);
 
   fail_unless (gst_structure_get_boolean (s, "bool", &bool));
   fail_unless (bool);
@@ -313,6 +315,9 @@ GST_START_TEST (test_structure_new)
   fail_unless (gst_structure_get_clock_time (s, "clocktime", &clocktime));
   fail_unless_equals_uint64 (clocktime, GST_CLOCK_TIME_NONE);
 
+  fail_unless (gst_structure_get_uint64 (s, "uint64", &uint64));
+  fail_unless_equals_uint64 (uint64, 1234);
+
   gst_structure_free (s);
 
   domain = g_quark_from_static_string ("test");
index f9f3254..8e177e1 100644 (file)
@@ -1084,11 +1084,13 @@ EXPORTS
        gst_structure_get_field_type
        gst_structure_get_fraction
        gst_structure_get_int
+       gst_structure_get_int64
        gst_structure_get_name
        gst_structure_get_name_id
        gst_structure_get_string
        gst_structure_get_type
        gst_structure_get_uint
+       gst_structure_get_uint64
        gst_structure_get_valist
        gst_structure_get_value
        gst_structure_has_field