⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modules.c

📁 video linux conference
💻 C
📖 第 1 页 / 共 5 页
字号:
    /* Initialize the module : fill p_module->psz_object_name, etc. */    if( pf_entry( p_module ) != 0 )    {        /* With a well-written module we shouldn't have to print an         * additional error message here, but just make sure. */        msg_Err( p_this, "failed calling entry point in builtin module" );        vlc_object_destroy( p_module );        return -1;    }    /* Everything worked fine ! The module is ready to be added to the list. */    p_module->b_builtin = VLC_TRUE;    /* msg_Dbg( p_this, "builtin \"%s\", %s",                p_module->psz_object_name, p_module->psz_longname ); */    vlc_object_attach( p_module, p_this->p_libvlc->p_module_bank );    return 0;}/***************************************************************************** * DeleteModule: delete a module and its structure. ***************************************************************************** * This function can only be called if the module isn't being used. *****************************************************************************/static int DeleteModule( module_t * p_module ){    vlc_object_detach( p_module );    /* We free the structures that we strdup()ed in Allocate*Module(). */#ifdef HAVE_DYNAMIC_PLUGINS    if( !p_module->b_builtin )    {        if( p_module->b_loaded && p_module->b_unloadable )        {            CloseModule( p_module->handle );        }        UndupModule( p_module );        free( p_module->psz_filename );    }#endif    /* Free and detach the object's children */    while( p_module->i_children )    {        vlc_object_t *p_this = p_module->pp_children[0];        vlc_object_detach( p_this );        vlc_object_destroy( p_this );    }    config_Free( p_module );    vlc_object_destroy( p_module );    return 0;}#ifdef HAVE_DYNAMIC_PLUGINS/***************************************************************************** * CallEntry: call an entry point. ***************************************************************************** * This function calls a symbol given its name and a module structure. The * symbol MUST refer to a function returning int and taking a module_t* as * an argument. *****************************************************************************/static int CallEntry( module_t * p_module ){    static char *psz_name = "vlc_entry" MODULE_SUFFIX;    int (* pf_symbol) ( module_t * p_module );    /* Try to resolve the symbol */    pf_symbol = (int (*)(module_t *)) GetSymbol( p_module->handle, psz_name );    if( pf_symbol == NULL )    {#if defined(HAVE_DL_DYLD) || defined(HAVE_DL_BEOS)        msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s'",                            psz_name, p_module->psz_filename );#elif defined(HAVE_DL_WINDOWS)        char *psz_error = GetWindowsError();        msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s' (%s)",                            psz_name, p_module->psz_filename, psz_error );        free( psz_error );#elif defined(HAVE_DL_DLOPEN)        msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s' (%s)",                            psz_name, p_module->psz_filename, dlerror() );#elif defined(HAVE_DL_SHL_LOAD)        msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s' (%s)",                            psz_name, p_module->psz_filename, strerror(errno) );#else#   error "Something is wrong in modules.c"#endif        return -1;    }    /* We can now try to call the symbol */    if( pf_symbol( p_module ) != 0 )    {        /* With a well-written module we shouldn't have to print an         * additional error message here, but just make sure. */        msg_Err( p_module, "failed calling symbol \"%s\" in file `%s'",                           psz_name, p_module->psz_filename );        return -1;    }    /* Everything worked fine, we can return */    return 0;}/***************************************************************************** * LoadModule: loads a dynamic library ***************************************************************************** * This function loads a dynamically linked library using a system dependant * method. Will return 0 on success as well as the module handle. *****************************************************************************/static int LoadModule( vlc_object_t *p_this, char *psz_file,                       module_handle_t *p_handle ){    module_handle_t handle;#if defined(HAVE_DL_DYLD)    NSObjectFileImage image;    NSObjectFileImageReturnCode ret;    ret = NSCreateObjectFileImageFromFile( psz_file, &image );    if( ret != NSObjectFileImageSuccess )    {        msg_Warn( p_this, "cannot create image from `%s'", psz_file );        return -1;    }    /* Open the dynamic module */    handle = NSLinkModule( image, psz_file,                           NSLINKMODULE_OPTION_RETURN_ON_ERROR );    if( !handle )    {        NSLinkEditErrors errors;        const char *psz_file, *psz_err;        int i_errnum;        NSLinkEditError( &errors, &i_errnum, &psz_file, &psz_err );        msg_Warn( p_this, "cannot link module `%s' (%s)", psz_file, psz_err );        NSDestroyObjectFileImage( image );        return -1;    }    /* Destroy our image, we won't need it */    NSDestroyObjectFileImage( image );#elif defined(HAVE_DL_BEOS)    handle = load_add_on( psz_file );    if( handle < 0 )    {        msg_Warn( p_this, "cannot load module `%s'", psz_file );        return -1;    }#elif defined(HAVE_DL_WINDOWS)#ifdef UNDER_CE    {        wchar_t psz_wfile[MAX_PATH];        MultiByteToWideChar( CP_ACP, 0, psz_file, -1, psz_wfile, MAX_PATH );        handle = LoadLibrary( psz_wfile );    }#else    handle = LoadLibrary( psz_file );#endif    if( handle == NULL )    {        char *psz_err = GetWindowsError();        msg_Warn( p_this, "cannot load module `%s' (%s)", psz_file, psz_err );        free( psz_err );        return -1;    }#elif defined(HAVE_DL_DLOPEN) && defined(RTLD_NOW)    /* static is OK, we are called atomically */    static vlc_bool_t b_kde = VLC_FALSE;#   if defined(SYS_LINUX)    /* XXX HACK #1 - we should NOT open modules with RTLD_GLOBAL, or we     * are going to get namespace collisions when two modules have common     * public symbols, but ALSA is being a pest here. */    if( strstr( psz_file, "alsa_plugin" ) )    {        handle = dlopen( psz_file, RTLD_NOW | RTLD_GLOBAL );        if( handle == NULL )        {            msg_Warn( p_this, "cannot load module `%s' (%s)",                              psz_file, dlerror() );            return -1;        }    }#   endif    /* XXX HACK #2 - the ugly KDE workaround. It seems that libkdewhatever     * causes dlopen() to segfault if libstdc++ is not loaded in the caller,     * so we just load libstdc++. Bwahahaha! ph34r! -- Sam. */    /* Update: FYI, this is Debian bug #180505, and seems to be fixed. */    if( !b_kde && !strstr( psz_file, "kde" ) )    {        dlopen( "libstdc++.so.6", RTLD_NOW )         || dlopen( "libstdc++.so.5", RTLD_NOW )         || dlopen( "libstdc++.so.4", RTLD_NOW )         || dlopen( "libstdc++.so.3", RTLD_NOW );        b_kde = VLC_TRUE;    }    handle = dlopen( psz_file, RTLD_NOW );    if( handle == NULL )    {        msg_Warn( p_this, "cannot load module `%s' (%s)",                          psz_file, dlerror() );        return -1;    }#elif defined(HAVE_DL_DLOPEN)#   if defined(DL_LAZY)    handle = dlopen( psz_file, DL_LAZY );#   else    handle = dlopen( psz_file, 0 );#   endif    if( handle == NULL )    {        msg_Warn( p_this, "cannot load module `%s' (%s)",                          psz_file, dlerror() );        return -1;    }#elif defined(HAVE_DL_SHL_LOAD)    handle = shl_load( psz_file, BIND_IMMEDIATE | BIND_NONFATAL, NULL );    if( handle == NULL )    {        msg_Warn( p_this, "cannot load module `%s' (%s)",                          psz_file, strerror(errno) );        return -1;    }#else#   error "Something is wrong in modules.c"#endif    *p_handle = handle;    return 0;}/***************************************************************************** * CloseModule: unload a dynamic library ***************************************************************************** * This function unloads a previously opened dynamically linked library * using a system dependant method. No return value is taken in consideration, * since some libraries sometimes refuse to close properly. *****************************************************************************/static void CloseModule( module_handle_t handle ){#if defined(HAVE_DL_DYLD)    NSUnLinkModule( handle, FALSE );#elif defined(HAVE_DL_BEOS)    unload_add_on( handle );#elif defined(HAVE_DL_WINDOWS)    FreeLibrary( handle );#elif defined(HAVE_DL_DLOPEN)    dlclose( handle );#elif defined(HAVE_DL_SHL_LOAD)    shl_unload( handle );#endif    return;}/***************************************************************************** * GetSymbol: get a symbol from a dynamic library ***************************************************************************** * This function queries a loaded library for a symbol specified in a * string, and returns a pointer to it. We don't check for dlerror() or * similar functions, since we want a non-NULL symbol anyway. *****************************************************************************/static void * _module_getsymbol( module_handle_t, const char * );static void * GetSymbol( module_handle_t handle, const char * psz_function ){    void * p_symbol = _module_getsymbol( handle, psz_function );    /* MacOS X dl library expects symbols to begin with "_". So do     * some other operating systems. That's really lame, but hey, what     * can we do ? */    if( p_symbol == NULL )    {        char *psz_call = malloc( strlen( psz_function ) + 2 );        strcpy( psz_call + 1, psz_function );        psz_call[ 0 ] = '_';        p_symbol = _module_getsymbol( handle, psz_call );        free( psz_call );    }    return p_symbol;}static void * _module_getsymbol( module_handle_t handle,                                 const char * psz_function ){#if defined(HAVE_DL_DYLD)    NSSymbol sym = NSLookupSymbolInModule( handle, psz_function );    return NSAddressOfSymbol( sym );#elif defined(HAVE_DL_BEOS)    void * p_symbol;    if( B_OK == get_image_symbol( handle, psz_function,                                  B_SYMBOL_TYPE_TEXT, &p_symbol ) )    {        return p_symbol;    }    else    {        return NULL;    }#elif defined(HAVE_DL_WINDOWS) && defined(UNDER_CE)    wchar_t psz_real[256];    MultiByteToWideChar( CP_ACP, 0, psz_function, -1, psz_real, 256 );    return (void *)GetProcAddress( handle, psz_real );#elif defined(HAVE_DL_WINDOWS) && defined(WIN32)    return (void *)GetProcAddress( handle, (char *)psz_function );#elif defined(HAVE_DL_DLOPEN)    return dlsym( handle, psz_function );#elif defined(HAVE_DL_SHL_LOAD)    void *p_sym;    shl_findsym( &handle, psz_function, TYPE_UNDEFINED, &p_sym );    return p_sym;#endif}#if defined(HAVE_DL_WINDOWS)static char * GetWindowsError( void ){#if defined(UNDER_CE)    wchar_t psz_tmp[MAX_PATH];    char * psz_buffer = malloc( MAX_PATH );#else    char * psz_tmp = malloc( MAX_PATH );#endif    int i = 0, i_error = GetLastError();    FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,                   NULL, i_error, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),                   (LPTSTR)psz_tmp, MAX_PATH, NULL );    /* Go to the end of the string */    while( psz_tmp[i] && psz_tmp[i] != _T('\r') && psz_tmp[i] != _T('\n') )    {        i++;    }    if( psz_tmp[i] )    {#if defined(UNDER_CE)        swprintf( psz_tmp + i, L" (error %i)", i_error );        psz_tmp[ 255 ] = L'\0';#else        snprintf( psz_tmp + i, 256 - i, " (error %i)", i_error );        psz_tmp[ 255 ] = '\0';#endif    }#if defined(UNDER_CE)    wcstombs( psz_buffer, psz_tmp, MAX_PATH );    return psz_buffer;#else    return psz_tmp;#endif}#endif /* HAVE_DL_WINDOWS *//***************************************************************************** * LoadPluginsCache: loads the plugins cache file ***************************************************************************** * This function will load the plugin cache if present and valid. This cache * will in turn be queried by AllocateAllPlugins() to see if it needs to * actually load the dynamically loadable module. * This allows us to only fully load plugins when they are actually used. *****************************************************************************/static void CacheLoad( vlc_object_t *p_this ){    char *psz_filename, *psz_homedir;    FILE *file;    int i, j, i_size, i_read;    char p_cachestring[sizeof(PLUGINSCACHE_DIR COPYRIGHT_MESSAGE)];    char p_cachelang[6], p_lang[6];    int i_cache;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -