Exemplo n.º 1
0
        /// <summary>
        /// Attaches an event to player with selected eventManager.
        /// And stores used delegate in internal list.
        /// </summary>
        internal void attachToEvent(IntPtr eventManager, Delegate eventHandlerDelegate, libvlc_event_type_e eventType, Object tag)
        {
            if (eventManager == IntPtr.Zero)
            {
                throw new ArgumentException("IntPtr.Zero is invalid value.", "eventManager");
            }
            if (eventHandlerDelegate == null)
            {
                throw new ArgumentNullException("eventHandlerDelegate");
            }
            //
            AttachedEvent newEvent = new AttachedEvent(); {
                newEvent.EventManager = eventManager;
                newEvent.EventType    = eventType;
                newEvent.UserData     = new IntPtr(totalEventsAttached++);
                newEvent.Event        = eventHandlerDelegate;
                newEvent.Function     = Marshal.GetFunctionPointerForDelegate(eventHandlerDelegate);
                newEvent.Tag          = tag;
            };
            //
            int res = LibVlcInterop.libvlc_event_attach(newEvent.EventManager, newEvent.EventType,
                                                        newEvent.Function,
                                                        newEvent.UserData);

            if (res != 0)
            {
                throw new VlcInternalException(String.Format("Unable to attach event {0}", eventType.ToString()));
            }
            // save delegate to a private list (to suppress finalizing it)
            eventDelegates.Add(newEvent);
        }
Exemplo n.º 2
0
        protected override void Dispose(bool isDisposing)
        {
            try {
                // Release unmanaged resources
                libvlc_exception_t exc = new libvlc_exception_t();
                LibVlcInterop.libvlc_exception_init(ref exc);
                LibVlcInterop.libvlc_log_close(descriptor, ref exc);
                if (exc.b_raised != 0)
                {
                    // Do not throw any exception in finalizer thread
                    if (isDisposing)
                    {
                        throw new VlcInternalException(exc.Message);
                    }
                    else
                    {
#if DEBUG
                        Debugger.Log(0, Debugger.DefaultCategory, String.Format("libvlc exception during finalizing a {0} : {1}", GetType(), exc.Message));
#endif
                    }
                }
            } finally {
                base.Dispose(isDisposing);
            }
        }
