2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstregistry.c: handle registry
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 #include "gst_private.h"
28 #include "gstregistrypool.h"
30 #include "gstfilter.h"
32 /* list of registries in the pool */
33 static GList *_gst_registry_pool = NULL;
35 /* list of plugins without a registry, like statically linked
37 static GList *_gst_registry_pool_plugins = NULL;
40 * gst_registry_pool_list:
42 * Get a list of all registries in the pool
44 * Returns: a Glist of GstRegistries, g_list_free after use.
47 gst_registry_pool_list (void)
49 return g_list_copy (_gst_registry_pool);
52 #ifndef GST_DISABLE_REGISTRY
54 gst_registry_compare_func (gconstpointer a, gconstpointer b)
56 return GST_REGISTRY (a)->priority - GST_REGISTRY (b)->priority;
60 * gst_registry_pool_add:
61 * @registry: the registry to add
62 * @priority: the priority of the registry
64 * Add the registry to the pool with the given priority.
67 gst_registry_pool_add (GstRegistry * registry, guint priority)
69 g_return_if_fail (GST_IS_REGISTRY (registry));
71 registry->priority = priority;
74 g_list_insert_sorted (_gst_registry_pool, registry,
75 gst_registry_compare_func);
79 * gst_registry_pool_remove:
80 * @registry: the registry to remove
82 * Remove the registry from the pool.
85 gst_registry_pool_remove (GstRegistry * registry)
87 g_return_if_fail (GST_IS_REGISTRY (registry));
89 _gst_registry_pool = g_list_remove (_gst_registry_pool, registry);
91 #endif /* GST_DISABLE_REGISTRY */
94 * gst_registry_pool_add_plugin:
95 * @plugin: the plugin to add
97 * Add the plugin to the global pool of plugins.
100 gst_registry_pool_add_plugin (GstPlugin * plugin)
102 _gst_registry_pool_plugins =
103 g_list_prepend (_gst_registry_pool_plugins, plugin);
106 #ifndef GST_DISABLE_REGISTRY
108 _registry_load_func (GstRegistry * registry, gpointer user_data)
110 if (!(registry->flags & GST_REGISTRY_DELAYED_LOADING)) {
111 gst_registry_load (registry);
114 #endif /* GST_DISABLE_REGISTRY */
117 * gst_registry_pool_load_all:
119 * Load all the registries in the pool. Registries with the
120 * GST_REGISTRY_DELAYED_LOADING will not be loaded.
123 gst_registry_pool_load_all (void)
125 #ifndef GST_DISABLE_REGISTRY
126 g_list_foreach (_gst_registry_pool, (GFunc) _registry_load_func, NULL);
127 #endif /* GST_DISABLE_REGISTRY */
131 * gst_registry_pool_plugin_list:
133 * Get a list of all plugins in the pool.
135 * Returns: a GList of plugins, g_list_free after use.
138 gst_registry_pool_plugin_list (void)
140 return gst_registry_pool_plugin_filter (NULL, FALSE, NULL);
144 * gst_registry_pool_plugin_filter:
145 * @filter: the filter to use
146 * @first: only return first match
147 * @user_data: user data passed to the filter function
149 * Runs a filter against all plugins in all registries and returns a GList with
150 * the results. If the first flag is set, only the first match is
151 * returned (as a list with a single object).
153 * Returns: a GList of plugins, g_list_free after use.
156 gst_registry_pool_plugin_filter (GstPluginFilter filter, gboolean first,
159 GList *result = NULL;
162 #ifndef GST_DISABLE_REGISTRY
165 walk = _gst_registry_pool;
168 GstRegistry *registry = GST_REGISTRY (walk->data);
170 temp = gst_registry_plugin_filter (registry, filter, first, user_data);
174 result = g_list_concat (result, temp);
176 walk = g_list_next (walk);
178 #endif /* GST_DISABLE_REGISTRY */
181 gst_filter_run (_gst_registry_pool_plugins, (GstFilterFunc) filter, first,
184 result = g_list_concat (result, temp);
190 * gst_registry_pool_feature_list:
191 * @type: the type of the features to list.
193 * Get a list of all pluginfeatures of the given type in the pool.
195 * Returns: a GList of pluginfeatures, g_list_free after use.
198 gst_registry_pool_feature_list (GType type)
200 GstTypeNameData data;
205 return gst_registry_pool_feature_filter (
206 (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
211 * gst_registry_pool_feature_filter:
212 * @filter: the filter to apply to the feature list
213 * @first: return the first matching feature
214 * @user_data: data passed to the filter function
216 * Apply the filter function to all features and return a list
217 * of those features that satisfy the filter. If the first flag
218 * is TRUE, only the first match is returned in a GList with
221 * Returns: a GList of pluginfeatures, g_list_free after use.
224 gst_registry_pool_feature_filter (GstPluginFeatureFilter filter, gboolean first,
227 GList *result = NULL;
230 #ifndef GST_DISABLE_REGISTRY
233 walk = _gst_registry_pool;
236 GstRegistry *registry = GST_REGISTRY (walk->data);
238 temp = gst_registry_feature_filter (registry, filter, first, user_data);
242 result = g_list_concat (result, temp);
244 walk = g_list_next (walk);
246 #endif /* GST_DISABLE_REGISTRY */
249 gst_plugin_list_feature_filter (_gst_registry_pool_plugins, filter, first,
252 result = g_list_concat (result, temp);
258 * gst_registry_pool_find_plugin:
259 * @name: the name of the plugin to find
261 * Get the named plugin from the registry pool
263 * Returns: The plugin with the given name or NULL if the plugin
267 gst_registry_pool_find_plugin (const gchar * name)
269 GstPlugin *result = NULL;
272 g_return_val_if_fail (name != NULL, NULL);
275 gst_registry_pool_plugin_filter ((GstPluginFilter) gst_plugin_name_filter,
276 TRUE, (gpointer) name);
279 result = GST_PLUGIN (walk->data);
287 * gst_registry_pool_find_feature:
288 * @name: the name of the pluginfeature to find
289 * @type: the type of the pluginfeature to find
291 * Get the pluginfeature with the given name and type from the pool of
294 * Returns: A pluginfeature with the given name and type or NULL if the feature
298 gst_registry_pool_find_feature (const gchar * name, GType type)
300 GstPluginFeature *result = NULL;
302 GstTypeNameData data;
304 g_return_val_if_fail (name != NULL, NULL);
310 gst_registry_pool_feature_filter ((GstPluginFeatureFilter)
311 gst_plugin_feature_type_name_filter, TRUE, &data);
314 result = GST_PLUGIN_FEATURE (walk->data);
322 * gst_registry_pool_get_prefered:
323 * @flags: The flags for the prefered registry
325 * Get the prefered registry with the given flags
327 * Returns: The registry with the flags.
330 gst_registry_pool_get_prefered (GstRegistryFlags flags)
332 #ifndef GST_DISABLE_REGISTRY
333 GList *walk = _gst_registry_pool;
336 GstRegistry *registry = GST_REGISTRY (walk->data);
338 if (registry->flags & flags)
341 walk = g_list_next (walk);
343 #endif /* GST_DISABLE_REGISTRY */