Esempio n. 1
0
        public VlcManager(DirectoryInfo dynamicLinkLibrariesPath, string[] args)
        {
            this.myLibraryLoader = VlcLibraryLoader.GetOrCreateLoader(dynamicLinkLibrariesPath);

            IntPtr[] utf8Args = new IntPtr[args?.Length ?? 0];
            try
            {
                for (var i = 0; i < utf8Args.Length; i++)
                {
                    byte[] bytes  = Encoding.UTF8.GetBytes(args[i]);
                    var    buffer = Marshal.AllocHGlobal(bytes.Length + 1);
                    Marshal.Copy(bytes, 0, buffer, bytes.Length);
                    Marshal.WriteByte(buffer, bytes.Length, 0);
                    utf8Args[i] = buffer;
                }

                myVlcInstance = new VlcInstance(this, myLibraryLoader.GetInteropDelegate <CreateNewInstance>().Invoke(utf8Args.Length, utf8Args));
            }
            finally
            {
                foreach (var arg in utf8Args)
                {
                    if (arg != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(arg);
                    }
                }
            }
        }
Esempio n. 2
0
 public void Dispose()
 {
     if (this.dialogCallbacksPointer != IntPtr.Zero)
     {
         Marshal.FreeHGlobal(this.dialogCallbacksPointer);
     }
     myVlcInstance.Dispose();
     VlcLibraryLoader.ReleaseLoader(this.myLibraryLoader);
 }
Esempio n. 3
0
 /// <summary>
 /// Decrements the reference counter of the specified loader.
 /// If this reference counter reaches 0, it is destroyed
 /// </summary>
 /// <param name="loader"></param>
 public static void ReleaseLoader(VlcLibraryLoader loader)
 {
     lock (myLoaderInstances)
     {
         loader.myRefCount--;
         if (loader.myRefCount == 0)
         {
             ((IDisposable)loader).Dispose();
             myLoaderInstances.Remove(loader.myDynamicLinkLibrariesPath.FullName);
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Creates a new VlcLibraryLoader, or get the existing one for that folder from the dictionary (increment its reference count).
        /// </summary>
        /// <param name="dynamicLinkLibrariesPath">The path from the dictionary</param>
        /// <returns>The loader</returns>
        public static VlcLibraryLoader GetOrCreateLoader(DirectoryInfo dynamicLinkLibrariesPath)
        {
            if (!dynamicLinkLibrariesPath.Exists)
            {
                throw new DirectoryNotFoundException();
            }

            lock (myLoaderInstances)
            {
                if (myLoaderInstances.ContainsKey(dynamicLinkLibrariesPath.FullName))
                {
                    var instance = myLoaderInstances[dynamicLinkLibrariesPath.FullName];
                    instance.myRefCount++;
                    return(instance);
                }

                var returnedInstance = new VlcLibraryLoader(dynamicLinkLibrariesPath);
                myLoaderInstances[dynamicLinkLibrariesPath.FullName] = returnedInstance;
                return(returnedInstance);
            }
        }