structure: Add getters for int64 and uint64 values

This commit is contained in:
Sebastian Dröge 2014-02-25 15:41:45 +01:00
parent 2c2e55789d
commit ab9fdf13a0
5 changed files with 96 additions and 3 deletions

View file

@ -2541,6 +2541,8 @@ gst_structure_id_has_field_typed
gst_structure_get_boolean gst_structure_get_boolean
gst_structure_get_int gst_structure_get_int
gst_structure_get_uint gst_structure_get_uint
gst_structure_get_int64
gst_structure_get_uint64
gst_structure_get_double gst_structure_get_double
gst_structure_get_string gst_structure_get_string
gst_structure_get_date gst_structure_get_date

View file

@ -1368,6 +1368,82 @@ gst_structure_get_uint (const GstStructure * structure,
return TRUE; return TRUE;
} }
/**
* 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: * gst_structure_get_date:
* @structure: a #GstStructure * @structure: a #GstStructure

View file

@ -230,6 +230,14 @@ gboolean gst_structure_get_uint (const GstStructure *
const gchar * fieldname, const gchar * fieldname,
guint * value); 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, gboolean gst_structure_get_double (const GstStructure * structure,
const gchar * fieldname, const gchar * fieldname,
gdouble * value); gdouble * value);

View file

@ -284,24 +284,26 @@ GST_START_TEST (test_structure_new)
gboolean bool; gboolean bool;
gint num, den; gint num, den;
GstClockTime clocktime; GstClockTime clocktime;
guint64 uint64;
s = gst_structure_new ("name", s = gst_structure_new ("name",
"key", G_TYPE_STRING, "value", "key", G_TYPE_STRING, "value",
"bool", G_TYPE_BOOLEAN, TRUE, "bool", G_TYPE_BOOLEAN, TRUE,
"fraction", GST_TYPE_FRACTION, 1, 5, "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); fail_unless (gst_structure_get_field_type (s, "unknown") == G_TYPE_INVALID);
/* test setting a different name */ /* test setting a different name */
gst_structure_set_name (s, "newname"); gst_structure_set_name (s, "newname");
fail_unless (strcmp (gst_structure_get_string (s, "key"), "value") == 0); fail_unless (strcmp (gst_structure_get_string (s, "key"), "value") == 0);
fail_unless (gst_structure_has_field (s, "key")); 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 */ /* test removing a field */
gst_structure_remove_field (s, "key"); gst_structure_remove_field (s, "key");
fail_if (gst_structure_get_string (s, "key")); fail_if (gst_structure_get_string (s, "key"));
fail_if (gst_structure_has_field (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 (gst_structure_get_boolean (s, "bool", &bool));
fail_unless (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 (gst_structure_get_clock_time (s, "clocktime", &clocktime));
fail_unless_equals_uint64 (clocktime, GST_CLOCK_TIME_NONE); 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); gst_structure_free (s);
domain = g_quark_from_static_string ("test"); domain = g_quark_from_static_string ("test");

View file

@ -1084,11 +1084,13 @@ EXPORTS
gst_structure_get_field_type gst_structure_get_field_type
gst_structure_get_fraction gst_structure_get_fraction
gst_structure_get_int gst_structure_get_int
gst_structure_get_int64
gst_structure_get_name gst_structure_get_name
gst_structure_get_name_id gst_structure_get_name_id
gst_structure_get_string gst_structure_get_string
gst_structure_get_type gst_structure_get_type
gst_structure_get_uint gst_structure_get_uint
gst_structure_get_uint64
gst_structure_get_valist gst_structure_get_valist
gst_structure_get_value gst_structure_get_value
gst_structure_has_field gst_structure_has_field