private void InitVlcLib(string libVlcDllsDirectory)
        {
            if (!Directory.Exists(libVlcDllsDirectory))
            {
                throw new DirectoryNotFoundException(string.Format("The directory : {0} not found.", libVlcDllsDirectory));
            }

            string libVlcFilePath = Path.Combine(libVlcDllsDirectory, "libvlc.dll");

            if (!File.Exists(libVlcFilePath))
            {
                throw new FileNotFoundException("Libvlc library not found in directory.");
            }
            string libVlcCoreFilePath = Path.Combine(libVlcDllsDirectory, "libvlccore.dll");

            if (!File.Exists(libVlcCoreFilePath))
            {
                throw new FileNotFoundException("Libvlccore library not found in directory.");
            }

            myLibVlcCoreDllHandle = Win32Interop.LoadLibrary(libVlcCoreFilePath);
            if (myLibVlcCoreDllHandle == IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
            myLibVlcDllHandle = Win32Interop.LoadLibrary(libVlcFilePath);
            if (myLibVlcDllHandle == IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            GetVersion = new LibVlcFunction <GetVersion>(myLibVlcDllHandle);

            var reg   = new Regex("^[0-9.]*");
            var match = reg.Match(GetVersion.Invoke());

            VlcVersion = new Version(match.Groups[0].Value);

            NewInstance     = new LibVlcFunction <NewInstance>(myLibVlcDllHandle, VlcVersion);
            ReleaseInstance = new LibVlcFunction <ReleaseInstance>(myLibVlcDllHandle, VlcVersion);
            RetainInstance  = new LibVlcFunction <RetainInstance>(myLibVlcDllHandle, VlcVersion);
            AddInterface    = new LibVlcFunction <AddInterface>(myLibVlcDllHandle, VlcVersion);
            SetExitCallback = new LibVlcFunction <SetExitCallback>(myLibVlcDllHandle, VlcVersion);
            Wait            = new LibVlcFunction <Wait>(myLibVlcDllHandle, VlcVersion);
            SetUserAgent    = new LibVlcFunction <SetUserAgent>(myLibVlcDllHandle, VlcVersion);
            GetCompiler     = new LibVlcFunction <GetCompiler>(myLibVlcDllHandle, VlcVersion);
            GetChangeSet    = new LibVlcFunction <GetChangeSet>(myLibVlcDllHandle, VlcVersion);
            FreeMemory      = new LibVlcFunction <FreeMemory>(myLibVlcDllHandle, VlcVersion);
            //GetModuleDescriptionList = new LibVlcFunction<GetModuleDescriptionList>(myLibVlcDllHandle, VlcVersion);
            //ReleaseModule = new LibVlcFunction<ReleaseModuleDescription>(myLibVlcDllHandle, VlcVersion);

            EventInterops         = new LibVlcAsynchronousEvents(myLibVlcDllHandle, VlcVersion);
            MediaPlayerInterops   = new LibVlcMediaPlayer(myLibVlcDllHandle, VlcVersion);
            MediaInterops         = new LibVlcMedia(myLibVlcDllHandle, VlcVersion);
            MediaListInterops     = new LibVlcMediaList(myLibVlcDllHandle, VlcVersion);
            AudioInterops         = new LibVlcAudio(myLibVlcDllHandle, VlcVersion);
            VideoInterops         = new LibVlcVideo(myLibVlcDllHandle, VlcVersion);
            LoggingInterops       = new LibVlcLogging(myLibVlcDllHandle, VlcVersion);
            ErrorHandlingInterops = new LibVlcErrorHandling(myLibVlcDllHandle, VlcVersion);
        }
        public void Dispose()
        {
            if (myLibVlcDllHandle != IntPtr.Zero)
            {
                Win32Interop.FreeLibrary(myLibVlcDllHandle);
                myLibVlcDllHandle = IntPtr.Zero;
            }
            if (myLibVlcCoreDllHandle != IntPtr.Zero)
            {
                Win32Interop.FreeLibrary(myLibVlcCoreDllHandle);
                myLibVlcCoreDllHandle = IntPtr.Zero;
            }
            NewInstance = null;
            ReleaseInstance = null;
            RetainInstance = null;
            AddInterface = null;
            SetExitCallback = null;
            Wait = null;
            SetUserAgent = null;
            GetVersion = null;
            GetCompiler = null;
            GetChangeSet = null;
            FreeMemory = null;
            //GetModuleDescriptionList = null;
            //ReleaseModule = null;

            if (EventInterops != null)
                EventInterops.Dispose();
            EventInterops = null;
            if (MediaPlayerInterops != null)
                MediaPlayerInterops.Dispose();
            MediaPlayerInterops = null;
            if (MediaInterops != null)
                MediaInterops.Dispose();
            MediaInterops = null;
            if (MediaListInterops != null)
                MediaListInterops.Dispose();
            MediaListInterops = null;
            if (AudioInterops != null)
                AudioInterops.Dispose();
            AudioInterops = null;
            if (VideoInterops != null)
                VideoInterops.Dispose();
            VideoInterops = null;
            if (LoggingInterops != null)
                LoggingInterops.Dispose();
            LoggingInterops = null;
            if (MediaListPlayerInterops != null)
                MediaListPlayerInterops.Dispose();
            MediaListPlayerInterops = null;
        }
 private void CreateDelegate(IntPtr libVlcDllPointer)
 {
     try
     {
         IntPtr procAddress = Win32Interop.GetProcAddress(libVlcDllPointer, VlcFunctionName);
         if (procAddress == IntPtr.Zero)
         {
             throw new Win32Exception();
         }
         Delegate delegateForFunctionPointer = Marshal.GetDelegateForFunctionPointer(procAddress, typeof(T));
         myDelegate = (T)Convert.ChangeType(delegateForFunctionPointer, typeof(T), null);
     }
     catch (Win32Exception e)
     {
         throw new MissingMethodException(String.Format("The address of the function {0} does not exist in libvlc library.", VlcFunctionNames), e);
     }
 }
Exemple #4
0
        public void Dispose()
        {
            if (myLibVlcDllHandle != IntPtr.Zero)
            {
                Win32Interop.FreeLibrary(myLibVlcDllHandle);
                myLibVlcDllHandle = IntPtr.Zero;
            }
            if (myLibVlcCoreDllHandle != IntPtr.Zero)
            {
                Win32Interop.FreeLibrary(myLibVlcCoreDllHandle);
                myLibVlcCoreDllHandle = IntPtr.Zero;
            }
            NewInstance     = null;
            ReleaseInstance = null;
            RetainInstance  = null;
            AddInterface    = null;
            SetExitCallback = null;
            Wait            = null;
            SetUserAgent    = null;
            GetVersion      = null;
            GetCompiler     = null;
            GetChangeSet    = null;
            FreeMemory      = null;
            //GetModuleDescriptionList = null;
            //ReleaseModule = null;

            if (EventInterops != null)
            {
                EventInterops.Dispose();
            }
            EventInterops = null;
            if (MediaPlayerInterops != null)
            {
                MediaPlayerInterops.Dispose();
            }
            MediaPlayerInterops = null;
            if (MediaInterops != null)
            {
                MediaInterops.Dispose();
            }
            MediaInterops = null;
            if (MediaListInterops != null)
            {
                MediaListInterops.Dispose();
            }
            MediaListInterops = null;
            if (AudioInterops != null)
            {
                AudioInterops.Dispose();
            }
            AudioInterops = null;
            if (VideoInterops != null)
            {
                VideoInterops.Dispose();
            }
            VideoInterops = null;
            if (LoggingInterops != null)
            {
                LoggingInterops.Dispose();
            }
            LoggingInterops = null;
            if (MediaListPlayerInterops != null)
            {
                MediaListPlayerInterops.Dispose();
            }
            MediaListPlayerInterops = null;

#if !SILVERLIGHT
            bool contains;
            do
            {
                foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
                {
                    if (
                        !(module.FileName.StartsWith(myLibVlcDllsDirectory, StringComparison.CurrentCultureIgnoreCase) &&
                          module.FileName.EndsWith("_plugin.dll")))
                    {
                        continue;
                    }
                    Win32Interop.FreeLibrary(module.BaseAddress);
                }
                contains = false;
                foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
                {
                    if (!module.FileName.StartsWith(myLibVlcDllsDirectory, StringComparison.CurrentCultureIgnoreCase) ||
                        !module.FileName.EndsWith("_plugin.dll"))
                    {
                        continue;
                    }

                    contains = true;
                    break;
                }
            }while (contains);
            foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
            {
                if (!module.FileName.StartsWith(myLibVlcDllsDirectory, StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }
                Win32Interop.FreeLibrary(module.BaseAddress);
            }
#endif
        }