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;
34 /* list of plugins without a registry, like statically linked
36 static GList *_gst_registry_pool_plugins = NULL;
39 * gst_registry_pool_list:
41 * Get a list of all registries in the pool
43 * Returns: a Glist of GstRegistries, g_list_free after use.
46 gst_registry_pool_list (void)
48 return g_list_copy (_gst_registry_pool);
51 #ifndef GST_DISABLE_REGISTRY
53 gst_registry_compare_func (gconstpointer a, gconstpointer b)
55 return GST_REGISTRY (a)->priority - GST_REGISTRY (b)->priority;
59 * gst_registry_pool_add:
60 * @registry: the registry to add
61 * @priority: the priority of the registry
63 * Add the registry to the pool with the given priority.
66 gst_registry_pool_add (GstRegistry *registry, guint priority)
68 g_return_if_fail (GST_IS_REGISTRY (registry));
70 registry->priority = priority;
72 _gst_registry_pool = g_list_insert_sorted (_gst_registry_pool, registry, gst_registry_compare_func);
76 * gst_registry_pool_remove:
77 * @registry: the registry to remove
79 * Remove the registry from the pool.
82 gst_registry_pool_remove (GstRegistry *registry)
84 g_return_if_fail (GST_IS_REGISTRY (registry));
86 _gst_registry_pool = g_list_remove (_gst_registry_pool, registry);
88 #endif /* GST_DISABLE_REGISTRY */
91 * gst_registry_pool_add_plugin:
92 * @plugin: the plugin to add
94 * Add the plugin to the global pool of plugins.
97 gst_registry_pool_add_plugin (GstPlugin *plugin)
99 _gst_registry_pool_plugins = g_list_prepend (_gst_registry_pool_plugins, plugin);
102 #ifndef GST_DISABLE_REGISTRY
104 _registry_load_func (GstRegistry *registry, gpointer user_data)
106 if (!(registry->flags & GST_REGISTRY_DELAYED_LOADING)) {
107 gst_registry_load (registry);
110 #endif /* GST_DISABLE_REGISTRY */
113 * gst_registry_pool_load_all:
115 * Load all the registries in the pool. Registries with the
116 * GST_REGISTRY_DELAYED_LOADING will not be loaded.
119 gst_registry_pool_load_all (void)
121 #ifndef GST_DISABLE_REGISTRY
122 g_list_foreach (_gst_registry_pool, (GFunc) _registry_load_func, NULL);
123 #endif /* GST_DISABLE_REGISTRY */
127 * gst_registry_pool_plugin_list:
129 * Get a list of all plugins in the pool.
131 * Returns: a GList of plugins, g_list_free after use.
134 gst_registry_pool_plugin_list (void)
136 return gst_registry_pool_plugin_filter (NULL, FALSE, NULL);
140 * gst_registry_pool_plugin_filter:
141 * @filter: the filter to use
142 * @first: only return first match
143 * @user_data: user data passed to the filter function
145 * Runs a filter against all plugins in all registries and returns a GList with
146 * the results. If the first flag is set, only the first match is
147 * returned (as a list with a single object).
149 * Returns: a GList of plugins, g_list_free after use.
152 gst_registry_pool_plugin_filter (GstPluginFilter filter, gboolean first, gpointer user_data)
154 GList *result = NULL;
157 #ifndef GST_DISABLE_REGISTRY
158 walk = _gst_registry_pool;
161 GstRegistry *registry = GST_REGISTRY (walk->data);
163 temp = gst_registry_plugin_filter (registry, filter, first, user_data);
167 result = g_list_concat (result, temp);
169 walk = g_list_next (walk);
171 #endif /* GST_DISABLE_REGISTRY */
173 temp = gst_filter_run (_gst_registry_pool_plugins, (GstFilterFunc) filter, first, user_data);
175 result = g_list_concat (result, temp);
181 * gst_registry_pool_feature_list:
182 * @type: the type of the features to list.
184 * Get a list of all pluginfeatures of the given type in the pool.
186 * Returns: a GList of pluginfeatures, g_list_free after use.
189 gst_registry_pool_feature_list (GType type)
191 GstTypeNameData data;
196 return gst_registry_pool_feature_filter (
197 (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
203 * gst_registry_pool_feature_filter:
204 * @filter: the filter to apply to the feature list
205 * @first: return the first matching feature
206 * @user_data: data passed to the filter function
208 * Apply the filter function to all features and return a list
209 * of those features that satisfy the filter. If the first flag
210 * is TRUE, only the first match is returned in a GList with
213 * Returns: a GList of pluginfeatures, g_list_free after use.
216 gst_registry_pool_feature_filter (GstPluginFeatureFilter filter, gboolean first, gpointer user_data)
218 GList *result = NULL;
221 #ifndef GST_DISABLE_REGISTRY
222 walk = _gst_registry_pool;
225 GstRegistry *registry = GST_REGISTRY (walk->data);
227 temp = gst_registry_feature_filter (registry, filter, first, user_data);
231 result = g_list_concat (result, temp);
233 walk = g_list_next (walk);
235 #endif /* GST_DISABLE_REGISTRY */
237 temp = gst_plugin_list_feature_filter (_gst_registry_pool_plugins, filter, first, user_data);
239 result = g_list_concat (result, temp);
245 * gst_registry_pool_find_plugin:
246 * @name: the name of the plugin to find
248 * Get the named plugin from the registry pool
250 * Returns: The plugin with the given name or NULL if the plugin
254 gst_registry_pool_find_plugin (const gchar *name)
256 GstPlugin *result = NULL;
259 g_return_val_if_fail (name != NULL, NULL);
261 walk = gst_registry_pool_plugin_filter ((GstPluginFilter) gst_plugin_name_filter, TRUE, (gpointer) name);
264 result = GST_PLUGIN (walk->data);
272 * gst_registry_pool_find_feature:
273 * @name: the name of the pluginfeature to find
274 * @type: the type of the pluginfeature to find
276 * Get the pluginfeature with the given name and type from the pool of
279 * Returns: A pluginfeature with the given name and type or NULL if the feature
283 gst_registry_pool_find_feature (const gchar *name, GType type)
285 GstPluginFeature *result = NULL;
287 GstTypeNameData data;
289 g_return_val_if_fail (name != NULL, NULL);
294 walk = gst_registry_pool_feature_filter ((GstPluginFeatureFilter) gst_plugin_feature_type_name_filter,
298 result = GST_PLUGIN_FEATURE (walk->data);
306 * gst_registry_pool_get_prefered:
307 * @flags: The flags for the prefered registry
309 * Get the prefered registry with the given flags
311 * Returns: The registry with the flags.
314 gst_registry_pool_get_prefered (GstRegistryFlags flags)
316 #ifndef GST_DISABLE_REGISTRY
317 GList *walk = _gst_registry_pool;
320 GstRegistry *registry = GST_REGISTRY (walk->data);
322 if (registry->flags & flags)
325 walk = g_list_next (walk);
327 #endif /* GST_DISABLE_REGISTRY */