mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 16:50:47 +00:00
gstplugin: Handle static plugins in gst_plugin_load_by_name()
gst_plugin_load_by_name() assumed a plugin has a filename, which isn't true for static plugins, leading to criticals. If a plugin is already loaded, just return the loaded plugin, which makes it work for static plugins as well as saving a moment for already-loaded dynamic plugins. Add locking in gst_plugin_is_loaded(), as a plugin may be still being loaded in another thread. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3552>
This commit is contained in:
parent
cbab7ffefb
commit
0791a73a04
1 changed files with 28 additions and 15 deletions
|
@ -1183,8 +1183,16 @@ gboolean
|
|||
gst_plugin_is_loaded (GstPlugin * plugin)
|
||||
{
|
||||
g_return_val_if_fail (plugin != NULL, FALSE);
|
||||
gboolean ret;
|
||||
|
||||
return (plugin->module != NULL || plugin->filename == NULL);
|
||||
if (plugin->filename == NULL)
|
||||
return TRUE; /* Static plugin */
|
||||
|
||||
g_mutex_lock (&gst_plugin_loading_mutex);
|
||||
ret = (plugin->module != NULL);
|
||||
g_mutex_unlock (&gst_plugin_loading_mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1406,7 +1414,16 @@ gst_plugin_load_by_name (const gchar * name)
|
|||
|
||||
GST_DEBUG ("looking up plugin %s in default registry", name);
|
||||
plugin = gst_registry_find_plugin (gst_registry_get (), name);
|
||||
if (plugin) {
|
||||
if (plugin == NULL) {
|
||||
GST_DEBUG ("Could not find plugin %s in registry", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (gst_plugin_is_loaded (plugin)) {
|
||||
GST_DEBUG ("plugin %s already loaded", name);
|
||||
return plugin;
|
||||
}
|
||||
|
||||
GST_DEBUG ("loading plugin %s from file %s", name, plugin->filename);
|
||||
newplugin = gst_plugin_load_file (plugin->filename, &error);
|
||||
gst_object_unref (plugin);
|
||||
|
@ -1418,10 +1435,6 @@ gst_plugin_load_by_name (const gchar * name)
|
|||
}
|
||||
/* newplugin was reffed by load_file */
|
||||
return newplugin;
|
||||
}
|
||||
|
||||
GST_DEBUG ("Could not find plugin %s in registry", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue