/// <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); }
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); } }
public string GetMrl() { VerifyObjectIsNotDisposed(); string mrl = LibVlcInterop.libvlc_media_get_mrl(this.descriptor); return(mrl); }
/// <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); } }
protected override void Dispose(bool isDisposing) { try { LibVlcInterop.libvlc_media_player_release(descriptor); } finally { base.Dispose(isDisposing); } }
protected override void Dispose(bool isDisposing) { try { // Release unmanaged resources LibVlcInterop.libvlc_log_close(descriptor); } finally { base.Dispose(isDisposing); } }
public void SetMedia(VlcMediaInternal media) { if (media == null) { throw new ArgumentNullException("media"); } // VerifyObjectIsNotDisposed(); // LibVlcInterop.libvlc_media_player_set_media(descriptor, media.Descriptor); }
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)); }
public void Play() { VerifyObjectIsNotDisposed(); // int res = LibVlcInterop.libvlc_media_player_play(descriptor); if (res != 0) { throw new VlcInternalException(LibVlcInterop.libvlc_errmsg()); } }
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); } }
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); } }
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); } }
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)); }
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); }
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)); }
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)); }
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); }
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); } }
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); }
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)); }
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)); }
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); }
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); } }
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); }
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); } }
public void Pause() { VerifyObjectIsNotDisposed(); // LibVlcInterop.libvlc_media_player_pause(descriptor); }
public void SetDisplayOutputAgl(IntPtr handle) { VerifyObjectIsNotDisposed(); // LibVlcInterop.libvlc_media_player_set_agl(descriptor, handle); }
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; } } } }
public bool IsParsed() { VerifyObjectIsNotDisposed(); return(LibVlcInterop.libvlc_media_is_parsed(this.descriptor)); }