1 /*****************************************************************************
2 * modules.c : Builtin and plugin modules management functions
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: modules.c,v 1.129 2003/08/23 14:14:01 hartman 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"
82 #include "vlc_video.h"
83 #include "video_output.h"
84 #include "vout_synchro.h"
86 #include "audio_output.h"
87 #include "aout_internal.h"
89 #include "stream_output.h"
90 /*#include "announce.h"*/
96 #if defined( UNDER_CE )
97 # define MYCHAR wchar_t
102 #ifdef HAVE_DYNAMIC_PLUGINS
103 # include "modules_plugin.h"
106 #if defined( UNDER_CE )
107 # include "modules_builtin_evc.h"
108 #elif defined( _MSC_VER )
109 # include "modules_builtin_msvc.h"
111 # include "modules_builtin.h"
114 /*****************************************************************************
116 *****************************************************************************/
117 #ifdef HAVE_DYNAMIC_PLUGINS
118 static void AllocateAllPlugins ( vlc_object_t * );
119 static void AllocatePluginDir ( vlc_object_t *, const MYCHAR *, int );
120 static int AllocatePluginFile ( vlc_object_t *, MYCHAR * );
122 static int AllocateBuiltinModule( vlc_object_t *, int ( * ) ( module_t * ) );
123 static int DeleteModule ( module_t * );
124 #ifdef HAVE_DYNAMIC_PLUGINS
125 static void DupModule ( module_t * );
126 static void UndupModule ( module_t * );
127 static int CallEntry ( module_t * );
130 /*****************************************************************************
131 * module_InitBank: create the module bank.
132 *****************************************************************************
133 * This function creates a module bank structure which will be filled later
134 * on with all the modules found.
135 *****************************************************************************/
136 void __module_InitBank( vlc_object_t *p_this )
138 module_bank_t *p_bank;
140 p_bank = vlc_object_create( p_this, sizeof(module_bank_t) );
141 p_bank->psz_object_name = "module bank";
144 * Store the symbols to be exported
146 #ifdef HAVE_DYNAMIC_PLUGINS
147 STORE_SYMBOLS( &p_bank->symbols );
150 /* Everything worked, attach the object */
151 p_this->p_libvlc->p_module_bank = p_bank;
152 vlc_object_attach( p_bank, p_this->p_libvlc );
157 /*****************************************************************************
158 * module_ResetBank: reset the module bank.
159 *****************************************************************************
160 * This function resets the module bank by unloading all unused plugin
162 *****************************************************************************/
163 void __module_ResetBank( vlc_object_t *p_this )
165 msg_Err( p_this, "FIXME: module_ResetBank unimplemented" );
169 /*****************************************************************************
170 * module_EndBank: empty the module bank.
171 *****************************************************************************
172 * This function unloads all unused plugin modules and empties the module
173 * bank in case of success.
174 *****************************************************************************/
175 void __module_EndBank( vlc_object_t *p_this )
179 vlc_object_detach( p_this->p_libvlc->p_module_bank );
181 while( p_this->p_libvlc->p_module_bank->i_children )
183 p_next = (module_t *)p_this->p_libvlc->p_module_bank->pp_children[0];
185 if( DeleteModule( p_next ) )
187 /* Module deletion failed */
188 msg_Err( p_this, "module \"%s\" can't be removed, trying harder",
189 p_next->psz_object_name );
191 /* We just free the module by hand. Niahahahahaha. */
192 vlc_object_detach( p_next );
193 vlc_object_destroy( p_next );
197 vlc_object_destroy( p_this->p_libvlc->p_module_bank );
202 /*****************************************************************************
203 * module_LoadMain: load the main program info into the module bank.
204 *****************************************************************************
205 * This function fills the module bank structure with the main module infos.
206 * This is very useful as it will allow us to consider the main program just
207 * as another module, and for instance the configuration options of main will
208 * be available in the module bank structure just as for every other module.
209 *****************************************************************************/
210 void __module_LoadMain( vlc_object_t *p_this )
212 AllocateBuiltinModule( p_this, vlc_entry__main );
215 /*****************************************************************************
216 * module_LoadBuiltins: load all modules which we built with.
217 *****************************************************************************
218 * This function fills the module bank structure with the builtin modules.
219 *****************************************************************************/
220 void __module_LoadBuiltins( vlc_object_t * p_this )
222 msg_Dbg( p_this, "checking builtin modules" );
223 ALLOCATE_ALL_BUILTINS();
226 /*****************************************************************************
227 * module_LoadPlugins: load all plugin modules we can find.
228 *****************************************************************************
229 * This function fills the module bank structure with the plugin modules.
230 *****************************************************************************/
231 void __module_LoadPlugins( vlc_object_t * p_this )
233 #ifdef HAVE_DYNAMIC_PLUGINS
234 msg_Dbg( p_this, "checking plugin modules" );
235 AllocateAllPlugins( p_this );
239 /*****************************************************************************
240 * module_Need: return the best module function, given a capability list.
241 *****************************************************************************
242 * This function returns the module that best fits the asked capabilities.
243 *****************************************************************************/
244 module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
245 const char *psz_name )
247 typedef struct module_list_t module_list_t;
253 module_list_t *p_next;
256 module_list_t *p_list, *p_first, *p_tmp;
259 int i_which_module, i_index = 0;
260 vlc_bool_t b_intf = VLC_FALSE;
265 char *psz_shortcuts = NULL, *psz_var = NULL;
267 msg_Dbg( p_this, "looking for %s module", psz_capability );
269 /* Deal with variables */
270 if( psz_name && psz_name[0] == '$' )
272 psz_var = config_GetPsz( p_this, psz_name + 1 );
276 /* Count how many different shortcuts were asked for */
277 if( psz_name && *psz_name )
281 /* If the user wants none, give him none. */
282 if( !strcmp( psz_name, "none" ) )
284 if( psz_var ) free( psz_var );
289 psz_shortcuts = strdup( psz_name );
291 for( psz_parser = psz_shortcuts; *psz_parser; psz_parser++ )
293 if( *psz_parser == ',' )
301 /* Sort the modules and test them */
302 p_all = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
303 p_list = malloc( p_all->i_count * sizeof( module_list_t ) );
306 /* Parse the module list for capabilities and probe each of them */
307 for( i_which_module = 0; i_which_module < p_all->i_count; i_which_module++ )
309 module_t * p_submodule = NULL;
310 int i_shortcut_bonus = 0, i_submodule;
312 p_module = (module_t *)p_all->p_values[i_which_module].p_object;
314 /* Test that this module can do what we need */
315 if( strcmp( p_module->psz_capability, psz_capability ) )
317 for( i_submodule = 0;
318 i_submodule < p_module->i_children;
321 if( !strcmp( ((module_t*)p_module->pp_children[ i_submodule ])
322 ->psz_capability, psz_capability ) )
325 (module_t*)p_module->pp_children[ i_submodule ];
330 if( p_submodule == NULL )
335 p_module = p_submodule;
338 /* Test if we have the required CPU */
339 if( (p_module->i_cpu & p_this->p_libvlc->i_cpu) != p_module->i_cpu )
344 /* If we required a shortcut, check this plugin provides it. */
348 int i_dummy, i_short = i_shortcuts;
349 char *psz_name = psz_shortcuts;
351 /* Let's drop modules with a 0 score (unless they are
352 * explicitly requested) */
353 b_trash = !p_module->i_score;
357 /* If the last given shortcut is "none" and we couldn't
358 * find the module in the list of provided shortcuts,
359 * then kick the bastard out of here!!! */
360 if( (i_short == 1) && !strcmp(psz_name, "none") )
366 for( i_dummy = 0; p_module->pp_shortcuts[i_dummy]; i_dummy++ )
368 if( !strcmp( psz_name,
369 p_module->pp_shortcuts[i_dummy] ) )
373 i_shortcut_bonus = i_short * 10000;
378 if( i_shortcut_bonus )
380 /* We found it... remember ? */
384 /* Go to the next shortcut... This is so lame! */
398 /* If we didn't require a shortcut, trash zero-scored plugins */
399 else if( !p_module->i_score )
404 /* Special case: test if we requested a particular intf plugin */
405 if( !i_shortcuts && p_module->psz_program
406 && !strcmp( p_module->psz_program,
407 p_this->p_vlc->psz_object_name ) )
411 /* Remove previous non-matching plugins */
418 /* This one doesn't match */
422 /* Store this new module */
423 p_list[ i_index ].p_module = p_module;
424 p_list[ i_index ].i_score = p_module->i_score + i_shortcut_bonus;
426 /* Add it to the modules-to-probe list */
429 p_list[ 0 ].p_next = NULL;
434 /* Ok, so at school you learned that quicksort is quick, and
435 * bubble sort sucks raw eggs. But that's when dealing with
436 * thousands of items. Here we have barely 50. */
437 module_list_t *p_newlist = p_first;
439 if( p_first->i_score < p_list[ i_index ].i_score )
441 p_list[ i_index ].p_next = p_first;
442 p_first = &p_list[ i_index ];
446 while( p_newlist->p_next != NULL &&
447 p_newlist->p_next->i_score >= p_list[ i_index ].i_score )
449 p_newlist = p_newlist->p_next;
452 p_list[ i_index ].p_next = p_newlist->p_next;
453 p_newlist->p_next = &p_list[ i_index ];
460 msg_Dbg( p_this, "probing %i candidate%s",
461 i_index, i_index == 1 ? "" : "s" );
463 /* Lock all candidate modules */
465 while( p_tmp != NULL )
467 vlc_object_yield( p_tmp->p_module );
468 p_tmp = p_tmp->p_next;
471 /* We can release the list, interesting modules were yielded */
472 vlc_list_release( p_all );
474 /* Parse the linked list and use the first successful module */
476 while( p_tmp != NULL )
478 if( p_tmp->p_module->pf_activate
479 && p_tmp->p_module->pf_activate( p_this ) == VLC_SUCCESS )
484 vlc_object_release( p_tmp->p_module );
485 p_tmp = p_tmp->p_next;
488 /* Store the locked module value */
491 p_module = p_tmp->p_module;
492 p_tmp = p_tmp->p_next;
499 /* Unlock the remaining modules */
500 while( p_tmp != NULL )
502 vlc_object_release( p_tmp->p_module );
503 p_tmp = p_tmp->p_next;
508 if( p_module != NULL )
510 msg_Dbg( p_module, "using %s module \"%s\"",
511 psz_capability, p_module->psz_object_name );
513 else if( p_first == NULL )
515 msg_Err( p_this, "no %s module matched \"%s\"",
516 psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
518 else if( psz_name != NULL && *psz_name )
520 msg_Warn( p_this, "no %s module matching \"%s\" could be loaded",
521 psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
526 free( psz_shortcuts );
534 /* Don't forget that the module is still locked */
538 /*****************************************************************************
539 * module_Unneed: decrease the usage count of a module.
540 *****************************************************************************
541 * This function must be called by the thread that called module_Need, to
542 * decrease the reference count and allow for hiding of modules.
543 *****************************************************************************/
544 void __module_Unneed( vlc_object_t * p_this, module_t * p_module )
546 /* Use the close method */
547 if( p_module->pf_deactivate )
549 p_module->pf_deactivate( p_this );
552 msg_Dbg( p_module, "unlocking module \"%s\"", p_module->psz_object_name );
554 vlc_object_release( p_module );
559 /*****************************************************************************
560 * Following functions are local.
561 *****************************************************************************/
563 /*****************************************************************************
564 * AllocateAllPlugins: load all plugin modules we can find.
565 *****************************************************************************/
566 #ifdef HAVE_DYNAMIC_PLUGINS
567 static void AllocateAllPlugins( vlc_object_t *p_this )
569 /* Yes, there are two NULLs because we replace one with "plugin-path". */
570 char * path[] = { "modules", PLUGIN_PATH, "plugins", NULL,
573 char ** ppsz_path = path;
575 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) \
576 || ( defined( WIN32 ) && !defined( UNDER_CE ) )
577 int i_vlclen = strlen( p_this->p_libvlc->psz_vlcpath );
578 vlc_bool_t b_notinroot;
581 #if defined( UNDER_CE )
582 wchar_t psz_dir[MAX_PATH];
585 /* If the user provided a plugin path, we add it to the list */
586 path[ sizeof(path)/sizeof(char*) - 2 ] = config_GetPsz( p_this,
589 #if defined( WIN32 ) && !defined( UNDER_CE ) && !defined( _MSC_VER )
590 /* If there is no 'plugins' nor 'modules' subdirectory, the user may have
591 * screwed up the unzipping stage, so we look into '.' instead */
592 if( !opendir( "plugins" ) && !opendir( "modules" )
593 && !strcmp( *ppsz_path, "modules" ) )
599 for( ; *ppsz_path != NULL ; ppsz_path++ )
601 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) \
602 || ( defined( WIN32 ) && !defined( UNDER_CE ) )
603 /* Store strlen(*ppsz_path) for later use. */
604 int i_dirlen = strlen( *ppsz_path );
606 b_notinroot = VLC_FALSE;
607 /* Under BeOS, we need to add beos_GetProgramPath() to access
608 * files under the current directory */
610 if( i_dirlen < 3 || (*ppsz_path)[3] != '\\' )
612 if( (*ppsz_path)[0] != '/' )
615 i_dirlen += i_vlclen + 2;
616 b_notinroot = VLC_TRUE;
618 psz_fullpath = malloc( i_dirlen );
619 if( psz_fullpath == NULL )
624 sprintf( psz_fullpath, "%s\\%s",
625 p_this->p_libvlc->psz_vlcpath, *ppsz_path );
627 sprintf( psz_fullpath, "%s/%s",
628 p_this->p_libvlc->psz_vlcpath, *ppsz_path );
634 psz_fullpath = *ppsz_path;
637 msg_Dbg( p_this, "recursively browsing `%s'", psz_fullpath );
639 /* Don't go deeper than 5 subdirectories */
640 #if defined( UNDER_CE )
641 MultiByteToWideChar( CP_ACP, 0, psz_fullpath, -1, psz_dir, MAX_PATH );
642 AllocatePluginDir( p_this, psz_dir, 5 );
644 AllocatePluginDir( p_this, psz_fullpath, 5 );
647 #if defined( SYS_BEOS ) || defined( SYS_DARWIN )
650 free( psz_fullpath );
655 /* Free plugin-path */
656 if( path[ sizeof(path)/sizeof(char*) - 2 ] )
657 free( path[ sizeof(path)/sizeof(char*) - 2 ] );
658 path[ sizeof(path)/sizeof(char*) - 2 ] = NULL;
661 /*****************************************************************************
662 * AllocatePluginDir: recursively parse a directory to look for plugins
663 *****************************************************************************/
664 static void AllocatePluginDir( vlc_object_t *p_this, const MYCHAR *psz_dir,
667 #if defined( UNDER_CE ) || defined( _MSC_VER )
669 MYCHAR psz_path[MAX_PATH + 256];
671 char psz_path[MAX_PATH + 256];
673 WIN32_FIND_DATA finddata;
680 struct dirent * file;
688 #if defined( UNDER_CE ) || defined( _MSC_VER )
689 rc = GetFileAttributes( psz_dir );
690 if( !(rc & FILE_ATTRIBUTE_DIRECTORY) )
692 /* Not a directory */
696 /* Parse all files in the directory */
698 swprintf( psz_path, L"%s\\*.*", psz_dir );
700 sprintf( psz_path, "%s\\*.*", psz_dir );
702 handle = FindFirstFile( psz_path, &finddata );
703 if( handle == INVALID_HANDLE_VALUE )
705 /* Empty directory */
709 /* Parse the directory and try to load all files it contains. */
713 unsigned int i_len = wcslen( finddata.cFileName );
714 swprintf( psz_path, L"%s\\%s", psz_dir, finddata.cFileName );
716 unsigned int i_len = strlen( finddata.cFileName );
717 /* Skip ".", ".." and anything starting with "." */
718 if( !*finddata.cFileName || *finddata.cFileName == '.' )
720 if( !FindNextFile( handle, &finddata ) ) break;
723 sprintf( psz_path, "%s\\%s", psz_dir, finddata.cFileName );
726 if( GetFileAttributes( psz_path ) & FILE_ATTRIBUTE_DIRECTORY )
728 AllocatePluginDir( p_this, psz_path, i_maxdepth - 1 );
730 else if( i_len > strlen( LIBEXT )
734 /* We only load files ending with LIBEXT */
735 && !strncasecmp( psz_path + strlen( psz_path)
737 LIBEXT, strlen( LIBEXT ) ) )
740 AllocatePluginFile( p_this, psz_path );
743 while( FindNextFile( handle, &finddata ) );
745 /* Close the directory */
749 dir = opendir( psz_dir );
755 i_dirlen = strlen( psz_dir );
757 /* Parse the directory and try to load all files it contains. */
758 while( (file = readdir( dir )) )
763 /* Skip ".", ".." and anything starting with "." */
764 if( !*file->d_name || *file->d_name == '.' )
769 i_len = strlen( file->d_name );
770 psz_file = malloc( i_dirlen + 1 + i_len + 1 );
772 sprintf( psz_file, "%s\\%s", psz_dir, file->d_name );
774 sprintf( psz_file, "%s/%s", psz_dir, file->d_name );
777 if( !stat( psz_file, &statbuf ) && statbuf.st_mode & S_IFDIR )
779 AllocatePluginDir( p_this, psz_file, i_maxdepth - 1 );
781 else if( i_len > strlen( LIBEXT )
782 /* We only load files ending with LIBEXT */
783 && !strncasecmp( file->d_name + i_len - strlen( LIBEXT ),
784 LIBEXT, strlen( LIBEXT ) ) )
786 AllocatePluginFile( p_this, psz_file );
792 /* Close the directory */
798 /*****************************************************************************
799 * AllocatePluginFile: load a module into memory and initialize it.
800 *****************************************************************************
801 * This function loads a dynamically loadable module and allocates a structure
802 * for its information data. The module can then be handled by module_Need
803 * and module_Unneed. It can be removed by DeleteModule.
804 *****************************************************************************/
805 static int AllocatePluginFile( vlc_object_t * p_this, MYCHAR * psz_file )
808 module_handle_t handle;
811 char psz_filename[MAX_PATH];
812 WideCharToMultiByte( CP_ACP, WC_DEFAULTCHAR, psz_file, -1,
813 psz_filename, MAX_PATH, NULL, NULL );
815 char * psz_filename = psz_file;
818 /* Try to dynamically load the module. */
819 if( module_load( psz_file, &handle ) )
821 char psz_buffer[256];
823 /* The plugin module couldn't be opened */
824 msg_Warn( p_this, "cannot open `%s' (%s)",
825 psz_filename, module_error( psz_buffer ) );
829 /* Now that we have successfully loaded the module, we can
830 * allocate a structure for it */
831 p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
832 if( p_module == NULL )
834 msg_Err( p_this, "out of memory" );
835 module_unload( handle );
839 /* We need to fill these since they may be needed by CallEntry() */
840 p_module->psz_filename = psz_filename;
841 p_module->handle = handle;
842 p_module->p_symbols = &p_this->p_libvlc->p_module_bank->symbols;
844 /* Initialize the module: fill p_module->psz_object_name, default config */
845 if( CallEntry( p_module ) != 0 )
847 /* We couldn't call module_init() */
848 vlc_object_destroy( p_module );
849 module_unload( handle );
853 DupModule( p_module );
854 p_module->psz_filename = strdup( p_module->psz_filename );
855 p_module->psz_longname = strdup( p_module->psz_longname );
857 /* Everything worked fine ! The module is ready to be added to the list. */
858 p_module->b_builtin = VLC_FALSE;
860 /* msg_Dbg( p_this, "plugin \"%s\", %s",
861 p_module->psz_object_name, p_module->psz_longname ); */
863 vlc_object_attach( p_module, p_this->p_libvlc->p_module_bank );
868 /*****************************************************************************
869 * DupModule: make a plugin module standalone.
870 *****************************************************************************
871 * This function duplicates all strings in the module, so that the dynamic
872 * object can be unloaded. It acts recursively on submodules.
873 *****************************************************************************/
874 static void DupModule( module_t *p_module )
879 for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
881 *pp_shortcut = strdup( *pp_shortcut );
884 /* We strdup() these entries so that they are still valid when the
885 * module is unloaded. */
886 p_module->psz_object_name = strdup( p_module->psz_object_name );
887 p_module->psz_capability = strdup( p_module->psz_capability );
889 if( p_module->psz_program != NULL )
891 p_module->psz_program = strdup( p_module->psz_program );
894 for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
896 DupModule( (module_t*)p_module->pp_children[ i_submodule ] );
900 /*****************************************************************************
901 * UndupModule: free a duplicated module.
902 *****************************************************************************
903 * This function frees the allocations done in DupModule().
904 *****************************************************************************/
905 static void UndupModule( module_t *p_module )
910 for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
912 UndupModule( (module_t*)p_module->pp_children[ i_submodule ] );
915 for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
917 free( *pp_shortcut );
920 free( p_module->psz_object_name );
921 free( p_module->psz_capability );
923 if( p_module->psz_program != NULL )
925 free( p_module->psz_program );
929 #endif /* HAVE_DYNAMIC_PLUGINS */
931 /*****************************************************************************
932 * AllocateBuiltinModule: initialize a builtin module.
933 *****************************************************************************
934 * This function registers a builtin module and allocates a structure
935 * for its information data. The module can then be handled by module_Need
936 * and module_Unneed. It can be removed by DeleteModule.
937 *****************************************************************************/
938 static int AllocateBuiltinModule( vlc_object_t * p_this,
939 int ( *pf_entry ) ( module_t * ) )
943 /* Now that we have successfully loaded the module, we can
944 * allocate a structure for it */
945 p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
946 if( p_module == NULL )
948 msg_Err( p_this, "out of memory" );
952 /* Initialize the module : fill p_module->psz_object_name, etc. */
953 if( pf_entry( p_module ) != 0 )
955 /* With a well-written module we shouldn't have to print an
956 * additional error message here, but just make sure. */
957 msg_Err( p_this, "failed calling entry point in builtin module" );
958 vlc_object_destroy( p_module );
962 /* Everything worked fine ! The module is ready to be added to the list. */
963 p_module->b_builtin = VLC_TRUE;
965 /* msg_Dbg( p_this, "builtin \"%s\", %s",
966 p_module->psz_object_name, p_module->psz_longname ); */
968 vlc_object_attach( p_module, p_this->p_libvlc->p_module_bank );
973 /*****************************************************************************
974 * DeleteModule: delete a module and its structure.
975 *****************************************************************************
976 * This function can only be called if the module isn't being used.
977 *****************************************************************************/
978 static int DeleteModule( module_t * p_module )
980 vlc_object_detach( p_module );
982 /* We free the structures that we strdup()ed in Allocate*Module(). */
983 #ifdef HAVE_DYNAMIC_PLUGINS
984 if( !p_module->b_builtin )
986 if( p_module->b_unloadable )
988 module_unload( p_module->handle );
990 UndupModule( p_module );
991 free( p_module->psz_filename );
992 free( p_module->psz_longname );
996 /* Free and detach the object's children */
997 while( p_module->i_children )
999 vlc_object_t *p_this = p_module->pp_children[0];
1000 vlc_object_detach( p_this );
1001 vlc_object_destroy( p_this );
1004 config_Free( p_module );
1005 vlc_object_destroy( p_module );
1010 #ifdef HAVE_DYNAMIC_PLUGINS
1011 /*****************************************************************************
1012 * CallEntry: call an entry point.
1013 *****************************************************************************
1014 * This function calls a symbol given its name and a module structure. The
1015 * symbol MUST refer to a function returning int and taking a module_t* as
1017 *****************************************************************************/
1018 static int CallEntry( module_t * p_module )
1020 static char *psz_name = "vlc_entry" MODULE_SUFFIX;
1021 int (* pf_symbol) ( module_t * p_module );
1023 /* Try to resolve the symbol */
1024 pf_symbol = (int (*)(module_t *)) module_getsymbol( p_module->handle,
1027 if( pf_symbol == NULL )
1029 char psz_buffer[256];
1031 /* We couldn't load the symbol */
1032 msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s' (%s)",
1033 psz_name, p_module->psz_filename,
1034 module_error( psz_buffer ) );
1038 /* We can now try to call the symbol */
1039 if( pf_symbol( p_module ) != 0 )
1041 /* With a well-written module we shouldn't have to print an
1042 * additional error message here, but just make sure. */
1043 msg_Err( p_module, "failed calling symbol \"%s\" in file `%s'",
1044 psz_name, p_module->psz_filename );
1048 /* Everything worked fine, we can return */
1051 #endif /* HAVE_DYNAMIC_PLUGINS */