]> git.sesse.net Git - vlc/blobdiff - src/misc/modules.c
* include/video.h: renamed this file to vlc_video.h to avoid name collisions
[vlc] / src / misc / modules.c
index b85ae1294a4107418b6f6fcb4e127f6f383abf13..71c5a0f5bdabf57db3e2b11c994445922d53f617 100644 (file)
@@ -2,7 +2,7 @@
  * modules.c : Builtin and plugin modules management functions
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: modules.c,v 1.98 2002/10/14 16:46:56 sam Exp $
+ * $Id: modules.c,v 1.123 2003/06/26 12:19:59 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Ethan C. Baldridge <BaldridgeE@cadmus.com>
 
 #include <vlc/vlc.h>
 
-#include <dirent.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+#ifdef HAVE_DIRENT_H
+#   include <dirent.h>
+#elif defined( UNDER_CE )
+#   include <windows.h>                               /* GetFileAttributes() */
+#else
+#   include "../extras/dirent.h"
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+#   include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#   include <sys/stat.h>
+#endif
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #endif
@@ -48,6 +59,8 @@
 #elif defined(HAVE_IMAGE_H)                                          /* BeOS */
 #   include <image.h>
 #   define HAVE_DYNAMIC_PLUGINS
+#elif defined(UNDER_CE)
+#   define HAVE_DYNAMIC_PLUGINS
 #elif defined(WIN32)
 #   define HAVE_DYNAMIC_PLUGINS
 #else
@@ -55,9 +68,8 @@
 #endif
 
 #include "error.h"
-#include "netutils.h"
 
-#include "interface.h"
+#include "vlc_interface.h"
 #include "vlc_playlist.h"
 #include "intf_eject.h"
 
 #include "input_ext-dec.h"
 #include "input_ext-plugins.h"
 
-#include "video.h"
+#include "vlc_video.h"
 #include "video_output.h"
+#include "vout_synchro.h"
 
 #include "audio_output.h"
 #include "aout_internal.h"
 
 #include "stream_output.h"
+#include "announce.h"
 
 #include "iso_lang.h"
 
+#if defined( UNDER_CE )
+#   define MYCHAR wchar_t
+#else
+#   define MYCHAR char
+#endif
+
 #ifdef HAVE_DYNAMIC_PLUGINS
 #   include "modules_plugin.h"
 #endif
 
-#if !defined( _MSC_VER )
-#    include "modules_builtin.h"
-#else
+#if defined( UNDER_CE )
+#    include "modules_builtin_evc.h"
+#elif defined( _MSC_VER )
 #    include "modules_builtin_msvc.h"
+#else
+#    include "modules_builtin.h"
 #endif
 
 /*****************************************************************************
  *****************************************************************************/
 #ifdef HAVE_DYNAMIC_PLUGINS
 static void AllocateAllPlugins   ( vlc_object_t * );
-static void AllocatePluginDir    ( vlc_object_t *, const char *, int );
-static int  AllocatePluginFile   ( vlc_object_t *, char * );
+static void AllocatePluginDir    ( vlc_object_t *, const MYCHAR *, int );
+static int  AllocatePluginFile   ( vlc_object_t *, MYCHAR * );
 #endif
 static int  AllocateBuiltinModule( vlc_object_t *, int ( * ) ( module_t * ) );
 static int  DeleteModule ( module_t * );
@@ -231,11 +253,10 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
     module_list_t *p_list, *p_first, *p_tmp;
     vlc_list_t *p_all;
 
-    int i_index = 0;
+    int i_which_module, i_index = 0;
     vlc_bool_t b_intf = VLC_FALSE;
 
     module_t *p_module;
-    module_t **pp_parser;
 
     int   i_shortcuts = 0;
     char *psz_shortcuts = NULL, *psz_var = NULL;
@@ -280,12 +301,12 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
     p_first = NULL;
 
     /* Parse the module list for capabilities and probe each of them */
