Mercurial > audlegacy
annotate audacious/pluginenum.c @ 538:e4e897d20791 trunk
[svn] remove libaudcore, we never did anything with it
| author | nenolod |
|---|---|
| date | Sat, 28 Jan 2006 09:21:21 -0800 |
| parents | 1e2fc0f461a1 |
| children | 980d651da2fc |
| 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" | |
|
538
e4e897d20791
[svn] remove libaudcore, we never did anything with it
nenolod
parents:
380
diff
changeset
|
35 #include "playback.h" |
| 0 | 36 #include "playlist.h" |
| 37 #include "util.h" | |
| 38 | |
| 39 #include "effect.h" | |
| 40 #include "general.h" | |
| 41 #include "input.h" | |
| 42 #include "output.h" | |
| 43 #include "visualization.h" | |
| 44 | |
| 45 const gchar *plugin_dir_list[] = { | |
| 46 PLUGINSUBS, | |
| 47 NULL | |
| 48 }; | |
| 49 | |
| 50 GHashTable *plugin_matrix = NULL; | |
| 51 | |
| 52 static gint | |
| 53 inputlist_compare_func(gconstpointer a, gconstpointer b) | |
| 54 { | |
| 55 const InputPlugin *ap = a, *bp = b; | |
| 56 return strcasecmp(ap->description, bp->description); | |
| 57 } | |
| 58 | |
| 59 static gint | |
| 60 outputlist_compare_func(gconstpointer a, gconstpointer b) | |
| 61 { | |
| 62 const OutputPlugin *ap = a, *bp = b; | |
| 63 return strcasecmp(ap->description, bp->description); | |
| 64 } | |
| 65 | |
| 66 static gint | |
| 67 effectlist_compare_func(gconstpointer a, gconstpointer b) | |
| 68 { | |
| 69 const EffectPlugin *ap = a, *bp = b; | |
| 70 return strcasecmp(ap->description, bp->description); | |
| 71 } | |
| 72 | |
| 73 static gint | |
| 74 generallist_compare_func(gconstpointer a, gconstpointer b) | |
| 75 { | |
| 76 const GeneralPlugin *ap = a, *bp = b; | |
| 77 return strcasecmp(ap->description, bp->description); | |
| 78 } | |
| 79 | |
| 80 static gint | |
| 81 vislist_compare_func(gconstpointer a, gconstpointer b) | |
| 82 { | |
| 83 const VisPlugin *ap = a, *bp = b; | |
| 84 return strcasecmp(ap->description, bp->description); | |
| 85 } | |
| 86 | |
| 87 static gboolean | |
| 88 plugin_is_duplicate(const gchar * filename) | |
| 89 { | |
| 90 GList *l; | |
| 91 const gchar *basename = g_basename(filename); | |
| 92 | |
| 93 /* FIXME: messy stuff */ | |
| 94 | |
| 95 for (l = ip_data.input_list; l; l = g_list_next(l)) | |
| 96 if (!strcmp(basename, g_basename(INPUT_PLUGIN(l->data)->filename))) | |
| 97 return TRUE; | |
| 98 | |
| 99 for (l = op_data.output_list; l; l = g_list_next(l)) | |
| 100 if (!strcmp(basename, g_basename(OUTPUT_PLUGIN(l->data)->filename))) | |
| 101 return TRUE; | |
| 102 | |
| 103 for (l = ep_data.effect_list; l; l = g_list_next(l)) | |
| 104 if (!strcmp(basename, g_basename(EFFECT_PLUGIN(l->data)->filename))) | |
| 105 return TRUE; | |
| 106 | |
| 107 for (l = gp_data.general_list; l; l = g_list_next(l)) | |
| 108 if (!strcmp(basename, g_basename(GENERAL_PLUGIN(l->data)->filename))) | |
| 109 return TRUE; | |
| 110 | |
| 111 for (l = vp_data.vis_list; l; l = g_list_next(l)) | |
| 112 if (!strcmp(basename, g_basename(VIS_PLUGIN(l->data)->filename))) | |
| 113 return TRUE; | |
| 114 | |
| 115 return FALSE; | |
| 116 } | |
| 117 | |
| 118 | |
| 119 #define PLUGIN_GET_INFO(x) ((PluginGetInfoFunc)(x))() | |
| 120 typedef Plugin * (*PluginGetInfoFunc) (void); | |
| 121 | |
| 122 static void | |
| 123 input_plugin_init(Plugin * plugin) | |
| 124 { | |
| 125 InputPlugin *p = INPUT_PLUGIN(plugin); | |
| 126 | |
| 127 p->get_vis_type = input_get_vis_type; | |
| 128 p->add_vis_pcm = input_add_vis_pcm; | |
| 129 | |
| 130 /* Pretty const casts courtesy of XMMS's plugin.h legacy. Anyone | |
| 131 else thinks we could use a CONST macro to solve the warnings? | |
| 132 - descender */ | |
| 133 p->set_info = (void (*)(gchar *, gint, gint, gint, gint)) playlist_set_info; | |
| 134 p->set_info_text = (void (*)(gchar *)) input_set_info_text; | |
| 135 | |
| 136 ip_data.input_list = g_list_append(ip_data.input_list, p); | |
| 137 | |
| 138 g_hash_table_replace(plugin_matrix, g_path_get_basename(p->filename), | |
| 139 GINT_TO_POINTER(1)); | |
| 140 } | |
| 141 | |
| 142 static void | |
| 143 output_plugin_init(Plugin * plugin) | |
| 144 { | |
| 145 OutputPlugin *p = OUTPUT_PLUGIN(plugin); | |
| 146 op_data.output_list = g_list_append(op_data.output_list, p); | |
| 147 } | |
| 148 | |
| 149 static void | |
| 150 effect_plugin_init(Plugin * plugin) | |
| 151 { | |
| 152 EffectPlugin *p = EFFECT_PLUGIN(plugin); | |
| 153 ep_data.effect_list = g_list_append(ep_data.effect_list, p); | |
| 154 } | |
| 155 | |
| 156 static void | |
| 157 general_plugin_init(Plugin * plugin) | |
| 158 { | |
| 159 GeneralPlugin *p = GENERAL_PLUGIN(plugin); | |
| 160 p->xmms_session = ctrlsocket_get_session_id(); | |
| 161 gp_data.general_list = g_list_append(gp_data.general_list, p); | |
| 162 } | |
| 163 | |
| 164 static void | |
| 165 vis_plugin_init(Plugin * plugin) | |
| 166 { | |
| 167 VisPlugin *p = VIS_PLUGIN(plugin); | |
| 168 p->xmms_session = ctrlsocket_get_session_id(); | |
| 169 p->disable_plugin = vis_disable_plugin; | |
| 170 vp_data.vis_list = g_list_append(vp_data.vis_list, p); | |
| 171 } | |
| 172 | |
| 173 | |
| 174 /* FIXME: Placed here (hopefully) temporarily - descender */ | |
| 175 | |
| 176 typedef struct { | |
| 177 const gchar *name; | |
| 178 const gchar *id; | |
| 179 void (*init)(Plugin *); | |
| 180 } PluginType; | |
| 181 | |
| 182 static PluginType plugin_types[] = { | |
| 183 { "input" , "get_iplugin_info", input_plugin_init }, | |
| 184 { "output" , "get_oplugin_info", output_plugin_init }, | |
| 185 { "effect" , "get_eplugin_info", effect_plugin_init }, | |
| 186 { "general" , "get_gplugin_info", general_plugin_init }, | |
| 187 { "visualization", "get_vplugin_info", vis_plugin_init }, | |
| 188 { NULL, NULL, NULL } | |
| 189 }; | |
| 190 | |
| 191 static void | |
| 192 add_plugin(const gchar * filename) | |
| 193 { | |
| 194 PluginType *type; | |
| 195 GModule *module; | |
| 196 gpointer func; | |
| 197 | |
| 198 if (plugin_is_duplicate(filename)) | |
| 199 return; | |
| 200 | |
| 201 if (!(module = g_module_open(filename, 0))) { | |
| 12 | 202 printf("Failed to load plugin (%s): %s\n", |
| 0 | 203 filename, g_module_error()); |
| 204 return; | |
| 205 } | |
| 206 | |
| 207 for (type = plugin_types; type->name; type++) | |
| 208 { | |
| 209 if (g_module_symbol(module, type->id, &func)) { | |
| 210 Plugin *plugin = PLUGIN_GET_INFO(func); | |
| 211 | |
| 212 plugin->handle = module; | |
| 213 plugin->filename = g_strdup(filename); | |
| 214 type->init(PLUGIN_GET_INFO(func)); | |
| 215 | |
| 216 return; | |
| 217 } | |
| 218 } | |
| 219 | |
| 12 | 220 printf("Invalid plugin (%s)\n", filename); |
| 0 | 221 g_module_close(module); |
| 222 } | |
| 223 | |
| 224 static gboolean | |
| 225 scan_plugin_func(const gchar * path, const gchar * basename, gpointer data) | |
| 226 { | |
| 227 if (!str_has_suffix_nocase(basename, G_MODULE_SUFFIX)) | |
| 228 return FALSE; | |
| 229 | |
| 230 if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) | |
| 231 return FALSE; | |
| 232 | |
| 233 add_plugin(path); | |
| 234 | |
| 235 return FALSE; | |
| 236 } | |
| 237 | |
| 238 static void | |
| 239 scan_plugins(const gchar * path) | |
| 240 { | |
| 241 dir_foreach(path, scan_plugin_func, NULL, NULL); | |
| 242 } | |
| 243 | |
| 244 void | |
| 245 plugin_system_init(void) | |
| 246 { | |
| 247 gchar *dir, **disabled; | |
| 248 GList *node; | |
| 249 OutputPlugin *op; | |
| 250 InputPlugin *ip; | |
| 251 gint dirsel = 0, i = 0; | |
| 252 | |
| 253 if (!g_module_supported()) { | |
| 254 /* FIXME: We should open an error dialog for this. BMP is | |
| 255 practically useless without plugins */ | |
| 256 g_warning("Module loading not supported! Plugins will not be loaded."); | |
| 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 | |
| 361 if (bmp_playback_get_playing()) | |
| 362 bmp_playback_stop(); | |
| 363 | |
| 364 for (node = get_input_list(); node; node = g_list_next(node)) { | |
| 365 ip = INPUT_PLUGIN(node->data); | |
| 366 if (ip && ip->cleanup) { | |
| 367 ip->cleanup(); | |
| 368 GDK_THREADS_LEAVE(); | |
| 369 while (g_main_iteration(FALSE)); | |
| 370 GDK_THREADS_ENTER(); | |
| 371 } | |
| 372 g_module_close(ip->handle); | |
| 373 } | |
| 374 | |
| 375 if (ip_data.input_list) | |
| 376 g_list_free(ip_data.input_list); | |
| 377 | |
| 378 for (node = get_output_list(); node; node = g_list_next(node)) { | |
| 379 op = OUTPUT_PLUGIN(node->data); | |
| 309 | 380 if (op && op->cleanup) { |
| 381 op->cleanup(); | |
| 382 GDK_THREADS_LEAVE(); | |
| 383 while (g_main_iteration(FALSE)); | |
| 384 GDK_THREADS_ENTER(); | |
| 385 } | |
| 0 | 386 g_module_close(op->handle); |
| 387 } | |
| 388 | |
| 389 if (op_data.output_list) | |
| 390 g_list_free(op_data.output_list); | |
| 391 | |
| 392 for (node = get_effect_list(); node; node = g_list_next(node)) { | |
| 393 ep = EFFECT_PLUGIN(node->data); | |
| 394 if (ep && ep->cleanup) { | |
| 395 ep->cleanup(); | |
| 396 GDK_THREADS_LEAVE(); | |
| 397 while (g_main_iteration(FALSE)); | |
| 398 GDK_THREADS_ENTER(); | |
| 399 } | |
| 400 g_module_close(ep->handle); | |
| 401 } | |
| 402 | |
| 403 if (ep_data.effect_list) | |
| 404 g_list_free(ep_data.effect_list); | |
| 405 | |
| 406 for (node = get_general_enabled_list(); node; node = g_list_next(node)) { | |
| 407 gp = GENERAL_PLUGIN(node->data); | |
| 408 enable_general_plugin(g_list_index(gp_data.general_list, gp), FALSE); | |
| 409 } | |
| 410 | |
| 411 if (gp_data.enabled_list) | |
| 412 g_list_free(gp_data.enabled_list); | |
| 413 | |
| 414 GDK_THREADS_LEAVE(); | |
| 415 while (g_main_iteration(FALSE)); | |
| 416 GDK_THREADS_ENTER(); | |
| 417 | |
| 418 for (node = get_general_list(); node; node = g_list_next(node)) { | |
| 419 gp = GENERAL_PLUGIN(node->data); | |
| 420 g_module_close(gp->handle); | |
| 421 } | |
| 422 | |
| 423 if (gp_data.general_list) | |
| 424 g_list_free(gp_data.general_list); | |
| 425 | |
| 426 for (node = get_vis_enabled_list(); node; node = g_list_next(node)) { | |
| 427 vp = VIS_PLUGIN(node->data); | |
| 428 enable_vis_plugin(g_list_index(vp_data.vis_list, vp), FALSE); | |
| 429 } | |
| 430 | |
| 431 if (vp_data.enabled_list) | |
| 432 g_list_free(vp_data.enabled_list); | |
| 433 | |
| 434 GDK_THREADS_LEAVE(); | |
| 435 while (g_main_iteration(FALSE)); | |
| 436 GDK_THREADS_ENTER(); | |
| 437 | |
| 438 for (node = get_vis_list(); node; node = g_list_next(node)) { | |
| 439 vp = VIS_PLUGIN(node->data); | |
| 440 g_module_close(vp->handle); | |
| 441 } | |
| 442 | |
| 443 if (vp_data.vis_list) | |
| 444 g_list_free(vp_data.vis_list); | |
| 445 } |
