/**
* gst_registry_add_plugin:
* @registry: the registry to add the plugin to
* @plugin: (transfer full): the plugin to add
*
* Add the plugin to the registry. The plugin-added signal will be emitted.
* This function will sink @plugin.
*
* Returns: %TRUE on success.
*
* MT safe.
*/
gboolean
gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin)
{
GstPlugin *existing_plugin;
g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
g_return_val_if_fail (GST_IS_PLUGIN (plugin), FALSE);
GST_OBJECT_LOCK (registry);
if (G_LIKELY (plugin->basename)) {
/* we have a basename, see if we find the plugin */
existing_plugin =
gst_registry_lookup_bn_locked (registry, plugin->basename);
if (existing_plugin) {
GST_DEBUG_OBJECT (registry,
"Replacing existing plugin \"%s\" %p with new plugin %p for filename \"%s\"",
GST_STR_NULL (existing_plugin->filename), existing_plugin, plugin,
GST_STR_NULL (plugin->filename));
/* If the new plugin is blacklisted and the existing one isn't cached, do not
* accept if it's from a different location than the existing one */
if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED) &&
strcmp (plugin->filename, existing_plugin->filename)) {
GST_WARNING_OBJECT (registry,
"Not replacing plugin because new one (%s) is blacklisted but for a different location than existing one (%s)",
plugin->filename, existing_plugin->filename);
gst_object_unref (plugin);
GST_OBJECT_UNLOCK (registry);
return FALSE;
}
registry->priv->plugins =
g_list_remove (registry->priv->plugins, existing_plugin);
if (G_LIKELY (existing_plugin->basename))
g_hash_table_remove (registry->priv->basename_hash,
existing_plugin->basename);
gst_object_unref (existing_plugin);
}
}
GST_DEBUG_OBJECT (registry, "adding plugin %p for filename \"%s\"",
plugin, GST_STR_NULL (plugin->filename));
registry->priv->plugins = g_list_prepend (registry->priv->plugins, plugin);
if (G_LIKELY (plugin->basename))
g_hash_table_replace (registry->priv->basename_hash, plugin->basename,
plugin);
gst_object_ref_sink (plugin);
GST_OBJECT_UNLOCK (registry);
GST_LOG_OBJECT (registry, "emitting plugin-added for filename \"%s\"",
GST_STR_NULL (plugin->filename));
g_signal_emit (registry, gst_registry_signals[PLUGIN_ADDED], 0, plugin);
return TRUE;
}
1.先查看是否有已存在的插件,如果有且当前插件符合要求,移除现有插件,而且清理hash,解除引用
registry->priv->plugins =
g_list_remove (registry->priv->plugins, existing_plugin);
if (G_LIKELY (existing_plugin->basename))
g_hash_table_remove (registry->priv->basename_hash,
existing_plugin->basename);
gst_object_unref (existing_plugin);
2.把当前plugin插入registry->priv->plugins,并添加到hash中
registry->priv->plugins = g_list_prepend (registry->priv->plugins, plugin);
if (G_LIKELY (plugin->basename))
g_hash_table_replace (registry->priv->basename_hash, plugin->basename,
plugin);