1 | /* GStreamer |
---|
2 | * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu> |
---|
3 | * 2000 Wim Taymans <wtay@chello.be> |
---|
4 | * |
---|
5 | * gstregistry.c: handle registry |
---|
6 | * |
---|
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. |
---|
11 | * |
---|
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. |
---|
16 | * |
---|
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. |
---|
21 | */ |
---|
22 | |
---|
23 | #include <string.h> |
---|
24 | |
---|
25 | #include "gst_private.h" |
---|
26 | |
---|
27 | #include "gstinfo.h" |
---|
28 | #include "gstregistrypool.h" |
---|
29 | #include "gstfilter.h" |
---|
30 | |
---|
31 | /* list of registries in the pool */ |
---|
32 | static GList *_gst_registry_pool = NULL; |
---|
33 | |
---|
34 | /* list of plugins without a registry, like statically linked |
---|
35 | * plugins */ |
---|
36 | static GList *_gst_registry_pool_plugins = NULL; |
---|
37 | |
---|
38 | /** |
---|
39 | * gst_registry_pool_list: |
---|
40 | * |
---|
41 | * Get a list of all registries in the pool |
---|
42 | * |
---|
43 | * Returns: a Glist of GstRegistries, g_list_free after use. |
---|
44 | */ |
---|
45 | GList * |
---|
46 | gst_registry_pool_list (void) |
---|
47 | { |
---|
48 | return g_list_copy (_gst_registry_pool); |
---|
49 | } |
---|
50 | |
---|
51 | #ifndef GST_DISABLE_REGISTRY |
---|
52 | static gint |
---|
53 | gst_registry_compare_func (gconstpointer a, gconstpointer b) |
---|
54 | { |
---|
55 | return GST_REGISTRY (a)->priority - GST_REGISTRY (b)->priority; |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * gst_registry_pool_add: |
---|
60 | * @registry: the registry to add |
---|
61 | * @priority: the priority of the registry |
---|
62 | * |
---|
63 | * Add the registry to the pool with the given priority. |
---|
64 | */ |
---|
65 | void |
---|
66 | gst_registry_pool_add (GstRegistry * registry, guint priority) |
---|
67 | { |
---|
68 | g_return_if_fail (GST_IS_REGISTRY (registry)); |
---|
69 | |
---|
70 | registry->priority = priority; |
---|
71 | |
---|
72 | _gst_registry_pool = |
---|
73 | g_list_insert_sorted (_gst_registry_pool, registry, |
---|
74 | gst_registry_compare_func); |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | * gst_registry_pool_remove: |
---|
79 | * @registry: the registry to remove |
---|
80 | * |
---|
81 | * Remove the registry from the pool. |
---|
82 | */ |
---|
83 | void |
---|
84 | gst_registry_pool_remove (GstRegistry * registry) |
---|
85 | { |
---|
86 | g_return_if_fail (GST_IS_REGISTRY (registry)); |
---|
87 | |
---|
88 | _gst_registry_pool = g_list_remove (_gst_registry_pool, registry); |
---|
89 | } |
---|
90 | #endif /* GST_DISABLE_REGISTRY */ |
---|
91 | |
---|
92 | /** |
---|
93 | * gst_registry_pool_add_plugin: |
---|
94 | * @plugin: the plugin to add |
---|
95 | * |
---|
96 | * Add the plugin to the global pool of plugins. |
---|
97 | */ |
---|
98 | void |
---|
99 | gst_registry_pool_add_plugin (GstPlugin * plugin) |
---|
100 | { |
---|
101 | _gst_registry_pool_plugins = |
---|
102 | g_list_prepend (_gst_registry_pool_plugins, plugin); |
---|
103 | } |
---|
104 | |
---|
105 | #ifndef GST_DISABLE_REGISTRY |
---|
106 | static void |
---|
107 | _registry_load_func (GstRegistry * registry, gpointer user_data) |
---|
108 | { |
---|
109 | if (!(registry->flags & GST_REGISTRY_DELAYED_LOADING)) { |
---|
110 | gst_registry_load (registry); |
---|
111 | } |
---|
112 | } |
---|
113 | #endif /* GST_DISABLE_REGISTRY */ |
---|
114 | |
---|
115 | /** |
---|
116 | * gst_registry_pool_load_all: |
---|
117 | * |
---|
118 | * Load all the registries in the pool. Registries with the |
---|
119 | * GST_REGISTRY_DELAYED_LOADING will not be loaded. |
---|
120 | */ |
---|
121 | void |
---|
122 | gst_registry_pool_load_all (void) |
---|
123 | { |
---|
124 | #ifndef GST_DISABLE_REGISTRY |
---|
125 | g_list_foreach (_gst_registry_pool, (GFunc) _registry_load_func, NULL); |
---|
126 | #endif /* GST_DISABLE_REGISTRY */ |
---|
127 | } |
---|
128 | |
---|
129 | /** |
---|
130 | * gst_registry_pool_plugin_list: |
---|
131 | * |
---|
132 | * Get a list of all plugins in the pool. |
---|
133 | * |
---|
134 | * Returns: a GList of plugins, g_list_free after use. |
---|
135 | */ |
---|
136 | GList * |
---|
137 | gst_registry_pool_plugin_list (void) |
---|
138 | { |
---|
139 | return gst_registry_pool_plugin_filter (NULL, FALSE, NULL); |
---|
140 | } |
---|
141 | |
---|
142 | /** |
---|
143 | * gst_registry_pool_plugin_filter: |
---|
144 | * @filter: the filter to use |
---|
145 | * @first: only return first match |
---|
146 | * @user_data: user data passed to the filter function |
---|
147 | * |
---|
148 | * Runs a filter against all plugins in all registries and returns a GList with |
---|
149 | * the results. If the first flag is set, only the first match is |
---|
150 | * returned (as a list with a single object). |
---|
151 | * |
---|
152 | * Returns: a GList of plugins, g_list_free after use. |
---|
153 | */ |
---|
154 | GList * |
---|
155 | gst_registry_pool_plugin_filter (GstPluginFilter filter, gboolean first, |
---|
156 | gpointer user_data) |
---|
157 | { |
---|
158 | GList *result = NULL; |
---|
159 | GList *temp; |
---|
160 | |
---|
161 | #ifndef GST_DISABLE_REGISTRY |
---|
162 | GList *walk; |
---|
163 | |
---|
164 | walk = _gst_registry_pool; |
---|
165 | |
---|
166 | while (walk) { |
---|
167 | GstRegistry *registry = GST_REGISTRY (walk->data); |
---|
168 | |
---|
169 | temp = gst_registry_plugin_filter (registry, filter, first, user_data); |
---|
170 | if (temp && first) |
---|
171 | return temp; |
---|
172 | |
---|
173 | result = g_list_concat (result, temp); |
---|
174 | |
---|
175 | walk = g_list_next (walk); |
---|
176 | } |
---|
177 | #endif /* GST_DISABLE_REGISTRY */ |
---|
178 | |
---|
179 | temp = |
---|
180 | gst_filter_run (_gst_registry_pool_plugins, (GstFilterFunc) filter, first, |
---|
181 | user_data); |
---|
182 | |
---|
183 | result = g_list_concat (result, temp); |
---|
184 | |
---|
185 | return result; |
---|
186 | } |
---|
187 | |
---|
188 | /** |
---|
189 | * gst_registry_pool_feature_list: |
---|
190 | * @type: the type of the features to list. |
---|
191 | * |
---|
192 | * Get a list of all pluginfeatures of the given type in the pool. |
---|
193 | * |
---|
194 | * Returns: a GList of pluginfeatures, g_list_free after use. |
---|
195 | */ |
---|
196 | GList * |
---|
197 | gst_registry_pool_feature_list (GType type) |
---|
198 | { |
---|
199 | GstTypeNameData data; |
---|
200 | |
---|
201 | data.name = NULL; |
---|
202 | data.type = type; |
---|
203 | |
---|
204 | return gst_registry_pool_feature_filter ( |
---|
205 | (GstPluginFeatureFilter) gst_plugin_feature_type_name_filter, |
---|
206 | FALSE, &data); |
---|
207 | } |
---|
208 | |
---|
209 | /** |
---|
210 | * gst_registry_pool_feature_filter: |
---|
211 | * @filter: the filter to apply to the feature list |
---|
212 | * @first: return the first matching feature |
---|
213 | * @user_data: data passed to the filter function |
---|
214 | * |
---|
215 | * Apply the filter function to all features and return a list |
---|
216 | * of those features that satisfy the filter. If the first flag |
---|
217 | * is TRUE, only the first match is returned in a GList with |
---|
218 | * one element. |
---|
219 | * |
---|
220 | * Returns: a GList of pluginfeatures, g_list_free after use. |
---|
221 | */ |
---|
222 | GList * |
---|
223 | gst_registry_pool_feature_filter (GstPluginFeatureFilter filter, gboolean first, |
---|
224 | gpointer user_data) |
---|
225 | { |
---|
226 | GList *result = NULL; |
---|
227 | GList *temp; |
---|
228 | |
---|
229 | #ifndef GST_DISABLE_REGISTRY |
---|
230 | GList *walk; |
---|
231 | |
---|
232 | walk = _gst_registry_pool; |
---|
233 | |
---|
234 | while (walk) { |
---|
235 | GstRegistry *registry = GST_REGISTRY (walk->data); |
---|
236 | |
---|
237 | temp = gst_registry_feature_filter (registry, filter, first, user_data); |
---|
238 | if (temp && first) |
---|
239 | return temp; |
---|
240 | |
---|
241 | result = g_list_concat (result, temp); |
---|
242 | |
---|
243 | walk = g_list_next (walk); |
---|
244 | } |
---|
245 | #endif /* GST_DISABLE_REGISTRY */ |
---|
246 | |
---|
247 | temp = |
---|
248 | gst_plugin_list_feature_filter (_gst_registry_pool_plugins, filter, first, |
---|
249 | user_data); |
---|
250 | |
---|
251 | result = g_list_concat (result, temp); |
---|
252 | |
---|
253 | return result; |
---|
254 | } |
---|
255 | |
---|
256 | /** |
---|
257 | * gst_registry_pool_find_plugin: |
---|
258 | * @name: the name of the plugin to find |
---|
259 | * |
---|
260 | * Get the named plugin from the registry pool |
---|
261 | * |
---|
262 | * Returns: The plugin with the given name or NULL if the plugin |
---|
263 | * was not found. |
---|
264 | */ |
---|
265 | GstPlugin * |
---|
266 | gst_registry_pool_find_plugin (const gchar * name) |
---|
267 | { |
---|
268 | GstPlugin *result = NULL; |
---|
269 | GList *walk; |
---|
270 | |
---|
271 | g_return_val_if_fail (name != NULL, NULL); |
---|
272 | |
---|
273 | walk = |
---|
274 | gst_registry_pool_plugin_filter ((GstPluginFilter) gst_plugin_name_filter, |
---|
275 | TRUE, (gpointer) name); |
---|
276 | |
---|
277 | if (walk) |
---|
278 | result = GST_PLUGIN (walk->data); |
---|
279 | |
---|
280 | g_list_free (walk); |
---|
281 | |
---|
282 | return result; |
---|
283 | } |
---|
284 | |
---|
285 | /** |
---|
286 | * gst_registry_pool_find_feature: |
---|
287 | * @name: the name of the pluginfeature to find |
---|
288 | * @type: the type of the pluginfeature to find |
---|
289 | * |
---|
290 | * Get the pluginfeature with the given name and type from the pool of |
---|
291 | * registries. |
---|
292 | * |
---|
293 | * Returns: A pluginfeature with the given name and type or NULL if the feature |
---|
294 | * was not found. |
---|
295 | */ |
---|
296 | GstPluginFeature * |
---|
297 | gst_registry_pool_find_feature (const gchar * name, GType type) |
---|
298 | { |
---|
299 | GstPluginFeature *result = NULL; |
---|
300 | GList *walk; |
---|
301 | GstTypeNameData data; |
---|
302 | |
---|
303 | g_return_val_if_fail (name != NULL, NULL); |
---|
304 | |
---|
305 | data.type = type; |
---|
306 | data.name = name; |
---|
307 | |
---|
308 | walk = gst_registry_pool_feature_filter ((GstPluginFeatureFilter) |
---|
309 | gst_plugin_feature_type_name_filter, TRUE, &data); |
---|
310 | |
---|
311 | if (walk) |
---|
312 | result = GST_PLUGIN_FEATURE (walk->data); |
---|
313 | |
---|
314 | g_list_free (walk); |
---|
315 | |
---|
316 | return result; |
---|
317 | } |
---|
318 | |
---|
319 | /** |
---|
320 | * gst_registry_pool_get_prefered: |
---|
321 | * @flags: The flags for the prefered registry |
---|
322 | * |
---|
323 | * Get the prefered registry with the given flags |
---|
324 | * |
---|
325 | * Returns: The registry with the flags. |
---|
326 | */ |
---|
327 | GstRegistry * |
---|
328 | gst_registry_pool_get_prefered (GstRegistryFlags flags) |
---|
329 | { |
---|
330 | #ifndef GST_DISABLE_REGISTRY |
---|
331 | GList *walk = _gst_registry_pool; |
---|
332 | |
---|
333 | while (walk) { |
---|
334 | GstRegistry *registry = GST_REGISTRY (walk->data); |
---|
335 | |
---|
336 | if (registry->flags & flags) |
---|
337 | return registry; |
---|
338 | |
---|
339 | walk = g_list_next (walk); |
---|
340 | } |
---|
341 | #endif /* GST_DISABLE_REGISTRY */ |
---|
342 | return NULL; |
---|
343 | } |
---|