mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 04:46:13 +00:00
gststructure: Add gst_structure_get_flags method
We don't prevent setting G_TYPE_FLAGS on GstStructure but no helper method for getting the value. Add a method similar to gst_structure_get_enum() Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2770>
This commit is contained in:
parent
205034dea9
commit
43052fabb5
3 changed files with 64 additions and 0 deletions
|
@ -3476,3 +3476,43 @@ gst_structure_set_list (GstStructure * structure, const gchar * fieldname,
|
||||||
{
|
{
|
||||||
_gst_structure_set_any_list (structure, GST_TYPE_LIST, fieldname, array);
|
_gst_structure_set_any_list (structure, GST_TYPE_LIST, fieldname, array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_structure_get_flags:
|
||||||
|
* @structure: a #GstStructure
|
||||||
|
* @fieldname: the name of a field
|
||||||
|
* @flags_type: the flags type of a field
|
||||||
|
* @value: (out): a pointer to an unsigned int to set
|
||||||
|
*
|
||||||
|
* Sets the unsigned int pointed to by @value corresponding to the value of the
|
||||||
|
* given field. Caller is responsible for making sure the field exists,
|
||||||
|
* has the correct type and that the flagstype is correct.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if the value could be set correctly. If there was no field
|
||||||
|
* with @fieldname or the existing field did not contain flags or
|
||||||
|
* did not contain flags of the given type, this function returns %FALSE.
|
||||||
|
*
|
||||||
|
* Since: 1.22
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
gst_structure_get_flags (const GstStructure * structure,
|
||||||
|
const gchar * fieldname, GType flags_type, guint * value)
|
||||||
|
{
|
||||||
|
GstStructureField *field;
|
||||||
|
|
||||||
|
g_return_val_if_fail (structure != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (fieldname != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (flags_type != G_TYPE_INVALID, FALSE);
|
||||||
|
g_return_val_if_fail (value != NULL, FALSE);
|
||||||
|
|
||||||
|
field = gst_structure_get_field (structure, fieldname);
|
||||||
|
|
||||||
|
if (field == NULL)
|
||||||
|
return FALSE;
|
||||||
|
if (!G_TYPE_CHECK_VALUE_TYPE (&field->value, flags_type))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
*value = g_value_get_flags (&field->value);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
|
@ -342,6 +342,13 @@ GST_API
|
||||||
gboolean gst_structure_get_list (GstStructure * structure,
|
gboolean gst_structure_get_list (GstStructure * structure,
|
||||||
const gchar * fieldname,
|
const gchar * fieldname,
|
||||||
GValueArray ** array);
|
GValueArray ** array);
|
||||||
|
|
||||||
|
GST_API
|
||||||
|
gboolean gst_structure_get_flags (const GstStructure * structure,
|
||||||
|
const gchar * fieldname,
|
||||||
|
GType flags_type,
|
||||||
|
guint * value);
|
||||||
|
|
||||||
GST_API
|
GST_API
|
||||||
gchar * gst_structure_to_string (const GstStructure * structure) G_GNUC_MALLOC;
|
gchar * gst_structure_to_string (const GstStructure * structure) G_GNUC_MALLOC;
|
||||||
GST_API
|
GST_API
|
||||||
|
|
|
@ -1018,6 +1018,22 @@ GST_START_TEST (test_flagset)
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
|
||||||
|
GST_START_TEST (test_flags)
|
||||||
|
{
|
||||||
|
GstStructure *s;
|
||||||
|
GstSeekFlags flags = GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT;
|
||||||
|
guint parsed_flags = 0;
|
||||||
|
|
||||||
|
s = gst_structure_new ("test-struct", "test-seek-flags",
|
||||||
|
GST_TYPE_SEEK_FLAGS, flags, NULL);
|
||||||
|
fail_unless (gst_structure_get_flags (s, "test-seek-flags",
|
||||||
|
GST_TYPE_SEEK_FLAGS, &parsed_flags));
|
||||||
|
fail_unless (flags == (GstSeekFlags) parsed_flags);
|
||||||
|
gst_structure_free (s);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
static Suite *
|
static Suite *
|
||||||
gst_structure_suite (void)
|
gst_structure_suite (void)
|
||||||
{
|
{
|
||||||
|
@ -1050,6 +1066,7 @@ gst_structure_suite (void)
|
||||||
tcase_add_test (tc_chain, test_map_in_place);
|
tcase_add_test (tc_chain, test_map_in_place);
|
||||||
tcase_add_test (tc_chain, test_filter_and_map_in_place);
|
tcase_add_test (tc_chain, test_filter_and_map_in_place);
|
||||||
tcase_add_test (tc_chain, test_flagset);
|
tcase_add_test (tc_chain, test_flagset);
|
||||||
|
tcase_add_test (tc_chain, test_flags);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue