Esempio n. 1
0
        private static IntPtr LoadLibrary(string libraryName, bool throwException)
        {
            if (LoadedLibraries.TryGetValue(libraryName, out var ptr))
            {
                return(ptr);
            }

            lock (SyncRoot)
            {
                if (LoadedLibraries.TryGetValue(libraryName, out ptr))
                {
                    return(ptr);
                }

                var dependencies = LibraryDependenciesMap[libraryName];
                dependencies.Where(n => !LoadedLibraries.ContainsKey(n) && !n.Equals(libraryName))
                .ToList()
                .ForEach(n => LoadLibrary(n, false));

                var version = LibraryVersionMap[libraryName];
                ptr = LibraryLoader.LoadNativeLibrary(RootPath, libraryName, version);

                if (ptr != IntPtr.Zero)
                {
                    LoadedLibraries.Add(libraryName, ptr);
                }
                else if (throwException)
                {
                    throw new DllNotFoundException(
                              $"Unable to load DLL '{libraryName}.{version} under {RootPath}': The specified module could not be found.");
                }

                return(ptr);
            }
        }
Esempio n. 2
0
        static ffmpeg()
        {
            var loadedLibraries = new Dictionary <string, IntPtr>();

            GetOrLoadLibrary = (name, version) =>
            {
                var key = $"{name}{version}";
                if (loadedLibraries.TryGetValue(key, out var ptr))
                {
                    return(ptr);
                }

                lock (SyncRoot)
                {
                    if (loadedLibraries.TryGetValue(key, out ptr))
                    {
                        return(ptr);
                    }

                    ptr = LibraryLoader.LoadNativeLibrary(RootPath, name, version);
                    if (ptr == IntPtr.Zero)
                    {
                        throw new DllNotFoundException($"Unable to load DLL '{name}.{version}': The specified module could not be found.");
                    }
                    loadedLibraries.Add(key, ptr);
                }

                return(ptr);
            };
        }
Esempio n. 3
0
        private static IntPtr LoadLibrary(string libraryName)
        {
            var dependencies = LibraryDependenciesMap[libraryName];

            dependencies.ForEach(x => GetOrLoadLibrary(x));
            var version = LibraryVersionMap[libraryName];
            var ptr     = LibraryLoader.LoadNativeLibrary(RootPath, libraryName, version);

            if (ptr == IntPtr.Zero)
            {
                throw new DllNotFoundException($"Unable to load DLL '{libraryName}.{version}': The specified module could not be found.");
            }
            return(ptr);
        }
        /// <summary>
        /// Loads the library from the specified path.
        /// </summary>
        /// <param name="basePath">The base path.</param>
        /// <returns>True if the registration was successful</returns>
        /// <exception cref="InvalidOperationException">When library has already been loaded.</exception>
        public bool Load(string basePath)
        {
            lock (LoadLock)
            {
                if (Reference != IntPtr.Zero)
                {
                    throw new InvalidOperationException($"Library {Name} was already loaded.");
                }

                var result = LibraryLoader.LoadNativeLibrary(basePath, Name, Version);

                if (result == IntPtr.Zero)
                {
                    return(false);
                }
                Reference     = result;
                BasePath      = basePath;
                LoadErrorCode = 0;
                return(true);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Loads the library from the specified path.
        /// </summary>
        /// <param name="basePath">The base path.</param>
        /// <returns>True if the registration was successful.</returns>
        /// <exception cref="InvalidOperationException">When library has already been loaded.</exception>
        public bool Load(string basePath)
        {
            lock (LoadLock)
            {
                if (Reference != IntPtr.Zero)
                {
                    return(true);
                }

                var result = LibraryLoader.LoadNativeLibrary(basePath, Name, Version);

                if (result == IntPtr.Zero)
                {
                    return(false);
                }

                Reference     = result;
                BasePath      = basePath;
                LoadErrorCode = 0;
                return(true);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes static members of the <see cref="SoundTouch"/> class.
        /// </summary>
        static SoundTouch()
        {
            try
            {
                // Include the ffmpeg directory in the search path
                var loadResult = LibraryLoader.LoadNativeLibrary(
                    Path.Combine(Library.FFmpegDirectory, SoundTouchLibrary));

                if (loadResult == IntPtr.Zero)
                {
                    IsAvailable = false;
                    return;
                }

                var versionId = NativeMethods.GetVersionId();
                IsAvailable = versionId != 0;
            }
            catch
            {
                IsAvailable = false;
            }
        }