Commit a1e39c15 authored by Jérémy VIGNELLES's avatar Jérémy VIGNELLES Committed by Martin Finkel

Refactored native libraries loading

(cherry picked from commit aea75b4328e52afd0beeda3ca4b375ce0378cf02)
parent 17dd5099
......@@ -26,14 +26,6 @@ namespace LibVLCSharp.Shared
static IntPtr _libvlccoreHandle;
static IntPtr _libvlcHandle;
const string Win64 = "win-x64";
const string Win86 = "win-x86";
const string Winrt64 = "winrt-x64";
const string Winrt86 = "winrt-x86";
const string Libvlc = "libvlc";
const string Libvlccore = "libvlccore";
public static void Initialize()
{
#if DESKTOP
......@@ -62,39 +54,42 @@ namespace LibVLCSharp.Shared
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var arch = Environment.Is64BitProcess ? Win64 : Win86;
var libvlccorePath = Path.Combine(Path.Combine(appExecutionDirectory, Libvlc),
Path.Combine(arch, $"{Libvlccore}.dll"));
var libvlcPath = Path.Combine(Path.Combine(appExecutionDirectory, Libvlc),
Path.Combine(arch, $"{Libvlc}.dll"));
Debug.WriteLine(nameof(libvlccorePath) + ": " + libvlccorePath);
Debug.WriteLine(nameof(libvlcPath) + ": " + libvlcPath);
LoadLibvlcLibraries(libvlccorePath, libvlcPath);
var arch = Environment.Is64BitProcess ? ArchitectureNames.Win64 : ArchitectureNames.Win86;
var librariesFolder = Path.Combine(appExecutionDirectory, Constants.LibrariesRepositoryFolderName, arch);
_libvlccoreHandle = PreloadNativeLibrary(librariesFolder, $"{Constants.CoreLibraryName}.dll");
if(_libvlccoreHandle == IntPtr.Zero)
{
throw new VLCException($"Failed to load required native library {Constants.CoreLibraryName}.dll");
}
_libvlcHandle = PreloadNativeLibrary(librariesFolder, $"{Constants.LibraryName}.dll");
if(_libvlcHandle == IntPtr.Zero)
{
throw new VLCException($"Failed to load required native library {Constants.LibraryName}.dll");
}
}
}
//TODO: check if Store app
static void LoadLibvlcLibraries(string libvlccorePath, string libvlcPath)
static IntPtr PreloadNativeLibrary(string nativeLibrariesPath, string libraryName)
{
if (string.IsNullOrEmpty(libvlccorePath)) throw new NullReferenceException(nameof(libvlccorePath));
if (string.IsNullOrEmpty(libvlcPath)) throw new NullReferenceException(nameof(libvlcPath));
_libvlccoreHandle = Native.LoadLibrary(libvlccorePath);
if (_libvlccoreHandle == IntPtr.Zero)
throw new InvalidOperationException("failed to load libvlccore with path " + libvlccorePath +
". Aborting...");
Debug.WriteLine($"Loading {libraryName}");
var libraryPath = Path.Combine(nativeLibrariesPath, libraryName);
if(!File.Exists(libraryPath))
{
Debug.WriteLine($"Cannot find {libraryPath}");
return IntPtr.Zero;
}
_libvlcHandle = Native.LoadLibrary(libvlcPath);
if (_libvlcHandle == IntPtr.Zero)
throw new InvalidOperationException("failed to load libvlc with path " + libvlcPath + ". Aborting...");
return Native.LoadLibrary(libraryPath);// TODO: cross-platform load
}
}
static class Constants
internal static class Constants
{
#if IOS
internal const string LibraryName = "@rpath/DynamicMobileVLCKit.framework/DynamicMobileVLCKit";
......@@ -103,5 +98,25 @@ namespace LibVLCSharp.Shared
#else
internal const string LibraryName = "libvlc";
#endif
internal const string CoreLibraryName = "libvlccore";
/// <summary>
/// The name of the folder that contains the per-architecture folders
/// </summary>
internal const string LibrariesRepositoryFolderName = "libvlc";
}
internal static class ArchitectureNames
{
internal const string Win64 = "win-x64";
internal const string Win86 = "win-x86";
internal const string Winrt64 = "winrt-x64";
internal const string Winrt86 = "winrt-x86";
internal const string Lin64 = "linux-x64";
internal const string LinArm = "linux-arm";
internal const string MacOS64 = "osx-x64";
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment