1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #ifndef INCLUDED_AVMEDIA_SOURCE_VLC_WRAPPER_SYMBOLLOADER_HXX
11 #define INCLUDED_AVMEDIA_SOURCE_VLC_WRAPPER_SYMBOLLOADER_HXX
13 #if !defined WIN32_LEAN_AND_MEAN
14 # define WIN32_LEAN_AND_MEAN
19 #include <osl/module.h>
20 #include <rtl/ustring.hxx>
21 #include <sal/log.hxx>
23 #define SYM_MAP(a) { #a, reinterpret_cast<SymbolFunc *>(&a) }
31 typedef void (*SymbolFunc
) (void);
40 const char LibName
[] = "libvlc.so.5";
41 #elif defined( MACOSX )
42 const char LibName
[] = "/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib";
44 const char LibName
[] = "libvlc.dll";
46 inline OUString
GetVLCPath()
49 wchar_t arCurrent
[MAX_PATH
];
50 DWORD dwType
, dwCurrentSize
= sizeof( arCurrent
);
52 //TODO: This one will work only with LibreOffice 32-bit + VLC 32-bit on Win x86_64.
53 const LONG errorCore
= ::RegOpenKeyExW( HKEY_LOCAL_MACHINE
, L
"SOFTWARE\\Wow6432Node\\VideoLAN\\VLC", 0, KEY_READ
| KEY_WOW64_64KEY
, &hKey
);
54 if ( errorCore
== ERROR_SUCCESS
)
56 if ( ::RegQueryValueExW( hKey
, L
"InstallDir", NULL
, &dwType
, (LPBYTE
) arCurrent
, &dwCurrentSize
) == ERROR_SUCCESS
&&
59 ::RegCloseKey( hKey
);
63 return OUString( arCurrent
, dwCurrentSize
) + OUString::createFromAscii("\\");
66 ::RegCloseKey( hKey
);
74 bool tryLink( oslModule
&aModule
, const ApiMap ( &pMap
)[N
] )
76 for (size_t i
= 0; i
< N
; ++i
)
78 SymbolFunc aMethod
= reinterpret_cast<SymbolFunc
>(osl_getFunctionSymbol
79 ( aModule
, OUString::createFromAscii( pMap
[ i
].symName
).pData
));
82 SAL_WARN("avmedia", "Cannot load method " << pMap
[ i
].symName
);
83 *pMap
[ i
].refValue
= nullptr;
87 *pMap
[ i
].refValue
= aMethod
;
94 bool InitApiMap( const ApiMap ( &pMap
)[N
] )
96 #if defined( LINUX ) || defined( MACOSX )
97 OUString
const fullPath(LibName
);
99 OUString
const fullPath(GetVLCPath() + LibName
);
101 SAL_INFO("avmedia", fullPath
);
103 oslModule aModule
= osl_loadModule( fullPath
.pData
,
104 SAL_LOADMODULE_DEFAULT
);
107 if( aModule
== nullptr)
109 SAL_WARN("avmedia", "Cannot load libvlc");
113 if (tryLink( aModule
, pMap
))
118 SAL_WARN("avmedia", "Cannot load libvlc");
119 osl_unloadModule( aModule
);
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */