/// <summary> /// Method for executing a session in a synchronous manner. /// </summary> /// <param name="baseInput">baseInput Object (in this case mediaInput Object) </param> /// <returns></returns> public override Result Execute(BaseInput baseInput) { CreateSessionInstance(SessionFileName); MediaInput mediaInput = (MediaInput)baseInput; string baseName = ""; string[] mediaFileAsArray = (string[])mediaInput.FileNames.ToArray(typeof(string)); if (OptionVerbose) { Implementation.ActivityReportEvent += new Dvtk.Events.ActivityReportEventHandler(ActivityReportEventHandler); } string fileName = Path.GetFileName((string)mediaInput.FileNames[0]); if (fileName.ToLower() == "dicomdir") { baseName = fileName; } else { baseName = fileName + "_DCM"; baseName.Replace(".", "_"); } string resultName = CreateResultFileName(baseName); Implementation.StartResultsGathering(resultName); Result = ((DvtkSession.MediaSession)Implementation).ValidateMediaFiles(mediaFileAsArray); Implementation.EndResultsGathering(); return(CreateResults(resultName)); }
public void TestPreparsedMediaCreate() { using (VlcMediaLibraryFactory factory = CreateNewFactory()) { factory.CreateSinglePlayers = true; PlayerOutput nullOutput = new PlayerOutput(); // string path = GetSampleAudioPath(); if (!System.IO.File.Exists(path)) { Assert.Ignore("The sample file doesn't exists. Ignoring."); } MediaInput input = new MediaInput(MediaInputType.File, path); // using (Player player = factory.CreatePlayer(nullOutput)) { PreparsedMedia media = player.ParseMediaInput(input); media = player.ParseMediaInput(input); // Assert.IsTrue(media.ContainsAudio); Assert.IsFalse(media.ContainsVideo); // AudioTrackInfo[] tracks = media.GetAudioTracks(); Assert.IsTrue(tracks.Length == 1, "There should be one audio track."); // VideoTrackInfo[] tracksVideo = media.GetVideoTracks(); Assert.IsTrue(tracksVideo.Length == 0, "There shouldn't be any video tracks."); } } }
/// <summary> /// Parses media and returns information about it. /// </summary> /// <param name="mediaInput"> /// A <see cref="MediaInput"/> to locate media to be preparsed. /// </param> /// <returns> /// A <see cref="PreparsedMedia"/> instance with information about media located using /// <param cref="mediaInput"/>. /// </returns> public override PreparsedMedia ParseMediaInput(MediaInput mediaInput) { VlcMediaInternal media = internalObjectsFactory.CreateVlcMediaInternal(mediaInput); media.Parse(); return(new VlcPreparsedMedia(mediaInput, media)); }
/// <summary> /// Initializes previously preparsed next media to play. /// </summary> /// <param name="preparsedMedia"> /// A <see cref="PreparsedMedia"/> instance returned from <see cref="ParseMediaInput"/> method. /// </param> public override void SetNextMediaInput(PreparsedMedia preparsedMedia) { VerifyObjectIsNotDisposed(); // if (preparsedMedia == null) { throw new ArgumentNullException("mediaInput"); } // nextMedia = preparsedMedia.MediaInput; // precreating of libvlc media if (currentMediaInternal != currentMediaInternalPreprepared) { if (nextMediaInternalPreprepared != null) { nextMediaInternalPreprepared.Dispose(); nextMediaInternalPreprepared = null; } } VlcMediaInternal media = GetPreparsedMediaInternal(preparsedMedia); media.SetOutput(playerOutput); // nextMediaInternalPreprepared = media; disposeNextMediaPreprepared = true; }
/// <summary> /// Default contructor with <see cref="MediaInput"/> which was passed /// to <see cref="Player.ParseMediaInput"/>. /// </summary> /// <param name="mediaInput"> /// A <see cref="MediaInput"/> instance to preparse. /// </param> public PreparsedMedia(MediaInput mediaInput) { if (mediaInput == null) { throw new ArgumentNullException("mediaInput"); } this.mediaInput = mediaInput; }
/// <summary> /// Method for executing a session in an Asynchronous manner. /// </summary> /// <param name="baseInput">baseInput Object</param> public override void BeginExecute(BaseInput baseInput) { CreateSessionInstance(SessionFileName); MediaInput mediaInput = (MediaInput)baseInput; string[] mediaFileAsArray = (string[])mediaInput.FileNames.ToArray(typeof(string)); foreach (string fileName in mediaFileAsArray) { mediaFilesToBeValidated.Enqueue(fileName); } ValidateMediaFiles(); }
private static void ValidateMediaFile() { MediaSession mediaSession = new MediaSession(); mediaSession.OptionVerbose = _OptionVerbose; mediaSession.SessionFileName = (string)_NonOptions[0]; FileInfo sessionFileName = null; if (mediaSession.SessionFileName == "") { Console.WriteLine("Warning : Provide proper arguments.\n"); return; } else { sessionFileName = new FileInfo(mediaSession.SessionFileName); } if (!sessionFileName.Exists) { Console.WriteLine(" Error : Session File does not exists.\n"); } else { MediaInput mediaInput = new MediaInput(); string mediaFile = (string)_NonOptions[1]; FileInfo mediaFileInfo = null; if (mediaFile == "") { Console.WriteLine("Warning : Provide proper arguments.\n"); return; } else { mediaFileInfo = new FileInfo(mediaFile); } if (!mediaFileInfo.Exists) { Console.WriteLine("Error : Media File does not exists.\n"); } else { mediaInput.FileNames.Add(mediaFile); Console.WriteLine(); Console.WriteLine("> Validating media file {0}...", mediaInput.FileNames[0]); mediaSession.Execute(mediaInput); DisplayResultCounters(mediaSession); DetermineExitCode(mediaSession); } } }
private bool OpenVideoStream(string URI) { try { MediaInput input = new MediaInput(MediaInputType.NetworkStream, URI); vlcPlayerControl.Play(input); } catch { return(false); } return(true); }
public void Play(string source) { MediaInput input = new MediaInput(MediaInputType.NetworkStream, source); try { vlcPlayerControl.Play(input); OnRecievingStarted(); } catch { OnRecievingFailed(); } }
/// <summary> /// Stops currently playing movie if player is not empty. /// </summary> public void Stop() { if (state != VlcPlayerControlState.Idle) { lazyInitialize(); // try { player.Stop(); } finally { currentPlaying = null; setCurrentState(VlcPlayerControlState.Idle); } } }
private void testPlayerState(Player player, MediaInput input) { Assert.AreEqual(player.State, PlayerState.Stopped); // player.SetMediaInput(input); // player.Play(); Assert.AreEqual(PlayerState.Playing, player.State); Thread.Sleep(1000); // player.Pause(); Assert.AreEqual(PlayerState.Paused, player.State); Thread.Sleep(1000); // player.Resume(); Assert.AreEqual(PlayerState.Playing, player.State); Thread.Sleep(1000); // player.Stop(); Assert.AreEqual(PlayerState.Stopped, player.State); // TestState state = new TestState(); state.player = player; state.onEndReachedCalled = false; state.handle = new EventWaitHandle(false, EventResetMode.AutoReset); state.state = 0; // try { EventsBasedPlayerEventsReceiver receiver = new EventsBasedPlayerEventsReceiver(state); receiver.EndReached += onEndReached; player.EventsReceivers.Add(receiver); // player.Play(); player.Position = 0.90f; // state.handle.WaitOne(5000); //player.Stop(); Assert.IsTrue(state.onEndReachedCalled, "EndReached event is expected."); Assert.AreEqual(PlayerState.Stopped, player.State); } finally { state.handle.Close(); state.handle = null; } }
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)); }
/// <summary> /// Method for executing a session in a synchronous manner. /// </summary> /// <param name="baseInput">baseInput Object (in this case mediaInput Object) </param> /// <returns></returns> public int ExecuteDir(BaseInput baseInput) { CreateSessionInstance(SessionFileName); MediaInput mediaInput = (MediaInput)baseInput; long TotalNrOfValidationErrors = 0; long TotalNrOfGeneralErrors = 0; long TotalNrOfUserErrors = 0; long TotalNrOfValidationWarnings = 0; long TotalNrOfGeneralWarnings = 0; long TotalNrOfUserWarnings = 0; string[] mediaFileAsArray = (string[])mediaInput.FileNames.ToArray(typeof(string)); string baseName = ""; if (OptionVerbose) { Implementation.ActivityReportEvent += new Dvtk.Events.ActivityReportEventHandler(ActivityReportEventHandler); } for (int i = 0; i < mediaInput.FileNames.Count; i++) { string fullFileName = (string)mediaInput.FileNames[i]; string fileName = Path.GetFileName(fullFileName); if (fileName.ToLower() == "dicomdir") { baseName = fileName; } else { baseName = fileName + "_DCM"; baseName.Replace(".", "_"); } Implementation.StartResultsGathering(CreateResultFileName(baseName)); string[] mediaFilesToValidate = new string[] { fullFileName }; Result = ((DvtkSession.MediaSession)Implementation).ValidateMediaFiles(mediaFilesToValidate); Implementation.EndResultsGathering(); TotalNrOfValidationErrors = TotalNrOfValidationErrors + Implementation.CountingTarget.TotalNrOfValidationErrors; TotalNrOfUserErrors = TotalNrOfValidationErrors + Implementation.CountingTarget.TotalNrOfUserErrors; TotalNrOfGeneralErrors = TotalNrOfValidationErrors + Implementation.CountingTarget.TotalNrOfGeneralErrors; TotalNrOfValidationWarnings = TotalNrOfValidationWarnings + Implementation.CountingTarget.TotalNrOfValidationWarnings; TotalNrOfGeneralWarnings = TotalNrOfValidationErrors + Implementation.CountingTarget.TotalNrOfGeneralWarnings; TotalNrOfUserWarnings = TotalNrOfUserWarnings + Implementation.CountingTarget.TotalNrOfUserWarnings; } DisplayResultCounters(TotalNrOfValidationErrors, TotalNrOfGeneralErrors, TotalNrOfUserErrors, TotalNrOfValidationWarnings, TotalNrOfGeneralWarnings, TotalNrOfUserWarnings); return(DetermineExitCode(TotalNrOfValidationErrors, TotalNrOfGeneralErrors, TotalNrOfUserErrors, TotalNrOfValidationWarnings, TotalNrOfGeneralWarnings, TotalNrOfUserWarnings)); }
private void testPlayerState(MediaLibraryFactory factory) { PlayerOutput nullOutput = new PlayerOutput(); // string path = GetSampleAudioPath(); if (!System.IO.File.Exists(path)) { Assert.Ignore("The sample file doesn't exists. Ignoring."); } MediaInput input = new MediaInput(MediaInputType.File, path); // using (Player player = factory.CreatePlayer(nullOutput)) { testPlayerState(player, input); } }
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)); }
/// <summary> /// Constructor. /// </summary> public PlaylistItem(MediaInput mediaInput, string title, TimeSpan duration) { if (mediaInput == null) { throw new ArgumentNullException("mediaInput"); } if (title == null) { throw new ArgumentNullException("title"); } if (title.Length == 0) { throw new ArgumentException("String is empty.", "title"); } // this.mediaInput = mediaInput; this.title = title; this.duration = duration; // isError = false; }
/// <summary> /// Starts playing. /// </summary> /// <param name="mediaInput">Media to play.</param> public void Play(MediaInput mediaInput) { if (mediaInput == null) { throw new ArgumentNullException("mediaInput"); } // lazyInitialize(); // try { currentPlaying = mediaInput; player.SetNextMediaInput(mediaInput); player.Volume = volume; player.PlayNext(); // setCurrentState(VlcPlayerControlState.Playing); } catch { Stop(); throw; } }
/// <summary> /// Specifies next media input. /// </summary> public override void SetNextMediaInput(MediaInput mediaInput) { VerifyObjectIsNotDisposed(); // if (mediaInput == null) { throw new ArgumentNullException("mediaInput"); } // nextMedia = mediaInput; // precreating of libvlc media if (currentMediaInternal != currentMediaInternalPreprepared) { if (nextMediaInternalPreprepared != null) { nextMediaInternalPreprepared.Dispose(); nextMediaInternalPreprepared = null; } } nextMediaInternalPreprepared = internalObjectsFactory.CreateVlcMediaInternal(nextMedia); nextMediaInternalPreprepared.SetOutput(playerOutput); disposeNextMediaPreprepared = true; }
/// <summary> /// Initializes next media. /// </summary> /// <param name="mediaInput">Specified media to play after <see cref="PlayNext"/> method call.</param> public abstract void SetNextMediaInput(MediaInput mediaInput);
/// <summary> /// Parses media and returns information about it. /// </summary> /// <param name="mediaInput"> /// A <see cref="MediaInput"/> to locate media to be preparsed. /// </param> /// <returns> /// A <see cref="PreparsedMedia"/> instance with information about media located using /// <param cref="mediaInput"/>. /// </returns> public abstract PreparsedMedia ParseMediaInput(MediaInput mediaInput);
private static void ValidateMediaDirectory() { MediaSession mediaSession = new MediaSession(); mediaSession.OptionVerbose = _OptionVerbose; mediaSession.SessionFileName = (string)_NonOptions[0]; FileInfo sessionFileName = null; ArrayList allDCMFilesTemp = new ArrayList(); FileInfo mediaFileInfo = null; if (mediaSession.SessionFileName == "") { Console.WriteLine("Warning : Provide proper arguments.\n"); return; } else { sessionFileName = new FileInfo(mediaSession.SessionFileName); } if (!sessionFileName.Exists) { Console.WriteLine(" Error : Session File does not exists.\n"); } else { MediaInput mediaInput = new MediaInput(); string mediaFile = (string)_NonOptions[1]; mediaFileInfo = new FileInfo(mediaFile); if (mediaFile == "") { Console.WriteLine("Warning : Provide proper arguments.\n"); return; } else if (mediaFileInfo.Exists) { allDCMFilesTemp.Add(mediaFileInfo.FullName); mediaInput.FileNames = allDCMFilesTemp; Console.WriteLine(); Console.WriteLine("> Validating media file {0}...", mediaInput.FileNames[0]); mediaSession.Execute(mediaInput); DisplayResultCounters(mediaSession); DetermineExitCode(mediaSession); } else { DirectoryInfo theDirectoryInfo = new DirectoryInfo(mediaFile); if (!theDirectoryInfo.Exists) { Console.WriteLine("Error : Directory or File mentioned does not exists.\n"); } else { mediaInput.FileNames = GetFilesRecursively(theDirectoryInfo); Console.WriteLine(); Console.WriteLine("> Validating media files ..."); _exitCode = mediaSession.ExecuteDir(mediaInput); //DisplayResultCounters(mediaSession); //DetermineExitCode(mediaSession); } } } }
private async Task <AnalyzeResult> GetVideoInfoAsync(MediaInput mediaInput, CancellationToken cancellationToken = default) { if (!File.Exists(this._ffprobePath)) { return(new AnalyzeResult { Successful = false, ErrorMessage = $"ffprobe could not be found {this._ffprobePath}" }); } var startInfo = new ProcessStartInfo { FileName = this._ffprobePath, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true, }; if (mediaInput.FileContent != null) { startInfo.RedirectStandardInput = true; startInfo.Arguments = $"-v quiet -print_format json -show_format -show_streams -"; } else { startInfo.Arguments = $"-v quiet -print_format json -show_format -show_streams \"{mediaInput.FilePath}\""; } using (var outputWaitHandle = new AutoResetEvent(false)) { var json = new StringBuilder(); var dataReceived = new DataReceivedEventHandler((sender, e) => { if (e.Data == null) { outputWaitHandle.Set(); return; } json.AppendLine(e.Data); }); this._process = new Process(); try { this._process.StartInfo = startInfo; this._process.OutputDataReceived += dataReceived; if (!this._process.Start()) { return(new AnalyzeResult { ErrorMessage = "Cannot start ffprobe" }); } this._process.BeginOutputReadLine(); if (mediaInput.FileContent != null) { using (var ffprobeIn = this._process.StandardInput.BaseStream) { var packageSize = 100000; for (var i = 0; i < mediaInput.FileContent.Length; i += packageSize) { var package = mediaInput.FileContent.Skip(i).Take(packageSize).ToArray(); await ffprobeIn.WriteAsync(package, 0, package.Length, cancellationToken); } await ffprobeIn.FlushAsync(cancellationToken); ffprobeIn.Close(); } } if (!this._process.WaitForExit(this._timeout) || !outputWaitHandle.WaitOne(this._timeout)) { return(new AnalyzeResult { ErrorMessage = $"Timeout reached {this._timeout} (ms)" }); } var videoInfo = JsonConvert.DeserializeObject <VideoInfoResult>(json.ToString(), this._jsonSerializerSettings); if (videoInfo.Format == null && videoInfo.Streams == null) { return(new AnalyzeResult { Successful = false, ErrorMessage = "No feedback from ffprobe" }); } return(new AnalyzeResult { Successful = true, VideoInfo = videoInfo }); } catch (IOException) { var videoInfo = JsonConvert.DeserializeObject <VideoInfoResult>(json.ToString(), this._jsonSerializerSettings); if (videoInfo.Format == null && videoInfo.Streams == null) { return(new AnalyzeResult { Successful = false, ErrorMessage = "No feedback from ffprobe (IOException)" }); } return(new AnalyzeResult { Successful = true, VideoInfo = videoInfo }); } catch (Exception exception) { return(new AnalyzeResult { Successful = false, ErrorMessage = exception.ToString() }); } finally { this._process.OutputDataReceived -= dataReceived; this._process?.Dispose(); } } }