From: Seungha Yang Date: Mon, 18 Jul 2022 19:05:55 +0000 (+0900) Subject: gststructure: Add gst_structure_get_flags method X-Git-Tag: 1.22.0~1257 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=43052fabb5a3eecc19bd90fe8819404de313e4b8;p=platform%2Fupstream%2Fgstreamer.git 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: --- diff --git a/subprojects/gstreamer/gst/gststructure.c b/subprojects/gstreamer/gst/gststructure.c index 5e3d6b8..2f46f06 100644 --- a/subprojects/gstreamer/gst/gststructure.c +++ b/subprojects/gstreamer/gst/gststructure.c @@ -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_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; +} diff --git a/subprojects/gstreamer/gst/gststructure.h b/subprojects/gstreamer/gst/gststructure.h index 38ea209..64fec16 100644 --- a/subprojects/gstreamer/gst/gststructure.h +++ b/subprojects/gstreamer/gst/gststructure.h @@ -342,6 +342,13 @@ GST_API gboolean gst_structure_get_list (GstStructure * structure, const gchar * fieldname, GValueArray ** array); + +GST_API +gboolean gst_structure_get_flags (const GstStructure * structure, + const gchar * fieldname, + GType flags_type, + guint * value); + GST_API gchar * gst_structure_to_string (const GstStructure * structure) G_GNUC_MALLOC; GST_API diff --git a/subprojects/gstreamer/tests/check/gst/gststructure.c b/subprojects/gstreamer/tests/check/gst/gststructure.c index e2bdfb8..21ad40a 100644 --- a/subprojects/gstreamer/tests/check/gst/gststructure.c +++ b/subprojects/gstreamer/tests/check/gst/gststructure.c @@ -1018,6 +1018,22 @@ GST_START_TEST (test_flagset) 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 * 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_filter_and_map_in_place); tcase_add_test (tc_chain, test_flagset); + tcase_add_test (tc_chain, test_flags); return s; }