示例#1
0
        //==========================================================================
        /// <summary>
        ///   Frees the provided library.
        /// </summary>
        /// <param name="library">
        ///   The library to free.
        /// </param>
        /// <returns>
        ///   The number how ofter the library is still referenced; will be <c>0</c>
        ///   in case the library is no longer referenced and has been disposed.
        /// </returns>
        public static uint Free(LibVLCLibrary library)
        {
            if (library == null)
            {
                throw new ArgumentNullException("library");
            }

            lock (m_LibraryHandles)
            {
                LibraryHandle library_handle;
                if (m_LibraryHandles.TryGetValue(library.Directory, out library_handle))
                {
                    if (library_handle.Library == library)
                    {
                        if (--library_handle.ReferenceCounter == 0)
                        {
                            library_handle.Library.Dispose();
                            m_LibraryHandles.Remove(library.Directory);
                        }

                        if (library_handle == m_DefaultLibraryHandle)
                        {
                            m_DefaultLibraryHandle = null;
                        }

                        return(library_handle.ReferenceCounter);
                    }
                }
            }

            throw new ArgumentException("The provided library has not been loaded using the Load method!", "library");
        }
示例#2
0
        //==========================================================================
        private void Dispose(bool disposing)
        {
            if (m_MediaPlayerHandle != IntPtr.Zero)
            {
                m_Library.libvlc_media_player_release(m_MediaPlayerHandle);

                if (disposing)
                {
                    UnregisterMediaPlayer(m_MediaPlayerHandle);
                }

                m_MediaPlayerHandle = IntPtr.Zero;
            }

            if (disposing)
            {
                if (m_Instance != null)
                {
                    if (m_IsInstanceOwner)
                    {
                        m_Instance.Dispose();
                    }
                    m_Instance = null;
                }

                if (m_Library != null)
                {
                    if (m_IsLibraryOwner)
                    {
                        LibVLCLibrary.Free(m_Library);
                    }
                    m_Library = null;
                }
            }
        }
示例#3
0
        //==========================================================================
        private static string GetErrorMessage(LibVLCLibrary library)
        {
            if (library == null)
            {
                throw new ArgumentNullException("library");
            }

            return(library.libvlc_errmsg());
        }
示例#4
0
        //==========================================================================
        private void Dispose(bool disposing)
        {
            if (m_Handle != IntPtr.Zero)
            {
                m_Library.libvlc_release(m_Handle);
                m_Handle = IntPtr.Zero;
            }

            if (disposing)
            {
                if (m_Library != null)
                {
                    if (m_IsLibraryOwner)
                    {
                        LibVLCLibrary.Free(m_Library);
                    }
                    m_Library = null;
                }
            }
        }
示例#5
0
        //==========================================================================
        /// <summary>
        ///   Initializes a new instance of the class <see cref="Instance"/>.
        /// </summary>
        /// <param name="library">
        ///   May be <c>null</c> to use the default library.
        /// </param>
        public Instance(LibVLCLibrary library)
        {
            if (library == null)
            {
                m_Library        = LibVLCLibrary.Load(null);
                m_IsLibraryOwner = true;
            }
            else
            {
                m_Library        = library;
                m_IsLibraryOwner = false;
            }

            try
            {
                m_Handle = m_Library.libvlc_new(false);//Not Environment Path

                if (m_Handle == IntPtr.Zero)
                {
                    throw new LibVLCException(m_Library);
                }
            }
            catch
            {
                if (m_IsLibraryOwner)
                {
                    try
                    {
                        LibVLCLibrary.Free(m_Library);
                    }
                    catch
                    {
                        // ...
                    }
                }

                throw;
            }
        }
示例#6
0
 //==========================================================================
 /// <summary>
 ///   Initializes a new <see cref="LibVLCException"/> with the most recent
 ///   <c>LibVLC</c> error.
 /// </summary>
 /// <param name="library">
 ///   The <see cref="LibVLCLibrary"/> which will be used to obtain the
 ///   most recent error for the calling thread.
 /// </param>
 /// <remarks>
 ///   <see cref="LibVLCLibrary.libvlc_errmsg"/> is called to get the
 ///   message to initialize <see cref="Exception.Message"/> with.
 /// </remarks>
 public LibVLCException(LibVLCLibrary library)
     : this(GetErrorMessage(library))
 {
     // ...
 }
示例#7
0
 //------------------------------------------------------------------------
 public LibraryHandle(string libVLCDirectory)
 {
     ReferenceCounter = 0;
     Library          = new LibVLCLibrary(libVLCDirectory);
 }
示例#8
0
        //==========================================================================
        public MediaPlayer(LibVLCLibrary library, Instance instance)
        {
            if (library != null)
            {
                if (instance != null)
                {
                    if (instance.Library != library)
                    {
                        throw new ArgumentException("The provided instance has not been created with the provided library!", "instance");
                    }
                }
            }
            if (instance != null)
            {
                if (library == null)
                {
                    library = instance.Library;
                }
            }

            if (library == null)
            {
                m_Library        = LibVLCLibrary.Load(null);
                m_IsLibraryOwner = true;
            }
            else
            {
                m_Library        = library;
                m_IsLibraryOwner = false;
            }
            try
            {
                if (instance == null)
                {
                    m_Instance        = new Instance(m_Library);
                    m_IsInstanceOwner = true;
                }
                else
                {
                    m_Instance        = instance;
                    m_IsInstanceOwner = false;
                }
                try
                {
                    m_MediaPlayerHandle    = CreateHandle();
                    m_oldMediaPlayerHandle = m_MediaPlayerHandle;//Park MediaPlayer
                }
                catch
                {
                    if (m_IsInstanceOwner)
                    {
                        m_Instance.Dispose();
                    }
                    m_Instance = null;
                    throw;
                }
            }
            catch
            {
                if (m_IsLibraryOwner)
                {
                    LibVLCLibrary.Free(m_Library);
                }
                m_Library = null;
                throw;
            }
        }