1 /*****************************************************************************
2 * modules.c : Builtin and plugin modules management functions
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: modules.c,v 1.121 2003/06/23 16:09:13 gbazin 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
72 #include "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"
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"
93 #if defined( UNDER_CE )
94 # define MYCHAR wchar_t
99 #ifdef HAVE_DYNAMIC_PLUGINS
100 # include "modules_plugin.h"
103 #if defined( UNDER_CE )
104 # include "modules_builtin_evc.h"
105 #elif defined( _MSC_VER )
106 # include "modules_builtin_msvc.h"
108 # include "modules_builtin.h"
111 /*****************************************************************************
113 *****************************************************************************/
114 #ifdef HAVE_DYNAMIC_PLUGINS
115 static void AllocateAllPlugins ( vlc_object_t * );
116 static void AllocatePluginDir ( vlc_object_t *, const MYCHAR *, int );
117 static int AllocatePluginFile ( vlc_object_t *, MYCHAR * );
119 static int AllocateBuiltinModule( vlc_object_t *, int ( * ) ( module_t * ) );
120 static int DeleteModule ( module_t * );
121 #ifdef HAVE_DYNAMIC_PLUGINS
122 static void DupModule ( module_t * );
123 static void UndupModule ( module_t * );
124 static int CallEntry ( module_t * );
127 /*****************************************************************************
128 * module_InitBank: create the module bank.
129 *****************************************************************************
130 * This function creates a module bank structure which will be filled later
131 * on with all the modules found.
132 *****************************************************************************/
133 void __module_InitBank( vlc_object_t *p_this )
135 module_bank_t *p_bank;
137 p_bank = vlc_object_create( p_this, sizeof(module_bank_t) );
138 p_bank->psz_object_name = "module bank";
141 * Store the symbols to be exported
143 #ifdef HAVE_DYNAMIC_PLUGINS
144 STORE_SYMBOLS( &p_bank->symbols );
147 /* Everything worked, attach the object */
148 p_this->p_libvlc->p_module_bank = p_bank;
149 vlc_object_attach( p_bank, p_this->p_libvlc );
154 /*****************************************************************************
155 * module_ResetBank: reset the module bank.
156 *****************************************************************************
157 * This function resets the module bank by unloading all unused plugin
159 *****************************************************************************/
160 void __module_ResetBank( vlc_object_t *p_this )
162 msg_Err( p_this, "FIXME: module_ResetBank unimplemented" );
166 /*****************************************************************************
167 * module_EndBank: empty the module bank.
168 *****************************************************************************
169 * This function unloads all unused plugin modules and empties the module
170 * bank in case of success.
171 *****************************************************************************/
172 void __module_EndBank( vlc_object_t *p_this )
176 vlc_object_detach( p_this->p_libvlc->p_module_bank );
178 while( p_this->p_libvlc->p_module_bank->i_children )
180 p_next = (module_t *)p_this->p_libvlc->p_module_bank->pp_children[0];
182 if( DeleteModule( p_next ) )
184 /* Module deletion failed */
185 msg_Err( p_this, "module \"%s\" can't be removed, trying harder",
186 p_next->psz_object_name );
188 /* We just free the module by hand. Niahahahahaha. */
189 vlc_object_detach( p_next );
190 vlc_object_destroy( p_next );
194 vlc_object_destroy( p_this->p_libvlc->p_module_bank );
199 /*****************************************************************************
200 * module_LoadMain: load the main program info into the module bank.
201 *****************************************************************************
202 * This function fills the module bank structure with the main module infos.
203 * This is very useful as it will allow us to consider the main program just
204 * as another module, and for instance the configuration options of main will
205 * be available in the module bank structure just as for every other module.
206 *****************************************************************************/
207 void __module_LoadMain( vlc_object_t *p_this )
209 AllocateBuiltinModule( p_this, vlc_entry__main );
212 /*****************************************************************************
213 * module_LoadBuiltins: load all modules which we built with.
214 *****************************************************************************
215 * This function fills the module bank structure with the builtin modules.
216 *****************************************************************************/
217 void __module_LoadBuiltins( vlc_object_t * p_this )
219 msg_Dbg( p_this, "checking builtin modules" );
220 ALLOCATE_ALL_BUILTINS();
223 /*****************************************************************************
224 * module_LoadPlugins: load all plugin modules we can find.
225 *****************************************************************************
226 * This function fills the module bank structure with the plugin modules.
227 *****************************************************************************/
228 void __module_LoadPlugins( vlc_object_t * p_this )
230 #ifdef HAVE_DYNAMIC_PLUGINS
231 msg_Dbg( p_this, "checking plugin modules" );
232 AllocateAllPlugins( p_this );
236 /*****************************************************************************
237 * module_Need: return the best module function, given a capability list.
238 *****************************************************************************
239 * This function returns the module that best fits the asked capabilities.
240 *****************************************************************************/
241 module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
242 const char *psz_name )
244 typedef struct module_list_t module_list_t;
250 module_list_t *p_next;
253 module_list_t *p_list, *p_first, *p_tmp;
256 int i_which_module, i_index = 0;
257 vlc_bool_t b_intf = VLC_FALSE;
262 char *psz_shortcuts = NULL, *psz_var = NULL;
264 msg_Dbg( p_this, "looking for %s module", psz_capability );
266 /* Deal with variables */
267 if( psz_name && psz_name[0] == '$' )
269 psz_var = config_GetPsz( p_this, psz_name + 1 );
273 /* Count how many different shortcuts were asked for */
274 if( psz_name && *psz_name )
278 /* If the user wants none, give him none. */
279 if( !strcmp( psz_name, "none" ) )
281 if( psz_var ) free( psz_var );
286 psz_shortcuts = strdup( psz_name );
288 for( psz_parser = psz_shortcuts; *psz_parser; psz_parser++ )
290 if( *psz_parser == ',' )
298 /* Sort the modules and test them */
299 p_all = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
300 p_list = malloc( p_all->i_count * sizeof( module_list_t ) );
303 /* Parse the module list for capabilities and probe each of them */
304 for( i_which_module = 0; i_which_module < p_all->i_count; i_which_module++ )
306 module_t * p_submodule = NULL;
307 int i_shortcut_bonus = 0, i_submodule;
309 p_module = (module_t *)p_all->p_values[i_which_module].p_object;
311 /* Test that this module can do what we need */
312 if( strcmp( p_module->psz_capability, psz_capability ) )
314 for( i_submodule = 0;
315 i_submodule < p_module->i_children;
318 if( !strcmp( ((module_t*)p_module->pp_children[ i_submodule ])
319 ->psz_capability, psz_capability ) )
322 (module_t*)p_module->pp_children[ i_submodule ];
327 if( p_submodule == NULL )
332 p_module = p_submodule;
335 /* Test if we have the required CPU */
336 if( (p_module->i_cpu & p_this->p_libvlc->i_cpu) != p_module->i_cpu )
341 /* If we required a shortcut, check this plugin provides it. */
345 int i_dummy, i_short = i_shortcuts;
346 char *psz_name = psz_shortcuts;
348 /* Let's drop modules with a 0 score (unless they are
349 * explicitly requested) */
350 b_trash = !p_module->i_score;
354 /* If the last given shortcut is "none" and we couldn't
355 * find the module in the list of provided shortcuts,
356 * then kick the bastard out of here!!! */
357 if( (i_short == 1) && !strcmp(psz_name, "none") )
363 for( i_dummy = 0; p_module->pp_shortcuts[i_dummy]; i_dummy++ )
365 if( !strcmp( psz_name,
366 p_module->pp_shortcuts[i_dummy] ) )
370 i_shortcut_bonus = i_short * 10000;
375 if( i_shortcut_bonus )
377 /* We found it... remember ? */
381 /* Go to the next shortcut... This is so lame! */
395 /* If we didn't require a shortcut, trash zero-scored plugins */
396 else if( !p_module->i_score )
401 /* Special case: test if we requested a particular intf plugin */
402 if( p_module->psz_program
403 && !strcmp( p_module->psz_program,
404 p_this->p_vlc->psz_object_name ) )
408 /* Remove previous non-matching plugins */
415 /* This one doesn't match */
419 /* Store this new module */
420 p_list[ i_index ].p_module = p_module;
421 p_list[ i_index ].i_score = p_module->i_score + i_shortcut_bonus;
423 /* Add it to the modules-to-probe list */
426 p_list[ 0 ].p_next = NULL;
431 /* Ok, so at school you learned that quicksort is quick, and
432 * bubble sort sucks raw eggs. But that's when dealing with
433 * thousands of items. Here we have barely 50. */
434 module_list_t *p_newlist = p_first;
436 if( p_first->i_score < p_list[ i_index ].i_score )
438 p_list[ i_index ].p_next = p_first;
439 p_first = &p_list[ i_index ];
443 while( p_newlist->p_next != NULL &&
444 p_newlist->p_next->i_score >= p_list[ i_index ].i_score )
446 p_newlist = p_newlist->p_next;
449 p_list[ i_index ].p_next = p_newlist->p_next;
450 p_newlist->p_next = &p_list[ i_index ];
457 msg_Dbg( p_this, "probing %i candidate%s",
458 i_index, i_index == 1 ? "" : "s" );
460 /* Lock all candidate modules */
462 while( p_tmp != NULL )
464 vlc_object_yield( p_tmp->p_module );
465 p_tmp = p_tmp->p_next;
468 /* We can release the list, interesting modules were yielded */
469 vlc_list_release( p_all );
471 /* Parse the linked list and use the first successful module */
473 while( p_tmp != NULL )
475 if( p_tmp->p_module->pf_activate
476 && p_tmp->p_module->pf_activate( p_this ) == VLC_SUCCESS )
481 vlc_object_release( p_tmp->p_module );
482 p_tmp = p_tmp->p_next;
485 /* Store the locked module value */
488 p_module = p_tmp->p_module;
489 p_tmp = p_tmp->p_next;
496 /* Unlock the remaining modules */
497 while( p_tmp != NULL )
499 vlc_object_release( p_tmp->p_module );
500 p_tmp = p_tmp->p_next;
505 if( p_module != NULL )
507 msg_Dbg( p_module, "using %s module \"%s\"",
508 psz_capability, p_module->psz_object_name );
510 else if( p_first == NULL )
512 msg_Err( p_this, "no %s module matched \"%s\"",
513 psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
515 else if( psz_name != NULL && *psz_name )
517 msg_Warn( p_this, "no %s module matching \"%s\" could be loaded",
518 psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
523 free( psz_shortcuts );
531 /* Don't forget that the module is still locked */
535 /*****************************************************************************
536 * module_Unneed: decrease the usage count of a module.
537 *****************************************************************************
538 * This function must be called by the thread that called module_Need, to
539 * decrease the reference count and allow for hiding of modules.
540 *****************************************************************************/
541 void __module_Unneed( vlc_object_t * p_this, module_t * p_module )
543 /* Use the close method */
544 if( p_module->pf_deactivate )
546 p_module->pf_deactivate( p_this );
549 msg_Dbg( p_module, "unlocking module \"%s\"", p_module->psz_object_name );
551 vlc_object_release( p_module );
556 /*****************************************************************************
557 * Following functions are local.
558 *****************************************************************************/
560 /*****************************************************************************
561 * AllocateAllPlugins: load all plugin modules we can find.
562 *****************************************************************************/
563 #ifdef HAVE_DYNAMIC_PLUGINS
564 static void AllocateAllPlugins( vlc_object_t *p_this )
566 /* Yes, there are two NULLs because we replace one with "plugin-path". */
567 char * path[] = { "modules", PLUGIN_PATH, "plugins", NULL,
570 char ** ppsz_path = path;
572 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) \
573 || ( defined( WIN32 ) && !defined( UNDER_CE ) )
574 int i_vlclen = strlen( p_this->p_libvlc->psz_vlcpath );
575 vlc_bool_t b_notinroot;
578 #if defined( UNDER_CE )
579 wchar_t psz_dir[MAX_PATH];
582 /* If the user provided a plugin path, we add it to the list */
583 path[ sizeof(path)/sizeof(char*) - 2 ] = config_GetPsz( p_this,
586 #if defined( WIN32 ) && !defined( UNDER_CE ) && !defined( _MSC_VER )
587 /* If there is no 'plugins' nor 'modules' subdirectory, the user may have
588 * screwed up the unzipping stage, so we look into '.' instead */
589 if( !opendir( "plugins" ) && !opendir( "modules" )
590 && !strcmp( *ppsz_path, "modules" ) )
596 for( ; *ppsz_path != NULL ; ppsz_path++ )
598 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) \
599 || ( defined( WIN32 ) && !defined( UNDER_CE ) )
600 /* Store strlen(*ppsz_path) for later use. */
601 int i_dirlen = strlen( *ppsz_path );
603 b_notinroot = VLC_FALSE;
604 /* Under BeOS, we need to add beos_GetProgramPath() to access
605 * files under the current directory */
607 if( i_dirlen < 3 || (*ppsz_path)[3] != '\\' )
609 if( (*ppsz_path)[0] != '/' )
612 i_dirlen += i_vlclen + 2;
613 b_notinroot = VLC_TRUE;
615 psz_fullpath = malloc( i_dirlen );
616 if( psz_fullpath == NULL )
621 sprintf( psz_fullpath, "%s\\%s",
622 p_this->p_libvlc->psz_vlcpath, *ppsz_path );
624 sprintf( psz_fullpath, "%s/%s",
625 p_this->p_libvlc->psz_vlcpath, *ppsz_path );
631 psz_fullpath = *ppsz_path;
634 msg_Dbg( p_this, "recursively browsing `%s'", psz_fullpath );
636 /* Don't go deeper than 5 subdirectories */
637 #if defined( UNDER_CE )
638 MultiByteToWideChar( CP_ACP, 0, psz_fullpath, -1, psz_dir, MAX_PATH );
639 AllocatePluginDir( p_this, psz_dir, 5 );
641 AllocatePluginDir( p_this, psz_fullpath, 5 );
644 #if defined( SYS_BEOS ) || defined( SYS_DARWIN )
647 free( psz_fullpath );
652 /* Free plugin-path */
653 if( path[ sizeof(path)/sizeof(char*) - 2 ] )
654 free( path[ sizeof(path)/sizeof(char*) - 2 ] );
655 path[ sizeof(path)/sizeof(char*) - 2 ] = NULL;
658 /*****************************************************************************
659 * AllocatePluginDir: recursively parse a directory to look for plugins
660 *****************************************************************************/
661 static void AllocatePluginDir( vlc_object_t *p_this, const MYCHAR *psz_dir,
664 #if defined( UNDER_CE ) || defined( _MSC_VER )
666 MYCHAR psz_path[MAX_PATH + 256];
668 char psz_path[MAX_PATH + 256];
670 WIN32_FIND_DATA finddata;
677 struct dirent * file;
685 #if defined( UNDER_CE ) || defined( _MSC_VER )
686 rc = GetFileAttributes( psz_dir );
687 if( !(rc & FILE_ATTRIBUTE_DIRECTORY) )
689 /* Not a directory */
693 /* Parse all files in the directory */
695 swprintf( psz_path, L"%s\\*.*", psz_dir );
697 sprintf( psz_path, "%s\\*.*", psz_dir );
699 handle = FindFirstFile( psz_path, &finddata );
700 if( handle == INVALID_HANDLE_VALUE )
702 /* Empty directory */
706 /* Parse the directory and try to load all files it contains. */
710 unsigned int i_len = wcslen( finddata.cFileName );
711 swprintf( psz_path, L"%s\\%s", psz_dir, finddata.cFileName );
713 unsigned int i_len = strlen( finddata.cFileName );
714 /* Skip ".", ".." and anything starting with "." */
715 if( !*finddata.cFileName || *finddata.cFileName == '.' )
717 if( !FindNextFile( handle, &finddata ) ) break;
720 sprintf( psz_path, "%s\\%s", psz_dir, finddata.cFileName );
723 if( GetFileAttributes( psz_path ) & FILE_ATTRIBUTE_DIRECTORY )
725 AllocatePluginDir( p_this, psz_path, i_maxdepth - 1 );
727 else if( i_len > strlen( LIBEXT )
731 /* We only load files ending with LIBEXT */
732 && !strncasecmp( psz_path + strlen( psz_path)
734 LIBEXT, strlen( LIBEXT ) ) )
737 AllocatePluginFile( p_this, psz_path );
740 while( FindNextFile( handle, &finddata ) );
742 /* Close the directory */
746 dir = opendir( psz_dir );
752 i_dirlen = strlen( psz_dir );
754 /* Parse the directory and try to load all files it contains. */
755 while( (file = readdir( dir )) )
760 /* Skip ".", ".." and anything starting with "." */
761 if( !*file->d_name || *file->d_name == '.' )
766 i_len = strlen( file->d_name );
767 psz_file = malloc( i_dirlen + 1 + i_len + 1 );
769 sprintf( psz_file, "%s\\%s", psz_dir, file->d_name );
771 sprintf( psz_file, "%s/%s", psz_dir, file->d_name );
774 if( !stat( psz_file, &statbuf ) && statbuf.st_mode & S_IFDIR )
776 AllocatePluginDir( p_this, psz_file, i_maxdepth - 1 );
778 else if( i_len > strlen( LIBEXT )
779 /* We only load files ending with LIBEXT */
780 && !strncasecmp( file->d_name + i_len - strlen( LIBEXT ),
781 LIBEXT, strlen( LIBEXT ) ) )
783 AllocatePluginFile( p_this, psz_file );
789 /* Close the directory */
795 /*****************************************************************************
796 * AllocatePluginFile: load a module into memory and initialize it.
797 *****************************************************************************
798 * This function loads a dynamically loadable module and allocates a structure
799 * for its information data. The module can then be handled by module_Need
800 * and module_Unneed. It can be removed by DeleteModule.
801 *****************************************************************************/
802 static int AllocatePluginFile( vlc_object_t * p_this, MYCHAR * psz_file )
805 module_handle_t handle;
808 char psz_filename[MAX_PATH];
809 WideCharToMultiByte( CP_ACP, WC_DEFAULTCHAR, psz_file, -1,
810 psz_filename, MAX_PATH, NULL, NULL );
812 char * psz_filename = psz_file;
815 /* Try to dynamically load the module. */
816 if( module_load( psz_file, &handle ) )
818 char psz_buffer[256];
820 /* The plugin module couldn't be opened */
821 msg_Warn( p_this, "cannot open `%s' (%s)",
822 psz_filename, module_error( psz_buffer ) );
826 /* Now that we have successfully loaded the module, we can
827 * allocate a structure for it */
828 p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
829 if( p_module == NULL )
831 msg_Err( p_this, "out of memory" );
832 module_unload( handle );
836 /* We need to fill these since they may be needed by CallEntry() */
837 p_module->psz_filename = psz_filename;
838 p_module->handle = handle;
839 p_module->p_symbols = &p_this->p_libvlc->p_module_bank->symbols;
841 /* Initialize the module: fill p_module->psz_object_name, default config */
842 if( CallEntry( p_module ) != 0 )
844 /* We couldn't call module_init() */
845 vlc_object_destroy( p_module );
846 module_unload( handle );
850 DupModule( p_module );
851 p_module->psz_filename = strdup( p_module->psz_filename );
852 p_module->psz_longname = strdup( p_module->psz_longname );
854 /* Everything worked fine ! The module is ready to be added to the list. */
855 p_module->b_builtin = VLC_FALSE;
857 /* msg_Dbg( p_this, "plugin \"%s\", %s",
858 p_module->psz_object_name, p_module->psz_longname ); */
860 vlc_object_attach( p_module, p_this->p_libvlc->p_module_bank );
865 /*****************************************************************************
866 * DupModule: make a plugin module standalone.
867 *****************************************************************************
868 * This function duplicates all strings in the module, so that the dynamic
869 * object can be unloaded. It acts recursively on submodules.
870 *****************************************************************************/
871 static void DupModule( module_t *p_module )
876 for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
878 *pp_shortcut = strdup( *pp_shortcut );
881 /* We strdup() these entries so that they are still valid when the
882 * module is unloaded. */
883 p_module->psz_object_name = strdup( p_module->psz_object_name );
884 p_module->psz_capability = strdup( p_module->psz_capability );
886 if( p_module->psz_program != NULL )
888 p_module->psz_program = strdup( p_module->psz_program );
891 for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
893 DupModule( (module_t*)p_module->pp_children[ i_submodule ] );
897 /*****************************************************************************
898 * UndupModule: free a duplicated module.
899 *****************************************************************************
900 * This function frees the allocations done in DupModule().
901 *****************************************************************************/
902 static void UndupModule( module_t *p_module )
907 for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
909 UndupModule( (module_t*)p_module->pp_children[ i_submodule ] );
912 for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
914 free( *pp_shortcut );
917 free( p_module->psz_object_name );
918 free( p_module->psz_capability );
920 if( p_module->psz_program != NULL )
922 free( p_module->psz_program );
926 #endif /* HAVE_DYNAMIC_PLUGINS */
928 /*****************************************************************************
929 * AllocateBuiltinModule: initialize a builtin module.
930 *****************************************************************************
931 * This function registers a builtin module and allocates a structure
932 * for its information data. The module can then be handled by module_Need
933 * and module_Unneed. It can be removed by DeleteModule.
934 *****************************************************************************/
935 static int AllocateBuiltinModule( vlc_object_t * p_this,
936 int ( *pf_entry ) ( module_t * ) )
940 /* Now that we have successfully loaded the module, we can
941 * allocate a structure for it */
942 p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
943 if( p_module == NULL )
945 msg_Err( p_this, "out of memory" );
949 /* Initialize the module : fill p_module->psz_object_name, etc. */
950 if( pf_entry( p_module ) != 0 )
952 /* With a well-written module we shouldn't have to print an
953 * additional error message here, but just make sure. */
954 msg_Err( p_this, "failed calling entry point in builtin module" );
955 vlc_object_destroy( p_module );
959 /* Everything worked fine ! The module is ready to be added to the list. */
960 p_module->b_builtin = VLC_TRUE;
962 /* msg_Dbg( p_this, "builtin \"%s\", %s",
963 p_module->psz_object_name, p_module->psz_longname ); */
965 vlc_object_attach( p_module, p_this->p_libvlc->p_module_bank );
970 /*****************************************************************************
971 * DeleteModule: delete a module and its structure.
972 *****************************************************************************
973 * This function can only be called if the module isn't being used.
974 *****************************************************************************/
975 static int DeleteModule( module_t * p_module )
977 vlc_object_detach( p_module );
979 /* We free the structures that we strdup()ed in Allocate*Module(). */
980 #ifdef HAVE_DYNAMIC_PLUGINS
981 if( !p_module->b_builtin )
983 if( p_module->b_unloadable )
985 module_unload( p_module->handle );
987 UndupModule( p_module );
988 free( p_module->psz_filename );
989 free( p_module->psz_longname );
993 /* Free and detach the object's children */
994 while( p_module->i_children )
996 vlc_object_t *p_this = p_module->pp_children[0];
997 vlc_object_detach( p_this );
998 vlc_object_destroy( p_this );
1001 config_Free( p_module );
1002 vlc_object_destroy( p_module );
1007 #ifdef HAVE_DYNAMIC_PLUGINS
1008 /*****************************************************************************
1009 * CallEntry: call an entry point.
1010 *****************************************************************************
1011 * This function calls a symbol given its name and a module structure. The
1012 * symbol MUST refer to a function returning int and taking a module_t* as
1014 *****************************************************************************/
1015 static int CallEntry( module_t * p_module )
1017 static char *psz_name = "vlc_entry" MODULE_SUFFIX;
1018 int (* pf_symbol) ( module_t * p_module );
1020 /* Try to resolve the symbol */
1021 pf_symbol = (int (*)(module_t *)) module_getsymbol( p_module->handle,
1024 if( pf_symbol == NULL )
1026 char psz_buffer[256];
1028 /* We couldn't load the symbol */
1029 msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s' (%s)",
1030 psz_name, p_module->psz_filename,
1031 module_error( psz_buffer ) );
1035 /* We can now try to call the symbol */
1036 if( pf_symbol( p_module ) != 0 )
1038 /* With a well-written module we shouldn't have to print an
1039 * additional error message here, but just make sure. */
1040 msg_Err( p_module, "failed calling symbol \"%s\" in file `%s'",
1041 psz_name, p_module->psz_filename );
1045 /* Everything worked fine, we can return */
1048 #endif /* HAVE_DYNAMIC_PLUGINS */