validate: Use an actual GstRegistry to track our plugins

Keeping everything internal for now

https://bugzilla.gnome.org/show_bug.cgi?id=743994
This commit is contained in:
Thibault Saunier 2015-02-04 14:50:14 +01:00
parent ed43ab1509
commit 5c90a06645

View file

@ -40,62 +40,34 @@
GST_DEBUG_CATEGORY (gstvalidate_debug); GST_DEBUG_CATEGORY (gstvalidate_debug);
static gboolean static GMutex _gst_validate_registry_mutex;
gst_validate_scan_path_for_plugins (const gchar * path) static GstRegistry *_gst_validate_registry_default = NULL;
static GstRegistry *
gst_validate_registry_get (void)
{ {
GDir *dir; GstRegistry *registry;
const gchar *dirent;
gchar *filename;
GstPlugin *plugin;
gboolean changed = FALSE;
dir = g_dir_open (path, 0, NULL); g_mutex_lock (&_gst_validate_registry_mutex);
if (!dir) if (G_UNLIKELY (!_gst_validate_registry_default)) {
return FALSE; _gst_validate_registry_default = g_object_newv (GST_TYPE_REGISTRY, 0, NULL);
gst_object_ref_sink (GST_OBJECT_CAST (_gst_validate_registry_default));
while ((dirent = g_dir_read_name (dir))) {
GStatBuf file_status;
filename = g_build_filename (path, dirent, NULL);
if (g_stat (filename, &file_status) < 0) {
/* Plugin will be removed from cache after the scan completes if it
* is still marked 'cached' */
g_free (filename);
continue;
} }
registry = _gst_validate_registry_default;
g_mutex_unlock (&_gst_validate_registry_mutex);
if (!(file_status.st_mode & S_IFREG)) { return registry;
g_free (filename);
continue;
} }
if (!g_str_has_suffix (dirent, G_MODULE_SUFFIX)) {
GST_TRACE ("extension is not recognized as module file, ignoring file %s",
filename);
g_free (filename);
continue;
}
plugin = gst_plugin_load_file (filename, NULL);
if (plugin) {
GST_DEBUG ("Plugin %s loaded", filename);
gst_object_unref (plugin);
}
g_free (filename);
}
g_dir_close (dir);
return changed;
}
static void static void
gst_validate_init_plugins (void) gst_validate_init_plugins (void)
{ {
GstRegistry *registry;
const gchar *plugin_path; const gchar *plugin_path;
gst_registry_fork_set_enabled (FALSE);
registry = gst_validate_registry_get ();
plugin_path = g_getenv ("GST_VALIDATE_PLUGIN_PATH"); plugin_path = g_getenv ("GST_VALIDATE_PLUGIN_PATH");
if (plugin_path) { if (plugin_path) {
char **list; char **list;
@ -104,7 +76,7 @@ gst_validate_init_plugins (void)
GST_DEBUG ("GST_VALIDATE_PLUGIN_PATH set to %s", plugin_path); GST_DEBUG ("GST_VALIDATE_PLUGIN_PATH set to %s", plugin_path);
list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0); list = g_strsplit (plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
for (i = 0; list[i]; i++) { for (i = 0; list[i]; i++) {
gst_validate_scan_path_for_plugins (list[i]); gst_registry_scan_path (registry, list[i]);
} }
g_strfreev (list); g_strfreev (list);
} else { } else {
@ -120,7 +92,7 @@ gst_validate_init_plugins (void)
"gstreamer-" GST_API_VERSION, "plugins", NULL); "gstreamer-" GST_API_VERSION, "plugins", NULL);
GST_DEBUG ("scanning home plugins %s", home_plugins); GST_DEBUG ("scanning home plugins %s", home_plugins);
gst_validate_scan_path_for_plugins (home_plugins); gst_registry_scan_path (registry, home_plugins);
g_free (home_plugins); g_free (home_plugins);
/* add the main (installed) library path */ /* add the main (installed) library path */
@ -141,15 +113,16 @@ gst_validate_init_plugins (void)
"lib", "gstreamer-" GST_API_VERSION, NULL); "lib", "gstreamer-" GST_API_VERSION, NULL);
GST_DEBUG ("scanning DLL dir %s", dir); GST_DEBUG ("scanning DLL dir %s", dir);
gst_validate_scan_path_for_plugins (dir); gst_registry_scan_path (registry, dir);
g_free (dir); g_free (dir);
g_free (base_dir); g_free (base_dir);
} }
#else #else
gst_validate_scan_path_for_plugins (PLUGINDIR); gst_registry_scan_path (registry, PLUGINDIR);
#endif #endif
} }
gst_registry_fork_set_enabled (TRUE);
} }
/** /**