Exemplo n.º 3
0
        public string GetMrl()
        {
            VerifyObjectIsNotDisposed();
            string mrl = LibVlcInterop.libvlc_media_get_mrl(this.descriptor);

            return(mrl);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Disposes all unmanaged resources.
 /// </summary>
 /// <param name="isDisposing">If this parameters is <code>True</code> then Dispose is called explicitly, else Dispose called from finalizer.</param>
 protected override void Dispose(bool isDisposing)
 {
     try {
         if (isDisposing)
         {
             if (thread != null)
             {
                 try {
                     if (thread.IsAlive)
                     {
                         stopLoggingThread();
                     }
                 } catch (Exception exc) {
                     if (logger.IsErrorEnabled)
                     {
                         logger.Error("Error while trying to interrupt a logging thread.", exc);
                     }
                     throw;
                 }
             }
             if (vlcLog != null)
             {
                 vlcLog.Dispose();
             }
         }
         //
         if (descriptor != IntPtr.Zero)
         {
             LibVlcInterop.libvlc_release(descriptor);
         }
     } finally {
         base.Dispose(isDisposing);
     }
 }
Exemplo n.º 5
0
 protected override void Dispose(bool isDisposing)
 {
     try {
         LibVlcInterop.libvlc_media_player_release(descriptor);
     } finally {
         base.Dispose(isDisposing);
     }
 }
Exemplo n.º 6
0
 protected override void Dispose(bool isDisposing)
 {
     try {
         // Release unmanaged resources
         LibVlcInterop.libvlc_log_close(descriptor);
     } finally {
         base.Dispose(isDisposing);
     }
 }
Exemplo n.º 7
0
 public void SetMedia(VlcMediaInternal media)
 {
     if (media == null)
     {
         throw new ArgumentNullException("media");
     }
     //
     VerifyObjectIsNotDisposed();
     //
     LibVlcInterop.libvlc_media_player_set_media(descriptor, media.Descriptor);
 }
Exemplo n.º 8
0
        public VlcMediaPlayerInternal CreateVlcMediaPlayerInternal()
        {
            IntPtr mediaplayerDescriptor = LibVlcInterop.libvlc_media_player_new(vlclibDescriptor);

            if (mediaplayerDescriptor == IntPtr.Zero)
            {
                throw new VlcInternalException(LibVlcInterop.libvlc_errmsg());
            }
            //
            return(new VlcMediaPlayerInternal(mediaplayerDescriptor));
        }
Exemplo n.º 9
0
        public void Play()
        {
            VerifyObjectIsNotDisposed();
            //
            int res = LibVlcInterop.libvlc_media_player_play(descriptor);

            if (res != 0)
            {
                throw new VlcInternalException(LibVlcInterop.libvlc_errmsg());
            }
        }
Exemplo n.º 10
0
        public void Clear()
        {
            VerifyObjectIsNotDisposed();
            // Clear the vlc log source
            libvlc_exception_t exc = new libvlc_exception_t();

            LibVlcInterop.libvlc_exception_init(ref exc);
            LibVlcInterop.libvlc_log_clear(descriptor, ref exc);
            if (exc.b_raised != 0)
            {
                throw new VlcInternalException(exc.Message);
            }
        }
Exemplo n.º 11
0
        public void SetDisplayOutput(Int32 handle)
        {
            VerifyObjectIsNotDisposed();
            //
            libvlc_exception_t exc = new libvlc_exception_t();

            LibVlcInterop.libvlc_exception_init(ref exc);
            LibVlcInterop.libvlc_media_player_set_drawable(descriptor, handle, ref exc);
            if (exc.b_raised != 0)
            {
                throw new VlcInternalException(exc.Message);
            }
        }
Exemplo n.º 12
0
        public void Pause()
        {
            VerifyObjectIsNotDisposed();
            //
            libvlc_exception_t exc = new libvlc_exception_t();

            LibVlcInterop.libvlc_exception_init(ref exc);
            LibVlcInterop.libvlc_media_player_pause(descriptor, ref exc);
            if (exc.b_raised != 0)
            {
                throw new VlcInternalException(exc.Message);
            }
        }
Exemplo n.º 13
0
        public VlcMediaPlayerInternal CreateVlcMediaPlayerInternal()
        {
            libvlc_exception_t exc = new libvlc_exception_t();

            LibVlcInterop.libvlc_exception_init(ref exc);
            IntPtr mediaplayerDescriptor = LibVlcInterop.libvlc_media_player_new(vlclibDescriptor, ref exc);

            if (exc.b_raised != 0)
            {
                throw new VlcInternalException(exc.Message);
            }
            //
            return(new VlcMediaPlayerInternal(mediaplayerDescriptor));
        }
Exemplo n.º 14
0
 private void addOption(string option)
 {
     if (option == null)
     {
         throw new ArgumentNullException("option");
     }
     if (option.Length == 0)
     {
         throw new ArgumentException("String is empty.", "option");
     }
     //
     VerifyObjectIsNotDisposed();
     //
     LibVlcInterop.libvlc_media_add_option(descriptor, option);
 }
Exemplo n.º 15
0
        public VlcLog CreateVlcLog(ILog log, ILogVerbosityManager logVerbosityManager)
        {
            if (log == null)
            {
                throw new ArgumentNullException("log");
            }
            //
            IntPtr libvlc_log_t = LibVlcInterop.libvlc_log_open(vlclibDescriptor);

            if (libvlc_log_t == IntPtr.Zero)
            {
                throw new VlcInternalException(LibVlcInterop.libvlc_errmsg());
            }
            //
            return(new VlcLog(libvlc_log_t, logVerbosityManager, log));
        }
Exemplo n.º 16
0
        public VlcMediaInternal CreateVlcMediaInternal(MediaInput mediaInput)
        {
            if (mediaInput == null)
            {
                throw new ArgumentNullException("mediaInput");
            }
            //
            IntPtr mediaDescriptor = LibVlcInterop.libvlc_media_new_path(vlclibDescriptor, mediaInput.Source);

            if (mediaDescriptor == IntPtr.Zero)
            {
                throw new VlcInternalException(LibVlcInterop.libvlc_errmsg());
            }
            //
            return(new VlcMediaInternal(mediaDescriptor));
        }
Exemplo n.º 17
0
        private static IntPtr createInstance(string[] parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            //
            IntPtr res = LibVlcInterop.libvlc_new(parameters);

            if (IntPtr.Zero == res)
            {
                throw new VlcInternalException(LibVlcInterop.libvlc_errmsg());
            }
            //
            return(res);
        }
Exemplo n.º 18
0
        public void SetMedia(VlcMediaInternal media)
        {
            if (media == null)
            {
                throw new ArgumentNullException("media");
            }
            //
            VerifyObjectIsNotDisposed();
            //
            libvlc_exception_t exc = new libvlc_exception_t();

            LibVlcInterop.libvlc_exception_init(ref exc);
            LibVlcInterop.libvlc_media_player_set_media(descriptor, media.Descriptor, ref exc);
            if (exc.b_raised != 0)
            {
                throw new VlcInternalException(exc.Message);
            }
        }
Exemplo n.º 19
0
        private void initializeEvents()
        {
            VlcMediaPlayerInternal player = internalPlayer;
            //
            IntPtr pFirstMediaPlayerInternalEventManager =
                LibVlcInterop.libvlc_media_player_event_manager(player.Descriptor);

            // Attaching to player
            attachToEvent(pFirstMediaPlayerInternalEventManager,
                          new LibVlcInterop.VlcEventHandlerDelegate(playerInternal_TimeChanged),
                          libvlc_event_type_e.libvlc_MediaPlayerTimeChanged);
            attachToEvent(pFirstMediaPlayerInternalEventManager,
                          new LibVlcInterop.VlcEventHandlerDelegate(playerInternal_Stopped),
                          libvlc_event_type_e.libvlc_MediaPlayerStopped);
            attachToEvent(pFirstMediaPlayerInternalEventManager,
                          new LibVlcInterop.VlcEventHandlerDelegate(playerInternal_PositionChanged),
                          libvlc_event_type_e.libvlc_MediaPlayerPositionChanged);
            attachToEvent(pFirstMediaPlayerInternalEventManager,
                          new LibVlcInterop.VlcEventHandlerDelegate(playerInternal_EncounteredError),
                          libvlc_event_type_e.libvlc_MediaPlayerEncounteredError);
            attachToEvent(pFirstMediaPlayerInternalEventManager,
                          new LibVlcInterop.VlcEventHandlerDelegate(playerInternal_EndReached),
                          libvlc_event_type_e.libvlc_MediaPlayerEndReached);

            // StateChanged events
            attachToEvent(pFirstMediaPlayerInternalEventManager,
                          new LibVlcInterop.VlcEventHandlerDelegate(playerInternal_StateChanged),
                          libvlc_event_type_e.libvlc_MediaPlayerOpening);
            attachToEvent(pFirstMediaPlayerInternalEventManager,
                          new LibVlcInterop.VlcEventHandlerDelegate(playerInternal_StateChanged),
                          libvlc_event_type_e.libvlc_MediaPlayerBuffering);
            attachToEvent(pFirstMediaPlayerInternalEventManager,
                          new LibVlcInterop.VlcEventHandlerDelegate(playerInternal_StateChanged),
                          libvlc_event_type_e.libvlc_MediaPlayerPlaying);
            attachToEvent(pFirstMediaPlayerInternalEventManager,
                          new LibVlcInterop.VlcEventHandlerDelegate(playerInternal_StateChanged),
                          libvlc_event_type_e.libvlc_MediaPlayerPaused);
            attachToEvent(pFirstMediaPlayerInternalEventManager,
                          new LibVlcInterop.VlcEventHandlerDelegate(playerInternal_StateChanged),
                          libvlc_event_type_e.libvlc_MediaPlayerSeekableChanged);
            attachToEvent(pFirstMediaPlayerInternalEventManager,
                          new LibVlcInterop.VlcEventHandlerDelegate(playerInternal_StateChanged),
                          libvlc_event_type_e.libvlc_MediaPlayerPausableChanged);
        }
Exemplo n.º 20
0
        public VlcLog CreateVlcLog(ILog log, ILogVerbosityManager logVerbosityManager)
        {
            if (log == null)
            {
                throw new ArgumentNullException("log");
            }
            //
            libvlc_exception_t exc = new libvlc_exception_t();

            LibVlcInterop.libvlc_exception_init(ref exc);
            IntPtr libvlc_log_t = LibVlcInterop.libvlc_log_open(vlclibDescriptor, ref exc);

            if (exc.b_raised != 0)
            {
                throw new VlcInternalException(exc.Message);
            }
            //
            return(new VlcLog(libvlc_log_t, logVerbosityManager, log));
        }
Exemplo n.º 21
0
        public VlcMediaInternal CreateVlcMediaInternal(MediaInput mediaInput)
        {
            if (mediaInput == null)
            {
                throw new ArgumentNullException("mediaInput");
            }
            //
            libvlc_exception_t exc = new libvlc_exception_t();

            LibVlcInterop.libvlc_exception_init(ref exc);
            IntPtr mediaDescriptor = LibVlcInterop.libvlc_media_new(vlclibDescriptor, mediaInput.Source, ref exc);

            if (exc.b_raised != 0)
            {
                throw new VlcInternalException(exc.Message);
            }
            //
            return(new VlcMediaInternal(mediaDescriptor));
        }
Exemplo n.º 22
0
        private static IntPtr createInstance(string[] parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            //
            libvlc_exception_t exc = new libvlc_exception_t();

            LibVlcInterop.libvlc_exception_init(ref exc);
            IntPtr res = LibVlcInterop.libvlc_new(parameters, ref exc);

            if (exc.b_raised != 0)
            {
                throw new VlcInternalException(exc.Message);
            }
            //
            return(res);
        }
Exemplo n.º 23
0
        public void TakeSnapshot(string filePath, int width, int height)
        {
            VerifyObjectIsNotDisposed();
            //
            IntPtr filePathPtr = Marshal.StringToHGlobalAnsi(filePath);
            //
            uint uwidth  = Convert.ToUInt32(width);
            uint uheight = Convert.ToUInt32(height);

            //
            try {
                int res = LibVlcInterop.libvlc_video_take_snapshot(descriptor, 0, filePathPtr, uwidth, uheight);
                if (-1 == res)
                {
                    throw new VlcInternalException(LibVlcInterop.libvlc_errmsg());
                }
            } finally {
                Marshal.FreeHGlobal(filePathPtr);
            }
        }
        private void addOption(string option)
        {
            if (option == null)
            {
                throw new ArgumentNullException("option");
            }
            if (option.Length == 0)
            {
                throw new ArgumentException("String is empty.", "option");
            }
            //
            VerifyObjectIsNotDisposed();
            //
            libvlc_exception_t exc = new libvlc_exception_t();

            LibVlcInterop.libvlc_exception_init(ref exc);
            LibVlcInterop.libvlc_media_add_option(descriptor, option, ref exc);
            if (exc.b_raised != 0)
            {
                throw new VlcInternalException(exc.Message);
            }
        }
Exemplo n.º 25
0
            public VlcPreparsedMedia(Io.MediaInput mediaInput, VlcMediaInternal media) : base(mediaInput)
            {
                if (media == null)
                {
                    throw new ArgumentNullException("media");
                }
                this.media    = media;
                this.Duration = media.Duration;
                //
                List <AudioTrackInfo> audioTracks = new List <AudioTrackInfo>();
                List <VideoTrackInfo> videoTracks = new List <VideoTrackInfo>();

                libvlc_media_track_info_t[] tracks = media.GetTracksInfo();
                foreach (libvlc_media_track_info_t track in tracks)
                {
                    if (track.i_type == libvlc_track_t.libvlc_track_audio)
                    {
                        AudioTrackInfo audioTrack = new AudioTrackInfo();
                        audioTrack.BitRate     = track.i_rate;
                        audioTrack.Channels    = (int)Math.Min(track.i_channels, (uint)int.MaxValue);
                        audioTrack.Code        = track.i_codec;
                        audioTrack.Description = LibVlcInterop.vlc_fourcc_GetDescription(0, track.i_codec);
                        audioTracks.Add(audioTrack);
                    }
                    else if (track.i_type == libvlc_track_t.libvlc_track_video)
                    {
                        VideoTrackInfo videoTrack = new VideoTrackInfo();
                        videoTrack.Code        = track.i_codec;
                        videoTrack.Description = LibVlcInterop.vlc_fourcc_GetDescription(0, track.i_codec);
                        videoTrack.Height      = (int)Math.Min((uint)int.MaxValue, (uint)track.i_height);
                        videoTrack.Width       = (int)Math.Min((uint)int.MaxValue, (uint)track.i_width);
                        videoTracks.Add(videoTrack);
                    }
                }
                //
                SetTracksInfo(videoTracks, audioTracks);
            }
Exemplo n.º 26
0
        public void TakeSnapshot(string filePath, int width, int height)
        {
            VerifyObjectIsNotDisposed();
            //
            libvlc_exception_t exc = new libvlc_exception_t();

            LibVlcInterop.libvlc_exception_init(ref exc);
            IntPtr filePathPtr = Marshal.StringToHGlobalAnsi(filePath);
            //
            uint uwidth  = Convert.ToUInt32(width);
            uint uheight = Convert.ToUInt32(height);

            //
            try {
                LibVlcInterop.libvlc_video_take_snapshot(descriptor, filePathPtr, uwidth, uheight, ref exc);
            } finally {
                Marshal.FreeHGlobal(filePathPtr);
            }
            //
            if (exc.b_raised != 0)
            {
                throw new VlcInternalException(exc.Message);
            }
        }
Exemplo n.º 27
0
 public void Pause()
 {
     VerifyObjectIsNotDisposed();
     //
     LibVlcInterop.libvlc_media_player_pause(descriptor);
 }
Exemplo n.º 28
0
 public void SetDisplayOutputAgl(IntPtr handle)
 {
     VerifyObjectIsNotDisposed();
     //
     LibVlcInterop.libvlc_media_player_set_agl(descriptor, handle);
 }
Exemplo n.º 29
0
 public void Parse()
 {
     VerifyObjectIsNotDisposed();
     //
     lock (staticLock) {
         if (!IsParsed())
         {
             LibVlcInterop.libvlc_media_parse(this.descriptor);
         }
         //
         if (tracksInfo == null)
         {
             parseState            = new ParseState();
             parseState.waitHandle = new EventWaitHandle(false,
                                                         EventResetMode.AutoReset);
             try {
                 IntPtr player = LibVlcInterop.libvlc_media_player_new_from_media(this.descriptor);
                 if (player == IntPtr.Zero)
                 {
                     throw new VlcInternalException(String.Format("Can't create an instance of player when parsing. LibVlc tells: {0}",
                                                                  LibVlcInterop.libvlc_errmsg()));
                 }
                 IntPtr playerEvents = LibVlcInterop.libvlc_media_player_event_manager(player);
                 if (playerEvents == IntPtr.Zero)
                 {
                     throw new VlcInternalException(String.Format("Can't get event manager of player when parsing. LibVlc tells: {0}",
                                                                  LibVlcInterop.libvlc_errmsg()));
                 }
                 //
                 try {
                     parseState.eventHandler = new LibVlcInterop.VlcEventHandlerDelegate(onTrackInfoEndReached);
                     IntPtr function = Marshal.GetFunctionPointerForDelegate(parseState.eventHandler);
                     //
                     int res = LibVlcInterop.libvlc_event_attach(playerEvents, libvlc_event_type_e.libvlc_MediaPlayerEndReached,
                                                                 function,
                                                                 IntPtr.Zero);
                     if (res != 0)
                     {
                         throw new VlcInternalException(String.Format("Unable to attach event {0}",
                                                                      libvlc_event_type_e.libvlc_MediaPlayerEndReached.ToString()));
                     }
                     //
                     LibVlcInterop.libvlc_media_add_option(descriptor, "sout=#description");
                     LibVlcInterop.libvlc_media_player_play(player);
                     //
                     if (parseState.waitHandle.WaitOne(parseTimeout))
                     {
                         //
                         LibVlcInterop.libvlc_media_player_release(player);
                         player = IntPtr.Zero;
                         //
                         tracksInfo = LibVlcInterop.libvlc_media_get_tracks_info(descriptor);
                         //
                         if (logger.IsInfoEnabled)
                         {
                             StringBuilder builder = new StringBuilder();
                             builder.Append("Parsed tracks info: ");
                             //
                             foreach (libvlc_media_track_info_t track in tracksInfo)
                             {
                                 builder.AppendLine("");
                                 if (track.i_type == libvlc_track_t.libvlc_track_audio)
                                 {
                                     builder.AppendLine("Type: audio");
                                     builder.AppendLine("Channels: " + track.i_channels);
                                     builder.AppendLine("Rate: " + track.i_rate);
                                 }
                                 else if (track.i_type == libvlc_track_t.libvlc_track_text)
                                 {
                                     builder.AppendLine("Type: text");
                                 }
                                 else if (track.i_type == libvlc_track_t.libvlc_track_video)
                                 {
                                     builder.AppendLine("Type: video");
                                 }
                                 else
                                 {
                                     builder.AppendLine("Type: unknown");
                                 }
                                 builder.AppendLine("Description: " + LibVlcInterop.vlc_fourcc_GetDescription(0, track.i_codec));
                             }
                             //
                             builder.AppendLine("Total tracks: " + tracksInfo.Length);
                             logger.Info(builder.ToString());
                         }
                     }
                     else
                     {
                         throw new VlcTimeoutException("Can't get tracks information.");
                     }
                 } finally {
                     if (player != IntPtr.Zero)
                     {
                         LibVlcInterop.libvlc_media_player_release(player);
                     }
                 }
             } catch (Exception exc) {
                 if (logger.IsErrorEnabled)
                 {
                     logger.Error("An error occured during parse.", exc);
                 }
                 throw;
             } finally {
                 parseState.waitHandle.Close();
                 parseState = null;
             }
         }
     }
 }
Exemplo n.º 30
0
 public bool IsParsed()
 {
     VerifyObjectIsNotDisposed();
     return(LibVlcInterop.libvlc_media_is_parsed(this.descriptor));
 }