diff options
author | Minh Ngo <nlminhtl@gmail.com> | 2013-08-25 17:43:10 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@iki.fi> | 2013-08-31 09:36:13 +0000 |
commit | 132f150d7da7dabe64d1d95775a55b034e723905 (patch) | |
tree | 1c1f2a4e8e36f03dbde7ce862dd114c157d6bf25 /avmedia | |
parent | 4ef149ba72c0a4b4f38905106a1acb8d21b023be (diff) |
Cross-platform libvlc loading.
Conflicts:
avmedia/source/vlc/wrapper/SymbolLoader.hxx
Change-Id: I2dcd86329419255751925e93db0c893da191be31
Reviewed-on: https://gerrit.libreoffice.org/5627
Reviewed-by: Tor Lillqvist <tml@iki.fi>
Tested-by: Tor Lillqvist <tml@iki.fi>
Diffstat (limited to 'avmedia')
-rw-r--r-- | avmedia/source/vlc/wrapper/SymbolLoader.hxx | 69 |
1 files changed, 48 insertions, 21 deletions
diff --git a/avmedia/source/vlc/wrapper/SymbolLoader.hxx b/avmedia/source/vlc/wrapper/SymbolLoader.hxx index 92b52eee3e05..83c349ea1555 100644 --- a/avmedia/source/vlc/wrapper/SymbolLoader.hxx +++ b/avmedia/source/vlc/wrapper/SymbolLoader.hxx @@ -9,7 +9,10 @@ #ifndef _SYMBOL_LOADER_HXX #define _SYMBOL_LOADER_HXX - +#if defined( WNT ) +# include <windows.h> +# include <winreg.h> +#endif #include <iostream> #include <osl/module.h> #include <rtl/ustring.hxx> @@ -26,11 +29,33 @@ struct ApiMap namespace { - const char *libNames[] = { - "libvlc.so.5", - "libvlc.dll", - "libvlc.dylib" - }; +#if defined( UNX ) + const char LibName[] = "libvlc.so.5"; +#elif defined( MACOS ) + const char LibName[] = "/Applications/VLC.app/libvlc.dylib"; +#elif defined( WNT ) + const char LibName[] = "libvlc.dll"; + + OUString GetVLCPath() + { + HKEY hKey; + TCHAR arCurrent[MAX_PATH]; + DWORD dwType, dwCurrentSize = sizeof( arCurrent ); + + if ( ::RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T( "Software\\VideoLAN\\VLC" ), + 0, KEY_READ, &hKey ) == ERROR_SUCCESS ) + { + if ( ::RegQueryValueEx( hKey, _T( "InstallDir" ), NULL, &dwType, ( LPBYTE )arCurrent, &dwCurrentSize ) == ERROR_SUCCESS ) + { + ::RegCloseKey( hKey ); + return OUString::createFromAscii( arCurrent ) + "/"; + } + + ::RegCloseKey( hKey ); + } + } +#endif + template<size_t N> bool tryLink( oslModule &aModule, const ApiMap ( &pMap )[N] ) @@ -58,27 +83,29 @@ namespace VLC template<size_t N> bool InitApiMap( const ApiMap ( &pMap )[N] ) { - oslModule aModule; - - for (uint j = 0; j < sizeof(libNames) / sizeof(libNames[0]); ++j) - { - aModule = osl_loadModule( OUString::createFromAscii - ( libNames[ j ] ).pData, - SAL_LOADMODULE_DEFAULT ); +#if defined( UNX ) || defined( MACOS ) + const OUString& fullPath = OUString::createFromAscii(LibName); +#elif defined( WNT ) + const OUString& fullPath = GetVLCPath() + OUString::createFromAscii(LibName); +#endif - if( aModule == NULL) - continue; + oslModule aModule = osl_loadModule( fullPath.pData, + SAL_LOADMODULE_DEFAULT ); - if (tryLink( aModule, pMap )) - { - osl_unloadModule( aModule ); - return true; - } + if( aModule == NULL) + { + std::cerr << "Cannot load libvlc" << std::endl; + return false; + } + if (tryLink( aModule, pMap )) + { osl_unloadModule( aModule ); + return true; } - std::cerr << "Cannot load libvlc" << std::endl; + osl_unloadModule( aModule ); + return false; } } |