1 /*****************************************************************************
2 * modules.c : Builtin and plugin modules management functions
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: modules.c,v 1.125 2003/07/14 21:32:59 sigmunau Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Ethan C. Baldridge <BaldridgeE@cadmus.com>
9 * Hans-Peter Jansen <hpj@urpla.net>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /* Some faulty libcs have a broken struct dirent when _FILE_OFFSET_BITS
27 * is set to 64. Don't try to be cleverer. */
28 #ifdef _FILE_OFFSET_BITS
29 #undef _FILE_OFFSET_BITS
32 #include <stdlib.h> /* free(), strtol() */
33 #include <stdio.h> /* sprintf() */
34 #include <string.h> /* strdup() */
40 #elif defined( UNDER_CE )
41 # include <windows.h> /* GetFileAttributes() */
43 # include "../extras/dirent.h"
46 #ifdef HAVE_SYS_TYPES_H
47 # include <sys/types.h>
49 #ifdef HAVE_SYS_STAT_H
50 # include <sys/stat.h>
56 #if defined(HAVE_DLFCN_H) /* Linux, BSD, Hurd */
57 # include <dlfcn.h> /* dlopen(), dlsym(), dlclose() */
58 # define HAVE_DYNAMIC_PLUGINS
59 #elif defined(HAVE_IMAGE_H) /* BeOS */
61 # define HAVE_DYNAMIC_PLUGINS
62 #elif defined(UNDER_CE)
63 # define HAVE_DYNAMIC_PLUGINS
65 # define HAVE_DYNAMIC_PLUGINS
67 # undef HAVE_DYNAMIC_PLUGINS
70 #include "vlc_error.h"
72 #include "vlc_interface.h"
73 #include "vlc_playlist.h"
74 #include "intf_eject.h"
76 #include "stream_control.h"
77 #include "input_ext-intf.h"
78 #include "input_ext-dec.h"
79 #include "input_ext-plugins.h"
81 #include "vlc_video.h"
82 #include "video_output.h"
83 #include "vout_synchro.h"
85 #include "audio_output.h"
86 #include "aout_internal.h"
88 #include "stream_output.h"
94 #if defined( UNDER_CE )
95 # define MYCHAR wchar_t
100 #ifdef HAVE_DYNAMIC_PLUGINS
101 # include "modules_plugin.h"
104 #if defined( UNDER_CE )
105 # include "modules_builtin_evc.h"
106 #elif defined( _MSC_VER )
107 # include "modules_builtin_msvc.h"
109 # include "modules_builtin.h"
112 /*****************************************************************************
114 *****************************************************************************/
115 #ifdef HAVE_DYNAMIC_PLUGINS
116 static void AllocateAllPlugins ( vlc_object_t * );
117 static void AllocatePluginDir ( vlc_object_t *, const MYCHAR *, int );
118 static int AllocatePluginFile ( vlc_object_t *, MYCHAR * );
120 static int AllocateBuiltinModule( vlc_object_t *, int ( * ) ( module_t * ) );
121 static int DeleteModule ( module_t * );
122 #ifdef HAVE_DYNAMIC_PLUGINS
123 static void DupModule ( module_t * );
124 static void UndupModule ( module_t * );
125 static int CallEntry ( module_t * );
128 /*****************************************************************************
129 * module_InitBank: create the module bank.
130 *****************************************************************************
131 * This function creates a module bank structure which will be filled later
132 * on with all the modules found.
133 *****************************************************************************/
134 void __module_InitBank( vlc_object_t *p_this )
136 module_bank_t *p_bank;
138 p_bank = vlc_object_create( p_this, sizeof(module_bank_t) );
139 p_bank->psz_object_name = "module bank";
142 * Store the symbols to be exported
144 #ifdef HAVE_DYNAMIC_PLUGINS
145 STORE_SYMBOLS( &p_bank->symbols );
148 /* Everything worked, attach the object */
149 p_this->p_libvlc->p_module_bank = p_bank;
150 vlc_object_attach( p_bank, p_this->p_libvlc );
155 /*****************************************************************************
156 * module_ResetBank: reset the module bank.
157 *****************************************************************************
158 * This function resets the module bank by unloading all unused plugin
160 *****************************************************************************/
161 void __module_ResetBank( vlc_object_t *p_this )
163 msg_Err( p_this, "FIXME: module_ResetBank unimplemented" );
167 /*****************************************************************************
168 * module_EndBank: empty the module bank.
169 *****************************************************************************
170 * This function unloads all unused plugin modules and empties the module
171 * bank in case of success.
172 *****************************************************************************/
173 void __module_EndBank( vlc_object_t *p_this )
177 vlc_object_detach( p_this->p_libvlc->p_module_bank );
179 while( p_this->p_libvlc->p_module_bank->i_children )
181 p_next = (module_t *)p_this->p_libvlc->p_module_bank->pp_children[0];
183 if( DeleteModule( p_next ) )
185 /* Module deletion failed */
186 msg_Err( p_this, "module \"%s\" can't be removed, trying harder",
187 p_next->psz_object_name );
189 /* We just free the module by hand. Niahahahahaha. */
190 vlc_object_detach( p_next );
191 vlc_object_destroy( p_next );
195 vlc_object_destroy( p_this->p_libvlc->p_module_bank );
200 /*****************************************************************************
201 * module_LoadMain: load the main program info into the module bank.
202 *****************************************************************************
203 * This function fills the module bank structure with the main module infos.
204 * This is very useful as it will allow us to consider the main program just
205 * as another module, and for instance the configuration options of main will
206 * be available in the module bank structure just as for every other module.
207 *****************************************************************************/
208 void __module_LoadMain( vlc_object_t *p_this )
210 AllocateBuiltinModule( p_this, vlc_entry__main );
213 /*****************************************************************************
214 * module_LoadBuiltins: load all modules which we built with.
215 *****************************************************************************
216 * This function fills the module bank structure with the builtin modules.
217 *****************************************************************************/
218 void __module_LoadBuiltins( vlc_object_t * p_this )
220 msg_Dbg( p_this, "checking builtin modules" );
221 ALLOCATE_ALL_BUILTINS();
224 /*****************************************************************************
225 * module_LoadPlugins: load all plugin modules we can find.
226 *****************************************************************************
227 * This function fills the module bank structure with the plugin modules.
228 *****************************************************************************/
229 void __module_LoadPlugins( vlc_object_t * p_this )
231 #ifdef HAVE_DYNAMIC_PLUGINS
232 msg_Dbg( p_this, "checking plugin modules" );
233 AllocateAllPlugins( p_this );
237 /*****************************************************************************
238 * module_Need: return the best module function, given a capability list.
239 *****************************************************************************
240 * This function returns the module that best fits the asked capabilities.
241 *****************************************************************************/
242 module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
243 const char *psz_name )
245 typedef struct module_list_t module_list_t;
251 module_list_t *p_next;
254 module_list_t *p_list, *p_first, *p_tmp;
257 int i_which_module, i_index = 0;
258 vlc_bool_t b_intf = VLC_FALSE;
263 char *psz_shortcuts = NULL, *psz_var = NULL;
265 msg_Dbg( p_this, "looking for %s module", psz_capability );
267 /* Deal with variables */
268 if( psz_name && psz_name[0] == '$' )
270 psz_var = config_GetPsz( p_this, psz_name + 1 );
274 /* Count how many different shortcuts were asked for */
275 if( psz_name && *psz_name )
279 /* If the user wants none, give him none. */
280 if( !strcmp( psz_name, "none" ) )
282 if( psz_var ) free( psz_var );
287 psz_shortcuts = strdup( psz_name );
289 for( psz_parser = psz_shortcuts; *psz_parser; psz_parser++ )
291 if( *psz_parser == ',' )
299 /* Sort the modules and test them */
300 p_all = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
301 p_list = malloc( p_all->i_count * sizeof( module_list_t ) );
304 /* Parse the module list for capabilities and probe each of them */
305 for( i_which_module = 0; i_which_module < p_all->i_count; i_which_module++ )
307 module_t * p_submodule = NULL;
308 int i_shortcut_bonus = 0, i_submodule;
310 p_module = (module_t *)p_all->p_values[i_which_module].p_object;
312 /* Test that this module can do what we need */
313 if( strcmp( p_module->psz_capability, psz_capability ) )
315 for( i_submodule = 0;
316 i_submodule < p_module->i_children;
319 if( !strcmp( ((module_t*)p_module->pp_children[ i_submodule ])
320 ->psz_capability, psz_capability ) )
323 (module_t*)p_module->pp_children[ i_submodule ];
328 if( p_submodule == NULL )
333 p_module = p_submodule;
336 /* Test if we have the required CPU */
337 if( (p_module->i_cpu & p_this->p_libvlc->i_cpu) != p_module->i_cpu )
342 /* If we required a shortcut, check this plugin provides it. */
346 int i_dummy, i_short = i_shortcuts;
347 char *psz_name = psz_shortcuts;
349 /* Let's drop modules with a 0 score (unless they are
350 * explicitly requested) */
351 b_trash = !p_module->i_score;
355 /* If the last given shortcut is "none" and we couldn't
356 * find the module in the list of provided shortcuts,
357 * then kick the bastard out of here!!! */
358 if( (i_short == 1) && !strcmp(psz_name, "none") )
364 for( i_dummy = 0; p_module->pp_shortcuts[i_dummy]; i_dummy++ )
366 if( !strcmp( psz_name,
367 p_module->pp_shortcuts[i_dummy] ) )
371 i_shortcut_bonus = i_short * 10000;
376 if( i_shortcut_bonus )
378 /* We found it... remember ? */
382 /* Go to the next shortcut... This is so lame! */
396 /* If we didn't require a shortcut, trash zero-scored plugins */
397 else if( !p_module->i_score )
402 /* Special case: test if we requested a particular intf plugin */
403 if( p_module->psz_program
404 && !strcmp( p_module->psz_program,
405 p_this->p_vlc->psz_object_name ) )
409 /* Remove previous non-matching plugins */
416 /* This one doesn't match */
420 /* Store this new module */
421 p_list[ i_index ].p_module = p_module;
422 p_list[ i_index ].i_score = p_module->i_score + i_shortcut_bonus;
424 /* Add it to the modules-to-probe list */
427 p_list[ 0 ].p_next = NULL;
432 /* Ok, so at school you learned that quicksort is quick, and
433 * bubble sort sucks raw eggs. But that's when dealing with
434 * thousands of items. Here we have barely 50. */
435 module_list_t *p_newlist = p_first;
437 if( p_first->i_score < p_list[ i_index ].i_score )
439 p_list[ i_index ].p_next = p_first;
440 p_first = &p_list[ i_index ];
444 while( p_newlist->p_next != NULL &&
445 p_newlist->p_next->i_score >= p_list[ i_index ].i_score )
447 p_newlist = p_newlist->p_next;
450 p_list[ i_index ].p_next = p_newlist->p_next;
451 p_newlist->p_next = &p_list[ i_index ];
458 msg_Dbg( p_this, "probing %i candidate%s",
459 i_index, i_index == 1 ? "" : "s" );
461 /* Lock all candidate modules */
463 while( p_tmp != NULL )
465 vlc_object_yield( p_tmp->p_module );
466 p_tmp = p_tmp->p_next;
469 /* We can release the list, interesting modules were yielded */
470 vlc_list_release( p_all );
472 /* Parse the linked list and use the first successful module */
474 while( p_tmp != NULL )
476 if( p_tmp->p_module->pf_activate
477 && p_tmp->p_module->pf_activate( p_this ) == VLC_SUCCESS )
482 vlc_object_release( p_tmp->p_module );
483 p_tmp = p_tmp->p_next;
486 /* Store the locked module value */
489 p_module = p_tmp->p_module;
490 p_tmp = p_tmp->p_next;
497 /* Unlock the remaining modules */
498 while( p_tmp != NULL )
500 vlc_object_release( p_tmp->p_module );
501 p_tmp = p_tmp->p_next;
506 if( p_module != NULL )
508 msg_Dbg( p_module, "using %s module \"%s\"",
509 psz_capability, p_module->psz_object_name );
511 else if( p_first == NULL )
513 msg_Err( p_this, "no %s module matched \"%s\"",
514 psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
516 else if( psz_name != NULL && *psz_name )
518 msg_Warn( p_this, "no %s module matching \"%s\" could be loaded",
519 psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
524 free( psz_shortcuts );
532 /* Don't forget that the module is still locked */
536 /*****************************************************************************
537 * module_Unneed: decrease the usage count of a module.
538 *****************************************************************************
539 * This function must be called by the thread that called module_Need, to
540 * decrease the reference count and allow for hiding of modules.
541 *****************************************************************************/
542 void __module_Unneed( vlc_object_t * p_this, module_t * p_module )
544 /* Use the close method */
545 if( p_module->pf_deactivate )
547 p_module->pf_deactivate( p_this );
550 msg_Dbg( p_module, "unlocking module \"%s\"", p_module->psz_object_name );
552 vlc_object_release( p_module );
557 /*****************************************************************************
558 * Following functions are local.
559 *****************************************************************************/
561 /*****************************************************************************
562 * AllocateAllPlugins: load all plugin modules we can find.
563 *****************************************************************************/
564 #ifdef HAVE_DYNAMIC_PLUGINS
565 static void AllocateAllPlugins( vlc_object_t *p_this )
567 /* Yes, there are two NULLs because we replace one with "plugin-path". */
568 char * path[] = { "modules", PLUGIN_PATH, "plugins", NULL,
571 char ** ppsz_path = path;
573 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) \
574 || ( defined( WIN32 ) && !defined( UNDER_CE ) )
575 int i_vlclen = strlen( p_this->p_libvlc->psz_vlcpath );
576 vlc_bool_t b_notinroot;
579 #if defined( UNDER_CE )
580 wchar_t psz_dir[MAX_PATH];
583 /* If the user provided a plugin path, we add it to the list */
584 path[ sizeof(path)/sizeof(char*) - 2 ] = config_GetPsz( p_this,
587 #if defined( WIN32 ) && !defined( UNDER_CE ) && !defined( _MSC_VER )
588 /* If there is no 'plugins' nor 'modules' subdirectory, the user may have
589 * screwed up the unzipping stage, so we look into '.' instead */
590 if( !opendir( "plugins" ) && !opendir( "modules" )
591 && !strcmp( *ppsz_path, "modules" ) )
597 for( ; *ppsz_path != NULL ; ppsz_path++ )
599 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) \
600 || ( defined( WIN32 ) && !defined( UNDER_CE ) )
601 /* Store strlen(*ppsz_path) for later use. */
602 int i_dirlen = strlen( *ppsz_path );
604 b_notinroot = VLC_FALSE;
605 /* Under BeOS, we need to add beos_GetProgramPath() to access
606 * files under the current directory */
608 if( i_dirlen < 3 || (*ppsz_path)[3] != '\\' )
610 if( (*ppsz_path)[0] != '/' )
613 i_dirlen += i_vlclen + 2;
614 b_notinroot = VLC_TRUE;
616 psz_fullpath = malloc( i_dirlen );
617 if( psz_fullpath == NULL )
622 sprintf( psz_fullpath, "%s\\%s",
623 p_this->p_libvlc->psz_vlcpath, *ppsz_path );
625 sprintf( psz_fullpath, "%s/%s",
626 p_this->p_libvlc->psz_vlcpath, *ppsz_path );
632 psz_fullpath = *ppsz_path;
635 msg_Dbg( p_this, "recursively browsing `%s'", psz_fullpath );
637 /* Don't go deeper than 5 subdirectories */
638 #if defined( UNDER_CE )
639 MultiByteToWideChar( CP_ACP, 0, psz_fullpath, -1, psz_dir, MAX_PATH );
640 AllocatePluginDir( p_this, psz_dir, 5 );
642 AllocatePluginDir( p_this, psz_fullpath, 5 );
645 #if defined( SYS_BEOS ) || defined( SYS_DARWIN )
648 free( psz_fullpath );
653 /* Free plugin-path */
654 if( path[ sizeof(path)/sizeof(char*) - 2 ] )
655 free( path[ sizeof(path)/sizeof(char*) - 2 ] );
656 path[ sizeof(path)/sizeof(char*) - 2 ] = NULL;
659 /*****************************************************************************
660 * AllocatePluginDir: recursively parse a directory to look for plugins
661 *****************************************************************************/
662 static void AllocatePluginDir( vlc_object_t *p_this, const MYCHAR *psz_dir,
665 #if defined( UNDER_CE ) || defined( _MSC_VER )
667 MYCHAR psz_path[MAX_PATH + 256];
669 char psz_path[MAX_PATH + 256];
671 WIN32_FIND_DATA finddata;
678 struct dirent * file;
686 #if defined( UNDER_CE ) || defined( _MSC_VER )
687 rc = GetFileAttributes( psz_dir );
688 if( !(rc & FILE_ATTRIBUTE_DIRECTORY) )
690 /* Not a directory */
694 /* Parse all files in the directory */
696 swprintf( psz_path, L"%s\\*.*", psz_dir );
698 sprintf( psz_path, "%s\\*.*", psz_dir );
700 handle = FindFirstFile( psz_path, &finddata );
701 if( handle == INVALID_HANDLE_VALUE )
703 /* Empty directory */
707 /* Parse the directory and try to load all files it contains. */
711 unsigned int i_len = wcslen( finddata.cFileName );
712 swprintf( psz_path, L"%s\\%s", psz_dir, finddata.cFileName );
714 unsigned int i_len = strlen( finddata.cFileName );
715 /* Skip ".", ".." and anything starting with "." */
716 if( !*finddata.cFileName || *finddata.cFileName == '.' )
718 if( !FindNextFile( handle, &finddata ) ) break;
721 sprintf( psz_path, "%s\\%s", psz_dir, finddata.cFileName );
724 if( GetFileAttributes( psz_path ) & FILE_ATTRIBUTE_DIRECTORY )
726 AllocatePluginDir( p_this, psz_path, i_maxdepth - 1 );
728 else if( i_len > strlen( LIBEXT )
732 /* We only load files ending with LIBEXT */
733 && !strncasecmp( psz_path + strlen( psz_path)
735 LIBEXT, strlen( LIBEXT ) ) )
738 AllocatePluginFile( p_this, psz_path );
741 while( FindNextFile( handle, &finddata ) );
743 /* Close the directory */
747 dir = opendir( psz_dir );
753 i_dirlen = strlen( psz_dir );
755 /* Parse the directory and try to load all files it contains. */
756 while( (file = readdir( dir )) )
761 /* Skip ".", ".." and anything starting with "." */
762 if( !*file->d_name || *file->d_name == '.' )
767 i_len = strlen( file->d_name );
768 psz_file = malloc( i_dirlen + 1 + i_len + 1 );
770 sprintf( psz_file, "%s\\%s", psz_dir, file->d_name );
772 sprintf( psz_file, "%s/%s", psz_dir, file->d_name );
775 if( !stat( psz_file, &statbuf ) && statbuf.st_mode & S_IFDIR )
777 AllocatePluginDir( p_this, psz_file, i_maxdepth - 1 );
779 else if( i_len > strlen( LIBEXT )
780 /* We only load files ending with LIBEXT */
781 && !strncasecmp( file->d_name + i_len - strlen( LIBEXT ),
782 LIBEXT, strlen( LIBEXT ) ) )
784 AllocatePluginFile( p_this, psz_file );
790 /* Close the directory */
796 /*****************************************************************************
797 * AllocatePluginFile: load a module into memory and initialize it.
798 *****************************************************************************
799 * This function loads a dynamically loadable module and allocates a structure
800 * for its information data. The module can then be handled by module_Need
801 * and module_Unneed. It can be removed by DeleteModule.
802 *****************************************************************************/
803 static int AllocatePluginFile( vlc_object_t * p_this, MYCHAR * psz_file )
806 module_handle_t handle;
809 char psz_filename[MAX_PATH];
810 WideCharToMultiByte( CP_ACP, WC_DEFAULTCHAR, psz_file, -1,
811 psz_filename, MAX_PATH, NULL, NULL );
813 char * psz_filename = psz_file;
816 /* Try to dynamically load the module. */
817 if( module_load( psz_file, &handle ) )
819 char psz_buffer[256];
821 /* The plugin module couldn't be opened */
822 msg_Warn( p_this, "cannot open `%s' (%s)",
823 psz_filename, module_error( psz_buffer ) );
827 /* Now that we have successfully loaded the module, we can
828 * allocate a structure for it */
829 p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
830 if( p_module == NULL )
832 msg_Err( p_this, "out of memory" );
833 module_unload( handle );
837 /* We need to fill these since they may be needed by CallEntry() */
838 p_module->psz_filename = psz_filename;
839 p_module->handle = handle;
840 p_module->p_symbols = &p_this->p_libvlc->p_module_bank->symbols;
842 /* Initialize the module: fill p_module->psz_object_name, default config */
843 if( CallEntry( p_module ) != 0 )
845 /* We couldn't call module_init() */
846 vlc_object_destroy( p_module );
847 module_unload( handle );
851 DupModule( p_module );
852 p_module->psz_filename = strdup( p_module->psz_filename );
853 p_module->psz_longname = strdup( p_module->psz_longname );
855 /* Everything worked fine ! The module is ready to be added to the list. */
856 p_module->b_builtin = VLC_FALSE;
858 /* msg_Dbg( p_this, "plugin \"%s\", %s",
859 p_module->psz_object_name, p_module->psz_longname ); */
861 vlc_object_attach( p_module, p_this->p_libvlc->p_module_bank );
866 /*****************************************************************************
867 * DupModule: make a plugin module standalone.
868 *****************************************************************************
869 * This function duplicates all strings in the module, so that the dynamic
870 * object can be unloaded. It acts recursively on submodules.
871 *****************************************************************************/
872 static void DupModule( module_t *p_module )
877 for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
879 *pp_shortcut = strdup( *pp_shortcut );
882 /* We strdup() these entries so that they are still valid when the
883 * module is unloaded. */
884 p_module->psz_object_name = strdup( p_module->psz_object_name );
885 p_module->psz_capability = strdup( p_module->psz_capability );
887 if( p_module->psz_program != NULL )
889 p_module->psz_program = strdup( p_module->psz_program );
892 for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
894 DupModule( (module_t*)p_module->pp_children[ i_submodule ] );
898 /*****************************************************************************
899 * UndupModule: free a duplicated module.
900 *****************************************************************************
901 * This function frees the allocations done in DupModule().
902 *****************************************************************************/
903 static void UndupModule( module_t *p_module )
908 for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
910 UndupModule( (module_t*)p_module->pp_children[ i_submodule ] );
913 for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
915 free( *pp_shortcut );
918 free( p_module->psz_object_name );
919 free( p_module->psz_capability );
921 if( p_module->psz_program != NULL )
923 free( p_module->psz_program );
927 #endif /* HAVE_DYNAMIC_PLUGINS */
929 /*****************************************************************************
930 * AllocateBuiltinModule: initialize a builtin module.
931 *****************************************************************************
932 * This function registers a builtin module and allocates a structure
933 * for its information data. The module can then be handled by module_Need
934 * and module_Unneed. It can be removed by DeleteModule.
935 *****************************************************************************/
936 static int AllocateBuiltinModule( vlc_object_t * p_this,
937 int ( *pf_entry ) ( module_t * ) )
941 /* Now that we have successfully loaded the module, we can
942 * allocate a structure for it */
943 p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
944 if( p_module == NULL )
946 msg_Err( p_this, "out of memory" );
950 /* Initialize the module : fill p_module->psz_object_name, etc. */
951 if( pf_entry( p_module ) != 0 )
953 /* With a well-written module we shouldn't have to print an
954 * additional error message here, but just make sure. */
955 msg_Err( p_this, "failed calling entry point in builtin module" );
956 vlc_object_destroy( p_module );
960 /* Everything worked fine ! The module is ready to be added to the list. */
961 p_module->b_builtin = VLC_TRUE;
963 /* msg_Dbg( p_this, "builtin \"%s\", %s",
964 p_module->psz_object_name, p_module->psz_longname ); */
966 vlc_object_attach( p_module, p_this->p_libvlc->p_module_bank );
971 /*****************************************************************************
972 * DeleteModule: delete a module and its structure.
973 *****************************************************************************
974 * This function can only be called if the module isn't being used.
975 *****************************************************************************/
976 static int DeleteModule( module_t * p_module )
978 vlc_object_detach( p_module );
980 /* We free the structures that we strdup()ed in Allocate*Module(). */
981 #ifdef HAVE_DYNAMIC_PLUGINS
982 if( !p_module->b_builtin )
984 if( p_module->b_unloadable )
986 module_unload( p_module->handle );
988 UndupModule( p_module );
989 free( p_module->psz_filename );
990 free( p_module->psz_longname );
994 /* Free and detach the object's children */
995 while( p_module->i_children )
997 vlc_object_t *p_this = p_module->pp_children[0];
998 vlc_object_detach( p_this );
999 vlc_object_destroy( p_this );
1002 config_Free( p_module );
1003 vlc_object_destroy( p_module );
1008 #ifdef HAVE_DYNAMIC_PLUGINS
1009 /*****************************************************************************
1010 * CallEntry: call an entry point.
1011 *****************************************************************************
1012 * This function calls a symbol given its name and a module structure. The
1013 * symbol MUST refer to a function returning int and taking a module_t* as
1015 *****************************************************************************/
1016 static int CallEntry( module_t * p_module )
1018 static char *psz_name = "vlc_entry" MODULE_SUFFIX;
1019 int (* pf_symbol) ( module_t * p_module );
1021 /* Try to resolve the symbol */
1022 pf_symbol = (int (*)(module_t *)) module_getsymbol( p_module->handle,
1025 if( pf_symbol == NULL )
1027 char psz_buffer[256];
1029 /* We couldn't load the symbol */
1030 msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s' (%s)",
1031 psz_name, p_module->psz_filename,
1032 module_error( psz_buffer ) );
1036 /* We can now try to call the symbol */
1037 if( pf_symbol( p_module ) != 0 )
1039 /* With a well-written module we shouldn't have to print an
1040 * additional error message here, but just make sure. */
1041 msg_Err( p_module, "failed calling symbol \"%s\" in file `%s'",
1042 psz_name, p_module->psz_filename );
1046 /* Everything worked fine, we can return */
1049 #endif /* HAVE_DYNAMIC_PLUGINS */