-    for( pp_parser = (module_t**)p_all->pp_objects ; *pp_parser ; pp_parser++ )
+    for( i_which_module = 0; i_which_module < p_all->i_count; i_which_module++ )
     {
         module_t * p_submodule = NULL;
         int i_shortcut_bonus = 0, i_submodule;
 
-        p_module = *pp_parser;
+        p_module = (module_t *)p_all->p_values[i_which_module].p_object;
 
         /* Test that this module can do what we need */
         if( strcmp( p_module->psz_capability, psz_capability ) )
@@ -320,23 +341,40 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
         /* If we required a shortcut, check this plugin provides it. */
         if( i_shortcuts )
         {
-            vlc_bool_t b_trash = VLC_TRUE;
+            vlc_bool_t b_trash;
             int i_dummy, i_short = i_shortcuts;
             char *psz_name = psz_shortcuts;
 
+            /* Let's drop modules with a 0 score (unless they are
+             * explicitly requested) */
+            b_trash = !p_module->i_score;
+
             while( i_short )
             {
-                for( i_dummy = 0;
-                     b_trash && p_module->pp_shortcuts[i_dummy];
-                     i_dummy++ )
+                /* If the last given shortcut is "none" and we couldn't
+                 * find the module in the list of provided shortcuts,
+                 * then kick the bastard out of here!!! */
+                if( (i_short == 1) && !strcmp(psz_name, "none") )
+                {
+                    b_trash = VLC_TRUE;
+                    break;
+                }
+
+                for( i_dummy = 0; p_module->pp_shortcuts[i_dummy]; i_dummy++ )
                 {
-                    b_trash = ( strcmp(psz_name, "any") || !p_module->i_score )
-                        && strcmp( psz_name, p_module->pp_shortcuts[i_dummy] );
+                    if( !strcmp( psz_name,
+                                 p_module->pp_shortcuts[i_dummy] ) )
+                    {
+                        /* Found it */
+                        b_trash = VLC_FALSE;
+                        i_shortcut_bonus = i_short * 10000;
+                        break;
+                    }
                 }
 
-                if( !b_trash )
+                if( i_shortcut_bonus )
                 {
-                    i_shortcut_bonus = i_short * 10000;
+                    /* We found it... remember ? */
                     break;
                 }
 
@@ -365,7 +403,7 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
              && !strcmp( p_module->psz_program,
                          p_this->p_vlc->psz_object_name ) )
         {
-            if( !b_intf ) 
+            if( !b_intf )
             {
                 /* Remove previous non-matching plugins */
                 i_index = 0;
@@ -476,8 +514,8 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
     }
     else if( psz_name != NULL && *psz_name )
     {
-        msg_Err( p_this, "no %s module matching \"%s\" could be loaded",
-                 psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
+        msg_Warn( p_this, "no %s module matching \"%s\" could be loaded",
+                  psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
     }
 
     if( psz_shortcuts )
@@ -531,26 +569,45 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
 
     char **         ppsz_path = path;
     char *          psz_fullpath;
-#if defined( SYS_BEOS ) || defined( SYS_DARWIN )
-    char *          psz_vlcpath = system_GetProgramPath();
-    int             i_vlclen = strlen( psz_vlcpath );
+#if defined( SYS_BEOS ) || defined( SYS_DARWIN ) \
+     || ( defined( WIN32 ) && !defined( UNDER_CE ) )
+    int             i_vlclen = strlen( p_this->p_libvlc->psz_vlcpath );
     vlc_bool_t      b_notinroot;
 #endif
 
+#if defined( UNDER_CE )
+    wchar_t         psz_dir[MAX_PATH];
+#endif
+
     /* If the user provided a plugin path, we add it to the list */
     path[ sizeof(path)/sizeof(char*) - 2 ] = config_GetPsz( p_this,
                                                             "plugin-path" );
 
+#if defined( WIN32 ) && !defined( UNDER_CE ) && !defined( _MSC_VER )
+    /* If there is no 'plugins' nor 'modules' subdirectory, the user may have
+     * screwed up the unzipping stage, so we look into '.' instead */
+    if( !opendir( "plugins" ) && !opendir( "modules" )
+        && !strcmp( *ppsz_path, "modules" ) )
+    {
+        *ppsz_path = ".";
+    }
+#endif
+
     for( ; *ppsz_path != NULL ; ppsz_path++ )
     {
-#if defined( SYS_BEOS ) || defined( SYS_DARWIN )
+#if defined( SYS_BEOS ) || defined( SYS_DARWIN ) \
+     || ( defined( WIN32 ) && !defined( UNDER_CE ) )
         /* Store strlen(*ppsz_path) for later use. */
         int i_dirlen = strlen( *ppsz_path );
 
         b_notinroot = VLC_FALSE;
         /* Under BeOS, we need to add beos_GetProgramPath() to access
          * files under the current directory */
-        if( ( i_dirlen > 1 ) && strncmp( *ppsz_path, "/", 1 ) )
+#ifdef WIN32
+        if( i_dirlen < 3 || (*ppsz_path)[3] != '\\' )
+#else
+        if( (*ppsz_path)[0] != '/' )
+#endif
         {
             i_dirlen += i_vlclen + 2;
             b_notinroot = VLC_TRUE;
@@ -560,7 +617,13 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
             {
                 continue;
             }
-            sprintf( psz_fullpath, "%s/%s", psz_vlcpath, *ppsz_path );
+#ifdef WIN32
+            sprintf( psz_fullpath, "%s\\%s",
+                     p_this->p_libvlc->psz_vlcpath, *ppsz_path );
+#else
+            sprintf( psz_fullpath, "%s/%s",
+                     p_this->p_libvlc->psz_vlcpath, *ppsz_path );
+#endif
         }
         else
 #endif
@@ -571,7 +634,12 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
         msg_Dbg( p_this, "recursively browsing `%s'", psz_fullpath );
 
         /* Don't go deeper than 5 subdirectories */
+#if defined( UNDER_CE )
+        MultiByteToWideChar( CP_ACP, 0, psz_fullpath, -1, psz_dir, MAX_PATH );
+        AllocatePluginDir( p_this, psz_dir, 5 );
+#else
         AllocatePluginDir( p_this, psz_fullpath, 5 );
+#endif
 
 #if defined( SYS_BEOS ) || defined( SYS_DARWIN )
         if( b_notinroot )
@@ -582,29 +650,100 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
     }
 
     /* Free plugin-path */
-    free( path[ sizeof(path)/sizeof(char*) - 2 ] );
+    if( path[ sizeof(path)/sizeof(char*) - 2 ] )
+        free( path[ sizeof(path)/sizeof(char*) - 2 ] );
     path[ sizeof(path)/sizeof(char*) - 2 ] = NULL;
 }
 
 /*****************************************************************************
  * AllocatePluginDir: recursively parse a directory to look for plugins
  *****************************************************************************/
-static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
+static void AllocatePluginDir( vlc_object_t *p_this, const MYCHAR *psz_dir,
                                int i_maxdepth )
 {
+#if defined( UNDER_CE ) || defined( _MSC_VER )
+#ifdef UNDER_CE
+    MYCHAR psz_path[MAX_PATH + 256];
+#else
+    char psz_path[MAX_PATH + 256];
+#endif
+    WIN32_FIND_DATA finddata;
+    HANDLE handle;
+    unsigned int rc;
+#else
     int    i_dirlen;
     DIR *  dir;
     char * psz_file;
-
     struct dirent * file;
+#endif
 
     if( i_maxdepth < 0 )
     {
         return;
     }
 
-    dir = opendir( psz_dir );
+#if defined( UNDER_CE ) || defined( _MSC_VER )
+    rc = GetFileAttributes( psz_dir );
+    if( !(rc & FILE_ATTRIBUTE_DIRECTORY) )
+    {
+        /* Not a directory */
+        return;
+    }
+
+    /* Parse all files in the directory */
+#ifdef UNDER_CE
+    swprintf( psz_path, L"%s\\*.*", psz_dir );
+#else
+    sprintf( psz_path, "%s\\*.*", psz_dir );
+#endif
+    handle = FindFirstFile( psz_path, &finddata );
+    if( handle == INVALID_HANDLE_VALUE )
+    {
+        /* Empty directory */
+        return;
+    }
+
+    /* Parse the directory and try to load all files it contains. */
+    do
+    {
+#ifdef UNDER_CE
+        unsigned int i_len = wcslen( finddata.cFileName );
+        swprintf( psz_path, L"%s\\%s", psz_dir, finddata.cFileName );
+#else
+        unsigned int i_len = strlen( finddata.cFileName );
+        /* Skip ".", ".." and anything starting with "." */
+        if( !*finddata.cFileName || *finddata.cFileName == '.' )
+        {
+            if( !FindNextFile( handle, &finddata ) ) break;
+            continue;
+        }
+        sprintf( psz_path, "%s\\%s", psz_dir, finddata.cFileName );
+#endif
+
+        if( GetFileAttributes( psz_path ) & FILE_ATTRIBUTE_DIRECTORY )
+        {
+            AllocatePluginDir( p_this, psz_path, i_maxdepth - 1 );
+        }
+        else if( i_len > strlen( LIBEXT )
+#ifdef UNDER_CE
+                )
+#else
+                  /* We only load files ending with LIBEXT */
+                  && !strncasecmp( psz_path + strlen( psz_path)
+                                   - strlen( LIBEXT ),
+                                   LIBEXT, strlen( LIBEXT ) ) )
+#endif
+        {
+            AllocatePluginFile( p_this, psz_path );
+        }
+    }
+    while( FindNextFile( handle, &finddata ) );
 
+    /* Close the directory */
+    FindClose( handle );
+
+#else
+    dir = opendir( psz_dir );
     if( !dir )
     {
         return;
@@ -616,7 +755,7 @@ static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
     while( (file = readdir( dir )) )
     {
         struct stat statbuf;
-        int i_len;
+        unsigned int i_len;
 
         /* Skip ".", ".." and anything starting with "." */
         if( !*file->d_name || *file->d_name == '.' )
@@ -625,9 +764,12 @@ static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
         }
 
         i_len = strlen( file->d_name );
-
-        psz_file = malloc( i_dirlen + 1 /* / */ + i_len + 1 /* \0 */ );
+        psz_file = malloc( i_dirlen + 1 + i_len + 1 );
+#ifdef WIN32
+        sprintf( psz_file, "%s\\%s", psz_dir, file->d_name );
+#else
         sprintf( psz_file, "%s/%s", psz_dir, file->d_name );
+#endif
 
         if( !stat( psz_file, &statbuf ) && statbuf.st_mode & S_IFDIR )
         {
@@ -635,8 +777,8 @@ static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
         }
         else if( i_len > strlen( LIBEXT )
                   /* We only load files ending with LIBEXT */
-                  && !strncmp( file->d_name + i_len - strlen( LIBEXT ),
-                               LIBEXT, strlen( LIBEXT ) ) )
+                  && !strncasecmp( file->d_name + i_len - strlen( LIBEXT ),
+                                   LIBEXT, strlen( LIBEXT ) ) )
         {
             AllocatePluginFile( p_this, psz_file );
         }
@@ -646,6 +788,8 @@ static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
 
     /* Close the directory */
     closedir( dir );
+
+#endif
 }
 
 /*****************************************************************************
@@ -655,11 +799,19 @@ static void AllocatePluginDir( vlc_object_t *p_this, const char *psz_dir,
  * for its information data. The module can then be handled by module_Need
  * and module_Unneed. It can be removed by DeleteModule.
  *****************************************************************************/
-static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file )
+static int AllocatePluginFile( vlc_object_t * p_this, MYCHAR * psz_file )
 {
     module_t * p_module;
     module_handle_t handle;
 
+#ifdef UNDER_CE
+    char psz_filename[MAX_PATH];
+    WideCharToMultiByte( CP_ACP, WC_DEFAULTCHAR, psz_file, -1,
+                         psz_filename, MAX_PATH, NULL, NULL );
+#else
+    char * psz_filename = psz_file;
+#endif
+
     /* Try to dynamically load the module. */
     if( module_load( psz_file, &handle ) )
     {
@@ -667,12 +819,12 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file )
 
         /* The plugin module couldn't be opened */
         msg_Warn( p_this, "cannot open `%s' (%s)",
-                  psz_file, module_error( psz_buffer ) );
+                  psz_filename, module_error( psz_buffer ) );
         return -1;
     }
 
     /* Now that we have successfully loaded the module, we can
-     * allocate a structure for it */ 
+     * allocate a structure for it */
     p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
     if( p_module == NULL )
     {
@@ -682,7 +834,7 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file )
     }
 
     /* We need to fill these since they may be needed by CallEntry() */
-    p_module->psz_filename = psz_file;
+    p_module->psz_filename = psz_filename;
     p_module->handle = handle;
     p_module->p_symbols = &p_this->p_libvlc->p_module_bank->symbols;
 
@@ -786,7 +938,7 @@ static int AllocateBuiltinModule( vlc_object_t * p_this,
     module_t * p_module;
 
     /* Now that we have successfully loaded the module, we can
-     * allocate a structure for it */ 
+     * allocate a structure for it */
     p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
     if( p_module == NULL )
     {
@@ -866,7 +1018,7 @@ static int CallEntry( module_t * p_module )
     int (* pf_symbol) ( module_t * p_module );
 
     /* Try to resolve the symbol */
-    pf_symbol = (int (*)(module_t *)) module_getsymbol( p_module->handle, 
+    pf_symbol = (int (*)(module_t *)) module_getsymbol( p_module->handle,
                                                         psz_name );
 
     if( pf_symbol == NULL )
@@ -894,4 +1046,3 @@ static int CallEntry( module_t * p_module )
     return 0;
 }
 #endif /* HAVE_DYNAMIC_PLUGINS */
-