mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 08:17:01 +00:00
validate: Add a way to avoid checking property value after setting it
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4485>
This commit is contained in:
parent
aed4d31e67
commit
9dda8050f2
5 changed files with 108 additions and 15 deletions
|
@ -1726,6 +1726,16 @@ target is in.</doc>
|
|||
</array>
|
||||
</field>
|
||||
</record>
|
||||
<bitfield name="ObjectSetPropertyFlags" version="1.24" glib:type-name="GstValidateObjectSetPropertyFlags" glib:get-type="gst_validate_object_set_property_flags_get_type" c:type="GstValidateObjectSetPropertyFlags">
|
||||
<member name="optional" value="1" c:identifier="GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_OPTIONAL" glib:nick="optional">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-enums.h">The property is optional, if it
|
||||
is not found on the object, nothing happens.</doc>
|
||||
</member>
|
||||
<member name="no_value_check" value="2" c:identifier="GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_NO_VALUE_CHECK" glib:nick="no-value-check">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-enums.h">Do not check that after
|
||||
setting the property, the value is the one we set.</doc>
|
||||
</member>
|
||||
</bitfield>
|
||||
<class name="Override" c:symbol-prefix="override" c:type="GstValidateOverride" parent="Gst.Object" glib:type-name="GstValidateOverride" glib:get-type="gst_validate_override_get_type" glib:type-struct="OverrideClass">
|
||||
<source-position filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-override.h"/>
|
||||
<implements name="Reporter"/>
|
||||
|
@ -4092,6 +4102,34 @@ function.</doc>
|
|||
</parameter>
|
||||
</parameters>
|
||||
</function>
|
||||
<function name="object_set_property_full" c:identifier="gst_validate_object_set_property_full" version="1.24">
|
||||
<source-position filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.h"/>
|
||||
<return-value transfer-ownership="none">
|
||||
<type name="ActionReturn" c:type="GstValidateActionReturn"/>
|
||||
</return-value>
|
||||
<parameters>
|
||||
<parameter name="reporter" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c">The #GstValidateReporter to use to report errors</doc>
|
||||
<type name="Reporter" c:type="GstValidateReporter*"/>
|
||||
</parameter>
|
||||
<parameter name="object" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c">The #GObject to set the property on</doc>
|
||||
<type name="GObject.Object" c:type="GObject*"/>
|
||||
</parameter>
|
||||
<parameter name="property" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c">The name of the property to set</doc>
|
||||
<type name="utf8" c:type="const gchar*"/>
|
||||
</parameter>
|
||||
<parameter name="value" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c">The value to set the property to</doc>
|
||||
<type name="GObject.Value" c:type="const GValue*"/>
|
||||
</parameter>
|
||||
<parameter name="flags" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-utils.c">The #GstValidateObjectSetPropertyFlags to use</doc>
|
||||
<type name="ObjectSetPropertyFlags" c:type="GstValidateObjectSetPropertyFlags"/>
|
||||
</parameter>
|
||||
</parameters>
|
||||
</function>
|
||||
<function name="override_registry_attach_overrides" c:identifier="gst_validate_override_registry_attach_overrides" moved-to="OverrideRegistry.attach_overrides">
|
||||
<source-position filename="../subprojects/gst-devtools/validate/gst/validate/gst-validate-override-registry.h"/>
|
||||
<return-value transfer-ownership="none">
|
||||
|
|
|
@ -113,4 +113,19 @@ typedef enum {
|
|||
GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_NO_EXPRESSION = 1 << 1,
|
||||
} GstValidateStructureResolveVariablesFlags;
|
||||
|
||||
|
||||
/**
|
||||
* GstValidateObjectSetPropertyFlags:
|
||||
* @GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_OPTIONAL: The property is optional, if it
|
||||
* is not found on the object, nothing happens.
|
||||
* @GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_NO_VALUE_CHECK: Do not check that after
|
||||
* setting the property, the value is the one we set.
|
||||
*
|
||||
* Since: 1.24
|
||||
*/
|
||||
typedef enum {
|
||||
GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_OPTIONAL = (1 << 0),
|
||||
GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_NO_VALUE_CHECK = (1 << 1),
|
||||
} GstValidateObjectSetPropertyFlags;
|
||||
|
||||
#endif /* __GST_VALIDATE_ENUMS_H__ */
|
||||
|
|
|
@ -1418,9 +1418,11 @@ _set_or_check_properties (GQuark field_id, const GValue * value,
|
|||
GstValidateAction *action;
|
||||
GstObject *obj = NULL;
|
||||
GParamSpec *paramspec = NULL;
|
||||
gboolean no_value_check = FALSE;
|
||||
GstValidateObjectSetPropertyFlags flags = 0;
|
||||
const gchar *field = g_quark_to_string (field_id);
|
||||
const gchar *unused_fields[] = { "__scenario__", "__action__", "__res__",
|
||||
"playback-time", "repeat", NULL
|
||||
"playback-time", "repeat", "no-value-check", NULL
|
||||
};
|
||||
|
||||
if (g_strv_contains (unused_fields, field))
|
||||
|
@ -1429,14 +1431,23 @@ _set_or_check_properties (GQuark field_id, const GValue * value,
|
|||
gst_structure_get (structure, "__scenario__", G_TYPE_POINTER, &scenario,
|
||||
"__action__", G_TYPE_POINTER, &action, NULL);
|
||||
|
||||
gst_structure_get_boolean (structure, "no-value-check", &no_value_check);
|
||||
|
||||
if (no_value_check) {
|
||||
flags |= GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_NO_VALUE_CHECK;
|
||||
}
|
||||
if (action->priv->optional)
|
||||
flags |= GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_OPTIONAL;
|
||||
|
||||
obj = _get_target_object_property (scenario, action, field, ¶mspec);
|
||||
if (!obj || !paramspec) {
|
||||
res = GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
|
||||
goto done;
|
||||
}
|
||||
if (gst_structure_has_name (action->structure, "set-properties"))
|
||||
res = gst_validate_object_set_property (GST_VALIDATE_REPORTER (scenario),
|
||||
G_OBJECT (obj), paramspec->name, value, action->priv->optional);
|
||||
res =
|
||||
gst_validate_object_set_property_full (GST_VALIDATE_REPORTER (scenario),
|
||||
G_OBJECT (obj), paramspec->name, value, flags);
|
||||
else
|
||||
res = _check_property (scenario, action, obj, paramspec->name, value);
|
||||
|
||||
|
|
|
@ -1032,10 +1032,20 @@ gst_validate_utils_get_clocktime (GstStructure * structure, const gchar * name,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_validate_object_set_property_full:
|
||||
* @reporter: The #GstValidateReporter to use to report errors
|
||||
* @object: The #GObject to set the property on
|
||||
* @property: The name of the property to set
|
||||
* @value: The value to set the property to
|
||||
* @flags: The #GstValidateObjectSetPropertyFlags to use
|
||||
*
|
||||
* Since: 1.24
|
||||
*/
|
||||
GstValidateActionReturn
|
||||
gst_validate_object_set_property (GstValidateReporter * reporter,
|
||||
gst_validate_object_set_property_full (GstValidateReporter * reporter,
|
||||
GObject * object, const gchar * property,
|
||||
const GValue * value, gboolean optional)
|
||||
const GValue * value, GstValidateObjectSetPropertyFlags flags)
|
||||
{
|
||||
GParamSpec *paramspec;
|
||||
GObjectClass *klass = G_OBJECT_GET_CLASS (object);
|
||||
|
@ -1044,7 +1054,7 @@ gst_validate_object_set_property (GstValidateReporter * reporter,
|
|||
|
||||
paramspec = g_object_class_find_property (klass, property);
|
||||
if (paramspec == NULL) {
|
||||
if (optional)
|
||||
if (!!(flags & GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_OPTIONAL))
|
||||
return TRUE;
|
||||
GST_ERROR ("Target doesn't have property %s", property);
|
||||
return FALSE;
|
||||
|
@ -1078,6 +1088,7 @@ gst_validate_object_set_property (GstValidateReporter * reporter,
|
|||
g_value_init (&nvalue, paramspec->value_type);
|
||||
g_object_get_property (object, property, &nvalue);
|
||||
|
||||
if (!(flags & GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_NO_VALUE_CHECK)) {
|
||||
if (gst_value_compare (&cvalue, &nvalue) != GST_VALUE_EQUAL) {
|
||||
gchar *nvalstr = gst_value_serialize (&nvalue);
|
||||
gchar *cvalstr = gst_value_serialize (&cvalue);
|
||||
|
@ -1089,6 +1100,7 @@ gst_validate_object_set_property (GstValidateReporter * reporter,
|
|||
g_free (nvalstr);
|
||||
g_free (cvalstr);
|
||||
}
|
||||
}
|
||||
|
||||
g_value_reset (&cvalue);
|
||||
g_value_reset (&nvalue);
|
||||
|
@ -1593,3 +1605,12 @@ gst_validate_fail_on_missing_plugin (void)
|
|||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GstValidateActionReturn
|
||||
gst_validate_object_set_property (GstValidateReporter * reporter,
|
||||
GObject * object,
|
||||
const gchar * property, const GValue * value, gboolean optional)
|
||||
{
|
||||
return gst_validate_object_set_property_full (reporter, object, property,
|
||||
value, optional ? GST_VALIDATE_OBJECT_SET_PROPERTY_FLAGS_OPTIONAL : 0);
|
||||
}
|
||||
|
|
|
@ -74,6 +74,14 @@ GstValidateActionReturn gst_validate_object_set_property (GstValidateReporter *
|
|||
const GValue * value,
|
||||
gboolean optional);
|
||||
|
||||
GST_VALIDATE_API
|
||||
GstValidateActionReturn gst_validate_object_set_property_full(GstValidateReporter * reporter,
|
||||
GObject * object,
|
||||
const gchar * property,
|
||||
const GValue * value,
|
||||
GstValidateObjectSetPropertyFlags flags);
|
||||
|
||||
|
||||
GST_VALIDATE_API
|
||||
void gst_validate_spin_on_fault_signals (void);
|
||||
|
||||
|
|
Loading…
Reference in a new issue