mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-28 20:05:38 +00:00
validate: Add an API to cleanly register action type from plugins
API: gst_validate_register_action_type_dynamic https://bugzilla.gnome.org/show_bug.cgi?id=743994
This commit is contained in:
parent
1194b313af
commit
441513e689
3 changed files with 83 additions and 6 deletions
|
@ -330,6 +330,7 @@ _execute_corrupt_socket_recv (GstValidateScenario * scenario,
|
|||
|
||||
socket_interposer_set_callback (&addr,
|
||||
(socket_interposer_callback) socket_callback_, action);
|
||||
|
||||
return GST_VALIDATE_EXECUTE_ACTION_ASYNC;
|
||||
}
|
||||
|
||||
|
@ -337,7 +338,8 @@ static gboolean
|
|||
socket_interposer_init (GstPlugin * plugin)
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
gst_validate_register_action_type ("corrupt-socket-recv", gst_plugin_get_name (plugin),
|
||||
gst_validate_register_action_type_dynamic (plugin, "corrupt-socket-recv",
|
||||
GST_RANK_PRIMARY,
|
||||
_execute_corrupt_socket_recv, ((GstValidateActionParameter[]) {
|
||||
{
|
||||
.name = "port",
|
||||
|
|
|
@ -2179,6 +2179,47 @@ gst_validate_register_action_type (const gchar * type_name,
|
|||
GstValidateExecuteAction function,
|
||||
GstValidateActionParameter * parameters,
|
||||
const gchar * description, GstValidateActionTypeFlags flags)
|
||||
{
|
||||
GstValidateActionType *type = gst_validate_register_action_type_dynamic (NULL,
|
||||
type_name, GST_RANK_NONE, function, parameters, description,
|
||||
flags);
|
||||
|
||||
g_free (type->implementer_namespace);
|
||||
type->implementer_namespace = g_strdup (implementer_namespace);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static void
|
||||
_free_action_types (GList * action_types)
|
||||
{
|
||||
g_list_free_full (action_types, (GDestroyNotify) gst_mini_object_unref);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_validate_register_action_type_dynamic:
|
||||
* @plugin: (allow-none): The #GstPlugin that register the action type,
|
||||
* or NULL for a static element.
|
||||
* @rank: The ranking of that implementation of the action type called
|
||||
* @type_name. If an action type has been registered with the same
|
||||
* name with a higher rank, the new implementation will not be used,
|
||||
* and the already registered action type is returned.
|
||||
* If the already registered implementation has a lower rank, the
|
||||
* new implementation will be used and returned.
|
||||
* @type_name: The name of the new action type to add
|
||||
* @function: (scope notified): The function to be called to execute the action
|
||||
* @parameters: (allow-none) (array zero-terminated=1) (element-type GstValidate.ActionParameter): The #GstValidateActionParameter usable as parameter of the type
|
||||
* @description: A description of the new type
|
||||
* @flags: The #GstValidateActionTypeFlags to be set on the new action type
|
||||
*
|
||||
* Returns: The newly created action type or the already registered action type
|
||||
* if it had a higher rank
|
||||
*/
|
||||
GstValidateActionType *
|
||||
gst_validate_register_action_type_dynamic (GstPlugin * plugin,
|
||||
const gchar * type_name, GstRank rank,
|
||||
GstValidateExecuteAction function, GstValidateActionParameter * parameters,
|
||||
const gchar * description, GstValidateActionTypeFlags flags)
|
||||
{
|
||||
GstValidateActionType *tmptype;
|
||||
GstValidateActionType *type = gst_validate_action_type_new ();
|
||||
|
@ -2201,17 +2242,40 @@ gst_validate_register_action_type (const gchar * type_name,
|
|||
|
||||
type->execute = function;
|
||||
type->name = g_strdup (type_name);
|
||||
type->implementer_namespace = g_strdup (implementer_namespace);
|
||||
if (plugin)
|
||||
type->implementer_namespace = g_strdup (gst_plugin_get_name (plugin));
|
||||
else
|
||||
type->implementer_namespace = g_strdup ("none");
|
||||
|
||||
type->description = g_strdup (description);
|
||||
type->flags = flags;
|
||||
type->action_struct_size = sizeof (GstValidateActionType);
|
||||
type->rank = rank;
|
||||
|
||||
if ((tmptype = _find_action_type (type_name))) {
|
||||
action_types = g_list_remove (action_types, tmptype);
|
||||
gst_mini_object_unref (GST_MINI_OBJECT (tmptype));
|
||||
if (tmptype->rank < rank) {
|
||||
action_types = g_list_remove (action_types, tmptype);
|
||||
gst_mini_object_unref (GST_MINI_OBJECT (tmptype));
|
||||
} else {
|
||||
gst_mini_object_unref (GST_MINI_OBJECT (type));
|
||||
|
||||
type = tmptype;
|
||||
}
|
||||
}
|
||||
|
||||
action_types = g_list_append (action_types, type);
|
||||
if (type != tmptype)
|
||||
action_types = g_list_append (action_types, type);
|
||||
|
||||
if (plugin) {
|
||||
GList *plugin_action_types = g_object_steal_data (G_OBJECT (plugin),
|
||||
"GstValidatePluginActionTypes");
|
||||
|
||||
plugin_action_types = g_list_prepend (plugin_action_types,
|
||||
gst_mini_object_ref (GST_MINI_OBJECT (type)));
|
||||
|
||||
g_object_set_data_full (G_OBJECT (plugin), "GstValidatePluginActionTypes",
|
||||
plugin_action_types, (GDestroyNotify) _free_action_types);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
|
|
@ -155,9 +155,10 @@ struct _GstValidateActionType
|
|||
GstValidateActionTypeFlags flags;
|
||||
|
||||
gsize action_struct_size;
|
||||
GstRank rank;
|
||||
|
||||
/*< private >*/
|
||||
gpointer _gst_reserved[GST_PADDING_LARGE - sizeof(gsize)];
|
||||
gpointer _gst_reserved[GST_PADDING_LARGE - sizeof(gsize) - sizeof (GstRank)];
|
||||
};
|
||||
|
||||
#define GST_TYPE_VALIDATE_ACTION_TYPE (gst_validate_action_type_get_type ())
|
||||
|
@ -245,6 +246,16 @@ gst_validate_register_action_type (const gchar *type_name,
|
|||
const gchar *description,
|
||||
GstValidateActionTypeFlags flags);
|
||||
|
||||
GstValidateActionType *
|
||||
gst_validate_register_action_type_dynamic (GstPlugin *plugin,
|
||||
const gchar * type_name,
|
||||
GstRank rank,
|
||||
GstValidateExecuteAction function,
|
||||
GstValidateActionParameter * parameters,
|
||||
const gchar * description,
|
||||
GstValidateActionTypeFlags flags);
|
||||
|
||||
|
||||
void
|
||||
gst_validate_action_type_set_action_struct_size (GstValidateActionType *type,
|
||||
gsize action_struct_size);
|
||||
|
|
Loading…
Reference in a new issue