Mercurial > audlegacy
annotate audacious/pluginenum.c @ 1409:0f6573c34500 trunk
[svn] - properly hook up mms
author | nenolod |
---|---|
date | Sat, 15 Jul 2006 16:52:52 -0700 |
parents | 3b990c26fc46 |
children | f12d7e208b43 |
rev | line source |
---|---|
0 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public Licensse as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program 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 | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 */ | |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 # include "config.h" | |
24 #endif | |
25 | |
26 #include "pluginenum.h" | |
27 | |
28 #include <glib.h> | |
29 #include <gmodule.h> | |
30 #include <glib/gprintf.h> | |
31 #include <string.h> | |
32 | |
33 #include "controlsocket.h" | |
34 #include "main.h" | |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
687
diff
changeset
|
35 #include "mainwin.h" |
538
e4e897d20791
[svn] remove libaudcore, we never did anything with it
nenolod
parents:
380
diff
changeset
|
36 #include "playback.h" |
0 | 37 #include "playlist.h" |
38 #include "util.h" | |
39 | |
40 #include "effect.h" | |
41 #include "general.h" | |
42 #include "input.h" | |
43 #include "output.h" | |
44 #include "visualization.h" | |
45 | |
46 const gchar *plugin_dir_list[] = { | |
47 PLUGINSUBS, | |
48 NULL | |
49 }; | |
50 | |
51 GHashTable *plugin_matrix = NULL; | |
52 | |
53 static gint | |
54 inputlist_compare_func(gconstpointer a, gconstpointer b) | |
55 { | |
56 const InputPlugin *ap = a, *bp = b; | |
57 return strcasecmp(ap->description, bp->description); | |
58 } | |
59 | |
60 static gint | |
61 outputlist_compare_func(gconstpointer a, gconstpointer b) | |
62 { | |
63 const OutputPlugin *ap = a, *bp = b; | |
64 return strcasecmp(ap->description, bp->description); | |
65 } | |
66 | |
67 static gint | |
68 effectlist_compare_func(gconstpointer a, gconstpointer b) | |
69 { | |
70 const EffectPlugin *ap = a, *bp = b; | |
71 return strcasecmp(ap->description, bp->description); | |
72 } | |
73 | |
74 static gint | |
75 generallist_compare_func(gconstpointer a, gconstpointer b) | |
76 { | |
77 const GeneralPlugin *ap = a, *bp = b; | |
78 return strcasecmp(ap->description, bp->description); | |
79 } | |
80 | |
81 static gint | |
82 vislist_compare_func(gconstpointer a, gconstpointer b) | |
83 { | |
84 const VisPlugin *ap = a, *bp = b; | |
85 return strcasecmp(ap->description, bp->description); | |
86 } | |
87 | |
88 static gboolean | |
89 plugin_is_duplicate(const gchar * filename) | |
90 { | |
91 GList *l; | |
92 const gchar *basename = g_basename(filename); | |
93 | |
94 /* FIXME: messy stuff */ | |
95 | |
96 for (l = ip_data.input_list; l; l = g_list_next(l)) | |
97 if (!strcmp(basename, g_basename(INPUT_PLUGIN(l->data)->filename))) | |
98 return TRUE; | |
99 | |
100 for (l = op_data.output_list; l; l = g_list_next(l)) | |
101 if (!strcmp(basename, g_basename(OUTPUT_PLUGIN(l->data)->filename))) | |
102 return TRUE; | |
103 | |
104 for (l = ep_data.effect_list; l; l = g_list_next(l)) | |
105 if (!strcmp(basename, g_basename(EFFECT_PLUGIN(l->data)->filename))) | |
106 return TRUE; | |
107 | |
108 for (l = gp_data.general_list; l; l = g_list_next(l)) | |
109 if (!strcmp(basename, g_basename(GENERAL_PLUGIN(l->data)->filename))) | |
110 return TRUE; | |
111 | |
112 for (l = vp_data.vis_list; l; l = g_list_next(l)) | |
113 if (!strcmp(basename, g_basename(VIS_PLUGIN(l->data)->filename))) | |
114 return TRUE; | |
115 | |
116 return FALSE; | |
117 } | |
118 | |
119 | |
120 #define PLUGIN_GET_INFO(x) ((PluginGetInfoFunc)(x))() | |
121 typedef Plugin * (*PluginGetInfoFunc) (void); | |
122 | |
123 static void | |
124 input_plugin_init(Plugin * plugin) | |
125 { | |
126 InputPlugin *p = INPUT_PLUGIN(plugin); | |
127 | |
128 p->get_vis_type = input_get_vis_type; | |
129 p->add_vis_pcm = input_add_vis_pcm; | |
130 | |
131 /* Pretty const casts courtesy of XMMS's plugin.h legacy. Anyone | |
132 else thinks we could use a CONST macro to solve the warnings? | |
133 - descender */ | |
134 p->set_info = (void (*)(gchar *, gint, gint, gint, gint)) playlist_set_info; | |
135 p->set_info_text = (void (*)(gchar *)) input_set_info_text; | |
1273
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
906
diff
changeset
|
136 p->set_status_buffering = (void (*)(gboolean)) input_set_status_buffering; |
3b990c26fc46
[svn] - Support for the buffer indicator in playpaus.png that was apparently
nhjm449
parents:
906
diff
changeset
|
137 |
0 | 138 ip_data.input_list = g_list_append(ip_data.input_list, p); |
139 | |
140 g_hash_table_replace(plugin_matrix, g_path_get_basename(p->filename), | |
141 GINT_TO_POINTER(1)); | |
142 } | |
143 | |
144 static void | |
145 output_plugin_init(Plugin * plugin) | |
146 { | |
147 OutputPlugin *p = OUTPUT_PLUGIN(plugin); | |
148 op_data.output_list = g_list_append(op_data.output_list, p); | |
149 } | |
150 | |
151 static void | |
152 effect_plugin_init(Plugin * plugin) | |
153 { | |
154 EffectPlugin *p = EFFECT_PLUGIN(plugin); | |
155 ep_data.effect_list = g_list_append(ep_data.effect_list, p); | |
156 } | |
157 | |
158 static void | |
159 general_plugin_init(Plugin * plugin) | |
160 { | |
161 GeneralPlugin *p = GENERAL_PLUGIN(plugin); | |
162 p->xmms_session = ctrlsocket_get_session_id(); | |
163 gp_data.general_list = g_list_append(gp_data.general_list, p); | |
164 } | |
165 | |
166 static void | |
167 vis_plugin_init(Plugin * plugin) | |
168 { | |
169 VisPlugin *p = VIS_PLUGIN(plugin); | |
170 p->xmms_session = ctrlsocket_get_session_id(); | |
171 p->disable_plugin = vis_disable_plugin; | |
172 vp_data.vis_list = g_list_append(vp_data.vis_list, p); | |
173 } | |
174 | |
175 | |
176 /* FIXME: Placed here (hopefully) temporarily - descender */ | |
177 | |
178 typedef struct { | |
179 const gchar *name; | |
180 const gchar *id; | |
181 void (*init)(Plugin *); | |
182 } PluginType; | |
183 | |
184 static PluginType plugin_types[] = { | |
185 { "input" , "get_iplugin_info", input_plugin_init }, | |
186 { "output" , "get_oplugin_info", output_plugin_init }, | |
187 { "effect" , "get_eplugin_info", effect_plugin_init }, | |
188 { "general" , "get_gplugin_info", general_plugin_init }, | |
189 { "visualization", "get_vplugin_info", vis_plugin_init }, | |
190 { NULL, NULL, NULL } | |
191 }; | |
192 | |
193 static void | |
194 add_plugin(const gchar * filename) | |
195 { | |
196 PluginType *type; | |
197 GModule *module; | |
198 gpointer func; | |
199 | |
200 if (plugin_is_duplicate(filename)) | |
201 return; | |
202 | |
834 | 203 if (!(module = g_module_open(filename, 0))) { |
12 | 204 printf("Failed to load plugin (%s): %s\n", |
0 | 205 filename, g_module_error()); |
206 return; | |
207 } | |
208 | |
209 for (type = plugin_types; type->name; type++) | |
210 { | |
211 if (g_module_symbol(module, type->id, &func)) { | |
212 Plugin *plugin = PLUGIN_GET_INFO(func); | |
213 | |
214 plugin->handle = module; | |
215 plugin->filename = g_strdup(filename); | |
216 type->init(PLUGIN_GET_INFO(func)); | |
217 | |
218 return; | |
219 } | |
220 } | |
221 | |
12 | 222 printf("Invalid plugin (%s)\n", filename); |
0 | 223 g_module_close(module); |
224 } | |
225 | |
226 static gboolean | |
227 scan_plugin_func(const gchar * path, const gchar * basename, gpointer data) | |
228 { | |
229 if (!str_has_suffix_nocase(basename, G_MODULE_SUFFIX)) | |
230 return FALSE; | |
231 | |
232 if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) | |
233 return FALSE; | |
234 | |
235 add_plugin(path); | |
236 | |
237 return FALSE; | |
238 } | |
239 | |
240 static void | |
241 scan_plugins(const gchar * path) | |
242 { | |
243 dir_foreach(path, scan_plugin_func, NULL, NULL); | |
244 } | |
245 | |
246 void | |
247 plugin_system_init(void) | |
248 { | |
249 gchar *dir, **disabled; | |
250 GList *node; | |
251 OutputPlugin *op; | |
252 InputPlugin *ip; | |
253 gint dirsel = 0, i = 0; | |
254 | |
255 if (!g_module_supported()) { | |
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
687
diff
changeset
|
256 report_error("Module loading not supported! Plugins will not be loaded.\n"); |
0 | 257 return; |
258 } | |
259 | |
260 plugin_matrix = g_hash_table_new_full(g_str_hash, g_int_equal, g_free, | |
261 NULL); | |
262 | |
263 #ifndef DISABLE_USER_PLUGIN_DIR | |
264 scan_plugins(bmp_paths[BMP_PATH_USER_PLUGIN_DIR]); | |
265 /* | |
266 * This is in a separate loop so if the user puts them in the | |
267 * wrong dir we'll still get them in the right order (home dir | |
268 * first) - Zinx | |
269 */ | |
270 while (plugin_dir_list[dirsel]) { | |
271 dir = g_build_filename(bmp_paths[BMP_PATH_USER_PLUGIN_DIR], | |
272 plugin_dir_list[dirsel++], NULL); | |
273 scan_plugins(dir); | |
274 g_free(dir); | |
275 } | |
276 dirsel = 0; | |
277 #endif | |
278 | |
279 while (plugin_dir_list[dirsel]) { | |
280 dir = g_build_filename(PLUGIN_DIR, plugin_dir_list[dirsel++], NULL); | |
281 scan_plugins(dir); | |
282 g_free(dir); | |
283 } | |
284 | |
285 op_data.output_list = g_list_sort(op_data.output_list, outputlist_compare_func); | |
286 if (!op_data.current_output_plugin | |
287 && g_list_length(op_data.output_list)) { | |
288 op_data.current_output_plugin = op_data.output_list->data; | |
289 } | |
290 | |
291 ip_data.input_list = g_list_sort(ip_data.input_list, inputlist_compare_func); | |
292 | |
293 ep_data.effect_list = g_list_sort(ep_data.effect_list, effectlist_compare_func); | |
294 ep_data.enabled_list = NULL; | |
295 | |
296 gp_data.general_list = g_list_sort(gp_data.general_list, generallist_compare_func); | |
297 gp_data.enabled_list = NULL; | |
298 | |
299 vp_data.vis_list = g_list_sort(vp_data.vis_list, vislist_compare_func); | |
300 vp_data.enabled_list = NULL; | |
301 | |
302 general_enable_from_stringified_list(cfg.enabled_gplugins); | |
303 vis_enable_from_stringified_list(cfg.enabled_vplugins); | |
304 effect_enable_from_stringified_list(cfg.enabled_eplugins); | |
305 | |
306 g_free(cfg.enabled_gplugins); | |
307 cfg.enabled_gplugins = NULL; | |
308 | |
309 g_free(cfg.enabled_vplugins); | |
310 cfg.enabled_vplugins = NULL; | |
311 | |
312 g_free(cfg.enabled_eplugins); | |
313 cfg.enabled_eplugins = NULL; | |
314 | |
315 for (node = op_data.output_list; node; node = g_list_next(node)) { | |
316 op = OUTPUT_PLUGIN(node->data); | |
317 /* | |
318 * Only test basename to avoid problems when changing | |
319 * prefix. We will only see one plugin with the same | |
320 * basename, so this is usually what the user want. | |
321 */ | |
322 if (!strcmp(g_basename(cfg.outputplugin), g_basename(op->filename))) | |
323 op_data.current_output_plugin = op; | |
324 if (op->init) | |
325 op->init(); | |
326 } | |
327 | |
328 for (node = ip_data.input_list; node; node = g_list_next(node)) { | |
329 ip = INPUT_PLUGIN(node->data); | |
330 if (ip->init) | |
331 ip->init(); | |
332 } | |
333 | |
334 if (cfg.disabled_iplugins) { | |
335 disabled = g_strsplit(cfg.disabled_iplugins, ":", 0); | |
336 while (disabled[i]) { | |
337 g_hash_table_replace(plugin_matrix, disabled[i], | |
338 GINT_TO_POINTER(FALSE)); | |
339 i++; | |
340 } | |
341 | |
342 g_free(disabled); | |
343 | |
344 g_free(cfg.disabled_iplugins); | |
345 cfg.disabled_iplugins = NULL; | |
346 } | |
347 } | |
348 | |
349 void | |
350 plugin_system_cleanup(void) | |
351 { | |
352 InputPlugin *ip; | |
353 OutputPlugin *op; | |
354 EffectPlugin *ep; | |
355 GeneralPlugin *gp; | |
356 VisPlugin *vp; | |
357 GList *node; | |
358 | |
359 g_message("Shutting down plugin system"); | |
360 | |
906 | 361 if (bmp_playback_get_playing()) { |
362 ip_data.stop = TRUE; | |
0 | 363 bmp_playback_stop(); |
906 | 364 ip_data.stop = FALSE; |
365 } | |
0 | 366 |
367 for (node = get_input_list(); node; node = g_list_next(node)) { | |
368 ip = INPUT_PLUGIN(node->data); | |
369 if (ip && ip->cleanup) { | |
370 ip->cleanup(); | |
371 GDK_THREADS_LEAVE(); | |
372 while (g_main_iteration(FALSE)); | |
373 GDK_THREADS_ENTER(); | |
374 } | |
375 g_module_close(ip->handle); | |
376 } | |
377 | |
378 if (ip_data.input_list) | |
379 g_list_free(ip_data.input_list); | |
380 | |
381 for (node = get_output_list(); node; node = g_list_next(node)) { | |
382 op = OUTPUT_PLUGIN(node->data); | |
309 | 383 if (op && op->cleanup) { |
384 op->cleanup(); | |
385 GDK_THREADS_LEAVE(); | |
386 while (g_main_iteration(FALSE)); | |
387 GDK_THREADS_ENTER(); | |
388 } | |
0 | 389 g_module_close(op->handle); |
390 } | |
391 | |
392 if (op_data.output_list) | |
393 g_list_free(op_data.output_list); | |
394 | |
395 for (node = get_effect_list(); node; node = g_list_next(node)) { | |
396 ep = EFFECT_PLUGIN(node->data); | |
397 if (ep && ep->cleanup) { | |
398 ep->cleanup(); | |
399 GDK_THREADS_LEAVE(); | |
400 while (g_main_iteration(FALSE)); | |
401 GDK_THREADS_ENTER(); | |
402 } | |
403 g_module_close(ep->handle); | |
404 } | |
405 | |
406 if (ep_data.effect_list) | |
407 g_list_free(ep_data.effect_list); | |
408 | |
409 for (node = get_general_enabled_list(); node; node = g_list_next(node)) { | |
410 gp = GENERAL_PLUGIN(node->data); | |
411 enable_general_plugin(g_list_index(gp_data.general_list, gp), FALSE); | |
412 } | |
413 | |
414 if (gp_data.enabled_list) | |
415 g_list_free(gp_data.enabled_list); | |
416 | |
417 GDK_THREADS_LEAVE(); | |
418 while (g_main_iteration(FALSE)); | |
419 GDK_THREADS_ENTER(); | |
420 | |
421 for (node = get_general_list(); node; node = g_list_next(node)) { | |
422 gp = GENERAL_PLUGIN(node->data); | |
650
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
423 if (gp && gp->cleanup) { |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
424 gp->cleanup(); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
425 GDK_THREADS_LEAVE(); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
426 while (g_main_iteration(FALSE)); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
427 GDK_THREADS_ENTER(); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
428 } |
0 | 429 g_module_close(gp->handle); |
430 } | |
431 | |
432 if (gp_data.general_list) | |
433 g_list_free(gp_data.general_list); | |
434 | |
435 for (node = get_vis_enabled_list(); node; node = g_list_next(node)) { | |
436 vp = VIS_PLUGIN(node->data); | |
437 enable_vis_plugin(g_list_index(vp_data.vis_list, vp), FALSE); | |
438 } | |
439 | |
440 if (vp_data.enabled_list) | |
441 g_list_free(vp_data.enabled_list); | |
442 | |
443 GDK_THREADS_LEAVE(); | |
444 while (g_main_iteration(FALSE)); | |
445 GDK_THREADS_ENTER(); | |
446 | |
447 for (node = get_vis_list(); node; node = g_list_next(node)) { | |
448 vp = VIS_PLUGIN(node->data); | |
650
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
449 if (vp && vp->cleanup) { |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
450 vp->cleanup(); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
451 GDK_THREADS_LEAVE(); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
452 while (g_main_iteration(FALSE)); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
453 GDK_THREADS_ENTER(); |
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
454 } |
0 | 455 g_module_close(vp->handle); |
456 } | |
457 | |
458 if (vp_data.vis_list) | |
459 g_list_free(vp_data.vis_list); | |
460 } |