[Libreoffice-commits] core.git: avmedia/source

Minh Ngo nlminhtl at gmail.com
Sat Aug 31 02:36:31 PDT 2013


 avmedia/source/vlc/wrapper/SymbolLoader.hxx |   69 +++++++++++++++++++---------
 1 file changed, 48 insertions(+), 21 deletions(-)

New commits:
commit 132f150d7da7dabe64d1d95775a55b034e723905
Author: Minh Ngo <nlminhtl at gmail.com>
Date:   Sun Aug 25 17:43:10 2013 +0300

    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 at iki.fi>
    Tested-by: Tor Lillqvist <tml at iki.fi>

diff --git a/avmedia/source/vlc/wrapper/SymbolLoader.hxx b/avmedia/source/vlc/wrapper/SymbolLoader.hxx
index 92b52ee..83c349e 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;
     }
 }


More information about the Libreoffice-commits mailing list